Commit Graph

858 Commits (78480547d5c900c8f7b398c8c799bbd4a7781bb0)

Author SHA1 Message Date
Philipp Hoenisch ea6e2f8f09
Simplify `to_address_string` by implying more context on the structure. 3 years ago
Philipp Hoenisch c8e6db24f8
Derive Tor secret key from seed. 3 years ago
Philipp Hoenisch 3a5395d7a5
Optimize torut features.
OnionV2 addresses are being deprecated and will be fully phased out on 15.10.2021: https://blog.torproject.org/v2-deprecation-timeline
3 years ago
Philipp Hoenisch 632293cf91
Add support for swapping through Tor.
This PR does a few things.
* It adds a TorTransport which either dials through Tor's socks5 proxy or via clearnet.
* It enables ASB to register hidden services for each network it is listening on. We assume that we only care about different ports and re-use the same onion-address for all of them. The ASB requires to have access to Tor's control port.
* It adds support to dial through a local Tor socks5 proxy. We assume that Tor is always available on localhost.  Swap cli only requires Tor to be running so that it can send messages via Tor's socks5 proxy.
* It adds a new e2e test which swaps through Tor. For this we assume that Tor is currently running on localhost. All other tests are running via clear net.
3 years ago
bors[bot] e262345b4f
Merge #442
442: Minor cleanups towards implementing a Monero wallet for local signing r=thomaseizinger a=thomaseizinger

Extracted out of #434.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger 0970c2bc72
Initialize reqwest clients with verbose logging 3 years ago
Daniel Karzel 0f11ab051e
Print peer ID on debog when starting CLI
In order to add more context to the debug logs we print Bob's peer ID.
This allows identifying peer related logs on the ASB.
3 years ago
Thomas Eizinger 22bdc08c83
Get rid of Bob's swap Builder
Doesn't serve any purpose. We are better of just having two
constructors.
3 years ago
Thomas Eizinger e266fb07ef
Don't stutter 3 years ago
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.
3 years ago
Thomas Eizinger be5bf01ed4
Don't overqualify types that are already imported 3 years ago
Thomas Eizinger 325fcbdb8c
Introduce protocol::bob::behaviour to mimic structure from alice module 3 years ago
Thomas Eizinger 5b515d6fb2
Don't qualify with `alice::` if we are within a module of Alice 3 years ago
Thomas Eizinger 6d06db3259
Use macro-based JSON-RPC client 3 years ago
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>
3 years ago
Thomas Eizinger 39eea61538
Upgrade to bdk 0.6 3 years ago
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>
3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
Thomas Eizinger d4c10a1292
Introduce swarm::{alice,bob} function to construct a Swarm instance 3 years ago
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>
3 years ago
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.
3 years ago
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>
3 years ago
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.
3 years ago
Daniel Karzel 548f057726
Try to open wallet in case generate_from_keys fails 3 years ago
Daniel Karzel b60790a32c
Allow buffering multiple transfer proofs per peer
Allowing multiple swaps with the same peer requires buffering multiple transfer proofs per peer.
3 years ago
rishflab 8805002f96 Remove redundant noun from tracing initialiser functions 3 years ago
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
3 years ago
rishflab e517c5934e Move asb tracing initializer to asb module 3 years ago
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>
3 years ago
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>
3 years ago
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
3 years ago
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>
3 years ago
Thomas Eizinger a99d12b9df
Add a configurable spread to the ASB
Fixes #381.
3 years ago
Thomas Eizinger 3e0301a9d4
Move `FixedRate` into event_loop module
This is where these types are used, they can be defined in there.
3 years ago
Thomas Eizinger 654cfff2a8
Make `kraken` module emit `PriceUpdate`s instead of `Rate`s 3 years ago
Thomas Eizinger cfc530e8ab
Make `ask` field of `Rate` private 3 years ago
Thomas Eizinger bc46d95985
Remove unnecessary `Serialize` implementations 3 years ago
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.
3 years ago
rishflab 7df93faa4b Remove unnecessary wrapper struct 3 years ago
Daniel Karzel 04b49d7117 Add command to print Bitcoin and Monero balance 3 years ago
Daniel Karzel 96008ec130 Add command to withdraw BTC
If no amount is given the wallet will be drained.
3 years ago
Daniel Karzel f5e81bb0ee Move seed and env_config outside Start command 3 years ago
Daniel Karzel d9d697821e Separate bitcoin and monero wallet initialization 3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
Thomas Eizinger 1b0c29b424
Use bmrng to model communicaton of Alice's EventLoop with the handle
This allows us to delay the ACKing of the encrypted signature up until
the swap has actually requested it.

Similarly, it allows us to wait for the ACK of the transfer proof within
the swap before continuing.
3 years ago
Thomas Eizinger 1c47b32681
Use bmrng to model communicaton of Bob's EventLoop with the handle
bmrng is a library providing a request-response channel that allows
the receiving end of the channel to send a response back to the sender.
This allows us to more accurately implement the functions on the
`EventLoopHandle`. In particular, we now _wait_ for the ACK of specific
messages from the other party before resolving the future.

For example, when sending the encrypted signature, the async function
on the `EventLoopHandle` does not resolve until we received the ACK
from the other party.

We also delete the `Channels` abstraction in favor of directly creating
bmrng channels. This allows us to directly control the channel buffer
which we set to 1 because we don't need more than that on Bob's side.
3 years ago
Thomas Eizinger 958e5b12bc
Don't match on expired_timelocks and race it in a select in parallel
There is no point in first checking for the expired timelocks and
then constructing a `select!` that also watches for the timelock to
expiry.

We can simply only have the select! invocation to achieve the same
effect. In case the timelock is already expired, this future will
resolve immediately.

Normally, the polling order of `select!` is pseudo-random. We
configure it to be _biased_ here to make sure the futures are polled
in order.
3 years ago
Thomas Eizinger dbe03ba1cf
Timeout Bob's execution-setup after 10 seconds
The execution setup is our only libp2p protocol that doesn't have
a timeout built-in. Hence, if anything fails on Alice's side, we
would wait here forever.

Wrapping the future in a timeout ensures that we fail eventually
if this protocol doesn't succeed.
3 years ago
Thomas Eizinger 5d75f1adba
Remove import line in favor of FQ macro usage 3 years ago
Thomas Eizinger 4c2e254543
Don't log subscription
This object is very verbose and not meant to be logged.
3 years ago
Thomas Eizinger 5b230bc75f
Don't import tracing macros
Typing them out is quicker than constantly adjusting imports.
3 years ago
Thomas Eizinger 90a7760124
Add some log statements to bob::cancel 3 years ago
Thomas Eizinger 3f54b39281
Make all error messages start with an uppercase letter 3 years ago
Thomas Eizinger 0ef9d97679
Remove delegation functions in favor of public fields
We don't need to hide the fields of this Behaviour as the only reason
for why this struct exists is because libp2p forces us to compose our
NetworkBehaviours into a new struct.
3 years ago
Thomas Eizinger b1d0ae8db7
Remove dead code
No codepath constructs this event, we can delete the associated code.
3 years ago
Daniel Karzel 2135a6e53e
Alice resumes swaps 3 years ago
Daniel Karzel d233e9914e
Avoid problems when re-ordering / changing Bob's states
Make it explicit in which states we are able NOT to cancel/refund.
3 years ago
Daniel Karzel e6dd194f77
next_state loop always exits in final state
Otherwise we can run into scenarios where the loop never properly exits.
3 years ago
Daniel Karzel d90496931b
Save Alice's peer-id in the db for Bob
This allows loading the seller-peer-id from the database upon resuming a swap.
Thus, the parameters `--seller-peer-id` is removed for the `resume` command.
Other than the peer-id the multi address of a seller can change and thus is
still a parameter. This parameter might become optional once we add DHT support.
3 years ago
Daniel Karzel bc442bcad3
Await 10 confirmations of lock tx in refund
Awaiting the confirmations in an earlier state can cause trouble with resuming
swaps with short cancel expiries (test scenarios).
Since it is the responsibility of the refund state to ensure that the XMR can
be sweeped, we now ensure that the lock transaction has 10 confirmations before
refunding the XMR using generate_from_keys.
3 years ago
Daniel Karzel 1c129d58c4
Distinguish loading all swaps for alice or bob on db level 3 years ago
Daniel Karzel 183e8f02de
Wait for lock tx and send transfer proof in separate state
Sending the transfer transaction in a distinct state helps ensuring
that we do not send the Monero lock transaction twice in a restart
scenario.
Waiting for the first transaction confirmation in a separate state
helps ensuring that we send the transfer proof in a restart scenario.
3 years ago
Daniel Karzel dfd69c9c80
Alice aborts if any timelock expired before locking XMR
Once we resume unfinished swaps upon startup we have to ensure that
it is safe for Alice to act.
If Bob has locked BTC it is only make sense for Alice to lock up the
XMR as long as no timelock has expired. Hence we abort if the BTC is
locked, but any timelock expired already.
3 years ago
Thomas Eizinger 52b9a78de2
Alice to validate Bob's PSBT for correctness
In order for the re-construction of TxLock to be meaningful, we limit
`Message2` to the PSBT instead of the full struct. This is a breaking
change in the network layer.

The PSBT is valid if:

- It has at most two outputs (we allow a change output)
- One of the outputs pays the agreed upon amount to a shared output script

Resolves #260.
3 years ago
Thomas Eizinger 8576894c10
Split bitcoin::Wallet functions into various impl blocks
This allows us to construct instances of bitcoin::Wallet for test
purposes that use a different blockchain and database implementation.

We also parameterize the electrum-client to make it possible to
construct a bitcoin::Wallet for tests that doesn't have one. This
is necessary because the client validates the connection as it is
constructed and we don't want to provide an Electrum backend for
unit tests.
3 years ago
Thomas Eizinger 11b45cd8c0
Move messages into `protocol` module
This allows us to remove all visibility modifiers from the message
fields because child modules (in this case {alice,bob}::state) can
always access private fields of structs.

It also moves the messages into a more natural place. Previously,
they were defined within the network layer even though they are
independent of the libp2p implementation.
3 years ago
Thomas Eizinger e130448200
Make as many fields of Alice's states private as possible
To achieve this, we need to add some pure helpers to the state structs.
This has the added benefit that we can reduce the amount of code within
the swap function.
3 years ago
Thomas Eizinger 7f5715e147
Remove unnecessary serde implementations 3 years ago
Thomas Eizinger c539465925
Make it possible to create random public keys
This is useful for tests.
3 years ago
rishflab 86f312e143 Safely abort swap if TxLock is not confirmed in a reasonable time
If TxLock does not confirm in a reasonable amount of time, Alice should
give up on the swap rather than waiting forever. Watching for TxLock in
the mempool is not required and it causes unnecessary complexity. What
if Alice does not see the transaction in mempool but it is already
confirmed? She will abort the swap for no reason.
3 years ago
Thomas Eizinger 01739eddb1
Introduce a more flexible transaction subscription system
Instead of watching for status changes directly on bitcoin::Wallet,
we return a Subscription object back to the caller. This subscription
object can be re-used multiple times.

Among other things, this now allows callers of `broadcast` to decide
on what to wait for given the returned Subscription object.

The new API is also more concise which allows us to remove some of
the functions on the actor states in favor of simple inline calls.

Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
bors[bot] 6fb495b6ab
Merge #383 #385 #386
383: Improve resilience of balance assertions r=thomaseizinger a=thomaseizinger

The final commit is the relevant patch!

It sits on top of several refactoring commits that happened while I was debugging why things didn't work as expected. Turned out to be reasonably useful so I just left them in :)

385: Bump anyhow from 1.0.39 to 1.0.40 r=thomaseizinger a=dependabot[bot]

Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.39 to 1.0.40.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/dtolnay/anyhow/releases">anyhow's releases</a>.</em></p>
<blockquote>
<h2>1.0.40</h2>
<ul>
<li>Reduce memory footprint of errors on Rust versions 1.51+ (<a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/145">#145</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="704622f25d"><code>704622f</code></a> Release 1.0.40</li>
<li><a href="64ac0c00a9"><code>64ac0c0</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/145">#145</a> from dtolnay/addrof</li>
<li><a href="ef082670ea"><code>ef08267</code></a> Eliminate functionally duplicate vtable methods on rustc 1.51+</li>
<li><a href="1295b1fef9"><code>1295b1f</code></a> Add additional builds on 1.50 and 1.51 validating addr_of codepath</li>
<li><a href="be89adf403"><code>be89adf</code></a> Detect whether ptr::addr_of is supported by current compiler</li>
<li><a href="ac64560c42"><code>ac64560</code></a> Switch object_ref return from real ref to Ref ptr</li>
<li><a href="2987c9b59e"><code>2987c9b</code></a> Ignore redundant_else pedantic clippy lint</li>
<li><a href="827bb9d4c6"><code>827bb9d</code></a> Catch some warnings in addr_of-related codepaths</li>
<li><a href="ce0041866d"><code>ce00418</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dtolnay/anyhow/issues/144">#144</a> from dtolnay/ptr</li>
<li><a href="3c32aa7dcd"><code>3c32aa7</code></a> Relax Sized bound on Own, Ref, Mut ptrs</li>
<li>Additional commits viewable in <a href="https://github.com/dtolnay/anyhow/compare/1.0.39...1.0.40">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=anyhow&package-manager=cargo&previous-version=1.0.39&new-version=1.0.40)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

386: Bump hyper from 0.14.4 to 0.14.5 r=thomaseizinger a=dependabot[bot]

Bumps [hyper](https://github.com/hyperium/hyper) from 0.14.4 to 0.14.5.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/hyperium/hyper/releases">hyper's releases</a>.</em></p>
<blockquote>
<h2>v0.14.5</h2>
<h2>Bug Fixes</h2>
<ul>
<li><strong>client:</strong> omit default port from automatic Host headers (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2441">#2441</a>) (<a href="0b11eee9bd">0b11eee9</a>)</li>
<li><strong>headers:</strong> Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>) (<a href="48fdaf1606">48fdaf16</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2470">#2470</a>)</li>
<li><strong>server:</strong> skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>) (<a href="8cbf9527df">8cbf9527</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2215">#2215</a>)</li>
</ul>
<h2>Features</h2>
<ul>
<li><strong>client:</strong> allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>) (<a href="68d4e4a3db">68d4e4a3</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2468">#2468</a>)</li>
<li><strong>server:</strong> add <code>AddrIncoming::from_listener</code> constructor (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2439">#2439</a>) (<a href="4c946af49c">4c946af4</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/hyperium/hyper/blob/master/CHANGELOG.md">hyper's changelog</a>.</em></p>
<blockquote>
<h3>v0.14.5 (2021-03-26)</h3>
<h4>Bug Fixes</h4>
<ul>
<li><strong>client:</strong> omit default port from automatic Host headers (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2441">#2441</a>) (<a href="0b11eee9bd">0b11eee9</a>)</li>
<li><strong>headers:</strong> Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>) (<a href="48fdaf1606">48fdaf16</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2470">#2470</a>)</li>
<li><strong>server:</strong> skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>) (<a href="8cbf9527df">8cbf9527</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2215">#2215</a>)</li>
</ul>
<h4>Features</h4>
<ul>
<li><strong>client:</strong> allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>) (<a href="68d4e4a3db">68d4e4a3</a>, closes <a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2468">#2468</a>)</li>
<li><strong>server:</strong> add <code>AddrIncoming::from_listener</code> constructor (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2439">#2439</a>) (<a href="4c946af49c">4c946af4</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="98e7e0bd15"><code>98e7e0b</code></a> v0.14.5</li>
<li><a href="895e4cf3fb"><code>895e4cf</code></a> refactor(ffi): return null ptr instead of aborting in C API (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2478">#2478</a>)</li>
<li><a href="68d4e4a3db"><code>68d4e4a</code></a> feat(client): allow HTTP/0.9 responses behind a flag (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2473">#2473</a>)</li>
<li><a href="51ed71b0a6"><code>51ed71b</code></a> docs(client): use Method::POST to match the example in <a href="https://hyper.rs/guide">https://hyper.rs/guide</a>...</li>
<li><a href="41f99578a5"><code>41f9957</code></a> refactor(dependencies): update to socket2 v0.4.0 (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2472">#2472</a>)</li>
<li><a href="48fdaf1606"><code>48fdaf1</code></a> fix(headers): Support multiple Content-Length values on same line (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2471">#2471</a>)</li>
<li><a href="eb0e718696"><code>eb0e718</code></a> docs(body): add links to to_bytes and aggregate (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2464">#2464</a>)</li>
<li><a href="297a068454"><code>297a068</code></a> docs(examples): upgrade tokio version (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2456">#2456</a>)</li>
<li><a href="34085afef6"><code>34085af</code></a> docs(examples): use hyper v0.14 and full feature (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2451">#2451</a>)</li>
<li><a href="8cbf9527df"><code>8cbf952</code></a> fix(server): skip automatic Content-Length headers when not allowed (<a href="https://github-redirect.dependabot.com/hyperium/hyper/issues/2216">#2216</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/hyperium/hyper/compare/v0.14.4...v0.14.5">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=hyper&package-manager=cargo&previous-version=0.14.4&new-version=0.14.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
3 years ago
bors[bot] a18c071559
Merge #384
384: Include author information in the `--help` text r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger c01cccb288
Use `tracing-log` feature flag instead of manual initialization
This also formats `log` events more nicely. Instead of

```
Mar 29 09:46:16.775  INFO log: Found message after comparing 82 lines log.target="testcontainers::core::wait_for_message" log.module_path="testcontainers::core::wait_for_message" log.file="/home/thomas/.cargo/registry/src/github.com-1ecc6299db9ec823/testcontainers-0.12.0/src/core/wait_for_message.rs" log.line=35
```

We now have

```
Mar 29 09:57:15.860  INFO testcontainers::core::wait_for_message: Found message after comparing 81 lines
```
3 years ago
Thomas Eizinger c5827f84ca
Refactor recursive function to loop
This should get rid of the ever-growing stack size issue.
3 years ago
Thomas Eizinger fc175a3f53
De-couple state from Monero wallet 3 years ago
Thomas Eizinger 42b6368298
Use full-qualified path for tracing macros
Saves an import line and makes it clear that we are using tracing.
3 years ago
Thomas Eizinger 5616683d7d
Monero confirmations are a u64
Trying to deserialize the number as a u32 caused deserialization
errors.
3 years ago
Thomas Eizinger 1b63d5486d
Move tick to the beginning of the loop
This ensures that we always wait for the provided interval, even in
the case of a `continue` which happens if there is an error within
the RPC call.
3 years ago
Thomas Eizinger 393ed45b9e
Say who we are in the `--help` message
The message now says:

swap 0.3.0
The COMIT guys <hello@comit.network>
CLI for swapping BTC for XMR

USAGE:
    swap [FLAGS] [OPTIONS] <SUBCOMMAND>

...
3 years ago
Thomas Eizinger 39b27e37d8
Delete empty file 3 years ago
rishflab a3e85526c6 Specify LANG env variable for monero wallet rpc for unix systems
By specifying the language we can look for a specific string to check if
 monero wallet rpc is ready
3 years ago
rishflab bc902ea63a Use language agnostic heuristic to check if monero_wallet_rpc is ready
Our strategy of searching for a english string to determine if
monero_wallet_rpc is ready is not compatible with languages other than
english. Instead we assume the monero rpc is ready if it has stopped
writing to stdout. We make a json rpc request to confirm this. A better
solution would have been to configure the monero_wallet_rpc to always
output in english but there is not command line argument to configure
the language.

Closes #353.
3 years ago
bors[bot] 7397cb5990
Merge #359
359: Bump bdk from 0.4.0 to 0.5.0 r=thomaseizinger a=dependabot[bot]

Bumps [bdk](https://github.com/bitcoindevkit/bdk) from 0.4.0 to 0.5.0.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/bitcoindevkit/bdk/blob/master/CHANGELOG.md">bdk's changelog</a>.</em></p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="f7944e871b"><code>f7944e8</code></a> Bump version to 0.5.0</li>
<li><a href="2fea1761c1"><code>2fea176</code></a> Bump deps version</li>
<li><a href="fa27ae210f"><code>fa27ae2</code></a> Update version in lib.rs</li>
<li><a href="46fa41470e"><code>46fa414</code></a> Update CHANGELOG with the new release tag</li>
<li><a href="8ebe7f0ea5"><code>8ebe7f0</code></a> Merge commit 'refs/pull/308/head' of github.com:bitcoindevkit/bdk into releas...</li>
<li><a href="eb85390846"><code>eb85390</code></a> Merge commit 'refs/pull/309/head' of github.com:bitcoindevkit/bdk into releas...</li>
<li><a href="dc83db273a"><code>dc83db2</code></a> better derivation path building</li>
<li><a href="201bd6ee02"><code>201bd6e</code></a> better derivation path building</li>
<li><a href="396ffb42f9"><code>396ffb4</code></a> handle descriptor xkey origin</li>
<li><a href="9cf62ce874"><code>9cf62ce</code></a> [ci] Manually install libclang-common-10-dev to 'check-wasm' job</li>
<li>Additional commits viewable in <a href="https://github.com/bitcoindevkit/bdk/compare/v0.4.0...v0.5.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=bdk&package-manager=cargo&previous-version=0.4.0&new-version=0.5.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
bors[bot] 9c9b1e4f0c
Merge #370
370: No Bitcoin deposit for Alice r=da-kami a=da-kami

The message to deposit Bitcoin only applies to Bob, not Alice.
Alice does not require any initial Bitcoin.

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Thomas Eizinger 1057d115d1
Re-order bob::event_loop based on importance 3 years ago
Thomas Eizinger 638a169a04
Buffer transfer proof if we are not connected to Bob
The request-response behaviour that is used for sending the transfer
proof actually has a functionality for buffering a message if we
are currently not connected. However, the request-response behaviour
also emits a dial attempt and **drops** all buffered messages if this
dial attempt fails. For us, the dial attempt will very likely always
fail because Bob is very likely behind NAT and we have to wait for
him to reconnect to us.

To mitigate this, we build our own buffer within the EventLoop and
send transfer proofs as soon as we are connected again.

Resolves #348.
3 years ago
Thomas Eizinger cde3f0f74a
Remove connection handling from swap execution
The swap should not be concerned with connection handling. This is
the responsibility of the overall application.

All but the execution-setup NetworkBehaviour are `request-response`
behaviours. These have built-in functionality to automatically emit
a dial attempt in case we are not connected at the time we want to
send a message. We remove all of the manual dialling code from the
swap in favor of this behaviour.

Additionally, we make sure to establish a connection as soon as the
EventLoop gets started. In case we ever loose the connection to Alice,
we try to re-establish it.
3 years ago
Daniel Karzel 1e2a3c2d32 No Bitcoin deposit for Alice
The message to deposit Bitcoin only applies to Bob, not Alice.
Alice does not require any initial Bitcoin.
3 years ago
Thomas Eizinger 804b34f6b0
Listen on all swarm events instead of just behaviour events 3 years ago
Thomas Eizinger 2200fce3f3
Pass Swarm into EventLoop
This reduces the amount of arguments we need to pass into the eventloop
at the expense of slightly more setup of the swarm.
3 years ago
Thomas Eizinger 2c9ab4f6eb
Improve code structure and error messages for running swaps
The quote message was repeated and we should set the overall
failure into a context to know what went wrong.
3 years ago
Thomas Eizinger 0c0a322a8f
Rename module to better represent what it contains
This module provides an implementation of the RequestResponseCodec
using a cbor serialization.
3 years ago
Thomas Eizinger 1de0b39b32
Unify encrypted-signature protocol to a single one 3 years ago
Thomas Eizinger 9979cc9f1f
Unify transfer-proof protocol to a single one
Previously, we had two implementations of this protocol. To reduce
code size, we make Alice and Bob use the same implementation.
3 years ago
Thomas Eizinger 9d0b9abde0
Introduce helper function for mapping RequestResponseEvent
Decomposing a RequestResponseEvent is quite verbose. We can introduce
a helper function that does the matching for us and delegates to
specific `From` implementations for the protocol specific bits.
3 years ago
Thomas Eizinger 73f30320a6
Seed should neither be Clone nor Copy
It is better to not copy around secret data within our process to
make heartbleed-like attacks harder.
3 years ago
Thomas Eizinger 96b2a76971
Take advantage of upgraded electrum-client dependency
The new version implements std::error::Error and fixes a bug that
allows us to use the default config again.
3 years ago
bors[bot] 968502827a
Merge #339
339: Bump dependency versions r=thomaseizinger a=thomaseizinger

Otherwise it will take a long time for dependabot to update all of
these.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
bors[bot] 097197783c
Merge #351
351: Show the actual BTC amount and fee to be swapped r=da-kami a=da-kami

We got user feedback, that it is confusing that the amount "found" in the wallet does not match the amount actually being swapped, thus with this PR we explicitly display the amount swapped and fees.

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
bors[bot] 189a13c063
Merge #319
319: Alice sweeps refunded funds into default wallet r=da-kami a=da-kami

Alice's refund scenario starts with generating the temporary wallet
from keys to claim the XMR which results in Alice' unloading the wallet.
Alice then loads her original wallet to be able to handle more swaps.
Since Alice is in the role of the long running daemon handling concurrent
swaps, the operation to close, claim and re-open her default wallet must
be atomic.
This PR adds an additional step, that sweeps all the refunded XMR back into
the default wallet. In order to ensure that this is possible, Alice has to
ensure that the locked XMR got enough confirmations.
These changes allow us to assert Alice's balance after refunding.

Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 62079fc342 Punish scenario falls back to refund or fails
If we enter a punish scenario we can be sure the punish timelock is expired.
Thus, we must be able to punish unless Bob published the refund transaction.
There is no benefit in racing punish against refund here, because we cannot recover from a punish tx failure anyway.

The logic was changed to:
Try to broadcast punish tx and await finality.
  If either punish broadcasting of finality fails, try to fetch the refund transaction.
    If it is available extract Bob's Monero key part and transition to refund.
    If refund tx is not available fail without a status update.

Note that we do not distinguish different errors upon failure of punish, because
we cannot recover anyway. If we fail to retrieve Bob's refund tx, we just exit without
a status update so punish can be retried by resuming the swap.
3 years ago
Thomas Eizinger a228349d8b
Bump dependency versions
Otherwise it will take a long time for dependabot to update all of
these.
3 years ago
Daniel Karzel 668d34080d Show the actual BTC amount and fee to be swapped 3 years ago
Thomas Eizinger f49f8977d3
Remove dead code 3 years ago
Daniel Karzel 396c4177a6 Alice sweeps refunded funds into default wallet
Since Alice's refund scenario starts with generating the temporary wallet
from keys to claim the XMR which results in Alice' unloading the wallet.
Alice then loads her original wallet to be able to handle more swaps.
Since Alice is in the role of the long running daemon handling concurrent
swaps, the operation to close, claim and re-open her default wallet must
be atomic.
This PR adds an additional step, that sweeps all the refunded XMR back into
the default wallet. In order to ensure that this is possible, Alice has to
ensure that the locked XMR got enough confirmations.
These changes allow us to assert Alice's balance after refunding.
3 years ago
Thomas Eizinger 16dfea035b
Simplify code within BobState::XmrLockProofReceived
To achieve this, we decompose `watch_for_locked_xmr` into two parts:

1. A non-self-consuming function to construct a `WatchRequest`
2. A state transition that can now consume `self` again because
it is only called once within the whole select! expression.

Ideally, we would move more logic onto this state transition (like
comparing the actual amounts and fail the transition if it is not
valid). Doing so would have an unfortunate side-effect: We would
always wait for the full confirmations before checking whether or
not we actually receive enough XMR.

This allows us to have state transitions that consume self.
3 years ago
Thomas Eizinger 338f4b82e5
Introduce dedicated bob::State6 for cancelling 3 years ago
Thomas Eizinger c32ef92cf5
Simplify code within BobState::EncSigSent 3 years ago
Thomas Eizinger 09e2d5b5d7
Simplify code within BobState::XmrLocked
By reducing the number of local variables, we can greatly simplify
this piece of code.
3 years ago
Thomas Eizinger 776a50137d
Use tokio::select macro instead of function
This is slightly less verbose and therefore hopefully easier to read.
3 years ago
Thomas Eizinger b1affe3ecf
Insert latest state and call run_until only once
Instead of calling this function in all the branches, we can simply
make the whole match statement evaluate to the new state and perform
this functionality at the very end.
3 years ago
Thomas Eizinger 0d8962762a
Use early return to reduce one level of indentation 3 years ago
Thomas Eizinger 05849505b1
Inline `wait_for_bitcoin_refund`
This function is essentially a single select! statement and can
easily be inlined into the swap state machine.
3 years ago
Thomas Eizinger 8c9285f1f9
Inline step function because it has been reduced to a single statement 3 years ago
Thomas Eizinger afb7e816a1
Don't wait for confirmations again
We only call this function within `CancelTimelockExpired`. There is
no need to check the confirmations again.
3 years ago
Thomas Eizinger c92f2dbc77
Move more domain knowledge onto the `TxCancel` type 3 years ago
Thomas Eizinger 75aec95b0c
Introduce monero::TransferRequest
This allows us to move critical crypto logic onto `State3` which
holds all the necessary data which consequently allows us to get
rid of `lock_xmr` altogether by inlining it into the swap function.
The reduced indirection improves readability.
3 years ago
Thomas Eizinger d682433ec9
Move `EventLoopHandle` next to its impl block
This struct is not that important so it can move further down.
3 years ago
Thomas Eizinger e77f1729b4
Move `extract_monero_private_key` onto TxRefund
This functionality is domain-specific to the refund transaction.
Move it onto there.
3 years ago
Thomas Eizinger a1e065b4e7
Simplify racing cancel timelock against learning enc-sig 3 years ago
Thomas Eizinger 575893fb51
Use domain types in fn signature instead of messages
This simplifies usage witin the swap module.
3 years ago
Thomas Eizinger 64b71d0b16
Remove unnecessary pinning 3 years ago
Daniel Karzel 105e291e67 Update the application name for `--version` print
swap --version
xmr-btc-swap 0.3.0

asb --version
xmr-btc-asb 0.3.0
3 years ago
bors[bot] 2c385ee7d9
Merge #321
321: Properly handle concurrent messages to and from peers r=thomaseizinger a=thomaseizinger

Previously, we were forwarding incoming messages from peers to all
swaps that were currently running. That is obviously wrong. The new
design scopes an `EventLoopHandle` to a specific PeerId to avoid
this problem.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
bors[bot] 113f2fa385
Merge #322
322: Refactor `ExecutionParams` and harmonize sync intervals of wallets r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
bors[bot] fc28609a96
Merge #323 #324
323: Minor fixes r=thomaseizinger a=rishflab



324: Enable dependabot r=thomaseizinger a=thomaseizinger



Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger e54d26b26c
Improve log messages by including PeerId 3 years ago
Thomas Eizinger a57f88d1b4
Properly handle concurrent messages to and from peers
Previously, we were forwarding incoming messages from peers to all
swaps that were currently running. That is obviously wrong. The new
design scopes an `EventLoopHandle` to a specific PeerId to avoid
this problem.
3 years ago
Thomas Eizinger ce78075932
Make Monero and Bitcoin wallet use a generalized sync interval
We define the sync interval as 1/10th of the blocktime. For the
special case of our tests, we however check at max once per second.
The tests have a super fast blocktime. As such we shouldn't hammer
the nodes with a request every 100ms.
3 years ago
Thomas Eizinger 09c41f89c4
Rename ExecutionParams to EnvironmentConfig 3 years ago
Thomas Eizinger bc43ed6ebd
Pass execution params directly into wallet for initialization
This reduces the amount of parameters that we need to pass in.
3 years ago
Thomas Eizinger 7213907a79
Group bitcoin and monero fields together 3 years ago
bors[bot] 95acbc6277
Merge #307
307: Reduce load on electrum r=thomaseizinger a=rishflab

.

Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
rishflab 8675d88727 Don't wait for tx lock confirmed after broadcast
Bob does not care whether tx lock is confirmed. That is alice's problem.
This wait was introduced to remedy a bug in status_of_script() which was
 failing when called on a transaction with no confirmations.
3 years ago
rishflab f5e6ba18e0 Use different address for redeem and punish
Having the same address could potentially cause issues when subscribing
to transactions by script
3 years ago
bors[bot] 345bc5b316
Merge #320
320: Fix env filter for asb r=thomaseizinger a=thomaseizinger

1. The asb didn't log any if the statements within main.rs
2. We were initializing unnecessary filters that don't make any sense
for the asb. warp and http are not used and the harness-es are for
test only.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
bors[bot] 9ed5ca9a04
Merge #317
317: Fix monero refresh interval r=thomaseizinger a=thomaseizinger

The comparison should be the MAXIMUM of the two values, not the
minimum, otherwise we always refresh at an interval of 1 second.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger 9e3a104b42
Disable timestamp if we log to a non-interactive terminal
A non-interactive terminal is likely something along the lines of
journalctl which captures a timestamp by itself. In theory, it could
also be just a logfile but we rather accept this limitation and keep
the configuration surface simple rather than exposing another config
switch.
3 years ago
Thomas Eizinger edb8851ce2
Fix env filter for asb
1. The asb didn't log any if the statements within main.rs
2. We were initializing unnecessary filters that don't make any sense
for the asb. warp and http are not used and the harness-es are for
test only.
3 years ago
Thomas Eizinger 273cf15631
Introduce `Watchable` abstraction for Bitcoin wallet
We have a repeated pattern where we construct one of our
Tx{Cancel,Redeem,Punish,Refund,Lock} transactions and wait until
the status of this transaction changes. We can make this more
ergonomic by creating and implementing a `Watchable` trait that
gives access to the TxId and relevant script for this transaction.
This allows us to remove a parameter from the `watch_until_status`
function.

Additionally, there is a 2nd pattern: "Completing" one of these
transaction and waiting until they are confirmed with the configured
number of blocks for finality. We can make this more ergonomic by
returning a future from `broadcast` that callers can await in case
they want to wait for the broadcasted transaction to reach finality.
3 years ago
Thomas Eizinger a0830f099f
Pass relevant execution params into wallet instead of via functions
The execution params don't change throughout the lifetime of the
program. They can be set in the wallet at the very beginning.
This simplifies the interface of the wallet functions.
3 years ago
Thomas Eizinger 84ea092a1b
Remove unnecessary state variables by constructing TXs on demand 3 years ago
rishflab e5c0158597
Greatly reduce load onto the Electrum backend
We achieve our optimizations in three ways:

1. Batching calls instead of making them individually.

To get access to the batch calls, we replace all our
calls to the HTTP interface with RPC calls.

2. Never directly make network calls based on function
calls on the wallet.

Instead, inquiring about the status of a script always
just returns information based on local data. With every
call, we check when we last refreshed the local data and
do so if the data is considered to be too old. This
interval is configurable.

3. Use electrum's notification feature to get updated
with the latest blockheight.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Rishab Sharma <rishflab@hotmail.com>
3 years ago
Thomas Eizinger e17cbadccb
Don't add signatures to transaction unless necessary
In order to compute the cancel TxID, we don't need to add the
signatures.
3 years ago
Thomas Eizinger 6beb732e35
Eliminate `build_bitcoin_punish_transaction`
We reduce indirection by constructing TxPunish directly based off
`State3` and make the type itself more powerful by moving the logic
of completing it with a signature onto it.
3 years ago
Daniel Karzel ea05c306e0 Alice spawns swaps outside the event loop
Instead of spawning the swap inside the event loop we send the swap back
to the caller to be spawned. This means we no longer need the remote handle
that was only used in the tests.
This now properly logs the swap results in production.
It also gives us more control over Alice's swap in the tests.
3 years ago
Thomas Eizinger dd6c66a594
Move completing of Bitcoin redeem tx onto RedeemTx
This allows us to have access to RedeemTx from within the scope
of the state transition which we are going to need for more
efficient watching of what happens to this TX on the blockchain.
3 years ago
rishflab 21429f24b2
Inline wait_for_locked_bitcoin() that is only called once
Reduce indirection.
3 years ago
rishflab 6a3e4802f1
Remove redundant reference 3 years ago
rishflab 458a8d594a
Rename fn param to correctly reflect underlying type 3 years ago
Thomas Eizinger 2704245ed5
Fix monero refresh interval
The comparison should be the MAXIMUM of the two values, not the
minimum, otherwise we always refresh at an interval of 1 second.
3 years ago
Daniel Karzel 0091b6cdaf Remove CLI config file in favour of parameters
The CLI has sensible default values for all parameters,
thus a config file is not really an advantage but just
keeps getting in our way, so re remove it.
3 years ago
bors[bot] 009597ac49
Merge #306
306: Fix logging and retrying of Monero transaction watching r=thomaseizinger a=thomaseizinger

Hopefully, this should also reduce the load because I am not asking the node every second.

Related: https://github.com/comit-network/xmr-btc-swap/issues/202

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel be52892e65
Monero wallet should not know about all execution params
Instead of passing all execution params in we only make the monero_avg_block_time known to the monero wallet.
3 years ago
Thomas Eizinger 82738b111e
Refactor `monero::Wallet::watch_for_transfer` to not use `backoff`
Instead, we use a regular loop and extract everything into a function
that can be independently tested.
`backoff` would be useful to retry the actual call to the node.
3 years ago
Thomas Eizinger 7e0c44ad1d
Add avg monero block time to execution params 3 years ago
Thomas Eizinger d560e69203
Make durations more readable by using extension methods from `time` 3 years ago
Thomas Eizinger ecff1d1cbe
Remove indirection of constants
We never use these constants anywhere else, inline them.
3 years ago
Thomas Eizinger bac0f11898
Disable `backoff`s `max_elapsed_time` functionality
This config setting makes backoff stop retrying if we didn't get an
error within this timeframe.
For us, this results in backoff not actually doing anything.

The connection to kraken is very long-running. It might be active
for hours without failing. However, the default value for
`max_elapsed_time` is set to 15 minutes. As such, once the connection
fails any time after that, backoff doesn't actually retry the operation
but just gives up.

Fixes #303.
3 years ago
Thomas Eizinger 9ad2160c69
Refactor the kraken module to automatically re-connect on errors
In order to be able to re-connect on certain errors, we model
connection errors separately from parsing errors. We also change
the API of the whole module to no longer forward all errors to
the subscribers but instead, only update the subscribers with
either a latest rate or a permanent failure in case we exhausted
all our options to re-connect the websocket.

To model all of this properly, we introduce to sub-modules so that
each submodule can have their own `Error` type.

Resolves #297.
3 years ago
Thomas Eizinger c560b3b21a
Introduce `RateUpdate` type alias to reduce duplication 3 years ago
Thomas Eizinger fd5b38739a
Remove constant in favor of inlining string
This removes an import and simplifies the `connect_async` call.
3 years ago
Thomas Eizinger 142e5e2d3a
Use tracing macros by fully-qualifying them 3 years ago
bors[bot] cc131ecf60
Merge #293
293: Some friday evening goodies r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 years ago
Thomas Eizinger 08923a14f3
Simplify GET request for block tip height 3 years ago
Thomas Eizinger e9d7d9299c
Simplify the GET request to the tx status URL 3 years ago
Thomas Eizinger 418ad7089d
Make tests more readable by following arrange-act-assert 3 years ago
Thomas Eizinger c2329b19a2
Tell the user more about the monero lock transaction
First, we tell the user that we are now waiting for Alice to lock
the monero. Additionally, we tell them once we received the
transfer proof which will lead directly into the
"waiting for confirmations" function.
3 years ago
Thomas Eizinger 13c4d29d40
Tell the user immediately how many confirmations we expect
Without this, the user doesn't see a message before the first
confirmation.
3 years ago
Thomas Eizinger 4883e23dd8
Tell the user for how many confirmations we are waiting
Without this, the user has no idea for how long the program is
waiting.
3 years ago
Thomas Eizinger 5d4cf40831
Fix comparison of Monero confirmations 3 years ago
rishflab f92a8ac300 Improve CLI help comments and "type" hints
The type hints are generated from the field names. This has the
unfortunate consequence of the config field becoming file_path which
does not really make sense people working on the codebase.
3 years ago
Daniel Karzel 196557b377 Rename binary to swap 3 years ago
Daniel Karzel f8b61e2e0e Make monero daemon host configurable 3 years ago
Daniel Karzel f091402c7a Remove parameter duplication by introducing structs 3 years ago
Thomas Eizinger c826a28911
Add context if we fail to compute extended private key 3 years ago
Thomas Eizinger 1aa6d177bf
Improve error messages when determining BTC amount to be swapped 3 years ago
Thomas Eizinger 4138039ea0
Make sure all error messages start with an uppercase letter
These might potentially be shown to a user, let's make them all
consistent.
3 years ago
Thomas Eizinger 816e8b9b96
Add more context to fallible functions inside bitcoin::Wallet 3 years ago
Thomas Eizinger 5c24a46298
Improve error message if stuff fails directly in main 3 years ago
Thomas Eizinger 37f97ac471
Shorten function name
The variable will always be at least called `wallet`, hence we can
omit the `_wallet` postfix from the function name.
3 years ago
Thomas Eizinger 4f66269887
Move error message on sync _into_ the function
The bitcoin::Wallet::sync_wallet function doesn't do anything else
other than delegating. As such, we have just as much information
about what went wrong inside this function as we have outside.

By moving the .context call into the function, we can avoid repeating
us on every call-site.
3 years ago
Thomas Eizinger 5953037b81
Don't repeat the module name within the type 3 years ago
Thomas Eizinger 87f928f56c
Move const to function where it is used 3 years ago
Thomas Eizinger 4642e6c0e3
Simplify arguments to `init_XYZ_wallet` functions
This makes the function calls fit onto one line.
3 years ago
Thomas Eizinger d0db6cba10
Favour individual logs over one in main 3 years ago
bors[bot] 2041f367c6
Merge #288
288: Switch to public stagenet node that works r=rishflab a=rishflab

The xmr.to node has been unreliable lately. The exan.tech node seems to
working.

@da-kami is following up with making this configurable. Lets get this in so we can get a release on Friday.

Co-authored-by: rishflab <rishflab@hotmail.com>
3 years ago
rishflab 754159c9f8 Switch to public stagenet node that works
The xmr.to node has been unreliable lately. The exan.tech node seems to
working.
3 years ago
Thomas Eizinger b178e95f95
Redo layout of eventloop module
1. Move internal types to the bottom and make them private
2. Sort public types by their importance
3 years ago
Thomas Eizinger 1822886cd0
Provide stronger isolation of kraken module
Instead of leaking the tokio::sync::Receiver type in our
return value, we create a newtype that implements the desired
interface. This allows us to get rid of the `RateService` structs
and instead implement `LatestRate` directly on top of this struct.

Given that `LatestRate` is only used within the event_loop module,
we move the definition of this type into there.
3 years ago
Thomas Eizinger f6ed4d65b5
Properly deal with additional messages sent from kraken 3 years ago
Thomas Eizinger 7575d412b8
Add kraken_ticker CLI for local testing of the client 3 years ago
Thomas Eizinger 60d6d50246
Extract kraken websocket client into dedicated module 3 years ago
bors[bot] 20f2e56e2d
Merge #271
271: Bob can verify that the XMR lock tx was published r=da-kami a=da-kami

The Monero `txhash` log was removed. I feel the user should have the possibility to verify that the transaction was actually published so I added the tx-hash to the confirmation output. 

We could potentially print the tx-hash when receiving the transfer proof already, but that might not add much value compared to printing it with the confirmations. 

Additionally we should allow the user to at least know when the XMR can be expected in the user's wallet, otherwise the swap ends like this:

```
2021-03-04 13:49:19   INFO Monero lock tx received 5 out of 5 confirmations
```

This is just not very informative - yes, the final transaction is an implementation detail, but I don't think we should hide the transactions from the user. By printing the tx-hash for spending from the lock-tx into the user wallet we ensure the user knows that the XMR can now be expected in the user wallet. 

--- 

To add context, here the complete log (with debug enabled) **before** this change: 

```
2021-03-04 13:30:46  DEBUG Database and seed will be stored in /Users/dakami/Library/Application Support/xmr-btc-swap
2021-03-04 13:30:46  DEBUG Starting monero-wallet-rpc on port 56145
2021-03-04 13:30:51  DEBUG Requesting quote
2021-03-04 13:30:51   INFO Received quote: 1 XMR = 0.00433500 BTC
2021-03-04 13:30:51   INFO Still got 0.01018746 BTC left in wallet, swapping ...
2021-03-04 13:30:51   INFO Spot price for 0.00500000 BTC is 1.153402537485 XMR
2021-03-04 13:30:52  DEBUG Starting execution setup with 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-04 13:30:55   INFO Published Bitcoin 3a6690a962191529892318819fb20e7f1ac4625400e64ee734056a9b2a17ad8f transaction as lock
2021-03-04 13:41:13  DEBUG Received Transfer Proof from 12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5sgBm2BwP1cqThi
2021-03-04 13:42:11   INFO Monero lock tx received 1 out of 5 confirmations
2021-03-04 13:45:33   INFO Monero lock tx received 2 out of 5 confirmations
2021-03-04 13:47:49   INFO Monero lock tx received 3 out of 5 confirmations
2021-03-04 13:48:56   INFO Monero lock tx received 4 out of 5 confirmations
2021-03-04 13:49:19   INFO Monero lock tx received 5 out of 5 confirmations
2021-03-04 13:49:19  DEBUG Encrypted signature sent
2021-03-04 13:49:19  DEBUG Alice acknowledged encrypted signature
2021-03-04 13:49:19  DEBUG watching for tx: e5569d3f0bcccac95252dffaebe74ead0360c09b76bc762de890aaa0e51afbcf
2021-03-04 13:49:20  DEBUG Received protocol error "missing transaction" from Electrum, retrying...
2021-03-04 13:49:22  DEBUG Received protocol error "missing transaction" from Electrum, retrying...
```



Co-authored-by: Daniel Karzel <daniel@comit.network>
3 years ago
Daniel Karzel 47a31760c0 Bob can verify the Monero txs by tx-hash
Print tx-hashes for monero transactions to allow Bob to look the transaction up in block explorer.

The story of Bab:
Our famous actor Bob has a brother named Bab.
In school they were often mixed up, because their names were so similar.
Eventually Bab renamed himself into Barbara, but that was even more confusing for now he
carried a female name even though he was not female. Bob wanted to help his brother and told him he
could just go for Bub. But that did not solve anything. Fun fact: Bub is actually married to Alice.
3 years ago