Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement runners #11

Merged
merged 12 commits into from
Dec 18, 2024
95 changes: 95 additions & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ gadget-event-listeners-tangle = { version = "0.1.0", path = "./crates/event-list
gadget-stores = { version = "0.1.0", path = "./crates/stores", default-features = false }
gadget-store-local-database = { version = "0.1.0", path = "./crates/stores/local-database", default-features = false }

# Runners
gadget-runners = { version = "0.1.0", path = "./crates/runners", default-features = false }
gadget-runner-core = { version = "0.1.0", path = "./crates/runners/core", default-features = false }
gadget-runner-eigenlayer = { version = "0.1.0", path = "./crates/runners/eigenlayer", default-features = false }
gadget-runner-tangle = { version = "0.1.0", path = "./crates/runners/tangle", default-features = false }
gadget-runner-symbiotic = { version = "0.1.0", path = "./crates/runners/symbiotic", default-features = false }

# SDK
gadget-blueprint-serde = { version = "0.3.1", path = "./crates/blueprint-serde", default-features = false }
gadget-config = { version = "0.1.0", path = "./crates/config", default-features = false }
Expand All @@ -69,6 +76,7 @@ gadget-tokio-std = { version = "0.1.0", path = "./crates/tokio-std", default-fea

# Utilities
gadget-utils = { version = "0.1.0", path = "./crates/utils", default-features = false }
gadget-utils-core = { version = "0.1.0", path = "./crates/utils/core", default-features = false }
gadget-utils-evm = { version = "0.1.0", path = "./crates/utils/evm", default-features = false }
gadget-utils-eigenlayer = { version = "0.1.0", path = "./crates/utils/eigenlayer", default-features = false }
gadget-utils-tangle = { version = "0.1.0", path = "./crates/utils/tangle", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions crates/clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ std = [
"gadget-client-networking?/std",
"gadget-client-tangle?/std",
]
no_std = ["gadget-client-tangle?/no_std"]

eigenlayer = ["gadget-client-eigenlayer"]
evm = ["gadget-client-evm"]
networking = ["gadget-client-networking"]
Expand Down
5 changes: 2 additions & 3 deletions crates/clients/eigenlayer/src/eigenlayer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::{EigenlayerClientError, Result};
use crate::error::Result;
use alloy_primitives::{Address, Bytes};
use alloy_provider::{Provider, ProviderBuilder, RootProvider};
use alloy_provider::{Provider, RootProvider};
use alloy_pubsub::PubSubFrontend;
use alloy_transport::BoxTransport;
use eigensdk::{client_avsregistry::reader::AvsRegistryReader, utils::get_ws_provider};
Expand Down Expand Up @@ -336,7 +336,6 @@ impl EigenlayerClient {
block_number: u32,
index: alloy_primitives::U256,
) -> Result<alloy_primitives::Uint<96, 2>> {
use alloy_provider::Provider as _;
let contract_addresses = self.config.protocol_settings.eigenlayer()?;
let provider = self.get_provider_http();
let registry_coordinator = eigensdk::utils::registrycoordinator::RegistryCoordinator::new(
Expand Down
1 change: 0 additions & 1 deletion crates/clients/eigenlayer/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use gadget_std::string::ParseError;
use gadget_std::string::String;
use thiserror::Error;

#[derive(Debug, Error)]
Expand Down
3 changes: 3 additions & 0 deletions crates/clients/evm/src/instrumented_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ use alloy_rpc_types_eth::{
use alloy_transport::{TransportError, TransportResult};
use alloy_transport_http::{Client, Http};
use gadget_rpc_calls::RpcCallsMetrics as RpcCallsCollector;
use gadget_std::boxed::Box;
use gadget_std::string::String;
use gadget_std::string::ToString;
use gadget_std::time::Instant;
use gadget_std::vec::Vec;
use hex;
use thiserror::Error;
use url::Url;
Expand Down
1 change: 1 addition & 0 deletions crates/clients/tangle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod tangle;

use async_trait::async_trait;
use auto_impl::auto_impl;
use gadget_std::boxed::Box;

#[async_trait]
#[auto_impl(Arc)]
Expand Down
3 changes: 2 additions & 1 deletion crates/clients/tangle/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::error::{Result, TangleClientError};
use crate::error::Result;
use crate::Client;
use gadget_std::boxed::Box;
use gadget_std::sync::Arc;
use gadget_std::time::Duration;
use gadget_tokio_std::mutex_ext::TokioMutexExt;
Expand Down
2 changes: 2 additions & 0 deletions crates/clients/tangle/src/services.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::error::TangleClientError;
use crate::error::{Result, TangleDispatchError};
use gadget_std::string::ToString;
use gadget_std::{vec, vec::Vec};
use subxt::backend::BlockRef;
use subxt::utils::AccountId32;
use subxt::utils::H256;
Expand Down
4 changes: 1 addition & 3 deletions crates/clients/tangle/src/tangle.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::error::{Result, TangleClientError};
use crate::error::Result;
use gadget_config::GadgetConfiguration;
use subxt::utils::AccountId32;
use tangle_subxt::tangle_testnet_runtime::api;
use tangle_subxt::tangle_testnet_runtime::api::runtime_types::pallet_multi_asset_delegation::types::operator::OperatorMetadata;
use sp_core::Encode;
use subxt::Config;

pub struct TangleClient {
pub config: GadgetConfiguration,
Expand Down
1 change: 0 additions & 1 deletion crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ keystore = []

# Testing features
test-utils = ["std"]

1 change: 1 addition & 0 deletions crates/config/src/context_config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_variables, dead_code)]
use super::*;
use gadget_std::fmt::Debug;
use gadget_std::str::FromStr;
Expand Down
1 change: 1 addition & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_variables, unreachable_code)]
use gadget_std::fmt::Debug;
use gadget_std::string::{String, ToString};

Expand Down
7 changes: 5 additions & 2 deletions crates/config/src/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use super::*;
#[cfg(any(feature = "eigenlayer", feature = "symbiotic"))]
use alloy_primitives::{address, Address};
use core::fmt::Debug;
use serde::{Deserialize, Serialize};

#[cfg(feature = "eigenlayer")]
use alloy_primitives::address;
#[cfg(any(feature = "eigenlayer", feature = "symbiotic"))]
use alloy_primitives::Address;

/// The protocol on which a gadget will be executed.
#[derive(Default, Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
#[cfg_attr(
Expand Down
1 change: 0 additions & 1 deletion crates/crypto/bn254/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ ark-bn254 = { workspace = true, features = ["scalar_field", "curve"] }
ark-ec = { workspace = true }
ark-ff = { workspace = true }
ark-serialize = { workspace = true }
# rust-bls-bn254 = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true, features = ["alloc"] }
thiserror = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions crates/event-listeners/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
gadget-std = { workspace = true }
async-trait = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }

[features]
Expand Down
15 changes: 7 additions & 8 deletions crates/event-listeners/core/src/exponential_backoff.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use gadget_std::iter::Iterator;
use gadget_std::time::Duration;
use gadget_std::u64::MAX as U64_MAX;

/// A retry strategy driven by exponential back-off.
///
Expand All @@ -22,7 +21,7 @@ impl ExponentialBackoff {
pub fn from_millis(base: u64) -> ExponentialBackoff {
ExponentialBackoff {
current: base,
base: base,
base,
factor: 1u64,
max_delay: None,
}
Expand Down Expand Up @@ -53,7 +52,7 @@ impl Iterator for ExponentialBackoff {
let duration = if let Some(duration) = self.current.checked_mul(self.factor) {
Duration::from_millis(duration)
} else {
Duration::from_millis(U64_MAX)
Duration::from_millis(u64::MAX)
};

// check if we reached max delay
Expand All @@ -66,7 +65,7 @@ impl Iterator for ExponentialBackoff {
if let Some(next) = self.current.checked_mul(self.base) {
self.current = next;
} else {
self.current = U64_MAX;
self.current = u64::MAX;
}

Some(duration)
Expand All @@ -93,11 +92,11 @@ fn returns_some_exponential_base_2() {

#[test]
fn saturates_at_maximum_value() {
let mut s = ExponentialBackoff::from_millis(U64_MAX - 1);
let mut s = ExponentialBackoff::from_millis(u64::MAX - 1);

assert_eq!(s.next(), Some(Duration::from_millis(U64_MAX - 1)));
assert_eq!(s.next(), Some(Duration::from_millis(U64_MAX)));
assert_eq!(s.next(), Some(Duration::from_millis(U64_MAX)));
assert_eq!(s.next(), Some(Duration::from_millis(u64::MAX - 1)));
assert_eq!(s.next(), Some(Duration::from_millis(u64::MAX)));
assert_eq!(s.next(), Some(Duration::from_millis(u64::MAX)));
}

#[test]
Expand Down
12 changes: 9 additions & 3 deletions crates/event-listeners/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ pub mod testing;
use async_trait::async_trait;
use exponential_backoff::ExponentialBackoff;
use gadget_std::iter::Take;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum Error {
#[error("Initializable event handler error: {0}")]
EventHandler(String),
}

/// The [`EventListener`] trait defines the interface for event listeners.
#[async_trait]
Expand All @@ -26,7 +33,6 @@ pub fn get_exponential_backoff<const N: usize>() -> Take<ExponentialBackoff> {

#[async_trait]
pub trait InitializableEventHandler {
async fn init_event_handler(
&self,
) -> Option<tokio::sync::oneshot::Receiver<Result<(), crate::Error>>>;
async fn init_event_handler(&self)
-> Option<tokio::sync::oneshot::Receiver<Result<(), Error>>>;
}
20 changes: 8 additions & 12 deletions crates/event-listeners/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
pub fn add(left: u64, right: u64) -> u64 {
left + right
}
pub use gadget_event_listeners_core as core;

#[cfg(test)]
mod tests {
use super::*;
#[cfg(feature = "evm")]
pub use gadget_event_listeners_evm as evm;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
#[cfg(feature = "tangle")]
pub use gadget_event_listeners_tangle as tangle;

#[cfg(feature = "periodic")]
pub use gadget_event_listeners_periodic as periodic;
2 changes: 0 additions & 2 deletions crates/event-listeners/tangle/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use gadget_std::sync::atomic::{AtomicBool, Ordering};
use gadget_std::sync::Arc;
use subxt::backend::StreamOfResults;
use subxt_core::events::{EventDetails, StaticEvent};
use subxt_core::utils::AccountId32;
use tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_primitives::services::field::Field;
use tangle_subxt::tangle_testnet_runtime::api::services::calls::types::call::{Job, ServiceId};
use tangle_subxt::tangle_testnet_runtime::api::services::events::job_called;
use tangle_subxt::tangle_testnet_runtime::api::services::events::job_called::CallId;
Expand Down
2 changes: 2 additions & 0 deletions crates/keystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ evm = [
tangle = [
"substrate",
"ecdsa",
"sr25519-schnorrkel",
"zebra",
]

tangle-bls = [
Expand Down
2 changes: 2 additions & 0 deletions crates/keystore/src/keystore/backends/bn254.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::*;
use crate::error::Result;
use gadget_crypto::bn254_crypto::{ArkBlsBn254Public, ArkBlsBn254Secret, ArkBlsBn254Signature};
use gadget_std::string::String;

#[async_trait::async_trait]
pub trait Bn254Backend: Send + Sync {
Expand Down
1 change: 1 addition & 0 deletions crates/keystore/src/keystore/backends/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use alloy_primitives::{Address, B256};
use alloy_signer_local::PrivateKeySigner;
use alloy_signer_local::{coins_bip39::English, MnemonicBuilder};
use gadget_crypto::KeyType;
use gadget_std::string::ToString;
use serde::de::DeserializeOwned;

#[async_trait::async_trait]
Expand Down
Loading
Loading