Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHIA-713] Add action_scope: WalletActionScope to all tx endpoints #18127

Merged
merged 23 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
05a7bb8
Add the concept of 'action scopes'
Quexington Jun 6, 2024
719b880
Add `WalletActionScope`
Quexington Jun 6, 2024
894ec9c
Fix CATWallet pending_change calculation
Quexington Jun 5, 2024
cd9973e
Add action_scope: WalletActionScope to all tx endpoints
Quexington May 6, 2024
3abb7ba
Add the concept of 'action scopes'
Quexington Jun 6, 2024
56230c6
pylint and test coverage
Quexington Jun 6, 2024
da718ec
add try/finally
Quexington Jun 6, 2024
7cb7860
Fix some bad merging
Quexington Jun 6, 2024
8acb86c
add try/except
Quexington Jun 6, 2024
2952287
Undo giving a variable a name
Quexington Jun 6, 2024
8f5e282
Merge branch 'quex.wallet_action_scope' into quex.fix_cat_pending_change
Quexington Jun 6, 2024
2baadfe
Fix CRCAT test
Quexington Jun 6, 2024
6aa1921
Merge branch 'quex.fix_cat_pending_change' into quex.add_action_scope…
Quexington Jun 6, 2024
6f65775
Fix trade tests
Quexington Jun 6, 2024
d6fef68
Fix cat test
Quexington Jun 6, 2024
829b9a9
Fix miscellaneous test
Quexington Jun 10, 2024
c78be1a
Fix miscellaneous test
Quexington Jun 10, 2024
0dc06f7
Fix miscellaneous test
Quexington Jun 10, 2024
1bf3f29
Add auto claim test coverage
Quexington Jun 10, 2024
c8e8527
Merge branch 'quex.auto_claim_better_test' into quex.add_action_scope…
Quexington Jun 10, 2024
64ce4a3
Merge remote-tracking branch 'origin/main' into quex.auto_claim_bette…
Quexington Jul 11, 2024
15a6a1b
Merge branch 'quex.auto_claim_better_test' into quex.add_action_scope…
Quexington Jul 12, 2024
8cf8a40
Merge remote-tracking branch 'origin/main' into quex.add_action_scope…
Quexington Jul 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 56 additions & 40 deletions chia/_tests/core/full_node/test_full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,13 @@ async def test_block_compression(self, setup_two_nodes_and_wallet, empty_blockch
await full_node_1.wait_for_wallet_synced(wallet_node=wallet_node_1, timeout=30)

# Send a transaction to mempool
[tr] = await wallet.generate_signed_transaction(
tx_size,
ph,
DEFAULT_TX_CONFIG,
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tr] = await wallet.generate_signed_transaction(
tx_size,
ph,
DEFAULT_TX_CONFIG,
action_scope,
)
[tr] = await wallet.wallet_state_manager.add_pending_transactions([tr])
await time_out_assert(
10,
Expand Down Expand Up @@ -217,11 +219,13 @@ async def check_transaction_confirmed(transaction) -> bool:
assert len((await full_node_1.get_all_full_blocks())[-1].transactions_generator_ref_list) == 0

# Send another tx
[tr] = await wallet.generate_signed_transaction(
20000,
ph,
DEFAULT_TX_CONFIG,
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tr] = await wallet.generate_signed_transaction(
20000,
ph,
DEFAULT_TX_CONFIG,
action_scope,
)
[tr] = await wallet.wallet_state_manager.add_pending_transactions([tr])
await time_out_assert(
10,
Expand Down Expand Up @@ -256,23 +260,27 @@ async def check_transaction_confirmed(transaction) -> bool:
await full_node_1.wait_for_wallet_synced(wallet_node=wallet_node_1, timeout=30)

# Send another 2 tx
[tr] = await wallet.generate_signed_transaction(
30000,
ph,
DEFAULT_TX_CONFIG,
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tr] = await wallet.generate_signed_transaction(
30000,
ph,
DEFAULT_TX_CONFIG,
action_scope,
)
[tr] = await wallet.wallet_state_manager.add_pending_transactions([tr])
await time_out_assert(
10,
full_node_2.full_node.mempool_manager.get_spendbundle,
tr.spend_bundle,
tr.name,
)
[tr] = await wallet.generate_signed_transaction(
40000,
ph,
DEFAULT_TX_CONFIG,
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tr] = await wallet.generate_signed_transaction(
40000,
ph,
DEFAULT_TX_CONFIG,
action_scope,
)
[tr] = await wallet.wallet_state_manager.add_pending_transactions([tr])
await time_out_assert(
10,
Expand All @@ -281,11 +289,13 @@ async def check_transaction_confirmed(transaction) -> bool:
tr.name,
)

[tr] = await wallet.generate_signed_transaction(
50000,
ph,
DEFAULT_TX_CONFIG,
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tr] = await wallet.generate_signed_transaction(
50000,
ph,
DEFAULT_TX_CONFIG,
action_scope,
)
[tr] = await wallet.wallet_state_manager.add_pending_transactions([tr])
await time_out_assert(
10,
Expand All @@ -294,11 +304,13 @@ async def check_transaction_confirmed(transaction) -> bool:
tr.name,
)

[tr] = await wallet.generate_signed_transaction(
3000000000000,
ph,
DEFAULT_TX_CONFIG,
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tr] = await wallet.generate_signed_transaction(
3000000000000,
ph,
DEFAULT_TX_CONFIG,
action_scope,
)
[tr] = await wallet.wallet_state_manager.add_pending_transactions([tr])
await time_out_assert(
10,
Expand All @@ -325,11 +337,13 @@ async def check_transaction_confirmed(transaction) -> bool:
assert num_blocks == 0

# Creates a standard_transaction and an anyone-can-spend tx
[tr] = await wallet.generate_signed_transaction(
30000,
Program.to(1).get_tree_hash(),
DEFAULT_TX_CONFIG,
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tr] = await wallet.generate_signed_transaction(
30000,
Program.to(1).get_tree_hash(),
DEFAULT_TX_CONFIG,
action_scope,
)
extra_spend = SpendBundle(
[
make_spend(
Expand Down Expand Up @@ -371,11 +385,13 @@ async def check_transaction_confirmed(transaction) -> bool:
assert len(all_blocks[-1].transactions_generator_ref_list) == 0

# Make a standard transaction and an anyone-can-spend transaction
[tr] = await wallet.generate_signed_transaction(
30000,
Program.to(1).get_tree_hash(),
DEFAULT_TX_CONFIG,
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tr] = await wallet.generate_signed_transaction(
30000,
Program.to(1).get_tree_hash(),
DEFAULT_TX_CONFIG,
action_scope,
)
extra_spend = SpendBundle(
[
make_spend(
Expand Down
14 changes: 8 additions & 6 deletions chia/_tests/core/full_node/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ async def peak_height(fna: FullNodeAPI):
await time_out_assert(20, peak_height, num_blocks, full_node_api_1)
await time_out_assert(20, peak_height, num_blocks, full_node_api_2)

[tx] = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, ph1, DEFAULT_TX_CONFIG, 0
)
async with wallet_0.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx] = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, ph1, DEFAULT_TX_CONFIG, action_scope, 0
)
[tx] = await wallet_0.wallet_state_manager.add_pending_transactions([tx])

await time_out_assert(
Expand Down Expand Up @@ -154,9 +155,10 @@ async def test_mempool_tx_sync(self, three_nodes_two_wallets, self_hostname, see
)
await time_out_assert(20, wallet_0.wallet_state_manager.main_wallet.get_confirmed_balance, funds)

[tx] = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, bytes32.random(seeded_random), DEFAULT_TX_CONFIG, 0
)
async with wallet_0.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx] = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, bytes32.random(seeded_random), DEFAULT_TX_CONFIG, action_scope, 0
)
[tx] = await wallet_0.wallet_state_manager.add_pending_transactions([tx])

await time_out_assert(
Expand Down
69 changes: 41 additions & 28 deletions chia/_tests/core/mempool/test_mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1622,9 +1622,10 @@ async def make_setup_and_coins(
for _ in range(2):
await farm_a_block(full_node_api, wallet_node, ph)
other_recipients = [Payment(puzzle_hash=p, amount=uint64(200), memos=[]) for p in phs[1:]]
[tx] = await wallet.generate_signed_transaction(
uint64(200), phs[0], DEFAULT_TX_CONFIG, primaries=other_recipients
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx] = await wallet.generate_signed_transaction(
uint64(200), phs[0], DEFAULT_TX_CONFIG, action_scope, primaries=other_recipients
)
[tx], _ = await wallet.wallet_state_manager.sign_transactions([tx])
assert tx.spend_bundle is not None
await send_to_mempool(full_node_api, tx.spend_bundle)
Expand All @@ -1640,9 +1641,16 @@ async def make_setup_and_coins(
wallet, coins, ph = await make_setup_and_coins(full_node_api, wallet_node)

# Make sure spending AB then BC would generate a conflict for the latter
[tx_a] = await wallet.generate_signed_transaction(uint64(30), ph, DEFAULT_TX_CONFIG, coins={coins[0].coin})
[tx_b] = await wallet.generate_signed_transaction(uint64(30), ph, DEFAULT_TX_CONFIG, coins={coins[1].coin})
[tx_c] = await wallet.generate_signed_transaction(uint64(30), ph, DEFAULT_TX_CONFIG, coins={coins[2].coin})
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx_a] = await wallet.generate_signed_transaction(
uint64(30), ph, DEFAULT_TX_CONFIG, action_scope, coins={coins[0].coin}
)
[tx_b] = await wallet.generate_signed_transaction(
uint64(30), ph, DEFAULT_TX_CONFIG, action_scope, coins={coins[1].coin}
)
[tx_c] = await wallet.generate_signed_transaction(
uint64(30), ph, DEFAULT_TX_CONFIG, action_scope, coins={coins[2].coin}
)
[tx_a, tx_b, tx_c], _ = await wallet.wallet_state_manager.sign_transactions([tx_a, tx_b, tx_c])
assert tx_a.spend_bundle is not None
assert tx_b.spend_bundle is not None
Expand All @@ -1657,9 +1665,10 @@ async def make_setup_and_coins(
# Make sure DE and EF would aggregate on E when E is eligible for deduplication

# Create a coin with the identity puzzle hash
[tx] = await wallet.generate_signed_transaction(
uint64(200), IDENTITY_PUZZLE_HASH, DEFAULT_TX_CONFIG, coins={coins[3].coin}
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx] = await wallet.generate_signed_transaction(
uint64(200), IDENTITY_PUZZLE_HASH, DEFAULT_TX_CONFIG, action_scope, coins={coins[3].coin}
)
[tx], _ = await wallet.wallet_state_manager.sign_transactions([tx])
assert tx.spend_bundle is not None
await send_to_mempool(full_node_api, tx.spend_bundle)
Expand All @@ -1682,22 +1691,25 @@ async def make_setup_and_coins(
message = b"Identical spend aggregation test"
e_announcement = AssertCoinAnnouncement(asserted_id=e_coin_id, asserted_msg=message)
# Create transactions D and F that consume an announcement created by E
[tx_d] = await wallet.generate_signed_transaction(
uint64(100),
ph,
DEFAULT_TX_CONFIG,
fee=uint64(0),
coins={coins[4].coin},
extra_conditions=(e_announcement,),
)
[tx_f] = await wallet.generate_signed_transaction(
uint64(150),
ph,
DEFAULT_TX_CONFIG,
fee=uint64(0),
coins={coins[5].coin},
extra_conditions=(e_announcement,),
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx_d] = await wallet.generate_signed_transaction(
uint64(100),
ph,
DEFAULT_TX_CONFIG,
action_scope,
fee=uint64(0),
coins={coins[4].coin},
extra_conditions=(e_announcement,),
)
[tx_f] = await wallet.generate_signed_transaction(
uint64(150),
ph,
DEFAULT_TX_CONFIG,
action_scope,
fee=uint64(0),
coins={coins[5].coin},
extra_conditions=(e_announcement,),
)
[tx_d, tx_f], _ = await wallet.wallet_state_manager.sign_transactions([tx_d, tx_f])
assert tx_d.spend_bundle is not None
assert tx_f.spend_bundle is not None
Expand All @@ -1724,9 +1736,10 @@ async def make_setup_and_coins(
sb_e2 = spend_bundle_from_conditions(conditions, e_coin)
g_coin = coins[6].coin
g_coin_id = g_coin.name()
[tx_g] = await wallet.generate_signed_transaction(
uint64(13), ph, DEFAULT_TX_CONFIG, coins={g_coin}, extra_conditions=(e_announcement,)
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx_g] = await wallet.generate_signed_transaction(
uint64(13), ph, DEFAULT_TX_CONFIG, action_scope, coins={g_coin}, extra_conditions=(e_announcement,)
)
[tx_g], _ = await wallet.wallet_state_manager.sign_transactions([tx_g])
assert tx_g.spend_bundle is not None
sb_e2g = SpendBundle.aggregate([sb_e2, tx_g.spend_bundle])
Expand Down
5 changes: 4 additions & 1 deletion chia/_tests/core/mempool/test_mempool_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ async def test_mempool_update_performance(
await time_out_assert(30, wallet_balance_at_least, True, wallet_node, send_amount + fee_amount)

ph = await wallet.get_new_puzzlehash()
[big_transaction] = await wallet.generate_signed_transaction(send_amount, ph, DEFAULT_TX_CONFIG, fee_amount)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[big_transaction] = await wallet.generate_signed_transaction(
send_amount, ph, DEFAULT_TX_CONFIG, action_scope, fee_amount
)
[big_transaction], _ = await wallet.wallet_state_manager.sign_transactions([big_transaction])
assert big_transaction.spend_bundle is not None
status, err = await full_node.add_transaction(
Expand Down
2 changes: 2 additions & 0 deletions chia/_tests/pools/test_pool_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ async def status_is_farming_to_pool() -> bool:
assert pw_info.current.pool_url == "https://pool-a.org"
assert pw_info.current.relative_lock_height == 5

await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)

join_pool_tx: TransactionRecord = (
await client.pw_join_pool(
wallet_id,
Expand Down
52 changes: 29 additions & 23 deletions chia/_tests/simulation/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ async def test_simulator_auto_farm_and_get_coins(

await time_out_assert(10, wallet.get_confirmed_balance, funds)
await time_out_assert(5, wallet.get_unconfirmed_balance, funds)
[tx] = await wallet.generate_signed_transaction(
uint64(10),
await wallet_node_2.wallet_state_manager.main_wallet.get_new_puzzlehash(),
DEFAULT_TX_CONFIG,
uint64(0),
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx] = await wallet.generate_signed_transaction(
uint64(10),
await wallet_node_2.wallet_state_manager.main_wallet.get_new_puzzlehash(),
DEFAULT_TX_CONFIG,
action_scope,
uint64(0),
)
[tx] = await wallet.wallet_state_manager.add_pending_transactions([tx])
# wait till out of mempool
await time_out_assert(10, full_node_api.full_node.mempool_manager.get_spendbundle, None, tx.name)
Expand Down Expand Up @@ -387,12 +389,14 @@ async def test_wait_transaction_records_entered_mempool(

# repeating just to try to expose any flakiness
for coin in coins:
[tx] = await wallet.generate_signed_transaction(
amount=uint64(tx_amount),
puzzle_hash=await wallet_node.wallet_state_manager.main_wallet.get_new_puzzlehash(),
tx_config=DEFAULT_TX_CONFIG,
coins={coin},
)
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
[tx] = await wallet.generate_signed_transaction(
amount=uint64(tx_amount),
puzzle_hash=await wallet_node.wallet_state_manager.main_wallet.get_new_puzzlehash(),
tx_config=DEFAULT_TX_CONFIG,
action_scope=action_scope,
coins={coin},
)
[tx] = await wallet.wallet_state_manager.add_pending_transactions([tx])

await full_node_api.wait_transaction_records_entered_mempool(records=[tx])
Expand Down Expand Up @@ -432,17 +436,19 @@ async def test_process_transactions(
# repeating just to try to expose any flakiness
for repeat in range(repeats):
coins = [next(coins_iter) for _ in range(tx_per_repeat)]
transactions = [
(
await wallet.generate_signed_transaction(
amount=uint64(tx_amount),
puzzle_hash=await wallet_node.wallet_state_manager.main_wallet.get_new_puzzlehash(),
tx_config=DEFAULT_TX_CONFIG,
coins={coin},
)
)[0]
for coin in coins
]
async with wallet.wallet_state_manager.new_action_scope(push=False) as action_scope:
transactions = [
(
await wallet.generate_signed_transaction(
amount=uint64(tx_amount),
puzzle_hash=await wallet_node.wallet_state_manager.main_wallet.get_new_puzzlehash(),
tx_config=DEFAULT_TX_CONFIG,
action_scope=action_scope,
coins={coin},
)
)[0]
for coin in coins
]
for tx in transactions:
assert tx.spend_bundle is not None, "the above created transaction is missing the expected spend bundle"

Expand Down
Loading
Loading