Skip to content

Commit

Permalink
remove snot/agent dependence on aot
Browse files Browse the repository at this point in the history
  • Loading branch information
Meshiest committed Mar 22, 2024
1 parent 2e27453 commit 55719ae
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 58 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions crates/snot-agent/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ impl AgentService for AgentRpcServer {
_: context::Context,
target: AgentState,
) -> Result<(), ReconcileError> {
if matches!(target, AgentState::Cannon(_, _)) {
unimplemented!("tx cannons are unimplemented");
}

// acquire the handle lock
let mut handle_container = self.state.reconcilation_handle.lock().await;

Expand Down Expand Up @@ -163,7 +159,7 @@ impl AgentService for AgentRpcServer {

// use `tar` to decompress the storage
let mut tar_child = Command::new("tar")
.current_dir(&base_path)
.current_dir(base_path)
.arg("-xzf")
.arg(LEDGER_STORAGE_FILE)
.kill_on_drop(true)
Expand Down Expand Up @@ -254,9 +250,6 @@ impl AgentService for AgentRpcServer {

*child_lock = Some(child);
}

// TODO
AgentState::Cannon(_, _) => unimplemented!(),
}

Ok(())
Expand Down
42 changes: 2 additions & 40 deletions crates/snot-common/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ use serde::{de::Error, Deserialize, Serialize};

type AgentId = usize;
type StorageId = usize;
type CannonSourceId = usize;

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub enum AgentState {
#[default]
// A node in the inventory can function as a transaction cannon
Inventory,
Node(StorageId, NodeState),
Cannon(StorageId, CannonState),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -31,43 +30,6 @@ pub struct NodeState {
pub validators: Vec<AgentPeer>,
}

/// Transaction cannon modes.
/// When a target node is specified, it MUST have REST ports available for
/// both broadcasting and for checking if a transaction has been confirmed for
/// private transactions (record must exist before transfer_private can be run)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum CannonState {
/// Generate transactions and submit them to the control-plane
AheadOfTime {
mode: TxGenMode,
pks: Vec<String>,
addrs: Vec<String>,
},
/// Generate transactions in realtime and submit them to a target node
Realtime {
target: AgentPeer,
mode: TxGenMode,
pks: Vec<String>,
addrs: Vec<String>,
},
/// Playback transactions from a file to a target node
Playback {
target: AgentPeer,
// number of transactions per second to emit
rate: u16,
// total number of transactions to emit
total: u32,
source: CannonSourceId,
},
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TxGenMode {
All,
OnlyPrivate,
OnlyPublic,
}

// // agent code
// impl AgentState {
// async fn reconcile(&self, target: AgentState) {
Expand Down Expand Up @@ -267,7 +229,7 @@ impl Display for NodeKey {
write!(f, "{}/{}", self.ty, self.id)?;
if let Some(ns) = &self.ns {
f.write_char('@')?;
f.write_str(&ns)?;
f.write_str(ns)?;
}

Ok(())
Expand Down
1 change: 0 additions & 1 deletion crates/snot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
sha2 = "0.10.8"
snarkos-aot = { path = "../aot", default-features = false }
snot-common = { path = "../snot-common" }
tarpc.workspace = true
tokio.workspace = true
Expand Down
59 changes: 51 additions & 8 deletions crates/snot/src/schema/storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
ops::Deref,
path::PathBuf,
process::Stdio,
sync::atomic::{AtomicUsize, Ordering},
};

Expand Down Expand Up @@ -29,7 +30,7 @@ pub struct StorageGeneration {
pub path: PathBuf,

// TODO: individually validate arguments, or just pass them like this?
pub genesis: snarkos_aot::genesis::Genesis,
pub genesis: GenesisGeneration,
pub ledger: LedgerGeneration,

#[serde(default)]
Expand All @@ -46,11 +47,32 @@ pub struct Transaction {
pub destinations: Vec<String>,
}

#[derive(Deserialize, Debug, Clone)]
pub struct GenesisGeneration {
pub output: PathBuf,
}

impl Default for GenesisGeneration {
fn default() -> Self {
Self {
output: PathBuf::from("genesis.block"),
}
}
}

#[derive(Deserialize, Debug, Clone)]
pub struct LedgerGeneration {
pub output: PathBuf,
}

impl Default for LedgerGeneration {
fn default() -> Self {
Self {
output: PathBuf::from("ledger"),
}
}
}

#[derive(Debug, Clone, Serialize)]
pub struct FilenameString(String);

Expand Down Expand Up @@ -129,15 +151,36 @@ impl Document {
break 'generate;
}

generation.genesis = snarkos_aot::genesis::Genesis {
generation.genesis = GenesisGeneration {
output: base.join("genesis.block"),
ledger: None,
additional_accounts_output: Some(base.join("accounts.json")),
committee_output: Some(base.join("committee.json")),
..generation.genesis
};

tokio::task::spawn_blocking(move || generation.genesis.parse()).await??;
// generation.genesis = snarkos_aot::genesis::Genesis {
// output: base.join("genesis.block"),
// ledger: None,
// additional_accounts_output: Some(base.join("accounts.json")),
// committee_output: Some(base.join("committee.json")),
// ..generation.genesis
// };

// generate the genesis block using the aot cli
Command::new("./target/release/snarkos-aot")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.current_dir(&base)
.arg("genesis")
.arg("--output")
.arg(&generation.genesis.output)
.arg("--committee-size")
.arg("5")
.arg("--committee-output")
.arg(base.join("committee.json"))
.arg("--additional-accounts")
.arg("5")
.arg("--additional-accounts-output")
.arg(base.join("accounts.json"))
.spawn()?
.wait()
.await?;

// TODO: transactions
}
Expand Down

0 comments on commit 55719ae

Please sign in to comment.