3x blocksim speedup by using EpochRef in attestation pool addResolved(...)
This commit is contained in:
parent
68b5638da4
commit
74dc2fffa6
|
@ -11,7 +11,7 @@ import
|
||||||
deques, sequtils, tables, options,
|
deques, sequtils, tables, options,
|
||||||
chronicles, stew/[byteutils], json_serialization/std/sets,
|
chronicles, stew/[byteutils], json_serialization/std/sets,
|
||||||
./spec/[beaconstate, datatypes, crypto, digest, helpers, validator],
|
./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"
|
logScope: topics = "attpool"
|
||||||
|
|
||||||
|
@ -150,8 +150,8 @@ func updateLatestVotes(
|
||||||
|
|
||||||
func get_attesting_indices_seq(state: BeaconState,
|
func get_attesting_indices_seq(state: BeaconState,
|
||||||
attestation_data: AttestationData,
|
attestation_data: AttestationData,
|
||||||
bits: CommitteeValidatorsBits): seq[ValidatorIndex] =
|
bits: CommitteeValidatorsBits,
|
||||||
var cache = get_empty_per_epoch_cache()
|
cache: var StateCache): seq[ValidatorIndex] =
|
||||||
toSeq(items(get_attesting_indices(
|
toSeq(items(get_attesting_indices(
|
||||||
state, attestation_data, bits, cache)))
|
state, attestation_data, bits, cache)))
|
||||||
|
|
||||||
|
@ -191,6 +191,7 @@ proc addResolved(pool: var AttestationPool, blck: BlockRef, attestation: Attesta
|
||||||
|
|
||||||
# TODO inefficient data structures..
|
# TODO inefficient data structures..
|
||||||
|
|
||||||
|
var cache = getEpochCache(blck, state)
|
||||||
let
|
let
|
||||||
attestationSlot = attestation.data.slot
|
attestationSlot = attestation.data.slot
|
||||||
idx = pool.slotIndex(state, attestationSlot)
|
idx = pool.slotIndex(state, attestationSlot)
|
||||||
|
@ -199,7 +200,7 @@ proc addResolved(pool: var AttestationPool, blck: BlockRef, attestation: Attesta
|
||||||
aggregation_bits: attestation.aggregation_bits,
|
aggregation_bits: attestation.aggregation_bits,
|
||||||
aggregate_signature: attestation.signature)
|
aggregate_signature: attestation.signature)
|
||||||
participants = get_attesting_indices_seq(
|
participants = get_attesting_indices_seq(
|
||||||
state, attestation.data, validation.aggregation_bits)
|
state, attestation.data, validation.aggregation_bits, cache)
|
||||||
|
|
||||||
var found = false
|
var found = false
|
||||||
for a in slotData.attestations.mitems():
|
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?
|
# and therefore being useful after all?
|
||||||
trace "Ignoring subset attestation",
|
trace "Ignoring subset attestation",
|
||||||
existingParticipants = get_attesting_indices_seq(
|
existingParticipants = get_attesting_indices_seq(
|
||||||
state, a.data, v.aggregation_bits),
|
state, a.data, v.aggregation_bits, cache),
|
||||||
newParticipants = participants,
|
newParticipants = participants,
|
||||||
cat = "filtering"
|
cat = "filtering"
|
||||||
found = true
|
found = true
|
||||||
|
@ -228,7 +229,7 @@ proc addResolved(pool: var AttestationPool, blck: BlockRef, attestation: Attesta
|
||||||
existingParticipants = a.validations.filterIt(
|
existingParticipants = a.validations.filterIt(
|
||||||
it.aggregation_bits.isSubsetOf(validation.aggregation_bits)
|
it.aggregation_bits.isSubsetOf(validation.aggregation_bits)
|
||||||
).mapIt(get_attesting_indices_seq(
|
).mapIt(get_attesting_indices_seq(
|
||||||
state, a.data, it.aggregation_bits)),
|
state, a.data, it.aggregation_bits, cache)),
|
||||||
newParticipants = participants,
|
newParticipants = participants,
|
||||||
cat = "pruning"
|
cat = "pruning"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
chronicles, tables,
|
chronicles, sequtils, tables,
|
||||||
metrics, stew/results,
|
metrics, stew/results,
|
||||||
../ssz/merkleization, ../state_transition, ../extras,
|
../ssz/merkleization, ../state_transition, ../extras,
|
||||||
../spec/[crypto, datatypes, digest, helpers],
|
../spec/[crypto, datatypes, digest, helpers],
|
||||||
|
@ -46,8 +46,8 @@ proc addResolvedBlock(
|
||||||
doAssert state.slot == signedBlock.message.slot, "state must match block"
|
doAssert state.slot == signedBlock.message.slot, "state must match block"
|
||||||
|
|
||||||
let blockRef = BlockRef.init(blockRoot, signedBlock.message)
|
let blockRef = BlockRef.init(blockRoot, signedBlock.message)
|
||||||
parent.epochsInfo =
|
blockRef.epochsInfo = filterIt(parent.epochsInfo,
|
||||||
@[populateEpochCache(state, state.slot.compute_epoch_at_slot)]
|
it.epoch + 1 >= state.slot.compute_epoch_at_slot)
|
||||||
link(parent, blockRef)
|
link(parent, blockRef)
|
||||||
|
|
||||||
dag.blocks[blockRoot] = blockRef
|
dag.blocks[blockRoot] = blockRef
|
||||||
|
|
|
@ -39,7 +39,7 @@ type Timers = enum
|
||||||
|
|
||||||
# TODO confutils is an impenetrable black box. how can a help text be added here?
|
# TODO confutils is an impenetrable black box. how can a help text be added here?
|
||||||
cli do(slots = SLOTS_PER_EPOCH * 6,
|
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,
|
attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.73,
|
||||||
blockRatio {.desc: "ratio of slots with blocks"} = 1.0,
|
blockRatio {.desc: "ratio of slots with blocks"} = 1.0,
|
||||||
replay = true):
|
replay = true):
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
import
|
import
|
||||||
options, sequtils, unittest,
|
options, sequtils, unittest,
|
||||||
./testutil, ./testblockutil,
|
./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]
|
../beacon_chain/[beacon_node_types, block_pool, state_transition, ssz]
|
||||||
|
|
||||||
suiteReport "BlockRef and helpers" & preset():
|
suiteReport "BlockRef and helpers" & preset():
|
||||||
|
@ -278,7 +278,7 @@ suiteReport "Block pool processing" & preset():
|
||||||
tmpState.data.data.slot == bs1.parent.slot
|
tmpState.data.data.slot == bs1.parent.slot
|
||||||
|
|
||||||
when const_preset == "minimal": # These require some minutes in mainnet
|
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():
|
suiteReport "BlockPool finalization tests" & preset():
|
||||||
setup:
|
setup:
|
||||||
|
|
Loading…
Reference in New Issue