aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorSonic <sonic@dexon.org>2018-12-21 14:53:37 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commitf5522f0ffcbe127a8fd364647848be46ecc68cda (patch)
treefb31ed0a49864ff6876f2130acd5e33c245fad1a /core
parent4002c85e8e073f3a03dbd8c71e98188c0306a942 (diff)
downloaddexon-f5522f0ffcbe127a8fd364647848be46ecc68cda.tar.gz
dexon-f5522f0ffcbe127a8fd364647848be46ecc68cda.tar.zst
dexon-f5522f0ffcbe127a8fd364647848be46ecc68cda.zip
core, dex, internal: block proposer syncing (first iteration) (#96)
* dex, internal: block proposer syncing (first iteration) * core: find block from db if not in memory This fix handles stopping proposing and then restarting * core: no need to reorg when reset Dexon will not fork. This commit also fix when a block confirm but its parent is not in db yet, during restarting proposing. * dex: always accept NewBlockMsg, NewBlockHashesMsg We need to accept NewBlockMsg, NewBlockHashesMsg to sync current block with other peers in block proposer mode when syncing lattice data. It's a waste when the node is synced and start proposing. Todo: control msg processing on/off more granular, accept NewBlockMsg, NewBlockHashesMsg when syncing, but stop when synced.
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go6
-rw-r--r--core/tx_pool.go53
2 files changed, 2 insertions, 57 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 31336f555..8ceb1186c 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1796,8 +1796,6 @@ func (bc *BlockChain) processPendingBlock(
return nil, nil, nil, fmt.Errorf("validate witness data error: %v", err)
}
- currentBlock := bc.CurrentBlock()
-
var (
receipts types.Receipts
usedGas = new(uint64)
@@ -1810,8 +1808,8 @@ func (bc *BlockChain) processPendingBlock(
var err error
parent, exist := bc.pendingBlocks[block.NumberU64()-1]
if !exist {
- parentBlock = currentBlock
- if parentBlock.NumberU64() != block.NumberU64()-1 {
+ parentBlock = bc.GetBlockByNumber(block.NumberU64() - 1)
+ if parentBlock == nil {
return nil, nil, nil, fmt.Errorf("parent block %d not exist", block.NumberU64()-1)
}
} else {
diff --git a/core/tx_pool.go b/core/tx_pool.go
index ea2025cde..911b6c261 100644
--- a/core/tx_pool.go
+++ b/core/tx_pool.go
@@ -19,7 +19,6 @@ package core
import (
"errors"
"fmt"
- "math"
"math/big"
"sort"
"sync"
@@ -405,53 +404,6 @@ func (pool *TxPool) lockedReset(oldHead, newHead *types.Header) {
// reset retrieves the current state of the blockchain and ensures the content
// of the transaction pool is valid with regard to the chain state.
func (pool *TxPool) reset(oldHead, newHead *types.Header) {
- // If we're reorging an old state, reinject all dropped transactions
- var reinject types.Transactions
-
- if oldHead != nil && oldHead.Hash() != newHead.ParentHash {
- // If the reorg is too deep, avoid doing it (will happen during fast sync)
- oldNum := oldHead.Number.Uint64()
- newNum := newHead.Number.Uint64()
-
- if depth := uint64(math.Abs(float64(oldNum) - float64(newNum))); depth > 64 {
- log.Debug("Skipping deep transaction reorg", "depth", depth)
- } else {
- // Reorg seems shallow enough to pull in all transactions into memory
- var discarded, included types.Transactions
-
- var (
- rem = pool.chain.GetBlock(oldHead.Hash(), oldHead.Number.Uint64())
- add = pool.chain.GetBlock(newHead.Hash(), newHead.Number.Uint64())
- )
- for rem.NumberU64() > add.NumberU64() {
- discarded = append(discarded, rem.Transactions()...)
- if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil {
- log.Error("Unrooted old chain seen by tx pool", "block", oldHead.Number, "hash", oldHead.Hash())
- return
- }
- }
- for add.NumberU64() > rem.NumberU64() {
- included = append(included, add.Transactions()...)
- if add = pool.chain.GetBlock(add.ParentHash(), add.NumberU64()-1); add == nil {
- log.Error("Unrooted new chain seen by tx pool", "block", newHead.Number, "hash", newHead.Hash())
- return
- }
- }
- for rem.Hash() != add.Hash() {
- discarded = append(discarded, rem.Transactions()...)
- if rem = pool.chain.GetBlock(rem.ParentHash(), rem.NumberU64()-1); rem == nil {
- log.Error("Unrooted old chain seen by tx pool", "block", oldHead.Number, "hash", oldHead.Hash())
- return
- }
- included = append(included, add.Transactions()...)
- if add = pool.chain.GetBlock(add.ParentHash(), add.NumberU64()-1); add == nil {
- log.Error("Unrooted new chain seen by tx pool", "block", newHead.Number, "hash", newHead.Hash())
- return
- }
- }
- reinject = types.TxDifference(discarded, included)
- }
- }
// Initialize the internal state to the current head
if newHead == nil {
newHead = pool.chain.CurrentBlock().Header() // Special case during testing
@@ -465,11 +417,6 @@ func (pool *TxPool) reset(oldHead, newHead *types.Header) {
pool.pendingState = state.ManageState(statedb)
pool.currentMaxGas = newHead.GasLimit
- // Inject any transactions discarded due to reorgs
- log.Debug("Reinjecting stale transactions", "count", len(reinject))
- senderCacher.recover(pool.signer, reinject)
- pool.addTxsLocked(reinject, false)
-
// validate the pool of pending transactions, this will remove
// any transactions that have been included in the block or
// have been invalidated because of another transaction (e.g.