1
0

lnbase: channel reestablishment working

This commit is contained in:
Janus
2018-05-04 18:23:29 +02:00
committed by ThomasV
parent a58a345dc3
commit d9d2989a6a
2 changed files with 45 additions and 20 deletions

View File

@@ -64,7 +64,7 @@ def serialize_channels(channels):
reconstructed = [reconstruct_namedtuples(x) for x in roundtripped]
if reconstructed != channels:
raise Exception("Channels did not roundtrip serialization without changes:\n" + repr(reconstructed) + "\n" + repr(channels))
return dumped
return roundtripped
if __name__ == "__main__":
if len(sys.argv) > 3:
@@ -107,15 +107,16 @@ if __name__ == "__main__":
if sys.argv[1] == "new_channel":
openingchannel = await peer.channel_establishment_flow(wallet, config, None, funding_satoshis, push_msat, temp_channel_id=os.urandom(32))
dumped = serialize_channels([openingchannel])
openchannel = await peer.wait_for_funding_locked(openingchannel, wallet)
dumped = serialize_channels([openchannel])
wallet.storage.put("channels", dumped)
return
else:
openingchannel = json.loads(channels)[0]
openingchannel = reconstruct_namedtuples(openingchannel)
next_local_commitment_number, next_remote_revocation_number = 1, 1
await peer.reestablish_channel(openingchannel, next_local_commitment_number, next_remote_revocation_number)
openchannel = await peer.wait_for_funding_locked(openingchannel, wallet)
wallet.storage.write()
return openchannel.channel_id
if channels is None or len(channels) < 1:
raise Exception("Can't reestablish: No channel saved")
openchannel = channels[0]
openchannel = reconstruct_namedtuples(openchannel)
openchannel = await peer.reestablish_channel(openchannel)
expected_received_sat = 400000
pay_req = lnencode(LnAddr(RHASH, amount=Decimal("0.00000001")*expected_received_sat, tags=[('d', 'one cup of coffee')]), peer.privkey[:32])
print("payment request", pay_req)
@@ -124,9 +125,13 @@ if __name__ == "__main__":
fut = asyncio.run_coroutine_threadsafe(async_test(), network.asyncio_loop)
while not fut.done():
time.sleep(1)
if fut.exception():
try:
try:
if fut.exception():
raise fut.exception()
except:
traceback.print_exc()
network.stop()
except:
traceback.print_exc()
else:
print("result", fut.result())
finally:
network.stop()