Commit Graph

113 Commits

Author SHA1 Message Date
Daniel Karzel
c9d492d155 Only wait for xmr-lock until t1 expired 2020-12-22 17:08:17 +11:00
Daniel Karzel
0cdb7ca8a8 Move current_epoch from lib to bitcoin.rs 2020-12-22 16:45:30 +11:00
Daniel Karzel
83ce6f2c85 Ensure that Bob can cancel correctly if T1 expired and Alice did not move
Bob has to check for the possibility to cancel in every state after he locked the BTC.
Otherwise Bob will try to perform actions that don't have any point.
2020-12-22 16:27:25 +11:00
Daniel Karzel
4143394767
Add recovery function for Alice 2020-12-15 11:40:40 +11:00
Franck Royer
1a5b9f9fa9
Update tests after rebase 2020-12-15 10:19:45 +11:00
Franck Royer
905fc6cf35
Save Bob state during swap 2020-12-15 10:18:46 +11:00
Franck Royer
71a0832ef4
Add zero const to monero::Amount 2020-12-15 10:10:42 +11:00
rishflab
6ff440d0cc Remove unused function 2020-12-14 11:28:52 +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
Daniel Karzel
03b8e5f52e Upgrade CLI for mainnet test 2020-12-11 14:46:29 +11:00
Franck Royer
c0478d7191
Move expiries to config
So they can be different for mainnet and regtest
2020-12-10 14:43:17 +11:00
rishflab
bd8e6e36e0 Fix monero blocktime config 2020-12-09 15:10:29 +11:00
rishflab
883a913f30 Remove nonsensical monero * monero multiplication 2020-12-08 16:12:00 +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
282997c105 Make monero finality calculation clearer 2020-12-07 13:43:23 +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
Franck Royer
247a993b55
Increase regtest timeout values for Linux CI 2020-12-04 12:54:48 +11:00
Franck Royer
624716d8a7
Upgrade rust-bitcoin to 0.25 2020-12-04 08:11:55 +11:00
Franck Royer
765482b0aa
Implement wait_for_transaction_finality 2020-12-02 10:02:20 +11:00
rishflab
1c401aad31 Fix clippy warnings and formatting 2020-12-01 15:38:24 +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
Franck Royer
437c1cbb80 Started to extract some steps
Tealised that the whole point is for them to be idempotent to be useful
2020-11-27 09:34:36 +11:00
Franck Royer
66866f8fbd Remove rng argument 2020-11-27 09:34:36 +11:00
Franck Royer
bff83bbe99 Progress on Cancellation path 2020-11-27 09:34:36 +11:00
Franck Royer
8976a03b3d Implemented Alice transition from BtcLocked to XmrLocked 2020-11-27 09:34:35 +11:00
rishflab
dd07e2f882 Add Alice execution path
Consolidate and simplify swap execution. Generators are no longer
needed. Consolidate recovery and swap data structures. The
recursive calls can be replaced with a loop if returning prior to
completion is desired for testing purposes.

Fill out alice abort path

Move state machine executors into seperate files

Not compiling due to recursion/async issues

Fix async recursion compilation errors

Fix Bob swap execution

Remove check for ack message from Alice. Seems like a bad idea to
rely on an acknowledgement message instead of looking at the
blockchain.

Fix Bob abort

Fix warnings

Xmr lock complete

Add TxCancel submit to XmrLocked

Bob swap completed

Remove alice
2020-11-27 09:21:21 +11:00
Lucas Soriano del Pino
483c819e17 Correctly re-export types from bitcoin and monero modules 2020-11-12 13:49:07 +11:00
Lucas Soriano del Pino
28225f8643 Implement swap recover function for Alice
This introduces a lot of duplication between the binary and the
library, but it's okay because this module should only be a temporary
measure until we allow recovery to be handled by the original state
machine.

Also, fix a bug in `xmr_btc::alice::action_generator` caused by the
incorrect assumption that Alice's ability to punish Bob could be
determined before the cancel transaction hits the blockchain.
2020-11-12 13:49:07 +11:00
Lucas Soriano del Pino
f9cfc2abe3 Remove generics from Database 2020-11-12 13:49:07 +11:00
rishflab
ea08778b2f Save state for Bob at specific points in the swap 2020-11-12 13:49:07 +11:00
Lucas Soriano del Pino
4790d701e5 Update cross-curve-dleq dependency
Making build times considerably faster.

On my machine, after running `cargo clean`, `cargo build -p swap`
takes 2min 19s.

The updated dependency also comes with a critical fix to the `Scalar`
type, which originally wrongly assumed that secp256k1 and ed25519
scalars had the same endianness. For this reason, we now have to
reverse the bytes of recovered scalars if we are to use them on a
different chain.

Finally, there is no need to append `RUST_MIN_STACK=100000000` to
avoid stack overflows in tests and when running the binary.
2020-11-09 13:14:09 +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
9384b0cf3c [WIP] Swap app e2e test 2020-10-30 14:04:27 +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
Lucas Soriano
58aa2b5a2b
Merge pull request #23 from comit-network/remove-re-export
Do not re-export curve25519_dalek
2020-10-27 10:21:58 +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
Lucas Soriano del Pino
0dd01c3a3b Do not re-export curve25519_dalek
Anything that needs to be re-exported by this crate from
`curve25519_dalek` can be re-exported from the `monero` module. In
fact, the `Scalar` type was already being re-exported.
2020-10-26 13:06:20 +11:00
Lucas Soriano del Pino
cea1af1e1a Take bitcoin_tx_lock_timeout as argument to action generators 2020-10-26 12:30:15 +11:00
Lucas Soriano del Pino
1d21ae7e7a Use pin_mut! instead of futures::pin_mut! 2020-10-26 12:30:15 +11:00
Lucas Soriano del Pino
aa2a20916e Include Bob being inactive as a reason for failure 2020-10-26 12:30:15 +11:00
Lucas Soriano del Pino
41e8c7283c Verify Bob's redeem encsig as Alice
Not doing so means that receiving an invalid encrypted signature from
Bob would make the generator produce a `RedeemBtc` action that should
not be accepted by the node (since Bob's signature would be invalid
after decrypting his encrypted signature).

It's better to fail early and let the user know what went wrong,
rather than let them hit an incomprehensible error when using their
wallet.
2020-10-26 12:30:15 +11:00
Lucas Soriano del Pino
def3399d1c Use while instead of loop 2020-10-26 12:30:15 +11:00
Lucas Soriano del Pino
c86a82b315 Rename action_generator_alice to action_generator 2020-10-26 12:30:15 +11:00
Lucas Soriano del Pino
e84c56378c Test that both parties refund if Alice does not redeem
Also:

- Move generator functions to `alice` and `bob` modules. This makes
using `tracing` a lot easier, since the context of the file name let's
us differentiate between Alice's and Bob's generator logs more
clearly.
- Accept 0 confirmations when watching for the Monero lock
transaction. This should eventually be configured by the application,
but in the tests it's making things unexpectedly slower.
2020-10-26 12:30:15 +11:00
rishflab
ec71f98252 Revert re-imports to qualified paths 2020-10-26 11:45:27 +11:00
rishflab
fea6b29da9 Test monero amount serialisation 2020-10-26 11:39:54 +11:00
rishflab
28ffe063b7 Remove stale comment 2020-10-26 11:36:46 +11:00