Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/beacon: eth/catalyst: Implement Kiln-v2 spec #24506

Merged
merged 14 commits into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
eth: core: remove notion of terminal pow block
  • Loading branch information
MariusVanDerWijden committed Mar 16, 2022
commit 4c57d092582e8ba2ff9d5eece481050cb1f5fe82
3 changes: 0 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,6 @@ func (bc *BlockChain) loadLastState() error {
if pivot := rawdb.ReadLastPivotNumber(bc.db); pivot != nil {
log.Info("Loaded last fast-sync pivot marker", "number", *pivot)
}
if terminalHeader := bc.CurrentTerminalHeader(); terminalHeader != nil {
log.Info("Loaded terminal block", "number", terminalHeader.Number, "hash", terminalHeader.Hash())
}
return nil
}

Expand Down
16 changes: 0 additions & 16 deletions core/blockchain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ func (bc *BlockChain) CurrentFastBlock() *types.Block {
return bc.currentFastBlock.Load().(*types.Block)
}

// CurrentTerminalHeader retrieves the current terminal header of the canonical
// chain. The block is retrieved from the blockchain's internal cache.
func (bc *BlockChain) CurrentTerminalHeader() *types.Header {
if head := rawdb.ReadTerminalBlockHash(bc.db); head != (common.Hash{}) {
if header := bc.GetHeaderByHash(head); header != nil {
return header
}
}
return nil
}

// SetTerminalBlock sets the current terminal block.
func (bc *BlockChain) SetTerminalBlock(header *types.Header) {
rawdb.WriteTerminalBlockHash(bc.db, header.Hash())
}

// HasHeader checks if a block header is present in the database or not, caching
// it if present.
func (bc *BlockChain) HasHeader(hash common.Hash, number uint64) bool {
Expand Down
4 changes: 0 additions & 4 deletions core/headerchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,7 @@ func (hc *HeaderChain) WriteHeaders(headers []*types.Header) (int, error) {
hash = header.Hash()
}
number := header.Number.Uint64()
old := new(big.Int).Set(newTD)
newTD.Add(newTD, header.Difficulty)
if hc.config.TerminalTotalDifficulty != nil && old.Cmp(hc.config.TerminalTotalDifficulty) < 0 && newTD.Cmp(hc.config.TerminalTotalDifficulty) >= 0 {
rawdb.WriteTerminalBlockHash(hc.chainDb, header.Hash())
}

// If the parent was not present, store it
// If the header is already known, skip it, otherwise store
Expand Down
16 changes: 0 additions & 16 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,6 @@ func WriteHeadFastBlockHash(db ethdb.KeyValueWriter, hash common.Hash) {
}
}

// ReadTerminalBlockHash retrieves the hash of the current terminal block.
func ReadTerminalBlockHash(db ethdb.KeyValueReader) common.Hash {
data, _ := db.Get(headTerminalBlockKey)
if len(data) == 0 {
return common.Hash{}
}
return common.BytesToHash(data)
}

// WriteTerminalBlockHash stores the hash of the current fast-sync head block.
func WriteTerminalBlockHash(db ethdb.KeyValueWriter, hash common.Hash) {
if err := db.Put(headTerminalBlockKey, hash.Bytes()); err != nil {
log.Crit("Failed to store last terminal block hash", "err", err)
}
}

// ReadLastPivotNumber retrieves the number of the last pivot block. If the node
// full synced, the last pivot will always be nil.
func ReadLastPivotNumber(db ethdb.KeyValueReader) *uint64 {
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
databaseVersionKey, headHeaderKey, headBlockKey, headFastBlockKey, lastPivotKey,
fastTrieProgressKey, snapshotDisabledKey, SnapshotRootKey, snapshotJournalKey,
snapshotGeneratorKey, snapshotRecoveryKey, txIndexTailKey, fastTxLookupLimitKey,
uncleanShutdownKey, badBlockKey, transitionStatusKey, skeletonSyncStatusKey, headTerminalBlockKey,
uncleanShutdownKey, badBlockKey, transitionStatusKey, skeletonSyncStatusKey,
} {
if bytes.Equal(key, meta) {
metadata.Add(size)
Expand Down
3 changes: 0 additions & 3 deletions core/rawdb/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ var (
// headFastBlockKey tracks the latest known incomplete block's hash during fast sync.
headFastBlockKey = []byte("LastFast")

// headTerminalBlockKey tracks the latest known terminal hash.
headTerminalBlockKey = []byte("LastTerminal")

// lastPivotKey tracks the last pivot block used by fast sync (to reenable on sethead).
lastPivotKey = []byte("LastPivot")

Expand Down
14 changes: 0 additions & 14 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,6 @@ func (api *ConsensusAPI) ExchangeTransitionConfigurationV1(config beacon.Transit
log.Warn("Invalid TTD configured", "geth", config.TerminalTotalDifficulty, "consensus client", ttd)
MariusVanDerWijden marked this conversation as resolved.
Show resolved Hide resolved
return nil, fmt.Errorf("invalid ttd: EL %v CL %v", config.TerminalTotalDifficulty, ttd)
MariusVanDerWijden marked this conversation as resolved.
Show resolved Hide resolved
}
terminalHeader := api.eth.BlockChain().CurrentTerminalHeader()
if terminalHeader != nil {
if config.TerminalBlockNumber != 0 && uint64(config.TerminalBlockNumber) != terminalHeader.Number.Uint64() {
return nil, fmt.Errorf("invalid terminal block number, got %v want %v", config.TerminalBlockNumber, terminalHeader.Number)
}

if config.TerminalBlockHash != (common.Hash{}) && config.TerminalBlockHash != terminalHeader.Hash() {
return nil, fmt.Errorf("invalid terminal block hash, got %v want %v", config.TerminalBlockHash, terminalHeader.Hash())
}
// TODO (MariusVanDerWijden): Here we used to return the correct terminal hash + number
// but according to the spec we should return the hash + number set by the user.
// Since we have no way of setting hash + number yet, just return TTD.
return &beacon.TransitionConfigurationV1{TerminalTotalDifficulty: (*hexutil.Big)(ttd)}, nil
}

if config.TerminalBlockHash != (common.Hash{}) {
return nil, fmt.Errorf("invalid terminal block hash, no terminal header set")
Expand Down
19 changes: 0 additions & 19 deletions eth/catalyst/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ func TestExchangeTransitionConfig(t *testing.T) {
var (
api = NewConsensusAPI(ethservice)
)
ethservice.BlockChain().SetTerminalBlock(preMergeBlocks[len(preMergeBlocks)-1].Header())
// invalid ttd
config := beacon.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(big.NewInt(0)),
Expand All @@ -496,15 +495,6 @@ func TestExchangeTransitionConfig(t *testing.T) {
if _, err := api.ExchangeTransitionConfigurationV1(config); err == nil {
t.Fatal("expected error on invalid config, invalid ttd")
}
// invalid terminal block bumber
config = beacon.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
TerminalBlockHash: common.Hash{},
TerminalBlockNumber: 1,
}
if _, err := api.ExchangeTransitionConfigurationV1(config); err == nil {
t.Fatal("expected error on invalid config, invalid blocknumber")
}
// invalid terminal block hash
config = beacon.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
Expand All @@ -523,13 +513,4 @@ func TestExchangeTransitionConfig(t *testing.T) {
if _, err := api.ExchangeTransitionConfigurationV1(config); err != nil {
t.Fatalf("expected no error on valid config, got %v", err)
}
// valid config
config = beacon.TransitionConfigurationV1{
TerminalTotalDifficulty: (*hexutil.Big)(genesis.Config.TerminalTotalDifficulty),
TerminalBlockHash: preMergeBlocks[len(preMergeBlocks)-1].Hash(),
TerminalBlockNumber: hexutil.Uint64(preMergeBlocks[len(preMergeBlocks)-1].NumberU64()),
}
if _, err := api.ExchangeTransitionConfigurationV1(config); err != nil {
t.Fatalf("expected no error on valid config, got %v", err)
}
}