Skip to content

Commit 9c4e779

Browse files
Tjemmmicdrewstone
andauthored
chore: complete blueprint sdk update (#123)
* fix: update contexts, runner structure, and code links wip * feat: runner docs and examples * chore: prettier * chore: fix * fix: broken link --------- Co-authored-by: Drew Stone <[email protected]>
1 parent 795a0e7 commit 9c4e779

22 files changed

+1020
-193
lines changed

pages/developers/_meta.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const meta: Meta = {
1313
},
1414
"blueprint-sdk": "Introduction",
1515
"blueprint-contexts": "Contexts",
16+
"blueprint-runner": "Blueprint Runner",
1617
"p2p-networking": "P2P Networking",
1718
"tangle-avs": "Build a Tangle Blueprint",
1819
"eigenlayer-avs": "Build an Eigenlayer AVS",

pages/developers/blueprint-contexts/_meta.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { Meta } from "nextra";
22

33
const meta: Meta = {
44
introduction: "Introduction to Contexts",
5-
"keystore-context": "Keystore Context",
5+
"eigenlayer-context": "Eigenlayer Context",
66
"evm-provider-context": "EVM Provider Context",
7+
"keystore-context": "Keystore Context",
8+
"services-context": "Services Context",
79
"tangle-client-context": "Tangle Client Context",
8-
"eigenlayer-context": "Eigenlayer Context",
910
};
1011

1112
export default meta;

pages/developers/blueprint-contexts/eigenlayer-context.mdx

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ The `EigenlayerContext` trait provides access to core Eigenlayer services and fu
3333
- Monitor stake across different quorums
3434

3535
<GithubFileReaderDisplay
36-
url="https://github.com/tangle-network/blueprint/blob/main/crates/contexts/src/eigenlayer.rs"
36+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/contexts/src/instrumented_evm_client.rs"
3737
title="EigenlayerContext Trait Definition"
38-
fromLine={5}
39-
toLine={9}
38+
fromLine={3}
39+
toLine={6}
4040
/>
4141

4242
## Using the Context
@@ -45,37 +45,42 @@ The `EigenlayerContext` trait provides access to core Eigenlayer services and fu
4545

4646
First, define your context struct that implements the `EigenlayerContext` trait:
4747

48-
{/* TODO: Add URL */}
49-
5048
<GithubFileReaderDisplay
51-
url=""
52-
fromLine={39}
53-
toLine={52}
49+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/examples/incredible-squaring-eigenlayer/src/contexts/aggregator.rs"
50+
fromLine={23}
51+
toLine={35}
5452
title="Aggregator Context Definition"
5553
/>
5654

57-
### 2. Use the Context in Jobs
55+
### 2. Implement methods for the context
5856

59-
You can then use this context in your jobs to access Eigenlayer functionality:
57+
You can implement methods for the context to provide custom functionality:
58+
59+
<GithubFileReaderDisplay
60+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/examples/incredible-squaring-eigenlayer/src/contexts/aggregator.rs"
61+
fromLine={245}
62+
toLine={261}
63+
title="Implementing Methods for the Context"
64+
/>
65+
66+
### 3. Use the Context in Jobs
6067

61-
{/* TODO: Add URL */}
68+
You can then use this context in your jobs to access Eigenlayer functionality:
6269

6370
<GithubFileReaderDisplay
64-
url=""
65-
fromLine={13}
66-
toLine={52}
71+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/examples/incredible-squaring-eigenlayer/src/jobs/initialize_task.rs"
72+
fromLine={32}
73+
toLine={35}
6774
title="Using EigenlayerContext in Jobs"
6875
/>
6976

70-
### 3. Instantiate the Context
77+
### 4. Instantiate the Context
7178

7279
Finally, instantiate your context in your main runner:
7380

74-
{/* TODO: Add URL */}
75-
7681
<GithubFileReaderDisplay
77-
url=""
78-
fromLine={27}
79-
toLine={53}
82+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/examples/incredible-squaring-eigenlayer/src/main.rs"
83+
fromLine={39}
84+
toLine={43}
8085
title="Instantiating the Context"
8186
/>

pages/developers/blueprint-contexts/evm-provider-context.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ The `EvmInstrumentedClientContext` trait provides a standardized [alloy-rs](http
1313
The `EvmInstrumentedClientContext` trait provides access to an EVM provider:
1414

1515
<GithubFileReaderDisplay
16-
url="https://github.com/tangle-network/blueprint/blob/main/crates/contexts/src/instrumented_evm_client.rs"
16+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/contexts/src/instrumented_evm_client.rs"
1717
fromLine={3}
18-
toLine={7}
18+
toLine={6}
1919
title="EvmInstrumentedClientContext Trait Definition"
2020
/>
2121

@@ -26,9 +26,9 @@ The `EvmInstrumentedClientContext` trait provides access to an EVM provider:
2626
First, define your context struct that implements the `EvmProviderContext` trait:
2727

2828
<GithubFileReaderDisplay
29-
url="https://github.com/tangle-network/blueprint/blob/main/crates/macros/context-derive/tests/ui/basic.rs"
30-
fromLine={22}
31-
toLine={31}
29+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/macros/context-derive/tests/ui/basic.rs"
30+
fromLine={13}
31+
toLine={22}
3232
title="EVM Provider Context Definition"
3333
/>
3434

@@ -37,8 +37,8 @@ First, define your context struct that implements the `EvmProviderContext` trait
3737
You can then use this context to access EVM provider parameters:
3838

3939
<GithubFileReaderDisplay
40-
url="https://github.com/tangle-network/blueprint/blob/main/crates/macros/context-derive/tests/ui/basic.rs"
41-
fromLine={45}
42-
toLine={45}
40+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/macros/context-derive/tests/ui/basic.rs"
41+
fromLine={36}
42+
toLine={36}
4343
title="Accessing EVM Provider Parameters"
4444
/>

pages/developers/blueprint-contexts/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Introduction to Contexts
44

55
## What is a Context?
66

7-
In the Gadget SDK, a Context holds utilities and dependencies that a job may need that aren't direct inputs. Think of it as a container for all the external resources and services your job requires to function.
7+
In the Blueprint SDK, a Context holds utilities and dependencies that a job may need that aren't direct inputs. Think of it as a container for all the external resources and services your job requires to function.
88

99
A Context can include various elements such as:
1010

pages/developers/blueprint-contexts/keystore-context.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ The `KeystoreContext` trait provides access to a `Keystore` that implements the
1919
- Key Import/Export - Import existing keys and export key data
2020

2121
<GithubFileReaderDisplay
22-
url="https://github.com/tangle-network/blueprint/blob/main/crates/contexts/src/keystore.rs"
22+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/contexts/src/keystore.rs"
2323
fromLine={4}
24-
toLine={8}
24+
toLine={7}
2525
title="KeystoreContext Trait Definition"
2626
/>
2727

@@ -32,9 +32,9 @@ The `KeystoreContext` trait provides access to a `Keystore` that implements the
3232
First, define your context struct that implements the `KeystoreContext` trait:
3333

3434
<GithubFileReaderDisplay
35-
url="https://github.com/tangle-network/blueprint/blob/main/crates/macros/context-derive/tests/ui/basic.rs"
36-
fromLine={22}
37-
toLine={31}
35+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/macros/context-derive/tests/ui/basic.rs"
36+
fromLine={13}
37+
toLine={22}
3838
title="Keystore Context Definition"
3939
/>
4040

@@ -43,8 +43,8 @@ First, define your context struct that implements the `KeystoreContext` trait:
4343
You can then use this context to access the keystore and perform key operations:
4444

4545
<GithubFileReaderDisplay
46-
url="https://github.com/tangle-network/blueprint/blob/main/crates/macros/context-derive/tests/ui/basic.rs"
47-
fromLine={44}
48-
toLine={44}
46+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/macros/context-derive/tests/ui/basic.rs"
47+
fromLine={35}
48+
toLine={35}
4949
title="Accessing Keystore Functionality"
5050
/>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Services Context
3+
---
4+
5+
import GithubFileReaderDisplay from '/components/GithubFileReaderDisplay';
6+
7+
# Services Context
8+
9+
The `ServicesContext` trait provides a standardized interface for interacting with the Tangle network in your Blueprint through a Subxt `OnlineClient` with a PolkadotConfig.
10+
11+
## Overview
12+
13+
The `ServicesContext` trait provides access to a Subxt client that enables:
14+
15+
- Fetching Blueprints - Retrieve Blueprints by ID
16+
- Querying Blueprints - Query Blueprints for an operator
17+
- Retrieving Blueprint Owners - Return the Owner for a Blueprint
18+
- Fetching Service Operators - Return a list of operators for a service
19+
20+
<GithubFileReaderDisplay
21+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/contexts/src/services.rs"
22+
fromLine={3}
23+
toLine={9}
24+
title="ServicesContext Trait Definition"
25+
/>
26+
27+
## Using the Context
28+
29+
### 1. Define Your Context
30+
31+
First, define your context struct that implements the `ServicesContext` trait:
32+
33+
<GithubFileReaderDisplay
34+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/macros/context-derive/tests/ui/basic.rs"
35+
fromLine={13}
36+
toLine={22}
37+
title="Services Context Definition"
38+
/>
39+
40+
### 2. Access Services Client Functionality
41+
42+
You can then use this context to access the services client and interact with Tangle services:
43+
44+
<GithubFileReaderDisplay
45+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/macros/context-derive/tests/ui/basic.rs"
46+
fromLine={38}
47+
toLine={38}
48+
title="Accessing Services Client Functionality"
49+
/>

pages/developers/blueprint-contexts/tangle-client-context.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ The `TangleClientContext` trait provides access to a Subxt client that enables:
1818
- RPC Calls - Make direct RPC calls to Tangle nodes
1919

2020
<GithubFileReaderDisplay
21-
url="https://github.com/tangle-network/blueprint/blob/main/crates/contexts/src/tangle.rs"
21+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/contexts/src/tangle.rs"
2222
fromLine={5}
23-
toLine={10}
23+
toLine={9}
2424
title="TangleClientContext Trait Definition"
2525
/>
2626

@@ -31,9 +31,9 @@ The `TangleClientContext` trait provides access to a Subxt client that enables:
3131
First, define your context struct that implements the `TangleClientContext` trait:
3232

3333
<GithubFileReaderDisplay
34-
url="https://github.com/tangle-network/blueprint/blob/main/crates/macros/context-derive/tests/ui/basic.rs"
35-
fromLine={22}
36-
toLine={31}
34+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/macros/context-derive/tests/ui/basic.rs"
35+
fromLine={13}
36+
toLine={22}
3737
title="Tangle Client Context Definition"
3838
/>
3939

@@ -42,8 +42,8 @@ First, define your context struct that implements the `TangleClientContext` trai
4242
You can then use this context to access the Subxt client and interact with Tangle:
4343

4444
<GithubFileReaderDisplay
45-
url="https://github.com/tangle-network/blueprint/blob/main/crates/macros/context-derive/tests/ui/basic.rs"
46-
fromLine={46}
47-
toLine={52}
45+
url="https://github.com/tangle-network/blueprint/blob/7d97147417af83ce30f52714c60840c50b9142be/crates/macros/context-derive/tests/ui/basic.rs"
46+
fromLine={37}
47+
toLine={37}
4848
title="Accessing Subxt Client Functionality"
4949
/>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Meta } from "nextra";
2+
3+
const meta: Meta = {
4+
introduction: "Introduction",
5+
jobs: "Jobs",
6+
routers: "Routers",
7+
producers: "Producers",
8+
consumers: "Consumers",
9+
"background-services": "Background Services",
10+
building: "Building a Blueprint Runner",
11+
};
12+
13+
export default meta;
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: Background Services
3+
---
4+
5+
import GithubFileReaderDisplay from '/components/GithubFileReaderDisplay';
6+
7+
# Background Services
8+
9+
Background services are optional components in the [Blueprint Runner](/developers/blueprint-runner/introduction) architecture that run continuously to support the operation of your Actively Validated Service (AVS). This document explains how background services work, how to configure them, and best practices for implementation.
10+
11+
## What are Background Services?
12+
13+
Background services refer to any long-running processes that operate independently of job execution. They:
14+
15+
1. Run continuously in the background
16+
2. Can perform periodic or ongoing tasks
17+
3. Might maintain state or connections
18+
4. Support the overall operation of the Blueprint Runner
19+
20+
Unlike job handlers that execute in response to specific requests, background services operate autonomously to provide supporting functionality.
21+
22+
## Common Use Cases
23+
24+
Background services could be used for various purposes in Blueprints, with the following being only a few examples:
25+
26+
### Data Collection and Aggregation
27+
28+
Services that collect and aggregate data, such as an aggregator that submits aggregated signatures to a Blockchain.
29+
30+
### Monitoring and Health Checks
31+
32+
Services that monitor the state of something, such as a health checker that verifies that a Blueprint is running.
33+
34+
## Background Service Configuration
35+
36+
Background services are typically configured in the `main.rs` file of your Blueprint binary, when building the Blueprint Runner. The configuration involves:
37+
38+
### Basic Background Service Setup
39+
40+
The only requirement for a background service is that it implements the `BackgroundService` trait:
41+
42+
<GithubFileReaderDisplay
43+
url="https://github.com/tangle-network/blueprint/blob/a9860d2e3a161af63a75d6d800f662d303e92e5b/examples/incredible-squaring/incredible-squaring-lib/src/lib.rs"
44+
fromLine={23}
45+
toLine={34}
46+
title="Defining a Background Service"
47+
/>
48+
49+
With a background service defined, it is passed into the Blueprint Runner's builder as producers and consumers are:
50+
51+
<GithubFileReaderDisplay
52+
url="https://github.com/tangle-network/blueprint/blob/7774ea42c4d3ec3ff7e170626de3ddce511d1f2f/examples/incredible-squaring/incredible-squaring-bin/src/main.rs"
53+
fromLine={36}
54+
toLine={67}
55+
title="Adding a Background Service to the Blueprint Runner"
56+
/>
57+
58+
For some background services, it may be necessary to add some sort of cleanup code that runs when the Blueprint Runner shuts down. This can be done in the `with_shutdown_handler` method seen in the above code. This specific example just prints a message, but it might end a background process gracefully.
59+
60+
## Integration with Other Components
61+
62+
Background services work closely with other Blueprint Runner components:
63+
64+
- **Routers**: Background services may provide support for [routers](/developers/blueprint-runner/routers), such as caching or state management
65+
- **Producers**: Background services can support [producers](/developers/blueprint-runner/producers) by maintaining connections or monitoring event sources
66+
- **Consumers**: Background services can assist [consumers](/developers/blueprint-runner/consumers) with resource management or periodic tasks
67+
68+
## Next Steps
69+
70+
Now that you understand background services, it might be helpful to take a look at:
71+
72+
- [Routers](/developers/blueprint-runner/routers) - How to direct job calls to appropriate handlers
73+
- [Producers](/developers/blueprint-runner/producers) - How to capture and process events
74+
- [Consumers](/developers/blueprint-runner/consumers) - How to handle job results
75+
- [Building a Blueprint Runner](/developers/blueprint-runner/building) - Step-by-step guide to building your own Blueprint Runner
76+
77+
## Conclusion
78+
79+
Background services are powerful components that enhance the capabilities of your Blueprint Runner by providing continuous support operations. By implementing well-designed background services, you can build more robust, efficient, and feature-rich Blueprints.

0 commit comments

Comments
 (0)