aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain.go
diff options
context:
space:
mode:
authorWei-Ning Huang <w@dexon.org>2018-11-17 13:18:34 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:18 +0800
commite5ebb174d61a6f7b0b9c6023b15c33a246b2c14f (patch)
treebde9aad9a676129fdb92732ea7a9d92bdfeb7e8b /core/blockchain.go
parent10697136e876446a2807d9fd4799a0a5b9605e30 (diff)
downloadgo-tangerine-e5ebb174d61a6f7b0b9c6023b15c33a246b2c14f.tar
go-tangerine-e5ebb174d61a6f7b0b9c6023b15c33a246b2c14f.tar.gz
go-tangerine-e5ebb174d61a6f7b0b9c6023b15c33a246b2c14f.tar.bz2
go-tangerine-e5ebb174d61a6f7b0b9c6023b15c33a246b2c14f.tar.lz
go-tangerine-e5ebb174d61a6f7b0b9c6023b15c33a246b2c14f.tar.xz
go-tangerine-e5ebb174d61a6f7b0b9c6023b15c33a246b2c14f.tar.zst
go-tangerine-e5ebb174d61a6f7b0b9c6023b15c33a246b2c14f.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.go21
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() {