mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-22 12:30:08 +00:00
add non-SZ getBlobSidecar and BlobSidecar database tests (#5528)
This commit is contained in:
parent
41dfc9ed91
commit
09df3f32b5
@ -48,6 +48,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
|||||||
+ sanity check Deneb blocks [Preset: mainnet] OK
|
+ sanity check Deneb blocks [Preset: mainnet] OK
|
||||||
+ sanity check Deneb states [Preset: mainnet] OK
|
+ sanity check Deneb states [Preset: mainnet] OK
|
||||||
+ sanity check Deneb states, reusing buffers [Preset: mainnet] OK
|
+ sanity check Deneb states, reusing buffers [Preset: mainnet] OK
|
||||||
|
+ sanity check blobs [Preset: mainnet] OK
|
||||||
+ sanity check genesis roundtrip [Preset: mainnet] OK
|
+ sanity check genesis roundtrip [Preset: mainnet] OK
|
||||||
+ sanity check phase 0 blocks [Preset: mainnet] OK
|
+ sanity check phase 0 blocks [Preset: mainnet] OK
|
||||||
+ sanity check phase 0 getState rollback [Preset: mainnet] OK
|
+ sanity check phase 0 getState rollback [Preset: mainnet] OK
|
||||||
@ -55,7 +56,7 @@ OK: 3/3 Fail: 0/3 Skip: 0/3
|
|||||||
+ sanity check phase 0 states, reusing buffers [Preset: mainnet] OK
|
+ sanity check phase 0 states, reusing buffers [Preset: mainnet] OK
|
||||||
+ sanity check state diff roundtrip [Preset: mainnet] OK
|
+ sanity check state diff roundtrip [Preset: mainnet] OK
|
||||||
```
|
```
|
||||||
OK: 24/24 Fail: 0/24 Skip: 0/24
|
OK: 25/25 Fail: 0/25 Skip: 0/25
|
||||||
## Beacon state [Preset: mainnet]
|
## Beacon state [Preset: mainnet]
|
||||||
```diff
|
```diff
|
||||||
+ Smoke test initialize_beacon_state_from_eth1 [Preset: mainnet] OK
|
+ Smoke test initialize_beacon_state_from_eth1 [Preset: mainnet] OK
|
||||||
@ -714,4 +715,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
|
|||||||
OK: 9/9 Fail: 0/9 Skip: 0/9
|
OK: 9/9 Fail: 0/9 Skip: 0/9
|
||||||
|
|
||||||
---TOTAL---
|
---TOTAL---
|
||||||
OK: 403/408 Fail: 0/408 Skip: 5/408
|
OK: 404/409 Fail: 0/409 Skip: 5/409
|
||||||
|
@ -1042,13 +1042,16 @@ proc getBlockSSZ*(
|
|||||||
getBlockSSZ(db, key, data, consensusFork.TrustedSignedBeaconBlock)
|
getBlockSSZ(db, key, data, consensusFork.TrustedSignedBeaconBlock)
|
||||||
|
|
||||||
proc getBlobSidecarSZ*(db: BeaconChainDB, root: Eth2Digest, index: BlobIndex,
|
proc getBlobSidecarSZ*(db: BeaconChainDB, root: Eth2Digest, index: BlobIndex,
|
||||||
data: var seq[byte]):
|
data: var seq[byte]): bool =
|
||||||
bool =
|
|
||||||
let dataPtr = addr data # Short-lived
|
let dataPtr = addr data # Short-lived
|
||||||
func decode(data: openArray[byte]) =
|
func decode(data: openArray[byte]) =
|
||||||
assign(dataPtr[], data)
|
assign(dataPtr[], data)
|
||||||
db.blobs.get(blobkey(root, index), decode).expectDb()
|
db.blobs.get(blobkey(root, index), decode).expectDb()
|
||||||
|
|
||||||
|
proc getBlobSidecar*(db: BeaconChainDB, root: Eth2Digest, index: BlobIndex,
|
||||||
|
value: var BlobSidecar): bool =
|
||||||
|
db.blobs.getSZSSZ(blobkey(root, index), value) == GetResult.found
|
||||||
|
|
||||||
proc getBlockSZ*(
|
proc getBlockSZ*(
|
||||||
db: BeaconChainDB, key: Eth2Digest, data: var seq[byte],
|
db: BeaconChainDB, key: Eth2Digest, data: var seq[byte],
|
||||||
T: type phase0.TrustedSignedBeaconBlock): bool =
|
T: type phase0.TrustedSignedBeaconBlock): bool =
|
||||||
|
@ -234,19 +234,6 @@ proc getForkedBlock*(db: BeaconChainDB, root: Eth2Digest):
|
|||||||
else:
|
else:
|
||||||
err()
|
err()
|
||||||
|
|
||||||
proc containsBlock(dag: ChainDAGRef, bid: BlockId): bool =
|
|
||||||
let fork = dag.cfg.consensusForkAtEpoch(bid.slot.epoch)
|
|
||||||
if dag.db.containsBlock(bid.root, fork):
|
|
||||||
return true
|
|
||||||
|
|
||||||
# TODO avoid loading bytes from era
|
|
||||||
var bytes: seq[byte]
|
|
||||||
(bid.slot <= dag.finalizedHead.slot and
|
|
||||||
getBlockSZ(
|
|
||||||
dag.era, getStateField(dag.headState, historical_roots).asSeq,
|
|
||||||
dag.headState.historical_summaries().asSeq,
|
|
||||||
bid.slot, bytes).isOk and bytes.len > 0)
|
|
||||||
|
|
||||||
proc getBlock*(
|
proc getBlock*(
|
||||||
dag: ChainDAGRef, bid: BlockId,
|
dag: ChainDAGRef, bid: BlockId,
|
||||||
T: type ForkyTrustedSignedBeaconBlock): Opt[T] =
|
T: type ForkyTrustedSignedBeaconBlock): Opt[T] =
|
||||||
|
@ -11,7 +11,6 @@ import
|
|||||||
unittest2,
|
unittest2,
|
||||||
../beacon_chain/beacon_chain_db,
|
../beacon_chain/beacon_chain_db,
|
||||||
../beacon_chain/spec/[beaconstate, forks, state_transition],
|
../beacon_chain/spec/[beaconstate, forks, state_transition],
|
||||||
../beacon_chain/spec/datatypes/[phase0, altair, bellatrix],
|
|
||||||
../beacon_chain/consensus_object_pools/blockchain_dag,
|
../beacon_chain/consensus_object_pools/blockchain_dag,
|
||||||
eth/db/kvstore,
|
eth/db/kvstore,
|
||||||
# test utilies
|
# test utilies
|
||||||
@ -761,6 +760,102 @@ suite "Beacon chain DB" & preset():
|
|||||||
check:
|
check:
|
||||||
hash_tree_root(state2[]) == root
|
hash_tree_root(state2[]) == root
|
||||||
|
|
||||||
|
test "sanity check blobs" & preset():
|
||||||
|
const
|
||||||
|
blockRoot0 = Eth2Digest.fromHex(
|
||||||
|
"0x436f3180d2541a94560de3423d6d8f0e16e3b4c061ccd620bcfaee31424b5eb6")
|
||||||
|
blockRoot1 = Eth2Digest.fromHex(
|
||||||
|
"0x0d3730dc690d5fe4d39ded682d3aec7679af597d5fc6a65a7c8b4e20f228f96d")
|
||||||
|
|
||||||
|
# Ensure minimal-difference pairs on both block root and blob index to
|
||||||
|
# verify that blobkey uses both
|
||||||
|
blobSidecar0 = BlobSidecar(block_root: blockRoot0, index: 3)
|
||||||
|
blobSidecar1 = BlobSidecar(block_root: blockRoot0, index: 2)
|
||||||
|
blobSidecar2 = BlobSidecar(block_root: blockRoot1, index: 2)
|
||||||
|
|
||||||
|
let db = makeTestDB(SLOTS_PER_EPOCH)
|
||||||
|
|
||||||
|
var
|
||||||
|
buf: seq[byte]
|
||||||
|
blobSidecar: BlobSidecar
|
||||||
|
|
||||||
|
check:
|
||||||
|
not db.getBlobSidecar(blockRoot0, 3, blobSidecar)
|
||||||
|
not db.getBlobSidecar(blockRoot0, 2, blobSidecar)
|
||||||
|
not db.getBlobSidecar(blockRoot1, 2, blobSidecar)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 3, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 2, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot1, 2, buf)
|
||||||
|
|
||||||
|
db.putBlobSidecar(blobSidecar0)
|
||||||
|
|
||||||
|
check:
|
||||||
|
db.getBlobSidecar(blockRoot0, 3, blobSidecar)
|
||||||
|
blobSidecar == blobSidecar0
|
||||||
|
not db.getBlobSidecar(blockRoot0, 2, blobSidecar)
|
||||||
|
not db.getBlobSidecar(blockRoot1, 2, blobSidecar)
|
||||||
|
db.getBlobSidecarSZ(blockRoot0, 3, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 2, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot1, 2, buf)
|
||||||
|
|
||||||
|
db.putBlobSidecar(blobSidecar1)
|
||||||
|
|
||||||
|
check:
|
||||||
|
db.getBlobSidecar(blockRoot0, 3, blobSidecar)
|
||||||
|
blobSidecar == blobSidecar0
|
||||||
|
db.getBlobSidecar(blockRoot0, 2, blobSidecar)
|
||||||
|
blobSidecar == blobSidecar1
|
||||||
|
not db.getBlobSidecar(blockRoot1, 2, blobSidecar)
|
||||||
|
db.getBlobSidecarSZ(blockRoot0, 3, buf)
|
||||||
|
db.getBlobSidecarSZ(blockRoot0, 2, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot1, 2, buf)
|
||||||
|
|
||||||
|
check db.delBlobSidecar(blockRoot0, 3)
|
||||||
|
|
||||||
|
check:
|
||||||
|
not db.getBlobSidecar(blockRoot0, 3, blobSidecar)
|
||||||
|
db.getBlobSidecar(blockRoot0, 2, blobSidecar)
|
||||||
|
blobSidecar == blobSidecar1
|
||||||
|
not db.getBlobSidecar(blockRoot1, 2, blobSidecar)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 3, buf)
|
||||||
|
db.getBlobSidecarSZ(blockRoot0, 2, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot1, 2, buf)
|
||||||
|
|
||||||
|
db.putBlobSidecar(blobSidecar2)
|
||||||
|
|
||||||
|
check:
|
||||||
|
not db.getBlobSidecar(blockRoot0, 3, blobSidecar)
|
||||||
|
db.getBlobSidecar(blockRoot0, 2, blobSidecar)
|
||||||
|
blobSidecar == blobSidecar1
|
||||||
|
db.getBlobSidecar(blockRoot1, 2, blobSidecar)
|
||||||
|
blobSidecar == blobSidecar2
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 3, buf)
|
||||||
|
db.getBlobSidecarSZ(blockRoot0, 2, buf)
|
||||||
|
db.getBlobSidecarSZ(blockRoot1, 2, buf)
|
||||||
|
|
||||||
|
check db.delBlobSidecar(blockRoot0, 2)
|
||||||
|
|
||||||
|
check:
|
||||||
|
not db.getBlobSidecar(blockRoot0, 3, blobSidecar)
|
||||||
|
not db.getBlobSidecar(blockRoot0, 2, blobSidecar)
|
||||||
|
db.getBlobSidecar(blockRoot1, 2, blobSidecar)
|
||||||
|
blobSidecar == blobSidecar2
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 3, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 2, buf)
|
||||||
|
db.getBlobSidecarSZ(blockRoot1, 2, buf)
|
||||||
|
|
||||||
|
check db.delBlobSidecar(blockRoot1, 2)
|
||||||
|
|
||||||
|
check:
|
||||||
|
not db.getBlobSidecar(blockRoot0, 3, blobSidecar)
|
||||||
|
not db.getBlobSidecar(blockRoot0, 2, blobSidecar)
|
||||||
|
not db.getBlobSidecar(blockRoot1, 2, blobSidecar)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 3, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot0, 2, buf)
|
||||||
|
not db.getBlobSidecarSZ(blockRoot1, 2, buf)
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
suite "FinalizedBlocks" & preset():
|
suite "FinalizedBlocks" & preset():
|
||||||
test "Basic ops" & preset():
|
test "Basic ops" & preset():
|
||||||
var
|
var
|
||||||
|
@ -23,6 +23,11 @@ proc makeTestDB*(
|
|||||||
eth1Data = Opt.none(Eth1Data),
|
eth1Data = Opt.none(Eth1Data),
|
||||||
flags: UpdateFlags = {},
|
flags: UpdateFlags = {},
|
||||||
cfg = defaultRuntimeConfig): BeaconChainDB =
|
cfg = defaultRuntimeConfig): BeaconChainDB =
|
||||||
|
# Blob support requires DENEB_FORK_EPOCH != FAR_FUTURE_EPOCH
|
||||||
|
var cfg = cfg
|
||||||
|
cfg.CAPELLA_FORK_EPOCH = 90000.Epoch
|
||||||
|
cfg.DENEB_FORK_EPOCH = 100000.Epoch
|
||||||
|
|
||||||
var genState = (ref ForkedHashedBeaconState)(
|
var genState = (ref ForkedHashedBeaconState)(
|
||||||
kind: ConsensusFork.Phase0,
|
kind: ConsensusFork.Phase0,
|
||||||
phase0Data: initialize_hashed_beacon_state_from_eth1(
|
phase0Data: initialize_hashed_beacon_state_from_eth1(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user