forked from cerc-io/plugeth
all: remove notion of trusted checkpoints in the post-merge world (#27147)
* all: remove notion of trusted checkpoints in the post-merge world * light: remove unused function * eth/ethconfig, les: remove unused config option * les: make linter happy --------- Co-authored-by: Gary Rong <garyrong0905@gmail.com>
This commit is contained in:
co-authored by
Gary Rong
parent
d3ece3a07c
commit
1e556d220c
+1
-52
@@ -78,7 +78,7 @@ type LightChain struct {
|
||||
// NewLightChain returns a fully initialised light chain using information
|
||||
// available in the database. It initialises the default Ethereum header
|
||||
// validator.
|
||||
func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.Engine, checkpoint *params.TrustedCheckpoint) (*LightChain, error) {
|
||||
func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.Engine) (*LightChain, error) {
|
||||
bc := &LightChain{
|
||||
chainDb: odr.Database(),
|
||||
indexerConfig: odr.IndexerConfig(),
|
||||
@@ -99,9 +99,6 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
|
||||
if bc.genesisBlock == nil {
|
||||
return nil, core.ErrNoGenesis
|
||||
}
|
||||
if checkpoint != nil {
|
||||
bc.AddTrustedCheckpoint(checkpoint)
|
||||
}
|
||||
if err := bc.loadLastState(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -116,22 +113,6 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
|
||||
return bc, nil
|
||||
}
|
||||
|
||||
// AddTrustedCheckpoint adds a trusted checkpoint to the blockchain
|
||||
func (lc *LightChain) AddTrustedCheckpoint(cp *params.TrustedCheckpoint) {
|
||||
if lc.odr.ChtIndexer() != nil {
|
||||
StoreChtRoot(lc.chainDb, cp.SectionIndex, cp.SectionHead, cp.CHTRoot)
|
||||
lc.odr.ChtIndexer().AddCheckpoint(cp.SectionIndex, cp.SectionHead)
|
||||
}
|
||||
if lc.odr.BloomTrieIndexer() != nil {
|
||||
StoreBloomTrieRoot(lc.chainDb, cp.SectionIndex, cp.SectionHead, cp.BloomRoot)
|
||||
lc.odr.BloomTrieIndexer().AddCheckpoint(cp.SectionIndex, cp.SectionHead)
|
||||
}
|
||||
if lc.odr.BloomIndexer() != nil {
|
||||
lc.odr.BloomIndexer().AddCheckpoint(cp.SectionIndex, cp.SectionHead)
|
||||
}
|
||||
log.Info("Added trusted checkpoint", "block", (cp.SectionIndex+1)*lc.indexerConfig.ChtSize-1, "hash", cp.SectionHead)
|
||||
}
|
||||
|
||||
func (lc *LightChain) getProcInterrupt() bool {
|
||||
return atomic.LoadInt32(&lc.procInterrupt) == 1
|
||||
}
|
||||
@@ -520,38 +501,6 @@ func (lc *LightChain) GetHeaderByNumberOdr(ctx context.Context, number uint64) (
|
||||
// Config retrieves the header chain's chain configuration.
|
||||
func (lc *LightChain) Config() *params.ChainConfig { return lc.hc.Config() }
|
||||
|
||||
// SyncCheckpoint fetches the checkpoint point block header according to
|
||||
// the checkpoint provided by the remote peer.
|
||||
//
|
||||
// Note if we are running the clique, fetches the last epoch snapshot header
|
||||
// which covered by checkpoint.
|
||||
func (lc *LightChain) SyncCheckpoint(ctx context.Context, checkpoint *params.TrustedCheckpoint) bool {
|
||||
// Ensure the remote checkpoint head is ahead of us
|
||||
head := lc.CurrentHeader().Number.Uint64()
|
||||
|
||||
latest := (checkpoint.SectionIndex+1)*lc.indexerConfig.ChtSize - 1
|
||||
if clique := lc.hc.Config().Clique; clique != nil {
|
||||
latest -= latest % clique.Epoch // epoch snapshot for clique
|
||||
}
|
||||
if head >= latest {
|
||||
return true
|
||||
}
|
||||
// Retrieve the latest useful header and update to it
|
||||
if header, err := GetHeaderByNumber(ctx, lc.odr, latest); header != nil && err == nil {
|
||||
lc.chainmu.Lock()
|
||||
defer lc.chainmu.Unlock()
|
||||
|
||||
// Ensure the chain didn't move past the latest block while retrieving it
|
||||
if lc.hc.CurrentHeader().Number.Uint64() < header.Number.Uint64() {
|
||||
log.Info("Updated latest header based on CHT", "number", header.Number, "hash", header.Hash(), "age", common.PrettyAge(time.Unix(int64(header.Time), 0)))
|
||||
rawdb.WriteHeadHeaderHash(lc.chainDb, header.Hash())
|
||||
lc.hc.SetCurrentHeader(header)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// LockChain locks the chain mutex for reading so that multiple canonical hashes can be
|
||||
// retrieved while it is guaranteed that they belong to the same version of the chain
|
||||
func (lc *LightChain) LockChain() {
|
||||
|
||||
@@ -56,7 +56,7 @@ func newCanonical(n int) (ethdb.Database, *LightChain, error) {
|
||||
db := rawdb.NewMemoryDatabase()
|
||||
gspec := core.Genesis{Config: params.TestChainConfig}
|
||||
genesis := gspec.MustCommit(db)
|
||||
blockchain, _ := NewLightChain(&dummyOdr{db: db, indexerConfig: TestClientIndexerConfig}, gspec.Config, ethash.NewFaker(), nil)
|
||||
blockchain, _ := NewLightChain(&dummyOdr{db: db, indexerConfig: TestClientIndexerConfig}, gspec.Config, ethash.NewFaker())
|
||||
|
||||
// Create and inject the requested chain
|
||||
if n == 0 {
|
||||
@@ -76,7 +76,7 @@ func newTestLightChain() *LightChain {
|
||||
Config: params.TestChainConfig,
|
||||
}
|
||||
gspec.MustCommit(db)
|
||||
lc, err := NewLightChain(&dummyOdr{db: db}, gspec.Config, ethash.NewFullFaker(), nil)
|
||||
lc, err := NewLightChain(&dummyOdr{db: db}, gspec.Config, ethash.NewFullFaker())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -347,7 +347,7 @@ func TestReorgBadHeaderHashes(t *testing.T) {
|
||||
defer func() { delete(core.BadHashes, headers[3].Hash()) }()
|
||||
|
||||
// Create a new LightChain and check that it rolled back the state.
|
||||
ncm, err := NewLightChain(&dummyOdr{db: bc.chainDb}, params.TestChainConfig, ethash.NewFaker(), nil)
|
||||
ncm, err := NewLightChain(&dummyOdr{db: bc.chainDb}, params.TestChainConfig, ethash.NewFaker())
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create new chain manager: %v", err)
|
||||
}
|
||||
|
||||
+5
-8
@@ -125,18 +125,15 @@ func (req *BlockRequest) StoreResult(db ethdb.Database) {
|
||||
|
||||
// ReceiptsRequest is the ODR request type for retrieving receipts.
|
||||
type ReceiptsRequest struct {
|
||||
Untrusted bool // Indicator whether the result retrieved is trusted or not
|
||||
Hash common.Hash
|
||||
Number uint64
|
||||
Header *types.Header
|
||||
Receipts types.Receipts
|
||||
Hash common.Hash
|
||||
Number uint64
|
||||
Header *types.Header
|
||||
Receipts types.Receipts
|
||||
}
|
||||
|
||||
// StoreResult stores the retrieved data in local database
|
||||
func (req *ReceiptsRequest) StoreResult(db ethdb.Database) {
|
||||
if !req.Untrusted {
|
||||
rawdb.WriteReceipts(db, req.Hash, req.Number, req.Receipts)
|
||||
}
|
||||
rawdb.WriteReceipts(db, req.Hash, req.Number, req.Receipts)
|
||||
}
|
||||
|
||||
// ChtRequest is the ODR request type for retrieving header by Canonical Hash Trie
|
||||
|
||||
+1
-1
@@ -284,7 +284,7 @@ func testChainOdr(t *testing.T, protocol int, fn odrTestFn) {
|
||||
|
||||
gspec.MustCommit(ldb)
|
||||
odr := &testOdr{sdb: sdb, ldb: ldb, serverState: blockchain.StateCache(), indexerConfig: TestClientIndexerConfig}
|
||||
lightchain, err := NewLightChain(odr, gspec.Config, ethash.NewFullFaker(), nil)
|
||||
lightchain, err := NewLightChain(odr, gspec.Config, ethash.NewFullFaker())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -197,30 +197,6 @@ func GetBlockLogs(ctx context.Context, odr OdrBackend, hash common.Hash, number
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// GetUntrustedBlockLogs retrieves the logs generated by the transactions included in a
|
||||
// block. The retrieved logs are regarded as untrusted and will not be stored in the
|
||||
// database. This function should only be used in light client checkpoint syncing.
|
||||
func GetUntrustedBlockLogs(ctx context.Context, odr OdrBackend, header *types.Header) ([][]*types.Log, error) {
|
||||
// Retrieve the potentially incomplete receipts from disk or network
|
||||
hash, number := header.Hash(), header.Number.Uint64()
|
||||
receipts := rawdb.ReadRawReceipts(odr.Database(), hash, number)
|
||||
if receipts == nil {
|
||||
r := &ReceiptsRequest{Hash: hash, Number: number, Header: header, Untrusted: true}
|
||||
if err := odr.Retrieve(ctx, r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
receipts = r.Receipts
|
||||
// Untrusted receipts won't be stored in the database. Therefore
|
||||
// derived fields computation is unnecessary.
|
||||
}
|
||||
// Return the logs without deriving any computed fields on the receipts
|
||||
logs := make([][]*types.Log, len(receipts))
|
||||
for i, receipt := range receipts {
|
||||
logs[i] = receipt.Logs
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// GetBloomBits retrieves a batch of compressed bloomBits vectors belonging to
|
||||
// the given bit index and section indexes.
|
||||
func GetBloomBits(ctx context.Context, odr OdrBackend, bit uint, sections []uint64) ([][]byte, error) {
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestTxPool(t *testing.T) {
|
||||
discard: make(chan int, 1),
|
||||
mined: make(chan int, 1),
|
||||
}
|
||||
lightchain, _ := NewLightChain(odr, params.TestChainConfig, ethash.NewFullFaker(), nil)
|
||||
lightchain, _ := NewLightChain(odr, params.TestChainConfig, ethash.NewFullFaker())
|
||||
txPermanent = 50
|
||||
pool := NewTxPool(params.TestChainConfig, lightchain, relay)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
|
||||
|
||||
Reference in New Issue
Block a user