Commit Graph

669 Commits (fac5b59d1774333ccc4df97be3ff052da697f9c9)
 

Author SHA1 Message Date
Franck Royer fac5b59d17
Remove unnecessary specification of the types 3 years ago
Franck Royer 7805a6d684
Move cli specific modules under cli folder
nectar will also have its own folder with a separate config.
3 years ago
Franck Royer 901c9e89c9
No evident added value of having separate `Seed` structs
Hence, reducing complexity of the codebase. Note that the seed will be
used by both nectar and the cli whereas the config mod will be different
so this changes helps with the next step of having a dedicated config
module for each binary.
3 years ago
Franck Royer 7d392c3086
This files contains `Command` and `Arguments` structs 3 years ago
Franck Royer 45dccb8be2
Rename the config struct `Config` 3 years ago
bors[bot] fadbf1638a
Merge #177
177: Nectar r=D4nte a=D4nte

Re-work Alice do be the Service Provider (nectar).
This means that Alice's event loop runs all the time and processes swap requests.

- We currently use a hardcoded fixed rate
- The binary for nectar is to be done in follow-up PR
- We removed the message acknowledgement feature as it created issues with other work and some work would have been needed to link a ack to the correct swap on Alice side.
- Because we removed the acks, we had to remove a number of restart tests. This can be re-introduced at a later stage once a decision on how to best test the restarts can be done
- We remove the punish test as it is a nectar (alice) feature and current focus is on the CLI (bob).

Co-authored-by: Franck Royer <franck@coblox.tech>
3 years ago
Franck Royer eb39add5ff
Fix typo 3 years ago
Franck Royer 6e6dc320b4
Alice event loop now handles the creation of new swaps 3 years ago
Franck Royer 15eb9a2fe4
Remove punish test
The punish test needs re-work due to the fact that Alice runs continuously

Currently focusing on the CLI (Bob), so we can re-introduce this test
once we want to ensure that nectar (Alice) punishes.
3 years ago
Franck Royer 3bc8b58b6a
Remove Bob restart tests after communication
The test do not work without acks as we stop the event loop as soon
as a message is considered as "sent" when actually the event loop
and swarm may not have yet sent the message.

The ack allow to avoid this issue as the message was considered "sent"
only once the other party sent a response. However, the ack brings
other issue so a review needs to be done to select the appropriate
solution.
3 years ago
Franck Royer fd9f633a77
Remove Alice restarts tests
Current focus is on CLI UX. Fair amount of change needs to happen to
cater for Alice (nectar) restart scenarios.
3 years ago
Franck Royer bfc19d5628
Remove acknowledgements processing
We are aware of issues of timeouts when waiting for acknowledgements.
Also, to properly supports acks in a multiple swap context, we need to
revert to doing event processing on the behaviour so that we can link
leverage the `RequestResponse` libp2p behaviour and link the messages
requests ids to swap ids when receiving an ack or response.

Acks are usefully for specific scenarios where we queue a message on the
behaviour to be sent, save as sent in the DB but crash before the
message is actually sent. With acks we are able to resume the swap,
without ack, the swap will abort (refund).
3 years ago
Franck Royer cc8b855117
Make it possible to clone a handle
This will be used for new swaps.
3 years ago
Franck Royer 1b2be804ed
Remove unnecessary channels
`alice::swap::run_until` will be called once the execution setup is
done. The steps before are directly handled by the event loop,
hence no channels are needed for said steps: connection established,
swap request/response & execution setup.
3 years ago
Franck Royer f5ca5faabf
Process execution setup failure similarly to other failures
By merging it in the failure event of the root behaviour.
3 years ago
Franck Royer 4ade5df0e5
Remove unnecessary impl block 3 years ago
Franck Royer 60e0b9382c
Introduced from float API for Monero quantities 3 years ago
Franck Royer b5b990257a
Move `Behaviour` in dedicated module 3 years ago
Franck Royer 87be9aeb2a
Prepare separation of event loop initialisation to swap initialisation
As for Alice, the event loop will be started with the program and will
be the one starting swaps (`run_until`) based on libp2p events (swap
request).
3 years ago
Franck Royer 530b9b2ea8
Remove possible mix up of timelocks when using `State0::new` 3 years ago
Franck Royer f35ed436ce
Allow `EventLoop` to hold a database ready to pass to `alice::Buider`
The `EventLoop` will use the `Builder` interface to instantiate a
`Swap` upon receiving a `SwapRequest` and successfully doing an
execution setup.
Before this change, the `EventLoop` would have to hold the path to the
db and re-open the db everytime it wants to construct a swap.

With this change, we can open the DB once and then hold a
`Arc<Database>` in the `EventLoop` and pass it to new `Swap`s structs.
3 years ago
Franck Royer 39a46baa2c
Preemptively box cancel tx to avoid size difference in enum 3 years ago
Franck Royer 69363e43a3
Preemptively box encrypted signature to avoid size difference in enum 3 years ago
Franck Royer fd084b764d
Move generation of keys inside `State0::new`
The event loop will now use this function so I want to simplify its
usage to avoid having to instantiate too many items to use it.
3 years ago
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
bors[bot] 639b3169d8
Merge #179
179: Watch only tmp monero wallet r=da-kami a=da-kami

When initializing Monero wallet, try to open temporary wallet, if opening errors then try to create it. If creating errors then fail with message asking the user to configure the wallet RPC.
If opening / creation succeeds get the block_height to verify that connection to wallet works, then proceed to swap. 

Note: RPC error handling is hacky, but I don't see the value of investing time into that at this point. The problem is, that we don't deal with the json rpc errors properly for calls were we don't serialize the result into an object (because the response is empty). Eventually we should switch to using https://github.com/thomaseizinger/rust-jsonrpc-client but that does not support parameters `by-name` yet, see: https://github.com/thomaseizinger/rust-jsonrpc-client/issues/20

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 56a59bc41c Remove newline in use statements 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
bors[bot] 27bb9498d5
Merge #170
170: Cancel and refund commands r=da-kami a=da-kami

I plugged the cancel and refund logic into the current state/state-machine logic of the swap.

## Follow ups  (out of scope)

We might want to record issues to be tackled later, since we are on a tight time budget :)
Please let me know what you think @D4nte @rishflab 

### Problems with `ack` after sending a message

Alice was waiting forever when awaiting the `ack` from bob when sending the lock proof in case she runs into a dial error. It seems the `acks` can cause the program to hang. This is a severe problem that we most probably will encountered in production at some point. For this PR I wrapped the `ack` of Alice upon sending the `encsig` in a timeout to work around this problem, see 7463081f88 - but **we might want to consider to remove all `ack` message. I don't see much value in them if we don't have a resilient retry strategy.**

### Do not require Monero wallet for cancel/refund

The cancel/refund commands don't require a monero wallet.
In this PR we re-uses the builder which requires the monero wallet as well - and we check for the monero balance upon wallet initialization, so the command will fail if no monero wallet is started.

### Save Alice connection info in Bob DB

Save Alice's peer-id/address in DB: It's cumbersome for the user to lookup those details again.




Co-authored-by: Daniel Karzel <daniel@comit.network>
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
bors[bot] ec661178f4
Merge #173
173: Use libp2p-async-await to improve API of execution setup phase r=D4nte a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
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