Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
41606fe
support first version of CodecV6 in relayer and add functionality to …
jonastheis Dec 30, 2024
0c0c417
adjust Sender to support multiple blobs when sending a transaction
jonastheis Dec 31, 2024
78c9963
implement batch submission of multiple batches per transaction and co…
jonastheis Dec 31, 2024
940fde0
implement missing part of commit logic for CodecV6
jonastheis Dec 31, 2024
ca8d930
feat(rollup-relayer): add Euclid support
omerfirmak Jan 9, 2025
421afe9
deprecate halo2 provers, start openvm prover
omerfirmak Jan 27, 2025
b460d4a
Merge remote-tracking branch 'origin/omerfirmak/mpt' into feat/use-co…
jonastheis Jan 28, 2025
182f8e3
update go.mod to latest da-codec version V7
jonastheis Jan 28, 2025
783b965
update go.mod to latest da-codec version V7
jonastheis Feb 5, 2025
5a479c3
address review comments
jonastheis Feb 5, 2025
310abdd
add InitialL1MessageQueueHash and LastL1MessageQueueHash to chunk and…
jonastheis Feb 5, 2025
2efbbd7
add support for bundles with CodecV7
jonastheis Feb 5, 2025
e713424
update contextIDFromBatches prefix to v7
jonastheis Feb 5, 2025
f4e17bc
fix ci
jonastheis Feb 5, 2025
99c0a9f
update to latest da-codec
jonastheis Feb 10, 2025
8db5339
fix issues with chunks when handling CodecV7
jonastheis Feb 10, 2025
69a80d4
add testCommitBatchAndFinalizeBundleCodecV7 for relayer
jonastheis Feb 10, 2025
5f22950
feat(prover): euclid prover first draft
omerfirmak Feb 5, 2025
9412c7f
feat(coordinator): abstract proof types behind an interface
omerfirmak Feb 6, 2025
c3a3bad
feat(rollup-relayer): add Euclid support
omerfirmak Jan 9, 2025
2de45f0
feat(coordinator): add euclid proof types
omerfirmak Feb 6, 2025
f01af24
fix: potentially flaky testResubmitZeroGasPriceTransaction
omerfirmak Feb 7, 2025
2bd0655
feat: Add Euclid verifier
omerfirmak Feb 7, 2025
848d3a6
fix: re-enable supported forks check
omerfirmak Feb 7, 2025
e5ad9c6
feat: allow stopping fake finalization at fork boundary
omerfirmak Feb 13, 2025
b424cef
feat: add CPU prover dockerfile
omerfirmak Feb 13, 2025
ac17696
feat: update contracts to euclid version
omerfirmak Feb 13, 2025
d503d4a
fix: base64 encode VKs
omerfirmak Feb 17, 2025
bf08436
fix: prover using wrong resources for batch/bundle circuits
omerfirmak Feb 17, 2025
83c73f8
fix: coordinator ignore euclid transition chunk
omerfirmak Feb 17, 2025
d3acd6b
adjust to recent CodecV7 changes. remove initialL1MessageQueueIndex a…
jonastheis Feb 19, 2025
f13863e
Merge remote-tracking branch 'origin/omerfirmak/euclid-prover' into f…
jonastheis Feb 20, 2025
8b57dd6
fixes after merge
jonastheis Feb 20, 2025
37924b0
feat: bump zkvm-prover to rc4
omerfirmak Feb 20, 2025
fbc14ac
address review comments
jonastheis Feb 20, 2025
867fda6
fix: add batch tasks details for v6 codec
omerfirmak Feb 20, 2025
2e9827a
fix: properly propagate verifier errors
omerfirmak Feb 21, 2025
01fa3b3
feat: use verifier-only types in coordinator
omerfirmak Feb 21, 2025
50ebf17
fix: generate evm proofs for bundles
omerfirmak Feb 21, 2025
e1a0bab
add new contract ABI and adjust submission to it
jonastheis Feb 24, 2025
bb9d404
fix: force byte arrays to be marshaled as JSON arrays
omerfirmak Feb 24, 2025
0125dd6
add new contract ABI
jonastheis Feb 27, 2025
121ce09
update config and adjust to new contract ABI
jonastheis Feb 27, 2025
ed394a6
make sure that all batches committed in the same tx are part of the s…
jonastheis Feb 27, 2025
a55de1f
feat: set code tx support (#1600)
colinlyguo Feb 27, 2025
89ede0d
build rollup images with --platform=linux/amd64
jonastheis Feb 27, 2025
782e019
Merge branch 'feat/use-codec-v6' of github.com:scroll-tech/scroll int…
jonastheis Feb 27, 2025
081d289
update da-codec dependency
jonastheis Feb 27, 2025
47a6c23
fix bug where chunk and batch blocks mismatch
jonastheis Feb 28, 2025
eb5758b
feat: bump to zkvm-prover rc5
roynalnaruto Feb 28, 2025
7353f30
update l2geth version in go.mod
jonastheis Feb 28, 2025
673777f
use go 1.22 in Dockerfile builder
jonastheis Feb 28, 2025
554a233
refactor: move euclid prover to new subdir
omerfirmak Mar 4, 2025
e27ab5a
Merge remote-tracking branch 'origin/develop' into omerfirmak/euclid-…
omerfirmak Mar 4, 2025
26a49cb
Merge remote-tracking branch 'origin/omerfirmak/euclid-prover' into f…
jonastheis Mar 6, 2025
8ea4315
update go.work.sum
jonastheis Mar 6, 2025
55b32e1
add debug log message
jonastheis Mar 6, 2025
d6674e8
add configuration parameter maxChunksPerBatch for batch proposer
jonastheis Mar 6, 2025
a1c4562
add configuration parameter maxChunksPerBatch for batch proposer
jonastheis Mar 6, 2025
c8b614f
unit tests fix
Mar 6, 2025
f91c999
fix batch proposer panic
Thegaram Mar 6, 2025
82dd5e0
feat(bridge-history): support codecv7
Mar 6, 2025
4333d51
Revert "feat(bridge-history): support codecv7"
Mar 6, 2025
b30f4d0
chore(zkvm-circuit): upgrade to 0.1.0-rc.6 (#1610)
colinlyguo Mar 7, 2025
03c63a6
update batch/chunk details for phase2
omerfirmak Mar 7, 2025
9f4c9ee
fix: prover version (#1611)
yiweichi Mar 7, 2025
101cc46
update dependencies
Mar 7, 2025
a868bc1
simplify version checks
Mar 7, 2025
8b08a57
Revert "simplify version checks"
Mar 7, 2025
f1ea4b3
process task with CodecV7, add check for BlobDataProof length and add…
jonastheis Mar 8, 2025
b7e7d1a
Merge remote-tracking branch 'origin/omerfirmak/euclid-prover' into f…
jonastheis Mar 8, 2025
94bee19
feat(bridge-history): support codecv7 (#1609)
colinlyguo Mar 8, 2025
f27ddb7
remove debug line
jonastheis Mar 8, 2025
da96331
tweak comments and some renamings
Mar 9, 2025
d79aaef
fix CI
jonastheis Mar 10, 2025
ab7038c
Merge branch 'feat/use-codec-v6' of github.com:scroll-tech/scroll int…
jonastheis Mar 10, 2025
47219f2
run goimports
jonastheis Mar 10, 2025
95adcc3
fix tests
jonastheis Mar 10, 2025
224546e
add new ABI and add more tests
jonastheis Mar 10, 2025
0799dd4
fix linter
jonastheis Mar 10, 2025
7a70e37
fix test
jonastheis Mar 10, 2025
57d50b7
Merge branch 'develop' into omerfirmak/euclid-prover
omerfirmak Mar 10, 2025
20dffe4
chore: auto version bump [bot]
omerfirmak Mar 10, 2025
867307d
Merge remote-tracking branch 'origin/omerfirmak/euclid-prover' into f…
jonastheis Mar 10, 2025
c9f6e8c
Merge remote-tracking branch 'origin/develop' into feat/use-codec-v6
jonastheis Mar 10, 2025
9b462e4
go mod tidy
jonastheis Mar 10, 2025
d57e6b0
chore: auto version bump [bot]
jonastheis Mar 10, 2025
4d677b3
address review comments
jonastheis Mar 10, 2025
90d1563
Merge remote-tracking branch 'origin/develop' into feat/use-codec-v6
jonastheis Mar 10, 2025
d987931
go mod tidy
jonastheis Mar 10, 2025
38b3239
chore: auto version bump [bot]
jonastheis Mar 10, 2025
e99a851
Merge branch 'feat/use-codec-v6' of github.com:scroll-tech/scroll int…
jonastheis Mar 10, 2025
bb6ee2c
Merge branch 'develop' into feat/use-codec-v6
jonastheis Mar 10, 2025
af38122
chore: auto version bump [bot]
jonastheis Mar 10, 2025
2cc9f65
chore: auto version bump [bot]
georgehao Mar 11, 2025
eacdc78
fix(bridge-history): overwrite l2geth dependency by replace (#1617)
colinlyguo Mar 11, 2025
bee4151
fix(coordinator): prover type string (#1618)
colinlyguo Mar 11, 2025
db5206d
Merge branch 'develop' into feat/use-codec-v6
Thegaram Mar 11, 2025
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
4 changes: 2 additions & 2 deletions rollup/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/holiman/uint256 v1.2.4
github.com/mitchellh/mapstructure v1.5.0
github.com/prometheus/client_golang v1.16.0
github.com/scroll-tech/da-codec v0.1.2
github.com/scroll-tech/go-ethereum v1.10.14-0.20241023093931-91c2f9c27f4d
github.com/scroll-tech/da-codec v0.1.3-0.20241227041406-286f2092d4cd
github.com/scroll-tech/go-ethereum v1.10.14-0.20241210104312-bdf64cfb39dc
github.com/smartystreets/goconvey v1.8.0
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
Expand Down
3 changes: 3 additions & 0 deletions rollup/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,11 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/scroll-tech/da-codec v0.1.2 h1:QyJ+dQ4zWVVJwuqxNt4MiKyrymVc6rHe4YPtURkjiRc=
github.com/scroll-tech/da-codec v0.1.2/go.mod h1:odz1ck3umvYccCG03osaQBISAYGinZktZYbpk94fYRE=
github.com/scroll-tech/da-codec v0.1.3-0.20241227041406-286f2092d4cd h1:Yq3vc5e9VqXKBEGAqpptPhviXlydoL3R8xX8R8C6YvY=
github.com/scroll-tech/da-codec v0.1.3-0.20241227041406-286f2092d4cd/go.mod h1:XfQhUl3msmE6dpZEbR/LIwiMxywPQcUQsch9URgXDzs=
github.com/scroll-tech/go-ethereum v1.10.14-0.20241023093931-91c2f9c27f4d h1:vuv7fGKEDtoeetI6RkKt8RAByJsYZBWk9Vo6gShv65c=
github.com/scroll-tech/go-ethereum v1.10.14-0.20241023093931-91c2f9c27f4d/go.mod h1:PWEOTg6LeWlJAlFJauO0msSLXWnpHmE+mVh5txtfeRM=
github.com/scroll-tech/go-ethereum v1.10.14-0.20241210104312-bdf64cfb39dc/go.mod h1:xRDJvaNUe7lCU2fB+AqyS7gahar+dfJPrUJplfXF4dw=
github.com/scroll-tech/zktrie v0.8.4 h1:UagmnZ4Z3ITCk+aUq9NQZJNAwnWl4gSxsLb2Nl7IgRE=
github.com/scroll-tech/zktrie v0.8.4/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
Expand Down
12 changes: 12 additions & 0 deletions rollup/internal/config/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ type SenderConfig struct {
TxType string `json:"tx_type"`
// The maximum number of pending blob-carrying transactions
MaxPendingBlobTxs int64 `json:"max_pending_blob_txs"`

// Config for batch submission
BatchSubmission *BatchSubmission `json:"batch_submission"`
}

type BatchSubmission struct {
// The minimum number of batches to submit in a single transaction.
MinBatches int `json:"min_batches"`
// The maximum number of batches to submit in a single transaction.
MaxBatches int `json:"max_batches"`
// The time in seconds after which a batch is considered stale and should be submitted ignoring the min batch count.
TimeoutSec int64 `json:"timeout"`
}

// ChainMonitor this config is used to get batch status from chain_monitor API.
Expand Down
252 changes: 246 additions & 6 deletions rollup/internal/controller/relayer/l2_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,178 @@ func (r *Layer2Relayer) ProcessGasPriceOracle() {
// ProcessPendingBatches processes the pending batches by sending commitBatch transactions to layer 1.
func (r *Layer2Relayer) ProcessPendingBatches() {
// get pending batches from database in ascending order by their index.
dbBatches, err := r.batchOrm.GetFailedAndPendingBatches(r.ctx, 5)
dbBatches, err := r.batchOrm.GetFailedAndPendingBatches(r.ctx, max(5, r.cfg.SenderConfig.BatchSubmission.MaxBatches))
if err != nil {
log.Error("Failed to fetch pending L2 batches", "err", err)
return
}

var batchesToSubmit []*dbBatchWithChunksAndParent
var forceSubmit bool
for i, dbBatch := range dbBatches {
if i == 0 && encoding.CodecVersion(dbBatch.CodecVersion) < encoding.CodecV6 {
// if the first batch is not >= V6 then we need to submit batches one by one
r.processPendingBatchesV4(dbBatches)
return
}

batchesToSubmitLen := len(batchesToSubmit)
var dbChunks []*orm.Chunk
var dbParentBatch *orm.Batch

// Verify batches compatibility
{
dbChunks, err = r.chunkOrm.GetChunksInRange(r.ctx, dbBatch.StartChunkIndex, dbBatch.EndChunkIndex)
if err != nil {
log.Error("failed to get chunks in range", "err", err)
return
}

// check codec version
for _, dbChunk := range dbChunks {
if dbBatch.CodecVersion != dbChunk.CodecVersion {
log.Error("batch codec version is different from chunk codec version", "batch index", dbBatch.Index, "chunk index", dbChunk.Index, "batch codec version", dbBatch.CodecVersion, "chunk codec version", dbChunk.CodecVersion)
return
}
}

if dbBatch.Index == 0 {
log.Error("invalid args: batch index is 0, should only happen in committing genesis batch")
return
}

dbParentBatch, err = r.batchOrm.GetBatchByIndex(r.ctx, dbBatch.Index-1)
if err != nil {
log.Error("failed to get parent batch header", "err", err)
return
}

if dbParentBatch.CodecVersion > dbBatch.CodecVersion {
log.Error("parent batch codec version is greater than current batch codec version", "index", dbBatch.Index, "hash", dbBatch.Hash, "parent codec version", dbParentBatch.CodecVersion, "current codec version", dbBatch.CodecVersion)
return
}

// make sure we commit batches of the same codec version together.
// If we encounter a batch with a different codec version, we stop here and will commit the batches we have so far.
// The next call of ProcessPendingBatches will then start with the batch with the different codec version.
if batchesToSubmitLen > 0 && batchesToSubmit[batchesToSubmitLen-1].Batch.CodecVersion != dbBatch.CodecVersion {
break
}
}

// if one of the batches is too old, we force submit all batches that we have so far in the next step
if !forceSubmit && time.Since(dbBatch.CreatedAt) > time.Duration(r.cfg.SenderConfig.BatchSubmission.TimeoutSec)*time.Second {
forceSubmit = true
}

if batchesToSubmitLen <= r.cfg.SenderConfig.BatchSubmission.MaxBatches {
batchesToSubmit = append(batchesToSubmit, &dbBatchWithChunksAndParent{
Batch: dbBatch,
Chunks: dbChunks,
ParentBatch: dbParentBatch,
})
}
}

if !forceSubmit && len(batchesToSubmit) < r.cfg.SenderConfig.BatchSubmission.MinBatches {
log.Debug("Not enough batches to submit", "count", len(batchesToSubmit), "minBatches", r.cfg.SenderConfig.BatchSubmission.MinBatches, "maxBatches", r.cfg.SenderConfig.BatchSubmission.MaxBatches)
return
}

if forceSubmit {
log.Info("Forcing submission of batches due to timeout", "batch index", batchesToSubmit[0].Batch.Index, "created at", batchesToSubmit[0].Batch.CreatedAt)
}

// We have at least 1 batch to commit
firstBatch := batchesToSubmit[0].Batch
lastBatch := batchesToSubmit[len(batchesToSubmit)-1].Batch

var calldata []byte
var blobs []*kzg4844.Blob
var maxBlockHeight uint64
var totalGasUsed uint64

codecVersion := encoding.CodecVersion(firstBatch.CodecVersion)
switch codecVersion {
case encoding.CodecV6:
calldata, blobs, maxBlockHeight, totalGasUsed, err = r.constructCommitBatchPayloadCodecV6(batchesToSubmit)
if err != nil {
log.Error("failed to construct commitBatchWithBlobProof payload for V6", "codecVersion", codecVersion, "start index", firstBatch.Index, "end index", lastBatch.Index, "err", err)
return
}
default:
log.Error("unsupported codec version in ProcessPendingBatches", "codecVersion", codecVersion, "start index", firstBatch, "end index", lastBatch.Index)
return
}

txHash, err := r.commitSender.SendTransaction(r.contextIDFromBatches(batchesToSubmit), &r.cfg.RollupContractAddress, calldata, blobs, 0)
if err != nil {
if errors.Is(err, sender.ErrTooManyPendingBlobTxs) {
r.metrics.rollupL2RelayerProcessPendingBatchErrTooManyPendingBlobTxsTotal.Inc()
log.Debug(
"Skipped sending commitBatch tx to L1: too many pending blob txs",
"maxPending", r.cfg.SenderConfig.MaxPendingBlobTxs,
"err", err,
)
return
}
log.Error(
"Failed to send commitBatch tx to layer1",
"start index", firstBatch.Index,
"start hash", firstBatch.Hash,
"end index", lastBatch.Index,
"end hash", lastBatch.Hash,
"RollupContractAddress", r.cfg.RollupContractAddress,
"err", err,
"calldata", common.Bytes2Hex(calldata),
)
return
}

if err = r.db.Transaction(func(dbTX *gorm.DB) error {
for _, dbBatch := range batchesToSubmit {
if err = r.batchOrm.UpdateCommitTxHashAndRollupStatus(r.ctx, dbBatch.Batch.Hash, txHash.String(), types.RollupCommitting, dbTX); err != nil {
return fmt.Errorf("UpdateCommitTxHashAndRollupStatus failed for batch %d: %s, err %v", dbBatch.Batch.Index, dbBatch.Batch.Hash, err)
}
}

return nil
}); err != nil {
log.Error("failed to update status for batches to RollupCommitting", "err", err)
}

r.metrics.rollupL2RelayerCommitBlockHeight.Set(float64(maxBlockHeight))
r.metrics.rollupL2RelayerCommitThroughput.Add(float64(totalGasUsed))
r.metrics.rollupL2RelayerProcessPendingBatchSuccessTotal.Add(float64(len(batchesToSubmit)))

log.Info("Sent the commitBatches tx to layer1", "batches count", len(batchesToSubmit), "start index", firstBatch.Index, "start hash", firstBatch.Hash, "end index", lastBatch.Index, "end hash", lastBatch.Hash, "tx hash", txHash.String())
}

func (r *Layer2Relayer) contextIDFromBatches(batches []*dbBatchWithChunksAndParent) string {
contextIDs := []string{"v6"}

for _, batch := range batches {
contextIDs = append(contextIDs, batch.Batch.Hash)
}

return strings.Join(contextIDs, "-")
}

func (r *Layer2Relayer) batchHashesFromContextID(contextID string) []string {
if strings.HasPrefix(contextID, "v6-") {
return strings.Split(contextID, "-")[1:]
}

return []string{contextID}
}

type dbBatchWithChunksAndParent struct {
Batch *orm.Batch
Chunks []*orm.Chunk
ParentBatch *orm.Batch
}

func (r *Layer2Relayer) processPendingBatchesV4(dbBatches []*orm.Batch) {
for _, dbBatch := range dbBatches {
r.metrics.rollupL2RelayerProcessPendingBatchTotal.Inc()

Expand Down Expand Up @@ -432,7 +599,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
return
}
default:
log.Error("unsupported codec version", "codecVersion", codecVersion)
log.Error("unsupported codec version in processPendingBatchesV4", "codecVersion", codecVersion)
return
}

Expand All @@ -444,7 +611,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
log.Warn("Batch commit previously failed, using eth_estimateGas for the re-submission", "hash", dbBatch.Hash)
}

txHash, err := r.commitSender.SendTransaction(dbBatch.Hash, &r.cfg.RollupContractAddress, calldata, blob, fallbackGasLimit)
txHash, err := r.commitSender.SendTransaction(dbBatch.Hash, &r.cfg.RollupContractAddress, calldata, []*kzg4844.Blob{blob}, fallbackGasLimit)
if err != nil {
if errors.Is(err, sender.ErrTooManyPendingBlobTxs) {
r.metrics.rollupL2RelayerProcessPendingBatchErrTooManyPendingBlobTxsTotal.Inc()
Expand Down Expand Up @@ -730,9 +897,17 @@ func (r *Layer2Relayer) handleConfirmation(cfm *sender.Confirmation) {
log.Warn("CommitBatchTxType transaction confirmed but failed in layer1", "confirmation", cfm)
}

err := r.batchOrm.UpdateCommitTxHashAndRollupStatus(r.ctx, cfm.ContextID, cfm.TxHash.String(), status)
if err != nil {
log.Warn("UpdateCommitTxHashAndRollupStatus failed", "confirmation", cfm, "err", err)
batchHashes := r.batchHashesFromContextID(cfm.ContextID)
if err := r.db.Transaction(func(dbTX *gorm.DB) error {
for _, batchHash := range batchHashes {
if err := r.batchOrm.UpdateCommitTxHashAndRollupStatus(r.ctx, batchHash, cfm.TxHash.String(), status, dbTX); err != nil {
return fmt.Errorf("UpdateCommitTxHashAndRollupStatus failed, batchHash: %s, txHash: %s, status: %s, err: %w", batchHash, cfm.TxHash.String(), status, err)
}
}

return nil
}); err != nil {
log.Warn("failed to update confirmation status for batches", "confirmation", cfm, "err", err)
}
case types.SenderTypeFinalizeBatch:
if strings.HasPrefix(cfm.ContextID, "finalizeBundle-") {
Expand Down Expand Up @@ -868,6 +1043,71 @@ func (r *Layer2Relayer) constructCommitBatchPayloadCodecV4(dbBatch *orm.Batch, d
return calldata, daBatch.Blob(), nil
}

func (r *Layer2Relayer) constructCommitBatchPayloadCodecV6(batchesToSubmit []*dbBatchWithChunksAndParent) ([]byte, []*kzg4844.Blob, uint64, uint64, error) {
var maxBlockHeight uint64
var totalGasUsed uint64
blobs := make([]*kzg4844.Blob, len(batchesToSubmit))

version := encoding.CodecVersion(batchesToSubmit[0].Batch.CodecVersion)
var firstParentBatch *orm.Batch
// construct blobs
for _, b := range batchesToSubmit {
// double check that all batches have the same version
batchVersion := encoding.CodecVersion(b.Batch.CodecVersion)
if batchVersion != version {
return nil, nil, 0, 0, fmt.Errorf("codec version mismatch, expected: %d, got: %d for batches %d and %d", version, batchVersion, batchesToSubmit[0].Batch.Index, b.Batch.Index)
}

if firstParentBatch == nil {
firstParentBatch = b.ParentBatch
}

chunks := make([]*encoding.Chunk, len(b.Chunks))
for i, c := range b.Chunks {
blocks, err := r.l2BlockOrm.GetL2BlocksInRange(r.ctx, c.StartBlockNumber, c.EndBlockNumber)
if err != nil {
return nil, nil, 0, 0, fmt.Errorf("failed to get blocks in range for batch %d: %w", b.Batch.Index, err)
}
chunks[i] = &encoding.Chunk{Blocks: blocks}

if c.EndBlockNumber > maxBlockHeight {
maxBlockHeight = c.EndBlockNumber
}
totalGasUsed += c.TotalL2TxGas
}

encodingBatch := &encoding.Batch{
Index: b.Batch.Index,
TotalL1MessagePoppedBefore: b.Chunks[0].TotalL1MessagesPoppedBefore,
ParentBatchHash: common.HexToHash(b.ParentBatch.Hash),
Chunks: chunks,
}

codec, err := encoding.CodecFromVersion(version)
if err != nil {
return nil, nil, 0, 0, fmt.Errorf("failed to get codec from version %d, err: %w", b.Batch.CodecVersion, err)
}

daBatch, err := codec.NewDABatch(encodingBatch)
if err != nil {
return nil, nil, 0, 0, fmt.Errorf("failed to create DA batch: %w", err)
}

blobs = append(blobs, daBatch.Blob())
}

if firstParentBatch == nil {
return nil, nil, 0, 0, fmt.Errorf("firstParentBatch is nil")
}

// TODO: this needs to be updated once the contract interface is finalized
calldata, err := r.l1RollupABI.Pack("commitBatches", version, firstParentBatch.BatchHeader)
if err != nil {
return nil, nil, 0, 0, fmt.Errorf("failed to pack commitBatchWithBlobProof: %w", err)
}
return calldata, blobs, maxBlockHeight, totalGasUsed, nil
}

func (r *Layer2Relayer) constructFinalizeBundlePayloadCodecV4(dbBatch *orm.Batch, aggProof *message.BundleProof) ([]byte, error) {
if aggProof != nil { // finalizeBundle with proof.
calldata, packErr := r.l1RollupABI.Pack(
Expand Down
18 changes: 11 additions & 7 deletions rollup/internal/controller/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ func (s *Sender) getFeeData(target *common.Address, data []byte, sidecar *gethTy
}

// SendTransaction send a signed L2tL1 transaction.
func (s *Sender) SendTransaction(contextID string, target *common.Address, data []byte, blob *kzg4844.Blob, fallbackGasLimit uint64) (common.Hash, error) {
func (s *Sender) SendTransaction(contextID string, target *common.Address, data []byte, blobs []*kzg4844.Blob, fallbackGasLimit uint64) (common.Hash, error) {
s.metrics.sendTransactionTotal.WithLabelValues(s.service, s.name).Inc()
var (
feeData *FeeData
sidecar *gethTypes.BlobTxSidecar
err error
)

if blob != nil {
if blobs != nil {
// check that number of pending blob-carrying txs is not too big
if s.senderType == types.SenderTypeCommitBatch {
var numPendingTransactions int64
Expand All @@ -197,7 +197,7 @@ func (s *Sender) SendTransaction(contextID string, target *common.Address, data
}

}
sidecar, err = makeSidecar(blob)
sidecar, err = makeSidecar(blobs)
if err != nil {
log.Error("failed to make sidecar for blob transaction", "error", err)
return common.Hash{}, fmt.Errorf("failed to make sidecar for blob transaction, err: %w", err)
Expand Down Expand Up @@ -681,12 +681,16 @@ func (s *Sender) getBlockNumberAndBaseFeeAndBlobFee(ctx context.Context) (uint64
return header.Number.Uint64() - 1, baseFee, blobBaseFee, nil
}

func makeSidecar(blob *kzg4844.Blob) (*gethTypes.BlobTxSidecar, error) {
if blob == nil {
return nil, errors.New("blob cannot be nil")
func makeSidecar(blobsInput []*kzg4844.Blob) (*gethTypes.BlobTxSidecar, error) {
if blobsInput == nil {
return nil, errors.New("blobs cannot be nil")
}

blobs := make([]kzg4844.Blob, len(blobsInput))
for i, blob := range blobsInput {
blobs[i] = *blob
}

blobs := []kzg4844.Blob{*blob}
var commitments []kzg4844.Commitment
var proofs []kzg4844.Proof

Expand Down
Loading