Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d44584c
basic version of python sdk with provider and node registration
JannikSt Jul 11, 2025
6141616
basic message queue with mock data
JannikSt Jul 11, 2025
5ac1a8e
restructure python sdk lib to have pyo bindings in sep. modules
JannikSt Jul 11, 2025
47bc4f4
fix async gil issues, add bootstrap cmd to Makefile
JannikSt Jul 11, 2025
58d2aec
cleanup message queue setup
JannikSt Jul 11, 2025
71ee224
integrate basic p2p messaging between nodes, auth flow with auth manager
JannikSt Jul 13, 2025
2b66c0b
clippy, add integration tests
JannikSt Jul 13, 2025
720dab3
add discovery to shared, use discovery service in protocol sdk until …
JannikSt Jul 13, 2025
de4a89e
implement basic validator sdk functionality to list nodes from discovery
JannikSt Jul 13, 2025
82ae84e
move p2p logic outside of py-sdk worker for sharing with validator + …
JannikSt Jul 13, 2025
86bdde1
share p2p functionality between all three components to easily send m…
JannikSt Jul 13, 2025
31870ad
allow validator to validate nodes using sdk
JannikSt Jul 13, 2025
5e327ac
ability to list all nodes for orchestrator compute pool
JannikSt Jul 13, 2025
c505468
move invite logic to prime-core crate
JannikSt Jul 13, 2025
26a79bb
implement orchestrator automatic invite flow, fix auth race condition
JannikSt Jul 13, 2025
dd64198
ability to eject nodes on orchestrator
JannikSt Jul 13, 2025
efef321
update readme and improve examples
JannikSt Jul 23, 2025
4722bbb
basic detection of validator + orchestrator role, basic message sendi…
JannikSt Jul 23, 2025
a5ffd0e
basic message passing example
JannikSt Jul 23, 2025
a25726d
clippy
JannikSt Jul 23, 2025
203f21b
remove additional print statements
JannikSt Jul 23, 2025
2732805
rename prime-protocol-py to python-sdk
JannikSt Jul 23, 2025
295c7fc
rename prime-core to operations
JannikSt Jul 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
342 changes: 316 additions & 26 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ members = [
"crates/orchestrator",
"crates/p2p",
"crates/dev-utils",
"crates/python-sdk",
"crates/operations",
]
resolver = "2"

[workspace.dependencies]
shared = { path = "crates/shared" }
p2p = { path = "crates/p2p" }
operations = { path = "crates/operations" }

actix-web = "4.9.0"
clap = { version = "4.5.27", features = ["derive"] }
Expand Down Expand Up @@ -42,7 +45,6 @@ mockito = "1.7.0"
iroh = "0.34.1"
rand_v8 = { package = "rand", version = "0.8.5", features = ["std"] }
rand_core_v6 = { package = "rand_core", version = "0.6.4", features = ["std"] }
ipld-core = "0.4"
rust-ipfs = "0.14"
cid = "0.11"
tracing = "0.1.41"
Expand All @@ -59,3 +61,10 @@ manual_let_else = "warn"

[workspace.lints.rust]
unreachable_pub = "warn"

[workspace.metadata.rust-analyzer]
# Help rust-analyzer with proc-macros
procMacro.enable = true
procMacro.attributes.enable = true
# Use a separate target directory for rust-analyzer
targetDir = true
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ up:
@# Attach to session
@tmux attach-session -t prime-dev

# Start Docker services and deploy contracts only
.PHONY: bootstrap
bootstrap:
@echo "Starting Docker services and deploying contracts..."
@# Start Docker services
@docker compose up -d reth redis discovery --wait --wait-timeout 180
@# Deploy contracts
@cd smart-contracts && sh deploy.sh && sh deploy_work_validation.sh && cd ..
@# Run setup
@$(MAKE) setup
@echo "Bootstrap complete - Docker services running and contracts deployed"

# Stop development environment
.PHONY: down
down:
Expand Down Expand Up @@ -268,3 +280,12 @@ deregister-worker:
set -a; source ${ENV_FILE}; set +a; \
cargo run --bin worker -- deregister --compute-pool-id $${WORKER_COMPUTE_POOL_ID} --private-key-provider $${PRIVATE_KEY_PROVIDER} --private-key-node $${PRIVATE_KEY_NODE} --rpc-url $${RPC_URL}

# Python Package
.PHONY: python-install
python-install:
@cd crates/prime-protocol-py && make install

.PHONY: python-test
python-test:
@cd crates/prime-protocol-py && make test

16 changes: 3 additions & 13 deletions crates/dev-utils/examples/compute_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async fn main() -> Result<()> {

let compute_limit = U256::from(0);

let tx = contracts
let _tx = contracts
.compute_pool
.create_compute_pool(
domain_id,
Expand All @@ -68,31 +68,21 @@ async fn main() -> Result<()> {
compute_limit,
)
.await;
println!("Transaction: {:?}", tx);
let rewards_distributor_address = contracts
.compute_pool
.get_reward_distributor_address(U256::from(0))
.await
.unwrap();

println!(
"Rewards distributor address: {:?}",
rewards_distributor_address
);
let rewards_distributor = RewardsDistributor::new(
rewards_distributor_address,
wallet.provider(),
"rewards_distributor.json",
);
let rate = U256::from(10000000000000000u64);
let tx = rewards_distributor.set_reward_rate(rate).await;
println!("Setting reward rate: {:?}", tx);
let _tx = rewards_distributor.set_reward_rate(rate).await;

let reward_rate = rewards_distributor.get_reward_rate().await.unwrap();
println!(
"Reward rate: {}",
reward_rate.to_string().parse::<f64>().unwrap_or(0.0) / 10f64.powf(18.0)
);
let _reward_rate = rewards_distributor.get_reward_rate().await.unwrap();

Ok(())
}
2 changes: 1 addition & 1 deletion crates/dev-utils/examples/create_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ async fn main() -> Result<()> {
.await;
println!("Creating domain: {}", args.domain_name);
println!("Validation logic: {}", args.validation_logic);
println!("Transaction: {:?}", tx);
println!("Transaction: {tx:?}");
Ok(())
}
6 changes: 3 additions & 3 deletions crates/dev-utils/examples/eject_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ async fn main() -> Result<()> {
.compute_registry
.get_node(provider_address, node_address)
.await;
println!("Node info: {:?}", node_info);
println!("Node info: {node_info:?}");

let tx = contracts
.compute_pool
.eject_node(args.pool_id, node_address)
.await;
println!("Ejected node {} from pool {}", args.node, args.pool_id);
println!("Transaction: {:?}", tx);
println!("Transaction: {tx:?}");

let node_info = contracts
.compute_registry
.get_node(provider_address, node_address)
.await;
println!("Post ejection node info: {:?}", node_info);
println!("Post ejection node info: {node_info:?}");

Ok(())
}
5 changes: 1 addition & 4 deletions crates/dev-utils/examples/get_node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ async fn main() -> Result<()> {
.await
.unwrap();

println!(
"Node Active: {}, Validated: {}, In Pool: {}",
active, validated, is_node_in_pool
);
println!("Node Active: {active}, Validated: {validated}, In Pool: {is_node_in_pool}");
Ok(())
}
2 changes: 1 addition & 1 deletion crates/dev-utils/examples/invalidate_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn main() -> Result<()> {
"Invalidated work in pool {} with penalty {}",
args.pool_id, args.penalty
);
println!("Transaction hash: {:?}", tx);
println!("Transaction hash: {tx:?}");

Ok(())
}
4 changes: 2 additions & 2 deletions crates/dev-utils/examples/mint_ai_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ async fn main() -> Result<()> {
let amount = U256::from(args.amount) * Unit::ETHER.wei();
let tx = contracts.ai_token.mint(address, amount).await;
println!("Minting to address: {}", args.address);
println!("Transaction: {:?}", tx);
println!("Transaction: {tx:?}");

let balance = contracts.ai_token.balance_of(address).await;
println!("Balance: {:?}", balance);
println!("Balance: {balance:?}");
Ok(())
}
4 changes: 2 additions & 2 deletions crates/dev-utils/examples/set_min_stake_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ async fn main() -> Result<()> {
.unwrap();

let min_stake_amount = U256::from(args.min_stake_amount) * Unit::ETHER.wei();
println!("Min stake amount: {}", min_stake_amount);
println!("Min stake amount: {min_stake_amount}");

let tx = contracts
.prime_network
.set_stake_minimum(min_stake_amount)
.await;
println!("Transaction: {:?}", tx);
println!("Transaction: {tx:?}");

Ok(())
}
2 changes: 1 addition & 1 deletion crates/dev-utils/examples/start_compute_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ async fn main() -> Result<()> {
.start_compute_pool(U256::from(args.pool_id))
.await;
println!("Started compute pool with id: {}", args.pool_id);
println!("Transaction: {:?}", tx);
println!("Transaction: {tx:?}");
Ok(())
}
2 changes: 1 addition & 1 deletion crates/dev-utils/examples/submit_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn main() -> Result<()> {
"Submitted work for node {} in pool {}",
args.node, args.pool_id
);
println!("Transaction hash: {:?}", tx);
println!("Transaction hash: {tx:?}");

Ok(())
}
14 changes: 7 additions & 7 deletions crates/dev-utils/examples/test_concurrent_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() -> Result<()> {
let wallet = Arc::new(Wallet::new(&args.key, Url::parse(&args.rpc_url)?).unwrap());

let price = wallet.provider.get_gas_price().await?;
println!("Gas price: {:?}", price);
println!("Gas price: {price:?}");

let current_nonce = wallet
.provider
Expand All @@ -50,8 +50,8 @@ async fn main() -> Result<()> {
.block_id(BlockId::Number(BlockNumberOrTag::Pending))
.await?;

println!("Pending nonce: {:?}", pending_nonce);
println!("Current nonce: {:?}", current_nonce);
println!("Pending nonce: {pending_nonce:?}");
println!("Current nonce: {current_nonce:?}");

// Unfortunately have to build all contracts atm
let contracts = Arc::new(
Expand All @@ -67,7 +67,7 @@ async fn main() -> Result<()> {
let address = Address::from_str(&args.address).unwrap();
let amount = U256::from(args.amount) * Unit::ETHER.wei();
let random = (rand::random::<u8>() % 10) + 1;
println!("Random: {:?}", random);
println!("Random: {random:?}");

let contracts_one = contracts.clone();
let wallet_one = wallet.clone();
Expand All @@ -80,7 +80,7 @@ async fn main() -> Result<()> {
let tx = retry_call(mint_call, 5, wallet_one.provider(), None)
.await
.unwrap();
println!("Transaction hash I: {:?}", tx);
println!("Transaction hash I: {tx:?}");
});

let contracts_two = contracts.clone();
Expand All @@ -93,11 +93,11 @@ async fn main() -> Result<()> {
let tx = retry_call(mint_call_two, 5, wallet_two.provider(), None)
.await
.unwrap();
println!("Transaction hash II: {:?}", tx);
println!("Transaction hash II: {tx:?}");
});

let balance = contracts.ai_token.balance_of(address).await.unwrap();
println!("Balance: {:?}", balance);
println!("Balance: {balance:?}");
tokio::time::sleep(tokio::time::Duration::from_secs(40)).await;
Ok(())
}
16 changes: 6 additions & 10 deletions crates/discovery/src/api/routes/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,10 @@ mod tests {
assert_eq!(body.data, "Node registered successfully");

let nodes = app_state.node_store.get_nodes().await;
let nodes = match nodes {
Ok(nodes) => nodes,
Err(_) => {
panic!("Error getting nodes");
}
let Ok(nodes) = nodes else {
panic!("Error getting nodes");
};

assert_eq!(nodes.len(), 1);
assert_eq!(nodes[0].id, node.id);
assert_eq!(nodes[0].last_updated, None);
Expand Down Expand Up @@ -611,12 +609,10 @@ mod tests {
assert_eq!(body.data, "Node registered successfully");

let nodes = app_state.node_store.get_nodes().await;
let nodes = match nodes {
Ok(nodes) => nodes,
Err(_) => {
panic!("Error getting nodes");
}
let Ok(nodes) = nodes else {
panic!("Error getting nodes");
};

assert_eq!(nodes.len(), 1);
assert_eq!(nodes[0].id, node.id);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/discovery/src/store/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ impl RedisStore {
_ => panic!("Expected TCP connection"),
};

let redis_url = format!("redis://{}:{}", host, port);
debug!("Starting test Redis server at {}", redis_url);
let redis_url = format!("redis://{host}:{port}");
debug!("Starting test Redis server at {redis_url}");

// Add a small delay to ensure server is ready
thread::sleep(Duration::from_millis(100));
Expand Down
32 changes: 32 additions & 0 deletions crates/operations/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "operations"
version = "0.1.0"
edition = "2021"

[lints]
workspace = true

[lib]
name = "operations"
path = "src/lib.rs"

[dependencies]
shared = { workspace = true }
p2p = { workspace = true }
alloy = { workspace = true }
alloy-provider = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
url = { workspace = true }
actix-web = { workspace = true }
anyhow = { workspace = true }
futures-util = { workspace = true }
hex = { workspace = true }
uuid = { workspace = true }
log = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }
redis = { workspace = true, features = ["aio", "tokio-comp"] }
rand_v8 = { workspace = true }
env_logger = { workspace = true }
subtle = "2.6.1"
Loading