Skip to content

Commit

Permalink
Added more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
savelev1 authored Sep 23, 2020
1 parent 0bf2157 commit b179c2f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions near-warchest-bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import shlex
import re
import math

configFileName = 'config.json';

Expand Down Expand Up @@ -92,8 +93,14 @@ def saveConfig(config):
with open(getFullPath(configFileName), "w") as file:
json.dump(config, file)

def getEpochLatestBlockHeight():
return int(runCommand("curl --silent https://rpc." + config["configurable"]["network"] + ".near.org/status | jq .sync_info.latest_block_height")["output"]);

def getCurrentEpochNum():
return math.ceil(getEpochLatestBlockHeight() / config["configurable"]["epochBlockLength"]);

def getEpochProgress():
latestBlockHeight = int(runCommand("curl --silent https://rpc." + config["configurable"]["network"] + ".near.org/status | jq .sync_info.latest_block_height")["output"])
latestBlockHeight = getEpochLatestBlockHeight()
startHeight = int(runCommand("curl --silent -d '{\"jsonrpc\": \"2.0\", \"method\": \"validators\", \"id\": \"dontcare\", \"params\": [null]}' -H 'Content-Type: application/json' https://rpc." + config["configurable"]["network"] + ".near.org | jq .result.epoch_start_height")["output"])
blockLeft = startHeight + config["configurable"]["epochBlockLength"] - latestBlockHeight
progress = 1 - blockLeft / config["configurable"]["epochBlockLength"]
Expand Down Expand Up @@ -178,6 +185,8 @@ def pingPool():
config['lastEpochProgress'] = epochProgress
saveConfig(config)

printAndLog(f"Epoch #{str(getCurrentEpochNum())}, progress: {str(epochProgress)}, latest block height: {str(getEpochLatestBlockHeight())}");

if isKickedOutPool():
printAndLog("Pool is kicked out in next epoch")

Expand Down Expand Up @@ -241,4 +250,3 @@ def pingPool():
printAndLog("Script ends \r\n\r\n")

# Script body end

0 comments on commit b179c2f

Please sign in to comment.