Skip to content

Commit

Permalink
Also lock in removals
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano54 committed Apr 21, 2021
1 parent 9c11d41 commit 111edd7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion chia/full_node/full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ async def respond_transaction(
if self.mempool_manager.seen(spend_name):
return MempoolInclusionStatus.FAILED, Err.ALREADY_INCLUDING_TRANSACTION
self.mempool_manager.add_and_maybe_pop_seen(spend_name)
self.log.debug(f"Processing transaction: {spend_name}")
self.log.debug(f"Processingetransaction: {spend_name}")
# Ignore if syncing
if self.sync_store.get_sync_mode():
status = MempoolInclusionStatus.FAILED
Expand Down
32 changes: 18 additions & 14 deletions chia/full_node/full_node_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ async def request_additions(self, request: wallet_protocol.RequestAdditions) ->

assert block is not None and block.foliage_transaction_block is not None

# Note: this might return bad data
# Note: this might return bad data if there is a reorg in this time
additions = await self.full_node.coin_store.get_coins_added_at_height(block.height)

if self.full_node.blockchain.height_to_hash(block.height) != request.header_hash:
Expand Down Expand Up @@ -1012,20 +1012,24 @@ async def request_removals(self, request: wallet_protocol.RequestRemovals) -> Op
block: Optional[FullBlock] = await self.full_node.block_store.get_full_block(request.header_hash)

# We lock so that the coin store does not get modified
async with self.full_node.blockchain.lock:
if (
block is None
or block.is_transaction_block() is False
or block.height != request.height
or block.height > self.full_node.blockchain.get_peak_height()
or self.full_node.blockchain.height_to_hash(block.height) != request.header_hash
):
reject = wallet_protocol.RejectRemovalsRequest(request.height, request.header_hash)
msg = make_msg(ProtocolMessageTypes.reject_removals_request, reject)
return msg
if (
block is None
or block.is_transaction_block() is False
or block.height != request.height
or block.height > self.full_node.blockchain.get_peak_height()
or self.full_node.blockchain.height_to_hash(block.height) != request.header_hash
):
reject = wallet_protocol.RejectRemovalsRequest(request.height, request.header_hash)
msg = make_msg(ProtocolMessageTypes.reject_removals_request, reject)
return msg

assert block is not None and block.foliage_transaction_block is not None

assert block is not None and block.foliage_transaction_block is not None
all_removals: List[CoinRecord] = await self.full_node.coin_store.get_coins_removed_at_height(block.height)
# Note: this might return bad data if there is a reorg in this time
all_removals: List[CoinRecord] = await self.full_node.coin_store.get_coins_removed_at_height(block.height)

if self.full_node.blockchain.height_to_hash(block.height) != request.header_hash:
raise ValueError(f"Block {block.header_hash} no longer in chain")

all_removals_dict: Dict[bytes32, Coin] = {}
for coin_record in all_removals:
Expand Down

0 comments on commit 111edd7

Please sign in to comment.