dont check for block reward or uncles if we are tracing POS (#5410)

* dont check for block reward or uncles if we are tracing POS

* comparing chainConfig to header difficulty

* fixed test

* difficulty == 0 then we are POS
This commit is contained in:
Enrique Jose Avila Asapche 2022-09-17 23:04:37 +02:00 committed by GitHub
parent 62bbc36d11
commit 7b1bf44ce6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -325,6 +325,7 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str
nExported := uint64(0)
it := allBlocks.Iterator()
isPos := false
for it.HasNext() {
b := it.Next()
// Extract transactions from block
@ -367,6 +368,10 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str
blockHash := block.Hash()
blockNumber := block.NumberU64()
if !isPos && api._chainConfig.TerminalTotalDifficulty != nil {
header := block.Header()
isPos = header.Difficulty.Cmp(common.Big0) == 0 || header.Difficulty.Cmp(api._chainConfig.TerminalTotalDifficulty) >= 0
}
txs := block.Transactions()
t, tErr := api.callManyTransactions(ctx, dbtx, txs, []string{TraceTypeTrace}, block.ParentHash(), rpc.BlockNumber(block.NumberU64()-1), block.Header(), -1 /* all tx indices */, types.MakeSigner(chainConfig, b), chainConfig.Rules(b))
if tErr != nil {
@ -416,6 +421,13 @@ func (api *TraceAPIImpl) Filter(ctx context.Context, req TraceFilterRequest, str
}
}
}
// if we are in POS
// we dont check for uncles or block rewards
if isPos {
continue
}
minerReward, uncleRewards := ethash.AccumulateRewards(chainConfig, block.Header(), block.Uncles())
if _, ok := toAddresses[block.Coinbase()]; ok || includeAll {
nSeen++

View File

@ -616,6 +616,10 @@ func verifyAndSaveDownloadedPoSHeaders(tx kv.RwTx, cfg HeadersCfg, headerInserte
headerLoadFunc := func(key, value []byte, _ etl.CurrentTableReader, _ etl.LoadNextFunc) error {
var h types.Header
// no header to process
if value == nil {
return nil
}
if err := rlp.DecodeBytes(value, &h); err != nil {
return err
}