-
Notifications
You must be signed in to change notification settings - Fork 1.1k
statement-store: New RPC result types #10421
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
base: master
Are you sure you want to change the base?
Changes from all commits
853a9df
c6d8e87
1cc5ae9
550d9fa
b153d0f
32b198b
31a606b
bc77940
67d915f
068364a
4b6cc03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| title: 'statement-store: New RPC result types' | ||
| doc: | ||
| - audience: Node Dev | ||
| description: |- | ||
| Moved submission failures from JSON-RPC errors into structured result types: | ||
| - Internal submission result type changed to hold more information for clients. | ||
| - The "statement_submit" method now returns enum with clear status variants (New, Known, Invalid, Rejected). | ||
| - NetworkPriority removed as we never used it. | ||
| - Updated and simplified the reputation system. | ||
| - Runtime API wasn't changed. | ||
|
|
||
| crates: | ||
| - name: sc-rpc-api | ||
| bump: major | ||
| - name: sc-rpc | ||
| bump: major | ||
| - name: sc-network-statement | ||
| bump: major | ||
| - name: sc-statement-store | ||
| bump: major | ||
| - name: sp-statement-store | ||
| bump: major |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,11 +24,38 @@ use jsonrpsee::{ | |
| Extensions, | ||
| }; | ||
| /// Re-export the API for backward compatibility. | ||
| pub use sc_rpc_api::statement::{error::Error, StatementApiServer}; | ||
| pub use sc_rpc_api::statement::{ | ||
| error::Error, InvalidReason, RejectionReason, StatementApiServer, StatementSubmitResult, | ||
| }; | ||
| use sp_core::Bytes; | ||
| use sp_statement_store::{StatementSource, SubmitResult}; | ||
| use std::sync::Arc; | ||
|
|
||
| /// Maps the internal InvalidReason to the RPC API InvalidReason type. | ||
| fn map_invalid_reason(reason: sp_statement_store::InvalidReason) -> InvalidReason { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: they seem to have the same invariant, so probably can be a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't add From here, either I didn't want to bring extra crates to dependencies. |
||
| match reason { | ||
| sp_statement_store::InvalidReason::NoProof => InvalidReason::NoProof, | ||
| sp_statement_store::InvalidReason::BadProof => InvalidReason::BadProof, | ||
| sp_statement_store::InvalidReason::EncodingTooLarge { submitted_size, max_size } => | ||
| InvalidReason::EncodingTooLarge { submitted_size, max_size }, | ||
| } | ||
| } | ||
|
|
||
| /// Maps the internal RejectionReason to the RPC API RejectionReason type. | ||
| fn map_rejection_reason(reason: sp_statement_store::RejectionReason) -> RejectionReason { | ||
| match reason { | ||
| sp_statement_store::RejectionReason::DataTooLarge { submitted_size, available_size } => | ||
| RejectionReason::DataTooLarge { submitted_size, available_size }, | ||
| sp_statement_store::RejectionReason::ChannelPriorityTooLow { | ||
| submitted_priority, | ||
| min_priority, | ||
| } => RejectionReason::ChannelPriorityTooLow { submitted_priority, min_priority }, | ||
| sp_statement_store::RejectionReason::AccountFull { submitted_priority, min_priority } => | ||
| RejectionReason::AccountFull { submitted_priority, min_priority }, | ||
| sp_statement_store::RejectionReason::StoreFull => RejectionReason::StoreFull, | ||
| } | ||
| } | ||
|
|
||
| /// Statement store API | ||
| pub struct StatementStore { | ||
| store: Arc<dyn sp_statement_store::StatementStore>, | ||
|
|
@@ -123,17 +150,19 @@ impl StatementApiServer for StatementStore { | |
| .collect()) | ||
| } | ||
|
|
||
| fn submit(&self, encoded: Bytes) -> RpcResult<()> { | ||
| fn submit(&self, encoded: Bytes) -> RpcResult<StatementSubmitResult> { | ||
| let statement = Decode::decode(&mut &*encoded) | ||
| .map_err(|e| Error::StatementStore(format!("Error decoding statement: {:?}", e)))?; | ||
| match self.store.submit(statement, StatementSource::Local) { | ||
| SubmitResult::New(_) | SubmitResult::Known => Ok(()), | ||
| SubmitResult::New => Ok(StatementSubmitResult::New), | ||
| SubmitResult::Known => Ok(StatementSubmitResult::Known), | ||
| // `KnownExpired` should not happen. Expired statements submitted with | ||
| // `StatementSource::Rpc` should be renewed. | ||
| SubmitResult::KnownExpired => | ||
| Err(Error::StatementStore("Submitted an expired statement.".into()).into()), | ||
| SubmitResult::Bad(e) => Err(Error::StatementStore(e.into()).into()), | ||
| SubmitResult::Ignored => Err(Error::StatementStore("Store is full.".into()).into()), | ||
| SubmitResult::KnownExpired => Ok(StatementSubmitResult::KnownExpired), | ||
| SubmitResult::Rejected(reason) => | ||
| Ok(StatementSubmitResult::Rejected(map_rejection_reason(reason))), | ||
| SubmitResult::Invalid(reason) => | ||
| Ok(StatementSubmitResult::Invalid(map_invalid_reason(reason))), | ||
| SubmitResult::InternalError(e) => Err(Error::StatementStore(e.to_string()).into()), | ||
| } | ||
| } | ||
|
|
||
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.
why this change ?
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.
Clean up. We never used the old GOOD_STATEMENT, so I removed it. But since we have only EXCELENT_STATEMENT, no need to keep it excelent, just good is ok