Commit Graph

52 Commits

Author SHA1 Message Date
bors[bot]
3db71997d3
Merge #99
99: Cleanup resume_from_database functions only used in tests r=da-kami a=da-kami

Follow up of https://github.com/comit-network/xmr-btc-swap/pull/88

Co-authored-by: Daniel Karzel <daniel@comit.network>
2020-12-18 03:01:18 +00:00
Daniel Karzel
e6493784bf Change pin_mut! to select! 2020-12-18 11:37:02 +11:00
Daniel Karzel
773eebc723 Cleanup resume_from_database functions only used in tests 2020-12-18 10:50:32 +11:00
Daniel Karzel
093cbaa4b4 Introduce T1Expired state for Bob properly and check expiries in states after both locked 2020-12-17 15:17:15 +11:00
Franck Royer
71cf501c29
Delete bob::negotiate
This module was intended to contain helper functions for each step.

However, those are not needed except for the negotiate step.
A dedicated module is not needed for one function.
2020-12-15 16:53:50 +11:00
Franck Royer
53d13330c2
Remove dupe code 2020-12-15 16:45:06 +11:00
Franck Royer
5ba830f3bf
Replace swap recover terminology with resume 2020-12-15 11:52:00 +11:00
Daniel Karzel
7cae6a9e4d
Add Bob restart test 2020-12-15 11:43:28 +11:00
Daniel Karzel
3692046758
Bob's recover function 2020-12-15 11:43:27 +11:00
rishflab
143d8bc07d
Move message0 response handler out of NB 2020-12-15 11:43:24 +11:00
Franck Royer
caf903acda
wip: Add test for when bob restarts 2020-12-15 10:18:48 +11:00
Franck Royer
905fc6cf35
Save Bob state during swap 2020-12-15 10:18:46 +11:00
Franck Royer
11cea9ba69
Remove passing alice peer id
The usage of the peer id is incorrect as we do not even check it when
dialing. For now, we can ignore it.
We can then re-introduce it and use it properly at a later stage.
2020-12-15 09:15:38 +11:00
rishflab
d8d6477ee9 Remove and fix comments 2020-12-14 11:56:14 +11:00
rishflab
7af4b6980a Test Alice refunds after Bob refund
Reworked Alice XmrLocked state transition handler to handle the
scenario when Alice received the encsig but Bob refunds.
Previously Alice was trying to redeem after receiving the encsig
without checking if t1 had elapsed.
2020-12-11 17:05:34 +11:00
rishflab
78c6a1a78f Add Bob refund execution 2020-12-11 16:59:29 +11:00
Franck Royer
2c9fb7b1da
Rename var to match type name 2020-12-10 14:03:45 +11:00
Franck Royer
53aae5cf5f
Use anyhow macro as intended 2020-12-10 14:00:48 +11:00
Franck Royer
51cc44484b
Remove unneeded pub qualifiers 2020-12-10 14:00:47 +11:00
rishflab
9ba89194b0 Rename swarm driver to event loop 2020-12-10 13:29:53 +11:00
rishflab
f5d3d54b13 Prevent premature Bob t1 timeout
Bob was hitting the t1 timeout and entering cancel
instead of redeem. This was resolved by increasing
the timeouts to 50.
2020-12-10 13:29:53 +11:00
rishflab
3d8866f1a0 Convert event loop to use fused futures select
Co-authored-by: Daniel Karzel <daniel@comit.network>
2020-12-10 13:29:53 +11:00
rishflab
58da1df9dc Create SwarmDriverHandle to resolve ownership issues 2020-12-10 11:24:08 +11:00
rishflab
6f7408ecce Drive swarm in seperate async task
Previously the libp2p swarm had to be manually polled within the
protocol execution code to execute actions such as sending a
message. The swarm is now wrapped in SwarmDriver which polls the
swarm in a seperate task
2020-12-10 11:24:05 +11:00
rishflab
8592ef5f79 Address PR feedback
Add context to logging statements. Use amount type for monero in tests. Remove stale
code and comments.
2020-12-07 13:55:13 +11:00
rishflab
c91e9652aa Add alice punish test
Use reusable test init functions for happy path test

Extract tracing setup to reusable function

Move test initialization to seperate functions

Increase stack size in CI

Fix monero max finality time

Force Bob swarm polling to send message 2

Run Bob state to xmr_locked in punish test to force the sending of
message2. Previously Bob state was run until btc_locked. Although
this was the right thing to do, message2 was not being sent as the
swarm was not polled in btc_locked. Alice punish test passes.

Add info logging to executor
2020-12-04 17:23:37 +11:00
rishflab
584cc22024 Allow Bob to exit execution at a specified state 2020-12-04 17:16:03 +11:00
rishflab
1c401aad31 Fix clippy warnings and formatting 2020-12-01 15:38:24 +11:00
rishflab
b06321a40f WIP: cleanup 2020-12-01 14:46:53 +11:00
rishflab
47c3ddc6f7 Fix happy path test
Poll bob swarm to send encsig after calling send message3. Comment
out unimplmented wait for transaction finality trait. Dial alice.
2020-12-01 14:30:02 +11:00
rishflab
d8218a7bea Remove mspc channel from new executor 2020-11-30 15:16:56 +11:00
Franck Royer
9e13034e54 Extract execution details from driving loop 2020-11-30 15:13:20 +11:00
rishflab
24631d464d Add test for recursive executor 2020-11-30 15:13:20 +11:00
rishflab
3b005bd15c Resolve rebase issues, restructure code and fix warnings 2020-11-30 15:13:20 +11:00
Lucas Soriano del Pino
7fa7641feb Clean up some logs and comments 2020-10-30 15:51:46 +11:00
Tobin C. Harding
4d4acde476 Bubble up an event when Bob receives message 3 response
Before this patch Bob is not sending message 3. This is because we are not
polling Bob's swarm correctly. To fix it we can just mimic the other NB's and
bubble up an event when Bob receives message 3 response from Alice, this way we
can `await` upon this event which triggers polling, making Bob's swarm send the
message.
2020-10-30 14:07:15 +11:00
Lucas Soriano del Pino
ae87c10cae wip: fixed message0 2020-10-30 14:05:45 +11:00
Tobin C. Harding
3e2f0b74a2 Do not trace events meant for other NBs 2020-10-30 14:05:45 +11:00
Lucas Soriano del Pino
a4e4c27bee Execute Bob's on-chain protocol after handshake
Co-authored-by: Tobin C. Harding <tobin@coblox.tech>
2020-10-30 14:03:27 +11:00
Lucas Soriano del Pino
4ee82a5a2a Execute Alice's on-chain protocol after handshake
Co-authored-by: Tobin C. Harding <tobin@coblox.tech>
2020-10-30 14:00:39 +11:00
Tobin C. Harding
b22f265cf3 Send back an empty response to Message2
Alice does not respond with anything when receiving message 2 from Bob. We don't
want to leave Bob's request/response protocol waiting so send an empty response
back.
2020-10-27 10:26:54 +11:00
Tobin C. Harding
cbccc282ef Send Message2 from Bob to Alice
In order for Alice to complete the handshake she needs to transition to state 3,
for this she needs message 2 from Bob.

Send `bob::Message2` to Alice and transition to `State3` - completing the
handshake.
2020-10-26 14:30:41 +11:00
Tobin C. Harding
19f065575d Do a bunch of cleanups 2020-10-22 14:30:10 +11:00
Tobin C. Harding
6e34f9c978 Use const TIMEOUT instead of an argument 2020-10-22 14:12:49 +11:00
Tobin C. Harding
ad006fae6a Do a bunch of cleanups 2020-10-22 13:35:55 +11:00
Tobin C. Harding
0f17ec076c Add message1 2020-10-22 13:23:12 +11:00
Tobin C. Harding
ad0d8d5713 Emit message0 out of NB (both parties) 2020-10-22 11:04:49 +11:00
Tobin C. Harding
bb94643943 Remove data from message until Message0 impl serde 2020-10-22 09:58:22 +11:00
Tobin C. Harding
e7504de76c Add state0 -> state1 messages 2020-10-21 15:02:52 +11:00
Tobin C. Harding
aaf1363c05 Refine peer tracker and amounts protocol
We model the getting of amounts as a network behaviour even though conceptually
it is a protocol. Refine/refactor the code a bit to make this more obvious.

- Use `Amounts` instead of `Messenger`

We only ever connect to a single peer, update peer tracker to reflect this. This
is a single patch because the handling of the two network behaviours is a
intertwined.

- Only track one peer connection
- Track the peer id and the multiaddr of the counterparty
- Emit an event for connection established on Alice's side as well as Bob's side
2020-10-21 10:11:24 +11:00