-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Solana JSON-RPC api #960
Solana JSON-RPC api #960
Conversation
Parity JSON-RPC has an active issue to update its hyper crate dependency (paritytech/jsonrpc#298), which should alleviate the cargo audit vulnerability. |
I was thinking this would be implemented within Fullnode and may render the RPU obsolete rather than building on top of it. I'd call it |
81f1850
to
7d4b21b
Compare
7d4b21b
to
6ae25c4
Compare
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.
You might find it helpful to run cargo cov
on this. I think you'd see a lack of code coverage on cases that'd be terribly boring to write tests for, and that to up that coverage, you might find it easier to remove those cases than to write those tests!
src/fullnode.rs
Outdated
@@ -54,6 +55,7 @@ impl Fullnode { | |||
keypair: Keypair, | |||
network_entry_for_validator: Option<SocketAddr>, | |||
sigverify_disabled: bool, | |||
json_rpc_enabled: bool, |
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.
Like the RPU, I'd prefer this always be enabled. If there's some port conflict, can we resolve that elsewhere?
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! It wasn't really a port-conflict issue, but a thread blocking issue.
src/rpc.rs
Outdated
pub request_processor: Option<JsonRpcRequestProcessor>, | ||
} | ||
impl Metadata for Meta {} | ||
impl Default for Meta { |
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.
Does some library require we implement Default
? If not, it'd be better to get rid of that Option<>
and pass the request processor into a Meta
constructor. Then you'd be able to get rid of all those unwrap()
calls on request_processor
.
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.
The version of jsonrpc on crates.io requires Default
for Metadata, but that has been fixed in more recent commits. I have changed the dependency to pull from github for now.
src/rpc.rs
Outdated
fn confirm_transaction(&self, meta: Self::Metadata, id: String) -> Result<bool> { | ||
let signature_vec = bs58::decode(id) | ||
.into_vec() | ||
.expect("base58-encoded public key"); |
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.
We can't use expect()
or unwrap()
here because that'd cause this thread to shut down if someone sent us bad input. Looks like it should be Err(Error::invalid_request())
. Also, the string is wrong - it's not a public key.
src/rpc.rs
Outdated
pub trait RpcSol { | ||
type Metadata; | ||
|
||
#[rpc(meta, name = "solana_confirmTransaction")] |
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.
Pity to have that solana_
prefix everywhere. What happens if we got rid of 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.
Nothing bad. I will do that. We might want to use prefixes at some point to differentiate method types, but there's no reason to clutter it up with an meaningless one now.
src/rpc.rs
Outdated
.expect("base58-encoded public key"); | ||
|
||
if signature_vec.len() != mem::size_of::<Signature>() { | ||
Err(Error::invalid_request()) |
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.
Use early returns to handle edge cases, so that the main case don't need to be nested under else
. The value-add here is more obvious when there are multiple edge cases, but we should do it here too to keep the codebase consistent.
src/rpc.rs
Outdated
} else { | ||
let signature = Signature::new(&signature_vec); | ||
let req = JsonRpcRequest::GetSignature { signature }; | ||
let resp = meta.request_processor.unwrap().process_request(req); |
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.
Calling process_request
here forces unnecessary branches below to decode the response. Since we already know this is a "GetSignature" request, I'd expect this code to call a get_signature
method that returns a Result<SignatureStatus>
. If we're going to do a match
on the result, it should only be to convert an internal type to its JSON RPC equivalent. The Some(_) => Err
case is the red flag here.
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.
Oh, nice. That's a much better method. Will build it out, thanks!
bdf7d6a
to
0f68c84
Compare
6d6fea7
to
f632b45
Compare
@mvines , is there a way to temporarily ignore the cargo audit error for smallvec until the jsonrpc crate is updated? ...I think the large-network test timeout is unrelated to this PR; looks like the tip of master has the same issue. |
Try this: --- a/ci/test-stable.sh
+++ b/ci/test-stable.sh
@@ -23,4 +23,4 @@ echo --- ci/localnet-sanity.sh
USE_INSTALL=1 ci/localnet-sanity.sh
)
-_ ci/audit.sh
+_ ci/audit.sh || true with an issue filed to revert of course |
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 great!
src/fullnode.rs
Outdated
@@ -190,7 +191,7 @@ impl Fullnode { | |||
let tick_duration = None; | |||
// TODO: To light up PoH, uncomment the following line: | |||
//let tick_duration = Some(Duration::from_millis(1000)); | |||
|
|||
// let node_info = node.data.clone(); |
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?
src/rpc.rs
Outdated
@@ -0,0 +1,278 @@ | |||
//! The `rpc` module implements the Solana rpc interface. |
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.
nit: "... Solana RPC interface."
0396807
to
4daa494
Compare
4daa494
to
d755f01
Compare
Woot! #996 allows this to pass the large-network test, so finally landing this. |
solana-labs#1116) * Added validator stake account list storage, deprecated old tests * Added join and leave stake pool instructions, error messages refactoring * Stake pool tests refactoring, tests for join and leave pool added * Added validator stake account creation instruction, join/leave pool instructions renamed, version field added * Formatting fixes * Added update list/pool instructions (no tests yet), updated deposit instruction logic, claim instruction removed, refactoring * Updated deposit logic and tests, updated withdraw logic and added tests, refactoring * Stake pool CLI updated to work with new deposit/withdraw instructions, claim usage removed * Added validator stake account management and balance update commands to the stake pool CLI, updated dependency versions, updated devnet program address * Merge conflicts fixed * Removed deprecated tests * Fixes for review comments * Additional program id checks across the code * Formatting errors fixed * Changed minimum stake balance in CLI, removed deprecated tests, removed check for stake history id * Added TODO for stake account warmup status check * Cargo.lock conflict fix * Formatting fixed * Update Cargo lock file for CI * Pin themis version of subtle Co-authored-by: Yuriy Savchenko <[email protected]>
This implements a preliminary JSON-RPC api infra, toward #702
It is currently built as a separate service (à la drone), but could be integrated into FullNode deployment instead.
Right now, the api just emulates the current wallet functionality plus several thin client functions. (0.9.0 JSON RPC Node Service step #1)
It uses a very janky method of pulling a client keypair to generate a transaction, to be rewritten as soon as integration with web-wallet progresses (in-wallet signatures).
(Incidentally, this module exposes a lot of work that needs to be done on the thin client module, including reworking of transfers to accommodate web-wallet signatures, and request timeouts. Will follow up with new issues.)