Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
04f2167
Start
bkchr Mar 13, 2023
08c0b32
More work!
bkchr Mar 13, 2023
d1d5d4c
Moar
bkchr Mar 14, 2023
55af869
More changes
bkchr Mar 15, 2023
4374d01
More fixes
bkchr Mar 16, 2023
cc3c030
More worrk
bkchr Mar 17, 2023
0cac727
More fixes
bkchr Mar 20, 2023
7dbaa81
More fixes to make it compile
bkchr Mar 20, 2023
5b2fc23
Adds `NoOffchainStorage`
bkchr Mar 21, 2023
9fed302
Pass the extensions
bkchr Mar 21, 2023
6730212
Small basti making small progress
bkchr Mar 22, 2023
63ada35
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Apr 4, 2023
a3ff3e3
Fix merge errors and remove `ExecutionContext`
bkchr Apr 4, 2023
afbc691
Move registration of `ReadRuntimeVersionExt` to `ExecutionExtension`
bkchr Apr 4, 2023
947b02f
Merge remote-tracking branch 'origin/bkchr-move-read-runtime-version-…
bkchr Apr 4, 2023
906fb5a
Fix compilation
bkchr Apr 5, 2023
20f3c02
Register the global extensions inside runtime api instance
bkchr Apr 10, 2023
f6928f8
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Apr 24, 2023
033a32b
Fixes
bkchr Apr 26, 2023
cb24657
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Apr 28, 2023
97befb6
Fix `generate_initial_session_keys` by passing the keystore extension
bkchr May 1, 2023
c76f8fd
Fix the grandpa tests
bkchr May 2, 2023
13347fb
Fix more tests
bkchr May 2, 2023
0bd9113
Fix more tests
bkchr May 2, 2023
d457ac9
Don't set any heap pages if there isn't an override
bkchr May 3, 2023
4e4b5e4
Fix small fallout
bkchr May 3, 2023
7d48c14
FMT
bkchr May 3, 2023
d85f8ea
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr May 5, 2023
05223f1
Fix tests
bkchr May 7, 2023
6ca6737
More tests
bkchr May 8, 2023
440d0e5
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr May 8, 2023
5942c96
Offchain worker custom extensions
bkchr May 9, 2023
5b253f8
More fixes
bkchr May 9, 2023
3b7a8b4
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr May 17, 2023
16714b6
Make offchain tx pool creation reusable
bkchr May 23, 2023
e52f63d
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr May 25, 2023
190e036
Merge remote-tracking branch 'origin/bkchr-offchain-tx-pool-factory' …
bkchr May 25, 2023
902f1a4
Fixes
bkchr May 25, 2023
671f9b9
Fixes
bkchr May 25, 2023
59a6fa0
Set offchain transaction pool in BABE before using it in the runtime
bkchr May 29, 2023
9145976
Add the `offchain_tx_pool` to Grandpa as well
bkchr May 30, 2023
c29dcb3
Fix the nodes
bkchr May 30, 2023
23578b1
Print some error when using the old warnings
bkchr Jun 2, 2023
9208bf4
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jun 2, 2023
0e0325c
Fix merge issues
bkchr Jun 2, 2023
d12e6ba
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jun 5, 2023
65248e9
Fix compilation
bkchr Jun 5, 2023
67b1730
Rename `babe_link`
bkchr Jun 5, 2023
b1bb12d
Rename to `offchain_tx_pool_factory`
bkchr Jun 5, 2023
d4de293
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jun 14, 2023
85ccb89
Cleanup
bkchr Jun 14, 2023
5042fb0
FMT
bkchr Jun 14, 2023
99a5ca8
Fix benchmark name
bkchr Jun 15, 2023
32e69a2
Fix `try-runtime`
bkchr Jun 15, 2023
38191af
Remove `--execution` CLI args
bkchr Jun 15, 2023
8960448
Make clippy happy
bkchr Jun 16, 2023
42301cd
Forward bls functions
bkchr Jun 16, 2023
296ffd5
Merge branch 'bkchr-execution-strategies-remove' of github.com:parity…
bkchr Jun 16, 2023
e4bfccc
Fix docs
bkchr Jun 16, 2023
ae756aa
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jun 20, 2023
22c5603
Update UI tests
bkchr Jun 20, 2023
74ac48e
Update client/api/src/execution_extensions.rs
bkchr Jun 24, 2023
b07fde8
Apply suggestions from code review
bkchr Jun 24, 2023
8b3f2d9
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jun 24, 2023
ec9e872
Update client/cli/src/params/import_params.rs
bkchr Jun 24, 2023
e4781c4
Update client/api/src/execution_extensions.rs
bkchr Jun 24, 2023
4115970
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jun 28, 2023
c668c7c
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jun 29, 2023
9d61976
Merge branch 'bkchr-execution-strategies-remove' of github.com:parity…
bkchr Jun 30, 2023
3c71aa1
Pass the offchain storage to the MMR RPC
bkchr Jun 30, 2023
0c5c43d
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jul 5, 2023
7079d01
Update client/api/src/execution_extensions.rs
bkchr Jul 10, 2023
ad87780
Review comments
bkchr Jul 10, 2023
dc65806
Merge remote-tracking branch 'origin/master' into bkchr-execution-str…
bkchr Jul 10, 2023
792fbcc
Fixes
bkchr Jul 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 7 additions & 29 deletions client/offchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,15 @@ mod tests {
use sc_client_api::Backend as _;
use sc_network::{config::MultiaddrWithPeerId, types::ProtocolName};
use sc_peerset::ReputationChange;
use sc_transaction_pool::{BasicPool, FullChainApi};
use sc_transaction_pool::BasicPool;
use sc_transaction_pool_api::{InPoolTransaction, TransactionPool};
use sp_consensus::BlockOrigin;
use sp_runtime::generic::BlockId;
use std::{collections::HashSet, sync::Arc};
use substrate_test_runtime_client::{
runtime::{
substrate_test_pallet::pallet::Call as PalletCall, Block, ExtrinsicBuilder, RuntimeCall,
substrate_test_pallet::pallet::Call as PalletCall, ExtrinsicBuilder, RuntimeCall,
},
ClientBlockImportExt, DefaultTestClientBuilderExt, TestClient, TestClientBuilderExt,
ClientBlockImportExt, DefaultTestClientBuilderExt, TestClientBuilderExt,
};

struct TestNetwork();
Expand Down Expand Up @@ -451,35 +450,14 @@ mod tests {
}
}

#[derive(Clone)]
struct TestPool(Arc<BasicPool<FullChainApi<TestClient, Block>, Block>>);

impl sc_transaction_pool_api::OffchainSubmitTransaction<Block> for TestPool {
fn submit_at(
&self,
at: &BlockId<Block>,
extrinsic: <Block as traits::Block>::Extrinsic,
) -> Result<(), ()> {
let source = sc_transaction_pool_api::TransactionSource::Local;
futures::executor::block_on(self.0.submit_one(&at, source, extrinsic))
.map(|_| ())
.map_err(|_| ())
}
}

#[test]
fn should_call_into_runtime_and_produce_extrinsic() {
sp_tracing::try_init_simple();

let client = Arc::new(substrate_test_runtime_client::new());
let spawner = sp_core::testing::TaskExecutor::new();
let pool = TestPool(BasicPool::new_full(
Default::default(),
true.into(),
None,
spawner,
client.clone(),
));
let pool =
BasicPool::new_full(Default::default(), true.into(), None, spawner, client.clone());
let network = Arc::new(TestNetwork());
let header = client.header(client.chain_info().genesis_hash).unwrap().unwrap();

Expand All @@ -497,9 +475,9 @@ mod tests {
futures::executor::block_on(offchain.on_block_imported(&header));

// then
assert_eq!(pool.0.status().ready, 1);
assert_eq!(pool.status().ready, 1);
assert!(matches!(
pool.0.ready().next().unwrap().data().function,
pool.ready().next().unwrap().data().function,
RuntimeCall::SubstrateTest(PalletCall::storage_change { .. })
));
}
Expand Down
2 changes: 2 additions & 0 deletions client/transaction-pool/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ description = "Transaction pool client facing API."

[dependencies]
async-trait = "0.1.57"
codec = { package = "parity-scale-codec", version = "3.2.2" }
futures = "0.3.21"
log = "0.4.17"
serde = { version = "1.0.136", features = ["derive"] }
thiserror = "1.0.30"
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
sp-core = { version = "7.0.0", default-features = false, path = "../../../primitives/core" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../../primitives/runtime" }

[dev-dependencies]
Expand Down
76 changes: 65 additions & 11 deletions client/transaction-pool/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ pub mod error;
use async_trait::async_trait;
use futures::{Future, Stream};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use sp_core::offchain::TransactionPoolExt;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Member, NumberFor},
};
use std::{collections::HashMap, hash::Hash, pin::Pin, sync::Arc};
use std::{
collections::HashMap,
hash::Hash,
pin::Pin,
sync::{Arc, Weak},
};

const LOG_TARGET: &str = "txpool::api";

Expand Down Expand Up @@ -329,29 +335,27 @@ pub trait LocalTransactionPool: Send + Sync {
/// `TransactionSource::Local`.
fn submit_local(
&self,
at: &BlockId<Self::Block>,
at: <Self::Block as BlockT>::Hash,
xt: LocalTransactionFor<Self>,
) -> Result<Self::Hash, Self::Error>;
}

/// An abstraction for transaction pool.
/// An abstraction for [`LocalTransactionPool`]
///
/// This trait is used by offchain calls to be able to submit transactions.
/// The main use case is for offchain workers, to feed back the results of computations,
/// but since the transaction pool access is a separate `ExternalitiesExtension` it can
/// be also used in context of other offchain calls. For one may generate and submit
/// a transaction for some misbehavior reports (say equivocation).
pub trait OffchainSubmitTransaction<Block: BlockT>: Send + Sync {
/// We want to use a transaction pool in [`OffchainTransactionPoolFactory`] in a `Arc` without
/// bleeding the associated types besides the `Block`. Thus, this abstraction here exists to achieve
/// the wrapping in a `Arc`.
trait OffchainSubmitTransaction<Block: BlockT>: Send + Sync {
/// Submit transaction.
///
/// The transaction will end up in the pool and be propagated to others.
fn submit_at(&self, at: &BlockId<Block>, extrinsic: Block::Extrinsic) -> Result<(), ()>;
fn submit_at(&self, at: Block::Hash, extrinsic: Block::Extrinsic) -> Result<(), ()>;
}

impl<TPool: LocalTransactionPool> OffchainSubmitTransaction<TPool::Block> for TPool {
fn submit_at(
&self,
at: &BlockId<TPool::Block>,
at: <TPool::Block as BlockT>::Hash,
extrinsic: <TPool::Block as BlockT>::Extrinsic,
) -> Result<(), ()> {
log::debug!(
Expand All @@ -372,6 +376,56 @@ impl<TPool: LocalTransactionPool> OffchainSubmitTransaction<TPool::Block> for TP
}
}

/// Factory for creating [`TransactionPoolExt`]s.
///
/// This provides an easy way for creating [`TransactionPoolExt`] extensions for registering them in
/// the wasm execution environment to send transactions from an offchain call to the runtime.
#[derive(Clone)]
pub struct OffchainTransactionPoolFactory<Block: BlockT> {
// To break retain cycle between `Client` and `TransactionPool` we require this
// extension to be a `Weak` reference.
pool: Weak<dyn OffchainSubmitTransaction<Block>>,
}

impl<Block: BlockT> OffchainTransactionPoolFactory<Block> {
/// Creates a new instance using the given `tx_pool`.
pub fn new<T: LocalTransactionPool<Block = Block> + 'static>(tx_pool: &Arc<T>) -> Self {
Self { pool: Arc::downgrade(tx_pool) as Weak<_> }
}

/// Returns an instance of [`TransactionPoolExt`] bound to the given `block_hash`.
///
/// Transactions that are being submitted by this instance will be submitted with `block_hash`
/// as context for validation.
pub fn offchain_transaction_pool(&self, block_hash: Block::Hash) -> TransactionPoolExt {
TransactionPoolExt::new(OffchainTransactionPool { pool: self.pool.clone(), block_hash })
}
}

/// Wraps a `pool` and `block_hash` to implemented [`sp_core::offchain::TransactionPool`].
struct OffchainTransactionPool<Block: BlockT> {
block_hash: Block::Hash,
pool: Weak<dyn OffchainSubmitTransaction<Block>>,
}

impl<Block: BlockT> sp_core::offchain::TransactionPool for OffchainTransactionPool<Block> {
fn submit_transaction(&mut self, extrinsic: Vec<u8>) -> Result<(), ()> {
let extrinsic = match codec::Decode::decode(&mut &extrinsic[..]) {
Ok(t) => t,
Err(e) => {
log::error!(
target: LOG_TARGET,
"Failed to decode extrinsic in `OffchainTransactionPool::submit_transaction`: {e:?}"
);

return Err(())
},
};

self.pool.upgrade().ok_or(())?.submit_at(self.block_hash, extrinsic)
}
}

/// Wrapper functions to keep the API backwards compatible over the wire for the old RPC spec.
mod v1_compatible {
use serde::{Deserialize, Deserializer, Serialize, Serializer};
Expand Down
14 changes: 9 additions & 5 deletions client/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ use std::{
use graph::{ExtrinsicHash, IsValidator};
use sc_transaction_pool_api::{
error::Error as TxPoolError, ChainEvent, ImportNotificationStream, MaintainedTransactionPool,
PoolFuture, PoolStatus, ReadyTransactions, TransactionFor, TransactionPool, TransactionSource,
TransactionStatusStreamFor, TxHash,
OffchainTransactionPoolFactory, PoolFuture, PoolStatus, ReadyTransactions, TransactionFor,
TransactionPool, TransactionSource, TransactionStatusStreamFor, TxHash,
};
use sp_core::traits::SpawnEssentialNamed;
use sp_runtime::{
Expand Down Expand Up @@ -418,7 +418,7 @@ where

fn submit_local(
&self,
at: &BlockId<Self::Block>,
at: Block::Hash,
xt: sc_transaction_pool_api::LocalTransactionFor<Self>,
) -> Result<Self::Hash, Self::Error> {
use sp_runtime::{
Expand All @@ -427,7 +427,11 @@ where

let validity = self
.api
.validate_transaction_blocking(at, TransactionSource::Local, xt.clone())?
.validate_transaction_blocking(
&BlockId::hash(at),
TransactionSource::Local,
xt.clone(),
)?
.map_err(|e| {
Self::Error::Pool(match e {
TransactionValidityError::Invalid(i) => TxPoolError::InvalidTransaction(i),
Expand All @@ -438,7 +442,7 @@ where
let (hash, bytes) = self.pool.validated_pool().api().hash_and_length(&xt);
let block_number = self
.api
.block_id_to_number(at)?
.block_id_to_number(&BlockId::hash(at))?
.ok_or_else(|| error::Error::BlockIdConversion(format!("{:?}", at)))?;

let validated = ValidatedTransaction::valid_at(
Expand Down