[ethereum/go-ethereum] light: CHT and bloom trie indexers working in light mode (#16534)

in case it will be helpful: i wanted to use this PR for pruning headers from older sections
but when i tried to sync headers cht indexer entered corrupted state which leads to such
this log being repeated all the time:

«`
INFO [08-15|10:36:33] Upgrading chain index type=cht percentage=0
ERROR[08-15|10:36:17] Section processing failed type=cht error=»canonical block #1 unknown»
ERROR[08-15|10:36:17] Section processing failed type=cht error=»canonical block #1 unknown»
ERROR[08-15|10:36:17] Section processing failed type=cht error=»canonical block #1 unknown»
ERROR[08-15|10:36:17] Section processing failed type=cht error=»canonical block #1 unknown»
«`

i decided that cht indexer state is corrupted, because i have another log that shows what is the last section number and section head
when SyncCht is called for synchronising with a peer:

«`
INFO [08-15|10:36:15] SYNC CHT head num=5848127 cht count=0 sec head=0x0000000000000000000000000000000000000000000000000000000000000000
«`

Without this PR it will print adequate information such as:

«`
INFO [08-15|10:44:02] SYNC CHT head num=0 cht count=175 sec head=0xa3ef48cd8f1c3a08419f0237fc7763491fe89497b3144b17adf87c1c43664613
«`

No special steps are required. Geth binary was build from this PR

«`
./geth —light —v5disc —verbosity 3 —datadir /tmp/cht2
«`

diff for a log line just in case:

«`
diff —git a/light/lightchain.go b/light/lightchain.go
index a30bfb5ae..f8c48217f 100644
— a/light/lightchain.go
+++ b/light/lightchain.go
@@ -456,7 +456,8 @@ func (self *LightChain) SyncCht(ctx context.Context) bool {
return false
}
headNum := self.CurrentHeader().Number.Uint64()
— chtCount, _, _ := self.odr.ChtIndexer().Sections()
+ chtCount, _, secHead := self.odr.ChtIndexer().Sections()
+ log.Info(«SYNC CHT», «head num», headNum, «cht count», chtCount, «sec head», secHead.String())
if headNum+1 < chtCount*CHTFrequencyClient { num := chtCount*CHTFrequencyClient - 1 header, err := GetHeaderByNumber(ctx, self.odr, num) ```

Добавить комментарий