Skip to content

Commit 7c7cd41

Browse files
authored
eth, miner: retrieve mining state from live database (#25139)
* miner: retrieve mining state from live database * eth/catalyst: ignore stale fcu events from cl
1 parent f49e298 commit 7c7cd41

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

eth/catalyst/api.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,26 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(update beacon.ForkchoiceStateV1, pa
140140
return beacon.ForkChoiceResponse{PayloadStatus: beacon.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
141141
}
142142
}
143-
143+
valid := func(id *beacon.PayloadID) beacon.ForkChoiceResponse {
144+
return beacon.ForkChoiceResponse{
145+
PayloadStatus: beacon.PayloadStatusV1{Status: beacon.VALID, LatestValidHash: &update.HeadBlockHash},
146+
PayloadID: id,
147+
}
148+
}
144149
if rawdb.ReadCanonicalHash(api.eth.ChainDb(), block.NumberU64()) != update.HeadBlockHash {
145150
// Block is not canonical, set head.
146151
if latestValid, err := api.eth.BlockChain().SetCanonical(block); err != nil {
147152
return beacon.ForkChoiceResponse{PayloadStatus: beacon.PayloadStatusV1{Status: beacon.INVALID, LatestValidHash: &latestValid}}, err
148153
}
154+
} else if api.eth.BlockChain().CurrentBlock().Hash() == update.HeadBlockHash {
155+
// If the specified head matches with our local head, do nothing and keep
156+
// generating the payload. It's a special corner case that a few slots are
157+
// missing and we are requested to generate the payload in slot.
149158
} else {
150159
// If the head block is already in our canonical chain, the beacon client is
151160
// probably resyncing. Ignore the update.
152161
log.Info("Ignoring beacon update to old head", "number", block.NumberU64(), "hash", update.HeadBlockHash, "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)), "have", api.eth.BlockChain().CurrentBlock().NumberU64())
162+
return valid(nil), nil
153163
}
154164
api.eth.SetSynced()
155165

@@ -183,12 +193,6 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(update beacon.ForkchoiceStateV1, pa
183193
return beacon.STATUS_INVALID, beacon.InvalidForkChoiceState.With(errors.New("safe block not in canonical chain"))
184194
}
185195
}
186-
valid := func(id *beacon.PayloadID) beacon.ForkChoiceResponse {
187-
return beacon.ForkChoiceResponse{
188-
PayloadStatus: beacon.PayloadStatusV1{Status: beacon.VALID, LatestValidHash: &update.HeadBlockHash},
189-
PayloadID: id,
190-
}
191-
}
192196
// If payload generation was requested, create a new block to be potentially
193197
// sealed by the beacon client. The payload will be requested later, and we
194198
// might replace it arbitrarily many times in between.

miner/miner.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
type Backend interface {
4141
BlockChain() *core.BlockChain
4242
TxPool() *core.TxPool
43-
StateAtBlock(block *types.Block, reexec uint64, base *state.StateDB, checkLive bool, preferDisk bool) (statedb *state.StateDB, err error)
4443
}
4544

4645
// Config is the configuration parameters of mining.

miner/worker.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -756,16 +756,6 @@ func (w *worker) makeEnv(parent *types.Block, header *types.Header, coinbase com
756756
// Retrieve the parent state to execute on top and start a prefetcher for
757757
// the miner to speed block sealing up a bit.
758758
state, err := w.chain.StateAt(parent.Root())
759-
if err != nil {
760-
// Note since the sealing block can be created upon the arbitrary parent
761-
// block, but the state of parent block may already be pruned, so the necessary
762-
// state recovery is needed here in the future.
763-
//
764-
// The maximum acceptable reorg depth can be limited by the finalised block
765-
// somehow. TODO(rjl493456442) fix the hard-coded number here later.
766-
state, err = w.eth.StateAtBlock(parent, 1024, nil, false, false)
767-
log.Warn("Recovered mining state", "root", parent.Root(), "err", err)
768-
}
769759
if err != nil {
770760
return nil, err
771761
}

0 commit comments

Comments
 (0)