diff --git a/AllTests-mainnet.md b/AllTests-mainnet.md index 5554fd1d6c..df83afd038 100644 --- a/AllTests-mainnet.md +++ b/AllTests-mainnet.md @@ -898,6 +898,12 @@ OK: 6/6 Fail: 0/6 Skip: 0/6 + Dynamic validator set: updateDynamicValidators() test OK ``` OK: 4/4 Fail: 0/4 Skip: 0/4 +## ValidatorPubKey Bloom filter +```diff ++ incremental construction with no false positives/negatives OK ++ one-shot construction with no false positives/negatives OK +``` +OK: 2/2 Fail: 0/2 Skip: 0/2 ## Zero signature sanity checks ```diff + SSZ serialization roundtrip of SignedBeaconBlockHeader OK @@ -993,4 +999,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2 OK: 9/9 Fail: 0/9 Skip: 0/9 ---TOTAL--- -OK: 670/675 Fail: 0/675 Skip: 5/675 +OK: 672/677 Fail: 0/677 Skip: 5/677 diff --git a/beacon_chain/bloomfilter.nim b/beacon_chain/bloomfilter.nim index ba37bba029..3faf80e34d 100644 --- a/beacon_chain/bloomfilter.nim +++ b/beacon_chain/bloomfilter.nim @@ -9,6 +9,7 @@ import "."/spec/crypto +from stew/bitops2 import getBit, setBit from "."/spec/datatypes/base import Validator, pubkey from "."/spec/helpers import bytes_to_uint32 @@ -20,8 +21,6 @@ type PubkeyBloomFilter* = object bloomFilter: array[1 shl pubkeyBloomFilterScale, byte] -from stew/bitops2 import getBit, setBit - iterator bloomFilterHashes(pubkey: ValidatorPubKey): auto = const pubkeyBloomFilterMask = (1 shl pubkeyBloomFilterScale) - 1 for r in countup(0'u32, 20'u32, 4'u32): @@ -30,17 +29,21 @@ iterator bloomFilterHashes(pubkey: ValidatorPubKey): auto = yield pubkey.blob.toOpenArray(r, r+3).bytes_to_uint32 and pubkeyBloomFilterMask +func incl*(bloomFilter: var PubkeyBloomFilter, pubkey: ValidatorPubKey) = + for bloomFilterHash in bloomFilterHashes(pubkey): + setBit(bloomFilter.bloomFilter, bloomFilterHash) + func constructBloomFilter*(x: openArray[Validator]): auto = let res = new PubkeyBloomFilter for m in x: - for bloomFilterHash in bloomFilterHashes(m.pubkey): - setBit(res[].bloomFilter, bloomFilterHash) + incl(res[], m.pubkey) res -func mightContain*(bf: PubkeyBloomFilter, pubkey: ValidatorPubKey): bool = +func mightContain*( + bloomFilter: PubkeyBloomFilter, pubkey: ValidatorPubKey): bool = # Might return false positive, but never false negative for bloomFilterHash in bloomFilterHashes(pubkey): - if not getBit(bf.bloomFilter, bloomFilterHash): + if not getBit(bloomFilter.bloomFilter, bloomFilterHash): return false true diff --git a/beacon_chain/spec/state_transition_block.nim b/beacon_chain/spec/state_transition_block.nim index 00800e3fcb..257d58c11c 100644 --- a/beacon_chain/spec/state_transition_block.nim +++ b/beacon_chain/spec/state_transition_block.nim @@ -288,7 +288,7 @@ func findValidatorIndex*(state: ForkyBeaconState, pubkey: ValidatorPubKey): return Opt[ValidatorIndex].ok((vidx - 1).ValidatorIndex) from ".."/bloomfilter import - PubkeyBloomFilter, constructBloomFilter, mightContain + PubkeyBloomFilter, constructBloomFilter, incl, mightContain proc process_deposit*( cfg: RuntimeConfig, state: var ForkyBeaconState, @@ -342,6 +342,7 @@ proc process_deposit*( return err("process_deposit: too many validators (inactivity_scores)") doAssert state.validators.len == state.balances.len + bloom_filter.incl pubkey else: # Deposits may come with invalid signatures - in that case, they are not # turned into a validator but still get processed to keep the deposit diff --git a/tests/all_tests.nim b/tests/all_tests.nim index 99e068ac6d..e75ed65876 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -7,6 +7,8 @@ # All tests except scenarios, which as compiled separately for mainnet and minimal +{.push raises: [].} + import ./testutil @@ -15,9 +17,11 @@ import # Unit test ./test_attestation_pool, ./test_beacon_chain_db, ./test_beacon_time, + ./test_blockchain_dag, ./test_block_dag, ./test_block_processor, ./test_block_quarantine, + ./test_bloom_filter, ./test_conf, ./test_datatypes, ./test_deposit_snapshots, @@ -31,6 +35,8 @@ import # Unit test ./test_gossip_validation, ./test_helpers, ./test_honest_validator, + ./test_keystore, + ./test_keystore_management, ./test_key_splitting, ./test_light_client_processor, ./test_light_client, @@ -54,14 +60,7 @@ import # Unit test ./slashing_protection/test_slashing_protection_db, ./test_validator_client -when not defined(i386): - # Avoids "Out of memory" CI failures - import - ./test_blockchain_dag, - ./test_keystore, - ./test_keystore_management - - when not defined(windows): - import ./test_keymanager_api +when not defined(windows): + import ./test_keymanager_api summarizeLongTests("AllTests")