From b14a4024cd2359e17622801acf2d41dfc348cc05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Mon, 19 Jun 2023 16:44:04 +0200 Subject: [PATCH] fix: improve L1Message RPC encoding (#368) correctly encode L1 messages in RPC response --- eth/api.go | 28 ++++++++++++++++++++++++++-- params/version.go | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/eth/api.go b/eth/api.go index 9c7779c016..87fd6bc0d8 100644 --- a/eth/api.go +++ b/eth/api.go @@ -613,6 +613,17 @@ type ScrollAPI struct { eth *Ethereum } +// l1MessageTxRPC is the RPC-layer representation of an L1 message. +type l1MessageTxRPC struct { + QueueIndex uint64 `json:"queueIndex"` + Gas uint64 `json:"gas"` + To *common.Address `json:"to"` + Value *hexutil.Big `json:"value"` + Data hexutil.Bytes `json:"data"` + Sender common.Address `json:"sender"` + Hash common.Hash `json:"hash"` +} + // NewScrollAPI creates a new RPC service to query the L1 message database. func NewScrollAPI(eth *Ethereum) *ScrollAPI { return &ScrollAPI{eth: eth} @@ -624,8 +635,21 @@ func (api *ScrollAPI) GetL1SyncHeight(ctx context.Context) (height *uint64, err } // GetL1MessageByIndex queries an L1 message by its index in the local database. -func (api *ScrollAPI) GetL1MessageByIndex(ctx context.Context, queueIndex uint64) (height *types.L1MessageTx, err error) { - return rawdb.ReadL1Message(api.eth.ChainDb(), queueIndex), nil +func (api *ScrollAPI) GetL1MessageByIndex(ctx context.Context, queueIndex uint64) (height *l1MessageTxRPC, err error) { + msg := rawdb.ReadL1Message(api.eth.ChainDb(), queueIndex) + if msg == nil { + return nil, nil + } + rpcMsg := l1MessageTxRPC{ + QueueIndex: msg.QueueIndex, + Gas: msg.Gas, + To: msg.To, + Value: (*hexutil.Big)(msg.Value), + Data: msg.Data, + Sender: msg.Sender, + Hash: types.NewTx(msg).Hash(), + } + return &rpcMsg, nil } // GetFirstQueueIndexNotInL2Block returns the first L1 message queue index that is diff --git a/params/version.go b/params/version.go index b765b8e71f..044c305da9 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 4 // Major version component of the current release VersionMinor = 2 // Minor version component of the current release - VersionPatch = 1 // Patch version component of the current release + VersionPatch = 2 // Patch version component of the current release VersionMeta = "sepolia" // Version metadata to append to the version string )