Skip to content

Commit 8528926

Browse files
terseczah
authored andcommitted
increase block proposal speed with many validators (#2423)
* increase block proposal speed with many validators * document CookedSig rationale
1 parent af0d302 commit 8528926

File tree

6 files changed

+30
-13
lines changed

6 files changed

+30
-13
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ ifeq ($(DISABLE_TEST_FIXTURES_SCRIPT), 0)
269269
endif
270270
for TEST_BINARY in $(TEST_BINARIES); do \
271271
PARAMS=""; \
272-
if [[ "$${TEST_BINARY}" == "state_sim" ]]; then PARAMS="--validators=3000 --slots=128"; \
273-
elif [[ "$${TEST_BINARY}" == "block_sim" ]]; then PARAMS="--validators=3000 --slots=128"; \
272+
if [[ "$${TEST_BINARY}" == "state_sim" ]]; then PARAMS="--validators=6000 --slots=128"; \
273+
elif [[ "$${TEST_BINARY}" == "block_sim" ]]; then PARAMS="--validators=6000 --slots=128"; \
274274
fi; \
275275
echo -e "\nRunning $${TEST_BINARY} $${PARAMS}\n"; \
276276
build/$${TEST_BINARY} $${PARAMS} || { echo -e "\n$${TEST_BINARY} $${PARAMS} failed; Aborting."; exit 1; }; \

beacon_chain/beacon_node_types.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type
3030
## added to the aggregate meaning that only non-overlapping aggregates may
3131
## be further combined.
3232
aggregation_bits*: CommitteeValidatorsBits
33-
aggregate_signature*: ValidatorSig
33+
aggregate_signature*: CookedSig
3434

3535
AttestationEntry* = object
3636
## Each entry holds the known signatures for a particular, distinct vote

beacon_chain/consensus_object_pools/attestation_pool.nim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import
1111
# Standard libraries
1212
std/[options, tables, sequtils],
1313
# Status libraries
14-
chronicles, stew/[byteutils], json_serialization/std/sets as jsonSets,
14+
chronicles, stew/byteutils, json_serialization/std/sets as jsonSets,
1515
# Internal
1616
../spec/[beaconstate, datatypes, crypto, digest],
1717
../ssz/merkleization,
@@ -176,9 +176,10 @@ proc addAttestation*(pool: var AttestationPool,
176176

177177
let
178178
attestationsSeen = addr pool.candidates[candidateIdx.get]
179+
# Only attestestions with valid signatures get here
179180
validation = Validation(
180181
aggregation_bits: attestation.aggregation_bits,
181-
aggregate_signature: attestation.signature)
182+
aggregate_signature: load(attestation.signature).get.CookedSig)
182183

183184
var found = false
184185
for a in attestationsSeen.attestations.mitems():
@@ -281,7 +282,7 @@ iterator attestations*(pool: AttestationPool, slot: Option[Slot],
281282
yield Attestation(
282283
aggregation_bits: validation.aggregation_bits,
283284
data: entry.data,
284-
signature: validation.aggregate_signature
285+
signature: validation.aggregate_signature.exportRaw
285286
)
286287

287288
func getAttestationDataKey(ad: AttestationData): AttestationDataKey =
@@ -377,7 +378,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool,
377378
attestation = Attestation(
378379
aggregation_bits: a.validations[0].aggregation_bits,
379380
data: a.data,
380-
signature: a.validations[0].aggregate_signature
381+
signature: a.validations[0].aggregate_signature.exportRaw
381382
)
382383

383384
agg {.noInit.}: AggregateSignature
@@ -448,7 +449,7 @@ proc getAggregatedAttestation*(pool: AttestationPool,
448449
attestation = Attestation(
449450
aggregation_bits: a.validations[0].aggregation_bits,
450451
data: a.data,
451-
signature: a.validations[0].aggregate_signature
452+
signature: a.validations[0].aggregate_signature.exportRaw
452453
)
453454

454455
agg {.noInit.}: AggregateSignature

beacon_chain/spec/crypto.nim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ type
6868

6969
SomeSig* = TrustedSig | ValidatorSig
7070

71+
CookedSig* = distinct blscurve.Signature ## \
72+
## Allows loading in an atttestation or other message's signature once across
73+
## all its computations, rather than repeatedly re-loading it each time it is
74+
## referenced. This primarily currently serves the attestation pool.
75+
7176
export AggregateSignature
7277

7378
# API
@@ -116,11 +121,19 @@ func init*(agg: var AggregateSignature, sig: ValidatorSig) {.inline.}=
116121
## This assumes that the signature is valid
117122
agg.init(sig.load().get())
118123

119-
func aggregate*(agg: var AggregateSignature, sig: ValidatorSig) {.inline.}=
124+
func init*(agg: var AggregateSignature, sig: CookedSig) {.inline.}=
125+
## Initializes an aggregate signature context
126+
agg.init(blscurve.Signature(sig))
127+
128+
proc aggregate*(agg: var AggregateSignature, sig: ValidatorSig) {.inline.}=
120129
## Aggregate two Validator Signatures
121130
## Both signatures must be valid
122131
agg.aggregate(sig.load.get())
123132

133+
proc aggregate*(agg: var AggregateSignature, sig: CookedSig) {.inline.}=
134+
## Aggregate two Validator Signatures
135+
agg.aggregate(blscurve.Signature(sig))
136+
124137
func finish*(agg: AggregateSignature): ValidatorSig {.inline.}=
125138
## Canonicalize an AggregateSignature into a signature
126139
var sig: blscurve.Signature
@@ -226,6 +239,9 @@ template toRaw*(x: TrustedSig): auto =
226239
func toHex*(x: BlsCurveType): string =
227240
toHex(toRaw(x))
228241

242+
func exportRaw*(x: CookedSig): ValidatorSig =
243+
ValidatorSig(blob: blscurve.Signature(x).exportRaw())
244+
229245
func fromRaw*(T: type ValidatorPrivKey, bytes: openArray[byte]): BlsResult[T] =
230246
var val: SecretKey
231247
if val.fromBytes(bytes):

research/block_sim.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ proc gauss(r: var Rand; mu = 0.0; sigma = 1.0): float =
5050
result = mu + sigma * (b / a)
5151

5252
# TODO confutils is an impenetrable black box. how can a help text be added here?
53-
cli do(slots = SLOTS_PER_EPOCH * 6,
54-
validators = SLOTS_PER_EPOCH * 200, # One per shard is minimum
53+
cli do(slots = SLOTS_PER_EPOCH * 5,
54+
validators = SLOTS_PER_EPOCH * 400, # One per shard is minimum
5555
attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.82,
5656
blockRatio {.desc: "ratio of slots with blocks"} = 1.0,
5757
replay = true):

research/state_sim.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ proc writeJson*(fn, v: auto) =
3333
defer: close(f)
3434
Json.saveFile(fn, v, pretty = true)
3535

36-
cli do(slots = SLOTS_PER_EPOCH * 6,
37-
validators = SLOTS_PER_EPOCH * 200, # One per shard is minimum
36+
cli do(slots = SLOTS_PER_EPOCH * 5,
37+
validators = SLOTS_PER_EPOCH * 400, # One per shard is minimum
3838
json_interval = SLOTS_PER_EPOCH,
3939
write_last_json = false,
4040
prefix: int = 0,

0 commit comments

Comments
 (0)