Skip to content

refactor(rollup-relayer): simplify construct commit batch payload #1673

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
22 changes: 10 additions & 12 deletions rollup/internal/controller/relayer/l2_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
}
}

var batchesToSubmit []*dbBatchWithChunksAndParent
var batchesToSubmit []*dbBatchWithChunks
for i, dbBatch := range dbBatches {
var dbChunks []*orm.Chunk
var dbParentBatch *orm.Batch
Expand Down Expand Up @@ -433,10 +433,9 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
}

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

Expand Down Expand Up @@ -523,7 +522,7 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
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 {
func (r *Layer2Relayer) contextIDFromBatches(batches []*dbBatchWithChunks) string {
contextIDs := []string{"v7"}

for _, batch := range batches {
Expand All @@ -541,10 +540,9 @@ func (r *Layer2Relayer) batchHashesFromContextID(contextID string) []string {
return []string{contextID}
}

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

// ProcessPendingBundles submits proof to layer 1 rollup contract
Expand Down Expand Up @@ -898,7 +896,7 @@ func (r *Layer2Relayer) handleL2RollupRelayerConfirmLoop(ctx context.Context) {
}
}

func (r *Layer2Relayer) constructCommitBatchPayloadCodecV7(batchesToSubmit []*dbBatchWithChunksAndParent, firstBatch, lastBatch *orm.Batch) ([]byte, []*kzg4844.Blob, uint64, uint64, error) {
func (r *Layer2Relayer) constructCommitBatchPayloadCodecV7(batchesToSubmit []*dbBatchWithChunks, firstBatch, lastBatch *orm.Batch) ([]byte, []*kzg4844.Blob, uint64, uint64, error) {
var maxBlockHeight uint64
var totalGasUsed uint64
blobs := make([]*kzg4844.Blob, 0, len(batchesToSubmit))
Expand Down Expand Up @@ -929,7 +927,7 @@ func (r *Layer2Relayer) constructCommitBatchPayloadCodecV7(batchesToSubmit []*db

encodingBatch := &encoding.Batch{
Index: b.Batch.Index,
ParentBatchHash: common.HexToHash(b.ParentBatch.Hash),
ParentBatchHash: common.HexToHash(b.Batch.ParentBatchHash),
PrevL1MessageQueueHash: common.HexToHash(b.Batch.PrevL1MessageQueueHash),
PostL1MessageQueueHash: common.HexToHash(b.Batch.PostL1MessageQueueHash),
Blocks: batchBlocks,
Expand Down