Skip to content

Commit

Permalink
set the proof elements in generateWork, not commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gballet committed Dec 14, 2022
1 parent ad4dd0d commit 90b32b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
8 changes: 4 additions & 4 deletions eth/catalyst/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ func (api *ConsensusAPI) ForkchoiceUpdatedV1(update beacon.ForkchoiceStateV1, pa
log.Error("TDs unavailable for TTD check", "number", block.NumberU64(), "hash", update.HeadBlockHash, "td", td, "parent", block.ParentHash(), "ptd", ptd)
return beacon.STATUS_INVALID, errors.New("TDs unavailable for TDD check")
}
if td.Cmp(ttd) < 0 {
log.Error("Refusing beacon update to pre-merge", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
return beacon.ForkChoiceResponse{PayloadStatus: beacon.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
}
// if td.Cmp(ttd) < 0 {
// log.Error("Refusing beacon update to pre-merge", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
// return beacon.ForkChoiceResponse{PayloadStatus: beacon.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
// }
if block.NumberU64() > 0 && ptd.Cmp(ttd) >= 0 {
log.Error("Parent block is already post-ttd", "number", block.NumberU64(), "hash", update.HeadBlockHash, "diff", block.Difficulty(), "age", common.PrettyAge(time.Unix(int64(block.Time()), 0)))
return beacon.ForkChoiceResponse{PayloadStatus: beacon.INVALID_TERMINAL_BLOCK, PayloadID: nil}, nil
Expand Down
27 changes: 26 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,32 @@ func (w *worker) generateWork(params *generateParams) (*types.Block, error) {
if !params.noTxs {
w.fillTransactions(nil, work)
}
return w.engine.FinalizeAndAssemble(w.chain, work.header, work.state, work.txs, work.unclelist(), work.receipts)
block, err := w.engine.FinalizeAndAssemble(w.chain, work.header, work.state, work.txs, work.unclelist(), work.receipts)
// Open the pre-tree to prove the pre-state against
preTrie, err := work.state.Database().OpenTrie(work.preRoot)
if err != nil {
return nil, err
}
if vtr, ok := preTrie.(*trie.VerkleTrie); ok {
keys := work.state.Witness().Keys()
kvs := work.state.Witness().KeyVals()
for _, key := range keys {
// XXX workaround - there is a problem in the witness creation
// so fix the witness creation as well.
v, err := vtr.TryGet(key)
if err != nil {
panic(err)
}
kvs[string(key)] = v
}
vtr.Hash()
p, k, err := vtr.ProveAndSerialize(work.state.Witness().Keys(), work.state.Witness().KeyVals())
if err != nil {
return nil, err
}
block.SetVerkleProof(p, k)
}
return block, nil
}

// commitWork generates several new sealing tasks based on the parent block
Expand Down

0 comments on commit 90b32b0

Please sign in to comment.