Skip to content

Commit

Permalink
Feed guardian checker into process/block/preprocess/transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Nov 19, 2024
1 parent 4834372 commit 9ff7f5c
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 1 deletion.
1 change: 1 addition & 0 deletions factory/processing/blockProcessorCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ func (pcf *processComponentsFactory) newShardBlockProcessor(
scheduledTxsExecutionHandler,
processedMiniBlocksTracker,
pcf.txExecutionOrderHandler,
pcf.bootstrapComponents.GuardedAccountHandler(),
)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions genesis/process/shardGenesisBlockCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo
disabledScheduledTxsExecutionHandler,
disabledProcessedMiniBlocksTracker,
arg.TxExecutionOrderHandler,
disabledGuardian.NewDisabledGuardedAccountHandler(),
)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion integrationTests/testProcessorNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -1689,6 +1689,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u
txTypeHandler, _ := coordinator.NewTxTypeHandler(argsTxTypeHandler)
tpn.GasHandler, _ = preprocess.NewGasComputation(tpn.EconomicsData, txTypeHandler, tpn.EnableEpochsHandler)
badBlocksHandler, _ := tpn.InterimProcContainer.Get(dataBlock.InvalidBlock)
guardianChecker := &guardianMocks.GuardedAccountHandlerStub{}

argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{
VmContainer: tpn.VMContainer,
Expand Down Expand Up @@ -1734,7 +1735,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u
ScrForwarder: tpn.ScrForwarder,
EnableRoundsHandler: tpn.EnableRoundsHandler,
EnableEpochsHandler: tpn.EnableEpochsHandler,
GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{},
GuardianChecker: guardianChecker,
TxVersionChecker: &testscommon.TxVersionCheckerStub{},
TxLogsProcessor: tpn.TransactionLogProcessor,
}
Expand Down Expand Up @@ -1774,6 +1775,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u
scheduledTxsExecutionHandler,
processedMiniBlocksTracker,
tpn.TxExecutionOrderHandler,
guardianChecker,
)
tpn.PreProcessorsContainer, _ = fact.Create()

Expand Down
4 changes: 4 additions & 0 deletions process/block/preprocess/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type ArgsTransactionPreProcessor struct {
ScheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler
ProcessedMiniBlocksTracker process.ProcessedMiniBlocksTracker
TxExecutionOrderHandler common.TxExecutionOrderHandler
GuardianChecker process.GuardianChecker
}

// NewTransactionPreprocessor creates a new transaction preprocessor object
Expand Down Expand Up @@ -154,6 +155,9 @@ func NewTransactionPreprocessor(
if check.IfNil(args.TxExecutionOrderHandler) {
return nil, process.ErrNilTxExecutionOrderHandler
}
if check.IfNil(args.GuardianChecker) {
return nil, process.ErrNilGuardianChecker
}

accountStateProvider, err := newAccountStateProvider(args.Accounts)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions process/block/preprocess/transactionsV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
commonMocks "github.com/multiversx/mx-chain-go/testscommon/common"
"github.com/multiversx/mx-chain-go/testscommon/economicsmocks"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
"github.com/multiversx/mx-chain-go/testscommon/guardianMocks"
"github.com/multiversx/mx-chain-go/testscommon/hashingMocks"
stateMock "github.com/multiversx/mx-chain-go/testscommon/state"
storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage"
Expand Down Expand Up @@ -76,6 +77,7 @@ func createTransactionPreprocessor() *transactions {
ScheduledTxsExecutionHandler: &testscommon.ScheduledTxsExecutionStub{},
ProcessedMiniBlocksTracker: &testscommon.ProcessedMiniBlocksTrackerStub{},
TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{},
GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{},
}

preprocessor, _ := NewTransactionPreprocessor(txPreProcArgs)
Expand Down
22 changes: 22 additions & 0 deletions process/block/preprocess/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/multiversx/mx-chain-go/testscommon/economicsmocks"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
"github.com/multiversx/mx-chain-go/testscommon/genericMocks"
"github.com/multiversx/mx-chain-go/testscommon/guardianMocks"
"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"
Expand Down Expand Up @@ -238,6 +239,7 @@ func createDefaultTransactionsProcessorArgs() ArgsTransactionPreProcessor {
ScheduledTxsExecutionHandler: &testscommon.ScheduledTxsExecutionStub{},
ProcessedMiniBlocksTracker: &testscommon.ProcessedMiniBlocksTrackerStub{},
TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{},
GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{},
}
}

Expand Down Expand Up @@ -446,6 +448,26 @@ func TestTxsPreprocessor_NewTransactionPreprocessorNilProcessedMiniBlocksTracker
assert.Equal(t, process.ErrNilProcessedMiniBlocksTracker, err)
}

func TestTxsPreprocessor_NewTransactionPreprocessorNilTxExecutionOrderHandler(t *testing.T) {
t.Parallel()

args := createDefaultTransactionsProcessorArgs()
args.TxExecutionOrderHandler = nil
txs, err := NewTransactionPreprocessor(args)
assert.Nil(t, txs)
assert.Equal(t, process.ErrNilTxExecutionOrderHandler, err)
}

func TestTxsPreprocessor_NewTransactionPreprocessorNilGuardianChecker(t *testing.T) {
t.Parallel()

args := createDefaultTransactionsProcessorArgs()
args.GuardianChecker = nil
txs, err := NewTransactionPreprocessor(args)
assert.Nil(t, txs)
assert.Equal(t, process.ErrNilGuardianChecker, err)
}

func TestTxsPreprocessor_NewTransactionPreprocessorOkValsShouldWork(t *testing.T) {
t.Parallel()

Expand Down
7 changes: 7 additions & 0 deletions process/block/shardblock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/multiversx/mx-chain-go/testscommon/economicsmocks"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
"github.com/multiversx/mx-chain-go/testscommon/epochNotifier"
"github.com/multiversx/mx-chain-go/testscommon/guardianMocks"
"github.com/multiversx/mx-chain-go/testscommon/hashingMocks"
"github.com/multiversx/mx-chain-go/testscommon/outport"
stateMock "github.com/multiversx/mx-chain-go/testscommon/state"
Expand Down Expand Up @@ -478,6 +479,7 @@ func TestShardProcessor_ProcessBlockWithInvalidTransactionShouldErr(t *testing.T
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := factory.Create()

Expand Down Expand Up @@ -700,6 +702,7 @@ func TestShardProcessor_ProcessBlockWithErrOnProcessBlockTransactionsCallShouldR
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := factory.Create()

Expand Down Expand Up @@ -2596,6 +2599,7 @@ func TestShardProcessor_MarshalizedDataToBroadcastShouldWork(t *testing.T) {
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := factory.Create()

Expand Down Expand Up @@ -2705,6 +2709,7 @@ func TestShardProcessor_MarshalizedDataMarshalWithoutSuccess(t *testing.T) {
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := factory.Create()

Expand Down Expand Up @@ -3100,6 +3105,7 @@ func TestShardProcessor_CreateMiniBlocksShouldWorkWithIntraShardTxs(t *testing.T
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := factory.Create()

Expand Down Expand Up @@ -3282,6 +3288,7 @@ func TestShardProcessor_RestoreBlockIntoPoolsShouldWork(t *testing.T) {
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := factory.Create()

Expand Down
10 changes: 10 additions & 0 deletions process/coordinator/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
"github.com/multiversx/mx-chain-go/testscommon/economicsmocks"
"github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock"
"github.com/multiversx/mx-chain-go/testscommon/guardianMocks"
"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"
Expand Down Expand Up @@ -559,6 +560,7 @@ func createPreProcessorContainer() process.PreProcessorsContainer {
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down Expand Up @@ -658,6 +660,7 @@ func createPreProcessorContainerWithDataPool(
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down Expand Up @@ -928,6 +931,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactions(t *tes
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down Expand Up @@ -1115,6 +1119,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactionsNilPreP
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down Expand Up @@ -1224,6 +1229,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessTransactionsFromMeNothingToPr
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down Expand Up @@ -1762,6 +1768,7 @@ func TestTransactionCoordinator_ProcessBlockTransactionProcessTxError(t *testing
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down Expand Up @@ -1889,6 +1896,7 @@ func TestTransactionCoordinator_RequestMiniblocks(t *testing.T) {
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down Expand Up @@ -2030,6 +2038,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithOkTxsShouldExecuteThemAndNot
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down Expand Up @@ -2172,6 +2181,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithErrorWhileProcessShouldCallR
&testscommon.ScheduledTxsExecutionStub{},
&testscommon.ProcessedMiniBlocksTrackerStub{},
&commonMock.TxExecutionOrderHandlerStub{},
&guardianMocks.GuardedAccountHandlerStub{},
)
container, _ := preFactory.Create()

Expand Down
2 changes: 2 additions & 0 deletions process/factory/metachain/preProcessorsContainerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/block/preprocess"
"github.com/multiversx/mx-chain-go/process/factory/containers"
"github.com/multiversx/mx-chain-go/process/guardian/disabled"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/state"
)
Expand Down Expand Up @@ -198,6 +199,7 @@ func (ppcm *preProcessorsContainerFactory) createTxPreProcessor() (process.PrePr
ScheduledTxsExecutionHandler: ppcm.scheduledTxsExecutionHandler,
ProcessedMiniBlocksTracker: ppcm.processedMiniBlocksTracker,
TxExecutionOrderHandler: ppcm.txExecutionOrderHandler,
GuardianChecker: disabled.NewDisabledGuardedAccountHandler(),
}

txPreprocessor, err := preprocess.NewTransactionPreprocessor(args)
Expand Down
7 changes: 7 additions & 0 deletions process/factory/shard/preProcessorsContainerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type preProcessorsContainerFactory struct {
scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler
processedMiniBlocksTracker process.ProcessedMiniBlocksTracker
txExecutionOrderHandler common.TxExecutionOrderHandler
guardianChecker process.GuardianChecker
}

// NewPreProcessorsContainerFactory is responsible for creating a new preProcessors factory object
Expand All @@ -66,6 +67,7 @@ func NewPreProcessorsContainerFactory(
scheduledTxsExecutionHandler process.ScheduledTxsExecutionHandler,
processedMiniBlocksTracker process.ProcessedMiniBlocksTracker,
txExecutionOrderHandler common.TxExecutionOrderHandler,
guardianChecker process.GuardianChecker,
) (*preProcessorsContainerFactory, error) {

if check.IfNil(shardCoordinator) {
Expand Down Expand Up @@ -134,6 +136,9 @@ func NewPreProcessorsContainerFactory(
if check.IfNil(txExecutionOrderHandler) {
return nil, process.ErrNilTxExecutionOrderHandler
}
if check.IfNil(guardianChecker) {
return nil, process.ErrNilGuardianChecker
}

return &preProcessorsContainerFactory{
shardCoordinator: shardCoordinator,
Expand All @@ -158,6 +163,7 @@ func NewPreProcessorsContainerFactory(
scheduledTxsExecutionHandler: scheduledTxsExecutionHandler,
processedMiniBlocksTracker: processedMiniBlocksTracker,
txExecutionOrderHandler: txExecutionOrderHandler,
guardianChecker: guardianChecker,
}, nil
}

Expand Down Expand Up @@ -230,6 +236,7 @@ func (ppcm *preProcessorsContainerFactory) createTxPreProcessor() (process.PrePr
ScheduledTxsExecutionHandler: ppcm.scheduledTxsExecutionHandler,
ProcessedMiniBlocksTracker: ppcm.processedMiniBlocksTracker,
TxExecutionOrderHandler: ppcm.txExecutionOrderHandler,
GuardianChecker: ppcm.guardianChecker,
}

txPreprocessor, err := preprocess.NewTransactionPreprocessor(args)
Expand Down
Loading

0 comments on commit 9ff7f5c

Please sign in to comment.