From 53e9ef984086824c8b867b06cc6c5c3675011779 Mon Sep 17 00:00:00 2001 From: brenzi Date: Wed, 24 Jun 2020 23:06:05 +0200 Subject: [PATCH] closes #7. all public getters implemented (#19) --- Cargo.lock | 10 +++--- client/Cargo.toml | 2 +- client/bootstrap_demo_currency.sh | 18 ++++++---- client/src/main.rs | 2 +- enclave/Cargo.lock | 14 ++++---- enclave/Cargo.toml | 2 +- enclave/chain_relay/Cargo.toml | 2 +- stf/Cargo.toml | 2 +- stf/src/cli.rs | 48 +++++++++++++++++++++++++-- stf/src/lib.rs | 7 +++- stf/src/sgx.rs | 32 +++++++++++++++++- substratee-node-primitives/Cargo.toml | 2 +- worker/Cargo.toml | 2 +- worker/worker-api/Cargo.toml | 2 +- 14 files changed, 113 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a094cb1bdb..d5495a4377 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -563,7 +563,7 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" [[package]] name = "encointer-client-teeproxy" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "base58", "blake2-rfc", @@ -640,7 +640,7 @@ dependencies = [ [[package]] name = "encointer-worker" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "base58", "cid", @@ -3996,7 +3996,7 @@ checksum = "d2a965994514ab35d3893e9260245f2947fd1981cdd4fffd2c6e6d1a9ce02e6a" [[package]] name = "substratee-node-primitives" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "base58", "encointer-node-teeproxy-runtime", @@ -4011,7 +4011,7 @@ dependencies = [ [[package]] name = "substratee-stf" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "base58", "clap", @@ -4043,7 +4043,7 @@ dependencies = [ [[package]] name = "substratee-worker-api" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "hex 0.4.2", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/client/Cargo.toml b/client/Cargo.toml index 9323a47efb..762a99b78d 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "encointer-client-teeproxy" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" authors = ["Supercomputing Systems AG "] edition = "2018" diff --git a/client/bootstrap_demo_currency.sh b/client/bootstrap_demo_currency.sh index 3e5d31924e..191195210f 100755 --- a/client/bootstrap_demo_currency.sh +++ b/client/bootstrap_demo_currency.sh @@ -80,12 +80,16 @@ $CLIENT trusted get-registration $account3 --mrenclave $MRENCLAVE --shard $cid wait_for_phase ASSIGNING -# nothing to do here until we can have debug getters +echo "* Waiting 30 seconds such that phase change happened in enclave" +sleep 30 +echo "" + +$CLIENT trusted info --mrenclave $MRENCLAVE --shard $cid wait_for_phase ATTESTING -echo "* Waiting 5 seconds such that phase change happened in enclave" -sleep 5 +echo "* Waiting 30 seconds such that phase change happened in enclave" +sleep 30 echo "" echo "*** start meetup" @@ -119,13 +123,13 @@ $CLIENT trusted get-attestations $account3 --mrenclave $MRENCLAVE --shard $cid wait_for_phase REGISTERING -echo "* Waiting 5 seconds such that phase change happened in enclave" -sleep 5 +echo "* Waiting 30 seconds such that phase change happened in enclave" +sleep 30 echo "" echo "account balances for new currency with cid $cid" $CLIENT trusted balance $account1 --mrenclave $MRENCLAVE --shard $cid $CLIENT trusted balance $account2 --mrenclave $MRENCLAVE --shard $cid $CLIENT trusted balance $account3 --mrenclave $MRENCLAVE --shard $cid -echo "total issuance (publicly readable)" -$CLIENT trusted total-issuance --mrenclave $MRENCLAVE --shard $cid +echo "currency info (publicly readable)" +$CLIENT trusted info --mrenclave $MRENCLAVE --shard $cid \ No newline at end of file diff --git a/client/src/main.rs b/client/src/main.rs index 61af286ca7..4966d25202 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -449,7 +449,7 @@ fn main() { compose_extrinsic!(api.clone(), "EncointerScheduler", "next_phase"); // send and watch extrinsic until finalized - let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::Finalized).unwrap(); + let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap(); let phase = get_current_phase(&api); println!( "Transaction got finalized. Phase is now: {:?}. tx hash: {:?}", diff --git a/enclave/Cargo.lock b/enclave/Cargo.lock index e2f5fed431..5117aa1c68 100644 --- a/enclave/Cargo.lock +++ b/enclave/Cargo.lock @@ -172,7 +172,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "chain-relay" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "derive_more 0.99.5 (registry+https://github.com/rust-lang/crates.io-index)", "finality-grandpa 0.11.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2120,7 +2120,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "substratee-node-primitives" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "parity-scale-codec 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2130,7 +2130,7 @@ dependencies = [ [[package]] name = "substratee-stf" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "derive_more 0.99.5 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (git+https://github.com/mesalock-linux/env_logger-sgx)", @@ -2153,12 +2153,12 @@ dependencies = [ [[package]] name = "substratee-worker-enclave" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" dependencies = [ "aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.10.1 (git+https://github.com/mesalock-linux/rust-base64-sgx)", "bit-vec 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "chain-relay 0.6.8-sub2.0.0-alpha.7", + "chain-relay 0.6.9-sub2.0.0-alpha.7", "chrono 0.4.11 (git+https://github.com/mesalock-linux/chrono-sgx)", "env_logger 0.7.1 (git+https://github.com/mesalock-linux/env_logger-sgx)", "httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2192,8 +2192,8 @@ dependencies = [ "sp-runtime 2.0.0-alpha.7 (registry+https://github.com/rust-lang/crates.io-index)", "sp-std 2.0.0-alpha.7 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-api-client 0.4.6-sub2.0.0-alpha.7 (git+https://github.com/scs/substrate-api-client?tag=v0.4.6-sub2.0.0-alpha.7)", - "substratee-node-primitives 0.6.8-sub2.0.0-alpha.7", - "substratee-stf 0.6.8-sub2.0.0-alpha.7", + "substratee-node-primitives 0.6.9-sub2.0.0-alpha.7", + "substratee-stf 0.6.9-sub2.0.0-alpha.7", "webpki 0.21.2 (git+https://github.com/mesalock-linux/webpki?branch=mesalock_sgx)", "webpki-roots 0.19.0 (git+https://github.com/mesalock-linux/webpki-roots?branch=mesalock_sgx)", "yasna 0.3.1 (git+https://github.com/mesalock-linux/yasna.rs-sgx?rev=sgx_1.1.2)", diff --git a/enclave/Cargo.toml b/enclave/Cargo.toml index 4d05bde011..6dec7252e4 100644 --- a/enclave/Cargo.toml +++ b/enclave/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substratee-worker-enclave" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" authors = ["Supercomputing Systems AG "] edition = "2018" diff --git a/enclave/chain_relay/Cargo.toml b/enclave/chain_relay/Cargo.toml index f54f39ebde..b5cfd30e66 100644 --- a/enclave/chain_relay/Cargo.toml +++ b/enclave/chain_relay/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chain-relay" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" authors = ["Supercomputing Systems AG "] edition = "2018" diff --git a/stf/Cargo.toml b/stf/Cargo.toml index 01fc61ae23..cecf51b5b8 100644 --- a/stf/Cargo.toml +++ b/stf/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substratee-stf" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" authors = ["Supercomputing Systems AG "] edition = "2018" diff --git a/stf/src/cli.rs b/stf/src/cli.rs index 42c921d772..5756873470 100644 --- a/stf/src/cli.rs +++ b/stf/src/cli.rs @@ -208,10 +208,11 @@ pub fn cmd<'a>( }), ) .add_cmd( - Command::new("total-issuance") - .description("query total issuance for currency (public information)") + Command::new("info") + .description("query various statistics and settings for a currency (public information)") .runner(move |_args: &str, matches: &ArgMatches<'_>| { let (_mrenclave, shard) = get_identifiers(matches); + println!("Public information about currency {}", shard.encode().to_base58()); let top: TrustedOperation = PublicGetter::total_issuance(shard) .into(); let res = perform_operation(matches, &top); @@ -229,7 +230,48 @@ pub fn cmd<'a>( } else { BalanceType::from_num(0) }; - println!("{}", bal); + println!(" total issuance: {}", bal); + + let top: TrustedOperation = PublicGetter::participant_count(shard) + .into(); + if let Some(v) = perform_operation(matches, &top) { + if let Ok(vd) = ParticipantIndexType::decode(&mut v.as_slice()) { + println!(" participant count: {}", vd); + } else { println!(" participant count: error decoding"); } + } else { println!(" participant count: undisclosed (might be REGISTERING phase?)"); }; + + let top: TrustedOperation = PublicGetter::meetup_count(shard) + .into(); + if let Some(v) = perform_operation(matches, &top) { + if let Ok(vd) = MeetupIndexType::decode(&mut v.as_slice()) { + println!(" meetup count: {}", vd); + } else { println!(" meetup count: error decoding"); } + } else { println!(" meetup count: unknown"); }; + + let top: TrustedOperation = PublicGetter::ceremony_reward(shard) + .into(); + if let Some(v) = perform_operation(matches, &top) { + if let Ok(vd) = BalanceType::decode(&mut v.as_slice()) { + println!(" ceremony reward: {}", vd); + } else { println!(" ceremony reward: error decoding"); } + } else { println!(" ceremony reward: unknown"); }; + + let top: TrustedOperation = PublicGetter::location_tolerance(shard) + .into(); + if let Some(v) = perform_operation(matches, &top) { + if let Ok(vd) = u32::decode(&mut v.as_slice()) { + println!(" location tolerance: {}m", vd); + } else { println!(" location tolerance: error decoding"); } + } else { println!(" location tolerance: unknown"); }; + + let top: TrustedOperation = PublicGetter::time_tolerance(shard) + .into(); + if let Some(v) = perform_operation(matches, &top) { + if let Ok(vd) = Moment::decode(&mut v.as_slice()) { + println!(" time tolerance: {}m", vd); + } else { println!(" time tolerance: unknown nodecode"); } + } else { println!(" time tolerance: unknown"); }; + Ok(()) }), ) diff --git a/stf/src/lib.rs b/stf/src/lib.rs index a641e76e9f..354b79c893 100644 --- a/stf/src/lib.rs +++ b/stf/src/lib.rs @@ -116,7 +116,12 @@ impl From for Getter { #[derive(Encode, Decode, Clone, Debug)] #[allow(non_camel_case_types)] pub enum PublicGetter { - total_issuance(CurrencyIdentifier), + total_issuance(CurrencyIdentifier), + participant_count(CurrencyIdentifier), + meetup_count(CurrencyIdentifier), + ceremony_reward(CurrencyIdentifier), + location_tolerance(CurrencyIdentifier), + time_tolerance(CurrencyIdentifier), } #[derive(Encode, Decode, Clone, Debug)] diff --git a/stf/src/sgx.rs b/stf/src/sgx.rs index c5b8037ce3..ab1cc229b0 100644 --- a/stf/src/sgx.rs +++ b/stf/src/sgx.rs @@ -170,7 +170,37 @@ impl Stf { let c_index = encointer_scheduler::Module::::current_ceremony_index(); let balance: BalanceEntry = encointer_balances::Module::::total_issuance_entry(cid); Some(balance.encode()) - } + }, + PublicGetter::participant_count(cid) => { + let c_index = encointer_scheduler::Module::::current_ceremony_index(); + match encointer_scheduler::Module::::current_phase() { + CeremonyPhaseType::REGISTERING => { + warn!("querying participant count during registering phase not allowed for privacy reasons"); + None + }, + _ => { + let count = encointer_ceremonies::Module::::participant_count((cid, c_index)); + Some(count.encode()) + } + } + }, + PublicGetter::meetup_count(cid) => { + let c_index = encointer_scheduler::Module::::current_ceremony_index(); + let count = encointer_ceremonies::Module::::meetup_count((cid, c_index)); + Some(count.encode()) + }, + PublicGetter::ceremony_reward(cid) => { + let reward = encointer_ceremonies::Module::::ceremony_reward(); + Some(reward.encode()) + }, + PublicGetter::location_tolerance(cid) => { + let tol = encointer_ceremonies::Module::::location_tolerance(); + Some(tol.encode()) + }, + PublicGetter::time_tolerance(cid) => { + let tol = encointer_ceremonies::Module::::time_tolerance(); + Some(tol.encode()) + } } } ) diff --git a/substratee-node-primitives/Cargo.toml b/substratee-node-primitives/Cargo.toml index 288dc1774d..0998dad06f 100644 --- a/substratee-node-primitives/Cargo.toml +++ b/substratee-node-primitives/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substratee-node-primitives" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" authors = ["clangenbacher "] edition = "2018" diff --git a/worker/Cargo.toml b/worker/Cargo.toml index f89b6fee43..6777dcdca8 100644 --- a/worker/Cargo.toml +++ b/worker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "encointer-worker" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" authors = ["Supercomputing Systems AG "] build = "build.rs" edition = "2018" diff --git a/worker/worker-api/Cargo.toml b/worker/worker-api/Cargo.toml index 3843c1e640..75262b44a0 100644 --- a/worker/worker-api/Cargo.toml +++ b/worker/worker-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "substratee-worker-api" -version = "0.6.8-sub2.0.0-alpha.7" +version = "0.6.9-sub2.0.0-alpha.7" authors = ["Supercomputing Systems AG "] edition = "2018"