12
12
the same local address. See Issue #14210 for more info.
13
13
Therefore, this test is limited to the remaining protection criteria.
14
14
"""
15
-
16
15
import time
17
16
18
17
from test_framework .blocktools import (
19
- COINBASE_MATURITY ,
20
18
create_block ,
21
19
create_coinbase ,
22
20
)
23
21
from test_framework .messages import (
24
22
msg_pong ,
25
23
msg_tx ,
26
- tx_from_hex ,
27
24
)
28
- from test_framework .p2p import P2PDataStore , P2PInterface
25
+ from test_framework .p2p import (
26
+ P2PDataStore ,
27
+ P2PInterface ,
28
+ )
29
29
from test_framework .test_framework import BitcoinTestFramework
30
30
from test_framework .util import assert_equal
31
+ from test_framework .wallet import MiniWallet
31
32
32
33
33
34
class SlowP2PDataStore (P2PDataStore ):
34
35
def on_ping (self , message ):
35
36
time .sleep (0.1 )
36
37
self .send_message (msg_pong (message .nonce ))
37
38
39
+
38
40
class SlowP2PInterface (P2PInterface ):
39
41
def on_ping (self , message ):
40
42
time .sleep (0.1 )
41
43
self .send_message (msg_pong (message .nonce ))
42
44
45
+
43
46
class P2PEvict (BitcoinTestFramework ):
44
47
def set_test_params (self ):
45
- self .setup_clean_chain = True
46
48
self .num_nodes = 1
47
49
# The choice of maxconnections=32 results in a maximum of 21 inbound connections
48
50
# (32 - 10 outbound - 1 feeler). 20 inbound peers are protected from eviction:
@@ -53,7 +55,7 @@ def run_test(self):
53
55
protected_peers = set () # peers that we expect to be protected from eviction
54
56
current_peer = - 1
55
57
node = self .nodes [0 ]
56
- self .generatetoaddress ( node , COINBASE_MATURITY + 1 , node . get_deterministic_priv_key (). address )
58
+ self .wallet = MiniWallet ( node )
57
59
58
60
self .log .info ("Create 4 peers and protect them from eviction by sending us a block" )
59
61
for _ in range (4 ):
@@ -79,21 +81,8 @@ def run_test(self):
79
81
current_peer += 1
80
82
txpeer .sync_with_ping ()
81
83
82
- prevtx = node .getblock (node .getblockhash (i + 1 ), 2 )['tx' ][0 ]
83
- rawtx = node .createrawtransaction (
84
- inputs = [{'txid' : prevtx ['txid' ], 'vout' : 0 }],
85
- outputs = [{node .get_deterministic_priv_key ().address : 50 - 0.00125 }],
86
- )
87
- sigtx = node .signrawtransactionwithkey (
88
- hexstring = rawtx ,
89
- privkeys = [node .get_deterministic_priv_key ().key ],
90
- prevtxs = [{
91
- 'txid' : prevtx ['txid' ],
92
- 'vout' : 0 ,
93
- 'scriptPubKey' : prevtx ['vout' ][0 ]['scriptPubKey' ]['hex' ],
94
- }],
95
- )['hex' ]
96
- txpeer .send_message (msg_tx (tx_from_hex (sigtx )))
84
+ tx = self .wallet .create_self_transfer ()['tx' ]
85
+ txpeer .send_message (msg_tx (tx ))
97
86
protected_peers .add (current_peer )
98
87
99
88
self .log .info ("Create 8 peers and protect them from eviction by having faster pings" )
@@ -133,5 +122,6 @@ def run_test(self):
133
122
self .log .debug ("{} protected peers: {}" .format (len (protected_peers ), protected_peers ))
134
123
assert evicted_peers [0 ] not in protected_peers
135
124
125
+
136
126
if __name__ == '__main__' :
137
127
P2PEvict ().main ()
0 commit comments