### Example Blueprint `main.rs` Entry Point Source: https://github.com/tangle-network/docs/blob/main/pages/developers/tangle-avs.mdx This file serves as the entry point for your Actively Validated Service (AVS) node. It sets up the runtime environment, initializes the necessary components, and starts the Blueprint Runner. It handles environment setup, client initialization, router configuration, producer/consumer setup, and background services. ```rust use std::error::Error; use std::sync::Arc; use tokio; use tangle_core::blueprint::{Blueprint, BlueprintRunner}; use tangle_core::config::Config; use tangle_core::network::client::TangleClient; mod blueprint; #[tokio::main] async fn main() -> Result<(), Box> { // 1. Environment Setup let config = Config::load("config.toml")?; // Initialize logger, error handling, etc. // 2. Client Initialization let client = TangleClient::new(&config.rpc_endpoint).await?; // 3. Router Configuration // let router = Router::new(); // 4. Producer Setup // let producers = vec![...]; // 5. Consumer Setup // let consumers = vec![...]; // 6. Background Services // let background_services = vec![...]; // 7. Blueprint Runner // let blueprint_runner = BlueprintRunner::new( // Arc::new(blueprint::MyBlueprint), // Replace with your actual Blueprint implementation // client, // router, // producers, // consumers, // background_services, // ); // blueprint_runner.run().await?; println!("Blueprint runner started (simulated)."); Ok(()) } ``` -------------------------------- ### Install Alertmanager Binaries Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Copies the Alertmanager binary and the amtool utility to the system's executable path, typically /usr/local/bin. This makes the commands available system-wide. ```sh sudo cp ./alertmanager-*.linux-amd64/alertmanager /usr/local/bin/ && sudo cp ./alertmanager-*.linux-amd64/amtool /usr/local/bin/ ``` -------------------------------- ### Example Blueprint Job Definition Source: https://github.com/tangle-network/docs/blob/main/pages/developers/tangle-avs.mdx This file contains the core logic of your Blueprint, including job definitions. Jobs are the main computational tasks that your Blueprint will execute. Here's an example of a simple "Hello World" job. ```rust pub trait Blueprint: Sized { type JobId: Send + Sync + 'static; type JobInput: Send + Sync + 'static; type JobOutput: Send + Sync + 'static; fn run_job(&self, job_id: Self::JobId, input: Self::JobInput) -> Box>>>; } #[derive(Debug, Clone)] pub struct HelloWorldBlueprint; impl Blueprint for HelloWorldBlueprint { type JobId = String; type JobInput = String; type JobOutput = String; fn run_job(&self, _job_id: Self::JobId, input: Self::JobInput) -> Box>>> { Box::new(async move { let greeting = format!("Hello, {}!", input.unwrap_or_else(|| "World".to_string())); Ok(greeting) }) } } ``` -------------------------------- ### Start Alertmanager Service Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Starts the Alertmanager service. This command initiates the Alertmanager process according to the configuration defined in its service file. ```sh sudo systemctl start alertmanager.service ``` -------------------------------- ### Build Project Source: https://github.com/tangle-network/docs/blob/main/pages/developers/tangle-avs.mdx To build your project, run: This command compiles your Rust code and checks for any errors. ```bash cargo build ``` -------------------------------- ### Clone Tangle AVS Repository Source: https://github.com/tangle-network/docs/blob/main/pages/operators/tangle-avs/quickstart.mdx Clones the Tangle AVS repository from GitHub and navigates into the created directory. This is the initial step to obtain the project's source code. ```sh git clone https://github.com/tangle-network/avs.git tangle-avs cd tangle-avs ``` -------------------------------- ### Update Tangle Node Source: https://github.com/tangle-network/docs/blob/main/pages/network/launch.mdx Instructions to download and install the latest Tangle node software from the official GitHub releases page to prepare for mainnet participation. ```bash echo "Visit the releases page on GitHub: https://github.com/tangle-network/tangle/releases" echo "Download and install the latest version of the Tangle node software." ``` -------------------------------- ### Integrate QoS in Main Blueprint Setup Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprint-qos.mdx Demonstrates how to configure and run a Blueprint with the QoS system enabled, including setting up the heartbeat consumer and standard runner components. ```rust #[tokio::main] async fn main() -> Result<(), blueprint_sdk::Error> { let env = BlueprintEnvironment::load()?; // Create your Blueprint's primary context let context = MyContext::new(env.clone()).await?; // Configure QoS system let qos_config = blueprint_qos::default_qos_config(); let heartbeat_consumer = Arc::new(MyHeartbeatConsumer::new()); // Standard Blueprint runner setup with QoS BlueprintRunner::builder(TangleConfig::default(), env) .router(Router::new() .route(JOB_ID, handler.layer(TangleLayer)) .with_context(context)) .producer(producer) .consumer(consumer) .qos_service(qos_config, Some(heartbeat_consumer)) .run() .await } ``` -------------------------------- ### Start System Services Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/prometheus.mdx Starts specified system services. This example demonstrates starting Prometheus, node_exporter, and process-exporter services to begin their operation. ```sh sudo systemctl start prometheus.service ``` ```sh sudo systemctl start node_exporter.service ``` ```sh sudo systemctl start process-exporter.service ``` -------------------------------- ### Shell: Install Foundry Source: https://github.com/tangle-network/docs/blob/main/pages/developers/eigenlayer-avs/incredible-squaring-avs.mdx Installs Foundry, a toolkit for smart contract development, which is often used for local testing and development of EVM-compatible projects. ```Shell curl -L https://foundry.paradigm.xyz | bash foundryup ``` -------------------------------- ### Install Web3 Package (Bash) Source: https://github.com/tangle-network/docs/blob/main/pages/developers/precompiles/utility/non-specific.mdx Installs the Web3 package, a JavaScript library for interacting with Ethereum-compatible blockchains. This is a prerequisite for using the ECRecoverPublicKey precompile example. It requires Node.js and npm to be installed. ```bash npm install --save web3 ``` -------------------------------- ### Rust: Provider Setup Source: https://github.com/tangle-network/docs/blob/main/pages/developers/eigenlayer-avs/incredible-squaring-avs.mdx Initializes an HTTP provider to establish a connection to the Ethereum network. This setup includes enabling a wallet for transacting, which is crucial for AVS operations. ```Rust use alloy::network::Ethereum; // Assuming Ethereum provider use alloy::providers::HttpProvider; use alloy::signers::wallet::LocalWallet; // ... inside main function or setup ... let provider = HttpProvider::::new("http://localhost:8545"); // Example RPC URL let wallet = LocalWallet::from_bytes(b"..."); // Load your private key let provider = provider.with_signer(wallet); ``` -------------------------------- ### Create Prometheus Rules File Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Creates the rules.yml file for Prometheus alerts using sudo touch and opens it with nano for editing. ```sh sudo touch /etc/prometheus/rules.yml sudo nano /etc/prometheus/rules.yml ``` -------------------------------- ### Customize QoS Configuration Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprint-qos.mdx Provides an example of creating a custom `QoSConfig` struct with specific settings for heartbeat, metrics, logging, and Grafana integration. ```rust let qos_config = QoSConfig { heartbeat: Some(HeartbeatConfig { service_id: Some(42), blueprint_id: Some(7), interval_seconds: 60, jitter_seconds: 5, }), metrics: Some(MetricsConfig::default()), loki: Some(LokiConfig::default()), grafana: Some(GrafanaConfig { endpoint: "http://localhost:3000".into(), admin_user: Some("admin".into()), admin_password: Some("admin".into()), folder: None, }), grafana_server: Some(GrafanaServerConfig::default()), loki_server: Some(LokiServerConfig::default()), prometheus_server: Some(PrometheusServerConfig::default()), docker_network: Some("blueprint-network".into()), manage_servers: true, service_id: Some(42), blueprint_id: Some(7), docker_bind_ip: Some("0.0.0.0".into()), }; ``` -------------------------------- ### Run Tangle AVS Tests Source: https://github.com/tangle-network/docs/blob/main/pages/operators/tangle-avs/quickstart.mdx Executes tests for the Tangle AVS against a local testnet. It sets the RUST_LOG environment variable to trace gadget activity and captures test output. ```sh RUST_LOG=gadget=trace cargo test test_full_tangle_avs -- --nocapture ``` -------------------------------- ### Start Tangle Mainnet Node (Shell) Source: https://github.com/tangle-network/docs/blob/main/pages/operators/node-basics/quickstart.mdx Starts the Tangle node and connects it to the Tangle mainnet. This command requires specifying a base path for data storage and a unique name for your node. The '--validator' flag indicates participation as a validator. ```shell ./tangle-default-linux-amd64 \ --base-path \ --chain tangle-mainnet.json \ --name \ --validator \ --telemetry-url "wss://telemetry.polkadot.io/submit/ 1" ``` -------------------------------- ### Create Alertmanager Configuration File Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Creates the alertmanager.yml file for configuring Alertmanager receivers and routes using sudo touch and nano. ```sh sudo touch /etc/alertmanager/alertmanager.yml sudo nano /etc/alertmanager/alertmanager.yml ``` -------------------------------- ### Build Tangle AVS Release Source: https://github.com/tangle-network/docs/blob/main/pages/operators/tangle-avs/quickstart.mdx Builds the Tangle AVS project in release mode using Cargo. This command compiles the Rust code, optimizing it for performance. ```sh cargo build --release ``` -------------------------------- ### Enable Alertmanager Service on Boot Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Configures the Alertmanager service to start automatically when the system boots up. This ensures that Alertmanager is available after a system restart. ```sh sudo systemctl enable alertmanager.service ``` -------------------------------- ### Use Default QoS Configuration Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprint-qos.mdx Illustrates how to initialize the QoS configuration using the default settings provided by the SDK. ```rust let qos_config = blueprint_qos::default_qos_config(); ``` -------------------------------- ### Basic Consumer Setup Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprint-runner/consumers.mdx Demonstrates the basic setup of a Blueprint Runner consumer, including loading the environment, obtaining signing keys, creating a Tangle producer and consumer, and configuring the Blueprint Runner. ```rust let env = BlueprintEnvironment::load()?; let sr25519_signer = env.keystore().first_local::()?; let sr25519_pair = env.keystore().get_secret::(&sr25519_signer)?; let sr25519_signer = TanglePairSigner::new(sr25519_pair.0); let tangle_client = env.tangle_client().await?; let tangle_producer = TangleProducer::finalized_blocks(tangle_client.rpc_client.clone()).await?; let tangle_consumer = TangleConsumer::new(tangle_client.rpc_client.clone(), sr25519_signer); BlueprintRunner::builder(tangle_config, env) .router(router) // Assuming your router is already defined .producer(tangle_producer) .consumer(tangle_consumer) .run() .await?; ``` -------------------------------- ### Clean Up Downloaded Alertmanager Files Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Removes the downloaded Alertmanager archive files and extracted directories from the current working directory. This helps keep the system clean after installation. ```sh rm -rf ./alertmanager* ``` -------------------------------- ### Configure QoS with Builder Pattern Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprint-qos.mdx Demonstrates using the builder pattern to fluently configure the `QoSService` with various options, including heartbeat, metrics, and server management. ```rust let qos_service = QoSServiceBuilder::new() .with_heartbeat_config(HeartbeatConfig { service_id: Some(service_id), blueprint_id: Some(blueprint_id), interval_seconds: 60, jitter_seconds: 5, }) .with_heartbeat_consumer(Arc::new(consumer)) .with_metrics_config(MetricsConfig::default()) .with_loki_config(LokiConfig::default()) .with_grafana_config(GrafanaConfig::default()) .with_prometheus_server_config(PrometheusServerConfig { host: "0.0.0.0".into(), port: 9090, ..Default::default() }) .manage_servers(true) .with_ws_rpc_endpoint(ws_endpoint) .with_keystore_uri(keystore_uri) .build()?; ``` -------------------------------- ### Tangle Blueprint CardGrid Component Usage Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprints/introduction.mdx Demonstrates the usage of the CardGrid component to display links and descriptions for Tangle's Blueprint-related resources. This component is used to present navigational cards for developers getting started with the Gadget SDK, Hello World examples, and Eigenlayer AVS integration. ```typescript import CardGrid from "../../../components/CardGrid.tsx" ``` -------------------------------- ### Install Grafana via Homebrew (macOS) Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/grafana.mdx Installs Grafana on macOS using the Homebrew package manager. This command updates Homebrew and then installs the latest Grafana package. ```sh brew update brew install grafana ``` -------------------------------- ### Install Grafana via APT (Linux) Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/grafana.mdx Installs Grafana on Debian/Ubuntu-based Linux systems after adding the Grafana repository. This involves updating the package list and then installing the grafana package. ```sh sudo apt-get install -y apt-transport-https sudo apt-get install -y software-properties-common wget wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - sudo apt update sudo apt install grafana ``` -------------------------------- ### Example P2P Network Usage Source: https://github.com/tangle-network/docs/blob/main/pages/developers/p2p-networking/usage.mdx Demonstrates how to initialize a P2P network, send direct and gossip messages, and receive messages using the `NetworkServiceHandle`. ```rust use blueprint_sdk::networking::service_handle::NetworkServiceHandle; use blueprint_sdk::networking::InstanceMsgPublicKey; use std::collections::HashSet; // Assuming GadgetConfiguration, GadgetError, MessageRouting, ParticipantInfo are defined elsewhere // For example: // struct GadgetConfiguration { ... } // struct GadgetError { ... } // struct NetworkConfig { instance_key_pair: (InstanceMsgPublicKey, /* private key type */) } // struct NetworkServiceHandle { ... } // struct MessageRouting { ... } // struct ParticipantInfo { public_key: InstanceMsgPublicKey, address: /* address type */ } async fn example_usage(config: GadgetConfiguration) -> Result<(), GadgetError> { let allowed_keys: HashSet = HashSet::new(); // Placeholder for actual keys // Create the `NetworkConfig` based on the `GadgetConfiguration` let network_config = config.libp2p_network_config("my/protocol/1.0.0")?; // Start up the network, getting a handle back let network_handle = config.libp2p_start_network(network_config, allowed_keys)?; // Use the handle to receive p2p messages from the network // This loop would typically run in a separate task or managed context // For demonstration, a simplified loop is shown: // loop { // if let Some(msg) = network_handle.next_protocol_message() { // println!("Received message: {:?}", msg); // } // tokio::time::sleep(std::time::Duration::from_millis(100)).await; // } // Use the handle to send p2p messages to the network let p2p_routing_direct = MessageRouting { message_id: 1, round_id: 1, sender: ParticipantInfo { public_key: InstanceMsgPublicKey(/* ... */), address: /* ... */ }, recipient: Some(ParticipantInfo { public_key: InstanceMsgPublicKey(/* ... */), address: /* ... */ }), }; // network_handle.send(p2p_routing_direct, /* ...some bytes (Vec)... */); // Send gossip messages to the network let p2p_routing_gossip = MessageRouting { message_id: 1, round_id: 1, sender: ParticipantInfo { public_key: InstanceMsgPublicKey(/* ... */), address: /* ... */ }, recipient: None, // None indicates a gossip message }; // network_handle.send(p2p_routing_gossip, /* ...some bytes (Vec)... */); Ok(()) } ``` -------------------------------- ### Make Tangle Node Binary Executable (Shell) Source: https://github.com/tangle-network/docs/blob/main/pages/operators/node-basics/quickstart.mdx Grants execute permissions to the downloaded Tangle node binary. This command is essential before you can run the binary. Replace 'tangle-default-linux-amd64' if your downloaded file has a different name. ```shell chmod +x tangle-default-linux-amd64 ``` -------------------------------- ### Deploy Tangle Blueprint to Devnet Source: https://github.com/tangle-network/docs/blob/main/pages/developers/cli/quickstart.mdx Deploy your Tangle Blueprint to a development network. This involves setting environment variables for signing and then executing the deploy command with the `--devnet` flag. ```shell export SIGNER="//Alice" export EVM_SIGNER="0xcb6df9de1efca7a3998a8ead4e02159d5fa99c3e0d4fd6432667390bb4726854" cargo tangle blueprint deploy tangle --devnet ``` -------------------------------- ### Create Alertmanager Systemd Service File Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Defines the systemd service unit for Alertmanager. This script uses `sudo tee` to write the service configuration to `/etc/systemd/system/alertmanager.service`, specifying user, group, execution path, configuration file, storage path, and web URLs. It ensures the service starts after the network is online. ```sh sudo tee /etc/systemd/system/alertmanager.service > /dev/null << EOF [Unit] Description=AlertManager Server Service Wants=network-online.target After=network-online.target [Service] User=alertmanager Group=alertmanager Type=simple ExecStart=/usr/local/bin/alertmanager \ --config.file /etc/alertmanager/alertmanager.yml \ --storage.path /var/lib/alertmanager \ --web.external-url=http://localhost:9093 \ --cluster.advertise-address='0.0.0.0:9093' [Install] WantedBy=multi-user.target EOF ``` -------------------------------- ### Install Grafana Alertmanager Plugin Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/grafana.mdx Installs the 'camptocamp-prometheus-alertmanager-datasource' plugin for Grafana using the grafana-cli tool. This plugin enables Grafana to connect to and visualize data from Prometheus Alertmanager. ```sh sudo grafana-cli plugins install camptocamp-prometheus-alertmanager-datasource ``` -------------------------------- ### Start Development Server Source: https://github.com/tangle-network/docs/blob/main/README.md Starts the local development server for the Tangle Network documentation. This allows you to preview changes in real-time. It's an alias for `yarn start` and `yarn develop`. ```bash yarn dev ``` -------------------------------- ### Create Tangle Blueprint Source: https://github.com/tangle-network/docs/blob/main/pages/developers/cli/quickstart.mdx Use the `cargo tangle blueprint create` command to initialize a new Tangle Blueprint project. Provide a unique name for your blueprint. This command sets up the basic project structure. ```shell cargo tangle blueprint create --name ``` -------------------------------- ### Tangle Client Context Definition Example Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprint-contexts/tangle-client-context.mdx An example demonstrating how to define a context struct that implements the TangleClientContext trait. This setup is the first step in utilizing the context for Tangle network interactions. ```rust #[derive(Debug, Clone)] pub struct MyContext { client: C, } impl TangleClientContext for MyContext { type Client = C; fn client(&self) -> &Self::Client { &self.client } } ``` -------------------------------- ### Manage Grafana Server Service (systemd) Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/grafana.mdx Manages the Grafana server service using systemd commands. This includes reloading the systemd daemon, starting the Grafana server, checking its status, and enabling it to start on boot. ```sh sudo systemctl daemon-reload sudo systemctl start grafana-server systemctl status grafana-server sudo systemctl enable grafana-server ``` -------------------------------- ### Install Dependencies Source: https://github.com/tangle-network/docs/blob/main/README.md Installs all necessary project dependencies using Yarn. This command should be run after cloning the repository and navigating into the project directory. ```bash yarn install ``` -------------------------------- ### Access QoS Service in Context Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprint-qos.mdx Demonstrates how to store and access the QoS service within the Blueprint context. This includes defining the context struct and initializing the QoS service. ```rust #[derive(Clone)] pub struct MyContext { #[config] pub env: BlueprintEnvironment, pub data_dir: PathBuf, pub qos_service: Option> >, pub service_id: u64, pub blueprint_id: u64, } impl MyContext { pub async fn new(env: BlueprintEnvironment) -> Result { // Initialize QoS service let qos_service = initialize_qos(&env)?; Ok(Self { data_dir: env.data_dir.clone().unwrap_or_else(default_data_dir), qos_service: Some(Arc::new(qos_service)), service_id: 42, blueprint_id: 7, env, }) } } // Accessing QoS metrics provider in a job handler pub async fn my_job( Context(ctx): Context, TangleArg(data): TangleArg, ) -> Result> { // Access QoS metrics provider if let Some(qos) = &ctx.qos_service { if let Some(provider) = qos.provider() { let cpu_usage = provider.get_cpu_usage()?; info!("Current CPU usage: {}%", cpu_usage); } } // Job implementation Ok(TangleResult::Success(())) } ``` -------------------------------- ### Download Alertmanager Binaries for Multiple Platforms Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Downloads the Alertmanager release binaries for different operating systems (darwin, linux, windows) and architectures (AMD64, ARM64). This step is crucial for obtaining the necessary executable files. ```sh wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.darwin-amd64.tar.gz ``` ```sh wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.darwin-arm64.tar.gz ``` ```sh wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.linux-amd64.tar.gz ``` ```sh wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.linux-arm64.tar.gz ``` ```sh wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.windows-amd64.tar.gz ``` ```sh wget https://github.com/prometheus/alertmanager/releases/download/v0.24.0/alertmanager-0.24.0.windows-arm64.tar.gz ``` -------------------------------- ### Check Prometheus Configuration Source: https://github.com/tangle-network/docs/blob/main/pages/operators/monitoring/alert-manager.mdx Validates the main Prometheus configuration file using the promtool command. ```sh promtool check config /etc/prometheus/prometheus.yml ``` -------------------------------- ### Basic Router Setup in Rust Source: https://github.com/tangle-network/docs/blob/main/pages/developers/blueprint-runner/routers.mdx Demonstrates the fundamental setup of a router in Rust using the Blueprint SDK. It shows how to build a router, define a route mapping a job ID to a handler, and associate a context with the router. ```rust use blueprint_sdk::runner::BlueprintRunner; use blueprint_sdk::Router; let router = Router::builder() .route(MY_JOB_ID, my_job) .with_context(my_context); ```