-
Notifications
You must be signed in to change notification settings - Fork 146
fix(dot/sync): remove block announcement in bootstrap sync mode
#2906
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
Changes from all commits
044e523
c5753b4
eb637eb
20fb8e8
b8f24f0
cb0c328
4025a56
079487a
ecac4b2
3f44d45
d770bee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,8 @@ type chainProcessor struct { | |
| ctx context.Context | ||
| cancel context.CancelFunc | ||
|
|
||
| chainSync ChainSync | ||
|
|
||
| // blocks that are ready for processing. ie. their parent is known, or their parent is ahead | ||
| // of them within this channel and thus will be processed first | ||
| readyBlocks *blockQueue | ||
|
|
@@ -42,24 +44,35 @@ type chainProcessor struct { | |
| telemetry telemetry.Client | ||
| } | ||
|
|
||
| func newChainProcessor(readyBlocks *blockQueue, pendingBlocks DisjointBlockSet, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Like given below, (here and everywhere
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eclesio's argument was:
Although I agree we should standardize our codebase as we progress through it, I agree with Kishan's suggestion especially for unexported/internal constructors. I would also add in my very opinionated opinion that config structs should be reserved for the public Go API (so exported public constructors) and every field can be set to a default (so the user can pass an empty struct). It also allows to add fields without breaking the constructor signature (so it stays retro-compat). For internal constructors, it's far easier to have plain and simple compulsory named arguments which would detect compilation problems when adding an argument. |
||
| blockState BlockState, storageState StorageState, | ||
| transactionState TransactionState, babeVerifier BabeVerifier, | ||
| finalityGadget FinalityGadget, blockImportHandler BlockImportHandler, telemetry telemetry.Client) *chainProcessor { | ||
| type chainProcessorConfig struct { | ||
| readyBlocks *blockQueue | ||
| pendingBlocks DisjointBlockSet | ||
| syncer ChainSync | ||
| blockState BlockState | ||
| storageState StorageState | ||
| transactionState TransactionState | ||
| babeVerifier BabeVerifier | ||
| finalityGadget FinalityGadget | ||
| blockImportHandler BlockImportHandler | ||
| telemetry telemetry.Client | ||
| } | ||
|
|
||
| func newChainProcessor(cfg chainProcessorConfig) *chainProcessor { | ||
| ctx, cancel := context.WithCancel(context.Background()) | ||
|
|
||
| return &chainProcessor{ | ||
| ctx: ctx, | ||
| cancel: cancel, | ||
| readyBlocks: readyBlocks, | ||
| pendingBlocks: pendingBlocks, | ||
| blockState: blockState, | ||
| storageState: storageState, | ||
| transactionState: transactionState, | ||
| babeVerifier: babeVerifier, | ||
| finalityGadget: finalityGadget, | ||
| blockImportHandler: blockImportHandler, | ||
| telemetry: telemetry, | ||
| readyBlocks: cfg.readyBlocks, | ||
| pendingBlocks: cfg.pendingBlocks, | ||
| chainSync: cfg.syncer, | ||
| blockState: cfg.blockState, | ||
| storageState: cfg.storageState, | ||
| transactionState: cfg.transactionState, | ||
| babeVerifier: cfg.babeVerifier, | ||
| finalityGadget: cfg.finalityGadget, | ||
| blockImportHandler: cfg.blockImportHandler, | ||
| telemetry: cfg.telemetry, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -109,6 +122,8 @@ func (s *chainProcessor) processBlockData(bd *types.BlockData) error { | |
| return fmt.Errorf("failed to check block state has body for hash %s: %w", bd.Hash, err) | ||
| } | ||
|
|
||
| // while in bootstrap mode we don't need to broadcast block announcements | ||
| announceImportedBlock := s.chainSync.syncState() == tip | ||
| if hasHeader && hasBody { | ||
| // TODO: fix this; sometimes when the node shuts down the "best block" isn't stored properly, | ||
| // so when the node restarts it has blocks higher than what it thinks is the best, causing it not to sync | ||
|
|
@@ -149,7 +164,7 @@ func (s *chainProcessor) processBlockData(bd *types.BlockData) error { | |
| return err | ||
| } | ||
|
|
||
| if err := s.blockImportHandler.HandleBlockImport(block, state); err != nil { | ||
| if err := s.blockImportHandler.HandleBlockImport(block, state, announceImportedBlock); err != nil { | ||
| logger.Warnf("failed to handle block import: %s", err) | ||
| } | ||
|
|
||
|
|
@@ -170,7 +185,7 @@ func (s *chainProcessor) processBlockData(bd *types.BlockData) error { | |
| Body: *bd.Body, | ||
| } | ||
|
|
||
| if err := s.handleBlock(block); err != nil { | ||
| if err := s.handleBlock(block, announceImportedBlock); err != nil { | ||
| logger.Debugf("failed to handle block number %d: %s", block.Header.Number, err) | ||
| return err | ||
| } | ||
|
|
@@ -201,7 +216,7 @@ func (s *chainProcessor) handleBody(body *types.Body) { | |
| } | ||
|
|
||
| // handleHeader handles blocks (header+body) included in BlockResponses | ||
| func (s *chainProcessor) handleBlock(block *types.Block) error { | ||
| func (s *chainProcessor) handleBlock(block *types.Block, announceImportedBlock bool) error { | ||
| parent, err := s.blockState.GetHeader(block.Header.ParentHash) | ||
| if err != nil { | ||
| return fmt.Errorf("%w: %s", errFailedToGetParent, err) | ||
|
|
@@ -233,7 +248,7 @@ func (s *chainProcessor) handleBlock(block *types.Block) error { | |
| return fmt.Errorf("failed to execute block %d: %w", block.Header.Number, err) | ||
| } | ||
|
|
||
| if err = s.blockImportHandler.HandleBlockImport(block, ts); err != nil { | ||
| if err = s.blockImportHandler.HandleBlockImport(block, ts, announceImportedBlock); err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.