ForkChoice¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | core/forkchoice.go |
forkchoice_pow.go |
| Symbol | ForkChoice |
ForkChoice |
| Ref | f4d53133f~1 |
etc/v1.17.3-full-node |
Adds
reorgFiltercallback field — extension point for MESS artificial finality (set viaSetReorgFilterin blockchain_mess.go)
3-way merge — purge → getc ← upstream¶
pre-purgefork-only
↗// ForkChoice is the fork chooser based on the highest total difficulty of the
// chain(the fork choice used in the eth1) and the external fork choice (the fork
// choice used in the eth2). This main goal of this ForkChoice is not only for
// offering fork choice during the eth1/2 merge phase, but also keep the compatibility
// for all other proof-of-work networks.
type ForkChoice struct {
chain ChainReader
rand *mrand.Rand
↗ // preserve is a helper function used in td fork choice.
// Miners will prefer to choose the local mined block if the
// local td is equal to the extern one. It can be nil for light
// client
preserve func(header *types.Header) bool
// reorgFilter is an optional callback that validates whether a reorg
// warranted by TD should actually be applied. Returns nil if allowed,
// non-nil error if the reorg must be rejected.
reorgFilter func(current, extern *types.Header) error
// sideBlockFeed delivers the headers of blocks that lost the fork choice
// (were not adopted as canonical) to subscribers — namely the PoW miner,
// which collects them as uncle candidates.
sideBlockFeed event.Feed
↗}
core-geth validation — +11 -1
| | | |---|---| | File | [`forkchoice.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/core/forkchoice.go) | | Symbol | `ForkChoice` | | Ref | `v1.12.20` |--- a/core-geth/core/forkchoice.go
+++ b/etc/core/forkchoice_pow.go
@@ -4,7 +4,7 @@
// offering fork choice during the eth1/2 merge phase, but also keep the compatibility
// for all other proof-of-work networks.
type ForkChoice struct {
- chain consensus.ChainHeaderReader
+ chain ChainReader
rand *mrand.Rand
// preserve is a helper function used in td fork choice.
@@ -12,4 +12,14 @@
// local td is equal to the extern one. It can be nil for light
// client
preserve func(header *types.Header) bool
+
+ // reorgFilter is an optional callback that validates whether a reorg
+ // warranted by TD should actually be applied. Returns nil if allowed,
+ // non-nil error if the reorg must be rejected.
+ reorgFilter func(current, extern *types.Header) error
+
+ // sideBlockFeed delivers the headers of blocks that lost the fork choice
+ // (were not adopted as canonical) to subscribers — namely the PoW miner,
+ // which collects them as uncle candidates.
+ sideBlockFeed event.Feed
}