31 releases (17 breaking)
0.25.0 | Mar 5, 2023 |
---|---|
0.23.0 | Feb 19, 2023 |
0.16.0 | Dec 21, 2022 |
0.9.0 | Feb 10, 2021 |
0.8.0-alpha.5 | Mar 24, 2020 |
#1197 in Magic Beans
2,302 downloads per month
Used in 2 crates
795KB
16K
SLoC
Basic implementation of block-authoring logic.
Example
// The first step is to create a `ProposerFactory`.
let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
// From this factory, we create a `Proposer`.
let proposer = proposer_factory.init(
&client.header(client.chain_info().genesis_hash).unwrap().unwrap(),
);
// The proposer is created asynchronously.
let proposer = futures::executor::block_on(proposer).unwrap();
// This `Proposer` allows us to create a block proposition.
// The proposer will grab transactions from the transaction pool, and put them into the block.
let future = proposer.propose(
Default::default(),
Default::default(),
Duration::from_secs(2),
);
// We wait until the proposition is performed.
let block = futures::executor::block_on(future).unwrap();
println!("Generated block: {:?}", block.block);
License: GPL-3.0-or-later WITH Classpath-exception-2.0
lib.rs
:
Basic implementation of block-authoring logic.
Example
# use sc_basic_authorship::ProposerFactory;
# use sp_consensus::{Environment, Proposer};
# use sp_runtime::generic::BlockId;
# use std::{sync::Arc, time::Duration};
# use substrate_test_runtime_client::{
# runtime::{Extrinsic, Transfer}, AccountKeyring,
# DefaultTestClientBuilderExt, TestClientBuilderExt,
# };
# use sc_transaction_pool::{BasicPool, FullChainApi};
# let client = Arc::new(substrate_test_runtime_client::new());
# let spawner = sp_core::testing::TaskExecutor::new();
# let txpool = BasicPool::new_full(
# Default::default(),
# true.into(),
# None,
# spawner.clone(),
# client.clone(),
# );
// The first step is to create a `ProposerFactory`.
let mut proposer_factory = ProposerFactory::new(
spawner,
client.clone(),
txpool.clone(),
None,
None,
);
// From this factory, we create a `Proposer`.
let proposer = proposer_factory.init(
&client.header(client.chain_info().genesis_hash).unwrap().unwrap(),
);
// The proposer is created asynchronously.
let proposer = futures::executor::block_on(proposer).unwrap();
// This `Proposer` allows us to create a block proposition.
// The proposer will grab transactions from the transaction pool, and put them into the block.
let future = proposer.propose(
Default::default(),
Default::default(),
Duration::from_secs(2),
None,
);
// We wait until the proposition is performed.
let block = futures::executor::block_on(future).unwrap();
println!("Generated block: {:?}", block.block);
Dependencies
~45–85MB
~1.5M SLoC