From af3355e0f8cb112a3fceea1c6767714f40b74c77 Mon Sep 17 00:00:00 2001 From: tersec Date: Wed, 12 Aug 2020 14:16:59 +0000 Subject: [PATCH] create local testnet mode for eth2_network (#1494) --- beacon_chain/eth2_network.nim | 16 ++++++++++++---- beacon_chain/spec/state_transition_epoch.nim | 6 +++--- scripts/launch_local_testnet.sh | 2 +- tests/simulation/start.sh | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/beacon_chain/eth2_network.nim b/beacon_chain/eth2_network.nim index ed980dc17..0712a455c 100644 --- a/beacon_chain/eth2_network.nim +++ b/beacon_chain/eth2_network.nim @@ -214,9 +214,13 @@ const ConcurrentConnections* = 4 ## Maximum number of active concurrent connection requests. - SeenTableTimeTimeout* = 5.minutes + SeenTableTimeTimeout* = + when not defined(local_testnet): 5.minutes else: 10.seconds + ## Seen period of time for timeout connections - SeenTableTimeDeadPeer* = 5.minutes + SeenTableTimeDeadPeer* = + when not defined(local_testnet): 5.minutes else: 10.seconds + ## Period of time for dead peers. SeenTableTimeIrrelevantNetwork* = 24.hours ## Period of time for `IrrelevantNetwork` error reason. @@ -890,8 +894,12 @@ proc init*(T: type Eth2Node, conf: BeaconNodeConf, enrForkId: ENRForkID, result.switch = switch result.wantedPeers = conf.maxPeers result.peerPool = newPeerPool[Peer, PeerID](maxPeers = conf.maxPeers) - result.connectTimeout = 1.minutes - result.seenThreshold = 5.minutes + when not defined(local_testnet): + result.connectTimeout = 1.minutes + result.seenThreshold = 5.minutes + else: + result.connectTimeout = 10.seconds + result.seenThreshold = 10.seconds result.seenTable = initTable[PeerID, SeenItem]() result.connTable = initHashSet[PeerID]() result.connQueue = newAsyncQueue[PeerAddr](ConcurrentConnections) diff --git a/beacon_chain/spec/state_transition_epoch.nim b/beacon_chain/spec/state_transition_epoch.nim index 14873d6cf..b9f6a8931 100644 --- a/beacon_chain/spec/state_transition_epoch.nim +++ b/beacon_chain/spec/state_transition_epoch.nim @@ -143,9 +143,9 @@ proc process_justification_and_finalization*(state: var BeaconState, # testnet0 and testnet1 have 8 non-attesting validators each, by default if missing_all_validators.len > 15: - fatal "Missing too many attesters from previous epoch in verifyFinalization mode", - missing_all_validators - doAssert false + info "Missing too many attesters from previous epoch in verifyFinalization mode", + missing_all_validators, + epoch = get_current_epoch(state) # This epoch processing is the last time these previous attestations can # matter -- in the next epoch, they'll be 2 epochs old, when BeaconState diff --git a/scripts/launch_local_testnet.sh b/scripts/launch_local_testnet.sh index 71864b4ec..2a1ffa04b 100755 --- a/scripts/launch_local_testnet.sh +++ b/scripts/launch_local_testnet.sh @@ -160,7 +160,7 @@ else fi NETWORK_NIM_FLAGS=$(scripts/load-testnet-nim-flags.sh ${NETWORK}) -$MAKE -j2 LOG_LEVEL="${LOG_LEVEL}" NIMFLAGS="-d:insecure -d:testnet_servers_image ${NETWORK_NIM_FLAGS}" beacon_node deposit_contract +$MAKE -j2 LOG_LEVEL="${LOG_LEVEL}" NIMFLAGS="-d:insecure -d:testnet_servers_image -d:local_testnet ${NETWORK_NIM_FLAGS}" beacon_node deposit_contract PIDS="" WEB3_ARG="" diff --git a/tests/simulation/start.sh b/tests/simulation/start.sh index 7c35fabe1..8ca8353c2 100755 --- a/tests/simulation/start.sh +++ b/tests/simulation/start.sh @@ -49,7 +49,7 @@ mkdir -p "$SECRETS_DIR" cd "$GIT_ROOT" -CUSTOM_NIMFLAGS="${NIMFLAGS} -d:useSysAsserts -d:chronicles_sinks:textlines,json[file] -d:const_preset=mainnet -d:insecure" +CUSTOM_NIMFLAGS="${NIMFLAGS} -d:useSysAsserts -d:chronicles_sinks:textlines,json[file] -d:const_preset=mainnet -d:insecure -d:local_testnet" GANACHE_BLOCK_TIME=5 # Run with "SLOTS_PER_EPOCH=8 ./start.sh" to change these