To generate the genesis file for Gaia-7002, we exported the state from Gaia-7001, at height 24570 where it halted. The current version of gaiad has a bug in gaiad export, but we were able to use a workaround to successfully export the state. (state.json)
Due to bugs in gaiad v0.22.0, there were some inconsistencies in the state which we corrected.
Builder script
First we load the exported state.
import json
from hashlib import sha256
from base64 import b64decode
j = json.loads(open("7001state.json","r").read())
Then we removed validators who never signed blocks on Gaia-7001. This should help with time to startup of the chain and speed of consensus.
#validator addresses which hubble lists as being bonded validators but never signed a block
pks = ['28d64d33cd086452e491becfc15f3d31054db144', '26cf59b48aa6ff3a5126330782090b19bd3b0e87', '1e1a2486dce3b96e08f41d313908088ad33ed491', '1866433301a542afd800b971d6390551088a0903', '10ddf9c6aaf8e6f91f33a4fae3ebeab3c98136d2', '00122e5e691286ac03220fcee3ebec038067dded', '60229e2e273297fe00219e46dffb8f76844cdef9', 'd9e215abd1d680db4d60f3b347a07f949ea5242a', 'e33184c1eab6fb7c6ccb893963e8534c277fa842', 'd9bb73add5962326c5b8c36494dac1c3d7425db5', 'cc4c1d46ddba0912e9d6e4dd1f4a0897a945c68c', 'b3cec3cbafba428bf33fd2204e11ca2232426593', '9a03741063366e11ec0347f6c80a2891c799003f', '5a6b67f68591404c5079bebd7a6b7e046779d3b6', '4b75e0191ab777afb6787b94e256388e78d6a910', '3e504d10079dc278960c0f214235b840e23392b2', '52b590a0de161917dfa8215f990506c4df7a9d0d', '09f1395bfcdb45aa6f09cde85aa8b69246131962', 'ebcaa6886da3c8ac73cfdf8fea26e8d9b14b4e4e']
#remove validators who never came online according to hubble
j['app_state']['stake']['validators'] = [vi for vi in j['app_state']['stake']['validators'] if sha256(b64decode(vi['pub_key']['value'])).digest().hex()[:40] not in pks]
#filter out bonds to no longer existing validators
j['app_state']['stake']['bonds'] = [b for b in j['app_state']['stake']['bonds'] if b['validator_addr'] in [v['owner'] for v in j['app_state']['stake']['validators']]]
Due to a bug, validators in Gaia-7001 were being listed as unbonded in the state, even though they had voting power. Also fixed the “do-not-modify” setting.
#set bonded status and fix do-not-modify flag on validators
for v in j['app_state']['stake']['validators']:
desc = v["description"]
for k,dv in desc.items():
if dv == "[do-not-modify]":
dv = ""
desc[k] = dv
v.update(status=2, description=desc)
We also added a validator entry for Shapeshift.
#adding a validator for shapeshift
j['app_state']['stake']['validators'].append({
"owner": "cosmosaccaddr1ztc70khr9aghgwmuxap5y9ufavpxutjtkvhpe7",
"pub_key": {
"type": "tendermint/PubKeyEd25519",
"value": "7vURd1EqPVfI/1viF/+LNm9lwaBAN/tSuoJ+Od972z0="
},
"revoked": False,
"status": 2,
"tokens": "100",
"delegator_shares": "100",
"description": {
"moniker": "Project Bohr",
"identity": "",
"website": "",
"details": ""
},
"bond_height": "0",
"bond_intra_tx_counter": 0,
"proposer_reward_pool": None,
"commission": "0",
"commission_max": "0",
"commission_change_rate": "0",
"commission_change_today": "0",
"prev_bonded_tokens": "0"
})
j['app_state']['stake']['bonds'].append({
'height': '0', 'validator_addr': 'cosmosaccaddr1ztc70khr9aghgwmuxap5y9ufavpxutjtkvhpe7', 'delegator_addr': 'cosmosaccaddr1ztc70khr9aghgwmuxap5y9ufavpxutjtkvhpe7', 'shares': '100'
})
Now that the data in app_state
has been updated, we need to write the set of validators back to the object that gets passed to tendermint to start the chain.
#update main validator section to match validators from state machine
j["validators"] = [{"pub_key":v["pub_key"], "power":v["tokens"], "name":v["description"]["moniker"]} for v in j["app_state"]["stake"]["validators"]]
We also recalculated the totals for bonded/loose tokens, which were not properly updated to reflect the steak given to the faucet in Gaia-7001.
coinsToMap = lambda x: type(x)==list and {c["denom"]:c["amount"] for c in x} or {}
#update pool total values to be accurate
j["app_state"]["stake"]["pool"]["loose_tokens"] = str(sum([int(coinsToMap(a["coins"]).get("steak",0)) for a in j["app_state"]["accounts"]]))
j["app_state"]["stake"]["pool"]["bonded_tokens"] = str(sum([int(v["power"]) for v in j["validators"]]))
Finally we set misc parameters and wrote the json back to a file.
#set chain id and timestamp
j["chain_id"] = "gaia-7002"
j["genesis_time"] = "2018-07-24T08:00:00.123456789Z"
open("7002-genesis.json","w").write(json.dumps(j, indent=2, sort_keys=True))
While the genesis file has been created, we’re still waiting on a final release of the software before we officially start Gaia-7002. So please stay tuned.