Commit Graph

505 Commits

Author SHA1 Message Date
Daniel Karzel
0945cee459 Remove traits in favour of public functions 2021-02-25 10:34:22 +11:00
Daniel Karzel
578d23d7fc Proper encapsulation of wallet boundaries through private fields 2021-02-25 10:30:24 +11:00
Daniel Karzel
947bcb6192 ASB reloads the default wallet after generate_from_keys atomically 2021-02-25 00:34:05 +11:00
Daniel Karzel
684cbe4d0b Remember monero wallet-height for Alice's refund scenario 2021-02-25 00:34:05 +11:00
Daniel Karzel
fa04775188 Rename function explicit to cancellation to cancel
For transitioning to state4 we either go into a redeem or a cancellation scenario.
The function name state4 is misleading, because it is only used for cancellation scenarios.
2021-02-25 00:34:05 +11:00
Daniel Karzel
1404057dbe Remove misleading TODO
This TDOO is misleading, because - to our current knowledge - it is impossible for
Bob to retrieve the exact inclusion block-height of the lock transaction (send by Alice).
The wallet RPC is only capable of retrieving the inclusion block height of a transaction
through `get_payments` and `get_bulk_payments` which requires the `payment_id`.
The `payment_id` can be retrieved through `get_transfer_by_txid` which states
"Show information about a transfer to/from this address." - however the address that the
transfer goes to is not part of Bob's wallet yet! Thus, it is impossible for Bob to use
`get_transfer_by_txid` which in turn means Bob is unable to use `get_payments`.

The only possible way for Bob to know the exact inclusion block/height of the lock transaction
would be if Alice sends it over to Bob. But for that Alice would have to extract it she would have
to wait for confirmation - which she currently does not and might never do. Even if she does await
the first confirmation before sending the transfer proof the solution for retrieving the inclusion
block-height is not fleshed out on her side yet.
2021-02-25 00:34:05 +11:00
Daniel Karzel
9f1deb9fdc Wrap the Monero wallet client in a Mutex
In order to ensure that we can atomically generate_from_keys and then reload a wallet,
we have to wrap the client of the monero wallet RPC inside a mutex.
When introducing the Mutex I noticed that several inner RPC calls were leaking to the
swap crate monero wallet. As this is a violation of boundaries I introduced the traits
`GetAddress`, `WalletBlockHeight` and `Refresh`.

Note that the monero wallet could potentially know its own public view key and
public spend key. If we refactor the wallet to include this information upon wallet
creation we can also generate addresses using `monero::Address::standard`.
2021-02-25 00:33:58 +11:00
Daniel Karzel
aed8358fb7 Remove dead code 2021-02-24 14:00:17 +11:00
bors[bot]
2654879ff3
Merge #218
218: Cleanup dependencies r=thomaseizinger a=thomaseizinger

Fixes https://github.com/comit-network/xmr-btc-swap/issues/208.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-02-23 05:02:55 +00:00
bors[bot]
fb2057453a
Merge #219 #221
219: Rename variables to add to understanding the code r=da-kami a=da-kami



221: Fix/improve comment explaining TxRefund encsigning r=thomaseizinger a=rishflab



Co-authored-by: Daniel Karzel <daniel@comit.network>
Co-authored-by: rishflab <rishflab@hotmail.com>
2021-02-23 03:37:26 +00:00
Thomas Eizinger
66db8e1851
Remove unnecessary log dependency
By updating `tracing_log`, we can access the re-export. That we need
to initialize the `tracing_log` adaptor.

The usage of `log::LevelFilter` for the `init_tracing` function was
conceptually incorrect. We should be using a type from the `tracing`
library here.
2021-02-23 14:30:32 +11:00
Thomas Eizinger
03078f328c
Split monero-harness into harness and rpc
This allows us to move `monero-harness` and `bitcoin-harness` into
`[dev-dependencies]` of `swap`.
2021-02-23 14:30:20 +11:00
Thomas Eizinger
2a3db9bd80
Remove unnecessary derivative dependency 2021-02-23 14:30:19 +11:00
Thomas Eizinger
f0ba80794c
Remove unnecessary serde_derive dependency declaration
We already express the same thing through the serde `derive` feature.
2021-02-23 14:30:19 +11:00
Thomas Eizinger
d54fac6fd9
Remove unnecessary tempfile prod dependency 2021-02-23 14:30:19 +11:00
Thomas Eizinger
729f4f09a8
Remove unnecessary tracing_core dependency 2021-02-23 14:30:19 +11:00
Thomas Eizinger
418aa02191
Remove unnecessary ed25519-dalek dependency 2021-02-23 14:30:14 +11:00
rishflab
8280072400 Fix/improve comment explaining TxRefund encsigning 2021-02-23 12:18:22 +11:00
Daniel Karzel
151f33ba10 Rename variables to add to understanding the code 2021-02-22 15:38:14 +11:00
bors[bot]
61a8282be1
Merge #203
203: Introduce dynamic rates r=da-kami a=D4nte



Co-authored-by: Franck Royer <franck@coblox.tech>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-22 04:36:49 +00:00
Daniel Karzel
b4ceee49df Change monitoring to default wallet
The automated swap backend (asb) requires Monero funds, because Alice is selling Monero.
We use a hardcoded default wallet named asb-wallet. This wallet is opened upon startup.
If the default wallet does not exist it will be created.
2021-02-22 15:00:06 +11:00
Daniel Karzel
9496dce917 Skip heartbeat messages 2021-02-22 14:51:22 +11:00
Thomas Eizinger
a8bfc1d686 Make LatestRate::Error require std::error::Error trait bound
This allows us to use .context instead of .map_err when calling
`latest_rate()`. For the static rate module, we simply fill in
`Infallible` which is actually better suited because it describes
that we are never using this error.
2021-02-22 13:27:47 +11:00
Thomas Eizinger
b47b06aa23 Import anyhow::Result across the codebase
There is no need to fully qualify this type because it is a type
alias for std::Result. We can mix and match the two as we want.
2021-02-22 13:26:56 +11:00
Franck Royer
519d1a5701 Log rate and amounts for Alice when doing execution setup 2021-02-22 13:26:27 +11:00
Franck Royer
b20c16df78 Improving logging on failure 2021-02-22 13:26:27 +11:00
Franck Royer
644f4c1732 Bubble up ws error to consumer
Note that because we are using `watch` channel, only a reference to the
channel value can be returned.
Hence, using custom Error that can be cloned to be able to
pass `Result` through the channel.
2021-02-22 13:26:27 +11:00
Franck Royer
92b3df4158 Introduce dynamic rates 2021-02-22 13:24:59 +11:00
bors[bot]
0359f8fbc0
Merge #216
216: To avoid CI failure wait for the balance instead of sleep r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-22 01:09:08 +00:00
bors[bot]
a6724f29af
Merge #214
214: Rename nectar to asb (automated swap backend) r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-22 00:39:19 +00:00
Daniel Karzel
bdb35c310d To avoid CI failure wait for the balance instead of sleep 2021-02-22 11:36:14 +11:00
bors[bot]
81228c9d5b
Merge #209
209: Upgrade to bdk 0.4 r=thomaseizinger a=thomaseizinger

Effectively, this also means:

- Upgrading to rust-bitcoin 0.26
- Upgrading to miniscript 5
- Upgrading monero to 0.10
- Upgrading curve25519-dalek to 3
- Upgrading bitcoin-harness to rust-bitcoin 0.26 (https://github.com/coblox/bitcoin-harness-rs/pull/21)
- Upgrade `ecdsa_fun` to latest version
- Replace `cross_curve_dleq` with `sigma_fun` (to avoid an upgrade dance on that library)

I refrained from specifying `rev`s in the Cargo.toml because we have a lock-file anyway. This should allow us to update those dependencies easier in the future by just running `cargo update -p <dependency>`.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-02-22 00:00:06 +00:00
Daniel Karzel
fe3d6f1fef Rename nectar to asb (automated swap backend) 2021-02-22 10:24:11 +11:00
Daniel Karzel
164de3c524 Properly calculate the confirmations for Bitcoin tx
Once the transaction was included into a block it has one confirmation - before inclusion it has zero.
current-block-height - transaction-block-height = zero; but that means one confirmation.
Hence, the confirmation calculation was adapted to: Current-block-height - (transaction-block-height - 1).
2021-02-19 17:09:53 +11:00
Thomas Eizinger
2d8ede80e1
Use released version of backoff 2021-02-19 15:18:40 +11:00
Thomas Eizinger
cabf0efb8c
Only construct proof system once
The proof system is a static element and can be reused several times.
2021-02-19 15:18:39 +11:00
Thomas Eizinger
84bc2c82b7
Upgrade to bdk 4.0
To achieve this we also:

- upgrade rust-bitcoin to 0.26
- upgrade bitcoin-harness to latest version (which also depends bitcoin 0.26)
- upgrade to latest edcsa-fun
- replace cross_curve_dleq proof with sigma_fun (to avoid an upgrade dance over there)
2021-02-19 15:18:37 +11:00
bors[bot]
b3f49cf83e
Merge #200
200: Wait for refund if insufficient Monero is locked up r=da-kami a=da-kami

In a scenario where Alice does not lock up sufficient funds Bob should properly transition to refunds. At the moment the CLI just panics. 
I noticed this when Alice accidentally had a different amount set than Bob. In the future this should not happen, because Alice provides the amount for Bob. However, in case Alice is malicious Bob should still transition correctly. 

Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-17 05:00:39 +00:00
bors[bot]
8537b88a68
Merge #201
201: Fix ASB - Prevent the future from being stopped in production r=da-kami a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-02-17 04:45:48 +00:00
bors[bot]
48635156ad
Merge #206
206: Remove misplaced wallet sync call r=rishflab a=rishflab

These bdk wallet sync calls must of gotten lost during a rebase. Removed the call in build TxLock and added one when nectar starts up

Co-authored-by: rishflab <rishflab@hotmail.com>
2021-02-17 03:36:25 +00:00
Daniel Karzel
babd1d7b60
Wait for refund if insufficient Monero is locked up 2021-02-17 11:58:05 +11:00
Daniel Karzel
ebb869e6f4 Distinguish transient and permanent Electrum errors 2021-02-17 11:56:17 +11:00
Daniel Karzel
9b93cabfdf Use context instead of map_error 2021-02-17 11:09:09 +11:00
rishflab
fe362d765b Add sync wallet on nectar's startup 2021-02-17 10:56:39 +11:00
rishflab
00e2b257c4 Remove misplaced sync wallet call 2021-02-17 10:56:10 +11:00
Thomas Eizinger
8c83f7e2e1
Upgrade to testcontainers v0.12 2021-02-16 17:11:25 +11:00
Daniel Karzel
2ced9ddba4 Prevent future from being stopped by calling forget on handle 2021-02-16 16:31:11 +11:00
Daniel Karzel
77ec7e502f Distinguish permanent and transient error when watching tx 2021-02-16 16:26:37 +11:00
rishflab
b66bb00c77 Remove stale code 2021-02-16 15:13:45 +11:00
rishflab
bc1d2bda54 Test URL creation for default electrum HTTP API 2021-02-16 15:13:45 +11:00