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

Add support for Otterscan JSON-RPC API extensions #3726

Open
8 of 12 tasks
ZePedroResende opened this issue Jul 11, 2023 · 11 comments
Open
8 of 12 tasks

Add support for Otterscan JSON-RPC API extensions #3726

ZePedroResende opened this issue Jul 11, 2023 · 11 comments
Assignees
Labels
A-rpc Related to the RPC implementation C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started

Comments

@ZePedroResende
Copy link
Contributor

ZePedroResende commented Jul 11, 2023

Describe the feature

Otterscan is an Ethereum block explorer designed to be run locally with an archive node companion.
It's more private compared to other solutions because it allows you to query your node, avoiding sharing sensitive data with third parties.
This is achieved without an external indexer through custom RPC methods that currently are only available in Erigon.
The addition of this extension (even if behind a feature flag) would allow the community to run Otterscan with a different client other than Erigon.
Users would have access to useful information not available on the standard RPC endpoints, without an external indexer, which can be very helpful for data-intensive applications.

Endpoint checklist

Additional context

No response

@ZePedroResende ZePedroResende added C-enhancement New feature or request S-needs-triage This issue needs to be labelled labels Jul 11, 2023
@mattsse mattsse added D-good-first-issue Nice and easy! A great choice to get started A-rpc Related to the RPC implementation and removed S-needs-triage This issue needs to be labelled labels Jul 11, 2023
@naps62
Copy link
Contributor

naps62 commented Jul 11, 2023

@gakonst as discussed, can we get this assigned to @ZePedroResende ? I'll be working on this with him

I was thinking a good first step would be to get an initial endpoint done as a draft, mainly to start discussing architecture. I imagine some input will be required, so I want to optimize everyone's time :)

@gakonst
Copy link
Member

gakonst commented Jul 11, 2023

SGTM! Let us know how to proceed here.

@mattsse
Copy link
Collaborator

mattsse commented Jul 11, 2023

cool, some pointers:
the way it's structure is that we define a trait per namespace with all the functions, like:

/// Web3 rpc interface.
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "web3"))]
#[cfg_attr(feature = "client", rpc(server, client, namespace = "web3"))]
#[async_trait::async_trait]
pub trait Web3Api {
/// Returns current client version.
#[method(name = "clientVersion")]
async fn client_version(&self) -> RpcResult<String>;
/// Returns sha3 of the given data.
#[method(name = "sha3")]
fn sha3(&self, input: Bytes) -> RpcResult<H256>;
}

and then add a type that implements this like:

#[async_trait]
impl<N> Web3ApiServer for Web3Api<N>
where
N: NetworkInfo + 'static,
{
/// Handler for `web3_clientVersion`
async fn client_version(&self) -> RpcResult<String> {
let status = self.network.network_status().await.to_rpc_result()?;
Ok(status.client_version)
}
/// Handler for `web3_sha3`
fn sha3(&self, input: Bytes) -> RpcResult<H256> {
Ok(keccak256(input))
}
}

@naps62
Copy link
Contributor

naps62 commented Jul 13, 2023

@mattsse thanks, that helped a lot already

what's your preference regarding how to manage the work here? a single large branch where we built the feature and merge as a whole? merging small incremental changes, disabled through a feature flag?

@mattsse
Copy link
Collaborator

mattsse commented Jul 13, 2023

incremental would be ideal, for example

  1. trait bindings
  2. impl (can be done in multiple steps)
  3. integration in rpc-builder+cli

@naps62
Copy link
Contributor

naps62 commented Jul 15, 2023

Bringing back @gakonst 's comment from the PR, feels more on-topic here:

My main Q/concern here is: What new tables are needed to support these APIs?
Could we scope them very clearly, as well as understand 1) what stages (if any) we need to add to generate these new tables, 2) how much DB overhead they incur?
My main Q/concern here is: What new tables are needed to support these APIs?

makes sense. We went this route because of mattsse's suggestion, but I do admit we still need to learn more about that. also because we're still learning the codebase here, so any input is much appreciated

I was getting more familiar with reth storage because of this topic yesterday. Here's my thoughts so far (I'll let @ZePedroResende correct/complete me):

  • ots_getTransactionBySenderAndNonce seems to need a (Address, u64) | H256 table
  • ots_getContractCreator should need an Address | Address mapping
  • ots_searchTransactionsBefore/After should be by far the biggest one: it requires mapping each address to any tx that ever touched it (outbound, inbound, internal).
  • ots_getBlockDetails shouldn't need extra tables, but it does have an issuance object. in Ethereum this is now meaningless, but depending on what other chains are need to support, may need some computation
  • ots_getTransactionError and ots_traceTransaction seem like they reuse the existing tracing code?

Maybe some of these can leverage existing tables that I overlooked?
I also assume we'll at the very least want to feature-gate these features to avoid the extra overhead unless explicitly needed?

@gakonst
Copy link
Member

gakonst commented Jul 15, 2023

I also assume we'll at the very least want to feature-gate these features to avoid the extra overhead unless explicitly needed?

100% - for sure.

cc @joshieDo as these are all indices and it might overlap with the future etl work

@ZePedroResende

This comment was marked as duplicate.

@onbjerg
Copy link
Member

onbjerg commented Jul 24, 2023

@ZePedroResende moved the tasklist to the main issue

ZePedroResende added a commit to naps62/reth that referenced this issue Jul 31, 2023
This tackles paradigmxyz#3726 by adding the implementations of `ots_getBlockDetails` and `ots_getBlockDetailsByHash`

* Add `ots_getBlockDetails` and `ots_getBlockDetailsByHash`
  implementation
* Implement From trait for `BlockDetails` from `Rich<Block>`
* Implement From trait for `OtsBlock` from `Block`
* Add Default trait for `InternalIssuance` as a placeholder
@0xAlcibiades
Copy link

This still seems to be missing a few parts including the erigon namespace for otterscan support to work. I see this was recently added to foundry and wonder if there'd be interest to bring things up to speed on this side @Rjected @Evalir @ZePedroResende

@0xAlcibiades
Copy link

Relates to: foundry-rs/foundry#5414

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started
Projects
Status: Todo
Development

No branches or pull requests

6 participants