Update header accumulator test to start from Mainnet genesis (#1111)
This commit is contained in:
parent
7216160ad0
commit
6d8b25a5f5
|
@ -19,7 +19,7 @@ export merkleization
|
||||||
|
|
||||||
const
|
const
|
||||||
epochSize = 8192 # blocks
|
epochSize = 8192 # blocks
|
||||||
maxHistoricalEpochs = 100_000 # Doesn't really need a limit, does it?
|
maxHistoricalEpochs = 131072 # 2^17
|
||||||
|
|
||||||
type
|
type
|
||||||
# Header Gossip Content Keys
|
# Header Gossip Content Keys
|
||||||
|
|
|
@ -11,6 +11,9 @@ import
|
||||||
json_serialization, json_serialization/std/tables,
|
json_serialization, json_serialization/std/tables,
|
||||||
stew/[byteutils, io2, results], nimcrypto/keccak, chronos, chronicles,
|
stew/[byteutils, io2, results], nimcrypto/keccak, chronos, chronicles,
|
||||||
eth/[rlp, common/eth_types],
|
eth/[rlp, common/eth_types],
|
||||||
|
# TODO: `NetworkId` should not be in these private types
|
||||||
|
eth/p2p/private/p2p_types,
|
||||||
|
../nimbus/[chain_config, genesis],
|
||||||
./content_db,
|
./content_db,
|
||||||
./network/wire/portal_protocol,
|
./network/wire/portal_protocol,
|
||||||
./network/history/history_content
|
./network/history/history_content
|
||||||
|
@ -155,6 +158,18 @@ func readBlockHeader*(blockData: BlockData): Result[BlockHeader, string] =
|
||||||
else:
|
else:
|
||||||
return err("Item is not a valid rlp list, number " & $blockData.number)
|
return err("Item is not a valid rlp list, number " & $blockData.number)
|
||||||
|
|
||||||
|
proc getGenesisHeader*(id: NetworkId = MainNet): BlockHeader =
|
||||||
|
let params =
|
||||||
|
try:
|
||||||
|
networkParams(id)
|
||||||
|
except ValueError, RlpError:
|
||||||
|
raise (ref Defect)(msg: "Network parameters should be valid")
|
||||||
|
|
||||||
|
try:
|
||||||
|
toGenesisHeader(params)
|
||||||
|
except RlpError:
|
||||||
|
raise (ref Defect)(msg: "Genesis should be valid")
|
||||||
|
|
||||||
proc historyStore*(
|
proc historyStore*(
|
||||||
p: PortalProtocol, dataFile: string, verify = false):
|
p: PortalProtocol, dataFile: string, verify = false):
|
||||||
Result[void, string] =
|
Result[void, string] =
|
||||||
|
|
|
@ -18,29 +18,34 @@ import
|
||||||
|
|
||||||
suite "Header Gossip Content":
|
suite "Header Gossip Content":
|
||||||
test "Header Accumulator Update":
|
test "Header Accumulator Update":
|
||||||
const dataFile = "./fluffy/tests/blocks/mainnet_blocks_1-2.json"
|
const
|
||||||
|
hashTreeRoots = [
|
||||||
|
"b629833240bb2f5eabfb5245be63d730ca4ed30d6a418340ca476e7c1f1d98c0",
|
||||||
|
"00cbebed829e1babb93f2300bebe7905a98cb86993c7fc09bb5b04626fd91ae5",
|
||||||
|
"88cce8439ebc0c1d007177ffb6831c15c07b4361984cc52235b6fd728434f0c7"]
|
||||||
|
|
||||||
|
dataFile = "./fluffy/tests/blocks/mainnet_blocks_1-2.json"
|
||||||
|
|
||||||
let blockDataRes = readBlockDataTable(dataFile)
|
let blockDataRes = readBlockDataTable(dataFile)
|
||||||
|
|
||||||
check blockDataRes.isOk()
|
check blockDataRes.isOk()
|
||||||
let blockData = blockDataRes.get()
|
let blockData = blockDataRes.get()
|
||||||
|
|
||||||
var headers: seq[BlockHeader]
|
var headers: seq[BlockHeader]
|
||||||
headers.setLen(blockData.len())
|
# Len of headers from blockdata + genesis header
|
||||||
|
headers.setLen(blockData.len() + 1)
|
||||||
|
|
||||||
|
headers[0] = getGenesisHeader()
|
||||||
|
|
||||||
for k, v in blockData.pairs:
|
for k, v in blockData.pairs:
|
||||||
let res = v.readBlockHeader()
|
let res = v.readBlockHeader()
|
||||||
check res.isOk()
|
check res.isOk()
|
||||||
let header = res.get()
|
let header = res.get()
|
||||||
headers[header.blockNumber.truncate(int) - 1] = header
|
headers[header.blockNumber.truncate(int)] = header
|
||||||
|
|
||||||
var accumulator: Accumulator
|
var accumulator: Accumulator
|
||||||
|
|
||||||
updateAccumulator(accumulator, headers[0])
|
for i, hash in hashTreeRoots:
|
||||||
|
updateAccumulator(accumulator, headers[i])
|
||||||
|
|
||||||
check accumulator.hash_tree_root().data.toHex() ==
|
check accumulator.hash_tree_root().data.toHex() == hashTreeRoots[i]
|
||||||
"411548579b5f6c651e6e1e56c3dc3fae6f389c663c0c910e462a4b806831fef6"
|
|
||||||
|
|
||||||
updateAccumulator(accumulator, headers[1])
|
|
||||||
|
|
||||||
check accumulator.hash_tree_root().data.toHex() ==
|
|
||||||
"e8dbd17538189d9a5b77001ff80c4ff6d841ceb0a3d374d17ddc4098550f5f93"
|
|
||||||
|
|
|
@ -457,7 +457,7 @@ proc chainConfigForNetwork(id: NetworkId): ChainConfig =
|
||||||
ChainConfig()
|
ChainConfig()
|
||||||
|
|
||||||
proc genesisBlockForNetwork(id: NetworkId): Genesis
|
proc genesisBlockForNetwork(id: NetworkId): Genesis
|
||||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
{.gcsafe, raises: [Defect, ValueError, RlpError].} =
|
||||||
result = case id
|
result = case id
|
||||||
of MainNet:
|
of MainNet:
|
||||||
Genesis(
|
Genesis(
|
||||||
|
@ -497,6 +497,6 @@ proc genesisBlockForNetwork(id: NetworkId): Genesis
|
||||||
Genesis()
|
Genesis()
|
||||||
|
|
||||||
proc networkParams*(id: NetworkId): NetworkParams
|
proc networkParams*(id: NetworkId): NetworkParams
|
||||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
{.gcsafe, raises: [Defect, ValueError, RlpError].} =
|
||||||
result.genesis = genesisBlockForNetwork(id)
|
result.genesis = genesisBlockForNetwork(id)
|
||||||
result.config = chainConfigForNetwork(id)
|
result.config = chainConfigForNetwork(id)
|
||||||
|
|
Loading…
Reference in New Issue