Commit Graph

815 Commits

Author SHA1 Message Date
Thomas Eizinger
8d76607343
Refactor monero-harness containers
1. Split up image::Monero into Monerod and MoneroWalletRpc
2. Don't use `bash` to run the internal command. Instead we disable
the entrypoint script as per https://github.com/XMRto/monero#raw-commands
3. Remove the start up delay by listening for the correct log message.
To make this more resilient, we make the log level NOT configurable and
instead always log verbosely.
2021-04-26 18:12:57 +10:00
Thomas Eizinger
0970c2bc72
Initialize reqwest clients with verbose logging 2021-04-26 18:12:56 +10:00
Thomas Eizinger
dc840e1562
Take wallet names by reference
We are always passing constants here. Make that more ergonomic.
2021-04-26 12:45:40 +10:00
Thomas Eizinger
22bdc08c83
Get rid of Bob's swap Builder
Doesn't serve any purpose. We are better of just having two
constructors.
2021-04-26 12:45:40 +10:00
Thomas Eizinger
e266fb07ef
Don't stutter 2021-04-26 12:45:39 +10:00
Thomas Eizinger
7adeaae12d
Be smart about how we import Config
By saying env::Config, we can save a line of code in the imports
and make it clearer, what kind of `Config` this is.
2021-04-26 12:45:39 +10:00
Thomas Eizinger
be5bf01ed4
Don't overqualify types that are already imported 2021-04-26 12:45:38 +10:00
Thomas Eizinger
325fcbdb8c
Introduce protocol::bob::behaviour to mimic structure from alice module 2021-04-26 12:45:37 +10:00
Thomas Eizinger
5b515d6fb2
Don't qualify with alice:: if we are within a module of Alice 2021-04-26 12:45:37 +10:00
Thomas Eizinger
a31d6febca
We don't need to import ourselves 2021-04-26 12:45:36 +10:00
Thomas Eizinger
881913ad9c
Re-order content of harness/mod.rs in a sane way
Most important things come first, remaining items are defined roughly
in the order they are used by the top level components.
2021-04-26 12:45:36 +10:00
Thomas Eizinger
6d06db3259
Use macro-based JSON-RPC client 2021-04-26 12:45:35 +10:00
dependabot[bot]
19483c5ead
Bump libp2p from 0.36.0 to 0.37.1
Bumps [libp2p](https://github.com/libp2p/rust-libp2p) from 0.36.0 to 0.37.1.
- [Release notes](https://github.com/libp2p/rust-libp2p/releases)
- [Changelog](https://github.com/libp2p/rust-libp2p/blob/master/CHANGELOG.md)
- [Commits](https://github.com/libp2p/rust-libp2p/compare/v0.36.0...v0.37.1)

Signed-off-by: dependabot[bot] <support@github.com>
2021-04-20 11:51:40 +10:00
Thomas Eizinger
39eea61538
Upgrade to bdk 0.6 2021-04-19 10:14:14 +10:00
COMIT Botty McBotface
43dc74cd9d Prepare release 0.5.0 2021-04-17 07:23:09 +00:00
Daniel Karzel
c1e993deb2
Json codec for quote protocol
A `RequestResponseCodec` for pull-based protocols where the response is encoded using JSON.
This was added to more properly express the behavior of the quote protocol, where the dialer
doesn't send any message and expects the listener to directly send the response.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-04-16 16:00:45 +10:00
Daniel Karzel
f70e2aa8d6
Listen on tcp and websocket transports
- Listen on both tcp and websockets as default
- Listening addresses in config as array
- Configure fallback transport using `or_transport` - if listening on a given address fails on WS, we fall back to TCP.
2021-04-16 16:00:38 +10:00
Thomas Eizinger
b417950f99
Improve error reporting of failed protocols
Instead of forwarding every error, we deliberately ignore certain
variants that are not worth being printed to the log. In particular,
this concerns "UnsupportedProtocols" and "ResponseOmission".

To make this less verbose we introduce a macro for mapping a
`RequestResponseEvent` to `{alice,bob}::OutEvent`. We use a macro
because those `OutEvent`s are different types and the only other
way of abstracting over them would be to introduce traits that we
implement on both of them.

To make the macro easier to use, we move all the `From` implementations
that convert between the protocol and the more high-level behaviour
into the actual protocol module.
2021-04-14 10:34:06 +10:00
Thomas Eizinger
f0f7288bb6
Introduce a redial::Behaviour
This behaviour makes Bob re-dial Alice with an exponential backoff as
soon as the connection is lost.
2021-04-14 10:07:14 +10:00
Thomas Eizinger
d4c10a1292
Introduce swarm::{alice,bob} function to construct a Swarm instance 2021-04-14 10:06:32 +10:00
bors[bot]
19766b9759
Merge #405
405: Concurrent swaps with same peer r=da-kami a=da-kami

Fixes #367 

- [x] Concurrent swaps with same peer

Not sure how much more time I should invest into this. We could just merge the current state and then do improvements on top...?

Improvements:

- [x] Think `// TODO: Remove unnecessary swap-id check` through and remove it
- [x] Add concurrent swap test, multiple swaps with same Bob
- [ ] Save swap messages without matching swap in execution in the database
- [ ] Assert the balances in the new concurrent swap tests
- [ ] ~~Add concurrent swap test, multiple swaps with different Bobs~~
- [ ] ~~Send swap-id in separate message, not on top of `Message0`~~

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-04-13 08:50:44 +00:00
Daniel Karzel
c976358c37
Multiple swaps with the same peer
- Swap-id is exchanged during execution setup. CLI (Bob) sends the swap-id to be used in his first message.
- Transfer poof and encryption signature messages include the swap-id so it can be properly associated with the correct swap.
- ASB: Encryption signatures are associated with swaps by swap-id, not peer-id.
- ASB: Transfer proofs are still associated to peer-ids (because they have to be sent to the respective peer), but the ASB can buffer multiple
- CLI: Incoming transfer proofs are checked for matching swap-id. If a transfer proof with a different swap-id than the current executing swap is received it will be ignored. We can change this to saving into the database.

Includes concurrent swap tests with the same Bob.

- One test that pauses and starts an additional swap after the transfer proof was received. Results in both swaps being redeemed after resuming the first swap.
- One test that pauses and starts an additional swap before the transfer proof is sent (just after BTC locked). Results in the second swap redeeming and the first swap being refunded (because the transfer proof on Bob's side is lost). Once we store transfer proofs that we receive during executing a different swap into the database both swaps should redeem.

Note that the monero harness was adapted to allow creating wallets with multiple outputs, which is needed for Alice.
2021-04-13 18:16:19 +10:00
Daniel Karzel
46f144ac67
Switch monero-rpc to debug in tests
To be able to see CI monero RPC errors.
2021-04-13 17:43:10 +10:00
bors[bot]
2f19222948
Merge #397
397: Always log at debug level to file r=rishflab a=rishflab

WILL SQUASH DOWN TO 3 COMMITS WHEN APPROVED!

Log at debug level to file

EnvFilter is applied globally. This means you cannot log at INFO level 
to the terminal and at DEBUG level to log files. To get a around this 
limitation I had to implement the layer trait on a new type and filter 
in the on_event() trait method. Each swap has its own log file denoted 
by its swap_id. The logger appends to the existing file when resuming a 
swap.

Closes #278 


I think the `DebugTerminalPritner` and `InfoTerminalPrinter` could be consolidated with some effort with some generics wizardry. It works for now and I think it can be done later. I wish in general there was a cleaner way to do this.
 

Co-authored-by: rishflab <rishflab@hotmail.com>
2021-04-09 00:19:56 +00:00
Daniel Karzel
489696ee08
Swap-id as file name for generated Monero wallet
Instead of using the private view-key as wallet filename we use the swap-id, to be able to identify which wallet is associated with which swap.
2021-04-08 19:23:54 +10:00
Daniel Karzel
548f057726
Try to open wallet in case generate_from_keys fails 2021-04-08 19:15:30 +10:00
Daniel Karzel
b60790a32c
Allow buffering multiple transfer proofs per peer
Allowing multiple swaps with the same peer requires buffering multiple transfer proofs per peer.
2021-04-08 17:02:18 +10:00
rishflab
8805002f96 Remove redundant noun from tracing initialiser functions 2021-04-08 16:14:32 +10:00
rishflab
9745d150e7 Log at debug level to file
EnvFilter is applied globally. This means you cannot log at INFO level
to the terminal and at DEBUG level to log files. To get a around this
limitation I had to implement the layer trait on a new type and filter
in the on_event() trait method. Each swap has its own log file denoted
by its swap_id. The logger appends to the existing file when resuming a
swap.

Closes #278
2021-04-08 16:10:35 +10:00
rishflab
e517c5934e Move asb tracing initializer to asb module 2021-04-08 10:51:54 +10:00
COMIT Botty McBotface
1687f84aa1 Prepare release 0.4.0 2021-04-06 08:20:31 +00:00
bors[bot]
32912ebd4a
Merge #394
394: Add a configurable spread to the ASB r=thomaseizinger a=thomaseizinger

Fixes #381.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-04-06 07:39:11 +00:00
bors[bot]
f0a8be6835
Merge #396
396: Remove default connection details from CLI r=thomaseizinger a=rishflab

Connecting buyers to us by default is not consistent with our vision of
a decentralised network of sellers.

Closes #395

Co-authored-by: rishflab <rishflab@hotmail.com>
2021-04-06 07:26:24 +00:00
rishflab
9b0467d43a Remove default connection details from CLI
Connecting buyers to us by default is not consistent with our vision of
a decentralised network of sellers.

Closes #395
2021-04-06 16:59:11 +10:00
bors[bot]
e0b859bb1e
Merge #387
387: Improve the resilience of the network layer r=thomaseizinger a=thomaseizinger

We improve the resilience in two ways:

1. Use a timeout on Bob's side for the execution-setup.
2. Use the `bmrng` library to model the communication between Alice and Bob.

See commit messages for details.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-04-06 06:20:30 +00:00
Thomas Eizinger
a99d12b9df
Add a configurable spread to the ASB
Fixes #381.
2021-04-06 16:16:58 +10:00
Thomas Eizinger
3e0301a9d4
Move FixedRate into event_loop module
This is where these types are used, they can be defined in there.
2021-04-06 16:16:57 +10:00
Thomas Eizinger
654cfff2a8
Make kraken module emit PriceUpdates instead of Rates 2021-04-06 16:16:56 +10:00
Thomas Eizinger
cfc530e8ab
Make ask field of Rate private 2021-04-06 16:16:53 +10:00
Thomas Eizinger
bc46d95985
Remove unnecessary Serialize implementations 2021-04-06 16:08:42 +10:00
Daniel Karzel
0341e7c9fc
Point BDK to commit that fixes overflow error
Edge cases of UTXOs where value < fee cause the BDK's `coin_select` calculation to panic.
This issue was fixed upstream thus we point the BDK dependency against the commit of the merged fix.
2021-04-06 14:50:27 +10:00
rishflab
7df93faa4b Remove unnecessary wrapper struct 2021-04-06 11:05:36 +10:00
Daniel Karzel
04b49d7117 Add command to print Bitcoin and Monero balance 2021-04-06 09:19:43 +10:00
Daniel Karzel
96008ec130 Add command to withdraw BTC
If no amount is given the wallet will be drained.
2021-04-06 09:19:43 +10:00
Daniel Karzel
f5e81bb0ee Move seed and env_config outside Start command 2021-04-06 09:19:43 +10:00
Daniel Karzel
d9d697821e Separate bitcoin and monero wallet initialization 2021-04-06 09:19:43 +10:00
Daniel Karzel
084fc618b4 Test Alice refunds if restarted and Bob refunded 2021-04-01 17:47:01 +11:00
Thomas Eizinger
1b2f476cae
Have --force flag only override the timelock check
It might very well be that the cancel transaction is already published.
If that is the case, there is no point in failing the command. We simply
transition to cancel and exit normally.

The reason this comes up now is because Alice now properly waits for
the cancel timelock as well and publishes the cancel transaction first.

Ultimately, she should not do that because there is no benefit to her
unless she can also publish the punish transaction.
2021-04-01 17:28:38 +11:00
Thomas Eizinger
24f444b9f7
Race sending transfer proof against cancel timelock
Sending the transfer proof might never resolve because Bob doesn't
come back online. In that case, we need to make sure we bail out
as soon as the timelock expires.
2021-04-01 17:09:18 +11:00
Thomas Eizinger
c0785ab05a
"Buffer" all requests to Alice until we are connected
We use the "precondition" feature of the `tokio::select!` macro to
avoid polling certain futures. In particular, we skip polling all
futures that - when resolved - require us to send a message to Alice.
2021-04-01 17:09:17 +11:00