Patch for concurrent iterator & others (onto v1.11.6) #386
@ -739,22 +739,25 @@ func (bc *BlockChain) Export(w io.Writer) error {
|
|||||||
|
|
||||||
// ExportN writes a subset of the active chain to the given writer.
|
// ExportN writes a subset of the active chain to the given writer.
|
||||||
func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
|
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 {
|
if first > last {
|
||||||
return fmt.Errorf("export failed: first (%d) is greater than last (%d)", 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)
|
log.Info("Exporting batch of blocks", "count", last-first+1)
|
||||||
|
|
||||||
start, reported := time.Now(), time.Now()
|
var (
|
||||||
|
parentHash common.Hash
|
||||||
|
start = time.Now()
|
||||||
|
reported = time.Now()
|
||||||
|
)
|
||||||
for nr := first; nr <= last; nr++ {
|
for nr := first; nr <= last; nr++ {
|
||||||
block := bc.GetBlockByNumber(nr)
|
block := bc.GetBlockByNumber(nr)
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return fmt.Errorf("export failed on #%d: not found", nr)
|
return fmt.Errorf("export failed on #%d: not found", nr)
|
||||||
}
|
}
|
||||||
|
if nr > first && block.ParentHash() != parentHash {
|
||||||
|
return fmt.Errorf("export failed: chain reorg during export")
|
||||||
|
}
|
||||||
|
parentHash = block.Hash()
|
||||||
if err := block.EncodeRLP(w); err != nil {
|
if err := block.EncodeRLP(w); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user