Skip to content

Commit

Permalink
client naming cleanup and some more logging. added cron bot-script
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain Brenzikofer committed Jun 21, 2020
1 parent 7f2c6be commit 10ac79e
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ########
Expand Down
4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <info@scs.ch>"]
edition = "2018"

Expand Down
90 changes: 90 additions & 0 deletions client/bot-community-sea-of-crete.sh
Original file line number Diff line number Diff line change
@@ -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

30 changes: 28 additions & 2 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <info@scs.ch>")
.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"))
Expand Down Expand Up @@ -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(())
Expand Down Expand Up @@ -795,4 +809,16 @@ fn get_current_phase(api: &Api<sr25519::Pair>) -> CeremonyPhaseType {
api.get_storage_value("EncointerScheduler", "CurrentPhase", None)
.or(Some(CeremonyPhaseType::default()))
.unwrap()
}

fn get_block_number(api: &Api<sr25519::Pair>) -> 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<sr25519::Pair>) -> CeremonyIndexType {
api.get_storage_value("EncointerScheduler", "CurrentCeremonyIndex", None)
.unwrap()
}

0 comments on commit 10ac79e

Please sign in to comment.