Commit Graph

508 Commits (1876d17ba456bcbc03b8854f5ed2444243ade75a)

Author SHA1 Message Date
Franck Royer 788445964a
Move main.rs to cli.rs to prepare for nectar binary 3 years ago
Franck Royer 311ba74cd6
Remove sell-xmr from CLI 3 years ago
Daniel Karzel 0a0bce1552 Rename temporary wallet to blockchain monitoring wallet 3 years ago
Daniel Karzel 1e29433bd2 Open or create temporary Monero wallet upon wallet initialization 3 years ago
Daniel Karzel dac4443bbd Add functionality to open monero wallet through rpc 3 years ago
Daniel Karzel 62605a318a Add CreateWallet trait to expose create_wallet 3 years ago
Daniel Karzel 53fcd9224c Give finding the refund tx priority over waiting for the punish transaction to be finalized.
This was introduced due to a CI run, where Bob included tx_refund, but Alice had waited until T2 had expired,
and then went for punishing Bob instead of refunding.
Weirdly, Alice's punich transaction did not fail in that scenario.
3 years ago
Daniel Karzel 86290649e7 work in review comments 3 years ago
Daniel Karzel c930ad84a4 Add --force flag for cancel and refund 3 years ago
Daniel Karzel 02f8eb7f18 Add test for cancel/refund before timelock expired 3 years ago
Daniel Karzel 2d5d70d856 Timeout for Alice waiting for ack for sending transfer proof
If dialing Bob fails Alice waits for the acknowledgement of the transfer proof indefinitely.
The timout prevents her execution from hanging.
Added a ToDo to re-visit the ack receivers. They don't add value at the moment and should be removed.
3 years ago
Daniel Karzel c9adbde5d5 Add test for Bob's manual cancel and refund 3 years ago
Daniel Karzel ad2aefc2a5 Refund Command 3 years ago
Daniel Karzel 0600a7048e Cancel command 3 years ago
Franck Royer dee8c1e335
Remove scopes 3 years ago
Franck Royer a48823a665
Re-organise Alice state to be more coherent with the msg sequence 3 years ago
Franck Royer eefb1b3b16
Use event_process = false for Bob
As we do not process the event, we can just implement the needed `From`
traits.
3 years ago
Franck Royer a7b89e2fe4
Use event_process = false for Alice
As we do not process the event, we can just implement the needed `From`
traits.
3 years ago
Franck Royer 554ae6c00e
Remove Request Response types
These are actually not needed and forces us to cater for variants when
processing requests and responses.
3 years ago
Franck Royer 5a5a1c05f7
Set appropriate name to codec 3 years ago
Franck Royer a11e894b31
Prepend all libp2p protocols with "comit" 3 years ago
Franck Royer cfc5cb5206
Remove dead code and combine swap request & one shot codecs 3 years ago
Franck Royer fc2d8d3861
Rename alice::Message0 to Message0
There is now only one message0
3 years ago
Franck Royer 88bf080dc0
rename alice::Message0 to Message1 3 years ago
Franck Royer 18f326ddd1
Rename bob::Message1 to Message2
As per sequence diagram.
3 years ago
Franck Royer 0d1be52966
Rename alice::Message1 to Message3
As per sequence diagram.
3 years ago
Franck Royer e74efd38b5
Rename bob::Message2 to Message4
As per sequence diagram.
3 years ago
Franck Royer 081237bb6f
Remove unused behaviours 3 years ago
Franck Royer ecb54958ee
Preemptively Box few messages 3 years ago
Franck Royer 3fa4ffa82c
Implement new behaviour for execution setup 3 years ago
Franck Royer 9ae050abf8
Use correct variable name 3 years ago
Franck Royer c316ea5244
Upgrade toolchain
Needed to use libp2p-async-await
3 years ago
Franck Royer e82383bcf6
Avoid carrying rng 3 years ago
Philipp Hoenisch 25bf5df122
Merge pull request #172 from comit-network/dead-code
Remove dead code
3 years ago
Philipp Hoenisch 8743527df9
Remove dead code 3 years ago
Daniel Karzel b27363e386 Use correct default data directory 3 years ago
Daniel Karzel 5cb4f3c99d rename configuration to config 3 years ago
Daniel Karzel 89b3775e05 Rename config to execution_params 3 years ago
Daniel Karzel 802dc61e7e Configuration for RPC urls and Bitcoin wallet name 3 years ago
Franck Royer f1c07fbb6d
Remove incorrect todo 3 years ago
Franck Royer c25d5ff07e
Improve network logging 3 years ago
Franck Royer f9f17b0e23
Do not consider transfer proof sent until it's ack'd 3 years ago
Franck Royer b968c98805
remove unnecessary logs 3 years ago
Franck Royer cc76b201b5
Do not consider encrypted signature sent until it's ack'd 3 years ago
Franck Royer 5af3532cbf
Fix log messages 3 years ago
Franck Royer 108cc1e6cc
Use trait instead of passing struct 3 years ago
Franck Royer 704a8e7b01
Add swap id to tracing context 3 years ago
Franck Royer b8a9356d1b
Change expiries depending on the test goal 3 years ago
Franck Royer 49b8d19e41
test: Log state on failure 3 years ago
rishflab 0b69573129
Run tests on one thread, increase T1 3 years ago
rishflab 1597f5336b
Restart event loop in tests
Alice was attempting to create a new event loop using the same listen addr as the old one which was still running. This commit aborts the event loop before creating a new one.
3 years ago
rishflab 77fc5743a2
Upgrade tokio to 1.0
Upgrade bitcoin harness dependency to latest commit

Upgrade backoff to fix failing tests. The previous version of backoff had a broken version of the retry function. Upgraded to a newer comit which fixes this problem.

Upgrade hyper to 0.14 as the 0.13 was bringing in tokio 0.2.24

Upgraded bitcoin harness to version that uses tokio 1.0 and reqwest 0.11

Upgrade reqwest to 0.11. Reqwest 0.11 uses tokio 1.0

Upgrade libp2p to 0.34 in preparation for tokio 1.0 upgrade
3 years ago
Franck Royer 2073e88683
Remove wrapping if `ReadOneError` when unnecessary 3 years ago
Franck Royer 2929a8f101
Use the correct protocol support 3 years ago
Franck Royer b62ef9c2d9
Harmonizing naming 3 years ago
Franck Royer 8fd2620b83
Improve names for messages 4 and 5 3 years ago
Franck Royer 33db688e3a
Bob peer id can be retrieved from the DB
This remove branches where Alice resumes from the DB but cannot contact
Bob.
3 years ago
Franck Royer a910bc2046
Box all messages in enum
The messages are very different, best to box them and save size on the
stack as an enum takes as much space on the stack than its bigger
variant.
3 years ago
Franck Royer d2a1937f51
Use `Message4` 3 years ago
Franck Royer 124d6f1ebb
Introduced Message 4 sent by Alice to replace message 2 response 3 years ago
Franck Royer edb93624f3
Introduce one shot code
To allow alice to be the requester for message 4.
3 years ago
Franck Royer 9a5e35c1bd
Rename `bob::Message2` to `Message5`
As per the proposed changed in the sequence diagram.
The aim is to have a unique terminology per message instead of having
the same name for 2 consequent messages that share the same behaviour.

Note that the aim is to remove the shared `RequestResponse` behaviours.
3 years ago
Franck Royer 10eeecfe54
Remove dependency of main.rs on lib.rs 3 years ago
Franck Royer f2a25ee49b
Move definitions out of lib.rs 3 years ago
Franck Royer b88a777bae
Remove dead code 3 years ago
Daniel Karzel 33a9057b1f Move run_until is_target_state comparison functions into testutils 4 years ago
Daniel Karzel 3593f5323a Bob saves lock proof after received so he can resume swap 4 years ago
Daniel Karzel 433704e48c Top to bottom `pub mod` then `mod` then `pub use` then `use` (incl. `use crate` and `use self`) 4 years ago
Daniel Karzel 44c4b5dcea Remove newlines from import statements to avoid problems
Rust fmt automatically groups the imports (from top to bottom) as `pub use` `use crate` and `use`.
There is no need to introduce sections which cause annoyance when auto importing using the IDE.
4 years ago
bors[bot] 4e858197c9
Merge #149
149: Fix Alice redeem scenario r=da-kami a=da-kami

Follow up of #144, partial fix of https://github.com/comit-network/xmr-btc-swap/issues/137

 Fix Alice redeem scenario

- Properly check the timelocks before trying to redeem
- Distinguish different failure scenarios and reactions to it.
    - if we fail to construct the redeem transaction: wait for cancel.
    - if we fail to publish the redeem transaction: wait for cancel but let the user know that restarting the application will result in retrying to publish the tx.
    - if we succeed to publish the tx but then fail when waiting for finality, print error to the user (secreat already leaked, the user has to check manually if the tx was included)



Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
Franck Royer 8c76abcd37
Remove TODO
This can be tackle when migrating to SQLite
4 years ago
Franck Royer 898b8bf8b0
Remove dead code 4 years ago
Franck Royer ae8134f04e
Replace amounts messages with swap res/req 4 years ago
Daniel Karzel 6a75c840b5 Fix Alice redeem scenario
- Properly check the timelocks before trying to redeem
- Distinguish different failure scenarios and reactions to it.
    - if we fail to construct the redeem transaction: wait for cancel.
    - if we fail to publish the redeem transaction: wait for cancel but let the user know that restarting the application will result in retrying to publish the tx.
    - if we succeed to publish the tx but then fail when waiting for finality, print error to the user (secreat already leaked, the user has to check manually if the tx was included)
4 years ago
Daniel Karzel 8a7d746e96 Wait for Bob's refund finality
For Alice we ensure to wait for redeem/punish finality, so it should be the same for Bob.
4 years ago
Franck Royer 94045b9a69
Use builder in tests 4 years ago
Franck Royer c44b867d01
Delay the wrapping in Arc 4 years ago
Franck Royer 83b72c0a45
Make `make_init_state` and `init_loop` associated to `alice::SwapFactory` 4 years ago
Franck Royer c11042ff0d
Use `builder` terminology instead of `factory`
This is not really a factory as a factory design pattern is about
producing several instances.

In the current usage, we are only interested in one swap instance. Once
the swap instance is created, the factory becomes useless. Hence, it is
more of a builder pattern.
4 years ago
Franck Royer 9148af2dbe
`bob::SwapFactory` should be consumed once a swap is returned 4 years ago
Franck Royer 652bfa14a9
Remove unnecessary `pub` qualifiers 4 years ago
Franck Royer b21dc03ed0
`alice::SwapFactory` should be consumed once a swap is returned 4 years ago
Franck Royer 9b32409b8d
Remove unnecessary `allow(clippy)` 4 years ago
Franck Royer 9e3ef7ea24
Remove `StartingBalances` from release code 4 years ago
Franck Royer 181999e04f
Remove unnecessary `alice` qualifiers in `alice::SwapFactor` 4 years ago
Franck Royer 3bc76a91c6
Make `init_state` associated to `bob::SwapFactory` 4 years ago
Franck Royer f0e6e45d56
Remove unecessary `bob` qualifier 4 years ago
Franck Royer dbc633ea06
Remove unecessary `connect` qualifier 4 years ago
Franck Royer e26629b593
Remove unecessary fields from `bob::SwapFactory` 4 years ago
Franck Royer 3c68026cfe
Move init event loop in `bob::SwapFactory` 4 years ago
Franck Royer 96b1b18037
Keep terminology consistent
Also avoid redundant qualifiers.
4 years ago
Daniel Karzel 28429fa9fe Revert log statement 4 years ago
Daniel Karzel 37f619dbfc Move StartingBalances into protocol module 4 years ago
Daniel Karzel 41e335fc2d Error messages instead of unreachable
Currently this code is actually not reachable, but that is semantically applied by the program's flow (the resume command includes the swap direction).
It is still preferred to have an error message rather than an unreachable statement.
4 years ago
Daniel Karzel 2dceab28a4 Derive Default 4 years ago
Daniel Karzel acfd43ee79 Rename Test to TestContext and argument to ctx 4 years ago
Daniel Karzel e91987e23f Fix rand import 4 years ago
Daniel Karzel 170e90ffed Rename do_run_until to _run_until_internal 4 years ago
Daniel Karzel 82974412b2 Remove roles from SwapFactory name as implied by module and cleanup 4 years ago
Daniel Karzel 75f89f3b25 Use Bob swap factory in production 4 years ago
Daniel Karzel e56c48ee23 Remove unused type 4 years ago
Daniel Karzel 3398ef8236 Use Alice swap factory in production 4 years ago
Daniel Karzel 67e925fe1f Refactor Bob's peer-id and identity to be handled on the outside
Doing this in the behaviour is a weird indirection that is not needed.
4 years ago
Daniel Karzel 0c19af9090 Refactor Alice's peer-id and identity to be handled on the outside
Doing this in the behaviour is a weird indirection that is not needed.
4 years ago
Daniel Karzel 8bf467b550 Make the factory code usable in production
- Introduce Test abstraction instead of tow harnesses, move test specific data into Test
- Change the abstraction from actors to swap, because we are creating swaps, not actors
- rename actor::swap  to run, because we are running a swap
4 years ago
Daniel Karzel e4795fa4ee Fix recursive call to swap by using run_until
We should call run_until instead of swap.
4 years ago
bors[bot] 35c42263df
Merge #145
145: Make lock-tx id available in redeem/punish state to be able to assert exact fees r=da-kami a=da-kami

We can do exact assertions for Bob's redeem as well, but have to store Bob's tx_lock id in the respective final state. Make tx_lock available in BtcRedeemed and BtcPunished to have better assertions / harmonize test behaviour.

Storing this information is strictly speaking not needed for the production environment. But it is static information that can be seen as additional information that can be handy for a user. We could potentially extract it inside the tests as well (for redeem without restart would be a bit tricky), but I think this solution is more elegant. 

Co-authored-by: Daniel Karzel <daniel@comit.network>
Co-authored-by: Franck Royer <franck@coblox.tech>
Co-authored-by: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
4 years ago
bors[bot] a7f68e4aa1
Merge #144
144: Test refactor r=da-kami a=da-kami

This PR is pure refactoring, keeping the logic of the tests we had before. No production code is touched besides re-exports in early commits (no logic changes).

In the follow ups improvements will be introduced, that touch the production code as well.

All remaining tasks actioned since Friday: 

- [x] `happy_path_bob _restart` (trivial)
- [x] add refund assertions to harnesses (trivial)
- [x] convert all refund scenarios currently being tested (trivial)
- [x] remove dead test init code once all old tests are converted
- [ ] ~~(optional) move alice and bob harness code into separate files~~ -> might action this once re-using test code in production.

Out of scope, follow up:
- [x] https://github.com/comit-network/xmr-btc-swap/pull/145 - We can do exact assertions for Bob's redeem as well, but have to store Bob's `tx_lock` id in the respective final state. Make `tx_lock` available in `BtcRedeemed` and `BtcPunished` to have better assertions / harmonize test behaviour. 
- [ ] update the production code to use the `Alice` and `Bob` structs to bundle the params - update tests to use the production struct.
- [ ] Re-use test swap setup in production (i.e. `Alice-/BobHarness::new`) to setup the swap.
- [ ] add additional tests
- [ ] re-try moving the tests from `test` to `src` (if the peer_id was the only problem this should be trivial now - but should be done after the refactor is finished)
- [ ] creating new wallets upon restart
- [ ] aborting the old event loop after restart

Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
Franck Royer 9a823dca4c
Do not introduced State6 4 years ago
bors[bot] 974b6ebf6f
Merge #136
136: Testnet resume fixes r=da-kami a=da-kami

Add a few log statements on Bob's side to make the user experience better.
Update / remove ToDos.

I set the log level to `Info` in main again, `Debug` heavily clutters the output. In order to make `Debug` more usable we might want to review printing all those `rpc` messages. But this goes beyond the scope of this PR.


Co-authored-by: Daniel Karzel <daniel@comit.network>
4 years ago
Daniel Karzel d4316f0cfe Print each monero confirmation for Bob
This is to provide more context to the user.
4 years ago
Daniel Karzel 8615aaed6e Make lock-tx id available in redeem/punish state to be able to assert exact fees 4 years ago
Daniel Karzel 317b251302 Re-arrange order of structs/functions in testutils
move important things to the top and harmonize structure for alice and bob.
4 years ago
Daniel Karzel 7832ee94f3 Remove unused code and only expose necessary functionality 4 years ago
Daniel Karzel 8ef8240771 Refactor refund test 4 years ago
Daniel Karzel 55024572ae Refactor punish test and punish assertions 4 years ago
Daniel Karzel 73a2841ec5 Refactor happy path bob restart tests 4 years ago
Daniel Karzel 8a2eb07928 Harmonize names and structure
Simple renames and structure changes, no logical changes.
4 years ago
Daniel Karzel bede1c13dd Refactor Bob's side (happy path + alice restart)
Refactor Bob's test setup in the same way as Alice's.
Introduce BobHarness that allows creating and restarting as well as asserting redeemed for Bob.
4 years ago
Daniel Karzel 59f9a1c286 Fix usage of StartingBalance in Alice and Bob 4 years ago
Daniel Karzel 87edec0d50 Rename Alice's factory to harness and include redeem assertions
This makes the redeem assertion reusable for all tests with a redeem scenario.
Since the factory was not a clean factory before and is now doing even more it was renamed to harness.
4 years ago
Daniel Karzel 152c8d7eba Refactor Alice restart test by introducing factory for creating Alices
The factory keeps all static state of Alice to be able to simulate a restart.
4 years ago
Daniel Karzel b031bc5e42 Re-export run_until 4 years ago
rishflab 537d05e01e Add reusable test function
We introduce a reusable test function to make it easier to add new tests and make our existing tests more readable.
4 years ago
rishflab 9cbf6e9774 Re-export event loop handles 4 years ago
rishflab 6040f2ae63 Re-export event loops 4 years ago
rishflab e8fdf62623 Re-export swap function 4 years ago
rishflab f5cfe014be Fix imports 4 years ago
Franck Royer 31c63f0c4d
Remove dead code 4 years ago
Franck Royer 0852f90473
Remove unused variant 4 years ago
Daniel Karzel f8848aca55 Describe additional state for ToDo that might cause trouble
If we wait for lock transaction confirmations immediately after sending the transaction without saving this state to the DB this might cause locking the money twice.
An additional state is needed for such a scenario.
4 years ago
Daniel Karzel 59f01ad680 Remove Todo that was already actioned
This ToDo does not add any value, I would not know what to do here.
4 years ago
Daniel Karzel 60f3923a63 Set tracing level to Info in production code
Trace / Debug should be used when there is a problem. They print way too much in production.
4 years ago
Daniel Karzel 00b4f3110f Remove ToDo that is already actioned
We already have a second watcher for the cancel timelock, so refund is already actioned.
4 years ago
Daniel Karzel ab9117aa4c Log Alice's lock tx proof receive on Bob's side 4 years ago
Daniel Karzel af45206fde Remember the block-height before XMR lock for generated monero wallet restore height
Speeds up wallet creation, because only the blocks after the recorded height will be scanned.
4 years ago
bors[bot] ca6ba78862
Merge #123
123: Small fixes after testnet usage r=da-kami a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
4 years ago
Daniel Karzel 664958939d Create network::Seed from swap::Seed instead of abstracting over byte array 4 years ago
Daniel Karzel f18d01dfaf Deterministic peer id from seed for bob 4 years ago
Daniel Karzel 0a21040e08 Deterministic peer id from seed for alice
This includes the introduction of the --data-dir parameter instead of the --database.
Both the seed file and the database are stored in the data-dir, the database in sub-folder `database`.
4 years ago
Franck Royer 6ffc66867c
Typo
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
4 years ago
Franck Royer 047f990d05
Improve error reporting on signature verification 4 years ago
Franck Royer ef906876a0
Increase timelocks on testnet
To allow time for stagenet Monero transaction to be mined.
4 years ago
Franck Royer 17356eaff9
Do not guard waiting for encrypted signature with arbitrary timeout
We already select waiting for this message with the cancellation expiry,
 we do not need add another guard that tries to guess how long it would
 for the Monero transaction to be finalised.
4 years ago
Franck Royer 95ecb02e7a
Small changes to make debugging easier and tests 4 years ago
Franck Royer 9d8f8b0a1f
P2p socket should be listening for external connections 4 years ago
rishflab 1c644cb377 Rename message behaviours 4 years ago
rishflab 5d7d72c826 Remove unused import 4 years ago
rishflab 387a4da2f6 Make modules private 4 years ago
rishflab dcea54dbf1 Move protocol parent states into appropriate module 4 years ago