@@ -25,11 +25,14 @@ import (
2525 "github.com/ethereum/go-ethereum/log"
2626)
2727
28- // headerRetriever is used by the unconfirmed block set to verify whether a previously
28+ // chainRetriever is used by the unconfirmed block set to verify whether a previously
2929// mined block is part of the canonical chain or not.
30- type headerRetriever interface {
30+ type chainRetriever interface {
3131 // GetHeaderByNumber retrieves the canonical header associated with a block number.
3232 GetHeaderByNumber (number uint64 ) * types.Header
33+
34+ // GetBlockByNumber retrieves the canonical block associated with a block number.
35+ GetBlockByNumber (number uint64 ) * types.Block
3336}
3437
3538// unconfirmedBlock is a small collection of metadata about a locally mined block
@@ -44,14 +47,14 @@ type unconfirmedBlock struct {
4447// used by the miner to provide logs to the user when a previously mined block
4548// has a high enough guarantee to not be reorged out of the canonical chain.
4649type unconfirmedBlocks struct {
47- chain headerRetriever // Blockchain to verify canonical status through
48- depth uint // Depth after which to discard previous blocks
49- blocks * ring.Ring // Block infos to allow canonical chain cross checks
50- lock sync.RWMutex // Protects the fields from concurrent access
50+ chain chainRetriever // Blockchain to verify canonical status through
51+ depth uint // Depth after which to discard previous blocks
52+ blocks * ring.Ring // Block infos to allow canonical chain cross checks
53+ lock sync.RWMutex // Protects the fields from concurrent access
5154}
5255
5356// newUnconfirmedBlocks returns new data structure to track currently unconfirmed blocks.
54- func newUnconfirmedBlocks (chain headerRetriever , depth uint ) * unconfirmedBlocks {
57+ func newUnconfirmedBlocks (chain chainRetriever , depth uint ) * unconfirmedBlocks {
5558 return & unconfirmedBlocks {
5659 chain : chain ,
5760 depth : depth ,
@@ -103,7 +106,23 @@ func (set *unconfirmedBlocks) Shift(height uint64) {
103106 case header .Hash () == next .hash :
104107 log .Info ("🔗 block reached canonical chain" , "number" , next .index , "hash" , next .hash )
105108 default :
106- log .Info ("⑂ block became a side fork" , "number" , next .index , "hash" , next .hash )
109+ // Block is not canonical, check whether we have an uncle or a lost block
110+ included := false
111+ for number := next .index ; ! included && number < next .index + uint64 (set .depth ) && number <= height ; number ++ {
112+ if block := set .chain .GetBlockByNumber (number ); block != nil {
113+ for _ , uncle := range block .Uncles () {
114+ if uncle .Hash () == next .hash {
115+ included = true
116+ break
117+ }
118+ }
119+ }
120+ }
121+ if included {
122+ log .Info ("⑂ block became an uncle" , "number" , next .index , "hash" , next .hash )
123+ } else {
124+ log .Info ("😱 block lost" , "number" , next .index , "hash" , next .hash )
125+ }
107126 }
108127 // Drop the block out of the ring
109128 if set .blocks .Value == set .blocks .Next ().Value {
0 commit comments