-
Notifications
You must be signed in to change notification settings - Fork 94
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
Arrr integration WIP. #1204
Arrr integration WIP. #1204
Conversation
Hide secrets before broadcasting.
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.
Great work! Just a few questions about unclear things to me 🙂
https://github.com/KomodoPlatform/atomicDEX-API/blob/c3408e9f997bea3448716115919bf78c3c83de4e/mm2src/lp_ordermatch.rs#L415-L418 |
Yes, banning won't work. For transparent addresses, we can sign p2p messages with the privkey, which address belongs to. It will allow us to check the balance to additionally validate the order in the future. It's not possible for privacy coins so yes, there will be tradeoffs for privacy. As of now, I'm unsure how we can solve it, but we will maybe have some ideas in the future 🙂
Yes, Gossipsub mesh size is not related to it. As per specification https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.0.md#gossipsub-the-gossiping-mesh-router, the mesh is used to transfer a message to a subset of subscribed peers to Also, in our customized gossipsub version, we form a mesh for relay nodes only, which send the messages to all subscribed "light" nodes. |
It should be possible to modify a sender, but I prefer to do it on the next iteration. Orderbook sync doesn't work properly now for these temporary keys anyway. This PR goal is to merge swap-related changes as fast as possible. Added to my checklist at #927 (comment) |
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.
Great progress! First batch of comments :)
mm2src/coins/eth.rs
Outdated
@@ -64,6 +64,7 @@ pub use ethcore_transaction::SignedTransaction as SignedEthTx; | |||
pub use rlp; | |||
|
|||
mod web3_transport; | |||
use crate::TradePreimageResult; |
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 please move this import to:
use super::{BalanceError, TradePreimageResult};
mm2src/lp_swap/maker_swap.rs
Outdated
@@ -452,12 +516,29 @@ impl MakerSwap { | |||
}, | |||
}; | |||
|
|||
let taker_pubkey = taker_data.persistent_pubkey(); | |||
let (taker_pubkey, maker_coin_htlc_pubkey, taker_coin_htlc_pubkey) = match taker_pubkey.len() { | |||
33 => (taker_pubkey.into(), None, None), |
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.
How about adding a enum that consists of taker_pubkey only by default and consists of a maker/taker htlc pubkeys pair? It will allow us to save backward compatibility and avoid errors like:
return Ok((Some(MakerSwapCommand::Finish), vec![MakerSwapEvent::NegotiateFailed(
ERRL!("Unexpected persistent_pubkey field len {}", taker_pubkey.len()).into(),
)]))
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 agree enum will be better, will do it tomorrow.
mm2src/lp_swap/maker_swap.rs
Outdated
(None, None) | ||
}; | ||
|
||
let (taker_coin_htlc_privkey, taker_coin_htlc_pubkey) = if self.taker_coin.is_privacy() { |
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.
How about adding a function that generates htlc keys pair if a coin is private. The code below is the same as for maker coin
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.
Makes sense, will do.
mm2src/lp_swap/maker_swap.rs
Outdated
}; | ||
|
||
Ok((Some(MakerSwapCommand::Negotiate), vec![MakerSwapEvent::Started(data)])) | ||
} | ||
|
||
async fn negotiate(&self) -> Result<(Option<MakerSwapCommand>, Vec<MakerSwapEvent>), String> { | ||
let mut persistent_pubkey = Vec::with_capacity(33); | ||
persistent_pubkey.extend_from_slice(self.r().maker_coin_htlc_keypair.public()); | ||
if self.r().maker_coin_htlc_keypair != self.r().taker_coin_htlc_keypair { |
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 we add a enum that is either a persistent pubkey or a pair of maker and taker htlc keypairs (see the next comment), then it can perform this checking in its AEnum::with_maker_taker_htlc_keypairs
constructor.
mm2src/lp_swap/maker_swap.rs
Outdated
@@ -717,7 +798,8 @@ impl MakerSwap { | |||
.validate_taker_payment( | |||
&self.r().taker_payment.clone().unwrap().tx_hex, | |||
self.taker_payment_lock.load(Ordering::Relaxed) as u32, | |||
&*self.r().other_persistent_pub, | |||
&*self.r().other_taker_coin_htlc_pub, | |||
&**self.r().taker_coin_htlc_keypair.public(), |
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 think it's a good time to add a struct that consists of the method arguments.
It's easy to make a mistake, for example, pass maker and taker pubkeys in the wrong order.
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 agree, will do it tomorrow.
Geth needs additional configuration to always return old transactions ethereum/go-ethereum#23569 (comment).
@sergeyboyko0791 It seems I resolved all remarks from the first iteration. Could you review it again, please? 🙂 |
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.
LGTM! 🔥
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 for the changes! I left a few more comments
@shamardy @sergeyboyko0791 It's ready for (hopefully) final review iteration. |
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.
Last questions and suggestions 😄
mm2src/lp_swap/maker_swap.rs
Outdated
/// Temporary pubkey used in HTLC redeem script when applicable for taker coin | ||
pub taker_coin_htlc_pubkey: Option<H264Json>, | ||
/// Temporary privkey used to sign P2P messages when applicable | ||
/// Temporary privkey used to sign P2P messages when applicable |
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.
Duplicate?
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.
Will fix it today.
mm2src/lp_swap/maker_swap.rs
Outdated
fn get_my_negotiation_data(&self) -> NegotiationDataMsg { | ||
let r = self.r(); | ||
let secret_hash = dhash160(&r.data.secret.0).take().to_vec(); | ||
let maker_coin_swap_contract = self.maker_coin.swap_contract_address().map_or(vec![], |addr| addr.0); |
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 think it should be a bit more efficient as the default vector is created if there is no contract address:
self.maker_coin.swap_contract_address().map(|addr| addr.0).unwrap_or_else(Vec::new);
Could you please consider refactoring the same lines in taker_swap.rs
?
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.
Good note, thanks!
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.
According to https://doc.rust-lang.org/beta/std/option/enum.Option.html#method.map_or, we can also use map_or_else
. It uses one line less after rustfmt 🙂
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.
Great :D
let maker_coin_swap_contract = self.maker_coin.swap_contract_address().map_or(vec![], |addr| addr.0); | ||
let taker_coin_swap_contract = self.taker_coin.swap_contract_address().map_or(vec![], |addr| addr.0); | ||
|
||
if r.my_maker_coin_htlc_keypair != r.my_taker_coin_htlc_keypair { |
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 think we should use the latest version of the negotiation data.
What if we want to add or change a field in the negotiation data. Currently, I see only one way: Add NegotiationDataV2.1
and NegotiationDataV3.1
that will be used accordingly to this condition:
if r.my_maker_coin_htlc_keypair != r.my_taker_coin_htlc_keypair
I'd suggest just using NegotiationDataV3
only. On the other hand, it will break the backward compatibility with the old nodes that don't support V3 yet. Or return HtlcPubkeyData
😅
I think renaming NegotiationDataV3
to NegotiationDataPubkeysPerCoin
is also ok.
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.
NegotiationDataPubkeysPerCoin
will break a naming convention that we already have (V1
, V2
, etc). If we need to add new fields, we will add NegotiationDataV4
. It won't be mandatorily tied to if r.my_maker_coin_htlc_keypair != r.my_taker_coin_htlc_keypair
, we will maybe have another condition or make it default and compatible with NegotiationDataV3
. Also, when the majority of nodes are updated, we can remove the condition and make the V3
default for everyone.
According to this, I don't think we need to change the existing code now (but we will change it later).
@sergeyboyko0791 Could you please review it again? 🙂 |
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 for the changes! LGTM
# Conflicts: # mm2src/coins/eth.rs # mm2src/coins/utxo/qtum.rs # mm2src/coins/utxo/utxo_common.rs # mm2src/coins/utxo/utxo_standard.rs
@sergeyboyko0791 I merged the dev into my branch - there were some conflicts. Could you please take a quick look and check that I didn't break something? |
If I can trust a condensed version of this 2785820 merge commit, everything looks good. |
Generate random p2p messages signing privkey for each order of a privacy coin.
Generate random keypair for HTLC redeem script of privacy coins.
Refactoring.
#927