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

feat(proposer): Check if blockhash is checkpointed #314

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
62 changes: 35 additions & 27 deletions proposer/op/proposer/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,32 +551,6 @@ func (l *L2OutputSubmitter) sendTransaction(ctx context.Context, output *eth.Out
return nil
}

// sendCheckpointTransaction sends a transaction to checkpoint the blockhash corresponding to `blockNumber` on the L2OO contract.
func (l *L2OutputSubmitter) sendCheckpointTransaction(ctx context.Context, blockNumber *big.Int) error {
var receipt *types.Receipt
data, err := l.CheckpointBlockHashTxData(blockNumber)
if err != nil {
return err
}
// TODO: This currently blocks the loop while it waits for the transaction to be confirmed. Up to 3 minutes.
receipt, err = l.Txmgr.Send(ctx, txmgr.TxCandidate{
TxData: data,
To: l.Cfg.L2OutputOracleAddr,
GasLimit: 0,
})
if err != nil {
return err
}

if receipt.Status == types.ReceiptStatusFailed {
l.Log.Error("checkpoint blockhash tx successfully published but reverted", "tx_hash", receipt.TxHash)
} else {
l.Log.Info("checkpoint blockhash tx successfully published",
"tx_hash", receipt.TxHash)
}
return nil
}

// loop is responsible for creating & submitting the next outputs
// TODO: Look into adding a transaction cache so the loop isn't waiting for the transaction to confirm. This sometimes takes up to 30s.
func (l *L2OutputSubmitter) loop() {
Expand Down Expand Up @@ -744,9 +718,43 @@ func (l *L2OutputSubmitter) checkpointBlockHash(ctx context.Context) (uint64, co
blockHash := header.Hash()
blockNumber := header.Number

err = l.sendCheckpointTransaction(cCtx, blockNumber)
// Check if the block hash has ALREADY been checkpointed on the L2OO contract.
// If it has, we can skip the checkpointing step.
contract, err := opsuccinctbindings.NewOPSuccinctL2OutputOracleCaller(*l.Cfg.L2OutputOracleAddr, l.L1Client)
if err != nil {
return 0, common.Hash{}, err
}
maybeBlockHash, err := contract.HistoricBlockHashes(&bind.CallOpts{Context: cCtx}, blockNumber)
if err != nil {
return 0, common.Hash{}, err
}
if maybeBlockHash != (common.Hash{}) {
l.Log.Info("Block hash already checkpointed on L2OO contract", "block_number", blockNumber, "block_hash", blockHash)
return blockNumber.Uint64(), blockHash, nil
}

// If not, send a transaction to checkpoint the blockhash on the L2OO contract.
var receipt *types.Receipt
data, err := l.CheckpointBlockHashTxData(blockNumber)
if err != nil {
return 0, common.Hash{}, err
}

// TODO: This currently blocks the loop while it waits for the transaction to be confirmed. Up to 3 minutes.
receipt, err = l.Txmgr.Send(ctx, txmgr.TxCandidate{
TxData: data,
To: l.Cfg.L2OutputOracleAddr,
GasLimit: 0,
})
if err != nil {
return 0, common.Hash{}, err
}

if receipt.Status == types.ReceiptStatusFailed {
l.Log.Error("checkpoint blockhash tx successfully published but reverted", "tx_hash", receipt.TxHash)
} else {
l.Log.Info("checkpoint blockhash tx successfully published",
"tx_hash", receipt.TxHash)
}
return blockNumber.Uint64(), blockHash, nil
}
Loading