Skip to content

Commit

Permalink
feat!: configs control preregistration and Eigenlayer support
Browse files Browse the repository at this point in the history
  • Loading branch information
Tjemmmic committed Jan 30, 2025
1 parent 8778ef9 commit 2fb7831
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 57 deletions.
46 changes: 0 additions & 46 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ members = [
"blueprints/*",
"crates/*",
]
exclude = [
"blueprints/incredible-squaring-symbiotic",
"blueprints/examples",
]

[workspace.package]
authors = ["Tangle Network"]
Expand Down
25 changes: 19 additions & 6 deletions blueprints/incredible-squaring-eigenlayer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@ sol!(
);

#[tokio::test(flavor = "multi_thread")]
#[allow(clippy::needless_return)]
async fn test_eigenlayer_incredible_squaring_blueprint() {
run_eigenlayer_incredible_squaring_test(false, 1).await;
}

#[tokio::test(flavor = "multi_thread")]
async fn test_eigenlayer_pre_register_incredible_squaring_blueprint() {
run_eigenlayer_incredible_squaring_test(true, 1).await;
}

async fn run_eigenlayer_incredible_squaring_test(pre_register: bool, expected_responses: usize) {
setup_log();

// Initialize test harness
Expand All @@ -48,7 +56,6 @@ async fn test_eigenlayer_incredible_squaring_blueprint() {
let task_manager_address = deploy_task_manager(&harness).await;

// Spawn Task Spawner and Task Response Listener
let num_successful_responses_required = 3;
let successful_responses = Arc::new(Mutex::new(0));
let successful_responses_clone = successful_responses.clone();
let response_listener_address =
Expand Down Expand Up @@ -91,14 +98,20 @@ async fn test_eigenlayer_incredible_squaring_blueprint() {
let x_square_eigen = XsquareEigenEventHandler::new(contract.clone(), eigen_client_context);

let mut test_env = EigenlayerBLSTestEnv::new(
EigenlayerBLSConfig::new(Default::default(), Default::default()),
EigenlayerBLSConfig::new(Default::default(), Default::default())
.with_pre_registration(pre_register),
env.clone(),
)
.unwrap();
test_env.add_job(initialize_task);
test_env.add_job(x_square_eigen);
test_env.add_background_service(aggregator_context);

if pre_register {
// Run the runner once to register, since pre-registration is enabled
test_env.run_runner().await.unwrap();
}

tokio::spawn(async move {
test_env.run_runner().await.unwrap();
});
Expand All @@ -110,7 +123,7 @@ async fn test_eigenlayer_incredible_squaring_blueprint() {
let timeout_duration = Duration::from_secs(300);
let result = wait_for_responses(
successful_responses.clone(),
num_successful_responses_required,
expected_responses,
timeout_duration,
)
.await;
Expand All @@ -123,13 +136,13 @@ async fn test_eigenlayer_incredible_squaring_blueprint() {

match result {
Ok(Ok(())) => {
info!("Test completed successfully with {num_successful_responses_required} tasks responded to.");
info!("Test completed successfully with {expected_responses} tasks responded to.");
}
_ => {
panic!(
"Test failed with {} successful responses out of {} required",
successful_responses_clone.lock().unwrap(),
num_successful_responses_required
expected_responses
);
}
}
Expand Down
6 changes: 6 additions & 0 deletions crates/runners/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub trait BlueprintConfig: Send + Sync + 'static {
async fn requires_registration(&self, _env: &GadgetConfiguration) -> Result<bool, RunnerError> {
Ok(true)
}
/// Controls whether the runner should exit after registration
///
/// Returns true if the runner should exit after registration, false if it should continue
fn should_pre_register(&self) -> bool {
true // By default, runners exit after registration
}
}

impl BlueprintConfig for () {}
6 changes: 4 additions & 2 deletions crates/runners/core/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ impl BlueprintRunner {
pub async fn run(&mut self) -> Result<(), Error> {
if self.config.requires_registration(&self.env).await? {
self.config.register(&self.env).await?;
// Return from pre-registration
return Ok(());
if self.config.should_pre_register() {
// Return from pre-registration
return Ok(());
}
}

let mut background_receivers = Vec::new();
Expand Down
15 changes: 15 additions & 0 deletions crates/runners/eigenlayer/src/bls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,26 @@ use gadget_utils::evm::get_provider_http;
pub struct EigenlayerBLSConfig {
earnings_receiver_address: Address,
delegation_approver_address: Address,
pre_register: bool,
}

impl EigenlayerBLSConfig {
/// Creates a new [`EigenlayerBLSConfig`] with the given earnings receiver and delegation approver addresses.
///
/// By default, a Runner created with this config will exit after registration (Pre-Registration). To change
/// this, use [`EigenlayerBLSConfig::with_pre_registration`] passing false.
pub fn new(earnings_receiver_address: Address, delegation_approver_address: Address) -> Self {
Self {
earnings_receiver_address,
delegation_approver_address,
pre_register: true,
}
}

pub fn with_pre_registration(mut self, pre_register: bool) -> Self {
self.pre_register = pre_register;
self
}
}

#[async_trait::async_trait]
Expand All @@ -45,6 +56,10 @@ impl BlueprintConfig for EigenlayerBLSConfig {
async fn requires_registration(&self, env: &GadgetConfiguration) -> Result<bool, Error> {
requires_registration_bls_impl(env).await
}

fn should_pre_register(&self) -> bool {
self.pre_register
}
}

async fn requires_registration_bls_impl(env: &GadgetConfiguration) -> Result<bool, Error> {
Expand Down
23 changes: 21 additions & 2 deletions crates/runners/tangle/src/tangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,35 @@ impl Default for PriceTargets {
#[derive(Clone, Default)]
pub struct TangleConfig {
pub price_targets: PriceTargets,
pub pre_register: bool,
}

impl TangleConfig {
pub fn new(price_targets: PriceTargets) -> Self {
Self {
price_targets,
pre_register: true,
}
}

pub fn with_pre_register(mut self, pre_register: bool) -> Self {
self.pre_register = pre_register;
self
}
}

#[async_trait::async_trait]
impl BlueprintConfig for TangleConfig {
async fn register(&self, env: &GadgetConfiguration) -> Result<(), Error> {
register_impl(self.price_targets.clone(), vec![], env).await
}

async fn requires_registration(&self, env: &GadgetConfiguration) -> Result<bool, Error> {
requires_registration_impl(env).await
}

async fn register(&self, env: &GadgetConfiguration) -> Result<(), Error> {
register_impl(self.clone().price_targets, vec![], env).await
fn should_pre_register(&self) -> bool {
self.pre_register
}
}

Expand Down
5 changes: 4 additions & 1 deletion crates/testing-utils/tangle/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ impl TangleTestHarness {
0
};

let config =
TangleConfig::new(PriceTargets::default()).with_pre_register(!automatic_registration);

// Create and spawn test environment
let test_env = TangleTestEnv::new(TangleConfig::default(), self.env().clone())?;
let test_env = TangleTestEnv::new(config, self.env().clone())?;

Ok((test_env, service_id, blueprint_id))
}
Expand Down

0 comments on commit 2fb7831

Please sign in to comment.