Skip to content

Commit

Permalink
Cleanup Comments & Fix get_pow_block_hash_at_ttd()
Browse files Browse the repository at this point in the history
  • Loading branch information
ethDreamer committed Nov 29, 2021
1 parent 7b95b72 commit 53f9e97
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 42 deletions.
26 changes: 1 addition & 25 deletions beacon_node/execution_layer/src/engine_api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -852,7 +828,7 @@ mod test {
"id": STATIC_ID,
"result": {
"status":"SUCCESS",
"payloadId": serde_json::Value::Null
"payloadId": JSON_NULL,
}
})],
|client| async move {
Expand Down
34 changes: 17 additions & 17 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,24 +530,24 @@ 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;

if block_reached_ttd && !parent_reached_ttd {
return Ok(Some(block.block_hash));
} else {
block = parent;
}
}

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));
} else {
block = parent;
else {
return Ok(None);
}
}
}
Expand Down

0 comments on commit 53f9e97

Please sign in to comment.