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

Changes to enable validation api extension #4783

Conversation

ckoopmann
Copy link
Contributor

@ckoopmann ckoopmann commented Sep 26, 2023

These are some changes that I did to enable a specific rpc extension for validating builder payloads, see:
ultrasoundmoney/reth-payload-validator#1
as well as:
ultrasoundmoney#5

The changes I had to do where:

  1. Re-export reth-rpc-types-compat to get access to try_into_sealed_block see here

  2. Re-export reth-consensus-common to get access to full_validation see here

  3. Export ExecutionPayloadV1, ExecutionPayloadV2 to implement a method that converts from my struct class into the ExecutionPayload type (necessary because of some different formatting in our api). see here

  4. Re-export reth_rpc::result to convert a RethResult to an RPC Result and add aditional implementations of map_ok_or_rpc_error. see here

  5. Add AccountReader trait in a few places since full_validation requires it.

I am also more than open to alternatives to using the above mentioned methods / datatypes in case those were intentionally not include din the library api.

Copy link
Member

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AccountReader trait bound is unnecessary since you already have StateProviderFactory. if you want to get latest account information, correct usage would be provider.latest()?.basic_account(address)

@rkrasiuk rkrasiuk added C-debt A clean up/refactor of existing code A-rpc Related to the RPC implementation A-cli Related to the reth CLI labels Sep 26, 2023
@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

Merging #4783 (6e2a642) into main (05198e9) will decrease coverage by 0.05%.
The diff coverage is 0.00%.

Impacted file tree graph

Files Coverage Δ
bin/reth/src/cli/ext.rs 6.73% <0.00%> (-0.07%) ⬇️
crates/rpc/rpc/src/result.rs 59.00% <0.00%> (-0.60%) ⬇️
bin/reth/src/args/rpc_server_args.rs 55.75% <0.00%> (-0.29%) ⬇️
crates/rpc/rpc-builder/src/lib.rs 63.75% <0.00%> (-0.13%) ⬇️
crates/storage/provider/src/providers/mod.rs 18.28% <0.00%> (-0.13%) ⬇️

... and 11 files with indirect coverage changes

Flag Coverage Δ
integration-tests 15.50% <0.00%> (-0.01%) ⬇️
unit-tests 62.58% <0.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 32.27% <0.00%> (-0.02%) ⬇️
blockchain tree 80.44% <ø> (ø)
pipeline 88.43% <ø> (-0.02%) ⬇️
storage (db) 73.29% <0.00%> (-0.02%) ⬇️
trie 94.48% <ø> (-0.04%) ⬇️
txpool 49.03% <ø> (-0.48%) ⬇️
networking 76.16% <ø> (-0.03%) ⬇️
rpc 57.78% <0.00%> (-0.03%) ⬇️
consensus 61.06% <ø> (ø)
revm 28.53% <ø> (ø)
payload builder 8.16% <ø> (ø)
primitives 85.23% <ø> (-0.04%) ⬇️

@ckoopmann
Copy link
Contributor Author

Thanks for the suggestion, Good point.
I'm trying to use the provider as an input to the full_validation function though, which requires this Trait.

So the alternative would be to reimplement / rewrite that function if I don't add the AccountReader interface ?🤔

@rkrasiuk
Copy link
Member

i see, fair enough. @ckoopmann pls fix the failing docs check

@ckoopmann
Copy link
Contributor Author

i see, fair enough. @ckoopmann pls fix the failing docs check

Should be fixed now (passing locally). Please re-approve ci run🙏

@ckoopmann ckoopmann force-pushed the changes-to-enable-validation-api-extension branch from 0f3147b to 01789de Compare September 27, 2023 11:05
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smol nits

bin/reth/src/lib.rs Outdated Show resolved Hide resolved
@@ -105,7 +106,7 @@ impl_to_rpc_result!(reth_interfaces::RethError);
impl_to_rpc_result!(reth_network_api::NetworkError);

/// An extension to used to apply error conversions to various result types
pub(crate) trait ToRpcResultExt {
pub trait ToRpcResultExt {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with making this pub

Copy link
Contributor Author

@ckoopmann ckoopmann Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not using this trait anymore in my specific use case. Instead I made the (more useful) ToRpcResult trait public:
f672f19

Therefore I removed the above change and kept the ...Ext trait crate internal.

Comment on lines 129 to 138
impl ToRpcResultExt for RethResult<()> {
type Ok = ();

fn map_ok_or_rpc_err(self) -> RpcResult<<Self as ToRpcResultExt>::Ok> {
match self {
Ok(()) => Ok(()),
Err(err) => Err(internal_rpc_err(err.to_string())),
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is very useful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in favour of ToRpcResult implementation:
f0247ad

Comment on lines 140 to 149
impl ToRpcResultExt for Result<SealedBlock, PayloadError> {
type Ok = SealedBlock;

fn map_ok_or_rpc_err(self) -> RpcResult<<Self as ToRpcResultExt>::Ok> {
match self {
Ok(block) => Ok(block),
Err(err) => Err(internal_rpc_err(err.to_string())),
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, we probably want

impl_to_rpc_result!(PayloadError);

here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done:
f0247ad

@mattsse mattsse added the M-changelog This change should be included in the changelog label Sep 28, 2023
@mattsse mattsse enabled auto-merge September 28, 2023 15:39
@ckoopmann ckoopmann requested a review from rkrasiuk September 29, 2023 01:25
@mattsse mattsse disabled auto-merge September 30, 2023 11:53
@mattsse mattsse enabled auto-merge September 30, 2023 11:53
@mattsse mattsse disabled auto-merge September 30, 2023 11:54
@mattsse
Copy link
Collaborator

mattsse commented Sep 30, 2023

@ckoopmann please resolve conflicts, unable to push manually to this branch

@ckoopmann ckoopmann force-pushed the changes-to-enable-validation-api-extension branch from 4f352f9 to 6e2a642 Compare September 30, 2023 12:20
@ckoopmann
Copy link
Contributor Author

@ckoopmann please resolve conflicts, unable to push manually to this branch

Resolved conflicts in rebase onto latest main.

@mattsse mattsse added this pull request to the merge queue Sep 30, 2023
Merged via the queue into paradigmxyz:main with commit fd697d9 Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Related to the reth CLI A-rpc Related to the RPC implementation C-debt A clean up/refactor of existing code M-changelog This change should be included in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants