Skip to content

Commit

Permalink
Improve chain state init efficiency
Browse files Browse the repository at this point in the history
Remove unnecessary slice of all block indexes and
remove DB iteration over all block indexes that
used to determined the size of the slice.
  • Loading branch information
lindlof authored and jcvernaleo committed Jun 8, 2020
1 parent 714de3f commit b11bf58
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,18 +1149,9 @@ func (b *BlockChain) initChainState() error {

blockIndexBucket := dbTx.Metadata().Bucket(blockIndexBucketName)

// Determine how many blocks will be loaded into the index so we can
// allocate the right amount.
var blockCount int32
cursor := blockIndexBucket.Cursor()
for ok := cursor.First(); ok; ok = cursor.Next() {
blockCount++
}
blockNodes := make([]blockNode, blockCount)

var i int32
var lastNode *blockNode
cursor = blockIndexBucket.Cursor()
cursor := blockIndexBucket.Cursor()
for ok := cursor.First(); ok; ok = cursor.Next() {
header, status, err := deserializeBlockRow(cursor.Value())
if err != nil {
Expand Down Expand Up @@ -1193,7 +1184,7 @@ func (b *BlockChain) initChainState() error {

// Initialize the block node for the block, connect it,
// and add it to the block index.
node := &blockNodes[i]
node := new(blockNode)
initBlockNode(node, header, parent)
node.status = status
b.index.addNode(node)
Expand Down

0 comments on commit b11bf58

Please sign in to comment.