mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
dont panic
This commit is contained in:
parent
d4938065c1
commit
89fadee71e
2 changed files with 34 additions and 17 deletions
|
|
@ -184,7 +184,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
// END: Bor changes
|
||||
|
||||
bcVersion := rawdb.ReadDatabaseVersion(chainDb)
|
||||
var dbVer = "<nil>"
|
||||
dbVer := "<nil>"
|
||||
if bcVersion != nil {
|
||||
dbVer = fmt.Sprintf("%d", *bcVersion)
|
||||
}
|
||||
|
|
@ -598,22 +598,25 @@ func (s *Ethereum) Start() error {
|
|||
// StartCheckpointWhitelistService starts the goroutine to fetch checkpoints and update the
|
||||
// checkpoint whitelist map.
|
||||
func (s *Ethereum) startCheckpointWhitelistService() {
|
||||
every := time.Duration(100) * time.Second
|
||||
ticker := time.NewTicker(every)
|
||||
defer ticker.Stop()
|
||||
|
||||
// first run the checkpoint whitelist
|
||||
err := s.handleWhitelistCheckpoint()
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrBorConsensusWithoutHeimdall) || errors.Is(err, ErrNotBorConsensus) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Warn("the first run", "err", err)
|
||||
}
|
||||
|
||||
ticker := time.NewTicker(100 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
err := s.handleWhitelistCheckpoint()
|
||||
if err != nil {
|
||||
log.Warn(err.Error())
|
||||
log.Warn("couldn't get whitelist checkpoint", "err", err)
|
||||
}
|
||||
case <-s.closeCh:
|
||||
return
|
||||
|
|
@ -621,20 +624,32 @@ func (s *Ethereum) startCheckpointWhitelistService() {
|
|||
}
|
||||
}
|
||||
|
||||
var (
|
||||
ErrNotBorConsensus = errors.New("not Bor consensus was given")
|
||||
ErrBorConsensusWithoutHeimdall = errors.New("Bor consensus without Heimdall")
|
||||
)
|
||||
|
||||
// handleWhitelistCheckpoint handles the checkpoint whitelist mechanism.
|
||||
func (s *Ethereum) handleWhitelistCheckpoint() error {
|
||||
ethHandler := (*ethHandler)(s.handler)
|
||||
|
||||
if !ethHandler.chain.Engine().(*bor.Bor).WithoutHeimdall {
|
||||
endBlockNum, endBlockHash, err := ethHandler.fetchWhitelistCheckpoint()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update the checkpoint whitelist map.
|
||||
ethHandler.downloader.ProcessCheckpoint(endBlockNum, endBlockHash)
|
||||
bor, ok := ethHandler.chain.Engine().(*bor.Bor)
|
||||
if !ok {
|
||||
return ErrNotBorConsensus
|
||||
}
|
||||
|
||||
if bor.WithoutHeimdall {
|
||||
return ErrBorConsensusWithoutHeimdall
|
||||
}
|
||||
|
||||
endBlockNum, endBlockHash, err := ethHandler.fetchWhitelistCheckpoint(bor)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update the checkpoint whitelist map.
|
||||
ethHandler.downloader.ProcessCheckpoint(endBlockNum, endBlockHash)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ package eth
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
|
@ -14,9 +14,9 @@ import (
|
|||
|
||||
// fetchWhitelistCheckpoint fetched the latest checkpoint from it's local heimdall
|
||||
// and verifies the data against bor data.
|
||||
func (h *ethHandler) fetchWhitelistCheckpoint() (uint64, common.Hash, error) {
|
||||
func (h *ethHandler) fetchWhitelistCheckpoint(bor *bor.Bor) (uint64, common.Hash, error) {
|
||||
// check for checkpoint whitelisting: bor
|
||||
checkpoint, err := h.chain.Engine().(*bor.Bor).HeimdallClient.FetchLatestCheckpoint()
|
||||
checkpoint, err := bor.HeimdallClient.FetchLatestCheckpoint()
|
||||
if err != nil {
|
||||
log.Debug("Failed to fetch latest checkpoint for whitelisting")
|
||||
return 0, common.Hash{}, errors.New("failed to fetch latest checkpoint")
|
||||
|
|
@ -47,6 +47,8 @@ func (h *ethHandler) fetchWhitelistCheckpoint() (uint64, common.Hash, error) {
|
|||
log.Debug("Failed to get end block hash of checkpoint while whitelisting")
|
||||
return 0, common.Hash{}, errors.New("failed to get end block")
|
||||
}
|
||||
|
||||
hash := fmt.Sprintf("%v", block["hash"])
|
||||
|
||||
return checkpoint.EndBlock.Uint64(), common.HexToHash(hash), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue