mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
core/blockchain: lessen mem-spike during 1.8->1.9 conversion
This commit is contained in:
parent
92a90d7578
commit
29b96d64e3
1 changed files with 25 additions and 4 deletions
|
|
@ -927,6 +927,12 @@ func (bc *BlockChain) truncateAncient(head uint64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// numberHash is just a container for a number and a hash, to represent a block
|
||||||
|
type numberHash struct {
|
||||||
|
number uint64
|
||||||
|
hash common.Hash
|
||||||
|
}
|
||||||
|
|
||||||
// InsertReceiptChain attempts to complete an already existing header chain with
|
// InsertReceiptChain attempts to complete an already existing header chain with
|
||||||
// transaction and receipt data.
|
// transaction and receipt data.
|
||||||
func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain []types.Receipts, ancientLimit uint64) (int, error) {
|
func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain []types.Receipts, ancientLimit uint64) (int, error) {
|
||||||
|
|
@ -994,7 +1000,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var deleted types.Blocks
|
var deleted []*numberHash
|
||||||
for i, block := range blockChain {
|
for i, block := range blockChain {
|
||||||
// Short circuit insertion if shutting down or processing failed
|
// Short circuit insertion if shutting down or processing failed
|
||||||
if atomic.LoadInt32(&bc.procInterrupt) == 1 {
|
if atomic.LoadInt32(&bc.procInterrupt) == 1 {
|
||||||
|
|
@ -1029,7 +1035,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
|
||||||
|
|
||||||
// Always keep genesis block in active database.
|
// Always keep genesis block in active database.
|
||||||
if b.NumberU64() != 0 {
|
if b.NumberU64() != 0 {
|
||||||
deleted = append(deleted, b)
|
deleted = append(deleted, &numberHash{b.NumberU64(), b.Hash()})
|
||||||
}
|
}
|
||||||
if time.Since(logged) > 8*time.Second {
|
if time.Since(logged) > 8*time.Second {
|
||||||
log.Info("Migrating ancient blocks", "count", count, "elapsed", common.PrettyDuration(time.Since(start)))
|
log.Info("Migrating ancient blocks", "count", count, "elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
|
|
@ -1062,7 +1068,14 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
|
||||||
previous = nil // disable rollback explicitly
|
previous = nil // disable rollback explicitly
|
||||||
|
|
||||||
// Wipe out canonical block data.
|
// Wipe out canonical block data.
|
||||||
for _, block := range append(deleted, blockChain...) {
|
for _, nh := range deleted {
|
||||||
|
// Always keep genesis block in active database.
|
||||||
|
if nh.number != 0 {
|
||||||
|
rawdb.DeleteBlockWithoutNumber(batch, nh.hash, nh.number)
|
||||||
|
rawdb.DeleteCanonicalHash(batch, nh.number)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, block := range blockChain {
|
||||||
// Always keep genesis block in active database.
|
// Always keep genesis block in active database.
|
||||||
if block.NumberU64() != 0 {
|
if block.NumberU64() != 0 {
|
||||||
rawdb.DeleteBlockWithoutNumber(batch, block.Hash(), block.NumberU64())
|
rawdb.DeleteBlockWithoutNumber(batch, block.Hash(), block.NumberU64())
|
||||||
|
|
@ -1075,7 +1088,15 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
|
||||||
batch.Reset()
|
batch.Reset()
|
||||||
|
|
||||||
// Wipe out side chain too.
|
// Wipe out side chain too.
|
||||||
for _, block := range append(deleted, blockChain...) {
|
for _, nh := range deleted {
|
||||||
|
// Always keep genesis block in active database.
|
||||||
|
if nh.number != 0 {
|
||||||
|
for _, hash := range rawdb.ReadAllHashes(bc.db, nh.number) {
|
||||||
|
rawdb.DeleteBlock(batch, hash, nh.number)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, block := range blockChain {
|
||||||
// Always keep genesis block in active database.
|
// Always keep genesis block in active database.
|
||||||
if block.NumberU64() != 0 {
|
if block.NumberU64() != 0 {
|
||||||
for _, hash := range rawdb.ReadAllHashes(bc.db, block.NumberU64()) {
|
for _, hash := range rawdb.ReadAllHashes(bc.db, block.NumberU64()) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue