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

chain: Avoid early getHeaders on sidechains #2315

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions chain/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,17 +623,19 @@ func (s *Syncer) blockConnected(ctx context.Context, params json.RawMessage) err
return err
}

// Ensure the ancestor is in the main chain. If it is not, this means
// we missed some blocks and should perform a new round of initial
// header sync.
if inMainChain, _, _ := s.wallet.BlockInMainChain(ctx, &header.PrevBlock); !inMainChain {
if !inMainChain {
log.Infof("Received header for block %s (height %d) when "+
"parent %s not in main chain. Re-requesting "+
"missing headers.", header.BlockHash(),
header.Height, header.PrevBlock)
return s.getHeaders(ctx)
}
// Ensure the ancestor is known to be in the main or in a side chain.
// If it is not, this means we missed some blocks and should perform a
// new round of initial header sync.
s.sidechainsMu.Lock()
prevInMainChain, _, _ := s.wallet.BlockInMainChain(ctx, &header.PrevBlock)
prevInSideChain := s.sidechains.HasSideChainBlock(&header.PrevBlock)
s.sidechainsMu.Unlock()
if !(prevInMainChain || prevInSideChain) {
log.Infof("Received header for block %s (height %d) when "+
"parent %s not in main or side chain. Re-requesting "+
"missing headers.", header.BlockHash(),
header.Height, header.PrevBlock)
return s.getHeaders(ctx)
}

blockHash := header.BlockHash()
Expand Down
Loading