snops_common/rpc/control/
agent.rs

1use std::net::IpAddr;
2
3use serde::{Deserialize, Serialize};
4
5use crate::rpc::error::*;
6use crate::state::snarkos_status::SnarkOSLiteBlock;
7use crate::{
8    prelude::EnvId,
9    state::{AgentState, NetworkId, PortConfig},
10};
11
12#[derive(Debug, Clone, Default, Serialize, Deserialize)]
13pub struct Handshake {
14    pub jwt: Option<String>,
15    pub loki: Option<String>,
16    pub state: AgentState,
17}
18
19/// The RPC service that agents implement as a server.
20#[tarpc::service]
21pub trait AgentService {
22    /// Handshake with some initial connection details.
23    async fn handshake(handshake: Handshake) -> Result<(), ReconcileError>;
24
25    /// Control plane asks the agent for its external network address, along
26    /// with local addrs.
27    async fn get_addrs() -> (PortConfig, Option<IpAddr>, Vec<IpAddr>);
28
29    /// Control plane instructs the agent to reconcile towards a particular
30    /// state.
31    async fn reconcile(to: AgentState) -> Result<(), ReconcileError>;
32
33    /// Broadcast a transaction locally
34    async fn broadcast_tx(tx: String) -> Result<(), AgentError>;
35
36    /// Make a GET request to the snarkos server
37    async fn snarkos_get(route: String) -> Result<String, SnarkosRequestError>;
38
39    /// Close the agent process
40    async fn kill();
41
42    /// Locally execute an authorization, using the given query
43    /// environment id is passed so the agent can determine which aot binary to
44    /// use
45    async fn execute_authorization(
46        env_id: EnvId,
47        network: NetworkId,
48        query: String,
49        auth: String,
50    ) -> Result<String, AgentError>;
51
52    async fn get_metric(metric: AgentMetric) -> f64;
53
54    async fn set_log_level(level: String) -> Result<(), AgentError>;
55
56    /// Find a transaction's block hash by its transaction id
57    async fn find_transaction(tx_id: String) -> Result<Option<String>, AgentError>;
58
59    /// Get a block info and transaction data from the agent's running node
60    async fn get_snarkos_block_lite(
61        block_hash: String,
62    ) -> Result<Option<SnarkOSLiteBlock>, AgentError>;
63
64    async fn set_aot_log_level(verbosity: u8) -> Result<(), AgentError>;
65
66    async fn get_status() -> Result<AgentStatus, AgentError>;
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct AgentStatus {
71    pub aot_online: bool,
72    pub version: String,
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub enum AgentMetric {
77    Tps,
78}