From b69099244c6a0f0f604ca345aa5e2d3add1b4849 Mon Sep 17 00:00:00 2001 From: Cyson Date: Sun, 19 Jun 2022 12:23:09 -0700 Subject: [PATCH 1/3] Add oracle price abstaining script --- scripts/oracle/abstain_oracle_voting.py | 85 +++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 scripts/oracle/abstain_oracle_voting.py diff --git a/scripts/oracle/abstain_oracle_voting.py b/scripts/oracle/abstain_oracle_voting.py new file mode 100644 index 0000000000..f542df5b21 --- /dev/null +++ b/scripts/oracle/abstain_oracle_voting.py @@ -0,0 +1,85 @@ +import time +import subprocess +import requests +from pathlib import Path +import sys + +# for internal loadtest only +CMD_TMPL = "printf '{password}\n' | " + str(Path.home()) + "/go/bin/seid" +PREVOTE_TMPL = ( + " tx oracle aggregate-prevote abc 0uusdc,00uatom {val_addr} --from={key} " + "--chain-id={chain_id} --fees=1000usei --gas=2000 -y --broadcast-mode=sync" +) +VOTE_TMPL = ( + " tx oracle aggregate-vote abc 0uusdc,0uatom {val_addr} --from={key} " + "--chain-id={chain_id} --fees=1000usei --gas=2000 -y --broadcast-mode=sync" +) + +KEY = "default_account" +CHAIN_ID = "sei-internal-testnet" +PASSWORD = "" +ADDR = "" +VAL_ADDR = "" + +def get_current_vote_period(): + res = requests.get("http://localhost:26657/blockchain") + body = res.json() + return int(body["result"]["last_height"]) // 10 + +def vote_for_period(): + print("vote") + result = subprocess.check_output( + [CMD_TMPL.format(password=PASSWORD) + VOTE_TMPL.format(key=KEY, chain_id=CHAIN_ID, val_addr=VAL_ADDR)], + stderr=subprocess.STDOUT, + shell=True, + ) + +def prevote_for_period(): + print("prevote") + result = subprocess.check_output( + [CMD_TMPL.format(password=PASSWORD) + PREVOTE_TMPL.format(key=KEY, chain_id=CHAIN_ID, val_addr=VAL_ADDR)], + stderr=subprocess.STDOUT, + shell=True, + ) + +def vote_loop(interval=1): + last_prevoted_period = -1 + last_voted_period = -1 + while True: + time.sleep(interval) + current_vote_period = get_current_vote_period() + if last_prevoted_period > last_voted_period and last_prevoted_period < current_vote_period: + vote_for_period() + last_voted_period = last_prevoted_period + elif last_prevoted_period == -1 or (last_voted_period >= last_prevoted_period and last_prevoted_period < current_vote_period): + prevote_for_period() + last_prevoted_period = current_vote_period + +def main(): + global KEY + global CHAIN_ID + global PASSWORD + global VAL_ADDR + args = sys.argv[1:] + KEY = args[0] + CHAIN_ID = args[1] + PASSWORD = args[2] + VAL_ADDR = args[3] + + print(args) + + # fetch validator address if not provided + if not VAL_ADDR: + ADDR = subprocess.check_output([CMD_TMPL.format(password=PASSWORD) + f" keys show {KEY} -a"], stderr=subprocess.STDOUT, + shell=True,).decode()[:-1] + + VAL_ADDR = subprocess.check_output( + [CMD_TMPL.format(password=PASSWORD) + f" query staking delegations {ADDR} | grep validator_address | cut -d':' -f2 | xargs"], + stderr=subprocess.STDOUT, + shell=True, + ).decode()[:-1] + + vote_loop() + +if __name__ == "__main__": + main() \ No newline at end of file From 4e4c0aa9567a873284e2d38be8114cee10000f11 Mon Sep 17 00:00:00 2001 From: Cyson Date: Mon, 20 Jun 2022 22:15:55 -0700 Subject: [PATCH 2/3] Fix gas fee err --- scripts/oracle/abstain_oracle_voting.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/oracle/abstain_oracle_voting.py b/scripts/oracle/abstain_oracle_voting.py index f542df5b21..77c595a3e1 100644 --- a/scripts/oracle/abstain_oracle_voting.py +++ b/scripts/oracle/abstain_oracle_voting.py @@ -7,12 +7,12 @@ # for internal loadtest only CMD_TMPL = "printf '{password}\n' | " + str(Path.home()) + "/go/bin/seid" PREVOTE_TMPL = ( - " tx oracle aggregate-prevote abc 0uusdc,00uatom {val_addr} --from={key} " - "--chain-id={chain_id} --fees=1000usei --gas=2000 -y --broadcast-mode=sync" + " tx oracle aggregate-prevote abc 0uusdc,0uatom {val_addr} --from={key} " + "--chain-id={chain_id} --fees=2000usei -y --broadcast-mode=sync" ) VOTE_TMPL = ( " tx oracle aggregate-vote abc 0uusdc,0uatom {val_addr} --from={key} " - "--chain-id={chain_id} --fees=1000usei --gas=2000 -y --broadcast-mode=sync" + "--chain-id={chain_id} --fees=2000usei -y --broadcast-mode=sync" ) KEY = "default_account" From 4ea23ce40e79918ed405e3056108b49cff2d3732 Mon Sep 17 00:00:00 2001 From: Cyson Date: Mon, 20 Jun 2022 22:48:44 -0700 Subject: [PATCH 3/3] Resolve comments --- scripts/oracle/abstain_oracle_voting.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/scripts/oracle/abstain_oracle_voting.py b/scripts/oracle/abstain_oracle_voting.py index 77c595a3e1..c2a85e4e13 100644 --- a/scripts/oracle/abstain_oracle_voting.py +++ b/scripts/oracle/abstain_oracle_voting.py @@ -16,7 +16,7 @@ ) KEY = "default_account" -CHAIN_ID = "sei-internal-testnet" +CHAIN_ID = "sei-testnet-2" PASSWORD = "" ADDR = "" VAL_ADDR = "" @@ -66,19 +66,13 @@ def main(): PASSWORD = args[2] VAL_ADDR = args[3] - print(args) - # fetch validator address if not provided if not VAL_ADDR: - ADDR = subprocess.check_output([CMD_TMPL.format(password=PASSWORD) + f" keys show {KEY} -a"], stderr=subprocess.STDOUT, - shell=True,).decode()[:-1] - VAL_ADDR = subprocess.check_output( - [CMD_TMPL.format(password=PASSWORD) + f" query staking delegations {ADDR} | grep validator_address | cut -d':' -f2 | xargs"], + [CMD_TMPL.format(password=PASSWORD) + f" keys show {KEY} --bech val | grep address | cut -d':' -f2 | xargs"], stderr=subprocess.STDOUT, shell=True, ).decode()[:-1] - vote_loop() if __name__ == "__main__":