Add fixes to map generation and add test helpers.
This commit is contained in:
parent
02b9f89b8f
commit
f8a476f31b
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
{.push raises: [].}
|
{.push raises: [].}
|
||||||
|
|
||||||
import std/[deques, heapqueue, tables, strutils, sequtils, math]
|
import std/[deques, heapqueue, tables, strutils, sequtils, math, typetraits]
|
||||||
import stew/base10, chronos, chronicles, results
|
import stew/base10, chronos, chronicles, results
|
||||||
import
|
import
|
||||||
../spec/datatypes/[base, phase0, altair],
|
../spec/datatypes/[base, phase0, altair],
|
||||||
|
@ -183,21 +183,30 @@ proc getShortMap*[T](
|
||||||
var
|
var
|
||||||
res = newStringOfCap(req.data.count)
|
res = newStringOfCap(req.data.count)
|
||||||
slider = req.data.slot
|
slider = req.data.slot
|
||||||
last = 0
|
notFirst = false
|
||||||
|
|
||||||
for i in 0 ..< req.data.count:
|
for i in 0 ..< int(req.data.count):
|
||||||
if last < len(blobs):
|
if i >= len(blobs):
|
||||||
if len(blobs[last]) > 0:
|
res.add('.'.repeat(int(req.data.count) - len(res)))
|
||||||
if blobs[last][0][].signed_block_header.message.slot == slider:
|
return res
|
||||||
res.add(Base10.toString(lenu64(blobs[last])))
|
|
||||||
|
if len(blobs[i]) > 0:
|
||||||
|
let slot = blobs[i][0][].signed_block_header.message.slot
|
||||||
|
if not(notFirst):
|
||||||
|
doAssert(slot >= slider, "Incorrect slot number in blobs list")
|
||||||
|
let firstCount = int(slot - slider)
|
||||||
|
res.add('.'.repeat(firstCount))
|
||||||
|
res.add(Base10.toString(lenu64(blobs[i])))
|
||||||
|
slider = slot
|
||||||
|
notFirst = true
|
||||||
|
else:
|
||||||
|
if slot == slider:
|
||||||
|
res.add(Base10.toString(lenu64(blobs[i])))
|
||||||
else:
|
else:
|
||||||
res.add('.')
|
res.add('.')
|
||||||
else:
|
|
||||||
res.add('.')
|
|
||||||
inc(last)
|
|
||||||
else:
|
else:
|
||||||
res.add('.')
|
if notFirst: res.add('.')
|
||||||
inc(slider)
|
if notFirst: inc(slider)
|
||||||
res
|
res
|
||||||
|
|
||||||
proc getShortMap*[T](
|
proc getShortMap*[T](
|
||||||
|
|
|
@ -89,6 +89,52 @@ func createBlobs(
|
||||||
inc sidecarIdx
|
inc sidecarIdx
|
||||||
res
|
res
|
||||||
|
|
||||||
|
func createBlobSidecars(srange: SyncRange, map: string): seq[BlobSidecars] =
|
||||||
|
var
|
||||||
|
res: seq[BlobSidecars]
|
||||||
|
notFirst = false
|
||||||
|
doAssert(lenu64(map) == srange.count,
|
||||||
|
"Length of map string should be equal to range size")
|
||||||
|
for index in 0 ..< srange.count:
|
||||||
|
let slot = srange.slot + index
|
||||||
|
if map[index] == '.':
|
||||||
|
if notFirst:
|
||||||
|
res.add(default(BlobSidecars))
|
||||||
|
else:
|
||||||
|
let count = Base10.decode(uint8, [map[index]]).get()
|
||||||
|
doAssert(count > 0 and count <= 9)
|
||||||
|
var subres: seq[ref BlobSidecar]
|
||||||
|
for i in 0 ..< int(count):
|
||||||
|
let car =
|
||||||
|
newClone(BlobSidecar(
|
||||||
|
index: uint64(i),
|
||||||
|
signed_block_header:
|
||||||
|
SignedBeaconBlockHeader(
|
||||||
|
message: BeaconBlockHeader(slot: slot))))
|
||||||
|
subres.add(car)
|
||||||
|
res.add(BlobSidecars(subres))
|
||||||
|
notFirst = true
|
||||||
|
res
|
||||||
|
|
||||||
|
func createBlobRange(srange: SyncRange, map: string): seq[ref BlobSidecar] =
|
||||||
|
var res: seq[ref BlobSidecar]
|
||||||
|
doAssert(lenu64(map) == srange.count,
|
||||||
|
"Length of map string should be equal to range size")
|
||||||
|
for index in 0 ..< srange.count:
|
||||||
|
let slot = srange.slot + index
|
||||||
|
if map[index] != '.':
|
||||||
|
let count = Base10.decode(uint8, [map[index]]).get()
|
||||||
|
doAssert(count > 0 and count <= 9)
|
||||||
|
for i in 0 ..< int(count):
|
||||||
|
let car =
|
||||||
|
newClone(BlobSidecar(
|
||||||
|
index: uint64(i),
|
||||||
|
signed_block_header:
|
||||||
|
SignedBeaconBlockHeader(
|
||||||
|
message: BeaconBlockHeader(slot: slot))))
|
||||||
|
res.add(car)
|
||||||
|
res
|
||||||
|
|
||||||
func collector(queue: AsyncQueue[BlockEntry]): BlockVerifier =
|
func collector(queue: AsyncQueue[BlockEntry]): BlockVerifier =
|
||||||
proc verify(
|
proc verify(
|
||||||
signedBlock: ForkedSignedBeaconBlock,
|
signedBlock: ForkedSignedBeaconBlock,
|
||||||
|
|
Loading…
Reference in New Issue