Skip to content

Commit

Permalink
revert "swap_version" field
Browse files Browse the repository at this point in the history
  • Loading branch information
laruh committed Dec 16, 2024
1 parent 653e074 commit f8ba975
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 125 deletions.
68 changes: 6 additions & 62 deletions mm2src/mm2_main/src/lp_ordermatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ const TRIE_STATE_HISTORY_TIMEOUT: u64 = 3;
const TRIE_ORDER_HISTORY_TIMEOUT: u64 = 300;
#[cfg(test)]
const TRIE_ORDER_HISTORY_TIMEOUT: u64 = 3;
/// Swap protocol version
const SWAP_VERSION: u32 = 2;

pub type OrderbookP2PHandlerResult = Result<(), MmError<OrderbookP2PHandlerError>>;

Expand Down Expand Up @@ -1172,9 +1170,6 @@ pub struct TakerRequest {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub rel_protocol_info: Option<Vec<u8>>,
#[serde(default = "legacy_swap_version")]
#[serde(skip_serializing_if = "is_legacy_swap_version")]
pub swap_version: u32,
}

impl TakerRequest {
Expand All @@ -1195,7 +1190,6 @@ impl TakerRequest {
conf_settings: Some(message.conf_settings),
base_protocol_info: message.base_protocol_info,
rel_protocol_info: message.rel_protocol_info,
swap_version: message.swap_version,
}
}

Expand Down Expand Up @@ -1241,7 +1235,6 @@ impl From<TakerOrder> for new_protocol::OrdermatchMessage {
conf_settings: taker_order.request.conf_settings.unwrap(),
base_protocol_info: taker_order.request.base_protocol_info,
rel_protocol_info: taker_order.request.rel_protocol_info,
swap_version: taker_order.request.swap_version,
})
}
}
Expand All @@ -1252,10 +1245,6 @@ impl TakerRequest {
fn get_rel_amount(&self) -> &MmNumber { &self.rel_amount }
}

fn legacy_swap_version() -> u32 { 1 }

fn is_legacy_swap_version(swap_version: &u32) -> bool { *swap_version == 1 }

pub struct TakerOrderBuilder<'a> {
base_coin: &'a MmCoinEnum,
rel_coin: &'a MmCoinEnum,
Expand All @@ -1271,7 +1260,6 @@ pub struct TakerOrderBuilder<'a> {
min_volume: Option<MmNumber>,
timeout: u64,
save_in_history: bool,
swap_version: u32,
}

pub enum TakerOrderBuildError {
Expand Down Expand Up @@ -1351,7 +1339,6 @@ impl<'a> TakerOrderBuilder<'a> {
order_type: OrderType::GoodTillCancelled,
timeout: TAKER_ORDER_TIMEOUT,
save_in_history: true,
swap_version: SWAP_VERSION,
}
}

Expand Down Expand Up @@ -1415,17 +1402,6 @@ impl<'a> TakerOrderBuilder<'a> {
self
}

/// 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 {
if !use_trading_proto_v2 {
self.swap_version = 1;
}
self
}

/// Validate fields and build
#[allow(clippy::result_large_err)]
pub fn build(self) -> Result<TakerOrder, TakerOrderBuildError> {
Expand Down Expand Up @@ -1514,7 +1490,6 @@ impl<'a> TakerOrderBuilder<'a> {
conf_settings: self.conf_settings,
base_protocol_info: Some(base_protocol_info),
rel_protocol_info: Some(rel_protocol_info),
swap_version: self.swap_version,
},
matches: Default::default(),
min_volume,
Expand Down Expand Up @@ -1555,7 +1530,6 @@ impl<'a> TakerOrderBuilder<'a> {
conf_settings: self.conf_settings,
base_protocol_info: Some(base_protocol_info),
rel_protocol_info: Some(rel_protocol_info),
swap_version: self.swap_version,
},
matches: HashMap::new(),
min_volume: Default::default(),
Expand Down Expand Up @@ -1717,9 +1691,6 @@ pub struct MakerOrder {
/// A custom priv key for more privacy to prevent linking orders of the same node between each other
/// Commonly used with privacy coins (ARRR, ZCash, etc.)
p2p_privkey: Option<SerializableSecp256k1Keypair>,
#[serde(default = "legacy_swap_version")]
#[serde(skip_serializing_if = "is_legacy_swap_version")]
pub swap_version: u32,
}

pub struct MakerOrderBuilder<'a> {
Expand All @@ -1732,7 +1703,6 @@ pub struct MakerOrderBuilder<'a> {
rel_orderbook_ticker: Option<String>,
conf_settings: Option<OrderConfirmationsSettings>,
save_in_history: bool,
swap_version: u32,
}

pub enum MakerOrderBuildError {
Expand Down Expand Up @@ -1882,7 +1852,6 @@ impl<'a> MakerOrderBuilder<'a> {
price: 0.into(),
conf_settings: None,
save_in_history: true,
swap_version: SWAP_VERSION,
}
}

Expand Down Expand Up @@ -1921,17 +1890,6 @@ impl<'a> MakerOrderBuilder<'a> {
self
}

/// When a new [MakerOrderBuilder::new] is created, it sets [SWAP_VERSION] by default.
/// However, if user has not specified in the config to use TPU V2,
/// the MakerOrderBuilder'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 {
if !use_trading_proto_v2 {
self.swap_version = 1;
}
self
}

/// Build MakerOrder
#[allow(clippy::result_large_err)]
pub fn build(self) -> Result<MakerOrder, MakerOrderBuildError> {
Expand Down Expand Up @@ -1988,7 +1946,6 @@ impl<'a> MakerOrderBuilder<'a> {
base_orderbook_ticker: self.base_orderbook_ticker,
rel_orderbook_ticker: self.rel_orderbook_ticker,
p2p_privkey,
swap_version: self.swap_version,
})
}

Expand All @@ -2013,7 +1970,6 @@ impl<'a> MakerOrderBuilder<'a> {
base_orderbook_ticker: None,
rel_orderbook_ticker: None,
p2p_privkey: None,
swap_version: self.swap_version,
}
}
}
Expand Down Expand Up @@ -2144,7 +2100,6 @@ impl From<TakerOrder> for MakerOrder {
base_orderbook_ticker: taker_order.base_orderbook_ticker,
rel_orderbook_ticker: taker_order.rel_orderbook_ticker,
p2p_privkey: taker_order.p2p_privkey,
swap_version: taker_order.request.swap_version,
},
// The "buy" taker order is recreated with reversed pair as Maker order is always considered as "sell"
TakerAction::Buy => {
Expand All @@ -2167,7 +2122,6 @@ impl From<TakerOrder> for MakerOrder {
base_orderbook_ticker: taker_order.rel_orderbook_ticker,
rel_orderbook_ticker: taker_order.base_orderbook_ticker,
p2p_privkey: taker_order.p2p_privkey,
swap_version: taker_order.request.swap_version,
}
},
}
Expand Down Expand Up @@ -2220,9 +2174,6 @@ pub struct MakerReserved {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub rel_protocol_info: Option<Vec<u8>>,
#[serde(default = "legacy_swap_version")]
#[serde(skip_serializing_if = "is_legacy_swap_version")]
pub swap_version: u32,
}

impl MakerReserved {
Expand Down Expand Up @@ -2250,7 +2201,6 @@ impl MakerReserved {
conf_settings: Some(message.conf_settings),
base_protocol_info: message.base_protocol_info,
rel_protocol_info: message.rel_protocol_info,
swap_version: message.swap_version,
}
}
}
Expand All @@ -2267,7 +2217,6 @@ impl From<MakerReserved> for new_protocol::OrdermatchMessage {
conf_settings: maker_reserved.conf_settings.unwrap(),
base_protocol_info: maker_reserved.base_protocol_info,
rel_protocol_info: maker_reserved.rel_protocol_info,
swap_version: maker_reserved.swap_version,
})
}
}
Expand Down Expand Up @@ -3048,9 +2997,8 @@ fn lp_connect_start_bob(ctx: MmArc, maker_match: MakerMatch, maker_order: MakerO
},
};

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() {
// TODO add alice swap protocol version check once protocol versioning is implemented
if !ctx.use_trading_proto_v2() {
let params = LegacySwapParams {
maker_coin: &maker_coin,
taker_coin: &taker_coin,
Expand Down Expand Up @@ -3269,9 +3217,8 @@ fn lp_connected_alice(ctx: MmArc, taker_order: TakerOrder, taker_match: TakerMat
uuid
);

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() {
// TODO add bob swap protocol version check once protocol versioning is implemented
if !ctx.use_trading_proto_v2() {
let params = LegacySwapParams {
maker_coin: &maker_coin,
taker_coin: &taker_coin,
Expand Down Expand Up @@ -3926,7 +3873,6 @@ async fn process_taker_request(ctx: MmArc, from_pubkey: H256Json, taker_request:
}),
base_protocol_info: Some(base_coin.coin_protocol_info(None)),
rel_protocol_info: Some(rel_coin.coin_protocol_info(Some(rel_amount.clone()))),
swap_version: order.swap_version,
};
let topic = order.orderbook_topic();
log::debug!("Request matched sending reserved {:?}", reserved);
Expand Down Expand Up @@ -4159,8 +4105,7 @@ pub async fn lp_auto_buy(
.with_sender_pubkey(H256Json::from(our_public_id.bytes))
.with_save_in_history(input.save_in_history)
.with_base_orderbook_ticker(ordermatch_ctx.orderbook_ticker(base_coin.ticker()))
.with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker()))
.use_trading_proto_v2(ctx.use_trading_proto_v2());
.with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker()));
if let Some(timeout) = input.timeout {
order_builder = order_builder.with_timeout(timeout);
}
Expand Down Expand Up @@ -4905,8 +4850,7 @@ pub async fn create_maker_order(ctx: &MmArc, req: SetPriceReq) -> Result<MakerOr
.with_conf_settings(conf_settings)
.with_save_in_history(req.save_in_history)
.with_base_orderbook_ticker(ordermatch_ctx.orderbook_ticker(base_coin.ticker()))
.with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker()))
.use_trading_proto_v2(ctx.use_trading_proto_v2());
.with_rel_orderbook_ticker(ordermatch_ctx.orderbook_ticker(rel_coin.ticker()));

let new_order = try_s!(builder.build());

Expand Down
2 changes: 0 additions & 2 deletions mm2src/mm2_main/src/lp_ordermatch/my_orders_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ mod tests {
base_orderbook_ticker: None,
rel_orderbook_ticker: None,
p2p_privkey: None,
swap_version: LEGACY_SWAP_V,
}
}

Expand All @@ -745,7 +744,6 @@ mod tests {
conf_settings: None,
base_protocol_info: None,
rel_protocol_info: None,
swap_version: LEGACY_SWAP_V,
},
matches: HashMap::new(),
created_at: now_ms(),
Expand Down
8 changes: 1 addition & 7 deletions mm2src/mm2_main/src/lp_ordermatch/new_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mm2_rpc::data::legacy::{MatchBy as SuperMatchBy, OrderConfirmationsSettings,
use std::collections::{HashMap, HashSet};
use uuid::Uuid;

use crate::lp_ordermatch::{is_legacy_swap_version, legacy_swap_version, AlbOrderedOrderbookPair, H64};
use crate::lp_ordermatch::{AlbOrderedOrderbookPair, H64};

#[derive(Debug, Deserialize, Serialize)]
#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -265,9 +265,6 @@ pub struct TakerRequest {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub rel_protocol_info: Option<Vec<u8>>,
#[serde(default = "legacy_swap_version")]
#[serde(skip_serializing_if = "is_legacy_swap_version")]
pub swap_version: u32,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand All @@ -285,9 +282,6 @@ pub struct MakerReserved {
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub rel_protocol_info: Option<Vec<u8>>,
#[serde(default = "legacy_swap_version")]
#[serde(skip_serializing_if = "is_legacy_swap_version")]
pub swap_version: u32,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
Loading

0 comments on commit f8ba975

Please sign in to comment.