1
- #!/usr/bin/python3
2
1
# This script exercises the core-lightning implementation
3
2
4
3
# Released by Rusty Russell under CC0:
27
26
SpecFileError ,
28
27
KeySet ,
29
28
Conn ,
29
+ RunnerConn ,
30
30
namespace ,
31
31
MustNotMsg ,
32
32
)
37
37
LIGHTNING_SRC = os .path .join (os .getcwd (), os .getenv ("LIGHTNING_SRC" , "../lightning/" ))
38
38
39
39
40
- class CLightningConn (lnprototest .Conn ):
41
- def __init__ (self , connprivkey : str , port : int ):
42
- super ().__init__ (connprivkey )
43
- # FIXME: pyln.proto.wire should just use coincurve PrivateKey!
44
- self .connection = pyln .proto .wire .connect (
45
- pyln .proto .wire .PrivateKey (bytes .fromhex (self .connprivkey .to_hex ())),
46
- # FIXME: Ask node for pubkey
47
- pyln .proto .wire .PublicKey (
48
- bytes .fromhex (
49
- "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"
50
- )
51
- ),
52
- "127.0.0.1" ,
53
- port ,
54
- )
55
-
56
-
57
40
class Runner (lnprototest .Runner ):
58
41
def __init__ (self , config : Any ):
59
42
super ().__init__ (config )
@@ -194,7 +177,7 @@ def stop(self, print_logs: bool = False, also_bitcoind: bool = True) -> None:
194
177
self .shutdown (also_bitcoind = also_bitcoind )
195
178
self .running = False
196
179
for c in self .conns .values ():
197
- cast ( CLightningConn , c ) .connection .connection .close ()
180
+ c .connection .connection .close ()
198
181
if print_logs :
199
182
log_path = f"{ self .lightning_dir } /regtest/log"
200
183
with open (log_path ) as log :
@@ -216,7 +199,13 @@ def restart(self) -> None:
216
199
self .start (also_bitcoind = False )
217
200
218
201
def connect (self , _ : Event , connprivkey : str ) -> None :
219
- self .add_conn (CLightningConn (connprivkey , self .lightning_port ))
202
+ self .add_conn (
203
+ RunnerConn (
204
+ connprivkey ,
205
+ "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798" ,
206
+ self .lightning_port ,
207
+ )
208
+ )
220
209
221
210
def getblockheight (self ) -> int :
222
211
return self .bitcoind .rpc .getblockcount ()
@@ -232,15 +221,13 @@ def add_blocks(self, event: Event, txs: List[str], n: int) -> None:
232
221
233
222
wait_for (lambda : self .rpc .getinfo ()["blockheight" ] == self .getblockheight ())
234
223
235
- def recv (self , event : Event , conn : Conn , outbuf : bytes ) -> None :
224
+ def recv (self , event : Event , conn : RunnerConn , outbuf : bytes ) -> None :
236
225
try :
237
- cast ( CLightningConn , conn ) .connection .send_message (outbuf )
226
+ conn .connection .send_message (outbuf )
238
227
except BrokenPipeError :
239
228
# This happens when they've sent an error and closed; try
240
229
# reading it to figure out what went wrong.
241
- fut = self .executor .submit (
242
- cast (CLightningConn , conn ).connection .read_message
243
- )
230
+ fut = self .executor .submit (conn .connection .read_message )
244
231
try :
245
232
msg = fut .result (1 )
246
233
except futures .TimeoutError :
@@ -255,7 +242,7 @@ def recv(self, event: Event, conn: Conn, outbuf: bytes) -> None:
255
242
def fundchannel (
256
243
self ,
257
244
event : Event ,
258
- conn : Conn ,
245
+ conn : RunnerConn ,
259
246
amount : int ,
260
247
feerate : int = 253 ,
261
248
expect_fail : bool = False ,
@@ -279,7 +266,7 @@ def fundchannel(
279
266
280
267
def _fundchannel (
281
268
runner : Runner ,
282
- conn : Conn ,
269
+ conn : RunnerConn ,
283
270
amount : int ,
284
271
feerate : int ,
285
272
expect_fail : bool = False ,
@@ -352,7 +339,7 @@ def kill_fundchannel(self) -> None:
352
339
def init_rbf (
353
340
self ,
354
341
event : Event ,
355
- conn : Conn ,
342
+ conn : RunnerConn ,
356
343
channel_id : str ,
357
344
amount : int ,
358
345
utxo_txid : str ,
@@ -416,7 +403,9 @@ def accept_add_fund(self, event: Event) -> None:
416
403
},
417
404
)
418
405
419
- def addhtlc (self , event : Event , conn : Conn , amount : int , preimage : str ) -> None :
406
+ def addhtlc (
407
+ self , event : Event , conn : RunnerConn , amount : int , preimage : str
408
+ ) -> None :
420
409
payhash = hashlib .sha256 (bytes .fromhex (preimage )).hexdigest ()
421
410
routestep = {
422
411
"msatoshi" : amount ,
@@ -429,9 +418,9 @@ def addhtlc(self, event: Event, conn: Conn, amount: int, preimage: str) -> None:
429
418
self .rpc .sendpay ([routestep ], payhash )
430
419
431
420
def get_output_message (
432
- self , conn : Conn , event : Event , timeout : int = TIMEOUT
421
+ self , conn : RunnerConn , event : Event , timeout : int = TIMEOUT
433
422
) -> Optional [bytes ]:
434
- fut = self .executor .submit (cast ( CLightningConn , conn ) .connection .read_message )
423
+ fut = self .executor .submit (conn .connection .read_message )
435
424
try :
436
425
return fut .result (timeout )
437
426
except futures .TimeoutError as ex :
@@ -441,7 +430,7 @@ def get_output_message(
441
430
logging .error (f"{ ex } " )
442
431
return None
443
432
444
- def check_error (self , event : Event , conn : Conn ) -> Optional [str ]:
433
+ def check_error (self , event : Event , conn : RunnerConn ) -> Optional [str ]:
445
434
# We get errors in form of err msgs, always.
446
435
super ().check_error (event , conn )
447
436
msg = self .get_output_message (conn , event )
@@ -452,13 +441,13 @@ def check_error(self, event: Event, conn: Conn) -> Optional[str]:
452
441
def check_final_error (
453
442
self ,
454
443
event : Event ,
455
- conn : Conn ,
444
+ conn : RunnerConn ,
456
445
expected : bool ,
457
446
must_not_events : List [MustNotMsg ],
458
447
) -> None :
459
448
if not expected :
460
449
# Inject raw packet to ensure it hangs up *after* processing all previous ones.
461
- cast ( CLightningConn , conn ) .connection .connection .send (bytes (18 ))
450
+ conn .connection .connection .send (bytes (18 ))
462
451
463
452
while True :
464
453
binmsg = self .get_output_message (conn , event )
@@ -475,7 +464,7 @@ def check_final_error(
475
464
if msgtype == namespace ().get_msgtype ("error" ).number :
476
465
raise EventError (event , "Got error msg: {}" .format (binmsg .hex ()))
477
466
478
- cast ( CLightningConn , conn ) .connection .connection .close ()
467
+ conn .connection .connection .close ()
479
468
480
469
def expect_tx (self , event : Event , txid : str ) -> None :
481
470
# Ah bitcoin endianness...
0 commit comments