diff --git a/beacon_chain/beacon_node.nim b/beacon_chain/beacon_node.nim index 265cf1fa6..547b5189c 100644 --- a/beacon_chain/beacon_node.nim +++ b/beacon_chain/beacon_node.nim @@ -28,7 +28,7 @@ const topicBeaconBlocks = "ethereum/2.1/beacon_chain/blocks" topicAttestations = "ethereum/2.1/beacon_chain/attestations" - stateStoragePeriod = EPOCH_LENGTH * 10 # Save states once per this number of slots. TODO: Find a good number. + stateStoragePeriod = EPOCH_LENGTH.uint64 * 10 # Save states once per this number of slots. TODO: Find a good number. func shortHash(x: auto): string = @@ -434,7 +434,11 @@ when isMainModule: info "Starting beacon node", slotsSinceFinalization = node.beaconState.slotDistanceFromNow(), - stateSlot = humaneSlotNum(node.beaconState.slot) + stateSlot = humaneSlotNum(node.beaconState.slot), + SHARD_COUNT, + EPOCH_LENGTH, + SLOT_DURATION, + SPEC_VERSION node.addLocalValidators() node.processBlocks() diff --git a/beacon_chain/spec/datatypes.nim b/beacon_chain/spec/datatypes.nim index ee188041f..7266e6148 100644 --- a/beacon_chain/spec/datatypes.nim +++ b/beacon_chain/spec/datatypes.nim @@ -40,11 +40,16 @@ import # TODO Many of these constants should go into a config object that can be used # to run.. well.. a chain with different constants! const + SPEC_VERSION* = "0.2.0" ## \ + ## Spec version we're aiming to be compatible with, right now + ## TODO: improve this scheme once we can negotiate versions in protocol + # Misc # https://github.com/ethereum/eth2.0-specs/blob/v0.2.0/specs/core/0_beacon-chain.md#misc - SHARD_COUNT* = 1024 ##\ + SHARD_COUNT* {.intdefine.} = 1024 ##\ ## Number of shards supported by the network - validators will jump around ## between these shards and provide attestations to their state. + ## Compile with -d:SHARD_COUNT=4 for fewer shard (= better with low validator counts) TARGET_COMMITTEE_SIZE* = 2^7 ##\ ## Number of validators in the committee attesting to one shard @@ -89,10 +94,11 @@ const ## the validator pool # Time parameter, here so that GENESIS_EPOCH can access it - EPOCH_LENGTH* = 64 ##\ + EPOCH_LENGTH* {.intdefine.} = 64 ##\ ## (~6.4 minutes) ## slots that make up an epoch, at the end of which more heavy ## processing is done + ## Compile with -d:EPOCH_LENGTH=4 for shorter epochs # Initial values # https://github.com/ethereum/eth2.0-specs/blob/v0.2.0/specs/core/0_beacon-chain.md#initial-values diff --git a/beacon_chain/state_transition.nim b/beacon_chain/state_transition.nim index 2e4214bc5..8d39a82bb 100644 --- a/beacon_chain/state_transition.nim +++ b/beacon_chain/state_transition.nim @@ -517,7 +517,8 @@ func processEpoch(state: var BeaconState) = let # Previous epoch boundary # TODO check this with spec... negative_uint_hack = - if state.slot < 2 * EPOCH_LENGTH: 0'u64 else: state.slot - 2 * EPOCH_LENGTH + if state.slot < 2'u64 * EPOCH_LENGTH: 0'u64 + else: state.slot - 2'u64 * EPOCH_LENGTH previous_epoch_boundary_attestations = boundary_attestations( state, get_block_root(state, negative_uint_hack), diff --git a/tests/simulation/start.sh b/tests/simulation/start.sh index 25518650f..e030965ff 100755 --- a/tests/simulation/start.sh +++ b/tests/simulation/start.sh @@ -25,11 +25,15 @@ mkdir -p $BUILD_OUTPUTS_DIR BEACON_NODE_BIN=$BUILD_OUTPUTS_DIR/beacon_node VALIDATOR_KEYGEN_BIN=$BUILD_OUTPUTS_DIR/validator_keygen -SLOT_DURATION="-d:SLOT_DURATION=3" # Default is 6 + +# Run with "SHARD_COUNT=4 ./start.sh" to change these +DEFS="-d:SHARD_COUNT=${SHARD_COUNT:-4} " +DEFS+="-d:EPOCH_LENGTH=${EPOCH_LENGTH:-8} " +DEFS+="-d:SLOT_DURATION=${SLOT_DURATION:-3} " if [[ -z "$SKIP_BUILDS" ]]; then - nim c -o:"$VALIDATOR_KEYGEN_BIN" "$SLOT_DURATION" -d:release beacon_chain/validator_keygen - nim c -o:"$BEACON_NODE_BIN" "$SLOT_DURATION" beacon_chain/beacon_node + nim c -o:"$VALIDATOR_KEYGEN_BIN" $DEFS -d:release beacon_chain/validator_keygen + nim c -o:"$BEACON_NODE_BIN" $DEFS beacon_chain/beacon_node fi if [ ! -f $STARTUP_FILE ]; then