Skip to content

Commit

Permalink
Ms.empty blocks3 (Chia-Network#3064)
Browse files Browse the repository at this point in the history
* Fix empty blocks

* Remove error log

* Missing imports

* .header_hash instead of .prev_hash in simulator
  • Loading branch information
mariano54 committed Apr 29, 2021
1 parent 5f9f631 commit e3ab63a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
8 changes: 6 additions & 2 deletions chia/full_node/full_node_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ async def tx_request_and_timeout(full_node: FullNode, transaction_id, task_id):

@api_request
async def request_transaction(self, request: full_node_protocol.RequestTransaction) -> Optional[Message]:
""" Peer has requested a full transaction from us. """
"""Peer has requested a full transaction from us."""
# Ignore if syncing
if self.full_node.sync_store.get_sync_mode():
return None
Expand Down Expand Up @@ -664,9 +664,13 @@ async def declare_proof_of_space(
async with self.full_node.blockchain.lock:
peak: Optional[BlockRecord] = self.full_node.blockchain.get_peak()
if peak is not None:
# Finds the last transaction block before this one
curr_l_tb: BlockRecord = peak
while not curr_l_tb.is_transaction_block:
curr_l_tb = self.full_node.blockchain.block_record(curr_l_tb.prev_hash)
try:
mempool_bundle = await self.full_node.mempool_manager.create_bundle_from_mempool(
peak.header_hash
curr_l_tb.header_hash
)
except Exception as e:
self.full_node.log.error(f"Error making spend bundle {e} peak: {peak}")
Expand Down
4 changes: 2 additions & 2 deletions chia/full_node/mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def shut_down(self):
self.pool.shutdown(wait=True)

async def create_bundle_from_mempool(
self, peak_header_hash: bytes32
self, last_tb_header_hash: bytes32
) -> Optional[Tuple[SpendBundle, List[Coin], List[Coin]]]:
"""
Returns aggregated spendbundle that can be used for creating new block,
additions and removals in that spend_bundle
"""
if (
self.peak is None
or self.peak.header_hash != peak_header_hash
or self.peak.header_hash != last_tb_header_hash
or int(time.time()) <= self.constants.INITIAL_FREEZE_END_TIMESTAMP
):
return None
Expand Down
10 changes: 8 additions & 2 deletions chia/simulator/full_node_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ async def farm_new_transaction_block(self, request: FarmNewBlockProtocol):

peak = self.full_node.blockchain.get_peak()
assert peak is not None
mempool_bundle = await self.full_node.mempool_manager.create_bundle_from_mempool(peak.header_hash)
curr: BlockRecord = peak
while not curr.is_transaction_block:
curr = self.full_node.blockchain.block_record(curr.prev_hash)
mempool_bundle = await self.full_node.mempool_manager.create_bundle_from_mempool(curr.header_hash)
if mempool_bundle is None:
spend_bundle = None
else:
Expand Down Expand Up @@ -86,7 +89,10 @@ async def farm_new_block(self, request: FarmNewBlockProtocol):

peak = self.full_node.blockchain.get_peak()
assert peak is not None
mempool_bundle = await self.full_node.mempool_manager.create_bundle_from_mempool(peak.header_hash)
curr: BlockRecord = peak
while not curr.is_transaction_block:
curr = self.full_node.blockchain.block_record(curr.prev_hash)
mempool_bundle = await self.full_node.mempool_manager.create_bundle_from_mempool(curr.header_hash)
if mempool_bundle is None:
spend_bundle = None
else:
Expand Down

0 comments on commit e3ab63a

Please sign in to comment.