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 RPC endpoint getBalancesChangesInBlock #3139

Closed
twilightrus opened this issue Jun 14, 2023 · 8 comments · Fixed by #3768
Closed

Add RPC endpoint getBalancesChangesInBlock #3139

twilightrus opened this issue Jun 14, 2023 · 8 comments · Fixed by #3768
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

@twilightrus
Copy link

Describe the feature

Add RPC endpoint getBalancesChangesInBlock like erigon: erigontech/erigon#4609

Additional context

No response

@twilightrus twilightrus added C-enhancement New feature or request S-needs-triage This issue needs to be labelled labels Jun 14, 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 Jun 14, 2023
@eserilev
Copy link

would there be interest in standardizing this endpoint by adding it to the official spec?

@eserilev
Copy link

ah after reading further i see this endpoint wouldnt be practical for certain clients

@eserilev
Copy link

migh want to create a seperate rpc interface for reth specific endpoints like this one? I don't think it should fall under the eth namespace, not sure if it would fit under any existing namespaces

I think the function definition itself could look something like

async fn get_balances_changes_in_block(&self, number: BlockHashOrNumber) -> RpcResult<HashMap<Address,u32>>;

@twilightrus
Copy link
Author

would there be interest in standardizing this endpoint by adding it to the official spec?

Yes

@twilightrus
Copy link
Author

migh want to create a seperate rpc interface for reth specific endpoints like this one? I don't think it should fall under the eth namespace, not sure if it would fit under any existing namespaces

I think the function definition itself could look something like

async fn get_balances_changes_in_block(&self, number: BlockHashOrNumber) -> RpcResult<HashMap<Address,u32>>;

Yes

@mattsse
Copy link
Collaborator

mattsse commented Jun 15, 2023

yeah, I'd like to move this to a new trait instead.

Is this endpoint similar to the existing statediff tracer but only uses balance changes?

@eserilev
Copy link

Is this endpoint similar to the existing statediff tracer but only uses balance changes?

still trying to wrap my head around it, but I think we might be able to use the AccountChangeSet

@ryanschneider
Copy link
Contributor

@eserilev would something like this work inside TraceApi?

pub async fn get_balances_changes_in_block(
        &self,
        block_id: BlockId,
    ) -> RpcResult<Option<HashMap<Address, U256>>> {
        let traced: EthResult<Option<Vec<Vec<(Address, U256)>>>> = self
            .trace_block_with(
                block_id,
                TracingInspectorConfig::default_parity(),
                |_, _, _, _, db| {
                    Ok(db.accounts.iter().map(|(k, v)| (*k, v.info.balance)).collect())
                },
            )
            .await;
        return if let Ok(Some(v)) = traced {
            let accounts: HashMap<Address, U256> = v.into_iter().flatten().collect();
            Ok(Some(accounts))
        } else {
            Ok(None)
        };
    }

This makes the perhaps totally incorrect assumption that db.accounts only contains the changed accounts inside the callback, if it includes all accounts it will of course fail spectacularly.

I'm very interested in trying to work on and debug this function, but am curious how to do so? Like how do the reth developers test their code locally, do you all work w/ a locally synced node or is there something like geth's --dev mode that I'm missing?

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
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants