Skip to content

handler.startBlockFetcher

Source (upstream pre-purge) Current
File eth/handler.go handler_pow.go
Symbol newHandler (lines 208-278) handler.startBlockFetcher
Ref f4d53133f~1 etc/v1.17.3-full-node

Extracted from newHandler() inline code into a separate method. Removed PoS merger/TDD checks (not applicable to ETC).

Diff — vs pre-nuke original (reimplemented)

--- a/eth/handler.go
+++ b/eth/handler_pow.go
@@ -1,71 +1,17 @@
+func (h *handler) startBlockFetcher() {
    validator := func(header *types.Header) error {
-       // All the block fetcher activities should be disabled
-       // after the transition. Print the warning log.
-       if h.merger.PoSFinalized() {
-           log.Warn("Unexpected validation activity", "hash", header.Hash(), "number", header.Number)
-           return errors.New("unexpected behavior after transition")
-       }
-       // Reject all the PoS style headers in the first place. No matter
-       // the chain has finished the transition or not, the PoS headers
-       // should only come from the trusted consensus layer instead of
-       // p2p network.
-       if beacon, ok := h.chain.Engine().(*beacon.Beacon); ok {
-           if beacon.IsPoSHeader(header) {
-               return errors.New("unexpected post-merge header")
-           }
-       }
        return h.chain.Engine().VerifyHeader(h.chain, header)
    }
    heighter := func() uint64 {
        return h.chain.CurrentBlock().Number.Uint64()
    }
    inserter := func(blocks types.Blocks) (int, error) {
-       // All the block fetcher activities should be disabled
-       // after the transition. Print the warning log.
-       if h.merger.PoSFinalized() {
-           var ctx []interface{}
-           ctx = append(ctx, "blocks", len(blocks))
-           if len(blocks) > 0 {
-               ctx = append(ctx, "firsthash", blocks[0].Hash())
-               ctx = append(ctx, "firstnumber", blocks[0].Number())
-               ctx = append(ctx, "lasthash", blocks[len(blocks)-1].Hash())
-               ctx = append(ctx, "lastnumber", blocks[len(blocks)-1].Number())
-           }
-           log.Warn("Unexpected insertion activity", ctx...)
-           return 0, errors.New("unexpected behavior after transition")
-       }
-       // If snap sync is running, deny importing weird blocks. This is a problematic
-       // clause when starting up a new network, because snap-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 sync hasn't completed yet, deny importing propagated blocks
        if !h.synced.Load() {
            log.Warn("Syncing, discarded propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
            return 0, nil
        }
-       if h.merger.TDDReached() {
-           // The blocks from the p2p network is regarded as untrusted
-           // after the transition. In theory block gossip should be disabled
-           // entirely whenever the transition is started. But in order to
-           // handle the transition boundary reorg in the consensus-layer,
-           // the legacy blocks are still accepted, but only for the terminal
-           // pow blocks. Spec: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3675.md#halt-the-importing-of-pow-blocks
-           for i, block := range blocks {
-               ptd := h.chain.GetTd(block.ParentHash(), block.NumberU64()-1)
-               if ptd == nil {
-                   return 0, nil
-               }
-               td := new(big.Int).Add(ptd, block.Difficulty())
-               if !h.chain.Config().IsTerminalPoWBlock(ptd, td) {
-                   log.Info("Filtered out non-terminal pow block", "number", block.NumberU64(), "hash", block.Hash())
-                   return 0, nil
-               }
-               if err := h.chain.InsertBlockWithoutSetHead(block); err != nil {
-                   return i, err
-               }
-           }
-           return 0, nil
-       }
        return h.chain.InsertChain(blocks)
    }
    h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, h.BroadcastBlock, heighter, nil, inserter, h.removePeer)
+}
core-geth validation — +5 -74 | | | |---|---| | File | [`handler.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/eth/handler.go) | | Symbol | `handler.newHandler` | | Ref | `v1.12.20` |
--- a/core-geth/eth/handler.go
+++ b/etc/eth/handler_pow.go
@@ -1,86 +1,17 @@
+func (h *handler) startBlockFetcher() {
    validator := func(header *types.Header) error {
-       // All the block fetcher activities should be disabled
-       // after the transition. Print the warning log.
-       if h.merger.PoSFinalized() {
-           log.Warn("Unexpected validation activity", "hash", header.Hash(), "number", header.Number)
-           return errors.New("unexpected behavior after transition")
-       }
-       // Reject all the PoS style headers in the first place. No matter
-       // the chain has finished the transition or not, the PoS headers
-       // should only come from the trusted consensus layer instead of
-       // p2p network.
-       if beacon, ok := h.chain.Engine().(*beacon.Beacon); ok {
-           if beacon.IsPoSHeader(header) {
-               return errors.New("unexpected post-merge header")
-           }
-       }
-       return h.chain.Engine().VerifyHeader(h.chain, header, true)
+       return h.chain.Engine().VerifyHeader(h.chain, header)
    }
    heighter := func() uint64 {
        return h.chain.CurrentBlock().Number.Uint64()
    }
    inserter := func(blocks types.Blocks) (int, error) {
-       // All the block fetcher activities should be disabled
-       // after the transition. Print the warning log.
-       if h.merger.PoSFinalized() {
-           var ctx []interface{}
-           ctx = append(ctx, "blocks", len(blocks))
-           if len(blocks) > 0 {
-               ctx = append(ctx, "firsthash", blocks[0].Hash())
-               ctx = append(ctx, "firstnumber", blocks[0].Number())
-               ctx = append(ctx, "lasthash", blocks[len(blocks)-1].Hash())
-               ctx = append(ctx, "lastnumber", blocks[len(blocks)-1].Number())
-           }
-           log.Warn("Unexpected insertion activity", ctx...)
-           return 0, errors.New("unexpected behavior after transition")
-       }
-       // 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 h.chain.CurrentBlock().Number.Uint64() < h.checkpointNumber {
-           log.Warn("Unsynced yet, discarded propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
-           return 0, nil
-       }
-       // If snap sync is running, deny importing weird blocks. This is a problematic
-       // clause when starting up a new network, because snap-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 sync hasn't completed yet, deny importing propagated blocks
        if !h.synced.Load() {
            log.Warn("Syncing, discarded propagated block", "number", blocks[0].Number(), "hash", blocks[0].Hash())
            return 0, nil
        }
-       if h.merger.TDDReached() {
-           // The blocks from the p2p network is regarded as untrusted
-           // after the transition. In theory block gossip should be disabled
-           // entirely whenever the transition is started. But in order to
-           // handle the transition boundary reorg in the consensus-layer,
-           // the legacy blocks are still accepted, but only for the terminal
-           // pow blocks. Spec: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3675.md#halt-the-importing-of-pow-blocks
-           for i, block := range blocks {
-               ptd := h.chain.GetTd(block.ParentHash(), block.NumberU64()-1)
-               if ptd == nil {
-                   return 0, nil
-               }
-               td := new(big.Int).Add(ptd, block.Difficulty())
-               if !h.chain.Config().IsTerminalPoWBlock(ptd, td) {
-                   log.Info("Filtered out non-terminal pow block", "number", block.NumberU64(), "hash", block.Hash())
-                   return 0, nil
-               }
-               if err := h.chain.InsertBlockWithoutSetHead(block); err != nil {
-                   return i, err
-               }
-           }
-           return 0, nil
-       }
-       n, err := h.chain.InsertChain(blocks)
-       // PTAL(meowsbits) This chunk was removed upstream. (No acceptTxs.Store...)
-       if err == nil {
-           h.eventMux.Post(fetcher.InsertChainEvent{Blocks: blocks})
-       }
-       return n, err
+       return h.chain.InsertChain(blocks)
    }
    h.blockFetcher = fetcher.NewBlockFetcher(false, nil, h.chain.GetBlockByHash, validator, h.BroadcastBlock, heighter, nil, inserter, h.removePeer)
+}

← Eth Service