Commit 971387d1 authored by Joshua Gutow's avatar Joshua Gutow

op-batcher: Use new API

parent e354d5e7
...@@ -314,7 +314,7 @@ func (l *BatchSubmitter) loop() { ...@@ -314,7 +314,7 @@ func (l *BatchSubmitter) loop() {
} }
// Record TX Status // Record TX Status
if receipt, err := l.SendTransaction(l.ctx, txdata.Bytes()); err != nil { if receipt, err := l.sendTransaction(l.ctx, txdata.Bytes()); err != nil {
l.recordFailedTx(txdata.ID(), err) l.recordFailedTx(txdata.ID(), err)
} else { } else {
l.recordConfirmedTx(txdata.ID(), receipt) l.recordConfirmedTx(txdata.ID(), receipt)
...@@ -343,31 +343,25 @@ const networkTimeout = 2 * time.Second // How long a single network request can ...@@ -343,31 +343,25 @@ const networkTimeout = 2 * time.Second // How long a single network request can
// along with op-proposer changes to include the updated tx manager // along with op-proposer changes to include the updated tx manager
const txManagerTimeout = 2 * time.Minute // How long the tx manager can take to send a transaction. const txManagerTimeout = 2 * time.Minute // How long the tx manager can take to send a transaction.
// SendTransaction creates & submits a transaction to the batch inbox address with the given `data`. // sendTransaction creates & submits a transaction to the batch inbox address with the given `data`.
// It currently uses the underlying `txmgr` to handle transaction sending & price management. // It currently uses the underlying `txmgr` to handle transaction sending & price management.
// This is a blocking method. It should not be called concurrently. // This is a blocking method. It should not be called concurrently.
func (l *BatchSubmitter) SendTransaction(ctx context.Context, data []byte) (*types.Receipt, error) { func (l *BatchSubmitter) sendTransaction(ctx context.Context, data []byte) (*types.Receipt, error) {
// Do the gas estimation offline. A value of 0 will cause the [txmgr] to estimate the gas limit. // Do the gas estimation offline. A value of 0 will cause the [txmgr] to estimate the gas limit.
intrinsicGas, err := core.IntrinsicGas(data, nil, false, true, true, false) intrinsicGas, err := core.IntrinsicGas(data, nil, false, true, true, false)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to calculate intrinsic gas: %w", err) return nil, fmt.Errorf("failed to calculate intrinsic gas: %w", err)
} }
// Create the transaction // Send the transaction through the txmgr
tx, err := l.txMgr.CraftTx(ctx, txmgr.TxCandidate{ ctx, cancel := context.WithTimeout(ctx, txManagerTimeout)
defer cancel()
if receipt, err := l.txMgr.Send(ctx, txmgr.TxCandidate{
To: l.Rollup.BatchInboxAddress, To: l.Rollup.BatchInboxAddress,
TxData: data, TxData: data,
From: l.From, From: l.From,
GasLimit: intrinsicGas, GasLimit: intrinsicGas,
}) }); err != nil {
if err != nil {
return nil, fmt.Errorf("failed to create tx: %w", err)
}
// Send the transaction through the txmgr
ctx, cancel := context.WithTimeout(ctx, txManagerTimeout)
defer cancel()
if receipt, err := l.txMgr.Send(ctx, tx); err != nil {
l.log.Warn("unable to publish tx", "err", err, "data_size", len(data)) l.log.Warn("unable to publish tx", "err", err, "data_size", len(data))
return nil, err return nil, err
} else { } else {
......
...@@ -73,10 +73,9 @@ func TestBatchSubmitter_SendTransaction(t *testing.T) { ...@@ -73,10 +73,9 @@ func TestBatchSubmitter_SendTransaction(t *testing.T) {
GasUsed: gas, GasUsed: gas,
} }
txMgr.On("CraftTx", mock.Anything, candidate).Return(tx, nil) txMgr.On("Send", mock.Anything, candidate).Return(&expectedReceipt, nil)
txMgr.On("Send", mock.Anything, tx).Return(&expectedReceipt, nil)
receipt, err := bs.SendTransaction(context.Background(), tx.Data()) receipt, err := bs.sendTransaction(context.Background(), tx.Data())
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, receipt, &expectedReceipt) require.Equal(t, receipt, &expectedReceipt)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment