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

Remove locking in (*BlockChain).ExportN #25254

Merged
merged 5 commits into from
Jul 14, 2022
Merged
Changes from 2 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
10 changes: 5 additions & 5 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,19 +739,19 @@ func (bc *BlockChain) Export(w io.Writer) error {

// ExportN writes a subset of the active chain to the given writer.
func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
if !bc.chainmu.TryLock() {
return errChainStopped
}
defer bc.chainmu.Unlock()

if first > last {
return fmt.Errorf("export failed: first (%d) is greater than last (%d)", first, last)
}
log.Info("Exporting batch of blocks", "count", last-first+1)

start, reported := time.Now(), time.Now()
var parentHash common.Hash
for nr := first; nr <= last; nr++ {
block := bc.GetBlockByNumber(nr)
if nr > first && block.Hash() != parentHash {
henridf marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("export failed: chain reorg during export")
}
parentHash = block.Hash()
if block == nil {
return fmt.Errorf("export failed on #%d: not found", nr)
}
Expand Down