Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Comments & Fix get_pow_block_hash_at_ttd() #2835

Merged
merged 1 commit into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
33 changes: 16 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,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);
}

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