Skip to content

Commit

Permalink
use map to replace sync.map
Browse files Browse the repository at this point in the history
  • Loading branch information
louisliu2048 committed Sep 2, 2024
1 parent b1249ab commit ffe1e76
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions zk/stages/stage_sequence_execute_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package stages

import (
"fmt"
"sync"

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

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

txInfos := []blockinfo.ExecutedTxInfo{}
var txHash2SenderCache sync.Map
txHash2SenderCache := make(map[common.Hash]common.Address)
builtBlockElements := batchState.blockState.builtBlockElements
for i, tx := range builtBlockElements.transactions {
var from common.Address
Expand All @@ -160,7 +158,7 @@ func finaliseBlock(
Signer: &from,
})

txHash2SenderCache.Store(tx.Hash(), sender)
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 @@ -307,15 +305,15 @@ func addSenders(
finalTransactions types.Transactions,
tx kv.RwTx,
finalHeader *types.Header,
txHash2SenderCache sync.Map,
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 {
if val, ok := txHash2SenderCache.Load(transaction.Hash()); ok {
from = val.(common.Address)
if val, ok := txHash2SenderCache[transaction.Hash()]; ok {
from = val
} else {
val, err := signer.SenderWithContext(cryptoContext, transaction)
if err != nil {
Expand Down

0 comments on commit ffe1e76

Please sign in to comment.