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

Message validation optimization #6462

Merged
merged 47 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
10afdba
initial commit.
cristure Sep 12, 2024
aaa9d4b
added test for processing message.
cristure Sep 13, 2024
603bd69
added message validation cache.
cristure Sep 16, 2024
57f009e
fix some tests.
cristure Sep 16, 2024
f5a6f2e
fixed missing topic.
cristure Sep 16, 2024
8eec330
fix some more tests.
cristure Sep 17, 2024
a733097
fix nil pointer dereferences in tests.
cristure Sep 17, 2024
bab3b05
more tests fixed.
cristure Sep 17, 2024
c3f7120
add map for cacher in more unit tests.
cristure Sep 17, 2024
b62e37b
fix nil map for more tests.
cristure Sep 17, 2024
c00f8ee
fix process tests.
cristure Sep 17, 2024
94a64c1
Merge branch 'feat/equivalent-messages' into message_validation_optim…
cristure Sep 17, 2024
d77e367
Merge remote-tracking branch 'origin/feat/equivalent-messages' into m…
cristure Sep 18, 2024
d59c5bd
fix conflicts with target branch.
cristure Sep 18, 2024
396cd8e
refactored message validation to a different component.
cristure Sep 19, 2024
a44129f
cosmetic changes.
cristure Sep 20, 2024
afdceb1
added intercepted data verifier stub in multi data tests.
cristure Sep 20, 2024
d8d8113
fix single data interceptor tests.
cristure Sep 20, 2024
fe2082c
commit debug strings for CI.
cristure Sep 20, 2024
c6b7a0f
moved map of cachers in node processor.
cristure Sep 20, 2024
f59fc85
cosmetic changes.
cristure Sep 20, 2024
d00c7ab
fix integration tests.
cristure Sep 20, 2024
f21e24f
fix some more tests.
cristure Sep 20, 2024
f40d222
fix some unit tests.
cristure Sep 23, 2024
3a327c4
fix nil map in tests.
cristure Sep 23, 2024
a756a1f
Merge branch 'feat/equivalent-messages' into message_validation_optim…
cristure Sep 23, 2024
ff8eaa9
Merge remote-tracking branch 'origin/feat/equivalent-messages' into m…
cristure Sep 25, 2024
cde6c80
cosmetic changes.
cristure Sep 25, 2024
e0cf24b
Merge remote-tracking branch 'origin/message_validation_optimization'…
cristure Sep 25, 2024
9504263
refactored map of caches for intercepted data into a new component.
cristure Sep 25, 2024
b622085
added mock for interceptedDataVerifierFactory and injected into tests.
cristure Sep 26, 2024
f0b34ef
more test fixes.
cristure Sep 26, 2024
b05c650
increase wait time for CI run.
cristure Sep 26, 2024
5dc6bba
bring back rw mutex on interceptedDataVerifier.
cristure Sep 26, 2024
d214027
fixes after review.
cristure Sep 30, 2024
899b04d
split test and improved lock mechanism.
cristure Oct 1, 2024
959e037
Update node/nodeRunner.go
cristure Oct 2, 2024
7762f62
addressed some comments.
cristure Oct 2, 2024
23dbb5a
more fixes.
cristure Oct 3, 2024
b9eb2a5
fix unit tests.
cristure Oct 3, 2024
0deeb37
Merge branch 'feat/equivalent-messages' into message_validation_optim…
sstanculeanu Oct 3, 2024
8451f62
added close to intercepted data cacher and a few unit tests on nil ch…
cristure Oct 3, 2024
130e115
Merge remote-tracking branch 'origin/message_validation_optimization'…
cristure Oct 3, 2024
754fae3
Merge branch 'feat/equivalent-messages' into message_validation_optim…
sstanculeanu Oct 3, 2024
8dd18b8
cosmetic changes.
cristure Oct 3, 2024
1b11cb8
Merge remote-tracking branch 'origin/message_validation_optimization'…
cristure Oct 3, 2024
111fdb1
Merge branch 'feat/equivalent-messages' into message_validation_optim…
AdoAdoAdo Oct 4, 2024
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
4 changes: 4 additions & 0 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,7 @@
# All validators will broadcast the message right away
{ EndIndex = 0, DelayInMilliseconds = 0 },
]

[InterceptedDataVerifier]
CacheSpanInSec = 30
CacheExpiryInSec = 30
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ type Config struct {
PoolsCleanersConfig PoolsCleanersConfig
Redundancy RedundancyConfig
ConsensusGradualBroadcast ConsensusGradualBroadcastConfig

InterceptedDataVerifier InterceptedDataVerifierConfig
}

// PeersRatingConfig will hold settings related to peers rating
Expand Down Expand Up @@ -679,3 +681,9 @@ type IndexBroadcastDelay struct {
type ConsensusGradualBroadcastConfig struct {
GradualIndexBroadcastDelay []IndexBroadcastDelay
}

// InterceptedDataVerifierConfig holds the configuration for the intercepted data verifier
type InterceptedDataVerifierConfig struct {
CacheSpanInSec uint64
CacheExpiryInSec uint64
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data/typeConverters"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
Expand All @@ -25,23 +26,24 @@ const timeSpanForBadHeaders = time.Minute
// ArgsEpochStartInterceptorContainer holds the arguments needed for creating a new epoch start interceptors
// container factory
type ArgsEpochStartInterceptorContainer struct {
CoreComponents process.CoreComponentsHolder
CryptoComponents process.CryptoComponentsHolder
Config config.Config
ShardCoordinator sharding.Coordinator
MainMessenger process.TopicHandler
FullArchiveMessenger process.TopicHandler
DataPool dataRetriever.PoolsHolder
WhiteListHandler update.WhiteListHandler
WhiteListerVerifiedTxs update.WhiteListHandler
AddressPubkeyConv core.PubkeyConverter
NonceConverter typeConverters.Uint64ByteSliceConverter
ChainID []byte
ArgumentsParser process.ArgumentsParser
HeaderIntegrityVerifier process.HeaderIntegrityVerifier
RequestHandler process.RequestHandler
SignaturesHandler process.SignaturesHandler
NodeOperationMode common.NodeOperation
CoreComponents process.CoreComponentsHolder
CryptoComponents process.CryptoComponentsHolder
Config config.Config
ShardCoordinator sharding.Coordinator
MainMessenger process.TopicHandler
FullArchiveMessenger process.TopicHandler
DataPool dataRetriever.PoolsHolder
WhiteListHandler update.WhiteListHandler
WhiteListerVerifiedTxs update.WhiteListHandler
AddressPubkeyConv core.PubkeyConverter
NonceConverter typeConverters.Uint64ByteSliceConverter
ChainID []byte
ArgumentsParser process.ArgumentsParser
HeaderIntegrityVerifier process.HeaderIntegrityVerifier
RequestHandler process.RequestHandler
SignaturesHandler process.SignaturesHandler
NodeOperationMode common.NodeOperation
InterceptedDataVerifierFactory process.InterceptedDataVerifierFactory
}

// NewEpochStartInterceptorsContainer will return a real interceptors container factory, but with many disabled components
Expand Down Expand Up @@ -78,36 +80,37 @@ func NewEpochStartInterceptorsContainer(args ArgsEpochStartInterceptorContainer)
hardforkTrigger := disabledFactory.HardforkTrigger()

containerFactoryArgs := interceptorscontainer.CommonInterceptorsContainerFactoryArgs{
CoreComponents: args.CoreComponents,
CryptoComponents: cryptoComponents,
Accounts: accountsAdapter,
ShardCoordinator: args.ShardCoordinator,
NodesCoordinator: nodesCoordinator,
MainMessenger: args.MainMessenger,
FullArchiveMessenger: args.FullArchiveMessenger,
Store: storer,
DataPool: args.DataPool,
MaxTxNonceDeltaAllowed: common.MaxTxNonceDeltaAllowed,
TxFeeHandler: feeHandler,
BlockBlackList: blackListHandler,
HeaderSigVerifier: headerSigVerifier,
HeaderIntegrityVerifier: args.HeaderIntegrityVerifier,
ValidityAttester: validityAttester,
EpochStartTrigger: epochStartTrigger,
WhiteListHandler: args.WhiteListHandler,
WhiteListerVerifiedTxs: args.WhiteListerVerifiedTxs,
AntifloodHandler: antiFloodHandler,
ArgumentsParser: args.ArgumentsParser,
PreferredPeersHolder: disabled.NewPreferredPeersHolder(),
SizeCheckDelta: uint32(sizeCheckDelta),
RequestHandler: args.RequestHandler,
PeerSignatureHandler: cryptoComponents.PeerSignatureHandler(),
SignaturesHandler: args.SignaturesHandler,
HeartbeatExpiryTimespanInSec: args.Config.HeartbeatV2.HeartbeatExpiryTimespanInSec,
MainPeerShardMapper: peerShardMapper,
FullArchivePeerShardMapper: fullArchivePeerShardMapper,
HardforkTrigger: hardforkTrigger,
NodeOperationMode: args.NodeOperationMode,
CoreComponents: args.CoreComponents,
CryptoComponents: cryptoComponents,
Accounts: accountsAdapter,
ShardCoordinator: args.ShardCoordinator,
NodesCoordinator: nodesCoordinator,
MainMessenger: args.MainMessenger,
FullArchiveMessenger: args.FullArchiveMessenger,
Store: storer,
DataPool: args.DataPool,
MaxTxNonceDeltaAllowed: common.MaxTxNonceDeltaAllowed,
TxFeeHandler: feeHandler,
BlockBlackList: blackListHandler,
HeaderSigVerifier: headerSigVerifier,
HeaderIntegrityVerifier: args.HeaderIntegrityVerifier,
ValidityAttester: validityAttester,
EpochStartTrigger: epochStartTrigger,
WhiteListHandler: args.WhiteListHandler,
WhiteListerVerifiedTxs: args.WhiteListerVerifiedTxs,
AntifloodHandler: antiFloodHandler,
ArgumentsParser: args.ArgumentsParser,
PreferredPeersHolder: disabled.NewPreferredPeersHolder(),
SizeCheckDelta: uint32(sizeCheckDelta),
RequestHandler: args.RequestHandler,
PeerSignatureHandler: cryptoComponents.PeerSignatureHandler(),
SignaturesHandler: args.SignaturesHandler,
HeartbeatExpiryTimespanInSec: args.Config.HeartbeatV2.HeartbeatExpiryTimespanInSec,
MainPeerShardMapper: peerShardMapper,
FullArchivePeerShardMapper: fullArchivePeerShardMapper,
HardforkTrigger: hardforkTrigger,
NodeOperationMode: args.NodeOperationMode,
InterceptedDataVerifierFactory: args.InterceptedDataVerifierFactory,
}

interceptorsContainerFactory, err := interceptorscontainer.NewMetaInterceptorsContainerFactory(containerFactoryArgs)
Expand Down
57 changes: 32 additions & 25 deletions epochStart/bootstrap/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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/typeConverters/uint64ByteSlice"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common"
disabledCommon "github.com/multiversx/mx-chain-go/common/disabled"
"github.com/multiversx/mx-chain-go/common/ordering"
Expand Down Expand Up @@ -52,7 +54,6 @@ import (
"github.com/multiversx/mx-chain-go/trie/storageMarker"
"github.com/multiversx/mx-chain-go/update"
updateSync "github.com/multiversx/mx-chain-go/update/sync"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("epochStart/bootstrap")
Expand Down Expand Up @@ -152,6 +153,8 @@ type epochStartBootstrap struct {
nodeType core.NodeType
startEpoch uint32
shuffledOut bool

interceptedDataVerifierFactory process.InterceptedDataVerifierFactory
}

type baseDataInStorage struct {
Expand Down Expand Up @@ -190,6 +193,7 @@ type ArgsEpochStartBootstrap struct {
NodeProcessingMode common.NodeProcessingMode
StateStatsHandler common.StateStatisticsHandler
NodesCoordinatorRegistryFactory nodesCoordinator.NodesCoordinatorRegistryFactory
InterceptedDataVerifierFactory process.InterceptedDataVerifierFactory
}

type dataToSync struct {
Expand Down Expand Up @@ -242,6 +246,7 @@ func NewEpochStartBootstrap(args ArgsEpochStartBootstrap) (*epochStartBootstrap,
stateStatsHandler: args.StateStatsHandler,
startEpoch: args.GeneralConfig.EpochStartConfig.GenesisEpoch,
nodesCoordinatorRegistryFactory: args.NodesCoordinatorRegistryFactory,
interceptedDataVerifierFactory: args.InterceptedDataVerifierFactory,
}

if epochStartProvider.prefsConfig.FullArchive {
Expand Down Expand Up @@ -553,16 +558,17 @@ func (e *epochStartBootstrap) prepareComponentsToSyncFromNetwork() error {
}

argsEpochStartSyncer := ArgsNewEpochStartMetaSyncer{
CoreComponentsHolder: e.coreComponentsHolder,
CryptoComponentsHolder: e.cryptoComponentsHolder,
RequestHandler: e.requestHandler,
Messenger: e.mainMessenger,
ShardCoordinator: e.shardCoordinator,
EconomicsData: e.economicsData,
WhitelistHandler: e.whiteListHandler,
StartInEpochConfig: epochStartConfig,
HeaderIntegrityVerifier: e.headerIntegrityVerifier,
MetaBlockProcessor: metaBlockProcessor,
CoreComponentsHolder: e.coreComponentsHolder,
CryptoComponentsHolder: e.cryptoComponentsHolder,
RequestHandler: e.requestHandler,
Messenger: e.mainMessenger,
ShardCoordinator: e.shardCoordinator,
EconomicsData: e.economicsData,
WhitelistHandler: e.whiteListHandler,
StartInEpochConfig: epochStartConfig,
HeaderIntegrityVerifier: e.headerIntegrityVerifier,
MetaBlockProcessor: metaBlockProcessor,
InterceptedDataVerifierFactory: e.interceptedDataVerifierFactory,
}
e.epochStartMetaBlockSyncer, err = NewEpochStartMetaSyncer(argsEpochStartSyncer)
if err != nil {
Expand All @@ -575,20 +581,21 @@ func (e *epochStartBootstrap) prepareComponentsToSyncFromNetwork() error {
func (e *epochStartBootstrap) createSyncers() error {
var err error
args := factoryInterceptors.ArgsEpochStartInterceptorContainer{
CoreComponents: e.coreComponentsHolder,
CryptoComponents: e.cryptoComponentsHolder,
Config: e.generalConfig,
ShardCoordinator: e.shardCoordinator,
MainMessenger: e.mainMessenger,
FullArchiveMessenger: e.fullArchiveMessenger,
DataPool: e.dataPool,
WhiteListHandler: e.whiteListHandler,
WhiteListerVerifiedTxs: e.whiteListerVerifiedTxs,
ArgumentsParser: e.argumentsParser,
HeaderIntegrityVerifier: e.headerIntegrityVerifier,
RequestHandler: e.requestHandler,
SignaturesHandler: e.mainMessenger,
NodeOperationMode: e.nodeOperationMode,
CoreComponents: e.coreComponentsHolder,
CryptoComponents: e.cryptoComponentsHolder,
Config: e.generalConfig,
ShardCoordinator: e.shardCoordinator,
MainMessenger: e.mainMessenger,
FullArchiveMessenger: e.fullArchiveMessenger,
DataPool: e.dataPool,
WhiteListHandler: e.whiteListHandler,
WhiteListerVerifiedTxs: e.whiteListerVerifiedTxs,
ArgumentsParser: e.argumentsParser,
HeaderIntegrityVerifier: e.headerIntegrityVerifier,
RequestHandler: e.requestHandler,
SignaturesHandler: e.mainMessenger,
NodeOperationMode: e.nodeOperationMode,
InterceptedDataVerifierFactory: e.interceptedDataVerifierFactory,
}

e.mainInterceptorContainer, e.fullArchiveInterceptorContainer, err = factoryInterceptors.NewEpochStartInterceptorsContainer(args)
Expand Down
7 changes: 5 additions & 2 deletions epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/multiversx/mx-chain-go/epochStart/bootstrap/types"
"github.com/multiversx/mx-chain-go/epochStart/mock"
"github.com/multiversx/mx-chain-go/process"
processMock "github.com/multiversx/mx-chain-go/process/mock"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/state"
Expand Down Expand Up @@ -251,8 +252,9 @@ func createMockEpochStartBootstrapArgs(
FlagsConfig: config.ContextFlagsConfig{
ForceStartFromNetwork: false,
},
TrieSyncStatisticsProvider: &testscommon.SizeSyncStatisticsHandlerStub{},
StateStatsHandler: disabledStatistics.NewStateStatistics(),
TrieSyncStatisticsProvider: &testscommon.SizeSyncStatisticsHandlerStub{},
StateStatsHandler: disabledStatistics.NewStateStatistics(),
InterceptedDataVerifierFactory: &processMock.InterceptedDataVerifierFactoryMock{},
}
}

Expand Down Expand Up @@ -994,6 +996,7 @@ func TestCreateSyncers(t *testing.T) {
epochStartProvider.whiteListerVerifiedTxs = &testscommon.WhiteListHandlerStub{}
epochStartProvider.requestHandler = &testscommon.RequestHandlerStub{}
epochStartProvider.storageService = &storageMocks.ChainStorerStub{}
epochStartProvider.interceptedDataVerifierFactory = &processMock.InterceptedDataVerifierFactoryMock{}

err := epochStartProvider.createSyncers()
assert.Nil(t, err)
Expand Down
22 changes: 12 additions & 10 deletions epochStart/bootstrap/storageProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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/endProcess"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
Expand Down Expand Up @@ -177,16 +178,17 @@ func (sesb *storageEpochStartBootstrap) prepareComponentsToSync() error {
}

argsEpochStartSyncer := ArgsNewEpochStartMetaSyncer{
CoreComponentsHolder: sesb.coreComponentsHolder,
CryptoComponentsHolder: sesb.cryptoComponentsHolder,
RequestHandler: sesb.requestHandler,
Messenger: sesb.mainMessenger,
ShardCoordinator: sesb.shardCoordinator,
EconomicsData: sesb.economicsData,
WhitelistHandler: sesb.whiteListHandler,
StartInEpochConfig: sesb.generalConfig.EpochStartConfig,
HeaderIntegrityVerifier: sesb.headerIntegrityVerifier,
MetaBlockProcessor: metablockProcessor,
CoreComponentsHolder: sesb.coreComponentsHolder,
CryptoComponentsHolder: sesb.cryptoComponentsHolder,
RequestHandler: sesb.requestHandler,
Messenger: sesb.mainMessenger,
ShardCoordinator: sesb.shardCoordinator,
EconomicsData: sesb.economicsData,
WhitelistHandler: sesb.whiteListHandler,
StartInEpochConfig: sesb.generalConfig.EpochStartConfig,
HeaderIntegrityVerifier: sesb.headerIntegrityVerifier,
MetaBlockProcessor: metablockProcessor,
InterceptedDataVerifierFactory: sesb.interceptedDataVerifierFactory,
}

sesb.epochStartMetaBlockSyncer, err = NewEpochStartMetaSyncer(argsEpochStartSyncer)
Expand Down
5 changes: 4 additions & 1 deletion epochStart/bootstrap/storageProcess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ 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/endProcess"
"github.com/stretchr/testify/assert"

"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/epochStart/mock"
"github.com/multiversx/mx-chain-go/process"
processMock "github.com/multiversx/mx-chain-go/process/mock"
"github.com/multiversx/mx-chain-go/sharding/nodesCoordinator"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/testscommon"
epochStartMocks "github.com/multiversx/mx-chain-go/testscommon/bootstrapMocks/epochStart"
dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever"
"github.com/multiversx/mx-chain-go/testscommon/economicsmocks"
"github.com/multiversx/mx-chain-go/testscommon/genesisMocks"
"github.com/stretchr/testify/assert"
)

func createMockStorageEpochStartBootstrapArgs(
Expand Down Expand Up @@ -127,6 +129,7 @@ func TestStorageEpochStartBootstrap_BootstrapMetablockNotFound(t *testing.T) {
}
args.GeneralConfig = testscommon.GetGeneralConfig()
args.GeneralConfig.EpochStartConfig.RoundsPerEpoch = roundsPerEpoch
args.InterceptedDataVerifierFactory = &processMock.InterceptedDataVerifierFactoryMock{}
sesb, _ := NewStorageEpochStartBootstrap(args)

params, err := sesb.Bootstrap()
Expand Down
Loading
Loading