Merge commit '4e71529422039ff76d6b3af064f8d7653ccead5f' into checkpoint/main_from_release_1.8.0_4e71529422039ff76d6b3af064f8d7653ccead5f

This commit is contained in:
Amine Khaldi 2023-05-02 19:22:13 +01:00
commit fc1e734b92
No known key found for this signature in database
GPG Key ID: B1C074FFC904E2D9
4 changed files with 78 additions and 46 deletions

View File

@ -815,7 +815,11 @@ def validate_unfinished_header_block(
return None, ValidationError(Err.INVALID_TRANSACTIONS_FILTER_HASH)
# 26a. The timestamp in Foliage Block must not be over 5 minutes in the future
if header_block.foliage_transaction_block.timestamp > int(time.time() + constants.MAX_FUTURE_TIME):
if height >= constants.SOFT_FORK2_HEIGHT:
max_future_time = constants.MAX_FUTURE_TIME2
else:
max_future_time = constants.MAX_FUTURE_TIME
if header_block.foliage_transaction_block.timestamp > int(time.time() + max_future_time):
return None, ValidationError(Err.TIMESTAMP_TOO_FAR_IN_FUTURE)
if prev_b is not None:

View File

@ -36,6 +36,7 @@ class ConsensusConstants:
SUB_SLOT_TIME_TARGET: int # The target number of seconds per sub-slot
NUM_SP_INTERVALS_EXTRA: int # The difference between signage point and infusion point (plus required_iters)
MAX_FUTURE_TIME: int # The next block can have a timestamp of at most these many seconds more
MAX_FUTURE_TIME2: int # After soft-fork2, this is the new MAX_FUTURE_TIME
NUMBER_OF_TIMESTAMPS: int # Than the average of the last NUMBER_OF_TIMESTAMPS blocks
# Used as the initial cc rc challenges, as well as first block back pointers, and first SES back pointer
# We override this value based on the chain being run (testnet0, testnet1, mainnet, etc)

View File

@ -26,6 +26,7 @@ default_kwargs = {
"SUB_SLOT_TIME_TARGET": 600, # The target number of seconds per slot, mainnet 600
"NUM_SP_INTERVALS_EXTRA": 3, # The number of sp intervals to add to the signage point
"MAX_FUTURE_TIME": 5 * 60, # The next block can have a timestamp of at most these many seconds in the future
"MAX_FUTURE_TIME2": 2 * 60, # The next block can have a timestamp of at most these many seconds in the future
"NUMBER_OF_TIMESTAMPS": 11, # Than the average of the last NUMBER_OF_TIMESTAMPS blocks
# Used as the initial cc rc challenges, as well as first block back pointers, and first SES back pointer
# We override this value based on the chain being run (testnet0, testnet1, mainnet, etc)

View File

@ -1486,55 +1486,81 @@ class TestBlockHeaderValidation:
await _validate_and_add_block(empty_blockchain, blocks[-1])
@pytest.mark.asyncio
async def test_bad_timestamp(self, empty_blockchain, bt):
@pytest.mark.parametrize("with_softfork2", [False, True])
async def test_bad_timestamp(self, bt, with_softfork2):
# 26
if with_softfork2:
# enable softfork2 at height 0, to make it apply to this test
# the test constants set MAX_FUTURE_TIME to 10 days, restore it to
# default for this test
constants = test_constants.replace(SOFT_FORK2_HEIGHT=0, MAX_FUTURE_TIME=5 * 60)
time_delta = 2 * 60
else:
constants = test_constants.replace(MAX_FUTURE_TIME=5 * 60)
time_delta = 5 * 60
blocks = bt.get_consecutive_blocks(1)
await _validate_and_add_block(empty_blockchain, blocks[0])
while True:
blocks = bt.get_consecutive_blocks(1, block_list_input=blocks)
if blocks[-1].foliage_transaction_block is not None:
block_bad: FullBlock = recursive_replace(
blocks[-1],
"foliage_transaction_block.timestamp",
blocks[0].foliage_transaction_block.timestamp - 10,
)
block_bad: FullBlock = recursive_replace(
block_bad, "foliage.foliage_transaction_block_hash", block_bad.foliage_transaction_block.get_hash()
)
new_m = block_bad.foliage.foliage_transaction_block_hash
new_fbh_sig = bt.get_plot_signature(new_m, blocks[-1].reward_chain_block.proof_of_space.plot_public_key)
block_bad = recursive_replace(block_bad, "foliage.foliage_transaction_block_signature", new_fbh_sig)
await _validate_and_add_block(empty_blockchain, block_bad, expected_error=Err.TIMESTAMP_TOO_FAR_IN_PAST)
block_bad: FullBlock = recursive_replace(
blocks[-1],
"foliage_transaction_block.timestamp",
blocks[0].foliage_transaction_block.timestamp,
)
block_bad: FullBlock = recursive_replace(
block_bad, "foliage.foliage_transaction_block_hash", block_bad.foliage_transaction_block.get_hash()
)
new_m = block_bad.foliage.foliage_transaction_block_hash
new_fbh_sig = bt.get_plot_signature(new_m, blocks[-1].reward_chain_block.proof_of_space.plot_public_key)
block_bad = recursive_replace(block_bad, "foliage.foliage_transaction_block_signature", new_fbh_sig)
await _validate_and_add_block(empty_blockchain, block_bad, expected_error=Err.TIMESTAMP_TOO_FAR_IN_PAST)
async with make_empty_blockchain(constants) as b:
await _validate_and_add_block(b, blocks[0])
while True:
blocks = bt.get_consecutive_blocks(1, block_list_input=blocks)
if blocks[-1].foliage_transaction_block is not None:
block_bad: FullBlock = recursive_replace(
blocks[-1],
"foliage_transaction_block.timestamp",
blocks[0].foliage_transaction_block.timestamp - 10,
)
block_bad: FullBlock = recursive_replace(
block_bad,
"foliage.foliage_transaction_block_hash",
block_bad.foliage_transaction_block.get_hash(),
)
new_m = block_bad.foliage.foliage_transaction_block_hash
new_fbh_sig = bt.get_plot_signature(
new_m, blocks[-1].reward_chain_block.proof_of_space.plot_public_key
)
block_bad = recursive_replace(block_bad, "foliage.foliage_transaction_block_signature", new_fbh_sig)
await _validate_and_add_block(b, block_bad, expected_error=Err.TIMESTAMP_TOO_FAR_IN_PAST)
block_bad: FullBlock = recursive_replace(
blocks[-1],
"foliage_transaction_block.timestamp",
blocks[0].foliage_transaction_block.timestamp + 10000000,
)
block_bad: FullBlock = recursive_replace(
block_bad, "foliage.foliage_transaction_block_hash", block_bad.foliage_transaction_block.get_hash()
)
new_m = block_bad.foliage.foliage_transaction_block_hash
new_fbh_sig = bt.get_plot_signature(new_m, blocks[-1].reward_chain_block.proof_of_space.plot_public_key)
block_bad = recursive_replace(block_bad, "foliage.foliage_transaction_block_signature", new_fbh_sig)
await _validate_and_add_block(
empty_blockchain, block_bad, expected_error=Err.TIMESTAMP_TOO_FAR_IN_FUTURE
)
return None
await _validate_and_add_block(empty_blockchain, blocks[-1])
block_bad: FullBlock = recursive_replace(
blocks[-1],
"foliage_transaction_block.timestamp",
blocks[0].foliage_transaction_block.timestamp,
)
block_bad: FullBlock = recursive_replace(
block_bad,
"foliage.foliage_transaction_block_hash",
block_bad.foliage_transaction_block.get_hash(),
)
new_m = block_bad.foliage.foliage_transaction_block_hash
new_fbh_sig = bt.get_plot_signature(
new_m, blocks[-1].reward_chain_block.proof_of_space.plot_public_key
)
block_bad = recursive_replace(block_bad, "foliage.foliage_transaction_block_signature", new_fbh_sig)
await _validate_and_add_block(b, block_bad, expected_error=Err.TIMESTAMP_TOO_FAR_IN_PAST)
# since tests can run slow sometimes, and since we're using
# the system clock, add some extra slack
slack = 5
block_bad: FullBlock = recursive_replace(
blocks[-1],
"foliage_transaction_block.timestamp",
blocks[0].foliage_transaction_block.timestamp + time_delta + slack,
)
block_bad: FullBlock = recursive_replace(
block_bad,
"foliage.foliage_transaction_block_hash",
block_bad.foliage_transaction_block.get_hash(),
)
new_m = block_bad.foliage.foliage_transaction_block_hash
new_fbh_sig = bt.get_plot_signature(
new_m, blocks[-1].reward_chain_block.proof_of_space.plot_public_key
)
block_bad = recursive_replace(block_bad, "foliage.foliage_transaction_block_signature", new_fbh_sig)
await _validate_and_add_block(b, block_bad, expected_error=Err.TIMESTAMP_TOO_FAR_IN_FUTURE)
return None
await _validate_and_add_block(b, blocks[-1])
@pytest.mark.asyncio
async def test_height(self, empty_blockchain, bt):