tdex-network / tdex-daemon

Go implementation of the TDEX Beta Daemon
https://tdex.network
MIT License
11 stars 13 forks source link

Detach wallet #655

Closed altafan closed 1 year ago

altafan commented 2 years ago

This contains a HUGE refactor of the daemon with the main purpose of detaching the embedded wallet and make it connect to an external ocean wallet instead. Secondary, this refactors the scaffolding and file naming for app and domain layers in order to increase the readability and maintainability of the codebase.

Changes

Note: I'll provide more detailed clues about the macro changes listed above in later comments.

Closes #260. Closes #309. Closes #413. Closes #415. Closes #482. Closes #539. Closes #552. Closes #654. (Removed env vars to fix asset)

Please @tiero review.

sekulicd commented 2 years ago

Also maybe we should have docker_compose in root and have 'make dev' cmd in Makefile which would start tdexd and ocean

altafan commented 2 years ago

@sekulicd do you have any suggestion for the CodeQL failing action (InsecureSkipVerify)? I tried several things but none of them seemed to work. Not sure why now it's not working now. I didn't actually change that and before this PR it was not giving problems...

tiero commented 2 years ago

CodeQL

Shouldn't //nosec enough?

altafan commented 2 years ago

I solved by manually dismissing those alerts with "Won't fix" reason.

altafan commented 2 years ago

Changes to env vars

tiero commented 2 years ago

The daemon doesn't make use of fixed base/quote asset anymore. Any kind of market can be created.

how do we account for it when restoring? how do we know which is base and which is quote? @altafan

tiero commented 2 years ago

This env var was removed for easiness, but it can (should?) be restored.

Maybe this should be calculated dynamically looking at meempool? user may want to turn off this as "priority" or not

altafan commented 1 year ago

how do we account for it when restoring? how do we know which is base and which is quote?

The user could pass a list of base assets when restoring a wallet. In general, my intention was to move this kind of config from env var to request message so the user can pass this info at runtime.

altafan commented 1 year ago

Maybe this should be calculated dynamically looking at meempool? user may want to turn off this as "priority" or not

Let's put this on pause for now. We'll create a dedicated ticket as soon as this PR gets merged so we can discuss about it further

altafan commented 1 year ago

Changes to tdex-daemon/v2 proto compared to v1:

tiero commented 1 year ago

Changes to tdex-daemon/v2 proto compared to v1:

cc/ @Janaka-Steph

thanks to the versioning system of protobuf/buf, we are sure we can handle the v1>v2 migration

Janaka-Steph commented 1 year ago
sekulicd commented 1 year ago

I want to re-discuss/challenge the way we are handling types in different layers in this PR.

Purpose of ports pkg is to isolate core from calls to 3rd party apps/infra. In this PR we moved almost all types to ports, even some that doesnt "leave" our core. I will use GetMarketReport method as an example and its arg TimeRange type. TimeRange is simple struct or DTO used only to pass some data around as a whole, as opposed to several individual variables. Before this TimeRange was defined as struct with its validation/toDate methods and now it is defined in ports as an interface. Representing DTO(in this case TimeRange) as an interface, introduces only unnecessary complexity. In this PR we are doing validation in upper layer(handler) which i find wrong as validation should happen in method using actual struct and not somewhere outside, since like this method is only "protected" in case it is called in this flow.

To summarise things i see problematic:

  1. Representing simple structs as interfaces and then creating additional structs in different layers that implements that interface, dont see any pros only adding complexity
  2. Moving types to ports that are not "leaving" core
  3. Validation structs outside of method using actual struct, not protecting method using validated struct if called from somewhere else, eg. test

Please share your thoughts. @tiero @altafan

tiero commented 1 year ago

2. Moving types to ports that are not "leaving" core

I agree on this, better to have little code replicated, but at least we can swap all layers without breaking anything in the future.

Validation structs outside of method using actual struct

+1

altafan commented 1 year ago
* Getting `ListTrades failure - RpcError: Skip must be set to a positive number` if `page: { number: 0, size: 5 }`. Number should be at least 1. What should be the behaviour of `number: 0`? Error message should be more explicit.

@Janaka-Steph fixed.

altafan commented 1 year ago

Purpose of ports pkg is to isolate core from calls to 3rd party apps/infra. In this PR we moved almost all types to ports, even some that doesnt "leave" our core.

At the beginning, I didn't want to make the stuff defined in ports be used like cross-layer types. You have to consider that most of the interfaces defined in ports are related to the WalletService (ocean), like for example WalletAccount, TxInput, TxOutputs, etc.

Even if we get back to the prev solution (ie. each layer has its own types, even if exactly the same), most of those interface will stay there anyway because they're related to an external service.

Then, it turned out that most of these interfaces are very similar to the proto types used by the interfaces layer, while the app layer have to deal with them in any case since it has to interact with the external wallet. Because of these reasons, I decided to use the interfaces as cross-layer types.

The main advantage of this approach is that we reduce the amount of repeated code, therefore the redundancy of potential bugs, and also allows us to write validators only once for any of those types.

Validation structs outside of method using actual struct, not protecting method using validated struct if called from somewhere else, eg. test

I definitely agree with this and I'm glad it came out because I just forgot about it. As I said just above, it would be enough to add validators (and related unit tests) and use them in both interface and application layers where the types are used.