log doppelganger attestation signature; rm withState.HashedBeaconState uses (#2608)

This commit is contained in:
tersec 2021-05-28 12:51:15 +00:00 committed by GitHub
parent 5be1f8bf93
commit 46c5a0110a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 19 additions and 52 deletions

View File

@ -246,11 +246,6 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ integer_squareroot OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
## Sync protocol
```diff
+ Compile OK
```
OK: 1/1 Fail: 0/1 Skip: 0/1
## SyncManager test suite
```diff
+ [SyncQueue] Async pending and resetWait() test OK
@ -322,4 +317,4 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
OK: 1/1 Fail: 0/1 Skip: 0/1
---TOTAL---
OK: 180/188 Fail: 0/188 Skip: 8/188
OK: 179/187 Fail: 0/187 Skip: 8/187

View File

@ -738,7 +738,6 @@ iterator getAncestorSummaries*(db: BeaconChainDB, root: Eth2Digest):
summaries = db.loadSummaries()
res: tuple[root: Eth2Digest, summary: BeaconBlockSummary]
blck: TrustedSignedBeaconBlock
foundOldSummary = false
res.root = root

View File

@ -142,7 +142,6 @@ proc updateCurrent(pool: var AttestationPool, wallSlot: Slot) =
proc oneIndex(bits: CommitteeValidatorsBits): Option[int] =
# Find the index of the set bit, iff one bit is set
var res = none(int)
var idx = 0
for idx in 0..<bits.len():
if bits[idx]:
if res.isNone():
@ -489,6 +488,10 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
# Fast path for when all remaining candidates fit
if candidates.lenu64 < MAX_ATTESTATIONS: candidates.len - 1
else: maxIndex(candidates)
# TODO slot not used; replace with _ when
# https://github.com/nim-lang/Nim/issues/15972 and
# https://github.com/nim-lang/Nim/issues/16217 are
# fixed in Status's Nim.
(_, slot, entry, j) = candidates[candidate]
candidates.del(candidate) # careful, `del` reorders candidates

View File

@ -58,6 +58,8 @@ template withStateVars*(
template stateData(): StateData {.inject, used.} = stateDataInternal
template hashedState(): HashedBeaconState {.inject, used.} =
stateDataInternal.data
template stateRoot(): Eth2Digest {.inject, used.} =
stateDataInternal.data.root
template blck(): BlockRef {.inject, used.} = stateDataInternal.blck
template root(): Eth2Digest {.inject, used.} = stateDataInternal.data.root

View File

@ -8,8 +8,7 @@
{.push raises: [Defect].}
import
../spec/[beaconstate, datatypes, digest, helpers, presets, validator],
./block_pools_types
../spec/[beaconstate, datatypes, digest, helpers, presets, validator]
# State-related functionality based on StateData instead of BeaconState

View File

@ -228,9 +228,6 @@ when hasGenesisDetection:
template blocks*(m: Eth1Monitor): Deque[Eth1Block] =
m.eth1Chain.blocks
template db(m: Eth1Monitor): auto =
m.eth1Chain.db
template preset(m: Eth1Monitor): auto =
m.eth1Chain.preset

View File

@ -156,21 +156,21 @@ proc blockValidator*(
ValidationResult.Accept
proc checkForPotentialDoppelganger(
self: var Eth2Processor, attestationData: AttestationData,
self: var Eth2Processor, attestation: Attestation,
attesterIndices: openArray[ValidatorIndex], wallSlot: Slot) =
let epoch = wallSlot.epoch
# Only check for current epoch, not potential attestations bouncing around
# from up to several minutes prior.
if attestationData.slot.epoch < epoch:
if attestation.data.slot.epoch < epoch:
return
if epoch < self.doppelgangerDetection.broadcastStartEpoch:
let tgtBlck = self.chainDag.getRef(attestationData.target.root)
let tgtBlck = self.chainDag.getRef(attestation.data.target.root)
doAssert not tgtBlck.isNil # because attestation is valid above
let epochRef = self.chainDag.getEpochRef(
tgtBlck, attestationData.target.epoch)
tgtBlck, attestation.data.target.epoch)
for validatorIndex in attesterIndices:
let validatorPubkey = epochRef.validator_keys[validatorIndex]
if self.doppelgangerDetectionEnabled and
@ -179,7 +179,7 @@ proc checkForPotentialDoppelganger(
warn "We believe you are currently running another instance of the same validator. We've disconnected you from the network as this presents a significant slashing risk. Possible next steps are (a) making sure you've disconnected your validator from your old machine before restarting the client; and (b) running the client again with the gossip-slashing-protection option disabled, only if you are absolutely sure this is the only instance of your validator running, and reporting the issue at https://github.com/status-im/nimbus-eth2/issues.",
validatorIndex,
validatorPubkey,
attestationSlot = attestationData.slot
attestation = shortLog(attestation)
quit QuitFailure
{.pop.} # async can raise anything
@ -220,7 +220,7 @@ proc attestationValidator*(
let (attestation_index, sig) = v.get()
self[].checkForPotentialDoppelganger(
attestation.data, [attestation_index], wallSlot)
attestation, [attestation_index], wallSlot)
trace "Attestation validated"
self.attestationPool[].addAttestation(
@ -267,7 +267,7 @@ proc aggregateValidator*(
let (attesting_indices, sig) = v.get()
self[].checkForPotentialDoppelganger(
signedAggregateAndProof.message.aggregate.data, attesting_indices,
signedAggregateAndProof.message.aggregate, attesting_indices,
wallSlot)
trace "Aggregate validated",

View File

@ -31,13 +31,6 @@ type
# Exported for "test_sync_manager"
v*: SyncBlock
AttestationEntry = object
v: Attestation
attesting_indices: seq[ValidatorIndex]
sig: CookedSig
AggregateEntry = AttestationEntry
VerifQueueManager* = object
## This manages the queues of blocks and attestations.
## Blocks and attestations are enqueued in a gossip-validated state

View File

@ -18,7 +18,6 @@ export protocol, keys
type
Eth2DiscoveryProtocol* = protocol.Protocol
Eth2DiscoveryId* = NodeId
PublicKey = keys.PublicKey
export
Eth2DiscoveryProtocol, open, start, close, closeWait, queryRandom,

View File

@ -74,7 +74,7 @@ proc setupLogging*(logLevel: string, logFile: Option[OutFile]) =
except ValueError as err:
try:
stderr.write "Invalid value for --log-level. " & err.msg
except IOError as exc:
except IOError:
echo "Invalid value for --log-level. " & err.msg
quit 1

View File

@ -190,7 +190,7 @@ proc installBeaconApiHandlers*(rpcServer: RpcServer, node: BeaconNode) {.
rpcServer.rpc("get_v1_beacon_states_root") do (stateId: string) -> Eth2Digest:
withStateForStateId(stateId):
return hashedState.root
return stateRoot
rpcServer.rpc("get_v1_beacon_states_fork") do (stateId: string) -> Fork:
withStateForStateId(stateId):

View File

@ -148,7 +148,7 @@ proc installBeaconApiHandlers*(router: var RestRouter, node: BeaconNode) =
$bres.error())
bres.get()
node.withStateForBlockSlot(bslot):
return RestApiResponse.jsonResponse((root: hashedState().root))
return RestApiResponse.jsonResponse((root: stateRoot))
return RestApiResponse.jsonError(Http500, InternalServerError)
# https://ethereum.github.io/eth2.0-APIs/#/Beacon/getStateFork

View File

@ -226,7 +226,6 @@ proc createAndSendAttestation(node: BeaconNode,
if not ok: # Logged in sendAttestation
return
let sent = node.beaconClock.now()
if node.config.dumpEnabled:
dump(node.config.dumpDirOutgoing, attestation.data, validator.pubKey)

View File

@ -1,5 +1,5 @@
# beacon_chain
# Copyright (c) 2018 Status Research & Development GmbH
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -29,7 +29,6 @@ import # Unit test
./test_state_transition,
./test_statediff,
./test_sync_manager,
./test_sync_protocol,
./test_zero_signature,
./fork_choice/tests_fork_choice,
./slashing_protection/test_slashing_interchange,

View File

@ -1,18 +0,0 @@
# 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 https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
{.used.}
import unittest2
import ../beacon_chain/sync/sync_protocol
suite "Sync protocol":
# Compile test
test "Compile":
discard