Add fixes to map generation and add test helpers.
This commit is contained in:
parent
02b9f89b8f
commit
f8a476f31b
|
@ -7,7 +7,7 @@
|
|||
|
||||
{.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
|
||||
../spec/datatypes/[base, phase0, altair],
|
||||
|
@ -183,21 +183,30 @@ proc getShortMap*[T](
|
|||
var
|
||||
res = newStringOfCap(req.data.count)
|
||||
slider = req.data.slot
|
||||
last = 0
|
||||
notFirst = false
|
||||
|
||||
for i in 0 ..< req.data.count:
|
||||
if last < len(blobs):
|
||||
if len(blobs[last]) > 0:
|
||||
if blobs[last][0][].signed_block_header.message.slot == slider:
|
||||
res.add(Base10.toString(lenu64(blobs[last])))
|
||||
for i in 0 ..< int(req.data.count):
|
||||
if i >= len(blobs):
|
||||
res.add('.'.repeat(int(req.data.count) - len(res)))
|
||||
return res
|
||||
|
||||
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:
|
||||
res.add('.')
|
||||
else:
|
||||
res.add('.')
|
||||
inc(last)
|
||||
else:
|
||||
res.add('.')
|
||||
inc(slider)
|
||||
if notFirst: res.add('.')
|
||||
if notFirst: inc(slider)
|
||||
res
|
||||
|
||||
proc getShortMap*[T](
|
||||
|
|
|
@ -89,6 +89,52 @@ func createBlobs(
|
|||
inc sidecarIdx
|
||||
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 =
|
||||
proc verify(
|
||||
signedBlock: ForkedSignedBeaconBlock,
|
||||
|
|
Loading…
Reference in New Issue