Commit 4abae618 authored by Joshua Gutow's avatar Joshua Gutow Committed by GitHub

op-batcher: Rewrite ChannelManager (#3859)

* op-batcher: Rewrite ChannelManager

The channel manager is now responsible for tracking in flight frames
and properly handling different error conditions.

* op-batcher: String() & TerminalString() for txID

* op-batcher: Remove channelPending bool

* op-batcher: Fix wraparound bug in timeout check

* op-batcher: Comments + Logging

* op-batcher: Properly exit loop
parent 9940c8cd
This diff is collapsed.
...@@ -150,7 +150,7 @@ func NewBatchSubmitter(cfg Config, l log.Logger) (*BatchSubmitter, error) { ...@@ -150,7 +150,7 @@ func NewBatchSubmitter(cfg Config, l log.Logger) (*BatchSubmitter, error) {
txMgr: NewTransactionManger(l, txManagerConfig, batchInboxAddress, chainID, sequencerPrivKey, l1Client), txMgr: NewTransactionManger(l, txManagerConfig, batchInboxAddress, chainID, sequencerPrivKey, l1Client),
done: make(chan struct{}), done: make(chan struct{}),
log: l, log: l,
state: new(channelManager), state: NewChannelManager(l, cfg.ChannelTimeout),
// TODO: this context only exists because the even loop doesn't reach done // TODO: this context only exists because the even loop doesn't reach done
// if the tx manager is blocking forever due to e.g. insufficient balance. // if the tx manager is blocking forever due to e.g. insufficient balance.
ctx: ctx, ctx: ctx,
...@@ -234,7 +234,7 @@ func (l *BatchSubmitter) calculateL2BlockRangeToStore(ctx context.Context) (eth. ...@@ -234,7 +234,7 @@ func (l *BatchSubmitter) calculateL2BlockRangeToStore(ctx context.Context) (eth.
if l.lastStoredBlock == (eth.BlockID{}) { if l.lastStoredBlock == (eth.BlockID{}) {
l.log.Info("Starting batch-submitter work at safe-head", "safe", syncStatus.SafeL2) l.log.Info("Starting batch-submitter work at safe-head", "safe", syncStatus.SafeL2)
l.lastStoredBlock = syncStatus.SafeL2.ID() l.lastStoredBlock = syncStatus.SafeL2.ID()
} else if l.lastStoredBlock.Number <= syncStatus.SafeL2.Number { } else if l.lastStoredBlock.Number < syncStatus.SafeL2.Number {
l.log.Warn("last submitted block lagged behind L2 safe head: batch submission will continue from the safe head now", "last", l.lastStoredBlock, "safe", syncStatus.SafeL2) l.log.Warn("last submitted block lagged behind L2 safe head: batch submission will continue from the safe head now", "last", l.lastStoredBlock, "safe", syncStatus.SafeL2)
l.lastStoredBlock = syncStatus.SafeL2.ID() l.lastStoredBlock = syncStatus.SafeL2.ID()
} }
...@@ -269,18 +269,33 @@ func (l *BatchSubmitter) loop() { ...@@ -269,18 +269,33 @@ func (l *BatchSubmitter) loop() {
l.loadBlocksIntoState(l.ctx) l.loadBlocksIntoState(l.ctx)
// Empty the state after loading into it on every iteration. // Empty the state after loading into it on every iteration.
blockLoop:
for { for {
// Collect the output frame // Collect the output frame
data, _, err := l.state.TxData(eth.L1BlockRef{}) data, id, err := l.state.TxData(eth.L1BlockRef{})
if err == io.EOF { if err == io.EOF {
l.log.Trace("no transaction data available")
break // local for loop break // local for loop
} else if err != nil { } else if err != nil {
l.log.Error("unable to get tx data", "err", err) l.log.Error("unable to get tx data", "err", err)
break break
} }
// Drop receipt + error for now // Record TX Status
if _, err := l.txMgr.SendTransaction(l.ctx, data); err != nil { if receipt, err := l.txMgr.SendTransaction(l.ctx, data); err != nil {
l.log.Error("Failed to send transaction", "err", err) l.log.Error("Failed to send transaction", "err", err)
l.state.TxFailed(id)
} else {
l.log.Info("Transaction confirmed", "tx_hash", receipt.TxHash, "status", receipt.Status, "block_hash", receipt.BlockHash, "block_number", receipt.BlockNumber)
l.state.TxConfirmed(id, eth.BlockID{Number: receipt.BlockNumber.Uint64(), Hash: receipt.BlockHash})
}
// hack to exit this loop. Proper fix is to do request another send tx or parallel tx sending
// from the channel manager rather than sending the channel in a loop. This stalls b/c if the
// context is cancelled while sending, it will never fuilly clearing the pending txns.
select {
case <-l.ctx.Done():
break blockLoop
default:
} }
} }
......
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