Commit fc13e850 authored by Michael de Hoog's avatar Michael de Hoog

Small simplification

parent a1064b2a
...@@ -370,52 +370,48 @@ func (l *BatchSubmitter) handleReceipt(r txmgr.TxReceipt[txData]) { ...@@ -370,52 +370,48 @@ func (l *BatchSubmitter) handleReceipt(r txmgr.TxReceipt[txData]) {
} }
} }
// publishStateToL1Factory produces a publishStateToL1Job job // publishStateToL1Factory returns a txmgr factory function that pulls the block data
// loaded into `state`, and returns a txmgr transaction candidate that can be used to
// submit the associated data to the L1 in the form of channel frames. The factory
// will return an io.EOF error if no data is available.
func (l *BatchSubmitter) publishStateToL1Factory() txmgr.TxFactory[txData] { func (l *BatchSubmitter) publishStateToL1Factory() txmgr.TxFactory[txData] {
return func(ctx context.Context) (txmgr.TxCandidate, txData, error) { return func(ctx context.Context) (txmgr.TxCandidate, txData, error) {
return l.publishStateToL1Job(ctx) // this is called from a separate goroutine in the txmgr.Queue,
} // so lock to prevent concurrent access to the state
} l.publishLock.Lock()
defer l.publishLock.Unlock()
// publishStateToL1Job pulls the block data loaded into `state`, and returns a function that
// will submit the associated data to the L1 in the form of channel frames when called. l1tip, err := l.l1Tip(ctx)
// Returns an io.EOF error if no data is available. if err != nil {
func (l *BatchSubmitter) publishStateToL1Job(ctx context.Context) (txmgr.TxCandidate, txData, error) { l.log.Error("Failed to query L1 tip", "error", err)
// this is called from a separate goroutine in the tx queue, so we need return txmgr.TxCandidate{}, txData{}, err
// to lock to prevent concurrent access to the state }
l.publishLock.Lock() l.recordL1Tip(l1tip)
defer l.publishLock.Unlock()
l1tip, err := l.l1Tip(ctx) // Collect next transaction data
if err != nil { txdata, err := l.state.TxData(l1tip.ID())
l.log.Error("Failed to query L1 tip", "error", err) if err == io.EOF {
return txmgr.TxCandidate{}, txData{}, err l.log.Trace("no transaction data available")
} return txmgr.TxCandidate{}, txData{}, err
l.recordL1Tip(l1tip) } else if err != nil {
l.log.Error("unable to get tx data", "err", err)
// Collect next transaction data return txmgr.TxCandidate{}, txData{}, err
txdata, err := l.state.TxData(l1tip.ID()) }
if err == io.EOF {
l.log.Trace("no transaction data available")
return txmgr.TxCandidate{}, txData{}, err
} else if err != nil {
l.log.Error("unable to get tx data", "err", err)
return txmgr.TxCandidate{}, txData{}, err
}
// 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.
data := txdata.Bytes() data := txdata.Bytes()
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 txmgr.TxCandidate{}, txData{}, fmt.Errorf("failed to calculate intrinsic gas: %w", err) return txmgr.TxCandidate{}, txData{}, fmt.Errorf("failed to calculate intrinsic gas: %w", err)
} }
candidate := txmgr.TxCandidate{ candidate := txmgr.TxCandidate{
To: &l.Rollup.BatchInboxAddress, To: &l.Rollup.BatchInboxAddress,
TxData: data, TxData: data,
GasLimit: intrinsicGas, GasLimit: intrinsicGas,
}
return candidate, txdata, nil
} }
return candidate, txdata, nil
} }
func (l *BatchSubmitter) recordL1Tip(l1tip eth.L1BlockRef) { func (l *BatchSubmitter) recordL1Tip(l1tip eth.L1BlockRef) {
......
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