Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache tx sender to reduce calculate it again #1062

Open
wants to merge 5 commits into
base: zkevm
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions zk/stages/stage_sequence_execute_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package stages

import (
"fmt"

"github.com/gateway-fm/cdk-erigon-lib/common"
"github.com/gateway-fm/cdk-erigon-lib/kv"

Expand Down Expand Up @@ -136,6 +135,7 @@ func finaliseBlock(
}

txInfos := []blockinfo.ExecutedTxInfo{}
txHash2SenderCache := make(map[common.Hash]common.Address)
builtBlockElements := batchState.blockState.builtBlockElements
for i, tx := range builtBlockElements.transactions {
var from common.Address
Expand All @@ -157,6 +157,8 @@ func finaliseBlock(
Receipt: localReceipt,
Signer: &from,
})

txHash2SenderCache[tx.Hash()] = sender
}

if err := postBlockStateHandling(*batchContext.cfg, ibs, batchContext.sdb.hermezDb, newHeader, ger, l1BlockHash, parentBlock.Root(), txInfos); err != nil {
Expand Down Expand Up @@ -232,7 +234,7 @@ func finaliseBlock(
}

// now process the senders to avoid a stage by itself
if err := addSenders(*batchContext.cfg, newNum, finalTransactions, batchContext.sdb.tx, finalHeader); err != nil {
if err := addSenders(*batchContext.cfg, newNum, finalTransactions, batchContext.sdb.tx, finalHeader, txHash2SenderCache); err != nil {
return nil, err
}

Expand Down Expand Up @@ -303,14 +305,21 @@ func addSenders(
finalTransactions types.Transactions,
tx kv.RwTx,
finalHeader *types.Header,
txHash2SenderCache map[common.Hash]common.Address,
) error {
signer := types.MakeSigner(cfg.chainConfig, newNum.Uint64())
cryptoContext := secp256k1.ContextForThread(1)
senders := make([]common.Address, 0, len(finalTransactions))
var from common.Address
for _, transaction := range finalTransactions {
from, err := signer.SenderWithContext(cryptoContext, transaction)
if err != nil {
return err
if val, ok := txHash2SenderCache[transaction.Hash()]; ok {
from = val
} else {
val, err := signer.SenderWithContext(cryptoContext, transaction)
if err != nil {
return err
}
from = val
}
senders = append(senders, from)
}
Expand Down
Loading