Skip to content

Commit

Permalink
Fix fns
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano54 authored and hoffmang9 committed Mar 6, 2021
1 parent ded3934 commit c5f2e58
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 39 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,7 @@ chia-blockchain-gui/src/locales/_build
build_scripts\win_build
build_scripts/win_build
win_code_sign_cert.p12

# Certificates
mozilla-ca

2 changes: 1 addition & 1 deletion src/consensus/make_sub_epoch_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def next_sub_epoch_summary(
constants, len(block.finished_sub_slots) > 0, prev_b, blocks
)[0]
overflow = is_overflow_block(constants, signage_point_index)

if (
len(block.finished_sub_slots) > 0
and block.finished_sub_slots[0].challenge_chain.subepoch_summary_hash is not None
Expand Down Expand Up @@ -151,7 +152,6 @@ def next_sub_epoch_summary(
overflow,
len(block.finished_sub_slots),
)

can_finish_se, can_finish_epoch = can_finish_sub_and_full_epoch(
constants,
blocks,
Expand Down
21 changes: 1 addition & 20 deletions src/full_node/full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)
from src.consensus.make_sub_epoch_summary import next_sub_epoch_summary
from src.consensus.multiprocess_validation import PreValidationResult
from src.consensus.pot_iterations import is_overflow_block, calculate_sp_iters
from src.consensus.pot_iterations import calculate_sp_iters
from src.consensus.block_record import BlockRecord
from src.full_node.block_store import BlockStore
from src.full_node.coin_store import CoinStore
Expand Down Expand Up @@ -1160,7 +1160,6 @@ async def new_infusion_point_vdf(self, request: timelord_protocol.NewInfusionPoi
self.log.warning(f"Previous block is None, infusion point {request.reward_chain_ip_vdf.challenge}")
return None

# TODO: finished slots is not correct
finished_sub_slots = self.full_node_store.get_finished_sub_slots(
self.blockchain,
prev_b,
Expand Down Expand Up @@ -1205,27 +1204,9 @@ async def new_infusion_point_vdf(self, request: timelord_protocol.NewInfusionPoi
sp_total_iters,
difficulty,
)
first_ss_new_epoch = False
if not self.has_valid_pool_sig(block):
self.log.warning("Trying to make a pre-farm block but height is not 0")
return None
if len(block.finished_sub_slots) > 0:
if block.finished_sub_slots[0].challenge_chain.new_difficulty is not None:
first_ss_new_epoch = True
else:
curr = prev_b
while (curr is not None) and not curr.first_in_sub_slot:
curr = self.blockchain.block_record(curr.prev_hash)
if (
curr is not None
and curr.first_in_sub_slot
and curr.sub_epoch_summary_included is not None
and curr.sub_epoch_summary_included.new_difficulty is not None
):
first_ss_new_epoch = True
if first_ss_new_epoch and overflow:
# No overflow blocks in the first sub-slot of each epoch
return None
try:
await self.respond_block(full_node_protocol.RespondBlock(block))
except ConsensusError as e:
Expand Down
26 changes: 16 additions & 10 deletions src/full_node/full_node_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,36 +601,42 @@ def get_finished_sub_slots(
self,
block_records: BlockchainInterface,
prev_b: Optional[BlockRecord],
last_challenge_hash: bytes32,
last_challenge_to_add: bytes32,
) -> List[EndOfSubSlotBundle]:
"""
Retrieves the EndOfSubSlotBundles that are in the store either:
1. From the starting challenge if prev_b is None
2. That are not included in the blockchain with peak of prev_b if prev_b is not None
Stops at last_challenge_hash
Stops at last_challenge
"""
if prev_b is None:
# The first sub slot must be None
assert self.finished_sub_slots[0][0] is None
if last_challenge_hash == self.constants.GENESIS_CHALLENGE:
return []
final_sub_slot_in_chain: bytes32 = self.constants.GENESIS_CHALLENGE
challenge_in_chain: bytes32 = self.constants.GENESIS_CHALLENGE
else:
curr: BlockRecord = prev_b
while not curr.first_in_sub_slot:
curr = block_records.block_record(curr.prev_hash)
assert curr is not None
assert curr.finished_challenge_slot_hashes is not None
final_sub_slot_in_chain = curr.finished_challenge_slot_hashes[-1]
challenge_in_chain = curr.finished_challenge_slot_hashes[-1]

if last_challenge_to_add == challenge_in_chain:
# No additional slots to add
return []

collected_sub_slots: List[EndOfSubSlotBundle] = []
found_last_challenge_hash = False
found_last_challenge = False
found_connecting_challenge = False
for sub_slot, sps, total_iters in self.finished_sub_slots[1:]:
assert sub_slot is not None
collected_sub_slots.append(sub_slot)
if sub_slot.challenge_chain.get_hash() == final_sub_slot_in_chain:
found_last_challenge_hash = True
if sub_slot.challenge_chain.challenge_chain_end_of_slot_vdf.challenge == challenge_in_chain:
found_connecting_challenge = True
if found_connecting_challenge and sub_slot.challenge_chain.get_hash() == last_challenge_to_add:
found_last_challenge = True
break
assert found_last_challenge_hash
if not found_last_challenge:
raise ValueError(f"Did not find hash {last_challenge_to_add} connected to " f"{challenge_in_chain}")
return collected_sub_slots
11 changes: 3 additions & 8 deletions tests/core/full_node/test_full_node_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ async def test_basic_store(self, empty_blockchain, normalized_to_identity: bool
BlockCache({}),
None,
sub_slots[0].challenge_chain.challenge_chain_end_of_slot_vdf.challenge,
False,
)
== []
)
Expand All @@ -108,15 +107,12 @@ async def test_basic_store(self, empty_blockchain, normalized_to_identity: bool
assert store.new_finished_sub_slot(sub_slots[i], {}, None) is not None
assert store.get_sub_slot(sub_slots[i].challenge_chain.get_hash())[0] == sub_slots[i]

assert (
store.get_finished_sub_slots(BlockCache({}), None, sub_slots[-1].challenge_chain.get_hash(), False)
== sub_slots
)
assert store.get_finished_sub_slots(BlockCache({}), None, sub_slots[-1].challenge_chain.get_hash()) == sub_slots
with raises(ValueError):
store.get_finished_sub_slots(None, {}, sub_slots[-1].challenge_chain.get_hash(), True)
store.get_finished_sub_slots(BlockCache({}), None, std_hash(b"not a valid hash"))

assert (
store.get_finished_sub_slots(BlockCache({}), None, sub_slots[-2].challenge_chain.get_hash(), False)
store.get_finished_sub_slots(BlockCache({}), None, sub_slots[-2].challenge_chain.get_hash())
== sub_slots[:-1]
)

Expand All @@ -142,7 +138,6 @@ async def test_basic_store(self, empty_blockchain, normalized_to_identity: bool
blockchain,
peak,
sub_slots[-1].challenge_chain.get_hash(),
False,
)
== []
)
Expand Down

0 comments on commit c5f2e58

Please sign in to comment.