diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-17 13:18:34 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:53 +0800 |
commit | bdfdd7cd028518e0bbbc6a7e0ed8322190b80582 (patch) | |
tree | bad3cb92055806b99a11827d479ce269c1ea662a /core/blockchain.go | |
parent | 1677355db643a52843a202529d0a044453b090b6 (diff) | |
download | dexon-bdfdd7cd028518e0bbbc6a7e0ed8322190b80582.tar dexon-bdfdd7cd028518e0bbbc6a7e0ed8322190b80582.tar.gz dexon-bdfdd7cd028518e0bbbc6a7e0ed8322190b80582.tar.bz2 dexon-bdfdd7cd028518e0bbbc6a7e0ed8322190b80582.tar.lz dexon-bdfdd7cd028518e0bbbc6a7e0ed8322190b80582.tar.xz dexon-bdfdd7cd028518e0bbbc6a7e0ed8322190b80582.tar.zst dexon-bdfdd7cd028518e0bbbc6a7e0ed8322190b80582.zip |
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.
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 21 |
1 files changed, 11 insertions, 10 deletions
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() { |