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

Adding API endpoint to get fee balance per account #2165

Merged
merged 6 commits into from
Nov 5, 2024

Conversation

fkrell
Copy link
Contributor

@fkrell fkrell commented Oct 11, 2024

Closes #2105

This PR:

Adds get_fee_balance endpoint to the sequencer API to retrieve the current balance of an account.
This allows to detect whenever the Builder is low on funds and issue the corresponding alert

This PR does not:

Key places to review:

sequencer/api/merklized_state.toml: defines new endpoint.
sequencer/src/api/endpoints.rs: extends merklized state API with the new endpoint and define its behaviour.
In particular, given address as an input it retrieves current height from state, and uses height and address to retrieve merkle path from merklized state. Balance is extracted from leaf of this path.

Manual test is to run the native demo locally, retrieve the builder address from http://localhost:31003/v0/block_info/builderaddress, then use the address to call the new endpoint
http://localhost:24001/v0/fee-state/fee_balance/

@fkrell fkrell changed the title Adding API point to get fee balance per account Adding API endpoint to get fee balance per account Oct 11, 2024
@@ -0,0 +1,4 @@
[route.getfeebalance]
PATH = ["/fee_balance/:address"]
Copy link
Member

Choose a reason for hiding this comment

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

As a convention we usually use hyphens in URL segments eg fee-balance

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 in d19a139

+ Sync
+ MerklizedStateDataSource<SeqTypes, FeeMerkleTree, 256>
+ MerklizedStateHeightPersistence,
//for<'a> <<UniversalMerkleTree<FeeAmount,Sha3Digest,FeeAccount,256,Sha3Node> as hotshot_query_service::merklized_state::MerklizedState<Types, ARITY>>::Commit as TryFrom<&'a TaggedBase64>>::Error: Display,
Copy link
Member

Choose a reason for hiding this comment

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

Delete before merging

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 in d19a139

.parse()
.map_err(|_| merklized_state::Error::Custom {
message: "failed to parse Key param".to_string(),
status: StatusCode::INTERNAL_SERVER_ERROR,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be a 400 / BadRequest error because it's the client's fault.

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 in d19a139

+ Sync
+ MerklizedStateDataSource<SeqTypes, FeeMerkleTree, 256>
+ MerklizedStateHeightPersistence,
//for<'a> <<UniversalMerkleTree<FeeAmount,Sha3Digest,FeeAccount,256,Sha3Node> as hotshot_query_service::merklized_state::MerklizedState<Types, ARITY>>::Commit as TryFrom<&'a TaggedBase64>>::Error: Display,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the comment?

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 in d19a139

let key = address
.parse()
.map_err(|_| merklized_state::Error::Custom {
message: "failed to parse Key param".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.

Failed to parse address?

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 in d19a139

[route.getfeebalance]
PATH = ["/fee_balance/:address"]
":address" = "Literal"
DOC = "Get current balance in address account."
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Balance in fee state" or something like that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

And mention that we are expecting an ethereum address in hex format.

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 in d19a139

sequencer/src/api/endpoints.rs Outdated Show resolved Hide resolved
sequencer/src/api/endpoints.rs Show resolved Hide resolved
sequencer/src/api/options.rs Show resolved Hide resolved
sequencer/src/api/options.rs Show resolved Hide resolved
@sveitser
Copy link
Collaborator

Did manually test it and that looks good 👍

@sveitser sveitser dismissed their stale review October 13, 2024 14:19

I'll dismiss my change request because I will be OOO and none of it is critical. Would be nice if some of the suggestions were acted on though.

@fkrell fkrell self-assigned this Oct 25, 2024
Copy link
Contributor

@tbro tbro left a comment

Choose a reason for hiding this comment

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

Looks like all the comments were addressed.

@fkrell fkrell merged commit 86cbb62 into main Nov 5, 2024
13 checks passed
@fkrell fkrell deleted the fkrell/fee_balance_api branch November 5, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API endpoint to get current balance of a fee account
4 participants