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

Extract Initial Sync Into its Own Package #404

Merged
merged 18 commits into from
Aug 22, 2018

Conversation

rawfalafel
Copy link
Contributor

This addresses #388

Once InitialSyncService is finished, it calls Start on SyncService. Note that Start for each sync service checks the state of the chain to decide whether or not to start the goroutine.

@codecov
Copy link

codecov bot commented Aug 17, 2018

Codecov Report

Merging #404 into master will increase coverage by 0.89%.
The diff coverage is 72.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #404      +/-   ##
==========================================
+ Coverage   73.67%   74.56%   +0.89%     
==========================================
  Files          29       30       +1     
  Lines        1979     2021      +42     
==========================================
+ Hits         1458     1507      +49     
+ Misses        371      360      -11     
- Partials      150      154       +4
Impacted Files Coverage Δ
beacon-chain/node/node.go 57.33% <42.85%> (-1.5%) ⬇️
beacon-chain/sync/initial-sync/service.go 72.5% <72.5%> (ø)
beacon-chain/sync/service.go 70% <88.88%> (+6.77%) ⬆️
beacon-chain/rpc/service.go 100% <0%> (+5.88%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 920a9a8...4c0fe06. Read the comment docs.

@rawfalafel
Copy link
Contributor Author

This is ready for review.

Currently, Simulator assumes an empty beacon chain and broadcasts blocks from the genesis block. However, InitialSync assumes that the network knows about a non-empty beacon chain where slot_number > 0. These two assumptions are incompatible at the moment.

Although a new node connected to a network would run InitialSync to catch up to the network's longest chain before running Sync, our simulated node should skip InitialSync and immediately begin syncing from the genesis block. This PR includes those changes and some TODO statements for when we're ready to test our code with the assumption that the node is connected to a network.

Copy link
Contributor

@rauljordan rauljordan left a comment

Choose a reason for hiding this comment

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

This is much cleaner and easier to understand now, thanks @rawfalafel !

}

// ChainService is the interface for the blockchain package's ChainService struct
type ChainService interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see this was what you meant by defining small interfaces within the packages themselves instead of relying on a single interfaces.go file when we only need a subset of methods. I like this pattern and we can split up the large interfaces we have in the types package into something like this.

SaveBlock(*types.Block) error
}

// SyncService is the interface for the Sync service
Copy link
Contributor

Choose a reason for hiding this comment

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

Punctuation on comments throughout this file and more descriptive godocs.

for {
select {
case <-s.ctx.Done():
log.Infof("Exiting goroutine")
Copy link
Contributor

Choose a reason for hiding this comment

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

log.Debug

if err != nil {
return err
}
log.WithField("Block received with hash", fmt.Sprintf("0x%x", h)).Debug("Crystallized state hash exists locally")
Copy link
Contributor

Choose a reason for hiding this comment

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

the field prefix is usually short, something like receivedBlockHash would be good

}

if s.currentSlotNumber == uint64(0) {
return fmt.Errorf("invalid slot number for syncing")
Copy link
Contributor

Choose a reason for hiding this comment

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

errors.New

Copy link
Member

@terencechain terencechain left a comment

Choose a reason for hiding this comment

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

Awesome PR. Just a few comments.

"github.com/sirupsen/logrus"
)

var log = logrus.WithField("prefix", "sync")
Copy link
Member

Choose a reason for hiding this comment

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

should this be "initialsync"?

var log = logrus.WithField("prefix", "initialsync")

@@ -0,0 +1,265 @@
package initialsync
Copy link
Member

Choose a reason for hiding this comment

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

can we add package level comment?


s.initialCrystallizedStateHash = block.CrystallizedStateHash()

log.Infof("Saved block with hash 0%x for initial sync", h)
Copy link
Member

Choose a reason for hiding this comment

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

is 0 a typo? or should it be 0x?

@rauljordan rauljordan changed the title Extract initial sync Extract Initial Sync Into its Own Package Aug 18, 2018
Copy link
Member

@nisdas nisdas left a comment

Choose a reason for hiding this comment

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

This is awesome ! Just had a few comments


var log = logrus.WithField("prefix", "sync")

// Config allows the channel's buffer sizes to be changed.
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what this config has to do with buffer sizes

) *InitialSync {
ctx, cancel := context.WithCancel(ctx)

blockBuf := make(chan p2p.Message)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't these channels be buffered ?


if stored {
// TODO: Bail out of the sync service if the chain is only partially synced
log.Infof("chain state detected, exiting initial sync")
Copy link
Member

Choose a reason for hiding this comment

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

First letter should be capitalized for logs

@rauljordan
Copy link
Contributor

Hey @rawfalafel update on this PR?

@rawfalafel
Copy link
Contributor Author

rawfalafel commented Aug 20, 2018 via email

@rawfalafel
Copy link
Contributor Author

ready for another look

@nisdas nisdas merged commit 7cfda8a into prysmaticlabs:master Aug 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants