diff --git a/Makefile b/Makefile index aad09665a..c3993a6b3 100644 --- a/Makefile +++ b/Makefile @@ -269,8 +269,8 @@ ifeq ($(DISABLE_TEST_FIXTURES_SCRIPT), 0) endif for TEST_BINARY in $(TEST_BINARIES); do \ PARAMS=""; \ - if [[ "$${TEST_BINARY}" == "state_sim" ]]; then PARAMS="--validators=3000 --slots=128"; \ - elif [[ "$${TEST_BINARY}" == "block_sim" ]]; then PARAMS="--validators=3000 --slots=128"; \ + if [[ "$${TEST_BINARY}" == "state_sim" ]]; then PARAMS="--validators=6000 --slots=128"; \ + elif [[ "$${TEST_BINARY}" == "block_sim" ]]; then PARAMS="--validators=6000 --slots=128"; \ fi; \ echo -e "\nRunning $${TEST_BINARY} $${PARAMS}\n"; \ build/$${TEST_BINARY} $${PARAMS} || { echo -e "\n$${TEST_BINARY} $${PARAMS} failed; Aborting."; exit 1; }; \ diff --git a/beacon_chain/beacon_node_types.nim b/beacon_chain/beacon_node_types.nim index 2afe7b465..83711e2de 100644 --- a/beacon_chain/beacon_node_types.nim +++ b/beacon_chain/beacon_node_types.nim @@ -30,7 +30,7 @@ type ## added to the aggregate meaning that only non-overlapping aggregates may ## be further combined. aggregation_bits*: CommitteeValidatorsBits - aggregate_signature*: ValidatorSig + aggregate_signature*: CookedSig AttestationEntry* = object ## Each entry holds the known signatures for a particular, distinct vote diff --git a/beacon_chain/consensus_object_pools/attestation_pool.nim b/beacon_chain/consensus_object_pools/attestation_pool.nim index 2f1bcd97a..689c527da 100644 --- a/beacon_chain/consensus_object_pools/attestation_pool.nim +++ b/beacon_chain/consensus_object_pools/attestation_pool.nim @@ -11,7 +11,7 @@ import # Standard libraries std/[options, tables, sequtils], # Status libraries - chronicles, stew/[byteutils], json_serialization/std/sets as jsonSets, + chronicles, stew/byteutils, json_serialization/std/sets as jsonSets, # Internal ../spec/[beaconstate, datatypes, crypto, digest], ../ssz/merkleization, @@ -176,9 +176,10 @@ proc addAttestation*(pool: var AttestationPool, let attestationsSeen = addr pool.candidates[candidateIdx.get] + # Only attestestions with valid signatures get here validation = Validation( aggregation_bits: attestation.aggregation_bits, - aggregate_signature: attestation.signature) + aggregate_signature: load(attestation.signature).get.CookedSig) var found = false for a in attestationsSeen.attestations.mitems(): @@ -281,7 +282,7 @@ iterator attestations*(pool: AttestationPool, slot: Option[Slot], yield Attestation( aggregation_bits: validation.aggregation_bits, data: entry.data, - signature: validation.aggregate_signature + signature: validation.aggregate_signature.exportRaw ) func getAttestationDataKey(ad: AttestationData): AttestationDataKey = @@ -377,7 +378,7 @@ proc getAttestationsForBlock*(pool: var AttestationPool, attestation = Attestation( aggregation_bits: a.validations[0].aggregation_bits, data: a.data, - signature: a.validations[0].aggregate_signature + signature: a.validations[0].aggregate_signature.exportRaw ) agg {.noInit.}: AggregateSignature @@ -448,7 +449,7 @@ proc getAggregatedAttestation*(pool: AttestationPool, attestation = Attestation( aggregation_bits: a.validations[0].aggregation_bits, data: a.data, - signature: a.validations[0].aggregate_signature + signature: a.validations[0].aggregate_signature.exportRaw ) agg {.noInit.}: AggregateSignature diff --git a/beacon_chain/spec/crypto.nim b/beacon_chain/spec/crypto.nim index 9761122c9..f2cee59cc 100644 --- a/beacon_chain/spec/crypto.nim +++ b/beacon_chain/spec/crypto.nim @@ -68,6 +68,11 @@ type SomeSig* = TrustedSig | ValidatorSig + CookedSig* = distinct blscurve.Signature ## \ + ## Allows loading in an atttestation or other message's signature once across + ## all its computations, rather than repeatedly re-loading it each time it is + ## referenced. This primarily currently serves the attestation pool. + export AggregateSignature # API @@ -116,11 +121,19 @@ func init*(agg: var AggregateSignature, sig: ValidatorSig) {.inline.}= ## This assumes that the signature is valid agg.init(sig.load().get()) -func aggregate*(agg: var AggregateSignature, sig: ValidatorSig) {.inline.}= +func init*(agg: var AggregateSignature, sig: CookedSig) {.inline.}= + ## Initializes an aggregate signature context + agg.init(blscurve.Signature(sig)) + +proc aggregate*(agg: var AggregateSignature, sig: ValidatorSig) {.inline.}= ## Aggregate two Validator Signatures ## Both signatures must be valid agg.aggregate(sig.load.get()) +proc aggregate*(agg: var AggregateSignature, sig: CookedSig) {.inline.}= + ## Aggregate two Validator Signatures + agg.aggregate(blscurve.Signature(sig)) + func finish*(agg: AggregateSignature): ValidatorSig {.inline.}= ## Canonicalize an AggregateSignature into a signature var sig: blscurve.Signature @@ -226,6 +239,9 @@ template toRaw*(x: TrustedSig): auto = func toHex*(x: BlsCurveType): string = toHex(toRaw(x)) +func exportRaw*(x: CookedSig): ValidatorSig = + ValidatorSig(blob: blscurve.Signature(x).exportRaw()) + func fromRaw*(T: type ValidatorPrivKey, bytes: openArray[byte]): BlsResult[T] = var val: SecretKey if val.fromBytes(bytes): diff --git a/research/block_sim.nim b/research/block_sim.nim index 54bed8176..4af95c68f 100644 --- a/research/block_sim.nim +++ b/research/block_sim.nim @@ -50,8 +50,8 @@ proc gauss(r: var Rand; mu = 0.0; sigma = 1.0): float = result = mu + sigma * (b / a) # 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 * 200, # One per shard is minimum +cli do(slots = SLOTS_PER_EPOCH * 5, + validators = SLOTS_PER_EPOCH * 400, # One per shard is minimum attesterRatio {.desc: "ratio of validators that attest in each round"} = 0.82, blockRatio {.desc: "ratio of slots with blocks"} = 1.0, replay = true): diff --git a/research/state_sim.nim b/research/state_sim.nim index cbe6a3d92..92a731ae9 100644 --- a/research/state_sim.nim +++ b/research/state_sim.nim @@ -33,8 +33,8 @@ proc writeJson*(fn, v: auto) = defer: close(f) Json.saveFile(fn, v, pretty = true) -cli do(slots = SLOTS_PER_EPOCH * 6, - validators = SLOTS_PER_EPOCH * 200, # One per shard is minimum +cli do(slots = SLOTS_PER_EPOCH * 5, + validators = SLOTS_PER_EPOCH * 400, # One per shard is minimum json_interval = SLOTS_PER_EPOCH, write_last_json = false, prefix: int = 0,