3x blocksim speedup by using EpochRef in attestation pool addResolved(...)

This commit is contained in:
Dustin Brody 2020-06-05 13:28:52 +02:00 committed by tersec
parent 68b5638da4
commit 74dc2fffa6
4 changed files with 14 additions and 13 deletions

View File

@ -11,7 +11,7 @@ import
deques, sequtils, tables, options,
chronicles, stew/[byteutils], json_serialization/std/sets,
./spec/[beaconstate, datatypes, crypto, digest, helpers, validator],
./extras, ./block_pool, ./beacon_node_types
./extras, ./block_pool, ./block_pools/candidate_chains, ./beacon_node_types
logScope: topics = "attpool"
@ -150,8 +150,8 @@ func updateLatestVotes(
func get_attesting_indices_seq(state: BeaconState,
attestation_data: AttestationData,
bits: CommitteeValidatorsBits): seq[ValidatorIndex] =
var cache = get_empty_per_epoch_cache()
bits: CommitteeValidatorsBits,
cache: var StateCache): seq[ValidatorIndex] =
toSeq(items(get_attesting_indices(
state, attestation_data, bits, cache)))
@ -191,6 +191,7 @@ proc addResolved(pool: var AttestationPool, blck: BlockRef, attestation: Attesta
# TODO inefficient data structures..
var cache = getEpochCache(blck, state)
let
attestationSlot = attestation.data.slot
idx = pool.slotIndex(state, attestationSlot)
@ -199,7 +200,7 @@ proc addResolved(pool: var AttestationPool, blck: BlockRef, attestation: Attesta
aggregation_bits: attestation.aggregation_bits,
aggregate_signature: attestation.signature)
participants = get_attesting_indices_seq(
state, attestation.data, validation.aggregation_bits)
state, attestation.data, validation.aggregation_bits, cache)
var found = false
for a in slotData.attestations.mitems():
@ -214,7 +215,7 @@ proc addResolved(pool: var AttestationPool, blck: BlockRef, attestation: Attesta
# and therefore being useful after all?
trace "Ignoring subset attestation",
existingParticipants = get_attesting_indices_seq(
state, a.data, v.aggregation_bits),
state, a.data, v.aggregation_bits, cache),
newParticipants = participants,
cat = "filtering"
found = true
@ -228,7 +229,7 @@ proc addResolved(pool: var AttestationPool, blck: BlockRef, attestation: Attesta
existingParticipants = a.validations.filterIt(
it.aggregation_bits.isSubsetOf(validation.aggregation_bits)
).mapIt(get_attesting_indices_seq(
state, a.data, it.aggregation_bits)),
state, a.data, it.aggregation_bits, cache)),
newParticipants = participants,
cat = "pruning"

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
chronicles, tables,
chronicles, sequtils, tables,
metrics, stew/results,
../ssz/merkleization, ../state_transition, ../extras,
../spec/[crypto, datatypes, digest, helpers],
@ -46,8 +46,8 @@ proc addResolvedBlock(
doAssert state.slot == signedBlock.message.slot, "state must match block"
let blockRef = BlockRef.init(blockRoot, signedBlock.message)
parent.epochsInfo =
@[populateEpochCache(state, state.slot.compute_epoch_at_slot)]
blockRef.epochsInfo = filterIt(parent.epochsInfo,
it.epoch + 1 >= state.slot.compute_epoch_at_slot)
link(parent, blockRef)
dag.blocks[blockRoot] = blockRef

View File

@ -39,7 +39,7 @@ type Timers = enum
# TODO confutils is an impenetrable black box. how can a help text be added here?
cli do(slots = SLOTS_PER_EPOCH * 6,
validators = SLOTS_PER_EPOCH * 100, # One per shard is minimum
validators = SLOTS_PER_EPOCH * 130, # One per shard is minimum
attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.73,
blockRatio {.desc: "ratio of slots with blocks"} = 1.0,
replay = true):

View File

@ -10,7 +10,7 @@
import
options, sequtils, unittest,
./testutil, ./testblockutil,
../beacon_chain/spec/[datatypes, digest, helpers, validator],
../beacon_chain/spec/[datatypes, digest, validator],
../beacon_chain/[beacon_node_types, block_pool, state_transition, ssz]
suiteReport "BlockRef and helpers" & preset():
@ -278,7 +278,7 @@ suiteReport "Block pool processing" & preset():
tmpState.data.data.slot == bs1.parent.slot
when const_preset == "minimal": # These require some minutes in mainnet
import ../beacon_chain/spec/validator
import ../beacon_chain/spec/helpers
suiteReport "BlockPool finalization tests" & preset():
setup: