Skip to content

Commit

Permalink
Merge pull request #1728 from ElrondNetwork/add-checks-for-epoch-star…
Browse files Browse the repository at this point in the history
…t-config

Add checks for epoch start config when init bootstrap
  • Loading branch information
LucianMincu committed May 13, 2020
2 parents 95405d1 + 430e319 commit 7eb0642
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
# ShuffleBetweenShards enables the shuffling of validators between shards at the end of epoch
ShuffleBetweenShards = false
MinNumConnectedPeersToStart = 2
MinNumOfPeersToConsiderBlockValid = 2 #TODO add tests for invalid values
MinNumOfPeersToConsiderBlockValid = 2

# ResourceStats, if enabled, will output in a folder called "stats"
# resource statistics. For example: number of active go routines, memory allocation, number of GC sweeps, etc.
Expand Down
6 changes: 6 additions & 0 deletions epochStart/bootstrap/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func checkArguments(args ArgsEpochStartBootstrap) error {
if check.IfNil(args.NodeShuffler) {
return fmt.Errorf("%s: %w", baseErrorMessage, epochStart.ErrNilShuffler)
}
if args.GeneralConfig.EpochStartConfig.MinNumOfPeersToConsiderBlockValid < minNumPeersToConsiderMetaBlockValid {
return fmt.Errorf("%s: %w", baseErrorMessage, epochStart.ErrNotEnoughNumOfPeersToConsiderBlockValid)
}
if args.GeneralConfig.EpochStartConfig.MinNumConnectedPeersToStart < minNumConnectedPeers {
return fmt.Errorf("%s: %w", baseErrorMessage, epochStart.ErrNotEnoughNumConnectedPeers)
}

return nil
}
14 changes: 8 additions & 6 deletions epochStart/bootstrap/epochStartMetaBlockProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
const durationBetweenChecks = 200 * time.Millisecond
const durationBetweenReRequests = 1 * time.Second
const durationBetweenCheckingNumConnectedPeers = 500 * time.Millisecond
const minNumPeersToConsiderMetaBlockValid = 1
const minNumConnectedPeers = 1

var _ process.InterceptorProcessor = (*epochStartMetaBlockProcessor)(nil)

Expand All @@ -45,8 +47,8 @@ func NewEpochStartMetaBlockProcessor(
marshalizer marshal.Marshalizer,
hasher hashing.Hasher,
consensusPercentage uint8,
minNumConnectedPeers int,
minNumOfPeersToConsiderBlockValid int,
minNumConnectedPeersConfig int,
minNumOfPeersToConsiderBlockValidConfig int,
) (*epochStartMetaBlockProcessor, error) {
if check.IfNil(messenger) {
return nil, epochStart.ErrNilMessenger
Expand All @@ -63,10 +65,10 @@ func NewEpochStartMetaBlockProcessor(
if !(consensusPercentage > 0 && consensusPercentage <= 100) {
return nil, epochStart.ErrInvalidConsensusThreshold
}
if minNumConnectedPeers < 1 {
if minNumConnectedPeersConfig < minNumConnectedPeers {
return nil, epochStart.ErrNotEnoughNumConnectedPeers
}
if minNumOfPeersToConsiderBlockValid < 1 {
if minNumOfPeersToConsiderBlockValidConfig < minNumPeersToConsiderMetaBlockValid {
return nil, epochStart.ErrNotEnoughNumOfPeersToConsiderBlockValid
}

Expand All @@ -75,8 +77,8 @@ func NewEpochStartMetaBlockProcessor(
requestHandler: handler,
marshalizer: marshalizer,
hasher: hasher,
minNumConnectedPeers: minNumConnectedPeers,
minNumOfPeersToConsiderBlockValid: minNumOfPeersToConsiderBlockValid,
minNumConnectedPeers: minNumConnectedPeersConfig,
minNumOfPeersToConsiderBlockValid: minNumOfPeersToConsiderBlockValidConfig,
mutReceivedMetaBlocks: sync.RWMutex{},
mapReceivedMetaBlocks: make(map[string]*block.MetaBlock),
mapMetaBlocksFromPeers: make(map[string][]p2p.PeerID),
Expand Down
6 changes: 4 additions & 2 deletions epochStart/bootstrap/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
func getGeneralConfig() config.Config {
return config.Config{
EpochStartConfig: config.EpochStartConfig{
MinRoundsBetweenEpochs: 5,
RoundsPerEpoch: 10,
MinRoundsBetweenEpochs: 5,
RoundsPerEpoch: 10,
MinNumOfPeersToConsiderBlockValid: 2,
MinNumConnectedPeersToStart: 2,
},
WhiteListPool: config.CacheConfig{
Size: 10000,
Expand Down
7 changes: 1 addition & 6 deletions epochStart/bootstrap/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,8 @@ func TestEpochStartBootstrap_Bootstrap(t *testing.T) {
return roundDuration
},
}
args.GeneralConfig = config.Config{
EpochStartConfig: config.EpochStartConfig{
RoundsPerEpoch: roundsPerEpoch,
},
}
args.GeneralConfig = getGeneralConfig()

args.GeneralConfig.EpochStartConfig.RoundsPerEpoch = roundsPerEpoch
epochStartProvider, _ := NewEpochStartBootstrap(args)

done := make(chan bool, 1)
Expand Down

0 comments on commit 7eb0642

Please sign in to comment.