mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
* merge geth v1.10.15 * fix: Removed FastSync from cli server * fix: TestHeadersRLPStorage * Added t.skip(ETH2 in bor) * fix: flow in create consensus engine * bumped version * Fix typo * increase block time * remove file * bumped version * merge gethv1.10.17 * bumped version * fix failing tests * Bump Go version to v1.18 (#368) * Bump Go version to v1.18.1 * Build using netgo tag This will create a static build using Go native networking stack. Checked and it works stable for all archs and distros. * Fix meta * initial implementation for common ancestor approach * extract whitelist interface * fix types * fix tests and format * add unit tests for IsValidChain function * more tests * wip * test ErrCheckpointMismatch * minor fixes * fix test * dont panic * fmt * Limit state sync by gas * Added logging for state-sync total gas usage * Added number of event-records in log * Minor Changes * Minor Fix * Adding individual gasUsed * Minor Fix * fix: return value for no remote block * handle all errors * modularise fake chain validator in downloader * add more tests * fix tests * Modifying miner.recommit flag and its adjustment function. (#370) * changed min/max/current recommit values * Remove Hardcoded min/max * Code Sanitization * Skipping tests for constant recommit interval * Adding default miner.recommit value * Minor Change * Increased default value of rpc.txfeecap to 5 * add debug rpc endpoints for checkpoint whitelist service * minor fixes and enhancements * avoid capping warnings for gas set by internal system transactions * use typed mocks * fix * fix * fix * fix close * fix * Create stale.yml * Fix bor consensus checkpoint bug Co-authored-by: Arpit Temani <temaniarpit27@gmail.com> Co-authored-by: Shivam Sharma <shivam691999@gmail.com> Co-authored-by: Manav Darji <manavdarji.india@gmail.com> Co-authored-by: Sandeep Sreenath <sandeep.sreenath@gmail.com> Co-authored-by: Victor Castell <victor@victorcastell.com> Co-authored-by: Ferran <ferranbt@protonmail.com> Co-authored-by: Krishna Upadhyaya <krishnau1604@gmail.com> Co-authored-by: Karlo <karlonovak@gmail.com> Co-authored-by: Sandeep Sreenath <ssandeep@users.noreply.github.com> Co-authored-by: Jerry <jerrycgh@gmail.com>
75 lines
2.7 KiB
Go
75 lines
2.7 KiB
Go
package eth
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/ethereum/go-ethereum/consensus/bor"
|
|
"github.com/ethereum/go-ethereum/log"
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
)
|
|
|
|
var (
|
|
// errCheckpoint is returned when we are unable to fetch the
|
|
// latest checkpoint from the local heimdall.
|
|
errCheckpoint = errors.New("failed to fetch latest checkpoint")
|
|
|
|
// errMissingCheckpoint is returned when we don't have the
|
|
// checkpoint blocks locally, yet.
|
|
errMissingCheckpoint = errors.New("missing checkpoint blocks")
|
|
|
|
// errRootHash is returned when we aren't able to calculate the root hash
|
|
// locally for a range of blocks.
|
|
errRootHash = errors.New("failed to get local root hash")
|
|
|
|
// errCheckpointRootHashMismatch is returned when the local root hash
|
|
// doesn't match with the root hash in checkpoint.
|
|
errCheckpointRootHashMismatch = errors.New("checkpoint roothash mismatch")
|
|
|
|
// errEndBlock is returned when we're unable to fetch a block locally.
|
|
errEndBlock = errors.New("failed to get end block")
|
|
)
|
|
|
|
// fetchWhitelistCheckpoint fetched the latest checkpoint from it's local heimdall
|
|
// and verifies the data against bor data.
|
|
func (h *ethHandler) fetchWhitelistCheckpoint(bor *bor.Bor) (uint64, common.Hash, error) {
|
|
// check for checkpoint whitelisting: bor
|
|
checkpoint, err := bor.HeimdallClient.FetchLatestCheckpoint()
|
|
if err != nil {
|
|
log.Debug("Failed to fetch latest checkpoint for whitelisting")
|
|
return 0, common.Hash{}, errCheckpoint
|
|
}
|
|
|
|
// check if we have the checkpoint blocks
|
|
head := h.ethAPI.BlockNumber()
|
|
if head < hexutil.Uint64(checkpoint.EndBlock.Uint64()) {
|
|
log.Debug("Head block behind checkpoint block", "head", head, "checkpoint end block", checkpoint.EndBlock)
|
|
return 0, common.Hash{}, errMissingCheckpoint
|
|
}
|
|
|
|
// 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{}, errRootHash
|
|
}
|
|
|
|
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{}, errCheckpointRootHashMismatch
|
|
}
|
|
|
|
// 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{}, errEndBlock
|
|
}
|
|
|
|
hash := fmt.Sprintf("%v", block["hash"])
|
|
|
|
return checkpoint.EndBlock.Uint64(), common.HexToHash(hash), nil
|
|
}
|