Merge remote-tracking branch 'origin/master' into epoch-state-2

This commit is contained in:
Jacek Sieka 2018-12-05 11:55:28 -06:00
commit eba4f18f71
No known key found for this signature in database
GPG Key ID: 6299FEB3EB6FA465
6 changed files with 65 additions and 10 deletions

View File

@ -1,7 +1,7 @@
import import
os, net, os, net, sequtils,
asyncdispatch2, chronicles, confutils, eth_p2p, eth_keys, asyncdispatch2, chronicles, confutils, eth_p2p, eth_keys,
spec/[beaconstate, datatypes, helpers], conf, time, fork_choice, spec/[beaconstate, datatypes, helpers, crypto], conf, time, fork_choice,
beacon_chain_db, validator_pool, mainchain_monitor, beacon_chain_db, validator_pool, mainchain_monitor,
sync_protocol, gossipsub_protocol, trusted_state_snapshots sync_protocol, gossipsub_protocol, trusted_state_snapshots
@ -67,16 +67,30 @@ proc sync*(node: BeaconNode): Future[bool] {.async.} =
return true return true
template findIt(s: openarray, predicate: untyped): int =
var res = -1
for i, it {.inject.} in s:
if predicate:
res = i
break
res
proc addLocalValidators*(node: BeaconNode) = proc addLocalValidators*(node: BeaconNode) =
for validator in node.config.validatorKeys: for validator in node.config.validatorKeys:
# TODO:
# 1. Parse the validator keys # 1. Parse the validator keys
# let privKey = loadPrivKey(validator)
let pubKey = privKey.pubKey()
# 2. Check whether the validators exist in the beacon state. # 2. Check whether the validators exist in the beacon state.
# (Report a warning otherwise) # (Report a warning otherwise)
# let idx = node.beaconState.validator_registry.findIt(it.pubKey == pubKey)
if idx == -1:
warn "Validator not in registry", pubKey
else:
# 3. Add the validators to node.attachedValidators # 3. Add the validators to node.attachedValidators
discard # TODO: Parse randao secret
node.attachedValidators.addLocalValidator(idx, pubKey, privKey, @[])
proc getAttachedValidator(node: BeaconNode, idx: int): AttachedValidator = proc getAttachedValidator(node: BeaconNode, idx: int): AttachedValidator =
let validatorKey = node.beaconState.validator_registry[idx].pubkey let validatorKey = node.beaconState.validator_registry[idx].pubkey

View File

@ -1,5 +1,5 @@
import import
confutils/defs confutils/defs, spec/crypto, milagro_crypto
type type
ValidatorKeyPath* = distinct string ValidatorKeyPath* = distinct string
@ -25,9 +25,14 @@ type
"Nimbus will automatically add the extensions .privkey and .pubkey.", "Nimbus will automatically add the extensions .privkey and .pubkey.",
shorthand: "v".}: seq[ValidatorKeyPath] shorthand: "v".}: seq[ValidatorKeyPath]
proc loadPrivKey*(p: ValidatorKeyPath): ValidatorPrivKey =
initSigKey(cast[seq[byte]](readFile(string(p) & ".privkey")))
proc parse*(T: type ValidatorKeyPath, input: TaintedString): T = proc parse*(T: type ValidatorKeyPath, input: TaintedString): T =
discard loadPrivKey(ValidatorKeyPath(input))
# TODO: # TODO:
# Check that the entered string is a valid base file name and # Check that the entered string is a valid base file name and
# that it has matching .privkey, .pubkey and .randaosecret files # that it has matching .privkey, and .randaosecret files
T(input) T(input)

View File

@ -20,3 +20,5 @@ type
template hash*(k: ValidatorPubKey|ValidatorPrivKey): Hash = template hash*(k: ValidatorPubKey|ValidatorPrivKey): Hash =
hash(k.getRaw) hash(k.getRaw)
proc pubKey*(pk: ValidatorPrivKey): ValidatorPubKey = fromSigKey(pk)

View File

@ -10,4 +10,6 @@ import
./test_block_processing, ./test_block_processing,
./test_helpers, ./test_helpers,
./test_ssz, ./test_ssz,
./test_validator ./test_validator,
./test_beacon_node,
./test_sync_protocol

View File

@ -0,0 +1,16 @@
# beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
unittest,
../beacon_chain/beacon_node
suite "Beacon node":
# Compile test
test "Compile":
discard

View File

@ -0,0 +1,16 @@
# beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
unittest,
../beacon_chain/sync_protocol
suite "Sync protocol":
# Compile test
test "Compile":
discard