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

feat: Duplicate Withdrawal and move try from impls to rpc-compat #4186

Merged
merged 30 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
755ae30
duplicate withdrawal and move try_from impls to compat
supernovahs Aug 14, 2023
c40b84a
delete unwanted comments
supernovahs Aug 14, 2023
b82163c
fmt
supernovahs Aug 14, 2023
270960e
no need for pub withdrawal
supernovahs Aug 14, 2023
01c354a
add proptest as dep
supernovahs Aug 14, 2023
179a3fd
remove unused dep
supernovahs Aug 14, 2023
4ffdeba
add back deps
supernovahs Aug 14, 2023
734a9c4
add decodable
supernovahs Aug 14, 2023
e7e94cc
remove unused dep
supernovahs Aug 14, 2023
0c2227a
clippy
supernovahs Aug 14, 2023
ce1d3a2
lint
supernovahs Aug 14, 2023
d736a41
recommended changes excluding conversion
supernovahs Aug 15, 2023
3738f86
wip , moved impls to compat , 4 tests failing
supernovahs Aug 18, 2023
3f6a163
Merge branch 'main' into standalone_rpc_types
supernovahs Sep 14, 2023
3b1b68f
fix errors , tests working
supernovahs Sep 16, 2023
14afb7f
docs for functions
supernovahs Sep 16, 2023
a8280b5
doc for module
supernovahs Sep 16, 2023
c5f9406
payload docs
supernovahs Sep 16, 2023
e539396
remove unused dep
supernovahs Sep 16, 2023
0efb110
clean code and fix clippy
supernovahs Sep 16, 2023
9440d5e
fix errors
supernovahs Sep 16, 2023
1011361
clippy
supernovahs Sep 16, 2023
76499e9
clippy ..
supernovahs Sep 16, 2023
ed47088
Merge branch 'main' into standalone_rpc_types
supernovahs Sep 16, 2023
6c0d707
Merge branch 'paradigmxyz:main' into standalone_rpc_types
supernovahs Sep 18, 2023
39aaeeb
doc
supernovahs Sep 18, 2023
e49d5a5
Merge branch 'main' into standalone_rpc_types
supernovahs Sep 18, 2023
5fc02f7
fix new conflicts
supernovahs Sep 19, 2023
534a4dd
nits
supernovahs Sep 19, 2023
d9a5306
nits more
supernovahs Sep 19, 2023
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
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/consensus/beacon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ reth-rpc-types.workspace = true
reth-tasks.workspace = true
reth-payload-builder.workspace = true
reth-prune = { path = "../../prune" }

reth-rpc-types-compat.workspace = true
# async
tokio = { workspace = true, features = ["sync"] }
tokio-stream.workspace = true
Expand Down
26 changes: 15 additions & 11 deletions crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use reth_rpc_types::engine::{
CancunPayloadFields, ExecutionPayload, PayloadAttributes, PayloadError, PayloadStatus,
PayloadStatusEnum, PayloadValidationError,
};
use reth_rpc_types_compat::engine::payload::try_into_sealed_block;
use reth_stages::{ControlFlow, Pipeline, PipelineError};
use reth_tasks::TaskSpawner;
use std::{
Expand Down Expand Up @@ -1137,7 +1138,8 @@ where
cancun_fields: Option<CancunPayloadFields>,
) -> Result<SealedBlock, PayloadStatus> {
let parent_hash = payload.parent_hash();
let block = match payload.try_into_sealed_block(
let block = match try_into_sealed_block(
payload,
cancun_fields.as_ref().map(|fields| fields.parent_beacon_block_root),
) {
Ok(block) => block,
Expand Down Expand Up @@ -1838,9 +1840,8 @@ mod tests {
use assert_matches::assert_matches;
use reth_primitives::{stage::StageCheckpoint, ChainSpec, ChainSpecBuilder, H256, MAINNET};
use reth_provider::{BlockWriter, ProviderFactory};
use reth_rpc_types::engine::{
ExecutionPayloadV1, ForkchoiceState, ForkchoiceUpdated, PayloadStatus,
};
use reth_rpc_types::engine::{ForkchoiceState, ForkchoiceUpdated, PayloadStatus};
use reth_rpc_types_compat::engine::payload::try_block_to_payload_v1;
use reth_stages::{ExecOutput, PipelineError, StageError};
use std::{collections::VecDeque, sync::Arc, time::Duration};
use tokio::sync::oneshot::error::TryRecvError;
Expand Down Expand Up @@ -1900,7 +1901,8 @@ mod tests {
assert_matches!(rx.try_recv(), Err(TryRecvError::Empty));

// consensus engine is still idle because no FCUs were received
let _ = env.send_new_payload(ExecutionPayloadV1::from(SealedBlock::default()), None).await;
let _ = env.send_new_payload(try_block_to_payload_v1(SealedBlock::default()), None).await;

assert_matches!(rx.try_recv(), Err(TryRecvError::Empty));

// consensus engine is still idle because pruning is running
Expand Down Expand Up @@ -2022,7 +2024,6 @@ mod tests {
use reth_db::{tables, transaction::DbTxMut};
use reth_interfaces::test_utils::{generators, generators::random_block};
use reth_rpc_types::engine::ForkchoiceUpdateError;

#[tokio::test]
async fn empty_head() {
let chain_spec = Arc::new(
Expand Down Expand Up @@ -2316,20 +2317,22 @@ mod tests {
// Send new payload
let res = env
.send_new_payload(
ExecutionPayloadV1::from(random_block(&mut rng, 0, None, None, Some(0))),
try_block_to_payload_v1(random_block(&mut rng, 0, None, None, Some(0))),
None,
)
.await;

// Invalid, because this is a genesis block
assert_matches!(res, Ok(result) => assert_matches!(result.status, PayloadStatusEnum::Invalid { .. }));

// Send new payload
let res = env
.send_new_payload(
ExecutionPayloadV1::from(random_block(&mut rng, 1, None, None, Some(0))),
try_block_to_payload_v1(random_block(&mut rng, 1, None, None, Some(0))),
None,
)
.await;

let expected_result = PayloadStatus::from_status(PayloadStatusEnum::Syncing);
assert_matches!(res, Ok(result) => assert_eq!(result, expected_result));

Expand Down Expand Up @@ -2379,9 +2382,10 @@ mod tests {

// Send new payload
let result = env
.send_new_payload_retry_on_syncing(ExecutionPayloadV1::from(block2.clone()), None)
.send_new_payload_retry_on_syncing(try_block_to_payload_v1(block2.clone()), None)
.await
.unwrap();

let expected_result = PayloadStatus::from_status(PayloadStatusEnum::Valid)
.with_latest_valid_hash(block2.hash);
assert_eq!(result, expected_result);
Expand Down Expand Up @@ -2479,7 +2483,7 @@ mod tests {

// Send new payload
let block = random_block(&mut rng, 2, Some(H256::random()), None, Some(0));
let res = env.send_new_payload(ExecutionPayloadV1::from(block), None).await;
let res = env.send_new_payload(try_block_to_payload_v1(block), None).await;
let expected_result = PayloadStatus::from_status(PayloadStatusEnum::Syncing);
assert_matches!(res, Ok(result) => assert_eq!(result, expected_result));

Expand Down Expand Up @@ -2542,7 +2546,7 @@ mod tests {

// Send new payload
let result = env
.send_new_payload_retry_on_syncing(ExecutionPayloadV1::from(block2.clone()), None)
.send_new_payload_retry_on_syncing(try_block_to_payload_v1(block2.clone()), None)
.await
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions crates/payload/builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ reth-rlp.workspace = true
reth-transaction-pool.workspace = true
reth-interfaces.workspace = true
reth-revm-primitives = { path = "../../revm/revm-primitives" }
reth-rpc-types-compat.workspace = true

## ethereum
revm-primitives.workspace = true
Expand Down
26 changes: 21 additions & 5 deletions crates/payload/builder/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ use reth_rpc_types::engine::{
ExecutionPayloadEnvelopeV2, ExecutionPayloadEnvelopeV3, ExecutionPayloadV1, PayloadAttributes,
PayloadId,
};
use reth_rpc_types_compat::engine::payload::{
convert_block_to_payload_field_v2, convert_standalonewithdraw_to_withdrawal,
try_block_to_payload_v1, try_block_to_payload_v3,
};
use revm_primitives::{BlockEnv, CfgEnv};

/// Contains the built payload.
///
/// According to the [engine API specification](https://github.com/ethereum/execution-apis/blob/main/src/engine/README.md) the execution layer should build the initial version of the payload with an empty transaction set and then keep update it in order to maximize the revenue.
Expand Down Expand Up @@ -76,7 +79,7 @@ impl BuiltPayload {
// V1 engine_getPayloadV1 response
impl From<BuiltPayload> for ExecutionPayloadV1 {
fn from(value: BuiltPayload) -> Self {
value.block.into()
try_block_to_payload_v1(value.block)
}
}

Expand All @@ -85,7 +88,10 @@ impl From<BuiltPayload> for ExecutionPayloadEnvelopeV2 {
fn from(value: BuiltPayload) -> Self {
let BuiltPayload { block, fees, .. } = value;

ExecutionPayloadEnvelopeV2 { block_value: fees, execution_payload: block.into() }
ExecutionPayloadEnvelopeV2 {
block_value: fees,
execution_payload: convert_block_to_payload_field_v2(block),
}
}
}

Expand All @@ -94,7 +100,7 @@ impl From<BuiltPayload> for ExecutionPayloadEnvelopeV3 {
let BuiltPayload { block, fees, sidecars, .. } = value;

ExecutionPayloadEnvelopeV3 {
execution_payload: block.into(),
execution_payload: try_block_to_payload_v3(block),
block_value: fees,
// From the engine API spec:
//
Expand Down Expand Up @@ -137,13 +143,23 @@ impl PayloadBuilderAttributes {
/// Derives the unique [PayloadId] for the given parent and attributes
pub fn new(parent: H256, attributes: PayloadAttributes) -> Self {
let id = payload_id(&parent, &attributes);

let withdraw = attributes.withdrawals.map(
|withdrawals: Vec<reth_rpc_types::engine::payload::Withdrawal>| {
withdrawals
.into_iter()
.map(convert_standalonewithdraw_to_withdrawal) // Removed the parentheses here
.collect::<Vec<_>>()
},
);

Self {
id,
parent,
timestamp: attributes.timestamp.as_u64(),
suggested_fee_recipient: attributes.suggested_fee_recipient,
prev_randao: attributes.prev_randao,
withdrawals: attributes.withdrawals.unwrap_or_default(),
withdrawals: withdraw.unwrap_or_default(),
parent_beacon_block_root: attributes.parent_beacon_block_root,
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/rpc-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ reth-rpc-engine-api = { path = "../rpc-engine-api" }
reth-rpc-types.workspace = true
reth-tasks.workspace = true
reth-transaction-pool.workspace = true
reth-rpc-types-compat.workspace = true

# rpc/net
jsonrpsee = { workspace = true, features = ["server"] }
Expand Down
8 changes: 5 additions & 3 deletions crates/rpc/rpc-builder/tests/it/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ use reth_primitives::Block;
use reth_rpc::JwtSecret;
use reth_rpc_api::clients::EngineApiClient;
use reth_rpc_types::engine::{ForkchoiceState, PayloadId, TransitionConfiguration};

use reth_rpc_types_compat::engine::payload::{
convert_block_to_payload_input_v2, try_block_to_payload_v1,
};
#[allow(unused_must_use)]
async fn test_basic_engine_calls<C>(client: &C)
where
C: ClientT + SubscriptionClientT + Sync,
{
let block = Block::default().seal_slow();
EngineApiClient::new_payload_v1(client, block.clone().into()).await;
EngineApiClient::new_payload_v2(client, block.into()).await;
EngineApiClient::new_payload_v1(client, try_block_to_payload_v1(block.clone())).await;
EngineApiClient::new_payload_v2(client, convert_block_to_payload_input_v2(block)).await;
EngineApiClient::fork_choice_updated_v1(client, ForkchoiceState::default(), None).await;
EngineApiClient::get_payload_v1(client, PayloadId::new([0, 0, 0, 0, 0, 0, 0, 0])).await;
EngineApiClient::get_payload_v2(client, PayloadId::new([0, 0, 0, 0, 0, 0, 0, 0])).await;
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-engine-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ reth-rpc-api = { path = "../rpc-api" }
reth-beacon-consensus = { path = "../../consensus/beacon" }
reth-payload-builder.workspace = true
reth-tasks.workspace = true

reth-rpc-types-compat.workspace = true
# async
tokio = { workspace = true, features = ["sync"] }

Expand Down
20 changes: 13 additions & 7 deletions crates/rpc/rpc-engine-api/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ use reth_rpc_types::engine::{
ForkchoiceUpdated, PayloadAttributes, PayloadId, PayloadStatus, TransitionConfiguration,
CAPABILITIES,
};
use reth_rpc_types_compat::engine::payload::{
convert_payload_input_v2_to_payload, convert_to_payload_body_v1,
};
use reth_tasks::TaskSpawner;
use std::sync::Arc;
use tokio::sync::oneshot;
Expand Down Expand Up @@ -84,7 +87,7 @@ where
&self,
payload: ExecutionPayloadInputV2,
) -> EngineApiResult<PayloadStatus> {
let payload = ExecutionPayload::from(payload);
let payload = convert_payload_input_v2_to_payload(payload);
let payload_or_attrs = PayloadOrAttributes::from_execution_payload(&payload, None);
self.validate_version_specific_fields(EngineApiMessageVersion::V2, &payload_or_attrs)?;
Ok(self.inner.beacon_consensus.new_payload(payload, None).await?)
Expand Down Expand Up @@ -280,7 +283,7 @@ where
let block_result = inner.provider.block(BlockHashOrNumber::Number(num));
match block_result {
Ok(block) => {
result.push(block.map(Into::into));
result.push(block.map(convert_to_payload_body_v1));
}
Err(err) => {
tx.send(Err(EngineApiError::Internal(Box::new(err)))).ok();
Expand Down Expand Up @@ -311,7 +314,7 @@ where
.provider
.block(BlockHashOrNumber::Hash(hash))
.map_err(|err| EngineApiError::Internal(Box::new(err)))?;
result.push(block.map(Into::into));
result.push(block.map(convert_to_payload_body_v1));
}

Ok(result)
Expand Down Expand Up @@ -836,8 +839,11 @@ mod tests {
random_block_range(&mut rng, start..=start + count - 1, H256::default(), 0..2);
handle.provider.extend_blocks(blocks.iter().cloned().map(|b| (b.hash(), b.unseal())));

let expected =
blocks.iter().cloned().map(|b| Some(b.unseal().into())).collect::<Vec<_>>();
let expected = blocks
.iter()
.cloned()
.map(|b| Some(convert_to_payload_body_v1(b.unseal())))
.collect::<Vec<_>>();

let res = api.get_payload_bodies_by_range(start, count).await.unwrap();
assert_eq!(res, expected);
Expand Down Expand Up @@ -875,7 +881,7 @@ mod tests {
if first_missing_range.contains(&b.number) {
None
} else {
Some(b.unseal().into())
Some(convert_to_payload_body_v1(b.unseal()))
}
})
.collect::<Vec<_>>();
Expand All @@ -894,7 +900,7 @@ mod tests {
{
None
} else {
Some(b.unseal().into())
Some(convert_to_payload_body_v1(b.unseal()))
}
})
.collect::<Vec<_>>();
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/rpc-engine-api/src/payload.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use reth_primitives::{Withdrawal, H256};
use reth_rpc_types::engine::{ExecutionPayload, PayloadAttributes};
use reth_primitives::H256;

use reth_rpc_types::engine::{ExecutionPayload, PayloadAttributes};
supernovahs marked this conversation as resolved.
Show resolved Hide resolved
/// Either an [ExecutionPayload] or a [PayloadAttributes].
pub(crate) enum PayloadOrAttributes<'a> {
/// An [ExecutionPayload] and optional parent beacon block root.
Expand All @@ -25,7 +25,7 @@ impl<'a> PayloadOrAttributes<'a> {
}

/// Return the withdrawals for the payload or attributes.
pub(crate) fn withdrawals(&self) -> Option<&Vec<Withdrawal>> {
pub(crate) fn withdrawals(&self) -> Option<&Vec<reth_rpc_types::engine::payload::Withdrawal>> {
match self {
Self::ExecutionPayload { payload, .. } => payload.withdrawals(),
Self::PayloadAttributes(attributes) => attributes.withdrawals.as_ref(),
Expand Down
Loading
Loading