Skip to content

Commit

Permalink
include FrontierBlockImport when doing manual sealing (#134)
Browse files Browse the repository at this point in the history
* include FrontierBlockImport when doing manual sealing to store ethereum block_hash and transactions into AuxStore

* fix
  • Loading branch information
ermalkaleci authored Sep 20, 2020
1 parent b75f492 commit b48c834
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
28 changes: 17 additions & 11 deletions template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;

pub enum ConsensusResult {
Aura((
Aura(
sc_consensus_aura::AuraBlockImport<
Block,
FullClient,
Expand All @@ -39,8 +39,8 @@ pub enum ConsensusResult {
AuraPair
>,
sc_finality_grandpa::LinkHalf<Block, FullClient, FullSelectChain>
)),
ManualSeal
),
ManualSeal(FrontierBlockImport<Block, Arc<FullClient>, FullClient>)
}

pub fn new_partial(config: &Configuration, manual_seal: bool) -> Result<
Expand Down Expand Up @@ -71,16 +71,22 @@ pub fn new_partial(config: &Configuration, manual_seal: bool) -> Result<
.map_err(Into::into)
.map_err(sp_consensus::error::Error::InherentData)?;

let frontier_block_import = FrontierBlockImport::new(
client.clone(),
client.clone(),
true,
);

let import_queue = sc_consensus_manual_seal::import_queue(
Box::new(client.clone()),
Box::new(frontier_block_import.clone()),
&task_manager.spawn_handle(),
config.prometheus_registry(),
);

return Ok(sc_service::PartialComponents {
client, backend, task_manager, import_queue, keystore, select_chain, transaction_pool,
inherent_data_providers,
other: ConsensusResult::ManualSeal
other: ConsensusResult::ManualSeal(frontier_block_import)
})
}

Expand Down Expand Up @@ -113,7 +119,7 @@ pub fn new_partial(config: &Configuration, manual_seal: bool) -> Result<
Ok(sc_service::PartialComponents {
client, backend, task_manager, import_queue, keystore, select_chain, transaction_pool,
inherent_data_providers,
other: ConsensusResult::Aura((aura_block_import, grandpa_link))
other: ConsensusResult::Aura(aura_block_import, grandpa_link)
})
}

Expand All @@ -126,7 +132,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result<TaskManager,
} = new_partial(&config, manual_seal)?;

let (network, network_status_sinks, system_rpc_tx, network_starter) = match consensus_result {
ConsensusResult::ManualSeal => {
ConsensusResult::ManualSeal(_) => {
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
Expand All @@ -139,7 +145,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result<TaskManager,
finality_proof_provider: None,
})?
},
ConsensusResult::Aura((_, _)) => {
ConsensusResult::Aura(_, _) => {
sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
Expand Down Expand Up @@ -203,7 +209,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result<TaskManager,
})?;

match consensus_result {
ConsensusResult::ManualSeal => {
ConsensusResult::ManualSeal(block_import) => {
if role.is_authority() {
let env = sc_basic_authorship::ProposerFactory::new(
client.clone(),
Expand All @@ -214,7 +220,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result<TaskManager,
// Background authorship future
let authorship_future = manual_seal::run_manual_seal(
manual_seal::ManualSealParams {
block_import: client.clone(),
block_import,
env,
client: client.clone(),
pool: transaction_pool.pool().clone(),
Expand All @@ -230,7 +236,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result<TaskManager,
}
log::info!("Manual Seal Ready");
},
ConsensusResult::Aura((aura_block_import, grandpa_link)) => {
ConsensusResult::Aura(aura_block_import, grandpa_link) => {
if role.is_authority() {
let proposer = sc_basic_authorship::ProposerFactory::new(
client.clone(),
Expand Down
11 changes: 11 additions & 0 deletions ts-tests/tests/test-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ describeWithFrontier("Frontier RPC (Block)", `simple-specs.json`, (context) => {
expect(block.timestamp).to.be.a("number");
});

step("get block by hash", async function() {
const latest_block = await context.web3.eth.getBlock("latest");
const block = await context.web3.eth.getBlock(latest_block.hash);
expect(block.hash).to.be.eq(latest_block.hash);
});

step("get block by number", async function() {
const block = await context.web3.eth.getBlock(1);
expect(block).not.null;
});

it.skip("should include previous block hash as parent", async function () {
this.timeout(15000);
await createAndFinalizeBlock(context.web3);
Expand Down
9 changes: 9 additions & 0 deletions ts-tests/tests/test-contract-methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ describeWithFrontier("Frontier RPC (Contract Methods)", `simple-specs.json`, (co
await createAndFinalizeBlock(context.web3);
});

it("get transaction by hash", async () => {
const latestBlock = await context.web3.eth.getBlock("latest");
expect(latestBlock.transactions.length).to.equal(1);

const tx_hash = latestBlock.transactions[0];
const tx = await context.web3.eth.getTransaction(tx_hash);
expect(tx.hash).to.equal(tx_hash);
});

it("should return contract method result", async function () {
const contract = new context.web3.eth.Contract([TEST_CONTRACT_ABI], FIRST_CONTRACT_ADDRESS, {
from: GENESIS_ACCOUNT,
Expand Down

0 comments on commit b48c834

Please sign in to comment.