add: `get_extended_sample_count` with test (#6544)
* add: get_extended_sample_count with test * drop return * reviews * review fix * fixed * fix doc * hooked to all_tests * rm bin * add updated test file * early return, maybe need results? * refactor function intricacies * drop columnsCount
This commit is contained in:
parent
16c21e1c1e
commit
f53b621818
|
@ -531,6 +531,11 @@ OK: 10/12 Fail: 0/12 Skip: 2/12
|
|||
+ snapshot_cases OK
|
||||
```
|
||||
OK: 5/5 Fail: 0/5 Skip: 0/5
|
||||
## EIP-7594 Sampling Tests
|
||||
```diff
|
||||
+ EIP7594: Extended Sample Count OK
|
||||
```
|
||||
OK: 1/1 Fail: 0/1 Skip: 0/1
|
||||
## EL Configuration
|
||||
```diff
|
||||
+ Empty config file OK
|
||||
|
@ -1114,4 +1119,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
|
|||
OK: 9/9 Fail: 0/9 Skip: 0/9
|
||||
|
||||
---TOTAL---
|
||||
OK: 759/764 Fail: 0/764 Skip: 5/764
|
||||
OK: 760/765 Fail: 0/765 Skip: 5/765
|
||||
|
|
|
@ -98,3 +98,29 @@ func get_custody_column_list*(node_id: NodeId,
|
|||
NUMBER_OF_COLUMNS div DATA_COLUMN_SIDECAR_SUBNET_COUNT
|
||||
|
||||
sortedColumnIndexList(ColumnIndex(columns_per_subnet), subnet_ids)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.5/specs/_features/eip7594/peer-sampling.md#get_extended_sample_count
|
||||
func get_extended_sample_count*(samples_per_slot: int,
|
||||
allowed_failures: int):
|
||||
int =
|
||||
## `get_extended_sample_count` computes the number of samples we
|
||||
## should query from peers, given the SAMPLES_PER_SLOT and
|
||||
## the number of allowed failures
|
||||
|
||||
# If 50% of the columns are missing, we are able to reconstruct the data
|
||||
# If 50% + 1 columns are missing, we cannot reconstruct the data
|
||||
const worstCaseConditionCount = (NUMBER_OF_COLUMNS div 2) + 1
|
||||
|
||||
# Compute the false positive threshold
|
||||
let falsePositiveThreshold =
|
||||
hypergeom_cdf(0, NUMBER_OF_COLUMNS, worstCaseConditionCount, samples_per_slot)
|
||||
|
||||
# Finally, compute the extended sample count
|
||||
for i in samples_per_slot .. NUMBER_OF_COLUMNS:
|
||||
if hypergeom_cdf(
|
||||
allowed_failures,
|
||||
NUMBER_OF_COLUMNS,
|
||||
worstCaseConditionCount, i) <= falsePositiveThreshold:
|
||||
return i
|
||||
|
||||
NUMBER_OF_COLUMNS
|
|
@ -27,6 +27,7 @@ import # Unit test
|
|||
./test_discovery,
|
||||
./test_engine_api_conversions,
|
||||
./test_engine_authentication,
|
||||
./test_eip7594_helpers,
|
||||
./test_el_manager,
|
||||
./test_el_conf,
|
||||
./test_eth2_ssz_serialization,
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
# beacon_chain
|
||||
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
||||
# Licensed and distributed under either of
|
||||
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
{.push raises: [].}
|
||||
{.used.}
|
||||
|
||||
import
|
||||
unittest2,
|
||||
../beacon_chain/spec/[helpers, eip7594_helpers]
|
||||
|
||||
suite "EIP-7594 Sampling Tests":
|
||||
test "EIP7594: Extended Sample Count":
|
||||
proc testExtendedSampleCount() =
|
||||
let samplesPerSlot = 16
|
||||
const tests = [
|
||||
(0, 16),
|
||||
(1, 20),
|
||||
(2, 24),
|
||||
(3, 27),
|
||||
(4, 29),
|
||||
(5, 32),
|
||||
(6, 35),
|
||||
(7, 37),
|
||||
(8, 40),
|
||||
(9, 42),
|
||||
(10, 44),
|
||||
(11, 47),
|
||||
(12, 49),
|
||||
(13, 51),
|
||||
(14, 53),
|
||||
(15, 55),
|
||||
(16, 57),
|
||||
(17, 59),
|
||||
(18, 61),
|
||||
(19, 63),
|
||||
(20, 65)
|
||||
]
|
||||
|
||||
for (allowed_failures, extendedSampleCount) in tests:
|
||||
check: get_extended_sample_count(
|
||||
samplesPerSlot, allowed_failures) == extendedSampleCount
|
||||
testExtendedSampleCount()
|
Loading…
Reference in New Issue