Skip to content

Commit 5e360a7

Browse files
notleshJoshOrndorffcrystalinCrystalintgmichel
authored
Bump Frontier and Friends Pre v0.5 (paritytech#176)
* Update substrate -> c9d9365 (master) * Update frontier -> 7e6f52e (v0.5-hotfixes) * Update Cumulus and re-resolve some dependency versions * Use same polkadot commit as Cumulus * Resolve dependencies related to primitive-types * Add SS58Prefix chain id to runtime config * Implement query_fee_details from TransactionPayment trait * Ensure frontier always points to v0.5-hotfixes * Let cargo update Cargo.lock * Move pubsub and rpc "hotfixes" back to frontier * Update cumulus and polkadot * correct hotfixes branch * Made it to compile errors in actual moonbeam code :) * runtime compiles * new logger structure * Fix call to start_collator * Totally not-dubious changes to Cargo.lock * Impl new query_fee_details fn * Revert "Impl new query_fee_details fn" This reverts commit 8c943f7279a9a6a3f453eb9e16beba3c501bd62b. * Update rpc and standalone to use txn graph * Cargo.lock changes again * Add graph to FullDeps @ parachain service * Run cargo fmt * Appease editorconfig * add web3api server * Spawn background task for pending transactions * Add log subscription tests * Add pending transaction RPC test * Prefer spaces over tabs in typescript tests * s/describeWithFrontier/describeWithMoonbeam/ * Post-merge clean up * prettier * rustfmt * fix test formatting * Fixes tests for pallet stake * Update runtime/Cargo.toml Co-authored-by: Joshy Orndorff <[email protected]> * reapply de-alias * restore missing cargo dep * Fixes new tests * Fixes some tests * Fix test-pending-pool * Fix test-subscription * Update Cargo.lock * Improves polkadot api test (WIP) * Better polkadot tests Co-authored-by: Joshy Orndorff <[email protected]> Co-authored-by: crystalin <[email protected]> Co-authored-by: Joshy Orndorff <[email protected]> Co-authored-by: Crystalin <[email protected]> Co-authored-by: tgmichel <[email protected]>
1 parent 05f9625 commit 5e360a7

File tree

20 files changed

+1946
-3039
lines changed

20 files changed

+1946
-3039
lines changed

Cargo.lock

Lines changed: 923 additions & 850 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/parachain/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrat
6262
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
6363
sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "master" }
6464

65-
fc-rpc = { git = "https://github.com/purestake/frontier", branch = "v0.4-hotfixes" }
66-
fp-rpc = { git = "https://github.com/purestake/frontier", branch = "v0.4-hotfixes" }
67-
fc-consensus = { git = "https://github.com/purestake/frontier", branch = "v0.4-hotfixes" }
65+
evm = { package = "pallet-evm", git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
66+
ethereum = { package = "pallet-ethereum", git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
67+
68+
fc-consensus = { git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
69+
fp-consensus = { git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
70+
fc-rpc-core = { git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
71+
fc-rpc = { git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
6872

6973
author-inherent = { path = "../../pallets/author-inherent"}
7074

node/parachain/src/command.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use moonbeam_runtime::Block;
2424
use parity_scale_codec::Encode;
2525
use polkadot_parachain::primitives::AccountIdConversion;
2626
use sc_cli::{
27-
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
28-
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
27+
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, InitLoggerParams,
28+
KeystoreParams, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
2929
};
3030
use sc_service::{
3131
config::{BasePath, PrometheusConfig},
@@ -206,7 +206,10 @@ pub fn run() -> Result<()> {
206206
})
207207
}
208208
Some(Subcommand::ExportGenesisState(params)) => {
209-
sc_cli::init_logger("", sc_tracing::TracingReceiver::Log, None, false)?;
209+
sc_cli::init_logger(InitLoggerParams {
210+
tracing_receiver: sc_tracing::TracingReceiver::Log,
211+
..Default::default()
212+
})?;
210213

211214
let block: Block = generate_genesis_block(&load_spec(
212215
&params.chain.clone().unwrap_or_default(),
@@ -228,7 +231,10 @@ pub fn run() -> Result<()> {
228231
Ok(())
229232
}
230233
Some(Subcommand::ExportGenesisWasm(params)) => {
231-
sc_cli::init_logger("", sc_tracing::TracingReceiver::Log, None, false)?;
234+
sc_cli::init_logger(InitLoggerParams {
235+
tracing_receiver: sc_tracing::TracingReceiver::Log,
236+
..Default::default()
237+
})?;
232238

233239
let raw_wasm_blob =
234240
extract_genesis_wasm(&cli.load_spec(&params.chain.clone().unwrap_or_default())?)?;

node/parachain/src/service.rs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ use cumulus_service::{
1919
prepare_node_config, start_collator, start_full_node, StartCollatorParams, StartFullNodeParams,
2020
};
2121
use fc_consensus::FrontierBlockImport;
22+
use fc_rpc_core::types::PendingTransactions;
2223
use moonbeam_runtime::{opaque::Block, RuntimeApi};
2324
use parity_scale_codec::Encode;
2425
use polkadot_primitives::v0::CollatorPair;
26+
use sc_client_api::BlockchainEvents;
2527
use sc_executor::native_executor_instance;
2628
pub use sc_executor::NativeExecutor;
2729
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
2830
use sp_core::{Pair, H160};
2931
use sp_inherents::InherentDataProviders;
3032
use sp_runtime::traits::BlakeTwo256;
3133
use sp_trie::PrefixedMemoryDB;
32-
use std::sync::Arc;
34+
use std::{
35+
collections::HashMap,
36+
sync::{Arc, Mutex},
37+
};
3338
// Our native executor instance.
3439
native_executor_instance!(
3540
pub Executor,
@@ -75,7 +80,10 @@ pub fn new_partial(
7580
(),
7681
sp_consensus::import_queue::BasicQueue<Block, PrefixedMemoryDB<BlakeTwo256>>,
7782
sc_transaction_pool::FullPool<Block, FullClient>,
78-
FrontierBlockImport<Block, Arc<FullClient>, FullClient>,
83+
(
84+
FrontierBlockImport<Block, Arc<FullClient>, FullClient>,
85+
PendingTransactions,
86+
),
7987
>,
8088
sc_service::Error,
8189
> {
@@ -94,6 +102,8 @@ pub fn new_partial(
94102
client.clone(),
95103
);
96104

105+
let pending_transactions: PendingTransactions = Some(Arc::new(Mutex::new(HashMap::new())));
106+
97107
let frontier_block_import = FrontierBlockImport::new(client.clone(), client.clone(), true);
98108

99109
let import_queue = cumulus_consensus::import_queue::import_queue(
@@ -113,7 +123,7 @@ pub fn new_partial(
113123
transaction_pool,
114124
inherent_data_providers,
115125
select_chain: (),
116-
other: frontier_block_import,
126+
other: (frontier_block_import, pending_transactions),
117127
};
118128

119129
Ok(params)
@@ -167,7 +177,7 @@ where
167177
let transaction_pool = params.transaction_pool.clone();
168178
let mut task_manager = params.task_manager;
169179
let import_queue = params.import_queue;
170-
let block_import = params.other;
180+
let (block_import, pending_transactions) = params.other;
171181
let (network, network_status_sinks, system_rpc_tx, start_network) =
172182
sc_service::build_network(sc_service::BuildNetworkParams {
173183
config: &parachain_config,
@@ -187,14 +197,16 @@ where
187197
let client = client.clone();
188198
let pool = transaction_pool.clone();
189199
let network = network.clone();
190-
200+
let pending = pending_transactions.clone();
191201
Box::new(move |deny_unsafe, _| {
192202
let deps = moonbeam_rpc::FullDeps {
193203
client: client.clone(),
194204
pool: pool.clone(),
205+
graph: pool.pool().clone(),
195206
deny_unsafe,
196207
is_authority,
197208
network: network.clone(),
209+
pending_transactions: pending.clone(),
198210
command_sink: None,
199211
};
200212

@@ -218,6 +230,53 @@ where
218230
system_rpc_tx,
219231
})?;
220232

233+
// Spawn Frontier pending transactions maintenance task (as essential, otherwise we leak).
234+
if pending_transactions.is_some() {
235+
use fp_consensus::{ConsensusLog, FRONTIER_ENGINE_ID};
236+
use futures::StreamExt;
237+
use sp_runtime::generic::OpaqueDigestItemId;
238+
239+
const TRANSACTION_RETAIN_THRESHOLD: u64 = 5;
240+
task_manager.spawn_essential_handle().spawn(
241+
"frontier-pending-transactions",
242+
client
243+
.import_notification_stream()
244+
.for_each(move |notification| {
245+
if let Ok(locked) = &mut pending_transactions.clone().unwrap().lock() {
246+
// As pending transactions have a finite lifespan anyway
247+
// we can ignore MultiplePostRuntimeLogs error checks.
248+
let mut frontier_log: Option<_> = None;
249+
for log in notification.header.digest.logs {
250+
let log = log.try_to::<ConsensusLog>(OpaqueDigestItemId::Consensus(
251+
&FRONTIER_ENGINE_ID,
252+
));
253+
if let Some(log) = log {
254+
frontier_log = Some(log);
255+
}
256+
}
257+
258+
let imported_number: u64 = notification.header.number as u64;
259+
260+
if let Some(ConsensusLog::EndBlock {
261+
block_hash: _,
262+
transaction_hashes,
263+
}) = frontier_log
264+
{
265+
// Retain all pending transactions that were not
266+
// processed in the current block.
267+
locked.retain(|&k, _| !transaction_hashes.contains(&k));
268+
}
269+
locked.retain(|_, v| {
270+
// Drop all the transactions that exceeded the given lifespan.
271+
let lifespan_limit = v.at_block + TRANSACTION_RETAIN_THRESHOLD;
272+
lifespan_limit > imported_number
273+
});
274+
}
275+
futures::future::ready(())
276+
}),
277+
);
278+
}
279+
221280
let announce_block = {
222281
let network = network.clone();
223282
Arc::new(move |hash, data| network.announce_block(hash, data))

node/rpc/Cargo.toml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,9 @@ substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate",
2929
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
3030
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
3131
sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "master" }
32+
sc-transaction-graph = { git = "https://github.com/paritytech/substrate", branch = "master" }
3233

33-
fc-rpc = { git = "https://github.com/purestake/frontier", branch = "v0.4-hotfixes" }
34-
fp-rpc = { git = "https://github.com/purestake/frontier", branch = "v0.4-hotfixes" }
34+
fc-rpc-core = { git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
35+
fc-rpc = { git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
36+
fp-rpc = { git = "https://github.com/purestake/frontier", branch = "v0.5-hotfixes" }
3537

36-
# Dependencies I've added for the server hotfixes
37-
ethereum = { version = "0.5", features = ["with-codec"] }
38-
ethereum-types = "0.9.0"
39-
sha3 = "0.8"
40-
sp-io = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
41-
sp-storage = { git = "https://github.com/paritytech/substrate.git", branch = "master" }
42-
fc-rpc-core = { git = "https://github.com/purestake/frontier", branch = "v0.4-hotfixes" }
43-
rlp = "0.4"
44-
fc-consensus = { git = "https://github.com/purestake/frontier", branch = "v0.4-hotfixes" }
45-
log = "0.4.8"

node/rpc/src/lib.rs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616

1717
//! A collection of node-specific RPC methods.
1818
19-
// Our drop-in replacements for Frontier's RPC servers.
20-
mod pubsub_hotfixes;
21-
mod server_hotfixes;
22-
2319
use std::{fmt, sync::Arc};
2420

25-
use fc_rpc::HexEncodedIdProvider;
21+
use fc_rpc_core::types::PendingTransactions;
2622
use jsonrpc_pubsub::manager::SubscriptionManager;
2723
use moonbeam_runtime::{opaque::Block, AccountId, Balance, Hash, Index};
2824
use sc_client_api::{
@@ -33,6 +29,7 @@ use sc_consensus_manual_seal::rpc::{EngineCommand, ManualSeal, ManualSealApi};
3329
use sc_network::NetworkService;
3430
use sc_rpc::SubscriptionTaskExecutor;
3531
use sc_rpc_api::DenyUnsafe;
32+
use sc_transaction_graph::{ChainApi, Pool};
3633
use sp_api::ProvideRuntimeApi;
3734
use sp_block_builder::BlockBuilder;
3835
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
@@ -52,24 +49,28 @@ pub struct LightDeps<C, F, P> {
5249
}
5350

5451
/// Full client dependencies.
55-
pub struct FullDeps<C, P> {
52+
pub struct FullDeps<C, P, A: ChainApi> {
5653
/// The client instance to use.
5754
pub client: Arc<C>,
5855
/// Transaction pool instance.
5956
pub pool: Arc<P>,
57+
/// Graph pool instance.
58+
pub graph: Arc<Pool<A>>,
6059
/// Whether to deny unsafe calls
6160
pub deny_unsafe: DenyUnsafe,
6261
/// The Node authority flag
6362
pub is_authority: bool,
6463
/// Network service
6564
pub network: Arc<NetworkService<Block, Hash>>,
65+
/// Ethereum pending transactions.
66+
pub pending_transactions: PendingTransactions,
6667
/// Manual seal command sink
6768
pub command_sink: Option<futures::channel::mpsc::Sender<EngineCommand<Hash>>>,
6869
}
6970

7071
/// Instantiate all Full RPC extensions.
71-
pub fn create_full<C, P, BE>(
72-
deps: FullDeps<C, P>,
72+
pub fn create_full<C, P, BE, A>(
73+
deps: FullDeps<C, P, A>,
7374
subscription_task_executor: SubscriptionTaskExecutor,
7475
) -> jsonrpc_core::IoHandler<sc_rpc::Metadata>
7576
where
@@ -82,25 +83,27 @@ where
8283
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
8384
C::Api: BlockBuilder<Block>,
8485
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
86+
A: ChainApi<Block = Block> + 'static,
8587
C::Api: fp_rpc::EthereumRuntimeRPCApi<Block>,
8688
<C::Api as sp_api::ApiErrorExt>::Error: fmt::Debug,
8789
P: TransactionPool<Block = Block> + 'static,
8890
{
89-
use fc_rpc::{NetApi, NetApiServer, Web3Api, Web3ApiServer};
91+
use fc_rpc::{
92+
EthApi, EthApiServer, EthPubSubApi, EthPubSubApiServer, HexEncodedIdProvider, NetApi,
93+
NetApiServer, Web3Api, Web3ApiServer,
94+
};
9095
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
9196
use substrate_frame_rpc_system::{FullSystem, SystemApi};
92-
// Our drop in replacements for the Eth APIs. These can be removed after
93-
// https://github.com/paritytech/frontier/pull/199 lands
94-
use pubsub_hotfixes::{EthPubSubApi, EthPubSubApiServer};
95-
use server_hotfixes::{EthApi, EthApiServer};
9697

9798
let mut io = jsonrpc_core::IoHandler::default();
9899
let FullDeps {
99100
client,
100101
pool,
102+
graph,
101103
deny_unsafe,
102104
is_authority,
103105
network,
106+
pending_transactions,
104107
command_sink,
105108
} = deps;
106109

@@ -113,14 +116,16 @@ where
113116
client.clone(),
114117
)));
115118

116-
// We currently don't want to support signing in the node. Users should prefer external tools
117-
// for transaction signing. So just pass in an empty vector of signers.
119+
// TODO: are we supporting signing?
118120
let signers = Vec::new();
121+
119122
io.extend_with(EthApiServer::to_delegate(EthApi::new(
120123
client.clone(),
121124
pool.clone(),
125+
graph,
122126
moonbeam_runtime::TransactionConverter,
123127
network.clone(),
128+
pending_transactions.clone(),
124129
signers,
125130
is_authority,
126131
)));
@@ -130,21 +135,24 @@ where
130135
)));
131136
io.extend_with(Web3ApiServer::to_delegate(Web3Api::new(client.clone())));
132137
io.extend_with(EthPubSubApiServer::to_delegate(EthPubSubApi::new(
133-
pool,
134-
client,
135-
network,
138+
pool.clone(),
139+
client.clone(),
140+
network.clone(),
136141
SubscriptionManager::<HexEncodedIdProvider>::with_id_provider(
137142
HexEncodedIdProvider::default(),
138143
Arc::new(subscription_task_executor),
139144
),
140145
)));
141146

142-
if let Some(command_sink) = command_sink {
143-
io.extend_with(
144-
// We provide the rpc handler with the sending end of the channel to allow the rpc
145-
// send EngineCommands to the background block authorship task.
146-
ManualSealApi::to_delegate(ManualSeal::new(command_sink)),
147-
);
147+
match command_sink {
148+
Some(command_sink) => {
149+
io.extend_with(
150+
// We provide the rpc handler with the sending end of the channel to allow the rpc
151+
// send EngineCommands to the background block authorship task.
152+
ManualSealApi::to_delegate(ManualSeal::new(command_sink)),
153+
);
154+
}
155+
_ => {}
148156
}
149157

150158
io

0 commit comments

Comments
 (0)