-
Notifications
You must be signed in to change notification settings - Fork 45
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
preload sender and check for errors #1480
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
"github.com/ledgerwatch/erigon/core/vm/evmtypes" | ||
"github.com/ledgerwatch/erigon/zk/utils" | ||
"github.com/ledgerwatch/log/v3" | ||
"github.com/ledgerwatch/secp256k1" | ||
) | ||
|
||
func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executionAt, forkId uint64, alreadyYielded mapset.Set[[32]byte]) ([]types.Transaction, []common.Hash, bool, error) { | ||
|
@@ -38,7 +39,7 @@ func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executio | |
if allConditionsOk, _, err = cfg.txPool.YieldBest(cfg.yieldSize, &slots, poolTx, executionAt, gasLimit, 0, alreadyYielded); err != nil { | ||
return err | ||
} | ||
yieldedTxs, yieldedIds, toRemove, err := extractTransactionsFromSlot(&slots) | ||
yieldedTxs, yieldedIds, toRemove, err := extractTransactionsFromSlot(&slots, executionAt, cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -55,7 +56,7 @@ func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executio | |
return transactions, ids, allConditionsOk, err | ||
} | ||
|
||
func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *common.Hash) ([]types.Transaction, error) { | ||
func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *common.Hash, executionAt uint64) ([]types.Transaction, error) { | ||
cfg.txPool.LockFlusher() | ||
defer cfg.txPool.UnlockFlusher() | ||
|
||
|
@@ -70,7 +71,7 @@ func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *comm | |
if slots != nil { | ||
// ignore the toRemove value here, we know the RLP will be sound as we had to read it from the pool | ||
// in the first place to get it into limbo | ||
transactions, _, _, err = extractTransactionsFromSlot(slots) | ||
transactions, _, _, err = extractTransactionsFromSlot(slots, executionAt, cfg) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -84,10 +85,12 @@ func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *comm | |
return transactions, nil | ||
} | ||
|
||
func extractTransactionsFromSlot(slot *types2.TxsRlp) ([]types.Transaction, []common.Hash, []common.Hash, error) { | ||
func extractTransactionsFromSlot(slot *types2.TxsRlp, currentHeight uint64, cfg SequenceBlockCfg) ([]types.Transaction, []common.Hash, []common.Hash, error) { | ||
ids := make([]common.Hash, 0, len(slot.TxIds)) | ||
transactions := make([]types.Transaction, 0, len(slot.Txs)) | ||
toRemove := make([]common.Hash, 0) | ||
signer := types.MakeSigner(cfg.chainConfig, currentHeight, 0) | ||
cryptoContext := secp256k1.ContextForThread(1) | ||
for idx, txBytes := range slot.Txs { | ||
transaction, err := types.DecodeTransaction(txBytes) | ||
if err == io.EOF { | ||
|
@@ -96,12 +99,23 @@ func extractTransactionsFromSlot(slot *types2.TxsRlp) ([]types.Transaction, []co | |
if err != nil { | ||
// we have a transaction that cannot be decoded or a similar issue. We don't want to handle | ||
// this tx so just WARN about it and remove it from the pool and continue | ||
log.Warn("Failed to decode transaction from pool, skipping and removing from pool", "error", err) | ||
log.Warn("[extractTransaction] Failed to decode transaction from pool, skipping and removing from pool", | ||
"error", err, | ||
"id", slot.TxIds[idx]) | ||
toRemove = append(toRemove, slot.TxIds[idx]) | ||
continue | ||
} | ||
var sender common.Address | ||
copy(sender[:], slot.Senders.At(idx)) | ||
|
||
// now attempt to recover the sender | ||
sender, err := signer.SenderWithContext(cryptoContext, transaction) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pprof shows that this line takes 27% of total time. I run sequencer and benchmark There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related issue: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why attempt to recover sender from public key? there should be sender address in the transaction There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The sender always needs recovering at some point, it isn't part of the RLP for a transaction. Once decoded it is cached on the transaction but until then something needs to recover it. |
||
if err != nil { | ||
log.Warn("[extractTransaction] Failed to recover sender from transaction, skipping and removing from pool", | ||
"error", err, | ||
"hash", transaction.Hash()) | ||
toRemove = append(toRemove, slot.TxIds[idx]) | ||
continue | ||
} | ||
|
||
transaction.SetSender(sender) | ||
transactions = append(transactions, transaction) | ||
ids = append(ids, slot.TxIds[idx]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use only 1 context for all transactions. This is sequential computation. Why not parallel?