Commit Graph

67 Commits (620ac569f7db4b19c3dc761619e7a4d0ab0841dd)

Author SHA1 Message Date
Daniel Karzel c0070f8fa7
Move files from `protocol` to appropriate module
Some network and application specific code does not belong in the protocol module and was moved.
Eventloop, recovery and the outside behaviour were moved to the respective application module because they are application specific.

The `swap_setup` was moved into the network module because upon change both sides will have to be changed and should thus stay close together.
3 years ago
Daniel Karzel 818147a629
`swap_setup` instead of `spot_price` and `execution_setup`
Having `spot_price` and `execution_setup` as separate protocols did not bring any advantages, but was problematic because we had to ensure that `execution_setup` would be triggered after `spot_price`. Because of this dependency it is better to combine the protocols into one.

Combining the protocols also allows a refactoring to get rid of the `libp2p-async-await` dependency.

Alice always listens for the `swap_setup` protocol. When Bob opens a substream on that protocol the spot price is communicated, and then all execution setup messages (swap-id and signature exchange).
3 years ago
Daniel Karzel daa572e5bf
Move recovery commands in dedicated module
Less clutter in the folder structure.
3 years ago
Daniel Karzel 4deb96a3c5
ASB manual recovery commands
Adds `cancel`, `refund`, `punish`, `redeem` and `safely-abort` commands to the ASB that can be used to trigger the specific scenario for the swap by ID.
3 years ago
Daniel Karzel 52f648e1de
Alice's spot price logic into dedicated behaviour
Move Alice's spot price logic into a dedicated network behaviour that handles all the logic.
The new behaviour encapsulates the complete state necessary for spot price request decision making.
The network behaviour cannot handle asynchronous calls, thus the balance is managed inside the spot price and has to updated regularly from the outside to ensure the spot price balance check has up to date data.
At the moment the balance is updated upon an incoming quote requests.

Code that is relevant for both ASB and CLI remains in the `network::spot_price` module (e.g. `network::spot_price::Error`).
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 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 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 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 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.
3 years ago
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.
3 years ago
Daniel Karzel 1b167f3eb6 Cleanup swap initialization for Alice and Bob 3 years ago
Franck Royer 144da75270
Remove redundant data 3 years ago
Franck Royer 9ded728879
The first message is actually a quote or rate request 3 years ago
Franck Royer 6e6dc320b4
Alice event loop now handles the creation of new swaps 3 years ago
Franck Royer b5b990257a
Move `Behaviour` in dedicated module 3 years ago
Franck Royer 87be9aeb2a
Prepare separation of event loop initialisation to swap initialisation
As for Alice, the event loop will be started with the program and will
be the one starting swaps (`run_until`) based on libp2p events (swap
request).
3 years ago
Franck Royer 530b9b2ea8
Remove possible mix up of timelocks when using `State0::new` 3 years ago
Franck Royer f35ed436ce
Allow `EventLoop` to hold a database ready to pass to `alice::Buider`
The `EventLoop` will use the `Builder` interface to instantiate a
`Swap` upon receiving a `SwapRequest` and successfully doing an
execution setup.
Before this change, the `EventLoop` would have to hold the path to the
db and re-open the db everytime it wants to construct a swap.

With this change, we can open the DB once and then hold a
`Arc<Database>` in the `EventLoop` and pass it to new `Swap`s structs.
3 years ago
Franck Royer fd084b764d
Move generation of keys inside `State0::new`
The event loop will now use this function so I want to simplify its
usage to avoid having to instantiate too many items to use it.
3 years ago
Franck Royer a7b89e2fe4
Use event_process = false for Alice
As we do not process the event, we can just implement the needed `From`
traits.
3 years ago
Franck Royer 554ae6c00e
Remove Request Response types
These are actually not needed and forces us to cater for variants when
processing requests and responses.
3 years ago
Franck Royer cfc5cb5206
Remove dead code and combine swap request & one shot codecs 3 years ago
Franck Royer 88bf080dc0
rename alice::Message0 to Message1 3 years ago
Franck Royer 0d1be52966
Rename alice::Message1 to Message3
As per sequence diagram.
3 years ago
Franck Royer 081237bb6f
Remove unused behaviours 3 years ago
Franck Royer ecb54958ee
Preemptively Box few messages 3 years ago
Franck Royer 3fa4ffa82c
Implement new behaviour for execution setup 3 years ago
Franck Royer e82383bcf6
Avoid carrying rng 3 years ago
Daniel Karzel 89b3775e05 Rename config to execution_params 3 years ago
Daniel Karzel 802dc61e7e Configuration for RPC urls and Bitcoin wallet name 3 years ago
Franck Royer c25d5ff07e
Improve network logging 3 years ago
Franck Royer f9f17b0e23
Do not consider transfer proof sent until it's ack'd 3 years ago
rishflab 1597f5336b
Restart event loop in tests
Alice was attempting to create a new event loop using the same listen addr as the old one which was still running. This commit aborts the event loop before creating a new one.
3 years ago
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
3 years ago
Franck Royer 8fd2620b83
Improve names for messages 4 and 5 3 years ago
Franck Royer d2a1937f51
Use `Message4` 3 years ago
Franck Royer 124d6f1ebb
Introduced Message 4 sent by Alice to replace message 2 response 3 years ago
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.
3 years ago
Franck Royer f2a25ee49b
Move definitions out of lib.rs 3 years ago
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.
3 years ago
Franck Royer ae8134f04e
Replace amounts messages with swap res/req 3 years ago
Franck Royer c44b867d01
Delay the wrapping in Arc 3 years ago
Franck Royer 83b72c0a45
Make `make_init_state` and `init_loop` associated to `alice::SwapFactory` 3 years ago
Franck Royer c11042ff0d
Use `builder` terminology instead of `factory`
This is not really a factory as a factory design pattern is about
producing several instances.

In the current usage, we are only interested in one swap instance. Once
the swap instance is created, the factory becomes useless. Hence, it is
more of a builder pattern.
3 years ago
Franck Royer 652bfa14a9
Remove unnecessary `pub` qualifiers 3 years ago
Franck Royer b21dc03ed0
`alice::SwapFactory` should be consumed once a swap is returned 3 years ago
Franck Royer 9b32409b8d
Remove unnecessary `allow(clippy)` 3 years ago