Skip to content

Commit

Permalink
Deleted blockchain_check_conditions (Chia-Network#1966)
Browse files Browse the repository at this point in the history
* deleted blockchain_check_conditions and added optional timestamp to mempool_check_conditions

* removed unnecessary code

* change back to < for block height

* time now passes on equal to condition value
  • Loading branch information
matt-o-how authored Apr 16, 2021
1 parent ae911f5 commit 1d6bc44
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 138 deletions.
4 changes: 2 additions & 2 deletions chia/consensus/block_body_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from chia.consensus.block_record import BlockRecord
from chia.consensus.block_rewards import calculate_base_farmer_reward, calculate_pool_reward
from chia.consensus.block_root_validation import validate_block_merkle_roots
from chia.consensus.blockchain_check_conditions import blockchain_check_conditions_dict
from chia.full_node.mempool_check_conditions import mempool_check_conditions_dict
from chia.consensus.blockchain_interface import BlockchainInterface
from chia.consensus.coinbase import create_farmer_coin, create_pool_coin
from chia.consensus.constants import ConsensusConstants
Expand Down Expand Up @@ -401,7 +401,7 @@ async def validate_block_body(
for npc in npc_list:
assert height is not None
unspent = removal_coin_records[npc.coin_name]
error = blockchain_check_conditions_dict(
error = mempool_check_conditions_dict(
unspent,
coin_announcement_names,
puzzle_announcement_names,
Expand Down
125 changes: 0 additions & 125 deletions chia/consensus/blockchain_check_conditions.py

This file was deleted.

25 changes: 16 additions & 9 deletions chia/full_node/mempool_check_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def mempool_assert_relative_block_height_exceeds(
return None


def mempool_assert_absolute_time_exceeds(condition: ConditionWithArgs) -> Optional[Err]:
def mempool_assert_absolute_time_exceeds(
condition: ConditionWithArgs, timestamp: Optional[uint64] = None
) -> Optional[Err]:
"""
Check if the current time in millis exceeds the time specified by condition
"""
Expand All @@ -78,13 +80,16 @@ def mempool_assert_absolute_time_exceeds(condition: ConditionWithArgs) -> Option
except ValueError:
return Err.INVALID_CONDITION

current_time = uint64(int(time.time() * 1000))
if current_time <= expected_mili_time:
if timestamp is None:
timestamp = uint64(int(time.time() * 1000))
if timestamp < expected_mili_time:
return Err.ASSERT_SECONDS_ABSOLUTE_FAILED
return None


def mempool_assert_relative_time_exceeds(condition: ConditionWithArgs, unspent: CoinRecord) -> Optional[Err]:
def mempool_assert_relative_time_exceeds(
condition: ConditionWithArgs, unspent: CoinRecord, timestamp: Optional[uint64] = None
) -> Optional[Err]:
"""
Check if the current time in millis exceeds the time specified by condition
"""
Expand All @@ -93,9 +98,10 @@ def mempool_assert_relative_time_exceeds(condition: ConditionWithArgs, unspent:
except ValueError:
return Err.INVALID_CONDITION

current_time = uint64(int(time.time() * 1000))
if current_time <= expected_mili_time + unspent.timestamp:
return Err.ASSERT_SECONDS_ABSOLUTE_FAILED
if timestamp is None:
timestamp = uint64(int(time.time() * 1000))
if timestamp < expected_mili_time + unspent.timestamp:
return Err.ASSERT_SECONDS_RELATIVE_FAILED
return None


Expand Down Expand Up @@ -186,6 +192,7 @@ def mempool_check_conditions_dict(
puzzle_announcement_names: Set[bytes32],
conditions_dict: Dict[ConditionOpcode, List[ConditionWithArgs]],
prev_transaction_block_height: uint32,
timestamp: Optional[uint64] = None,
) -> Optional[Err]:
"""
Check all conditions against current state.
Expand All @@ -205,9 +212,9 @@ def mempool_check_conditions_dict(
elif cvp.opcode is ConditionOpcode.ASSERT_HEIGHT_RELATIVE:
error = mempool_assert_relative_block_height_exceeds(cvp, unspent, prev_transaction_block_height)
elif cvp.opcode is ConditionOpcode.ASSERT_SECONDS_ABSOLUTE:
error = mempool_assert_absolute_time_exceeds(cvp)
error = mempool_assert_absolute_time_exceeds(cvp, timestamp)
elif cvp.opcode is ConditionOpcode.ASSERT_SECONDS_RELATIVE:
error = mempool_assert_relative_time_exceeds(cvp, unspent)
error = mempool_assert_relative_time_exceeds(cvp, unspent, timestamp)
elif cvp.opcode is ConditionOpcode.ASSERT_MY_PARENT_ID:
error = mempool_assert_my_parent_id(cvp, unspent)
elif cvp.opcode is ConditionOpcode.ASSERT_MY_PUZZLEHASH:
Expand Down
4 changes: 2 additions & 2 deletions tests/clvm/coin_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass, replace
from typing import Dict, Iterator, Set

from chia.consensus.blockchain_check_conditions import blockchain_check_conditions_dict
from chia.full_node.mempool_check_conditions import mempool_check_conditions_dict
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_record import CoinRecord
Expand Down Expand Up @@ -65,7 +65,7 @@ def validate_spend_bundle(
prev_transaction_block_height = now.height
timestamp = now.seconds
coin_record = self._db[coin_solution.coin.name()]
err = blockchain_check_conditions_dict(
err = mempool_check_conditions_dict(
coin_record,
coin_announcements,
puzzle_announcements,
Expand Down

0 comments on commit 1d6bc44

Please sign in to comment.