Skip to content
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

[r2r] Swap watcher node basic functionality #1457

Merged
merged 48 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a8d110b
add initial swap watcher node functionality
caglaryucekaya Sep 1, 2022
735dc2b
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wa…
caglaryucekaya Sep 1, 2022
b922e4e
broadcast watcher message immediately after taker payment is sent
caglaryucekaya Sep 2, 2022
8127ee5
rename the WatcherData struct to TakerSwapWatcherData
caglaryucekaya Sep 3, 2022
638f1b7
use separate SwapWatcherMsg for watchers
caglaryucekaya Sep 3, 2022
a14d31d
make taker send the entire spending transaction to watcher nodes
caglaryucekaya Sep 4, 2022
8d2e6cb
broadcast watcher message periodically in wait_for_taker_payment_spend
caglaryucekaya Sep 5, 2022
39f5be2
check if transaction outputs is empty in p2sh_spending_tx
caglaryucekaya Sep 5, 2022
a534d8d
fix minor details
caglaryucekaya Sep 5, 2022
8b57858
move utxo coin generation methods to docker_tests_common
caglaryucekaya Sep 5, 2022
df84e4d
use Mm2TestConf for watcher node tests
caglaryucekaya Sep 5, 2022
1f0c6a7
prevent running multiple watcher threads for the same swap
caglaryucekaya Sep 7, 2022
efe4294
remove async from spawn_taker_swap_watcher
caglaryucekaya Sep 7, 2022
96e1aeb
check if htlc spend fee is greater than the transaction output
caglaryucekaya Sep 7, 2022
bf93a96
add empty line at the end of docker_tests_common
caglaryucekaya Sep 7, 2022
03044f1
discard prev_transaction mutability after modification
caglaryucekaya Sep 7, 2022
52ecd87
check if transaction outputs is empty in utxo_common functions
caglaryucekaya Sep 7, 2022
979d036
use the drop_mutability macro
caglaryucekaya Sep 7, 2022
d897dbf
move all watcher related code to the swap_watcher module
caglaryucekaya Sep 8, 2022
807386e
improve the taker_swap_watchers usage
caglaryucekaya Sep 8, 2022
63ffaa9
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wa…
caglaryucekaya Sep 8, 2022
693c005
remove unused types and structs
caglaryucekaya Sep 9, 2022
726afe3
check if the transaction script has instructions
caglaryucekaya Sep 9, 2022
e89f88d
check if the transaction has any inputs
caglaryucekaya Sep 9, 2022
c0f8c1e
fix minor stuff
caglaryucekaya Sep 9, 2022
011ba95
make watchers validate taker payment at most once
caglaryucekaya Sep 9, 2022
34dc5b7
release taker_swap_watchers lock after inserting the uuid to the set
caglaryucekaya Sep 9, 2022
4958834
fix the error type in instruction iterator
caglaryucekaya Sep 11, 2022
152d507
reorder taker_swap_watchers lock/release structure
caglaryucekaya Sep 11, 2022
2521f43
use separate files for large json test strings
caglaryucekaya Sep 11, 2022
376d97d
remove watcher arguments from test helper functions
caglaryucekaya Sep 12, 2022
20c35e8
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wa…
caglaryucekaya Sep 12, 2022
40e94b4
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wa…
caglaryucekaya Sep 12, 2022
9130ba8
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wa…
caglaryucekaya Sep 13, 2022
4e36127
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wa…
caglaryucekaya Sep 13, 2022
d2166de
propagate watcher messages whether the node is watcher or not
caglaryucekaya Sep 14, 2022
424b1fb
remove swap lock related code from the swap_watcher
caglaryucekaya Sep 14, 2022
7aaa88f
remove running_swaps related code from swap_watcher
caglaryucekaya Sep 14, 2022
e5dd063
check if a watcher with the same uuid exists before spawning a thread
caglaryucekaya Sep 14, 2022
65b437c
fix minor problems
caglaryucekaya Sep 14, 2022
f58bc9d
remove AtomicSwap implementation from swap_watcher
caglaryucekaya Sep 14, 2022
c403935
make taker trigger a WatcherMessageSent event only if it is actually …
caglaryucekaya Sep 14, 2022
b5077b5
remove an unnecessary line
caglaryucekaya Sep 15, 2022
f9ad101
log error if watcher message could not be sent
caglaryucekaya Sep 19, 2022
473a04c
improve mutex usage for the taker_swap_watchers
caglaryucekaya Sep 22, 2022
0c8b58f
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wa…
caglaryucekaya Sep 22, 2022
281fb4b
fix formatting
caglaryucekaya Sep 22, 2022
56aac96
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wa…
caglaryucekaya Sep 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ use super::{coin_conf, AsyncMutex, BalanceError, BalanceFut, CoinBalance, CoinPr
TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult, TradePreimageValue, Transaction,
TransactionDetails, TransactionEnum, TransactionErr, TransactionFut, TxMarshalingErr,
UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput, VerificationError,
VerificationResult, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest, WithdrawResult};
VerificationResult, WatcherValidatePaymentInput, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest,
WithdrawResult};

pub use rlp;

Expand Down Expand Up @@ -791,6 +792,21 @@ impl SwapOps for EthCoin {
)
}

fn send_taker_spends_maker_payment_preimage(&self, _preimage: &[u8], _secret: &[u8]) -> TransactionFut {
unimplemented!();
}

fn create_taker_spends_maker_payment_preimage(
&self,
_maker_payment_tx: &[u8],
_time_lock: u32,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
) -> TransactionFut {
unimplemented!();
}

fn send_taker_spends_maker_payment(
&self,
maker_payment_tx: &[u8],
Expand Down Expand Up @@ -978,6 +994,13 @@ impl SwapOps for EthCoin {
)
}

fn watcher_validate_taker_payment(
&self,
_input: WatcherValidatePaymentInput,
) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!();
}

fn check_if_my_payment_sent(
&self,
time_lock: u32,
Expand Down
24 changes: 23 additions & 1 deletion mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{BalanceFut, CoinBalance, FeeApproxStage, FoundSwapTxSpend, HistorySy
SignatureError, SignatureResult, SwapOps, TradeFee, TradePreimageFut, TradePreimageResult,
TradePreimageValue, TransactionEnum, TransactionFut, TxMarshalingErr, UnexpectedDerivationMethod,
UtxoStandardCoin, ValidateAddressResult, ValidatePaymentInput, VerificationError, VerificationResult,
WithdrawError, WithdrawFut, WithdrawRequest};
WatcherValidatePaymentInput, WithdrawError, WithdrawFut, WithdrawRequest};
use async_trait::async_trait;
use bitcoin::hashes::Hash;
use bitcoin_hashes::sha256::Hash as Sha256;
Expand Down Expand Up @@ -314,6 +314,17 @@ impl SwapOps for LightningCoin {
unimplemented!()
}

fn create_taker_spends_maker_payment_preimage(
&self,
_maker_payment_tx: &[u8],
_time_lock: u32,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
) -> TransactionFut {
unimplemented!();
}

fn send_taker_spends_maker_payment(
&self,
_maker_payment_tx: &[u8],
Expand All @@ -326,6 +337,10 @@ impl SwapOps for LightningCoin {
unimplemented!()
}

fn send_taker_spends_maker_payment_preimage(&self, _preimage: &[u8], _secret: &[u8]) -> TransactionFut {
unimplemented!();
}

fn send_taker_refunds_payment(
&self,
_taker_payment_tx: &[u8],
Expand Down Expand Up @@ -376,6 +391,13 @@ impl SwapOps for LightningCoin {
unimplemented!()
}

fn watcher_validate_taker_payment(
&self,
_input: WatcherValidatePaymentInput,
) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!();
}

fn check_if_my_payment_sent(
&self,
_time_lock: u32,
Expand Down
28 changes: 28 additions & 0 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,18 @@ pub enum NegotiateSwapContractAddrErr {
NoOtherAddrAndNoFallback,
}

#[derive(Clone, Debug)]
pub struct WatcherValidatePaymentInput {
pub payment_tx: Vec<u8>,
pub time_lock: u32,
pub taker_pub: Vec<u8>,
pub maker_pub: Vec<u8>,
pub secret_hash: Vec<u8>,
pub amount: BigDecimal,
pub try_spv_proof_until: u64,
pub confirmations: u64,
}

#[derive(Clone, Debug)]
pub struct ValidatePaymentInput {
pub payment_tx: Vec<u8>,
Expand Down Expand Up @@ -492,6 +504,15 @@ pub trait SwapOps {
swap_unique_data: &[u8],
) -> TransactionFut;

fn create_taker_spends_maker_payment_preimage(
&self,
_maker_payment_tx: &[u8],
_time_lock: u32,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
) -> TransactionFut;

fn send_taker_spends_maker_payment(
&self,
maker_payment_tx: &[u8],
Expand All @@ -502,6 +523,8 @@ pub trait SwapOps {
swap_unique_data: &[u8],
) -> TransactionFut;

fn send_taker_spends_maker_payment_preimage(&self, preimage: &[u8], secret: &[u8]) -> TransactionFut;

fn send_taker_refunds_payment(
&self,
taker_payment_tx: &[u8],
Expand Down Expand Up @@ -536,6 +559,11 @@ pub trait SwapOps {

fn validate_taker_payment(&self, input: ValidatePaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send>;

fn watcher_validate_taker_payment(
&self,
_input: WatcherValidatePaymentInput,
) -> Box<dyn Future<Item = (), Error = String> + Send>;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add corresponding WatcherValidatePayment error?
Probably at the next sprint.


fn check_if_my_payment_sent(
&self,
time_lock: u32,
Expand Down
26 changes: 24 additions & 2 deletions mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use crate::{BalanceError, BalanceFut, CoinBalance, FeeApproxStage, FoundSwapTxSp
SearchForSwapTxSpendInput, SignatureResult, SwapOps, TradeFee, TradePreimageError, TradePreimageFut,
TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionEnum, TransactionErr,
TransactionFut, TransactionType, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult,
ValidatePaymentInput, VerificationResult, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest,
WithdrawResult};
ValidatePaymentInput, VerificationResult, WatcherValidatePaymentInput, WithdrawError, WithdrawFee,
WithdrawFut, WithdrawRequest, WithdrawResult};
use async_trait::async_trait;
use bitcrypto::{dhash160, sha256};
use chain::TransactionOutput;
Expand Down Expand Up @@ -793,6 +793,17 @@ impl SwapOps for Qrc20Coin {
Box::new(fut.boxed().compat())
}

fn create_taker_spends_maker_payment_preimage(
&self,
_maker_payment_tx: &[u8],
_time_lock: u32,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
) -> TransactionFut {
unimplemented!();
}

fn send_taker_spends_maker_payment(
&self,
maker_payment_tx: &[u8],
Expand All @@ -815,6 +826,10 @@ impl SwapOps for Qrc20Coin {
Box::new(fut.boxed().compat())
}

fn send_taker_spends_maker_payment_preimage(&self, _preimage: &[u8], _secret: &[u8]) -> TransactionFut {
unimplemented!();
}

fn send_taker_refunds_payment(
&self,
taker_payment_tx: &[u8],
Expand Down Expand Up @@ -928,6 +943,13 @@ impl SwapOps for Qrc20Coin {
Box::new(fut.boxed().compat())
}

fn watcher_validate_taker_payment(
&self,
_input: WatcherValidatePaymentInput,
) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!();
}

fn check_if_my_payment_sent(
&self,
time_lock: u32,
Expand Down
25 changes: 24 additions & 1 deletion mm2src/coins/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::{BalanceError, BalanceFut, FeeApproxStage, FoundSwapTxSpend, Negotiat
RawTransactionFut, RawTransactionRequest, SearchForSwapTxSpendInput, SignatureResult, TradePreimageFut,
TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionFut, TransactionType,
TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput,
VerificationResult, WithdrawError, WithdrawFut, WithdrawRequest, WithdrawResult};
VerificationResult, WatcherValidatePaymentInput, WithdrawError, WithdrawFut, WithdrawRequest,
WithdrawResult};
use async_trait::async_trait;
use base58::ToBase58;
use bincode::{deserialize, serialize};
Expand Down Expand Up @@ -489,6 +490,17 @@ impl SwapOps for SolanaCoin {
unimplemented!()
}

fn create_taker_spends_maker_payment_preimage(
&self,
_maker_payment_tx: &[u8],
_time_lock: u32,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
) -> TransactionFut {
unimplemented!();
}

fn send_taker_spends_maker_payment(
&self,
maker_payment_tx: &[u8],
Expand All @@ -501,6 +513,10 @@ impl SwapOps for SolanaCoin {
unimplemented!()
}

fn send_taker_spends_maker_payment_preimage(&self, preimage: &[u8], secret: &[u8]) -> TransactionFut {
unimplemented!();
}

fn send_taker_refunds_payment(
&self,
taker_payment_tx: &[u8],
Expand Down Expand Up @@ -545,6 +561,13 @@ impl SwapOps for SolanaCoin {
unimplemented!()
}

fn watcher_validate_taker_payment(
&self,
_input: WatcherValidatePaymentInput,
) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!();
}

fn check_if_my_payment_sent(
&self,
time_lock: u32,
Expand Down
25 changes: 24 additions & 1 deletion mm2src/coins/solana/spl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::{BalanceFut, FeeApproxStage, FoundSwapTxSpend, NegotiateSwapContractA
RawTransactionRequest, SearchForSwapTxSpendInput, SignatureResult, SolanaCoin, TradePreimageFut,
TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionFut, TransactionType,
TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput,
VerificationResult, WithdrawError, WithdrawFut, WithdrawRequest, WithdrawResult};
VerificationResult, WatcherValidatePaymentInput, WithdrawError, WithdrawFut, WithdrawRequest,
WithdrawResult};
use async_trait::async_trait;
use bincode::serialize;
use common::{async_blocking, now_ms};
Expand Down Expand Up @@ -323,6 +324,17 @@ impl SwapOps for SplToken {
unimplemented!()
}

fn create_taker_spends_maker_payment_preimage(
&self,
_maker_payment_tx: &[u8],
_time_lock: u32,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
) -> TransactionFut {
unimplemented!();
}

fn send_taker_spends_maker_payment(
&self,
maker_payment_tx: &[u8],
Expand All @@ -335,6 +347,10 @@ impl SwapOps for SplToken {
unimplemented!()
}

fn send_taker_spends_maker_payment_preimage(&self, preimage: &[u8], secret: &[u8]) -> TransactionFut {
unimplemented!();
}

fn send_taker_refunds_payment(
&self,
taker_payment_tx: &[u8],
Expand Down Expand Up @@ -379,6 +395,13 @@ impl SwapOps for SplToken {
unimplemented!()
}

fn watcher_validate_taker_payment(
&self,
_input: WatcherValidatePaymentInput,
) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!();
}

fn check_if_my_payment_sent(
&self,
time_lock: u32,
Expand Down
26 changes: 24 additions & 2 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{big_decimal_from_sat_unsigned, BalanceError, BalanceFut, BigDecimal,
RawTransactionFut, RawTransactionRequest, SearchForSwapTxSpendInput, SignatureResult, SwapOps, TradeFee,
TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionEnum,
TransactionFut, TransactionType, TxFeeDetails, TxMarshalingErr, UnexpectedDerivationMethod,
ValidateAddressResult, ValidatePaymentInput, VerificationResult, WithdrawError, WithdrawFut,
WithdrawRequest};
ValidateAddressResult, ValidatePaymentInput, VerificationResult, WatcherValidatePaymentInput,
WithdrawError, WithdrawFut, WithdrawRequest};
use async_trait::async_trait;
use bitcrypto::sha256;
use common::{get_utc_timestamp, Future01CompatExt};
Expand Down Expand Up @@ -659,6 +659,17 @@ impl SwapOps for TendermintCoin {
todo!()
}

fn create_taker_spends_maker_payment_preimage(
&self,
_maker_payment_tx: &[u8],
_time_lock: u32,
_maker_pub: &[u8],
_secret_hash: &[u8],
_swap_unique_data: &[u8],
) -> TransactionFut {
unimplemented!();
}

fn send_taker_spends_maker_payment(
&self,
maker_payment_tx: &[u8],
Expand All @@ -671,6 +682,10 @@ impl SwapOps for TendermintCoin {
todo!()
}

fn send_taker_spends_maker_payment_preimage(&self, preimage: &[u8], secret: &[u8]) -> TransactionFut {
unimplemented!();
}

fn send_taker_refunds_payment(
&self,
taker_payment_tx: &[u8],
Expand Down Expand Up @@ -715,6 +730,13 @@ impl SwapOps for TendermintCoin {
todo!()
}

fn watcher_validate_taker_payment(
&self,
_input: WatcherValidatePaymentInput,
) -> Box<dyn Future<Item = (), Error = String> + Send> {
unimplemented!();
}

fn check_if_my_payment_sent(
&self,
time_lock: u32,
Expand Down
Loading