-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(tpu-v2): provide swap protocol versioning #2324
base: fix-tpu-v2-wait-for-payment-spend
Are you sure you want to change the base?
feat(tpu-v2): provide swap protocol versioning #2324
Conversation
updated my_swaps table migration, new swap_version field provided in Maker/TakerSwapStorage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this blocking anything currently? These changes look like a hacky workaround rather than a being proper solution. It would be great if we can avoid this change.
mm2src/mm2_main/src/lp_ordermatch.rs
Outdated
fn legacy_swap_version() -> u32 { 1 } | ||
|
||
fn is_legacy_swap_version(swap_version: &u32) -> bool { *swap_version == 1 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn legacy_swap_version() -> u32 { 1 } | |
fn is_legacy_swap_version(swap_version: &u32) -> bool { *swap_version == 1 } | |
const fn legacy_swap_version() -> u32 { 1 } | |
fn is_legacy_swap_version(swap_version: &u32) -> bool { *swap_version == legacy_swap_version() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided const fn 998e75a
We need swap versioning to do a legacy fallback on order matching |
mm2src/mm2_main/src/lp_ordermatch.rs
Outdated
/// In the future alls users will be using TPU V2 by default without "use_trading_proto_v2" configuration. | ||
pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { | ||
if !use_trading_proto_v2 { | ||
self.swap_version = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we reserve only single value for legacy swaps?
I think legacy swaps may exist for sometime and we should allow version grow for them too.
I suggest use a structured encoding, for e.g.:
for legacy swaps: 1.x.y
for TPU: 2.x.y
(we could encode it into u32 as 1 * 10000 + x * 100 + y)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explain how this is supposed to work and to be supported for kickstart process for example.
I really doubt we will use minor and patch versions in the current repo.
We can start legacy from 0 and reserve 1 version for legacy kmd burn implementation.
I think it will be the first and the last feature in legacy which will require explicit version separation.
zero fee shouldn't make many changes in utxo and evm code?
anyway everything which changes backward compatibility should update swap version "major" integer.
will legacy and legacy burn fee/zero fee be incompatible or not? That is only matters. Even if we dont reserve numbers before 2 for legacy, we could use next numbers after 2 for newer legacy versions. its just numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you plz add some info how swap_version is used, to the PR description?
Was it meant to have just 1 and 2 values?
I am referring to the discussion in the team chat where it was discussed to get swap parties versions from the order matching. Maybe this PR should be reconsidered after we work out that concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated PR description
I am referring to the discussion in the team chat where it was discussed to get swap parties versions from the order matching.
This PR provides swap version from order matching
Maybe this PR should be reconsidered after we work out that concept.
This PR exists due to the reason that we still dont have any conclusion related to versioning. It is blocking TPU, to launch TPU in production, we need support for a legacy fallback.
I would tell we can change versioning later in other PRs, when we see by practice what versioning approach is preferable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks
mm2src/mm2_main/src/lp_ordermatch.rs
Outdated
/// In the future alls users will be using TPU V2 by default without "use_trading_proto_v2" configuration. | ||
pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { | ||
if !use_trading_proto_v2 { | ||
self.swap_version = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use a const like LEGACY_SWAP_VERSION (indicating current version this code supports)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current version this code/repo supports is this const SWAP_VERSION
.
If use_trading_proto_v2:false
it means user didnt enable TPU
reused const fn 53d4b40
we need const function for #[serde(default = "legacy_swap_version")]
, so no need to create one more const variable.
UPD: I refactored this function a bit according to Onur notes, so please check newer commits
mm2src/mm2_main/src/lp_ordermatch.rs
Outdated
pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { | ||
if !use_trading_proto_v2 { | ||
self.swap_version = legacy_swap_version(); | ||
} | ||
self | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not this?
pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { | |
if !use_trading_proto_v2 { | |
self.swap_version = legacy_swap_version(); | |
} | |
self | |
} | |
pub fn use_trading_proto_v2(mut self) -> Self { | |
self.swap_version = legacy_swap_version(); | |
self | |
} |
or, at least rename it to something like maybe_**
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u suggested to change version to legacy protocol calling use_trading_proto_v2
please re read doc comment
/// When a new [TakerOrderBuilder::new] is created, it sets [SWAP_VERSION] by default.
/// However, if user has not specified in the config to use TPU V2,
/// the TakerOrderBuilder's swap_version is changed to legacy.
/// In the future alls users will be using TPU V2 by default without "use_trading_proto_v2" configuration.
pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I suggest is, either remove this boolean from the function and check it on the caller side or declare that in the function name with "maybe" prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I suggest is, either remove this boolean from the function and check it on the caller side
I dont get it, on the caller side it is where? Right now it looks like, you call use_trading_proto_v2
and set legacy
pub fn use_trading_proto_v2(mut self) -> Self {
self.swap_version = legacy_swap_version();
self
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated function name e37c74e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't pay attention to the logic, the usage was just unclear. Looking at the logic, it's even more unclear.. Function is called use_trading_proto_v2
but it downgrades version to legacy if given boolean is false.
Why not just this:
pub fn use_trading_proto_legacy(mut self) -> Self {
self.swap_version = legacy_swap_version();
self
}
and call it only when use_trading_proto_v2
is false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the thing is that use_trading_proto_v2 initially is a config boolean flag, so use_trading_proto_legacy is supposed to be a question
ok I refactored function, now its purpose is only to set legacy protocol a62f56a
mm2src/mm2_main/src/lp_ordermatch.rs
Outdated
pub fn use_trading_proto_v2(mut self, use_trading_proto_v2: bool) -> Self { | ||
if !use_trading_proto_v2 { | ||
self.swap_version = legacy_swap_version(); | ||
} | ||
self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
mm2src/mm2_main/src/lp_ordermatch.rs
Outdated
let alice_swap_v = maker_match.request.swap_version; | ||
|
||
// Start legacy swap if taker uses legacy protocol (version 1) or if conditions for trading_proto_v2 aren't met. | ||
if alice_swap_v == 1u32 || !ctx.use_trading_proto_v2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if alice_swap_v == 1u32 || !ctx.use_trading_proto_v2() { | |
if alice_swap_v == legacy_swap_version() || !ctx.use_trading_proto_v2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done d4c5a16
mm2src/mm2_main/src/lp_ordermatch.rs
Outdated
let bob_swap_v = taker_match.reserved.swap_version; | ||
|
||
// Start legacy swap if maker uses legacy protocol (version 1) or if conditions for trading_proto_v2 aren't met. | ||
if bob_swap_v == 1u32 || !ctx.use_trading_proto_v2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if bob_swap_v == 1u32 || !ctx.use_trading_proto_v2() { | |
if bob_swap_v == legacy_swap_version() || !ctx.use_trading_proto_v2() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done d4c5a16
@@ -706,6 +706,8 @@ mod tests { | |||
|
|||
wasm_bindgen_test_configure!(run_in_browser); | |||
|
|||
const LEGACY_SWAP_V: u32 = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
legacy_swap_version
can replace this need
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done d4c5a16
@@ -20,6 +20,8 @@ use std::collections::HashSet; | |||
use std::iter::{self, FromIterator}; | |||
use std::sync::Mutex; | |||
|
|||
const LEGACY_SWAP_V: u32 = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done d4c5a16
ordermatch structs which got swap_version field:
swap structs. if swap started swap_version will be saved in db:
swap version 2 is tpu v2 protocol
legacy swap protocol is 1 version
When Taker or Maker build order, the value
const SWAP_VERSION: u32 = 2;
is used for order Builder.However in
create_maker_order
/lp_auto_buy
if user didnt usectx.use_trading_proto_v2()
in config we set legacy protocol version to the order.