Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sovereign] Clean incoming header processor argument and checks #6668

Merged
merged 2 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions factory/disabled/incomingHeaderProcessor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package disabled

import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/data/sovereign"
)

// IncomingHeaderProcessor is a disabled incoming header processor
type IncomingHeaderProcessor struct {
}

// AddHeader does nothing
func (ihp *IncomingHeaderProcessor) AddHeader(_ []byte, _ sovereign.IncomingHeaderHandler) error {
return nil
}

// CreateExtendedHeader returns an empty extended shard header
func (ihp *IncomingHeaderProcessor) CreateExtendedHeader(_ sovereign.IncomingHeaderHandler) (data.ShardHeaderExtendedHandler, error) {
return &block.ShardHeaderExtended{Header: &block.HeaderV2{}}, nil
}

// IsInterfaceNil checks if the underlying pointer is nil
func (ihp *IncomingHeaderProcessor) IsInterfaceNil() bool {
return ihp == nil
}
3 changes: 3 additions & 0 deletions factory/processing/processComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -2119,6 +2119,9 @@ func checkProcessComponentsArgs(args ProcessComponentsFactoryArgs) error {
if check.IfNil(args.RunTypeComponents.OutportDataProviderFactory()) {
return fmt.Errorf("%s: %w", baseErrMessage, errorsMx.ErrNilOutportDataProviderFactory)
}
if check.IfNil(args.IncomingHeaderSubscriber) {
return fmt.Errorf("%s: %w", baseErrMessage, errorsMx.ErrNilIncomingHeaderSubscriber)
}

return nil
}
Expand Down
9 changes: 9 additions & 0 deletions factory/processing/processComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,15 @@ func TestNewProcessComponentsFactory(t *testing.T) {
require.True(t, errors.Is(err, errorsMx.ErrNilOutportDataProviderFactory))
require.Nil(t, pcf)
})
t.Run("nil IncomingHeaderSubscriber should error", func(t *testing.T) {
t.Parallel()

args := createMockProcessComponentsFactoryArgs()
args.IncomingHeaderSubscriber = nil
pcf, err := processComp.NewProcessComponentsFactory(args)
require.True(t, errors.Is(err, errorsMx.ErrNilIncomingHeaderSubscriber))
require.Nil(t, pcf)
})
t.Run("should work", func(t *testing.T) {
t.Parallel()

Expand Down
42 changes: 22 additions & 20 deletions integrationTests/realcomponents/processorRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
factoryCore "github.com/multiversx/mx-chain-go/factory/core"
factoryCrypto "github.com/multiversx/mx-chain-go/factory/crypto"
factoryData "github.com/multiversx/mx-chain-go/factory/data"
"github.com/multiversx/mx-chain-go/factory/disabled"
factoryNetwork "github.com/multiversx/mx-chain-go/factory/network"
factoryProcessing "github.com/multiversx/mx-chain-go/factory/processing"
"github.com/multiversx/mx-chain-go/factory/runType"
Expand Down Expand Up @@ -434,26 +435,27 @@ func (pr *ProcessorRunner) createProcessComponents(tb testing.TB) {
Version: "test",
WorkingDir: pr.Config.FlagsConfig.WorkingDir,
},
SmartContractParser: smartContractParser,
GasSchedule: gasScheduleNotifier,
NodesCoordinator: pr.NodesCoordinator,
RequestedItemsHandler: requestedItemsHandler,
WhiteListHandler: whiteListRequest,
WhiteListerVerifiedTxs: whiteListerVerifiedTxs,
MaxRating: pr.Config.RatingsConfig.General.MaxRating,
SystemSCConfig: pr.Config.SystemSCConfig,
ImportStartHandler: importStartHandler,
HistoryRepo: historyRepository,
Data: pr.DataComponents,
CoreData: pr.CoreComponents,
Crypto: pr.CryptoComponents,
State: pr.StateComponents,
Network: pr.NetworkComponents,
BootstrapComponents: pr.BootstrapComponents,
StatusComponents: pr.StatusComponents,
StatusCoreComponents: pr.StatusCoreComponents,
TxExecutionOrderHandler: txExecutionOrderHandler,
RunTypeComponents: pr.RunTypeComponents,
SmartContractParser: smartContractParser,
GasSchedule: gasScheduleNotifier,
NodesCoordinator: pr.NodesCoordinator,
RequestedItemsHandler: requestedItemsHandler,
WhiteListHandler: whiteListRequest,
WhiteListerVerifiedTxs: whiteListerVerifiedTxs,
MaxRating: pr.Config.RatingsConfig.General.MaxRating,
SystemSCConfig: pr.Config.SystemSCConfig,
ImportStartHandler: importStartHandler,
HistoryRepo: historyRepository,
Data: pr.DataComponents,
CoreData: pr.CoreComponents,
Crypto: pr.CryptoComponents,
State: pr.StateComponents,
Network: pr.NetworkComponents,
BootstrapComponents: pr.BootstrapComponents,
StatusComponents: pr.StatusComponents,
StatusCoreComponents: pr.StatusCoreComponents,
TxExecutionOrderHandler: txExecutionOrderHandler,
RunTypeComponents: pr.RunTypeComponents,
IncomingHeaderSubscriber: &disabled.IncomingHeaderProcessor{},
}

processFactory, err := factoryProcessing.NewProcessComponentsFactory(argsProcess)
Expand Down
56 changes: 29 additions & 27 deletions node/nodeRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
coreComp "github.com/multiversx/mx-chain-go/factory/core"
cryptoComp "github.com/multiversx/mx-chain-go/factory/crypto"
dataComp "github.com/multiversx/mx-chain-go/factory/data"
factoryDisabled "github.com/multiversx/mx-chain-go/factory/disabled"
heartbeatComp "github.com/multiversx/mx-chain-go/factory/heartbeat"
networkComp "github.com/multiversx/mx-chain-go/factory/network"
processComp "github.com/multiversx/mx-chain-go/factory/processing"
Expand Down Expand Up @@ -1236,33 +1237,34 @@ func (nr *nodeRunner) CreateManagedProcessComponents(
txExecutionOrderHandler := ordering.NewOrderedCollection()

processArgs := processComp.ProcessComponentsFactoryArgs{
Config: *configs.GeneralConfig,
EpochConfig: *configs.EpochConfig,
RoundConfig: *configs.RoundConfig,
PrefConfigs: *configs.PreferencesConfig,
ImportDBConfig: *configs.ImportDbConfig,
EconomicsConfig: *configs.EconomicsConfig,
SmartContractParser: smartContractParser,
GasSchedule: gasScheduleNotifier,
NodesCoordinator: nodesCoordinator,
Data: dataComponents,
CoreData: coreComponents,
Crypto: cryptoComponents,
State: stateComponents,
Network: networkComponents,
BootstrapComponents: bootstrapComponents,
StatusComponents: statusComponents,
StatusCoreComponents: statusCoreComponents,
RequestedItemsHandler: requestedItemsHandler,
WhiteListHandler: whiteListRequest,
WhiteListerVerifiedTxs: whiteListerVerifiedTxs,
MaxRating: configs.RatingsConfig.General.MaxRating,
SystemSCConfig: configs.SystemSCConfig,
ImportStartHandler: importStartHandler,
HistoryRepo: historyRepository,
FlagsConfig: *configs.FlagsConfig,
TxExecutionOrderHandler: txExecutionOrderHandler,
RunTypeComponents: runTypeComponents,
Config: *configs.GeneralConfig,
EpochConfig: *configs.EpochConfig,
RoundConfig: *configs.RoundConfig,
PrefConfigs: *configs.PreferencesConfig,
ImportDBConfig: *configs.ImportDbConfig,
EconomicsConfig: *configs.EconomicsConfig,
SmartContractParser: smartContractParser,
GasSchedule: gasScheduleNotifier,
NodesCoordinator: nodesCoordinator,
Data: dataComponents,
CoreData: coreComponents,
Crypto: cryptoComponents,
State: stateComponents,
Network: networkComponents,
BootstrapComponents: bootstrapComponents,
StatusComponents: statusComponents,
StatusCoreComponents: statusCoreComponents,
RequestedItemsHandler: requestedItemsHandler,
WhiteListHandler: whiteListRequest,
WhiteListerVerifiedTxs: whiteListerVerifiedTxs,
MaxRating: configs.RatingsConfig.General.MaxRating,
SystemSCConfig: configs.SystemSCConfig,
ImportStartHandler: importStartHandler,
HistoryRepo: historyRepository,
FlagsConfig: *configs.FlagsConfig,
TxExecutionOrderHandler: txExecutionOrderHandler,
RunTypeComponents: runTypeComponents,
IncomingHeaderSubscriber: &factoryDisabled.IncomingHeaderProcessor{},
}
processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions testscommon/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ func GetProcessArgs(
},
},
},
IncomingHeaderSubscriber: &sovereign.IncomingHeaderSubscriberStub{},
}

initialAccounts := createAccounts()
Expand Down
Loading