-
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
fix(legacy-swap): wait for confirmation of taker spend maker payment #2206
Changes from all commits
17a5fab
9827b54
98afd06
d846616
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2560,7 +2560,7 @@ impl MarketCoinOps for TendermintCoin { | |
}) | ||
} | ||
|
||
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = (), Error = String> + Send> { | ||
fn wait_for_confirmations(&self, input: ConfirmPaymentInput) -> Box<dyn Future<Item = u64, Error = String> + Send> { | ||
// Sanity check | ||
let _: TxRaw = try_fus!(Message::decode(input.payment_tx.as_slice())); | ||
|
||
|
@@ -2581,7 +2581,8 @@ impl MarketCoinOps for TendermintCoin { | |
|
||
if let Some(tx_status_code) = tx_status_code { | ||
return match tx_status_code { | ||
cosmrs::tendermint::abci::Code::Ok => Ok(()), | ||
// Tendermint uses Byzantine Fault Tolerance (BFT), achieve instant finality once a block is committed. | ||
cosmrs::tendermint::abci::Code::Ok => Ok(1u64), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better this function |
||
cosmrs::tendermint::abci::Code::Err(err_code) => Err(format!( | ||
"Got error code: '{}' for tx: '{}'. Broadcasted tx isn't valid.", | ||
err_code, tx_hash | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1824,6 +1824,30 @@ impl TakerSwap { | |
|
||
let tx_hash = transaction.tx_hash_as_bytes(); | ||
info!("Maker payment spend tx {:02x}", tx_hash); | ||
|
||
// we should wait for only one confirmation to make sure spend maker payment transaction is not failed | ||
let confirm_maker_payment_spend_input = ConfirmPaymentInput { | ||
payment_tx: transaction.tx_hex(), | ||
confirmations: std::cmp::min(1, self.r().data.maker_payment_confirmations), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason to involve 'maker_payment_confirmations' if we always want exactly 1 conf? |
||
requires_nota: self.r().data.maker_payment_requires_nota.unwrap_or(false), | ||
wait_until: self.wait_refund_until(), | ||
check_every: WAIT_CONFIRM_INTERVAL_SEC, | ||
}; | ||
let wait_fut = self | ||
.maker_coin | ||
.wait_for_confirmations(confirm_maker_payment_spend_input); | ||
let confirmations = match wait_fut.compat().await { | ||
Ok(conf) => conf, | ||
Err(err) => { | ||
return Ok((Some(TakerSwapCommand::Finish), vec![ | ||
TakerSwapEvent::MakerPaymentSpendFailed( | ||
ERRL!("!wait for maker payment spend confirmations: {}", err).into(), | ||
), | ||
])); | ||
}, | ||
}; | ||
info!("Maker payment spend confirmed. Confirmation number: {}", confirmations); | ||
|
||
let tx_ident = TransactionIdentifier { | ||
tx_hex: BytesJson::from(transaction.tx_hex()), | ||
tx_hash, | ||
|
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
u8
oru16
?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.
too keep consistence with the field
pub confirmations: u64,