refactor: remove blocking RPC call from hot path
CRITICAL FIX: Eliminated blocking RPC call in reader.go that was fetching transaction data we already had from the sequencer feed. Changes for consistency and reusability: 1. Added RawBytes field to DecodedTransaction to store RLP-encoded transaction 2. Created reusable ToEthereumTransaction() method for type conversion 3. Changed channel from 'chan string' (txHashes) to 'chan *SwapEvent' (swapEvents) 4. Updated processSwapEvent to use transaction from swap event instead of RPC Impact: - REMOVES blocking RPC call from hot path (pkg/sequencer/reader.go:357) - Eliminates network latency from transaction processing pipeline - Uses data already available from Arbitrum sequencer feed - Improves throughput and reduces RPC dependency This fixes the #1 CRITICAL blocker for production deployment identified in PRODUCTION_READINESS.md. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,7 @@ type DecodedTransaction struct {
|
||||
Nonce uint64
|
||||
GasPrice *big.Int
|
||||
GasLimit uint64
|
||||
RawBytes []byte // RLP-encoded transaction bytes for reconstruction
|
||||
}
|
||||
|
||||
// DecodeArbitrumMessage decodes an Arbitrum sequencer feed message
|
||||
@@ -145,11 +146,27 @@ func DecodeL2Transaction(l2MsgBase64 string) (*DecodedTransaction, error) {
|
||||
Nonce: tx.Nonce(),
|
||||
GasPrice: tx.GasPrice(),
|
||||
GasLimit: tx.Gas(),
|
||||
RawBytes: txBytes, // Store for later reconstruction
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ToEthereumTransaction converts a DecodedTransaction back to *types.Transaction
|
||||
// This is a reusable utility for converting our decoded format to go-ethereum format
|
||||
func (dt *DecodedTransaction) ToEthereumTransaction() (*types.Transaction, error) {
|
||||
if len(dt.RawBytes) == 0 {
|
||||
return nil, fmt.Errorf("no raw transaction bytes available")
|
||||
}
|
||||
|
||||
tx := new(types.Transaction)
|
||||
if err := rlp.DecodeBytes(dt.RawBytes, tx); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode transaction: %w", err)
|
||||
}
|
||||
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// IsSwapTransaction checks if the transaction data is a DEX swap
|
||||
func IsSwapTransaction(data []byte) bool {
|
||||
if len(data) < 4 {
|
||||
|
||||
Reference in New Issue
Block a user