From 0bb2d1c3cd36a337d5a532d974565d90a6a74f7d Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Fri, 18 Sep 2020 20:30:32 +0200 Subject: [PATCH 1/2] include FrontierBlockImport when doing manual sealing to store ethereum block_hash and transactions into AuxStore --- template/node/src/service.rs | 27 +++++++++++++++---------- ts-tests/tests/test-block.ts | 11 ++++++++++ ts-tests/tests/test-contract-methods.ts | 9 +++++++++ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/template/node/src/service.rs b/template/node/src/service.rs index a45a84c582..7d62c428f3 100644 --- a/template/node/src/service.rs +++ b/template/node/src/service.rs @@ -27,7 +27,7 @@ type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; pub enum ConsensusResult { - Aura(( + Aura( sc_consensus_aura::AuraBlockImport< Block, FullClient, @@ -39,8 +39,8 @@ pub enum ConsensusResult { AuraPair >, sc_finality_grandpa::LinkHalf - )), - ManualSeal + ), + ManualSeal(FrontierBlockImport, FullClient>) } pub fn new_partial(config: &Configuration, manual_seal: bool) -> Result< @@ -71,8 +71,13 @@ 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() + ); + 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(), ); @@ -80,7 +85,7 @@ pub fn new_partial(config: &Configuration, manual_seal: bool) -> Result< 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) }) } @@ -112,7 +117,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) }) } @@ -125,7 +130,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result { + ConsensusResult::ManualSeal(_) => { sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -138,7 +143,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result { + ConsensusResult::Aura(_, _) => { sc_service::build_network(sc_service::BuildNetworkParams { config: &config, client: client.clone(), @@ -202,7 +207,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result { + ConsensusResult::ManualSeal(block_import) => { if role.is_authority() { let env = sc_basic_authorship::ProposerFactory::new( client.clone(), @@ -213,7 +218,7 @@ pub fn new_full(config: Configuration, manual_seal: bool) -> Result Result { + ConsensusResult::Aura(aura_block_import, grandpa_link) => { if role.is_authority() { let proposer = sc_basic_authorship::ProposerFactory::new( client.clone(), diff --git a/ts-tests/tests/test-block.ts b/ts-tests/tests/test-block.ts index 787f23df8d..3c47b13502 100644 --- a/ts-tests/tests/test-block.ts +++ b/ts-tests/tests/test-block.ts @@ -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); diff --git a/ts-tests/tests/test-contract-methods.ts b/ts-tests/tests/test-contract-methods.ts index 525f6bed0f..6b36029f57 100644 --- a/ts-tests/tests/test-contract-methods.ts +++ b/ts-tests/tests/test-contract-methods.ts @@ -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, From 4ffd29fa78c153bb4935e46a4d0e86133f0b0b13 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Fri, 18 Sep 2020 21:14:02 +0200 Subject: [PATCH 2/2] fix --- template/node/src/service.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/template/node/src/service.rs b/template/node/src/service.rs index 5df6ac9cfd..5bc361d11c 100644 --- a/template/node/src/service.rs +++ b/template/node/src/service.rs @@ -73,7 +73,8 @@ pub fn new_partial(config: &Configuration, manual_seal: bool) -> Result< let frontier_block_import = FrontierBlockImport::new( client.clone(), - client.clone() + client.clone(), + true, ); let import_queue = sc_consensus_manual_seal::import_queue(