From 93a5a1488a773d4f04d23d2b7ff535f949b8526d Mon Sep 17 00:00:00 2001 From: Jihoon Song Date: Sun, 19 Jan 2025 14:32:34 +0900 Subject: [PATCH] beacon/engine, eth/catalyst, miner: use primitive type instead of new structures --- beacon/engine/types.go | 18 ++++-------------- eth/catalyst/api.go | 24 +++++++++--------------- eth/catalyst/api_test.go | 4 ++-- eth/catalyst/queue.go | 6 +++--- miner/inclusion_list_building.go | 2 +- miner/inclusion_list_building_test.go | 2 +- 6 files changed, 20 insertions(+), 36 deletions(-) diff --git a/beacon/engine/types.go b/beacon/engine/types.go index 622052b219..1e2fbb5e20 100644 --- a/beacon/engine/types.go +++ b/beacon/engine/types.go @@ -132,14 +132,6 @@ type executionPayloadEnvelopeMarshaling struct { // Max size of inclusion list in bytes. const MaxBytesPerInclusionList = uint64(8192) -type InclusionListV1 struct { - Transactions [][]byte `json:"transactions" gencodec:"required"` -} - -type UpdateInclusionListResponse struct { - PayloadID *PayloadID `json:"payloadId"` -} - type PayloadStatusV1 struct { Status string `json:"status"` Witness *hexutil.Bytes `json:"witness"` @@ -355,8 +347,8 @@ func BlockToExecutableData(block *types.Block, fees *big.Int, sidecars []*types. } } -func InclusionListToTransactions(inclusionList *InclusionListV1) ([]*types.Transaction, error) { - txs, err := decodeTransactions(inclusionList.Transactions) +func InclusionListToTransactions(inclusionList [][]byte) ([]*types.Transaction, error) { + txs, err := decodeTransactions(inclusionList) if err != nil { return nil, err } @@ -364,10 +356,8 @@ func InclusionListToTransactions(inclusionList *InclusionListV1) ([]*types.Trans return txs, nil } -func TransactionsToInclusionList(txs []*types.Transaction) *InclusionListV1 { - return &InclusionListV1{ - Transactions: encodeTransactions(txs), - } +func TransactionsToInclusionList(txs []*types.Transaction) [][]byte { + return encodeTransactions(txs) } // ExecutionPayloadBody is used in the response to GetPayloadBodiesByHash and GetPayloadBodiesByRange diff --git a/eth/catalyst/api.go b/eth/catalyst/api.go index ff0be0805a..af0192f855 100644 --- a/eth/catalyst/api.go +++ b/eth/catalyst/api.go @@ -562,7 +562,7 @@ func (api *ConsensusAPI) GetBlobsV1(hashes []common.Hash) ([]*engine.BlobAndProo return res, nil } -func (api *ConsensusAPI) GetInclusionListV1(parentHash common.Hash) (*engine.InclusionListV1, error) { +func (api *ConsensusAPI) GetInclusionListV1(parentHash common.Hash) ([][]byte, error) { if inclusionList := api.localInclusionLists.get(parentHash); inclusionList != nil { return inclusionList, nil } @@ -581,26 +581,20 @@ func (api *ConsensusAPI) GetInclusionListV1(parentHash common.Hash) (*engine.Inc return inclusionList, nil } -func (api *ConsensusAPI) UpdatePayloadWithInclusionListV1(payloadID engine.PayloadID, inclusionList engine.InclusionListV1) (engine.UpdateInclusionListResponse, error) { - response := func(id *engine.PayloadID) engine.UpdateInclusionListResponse { - return engine.UpdateInclusionListResponse{ - PayloadID: id, - } - } - +func (api *ConsensusAPI) UpdatePayloadWithInclusionListV1(payloadID engine.PayloadID, inclusionList [][]byte) (*engine.PayloadID, error) { payload := api.localBlocks.peak(payloadID) if payload == nil { - return engine.UpdateInclusionListResponse{PayloadID: nil}, engine.UnknownPayload + return nil, engine.UnknownPayload } - inclusionListTxs, err := engine.InclusionListToTransactions(&inclusionList) + inclusionListTxs, err := engine.InclusionListToTransactions(inclusionList) if err != nil { - return engine.UpdateInclusionListResponse{PayloadID: nil}, err + return nil, err } payload.UpdateWithInclusionList(inclusionListTxs) - return response(&payloadID), nil + return &payloadID, nil } // NewPayloadV1 creates an Eth1 block, inserts it in the chain, and returns the status of the chain. @@ -692,7 +686,7 @@ func (api *ConsensusAPI) NewPayloadV4(params engine.ExecutableData, versionedHas } // NewPayloadV5 creates an Eth1 block, inserts it in the chain, and returns the status of the chain. -func (api *ConsensusAPI) NewPayloadV5(params engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash, executionRequests []hexutil.Bytes, inclusionList *engine.InclusionListV1) (engine.PayloadStatusV1, error) { +func (api *ConsensusAPI) NewPayloadV5(params engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash, executionRequests []hexutil.Bytes, inclusionList [][]byte) (engine.PayloadStatusV1, error) { if params.Withdrawals == nil { return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil withdrawals post-shanghai")) } @@ -814,7 +808,7 @@ func (api *ConsensusAPI) NewPayloadWithWitnessV4(params engine.ExecutableData, v // NewPayloadWithWitnessV5 is analogous to NewPayloadV5, only it also generates // and returns a stateless witness after running the payload. -func (api *ConsensusAPI) NewPayloadWithWitnessV5(params engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash, executionRequests []hexutil.Bytes, inclusionList *engine.InclusionListV1) (engine.PayloadStatusV1, error) { +func (api *ConsensusAPI) NewPayloadWithWitnessV5(params engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash, executionRequests []hexutil.Bytes, inclusionList [][]byte) (engine.PayloadStatusV1, error) { if params.Withdrawals == nil { return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("nil withdrawals post-shanghai")) } @@ -934,7 +928,7 @@ func (api *ConsensusAPI) ExecuteStatelessPayloadV4(params engine.ExecutableData, return api.executeStatelessPayload(params, versionedHashes, beaconRoot, requests, opaqueWitness) } -func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash, requests [][]byte, inclusionList *engine.InclusionListV1, witness bool) (engine.PayloadStatusV1, error) { +func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash, requests [][]byte, inclusionList [][]byte, witness bool) (engine.PayloadStatusV1, error) { // The locking here is, strictly, not required. Without these locks, this can happen: // // 1. NewPayload( execdata-N ) is invoked from the CL. It goes all the way down to diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index c509717253..7ab7ed922f 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -1869,7 +1869,7 @@ func TestInclusionList(t *testing.T) { for i, tt := range []*struct { name string - inclusionList *engine.InclusionListV1 + inclusionList [][]byte updateInclusionList bool expectedTransactions int expectedStatus string @@ -1934,7 +1934,7 @@ func TestInclusionList(t *testing.T) { if tt.updateInclusionList { // Update the payload with the inclusion list. - api.UpdatePayloadWithInclusionListV1(*resp.PayloadID, *tt.inclusionList) + api.UpdatePayloadWithInclusionListV1(*resp.PayloadID, tt.inclusionList) } // Get the payload. diff --git a/eth/catalyst/queue.go b/eth/catalyst/queue.go index 9fd8be63f2..1a6dc7d6a8 100644 --- a/eth/catalyst/queue.go +++ b/eth/catalyst/queue.go @@ -181,7 +181,7 @@ func (q *headerQueue) get(hash common.Hash) *types.Header { // or evicted. type inclusionListQueueItem struct { parentHash common.Hash - inclusionList *engine.InclusionListV1 + inclusionList [][]byte } // inclusionListQueue tracks the latest handful of constructed inclusion lists to be retrieved @@ -201,7 +201,7 @@ func newInclusionListQueue() *inclusionListQueue { // put inserts a new inclusion list into the queue at the given parent hash that // the inclusion list is built upon. -func (q *inclusionListQueue) put(parentHash common.Hash, inclusionList *engine.InclusionListV1) { +func (q *inclusionListQueue) put(parentHash common.Hash, inclusionList [][]byte) { q.lock.Lock() defer q.lock.Unlock() @@ -213,7 +213,7 @@ func (q *inclusionListQueue) put(parentHash common.Hash, inclusionList *engine.I } // get retrieves a previously stored inclusion list item or nil if it does not exist. -func (q *inclusionListQueue) get(parentHash common.Hash) *engine.InclusionListV1 { +func (q *inclusionListQueue) get(parentHash common.Hash) [][]byte { q.lock.RLock() defer q.lock.RUnlock() diff --git a/miner/inclusion_list_building.go b/miner/inclusion_list_building.go index e432f25b4c..43e3541cff 100644 --- a/miner/inclusion_list_building.go +++ b/miner/inclusion_list_building.go @@ -13,7 +13,7 @@ type BuildInclusionListArgs struct { Parent common.Hash // The parent block to build inclusion list on top } -func (miner *Miner) BuildInclusionList(args *BuildInclusionListArgs) (*engine.InclusionListV1, error) { +func (miner *Miner) BuildInclusionList(args *BuildInclusionListArgs) ([][]byte, error) { params := &generateParams{ timestamp: uint64(time.Now().Unix()), forceTime: false, diff --git a/miner/inclusion_list_building_test.go b/miner/inclusion_list_building_test.go index 4c1ba89703..241151614b 100644 --- a/miner/inclusion_list_building_test.go +++ b/miner/inclusion_list_building_test.go @@ -114,7 +114,7 @@ func TestBuildInclusionList(t *testing.T) { // Verify inclusion list size. inclusionListSize := uint64(0) - for _, tx := range inclusionList.Transactions { + for _, tx := range inclusionList { inclusionListSize += uint64(len(tx)) } require.LessOrEqual(t, inclusionListSize, engine.MaxBytesPerInclusionList)