PoW
The basic-pow node demonstrates how to add a custom consensus engine to a Substrate-based blockchain. In this example, the node uses a minimal proof-of-work consensus engine to reach agreement over the blockchain. This guide introduces a few core principles for working with consensus engines.
Use cases
Launch a chain that uses a proof-of-work consensus engine.
Upgrade a chain from an authority-based consensus engine to a proof-of-work consensus engine.
Steps preview
Define a full node that uses proof-of-work consensus.
Create an import queue for data providers.
Define the
proposerandworkerfunctions.Define a light client service.
Define a full node using sc_consensus_pow and sc_service
In src/service.rs, make a function called new_full that defines PartialComponents and PowBlockImport:
let pow_block_import = sc_consensus_pow::PowBlockImport::new(
client.clone(),
client.clone(),
sha3pow::MinimalSha3Algorithm,
0, // check inherents starting at block 0
select_chain.clone(),
inherent_data_providers.clone(),
can_author_with,
);
let import_queue = sc_consensus_pow::import_queue(
Box::new(pow_block_import.clone()),
None,
sha3pow::MinimalSha3Algorithm, // provide it with references to our client
inherent_data_providers.clone(),
&task_manager.spawn_handle(),
config.prometheus_registry(),
)?;Create an import queue
Define your node's inherents by using InherentDataProviders in a function that defines the providers of your POW system:
Define the proposer and worker
In the new_full function, define proposer:
Let the task manager spawn it:
Examples
Resources
Last updated