diff --git a/tig-benchmarker/master/__pycache__/__init__.cpython-310.pyc b/tig-benchmarker/master/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000..a2189a67 Binary files /dev/null and b/tig-benchmarker/master/__pycache__/__init__.cpython-310.pyc differ diff --git a/tig-benchmarker/master/__pycache__/config.cpython-310.pyc b/tig-benchmarker/master/__pycache__/config.cpython-310.pyc new file mode 100644 index 00000000..c7ede5d8 Binary files /dev/null and b/tig-benchmarker/master/__pycache__/config.cpython-310.pyc differ diff --git a/tig-benchmarker/master/__pycache__/data.cpython-310.pyc b/tig-benchmarker/master/__pycache__/data.cpython-310.pyc new file mode 100644 index 00000000..584f98f4 Binary files /dev/null and b/tig-benchmarker/master/__pycache__/data.cpython-310.pyc differ diff --git a/tig-benchmarker/master/__pycache__/data_fetcher.cpython-310.pyc b/tig-benchmarker/master/__pycache__/data_fetcher.cpython-310.pyc new file mode 100644 index 00000000..3260daf1 Binary files /dev/null and b/tig-benchmarker/master/__pycache__/data_fetcher.cpython-310.pyc differ diff --git a/tig-benchmarker/src/benchmarker/find_proof_to_submit.rs b/tig-benchmarker/src/benchmarker/find_proof_to_submit.rs index fce0c07f..9e289f9c 100644 --- a/tig-benchmarker/src/benchmarker/find_proof_to_submit.rs +++ b/tig-benchmarker/src/benchmarker/find_proof_to_submit.rs @@ -1,8 +1,8 @@ use super::{state, QueryData, Result}; use std::collections::HashSet; -use tig_worker::SolutionData; +use tig_worker::OutputData; -pub async fn execute() -> Result)>> { +pub async fn execute() -> Result)>> { let QueryData { proofs, benchmarks, diff --git a/tig-benchmarker/src/benchmarker/mod.rs b/tig-benchmarker/src/benchmarker/mod.rs index a3502b07..aba091ce 100644 --- a/tig-benchmarker/src/benchmarker/mod.rs +++ b/tig-benchmarker/src/benchmarker/mod.rs @@ -279,7 +279,7 @@ async fn run_once(num_workers: u32, ms_per_benchmark: u32) -> Result<()> { }) .collect(), }; - let solutions_data = Arc::new(Mutex::new(Vec::::new())); + let solutions_data = Arc::new(Mutex::new(Vec::::new())); let solutions_count = Arc::new(Mutex::new(0u32)); update_status("Starting benchmark").await; run_benchmark::execute( @@ -396,7 +396,7 @@ async fn run_once(num_workers: u32, ms_per_benchmark: u32) -> Result<()> { Ok(()) } -pub async fn drain_solutions(benchmark_id: &String, solutions_data: &mut Vec) -> u32 { +pub async fn drain_solutions(benchmark_id: &String, solutions_data: &mut Vec) -> u32 { let mut state = (*state()).lock().await; let QueryData { benchmarks, proofs, .. @@ -407,7 +407,7 @@ pub async fn drain_solutions(benchmark_id: &String, solutions_data: &mut Vec>>, job: &Job, wasm: &Vec, - solutions_data: Arc>>, + solutions_data: Arc>>, solutions_count: Arc>, ) { for nonce_iter in nonce_iters { diff --git a/tig-benchmarker/src/benchmarker/submit_proof.rs b/tig-benchmarker/src/benchmarker/submit_proof.rs index ad3fb203..bd54f000 100644 --- a/tig-benchmarker/src/benchmarker/submit_proof.rs +++ b/tig-benchmarker/src/benchmarker/submit_proof.rs @@ -1,14 +1,14 @@ use super::{api, Result}; use crate::future_utils::sleep; use tig_api::SubmitProofReq; -use tig_worker::SolutionData; +use tig_worker::OutputData; const MAX_RETRIES: u32 = 3; -pub async fn execute(benchmark_id: String, solutions_data: Vec) -> Result<()> { +pub async fn execute(benchmark_id: String, solutions_data: Vec) -> Result<()> { let req = SubmitProofReq { benchmark_id, - solutions_data, + merkle_data: solutions_data, }; for attempt in 1..=MAX_RETRIES { println!("Submission attempt {} of {}", attempt, MAX_RETRIES); diff --git a/tig-benchmarker/src/main.rs b/tig-benchmarker/src/main.rs index 0402b242..b5066bd5 100644 --- a/tig-benchmarker/src/main.rs +++ b/tig-benchmarker/src/main.rs @@ -109,7 +109,7 @@ async fn slave_node(master: &String, port: u16, num_workers: u32) { let master_url = format!("http://{}:{}", master, port); let mut job: Option = None; let mut nonce_iters: Vec>> = Vec::new(); - let mut solutions_data = Arc::new(Mutex::new(Vec::::new())); + let mut solutions_data = Arc::new(Mutex::new(Vec::::new())); let mut solutions_count = Arc::new(Mutex::new(0u32)); let mut num_solutions = 0; loop { @@ -129,7 +129,7 @@ async fn slave_node(master: &String, port: u16, num_workers: u32) { (*(*nonce_iter).lock().await).empty(); } nonce_iters.clear(); - solutions_data = Arc::new(Mutex::new(Vec::::new())); + solutions_data = Arc::new(Mutex::new(Vec::::new())); solutions_count = Arc::new(Mutex::new(0u32)); num_solutions = 0; if next_job @@ -195,7 +195,7 @@ async fn slave_node(master: &String, port: u16, num_workers: u32) { let n = solutions_data.len(); if n > 0 { num_solutions += n as u32; - let data: Vec = solutions_data.drain(..).collect(); + let data: Vec = solutions_data.drain(..).collect(); println!("Posting {} solutions", n); if let Err(e) = post::( &format!("{}/solutions_data/{}", master_url, job.benchmark_id), @@ -264,7 +264,7 @@ async fn master_node( .and(warp::post()) .and(warp::body::json()) .and_then( - |benchmark_id: String, mut solutions_data: Vec| async move { + |benchmark_id: String, mut solutions_data: Vec| async move { benchmarker::drain_solutions(&benchmark_id, &mut solutions_data).await; Ok::<_, warp::Rejection>(warp::reply::with_status( "SolutionsData received", diff --git a/tig-protocol/src/add_block.rs b/tig-protocol/src/add_block.rs index 6ebe2a22..76f455f4 100644 --- a/tig-protocol/src/add_block.rs +++ b/tig-protocol/src/add_block.rs @@ -10,6 +10,7 @@ pub(crate) async fn execute(ctx: &T) -> String { let (block, mut cache) = create_block(ctx).await; confirm_mempool_challenges(&block, &mut cache).await; confirm_mempool_algorithms(&block, &mut cache).await; + confirm_mempool_precommits(&block, &mut cache).await; confirm_mempool_benchmarks(&block, &mut cache).await; confirm_mempool_proofs(ctx, &block, &mut cache).await; confirm_mempool_frauds(&block, &mut cache).await; @@ -19,6 +20,7 @@ pub(crate) async fn execute(ctx: &T) -> String { update_qualifiers(&block, &mut cache).await; update_frontiers(&block, &mut cache).await; update_solution_signature_thresholds(&block, &mut cache).await; + update_base_fees(&block, &mut cache).await; update_influence(&block, &mut cache).await; update_adoption(&block, &mut cache).await; update_innovator_rewards(&block, &mut cache).await; @@ -33,6 +35,7 @@ struct AddBlockCache { pub mempool_challenges: Vec, pub mempool_algorithms: Vec, pub mempool_benchmarks: Vec, + pub mempool_precommits: Vec, pub mempool_proofs: Vec, pub mempool_frauds: Vec, pub mempool_wasms: Vec, @@ -93,6 +96,17 @@ async fn setup_cache( }); mempool_benchmarks.push(benchmark); } + let mut mempool_precommits = Vec::new(); + for mut precommit in ctx + .get_precommits(PrecommitsFilter::Mempool { from_block_started }) + .await + .unwrap_or_else(|e| panic!("get_precommits error: {:?}", e)) + { + precommit.state = Some(PrecommitState { + block_confirmed: None, + }); + mempool_precommits.push(precommit); + } let mut mempool_proofs = Vec::new(); for mut proof in ctx .get_proofs(ProofsFilter::Mempool { from_block_started }, false) @@ -148,6 +162,7 @@ async fn setup_cache( cutoff_frontier: None, scaling_factor: None, qualifier_difficulties: None, + base_fee: None, }); active_challenges.insert(challenge.id.clone(), challenge); } @@ -292,6 +307,7 @@ async fn setup_cache( mempool_challenges, mempool_algorithms, mempool_benchmarks, + mempool_precommits, mempool_proofs, mempool_frauds, mempool_wasms, @@ -395,10 +411,17 @@ async fn confirm_mempool_algorithms(block: &Block, cache: &mut AddBlockCache) { } } +#[time] +async fn confirm_mempool_precommits(block: &Block, cache: &mut AddBlockCache) { + let config = block.config(); + // FIXME +} + #[time] async fn confirm_mempool_benchmarks(block: &Block, cache: &mut AddBlockCache) { let config = block.config(); + // FIXME sample solutions and non-solutions for benchmark in cache.mempool_benchmarks.iter_mut() { let seed = u32_from_str(format!("{:?}|{:?}", block.id, benchmark.id).as_str()); let mut rng = StdRng::seed_from_u64(seed as u64); @@ -614,6 +637,11 @@ async fn update_solution_signature_thresholds(block: &Block, cache: &mut AddBloc } } +#[time] +async fn update_base_fees(block: &Block, cache: &mut AddBlockCache) { + // FIXME +} + fn find_smallest_range_dimension(points: &Frontier) -> usize { (0..2) .min_by_key(|&d| { diff --git a/tig-utils/src/merkle_tree.rs b/tig-utils/src/merkle_tree.rs index b430145b..d39b5736 100644 --- a/tig-utils/src/merkle_tree.rs +++ b/tig-utils/src/merkle_tree.rs @@ -153,14 +153,14 @@ impl MerkleTree { hashes[0].clone() } - pub fn calc_merkle_proof(&self, branch_idx: usize) -> Result { + pub fn calc_merkle_branch(&self, branch_idx: usize) -> Result { if branch_idx >= self.n { return Err(anyhow!("Invalid branch index")); } let mut hashes = self.hashed_leafs.clone(); let null_hash = MerkleHash::null(); - let mut proof = Vec::new(); + let mut branch = Vec::new(); let mut idx = branch_idx; while hashes.len() > 1 { @@ -170,7 +170,7 @@ impl MerkleTree { let right = chunk.get(1).unwrap_or(&null_hash); if idx >> 1 == i { - proof.push(if idx % 2 == 0 { right } else { left }.clone()); + branch.push(if idx % 2 == 0 { right } else { left }.clone()); } let mut combined = [0u8; 32]; @@ -182,7 +182,7 @@ impl MerkleTree { idx /= 2; } - Ok(MerkleBranch(proof)) + Ok(MerkleBranch(branch)) } } diff --git a/tig-utils/tests/merkle_tree.rs b/tig-utils/tests/merkle_tree.rs index 7a3bb5d8..b8e25177 100644 --- a/tig-utils/tests/merkle_tree.rs +++ b/tig-utils/tests/merkle_tree.rs @@ -17,7 +17,7 @@ mod tests { let tree = MerkleTree::new(hashes.clone(), 16).unwrap(); let root = tree.calc_merkle_root(); - let proof = tree.calc_merkle_proof(7).unwrap(); + let proof = tree.calc_merkle_branch(7).unwrap(); let leaf_hash = &hashes[7]; let calculated_root = proof.calc_merkle_root(leaf_hash, 7); @@ -37,7 +37,7 @@ mod tests { let hashes = create_test_hashes(); let tree = MerkleTree::new(hashes, 16).unwrap(); - let result = tree.calc_merkle_proof(16); + let result = tree.calc_merkle_branch(16); assert!(result.is_err()); } @@ -46,7 +46,7 @@ mod tests { let hashes = create_test_hashes(); let tree = MerkleTree::new(hashes.clone(), 16).unwrap(); - let proof = tree.calc_merkle_proof(7).unwrap(); + let proof = tree.calc_merkle_branch(7).unwrap(); let tree_json = serde_json::to_string(&tree).unwrap(); let deserialized_tree: MerkleTree = serde_json::from_str(&tree_json).unwrap(); diff --git a/tig-worker/src/worker.rs b/tig-worker/src/worker.rs index db4805f2..df74aa94 100644 --- a/tig-worker/src/worker.rs +++ b/tig-worker/src/worker.rs @@ -1,7 +1,7 @@ use anyhow::{anyhow, Result}; use bincode; use tig_challenges::*; -pub use tig_structs::core::{BenchmarkSettings, Solution, SolutionData}; +pub use tig_structs::core::{BenchmarkSettings, OutputData, Solution}; use tig_utils::decompress_obj; use wasmi::{Config, Engine, Linker, Module, Store, StoreLimitsBuilder}; @@ -11,7 +11,7 @@ pub fn compute_solution( wasm: &[u8], max_memory: u64, max_fuel: u64, -) -> Result> { +) -> Result> { let seeds = settings.calc_seeds(nonce); let serialized_challenge = match settings.challenge_id.as_str() { "c001" => { @@ -86,6 +86,7 @@ pub fn compute_solution( .map_err(|e| anyhow!("Failed to call function: {:?}", e))?; // Get runtime signature + // FIXME read runtime signature on execution error let runtime_signature_u64 = store.get_runtime_signature(); let runtime_signature = (runtime_signature_u64 as u32) ^ ((runtime_signature_u64 >> 32) as u32); let fuel_consumed = max_fuel - store.get_fuel().unwrap(); @@ -103,7 +104,7 @@ pub fn compute_solution( &mut serialized_solution, ) .expect("Failed to read solution from memory"); - let mut solution_data = SolutionData { + let mut solution_data = OutputData { nonce, runtime_signature, fuel_consumed,