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

better handling of errors bubbling up from the txpool #1278

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/emicklei/dot v1.0.0
github.com/emirpasic/gods v1.18.1
github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c
github.com/gateway-fm/cdk-erigon-lib v0.0.0-20241004104722-f8fd79a58182
github.com/gateway-fm/cdk-erigon-lib v0.0.0-20241004145804-75fb2f0a851d
github.com/gateway-fm/vectorized-poseidon-gold v1.0.0
github.com/gballet/go-verkle v0.0.0-20221121182333-31427a1f2d35
github.com/go-stack/stack v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ github.com/gateway-fm/cdk-erigon-lib v0.0.0-20240805074757-5e3196248fde h1:0myae
github.com/gateway-fm/cdk-erigon-lib v0.0.0-20240805074757-5e3196248fde/go.mod h1:Ky//z32wQOTY/drV858kr8dECBD9OBV9Xzy+aG6TxSk=
github.com/gateway-fm/cdk-erigon-lib v0.0.0-20241004104722-f8fd79a58182 h1:yFaHDSRsESUJsvqHRwg7Y90A/TkVRdCyDCT9uNE0y3g=
github.com/gateway-fm/cdk-erigon-lib v0.0.0-20241004104722-f8fd79a58182/go.mod h1:Ky//z32wQOTY/drV858kr8dECBD9OBV9Xzy+aG6TxSk=
github.com/gateway-fm/cdk-erigon-lib v0.0.0-20241004145804-75fb2f0a851d h1:K7VaLJyD+2gSZADlITjTSaBULBxpFvNMEf2DEZkdEOc=
github.com/gateway-fm/cdk-erigon-lib v0.0.0-20241004145804-75fb2f0a851d/go.mod h1:Ky//z32wQOTY/drV858kr8dECBD9OBV9Xzy+aG6TxSk=
github.com/gateway-fm/vectorized-poseidon-gold v1.0.0 h1:Du0ZW+fkZhgRNGx/gAkHnMj3/Rl8uJkAEe+ZDPX3PDw=
github.com/gateway-fm/vectorized-poseidon-gold v1.0.0/go.mod h1:VLGQpyjrOg8+FugH/+d8tfYd/c3z4Xqa+zbUBITygaw=
github.com/gballet/go-verkle v0.0.0-20221121182333-31427a1f2d35 h1:I8QswD9gf3VEpr7bpepKKOm7ChxFITIG+oc1I5/S0no=
Expand Down
20 changes: 15 additions & 5 deletions zk/stages/stage_sequence_execute_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executio
if allConditionsOk, _, err = cfg.txPool.YieldBest(cfg.yieldSize, &slots, poolTx, executionAt, gasLimit, alreadyYielded); err != nil {
return err
}
yieldedTxs, err := extractTransactionsFromSlot(&slots)
yieldedTxs, toRemove, err := extractTransactionsFromSlot(&slots)
if err != nil {
return err
}
for _, txId := range toRemove {
cfg.txPool.MarkForDiscardFromPendingBest(txId)
}
transactions = append(transactions, yieldedTxs...)
return nil
}); err != nil {
Expand All @@ -65,7 +68,9 @@ func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *comm
}

if slots != nil {
transactions, err = extractTransactionsFromSlot(slots)
// 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)
if err != nil {
return err
}
Expand All @@ -79,8 +84,9 @@ func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *comm
return transactions, nil
}

func extractTransactionsFromSlot(slot *types2.TxsRlp) ([]types.Transaction, error) {
func extractTransactionsFromSlot(slot *types2.TxsRlp) ([]types.Transaction, []common.Hash, error) {
transactions := make([]types.Transaction, 0, len(slot.Txs))
toRemove := make([]common.Hash, 0)
reader := bytes.NewReader([]byte{})
stream := new(rlp.Stream)
for idx, txBytes := range slot.Txs {
Expand All @@ -91,14 +97,18 @@ func extractTransactionsFromSlot(slot *types2.TxsRlp) ([]types.Transaction, erro
continue
}
if err != nil {
return nil, err
// 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)
toRemove = append(toRemove, slot.TxIds[idx])
continue
}
var sender common.Address
copy(sender[:], slot.Senders.At(idx))
transaction.SetSender(sender)
transactions = append(transactions, transaction)
}
return transactions, nil
return transactions, toRemove, nil
}

func attemptAddTransaction(
Expand Down
1 change: 1 addition & 0 deletions zk/txpool/pool_zk.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (p *TxPool) best(n uint16, txs *types.TxsRlp, tx kv.Tx, onTopOf, availableG
}

txs.Txs[count] = rlpTx
txs.TxIds[count] = mt.Tx.IDHash
copy(txs.Senders.At(count), sender.Bytes())
txs.IsLocal[count] = isLocal
toSkip.Add(mt.Tx.IDHash)
Expand Down
1 change: 1 addition & 0 deletions zk/txpool/pool_zk_limbo.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (p *TxPool) GetLimboTxRplsByHash(tx kv.Tx, txHash *common.Hash) (*types.Txs
for i := uint32(0); i < txSize; i++ {
limboTx := limboBlock.Transactions[i]
txsRlps.Txs[i] = limboTx.Rlp
txsRlps.TxIds[i] = limboTx.Hash
copy(txsRlps.Senders.At(int(i)), limboTx.Sender[:])
txsRlps.IsLocal[i] = true // all limbo tx are considered local //TODO: explain better about local
}
Expand Down