Skip to content

Commit

Permalink
WIP: test, automatically abandon txs during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
furszy committed Jan 31, 2025
1 parent eeaa308 commit be9f014
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions test/functional/wallet_reorgsrestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ def test_automatic_abandon_during_startup(self):
# part of the best chain.
# TODO: need to also verify that any descendant of this coinbase transaction is also marked as abandoned..
# TODO: The code to fix this is to copy paste AddToWallet into LoadToWallet
# TODO: hmm, thinking further about what was doing this morning..
# After chain replacement, because the coinbase tx is not marked abandoned during startup, their descendants
# will not be marked as abandoned neither.. so the wallet will continue broadcasting them over the network.
# Which will fill all the connected peers mempool for no reason because the node will not broadcast the parent
# (because it is a coinbase tx)
##########################################################################################################
# Sync nodes for the coming test and assert all are at the same block
for i, j in [(0, 1), (1, 2), (2, 0)]:
Expand All @@ -56,12 +61,16 @@ def test_automatic_abandon_during_startup(self):
self.generatetoaddress(self.nodes[0], 1, wallet0.getnewaddress(), sync_fun=self.no_op)
node0_coinbase_tx_hash = wallet0.getblock(wallet0.getbestblockhash(), verbose=1)['tx'][0]

# Mine 100 blocks on top to mature the coinbase and create a descendant
self.generate(self.nodes[0], 101, sync_fun=self.no_op)
# Make descendant, send-to-self
descendant_tx_id = wallet0.sendtoaddress(wallet0.getnewaddress(), 1)

# Verify balance is greater than 0.
wallet0.syncwithvalidationinterfacequeue()
assert(wallet0.getbalances()['mine']['immature'] > 0)
assert(wallet0.getbalances()['mine']['trusted'] > 0)

# Now create another block in node1 at the same tip as the one we just created for node0
# This will be used to replace the node0 chain later.
# Now create a fork in node1. This will be used to replace node0's chain later.
self.nodes[1].createwallet(wallet_name="w1", load_on_startup=True)
wallet1 = self.nodes[1].get_wallet_rpc("w1")
self.generatetoaddress(self.nodes[1], 1, wallet1.getnewaddress(), sync_fun=self.no_op)
Expand All @@ -87,10 +96,10 @@ def test_automatic_abandon_during_startup(self):

# Verify the coinbase tx was marked as abandoned and balance correctly computed
assert_equal(wallet0.gettransaction(node0_coinbase_tx_hash)['details'][0]['abandoned'], True)
assert(wallet0.getbalances()['mine']['immature'] == 0)
assert(wallet0.getbalances()['mine']['trusted'] == 0)
# Verify the coinbase descendant was also marked as abandoned
assert_equal(wallet0.gettransaction(descendant_tx_id)['details'][0]['abandoned'], True)

# TODO: need to also verify that any descendant of this coinbase transaction is also marked as abandoned..
# TODO: The code to fix this is to copy paste AddToWallet into LoadToWallet

def run_test(self):
# Send a tx from which to conflict outputs later
Expand Down

0 comments on commit be9f014

Please sign in to comment.