core: recover state when beacon sets canonical head if it's missing (#24613)

* core: recover the state in SetChainHead if the head state is missing

* core: disable test logging

* core: address comment from martin

* core: improve log level in case state is recovered

* core, eth, les, light: rename SetChainHead to SetCanonical
This commit is contained in:
rjl493456442
2022-05-05 10:36:26 +03:00
committed by GitHub
parent 11b56ace2a
commit 7f6f01d46f
7 changed files with 102 additions and 14 deletions
+4 -4
View File
@@ -87,7 +87,7 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(heads beacon.ForkchoiceStateV1, pay
}
}
// SetHead
if err := api.setHead(heads.HeadBlockHash); err != nil {
if err := api.setCanonical(heads.HeadBlockHash); err != nil {
return beacon.STATUS_INVALID, err
}
if payloadAttributes != nil {
@@ -166,8 +166,8 @@ func (api *ConsensusAPI) checkTerminalTotalDifficulty(head common.Hash) error {
return nil
}
// setHead is called to perform a force choice.
func (api *ConsensusAPI) setHead(newHead common.Hash) error {
// setCanonical is called to perform a force choice.
func (api *ConsensusAPI) setCanonical(newHead common.Hash) error {
log.Info("Setting head", "head", newHead)
headHeader := api.les.BlockChain().CurrentHeader()
@@ -178,7 +178,7 @@ func (api *ConsensusAPI) setHead(newHead common.Hash) error {
if newHeadHeader == nil {
return &beacon.GenericServerError
}
if err := api.les.BlockChain().SetChainHead(newHeadHeader); err != nil {
if err := api.les.BlockChain().SetCanonical(newHeadHeader); err != nil {
return err
}
// Trigger the transition if it's the first `NewHead` event.
+1 -1
View File
@@ -194,7 +194,7 @@ func TestEth2DeepReorg(t *testing.T) {
if ethservice.BlockChain().CurrentBlock().NumberU64() != head {
t.Fatalf("Chain head shouldn't be updated")
}
if err := api.setHead(block.Hash()); err != nil {
if err := api.setCanonical(block.Hash()); err != nil {
t.Fatalf("Failed to set head: %v", err)
}
if ethservice.BlockChain().CurrentBlock().NumberU64() != block.NumberU64() {