-
Notifications
You must be signed in to change notification settings - Fork 84
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
Conversation
sequencer/api/merklized_state.toml
Outdated
@@ -0,0 +1,4 @@ | |||
[route.getfeebalance] | |||
PATH = ["/fee_balance/:address"] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
+ 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete before merging
There was a problem hiding this comment.
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
.parse() | ||
.map_err(|_| merklized_state::Error::Custom { | ||
message: "failed to parse Key param".to_string(), | ||
status: StatusCode::INTERNAL_SERVER_ERROR, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
+ 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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the comment?
There was a problem hiding this comment.
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
let key = address | ||
.parse() | ||
.map_err(|_| merklized_state::Error::Custom { | ||
message: "failed to parse Key param".to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed to parse address?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in d19a139
sequencer/api/merklized_state.toml
Outdated
[route.getfeebalance] | ||
PATH = ["/fee_balance/:address"] | ||
":address" = "Literal" | ||
DOC = "Get current balance in address account." |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in d19a139
Did manually test it and that looks good 👍 |
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.
There was a problem hiding this 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.
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/