@@ -21,6 +21,7 @@ import (
2121 "crypto/sha256"
2222 "encoding/binary"
2323 "fmt"
24+
2425 "github.com/ethereum/go-ethereum/common"
2526 "github.com/ethereum/go-ethereum/core/beacon"
2627 "github.com/ethereum/go-ethereum/core/types"
@@ -74,38 +75,42 @@ func NewConsensusAPI(eth *eth.Ethereum) *ConsensusAPI {
7475func (api * ConsensusAPI ) ForkchoiceUpdatedV1 (heads beacon.ForkchoiceStateV1 , payloadAttributes * beacon.PayloadAttributesV1 ) (beacon.ForkChoiceResponse , error ) {
7576 log .Trace ("Engine API request received" , "method" , "ForkChoiceUpdated" , "head" , heads .HeadBlockHash , "finalized" , heads .FinalizedBlockHash , "safe" , heads .SafeBlockHash )
7677 if heads .HeadBlockHash == (common.Hash {}) {
77- return beacon.ForkChoiceResponse { Status : beacon . SUCCESS . Status , PayloadID : nil } , nil
78+ return beacon .STATUS_SUCCESS , nil
7879 }
7980 if err := api .checkTerminalTotalDifficulty (heads .HeadBlockHash ); err != nil {
8081 if block := api .eth .BlockChain ().GetBlockByHash (heads .HeadBlockHash ); block == nil {
8182 // TODO (MariusVanDerWijden) trigger sync
82- return beacon .SYNCING , nil
83+ return beacon .STATUS_SYNCING , nil
8384 }
84- return beacon .INVALID , err
85+ return beacon.ForkChoiceResponse { PayloadStatus : api . invalid ( err )}, nil
8586 }
8687 // If the finalized block is set, check if it is in our blockchain
8788 if heads .FinalizedBlockHash != (common.Hash {}) {
8889 if block := api .eth .BlockChain ().GetBlockByHash (heads .FinalizedBlockHash ); block == nil {
8990 // TODO (MariusVanDerWijden) trigger sync
90- return beacon .SYNCING , nil
91+ return beacon .STATUS_SYNCING , nil
9192 }
9293 }
94+ if block := api .eth .BlockChain ().GetBlockByHash (heads .HeadBlockHash ); block == nil {
95+ // TODO (MariusVanDerWijden) trigger sync
96+ return beacon .STATUS_SYNCING , nil
97+ }
9398 // SetHead
9499 if err := api .setHead (heads .HeadBlockHash ); err != nil {
95- return beacon .INVALID , err
100+ return beacon.ForkChoiceResponse { PayloadStatus : api . invalid ( err )}, nil
96101 }
97102 // Assemble block (if needed). It only works for full node.
98103 if payloadAttributes != nil {
99104 data , err := api .assembleBlock (heads .HeadBlockHash , payloadAttributes )
100105 if err != nil {
101- return beacon .INVALID , err
106+ return beacon .STATUS_INVALID , err
102107 }
103108 id := computePayloadId (heads .HeadBlockHash , payloadAttributes )
104109 api .preparedBlocks .put (id , data )
105110 log .Info ("Created payload" , "payloadID" , id )
106- return beacon.ForkChoiceResponse {Status : beacon .SUCCESS . Status , PayloadID : & id }, nil
111+ return beacon.ForkChoiceResponse {PayloadStatus : beacon.PayloadStatusV1 { Status : beacon . VALID } , PayloadID : & id }, nil
107112 }
108- return beacon.ForkChoiceResponse { Status : beacon . SUCCESS . Status , PayloadID : nil } , nil
113+ return beacon .STATUS_SUCCESS , nil
109114}
110115
111116// GetPayloadV1 returns a cached payload by id.
@@ -118,38 +123,39 @@ func (api *ConsensusAPI) GetPayloadV1(payloadID beacon.PayloadID) (*beacon.Execu
118123 return data , nil
119124}
120125
121- // ExecutePayloadV1 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
122- func (api * ConsensusAPI ) ExecutePayloadV1 (params beacon.ExecutableDataV1 ) (beacon.ExecutePayloadResponse , error ) {
126+ // NewPayloadV1 creates an Eth1 block, inserts it in the chain, and returns the status of the chain.
127+ func (api * ConsensusAPI ) NewPayloadV1 (params beacon.ExecutableDataV1 ) (beacon.PayloadStatusV1 , error ) {
123128 log .Trace ("Engine API request received" , "method" , "ExecutePayload" , params .BlockHash , "number" , params .Number )
124129 block , err := beacon .ExecutableDataToBlock (params )
125130 if err != nil {
126- return api . invalid (), err
131+ return beacon. PayloadStatusV1 { Status : beacon . INVALIDBLOCKHASH }, nil
127132 }
128133 if ! api .eth .BlockChain ().HasBlock (block .ParentHash (), block .NumberU64 ()- 1 ) {
129134 /*
130- TODO (MariusVanDerWijden) reenable once sync is merged
135+ TODO (MariusVanDerWijden) maybe reenable once sync is merged
131136 if err := api.eth.Downloader().BeaconSync(api.eth.SyncMode(), block.Header()); err != nil {
132137 return SYNCING, err
133138 }
134139 */
135140 // TODO (MariusVanDerWijden) we should return nil here not empty hash
136- return beacon.ExecutePayloadResponse {Status : beacon .SYNCING . Status , LatestValidHash : common. Hash {} }, nil
141+ return beacon.PayloadStatusV1 {Status : beacon .ACCEPTED }, nil
137142 }
138143 parent := api .eth .BlockChain ().GetBlockByHash (params .ParentHash )
139144 td := api .eth .BlockChain ().GetTd (parent .Hash (), block .NumberU64 ()- 1 )
140145 ttd := api .eth .BlockChain ().Config ().TerminalTotalDifficulty
141146 if td .Cmp (ttd ) < 0 {
142- return api .invalid (), fmt .Errorf ("can not execute payload on top of block with low td got: %v threshold %v" , td , ttd )
147+ err := fmt .Errorf ("can not execute payload on top of block with low td got: %v threshold %v" , td , ttd )
148+ return api .invalid (err ), nil
143149 }
144150 log .Trace ("Inserting block without head" , "hash" , block .Hash (), "number" , block .Number )
145151 if err := api .eth .BlockChain ().InsertBlockWithoutSetHead (block ); err != nil {
146- return api .invalid (), err
152+ return api .invalid (err ), nil
147153 }
148154
149155 if merger := api .eth .Merger (); ! merger .TDDReached () {
150156 merger .ReachTTD ()
151157 }
152- return beacon.ExecutePayloadResponse {Status : beacon .VALID . Status , LatestValidHash : block .Hash ()}, nil
158+ return beacon.PayloadStatusV1 {Status : beacon .VALID , LatestValidHash : block .Hash ()}, nil
153159}
154160
155161// computePayloadId computes a pseudo-random payloadid, based on the parameters.
@@ -166,8 +172,8 @@ func computePayloadId(headBlockHash common.Hash, params *beacon.PayloadAttribute
166172}
167173
168174// invalid returns a response "INVALID" with the latest valid hash set to the current head.
169- func (api * ConsensusAPI ) invalid () beacon.ExecutePayloadResponse {
170- return beacon.ExecutePayloadResponse {Status : beacon .INVALID . Status , LatestValidHash : api .eth .BlockChain ().CurrentHeader ().Hash ()}
175+ func (api * ConsensusAPI ) invalid (err error ) beacon.PayloadStatusV1 {
176+ return beacon.PayloadStatusV1 {Status : beacon .INVALID , LatestValidHash : api .eth .BlockChain ().CurrentHeader ().Hash (), ValidationError : err . Error ()}
171177}
172178
173179// assembleBlock creates a new block and returns the "execution
0 commit comments