mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
minor fixes
This commit is contained in:
parent
b1b0c0e2fb
commit
fb46dd8cdf
2 changed files with 16 additions and 7 deletions
|
|
@ -586,10 +586,12 @@ func (s *Ethereum) Start() error {
|
|||
}
|
||||
maxPeers -= s.config.LightPeers
|
||||
}
|
||||
|
||||
// Start the networking layer and the light server if requested
|
||||
s.handler.Start(maxPeers)
|
||||
|
||||
go s.startCheckpointWhitelistService()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -600,7 +602,12 @@ func (s *Ethereum) startCheckpointWhitelistService() {
|
|||
ticker := time.NewTicker(every)
|
||||
defer ticker.Stop()
|
||||
|
||||
Loop:
|
||||
// first run the checkpoint whitelist
|
||||
err := s.handleWhitelistCheckpoint()
|
||||
if err != nil {
|
||||
log.Warn("the first run", "err", err)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
|
|
@ -609,7 +616,7 @@ Loop:
|
|||
log.Warn(err.Error())
|
||||
}
|
||||
case <-s.closeCh:
|
||||
break Loop
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package eth
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
|
@ -18,32 +19,33 @@ func (h *ethHandler) fetchWhitelistCheckpoint() (uint64, common.Hash, error) {
|
|||
checkpoint, err := h.chain.Engine().(*bor.Bor).HeimdallClient.FetchLatestCheckpoint()
|
||||
if err != nil {
|
||||
log.Debug("Failed to fetch latest checkpoint for whitelisting")
|
||||
return 0, common.Hash{}, fmt.Errorf("failed to fetch latest checkpoint")
|
||||
return 0, common.Hash{}, errors.New("failed to fetch latest checkpoint")
|
||||
}
|
||||
|
||||
// check if we have the checkpoint blocks
|
||||
head := h.ethAPI.BlockNumber()
|
||||
if head < hexutil.Uint64(checkpoint.EndBlock.Uint64()) {
|
||||
log.Debug("Head block behing checkpoint block", "head", head, "checkpoint end block", checkpoint.EndBlock)
|
||||
return 0, common.Hash{}, fmt.Errorf("missing checkpoint blocks")
|
||||
return 0, common.Hash{}, errors.New("missing checkpoint blocks")
|
||||
}
|
||||
|
||||
// verify the root hash of checkpoint
|
||||
roothash, err := h.ethAPI.GetRootHash(context.Background(), checkpoint.StartBlock.Uint64(), checkpoint.EndBlock.Uint64())
|
||||
if err != nil {
|
||||
log.Debug("Failed to get root hash of checkpoint while whitelisting")
|
||||
return 0, common.Hash{}, fmt.Errorf("failed to get local root hash")
|
||||
return 0, common.Hash{}, errors.New("failed to get local root hash")
|
||||
}
|
||||
|
||||
if roothash != checkpoint.RootHash.String()[2:] {
|
||||
log.Warn("Checkpoint root hash mismatch while whitelisting", "expected", checkpoint.RootHash.String()[2:], "got", roothash)
|
||||
return 0, common.Hash{}, fmt.Errorf("checkpoint roothash mismatch")
|
||||
return 0, common.Hash{}, errors.New("checkpoint roothash mismatch")
|
||||
}
|
||||
|
||||
// fetch the end checkpoint block hash
|
||||
block, err := h.ethAPI.GetBlockByNumber(context.Background(), rpc.BlockNumber(checkpoint.EndBlock.Uint64()), false)
|
||||
if err != nil {
|
||||
log.Debug("Failed to get end block hash of checkpoint while whitelisting")
|
||||
return 0, common.Hash{}, fmt.Errorf("failed to get end block")
|
||||
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