Skip to content

Commit 4671fc3

Browse files
committed
1 parent 91f3073 commit 4671fc3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/functional/wallet_balance.py

+38
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,44 @@ def run_test(self):
109109

110110
self.log.info("Test getbalance and getunconfirmedbalance with unconfirmed inputs")
111111

112+
# Before `test_balance()`, we have had two nodes with a balance of 50
113+
# each and then we:
114+
#
115+
# 1) Sent 40 from node A to node B with fee 0.01
116+
# 2) Sent 60 from node B to node A with fee 0.01
117+
#
118+
# Then we check the balances:
119+
#
120+
# 1) As is
121+
# 2) With transaction 2 from above with 2x the fee
122+
#
123+
# Prior to #16766, in this situation, the node would immediately report
124+
# a balance of 30 on node B as unconfirmed and trusted.
125+
#
126+
# After #16766, we show that balance as unconfirmed.
127+
#
128+
# The balance is indeed "trusted" and "confirmed" insofar as removing
129+
# the mempool transactions would return at least that much money. But
130+
# the algorithm after #16766 marks it as unconfirmed because the 'taint'
131+
# tracking of transaction trust for summing balances doesn't consider
132+
# which inputs belong to a user. In this case, the change output in
133+
# question could be "destroyed" by replace the 1st transaction above.
134+
#
135+
# The post #16766 behavior is correct; we shouldn't be treating those
136+
# funds as confirmed. If you want to rely on that specific UTXO existing
137+
# which has given you that balance, you cannot, as a third party
138+
# spending the other input would destroy that unconfirmed.
139+
#
140+
# For example, if the test transactions were:
141+
#
142+
# 1) Sent 40 from node A to node B with fee 0.01
143+
# 2) Sent 10 from node B to node A with fee 0.01
144+
#
145+
# Then our node would report a confirmed balance of 40 + 50 - 10 = 80
146+
# BTC, which is more than would be available if transaction 1 were
147+
# replaced.
148+
149+
112150
def test_balances(*, fee_node_1=0):
113151
# getbalance without any arguments includes unconfirmed transactions, but not untrusted transactions
114152
assert_equal(self.nodes[0].getbalance(), Decimal('9.99')) # change from node 0's send

0 commit comments

Comments
 (0)