aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2019-04-30 16:03:57 +0800
committerGitHub <noreply@github.com>2019-04-30 16:03:57 +0800
commitbefca7e8b0eac00499155c0b9d25814615f0fe24 (patch)
tree521ce83f8dd8645b22a278175a2990ae7028cf8a
parentaf96b6644e2f73603ffd25b7d5df38e79d99c263 (diff)
parented47f29bc8140d0031927804ef89a6bdde810d7d (diff)
downloadgo-tangerine-befca7e8b0eac00499155c0b9d25814615f0fe24.tar.gz
go-tangerine-befca7e8b0eac00499155c0b9d25814615f0fe24.tar.zst
go-tangerine-befca7e8b0eac00499155c0b9d25814615f0fe24.zip
Merge pull request #19500 from karalabe/cht-txpool-open-limit
eth: enforce chain above CHT before accepting txs into the pool
-rw-r--r--eth/handler.go25
-rw-r--r--eth/sync.go13
2 files changed, 32 insertions, 6 deletions
diff --git a/eth/handler.go b/eth/handler.go
index 29f224910..7b753ebb4 100644
--- a/eth/handler.go
+++ b/eth/handler.go
@@ -181,13 +181,30 @@ func NewProtocolManager(config *params.ChainConfig, mode downloader.SyncMode, ne
return blockchain.CurrentBlock().NumberU64()
}
inserter := func(blocks types.Blocks) (int, error) {
- // If fast sync is running, deny importing weird blocks
+ // If sync hasn't reached the checkpoint yet, deny importing weird blocks.
+ //
+ // Ideally we would also compare the head block's timestamp and similarly reject
+ // the propagated block if the head is too old. Unfortunately there is a corner
+ // case when starting new networks, where the genesis might be ancient (0 unix)
+ // which would prevent full nodes from accepting it.
+ if manager.blockchain.CurrentBlock().NumberU64() < manager.checkpointNumber {
+ log.Warn("Unsynced yet, discarded propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
+ return 0, nil
+ }
+ // If fast sync is running, deny importing weird blocks. This is a problematic
+ // clause when starting up a new network, because fast-syncing miners might not
+ // accept each others' blocks until a restart. Unfortunately we haven't figured
+ // out a way yet where nodes can decide unilaterally whether the network is new
+ // or not. This should be fixed if we figure out a solution.
if atomic.LoadUint32(&manager.fastSync) == 1 {
- log.Warn("Discarded bad propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
+ log.Warn("Fast syncing, discarded propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
return 0, nil
}
- atomic.StoreUint32(&manager.acceptTxs, 1) // Mark initial sync done on any fetcher import
- return manager.blockchain.InsertChain(blocks)
+ n, err := manager.blockchain.InsertChain(blocks)
+ if err == nil {
+ atomic.StoreUint32(&manager.acceptTxs, 1) // Mark initial sync done on any fetcher import
+ }
+ return n, err
}
manager.fetcher = fetcher.New(blockchain.GetBlockByHash, validator, manager.BroadcastBlock, heighter, inserter, manager.removePeer)
diff --git a/eth/sync.go b/eth/sync.go
index 3e23c5378..e303ef8d4 100644
--- a/eth/sync.go
+++ b/eth/sync.go
@@ -202,8 +202,17 @@ func (pm *ProtocolManager) synchronise(peer *peer) {
log.Info("Fast sync complete, auto disabling")
atomic.StoreUint32(&pm.fastSync, 0)
}
- atomic.StoreUint32(&pm.acceptTxs, 1) // Mark initial sync done
- if head := pm.blockchain.CurrentBlock(); head.NumberU64() > 0 {
+ // If we've successfully finished a sync cycle and passed any required checkpoint,
+ // enable accepting transactions from the network.
+ head := pm.blockchain.CurrentBlock()
+ if head.NumberU64() >= pm.checkpointNumber {
+ // Checkpoint passed, sanity check the timestamp to have a fallback mechanism
+ // for non-checkpointed (number = 0) private networks.
+ if head.Time() >= uint64(time.Now().AddDate(0, -1, 0).Unix()) {
+ atomic.StoreUint32(&pm.acceptTxs, 1)
+ }
+ }
+ if head.NumberU64() > 0 {
// We've completed a sync cycle, notify all peers of new state. This path is
// essential in star-topology networks where a gateway node needs to notify
// all its out-of-date peers of the availability of a new block. This failure