Skip to content

Commit

Permalink
Merge commit 'f9b7ddcfcf50b8a0cf7a39a9c9f5f53214702319' into checkpoi…
Browse files Browse the repository at this point in the history
…nt/main_from_release_2.5.0_f9b7ddcfcf50b8a0cf7a39a9c9f5f53214702319
  • Loading branch information
AmineKhaldi committed Dec 6, 2024
2 parents 005d656 + f9b7ddc commit 68f230a
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 14 deletions.
8 changes: 4 additions & 4 deletions chia/_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ def get_keychain():
class ConsensusMode(ComparableEnum):
PLAIN = 0
HARD_FORK_2_0 = 1
SOFT_FORK_5 = 2
SOFT_FORK_6 = 2


@pytest.fixture(
scope="session",
params=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0, ConsensusMode.SOFT_FORK_5],
params=[ConsensusMode.PLAIN, ConsensusMode.HARD_FORK_2_0, ConsensusMode.SOFT_FORK_6],
)
def consensus_mode(request):
return request.param
Expand All @@ -216,7 +216,7 @@ def blockchain_constants(consensus_mode: ConsensusMode) -> ConsensusConstants:
PLOT_FILTER_64_HEIGHT=uint32(15),
PLOT_FILTER_32_HEIGHT=uint32(20),
)
if consensus_mode >= ConsensusMode.SOFT_FORK_5:
if consensus_mode >= ConsensusMode.SOFT_FORK_6:
ret = ret.replace(
SOFT_FORK6_HEIGHT=uint32(2),
)
Expand Down Expand Up @@ -267,7 +267,7 @@ def db_version(request) -> int:
return request.param


SOFTFORK_HEIGHTS = [1000000, 5496000, 5496100, 5716000, 5940000]
SOFTFORK_HEIGHTS = [1000000, 5496000, 5496100, 5716000, 6800000]


@pytest.fixture(scope="function", params=SOFTFORK_HEIGHTS)
Expand Down
78 changes: 77 additions & 1 deletion chia/_tests/core/mempool/test_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from typing import Callable, Optional

import pytest
from chia_rs import G1Element, G2Element
from chia_rs import G1Element, G2Element, get_flags_for_height_and_constants
from clvm.casts import int_to_bytes
from clvm_tools import binutils
from clvm_tools.binutils import assemble

from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block
from chia._tests.connection_utils import add_dummy_connection, connect_and_get_peer
Expand All @@ -28,6 +29,7 @@
from chia._tests.util.time_out_assert import time_out_assert
from chia.consensus.condition_costs import ConditionCost
from chia.consensus.cost_calculator import NPCResult
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.full_node.bitcoin_fee_estimator import create_bitcoin_fee_estimator
from chia.full_node.fee_estimation import EmptyMempoolInfo, MempoolInfo
from chia.full_node.full_node_api import FullNodeAPI
Expand Down Expand Up @@ -3186,3 +3188,77 @@ def test_get_puzzle_and_solution_for_coin_failure() -> None:
ValueError, match=f"Failed to get puzzle and solution for coin {TEST_COIN}, error: \\('coin not found', '80'\\)"
):
get_puzzle_and_solution_for_coin(BlockGenerator(SerializedProgram.to(None), []), TEST_COIN, 0, test_constants)


# TODO: import this from chia_rs once we bump the version we depend on
ENABLE_KECCAK = 0x200
ENABLE_KECCAK_OPS_OUTSIDE_GUARD = 0x100


def test_flags_for_height() -> None:
# the keccak operator is supposed to be enabled at soft-fork 6 height
flags = get_flags_for_height_and_constants(DEFAULT_CONSTANTS.SOFT_FORK6_HEIGHT, DEFAULT_CONSTANTS)
print(f"{flags:x}")
assert (flags & ENABLE_KECCAK) != 0

flags = get_flags_for_height_and_constants(DEFAULT_CONSTANTS.SOFT_FORK6_HEIGHT - 1, DEFAULT_CONSTANTS)
print(f"{flags:x}")
assert (flags & ENABLE_KECCAK) == 0


def test_keccak() -> None:
# the keccak operator is 62. The assemble() function doesn't support it
# (yet)

# keccak256 is available when the softfork has activated
keccak_prg = Program.to(
assemble(
"(softfork (q . 1134) (q . 1) (q a (i "
"(= "
'(62 (q . "foobar"))'
"(q . 0x38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e))"
"(q . 0) (q x)) (q . ())) (q . ()))"
)
)

cost, ret = keccak_prg.run_with_flags(1215, ENABLE_KECCAK, [])
assert cost == 1215
assert ret.atom == b""

# keccak is ignored when the softfork has not activated
cost, ret = keccak_prg.run_with_flags(1215, 0, [])
assert cost == 1215
assert ret.atom == b""

# make sure keccak is actually executed, by comparing with the wrong output
keccak_prg = Program.to(
assemble(
"(softfork (q . 1134) (q . 1) (q a (i "
'(= (62 (q . "foobar")) '
"(q . 0x58d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e))"
"(q . 0) (q x)) (q . ())) (q . ()))"
)
)
with pytest.raises(ValueError, match="clvm raise"):
keccak_prg.run_with_flags(1215, ENABLE_KECCAK, [])

# keccak is ignored when the softfork has not activated
cost, ret = keccak_prg.run_with_flags(1215, 0, [])
assert cost == 1215
assert ret.atom == b""

# === HARD FORK ===
# new operators *outside* the softfork guard
# keccak256 is available outside the guard with the appropriate flag
keccak_prg = Program.to(
assemble(
"(a (i (= "
'(62 (q . "foobar")) '
"(q . 0x38d18acb67d25c8bb9942764b62f18e17054f66a817bd4295423adf9ed98873e)) "
"(q . 0) (q x)) (q . ()))"
)
)

cost, ret = keccak_prg.run_with_flags(994, ENABLE_KECCAK | ENABLE_KECCAK_OPS_OUTSIDE_GUARD, [])
assert cost == 994
assert ret.atom == b""
2 changes: 1 addition & 1 deletion chia/_tests/util/test_replace_str_to_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
MAX_GENERATOR_SIZE=uint32(1000000),
MAX_GENERATOR_REF_LIST_SIZE=uint32(512),
POOL_SUB_SLOT_ITERS=uint64(37600000000),
SOFT_FORK6_HEIGHT=uint32(9999999),
SOFT_FORK6_HEIGHT=uint32(6800000),
HARD_FORK_HEIGHT=uint32(5496000),
PLOT_FILTER_128_HEIGHT=uint32(10542000),
PLOT_FILTER_64_HEIGHT=uint32(15592000),
Expand Down
2 changes: 1 addition & 1 deletion chia/_tests/util/test_testnet_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_testnet11() -> None:
overrides: dict[str, Any] = {}
update_testnet_overrides("testnet11", overrides)
assert overrides == {
"SOFT_FORK6_HEIGHT": 9999999,
"SOFT_FORK6_HEIGHT": 2000000,
}


Expand Down
6 changes: 3 additions & 3 deletions chia/cmds/sim_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ def create_chia_directory(
# get fork heights then write back to config
if "HARD_FORK_HEIGHT" not in sim_config: # this meh code is done so that we also write to the config file.
sim_config["HARD_FORK_HEIGHT"] = 0
if "SOFT_FORK5_HEIGHT" not in sim_config:
sim_config["SOFT_FORK5_HEIGHT"] = 0
if "SOFT_FORK6_HEIGHT" not in sim_config:
sim_config["SOFT_FORK6_HEIGHT"] = 0
simulator_consts["HARD_FORK_HEIGHT"] = sim_config["HARD_FORK_HEIGHT"]
simulator_consts["SOFT_FORK5_HEIGHT"] = sim_config["SOFT_FORK5_HEIGHT"]
simulator_consts["SOFT_FORK6_HEIGHT"] = sim_config["SOFT_FORK6_HEIGHT"]

# save config and return the config
save_config(chia_root, "config.yaml", config)
Expand Down
4 changes: 2 additions & 2 deletions chia/consensus/default_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
MAX_GENERATOR_SIZE=uint32(1000000),
MAX_GENERATOR_REF_LIST_SIZE=uint32(512), # Number of references allowed in the block generator ref list
POOL_SUB_SLOT_ITERS=uint64(37600000000), # iters limit * NUM_SPS
SOFT_FORK6_HEIGHT=uint32(9999999), # temporary placeholder
SOFT_FORK6_HEIGHT=uint32(6800000),
# June 2024
HARD_FORK_HEIGHT=uint32(5496000),
# June 2027
Expand All @@ -86,4 +86,4 @@
def update_testnet_overrides(network_id: str, overrides: dict[str, Any]) -> None:
if network_id == "testnet11":
if "SOFT_FORK6_HEIGHT" not in overrides:
overrides["SOFT_FORK6_HEIGHT"] = 9999999 # temporary placeholder
overrides["SOFT_FORK6_HEIGHT"] = 2000000
4 changes: 2 additions & 2 deletions chia/util/initial-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ network_overrides: &network_overrides
SUB_SLOT_ITERS_STARTING: 67108864
# Forks activated from the beginning on this network
HARD_FORK_HEIGHT: 0
SOFT_FORK5_HEIGHT: 1340000
SOFT_FORK6_HEIGHT: 2000000
PLOT_FILTER_128_HEIGHT: 6029568
PLOT_FILTER_64_HEIGHT: 11075328
PLOT_FILTER_32_HEIGHT: 16121088
Expand Down Expand Up @@ -686,4 +686,4 @@ simulator:

# Fork Settings
HARD_FORK_HEIGHT: 0
SOFT_FORK5_HEIGHT: 0
SOFT_FORK6_HEIGHT: 0

0 comments on commit 68f230a

Please sign in to comment.