From a9c026b957b12cbdcd6b86de782ce3732339360f Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Mon, 21 Jan 2019 21:42:37 +0200 Subject: [PATCH] More logging close to the code that fails often --- beacon_chain/beacon_node.nim | 26 ++++++++++++++++++++------ beacon_chain/validator_keygen.nim | 2 +- tests/simulation/.gitignore | 2 +- tests/simulation/start.sh | 6 +++--- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index eee129b95..0fc54e350 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -262,6 +262,8 @@ proc scheduleEpochActions(node: BeaconNode, epoch: uint64) = ## attestations from our attached validators. doAssert node != nil + debug "Scheduling epoch actions", epoch + # TODO: this copy of the state shouldn't be necessary, but please # see the comments in `get_beacon_proposer_index` var nextState = node.beaconState @@ -299,19 +301,30 @@ proc scheduleEpochActions(node: BeaconNode, epoch: uint64) = proc processBlocks*(node: BeaconNode) = node.network.subscribe(topicBeaconBlocks) do (newBlock: BeaconBlock): info "Block received", slot = newBlock.slot, - stateRoot = shortHash(newBlock.state_root) + stateRoot = shortHash(newBlock.state_root), + currentStateSlot = node.beaconState.slot + + # TODO: This should be replaced with the real fork-choice rule + if newBlock.slot <= node.beaconState.slot: + debug "Ignoring block" + return let newBlockRoot = hash_tree_root_final(newBlock) + var state = node.beaconState for slot in node.beaconState.slot + 1 ..< newBlock.slot: info "Skipping block", slot - let ok = updateState(node.beaconState, node.headBlockRoot, none[BeaconBlock](), {}) + let ok = updateState(state, node.headBlockRoot, none[BeaconBlock](), {}) + doAssert ok - let ok = updateState(node.beaconState, node.headBlockRoot, some(newBlock), {}) - doAssert ok + let ok = updateState(state, node.headBlockRoot, some(newBlock), {}) + if not ok: + debug "Ignoring non-validating block" + return node.headBlock = newBlock node.headBlockRoot = newBlockRoot + node.beaconState = state # TODO: # @@ -334,7 +347,7 @@ proc processBlocks*(node: BeaconNode) = node.attestationPool.add(a, node.beaconState) dynamicLogScope(node = node.config.tcpPort - 50000): - let epoch = node.beaconState.slot.epoch + let epoch = node.beaconState.timeSinceGenesis().toSlot div EPOCH_LENGTH node.scheduleEpochActions(epoch) runForever() @@ -348,7 +361,8 @@ proc createPidFile(filename: string) = when isMainModule: let config = load BeaconNodeConf - setLogLevel(config.logLevel) + if config.logLevel != LogLevel.NONE: + setLogLevel(config.logLevel) case config.cmd of createChain: diff --git a/beacon_chain/validator_keygen.nim b/beacon_chain/validator_keygen.nim index 3981690ff..e314e1f54 100644 --- a/beacon_chain/validator_keygen.nim +++ b/beacon_chain/validator_keygen.nim @@ -71,7 +71,7 @@ proc main() = withdrawal_credentials: withdrawalCredentials, randao_commitment: randaoCommitment))) - startupData.genesisTime = (now() div 1000) + 10 + startupData.genesisTime = (now() div 1000) writeFile(outPath / "startup.json", startupData) diff --git a/tests/simulation/.gitignore b/tests/simulation/.gitignore index 85b04005d..6dbccb1ed 100644 --- a/tests/simulation/.gitignore +++ b/tests/simulation/.gitignore @@ -1,2 +1,2 @@ -simulation-data +data/ diff --git a/tests/simulation/start.sh b/tests/simulation/start.sh index ee5b297b4..9742b4e8f 100755 --- a/tests/simulation/start.sh +++ b/tests/simulation/start.sh @@ -9,7 +9,7 @@ set -eu NUMBER_OF_VALIDATORS=99 cd $(dirname "$0") -SIMULATION_DIR=$PWD/simulation-data +SIMULATION_DIR=$PWD/data mkdir -p "$SIMULATION_DIR" STARTUP_FILE="$SIMULATION_DIR/startup.json" @@ -38,7 +38,7 @@ if [ ! -f $SNAPSHOT_FILE ]; then --out:$SNAPSHOT_FILE fi -MASTER_NODE_ADDRESS_FILE="$SIMULATION_DIR/data-0/beacon_node.address" +MASTER_NODE_ADDRESS_FILE="$SIMULATION_DIR/node-0/beacon_node.address" # Delete any leftover address files from a previous session if [ -f $MASTER_NODE_ADDRESS_FILE ]; then @@ -57,7 +57,7 @@ for i in $(seq 0 9); do done fi - DATA_DIR=$SIMULATION_DIR/data-$i + DATA_DIR=$SIMULATION_DIR/node-$i $BEACON_NODE_BIN \ --dataDir:"$DATA_DIR" \