Commit Graph

241 Commits

Author SHA1 Message Date
Thomas Eizinger
a1e065b4e7
Simplify racing cancel timelock against learning enc-sig 2021-03-18 15:44:36 +11:00
Thomas Eizinger
575893fb51
Use domain types in fn signature instead of messages
This simplifies usage witin the swap module.
2021-03-18 15:44:35 +11:00
Thomas Eizinger
64b71d0b16
Remove unnecessary pinning 2021-03-18 15:44:31 +11:00
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>
2021-03-17 10:22:26 +00:00
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>
2021-03-17 06:25:59 +00:00
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>
2021-03-17 05:59:01 +00:00
Thomas Eizinger
e54d26b26c
Improve log messages by including PeerId 2021-03-17 16:32:19 +11:00
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.
2021-03-17 16:32:17 +11:00
Thomas Eizinger
09c41f89c4
Rename ExecutionParams to EnvironmentConfig 2021-03-17 16:31:16 +11:00
Thomas Eizinger
bc43ed6ebd
Pass execution params directly into wallet for initialization
This reduces the amount of parameters that we need to pass in.
2021-03-17 16:30:58 +11:00
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>
2021-03-17 05:10:50 +00:00
rishflab
f5e6ba18e0 Use different address for redeem and punish
Having the same address could potentially cause issues when subscribing
to transactions by script
2021-03-17 15:26:44 +11:00
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.
2021-03-16 19:24:32 +11:00
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.
2021-03-16 19:24:31 +11:00
Thomas Eizinger
84ea092a1b
Remove unnecessary state variables by constructing TXs on demand 2021-03-16 19:24:31 +11:00
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>
2021-03-16 19:24:31 +11:00
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.
2021-03-16 19:21:15 +11:00
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.
2021-03-16 18:31:46 +11:00
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.
2021-03-16 17:11:31 +11:00
rishflab
21429f24b2
Inline wait_for_locked_bitcoin() that is only called once
Reduce indirection.
2021-03-16 17:11:31 +11:00
rishflab
6a3e4802f1
Remove redundant reference 2021-03-16 17:11:30 +11:00
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.
2021-03-05 15:49:15 +11:00
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
2021-03-05 14:02:24 +11:00
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.
2021-03-05 13:56:25 +11:00
Thomas Eizinger
601bf07255
Introduce quote protocol and display it to the user before they fund
Previously, the user neither knew the price nor the maximum quantity
they could trade. We now request a quote from the user and display
it to them.

Fixes #255.
2021-03-04 16:26:27 +11:00
Thomas Eizinger
bc176bc4fb
Minor import optimizations 2021-03-04 14:48:28 +11:00
Thomas Eizinger
6d9b21cb47
Change imports_granularity to module
This reduces the overall amount of LoC that imports take up in our
codebase by almost 100.
It also makes merge-conflicts less likely because there is less
grouping together of imports that may lead to layout changes which
in turn can cause merge conflicts.
2021-03-04 14:48:13 +11:00
bors[bot]
d1363d130c
Merge #265
265: Replace quote with spot-price protocol r=thomaseizinger a=thomaseizinger

This is essentially functionally equivalent but includes some
cleanups by removing a layer of abstraction: `spot_price::Behaviour`
is now just a type-alias for a request-response behaviour.

Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-03-04 02:52:06 +00:00
bors[bot]
cba9f119b6
Merge #261
261: Sweep xmr funds from generated temp wallet r=da-kami a=da-kami

Fixes #252

Please review by commit :)
Did a few cleanups before actually doing the feature.

Please note the comment that influenced this solution: https://github.com/comit-network/xmr-btc-swap/issues/252#issuecomment-789387074



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-03 06:29:37 +00:00
Daniel Karzel
2e3c2d8edf Remove Arcs in favour of references 2021-03-03 17:23:07 +11:00
Daniel Karzel
d63790c2a6 Remove unnecessary monero wallet trait abstractions 2021-03-03 17:15:37 +11:00
Daniel Karzel
1041212a60 Work in review comments 2021-03-03 17:15:37 +11:00
Thomas Eizinger
7042ed9441
Replace quote with spot-price protocol
This is essentially functionally equivalent but includes some
cleanups by removing a layer of abstraction: `spot_price::Behaviour`
is now just a type-alias for a request-response behaviour.
2021-03-03 17:09:38 +11:00
Daniel Karzel
9f53dab3c6 Harmonize names to make more sense
The wallet is an instance of a wallet that has a name.
When we use `CreateWalletForOutputThenReloadWallet` we actually unload the wallet.
It would be cleaner to create a new instance that does that swap, but I did not go that far.
2021-03-03 17:03:34 +11:00
Thomas Eizinger
2440964385
Allow ASB to be configured with max BTC buy amount
This will make it easier to also configure the CLI to display an appropriate max amount the user has to deal with.
2021-03-03 16:56:34 +11:00
Thomas Eizinger
54bc91581f
Don't unnecessarily create async blocks
If our expression directly evaluates to a future, we don't need to
create an async block.

This requires us to have `EventLoopRun::run` consume the instance
instead of just taking a mutable reference (otherwise we run into
lifetime issues). However, that is better anyway because `run` is
an endless loop so you never get to use the handle afterwards
anyway.
2021-03-03 14:53:05 +11:00
Thomas Eizinger
a4c25080b6
Merge network::Seed into crate::Seed
This allows us to unify the way we derive new secret key material
and simplify the usage of seed by only having a single one.
2021-03-03 14:53:01 +11:00
Daniel Karzel
1b167f3eb6 Cleanup swap initialization for Alice and Bob 2021-03-03 14:07:00 +11:00
Thomas Eizinger
8c9b087e39
Unify logging of broadcasted transactions
We eliminate unnecessary layers of indirection for broadcasting logic
and force our callers to provide us with the `kind` of transaction
that we are publishing.

Eventually, we can replace this string with some type-system magic
we can derive the name from the actual transaction. For now, we just
require the caller to duplicate this information because it is faster
and good enough TM.
2021-03-02 12:51:22 +11:00
Thomas Eizinger
3a503bf95f
Shorten function name
This struct is a wallet. The only thing it can meaningfully broadcast
are transactions. The fact that they have to be signed for that is
implied. You cannot broadcast unsigned transactions.
2021-03-02 12:25:47 +11:00
Thomas Eizinger
45cff81ea5
Remove traits in favor of using the wallet struct directly
Abstracting over the individual bits of functionality of the wallet
does have its place, especially if one wants to keep a separation
of an abstract protocol library that other people can use with their
own wallets.

However, at the moment, the traits only cause unnecessary friction.
We can always add such abstraction layers again once we need them.
2021-03-02 12:22:23 +11:00
Thomas Eizinger
3d2d447fba
Improve error message
YMMV but I think this sounds better.
2021-03-02 09:49:55 +11:00
Thomas Eizinger
7387884e6d
Move log messages to the appropriate abstraction layer
Log messages are ideally as close to the functionality they are talking about, otherwise we might end up repeating ourselves on several callsites or the log messages gets outdated if the behaviour changes.
2021-03-02 09:49:33 +11:00
Thomas Eizinger
40dcf0355a
Simplify Transfer::transfer return type
We never use the fee returned from this function, remove it.
2021-03-02 09:49:30 +11:00
Daniel Karzel
8c40ee1da4 Change anyhow! to bail! in error scenarios 2021-03-01 14:24:44 +11:00
bors[bot]
7251588e79
Merge #233
233: ASB max sell amount r=thomaseizinger a=da-kami



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-03-01 01:47:34 +00:00
bors[bot]
9a32f7d405
Merge #236
236: Some wallet cleanup + watch for deposit r=thomaseizinger a=thomaseizinger



Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
2021-02-28 23:26:31 +00:00
Daniel Karzel
019d6c725a Maximum sell amount for ASB that defaults to 0.5 XMR 2021-02-26 16:48:27 +11:00
Thomas Eizinger
6c38d66864
Remove Tx arguments from add_signatures functions
The only reason we need this argument is because we need to access
the output descriptor. We can save that one ahead of time at when
we construct the type.
2021-02-26 14:36:58 +11:00
Daniel Karzel
cad6a1c3a7 ABS only sends quote response if sufficient XMR balance 2021-02-26 11:12:32 +11:00
Daniel Karzel
0945cee459 Remove traits in favour of public functions 2021-02-25 10:34:22 +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
aed8358fb7 Remove dead code 2021-02-24 14:00:17 +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
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
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
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
180e778df9 Allow blockchain calls to fail
Prior to this change, functions could not fail early on permanent errors eg. parsing a url. Merged error enums.
2021-02-16 14:57:10 +11:00
bors[bot]
4d8e801c1e
Merge #190
190: Do not pass Monero amount to the CLI r=D4nte a=D4nte

The CLI user only pass the Bitcoin amount they want to sell.

The CLI then do a quote request to nectar which provides the Monero amount the taker can get.

Co-authored-by: Franck Royer <franck@coblox.tech>
2021-02-15 22:56:50 +00:00
Franck Royer
f36f5acaf1
Remove unnecessary async block 2021-02-15 16:23:21 +11:00
Franck Royer
2dbd43e2c0
Only pass btc amount to CLI
The CLI requests a quote to nectar to know how much xmr it can get.
Also align terminology with the sequence diagram.
2021-02-15 16:20:34 +11:00
Franck Royer
144da75270
Remove redundant data 2021-02-15 16:20:34 +11:00
Franck Royer
b8a84aa34b
Avoid possible mix up between timelocks
Introduce new type to ensure no mix up happens when ordering the fields
in function calls.
2021-02-15 16:20:31 +11:00
Franck Royer
65e0e5b731
Use Remote handle to access ongoing swaps on Alice 2021-02-15 15:00:47 +11:00
Franck Royer
9ded728879
The first message is actually a quote or rate request 2021-02-12 17:05:06 +11:00
Franck Royer
6e6dc320b4
Alice event loop now handles the creation of new swaps 2021-02-10 16:42:55 +11:00
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).
2021-02-10 16:42:55 +11:00
Franck Royer
cc8b855117
Make it possible to clone a handle
This will be used for new swaps.
2021-02-10 16:42:54 +11:00
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.
2021-02-10 16:42:54 +11:00
Franck Royer
f5ca5faabf
Process execution setup failure similarly to other failures
By merging it in the failure event of the root behaviour.
2021-02-10 16:42:54 +11:00
Franck Royer
4ade5df0e5
Remove unnecessary impl block 2021-02-10 16:42:54 +11:00
Franck Royer
b5b990257a
Move Behaviour in dedicated module 2021-02-10 16:42:54 +11:00
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).
2021-02-10 16:42:54 +11:00
Franck Royer
530b9b2ea8
Remove possible mix up of timelocks when using State0::new 2021-02-10 16:42:53 +11:00
Franck Royer
39a46baa2c
Preemptively box cancel tx to avoid size difference in enum 2021-02-10 16:42:53 +11:00
Franck Royer
69363e43a3
Preemptively box encrypted signature to avoid size difference in enum 2021-02-10 16:42:53 +11:00
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.
2021-02-10 16:42:53 +11:00
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.
2021-02-09 12:13:43 +11:00
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.
2021-02-08 21:18:37 +11:00
Franck Royer
a48823a665
Re-organise Alice state to be more coherent with the msg sequence 2021-02-08 09:16:31 +11:00
Franck Royer
a7b89e2fe4
Use event_process = false for Alice
As we do not process the event, we can just implement the needed `From`
traits.
2021-02-08 09:16:29 +11:00
Franck Royer
554ae6c00e
Remove Request Response types
These are actually not needed and forces us to cater for variants when
processing requests and responses.
2021-02-08 09:15:21 +11:00
Franck Royer
5a5a1c05f7
Set appropriate name to codec 2021-02-08 09:15:21 +11:00
Franck Royer
a11e894b31
Prepend all libp2p protocols with "comit" 2021-02-08 09:15:21 +11:00
Franck Royer
cfc5cb5206
Remove dead code and combine swap request & one shot codecs 2021-02-08 09:15:20 +11:00
Franck Royer
fc2d8d3861
Rename alice::Message0 to Message0
There is now only one message0
2021-02-08 09:15:20 +11:00
Franck Royer
88bf080dc0
rename alice::Message0 to Message1 2021-02-08 09:15:20 +11:00
Franck Royer
18f326ddd1
Rename bob::Message1 to Message2
As per sequence diagram.
2021-02-08 09:15:20 +11:00
Franck Royer
0d1be52966
Rename alice::Message1 to Message3
As per sequence diagram.
2021-02-08 09:15:20 +11:00
Franck Royer
e74efd38b5
Rename bob::Message2 to Message4
As per sequence diagram.
2021-02-08 09:15:20 +11:00
Franck Royer
081237bb6f
Remove unused behaviours 2021-02-08 09:15:20 +11:00
Franck Royer
ecb54958ee
Preemptively Box few messages 2021-02-08 09:15:19 +11:00
Franck Royer
3fa4ffa82c
Implement new behaviour for execution setup 2021-02-05 16:42:46 +11:00
Franck Royer
c316ea5244
Upgrade toolchain
Needed to use libp2p-async-await
2021-02-04 15:18:33 +11:00
Franck Royer
e82383bcf6
Avoid carrying rng 2021-02-04 15:18:33 +11:00
Philipp Hoenisch
8743527df9
Remove dead code 2021-02-03 14:26:36 +11:00
Daniel Karzel
89b3775e05 Rename config to execution_params 2021-01-29 17:27:50 +11:00
Daniel Karzel
802dc61e7e Configuration for RPC urls and Bitcoin wallet name 2021-01-29 17:21:19 +11:00
Franck Royer
c25d5ff07e
Improve network logging 2021-01-29 16:13:25 +11:00
Franck Royer
f9f17b0e23
Do not consider transfer proof sent until it's ack'd 2021-01-29 15:41:50 +11:00
Franck Royer
cc76b201b5
Do not consider encrypted signature sent until it's ack'd 2021-01-29 15:41:50 +11:00
Franck Royer
704a8e7b01
Add swap id to tracing context 2021-01-29 13:29:24 +11:00
rishflab
77fc5743a2
Upgrade tokio to 1.0
Upgrade bitcoin harness dependency to latest commit

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

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

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

Upgrade reqwest to 0.11. Reqwest 0.11 uses tokio 1.0

Upgrade libp2p to 0.34 in preparation for tokio 1.0 upgrade
2021-01-29 11:36:10 +11:00
Franck Royer
2929a8f101
Use the correct protocol support 2021-01-27 14:27:59 +11:00
Franck Royer
b62ef9c2d9
Harmonizing naming 2021-01-27 14:25:45 +11:00
Franck Royer
8fd2620b83
Improve names for messages 4 and 5 2021-01-27 14:16:31 +11:00
Franck Royer
33db688e3a
Bob peer id can be retrieved from the DB
This remove branches where Alice resumes from the DB but cannot contact
Bob.
2021-01-22 17:19:20 +11:00
Franck Royer
a910bc2046
Box all messages in enum
The messages are very different, best to box them and save size on the
stack as an enum takes as much space on the stack than its bigger
variant.
2021-01-22 17:19:20 +11:00
Franck Royer
d2a1937f51
Use Message4 2021-01-22 17:19:20 +11:00
Franck Royer
124d6f1ebb
Introduced Message 4 sent by Alice to replace message 2 response 2021-01-22 17:00:40 +11:00
Franck Royer
edb93624f3
Introduce one shot code
To allow alice to be the requester for message 4.
2021-01-22 16:57:34 +11:00
Franck Royer
9a5e35c1bd
Rename bob::Message2 to Message5
As per the proposed changed in the sequence diagram.
The aim is to have a unique terminology per message instead of having
the same name for 2 consequent messages that share the same behaviour.

Note that the aim is to remove the shared `RequestResponse` behaviours.
2021-01-22 16:57:32 +11:00
Franck Royer
f2a25ee49b
Move definitions out of lib.rs 2021-01-22 09:00:46 +11:00
Daniel Karzel
33a9057b1f Move run_until is_target_state comparison functions into testutils 2021-01-21 23:39:55 +11:00
Daniel Karzel
3593f5323a Bob saves lock proof after received so he can resume swap 2021-01-21 23:35:54 +11:00
Daniel Karzel
44c4b5dcea Remove newlines from import statements to avoid problems
Rust fmt automatically groups the imports (from top to bottom) as `pub use` `use crate` and `use`.
There is no need to introduce sections which cause annoyance when auto importing using the IDE.
2021-01-21 19:10:51 +11:00
bors[bot]
4e858197c9
Merge #149
149: Fix Alice redeem scenario r=da-kami a=da-kami

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

 Fix Alice redeem scenario

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



Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-01-21 06:27:38 +00:00
Franck Royer
8c76abcd37
Remove TODO
This can be tackle when migrating to SQLite
2021-01-21 12:27:32 +11:00
Franck Royer
ae8134f04e
Replace amounts messages with swap res/req 2021-01-21 12:27:30 +11:00
Daniel Karzel
6a75c840b5 Fix Alice redeem scenario
- Properly check the timelocks before trying to redeem
- Distinguish different failure scenarios and reactions to it.
    - if we fail to construct the redeem transaction: wait for cancel.
    - if we fail to publish the redeem transaction: wait for cancel but let the user know that restarting the application will result in retrying to publish the tx.
    - if we succeed to publish the tx but then fail when waiting for finality, print error to the user (secreat already leaked, the user has to check manually if the tx was included)
2021-01-21 12:13:02 +11:00
Daniel Karzel
170e90ffed Rename do_run_until to _run_until_internal 2021-01-20 10:37:16 +11:00
Daniel Karzel
0c19af9090 Refactor Alice's peer-id and identity to be handled on the outside
Doing this in the behaviour is a weird indirection that is not needed.
2021-01-19 09:16:04 +11:00
Daniel Karzel
8bf467b550 Make the factory code usable in production
- Introduce Test abstraction instead of tow harnesses, move test specific data into Test
- Change the abstraction from actors to swap, because we are creating swaps, not actors
- rename actor::swap  to run, because we are running a swap
2021-01-19 09:16:04 +11:00
Daniel Karzel
e4795fa4ee Fix recursive call to swap by using run_until
We should call run_until instead of swap.
2021-01-19 09:06:44 +11:00
bors[bot]
a7f68e4aa1
Merge #144
144: Test refactor r=da-kami a=da-kami

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

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

All remaining tasks actioned since Friday: 

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

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

Co-authored-by: rishflab <rishflab@hotmail.com>
Co-authored-by: Daniel Karzel <daniel@comit.network>
2021-01-18 04:49:52 +00:00
rishflab
f5cfe014be Fix imports 2021-01-15 10:13:39 +11:00
Daniel Karzel
f8848aca55 Describe additional state for ToDo that might cause trouble
If we wait for lock transaction confirmations immediately after sending the transaction without saving this state to the DB this might cause locking the money twice.
An additional state is needed for such a scenario.
2021-01-12 14:39:17 +11:00
Daniel Karzel
59f01ad680 Remove Todo that was already actioned
This ToDo does not add any value, I would not know what to do here.
2021-01-12 14:39:17 +11:00
Daniel Karzel
af45206fde Remember the block-height before XMR lock for generated monero wallet restore height
Speeds up wallet creation, because only the blocks after the recorded height will be scanned.
2021-01-12 13:18:49 +11:00
Franck Royer
6ffc66867c
Typo
Co-authored-by: Daniel Karzel <daniel.karzel@coblox.tech>
2021-01-11 11:39:21 +11:00
Franck Royer
047f990d05
Improve error reporting on signature verification 2021-01-11 11:39:18 +11:00
Franck Royer
17356eaff9
Do not guard waiting for encrypted signature with arbitrary timeout
We already select waiting for this message with the cancellation expiry,
 we do not need add another guard that tries to guess how long it would
 for the Monero transaction to be finalised.
2021-01-11 11:35:52 +11:00
rishflab
1c644cb377 Rename message behaviours 2021-01-09 11:47:23 +11:00
rishflab
dcea54dbf1 Move protocol parent states into appropriate module 2021-01-08 12:34:36 +11:00
rishflab
c900d12593 Merge xmr_btc crate
Created network, storage and protocol modules. Organised
files into the modules where the belong.

xmr_btc crate moved into isolated modulein swap crate.

Remove the xmr_btc module and integrate into swap crate.

Consolidate message related code

Reorganise imports

Remove unused parent Message enum

Remove unused parent State enum

Remove unused dependencies from Cargo.toml
2021-01-08 12:34:33 +11:00