2018-11-23 23:58:49 +00:00
|
|
|
import
|
2019-03-07 13:59:28 +00:00
|
|
|
ospaths, chronos, json_serialization, strformat,
|
2018-12-28 16:51:40 +00:00
|
|
|
spec/[datatypes, crypto, digest, beaconstate], beacon_chain_db, conf
|
2018-11-29 01:08:34 +00:00
|
|
|
|
|
|
|
const
|
2019-02-19 23:07:56 +00:00
|
|
|
WEAK_SUBJECTVITY_PERIOD* = uint64(4 * 30 * 24 * 60 * 60) div SECONDS_PER_SLOT
|
2018-11-29 01:08:34 +00:00
|
|
|
# TODO: This needs revisiting.
|
|
|
|
# Why was the validator WITHDRAWAL_PERIOD altered in the spec?
|
2018-11-23 23:58:49 +00:00
|
|
|
|
|
|
|
proc obtainTrustedStateSnapshot*(db: BeaconChainDB): Future[BeaconState] {.async.} =
|
|
|
|
# In case our latest state is too old, we must obtain a recent snapshot
|
|
|
|
# of the state from a trusted location. This is explained in detail here:
|
|
|
|
# https://notes.ethereum.org/oaQV3IF5R2qlJuW-V1r1ew#Beacon-chain-sync
|
|
|
|
|
|
|
|
# TODO: implement this:
|
|
|
|
#
|
|
|
|
# 1. Specify a large set of trusted state signees
|
|
|
|
# (perhaps stored in a config file)
|
|
|
|
#
|
|
|
|
# 2. Download a signed state hash from a known location
|
|
|
|
# (The known location can be either a HTTPS host or a DHT record)
|
|
|
|
#
|
|
|
|
# 3. Check that enough of the specified required signatures are present
|
|
|
|
#
|
|
|
|
# 4. Download a snapshot file from a known location
|
|
|
|
# (or just obtain it from the network using the ETH protocols)
|
|
|
|
#
|
|
|
|
# 5. Check that the state snapshot hash is correct and save it in the DB.
|
|
|
|
|
2019-01-25 14:17:35 +00:00
|
|
|
assert(false, "Not implemented")
|
2018-11-23 23:58:49 +00:00
|
|
|
|
2019-02-15 16:33:32 +00:00
|
|
|
proc createStateSnapshot*(
|
2019-03-07 13:59:28 +00:00
|
|
|
validatorDir: string, numValidators, firstValidator, genesisOffset: int,
|
|
|
|
outFile: string) =
|
|
|
|
|
|
|
|
var deposits: seq[Deposit]
|
|
|
|
for i in firstValidator..<numValidators:
|
|
|
|
deposits.add Json.loadFile(validatorDir / &"v{i:07}.deposit.json", Deposit)
|
|
|
|
|
2019-02-22 09:56:45 +00:00
|
|
|
let initialState = get_genesis_beacon_state(
|
2019-03-07 13:59:28 +00:00
|
|
|
deposits,
|
2019-02-15 16:33:32 +00:00
|
|
|
uint64(int(fastEpochTime() div 1000) + genesisOffset),
|
|
|
|
Eth1Data(), {})
|
2018-12-28 16:51:40 +00:00
|
|
|
|
2019-01-17 18:27:11 +00:00
|
|
|
var vr: Validator
|
2018-12-28 16:51:40 +00:00
|
|
|
Json.saveFile(outFile, initialState, pretty = true)
|
|
|
|
echo "Wrote ", outFile
|