disable block/attestation pool tests in mainnet

This commit is contained in:
Jacek Sieka 2019-12-19 15:13:35 +01:00 committed by tersec
parent b994da78a7
commit 07c37517ea
2 changed files with 245 additions and 243 deletions

View File

@ -15,206 +15,207 @@ import
../beacon_chain/spec/[beaconstate, crypto, datatypes, digest, helpers, validator],
../beacon_chain/[beacon_node_types, attestation_pool, block_pool, extras, state_transition, ssz]
suite "Attestation pool processing" & preset():
## For now just test that we can compile and execute block processing with
## mock data.
when const_preset == "minimal": # Too much stack space used on mainnet
suite "Attestation pool processing" & preset():
## For now just test that we can compile and execute block processing with
## mock data.
setup:
# Genesis state that results in 3 members per committee
var
blockPool = BlockPool.init(makeTestDB(SLOTS_PER_EPOCH * 3))
pool = AttestationPool.init(blockPool)
state = loadTailState(blockPool)
# Slot 0 is a finalized slot - won't be making attestations for it..
process_slots(state.data, state.data.data.slot + 1)
setup:
# Genesis state that results in 3 members per committee
var
blockPool = BlockPool.init(makeTestDB(SLOTS_PER_EPOCH * 3))
pool = AttestationPool.init(blockPool)
state = loadTailState(blockPool)
# Slot 0 is a finalized slot - won't be making attestations for it..
process_slots(state.data, state.data.data.slot + 1)
timedTest "Can add and retrieve simple attestation" & preset():
var cache = get_empty_per_epoch_cache()
let
# Create an attestation for slot 1!
beacon_committee = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation = makeAttestation(
state.data.data, state.blck.root, beacon_committee[0], cache)
timedTest "Can add and retrieve simple attestation" & preset():
var cache = get_empty_per_epoch_cache()
let
# Create an attestation for slot 1!
beacon_committee = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation = makeAttestation(
state.data.data, state.blck.root, beacon_committee[0], cache)
pool.add(attestation)
pool.add(attestation)
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
check:
attestations.len == 1
check:
attestations.len == 1
timedTest "Attestations may arrive in any order" & preset():
var cache = get_empty_per_epoch_cache()
let
# Create an attestation for slot 1!
bc0 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation0 = makeAttestation(
state.data.data, state.blck.root, bc0[0], cache)
timedTest "Attestations may arrive in any order" & preset():
var cache = get_empty_per_epoch_cache()
let
# Create an attestation for slot 1!
bc0 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation0 = makeAttestation(
state.data.data, state.blck.root, bc0[0], cache)
process_slots(state.data, state.data.data.slot + 1)
process_slots(state.data, state.data.data.slot + 1)
let
bc1 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation1 = makeAttestation(
state.data.data, state.blck.root, bc1[0], cache)
let
bc1 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation1 = makeAttestation(
state.data.data, state.blck.root, bc1[0], cache)
# test reverse order
pool.add(attestation1)
pool.add(attestation0)
# test reverse order
pool.add(attestation1)
pool.add(attestation0)
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
check:
attestations.len == 1
check:
attestations.len == 1
timedTest "Attestations should be combined" & preset():
var cache = get_empty_per_epoch_cache()
let
# Create an attestation for slot 1!
bc0 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation0 = makeAttestation(
state.data.data, state.blck.root, bc0[0], cache)
attestation1 = makeAttestation(
state.data.data, state.blck.root, bc0[1], cache)
timedTest "Attestations should be combined" & preset():
var cache = get_empty_per_epoch_cache()
let
# Create an attestation for slot 1!
bc0 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation0 = makeAttestation(
state.data.data, state.blck.root, bc0[0], cache)
attestation1 = makeAttestation(
state.data.data, state.blck.root, bc0[1], cache)
pool.add(attestation0)
pool.add(attestation1)
pool.add(attestation0)
pool.add(attestation1)
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
check:
attestations.len == 1
check:
attestations.len == 1
timedTest "Attestations may overlap, bigger first" & preset():
var cache = get_empty_per_epoch_cache()
timedTest "Attestations may overlap, bigger first" & preset():
var cache = get_empty_per_epoch_cache()
var
# Create an attestation for slot 1!
bc0 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation0 = makeAttestation(
state.data.data, state.blck.root, bc0[0], cache)
attestation1 = makeAttestation(
state.data.data, state.blck.root, bc0[1], cache)
var
# Create an attestation for slot 1!
bc0 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation0 = makeAttestation(
state.data.data, state.blck.root, bc0[0], cache)
attestation1 = makeAttestation(
state.data.data, state.blck.root, bc0[1], cache)
attestation0.combine(attestation1, {skipValidation})
attestation0.combine(attestation1, {skipValidation})
pool.add(attestation0)
pool.add(attestation1)
pool.add(attestation0)
pool.add(attestation1)
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
check:
attestations.len == 1
check:
attestations.len == 1
timedTest "Attestations may overlap, smaller first" & preset():
var cache = get_empty_per_epoch_cache()
var
# Create an attestation for slot 1!
bc0 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation0 = makeAttestation(
state.data.data, state.blck.root, bc0[0], cache)
attestation1 = makeAttestation(
state.data.data, state.blck.root, bc0[1], cache)
timedTest "Attestations may overlap, smaller first" & preset():
var cache = get_empty_per_epoch_cache()
var
# Create an attestation for slot 1!
bc0 = get_beacon_committee(state.data.data,
state.data.data.slot, 0, cache)
attestation0 = makeAttestation(
state.data.data, state.blck.root, bc0[0], cache)
attestation1 = makeAttestation(
state.data.data, state.blck.root, bc0[1], cache)
attestation0.combine(attestation1, {skipValidation})
attestation0.combine(attestation1, {skipValidation})
pool.add(attestation1)
pool.add(attestation0)
pool.add(attestation1)
pool.add(attestation0)
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
process_slots(state.data, MIN_ATTESTATION_INCLUSION_DELAY.Slot) # minus 1?
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
let attestations = pool.getAttestationsForBlock(
state.data.data, state.data.data.slot + 1)
check:
attestations.len == 1
check:
attestations.len == 1
timedTest "Fork choice returns latest block with no attestations":
let
b1 = addBlock(state.data.data, blockPool.tail.root, BeaconBlockBody())
b1Root = hash_tree_root(b1.message)
b1Add = blockPool.add(b1Root, b1)
head = pool.selectHead()
timedTest "Fork choice returns latest block with no attestations":
let
b1 = addBlock(state.data.data, blockPool.tail.root, BeaconBlockBody())
b1Root = hash_tree_root(b1.message)
b1Add = blockPool.add(b1Root, b1)
head = pool.selectHead()
check:
head == b1Add
check:
head == b1Add
let
b2 = addBlock(state.data.data, b1Root, BeaconBlockBody())
b2Root = hash_tree_root(b2.message)
b2Add = blockPool.add(b2Root, b2)
head2 = pool.selectHead()
let
b2 = addBlock(state.data.data, b1Root, BeaconBlockBody())
b2Root = hash_tree_root(b2.message)
b2Add = blockPool.add(b2Root, b2)
head2 = pool.selectHead()
check:
head2 == b2Add
check:
head2 == b2Add
timedTest "Fork choice returns block with attestation":
var cache = get_empty_per_epoch_cache()
let
b10 = makeBlock(state.data.data, blockPool.tail.root, BeaconBlockBody())
b10Root = hash_tree_root(b10.message)
b10Add = blockPool.add(b10Root, b10)
head = pool.selectHead()
timedTest "Fork choice returns block with attestation":
var cache = get_empty_per_epoch_cache()
let
b10 = makeBlock(state.data.data, blockPool.tail.root, BeaconBlockBody())
b10Root = hash_tree_root(b10.message)
b10Add = blockPool.add(b10Root, b10)
head = pool.selectHead()
check:
head == b10Add
check:
head == b10Add
let
b11 = makeBlock(state.data.data, blockPool.tail.root, BeaconBlockBody(
graffiti: Eth2Digest(data: [1'u8, 0, 0, 0 ,0 ,0 ,0 ,0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
))
b11Root = hash_tree_root(b11.message)
b11Add = blockPool.add(b11Root, b11)
let
b11 = makeBlock(state.data.data, blockPool.tail.root, BeaconBlockBody(
graffiti: Eth2Digest(data: [1'u8, 0, 0, 0 ,0 ,0 ,0 ,0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
))
b11Root = hash_tree_root(b11.message)
b11Add = blockPool.add(b11Root, b11)
bc1 = get_beacon_committee(state.data.data,
state.data.data.slot, 1, cache)
attestation0 = makeAttestation(
state.data.data, b10Root, bc1[0], cache)
bc1 = get_beacon_committee(state.data.data,
state.data.data.slot, 1, cache)
attestation0 = makeAttestation(
state.data.data, b10Root, bc1[0], cache)
pool.add(attestation0)
pool.add(attestation0)
let head2 = pool.selectHead()
let head2 = pool.selectHead()
check:
# Single vote for b10 and no votes for b11
head2 == b10Add
check:
# Single vote for b10 and no votes for b11
head2 == b10Add
let
attestation1 = makeAttestation(
state.data.data, b11Root, bc1[1], cache)
attestation2 = makeAttestation(
state.data.data, b11Root, bc1[2], cache)
pool.add(attestation1)
let
attestation1 = makeAttestation(
state.data.data, b11Root, bc1[1], cache)
attestation2 = makeAttestation(
state.data.data, b11Root, bc1[2], cache)
pool.add(attestation1)
let head3 = pool.selectHead()
let smaller = if b10Root.data < b11Root.data: b10Add else: b11Add
let head3 = pool.selectHead()
let smaller = if b10Root.data < b11Root.data: b10Add else: b11Add
check:
# Ties broken lexicographically
head3 == smaller
check:
# Ties broken lexicographically
head3 == smaller
pool.add(attestation2)
pool.add(attestation2)
let head4 = pool.selectHead()
let head4 = pool.selectHead()
check:
# Two votes for b11
head4 == b11Add
check:
# Two votes for b11
head4 == b11Add

View File

@ -13,116 +13,117 @@ import
../beacon_chain/spec/[beaconstate, datatypes, digest],
../beacon_chain/[beacon_node_types, block_pool, beacon_chain_db, extras, ssz]
suite "Block pool processing" & preset():
setup:
var
db = makeTestDB(SLOTS_PER_EPOCH)
pool = BlockPool.init(db)
state = pool.loadTailState().data.data
b1 = addBlock(state, pool.tail.root, BeaconBlockBody())
b1Root = hash_tree_root(b1.message)
b2 = addBlock(state, b1Root, BeaconBlockBody())
b2Root = hash_tree_root(b2.message)
when const_preset == "minimal": # Too much stack space used on mainnet
suite "Block pool processing" & preset():
setup:
var
db = makeTestDB(SLOTS_PER_EPOCH)
pool = BlockPool.init(db)
state = pool.loadTailState().data.data
b1 = addBlock(state, pool.tail.root, BeaconBlockBody())
b1Root = hash_tree_root(b1.message)
b2 = addBlock(state, b1Root, BeaconBlockBody())
b2Root = hash_tree_root(b2.message)
timedTest "getRef returns nil for missing blocks":
check:
pool.getRef(default Eth2Digest) == nil
timedTest "getRef returns nil for missing blocks":
check:
pool.getRef(default Eth2Digest) == nil
timedTest "loadTailState gets genesis block on first load" & preset():
var
b0 = pool.get(pool.tail.root)
timedTest "loadTailState gets genesis block on first load" & preset():
var
b0 = pool.get(pool.tail.root)
check:
b0.isSome()
toSeq(pool.blockRootsForSlot(GENESIS_SLOT)) == @[pool.tail.root]
check:
b0.isSome()
toSeq(pool.blockRootsForSlot(GENESIS_SLOT)) == @[pool.tail.root]
timedTest "Simple block add&get" & preset():
let
b1Add = pool.add(b1Root, b1)
b1Get = pool.get(b1Root)
timedTest "Simple block add&get" & preset():
let
b1Add = pool.add(b1Root, b1)
b1Get = pool.get(b1Root)
check:
b1Get.isSome()
b1Get.get().refs.root == b1Root
b1Add.root == b1Get.get().refs.root
check:
b1Get.isSome()
b1Get.get().refs.root == b1Root
b1Add.root == b1Get.get().refs.root
let
b2Add = pool.add(b2Root, b2)
b2Get = pool.get(b2Root)
let
b2Add = pool.add(b2Root, b2)
b2Get = pool.get(b2Root)
check:
b2Get.isSome()
b2Get.get().refs.root == b2Root
b2Add.root == b2Get.get().refs.root
check:
b2Get.isSome()
b2Get.get().refs.root == b2Root
b2Add.root == b2Get.get().refs.root
timedTest "Reverse order block add & get" & preset():
discard pool.add(b2Root, b2)
timedTest "Reverse order block add & get" & preset():
discard pool.add(b2Root, b2)
check:
pool.get(b2Root).isNone() # Unresolved, shouldn't show up
FetchRecord(root: b1Root, historySlots: 1) in pool.checkMissing()
check:
pool.get(b2Root).isNone() # Unresolved, shouldn't show up
FetchRecord(root: b1Root, historySlots: 1) in pool.checkMissing()
discard pool.add(b1Root, b1)
discard pool.add(b1Root, b1)
let
b1Get = pool.get(b1Root)
b2Get = pool.get(b2Root)
let
b1Get = pool.get(b1Root)
b2Get = pool.get(b2Root)
check:
b1Get.isSome()
b2Get.isSome()
check:
b1Get.isSome()
b2Get.isSome()
b1Get.get().refs.children[0] == b2Get.get().refs
b2Get.get().refs.parent == b1Get.get().refs
toSeq(pool.blockRootsForSlot(b1.message.slot)) == @[b1Root]
toSeq(pool.blockRootsForSlot(b2.message.slot)) == @[b2Root]
b1Get.get().refs.children[0] == b2Get.get().refs
b2Get.get().refs.parent == b1Get.get().refs
toSeq(pool.blockRootsForSlot(b1.message.slot)) == @[b1Root]
toSeq(pool.blockRootsForSlot(b2.message.slot)) == @[b2Root]
db.putHeadBlock(b2Root)
db.putHeadBlock(b2Root)
# The heads structure should have been updated to contain only the new
# b2 head
check:
pool.heads.mapIt(it.blck) == @[b2Get.get().refs]
# The heads structure should have been updated to contain only the new
# b2 head
check:
pool.heads.mapIt(it.blck) == @[b2Get.get().refs]
# check that init also reloads block graph
var
pool2 = BlockPool.init(db)
# check that init also reloads block graph
var
pool2 = BlockPool.init(db)
check:
pool2.get(b1Root).isSome()
pool2.get(b2Root).isSome()
check:
pool2.get(b1Root).isSome()
pool2.get(b2Root).isSome()
timedTest "isAncestorOf sanity" & preset():
let
a = BlockRef(slot: Slot(1))
b = BlockRef(slot: Slot(2), parent: a)
c = BlockRef(slot: Slot(3), parent: b)
timedTest "isAncestorOf sanity" & preset():
let
a = BlockRef(slot: Slot(1))
b = BlockRef(slot: Slot(2), parent: a)
c = BlockRef(slot: Slot(3), parent: b)
check:
a.isAncestorOf(a)
a.isAncestorOf(b)
a.isAncestorOf(c)
b.isAncestorOf(c)
check:
a.isAncestorOf(a)
a.isAncestorOf(b)
a.isAncestorOf(c)
b.isAncestorOf(c)
not c.isAncestorOf(a)
not c.isAncestorOf(b)
not b.isAncestorOf(a)
not c.isAncestorOf(a)
not c.isAncestorOf(b)
not b.isAncestorOf(a)
timedTest "Can add same block twice" & preset():
let
b10 = pool.add(b1Root, b1)
b11 = pool.add(b1Root, b1)
timedTest "Can add same block twice" & preset():
let
b10 = pool.add(b1Root, b1)
b11 = pool.add(b1Root, b1)
check:
b10 == b11
not b10.isNil
check:
b10 == b11
not b10.isNil
timedTest "updateHead updates head and headState" & preset():
let
b1Add = pool.add(b1Root, b1)
timedTest "updateHead updates head and headState" & preset():
let
b1Add = pool.add(b1Root, b1)
pool.updateHead(b1Add)
pool.updateHead(b1Add)
check:
pool.head.blck == b1Add
pool.headState.data.data.slot == b1Add.slot
check:
pool.head.blck == b1Add
pool.headState.data.data.slot == b1Add.slot