This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganise relayer config and add retry logic (#76)
- Loading branch information
1 parent
26728a1
commit 1241ff0
Showing
28 changed files
with
310 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
[workspace.package] | ||
version = "0.2.0-dev" | ||
authors = ["Webb Developers <[email protected]>"] | ||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0" | ||
homepage = "https://webb.tools" | ||
repository = "https://github.com/webb-tools/pallet-eth2-light-client" | ||
edition = "2021" | ||
|
||
[workspace] | ||
members = [ | ||
"pallets/*", | ||
|
@@ -48,7 +56,7 @@ thread = "*" | |
dotenvy = "0.15.7" | ||
rand = { version = "0.7.3", default-features = false } | ||
rand_chacha = { version = "0.3.1", default-features = false } | ||
|
||
backoff = { version = "0.4.0", features = ["tokio"] } | ||
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false } | ||
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
[package] | ||
name = "webb-bls" | ||
version = "0.2.0" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
authors = ["Paul Hauner <[email protected]>, Webb Developers <[email protected]>"] | ||
edition = "2021" | ||
|
||
|
||
[dependencies] | ||
ssz = { package = "webb-eth2-ssz", path = "../ssz", default-features = false } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
[package] | ||
name = "eth-types" | ||
version = "0.1.0" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
authors = ["Near Inc <[email protected]>", "Webb Developers <[email protected]>"] | ||
edition = "2021" | ||
|
||
|
||
[dependencies] | ||
ssz = { package = "webb-eth2-ssz", path = "../ssz", default-features = false } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[package] | ||
name = "webb-eth2-hashing" | ||
version = "0.3.0" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
authors = ["Paul Hauner <[email protected]>, Webb Developers <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
description = "Hashing primitives used in Ethereum 2.0" | ||
|
||
[dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "webb-lc-relay-config" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
authors = { workspace = true } | ||
|
||
[dependencies] | ||
serde = { workspace = true } | ||
eth-rpc-client = { package = "webb-eth-rpc-client", path = "../eth-rpc-client" } | ||
eth2-pallet-init = { package = "webb-eth2-pallet-init", path = "../eth2-pallet-init" } | ||
reqwest = { workspace = true, features = ["blocking", "json"] } | ||
dotenvy = { workspace = true } | ||
toml = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "webb-lc-relayer-context" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
authors = { workspace = true } | ||
|
||
|
||
[dependencies] | ||
# Eth2 Light Client | ||
eth2-pallet-init = { package = "webb-eth2-pallet-init", path = "../eth2-pallet-init" } | ||
lc-relay-config = { package = "webb-lc-relay-config", path = "../lc-relay-config" } | ||
anyhow = { workspace = true } | ||
tracing = { workspace = true } | ||
subxt = { workspace = true } | ||
tokio = { workspace = true, features = ["macros", "rt", "time"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use eth2_pallet_init::config::Config as InitConfig; | ||
use lc_relay_config::RelayConfig; | ||
use subxt::OnlineClient; | ||
use tokio::sync::broadcast; | ||
|
||
/// LightClientRelayerContext contains Relayer's configuration and shutdown signal. | ||
#[derive(Clone)] | ||
pub struct LightClientRelayerContext { | ||
pub lc_relay_config: RelayConfig, | ||
pub lc_init_config: InitConfig, | ||
/// Broadcasts a shutdown signal to all active connections. | ||
/// | ||
/// The initial `shutdown` trigger is provided by the `run` caller. The | ||
/// server is responsible for gracefully shutting down active connections. | ||
/// When a connection task is spawned, it is passed a broadcast receiver | ||
/// handle. When a graceful shutdown is initiated, a `()` value is sent via | ||
/// the broadcast::Sender. Each active connection receives it, reaches a | ||
/// safe terminal state, and completes the task. | ||
notify_shutdown: broadcast::Sender<()>, | ||
} | ||
|
||
impl LightClientRelayerContext { | ||
pub fn new(lc_relay_config: RelayConfig, lc_init_config: InitConfig) -> Self { | ||
let (notify_shutdown, _) = broadcast::channel(2); | ||
Self { lc_relay_config, lc_init_config, notify_shutdown } | ||
} | ||
pub async fn substrate_provider(self) -> anyhow::Result<OnlineClient<subxt::PolkadotConfig>> { | ||
let maybe_client = OnlineClient::<subxt::PolkadotConfig>::from_url( | ||
self.lc_relay_config.substrate_endpoint.clone(), | ||
) | ||
.await; | ||
let client = match maybe_client { | ||
Ok(client) => client, | ||
Err(err) => return Err(err.into()), | ||
}; | ||
Ok(client) | ||
} | ||
/// Returns a broadcast receiver handle for the shutdown signal. | ||
pub fn shutdown_signal(&self) -> Shutdown { | ||
Shutdown::new(self.notify_shutdown.subscribe()) | ||
} | ||
/// Sends a shutdown signal to all subscribed tasks/connections. | ||
pub fn shutdown(&self) { | ||
let _ = self.notify_shutdown.send(()); | ||
} | ||
} | ||
|
||
/// Listens for the server shutdown signal. | ||
/// | ||
/// Shutdown is signalled using a `broadcast::Receiver`. Only a single value is | ||
/// ever sent. Once a value has been sent via the broadcast channel, the server | ||
/// should shutdown. | ||
/// | ||
/// The `Shutdown` struct listens for the signal and tracks that the signal has | ||
/// been received. Callers may query for whether the shutdown signal has been | ||
/// received or not. | ||
#[derive(Debug)] | ||
pub struct Shutdown { | ||
/// `true` if the shutdown signal has been received | ||
shutdown: bool, | ||
|
||
/// The receive half of the channel used to listen for shutdown. | ||
notify: broadcast::Receiver<()>, | ||
} | ||
|
||
impl Shutdown { | ||
/// Create a new `Shutdown` backed by the given `broadcast::Receiver`. | ||
pub fn new(notify: broadcast::Receiver<()>) -> Shutdown { | ||
Shutdown { shutdown: false, notify } | ||
} | ||
|
||
/// Receive the shutdown notice, waiting if necessary. | ||
pub async fn recv(&mut self) { | ||
// If the shutdown signal has already been received, then return | ||
// immediately. | ||
if self.shutdown { | ||
return | ||
} | ||
|
||
// Cannot receive a "lag error" as only one value is ever sent. | ||
let _ = self.notify.recv().await; | ||
|
||
// Remember that the signal has been received. | ||
self.shutdown = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
[package] | ||
name = "webb-merkle-proof" | ||
version = "0.2.0" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
authors = ["Michael Sproul <[email protected]>", "Webb Developers <[email protected]>"] | ||
edition = "2021" | ||
|
||
[dependencies] | ||
eth2-hashing = { package = "webb-eth2-hashing", path = "../eth2-hashing", default-features = false, features = ["zero_hash_cache"] } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
[package] | ||
name = "webb-safe-arith" | ||
version = "0.1.0" | ||
authors = ["Michael Sproul <[email protected]>"] | ||
edition = "2021" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
[package] | ||
name = "webb-eth2-serde-utils" | ||
version = "0.1.1" | ||
authors = ["Paul Hauner <[email protected]", "Michael Sproul <[email protected]>"] | ||
edition = "2021" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
authors = ["Paul Hauner <[email protected]", "Michael Sproul <[email protected]>", "Webb Developers <[email protected]>"] | ||
description = "Serialization and deserialization utilities useful for JSON representations of Ethereum 2.0 types." | ||
license = "Apache-2.0" | ||
|
||
|
||
|
||
[dependencies] | ||
serde = { workspace = true, features = ["derive"], optional = true } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
[package] | ||
name = "webb-eth2-ssz-derive" | ||
version = "0.3.0" | ||
authors = ["Paul Hauner <[email protected]>"] | ||
edition = "2021" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
license = { workspace = true } | ||
authors = ["Paul Hauner <[email protected]>", "Webb Developers <[email protected]>"] | ||
description = "Procedural derive macros to accompany the eth2_ssz crate." | ||
license = "Apache-2.0" | ||
|
||
[lib] | ||
name = "ssz_derive" | ||
|
Oops, something went wrong.