Skip to content

Commit

Permalink
Verify PoS headers before inserting them into DB (erigontech#3151)
Browse files Browse the repository at this point in the history
* Remove TotalDifficulty stage

* Introduce FeedHeaderFuncType

* Some TODOs

* Don't gossip PoS headers

* FeedHeaderPoS

* Call header.Hash once

* Use FeedHeaderPoS for to write PoS header

* Support errors in EngineExecutePayloadV1

* useExternalTx boilerplate

* Call VerifyHeader on PoS header

* latestValidHash must be nil when status is SYNCING

* fixCanonicalChain instead of canonicalHeadersCollector

* engine.VerifyHeader + FeedHeaderPoS as headerLoadFunc

* fix daemon

Co-authored-by: Giulio Rebuffo <giulio.rebuffo@gmail.com>
  • Loading branch information
yperbasis and Giulio2002 authored Dec 23, 2021
1 parent 1dbcaa6 commit 445ac05
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 550 deletions.
11 changes: 8 additions & 3 deletions cmd/rpcdaemon/commands/engine_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,15 @@ func (e *EngineImpl) ExecutePayloadV1(ctx context.Context, payload *ExecutionPay
return nil, err
}

var latestValidHash common.Hash = gointerfaces.ConvertH256ToHash(res.LatestValidHash)
if res.LatestValidHash != nil {
var latestValidHash common.Hash = gointerfaces.ConvertH256ToHash(res.LatestValidHash)
return map[string]interface{}{
"status": res.Status,
"latestValidHash": common.Bytes2Hex(latestValidHash.Bytes()),
}, nil
}
return map[string]interface{}{
"status": res.Status,
"latestValidHash": common.Bytes2Hex(latestValidHash.Bytes()),
"status": res.Status,
}, nil
}

Expand Down
15 changes: 1 addition & 14 deletions eth/stagedsync/default_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ledgerwatch/erigon/ethdb/prune"
)

func DefaultStages(ctx context.Context, sm prune.Mode, headers HeadersCfg, blockHashCfg BlockHashesCfg, bodies BodiesCfg, issuance IssuanceCfg, difficulty DifficultyCfg, senders SendersCfg, exec ExecuteBlockCfg, trans TranspileCfg, hashState HashStateCfg, trieCfg TrieCfg, history HistoryCfg, logIndex LogIndexCfg, callTraces CallTracesCfg, txLookup TxLookupCfg, finish FinishCfg, test bool) []*Stage {
func DefaultStages(ctx context.Context, sm prune.Mode, headers HeadersCfg, blockHashCfg BlockHashesCfg, bodies BodiesCfg, issuance IssuanceCfg, senders SendersCfg, exec ExecuteBlockCfg, trans TranspileCfg, hashState HashStateCfg, trieCfg TrieCfg, history HistoryCfg, logIndex LogIndexCfg, callTraces CallTracesCfg, txLookup TxLookupCfg, finish FinishCfg, test bool) []*Stage {
return []*Stage{
{
ID: stages.Headers,
Expand Down Expand Up @@ -52,19 +52,6 @@ func DefaultStages(ctx context.Context, sm prune.Mode, headers HeadersCfg, block
return PruneBodiesStage(p, tx, bodies, ctx)
},
},
{
ID: stages.TotalDifficulty,
Description: "Compute total difficulty",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnDifficultyStage(s, tx, difficulty, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindDifficultyStage(u, tx, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneDifficultyStage(p, tx, ctx)
},
},
{
ID: stages.Senders,
Description: "Recover senders from tx signatures",
Expand Down
158 changes: 0 additions & 158 deletions eth/stagedsync/stage_difficulty.go

This file was deleted.

Loading

0 comments on commit 445ac05

Please sign in to comment.