Skip to content

Commit

Permalink
Chore/ethy gadget update (#44)
Browse files Browse the repository at this point in the history
* Update ethy-gadget w upstream some upstream changes
* if node is (major) syncing don't participate in ethy
* Memory leak after node finishes syncing with relay chain paritytech/substrate#11604)
* proof threshold is now set by runtime (before it was hard coded)
  • Loading branch information
jordy25519 authored Sep 4, 2022
1 parent 4c802a3 commit 4269476
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 77 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions client/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ pub fn new_full(mut config: Configuration, cli: &Cli) -> Result<TaskManager, Ser
}
};

// derive ethy protocol name
let genesis_hash = client.block_hash(0).ok().flatten().expect("Genesis block exists; qed");
let ethy_protocol_name = ethy_gadget::protocol_standard_name(&genesis_hash, &config.chain_spec);

let _rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
network: network.clone(),
client: client.clone(),
Expand Down Expand Up @@ -412,6 +416,7 @@ pub fn new_full(mut config: Configuration, cli: &Cli) -> Result<TaskManager, Ser
network: network.clone(),
event_proof_sender,
prometheus_registry: prometheus_registry.clone(),
protocol_name: ethy_protocol_name,
_phantom: std::marker::PhantomData,
};
// Start the ETHY bridge gadget.
Expand Down
15 changes: 8 additions & 7 deletions ethy-gadget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[dependencies]
ethabi = { version = "17.1.0" }
futures = "0.3.24"
futures-timer = "3.0.1"
hex = "0.4"
log = "0.4"
parking_lot = "0.12.1"
thiserror = "1.0"

codec = { version = "3.0.0", package = "parity-scale-codec", features = ["derive"] }
libsecp256k1 = { version = "0.6.0" }
prometheus = { package = "substrate-prometheus-endpoint", git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27", version = "0.10.0-dev"}

sc-chain-spec = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-client-api = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-keystore = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-network = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-network-gossip = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-utils = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sp-api = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sp-application-crypto = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sp-arithmetic = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
Expand All @@ -25,15 +30,11 @@ sp-consensus = { git = "https://github.com/futureversecom/substrate", branch = "
sp-core = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sp-keystore = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sp-runtime = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-client-api = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-keystore = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-network = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-network-gossip = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
sc-utils = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }

seed-primitives = { path = "../primitives" }

[dev-dependencies]
sc-network-test = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27", version = "0.8.0" }
substrate-test-runtime-client = { git = "https://github.com/futureversecom/substrate", branch = "polkadot-v0.9.27" }
hex-literal = "*"
strum = { version = "0.23", features = ["derive"] }
55 changes: 36 additions & 19 deletions ethy-gadget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use sc_client_api::{Backend, BlockchainEvents, Finalizer};
use sc_network_gossip::{GossipEngine, Network as GossipNetwork};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_consensus::SyncOracle;
use sp_keystore::SyncCryptoStorePtr;
use sp_runtime::traits::Block;

Expand All @@ -50,23 +51,35 @@ mod worker;

pub mod notification;

/// The p2p protocol name for Eth bridge messages
pub const ETHY_PROTOCOL_NAME: &'static str = "/cennznet/ethy/1";
pub use ethy_protocol_name::standard_name as protocol_standard_name;

pub(crate) mod ethy_protocol_name {
use sc_chain_spec::ChainSpec;

const NAME: &str = "/ethy/1";
/// Name of the notifications protocol used by Ethy.
///
/// Must be registered towards the networking in order for Ethy to properly function.
pub fn standard_name<Hash: AsRef<[u8]>>(
genesis_hash: &Hash,
chain_spec: &Box<dyn ChainSpec>,
) -> std::borrow::Cow<'static, str> {
let chain_prefix = match chain_spec.fork_id() {
Some(fork_id) => format!("/{}/{}", hex::encode(genesis_hash), fork_id),
None => format!("/{}", hex::encode(genesis_hash)),
};
format!("{}{}", chain_prefix, NAME).into()
}
}

/// Returns the configuration value to put in
/// [`sc_network::config::NetworkConfiguration::extra_sets`].
pub fn ethy_peers_set_config() -> sc_network::config::NonDefaultSetConfig {
sc_network::config::NonDefaultSetConfig {
notifications_protocol: ETHY_PROTOCOL_NAME.into(),
max_notification_size: 1024 * 1024,
set_config: sc_network::config::SetConfig {
in_peers: 25,
out_peers: 25,
reserved_nodes: Vec::new(),
non_reserved_mode: sc_network::config::NonReservedPeerMode::Accept,
},
fallback_names: vec![],
}
pub fn ethy_peers_set_config(
protocol_name: std::borrow::Cow<'static, str>,
) -> sc_network::config::NonDefaultSetConfig {
let mut cfg = sc_network::config::NonDefaultSetConfig::new(protocol_name, 1024 * 1024);
cfg.allow_non_reserved(25, 25);
cfg
}

/// A convenience ETHY client trait that defines all the type bounds a ETHY client
Expand Down Expand Up @@ -103,7 +116,7 @@ where
BE: Backend<B>,
C: Client<B, BE>,
C::Api: EthyApi<B>,
N: GossipNetwork<B> + Clone + Send + 'static,
N: GossipNetwork<B> + Clone + SyncOracle + Send + 'static,
{
/// ETHY client
pub client: Arc<C>,
Expand All @@ -117,6 +130,8 @@ where
pub event_proof_sender: notification::EthyEventProofSender,
/// Prometheus metric registry
pub prometheus_registry: Option<Registry>,
/// Chain specific Ethy protocol name. See [`ethy_protocol_name::standard_name`].
pub protocol_name: std::borrow::Cow<'static, str>,
pub _phantom: std::marker::PhantomData<B>,
}

Expand All @@ -129,7 +144,7 @@ where
BE: Backend<B>,
C: Client<B, BE>,
C::Api: EthyApi<B>,
N: GossipNetwork<B> + Clone + Send + 'static,
N: GossipNetwork<B> + Clone + SyncOracle + Sync + Send + 'static,
{
let EthyParams {
client,
Expand All @@ -138,12 +153,13 @@ where
network,
event_proof_sender,
prometheus_registry,
protocol_name,
_phantom: std::marker::PhantomData,
} = ethy_params;

let sync_oracle = network.clone();
let gossip_validator = Arc::new(gossip::GossipValidator::new(Default::default()));
let gossip_engine =
GossipEngine::new(network, ETHY_PROTOCOL_NAME, gossip_validator.clone(), None);
let gossip_engine = GossipEngine::new(network, protocol_name, gossip_validator.clone(), None);

let metrics =
prometheus_registry.as_ref().map(metrics::Metrics::register).and_then(
Expand All @@ -167,9 +183,10 @@ where
gossip_engine,
gossip_validator,
metrics,
sync_oracle,
};

let worker = worker::EthyWorker::<_, _, _>::new(worker_params);
let worker = worker::EthyWorker::<_, _, _, _>::new(worker_params);

worker.run().await
}
Loading

0 comments on commit 4269476

Please sign in to comment.