Add documentation to SubmitSignedTransaction and actually make it work (#4200)

* Add documentation to signed transactions and actually make them work.

* Fix naming and bounds.

* Forgotten import.

* Remove warning.

* Make accounts optional, fix logic.

* Split the method to avoid confusing type error message.

* Move executor tests to integration.

* Add submit transactions tests.

* Make `submit_transaction` tests compile

* Remove a file that was accidently committed

* Add can_sign helper function.

* Fix compilation.

* Add a key to keystore.

* Fix the tests.

* Remove env_logger.

* Fix sending multiple transactions.

* Remove commented code.

* Bring back criterion.

* Remove stray debug log.

* Apply suggestions from code review

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Make sure to initialize block correctly.

* Initialize block for offchain workers.

* Add test for transaction validity.

* Fix tests.

* Review suggestions.

* Remove redundant comment.

* Make sure to use correct block number of authoring.

* Change the runtime API.

* Support both versions.

* Bump spec version, fix RPC test.

Co-authored-by: Hernando Castano <HCastano@users.noreply.github.com>
Co-authored-by: Gavin Wood <github@gavwood.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Tomasz Drwięga
2020-01-10 01:46:55 +01:00
committed by Gavin Wood
parent a1e0076aa8
commit 74d6e660c6
29 changed files with 2096 additions and 1413 deletions
@@ -174,6 +174,7 @@ impl TryFrom<u32> for HttpRequestStatus {
/// A blob to hold information about the local node's network state
/// without committing to its format.
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, PassByCodec)]
#[cfg_attr(feature = "std", derive(Default))]
pub struct OpaqueNetworkState {
/// PeerId of the local node.
pub peer_id: OpaquePeerId,
+6
View File
@@ -26,9 +26,15 @@ pub const STORAGE_PREFIX: &[u8] = b"storage";
sp_api::decl_runtime_apis! {
/// The offchain worker api.
#[api_version(2)]
pub trait OffchainWorkerApi {
/// Starts the off-chain task for given block number.
#[skip_initialize_block]
#[changed_in(2)]
fn offchain_worker(number: NumberFor<Block>);
/// Starts the off-chain task for given block header.
#[skip_initialize_block]
fn offchain_worker(header: &Block::Header);
}
}
+3 -3
View File
@@ -23,7 +23,7 @@ use sp_io;
use std::fmt::Display;
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize, de::DeserializeOwned};
use sp_core::{self, Hasher, Blake2Hasher, TypeId};
use sp_core::{self, Hasher, Blake2Hasher, TypeId, RuntimeDebug};
use crate::codec::{Codec, Encode, Decode};
use crate::transaction_validity::{
ValidTransaction, TransactionValidity, TransactionValidityError, UnknownTransaction,
@@ -157,7 +157,7 @@ pub trait EnsureOrigin<OuterOrigin> {
}
/// An error that indicates that a lookup failed.
#[derive(Encode, Decode)]
#[derive(Encode, Decode, RuntimeDebug)]
pub struct LookupError;
impl From<LookupError> for &'static str {
@@ -391,7 +391,7 @@ pub trait Hash: 'static + MaybeSerializeDeserialize + Debug + Clone + Eq + Parti
}
/// Blake2-256 Hash implementation.
#[derive(PartialEq, Eq, Clone, sp_core::RuntimeDebug)]
#[derive(PartialEq, Eq, Clone, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct BlakeTwo256;
@@ -163,6 +163,8 @@ pub trait TransactionPool: Send + Sync {
/// Error type.
type Error: From<crate::error::Error> + crate::error::IntoPoolError;
// Networking
/// Returns a future that imports a bunch of unverified transactions to the pool.
fn submit_at(
&self,
@@ -183,6 +185,8 @@ pub trait TransactionPool: Send + Sync {
Self::Error
>> + Send + Unpin>;
// RPC
/// Returns a future that import a single transaction and starts to watch their progress in the pool.
fn submit_and_watch(
&self,
@@ -190,23 +194,35 @@ pub trait TransactionPool: Send + Sync {
xt: TransactionFor<Self>,
) -> Box<dyn Future<Output=Result<Box<TransactionStatusStreamFor<Self>>, Self::Error>> + Send + Unpin>;
/// Remove transactions identified by given hashes (and dependent transactions) from the pool.
fn remove_invalid(&self, hashes: &[TxHash<Self>]) -> Vec<Arc<Self::InPoolTransaction>>;
/// Returns pool status.
fn status(&self) -> PoolStatus;
// Block production / Networking
/// Get an iterator for ready transactions ordered by priority
fn ready(&self) -> Box<dyn Iterator<Item=Arc<Self::InPoolTransaction>>>;
// Block production
/// Remove transactions identified by given hashes (and dependent transactions) from the pool.
fn remove_invalid(&self, hashes: &[TxHash<Self>]) -> Vec<Arc<Self::InPoolTransaction>>;
// logging
/// Returns pool status.
fn status(&self) -> PoolStatus;
// logging / RPC / networking
/// Return an event stream of transactions imported to the pool.
fn import_notification_stream(&self) -> ImportNotificationStream;
/// Returns transaction hash
fn hash_of(&self, xt: &TransactionFor<Self>) -> TxHash<Self>;
// networking
/// Notify the pool about transactions broadcast.
fn on_broadcasted(&self, propagations: HashMap<TxHash<Self>, Vec<String>>);
/// Returns transaction hash
fn hash_of(&self, xt: &TransactionFor<Self>) -> TxHash<Self>;
}
/// An abstraction for transaction pool.