From 60d1e057e45003e02320b0caf97059cfab180888 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 26 Sep 2025 18:31:46 +0300 Subject: [PATCH 1/8] adapted the gas tracker implementation to follow the new limits after supernova activation --- factory/processing/blockProcessorCreator.go | 2 + genesis/process/disabled/disabled_test.go | 4 + genesis/process/disabled/feeHandler.go | 20 +++++ genesis/process/metaGenesisBlockCreator.go | 1 + genesis/process/shardGenesisBlockCreator.go | 1 + integrationTests/testProcessorNode.go | 2 + process/block/preprocess/gasTracker.go | 47 ++++++++-- process/block/preprocess/gasTracker_test.go | 86 +++++++++++++++---- .../block/preprocess/miniBlockBuilder_test.go | 9 ++ .../block/preprocess/rewardTxPreProcessor.go | 8 +- .../block/preprocess/smartContractResults.go | 12 ++- .../preprocess/smartContractResults_test.go | 69 +++++++++++++++ process/block/preprocess/transactions.go | 12 ++- .../block/preprocess/transactionsV2_test.go | 1 + process/block/preprocess/transactions_test.go | 66 +++++++++----- process/block/shardblock_test.go | 6 ++ process/coordinator/process_test.go | 9 ++ process/economics/economicsData.go | 5 ++ process/economics/economicsData_test.go | 9 ++ process/economics/gasConfigHandler.go | 49 ++++++----- process/errors.go | 3 + .../preProcessorsContainerFactory.go | 8 ++ .../preProcessorsContainerFactory_test.go | 53 ++++++++++++ .../shard/preProcessorsContainerFactory.go | 8 ++ .../preProcessorsContainerFactory_test.go | 60 +++++++++++++ process/interface.go | 4 + .../economicsmocks/economicsHandlerMock.go | 36 ++++++++ 27 files changed, 518 insertions(+), 72 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 85e4b975098..0dfc39e6976 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -348,6 +348,7 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( blockSizeComputationHandler, balanceComputationHandler, pcf.coreData.EnableEpochsHandler(), + pcf.coreData.EnableRoundsHandler(), txTypeHandler, scheduledTxsExecutionHandler, processedMiniBlocksTracker, @@ -658,6 +659,7 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor( blockSizeComputationHandler, balanceComputationHandler, pcf.coreData.EnableEpochsHandler(), + pcf.coreData.EnableRoundsHandler(), txTypeHandler, scheduledTxsExecutionHandler, processedMiniBlocksTracker, diff --git a/genesis/process/disabled/disabled_test.go b/genesis/process/disabled/disabled_test.go index 487a17c5af3..ca641600a39 100644 --- a/genesis/process/disabled/disabled_test.go +++ b/genesis/process/disabled/disabled_test.go @@ -108,6 +108,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 6940b94cf49..b7fcfdea9dc 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -511,6 +511,7 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc disabledBlockSizeComputationHandler, disabledBalanceComputationHandler, enableEpochsHandler, + enableRoundsHandler, txTypeHandler, disabledScheduledTxsExecutionHandler, disabledProcessedMiniBlocksTracker, diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 9a168ba6ce7..638f003eb51 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -599,6 +599,7 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo disabledBlockSizeComputationHandler, disabledBalanceComputationHandler, enableEpochsHandler, + enableRoundsHandler, txTypeHandler, disabledScheduledTxsExecutionHandler, disabledProcessedMiniBlocksTracker, diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index b5e993df557..eec4e69c04e 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1870,6 +1870,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u TestBlockSizeComputationHandler, TestBalanceComputationHandler, tpn.EnableEpochsHandler, + tpn.EnableRoundsHandler, txTypeHandler, scheduledTxsExecutionHandler, processedMiniBlocksTracker, @@ -2152,6 +2153,7 @@ func (tpn *TestProcessorNode) initMetaInnerProcessors(gasMap map[string]map[stri TestBlockSizeComputationHandler, TestBalanceComputationHandler, tpn.EnableEpochsHandler, + tpn.EnableRoundsHandler, txTypeHandler, scheduledTxsExecutionHandler, processedMiniBlocksTracker, diff --git a/process/block/preprocess/gasTracker.go b/process/block/preprocess/gasTracker.go index 6cebea3426d..ccf0f9a361d 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( @@ -33,18 +38,18 @@ func (gt *gasTracker) computeGasProvided( if gt.shardCoordinator.SelfId() == senderShardId { gasProvidedByTxInSelfShard = gasProvidedByTxInSenderShard - if gasProvidedByTxInReceiverShard > gt.economicsFee.MaxGasLimitPerTx() { + if gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerTx() { return 0, process.ErrMaxGasLimitPerOneTxInReceiverShardIsReached } - if gasInfo.gasConsumedByMiniBlockInReceiverShard+gasProvidedByTxInReceiverShard > gt.economicsFee.MaxGasLimitPerBlockForSafeCrossShard() { + if gasInfo.gasConsumedByMiniBlockInReceiverShard+gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerBlockForSafeCrossShard() { return 0, process.ErrMaxGasLimitPerMiniBlockInReceiverShardIsReached } } else { gasProvidedByTxInSelfShard = gasProvidedByTxInReceiverShard } - if gasInfo.totalGasConsumedInSelfShard+gasProvidedByTxInSelfShard > gt.economicsFee.MaxGasLimitPerBlock(gt.shardCoordinator.SelfId()) { + if gasInfo.totalGasConsumedInSelfShard+gasProvidedByTxInSelfShard > gt.getMaxGasLimitPerBlock() { return 0, process.ErrMaxGasLimitPerBlockInSelfShardIsReached } @@ -55,6 +60,36 @@ func (gt *gasTracker) computeGasProvided( return gasProvidedByTxInSelfShard, nil } +func (gt *gasTracker) getEpochAndOverestimationFactorForGasLimits() (epoch uint32, overestimationFactor uint64) { + epoch = gt.enableEpochsHandler.GetCurrentEpoch() + overestimationFactor = noOverestimationFactor + isSupernovaRoundEnabled := gt.enableRoundsHandler.IsFlagEnabled(common.SupernovaRoundFlag) + if !isSupernovaRoundEnabled { + return + } + + // new limits and overestimation should be enabled once the Supernova round is active + epoch = epoch - 1 + overestimationFactor = gt.economicsFee.BlockCapacityOverestimationFactor() + + return +} + +func (gt *gasTracker) getMaxGasLimitPerTx() uint64 { + epoch, _ := gt.getEpochAndOverestimationFactorForGasLimits() + return gt.economicsFee.MaxGasLimitPerTxInEpoch(epoch) +} + +func (gt *gasTracker) getMaxGasLimitPerBlockForSafeCrossShard() uint64 { + epoch, overEstimationFactor := gt.getEpochAndOverestimationFactorForGasLimits() + return gt.economicsFee.MaxGasLimitPerBlockForSafeCrossShardInEpoch(epoch) * overEstimationFactor / 100 +} + +func (gt *gasTracker) getMaxGasLimitPerBlock() uint64 { + epoch, overEstimationFactor := gt.getEpochAndOverestimationFactorForGasLimits() + 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 d02d28ce5a4..6196785472b 100644 --- a/process/block/preprocess/gasTracker_test.go +++ b/process/block/preprocess/gasTracker_test.go @@ -8,9 +8,11 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/transaction" + "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" @@ -60,6 +62,7 @@ func createDefaultGasTracker( selfShardID uint32, gcr *gasConsumedResult, gasRefunded uint64, + afterSupernova bool, ) *gasTracker { shardCoordinator := &testscommon.ShardsCoordinatorMock{ CurrentShard: selfShardID, @@ -68,15 +71,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{ @@ -89,9 +98,15 @@ func createDefaultGasTracker( } gt := &gasTracker{ - shardCoordinator: shardCoordinator, - economicsFee: economicsFee, - gasHandler: gasHandler, + shardCoordinator: shardCoordinator, + economicsFee: economicsFee, + gasHandler: gasHandler, + enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + enableRoundsHandler: &testscommon.EnableRoundsHandlerStub{ + IsFlagEnabledCalled: func(flag common.EnableRoundFlag) bool { + return afterSupernova + }, + }, } return gt @@ -113,7 +128,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) @@ -149,7 +164,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") @@ -185,7 +200,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) @@ -220,7 +235,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") @@ -256,7 +271,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") @@ -299,7 +314,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") @@ -345,7 +360,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") @@ -387,7 +402,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") @@ -424,7 +439,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") @@ -444,6 +459,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() @@ -461,7 +513,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") @@ -498,7 +550,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") diff --git a/process/block/preprocess/miniBlockBuilder_test.go b/process/block/preprocess/miniBlockBuilder_test.go index f03333362c3..92354c2b951 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) @@ -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 e695d51e498..ee419ff896f 100644 --- a/process/block/preprocess/rewardTxPreProcessor.go +++ b/process/block/preprocess/rewardTxPreProcessor.go @@ -97,9 +97,11 @@ func NewRewardTxPreprocessor( hasher: hasher, marshalizer: marshalizer, gasTracker: gasTracker{ - shardCoordinator: shardCoordinator, - gasHandler: gasHandler, - economicsFee: nil, + shardCoordinator: shardCoordinator, + gasHandler: gasHandler, + economicsFee: nil, + enableEpochsHandler: nil, + enableRoundsHandler: nil, }, blockSizeComputation: blockSizeComputation, balanceComputation: balanceComputation, diff --git a/process/block/preprocess/smartContractResults.go b/process/block/preprocess/smartContractResults.go index 3ac910a1834..e32c3b8fd90 100644 --- a/process/block/preprocess/smartContractResults.go +++ b/process/block/preprocess/smartContractResults.go @@ -49,6 +49,7 @@ func NewSmartContractResultPreprocessor( blockSizeComputation BlockSizeComputationHandler, balanceComputation BalanceComputationHandler, enableEpochsHandler common.EnableEpochsHandler, + enableRoundsHandler common.EnableRoundsHandler, processedMiniBlocksTracker process.ProcessedMiniBlocksTracker, txExecutionOrderHandler common.TxExecutionOrderHandler, ) (*smartContractResults, error) { @@ -95,6 +96,9 @@ func NewSmartContractResultPreprocessor( if check.IfNil(enableEpochsHandler) { return nil, process.ErrNilEnableEpochsHandler } + if check.IfNil(enableRoundsHandler) { + return nil, process.ErrNilEnableRoundsHandler + } if check.IfNil(processedMiniBlocksTracker) { return nil, process.ErrNilProcessedMiniBlocksTracker } @@ -114,9 +118,11 @@ func NewSmartContractResultPreprocessor( hasher: hasher, marshalizer: marshalizer, gasTracker: gasTracker{ - shardCoordinator: shardCoordinator, - gasHandler: gasHandler, - economicsFee: economicsFee, + shardCoordinator: shardCoordinator, + gasHandler: gasHandler, + economicsFee: economicsFee, + enableEpochsHandler: enableEpochsHandler, + enableRoundsHandler: enableRoundsHandler, }, blockSizeComputation: blockSizeComputation, balanceComputation: balanceComputation, diff --git a/process/block/preprocess/smartContractResults_test.go b/process/block/preprocess/smartContractResults_test.go index 37a03255c66..11e51d7e35b 100644 --- a/process/block/preprocess/smartContractResults_test.go +++ b/process/block/preprocess/smartContractResults_test.go @@ -77,6 +77,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilPool(t *testing.T &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -105,6 +106,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilStore(t *testing. &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -133,6 +135,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilHasher(t *testing &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -161,6 +164,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilMarsalizer(t *tes &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -189,6 +193,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilTxProce(t *testin &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -217,6 +222,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilShardCoord(t *tes &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -245,6 +251,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilAccounts(t *testi &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -272,6 +279,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilRequestFunc(t *te &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -300,6 +308,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilGasHandler(t *tes &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -328,6 +337,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorShouldWork(t *testin &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -356,6 +366,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilPubkeyConverter(t &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -384,6 +395,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilBlockSizeComputat nil, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -412,6 +424,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilBalanceComputatio &testscommon.BlockSizeComputationStub{}, nil, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -440,6 +453,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilEnableEpochsHandl &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, nil, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -448,6 +462,35 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilEnableEpochsHandl assert.Equal(t, process.ErrNilEnableEpochsHandler, err) } +func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilEnableRoundsHandler(t *testing.T) { + t.Parallel() + + tdp := initDataPool() + requestTransaction := func(shardID uint32, txHashes [][]byte) {} + txs, err := NewSmartContractResultPreprocessor( + tdp.UnsignedTransactions(), + &storageStubs.ChainStorerStub{}, + &hashingMocks.HasherMock{}, + &mock.MarshalizerMock{}, + &testscommon.TxProcessorMock{}, + mock.NewMultiShardsCoordinatorMock(3), + &stateMock.AccountsStub{}, + requestTransaction, + &mock.GasHandlerMock{}, + feeHandlerMock(), + createMockPubkeyConverter(), + &testscommon.BlockSizeComputationStub{}, + &testscommon.BalanceComputationStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + nil, + &testscommon.ProcessedMiniBlocksTrackerStub{}, + &commonTests.TxExecutionOrderHandlerStub{}, + ) + + assert.Nil(t, txs) + assert.Equal(t, process.ErrNilEnableRoundsHandler, err) +} + func TestScrsPreprocessor_NewSmartContractResultPreprocessorInvalidEnableEpochsHandler(t *testing.T) { t.Parallel() @@ -468,6 +511,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorInvalidEnableEpochsH &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStubWithNoFlagsDefined(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -496,6 +540,7 @@ func TestScrsPreprocessor_NewSmartContractResultPreprocessorNilProcessedMiniBloc &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, nil, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -524,6 +569,7 @@ func TestNewSmartContractResult_NilTxExecutionOrderHandlerShouldErr(t *testing.T &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, nil, ) @@ -552,6 +598,7 @@ func TestScrsPreProcessor_GetTransactionFromPool(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -590,6 +637,7 @@ func TestScrsPreprocessor_RequestTransactionNothingToRequestAsGeneratedAtProcess &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -630,6 +678,7 @@ func TestScrsPreprocessor_RequestTransactionFromNetwork(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -669,6 +718,7 @@ func TestScrsPreprocessor_RequestBlockTransactionFromMiniBlockFromNetwork(t *tes &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -719,6 +769,7 @@ func TestScrsPreprocessor_ReceivedTransactionShouldEraseRequested(t *testing.T) &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -795,6 +846,7 @@ func TestScrsPreprocessor_GetAllTxsFromMiniBlockShouldWork(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -884,6 +936,7 @@ func TestScrsPreprocessor_GetAllTxsFromMiniBlockShouldWorkEvenIfScrIsMisplaced(t &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -929,6 +982,7 @@ func TestScrsPreprocessor_RemoveBlockDataFromPoolsNilBlockShouldErr(t *testing.T &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -959,6 +1013,7 @@ func TestScrsPreprocessor_RemoveBlockDataFromPoolsOK(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1002,6 +1057,7 @@ func TestScrsPreprocessor_IsDataPreparedErr(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1032,6 +1088,7 @@ func TestScrsPreprocessor_IsDataPrepared(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1067,6 +1124,7 @@ func TestScrsPreprocessor_SaveTxsToStorage(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1125,6 +1183,7 @@ func TestScrsPreprocessor_SaveTxsToStorageShouldSaveCorrectly(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1205,6 +1264,7 @@ func TestScrsPreprocessor_SaveTxsToStorageMissingTransactionsShouldNotErr(t *tes &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1253,6 +1313,7 @@ func TestScrsPreprocessor_ProcessBlockTransactionsShouldWork(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1317,6 +1378,7 @@ func TestScrsPreprocessor_ProcessBlockTransactionsMissingTrieNode(t *testing.T) &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1382,6 +1444,7 @@ func TestScrsPreprocessor_ProcessBlockTransactionsShouldErrMaxGasLimitPerBlockIn &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandler, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{ AddCalled: func(txHash []byte) { @@ -1465,6 +1528,7 @@ func TestScrsPreprocessor_ProcessMiniBlock(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1510,6 +1574,7 @@ func TestScrsPreprocessor_ProcessMiniBlockWrongTypeMiniblockShouldErr(t *testing &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1574,6 +1639,7 @@ func TestScrsPreprocessor_RestoreBlockDataIntoPools(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1619,6 +1685,7 @@ func TestScrsPreprocessor_RestoreBlockDataIntoPoolsNilMiniblockPoolShouldErr(t * &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1654,6 +1721,7 @@ func TestSmartContractResults_CreateBlockStartedShouldEmptyTxHashAndInfo(t *test &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) @@ -1683,6 +1751,7 @@ func TestSmartContractResults_GetAllCurrentUsedTxs(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, &commonTests.TxExecutionOrderHandlerStub{}, ) diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index e2f331587d5..051cda58d3d 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -73,6 +73,7 @@ type ArgsTransactionPreProcessor struct { BlockSizeComputation BlockSizeComputationHandler BalanceComputation BalanceComputationHandler EnableEpochsHandler common.EnableEpochsHandler + EnableRoundsHandler common.EnableRoundsHandler TxTypeHandler process.TxTypeHandler ScheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler ProcessedMiniBlocksTracker process.ProcessedMiniBlocksTracker @@ -129,6 +130,9 @@ func NewTransactionPreprocessor( if check.IfNil(args.EnableEpochsHandler) { return nil, process.ErrNilEnableEpochsHandler } + if check.IfNil(args.EnableRoundsHandler) { + return nil, process.ErrNilEnableRoundsHandler + } err := core.CheckHandlerCompatibility(args.EnableEpochsHandler, []core.EnableEpochFlag{ common.OptimizeGasUsedInCrossMiniBlocksFlag, common.ScheduledMiniBlocksFlag, @@ -174,9 +178,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, diff --git a/process/block/preprocess/transactionsV2_test.go b/process/block/preprocess/transactionsV2_test.go index 64ef1fb39c2..330e53dad6b 100644 --- a/process/block/preprocess/transactionsV2_test.go +++ b/process/block/preprocess/transactionsV2_test.go @@ -66,6 +66,7 @@ func createTransactionPreprocessor() *transactions { }, }, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, TxTypeHandler: &testscommon.TxTypeHandlerMock{ ComputeTransactionTypeCalled: func(tx data.TransactionHandler) (process.TransactionType, process.TransactionType, bool) { if bytes.Equal(tx.GetRcvAddr(), []byte("smart contract address")) { diff --git a/process/block/preprocess/transactions_test.go b/process/block/preprocess/transactions_test.go index 87957f569fb..38ce84c15ba 100644 --- a/process/block/preprocess/transactions_test.go +++ b/process/block/preprocess/transactions_test.go @@ -237,6 +237,7 @@ func createDefaultTransactionsProcessorArgs() ArgsTransactionPreProcessor { BlockSizeComputation: &testscommon.BlockSizeComputationStub{}, BalanceComputation: &testscommon.BalanceComputationStub{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, TxTypeHandler: &testscommon.TxTypeHandlerMock{}, ScheduledTxsExecutionHandler: &testscommon.ScheduledTxsExecutionStub{}, ProcessedMiniBlocksTracker: &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -427,6 +428,17 @@ func TestTxsPreprocessor_NewTransactionPreprocessorInvalidEnableEpochsHandler(t assert.True(t, errors.Is(err, core.ErrInvalidEnableEpochsHandler)) } +func TestTxsPreprocessor_NewTransactionPreprocessorNilEnableRoundsHandler(t *testing.T) { + t.Parallel() + + args := createDefaultTransactionsProcessorArgs() + args.EnableRoundsHandler = nil + + txs, err := NewTransactionPreprocessor(args) + assert.Nil(t, txs) + assert.True(t, errors.Is(err, core.ErrNilEnableEpochsHandler)) +} + func TestTxsPreprocessor_NewTransactionPreprocessorNilTxTypeHandler(t *testing.T) { t.Parallel() @@ -969,7 +981,7 @@ func TestCleanupSelfShardTxCache(t *testing.T) { } expectEvictedByRemoveTxsFromPool := 8 // 5 selected (2,3 for alice, 42,43 for bob, 7 for carol) + lower nonces: 1 for alice, 6 *2 for carol - expectedEvictedByCleanup := 4 //nonce 779 * 2 for dave, nonce 100, 101 for eve + expectedEvictedByCleanup := 4 // nonce 779 * 2 for dave, nonce 100, 101 for eve assert.Equal(t, 15-expectedEvictedByCleanup-expectEvictedByRemoveTxsFromPool, int(txs.txPool.GetCounts().GetTotal())) } @@ -1856,9 +1868,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{}, }, }, } @@ -1905,9 +1919,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{}, }, }, } @@ -1966,9 +1982,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{}, }, }, } @@ -2035,9 +2053,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{}, }, }, } @@ -2096,9 +2116,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(), }, @@ -2126,9 +2148,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{}, }, }, } @@ -2332,7 +2356,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/block/shardblock_test.go b/process/block/shardblock_test.go index cf71e6bbc29..5b4903ba043 100644 --- a/process/block/shardblock_test.go +++ b/process/block/shardblock_test.go @@ -487,6 +487,7 @@ func TestShardProcessor_ProcessBlockWithInvalidTransactionShouldErr(t *testing.T &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -716,6 +717,7 @@ func TestShardProcessor_ProcessBlockWithErrOnProcessBlockTransactionsCallShouldR &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -2715,6 +2717,7 @@ func TestShardProcessor_MarshalizedDataToBroadcastShouldWork(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -2828,6 +2831,7 @@ func TestShardProcessor_MarshalizedDataMarshalWithoutSuccess(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -3236,6 +3240,7 @@ func TestShardProcessor_CreateMiniBlocksShouldWorkWithIntraShardTxs(t *testing.T &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -3422,6 +3427,7 @@ func TestShardProcessor_RestoreBlockIntoPoolsShouldWork(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, diff --git a/process/coordinator/process_test.go b/process/coordinator/process_test.go index e26d5875599..2d4cf1afd8a 100644 --- a/process/coordinator/process_test.go +++ b/process/coordinator/process_test.go @@ -569,6 +569,7 @@ func createPreProcessorContainer() process.PreProcessorsContainer { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -670,6 +671,7 @@ func createPreProcessorContainerWithDataPool( &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -941,6 +943,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactions(t *tes &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -1129,6 +1132,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactionsNilPreP &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -1239,6 +1243,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeNothingToPr &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -1834,6 +1839,7 @@ func TestTransactionCoordinator_ProcessBlockTransactionProcessTxError(t *testing &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -1962,6 +1968,7 @@ func TestTransactionCoordinator_RequestMiniblocks(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -2107,6 +2114,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithOkTxsShouldExecuteThemAndNot &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -2253,6 +2261,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithErrorWhileProcessShouldCallR &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, 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..6aec8611fd6 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -1432,6 +1432,15 @@ func TestEconomicsData_MaxGasPriceSetGuardian(t *testing.T) { require.Equal(t, expectedMaxGasPriceSetGuardian, economicData.MaxGasPriceSetGuardian()) } +func TestEconomicsData_BlockCapacityOverestimationFactor(t *testing.T) { + t.Parallel() + + args := createArgsForEconomicsDataRealFees() + economicData, _ := economics.NewEconomicsData(args) + + require.Equal(t, uint64(200), economicData.BlockCapacityOverestimationFactor()) +} + func TestEconomicsData_SetStatusHandler(t *testing.T) { t.Parallel() diff --git a/process/economics/gasConfigHandler.go b/process/economics/gasConfigHandler.go index bea38e07865..cf8e367845f 100644 --- a/process/economics/gasConfigHandler.go +++ b/process/economics/gasConfigHandler.go @@ -30,13 +30,14 @@ type gasConfig struct { } 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 +51,19 @@ func newGasConfigHandler(economics *config.EconomicsConfig) (*gasConfigHandler, return gasConfigSlice[i].gasLimitSettingEpoch < gasConfigSlice[j].gasLimitSettingEpoch }) - minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, err := convertGenericValues(economics) + minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, blockCapacityOverestimationFactor, 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: minGasPrice, + gasPerDataByte: gasPerDataByte, + genesisTotalSupply: genesisTotalSupply, + maxGasPriceSetGuardian: maxGasPriceSetGuardian, + blockCapacityOverestimationFactor: blockCapacityOverestimationFactor, }, nil } @@ -259,29 +261,36 @@ 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) (uint64, uint64, *big.Int, uint64, uint64, 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 0, 0, nil, 0, 0, process.ErrInvalidMinimumGasPrice } gasPerDataByte, err := strconv.ParseUint(economics.FeeSettings.GasPerDataByte, conversionBase, bitConversionSize) if err != nil { - return 0, 0, nil, 0, process.ErrInvalidGasPerDataByte + return 0, 0, nil, 0, 0, process.ErrInvalidGasPerDataByte } genesisTotalSupply, ok := big.NewInt(0).SetString(economics.GlobalSettings.GenesisTotalSupply, conversionBase) if !ok { - return 0, 0, nil, 0, process.ErrInvalidGenesisTotalSupply + return 0, 0, nil, 0, 0, process.ErrInvalidGenesisTotalSupply } maxGasPriceSetGuardian, err := strconv.ParseUint(economics.FeeSettings.MaxGasPriceSetGuardian, conversionBase, bitConversionSize) if err != nil { - return 0, 0, nil, 0, process.ErrInvalidMaxGasPriceSetGuardian + return 0, 0, nil, 0, 0, process.ErrInvalidMaxGasPriceSetGuardian } - return minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, nil + // TODO[Sorin]: uncomment this once feat/supernova-async-exec merges with feat/sub-second-round + // blockCapacityOverestimationFactor, err := strconv.ParseUint(economics.FeeSettings.BlockCapacityOverestimationFactor, conversionBase, bitConversionSize) + // if err != nil { + // return 0, 0, nil, 0, 0, process.ErrInvalidBlockCapacityOverestimationFactor + // } + blockCapacityOverestimationFactor := uint64(200) + + return minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, blockCapacityOverestimationFactor, nil } diff --git a/process/errors.go b/process/errors.go index 7a8580e3554..e015b84a8ad 100644 --- a/process/errors.go +++ b/process/errors.go @@ -540,6 +540,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 ae7dd7379ff..5a7e13b6dfc 100644 --- a/process/factory/metachain/preProcessorsContainerFactory.go +++ b/process/factory/metachain/preProcessorsContainerFactory.go @@ -35,6 +35,7 @@ type preProcessorsContainerFactory struct { blockSizeComputation preprocess.BlockSizeComputationHandler balanceComputation preprocess.BalanceComputationHandler enableEpochsHandler common.EnableEpochsHandler + enableRoundsHandler common.EnableRoundsHandler txTypeHandler process.TxTypeHandler scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler processedMiniBlocksTracker process.ProcessedMiniBlocksTracker @@ -60,6 +61,7 @@ func NewPreProcessorsContainerFactory( blockSizeComputation preprocess.BlockSizeComputationHandler, balanceComputation preprocess.BalanceComputationHandler, enableEpochsHandler common.EnableEpochsHandler, + enableRoundsHandler common.EnableRoundsHandler, txTypeHandler process.TxTypeHandler, scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler, processedMiniBlocksTracker process.ProcessedMiniBlocksTracker, @@ -115,6 +117,9 @@ func NewPreProcessorsContainerFactory( if check.IfNil(enableEpochsHandler) { return nil, process.ErrNilEnableEpochsHandler } + if check.IfNil(enableRoundsHandler) { + return nil, process.ErrNilEnableRoundsHandler + } if check.IfNil(txTypeHandler) { return nil, process.ErrNilTxTypeHandler } @@ -145,6 +150,7 @@ func NewPreProcessorsContainerFactory( blockSizeComputation: blockSizeComputation, balanceComputation: balanceComputation, enableEpochsHandler: enableEpochsHandler, + enableRoundsHandler: enableRoundsHandler, txTypeHandler: txTypeHandler, scheduledTxsExecutionHandler: scheduledTxsExecutionHandler, processedMiniBlocksTracker: processedMiniBlocksTracker, @@ -198,6 +204,7 @@ func (ppcm *preProcessorsContainerFactory) createTxPreProcessor() (process.PrePr BlockSizeComputation: ppcm.blockSizeComputation, BalanceComputation: ppcm.balanceComputation, EnableEpochsHandler: ppcm.enableEpochsHandler, + EnableRoundsHandler: ppcm.enableRoundsHandler, TxTypeHandler: ppcm.txTypeHandler, ScheduledTxsExecutionHandler: ppcm.scheduledTxsExecutionHandler, ProcessedMiniBlocksTracker: ppcm.processedMiniBlocksTracker, @@ -226,6 +233,7 @@ func (ppcm *preProcessorsContainerFactory) createSmartContractResultPreProcessor ppcm.blockSizeComputation, ppcm.balanceComputation, ppcm.enableEpochsHandler, + ppcm.enableRoundsHandler, ppcm.processedMiniBlocksTracker, ppcm.txExecutionOrderHandler, ) diff --git a/process/factory/metachain/preProcessorsContainerFactory_test.go b/process/factory/metachain/preProcessorsContainerFactory_test.go index 7e40baf4096..5ff04c9a523 100644 --- a/process/factory/metachain/preProcessorsContainerFactory_test.go +++ b/process/factory/metachain/preProcessorsContainerFactory_test.go @@ -50,6 +50,7 @@ func TestNewPreProcessorsContainerFactory_NilShardCoordinator(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -81,6 +82,7 @@ func TestNewPreProcessorsContainerFactory_NilStore(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -112,6 +114,7 @@ func TestNewPreProcessorsContainerFactory_NilMarshalizer(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -143,6 +146,7 @@ func TestNewPreProcessorsContainerFactory_NilHasher(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -174,6 +178,7 @@ func TestNewPreProcessorsContainerFactory_NilDataPool(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -205,6 +210,7 @@ func TestNewPreProcessorsContainerFactory_NilAccounts(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -236,6 +242,7 @@ func TestNewPreProcessorsContainerFactory_NilFeeHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -267,6 +274,7 @@ func TestNewPreProcessorsContainerFactory_NilTxProcessor(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -298,6 +306,7 @@ func TestNewPreProcessorsContainerFactory_NilRequestHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -328,6 +337,7 @@ func TestNewPreProcessorsContainerFactory_NilGasHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -358,6 +368,7 @@ func TestNewPreProcessorsContainerFactory_NilBlockTracker(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -388,6 +399,7 @@ func TestNewPreProcessorsContainerFactory_NilPubkeyConverter(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -418,6 +430,7 @@ func TestNewPreProcessorsContainerFactory_NilBlockSizeComputationHandler(t *test nil, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -448,6 +461,7 @@ func TestNewPreProcessorsContainerFactory_NilBalanceComputationHandler(t *testin &testscommon.BlockSizeComputationStub{}, nil, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -478,6 +492,7 @@ func TestNewPreProcessorsContainerFactory_NilEnableEpochsHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, nil, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -488,6 +503,37 @@ func TestNewPreProcessorsContainerFactory_NilEnableEpochsHandler(t *testing.T) { assert.Nil(t, ppcm) } +func TestNewPreProcessorsContainerFactory_NilEnableRoundsHandler(t *testing.T) { + t.Parallel() + + ppcm, err := metachain.NewPreProcessorsContainerFactory( + mock.NewMultiShardsCoordinatorMock(3), + &storageStubs.ChainStorerStub{}, + &mock.MarshalizerMock{}, + &hashingMocks.HasherMock{}, + dataRetrieverMock.NewPoolsHolderMock(), + &stateMock.AccountsStub{}, + &testscommon.RequestHandlerStub{}, + &testscommon.TxProcessorMock{}, + &testscommon.SmartContractResultsProcessorMock{}, + &economicsmocks.EconomicsHandlerMock{}, + &testscommon.GasHandlerStub{}, + &mock.BlockTrackerMock{}, + createMockPubkeyConverter(), + &testscommon.BlockSizeComputationStub{}, + &testscommon.BalanceComputationStub{}, + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + nil, + &testscommon.TxTypeHandlerMock{}, + &testscommon.ScheduledTxsExecutionStub{}, + &testscommon.ProcessedMiniBlocksTrackerStub{}, + &commonMock.TxExecutionOrderHandlerStub{}, + createMockTxCacheSelectionConfig(), + ) + assert.Equal(t, process.ErrNilEnableRoundsHandler, err) + assert.Nil(t, ppcm) +} + func TestNewPreProcessorsContainerFactory_NilTxTypeHandler(t *testing.T) { t.Parallel() @@ -508,6 +554,7 @@ func TestNewPreProcessorsContainerFactory_NilTxTypeHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, nil, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -538,6 +585,7 @@ func TestNewPreProcessorsContainerFactory_NilScheduledTxsExecutionHandler(t *tes &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, nil, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -568,6 +616,7 @@ func TestNewPreProcessorsContainerFactory_NilProcessedMiniBlocksTracker(t *testi &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, nil, @@ -598,6 +647,7 @@ func TestNewPreProcessorsContainerFactory_NilTxExecutionOrderHandler(t *testing. &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -629,6 +679,7 @@ func TestNewPreProcessorsContainerFactory(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -666,6 +717,7 @@ func TestPreProcessorsContainerFactory_CreateErrTxPreproc(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -701,6 +753,7 @@ func TestPreProcessorsContainerFactory_Create(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, diff --git a/process/factory/shard/preProcessorsContainerFactory.go b/process/factory/shard/preProcessorsContainerFactory.go index b97c11d23e8..740887ef73f 100644 --- a/process/factory/shard/preProcessorsContainerFactory.go +++ b/process/factory/shard/preProcessorsContainerFactory.go @@ -37,6 +37,7 @@ type preProcessorsContainerFactory struct { blockSizeComputation preprocess.BlockSizeComputationHandler balanceComputation preprocess.BalanceComputationHandler enableEpochsHandler common.EnableEpochsHandler + enableRoundsHandler common.EnableRoundsHandler txTypeHandler process.TxTypeHandler scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler processedMiniBlocksTracker process.ProcessedMiniBlocksTracker @@ -64,6 +65,7 @@ func NewPreProcessorsContainerFactory( blockSizeComputation preprocess.BlockSizeComputationHandler, balanceComputation preprocess.BalanceComputationHandler, enableEpochsHandler common.EnableEpochsHandler, + enableRoundsHandler common.EnableRoundsHandler, txTypeHandler process.TxTypeHandler, scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler, processedMiniBlocksTracker process.ProcessedMiniBlocksTracker, @@ -125,6 +127,9 @@ func NewPreProcessorsContainerFactory( if check.IfNil(enableEpochsHandler) { return nil, process.ErrNilEnableEpochsHandler } + if check.IfNil(enableRoundsHandler) { + return nil, process.ErrNilEnableRoundsHandler + } if check.IfNil(txTypeHandler) { return nil, process.ErrNilTxTypeHandler } @@ -157,6 +162,7 @@ func NewPreProcessorsContainerFactory( blockSizeComputation: blockSizeComputation, balanceComputation: balanceComputation, enableEpochsHandler: enableEpochsHandler, + enableRoundsHandler: enableRoundsHandler, txTypeHandler: txTypeHandler, scheduledTxsExecutionHandler: scheduledTxsExecutionHandler, processedMiniBlocksTracker: processedMiniBlocksTracker, @@ -230,6 +236,7 @@ func (ppcm *preProcessorsContainerFactory) createTxPreProcessor() (process.PrePr BlockSizeComputation: ppcm.blockSizeComputation, BalanceComputation: ppcm.balanceComputation, EnableEpochsHandler: ppcm.enableEpochsHandler, + EnableRoundsHandler: ppcm.enableRoundsHandler, TxTypeHandler: ppcm.txTypeHandler, ScheduledTxsExecutionHandler: ppcm.scheduledTxsExecutionHandler, ProcessedMiniBlocksTracker: ppcm.processedMiniBlocksTracker, @@ -258,6 +265,7 @@ func (ppcm *preProcessorsContainerFactory) createSmartContractResultPreProcessor ppcm.blockSizeComputation, ppcm.balanceComputation, ppcm.enableEpochsHandler, + ppcm.enableRoundsHandler, ppcm.processedMiniBlocksTracker, ppcm.txExecutionOrderHandler, ) diff --git a/process/factory/shard/preProcessorsContainerFactory_test.go b/process/factory/shard/preProcessorsContainerFactory_test.go index 8cd2cbbd6ca..7bc5fa72222 100644 --- a/process/factory/shard/preProcessorsContainerFactory_test.go +++ b/process/factory/shard/preProcessorsContainerFactory_test.go @@ -55,6 +55,7 @@ func TestNewPreProcessorsContainerFactory_NilShardCoordinator(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -88,6 +89,7 @@ func TestNewPreProcessorsContainerFactory_NilStore(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -121,6 +123,7 @@ func TestNewPreProcessorsContainerFactory_NilMarshalizer(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -154,6 +157,7 @@ func TestNewPreProcessorsContainerFactory_NilHasher(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -187,6 +191,7 @@ func TestNewPreProcessorsContainerFactory_NilDataPool(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -220,6 +225,7 @@ func TestNewPreProcessorsContainerFactory_NilAddrConv(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -253,6 +259,7 @@ func TestNewPreProcessorsContainerFactory_NilAccounts(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -286,6 +293,7 @@ func TestNewPreProcessorsContainerFactory_NilTxProcessor(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -319,6 +327,7 @@ func TestNewPreProcessorsContainerFactory_NilSCProcessor(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -352,6 +361,7 @@ func TestNewPreProcessorsContainerFactory_NilSCR(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -385,6 +395,7 @@ func TestNewPreProcessorsContainerFactory_NilRewardTxProcessor(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -418,6 +429,7 @@ func TestNewPreProcessorsContainerFactory_NilRequestHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -451,6 +463,7 @@ func TestNewPreProcessorsContainerFactory_NilFeeHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -484,6 +497,7 @@ func TestNewPreProcessorsContainerFactory_NilGasHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -517,6 +531,7 @@ func TestNewPreProcessorsContainerFactory_NilBlockTracker(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -550,6 +565,7 @@ func TestNewPreProcessorsContainerFactory_NilBlockSizeComputationHandler(t *test nil, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -583,6 +599,7 @@ func TestNewPreProcessorsContainerFactory_NilBalanceComputationHandler(t *testin &testscommon.BlockSizeComputationStub{}, nil, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -616,6 +633,7 @@ func TestNewPreProcessorsContainerFactory_NilEnableEpochsHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, nil, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -627,6 +645,40 @@ func TestNewPreProcessorsContainerFactory_NilEnableEpochsHandler(t *testing.T) { assert.Nil(t, ppcm) } +func TestNewPreProcessorsContainerFactory_NilEnableRoundsHandler(t *testing.T) { + t.Parallel() + + ppcm, err := NewPreProcessorsContainerFactory( + mock.NewMultiShardsCoordinatorMock(3), + &storageStubs.ChainStorerStub{}, + &mock.MarshalizerMock{}, + &hashingMocks.HasherMock{}, + dataRetrieverMock.NewPoolsHolderMock(), + createMockPubkeyConverter(), + &stateMock.AccountsStub{}, + &testscommon.RequestHandlerStub{}, + &testscommon.TxProcessorMock{}, + &testscommon.SCProcessorMock{}, + &testscommon.SmartContractResultsProcessorMock{}, + &testscommon.RewardTxProcessorMock{}, + &economicsmocks.EconomicsHandlerMock{}, + &testscommon.GasHandlerStub{}, + &mock.BlockTrackerMock{}, + &testscommon.BlockSizeComputationStub{}, + &testscommon.BalanceComputationStub{}, + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + nil, + &testscommon.TxTypeHandlerMock{}, + &testscommon.ScheduledTxsExecutionStub{}, + &testscommon.ProcessedMiniBlocksTrackerStub{}, + &commonMock.TxExecutionOrderHandlerStub{}, + createMockTxCacheSelectionConfig(), + ) + + assert.Equal(t, process.ErrNilEnableRoundsHandler, err) + assert.Nil(t, ppcm) +} + func TestNewPreProcessorsContainerFactory_NilTxTypeHandler(t *testing.T) { t.Parallel() @@ -649,6 +701,7 @@ func TestNewPreProcessorsContainerFactory_NilTxTypeHandler(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, nil, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -682,6 +735,7 @@ func TestNewPreProcessorsContainerFactory_NilScheduledTxsExecutionHandler(t *tes &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, nil, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -715,6 +769,7 @@ func TestNewPreProcessorsContainerFactory_NilProcessedMiniBlocksTracker(t *testi &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, nil, @@ -748,6 +803,7 @@ func TestNewPreProcessorsContainerFactory_NilTxExecutionOrderHandler(t *testing. &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -781,6 +837,7 @@ func TestNewPreProcessorsContainerFactory(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -819,6 +876,7 @@ func TestPreProcessorsContainerFactory_CreateErrTxPreproc(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -863,6 +921,7 @@ func TestPreProcessorsContainerFactory_CreateErrScrPreproc(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, @@ -910,6 +969,7 @@ func TestPreProcessorsContainerFactory_Create(t *testing.T) { &testscommon.BlockSizeComputationStub{}, &testscommon.BalanceComputationStub{}, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &testscommon.EnableRoundsHandlerStub{}, &testscommon.TxTypeHandlerMock{}, &testscommon.ScheduledTxsExecutionStub{}, &testscommon.ProcessedMiniBlocksTrackerStub{}, diff --git a/process/interface.go b/process/interface.go index bfa4e197c2a..72c1dc74684 100644 --- a/process/interface.go +++ b/process/interface.go @@ -698,10 +698,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 @@ -709,6 +712,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 { From b7f753d16a818d594fccf41ec9bb7585569051b1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 26 Sep 2025 18:38:56 +0300 Subject: [PATCH 2/8] updated blockCapacityOverestimationFactor value --- process/economics/gasConfigHandler.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/economics/gasConfigHandler.go b/process/economics/gasConfigHandler.go index cf8e367845f..8b0a9100147 100644 --- a/process/economics/gasConfigHandler.go +++ b/process/economics/gasConfigHandler.go @@ -290,7 +290,7 @@ func convertGenericValues(economics *config.EconomicsConfig) (uint64, uint64, *b // if err != nil { // return 0, 0, nil, 0, 0, process.ErrInvalidBlockCapacityOverestimationFactor // } - blockCapacityOverestimationFactor := uint64(200) + blockCapacityOverestimationFactor := uint64(100) // returning 100 so nothing changes after activation return minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, blockCapacityOverestimationFactor, nil } From 81136a5ba4c4740f06964b9885b4714a468a1517 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 26 Sep 2025 18:58:32 +0300 Subject: [PATCH 3/8] fixed tests --- process/block/preprocess/miniBlockBuilder_test.go | 6 +++--- process/block/preprocess/transactionsV2_test.go | 6 +++--- process/block/preprocess/transactions_test.go | 13 +++++++++++-- process/coordinator/process_test.go | 9 +++++++++ process/economics/economicsData_test.go | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/process/block/preprocess/miniBlockBuilder_test.go b/process/block/preprocess/miniBlockBuilder_test.go index 92354c2b951..8ad9457b16a 100644 --- a/process/block/preprocess/miniBlockBuilder_test.go +++ b/process/block/preprocess/miniBlockBuilder_test.go @@ -845,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 }, }, diff --git a/process/block/preprocess/transactionsV2_test.go b/process/block/preprocess/transactionsV2_test.go index 330e53dad6b..c89ac57c206 100644 --- a/process/block/preprocess/transactionsV2_test.go +++ b/process/block/preprocess/transactionsV2_test.go @@ -42,13 +42,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 38ce84c15ba..6203644151f 100644 --- a/process/block/preprocess/transactions_test.go +++ b/process/block/preprocess/transactions_test.go @@ -75,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 + }, } } @@ -436,7 +445,7 @@ func TestTxsPreprocessor_NewTransactionPreprocessorNilEnableRoundsHandler(t *tes txs, err := NewTransactionPreprocessor(args) assert.Nil(t, txs) - assert.True(t, errors.Is(err, core.ErrNilEnableEpochsHandler)) + assert.True(t, errors.Is(err, process.ErrNilEnableRoundsHandler)) } func TestTxsPreprocessor_NewTransactionPreprocessorNilTxTypeHandler(t *testing.T) { @@ -1746,7 +1755,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 }, } diff --git a/process/coordinator/process_test.go b/process/coordinator/process_test.go index 2d4cf1afd8a..c2839df6fbd 100644 --- a/process/coordinator/process_test.go +++ b/process/coordinator/process_test.go @@ -84,6 +84,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_test.go b/process/economics/economicsData_test.go index 6aec8611fd6..65c881c7fa0 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -1438,7 +1438,7 @@ func TestEconomicsData_BlockCapacityOverestimationFactor(t *testing.T) { args := createArgsForEconomicsDataRealFees() economicData, _ := economics.NewEconomicsData(args) - require.Equal(t, uint64(200), economicData.BlockCapacityOverestimationFactor()) + require.Equal(t, uint64(100), economicData.BlockCapacityOverestimationFactor()) } func TestEconomicsData_SetStatusHandler(t *testing.T) { From 8947bbf5bc22ce9ed057178bed646dd1d5578e51 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 Oct 2025 13:17:07 +0300 Subject: [PATCH 4/8] fixes after merge --- consensus/spos/bls/v2/subroundBlock_test.go | 2 +- consensus/spos/bls/v2/subroundEndRound_test.go | 2 +- genesis/process/metaGenesisBlockCreator.go | 3 --- process/block/preprocess/rewardTxPreProcessor.go | 8 +++++--- process/block/preprocess/smartContractResults.go | 8 +++++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/consensus/spos/bls/v2/subroundBlock_test.go b/consensus/spos/bls/v2/subroundBlock_test.go index 90f0a2722de..164c668ee58 100644 --- a/consensus/spos/bls/v2/subroundBlock_test.go +++ b/consensus/spos/bls/v2/subroundBlock_test.go @@ -1327,7 +1327,7 @@ func TestSubroundBlock_UpdateConsensusMetrics(t *testing.T) { }, } count := 0 - roundHandlerMock := consensusMocks.RoundHandlerMock{ + roundHandlerMock := testscommon.RoundHandlerMock{ TimeStampCalled: func() time.Time { defer func() { count++ }() if count == 0 { diff --git a/consensus/spos/bls/v2/subroundEndRound_test.go b/consensus/spos/bls/v2/subroundEndRound_test.go index 1b10ab7621e..8ba26a4639c 100644 --- a/consensus/spos/bls/v2/subroundEndRound_test.go +++ b/consensus/spos/bls/v2/subroundEndRound_test.go @@ -2448,7 +2448,7 @@ func TestSubroundEndRound_UpdateConsensusMetrics(t *testing.T) { return now }, } - roundHandlerMock := consensusMocks.RoundHandlerMock{ + roundHandlerMock := testscommon.RoundHandlerMock{ TimeStampCalled: func() time.Time { return now.Add(-500 * time.Nanosecond) }, diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 3bcbd8d8a1d..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" 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, From 57daf58f84a4ea42335c025101331fe5275d29dc Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 Oct 2025 13:41:10 +0300 Subject: [PATCH 5/8] fixed duplicated error after merge --- process/errors.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/process/errors.go b/process/errors.go index 0893dc6a880..65fabcc0c3a 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1406,6 +1406,3 @@ var ErrZeroLimit = errors.New("zero limit") // ErrInvalidBlockType signals that an invalid block type has been provided var ErrInvalidBlockType = errors.New("invalid block type") - -// ErrDuplicatedInterceptedDataNotAllowed signals that duplicated intercepted data is not allowed -var ErrDuplicatedInterceptedDataNotAllowed = errors.New("duplicated intercepted data not allowed") From 1aced0f6f18c38da7414c27f7d190a11079547de Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 Oct 2025 13:44:18 +0300 Subject: [PATCH 6/8] removed todo --- process/economics/economicsData_test.go | 1 + process/economics/gasConfigHandler.go | 8 +------- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index 65c881c7fa0..378367f052f 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -1436,6 +1436,7 @@ 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()) diff --git a/process/economics/gasConfigHandler.go b/process/economics/gasConfigHandler.go index 8b0a9100147..de494f03c22 100644 --- a/process/economics/gasConfigHandler.go +++ b/process/economics/gasConfigHandler.go @@ -285,12 +285,6 @@ func convertGenericValues(economics *config.EconomicsConfig) (uint64, uint64, *b return 0, 0, nil, 0, 0, process.ErrInvalidMaxGasPriceSetGuardian } - // TODO[Sorin]: uncomment this once feat/supernova-async-exec merges with feat/sub-second-round - // blockCapacityOverestimationFactor, err := strconv.ParseUint(economics.FeeSettings.BlockCapacityOverestimationFactor, conversionBase, bitConversionSize) - // if err != nil { - // return 0, 0, nil, 0, 0, process.ErrInvalidBlockCapacityOverestimationFactor - // } - blockCapacityOverestimationFactor := uint64(100) // returning 100 so nothing changes after activation - + blockCapacityOverestimationFactor := economics.FeeSettings.BlockCapacityOverestimationFactor return minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, blockCapacityOverestimationFactor, nil } From e6e50724b5e58b29561640158d77f28bbf6c3c65 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 28 Oct 2025 13:20:46 +0200 Subject: [PATCH 7/8] fixes after review --- process/block/preprocess/gasTracker.go | 31 ++++++---- process/block/preprocess/gasTracker_test.go | 65 +++++++++++++++++++-- process/economics/gasConfigHandler.go | 39 +++++++++---- 3 files changed, 109 insertions(+), 26 deletions(-) diff --git a/process/block/preprocess/gasTracker.go b/process/block/preprocess/gasTracker.go index ccf0f9a361d..f3d1a2bd332 100644 --- a/process/block/preprocess/gasTracker.go +++ b/process/block/preprocess/gasTracker.go @@ -34,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.getMaxGasLimitPerTx() { + if gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerTx(epoch) { return 0, process.ErrMaxGasLimitPerOneTxInReceiverShardIsReached } - if gasInfo.gasConsumedByMiniBlockInReceiverShard+gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerBlockForSafeCrossShard() { + if gasInfo.gasConsumedByMiniBlockInReceiverShard+gasProvidedByTxInReceiverShard > gt.getMaxGasLimitPerBlockForSafeCrossShard(epoch, overEstimationFactor) { return 0, process.ErrMaxGasLimitPerMiniBlockInReceiverShardIsReached } } else { gasProvidedByTxInSelfShard = gasProvidedByTxInReceiverShard } - if gasInfo.totalGasConsumedInSelfShard+gasProvidedByTxInSelfShard > gt.getMaxGasLimitPerBlock() { + if gasInfo.totalGasConsumedInSelfShard+gasProvidedByTxInSelfShard > gt.getMaxGasLimitPerBlock(epoch, overEstimationFactor) { return 0, process.ErrMaxGasLimitPerBlockInSelfShardIsReached } @@ -63,30 +65,39 @@ func (gt *gasTracker) computeGasProvided( 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 - epoch = epoch - 1 overestimationFactor = gt.economicsFee.BlockCapacityOverestimationFactor() return } -func (gt *gasTracker) getMaxGasLimitPerTx() uint64 { - epoch, _ := gt.getEpochAndOverestimationFactorForGasLimits() +func (gt *gasTracker) getMaxGasLimitPerTx(epoch uint32) uint64 { return gt.economicsFee.MaxGasLimitPerTxInEpoch(epoch) } -func (gt *gasTracker) getMaxGasLimitPerBlockForSafeCrossShard() uint64 { - epoch, overEstimationFactor := gt.getEpochAndOverestimationFactorForGasLimits() +func (gt *gasTracker) getMaxGasLimitPerBlockForSafeCrossShard(epoch uint32, overEstimationFactor uint64) uint64 { return gt.economicsFee.MaxGasLimitPerBlockForSafeCrossShardInEpoch(epoch) * overEstimationFactor / 100 } -func (gt *gasTracker) getMaxGasLimitPerBlock() uint64 { - epoch, overEstimationFactor := gt.getEpochAndOverestimationFactorForGasLimits() +func (gt *gasTracker) getMaxGasLimitPerBlock(epoch uint32, overEstimationFactor uint64) uint64 { return gt.economicsFee.MaxGasLimitPerBlockInEpoch(gt.shardCoordinator.SelfId(), epoch) * overEstimationFactor / 100 } diff --git a/process/block/preprocess/gasTracker_test.go b/process/block/preprocess/gasTracker_test.go index 6196785472b..16a23a105bc 100644 --- a/process/block/preprocess/gasTracker_test.go +++ b/process/block/preprocess/gasTracker_test.go @@ -6,6 +6,7 @@ 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/multiversx/mx-chain-go/common" @@ -98,10 +99,14 @@ func createDefaultGasTracker( } gt := &gasTracker{ - shardCoordinator: shardCoordinator, - economicsFee: economicsFee, - gasHandler: gasHandler, - enableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + 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 @@ -570,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/economics/gasConfigHandler.go b/process/economics/gasConfigHandler.go index de494f03c22..23ade15d78d 100644 --- a/process/economics/gasConfigHandler.go +++ b/process/economics/gasConfigHandler.go @@ -29,6 +29,14 @@ 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 @@ -51,7 +59,7 @@ func newGasConfigHandler(economics *config.EconomicsConfig) (*gasConfigHandler, return gasConfigSlice[i].gasLimitSettingEpoch < gasConfigSlice[j].gasLimitSettingEpoch }) - minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, blockCapacityOverestimationFactor, err := convertGenericValues(economics) + result, err := convertGenericValues(economics) if err != nil { return nil, err } @@ -59,11 +67,11 @@ func newGasConfigHandler(economics *config.EconomicsConfig) (*gasConfigHandler, return &gasConfigHandler{ statusHandler: statusHandler.NewNilStatusHandler(), gasLimitSettings: gasConfigSlice, - minGasPrice: minGasPrice, - gasPerDataByte: gasPerDataByte, - genesisTotalSupply: genesisTotalSupply, - maxGasPriceSetGuardian: maxGasPriceSetGuardian, - blockCapacityOverestimationFactor: blockCapacityOverestimationFactor, + minGasPrice: result.minGasPrice, + gasPerDataByte: result.gasPerDataByte, + genesisTotalSupply: result.genesisTotalSupply, + maxGasPriceSetGuardian: result.maxGasPriceSetGuardian, + blockCapacityOverestimationFactor: result.blockCapacityOverestimationFactor, }, nil } @@ -261,30 +269,37 @@ func checkAndParseGasLimitSettings(gasLimitSetting config.GasLimitSetting) (*gas return gc, nil } -func convertGenericValues(economics *config.EconomicsConfig) (uint64, uint64, *big.Int, uint64, 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, 0, process.ErrInvalidMinimumGasPrice + return nil, process.ErrInvalidMinimumGasPrice } gasPerDataByte, err := strconv.ParseUint(economics.FeeSettings.GasPerDataByte, conversionBase, bitConversionSize) if err != nil { - return 0, 0, nil, 0, 0, process.ErrInvalidGasPerDataByte + return nil, process.ErrInvalidGasPerDataByte } genesisTotalSupply, ok := big.NewInt(0).SetString(economics.GlobalSettings.GenesisTotalSupply, conversionBase) if !ok { - return 0, 0, nil, 0, 0, process.ErrInvalidGenesisTotalSupply + return nil, process.ErrInvalidGenesisTotalSupply } maxGasPriceSetGuardian, err := strconv.ParseUint(economics.FeeSettings.MaxGasPriceSetGuardian, conversionBase, bitConversionSize) if err != nil { - return 0, 0, nil, 0, 0, process.ErrInvalidMaxGasPriceSetGuardian + return nil, process.ErrInvalidMaxGasPriceSetGuardian } blockCapacityOverestimationFactor := economics.FeeSettings.BlockCapacityOverestimationFactor - return minGasPrice, gasPerDataByte, genesisTotalSupply, maxGasPriceSetGuardian, blockCapacityOverestimationFactor, nil + + return &convertedGenericEconomicValues{ + minGasPrice: minGasPrice, + gasPerDataByte: gasPerDataByte, + genesisTotalSupply: genesisTotalSupply, + maxGasPriceSetGuardian: maxGasPriceSetGuardian, + blockCapacityOverestimationFactor: blockCapacityOverestimationFactor, + }, nil } From 9715c7d9f9c9944eddfc7de03a44c9c0ac9075e4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 28 Oct 2025 15:32:24 +0200 Subject: [PATCH 8/8] fix panic --- process/block/preprocess/transactions.go | 1 + 1 file changed, 1 insertion(+) diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index 2507c073ab3..4bb8a8b9fd7 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -133,6 +133,7 @@ func NewTransactionPreprocessor( accountsProposal: args.AccountsProposal, pubkeyConverter: args.PubkeyConverter, enableEpochsHandler: args.EnableEpochsHandler, + enableRoundsHandler: args.EnableRoundsHandler, processedMiniBlocksTracker: args.ProcessedMiniBlocksTracker, txExecutionOrderHandler: args.TxExecutionOrderHandler, }