Skip to content

Commit

Permalink
Merge pull request #3883 from ElrondNetwork/EN-11664-nodes-coordinato…
Browse files Browse the repository at this point in the history
…r-staking-v4

Nodes coordinator with staking v4
  • Loading branch information
mariusmihaic committed Mar 24, 2022
2 parents 837d416 + 6092f80 commit 8a122e8
Show file tree
Hide file tree
Showing 46 changed files with 3,596 additions and 745 deletions.
2 changes: 1 addition & 1 deletion epochStart/bootstrap/baseStorageHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (bsh *baseStorageHandler) groupMiniBlocksByShard(miniBlocks map[string]*blo

func (bsh *baseStorageHandler) saveNodesCoordinatorRegistry(
metaBlock data.HeaderHandler,
nodesConfig *nodesCoordinator.NodesCoordinatorRegistry,
nodesConfig nodesCoordinator.NodesCoordinatorRegistryHandler,
) ([]byte, error) {
key := append([]byte(common.NodesCoordinatorRegistryKeyPrefix), metaBlock.GetPrevRandSeed()...)

Expand Down
4 changes: 4 additions & 0 deletions epochStart/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go/epochStart"
"github.com/ElrondNetwork/elrond-go/sharding/nodesCoordinator"
)

const baseErrorMessage = "error with epoch start bootstrapper arguments"
Expand Down Expand Up @@ -106,6 +107,9 @@ func checkArguments(args ArgsEpochStartBootstrap) error {
if args.GeneralConfig.TrieSync.NumConcurrentTrieSyncers < 1 {
return fmt.Errorf("%s: %w", baseErrorMessage, epochStart.ErrInvalidNumConcurrentTrieSyncers)
}
if check.IfNil(args.NodesCoordinatorRegistryFactory) {
return fmt.Errorf("%s: %w", baseErrorMessage, nodesCoordinator.ErrNilNodesCoordinatorRegistryFactory)
}

return nil
}
14 changes: 6 additions & 8 deletions epochStart/bootstrap/fromLocalStorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bootstrap

import (
"bytes"
"encoding/json"
"fmt"
"strconv"

Expand Down Expand Up @@ -192,19 +191,19 @@ func (e *epochStartBootstrap) prepareEpochFromStorage() (Parameters, error) {

func (e *epochStartBootstrap) checkIfShuffledOut(
pubKey []byte,
nodesConfig *nodesCoordinator.NodesCoordinatorRegistry,
nodesConfig nodesCoordinator.NodesCoordinatorRegistryHandler,
) (uint32, bool) {
epochIDasString := fmt.Sprint(e.baseData.lastEpoch)
epochConfig := nodesConfig.EpochsConfig[epochIDasString]
epochConfig := nodesConfig.GetEpochsConfig()[epochIDasString]

newShardId, isWaitingForShard := checkIfPubkeyIsInMap(pubKey, epochConfig.WaitingValidators)
newShardId, isWaitingForShard := checkIfPubkeyIsInMap(pubKey, epochConfig.GetWaitingValidators())
if isWaitingForShard {
isShuffledOut := newShardId != e.baseData.shardId
e.nodeType = core.NodeTypeValidator
return newShardId, isShuffledOut
}

newShardId, isEligibleForShard := checkIfPubkeyIsInMap(pubKey, epochConfig.EligibleValidators)
newShardId, isEligibleForShard := checkIfPubkeyIsInMap(pubKey, epochConfig.GetEligibleValidators())
if isEligibleForShard {
isShuffledOut := newShardId != e.baseData.shardId
e.nodeType = core.NodeTypeValidator
Expand Down Expand Up @@ -245,7 +244,7 @@ func checkIfValidatorIsInList(
return false
}

func (e *epochStartBootstrap) getLastBootstrapData(storer storage.Storer) (*bootstrapStorage.BootstrapData, *nodesCoordinator.NodesCoordinatorRegistry, error) {
func (e *epochStartBootstrap) getLastBootstrapData(storer storage.Storer) (*bootstrapStorage.BootstrapData, nodesCoordinator.NodesCoordinatorRegistryHandler, error) {
bootStorer, err := bootstrapStorage.NewBootstrapStorer(e.coreComponentsHolder.InternalMarshalizer(), storer)
if err != nil {
return nil, nil, err
Expand All @@ -264,8 +263,7 @@ func (e *epochStartBootstrap) getLastBootstrapData(storer storage.Storer) (*boot
return nil, nil, err
}

config := &nodesCoordinator.NodesCoordinatorRegistry{}
err = json.Unmarshal(d, config)
config, err := e.nodesCoordinatorRegistryFactory.CreateNodesCoordinatorRegistry(d)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions epochStart/bootstrap/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// StartOfEpochNodesConfigHandler defines the methods to process nodesConfig from epoch start metablocks
type StartOfEpochNodesConfigHandler interface {
NodesConfigFromMetaBlock(currMetaBlock data.HeaderHandler, prevMetaBlock data.HeaderHandler) (*nodesCoordinator.NodesCoordinatorRegistry, uint32, error)
NodesConfigFromMetaBlock(currMetaBlock data.HeaderHandler, prevMetaBlock data.HeaderHandler) (nodesCoordinator.NodesCoordinatorRegistryHandler, uint32, error)
IsInterfaceNil() bool
}

Expand All @@ -25,7 +25,7 @@ type EpochStartMetaBlockInterceptorProcessor interface {
// StartInEpochNodesCoordinator defines the methods to process and save nodesCoordinator information to storage
type StartInEpochNodesCoordinator interface {
EpochStartPrepare(metaHdr data.HeaderHandler, body data.BodyHandler)
NodesCoordinatorToRegistry() *nodesCoordinator.NodesCoordinatorRegistry
NodesCoordinatorToRegistry() nodesCoordinator.NodesCoordinatorRegistryHandler
ShardIdForEpoch(epoch uint32) (uint32, error)
IsInterfaceNil() bool
}
Expand Down
164 changes: 84 additions & 80 deletions epochStart/bootstrap/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ type Parameters struct {
Epoch uint32
SelfShardId uint32
NumOfShards uint32
NodesConfig *nodesCoordinator.NodesCoordinatorRegistry
NodesConfig nodesCoordinator.NodesCoordinatorRegistryHandler
}

// ComponentsNeededForBootstrap holds the components which need to be initialized from network
type ComponentsNeededForBootstrap struct {
EpochStartMetaBlock data.MetaHeaderHandler
PreviousEpochStart data.MetaHeaderHandler
ShardHeader data.HeaderHandler
NodesConfig *nodesCoordinator.NodesCoordinatorRegistry
NodesConfig nodesCoordinator.NodesCoordinatorRegistryHandler
Headers map[string]data.HeaderHandler
ShardCoordinator sharding.Coordinator
PendingMiniBlocks map[string]*block.MiniBlock
Expand Down Expand Up @@ -104,29 +104,30 @@ type epochStartBootstrap struct {
trieSyncerVersion int

// created components
requestHandler process.RequestHandler
interceptorContainer process.InterceptorsContainer
dataPool dataRetriever.PoolsHolder
miniBlocksSyncer epochStart.PendingMiniBlocksSyncHandler
headersSyncer epochStart.HeadersByHashSyncer
txSyncerForScheduled update.TransactionsSyncHandler
epochStartMetaBlockSyncer epochStart.StartOfEpochMetaSyncer
nodesConfigHandler StartOfEpochNodesConfigHandler
whiteListHandler update.WhiteListHandler
whiteListerVerifiedTxs update.WhiteListHandler
storageOpenerHandler storage.UnitOpenerHandler
latestStorageDataProvider storage.LatestStorageDataProviderHandler
argumentsParser process.ArgumentsParser
enableEpochs config.EnableEpochs
dataSyncerFactory types.ScheduledDataSyncerCreator
dataSyncerWithScheduled types.ScheduledDataSyncer
storageService dataRetriever.StorageService
requestHandler process.RequestHandler
interceptorContainer process.InterceptorsContainer
dataPool dataRetriever.PoolsHolder
miniBlocksSyncer epochStart.PendingMiniBlocksSyncHandler
headersSyncer epochStart.HeadersByHashSyncer
txSyncerForScheduled update.TransactionsSyncHandler
epochStartMetaBlockSyncer epochStart.StartOfEpochMetaSyncer
nodesConfigHandler StartOfEpochNodesConfigHandler
whiteListHandler update.WhiteListHandler
whiteListerVerifiedTxs update.WhiteListHandler
storageOpenerHandler storage.UnitOpenerHandler
latestStorageDataProvider storage.LatestStorageDataProviderHandler
argumentsParser process.ArgumentsParser
enableEpochs config.EnableEpochs
dataSyncerFactory types.ScheduledDataSyncerCreator
dataSyncerWithScheduled types.ScheduledDataSyncer
storageService dataRetriever.StorageService
nodesCoordinatorRegistryFactory nodesCoordinator.NodesCoordinatorRegistryFactory

// gathered data
epochStartMeta data.MetaHeaderHandler
prevEpochStartMeta data.MetaHeaderHandler
syncedHeaders map[string]data.HeaderHandler
nodesConfig *nodesCoordinator.NodesCoordinatorRegistry
nodesConfig nodesCoordinator.NodesCoordinatorRegistryHandler
baseData baseDataInStorage
startRound int64
nodeType core.NodeType
Expand All @@ -145,26 +146,27 @@ type baseDataInStorage struct {

// ArgsEpochStartBootstrap holds the arguments needed for creating an epoch start data provider component
type ArgsEpochStartBootstrap struct {
CoreComponentsHolder process.CoreComponentsHolder
CryptoComponentsHolder process.CryptoComponentsHolder
DestinationShardAsObserver uint32
Messenger Messenger
GeneralConfig config.Config
PrefsConfig config.PreferencesConfig
EnableEpochs config.EnableEpochs
EconomicsData process.EconomicsDataHandler
GenesisNodesConfig sharding.GenesisNodesSetupHandler
GenesisShardCoordinator sharding.Coordinator
StorageUnitOpener storage.UnitOpenerHandler
LatestStorageDataProvider storage.LatestStorageDataProviderHandler
Rater nodesCoordinator.ChanceComputer
NodeShuffler nodesCoordinator.NodesShuffler
RoundHandler epochStart.RoundHandler
ArgumentsParser process.ArgumentsParser
StatusHandler core.AppStatusHandler
HeaderIntegrityVerifier process.HeaderIntegrityVerifier
DataSyncerCreator types.ScheduledDataSyncerCreator
ScheduledSCRsStorer storage.Storer
CoreComponentsHolder process.CoreComponentsHolder
CryptoComponentsHolder process.CryptoComponentsHolder
DestinationShardAsObserver uint32
Messenger Messenger
GeneralConfig config.Config
PrefsConfig config.PreferencesConfig
EnableEpochs config.EnableEpochs
EconomicsData process.EconomicsDataHandler
GenesisNodesConfig sharding.GenesisNodesSetupHandler
GenesisShardCoordinator sharding.Coordinator
StorageUnitOpener storage.UnitOpenerHandler
LatestStorageDataProvider storage.LatestStorageDataProviderHandler
Rater nodesCoordinator.ChanceComputer
NodeShuffler nodesCoordinator.NodesShuffler
RoundHandler epochStart.RoundHandler
ArgumentsParser process.ArgumentsParser
StatusHandler core.AppStatusHandler
HeaderIntegrityVerifier process.HeaderIntegrityVerifier
DataSyncerCreator types.ScheduledDataSyncerCreator
ScheduledSCRsStorer storage.Storer
NodesCoordinatorRegistryFactory nodesCoordinator.NodesCoordinatorRegistryFactory
}

type dataToSync struct {
Expand All @@ -182,33 +184,34 @@ func NewEpochStartBootstrap(args ArgsEpochStartBootstrap) (*epochStartBootstrap,
}

epochStartProvider := &epochStartBootstrap{
coreComponentsHolder: args.CoreComponentsHolder,
cryptoComponentsHolder: args.CryptoComponentsHolder,
messenger: args.Messenger,
generalConfig: args.GeneralConfig,
prefsConfig: args.PrefsConfig,
economicsData: args.EconomicsData,
genesisNodesConfig: args.GenesisNodesConfig,
genesisShardCoordinator: args.GenesisShardCoordinator,
rater: args.Rater,
destinationShardAsObserver: args.DestinationShardAsObserver,
nodeShuffler: args.NodeShuffler,
roundHandler: args.RoundHandler,
storageOpenerHandler: args.StorageUnitOpener,
latestStorageDataProvider: args.LatestStorageDataProvider,
shuffledOut: false,
statusHandler: args.StatusHandler,
nodeType: core.NodeTypeObserver,
argumentsParser: args.ArgumentsParser,
headerIntegrityVerifier: args.HeaderIntegrityVerifier,
epochNotifier: args.CoreComponentsHolder.EpochNotifier(),
numConcurrentTrieSyncers: args.GeneralConfig.TrieSync.NumConcurrentTrieSyncers,
maxHardCapForMissingNodes: args.GeneralConfig.TrieSync.MaxHardCapForMissingNodes,
trieSyncerVersion: args.GeneralConfig.TrieSync.TrieSyncerVersion,
enableEpochs: args.EnableEpochs,
dataSyncerFactory: args.DataSyncerCreator,
storerScheduledSCRs: args.ScheduledSCRsStorer,
shardCoordinator: args.GenesisShardCoordinator,
coreComponentsHolder: args.CoreComponentsHolder,
cryptoComponentsHolder: args.CryptoComponentsHolder,
messenger: args.Messenger,
generalConfig: args.GeneralConfig,
prefsConfig: args.PrefsConfig,
economicsData: args.EconomicsData,
genesisNodesConfig: args.GenesisNodesConfig,
genesisShardCoordinator: args.GenesisShardCoordinator,
rater: args.Rater,
destinationShardAsObserver: args.DestinationShardAsObserver,
nodeShuffler: args.NodeShuffler,
roundHandler: args.RoundHandler,
storageOpenerHandler: args.StorageUnitOpener,
latestStorageDataProvider: args.LatestStorageDataProvider,
shuffledOut: false,
statusHandler: args.StatusHandler,
nodeType: core.NodeTypeObserver,
argumentsParser: args.ArgumentsParser,
headerIntegrityVerifier: args.HeaderIntegrityVerifier,
epochNotifier: args.CoreComponentsHolder.EpochNotifier(),
numConcurrentTrieSyncers: args.GeneralConfig.TrieSync.NumConcurrentTrieSyncers,
maxHardCapForMissingNodes: args.GeneralConfig.TrieSync.MaxHardCapForMissingNodes,
trieSyncerVersion: args.GeneralConfig.TrieSync.TrieSyncerVersion,
enableEpochs: args.EnableEpochs,
dataSyncerFactory: args.DataSyncerCreator,
storerScheduledSCRs: args.ScheduledSCRsStorer,
shardCoordinator: args.GenesisShardCoordinator,
nodesCoordinatorRegistryFactory: args.NodesCoordinatorRegistryFactory,
}

log.Debug("process: enable epoch for transaction signed with tx hash", "epoch", epochStartProvider.enableEpochs.TransactionSignedWithTxHashEnableEpoch)
Expand Down Expand Up @@ -697,19 +700,20 @@ func (e *epochStartBootstrap) processNodesConfig(pubKey []byte) error {
shardId = e.genesisShardCoordinator.SelfId()
}
argsNewValidatorStatusSyncers := ArgsNewSyncValidatorStatus{
DataPool: e.dataPool,
Marshalizer: e.coreComponentsHolder.InternalMarshalizer(),
RequestHandler: e.requestHandler,
ChanceComputer: e.rater,
GenesisNodesConfig: e.genesisNodesConfig,
NodeShuffler: e.nodeShuffler,
Hasher: e.coreComponentsHolder.Hasher(),
PubKey: pubKey,
ShardIdAsObserver: shardId,
WaitingListFixEnableEpoch: e.enableEpochs.WaitingListFixEnableEpoch,
ChanNodeStop: e.coreComponentsHolder.ChanStopNodeProcess(),
NodeTypeProvider: e.coreComponentsHolder.NodeTypeProvider(),
IsFullArchive: e.prefsConfig.FullArchive,
DataPool: e.dataPool,
Marshalizer: e.coreComponentsHolder.InternalMarshalizer(),
RequestHandler: e.requestHandler,
ChanceComputer: e.rater,
GenesisNodesConfig: e.genesisNodesConfig,
NodeShuffler: e.nodeShuffler,
Hasher: e.coreComponentsHolder.Hasher(),
PubKey: pubKey,
ShardIdAsObserver: shardId,
WaitingListFixEnableEpoch: e.enableEpochs.WaitingListFixEnableEpoch,
ChanNodeStop: e.coreComponentsHolder.ChanStopNodeProcess(),
NodeTypeProvider: e.coreComponentsHolder.NodeTypeProvider(),
IsFullArchive: e.prefsConfig.FullArchive,
NodesCoordinatorRegistryFactory: e.nodesCoordinatorRegistryFactory,
}

e.nodesConfigHandler, err = NewSyncValidatorStatus(argsNewValidatorStatusSyncers)
Expand Down
14 changes: 10 additions & 4 deletions epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,17 @@ func createMockEpochStartBootstrapArgs(
cryptoMock *mock.CryptoComponentsMock,
) ArgsEpochStartBootstrap {
generalCfg := testscommon.GetGeneralConfig()
nodesCoordinatorRegistryFactory, _ := nodesCoordinator.NewNodesCoordinatorRegistryFactory(
&testscommon.MarshalizerMock{},
&epochNotifier.EpochNotifierStub{},
444,
)
return ArgsEpochStartBootstrap{
ScheduledSCRsStorer: genericMocks.NewStorerMock("path", 0),
CoreComponentsHolder: coreMock,
CryptoComponentsHolder: cryptoMock,
Messenger: &mock.MessengerStub{},
ScheduledSCRsStorer: genericMocks.NewStorerMock("path", 0),
CoreComponentsHolder: coreMock,
CryptoComponentsHolder: cryptoMock,
Messenger: &mock.MessengerStub{},
NodesCoordinatorRegistryFactory: nodesCoordinatorRegistryFactory,
GeneralConfig: config.Config{
MiniBlocksStorage: generalCfg.MiniBlocksStorage,
PeerBlockBodyStorage: generalCfg.PeerBlockBodyStorage,
Expand Down
2 changes: 1 addition & 1 deletion epochStart/bootstrap/shardStorageHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (ssh *shardStorageHandler) SaveDataToStorage(components *ComponentsNeededFo
return err
}

components.NodesConfig.CurrentEpoch = components.ShardHeader.GetEpoch()
components.NodesConfig.SetCurrentEpoch(components.ShardHeader.GetEpoch())
nodesCoordinatorConfigKey, err := ssh.saveNodesCoordinatorRegistry(components.EpochStartMetaBlock, components.NodesConfig)
if err != nil {
return err
Expand Down
25 changes: 13 additions & 12 deletions epochStart/bootstrap/storageProcess.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,19 @@ func (sesb *storageEpochStartBootstrap) processNodesConfig(pubKey []byte) error
shardId = sesb.genesisShardCoordinator.SelfId()
}
argsNewValidatorStatusSyncers := ArgsNewSyncValidatorStatus{
DataPool: sesb.dataPool,
Marshalizer: sesb.coreComponentsHolder.InternalMarshalizer(),
RequestHandler: sesb.requestHandler,
ChanceComputer: sesb.rater,
GenesisNodesConfig: sesb.genesisNodesConfig,
NodeShuffler: sesb.nodeShuffler,
Hasher: sesb.coreComponentsHolder.Hasher(),
PubKey: pubKey,
ShardIdAsObserver: shardId,
ChanNodeStop: sesb.coreComponentsHolder.ChanStopNodeProcess(),
NodeTypeProvider: sesb.coreComponentsHolder.NodeTypeProvider(),
IsFullArchive: sesb.prefsConfig.FullArchive,
DataPool: sesb.dataPool,
Marshalizer: sesb.coreComponentsHolder.InternalMarshalizer(),
RequestHandler: sesb.requestHandler,
ChanceComputer: sesb.rater,
GenesisNodesConfig: sesb.genesisNodesConfig,
NodeShuffler: sesb.nodeShuffler,
Hasher: sesb.coreComponentsHolder.Hasher(),
PubKey: pubKey,
ShardIdAsObserver: shardId,
ChanNodeStop: sesb.coreComponentsHolder.ChanStopNodeProcess(),
NodeTypeProvider: sesb.coreComponentsHolder.NodeTypeProvider(),
IsFullArchive: sesb.prefsConfig.FullArchive,
NodesCoordinatorRegistryFactory: sesb.nodesCoordinatorRegistryFactory,
}
sesb.nodesConfigHandler, err = NewSyncValidatorStatus(argsNewValidatorStatusSyncers)
if err != nil {
Expand Down

0 comments on commit 8a122e8

Please sign in to comment.