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 26 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
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 @@ -16,6 +17,7 @@ import (
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/factory/interceptorscontainer"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/storage/cache"
"github.com/multiversx/mx-chain-go/update"
)
Expand Down Expand Up @@ -108,6 +110,7 @@ func NewEpochStartInterceptorsContainer(args ArgsEpochStartInterceptorContainer)
FullArchivePeerShardMapper: fullArchivePeerShardMapper,
HardforkTrigger: hardforkTrigger,
NodeOperationMode: args.NodeOperationMode,
ProcessedMessagesCacheMap: make(map[string]storage.Cacher),
AdoAdoAdo marked this conversation as resolved.
Show resolved Hide resolved
}

interceptorsContainerFactory, err := interceptorscontainer.NewMetaInterceptorsContainerFactory(containerFactoryArgs)
Expand Down
8 changes: 7 additions & 1 deletion 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

interceptedDataCache map[string]storage.Cacher
}

type baseDataInStorage struct {
Expand Down Expand Up @@ -190,6 +193,7 @@ type ArgsEpochStartBootstrap struct {
NodeProcessingMode common.NodeProcessingMode
StateStatsHandler common.StateStatisticsHandler
NodesCoordinatorRegistryFactory nodesCoordinator.NodesCoordinatorRegistryFactory
InterceptedDataCache map[string]storage.Cacher
}

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,
interceptedDataCache: args.InterceptedDataCache,
}

if epochStartProvider.prefsConfig.FullArchive {
Expand Down Expand Up @@ -563,6 +568,7 @@ func (e *epochStartBootstrap) prepareComponentsToSyncFromNetwork() error {
StartInEpochConfig: epochStartConfig,
HeaderIntegrityVerifier: e.headerIntegrityVerifier,
MetaBlockProcessor: metaBlockProcessor,
InterceptedDataCache: e.interceptedDataCache,
}
e.epochStartMetaBlockSyncer, err = NewEpochStartMetaSyncer(argsEpochStartSyncer)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func createMockEpochStartBootstrapArgs(
},
TrieSyncStatisticsProvider: &testscommon.SizeSyncStatisticsHandlerStub{},
StateStatsHandler: disabledStatistics.NewStateStatistics(),
InterceptedDataCache: make(map[string]storage.Cacher),
}
}

Expand Down
2 changes: 2 additions & 0 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 @@ -187,6 +188,7 @@ func (sesb *storageEpochStartBootstrap) prepareComponentsToSync() error {
StartInEpochConfig: sesb.generalConfig.EpochStartConfig,
HeaderIntegrityVerifier: sesb.headerIntegrityVerifier,
MetaBlockProcessor: metablockProcessor,
InterceptedDataCache: sesb.interceptedDataCache,
}

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

func createMockStorageEpochStartBootstrapArgs(
Expand Down Expand Up @@ -127,6 +128,7 @@ func TestStorageEpochStartBootstrap_BootstrapMetablockNotFound(t *testing.T) {
}
args.GeneralConfig = testscommon.GetGeneralConfig()
args.GeneralConfig.EpochStartConfig.RoundsPerEpoch = roundsPerEpoch
args.InterceptedDataCache = make(map[string]storage.Cacher)
sesb, _ := NewStorageEpochStartBootstrap(args)

params, err := sesb.Bootstrap()
Expand Down
69 changes: 50 additions & 19 deletions epochStart/bootstrap/syncEpochStartMeta.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/epochStart"
Expand All @@ -17,17 +18,25 @@ import (
"github.com/multiversx/mx-chain-go/process/interceptors"
interceptorsFactory "github.com/multiversx/mx-chain-go/process/interceptors/factory"
"github.com/multiversx/mx-chain-go/sharding"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/storage/cache"
)

const (
cacheDefaultSpan = 30 * time.Second
cacheDefaultExpiry = 30 * time.Second
)

var _ epochStart.StartOfEpochMetaSyncer = (*epochStartMetaSyncer)(nil)

type epochStartMetaSyncer struct {
requestHandler RequestHandler
messenger Messenger
marshalizer marshal.Marshalizer
hasher hashing.Hasher
singleDataInterceptor process.Interceptor
metaBlockProcessor EpochStartMetaBlockInterceptorProcessor
requestHandler RequestHandler
messenger Messenger
marshalizer marshal.Marshalizer
hasher hashing.Hasher
singleDataInterceptor process.Interceptor
metaBlockProcessor EpochStartMetaBlockInterceptorProcessor
interceptedDataCacheMap map[string]storage.Cacher
}

// ArgsNewEpochStartMetaSyncer -
Expand All @@ -43,6 +52,7 @@ type ArgsNewEpochStartMetaSyncer struct {
ArgsParser process.ArgumentsParser
HeaderIntegrityVerifier process.HeaderIntegrityVerifier
MetaBlockProcessor EpochStartMetaBlockInterceptorProcessor
InterceptedDataCache map[string]storage.Cacher
}

// NewEpochStartMetaSyncer will return a new instance of epochStartMetaSyncer
Expand All @@ -64,11 +74,12 @@ func NewEpochStartMetaSyncer(args ArgsNewEpochStartMetaSyncer) (*epochStartMetaS
}

e := &epochStartMetaSyncer{
requestHandler: args.RequestHandler,
messenger: args.Messenger,
marshalizer: args.CoreComponentsHolder.InternalMarshalizer(),
hasher: args.CoreComponentsHolder.Hasher(),
metaBlockProcessor: args.MetaBlockProcessor,
requestHandler: args.RequestHandler,
messenger: args.Messenger,
marshalizer: args.CoreComponentsHolder.InternalMarshalizer(),
hasher: args.CoreComponentsHolder.Hasher(),
metaBlockProcessor: args.MetaBlockProcessor,
interceptedDataCacheMap: args.InterceptedDataCache,
}

argsInterceptedDataFactory := interceptorsFactory.ArgInterceptedDataFactory{
Expand All @@ -89,16 +100,22 @@ func NewEpochStartMetaSyncer(args ArgsNewEpochStartMetaSyncer) (*epochStartMetaS
return nil, err
}

interceptedDataVerifier, err := e.createCacheForInterceptor(factory.MetachainBlocksTopic)
if err != nil {
return nil, err
}

e.singleDataInterceptor, err = interceptors.NewSingleDataInterceptor(
interceptors.ArgSingleDataInterceptor{
Topic: factory.MetachainBlocksTopic,
DataFactory: interceptedMetaHdrDataFactory,
Processor: args.MetaBlockProcessor,
Throttler: disabled.NewThrottler(),
AntifloodHandler: disabled.NewAntiFloodHandler(),
WhiteListRequest: args.WhitelistHandler,
CurrentPeerId: args.Messenger.ID(),
PreferredPeersHolder: disabled.NewPreferredPeersHolder(),
Topic: factory.MetachainBlocksTopic,
DataFactory: interceptedMetaHdrDataFactory,
Processor: args.MetaBlockProcessor,
Throttler: disabled.NewThrottler(),
AntifloodHandler: disabled.NewAntiFloodHandler(),
WhiteListRequest: args.WhitelistHandler,
CurrentPeerId: args.Messenger.ID(),
PreferredPeersHolder: disabled.NewPreferredPeersHolder(),
InterceptedDataVerifier: interceptedDataVerifier,
},
)
if err != nil {
Expand Down Expand Up @@ -152,6 +169,20 @@ func (e *epochStartMetaSyncer) initTopicForEpochStartMetaBlockInterceptor() erro
return nil
}

func (e *epochStartMetaSyncer) createCacheForInterceptor(topic string) (process.InterceptedDataVerifier, error) {
internalCache, err := cache.NewTimeCacher(cache.ArgTimeCacher{
DefaultSpan: cacheDefaultSpan,
CacheExpiry: cacheDefaultExpiry,
})
if err != nil {
return nil, err
}

e.interceptedDataCacheMap[topic] = internalCache
verifier := interceptors.NewInterceptedDataVerifier(internalCache)
return verifier, nil
}

// IsInterfaceNil returns true if underlying object is nil
func (e *epochStartMetaSyncer) IsInterfaceNil() bool {
return e == nil
Expand Down
7 changes: 5 additions & 2 deletions epochStart/bootstrap/syncEpochStartMeta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/epochStart/mock"
"github.com/multiversx/mx-chain-go/p2p"
"github.com/multiversx/mx-chain-go/storage"
"github.com/multiversx/mx-chain-go/testscommon"
"github.com/multiversx/mx-chain-go/testscommon/cryptoMocks"
"github.com/multiversx/mx-chain-go/testscommon/economicsmocks"
"github.com/multiversx/mx-chain-go/testscommon/hashingMocks"
"github.com/multiversx/mx-chain-go/testscommon/p2pmocks"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestNewEpochStartMetaSyncer_NilsShouldError(t *testing.T) {
Expand Down Expand Up @@ -161,5 +163,6 @@ func getEpochStartSyncerArgs() ArgsNewEpochStartMetaSyncer {
},
HeaderIntegrityVerifier: &mock.HeaderIntegrityVerifierStub{},
MetaBlockProcessor: &mock.EpochStartMetaBlockProcessorStub{},
InterceptedDataCache: make(map[string]storage.Cacher),
}
}
24 changes: 13 additions & 11 deletions factory/bootstrap/bootstrapComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
logger "github.com/multiversx/mx-chain-logger-go"

nodeFactory "github.com/multiversx/mx-chain-go/cmd/node/factory"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
Expand All @@ -24,23 +26,23 @@ import (
storageFactory "github.com/multiversx/mx-chain-go/storage/factory"
"github.com/multiversx/mx-chain-go/storage/latestData"
"github.com/multiversx/mx-chain-go/storage/storageunit"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("factory")

// BootstrapComponentsFactoryArgs holds the arguments needed to create a bootstrap components factory
type BootstrapComponentsFactoryArgs struct {
Config config.Config
RoundConfig config.RoundConfig
PrefConfig config.Preferences
ImportDbConfig config.ImportDbConfig
FlagsConfig config.ContextFlagsConfig
WorkingDir string
CoreComponents factory.CoreComponentsHolder
CryptoComponents factory.CryptoComponentsHolder
NetworkComponents factory.NetworkComponentsHolder
StatusCoreComponents factory.StatusCoreComponentsHolder
Config config.Config
RoundConfig config.RoundConfig
PrefConfig config.Preferences
ImportDbConfig config.ImportDbConfig
FlagsConfig config.ContextFlagsConfig
WorkingDir string
CoreComponents factory.CoreComponentsHolder
CryptoComponents factory.CryptoComponentsHolder
NetworkComponents factory.NetworkComponentsHolder
StatusCoreComponents factory.StatusCoreComponentsHolder
InterceptedDataCacheMap map[string]storage.Cacher
}

type bootstrapComponentsFactory struct {
Expand Down
Loading
Loading