diff --git a/genesis/process/disabled/disabled_test.go b/genesis/process/disabled/disabled_test.go index ab5cc1e93be..86edf18fab1 100644 --- a/genesis/process/disabled/disabled_test.go +++ b/genesis/process/disabled/disabled_test.go @@ -109,6 +109,10 @@ func TestFeeHandler(t *testing.T) { require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerBlockForSafeCrossShard()) require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerMiniBlockForSafeCrossShard()) require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerTx()) + require.Equal(t, uint64(math.MaxUint64), handler.BlockCapacityOverestimationFactor()) + require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerTxInEpoch(0)) + require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerBlockForSafeCrossShardInEpoch(0)) + require.Equal(t, uint64(math.MaxUint64), handler.MaxGasLimitPerBlockInEpoch(0, 0)) require.Equal(t, uint64(0), handler.ComputeGasLimit(nil)) require.Equal(t, big.NewInt(0), handler.ComputeMoveBalanceFee(nil)) require.Equal(t, big.NewInt(0), handler.ComputeFeeForProcessing(nil, 0)) diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index 9f2a8f7ec29..652e03f15a9 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -57,11 +57,21 @@ func (fh *FeeHandler) MaxGasPriceSetGuardian() uint64 { return math.MaxUint64 } +// BlockCapacityOverestimationFactor returns max uint64 +func (fh *FeeHandler) BlockCapacityOverestimationFactor() uint64 { + return math.MaxUint64 +} + // MaxGasLimitPerBlock returns max uint64 func (fh *FeeHandler) MaxGasLimitPerBlock(uint32) uint64 { return math.MaxUint64 } +// MaxGasLimitPerBlockInEpoch returns max uint64 +func (fh *FeeHandler) MaxGasLimitPerBlockInEpoch(_ uint32, _ uint32) uint64 { + return math.MaxUint64 +} + // MaxGasLimitPerMiniBlock returns max uint64 func (fh *FeeHandler) MaxGasLimitPerMiniBlock(uint32) uint64 { return math.MaxUint64 @@ -72,6 +82,11 @@ func (fh *FeeHandler) MaxGasLimitPerBlockForSafeCrossShard() uint64 { return math.MaxUint64 } +// MaxGasLimitPerBlockForSafeCrossShardInEpoch returns max uint64 +func (fh *FeeHandler) MaxGasLimitPerBlockForSafeCrossShardInEpoch(_ uint32) uint64 { + return math.MaxUint64 +} + // MaxGasLimitPerMiniBlockForSafeCrossShard returns max uint64 func (fh *FeeHandler) MaxGasLimitPerMiniBlockForSafeCrossShard() uint64 { return math.MaxUint64 @@ -87,6 +102,11 @@ func (fh *FeeHandler) MaxGasLimitPerTx() uint64 { return math.MaxUint64 } +// MaxGasLimitPerTxInEpoch returns max uint64 +func (fh *FeeHandler) MaxGasLimitPerTxInEpoch(_ uint32) uint64 { + return math.MaxUint64 +} + // ComputeGasLimit returns 0 func (fh *FeeHandler) ComputeGasLimit(_ data.TransactionWithFeeHandler) uint64 { return 0 diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 12cdf5b7fbb..4b245182699 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -15,9 +15,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/marshal" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - vmcommonBuiltInFunctions "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" - "github.com/multiversx/mx-chain-vm-common-go/parsers" processBlock "github.com/multiversx/mx-chain-go/process/block" @@ -51,6 +48,9 @@ import ( "github.com/multiversx/mx-chain-go/update" hardForkProcess "github.com/multiversx/mx-chain-go/update/process" "github.com/multiversx/mx-chain-go/vm" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + vmcommonBuiltInFunctions "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" + "github.com/multiversx/mx-chain-vm-common-go/parsers" ) // CreateMetaGenesisBlock will create a metachain genesis block diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index da92c3058db..cb9db5f2136 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -10,9 +10,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" dataBlock "github.com/multiversx/mx-chain-core-go/data/block" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/multiversx/mx-chain-vm-common-go/parsers" - "github.com/multiversx/mx-chain-go/common" disabledCommon "github.com/multiversx/mx-chain-go/common/disabled" "github.com/multiversx/mx-chain-go/common/enablers" @@ -45,6 +42,8 @@ import ( "github.com/multiversx/mx-chain-go/txcache" "github.com/multiversx/mx-chain-go/update" hardForkProcess "github.com/multiversx/mx-chain-go/update/process" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-vm-common-go/parsers" ) const unreachableEpoch = ^uint32(0) diff --git a/process/block/preprocess/gasTracker.go b/process/block/preprocess/gasTracker.go index 6cebea3426d..f3d1a2bd332 100644 --- a/process/block/preprocess/gasTracker.go +++ b/process/block/preprocess/gasTracker.go @@ -3,14 +3,19 @@ package preprocess import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" ) +const noOverestimationFactor = uint64(100) + type gasTracker struct { - shardCoordinator sharding.Coordinator - economicsFee process.FeeHandler - gasHandler process.GasHandler + shardCoordinator sharding.Coordinator + economicsFee process.FeeHandler + gasHandler process.GasHandler + enableEpochsHandler common.EnableEpochsHandler + enableRoundsHandler common.EnableRoundsHandler } func (gt *gasTracker) computeGasProvided( @@ -29,22 +34,24 @@ func (gt *gasTracker) computeGasProvided( return 0, err } + epoch, overEstimationFactor := gt.getEpochAndOverestimationFactorForGasLimits() + gasProvidedByTxInSelfShard := uint64(0) if gt.shardCoordinator.SelfId() == senderShardId { gasProvidedByTxInSelfShard = gasProvidedByTxInSenderShard - if gasProvidedByTxInReceiverShard > gt.economicsFee.MaxGasLimitPerTx() { + if gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerTx(epoch) { return 0, process.ErrMaxGasLimitPerOneTxInReceiverShardIsReached } - if gasInfo.gasConsumedByMiniBlockInReceiverShard+gasProvidedByTxInReceiverShard > gt.economicsFee.MaxGasLimitPerBlockForSafeCrossShard() { + if gasInfo.gasConsumedByMiniBlockInReceiverShard+gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerBlockForSafeCrossShard(epoch, overEstimationFactor) { return 0, process.ErrMaxGasLimitPerMiniBlockInReceiverShardIsReached } } else { gasProvidedByTxInSelfShard = gasProvidedByTxInReceiverShard } - if gasInfo.totalGasConsumedInSelfShard+gasProvidedByTxInSelfShard > gt.economicsFee.MaxGasLimitPerBlock(gt.shardCoordinator.SelfId()) { + if gasInfo.totalGasConsumedInSelfShard+gasProvidedByTxInSelfShard > gt.getMaxGasLimitPerBlock(epoch, overEstimationFactor) { return 0, process.ErrMaxGasLimitPerBlockInSelfShardIsReached } @@ -55,6 +62,45 @@ func (gt *gasTracker) computeGasProvided( return gasProvidedByTxInSelfShard, nil } +func (gt *gasTracker) getEpochAndOverestimationFactorForGasLimits() (epoch uint32, overestimationFactor uint64) { + epoch = gt.enableEpochsHandler.GetCurrentEpoch() + overestimationFactor = noOverestimationFactor + + // TODO: optimize this to be called once per epoch, not once per tx + isSupernovaEpochEnabled := gt.enableEpochsHandler.IsFlagEnabled(common.SupernovaFlag) + if !isSupernovaEpochEnabled { + return + } + + isSupernovaRoundEnabled := gt.enableRoundsHandler.IsFlagEnabled(common.SupernovaRoundFlag) + if !isSupernovaRoundEnabled { + // if Supernova epoch is active, but round not yet, + // use the limits from previous epoch with no overestimation factor + if epoch > 0 { + epoch = epoch - 1 + } + + return + } + + // new limits and overestimation should be enabled once the Supernova round is active + overestimationFactor = gt.economicsFee.BlockCapacityOverestimationFactor() + + return +} + +func (gt *gasTracker) getMaxGasLimitPerTx(epoch uint32) uint64 { + return gt.economicsFee.MaxGasLimitPerTxInEpoch(epoch) +} + +func (gt *gasTracker) getMaxGasLimitPerBlockForSafeCrossShard(epoch uint32, overEstimationFactor uint64) uint64 { + return gt.economicsFee.MaxGasLimitPerBlockForSafeCrossShardInEpoch(epoch) * overEstimationFactor / 100 +} + +func (gt *gasTracker) getMaxGasLimitPerBlock(epoch uint32, overEstimationFactor uint64) uint64 { + return gt.economicsFee.MaxGasLimitPerBlockInEpoch(gt.shardCoordinator.SelfId(), epoch) * overEstimationFactor / 100 +} + func (gt *gasTracker) computeGasProvidedByTx( senderShardId uint32, receiverShardId uint32, diff --git a/process/block/preprocess/gasTracker_test.go b/process/block/preprocess/gasTracker_test.go index 3943d42f027..16a23a105bc 100644 --- a/process/block/preprocess/gasTracker_test.go +++ b/process/block/preprocess/gasTracker_test.go @@ -6,15 +6,17 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/stretchr/testify/require" - + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" + "github.com/stretchr/testify/require" ) func moveBalanceGas(data []byte) uint64 { @@ -61,6 +63,7 @@ func createDefaultGasTracker( selfShardID uint32, gcr *gasConsumedResult, gasRefunded uint64, + afterSupernova bool, ) *gasTracker { shardCoordinator := &testscommon.ShardsCoordinatorMock{ CurrentShard: selfShardID, @@ -69,15 +72,21 @@ func createDefaultGasTracker( MaxGasLimitPerBlockCalled: func(shardID uint32) uint64 { return 1500000000 }, - ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { + MaxGasLimitPerBlockInEpochCalled: func(shardID uint32, epoch uint32) uint64 { + return 1500000000 + }, + ComputeGasLimitInEpochCalled: func(tx data.TransactionWithFeeHandler, epoch uint32) uint64 { return moveBalanceGas(tx.GetData()) }, - MaxGasLimitPerTxCalled: func() uint64 { + MaxGasLimitPerTxInEpochCalled: func(epoch uint32) uint64 { return 1000000 }, - MaxGasLimitPerBlockForSafeCrossShardCalled: func() uint64 { + MaxGasLimitPerBlockForSafeCrossShardInEpochCalled: func(epoch uint32) uint64 { return 1000000 }, + BlockCapacityOverestimationFactorCalled: func() uint64 { + return 200 + }, } gasHandler := &testscommon.GasHandlerStub{ @@ -93,6 +102,16 @@ func createDefaultGasTracker( shardCoordinator: shardCoordinator, economicsFee: economicsFee, gasHandler: gasHandler, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledCalled: func(flag core.EnableEpochFlag) bool { + return afterSupernova + }, + }, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{ + IsFlagEnabledCalled: func(flag common.EnableRoundFlag) bool { + return afterSupernova + }, + }, } return gt @@ -114,7 +133,7 @@ func Test_computeGasProvidedSelfSenderMoveBalanceIntra(t *testing.T) { } gasRefund := uint64(25000) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) @@ -150,7 +169,7 @@ func Test_computeGasProvidedSelfSenderSCCallIntra(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("sc invoking data") @@ -186,7 +205,7 @@ func Test_computeGasProvidedByTxSelfSenderMoveBalanceCross(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) txm, _ := marshaller.Marshal(tx) @@ -221,7 +240,7 @@ func Test_computeGasProvidedByTxSelfSenderScCallCross(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("tx invoking data") @@ -257,7 +276,7 @@ func Test_computeGasProvidedByTxGasHandlerComputeGasErrors(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("tx invoking data") @@ -300,7 +319,7 @@ func Test_computeGasProvidedByTxGasHandlerRefundGasLargerThanLimit(t *testing.T) gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("tx invoking data") @@ -346,7 +365,7 @@ func Test_computeGasProvidedWithErrorForGasConsumedForTx(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("tx invoking data") @@ -388,7 +407,7 @@ func Test_computeGasProvidedMaxGasLimitInSenderShardReached(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("tx invoking data") @@ -425,7 +444,7 @@ func Test_computeGasProvidedMaxGasLimitInReceiverShardReached(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(receiverShardID, gcr, gasRefund) + gt := createDefaultGasTracker(receiverShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("tx invoking data") @@ -445,6 +464,43 @@ func Test_computeGasProvidedMaxGasLimitInReceiverShardReached(t *testing.T) { require.Equal(t, nil, err) } +func Test_computeGasProvidedMaxGasLimitInReceiverShardReachedIntra(t *testing.T) { + t.Parallel() + + senderShardID := uint32(0) + sndAddr, _ := hex.DecodeString("addrSender" + suffixShard0) + receiverShardID := uint32(0) + rcvAddr, _ := hex.DecodeString(smartContractAddressStart + suffixShard1) + hasher := &hashingMocks.HasherMock{} + marshaller := &marshallerMock.MarshalizerMock{} + gcr := &gasConsumedResult{ + consumedSenderShard: 75000, + consumedReceiverShard: 2000000, + err: nil, + } + + gasRefund := uint64(25000) + gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) + gt := createDefaultGasTracker(receiverShardID, gcr, gasRefund, false) + tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) + tx.Data = []byte("tx invoking data") + + txm, _ := marshaller.Marshal(tx) + txHash := hasher.Compute(string(txm)) + + gci := &gasConsumedInfo{ + gasConsumedByMiniBlocksInSenderShard: gt.economicsFee.MaxGasLimitPerBlock(senderShardID) - gcr.consumedSenderShard/2, + } + _, err := gt.computeGasProvided( + senderShardID, + receiverShardID, + tx, + txHash, + gci, + ) + require.Equal(t, process.ErrMaxGasLimitPerOneTxInReceiverShardIsReached, err) +} + func Test_computeGasProvidedMaxGasLimitPerBlockReached(t *testing.T) { t.Parallel() @@ -462,7 +518,7 @@ func Test_computeGasProvidedMaxGasLimitPerBlockReached(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, false) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("tx invoking data") @@ -499,7 +555,7 @@ func Test_computeGasProvidedOK(t *testing.T) { gasRefund := uint64(25000) gasLimit := computeGasLimitFromResultAndRefund(gcr, gasRefund) - gt := createDefaultGasTracker(senderShardID, gcr, gasRefund) + gt := createDefaultGasTracker(senderShardID, gcr, gasRefund, true) tx := createDefaultTx(sndAddr, rcvAddr, gasLimit) tx.Data = []byte("tx invoking data") @@ -519,3 +575,55 @@ func Test_computeGasProvidedOK(t *testing.T) { require.Equal(t, gcr.consumedReceiverShard, gci.gasConsumedByMiniBlockInReceiverShard) require.Equal(t, gcr.consumedSenderShard, gci.totalGasConsumedInSelfShard) } + +func Test_getEpochAndOverestimationFactorForGasLimits(t *testing.T) { + t.Parallel() + + var isSupernovaEpochEnabled bool + var isSupernovaRoundEnabled bool + providedCurrentEpoch := uint32(10) + providedOverestimationFactor := uint64(200) + gt := &gasTracker{ + shardCoordinator: &testscommon.ShardsCoordinatorMock{}, + economicsFee: &economicsmocks.EconomicsHandlerMock{ + BlockCapacityOverestimationFactorCalled: func() uint64 { + return providedOverestimationFactor + }, + }, + gasHandler: &testscommon.GasHandlerStub{}, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledCalled: func(flag core.EnableEpochFlag) bool { + return isSupernovaEpochEnabled + }, + GetCurrentEpochCalled: func() uint32 { + return providedCurrentEpoch + }, + }, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{ + IsFlagEnabledCalled: func(flag common.EnableRoundFlag) bool { + return isSupernovaRoundEnabled + }, + }, + } + + // before supernova + isSupernovaEpochEnabled = false + isSupernovaRoundEnabled = false + epoch, overestimationFactor := gt.getEpochAndOverestimationFactorForGasLimits() + require.Equal(t, providedCurrentEpoch, epoch) + require.Equal(t, noOverestimationFactor, overestimationFactor) + + // supernova epoch active + isSupernovaEpochEnabled = true + isSupernovaRoundEnabled = false + epoch, overestimationFactor = gt.getEpochAndOverestimationFactorForGasLimits() + require.Equal(t, providedCurrentEpoch-1, epoch) + require.Equal(t, noOverestimationFactor, overestimationFactor) + + // supernova activation completed + isSupernovaEpochEnabled = true + isSupernovaRoundEnabled = true + epoch, overestimationFactor = gt.getEpochAndOverestimationFactorForGasLimits() + require.Equal(t, providedCurrentEpoch, epoch) + require.Equal(t, providedOverestimationFactor, overestimationFactor) +} diff --git a/process/block/preprocess/miniBlockBuilder_test.go b/process/block/preprocess/miniBlockBuilder_test.go index f03333362c3..8ad9457b16a 100644 --- a/process/block/preprocess/miniBlockBuilder_test.go +++ b/process/block/preprocess/miniBlockBuilder_test.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -496,6 +497,8 @@ func Test_MiniBlocksBuilderAccountGasForTxComputeGasProvidedWithErr(t *testing.T return 0, 0, expectedErr }, }, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, } mbb, _ := newMiniBlockBuilder(args) sender, _ := hex.DecodeString("aaaaaaaaaa" + suffixShard0) @@ -528,6 +531,8 @@ func Test_MiniBlocksBuilderAccountGasForTxComputeGasProvidedOK(t *testing.T) { return gasProvidedByTxInSenderShard, gasProvidedByTxInReceiverShard, nil }, }, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, } mbb, _ := newMiniBlockBuilder(args) sender, _ := hex.DecodeString("aaaaaaaaaa" + suffixShard0) @@ -796,6 +801,8 @@ func Test_MiniBlocksBuilderCheckAddTransactionGasAccountingError(t *testing.T) { return 0, 0, expectedErr }, }, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, } mbb, _ := newMiniBlockBuilder(args) @@ -838,13 +845,13 @@ func createDefaultMiniBlockBuilderArgs() miniBlocksBuilderArgs { }, }, economicsFee: &economicsmocks.EconomicsHandlerMock{ - MaxGasLimitPerTxCalled: func() uint64 { + MaxGasLimitPerTxInEpochCalled: func(_ uint32) uint64 { return 1000000 }, - MaxGasLimitPerBlockForSafeCrossShardCalled: func() uint64 { + MaxGasLimitPerBlockForSafeCrossShardInEpochCalled: func(_ uint32) uint64 { return 1000000 }, - MaxGasLimitPerBlockCalled: func(shardID uint32) uint64 { + MaxGasLimitPerBlockInEpochCalled: func(shardID uint32, _ uint32) uint64 { return 1000000 }, }, @@ -856,6 +863,8 @@ func createDefaultMiniBlockBuilderArgs() miniBlocksBuilderArgs { RemoveGasPenalizedCalled: func(hashes [][]byte) { }, }, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, }, accounts: &stateMock.AccountsStub{}, blockSizeComputation: &testscommon.BlockSizeComputationStub{}, diff --git a/process/block/preprocess/rewardTxPreProcessor.go b/process/block/preprocess/rewardTxPreProcessor.go index 5a34151b038..8eb820cfc64 100644 --- a/process/block/preprocess/rewardTxPreProcessor.go +++ b/process/block/preprocess/rewardTxPreProcessor.go @@ -46,9 +46,11 @@ func NewRewardTxPreprocessor(args RewardsPreProcessorArgs) (*rewardTxPreprocesso hasher: args.Hasher, marshalizer: args.Marshalizer, gasTracker: gasTracker{ - shardCoordinator: args.ShardCoordinator, - gasHandler: args.GasHandler, - economicsFee: args.EconomicsFee, + shardCoordinator: args.ShardCoordinator, + gasHandler: args.GasHandler, + economicsFee: args.EconomicsFee, + enableEpochsHandler: args.EnableEpochsHandler, + enableRoundsHandler: args.EnableRoundsHandler, }, blockSizeComputation: args.BlockSizeComputation, balanceComputation: args.BalanceComputation, diff --git a/process/block/preprocess/smartContractResults.go b/process/block/preprocess/smartContractResults.go index 39c943e37d9..bdccd3a047b 100644 --- a/process/block/preprocess/smartContractResults.go +++ b/process/block/preprocess/smartContractResults.go @@ -60,9 +60,11 @@ func NewSmartContractResultPreprocessor(args SmartContractResultsArgs) (*smartCo hasher: args.Hasher, marshalizer: args.Marshalizer, gasTracker: gasTracker{ - shardCoordinator: args.ShardCoordinator, - gasHandler: args.GasHandler, - economicsFee: args.EconomicsFee, + shardCoordinator: args.ShardCoordinator, + gasHandler: args.GasHandler, + economicsFee: args.EconomicsFee, + enableEpochsHandler: args.EnableEpochsHandler, + enableRoundsHandler: args.EnableRoundsHandler, }, blockSizeComputation: args.BlockSizeComputation, balanceComputation: args.BalanceComputation, diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index a949c3bd2d4..4bb8a8b9fd7 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -13,18 +13,16 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" - logger "github.com/multiversx/mx-chain-logger-go" - - "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/txcache" + logger "github.com/multiversx/mx-chain-logger-go" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/helpers" + "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" ) @@ -123,9 +121,11 @@ func NewTransactionPreprocessor( hasher: args.Hasher, marshalizer: args.Marshalizer, gasTracker: gasTracker{ - shardCoordinator: args.ShardCoordinator, - gasHandler: args.GasHandler, - economicsFee: args.EconomicsFee, + shardCoordinator: args.ShardCoordinator, + gasHandler: args.GasHandler, + economicsFee: args.EconomicsFee, + enableEpochsHandler: args.EnableEpochsHandler, + enableRoundsHandler: args.EnableRoundsHandler, }, blockSizeComputation: args.BlockSizeComputation, balanceComputation: args.BalanceComputation, @@ -133,9 +133,9 @@ func NewTransactionPreprocessor( accountsProposal: args.AccountsProposal, pubkeyConverter: args.PubkeyConverter, enableEpochsHandler: args.EnableEpochsHandler, + enableRoundsHandler: args.EnableRoundsHandler, processedMiniBlocksTracker: args.ProcessedMiniBlocksTracker, txExecutionOrderHandler: args.TxExecutionOrderHandler, - enableRoundsHandler: args.EnableRoundsHandler, } txs := &transactions{ diff --git a/process/block/preprocess/transactionsV2_test.go b/process/block/preprocess/transactionsV2_test.go index bdd1bb6e730..7a63c8f9e4b 100644 --- a/process/block/preprocess/transactionsV2_test.go +++ b/process/block/preprocess/transactionsV2_test.go @@ -31,13 +31,13 @@ func createTransactionPreprocessor() *transactions { MaxGasLimitPerMiniBlockForSafeCrossShardCalled: func() uint64 { return MaxGasLimitPerBlock }, - MaxGasLimitPerBlockForSafeCrossShardCalled: func() uint64 { + MaxGasLimitPerBlockForSafeCrossShardInEpochCalled: func(_ uint32) uint64 { return MaxGasLimitPerBlock }, - MaxGasLimitPerBlockCalled: func(_ uint32) uint64 { + MaxGasLimitPerBlockInEpochCalled: func(_ uint32, _ uint32) uint64 { return MaxGasLimitPerBlock }, - MaxGasLimitPerTxCalled: func() uint64 { + MaxGasLimitPerTxInEpochCalled: func(_ uint32) uint64 { return MaxGasLimitPerBlock }, } diff --git a/process/block/preprocess/transactions_test.go b/process/block/preprocess/transactions_test.go index 23f4301431f..644332b2f47 100644 --- a/process/block/preprocess/transactions_test.go +++ b/process/block/preprocess/transactions_test.go @@ -21,13 +21,12 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing/blake2b" "github.com/multiversx/mx-chain-core-go/hashing/sha256" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/txcache" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/txcache" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -76,6 +75,15 @@ func feeHandlerMock() *economicsmocks.EconomicsHandlerMock { MaxGasLimitPerTxCalled: func() uint64 { return MaxGasLimitPerBlock }, + MaxGasLimitPerTxInEpochCalled: func(_ uint32) uint64 { + return MaxGasLimitPerBlock + }, + MaxGasLimitPerBlockForSafeCrossShardInEpochCalled: func(_ uint32) uint64 { + return MaxGasLimitPerBlock + }, + MaxGasLimitPerBlockInEpochCalled: func(shardID uint32, _ uint32) uint64 { + return MaxGasLimitPerBlock + }, } } @@ -440,7 +448,7 @@ func TestTxsPreprocessor_NewTransactionPreprocessorNilEnableRoundsHandler(t *tes txs, err := NewTransactionPreprocessor(args) assert.Nil(t, txs) - assert.Equal(t, process.ErrNilEnableRoundsHandler, err) + assert.True(t, errors.Is(err, process.ErrNilEnableRoundsHandler)) } func TestTxsPreprocessor_NewTransactionPreprocessorNilTxTypeHandler(t *testing.T) { @@ -1754,7 +1762,7 @@ func TestTransactionsPreprocessor_ComputeGasProvidedShouldWork(t *testing.T) { txGasLimitInReceiver := maxGasLimit args := createDefaultTransactionsProcessorArgs() args.EconomicsFee = &economicsmocks.EconomicsHandlerMock{ - MaxGasLimitPerBlockCalled: func(_ uint32) uint64 { + MaxGasLimitPerBlockInEpochCalled: func(_ uint32, _ uint32) uint64 { return maxGasLimit }, } @@ -1877,9 +1885,11 @@ func TestTransactionsPreProcessor_preFilterTransactionsNoBandwidth(t *testing.T) txsProcessor := &transactions{ basePreProcess: &basePreProcess{ gasTracker: gasTracker{ - shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - economicsFee: economicsFee, - gasHandler: gasHandler, + shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), + economicsFee: economicsFee, + gasHandler: gasHandler, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, }, }, } @@ -1926,9 +1936,11 @@ func TestTransactionsPreProcessor_preFilterTransactionsLimitedBandwidthMultipleT txsProcessor := &transactions{ basePreProcess: &basePreProcess{ gasTracker: gasTracker{ - shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - economicsFee: economicsFee, - gasHandler: gasHandler, + shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), + economicsFee: economicsFee, + gasHandler: gasHandler, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, }, }, } @@ -1987,9 +1999,11 @@ func TestTransactionsPreProcessor_preFilterTransactionsLimitedBandwidthMultipleT txsProcessor := &transactions{ basePreProcess: &basePreProcess{ gasTracker: gasTracker{ - shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - economicsFee: economicsFee, - gasHandler: gasHandler, + shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), + economicsFee: economicsFee, + gasHandler: gasHandler, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, }, }, } @@ -2056,9 +2070,11 @@ func TestTransactionsPreProcessor_preFilterTransactionsHighBandwidth(t *testing. txsProcessor := &transactions{ basePreProcess: &basePreProcess{ gasTracker: gasTracker{ - shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - economicsFee: economicsFee, - gasHandler: gasHandler, + shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), + economicsFee: economicsFee, + gasHandler: gasHandler, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, }, }, } @@ -2117,9 +2133,11 @@ func TestTransactionsPreProcessor_getRemainingGasPerBlock(t *testing.T) { txsProcessor := &transactions{ basePreProcess: &basePreProcess{ gasTracker: gasTracker{ - shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - economicsFee: economicsFee, - gasHandler: gasHandler, + shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), + economicsFee: economicsFee, + gasHandler: gasHandler, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, }, enableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), }, @@ -2147,9 +2165,11 @@ func TestTransactionsPreProcessor_getRemainingGasPerBlockAsScheduled(t *testing. txsProcessor := &transactions{ basePreProcess: &basePreProcess{ gasTracker: gasTracker{ - shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), - economicsFee: economicsFee, - gasHandler: gasHandler, + shardCoordinator: mock.NewMultiShardsCoordinatorMock(3), + economicsFee: economicsFee, + gasHandler: gasHandler, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, }, }, } @@ -2356,7 +2376,9 @@ func TestTransactions_ComputeCacheIdentifier(t *testing.T) { txs := &transactions{ basePreProcess: &basePreProcess{ gasTracker: gasTracker{ - shardCoordinator: coordinator, + shardCoordinator: coordinator, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, }, enableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ScheduledMiniBlocksFlag), }, diff --git a/process/coordinator/process_test.go b/process/coordinator/process_test.go index 44c6e436439..eacc4be5f13 100644 --- a/process/coordinator/process_test.go +++ b/process/coordinator/process_test.go @@ -21,12 +21,11 @@ import ( "github.com/multiversx/mx-chain-core-go/data/scheduled" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -86,6 +85,15 @@ func FeeHandlerMock() *economicsmocks.EconomicsHandlerMock { MaxGasLimitPerTxCalled: func() uint64 { return MaxGasLimitPerBlock }, + MaxGasLimitPerTxInEpochCalled: func(_ uint32) uint64 { + return MaxGasLimitPerBlock + }, + MaxGasLimitPerBlockForSafeCrossShardInEpochCalled: func(_ uint32) uint64 { + return MaxGasLimitPerBlock + }, + MaxGasLimitPerBlockInEpochCalled: func(shardID uint32, _ uint32) uint64 { + return MaxGasLimitPerBlock + }, } } diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index af40be19d34..f9f3a5e13c9 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -233,6 +233,11 @@ func (ed *economicsData) MaxGasPriceSetGuardian() uint64 { return ed.maxGasPriceSetGuardian } +// BlockCapacityOverestimationFactor returns the block capacity overestimation factor +func (ed *economicsData) BlockCapacityOverestimationFactor() uint64 { + return ed.blockCapacityOverestimationFactor +} + // GasPerDataByte returns the gas required for a economicsData byte func (ed *economicsData) GasPerDataByte() uint64 { return ed.gasPerDataByte diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index 0e7597e22a9..378367f052f 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -1432,6 +1432,16 @@ func TestEconomicsData_MaxGasPriceSetGuardian(t *testing.T) { require.Equal(t, expectedMaxGasPriceSetGuardian, economicData.MaxGasPriceSetGuardian()) } +func TestEconomicsData_BlockCapacityOverestimationFactor(t *testing.T) { + t.Parallel() + + args := createArgsForEconomicsDataRealFees() + args.Economics.FeeSettings.BlockCapacityOverestimationFactor = 100 + economicData, _ := economics.NewEconomicsData(args) + + require.Equal(t, uint64(100), economicData.BlockCapacityOverestimationFactor()) +} + func TestEconomicsData_SetStatusHandler(t *testing.T) { t.Parallel() diff --git a/process/economics/gasConfigHandler.go b/process/economics/gasConfigHandler.go index bea38e07865..23ade15d78d 100644 --- a/process/economics/gasConfigHandler.go +++ b/process/economics/gasConfigHandler.go @@ -29,14 +29,23 @@ type gasConfig struct { maxGasHigherFactorAccepted uint64 } +type convertedGenericEconomicValues struct { + minGasPrice uint64 + gasPerDataByte uint64 + genesisTotalSupply *big.Int + maxGasPriceSetGuardian uint64 + blockCapacityOverestimationFactor uint64 +} + type gasConfigHandler struct { - statusHandler core.AppStatusHandler - gasLimitSettings []*gasConfig - minGasPrice uint64 - gasPerDataByte uint64 - genesisTotalSupply *big.Int - maxGasPriceSetGuardian uint64 - mut sync.RWMutex + statusHandler core.AppStatusHandler + gasLimitSettings []*gasConfig + minGasPrice uint64 + gasPerDataByte uint64 + genesisTotalSupply *big.Int + maxGasPriceSetGuardian uint64 + blockCapacityOverestimationFactor uint64 + mut sync.RWMutex } // newGasConfigHandler returns a new instance of gasConfigHandler @@ -50,18 +59,19 @@ func newGasConfigHandler(economics *config.EconomicsConfig) (*gasConfigHandler, return gasConfigSlice[i].gasLimitSettingEpoch < gasConfigSlice[j].gasLimitSettingEpoch }) - minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, err := convertGenericValues(economics) + result, err := convertGenericValues(economics) if err != nil { return nil, err } return &gasConfigHandler{ - statusHandler: statusHandler.NewNilStatusHandler(), - gasLimitSettings: gasConfigSlice, - minGasPrice: minGasPrice, - gasPerDataByte: gasPerDataByte, - genesisTotalSupply: genesisTotalSupply, - maxGasPriceSetGuardian: maxGasPriceSetGuardian, + statusHandler: statusHandler.NewNilStatusHandler(), + gasLimitSettings: gasConfigSlice, + minGasPrice: result.minGasPrice, + gasPerDataByte: result.gasPerDataByte, + genesisTotalSupply: result.genesisTotalSupply, + maxGasPriceSetGuardian: result.maxGasPriceSetGuardian, + blockCapacityOverestimationFactor: result.blockCapacityOverestimationFactor, }, nil } @@ -259,29 +269,37 @@ func checkAndParseGasLimitSettings(gasLimitSetting config.GasLimitSetting) (*gas return gc, nil } -func convertGenericValues(economics *config.EconomicsConfig) (uint64, uint64, *big.Int, uint64, error) { +func convertGenericValues(economics *config.EconomicsConfig) (*convertedGenericEconomicValues, error) { conversionBase := 10 bitConversionSize := 64 minGasPrice, err := strconv.ParseUint(economics.FeeSettings.MinGasPrice, conversionBase, bitConversionSize) if err != nil { - return 0, 0, nil, 0, process.ErrInvalidMinimumGasPrice + return nil, process.ErrInvalidMinimumGasPrice } gasPerDataByte, err := strconv.ParseUint(economics.FeeSettings.GasPerDataByte, conversionBase, bitConversionSize) if err != nil { - return 0, 0, nil, 0, process.ErrInvalidGasPerDataByte + return nil, process.ErrInvalidGasPerDataByte } genesisTotalSupply, ok := big.NewInt(0).SetString(economics.GlobalSettings.GenesisTotalSupply, conversionBase) if !ok { - return 0, 0, nil, 0, process.ErrInvalidGenesisTotalSupply + return nil, process.ErrInvalidGenesisTotalSupply } maxGasPriceSetGuardian, err := strconv.ParseUint(economics.FeeSettings.MaxGasPriceSetGuardian, conversionBase, bitConversionSize) if err != nil { - return 0, 0, nil, 0, process.ErrInvalidMaxGasPriceSetGuardian + return nil, process.ErrInvalidMaxGasPriceSetGuardian } - return minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, nil + blockCapacityOverestimationFactor := economics.FeeSettings.BlockCapacityOverestimationFactor + + return &convertedGenericEconomicValues{ + minGasPrice: minGasPrice, + gasPerDataByte: gasPerDataByte, + genesisTotalSupply: genesisTotalSupply, + maxGasPriceSetGuardian: maxGasPriceSetGuardian, + blockCapacityOverestimationFactor: blockCapacityOverestimationFactor, + }, nil } diff --git a/process/errors.go b/process/errors.go index cbd4b555e01..90062582649 100644 --- a/process/errors.go +++ b/process/errors.go @@ -546,6 +546,9 @@ var ErrInvalidExtraGasLimitGuardedTx = errors.New("invalid extra gas limit for g // ErrInvalidMaxGasPriceSetGuardian signals that an invalid maximum gas price has been provided in the config file var ErrInvalidMaxGasPriceSetGuardian = errors.New("invalid maximum gas price for set guardian") +// ErrInvalidBlockCapacityOverestimationFactor signals that an invalid block capacity overestimation factor has been provided in the config file +var ErrInvalidBlockCapacityOverestimationFactor = errors.New("invalid block capacity overestimation factor") + // ErrInvalidMaxGasHigherFactorAccepted signals that an invalid gas factor has been provided in the config file var ErrInvalidMaxGasHigherFactorAccepted = errors.New("invalid gas higher factor accepted") diff --git a/process/factory/metachain/preProcessorsContainerFactory.go b/process/factory/metachain/preProcessorsContainerFactory.go index 89fdae0b75e..9af5f33314e 100644 --- a/process/factory/metachain/preProcessorsContainerFactory.go +++ b/process/factory/metachain/preProcessorsContainerFactory.go @@ -8,7 +8,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" diff --git a/process/factory/metachain/preProcessorsContainerFactory_test.go b/process/factory/metachain/preProcessorsContainerFactory_test.go index cd600d2eb53..f68ee3a26db 100644 --- a/process/factory/metachain/preProcessorsContainerFactory_test.go +++ b/process/factory/metachain/preProcessorsContainerFactory_test.go @@ -3,8 +3,6 @@ package metachain_test import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -18,6 +16,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" + "github.com/stretchr/testify/assert" ) func createMockTxCacheSelectionConfig() config.TxCacheSelectionConfig { diff --git a/process/factory/shard/preProcessorsContainerFactory.go b/process/factory/shard/preProcessorsContainerFactory.go index 899fcb242ce..d9b3825eeed 100644 --- a/process/factory/shard/preProcessorsContainerFactory.go +++ b/process/factory/shard/preProcessorsContainerFactory.go @@ -8,7 +8,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" diff --git a/process/factory/shard/preProcessorsContainerFactory_test.go b/process/factory/shard/preProcessorsContainerFactory_test.go index 541f73485d3..4eef59ef7e2 100644 --- a/process/factory/shard/preProcessorsContainerFactory_test.go +++ b/process/factory/shard/preProcessorsContainerFactory_test.go @@ -3,8 +3,6 @@ package shard import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -17,6 +15,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" + "github.com/stretchr/testify/assert" ) func createMockPubkeyConverter() *testscommon.PubkeyConverterMock { diff --git a/process/interface.go b/process/interface.go index 10aa9275b3d..375c18d5ed7 100644 --- a/process/interface.go +++ b/process/interface.go @@ -766,10 +766,13 @@ type feeHandler interface { DeveloperPercentage() float64 GasPerDataByte() uint64 MaxGasLimitPerBlock(shardID uint32) uint64 + MaxGasLimitPerBlockInEpoch(shardID uint32, epoch uint32) uint64 MaxGasLimitPerMiniBlock(shardID uint32) uint64 MaxGasLimitPerBlockForSafeCrossShard() uint64 + MaxGasLimitPerBlockForSafeCrossShardInEpoch(epoch uint32) uint64 MaxGasLimitPerMiniBlockForSafeCrossShard() uint64 MaxGasLimitPerTx() uint64 + MaxGasLimitPerTxInEpoch(epoch uint32) uint64 ComputeGasLimit(tx data.TransactionWithFeeHandler) uint64 ComputeMoveBalanceFee(tx data.TransactionWithFeeHandler) *big.Int ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int @@ -777,6 +780,7 @@ type feeHandler interface { ComputeFeeForProcessing(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int MinGasPrice() uint64 MaxGasPriceSetGuardian() uint64 + BlockCapacityOverestimationFactor() uint64 GasPriceModifier() float64 MinGasLimit() uint64 ExtraGasLimitGuardedTx() uint64 diff --git a/testscommon/economicsmocks/economicsHandlerMock.go b/testscommon/economicsmocks/economicsHandlerMock.go index 046ae3f12e1..c8c445c605a 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -18,10 +18,13 @@ type EconomicsHandlerMock struct { SetMinGasPriceCalled func(minGasPrice uint64) SetMinGasLimitCalled func(minGasLimit uint64) MaxGasLimitPerBlockCalled func(shardID uint32) uint64 + MaxGasLimitPerBlockInEpochCalled func(shardID uint32, epoch uint32) uint64 MaxGasLimitPerMiniBlockCalled func(shardID uint32) uint64 MaxGasLimitPerBlockForSafeCrossShardCalled func() uint64 + MaxGasLimitPerBlockForSafeCrossShardInEpochCalled func(epoch uint32) uint64 MaxGasLimitPerMiniBlockForSafeCrossShardCalled func() uint64 MaxGasLimitPerTxCalled func() uint64 + MaxGasLimitPerTxInEpochCalled func(epoch uint32) uint64 ComputeGasLimitCalled func(tx data.TransactionWithFeeHandler) uint64 ComputeFeeCalled func(tx data.TransactionWithFeeHandler) *big.Int CheckValidityTxValuesCalled func(tx data.TransactionWithFeeHandler) error @@ -51,6 +54,7 @@ type EconomicsHandlerMock struct { ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int GenesisTotalSupplyCalled func() *big.Int MaxGasPriceSetGuardianCalled func() uint64 + BlockCapacityOverestimationFactorCalled func() uint64 LeaderPercentageInEpochCalled func(epoch uint32) float64 DeveloperPercentageInEpochCalled func(epoch uint32) float64 ProtocolSustainabilityPercentageInEpochCalled func(epoch uint32) float64 @@ -118,6 +122,14 @@ func (ehm *EconomicsHandlerMock) MaxGasPriceSetGuardian() uint64 { return 0 } +// BlockCapacityOverestimationFactor - +func (ehm *EconomicsHandlerMock) BlockCapacityOverestimationFactor() uint64 { + if ehm.BlockCapacityOverestimationFactorCalled != nil { + return ehm.BlockCapacityOverestimationFactorCalled() + } + return 0 +} + // GasPerDataByte - func (ehm *EconomicsHandlerMock) GasPerDataByte() uint64 { return 0 @@ -162,6 +174,14 @@ func (ehm *EconomicsHandlerMock) MaxGasLimitPerBlock(shardID uint32) uint64 { return 0 } +// MaxGasLimitPerBlockInEpoch - +func (ehm *EconomicsHandlerMock) MaxGasLimitPerBlockInEpoch(shardID uint32, epoch uint32) uint64 { + if ehm.MaxGasLimitPerBlockInEpochCalled != nil { + return ehm.MaxGasLimitPerBlockInEpochCalled(shardID, epoch) + } + return 0 +} + // MaxGasLimitPerMiniBlock - func (ehm *EconomicsHandlerMock) MaxGasLimitPerMiniBlock(shardID uint32) uint64 { if ehm.MaxGasLimitPerMiniBlockCalled != nil { @@ -178,6 +198,14 @@ func (ehm *EconomicsHandlerMock) MaxGasLimitPerBlockForSafeCrossShard() uint64 { return 0 } +// MaxGasLimitPerBlockForSafeCrossShardInEpoch - +func (ehm *EconomicsHandlerMock) MaxGasLimitPerBlockForSafeCrossShardInEpoch(epoch uint32) uint64 { + if ehm.MaxGasLimitPerBlockForSafeCrossShardInEpochCalled != nil { + return ehm.MaxGasLimitPerBlockForSafeCrossShardInEpochCalled(epoch) + } + return 0 +} + // MaxGasLimitPerMiniBlockForSafeCrossShard - func (ehm *EconomicsHandlerMock) MaxGasLimitPerMiniBlockForSafeCrossShard() uint64 { if ehm.MaxGasLimitPerMiniBlockForSafeCrossShardCalled != nil { @@ -194,6 +222,14 @@ func (ehm *EconomicsHandlerMock) MaxGasLimitPerTx() uint64 { return 0 } +// MaxGasLimitPerTxInEpoch - +func (ehm *EconomicsHandlerMock) MaxGasLimitPerTxInEpoch(epoch uint32) uint64 { + if ehm.MaxGasLimitPerTxInEpochCalled != nil { + return ehm.MaxGasLimitPerTxInEpochCalled(epoch) + } + return 0 +} + // ComputeGasLimit - func (ehm *EconomicsHandlerMock) ComputeGasLimit(tx data.TransactionWithFeeHandler) uint64 { if ehm.ComputeGasLimitCalled != nil {