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

EN-5829: node start in epoch #1238

Conversation

bogdan-rosianu
Copy link
Contributor

No description provided.

sasurobert and others added 8 commits March 19, 2020 10:46
…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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe BootstrapParameters ?

Copy link
Contributor

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EpochCoordinates :)

Anyway, fix comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if err != nil {
return err
missingChildren = append(missingChildren, bn.EncodedChildren[i])
Copy link
Collaborator

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?

Copy link
Contributor

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
Copy link
Collaborator

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.

Copy link
Contributor

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) {
Copy link
Collaborator

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.

Copy link
Contributor

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()
Copy link
Collaborator

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).

Copy link
Contributor

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.

@@ -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
Copy link
Collaborator

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:

golang/go#22602

Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can set capacity optionally.

Copy link
Contributor

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
Copy link
Collaborator

@andreibancioiu andreibancioiu Mar 30, 2020

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?

Copy link
Contributor

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minChanceOfNotLeaving?

Copy link
Contributor

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)
Copy link
Collaborator

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.

Copy link
Contributor

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()
Copy link
Collaborator

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

@@ -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
Copy link
Contributor

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

data/trie/sync.go Outdated Show resolved Hide resolved
}
return false

ts.receivedNodesMutex.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might extract this

Copy link
Contributor

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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might extract this

Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might wrap this

Copy link
Contributor

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.

Copy link
Contributor

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.

epochStart/bootstrap/process.go Outdated Show resolved Hide resolved
}

// ProcessReceivedMessage will receive the metablocks and will add them to the maps
func (s *simpleEpochStartMetaBlockInterceptor) ProcessReceivedMessage(message p2p.MessageP2P, _ p2p.PeerID) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not done

epochStart/metachain/trigger.go Outdated Show resolved Hide resolved
sharding/indexHashedNodesCoordinatorRegistry.go Outdated Show resolved Hide resolved
p.mutPendingMb.Unlock()

var err error
defer func() {
for {
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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.

@iulianpascalau iulianpascalau merged commit 5ad08ed into feat/start-in-epoch Mar 31, 2020
@iulianpascalau iulianpascalau deleted the EN-5829-link-start-in-epoch-to-bootstrap-from-storage branch March 31, 2020 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants