From e5ebb174d61a6f7b0b9c6023b15c33a246b2c14f Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Sat, 17 Nov 2018 13:18:34 +0800 Subject: core: more fix on light node synchronization (#32) Fix gas calculation in governance contract. Correctly register round height when processing pending blocks. We should register the mapping when we get the pending block instead of waiting for block confirmation. --- core/blockchain.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'core/blockchain.go') diff --git a/core/blockchain.go b/core/blockchain.go index f8d9bca9e..f4f4c425c 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1596,7 +1596,7 @@ func (bc *BlockChain) processPendingBlock( return nil, nil, nil, err } - // Iterate over and process the individual transactions + // Iterate over and process the individual transactions. for i, tx := range block.Transactions() { pendingState.Prepare(tx.Hash(), block.Hash(), i) receipt, _, err := ApplyTransaction(bc.chainConfig, bc, nil, gp, pendingState, header, tx, usedGas, bc.vmConfig) @@ -1613,19 +1613,23 @@ func (bc *BlockChain) processPendingBlock( return nil, nil, nil, fmt.Errorf("finalize error: %v", err) } + if _, ok := bc.GetRoundHeight(newPendingBlock.Round()); !ok { + bc.storeRoundHeight(newPendingBlock.Round(), newPendingBlock.NumberU64()) + } + proctime := time.Since(bstart) - // commit state to refresh stateCache + // Commit state to refresh stateCache. _, err = pendingState.Commit(true) if err != nil { return nil, nil, nil, fmt.Errorf("pendingState commit error: %v", err) } - // add into pending blocks + // Add into pending blocks. bc.addPendingBlock(newPendingBlock, receipts) events = append(events, BlockConfirmedEvent{newPendingBlock}) - // start insert available pending blocks into db + // Start insert available pending blocks into db for pendingHeight := bc.CurrentBlock().NumberU64() + 1; pendingHeight <= witness.Height; pendingHeight++ { pendingIns, exist := bc.pendingBlocks[pendingHeight] if !exist { @@ -1646,8 +1650,9 @@ func (bc *BlockChain) processPendingBlock( switch status { case CanonStatTy: - log.Debug("Inserted new block", "number", pendingIns.block.Number(), "hash", pendingIns.block.Hash(), "uncles", len(pendingIns.block.Uncles()), - "txs", len(pendingIns.block.Transactions()), "gas", pendingIns.block.GasUsed(), "elapsed", common.PrettyDuration(time.Since(bstart))) + log.Debug("Inserted new block", "number", pendingIns.block.Number(), "hash", pendingIns.block.Hash(), + "uncles", len(pendingIns.block.Uncles()), "txs", len(pendingIns.block.Transactions()), + "gas", pendingIns.block.GasUsed(), "elapsed", common.PrettyDuration(time.Since(bstart))) var allLogs []*types.Log for _, r := range pendingIns.receipts { @@ -1671,10 +1676,6 @@ func (bc *BlockChain) processPendingBlock( cache, _ := bc.stateCache.TrieDB().Size() stats.report([]*types.Block{pendingIns.block}, 0, cache) - - if _, ok := bc.GetRoundHeight(pendingIns.block.Round()); !ok { - bc.storeRoundHeight(pendingIns.block.Round(), pendingHeight) - } } // Append a single chain head event if we've progressed the chain if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() { -- cgit v1.2.3