-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Statement store #13701
Statement store #13701
Changes from 1 commit
729e524
7591d22
ff1edaa
8407e40
21c9aaf
c706097
e066abe
bfbbc5b
d36a867
d610e62
0b73266
66b9c98
c8f0467
9bc6773
8263aa4
7779458
f01160e
7431f55
5cc24b2
dea2dea
4febbea
b06e356
c6f2b53
50b583d
e141eb7
c5555e9
1171ba0
399cbbd
365e5e8
3d571ca
85a31c9
b07775f
659b494
25f3771
27e73cc
39f0145
51b16ff
0e84775
312a07e
9c21172
0d95b2e
61f6e5f
d93493a
f06ac25
3c2373d
a13e2c0
ac499ab
e562b65
06f3376
167c4ad
4c840c0
03906c8
f33942c
206488d
2625783
a7f652a
0bf748e
8c883a7
c05e3d7
6c15ce9
f383ab6
a978b2a
83f343f
94b10a7
1c22fef
f08810b
7849cc8
64ac7f5
f05f5a3
21dd020
d72290c
16e469e
8d18b5e
9d3add2
cd7c9dc
d29ebc7
38d893d
fdb43c5
74e4945
4f1ac76
2f2d4f8
75ee1bf
b501198
692f58a
704d53a
71b39cf
a798b08
7af3b5a
47a8e6b
4fb2aee
df2df2a
f81511d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -351,7 +351,24 @@ impl Index { | |
|
|
||
| impl Store { | ||
| /// Create a new shared store instance. There should only be one per process. | ||
| pub fn new<Block, Client>( | ||
| pub fn new_shared<Block, Client>( | ||
| path: &std::path::Path, | ||
|
Member
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. Maybe some comment on what this path is used for. |
||
| client: Arc<Client>, | ||
| prometheus: Option<&PrometheusRegistry>, | ||
| ) -> Result<Arc<Store>> | ||
| where | ||
| Block: BlockT, | ||
| Block::Hash: From<BlockHash>, | ||
| Client: ProvideRuntimeApi<Block> + HeaderBackend<Block> + sc_client_api::ExecutorProvider<Block> + Send + Sync + 'static, | ||
| Client::Api: ValidateStatement<Block>, | ||
| { | ||
| let store = Arc::new(Self::new(path, client.clone(), prometheus)?); | ||
| client.execution_extensions().register_statement_store(store.clone()); | ||
| Ok(store) | ||
| } | ||
|
|
||
| /// Create a new instance. | ||
| fn new<Block, Client>( | ||
| path: &std::path::Path, | ||
| client: Arc<Client>, | ||
| prometheus: Option<&PrometheusRegistry>, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| use codec::{Decode, Encode}; | ||
| use scale_info::TypeInfo; | ||
| use sp_application_crypto::RuntimeAppPublic; | ||
| use sp_runtime_interface::pass_by::PassByCodec; | ||
| #[cfg(feature = "std")] | ||
| use sp_core::Pair; | ||
| use sp_std::vec::Vec; | ||
|
|
@@ -76,7 +77,7 @@ pub fn hash_encoded(data: &[u8]) -> [u8; 32] { | |
| } | ||
|
|
||
| /// Statement proof. | ||
| #[derive(Encode, Decode, TypeInfo, sp_runtime::RuntimeDebug, Clone, PartialEq, Eq)] | ||
| #[derive(Encode, Decode, TypeInfo, sp_core::RuntimeDebug, Clone, PartialEq, Eq)] | ||
| pub enum Proof { | ||
| /// Sr25519 Signature. | ||
|
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. I would force the index with #[codec(index=0)] for all these encoded enum. |
||
| Sr25519 { | ||
|
|
@@ -110,7 +111,7 @@ pub enum Proof { | |
| }, | ||
| } | ||
|
|
||
| #[derive(Encode, Decode, TypeInfo, sp_runtime::RuntimeDebug, Clone, PartialEq, Eq)] | ||
| #[derive(Encode, Decode, TypeInfo, sp_core::RuntimeDebug, Clone, PartialEq, Eq)] | ||
| /// Statement attributes. Each statement is a list of 0 or more fields. Fields may only appear in | ||
| /// the order declared here. | ||
| #[repr(u8)] | ||
|
|
@@ -131,7 +132,7 @@ pub enum Field { | |
| Data(Vec<u8>) = 6, | ||
| } | ||
|
|
||
| #[derive(TypeInfo, sp_runtime::RuntimeDebug, Clone, PartialEq, Eq, Default)] | ||
| #[derive(TypeInfo, sp_core::RuntimeDebug, PassByCodec, Clone, PartialEq, Eq, Default)] | ||
| /// Statement structure. | ||
| pub struct Statement { | ||
| proof: Option<Proof>, | ||
|
|
@@ -296,7 +297,8 @@ impl Statement { | |
| let signature = sp_core::ecdsa::Signature(*signature); | ||
| let public = sp_core::ecdsa::Public(*signer); | ||
| if signature.verify(to_sign.as_slice(), &public) { | ||
| SignatureVerificationResult::Valid(sp_io::hashing::blake2_256(signer)) | ||
| let sender_hash = <sp_runtime::traits::BlakeTwo256 as sp_core::Hasher>::hash(signer); | ||
| SignatureVerificationResult::Valid(sender_hash.into()) | ||
| } else { | ||
| SignatureVerificationResult::Invalid | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,10 +17,13 @@ | |||||
|
|
||||||
| //! Runtime support for the statement store. | ||||||
|
|
||||||
| use crate::Statement; | ||||||
| use crate::{Topic, Statement, Hash}; | ||||||
| use codec::{Decode, Encode}; | ||||||
| use scale_info::TypeInfo; | ||||||
| use sp_runtime::RuntimeDebug; | ||||||
| use sp_runtime_interface::{runtime_interface, pass_by::PassByEnum}; | ||||||
| use sp_externalities::ExternalitiesExt; | ||||||
| use sp_std::vec::Vec; | ||||||
|
|
||||||
| /// Information concerning a valid statement. | ||||||
| #[derive(Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo)] | ||||||
|
|
@@ -75,3 +78,93 @@ sp_api::decl_runtime_apis! { | |||||
| ) -> Result<ValidStatement, InvalidStatement>; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[cfg(feature = "std")] | ||||||
| sp_externalities::decl_extension! { | ||||||
| /// The offchain database extension that will be registered at the Substrate externalities. | ||||||
| pub struct StatementStoreExt(std::sync::Arc<dyn crate::StatementStore>); | ||||||
| } | ||||||
|
|
||||||
| #[cfg(feature = "std")] | ||||||
| /// Host extensions for the runtime. | ||||||
bkchr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| impl StatementStoreExt { | ||||||
| /// Create new instance of externalities extensions. | ||||||
| pub fn new(store: std::sync::Arc<dyn crate::StatementStore>) -> Self { | ||||||
| Self(store) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| #[derive(Debug, Eq, PartialEq, Clone, Copy, Encode, Decode, PassByEnum)] | ||||||
| /// Submission result. | ||||||
arkpar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| pub enum SubmitResult { | ||||||
| /// Accepted as new. | ||||||
| OkNew, | ||||||
| /// Known statement | ||||||
| OkKnown, | ||||||
| /// Statement failed validation. | ||||||
| Bad, | ||||||
| /// The store is not available. | ||||||
| NotAvailable, | ||||||
| } | ||||||
|
|
||||||
| /// Host interface | ||||||
| #[runtime_interface] | ||||||
| pub trait Io { | ||||||
|
||||||
| pub trait Io { | |
| pub trait StatementStore { |
The name is used as part of the host functions and Io is not expressive enough.
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.
Doesn't it also use the name of the containing module?
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.
No
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.
Fixed
Uh oh!
There was an error while loading. Please reload this page.