-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change(rpc): add submitblock RPC method (#5526)
* adds submitblock rpc method * re-orders imports * replaces thread::yield_now with async yield_now * Fix doc warnings and unused variable warnings, add missing docs * Mark work_id as optional * Use the same ChainVerifier for downloaded and submitted blocks * Revert unused changes & minor cleanups * Document currently-unreachable code * updates tests and submit_block response for AlreadyVerified error * Update zebra-rpc/src/methods/get_block_template_rpcs.rs Co-authored-by: Alfredo Garcia <[email protected]> * changes names from BlockVerifier to ChainVerifier and block_verifier to chain_verifier to keep it consistent with naming in zebra-consensus * move how to run the submit_block test example to acceptance.rs * updates snapshot tests * moved acceptance test to a separate file * removes extra tower::ServiceBuilder::new(), updates docs * updates vectors and snapshot tests, changes hex decoding error in submit_block method from server error to parse error * hides errors module in zebra-rpc behind a feature flag and adds docs. * Updates snapshot test, adds mod docs, moves HexData to its own mod, and removes the unrelated make_server_error refactor for now * update submit block acceptance test mod doc Co-authored-by: teor <[email protected]> Co-authored-by: Alfredo Garcia <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
34313b8
commit 2f3b05f
Showing
21 changed files
with
638 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
zebra-rpc/src/methods/get_block_template_rpcs/types/hex_data.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//! Deserializes hex-encoded inputs such as the one required | ||
//! for the `submitblock` RPC method. | ||
/// Deserialize hex-encoded strings to bytes. | ||
#[derive(Debug, PartialEq, Eq, serde::Deserialize)] | ||
pub struct HexData(#[serde(with = "hex")] pub Vec<u8>); |
47 changes: 47 additions & 0 deletions
47
zebra-rpc/src/methods/get_block_template_rpcs/types/submit_block.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//! Parameter and response types for the `submitblock` RPC. | ||
// Allow doc links to these imports. | ||
#[allow(unused_imports)] | ||
use crate::methods::get_block_template_rpcs::GetBlockTemplateRpc; | ||
|
||
/// Optional argument `jsonparametersobject` for `submitblock` RPC request | ||
/// | ||
/// See notes for [`GetBlockTemplateRpc::submit_block`] method | ||
#[derive(Debug, serde::Deserialize)] | ||
pub struct JsonParameters { | ||
pub(crate) _work_id: Option<String>, | ||
} | ||
|
||
/// Response to a `submitblock` RPC request. | ||
/// | ||
/// Zebra never returns "duplicate-invalid", because it does not store invalid blocks. | ||
#[derive(Debug, PartialEq, Eq, serde::Serialize)] | ||
#[serde(rename_all = "kebab-case")] | ||
pub enum ErrorResponse { | ||
/// Block was already committed to the non-finalized or finalized state | ||
Duplicate, | ||
/// Block was already added to the state queue or channel, but not yet committed to the non-finalized state | ||
DuplicateInconclusive, | ||
/// Block was already committed to the non-finalized state, but not on the best chain | ||
Inconclusive, | ||
/// Block rejected as invalid | ||
Rejected, | ||
} | ||
|
||
/// Response to a `submitblock` RPC request. | ||
/// | ||
/// Zebra never returns "duplicate-invalid", because it does not store invalid blocks. | ||
#[derive(Debug, PartialEq, Eq, serde::Serialize)] | ||
#[serde(untagged)] | ||
pub enum Response { | ||
/// Block was not successfully submitted, return error | ||
ErrorResponse(ErrorResponse), | ||
/// Block successfully submitted, returns null | ||
Accepted, | ||
} | ||
|
||
impl From<ErrorResponse> for Response { | ||
fn from(error_response: ErrorResponse) -> Self { | ||
Self::ErrorResponse(error_response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.