Skip to content

Commit 81df41c

Browse files
committed
add better error handling and wait for transaction confirmation
1 parent 596fabf commit 81df41c

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

permissionless-batches/README.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ To produce a batch you need to run the `batch-production-submission` profile in
9191

9292

9393
Run with `docker compose --profile batch-production-submission up`.
94+
This will produce chunks, a batch and bundle which will be proven in the next step.
95+
`Success! You're ready to generate proofs!` indicates that everything is working correctly and the batch is ready to be proven.
9496

9597
#### Proving a batch
96-
To prove a batch you need to run the `proving` profile in `docker-compose.yml`.
98+
To prove the chunk, batch and bundle you just generated you need to run the `proving` profile in `docker-compose.yml`.
9799

98100
1. Make sure `verifier` `low_version_circuit` and `high_version_circuit` in `conf/coordinator/config.json` are correct for the latest fork: [TODO link list with versions](#batch-production-toolkit)
99101
2. Download the latest `assets` and `params` for the circuit from [TODO link list with versions](#batch-production-toolkit) into `conf/coordinator/assets` and `conf/coordinator/params` respectively.
@@ -104,8 +106,17 @@ Run with `docker compose --profile proving up`.
104106

105107

106108
#### Batch submission
107-
TODO
109+
To submit the batch you need to run the `batch-production-submission` profile in `docker-compose.yml`.
108110

111+
1. Fill in required fields in `conf/relayer/config.json` for the sender config.
112+
113+
Run with `docker compose --profile batch-production-submission up`.
114+
This will submit the batch to L1 and finalize it. The transaction will be retried in case of failure.
115+
116+
**Troubleshooting**
117+
- in case the submission fails it will print the calldata for the transaction in an error message. You can use this with `cast call --trace --rpc-url "$SCROLL_L1_DEPLOYMENT_RPC" "$L1_SCROLL_CHAIN_PROXY_ADDR" <calldata>` to see what went wrong.
118+
- `0x4df567b9: ErrorNotInEnforcedBatchMode`: permissionless batch mode is not activated, you can't submit a batch
119+
- `0xa5d305cc: ErrorBatchIsEmpty`: no blob was provided. This is usually returned if you do the `cast call`, permissionless mode is activated but you didn't provide a blob in the transaction.
109120

110121
## Operator recovery
111122
Operator recovery needs to be run by the rollup operator to resume normal rollup operation after permissionless batch mode is deactivated. It consists of two main components:

rollup/cmd/permissionless_batches/app/app.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,21 @@ func action(ctx *cli.Context) error {
113113
return fmt.Errorf("failed to submit batch: %w", err)
114114
}
115115

116-
// TODO: wait until tx is confirmed here
116+
log.Info("Transaction submitted to L1, waiting for confirmation...")
117+
118+
// Catch CTRL-C to ensure a graceful shutdown.
119+
interrupt := make(chan os.Signal, 1)
120+
signal.Notify(interrupt, os.Interrupt)
121+
122+
select {
123+
case <-subCtx.Done():
124+
case confirmation := <-submitter.Sender().ConfirmChan():
125+
if confirmation.IsSuccessful {
126+
log.Info("Transaction confirmed on L1, your permissionless batch is part of the ledger!", "tx hash", confirmation.TxHash)
127+
}
128+
case <-interrupt:
129+
log.Info("CTRL-C received, shutting down...")
130+
}
117131
}
118132

119133
return nil

rollup/internal/controller/permissionless_batches/minimal_recovery.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/scroll-tech/go-ethereum/log"
1414
"github.com/scroll-tech/go-ethereum/rollup/da_syncer/blob_client"
1515
"github.com/scroll-tech/go-ethereum/rollup/l1"
16+
1617
"scroll-tech/common/types"
1718

1819
"scroll-tech/database/migrate"
@@ -267,7 +268,7 @@ func (r *MinimalRecovery) restoreMinimalPreviousState() (*orm.Chunk, *orm.Batch,
267268
// 4. Get the L1 messages count after the latest finalized batch.
268269
var l1MessagesCount uint64
269270
if r.cfg.RecoveryConfig.ForceL1MessageCount == 0 {
270-
l1MessagesCount, err = reader.FinalizedL1MessageQueueIndex(latestFinalizedL1Block)
271+
l1MessagesCount, err = reader.NextUnfinalizedL1MessageQueueIndex(latestFinalizedL1Block)
271272
if err != nil {
272273
return nil, nil, nil, fmt.Errorf("failed to get L1 messages count: %w", err)
273274
}

rollup/internal/controller/permissionless_batches/submitter.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package permissionless_batches
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"math/big"
78

@@ -15,6 +16,7 @@ import (
1516
"github.com/scroll-tech/go-ethereum/log"
1617
"github.com/scroll-tech/go-ethereum/params"
1718
"github.com/scroll-tech/go-ethereum/rpc"
19+
1820
"scroll-tech/common/types"
1921
"scroll-tech/common/types/message"
2022
bridgeAbi "scroll-tech/rollup/abi"
@@ -62,6 +64,10 @@ func NewSubmitter(ctx context.Context, db *gorm.DB, cfg *config.RelayerConfig, c
6264

6365
}
6466

67+
func (s *Submitter) Sender() *sender.Sender {
68+
return s.finalizeSender
69+
}
70+
6571
func (s *Submitter) Submit(withProof bool) error {
6672
// Check if the bundle is already finalized
6773
bundle, err := s.bundleOrm.GetLatestBundle(s.ctx)
@@ -140,9 +146,12 @@ func (s *Submitter) Submit(withProof bool) error {
140146
log.Error("commitAndFinalize in layer1 failed", "with proof", withProof, "index", bundle.Index,
141147
"batch index", bundle.StartBatchIndex,
142148
"RollupContractAddress", s.cfg.RollupContractAddress, "err", err, "calldata", common.Bytes2Hex(calldata))
143-
if typedErr, ok := err.(rpc.Error); ok {
144-
fmt.Println("errorData", typedErr.ErrorCode())
149+
150+
var rpcError rpc.DataError
151+
if errors.As(err, &rpcError) {
152+
log.Error("rpc.DataError ", "error", rpcError.Error(), "message", rpcError.ErrorData())
145153
}
154+
146155
return fmt.Errorf("commitAndFinalize failed, bundle index: %d, err: %w", bundle.Index, err)
147156
}
148157

0 commit comments

Comments
 (0)