-
Notifications
You must be signed in to change notification settings - Fork 199
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
EN-5829: node start in epoch #1238
EN-5829: node start in epoch #1238
Conversation
…-start-mb # Conflicts: # cmd/node/factory/structs.go # cmd/node/main.go # dataRetriever/factory/resolverscontainer/shardResolversContainerFactory.go # facade/elrondNodeFacade.go # facade/elrondNodeFacade_test.go
…-start-mb # Conflicts: # integrationTests/testInitializer.go
…-start-in-epoch-to-bootstrap-from-storage
…on-test' into EN-5829-link-start-in-epoch-to-bootstrap-from-storage # Conflicts: # epochStart/bootstrap/epochStartDataProvider.go # epochStart/bootstrap/errors.go
…into EN-5829-link-start-in-epoch-to-bootstrap-from-storage # Conflicts: # cmd/node/main.go # epochStart/bootstrap/epochStartDataProvider.go # epochStart/bootstrap/factory/epochStartDataProviderFactory.go
@@ -44,6 +44,13 @@ var log = logger.GetOrCreate("epochStart/bootstrap") | |||
|
|||
const timeToWait = 5 * time.Second | |||
|
|||
// BootstrapParameters | |||
type Parameters struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe BootstrapParameters ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not recommended to have the same starting string as the package name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EpochCoordinates
:)
Anyway, fix comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…o-bootstrap-from-storage # Conflicts: # cmd/node/factory/structs.go # cmd/node/main.go # process/peer/process.go # sharding/indexHashedNodesCoordinator.go # sharding/indexHashedNodesCoordinatorRegistry.go
if err != nil { | ||
return err | ||
missingChildren = append(missingChildren, bn.EncodedChildren[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we Trace() the error perhaps, at least, or not necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary - this is called by syncing mechanism so it is normal to have a few missing - than request it.
return err | ||
if requestedHdrs == 0 { | ||
m.mutMissingHdrs.Lock() | ||
m.stopSyncing = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If syncedAll
and stopSyncing
were atomic.Flag
, there would be less mutex handling inside select
expressions - improved readability, less complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave it as it is for now.
} | ||
|
||
// receivedHeader is a callback function when a new header was received | ||
// it will further ask for missing transactions | ||
func (m *missingHeadersByHash) receivedHeader(hdrHandler data.HeaderHandler, hdrHash []byte) { | ||
func (m *syncHeadersByHash) receivedHeader(hdrHandler data.HeaderHandler, hdrHash []byte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using Unlock with defer here? Could cause troubles if function is modified without full attention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not possible as you have the h.chReceivedAll <- true which should be called outside of mutex.
return nil | ||
select { | ||
case <-p.chReceivedAll: | ||
p.mutPendingMb.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As before, perhaps atomic flags (core/atomic/flag.go
) instead of using so much mutex handling in channel-related expressions (can improve code readability).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave it as it is for now.
data/syncer/userAccountsSyncer.go
Outdated
@@ -52,6 +54,10 @@ func (u *userAccountsSyncer) SyncAccounts(rootHash []byte) error { | |||
u.mutex.Lock() | |||
defer u.mutex.Unlock() | |||
|
|||
ctx, cancel := context.WithTimeout(context.Background(), u.waitTime) | |||
defer cancel() | |||
u.ctx = ctx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs,
Do not store Contexts inside a struct type; instead, pass a Context explicitly to each function that needs it.
This is the pattern, but not mandatory:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, with little injecting work we can drop u.ctx = ctx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
validatorsMap := make(map[uint32][]Validator) | ||
|
||
for shId, nodeInfoList := range nodesInfo { | ||
validators := make([]Validator, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can set capacity optionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
for _, validatorInfo := range validatorInfos { | ||
validator, err := sharding.NewValidator(validatorInfo.PublicKey, validatorInfo.RewardAddress) | ||
if err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Break-break or skip validator info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
break. as error
|
||
func (n *nodesCoordinator) computeLeaving(allValidators []*state.ValidatorInfo) ([]sharding.Validator, error) { | ||
leavingValidators := make([]sharding.Validator, 0) | ||
minChances := n.chance.GetChance(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minChanceOfNotLeaving
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep it simple.
return Parameters{}, err | ||
} | ||
|
||
unitsToOpen := make([]string, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May use simple initialization instead of append.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
} | ||
|
||
if e.shardCoordinator.SelfId() == core.MetachainShardId { | ||
err = e.requestAndProcessForShard() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If meta, requestAndProcessForShard
/ from shard? Just double check if this is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
data/syncer/userAccountsSyncer.go
Outdated
@@ -52,6 +54,10 @@ func (u *userAccountsSyncer) SyncAccounts(rootHash []byte) error { | |||
u.mutex.Lock() | |||
defer u.mutex.Unlock() | |||
|
|||
ctx, cancel := context.WithTimeout(context.Background(), u.waitTime) | |||
defer cancel() | |||
u.ctx = ctx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, with little injecting work we can drop u.ctx = ctx
} | ||
return false | ||
|
||
ts.receivedNodesMutex.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might extract this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 lines of code used in a single space
if hashInSlice(hash, ts.requestedHashes) { | ||
ts.chRcvTrieNodes <- true | ||
ts.removeRequestedHash(hash) | ||
ts.nodeHashesMutex.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might extract this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 lines of code used in a single space
@@ -47,6 +49,9 @@ func NewResolverRequestHandler( | |||
if check.IfNil(whiteList) { | |||
return nil, dataRetriever.ErrNilWhiteListHandler | |||
} | |||
if requestInterval < time.Millisecond { | |||
return nil, dataRetriever.ErrRequestIntervalTooSmall |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might wrap this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is of common sense to put more than a millisecond. done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, but wrapping the error is all about finding the problem in no time (most of the start-up problems are due to bad configs). Showing a simple, inexpressive "nil cacher" message should be avoided.
} | ||
|
||
// ProcessReceivedMessage will receive the metablocks and will add them to the maps | ||
func (s *simpleEpochStartMetaBlockInterceptor) ProcessReceivedMessage(message p2p.MessageP2P, _ p2p.PeerID) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not done
p.mutPendingMb.Unlock() | ||
|
||
var err error | ||
defer func() { | ||
for { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate code with syncHeadersByHash.go. Add a TODO to extract the common functionality
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namings are different. mutexes are different. not really duplicated code - yes, same principle. the code is kept as clean as possible. the thing is underlying structures have different elements - one headers other miniblocks. go does not support generics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will think of a solution to this.
No description provided.