From c2f28133857cb4cc7496b8dbe442cfb3cb5227ad Mon Sep 17 00:00:00 2001 From: ethDreamer <37123614+ethDreamer@users.noreply.github.com> Date: Mon, 29 Nov 2021 18:56:49 -0600 Subject: [PATCH] Cleanup Comments & Fix get_pow_block_hash_at_ttd() (#2835) --- .../execution_layer/src/engine_api/http.rs | 26 +--------------- beacon_node/execution_layer/src/lib.rs | 31 +++++++++---------- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/beacon_node/execution_layer/src/engine_api/http.rs b/beacon_node/execution_layer/src/engine_api/http.rs index 51e0e123c..c4e7a71ae 100644 --- a/beacon_node/execution_layer/src/engine_api/http.rs +++ b/beacon_node/execution_layer/src/engine_api/http.rs @@ -624,18 +624,6 @@ mod test { .await .with_preloaded_responses( // engine_forkchoiceUpdatedV1 (prepare payload) RESPONSE validation - // - // NOTE THIS HAD TO BE MODIFIED FROM ORIGINAL RESPONSE - // { - // "jsonrpc":"2.0", - // "id":67, - // "result":{ - // "status":"VALID", // <- This must be SUCCESS - // "payloadId":"0xa247243752eb10b4" - // } - // } - // see spec for engine_forkchoiceUpdatedV1 response: - // https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.4/src/engine/specification.md#response-1 vec![json!({ "id": STATIC_ID, "jsonrpc": JSONRPC_VERSION, @@ -779,18 +767,6 @@ mod test { .await .with_preloaded_responses( // engine_executePayloadV1 RESPONSE validation - // - // NOTE THIS HAD TO BE MODIFIED FROM ORIGINAL RESPONSE - // { - // "jsonrpc":"2.0", - // "id":67, - // "result":{ - // "status":"SUCCESS", // <- This must be VALID - // "latestValidHash":"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858" - // } - // } - // see spec for engine_executePayloadV1 response: - // https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.4/src/engine/specification.md#response vec![json!({ "jsonrpc": JSONRPC_VERSION, "id": STATIC_ID, @@ -852,7 +828,7 @@ mod test { "id": STATIC_ID, "result": { "status":"SUCCESS", - "payloadId": serde_json::Value::Null + "payloadId": JSON_NULL, } })], |client| async move { diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index e322b815e..ec5d7e826 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -530,24 +530,23 @@ impl ExecutionLayer { // this implementation becomes canonical. loop { let block_reached_ttd = block.total_difficulty >= spec.terminal_total_difficulty; - if block_reached_ttd && block.parent_hash == Hash256::zero() { - return Ok(Some(block.block_hash)); - } else if block.parent_hash == Hash256::zero() { - // The end of the chain has been reached without finding the TTD, there is no - // terminal block. - return Ok(None); - } + if block_reached_ttd { + if block.parent_hash == Hash256::zero() { + return Ok(Some(block.block_hash)); + } + let parent = self + .get_pow_block(engine, block.parent_hash) + .await? + .ok_or(ApiError::ExecutionBlockNotFound(block.parent_hash))?; + let parent_reached_ttd = parent.total_difficulty >= spec.terminal_total_difficulty; - let parent = self - .get_pow_block(engine, block.parent_hash) - .await? - .ok_or(ApiError::ExecutionBlockNotFound(block.parent_hash))?; - let parent_reached_ttd = parent.total_difficulty >= spec.terminal_total_difficulty; - - if block_reached_ttd && !parent_reached_ttd { - return Ok(Some(block.block_hash)); + if block_reached_ttd && !parent_reached_ttd { + return Ok(Some(block.block_hash)); + } else { + block = parent; + } } else { - block = parent; + return Ok(None); } } }