From 67d4a670e1a1f9e19e84a5a74e0d1f2c82a9b28f Mon Sep 17 00:00:00 2001
From: FletcherMan <fanciture@163.com>
Date: Wed, 27 Nov 2024 17:38:12 +0800
Subject: [PATCH] update rollup batch

---
 core/types/gen_batch.go    | 38 +++++++++++++++++++++++++-------------
 core/types/rollup_batch.go | 16 ++++++++++------
 eth/api.go                 |  6 ++++--
 3 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/core/types/gen_batch.go b/core/types/gen_batch.go
index f87294044..39a582250 100644
--- a/core/types/gen_batch.go
+++ b/core/types/gen_batch.go
@@ -18,12 +18,14 @@ func (r RollupBatch) MarshalJSON() ([]byte, error) {
 		Hash                     common.Hash
 		Version                  hexutil.Uint
 		ParentBatchHeader        hexutil.Bytes
-		BlockContexts            hexutil.Bytes
-		SkippedL1MessageBitmap   hexutil.Bytes
-		CurrentSequencerSetBytes hexutil.Bytes
-		PrevStateRoot            common.Hash
-		PostStateRoot            common.Hash
-		WithdrawRoot             common.Hash
+		BlockContexts            hexutil.Bytes  `rlp:"optional"`
+		SkippedL1MessageBitmap   hexutil.Bytes  `rlp:"optional"`
+		CurrentSequencerSetBytes hexutil.Bytes  `rlp:"optional"`
+		PrevStateRoot            common.Hash    `rlp:"optional"`
+		PostStateRoot            common.Hash    `rlp:"optional"`
+		WithdrawRoot             common.Hash    `rlp:"optional"`
+		LastBlockNumber          hexutil.Uint64 `rlp:"optional"`
+		NumL1Messages            hexutil.Uint   `rlp:"optional"`
 		Sidecar                  *BlobTxSidecar `rlp:"-"`
 	}
 	var enc RollupBatch
@@ -37,6 +39,8 @@ func (r RollupBatch) MarshalJSON() ([]byte, error) {
 	enc.PrevStateRoot = r.PrevStateRoot
 	enc.PostStateRoot = r.PostStateRoot
 	enc.WithdrawRoot = r.WithdrawRoot
+	enc.LastBlockNumber = hexutil.Uint64(r.LastBlockNumber)
+	enc.NumL1Messages = hexutil.Uint(r.NumL1Messages)
 	enc.Sidecar = r.Sidecar
 	return json.Marshal(&enc)
 }
@@ -48,13 +52,15 @@ func (r *RollupBatch) UnmarshalJSON(input []byte) error {
 		Hash                     *common.Hash
 		Version                  *hexutil.Uint
 		ParentBatchHeader        *hexutil.Bytes
-		BlockContexts            *hexutil.Bytes
-		SkippedL1MessageBitmap   *hexutil.Bytes
-		CurrentSequencerSetBytes *hexutil.Bytes
-		PrevStateRoot            *common.Hash
-		PostStateRoot            *common.Hash
-		WithdrawRoot             *common.Hash
-		Sidecar                  *BlobTxSidecar `rlp:"-"`
+		BlockContexts            *hexutil.Bytes  `rlp:"optional"`
+		SkippedL1MessageBitmap   *hexutil.Bytes  `rlp:"optional"`
+		CurrentSequencerSetBytes *hexutil.Bytes  `rlp:"optional"`
+		PrevStateRoot            *common.Hash    `rlp:"optional"`
+		PostStateRoot            *common.Hash    `rlp:"optional"`
+		WithdrawRoot             *common.Hash    `rlp:"optional"`
+		LastBlockNumber          *hexutil.Uint64 `rlp:"optional"`
+		NumL1Messages            *hexutil.Uint   `rlp:"optional"`
+		Sidecar                  *BlobTxSidecar  `rlp:"-"`
 	}
 	var dec RollupBatch
 	if err := json.Unmarshal(input, &dec); err != nil {
@@ -90,6 +96,12 @@ func (r *RollupBatch) UnmarshalJSON(input []byte) error {
 	if dec.WithdrawRoot != nil {
 		r.WithdrawRoot = *dec.WithdrawRoot
 	}
+	if dec.LastBlockNumber != nil {
+		r.LastBlockNumber = uint64(*dec.LastBlockNumber)
+	}
+	if dec.NumL1Messages != nil {
+		r.NumL1Messages = uint16(*dec.NumL1Messages)
+	}
 	if dec.Sidecar != nil {
 		r.Sidecar = dec.Sidecar
 	}
diff --git a/core/types/rollup_batch.go b/core/types/rollup_batch.go
index c7e28777b..cb1b8e083 100644
--- a/core/types/rollup_batch.go
+++ b/core/types/rollup_batch.go
@@ -14,12 +14,14 @@ type RollupBatch struct {
 	Hash                     common.Hash
 	Version                  uint
 	ParentBatchHeader        []byte
-	BlockContexts            []byte
-	SkippedL1MessageBitmap   []byte
-	CurrentSequencerSetBytes []byte
-	PrevStateRoot            common.Hash
-	PostStateRoot            common.Hash
-	WithdrawRoot             common.Hash
+	BlockContexts            []byte      `rlp:"optional"` // legacy field
+	SkippedL1MessageBitmap   []byte      `rlp:"optional"` // legacy field
+	CurrentSequencerSetBytes []byte      `rlp:"optional"`
+	PrevStateRoot            common.Hash `rlp:"optional"`
+	PostStateRoot            common.Hash `rlp:"optional"`
+	WithdrawRoot             common.Hash `rlp:"optional"`
+	LastBlockNumber          uint64      `rlp:"optional"`
+	NumL1Messages            uint16      `rlp:"optional"`
 
 	Sidecar *BlobTxSidecar `rlp:"-"`
 }
@@ -27,6 +29,8 @@ type RollupBatch struct {
 type rollupBatchMarshaling struct {
 	Version                  hexutil.Uint
 	Index                    hexutil.Uint64
+	LastBlockNumber          hexutil.Uint64
+	NumL1Messages            hexutil.Uint
 	ParentBatchHeader        hexutil.Bytes
 	BlockContexts            hexutil.Bytes
 	SkippedL1MessageBitmap   hexutil.Bytes
diff --git a/eth/api.go b/eth/api.go
index 30db55276..41fc81b1e 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -583,11 +583,12 @@ type RPCRollupBatch struct {
 	Hash                     common.Hash   `json:"hash"`
 	ParentBatchHeader        hexutil.Bytes `json:"parentBatchHeader"`
 	BlockContexts            hexutil.Bytes `json:"blockContexts"`
-	SkippedL1MessageBitmap   hexutil.Bytes `json:"skippedL1MessageBitmap"`
 	CurrentSequencerSetBytes hexutil.Bytes `json:"currentSequencerSetBytes"`
 	PrevStateRoot            common.Hash   `json:"prevStateRoot"`
 	PostStateRoot            common.Hash   `json:"postStateRoot"`
 	WithdrawRoot             common.Hash   `json:"withdrawRoot"`
+	LastBlockNumber          uint64        `json:"lastBlockNumber"`
+	NumL1Messages            uint16        `json:"numL1Messages"`
 
 	Sidecar    types.BlobTxSidecar `json:"sidecar"`
 	Signatures []RPCBatchSignature `json:"signatures"`
@@ -640,10 +641,11 @@ func (api *MorphAPI) GetRollupBatchByIndex(ctx context.Context, index uint64) (*
 		ParentBatchHeader:        rollupBatch.ParentBatchHeader,
 		BlockContexts:            rollupBatch.BlockContexts,
 		CurrentSequencerSetBytes: rollupBatch.CurrentSequencerSetBytes,
-		SkippedL1MessageBitmap:   rollupBatch.SkippedL1MessageBitmap,
 		PrevStateRoot:            rollupBatch.PrevStateRoot,
 		PostStateRoot:            rollupBatch.PostStateRoot,
 		WithdrawRoot:             rollupBatch.WithdrawRoot,
+		LastBlockNumber:          rollupBatch.LastBlockNumber,
+		NumL1Messages:            rollupBatch.NumL1Messages,
 		Sidecar:                  sidecar,
 		Signatures:               rpcSignatures,
 		CollectedL1Fee:           collectedL1Fee,