From 10ac79e9d2ad91394506cd07475ca6b68304e593 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Sun, 21 Jun 2020 14:16:11 +0200 Subject: [PATCH] client naming cleanup and some more logging. added cron bot-script --- Cargo.lock | 4 +- Makefile | 2 +- client/Cargo.toml | 4 +- client/bot-community-sea-of-crete.sh | 90 ++++++++++++++++++++++++++++ client/src/main.rs | 30 +++++++++- 5 files changed, 123 insertions(+), 7 deletions(-) create mode 100644 client/bot-community-sea-of-crete.sh diff --git a/Cargo.lock b/Cargo.lock index a3cd0be608..d26b6757ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -562,8 +562,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" [[package]] -name = "encointer-client" -version = "0.6.5-sub2.0.0-alpha.7" +name = "encointer-client-teeproxy" +version = "0.6.6-sub2.0.0-alpha.7" dependencies = [ "base58", "blake2-rfc", diff --git a/Makefile b/Makefile index 27159a3ff3..70b875d0c2 100755 --- a/Makefile +++ b/Makefile @@ -109,7 +109,7 @@ Client_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(Worker_Include_Pa Client_Rust_Path := target/$(OUTPUT_PATH) Client_Path := bin -Client_Binary := encointer-client +Client_Binary := encointer-client-teeproxy Client_Name := $(Client_Path)/$(Client_Binary) ######## Enclave settings ######## diff --git a/client/Cargo.toml b/client/Cargo.toml index 5d77fb5bbf..63b6caa241 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -1,6 +1,6 @@ [package] -name = "encointer-client" -version = "0.6.5-sub2.0.0-alpha.7" +name = "encointer-client-teeproxy" +version = "0.6.6-sub2.0.0-alpha.7" authors = ["Supercomputing Systems AG "] edition = "2018" diff --git a/client/bot-community-sea-of-crete.sh b/client/bot-community-sea-of-crete.sh new file mode 100644 index 0000000000..c705058462 --- /dev/null +++ b/client/bot-community-sea-of-crete.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# this script should be called once per ceremony phase in order to maintain a constant population +# on Cantillon it is sufficient to call it once per day with cron +# +# as a normal user, run +# > crontab -e +# +# and add one line: +# 0 8 * * * timeout 600s /home/cantillon/bin/bot-community-sea-of-crete.sh >> /home/cantillon/bin/bot-community-sea-of-crete.log 2>&1 +# +# because of issue #11 the client can hang if calls fail and we need to timeout the script +# + +date + +# Cantillon node endpoint +NURL=wss://cantillon.encointer.org +NPORT=443 +# Cantillon worker endpoint +WURL=wss://substratee03.scs.ch +WPORT=443 + +nctr="/home/cantillon/bin/encointer-client -u $NURL -p $NPORT -U $WURL -P $WPORT" +cd /home/cantillon/bin + +phase=$($nctr get-phase) +echo $phase + +MRENCLAVE=J9D51UiwXnNbG1e76q7MivWmA944JdWXvsTUpM2HREta +cid=7eLSZLSMShw4ju9GvuMmoVgeZxZimtvsGTSvLEdvcRqQ + +accounts=(//AliceIncognito \ +//BobIncognito \ +//CharlieIncognito) + +echo "as Alice will pay for all proxy fees, check her balance" +$nctr balance //Alice + +if [ $phase = "REGISTERING" ]; then + for p in ${accounts[@]}; do + $nctr trusted balance $p --mrenclave $MRENCLAVE --shard $cid + $nctr trusted register-participant $p --mrenclave $MRENCLAVE --shard $cid + done + + sleep 60 + + echo "verify registrations:" + + for p in ${accounts[@]}; do + $nctr trusted get-registration $p --mrenclave $MRENCLAVE --shard $cid + done + +fi + +if [ $phase = "ASSIGNING" ]; then + echo "verify meetup assignments NOT YET SUPPORTED BY CLIENT" +fi + +if [ $phase = "ATTESTING" ]; then + echo "performing bot meetup. as we can't look up meetup assignments, we assume everybody got assigned to the same meetup" + N=${#accounts[@]} + echo "number of participants is $N" + claims=() + for ((i = 0; i < $N; i++)); do + #claim="claim-for-${m[i]}-vote-$N" # + claim="" + # queries can fail (see worker #12). just try again + while [ -z "$claim" ]; do + claim=$($nctr trusted new-claim ${accounts[i]} $N --mrenclave $MRENCLAVE --shard $cid) + sleep 1 + done + echo "CLAIM: $claim" + claims+=( $claim ) + done + for ((i = 0; i < $N; i++)); do + attestations=() + for ((j = 0; j < $N; j++)); do + if [[ $i -eq $j ]]; then continue; fi + echo "${accounts[$j]} attests:${claims[$i]}" + attestation=$($nctr sign-claim ${accounts[$j]} ${claims[$i]}) + echo "ATTESTATION: $attestation" + attestations+=( $attestation ) + done + echo "register attestations for ${accounts[$i]}" + echo "command: $nctr trusted register-attestations ${accounts[$i]} ${attestations[@]} --mrenclave $MRENCLAVE --shard $cid" + $nctr trusted register-attestations ${accounts[$i]} ${attestations[@]} --mrenclave $MRENCLAVE --shard $cid + done +fi + diff --git a/client/src/main.rs b/client/src/main.rs index 72220f0ded..18b75dfa87 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -121,10 +121,10 @@ fn main() { .default_value("2000") .help("worker port"), ) - .name("substratee-client") + .name("encointer-client-teeproxy") .version(VERSION) .author("Supercomputing Systems AG ") - .about("interact with substraTEE node and workers") + .about("interact with encointer-node-teeproxy and workers") .after_help("stf subcommands depend on the stf crate this has been built against") }) .args(|_args, matches| matches.value_of("environment").unwrap_or("dev")) @@ -419,6 +419,20 @@ fn main() { .description("read current ceremony phase from chain") .runner(|_args: &str, matches: &ArgMatches<'_>| { let api = get_chain_api(matches); + + // >>>> add some debug info as well + let bn = get_block_number(&api); + info!("block number: {}", bn); + let cindex = get_ceremony_index(&api); + info!("ceremony index: {}", cindex); + let tnext: Moment = api.get_storage_value( + "EncointerScheduler", + "NextPhaseTimestamp", + None + ).unwrap(); + info!("next phase timestamp: {}", tnext); + // <<<< + let phase = get_current_phase(&api); println!("{:?}", phase); Ok(()) @@ -795,4 +809,16 @@ fn get_current_phase(api: &Api) -> CeremonyPhaseType { api.get_storage_value("EncointerScheduler", "CurrentPhase", None) .or(Some(CeremonyPhaseType::default())) .unwrap() +} + +fn get_block_number(api: &Api) -> BlockNumber { + let hdr: Header = api.get_header(None).unwrap(); + debug!("decoded: {:?}", hdr); + //let hdr: Header= Decode::decode(&mut .as_bytes()).unwrap(); + hdr.number +} + +fn get_ceremony_index(api: &Api) -> CeremonyIndexType { + api.get_storage_value("EncointerScheduler", "CurrentCeremonyIndex", None) + .unwrap() } \ No newline at end of file