Skip to content

Commit f60e49d

Browse files
committed
Merge pull request #3694 from gavinandresen/vfspent
Remove CWalletTx::vfSpent
2 parents 68c97fe + 93a18a3 commit f60e49d

15 files changed

+356
-362
lines changed

qa/rpc-tests/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
Regression tests of RPC interface
22
=================================
33

4-
wallet.sh : Exercise wallet send/receive code.
4+
Bash scripts that use the RPC interface and command-line bitcoin-cli to test
5+
full functionality in -regtest mode.
56

6-
walletbackup.sh : Exercise wallet backup / dump / import
7+
wallet.sh : Exercise wallet send/receive code.
78

89
txnmall.sh : Test proper accounting of malleable transactions
910

qa/rpc-tests/conflictedbalance.sh

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env bash
2+
3+
# Test marking of spent outputs
4+
5+
# Create a transaction graph with four transactions,
6+
# A/B/C/D
7+
# C spends A
8+
# D spends B and C
9+
10+
# Then simulate C being mutated, to create C'
11+
# that is mined.
12+
# A is still (correctly) considered spent.
13+
# B should be treated as unspent
14+
15+
if [ $# -lt 1 ]; then
16+
echo "Usage: $0 path_to_binaries"
17+
echo "e.g. $0 ../../src"
18+
exit 1
19+
fi
20+
21+
set -f
22+
23+
BITCOIND=${1}/bitcoind
24+
CLI=${1}/bitcoin-cli
25+
26+
DIR="${BASH_SOURCE%/*}"
27+
SENDANDWAIT="${DIR}/send.sh"
28+
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
29+
. "$DIR/util.sh"
30+
31+
D=$(mktemp -d test.XXXXX)
32+
33+
# Two nodes; one will play the part of merchant, the
34+
# other an evil transaction-mutating miner.
35+
36+
D1=${D}/node1
37+
CreateDataDir $D1 port=11000 rpcport=11001
38+
B1ARGS="-datadir=$D1 -debug=mempool"
39+
$BITCOIND $B1ARGS &
40+
B1PID=$!
41+
42+
D2=${D}/node2
43+
CreateDataDir $D2 port=11010 rpcport=11011
44+
B2ARGS="-datadir=$D2 -debug=mempool"
45+
$BITCOIND $B2ARGS &
46+
B2PID=$!
47+
48+
# Wait until all four nodes are at the same block number
49+
function WaitBlocks {
50+
while :
51+
do
52+
sleep 1
53+
declare -i BLOCKS1=$( GetBlocks $B1ARGS )
54+
declare -i BLOCKS2=$( GetBlocks $B2ARGS )
55+
if (( BLOCKS1 == BLOCKS2 ))
56+
then
57+
break
58+
fi
59+
done
60+
}
61+
62+
# Wait until node has $N peers
63+
function WaitPeers {
64+
while :
65+
do
66+
declare -i PEERS=$( $CLI $1 getconnectioncount )
67+
if (( PEERS == "$2" ))
68+
then
69+
break
70+
fi
71+
sleep 1
72+
done
73+
}
74+
75+
echo "Generating test blockchain..."
76+
77+
# Start with B2 connected to B1:
78+
$CLI $B2ARGS addnode 127.0.0.1:11000 onetry
79+
WaitPeers "$B1ARGS" 1
80+
81+
# 2 block, 50 XBT each == 100 XBT
82+
# These will be transactions "A" and "B"
83+
$CLI $B1ARGS setgenerate true 2
84+
85+
WaitBlocks
86+
# 100 blocks, 0 mature == 0 XBT
87+
$CLI $B2ARGS setgenerate true 100
88+
WaitBlocks
89+
90+
CheckBalance "$B1ARGS" 100
91+
CheckBalance "$B2ARGS" 0
92+
93+
# restart B2 with no connection
94+
$CLI $B2ARGS stop > /dev/null 2>&1
95+
wait $B2PID
96+
$BITCOIND $B2ARGS &
97+
B2PID=$!
98+
99+
B1ADDRESS=$( $CLI $B1ARGS getnewaddress )
100+
B2ADDRESS=$( $CLI $B2ARGS getnewaddress )
101+
102+
# Transaction C: send-to-self, spend A
103+
TXID_C=$( $CLI $B1ARGS sendtoaddress $B1ADDRESS 50.0)
104+
105+
# Transaction D: spends B and C
106+
TXID_D=$( $CLI $B1ARGS sendtoaddress $B2ADDRESS 100.0)
107+
108+
CheckBalance "$B1ARGS" 0
109+
110+
# Mutate TXID_C and add it to B2's memory pool:
111+
RAWTX_C=$( $CLI $B1ARGS getrawtransaction $TXID_C )
112+
113+
# ... mutate C to create C'
114+
L=${RAWTX_C:82:2}
115+
NEWLEN=$( printf "%x" $(( 16#$L + 1 )) )
116+
MUTATEDTX_C=${RAWTX_C:0:82}${NEWLEN}4c${RAWTX_C:84}
117+
# ... give mutated tx1 to B2:
118+
MUTATEDTXID=$( $CLI $B2ARGS sendrawtransaction $MUTATEDTX_C )
119+
120+
echo "TXID_C: " $TXID_C
121+
echo "Mutated: " $MUTATEDTXID
122+
123+
# Re-connect nodes, and have both nodes mine some blocks:
124+
$CLI $B2ARGS addnode 127.0.0.1:11000 onetry
125+
WaitPeers "$B1ARGS" 1
126+
127+
# Having B2 mine the next block puts the mutated
128+
# transaction C in the chain:
129+
$CLI $B2ARGS setgenerate true 1
130+
WaitBlocks
131+
132+
# B1 should still be able to spend 100, because D is conflicted
133+
# so does not count as a spend of B
134+
CheckBalance "$B1ARGS" 100
135+
136+
$CLI $B2ARGS stop > /dev/null 2>&1
137+
wait $B2PID
138+
$CLI $B1ARGS stop > /dev/null 2>&1
139+
wait $B1PID
140+
141+
echo "Tests successful, cleaning up"
142+
rm -rf $D
143+
exit 0

qa/rpc-tests/txnmall.sh

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
# Test block generation and basic wallet sending
3+
# Test proper accounting with malleable transactions
44

55
if [ $# -lt 1 ]; then
66
echo "Usage: $0 path_to_binaries"
@@ -35,16 +35,14 @@ B2ARGS="-datadir=$D2"
3535
$BITCOIND $B2ARGS &
3636
B2PID=$!
3737

38-
trap "kill -9 $B1PID $B2PID; rm -rf $D" EXIT
39-
40-
# Wait until all four nodes are at the same block number
38+
# Wait until both nodes are at the same block number
4139
function WaitBlocks {
4240
while :
4341
do
4442
sleep 1
45-
BLOCKS1=$( GetBlocks $B1ARGS )
46-
BLOCKS2=$( GetBlocks $B2ARGS )
47-
if (( $BLOCKS1 == $BLOCKS2 ))
43+
declare -i BLOCKS1=$( GetBlocks $B1ARGS )
44+
declare -i BLOCKS2=$( GetBlocks $B2ARGS )
45+
if (( BLOCKS1 == BLOCKS2 ))
4846
then
4947
break
5048
fi
@@ -55,15 +53,17 @@ function WaitBlocks {
5553
function WaitPeers {
5654
while :
5755
do
58-
PEERS=$( $CLI $1 getconnectioncount )
59-
if (( "$PEERS" == $2 ))
56+
declare -i PEERS=$( $CLI $1 getconnectioncount )
57+
if (( PEERS == "$2" ))
6058
then
6159
break
6260
fi
6361
sleep 1
6462
done
6563
}
6664

65+
echo "Generating test blockchain..."
66+
6767
# Start with B2 connected to B1:
6868
$CLI $B2ARGS addnode 127.0.0.1:11000 onetry
6969
WaitPeers "$B1ARGS" 1
@@ -76,29 +76,27 @@ WaitBlocks
7676
$CLI $B2ARGS setgenerate true 100
7777
WaitBlocks
7878

79-
CheckBalance $B1ARGS 50
80-
CheckBalance $B2ARGS 0
79+
CheckBalance "$B1ARGS" 50
80+
CheckBalance "$B2ARGS" 0
8181

8282
# restart B2 with no connection
8383
$CLI $B2ARGS stop > /dev/null 2>&1
8484
wait $B2PID
8585
$BITCOIND $B2ARGS &
8686
B2PID=$!
8787

88-
B2ADDRESS=$( $CLI $B2ARGS getnewaddress )
88+
B2ADDRESS=$( $CLI $B2ARGS getaccountaddress "from1" )
8989

9090
# Have B1 create two transactions; second will
9191
# spend change from first, since B1 starts with only a single
9292
# 50 bitcoin output:
93-
$CLI $B1ARGS move "" "foo" 10.0
94-
$CLI $B1ARGS move "" "bar" 10.0
93+
$CLI $B1ARGS move "" "foo" 10.0 > /dev/null
94+
$CLI $B1ARGS move "" "bar" 10.0 > /dev/null
9595
TXID1=$( $CLI $B1ARGS sendfrom foo $B2ADDRESS 1.0 0)
9696
TXID2=$( $CLI $B1ARGS sendfrom bar $B2ADDRESS 2.0 0)
9797

9898
# Mutate TXID1 and add it to B2's memory pool:
9999
RAWTX1=$( $CLI $B1ARGS getrawtransaction $TXID1 )
100-
RAWTX2=$( $CLI $B1ARGS getrawtransaction $TXID2 )
101-
# ... mutate RAWTX1:
102100
# RAWTX1 is hex-encoded, serialized transaction. So each
103101
# byte is two characters; we'll prepend the first
104102
# "push" in the scriptsig with OP_PUSHDATA1 (0x4c),
@@ -123,28 +121,28 @@ echo "TXID1: " $TXID1
123121
echo "Mutated: " $MUTATEDTXID
124122

125123
# Re-connect nodes, and have B2 mine a block
124+
# containing the mutant:
126125
$CLI $B2ARGS addnode 127.0.0.1:11000 onetry
127-
WaitPeers "$B1ARGS" 1
128-
129-
$CLI $B2ARGS setgenerate true 3
130-
WaitBlocks
131-
$CLI $B1ARGS setgenerate true 3
126+
$CLI $B2ARGS setgenerate true 1
132127
WaitBlocks
133128

129+
# B1 should have 49 BTC; the 2 BTC send is
130+
# conflicted, and should not count in
131+
# balances.
132+
CheckBalance "$B1ARGS" 49
133+
CheckBalance "$B1ARGS" 49 "*"
134+
CheckBalance "$B1ARGS" 9 "foo"
135+
CheckBalance "$B1ARGS" 10 "bar"
136+
137+
# B2 should have 51 BTC
138+
CheckBalance "$B2ARGS" 51
139+
CheckBalance "$B2ARGS" 1 "from1"
140+
134141
$CLI $B2ARGS stop > /dev/null 2>&1
135142
wait $B2PID
136143
$CLI $B1ARGS stop > /dev/null 2>&1
137144
wait $B1PID
138145

139-
trap "" EXIT
140-
141-
echo "Done, bitcoind's shut down. To rerun/poke around:"
142-
echo "${1}/bitcoind -datadir=$D1 -daemon"
143-
echo "${1}/bitcoind -datadir=$D2 -daemon -connect=127.0.0.1:11000"
144-
echo "To cleanup:"
145-
echo "killall bitcoind; rm -rf test.*"
146-
exit 0
147-
148146
echo "Tests successful, cleaning up"
149147
rm -rf $D
150148
exit 0

qa/rpc-tests/util.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ function AssertEqual {
4141

4242
# CheckBalance -datadir=... amount account minconf
4343
function CheckBalance {
44+
declare -i EXPECT="$2"
4445
B=$( $CLI $1 getbalance $3 $4 )
45-
if (( $( echo "$B == $2" | bc ) == 0 ))
46+
if (( $( echo "$B == $EXPECT" | bc ) == 0 ))
4647
then
4748
echoerr "bad balance: $B (expected $2)"
4849
exit 1
@@ -87,5 +88,5 @@ function SendRawTxn {
8788
# Use: GetBlocks <datadir>
8889
# returns number of blocks from getinfo
8990
function GetBlocks {
90-
ExtractKey blocks "$( $CLI $1 getinfo )"
91+
$CLI $1 getblockcount
9192
}

0 commit comments

Comments
 (0)