Skip to content

Commit 5d3fd3f

Browse files
authored
catchup: into long_lived/datalayer_merkle_blob from main @ e81b213 (#19614)
Source hash: e81b213 Remaining commits: 0
2 parents 7bd9668 + 1a66185 commit 5d3fd3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+890
-332
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.github/**/* @Chia-Network/actions-reviewers
33
/PRETTY_GOOD_PRACTICES.md @altendky @Chia-Network/required-reviewers
44
/tests/ether.py @altendky @Chia-Network/required-reviewers
5+
/pyproject.toml @altendky @Chia-Network/required-reviewers

chia/_tests/blockchain/blockchain_test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
from chia_rs import FullBlock, SpendBundleConditions
66
from chia_rs.sized_ints import uint32, uint64
77

8+
from chia.consensus.augmented_chain import AugmentedBlockchain
89
from chia.consensus.block_body_validation import ForkInfo
910
from chia.consensus.blockchain import AddBlockResult, Blockchain
1011
from chia.consensus.difficulty_adjustment import get_next_sub_slot_iters_and_difficulty
1112
from chia.consensus.multiprocess_validation import PreValidationResult, pre_validate_block
1213
from chia.types.validation_state import ValidationState
13-
from chia.util.augmented_chain import AugmentedBlockchain
1414
from chia.util.errors import Err
1515

1616

chia/_tests/blockchain/test_augmented_chain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
from chia._tests.blockchain.blockchain_test_utils import _validate_and_add_block
1212
from chia._tests.util.blockchain import create_blockchain
13+
from chia.consensus.augmented_chain import AugmentedBlockchain
1314
from chia.simulator.block_tools import BlockTools
14-
from chia.util.augmented_chain import AugmentedBlockchain
1515
from chia.util.errors import Err
1616

1717

chia/_tests/blockchain/test_blockchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from chia._tests.conftest import ConsensusMode
3838
from chia._tests.util.blockchain import create_blockchain
3939
from chia._tests.util.get_name_puzzle_conditions import get_name_puzzle_conditions
40+
from chia.consensus.augmented_chain import AugmentedBlockchain
4041
from chia.consensus.block_body_validation import ForkInfo
4142
from chia.consensus.block_header_validation import validate_finished_header_block
4243
from chia.consensus.block_rewards import calculate_base_farmer_reward
@@ -58,7 +59,6 @@
5859
from chia.types.condition_with_args import ConditionWithArgs
5960
from chia.types.generator_types import BlockGenerator
6061
from chia.types.validation_state import ValidationState
61-
from chia.util.augmented_chain import AugmentedBlockchain
6262
from chia.util.errors import Err
6363
from chia.util.generator_tools import get_block_header
6464
from chia.util.hash import std_hash

chia/_tests/blockchain/test_blockchain_transactions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
from chia.simulator.wallet_tools import WalletTool
2020
from chia.types.condition_opcodes import ConditionOpcode
2121
from chia.types.condition_with_args import ConditionWithArgs
22-
from chia.types.spend_bundle import estimate_fees
2322
from chia.util.errors import Err
2423
from chia.wallet.conditions import AssertCoinAnnouncement, AssertPuzzleAnnouncement
24+
from chia.wallet.estimate_fees import estimate_fees
2525

2626
BURN_PUZZLE_HASH = bytes32(b"0" * 32)
2727

chia/_tests/clvm/test_spend_sim.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
from chia._tests.util.spend_sim import sim_and_client
88
from chia.types.blockchain_format.program import Program
9-
from chia.types.coin_spend import compute_additions, make_spend
9+
from chia.types.coin_spend import make_spend
1010
from chia.types.condition_opcodes import ConditionOpcode
11+
from chia.wallet.util.compute_additions import compute_additions
1112

1213

1314
@pytest.mark.anyio

chia/_tests/core/full_node/test_full_node.py

Lines changed: 113 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from chia._tests.util.misc import wallet_height_at_least
4141
from chia._tests.util.setup_nodes import OldSimulatorsAndWallets, SimulatorsAndWalletsServices
4242
from chia._tests.util.time_out_assert import time_out_assert, time_out_assert_custom_interval, time_out_messages
43+
from chia.consensus.augmented_chain import AugmentedBlockchain
4344
from chia.consensus.block_body_validation import ForkInfo
4445
from chia.consensus.blockchain import Blockchain
4546
from chia.consensus.get_block_challenge import get_block_challenge
@@ -91,15 +92,14 @@
9192
from chia.types.condition_with_args import ConditionWithArgs
9293
from chia.types.mempool_inclusion_status import MempoolInclusionStatus
9394
from chia.types.peer_info import PeerInfo, TimestampedPeerInfo
94-
from chia.types.spend_bundle import estimate_fees
9595
from chia.types.validation_state import ValidationState
96-
from chia.util.augmented_chain import AugmentedBlockchain
9796
from chia.util.errors import ConsensusError, Err
9897
from chia.util.hash import std_hash
9998
from chia.util.limited_semaphore import LimitedSemaphore
10099
from chia.util.recursive_replace import recursive_replace
101100
from chia.util.task_referencer import create_referenced_task
102101
from chia.util.vdf_prover import get_vdf_info_and_proof
102+
from chia.wallet.estimate_fees import estimate_fees
103103
from chia.wallet.transaction_record import TransactionRecord
104104
from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG
105105
from chia.wallet.wallet_node import WalletNode
@@ -2995,6 +2995,117 @@ async def test_declare_proof_of_space_overflow(
29952995
assert full_node_api.full_node.blockchain.get_peak_height() == block.height
29962996

29972997

2998+
@pytest.mark.anyio
2999+
async def test_add_unfinished_block_with_generator_refs(
3000+
wallet_nodes: tuple[
3001+
FullNodeSimulator, FullNodeSimulator, ChiaServer, ChiaServer, WalletTool, WalletTool, BlockTools
3002+
],
3003+
) -> None:
3004+
"""
3005+
Robustly test add_unfinished_block, including generator refs and edge cases.
3006+
Assert block height after each added block.
3007+
"""
3008+
full_node_1, _, _, _, wallet, wallet_receiver, bt = wallet_nodes
3009+
coinbase_puzzlehash = wallet.get_new_puzzlehash()
3010+
blocks = bt.get_consecutive_blocks(
3011+
5, block_list_input=[], guarantee_transaction_block=True, farmer_reward_puzzle_hash=coinbase_puzzlehash
3012+
)
3013+
for i in range(3):
3014+
blocks = bt.get_consecutive_blocks(
3015+
1,
3016+
block_list_input=blocks,
3017+
guarantee_transaction_block=True,
3018+
transaction_data=wallet.generate_signed_transaction(
3019+
uint64(1000),
3020+
wallet_receiver.get_new_puzzlehash(),
3021+
blocks[-3].get_included_reward_coins()[0],
3022+
),
3023+
block_refs=[blocks[-1].height, blocks[-2].height],
3024+
)
3025+
3026+
for idx, block in enumerate(blocks[:-1]):
3027+
await full_node_1.full_node.add_block(block)
3028+
# Assert block height after each add
3029+
peak = full_node_1.full_node.blockchain.get_peak()
3030+
assert peak is not None and peak.height == blocks[-2].height
3031+
block = blocks[-1]
3032+
unf = unfinished_from_full_block(block)
3033+
3034+
# Test with missing generator ref (should raise ConsensusError)
3035+
bad_refs = [uint32(9999999)]
3036+
unf_bad = unf.replace(transactions_generator_ref_list=bad_refs)
3037+
with pytest.raises(Exception) as excinfo:
3038+
await full_node_1.full_node.add_unfinished_block(unf_bad, None)
3039+
assert excinfo.value.args[0] == Err.GENERATOR_REF_HAS_NO_GENERATOR
3040+
3041+
unf_no_gen = unf.replace(transactions_generator_ref_list=bad_refs, transactions_generator=None)
3042+
with pytest.raises(Exception) as excinfo:
3043+
await full_node_1.full_node.add_unfinished_block(unf_no_gen, None)
3044+
assert isinstance(excinfo.value, ConsensusError)
3045+
assert excinfo.value.code == Err.INVALID_TRANSACTIONS_GENERATOR_HASH
3046+
3047+
# Duplicate generator refs (should raise ConsensusError or be rejected)
3048+
dup_ref = blocks[-2].height
3049+
unf_dup_refs = unf.replace(transactions_generator_ref_list=[dup_ref, dup_ref])
3050+
with pytest.raises(Exception) as excinfo:
3051+
await full_node_1.full_node.add_unfinished_block(unf_dup_refs, None)
3052+
assert isinstance(excinfo.value, ConsensusError)
3053+
assert excinfo.value.code == Err.INVALID_TRANSACTIONS_GENERATOR_REFS_ROOT
3054+
3055+
# ref block with no generator
3056+
unf_bad_ref = unf.replace(transactions_generator_ref_list=[uint32(2)])
3057+
with pytest.raises(Exception) as excinfo:
3058+
await full_node_1.full_node.add_unfinished_block(unf_bad_ref, None)
3059+
assert excinfo.value.args[0] == Err.GENERATOR_REF_HAS_NO_GENERATOR
3060+
3061+
# Generator ref points to block not yet in store (simulate by using a future height)
3062+
unf_future_ref = unf.replace(transactions_generator_ref_list=[uint32(blocks[-1].height + 1000)])
3063+
with pytest.raises(Exception) as excinfo:
3064+
await full_node_1.full_node.add_unfinished_block(unf_future_ref, None)
3065+
assert excinfo.value.args[0] == Err.GENERATOR_REF_HAS_NO_GENERATOR
3066+
3067+
# Generator ref points to itself
3068+
unf_self_ref = unf.replace(transactions_generator_ref_list=[block.height])
3069+
# Should raise ConsensusError or be rejected
3070+
with pytest.raises(Exception) as excinfo:
3071+
await full_node_1.full_node.add_unfinished_block(unf_self_ref, None)
3072+
assert excinfo.value.args[0] == Err.GENERATOR_REF_HAS_NO_GENERATOR
3073+
3074+
# unsorted Generator refs
3075+
unf_unsorted = unf.replace(transactions_generator_ref_list=[blocks[-2].height, blocks[-1].height])
3076+
with pytest.raises(Exception) as excinfo:
3077+
await full_node_1.full_node.add_unfinished_block(unf_unsorted, None)
3078+
assert excinfo.value.args[0] == Err.GENERATOR_REF_HAS_NO_GENERATOR
3079+
3080+
# valid unfinished block with refs
3081+
await full_node_1.full_node.add_unfinished_block(unf, None)
3082+
assert full_node_1.full_node.full_node_store.get_unfinished_block(unf.partial_hash) is not None
3083+
assert full_node_1.full_node.full_node_store.seen_unfinished_block(unf.get_hash())
3084+
3085+
# Test disconnected block
3086+
fork_blocks = blocks[:-3]
3087+
for i in range(3):
3088+
# Add a block with a transaction
3089+
fork_blocks = bt.get_consecutive_blocks(
3090+
1,
3091+
block_list_input=fork_blocks,
3092+
guarantee_transaction_block=True,
3093+
transaction_data=wallet.generate_signed_transaction(
3094+
uint64(1000),
3095+
wallet_receiver.get_new_puzzlehash(),
3096+
fork_blocks[-3].get_included_reward_coins()[0],
3097+
),
3098+
min_signage_point=blocks[-1].reward_chain_block.signage_point_index + 1,
3099+
seed=b"random_seed",
3100+
block_refs=[fork_blocks[-2].height],
3101+
)
3102+
3103+
disconnected_unf = unfinished_from_full_block(fork_blocks[-1])
3104+
# Should not raise, but should not add the block either
3105+
await full_node_1.full_node.add_unfinished_block(disconnected_unf, None)
3106+
assert disconnected_unf.get_hash() not in full_node_1.full_node.full_node_store.seen_unfinished_blocks
3107+
3108+
29983109
def unfinished_from_full_block(block: FullBlock) -> UnfinishedBlock:
29993110
unfinished_block_expected = UnfinishedBlock(
30003111
block.finished_sub_slots,

chia/_tests/core/mempool/test_mempool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from chia.consensus.cost_calculator import NPCResult
4444
from chia.consensus.default_constants import DEFAULT_CONSTANTS
4545
from chia.full_node.bitcoin_fee_estimator import create_bitcoin_fee_estimator
46+
from chia.full_node.eligible_coin_spends import run_for_cost
4647
from chia.full_node.fee_estimation import EmptyMempoolInfo, MempoolInfo
4748
from chia.full_node.full_node_api import FullNodeAPI
4849
from chia.full_node.mempool import Mempool
@@ -67,16 +68,15 @@
6768
from chia.types.coin_spend import make_spend
6869
from chia.types.condition_opcodes import ConditionOpcode
6970
from chia.types.condition_with_args import ConditionWithArgs
70-
from chia.types.eligible_coin_spends import run_for_cost
7171
from chia.types.fee_rate import FeeRate
7272
from chia.types.generator_types import BlockGenerator
7373
from chia.types.mempool_inclusion_status import MempoolInclusionStatus
7474
from chia.types.mempool_item import MempoolItem, UnspentLineageInfo
75-
from chia.types.spend_bundle import estimate_fees
7675
from chia.util.errors import Err
7776
from chia.util.hash import std_hash
7877
from chia.util.recursive_replace import recursive_replace
7978
from chia.wallet.conditions import AssertCoinAnnouncement, AssertPuzzleAnnouncement
79+
from chia.wallet.estimate_fees import estimate_fees
8080

8181
BURN_PUZZLE_HASH = bytes32(b"0" * 32)
8282
BURN_PUZZLE_HASH_2 = bytes32(b"1" * 32)

0 commit comments

Comments
 (0)