From 68ea8e63d85071769cc13472a8c0d9b0d541667b Mon Sep 17 00:00:00 2001 From: shekohex Date: Wed, 27 Nov 2024 20:57:00 +0200 Subject: [PATCH] chore(gadget-sdk)!: update to latest tangle (#503) * chore: update to latest tangle-subxt * fix: support for MBSM Revision * fixUpdate the example of the ISQ * chore: add dummy test for the CI * chore: Apply suggestions from code review Co-authored-by: Alex <69764315+Serial-ATA@users.noreply.github.com> * chore: Update default value and metadata alias * chore: fmt * chore: clippy --------- Co-authored-by: Alex <69764315+Serial-ATA@users.noreply.github.com> --- Cargo.lock | 4 +- Cargo.toml | 2 +- blueprint-manager/src/lib.rs | 8 +++ blueprint-metadata/src/lib.rs | 29 ++++++---- .../src/tangle/transactions.rs | 5 +- blueprint-test-utils/src/test_ext.rs | 3 +- .../contracts/lib/forge-std | 2 +- blueprints/incredible-squaring/Cargo.toml | 1 + .../contracts/lib/forge-std | 2 +- macros/blueprint-proc-macro-core/src/lib.rs | 21 +++++++ macros/context-derive/src/services.rs | 58 ++++++++++--------- sdk/src/contexts/services.rs | 44 ++++++++++++-- sdk/src/lib.rs | 2 - sdk/src/runners/tangle.rs | 1 + 14 files changed, 133 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0744cb5..6682e943 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12150,9 +12150,9 @@ dependencies = [ [[package]] name = "tangle-subxt" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd92b3c29823ab4db09ed7030222dbcdf94d5edbb384b5fca4eb76f646ead9c" +checksum = "f66ffe3bf80b02cebae9b5d8b0932becf5638179e4cf7b9c12d0c753b51c5e64" dependencies = [ "parity-scale-codec", "scale-info", diff --git a/Cargo.toml b/Cargo.toml index b3705d0f..9d83e536 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ cargo-tangle = { path = "./cli", version = "0.3.0" } cargo_metadata = { version = "0.18.1" } # Tangle-related dependencies -tangle-subxt = { version = "0.5.0", default-features = false } +tangle-subxt = { version = "0.6.0", default-features = false } subxt-signer = { version = "0.37.0", default-features = false } subxt = { version = "0.37.0", default-features = false } subxt-core = { version = "0.37.0", default-features = false } diff --git a/blueprint-manager/src/lib.rs b/blueprint-manager/src/lib.rs index 12774529..7168062c 100644 --- a/blueprint-manager/src/lib.rs +++ b/blueprint-manager/src/lib.rs @@ -6,3 +6,11 @@ pub mod protocols; pub mod sdk; pub mod sources; pub use executor::run_blueprint_manager; + +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +} diff --git a/blueprint-metadata/src/lib.rs b/blueprint-metadata/src/lib.rs index 5fff780c..60efe587 100644 --- a/blueprint-metadata/src/lib.rs +++ b/blueprint-metadata/src/lib.rs @@ -8,7 +8,8 @@ use std::{ use cargo_metadata::{Metadata, Package}; use gadget_blueprint_proc_macro_core::{ BlueprintManager, FieldType, Gadget, GadgetSource, GadgetSourceFetcher, JobDefinition, - NativeGadget, ServiceBlueprint, ServiceMetadata, TestFetcher, + MasterBlueprintServiceManagerRevision, NativeGadget, ServiceBlueprint, ServiceMetadata, + TestFetcher, }; use rustdoc_types::{Crate, Id, Item, ItemEnum, Module}; @@ -41,7 +42,7 @@ impl Config { let crate_name = std::env::var("CARGO_PKG_NAME").expect("Failed to get package name"); let package = find_package(&metadata, &crate_name); let gadget = generate_gadget(package); - let manager = extract_blueprint_manager(package); + let metadata = extract_blueprint_metadata(package); eprintln!("Generating blueprint.json to {:?}", output_file); let blueprint = ServiceBlueprint { metadata: ServiceMetadata { @@ -57,7 +58,8 @@ impl Config { license: std::env::var("CARGO_PKG_LICENSE").map(Into::into).ok(), }, jobs, - manager, + manager: metadata.manager, + master_manager_revision: metadata.master_blueprint_service_manager_revision, registration_params: hooks .iter() .find_map(|hook| match hook { @@ -280,25 +282,32 @@ fn extract_metadata() -> Metadata { #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] struct BlueprintMetadata { manager: BlueprintManager, + #[serde(alias = "master_revision", default)] + master_blueprint_service_manager_revision: MasterBlueprintServiceManagerRevision, } -fn extract_blueprint_manager(package: &Package) -> BlueprintManager { +fn extract_blueprint_metadata(package: &Package) -> BlueprintMetadata { let Some(blueprint) = package.metadata.get("blueprint") else { eprintln!("No blueprint metadata found in the Cargo.toml."); eprintln!("For more information, see:"); eprintln!(""); // TODO(@shekohex): make this hard error - return BlueprintManager::Evm(Default::default()); + return BlueprintMetadata { + manager: BlueprintManager::Evm("".into()), + master_blueprint_service_manager_revision: + MasterBlueprintServiceManagerRevision::Latest, + }; }; - let metadata: BlueprintMetadata = + let mut metadata: BlueprintMetadata = serde_json::from_value(blueprint.clone()).expect("Failed to deserialize gadget."); - match metadata.manager { + match &mut metadata.manager { BlueprintManager::Evm(manager) => { - let path = resolve_evm_contract_path_by_name(&manager); - BlueprintManager::Evm(path.display().to_string()) + let path = resolve_evm_contract_path_by_name(manager); + *manager = path.display().to_string(); } _ => unreachable!("Unsupported blueprint manager"), - } + }; + metadata } /// Generates the metadata for the gadget. diff --git a/blueprint-test-utils/src/tangle/transactions.rs b/blueprint-test-utils/src/tangle/transactions.rs index 36a57b0b..310e688a 100644 --- a/blueprint-test-utils/src/tangle/transactions.rs +++ b/blueprint-test-utils/src/tangle/transactions.rs @@ -50,11 +50,12 @@ pub async fn register_blueprint( blueprint_id: u64, preferences: Preferences, registration_args: RegistrationArgs, + value: u128, ) -> Result<(), Box> { info!("Registering to blueprint {blueprint_id} to become an operator ..."); let call = api::tx() .services() - .register(blueprint_id, preferences, registration_args); + .register(blueprint_id, preferences, registration_args, value); let res = client .tx() .sign_and_submit_then_watch_default(&call, account_id) @@ -99,6 +100,7 @@ pub async fn request_service( user: &TanglePairSigner, blueprint_id: u64, test_nodes: Vec, + value: u128, ) -> Result<(), Box> { let call = api::tx().services().request( blueprint_id, @@ -107,6 +109,7 @@ pub async fn request_service( Default::default(), vec![0], 1000, + value, ); let res = client .tx() diff --git a/blueprint-test-utils/src/test_ext.rs b/blueprint-test-utils/src/test_ext.rs index 3ae44daa..4fd0dc67 100644 --- a/blueprint-test-utils/src/test_ext.rs +++ b/blueprint-test-utils/src/test_ext.rs @@ -188,6 +188,7 @@ pub async fn new_test_ext_blueprint_manager< blueprint_id, preferences, registration_args.clone(), + 0, ) .await { @@ -215,7 +216,7 @@ pub async fn new_test_ext_blueprint_manager< info!("Requesting service for blueprint ID {blueprint_id} using Alice's keys ..."); if let Err(err) = - transactions::request_service(&client, handles[0].sr25519_id(), blueprint_id, all_nodes) + transactions::request_service(&client, handles[0].sr25519_id(), blueprint_id, all_nodes, 0) .await { error!("Failed to register service: {err}"); diff --git a/blueprints/incredible-squaring-eigenlayer/contracts/lib/forge-std b/blueprints/incredible-squaring-eigenlayer/contracts/lib/forge-std index 1eea5bae..1de6eecf 160000 --- a/blueprints/incredible-squaring-eigenlayer/contracts/lib/forge-std +++ b/blueprints/incredible-squaring-eigenlayer/contracts/lib/forge-std @@ -1 +1 @@ -Subproject commit 1eea5bae12ae557d589f9f0f0edae2faa47cb262 +Subproject commit 1de6eecf821de7fe2c908cc48d3ab3dced20717f diff --git a/blueprints/incredible-squaring/Cargo.toml b/blueprints/incredible-squaring/Cargo.toml index ec765f71..53811def 100644 --- a/blueprints/incredible-squaring/Cargo.toml +++ b/blueprints/incredible-squaring/Cargo.toml @@ -39,3 +39,4 @@ std = [] [package.metadata.blueprint] manager = { Evm = "IncredibleSquaringBlueprint" } +master_revision = "Latest" diff --git a/blueprints/incredible-squaring/contracts/lib/forge-std b/blueprints/incredible-squaring/contracts/lib/forge-std index 1eea5bae..1de6eecf 160000 --- a/blueprints/incredible-squaring/contracts/lib/forge-std +++ b/blueprints/incredible-squaring/contracts/lib/forge-std @@ -1 +1 @@ -Subproject commit 1eea5bae12ae557d589f9f0f0edae2faa47cb262 +Subproject commit 1de6eecf821de7fe2c908cc48d3ab3dced20717f diff --git a/macros/blueprint-proc-macro-core/src/lib.rs b/macros/blueprint-proc-macro-core/src/lib.rs index 1a0eea11..f32e5ced 100644 --- a/macros/blueprint-proc-macro-core/src/lib.rs +++ b/macros/blueprint-proc-macro-core/src/lib.rs @@ -101,6 +101,11 @@ pub struct ServiceBlueprint<'a> { pub metadata: ServiceMetadata<'a>, /// The blueprint manager that will be used to manage the blueprints lifecycle. pub manager: BlueprintManager, + /// The Revision number of the Master Blueprint Service Manager. + /// + /// If not sure what to use, use `MasterBlueprintServiceManagerRevision::default()` which will use + /// the latest revision available. + pub master_manager_revision: MasterBlueprintServiceManagerRevision, /// The job definitions that are available in this service. pub jobs: Vec>, /// The parameters that are required for the service registration. @@ -147,6 +152,22 @@ pub struct JobDefinition<'a> { pub result: Vec, } +/// Master Blueprint Service Manager Revision. +#[derive(Default, PartialEq, Eq, Clone, Copy, Debug, serde::Serialize, serde::Deserialize)] +#[non_exhaustive] +pub enum MasterBlueprintServiceManagerRevision { + /// Use Whatever the latest revision available on-chain. + /// + /// This is the default value. + #[default] + Latest, + + /// Use a specific revision number. + /// + /// Note: Must be already deployed on-chain. + Specific(u32), +} + #[derive(Default, Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct JobMetadata<'a> { /// The Job name. diff --git a/macros/context-derive/src/services.rs b/macros/context-derive/src/services.rs index 4b3e8ea0..18022087 100644 --- a/macros/context-derive/src/services.rs +++ b/macros/context-derive/src/services.rs @@ -30,8 +30,7 @@ pub fn generate_context_impl( Output = Result< gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_primitives::services::ServiceBlueprint, gadget_sdk::ext::subxt::Error - > - >{ + >> { use gadget_sdk::ext::subxt; use gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api; @@ -61,9 +60,7 @@ pub fn generate_context_impl( fn current_blueprint_owner( &self, client: &gadget_sdk::ext::subxt::OnlineClient, - ) -> impl core::future::Future< - Output = Result, - > { + ) -> impl core::future::Future> { use gadget_sdk::ext::subxt; use gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api; async move { @@ -95,12 +92,12 @@ pub fn generate_context_impl( ) -> impl core::future::Future< Output = Result< Vec<( - gadget_sdk::ext::subxt::utils::AccountId32, - gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::sp_arithmetic::per_things::Percent, - )>, + gadget_sdk::ext::subxt::utils::AccountId32, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::sp_arithmetic::per_things::Percent, + )>, gadget_sdk::ext::subxt::Error > - >{ + > { use gadget_sdk::ext::subxt; use gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api; @@ -144,14 +141,16 @@ pub fn generate_context_impl( Vec<( gadget_sdk::ext::subxt::utils::AccountId32, gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::runtime_types::pallet_multi_asset_delegation::types::operator::OperatorMetadata< - gadget_sdk::ext::subxt::utils::AccountId32, // delegator - gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::force_created::AssetId, + gadget_sdk::ext::subxt::utils::AccountId32, gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::burned::Balance, - >, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::accounts_destroyed::AssetId, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxDelegations, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxOperatorBlueprints, + > )>, gadget_sdk::ext::subxt::Error > - >{ + > { use gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api; async move { @@ -179,13 +178,15 @@ pub fn generate_context_impl( ) -> Result< Option< gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::runtime_types::pallet_multi_asset_delegation::types::operator::OperatorMetadata< - gadget_sdk::ext::subxt::utils::AccountId32, // delegator - gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::force_created::AssetId, + gadget_sdk::ext::subxt::utils::AccountId32, gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::burned::Balance, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::accounts_destroyed::AssetId, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxDelegations, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxOperatorBlueprints, > >, gadget_sdk::ext::subxt::Error, - >{ + > { use gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api; let storage = client.storage().at_latest().await?; @@ -199,17 +200,21 @@ pub fn generate_context_impl( operators: Vec, ) -> Result< Vec<( - gadget_sdk::ext::subxt::utils::AccountId32, // operator + gadget_sdk::ext::subxt::utils::AccountId32, Option< gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::runtime_types::pallet_multi_asset_delegation::types::delegator::DelegatorMetadata< gadget_sdk::ext::subxt::utils::AccountId32, - gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::force_created::AssetId, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::accounts_destroyed::AssetId, gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::burned::Balance, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxWithdrawRequests, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxDelegations, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxUnstakeRequests, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxDelegatorBlueprints, > > )>, gadget_sdk::ext::subxt::Error, - >{ + > { use gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api; use gadget_sdk::ext::subxt::utils::AccountId32; use gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::force_created::AssetId; @@ -217,10 +222,7 @@ pub fn generate_context_impl( use gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::runtime_types::pallet_multi_asset_delegation::types::delegator::DelegatorMetadata; let storage = client.storage().at_latest().await?; - let mut operator_delegations: Vec<( - AccountId32, - Option>, - )> = Vec::new(); + let mut operator_delegations = Vec::new(); for operator in operators { let delegations_storage_key = api::storage() @@ -242,12 +244,16 @@ pub fn generate_context_impl( Option< gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::runtime_types::pallet_multi_asset_delegation::types::delegator::DelegatorMetadata< gadget_sdk::ext::subxt::utils::AccountId32, - gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::force_created::AssetId, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::accounts_destroyed::AssetId, gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::burned::Balance, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxWithdrawRequests, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxDelegations, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxUnstakeRequests, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::MaxDelegatorBlueprints, > >, gadget_sdk::ext::subxt::Error, - >{ + > { use gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api; let storage = client.storage().at_latest().await?; @@ -264,7 +270,7 @@ pub fn generate_context_impl( gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_primitives::services::Service< gadget_sdk::ext::subxt::utils::AccountId32, gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::system::storage::types::number::Number, - gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::force_created::AssetId, + gadget_sdk::ext::tangle_subxt::tangle_testnet_runtime::api::assets::events::accounts_destroyed::AssetId, >, gadget_sdk::ext::subxt::Error, >{ diff --git a/sdk/src/contexts/services.rs b/sdk/src/contexts/services.rs index 05d0329d..6b06d4f5 100644 --- a/sdk/src/contexts/services.rs +++ b/sdk/src/contexts/services.rs @@ -4,10 +4,12 @@ use tangle_subxt::tangle_testnet_runtime::api::runtime_types::sp_arithmetic::per use tangle_subxt::tangle_testnet_runtime::api::runtime_types::pallet_multi_asset_delegation::types::operator::OperatorMetadata; use tangle_subxt::tangle_testnet_runtime::api::assets::events::burned::Balance; use tangle_subxt::tangle_testnet_runtime::api::assets::events::accounts_destroyed::AssetId; +use tangle_subxt::tangle_testnet_runtime::api::runtime_types::tangle_testnet_runtime::{MaxDelegations, MaxDelegatorBlueprints, MaxOperatorBlueprints, MaxUnstakeRequests, MaxWithdrawRequests}; use tangle_subxt::tangle_testnet_runtime::api::system::storage::types::number::Number; use tangle_subxt::tangle_testnet_runtime::api::runtime_types::pallet_multi_asset_delegation::types::delegator::DelegatorMetadata; /// `ServicesContext` trait provides access to the current service and current blueprint from the context. +#[allow(clippy::type_complexity)] pub trait ServicesContext { type Config: subxt::Config; /// Get the current blueprint information from the context. @@ -40,7 +42,13 @@ pub trait ServicesContext { Output = color_eyre::Result< Vec<( subxt::utils::AccountId32, - OperatorMetadata, + OperatorMetadata< + subxt::utils::AccountId32, + Balance, + AssetId, + MaxDelegations, + MaxOperatorBlueprints, + >, )>, subxt::Error, >, @@ -54,7 +62,15 @@ pub trait ServicesContext { operator: subxt::utils::AccountId32, ) -> impl Future< Output = color_eyre::Result< - Option>, + Option< + OperatorMetadata< + subxt::utils::AccountId32, + Balance, + AssetId, + MaxDelegations, + MaxOperatorBlueprints, + >, + >, subxt::Error, >, >; @@ -80,7 +96,17 @@ pub trait ServicesContext { Output = color_eyre::Result< Vec<( subxt::utils::AccountId32, // operator - Option>, + Option< + DelegatorMetadata< + subxt::utils::AccountId32, + AssetId, + Balance, + MaxWithdrawRequests, + MaxDelegations, + MaxUnstakeRequests, + MaxDelegatorBlueprints, + >, + >, )>, subxt::Error, >, @@ -93,7 +119,17 @@ pub trait ServicesContext { operator: subxt::utils::AccountId32, ) -> impl Future< Output = color_eyre::Result< - Option>, + Option< + DelegatorMetadata< + subxt::utils::AccountId32, + AssetId, + Balance, + MaxWithdrawRequests, + MaxDelegations, + MaxUnstakeRequests, + MaxDelegatorBlueprints, + >, + >, subxt::Error, >, >; diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 7d687d50..030fd15c 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -7,9 +7,7 @@ //! Gadget SDK #![cfg_attr(all(not(feature = "std"), not(feature = "wasm")), no_std)] - extern crate alloc; -extern crate core; /// Benchmark Module #[cfg(any(feature = "std", feature = "wasm"))] diff --git a/sdk/src/runners/tangle.rs b/sdk/src/runners/tangle.rs index d6fdda6e..c5448e08 100644 --- a/sdk/src/runners/tangle.rs +++ b/sdk/src/runners/tangle.rs @@ -118,6 +118,7 @@ impl BlueprintConfig for TangleConfig { price_targets: self.price_targets.clone().0, }, Default::default(), + 0, ); // send the tx to the tangle and exit.