[ethereum/go-ethereum] contracts: add checkpoint registrar smart contract (#16842)

rjl493456442 commented on this pull request.

> + for {
+ select {
+ case event := <-eventCh: + if event == nil { + // This should never happen. + log.Info("Ignore empty checkpoint event") + continue + } + // Note several events have same index may be received because of chain reorg and + // the modification of the latest checkpoint. + if checkpoint == nil || event.Index.Uint64() > checkpoint.SectionIdx {
+ log.Info(«Receive new checkpoint event», «section», event.Index, «hash», common.Hash(event.CheckpointHash).Hex(),
+ «grantor», event.Grantor.Hex())
+ announcement[event.Index.Uint64()] = common.Hash(event.CheckpointHash)
+ }
+ case head := <-headCh: If at that time(announcement received, current block number > section height + 256) cht root and bloom trie root have not been calculated, the generated checkpoint will mismatch the hash attached in announcement. So that server will try to generate a stable checkpoint and match the hash in the next few blocks until indexer finishes calculation.

And for order should be:
— indexer calculates and generates unstable checkpoint
— admin fetches and register the unstable checkpoint
— server receives checkpoint announcement
— persist stable checkpoint

If we subscribe events from indexer, the logic will only be triggered every 32768 blocks. And for the usual case, `new section event` will be received early than `unstable checkpoint announcement`. So that we can not update stable checkpoint asap

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