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] wait for EVM approval transaction confirmation #1706

Merged
merged 5 commits into from
Mar 13, 2023

Conversation

shamardy
Copy link
Collaborator

@shamardy shamardy commented Mar 9, 2023

Fixes #1689

@shamardy shamardy changed the title [wip] wait for EVM approval transaction confirmation [r2r] wait for EVM approval transaction confirmation Mar 9, 2023
@shamardy shamardy requested review from cipig and caglaryucekaya March 9, 2023 19:09
@cipig
Copy link
Member

cipig commented Mar 10, 2023

listed a new token and tried to sell it to my maker, but the swap failed:

{
   "error_events" : [
      "StartFailed",
      "NegotiateFailed",
      "TakerFeeSendFailed",
      "MakerPaymentValidateFailed",
      "MakerPaymentWaitConfirmFailed",
      "TakerPaymentTransactionFailed",
      "TakerPaymentWaitConfirmFailed",
      "TakerPaymentDataSendFailed",
      "TakerPaymentWaitForSpendFailed",
      "MakerPaymentSpendFailed",
      "TakerPaymentWaitRefundStarted",
      "TakerPaymentRefundStarted",
      "TakerPaymentRefunded",
      "TakerPaymentRefundFailed",
      "TakerPaymentRefundFinished"
   ],
   "events" : [
      {
         "event" : {
            "data" : {
               "fee_to_send_taker_fee" : {
                  "amount" : "0.0111057793",
                  "coin" : "MATIC",
                  "paid_from_trading_vol" : false
               },
               "lock_duration" : 7800,
               "maker" : "de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "maker_amount" : "76.99287909801446790273000026965078779261488628646724563409875443550928122442960240325832185390075819",
               "maker_coin" : "KMD",
               "maker_coin_htlc_pubkey" : "023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "maker_coin_start_block" : 3328046,
               "maker_payment_confirmations" : 1,
               "maker_payment_requires_nota" : false,
               "maker_payment_spend_trade_fee" : {
                  "amount" : "0.00001",
                  "coin" : "KMD",
                  "paid_from_trading_vol" : true
               },
               "maker_payment_wait" : 1678424508,
               "my_persistent_pub" : "023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "p2p_privkey" : null,
               "started_at" : 1678421388,
               "taker_amount" : "199.9791667698661389509074550128534704370179948586118251928020565552699228791773778920308483290488432",
               "taker_coin" : "REQ-PLG20",
               "taker_coin_htlc_pubkey" : "023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "taker_coin_start_block" : 40170173,
               "taker_coin_swap_contract_address" : "9130b257d37a52e52f21054c4da3450c72f595ce",
               "taker_payment_confirmations" : 3,
               "taker_payment_lock" : 1678429188,
               "taker_payment_requires_nota" : false,
               "taker_payment_trade_fee" : {
                  "amount" : "0.07455553545",
                  "coin" : "MATIC",
                  "paid_from_trading_vol" : false
               },
               "uuid" : "1c90c366-d573-4d93-a179-d26204045e31"
            },
            "type" : "Started"
         },
         "timestamp" : 1678421388787
      },
      {
         "event" : {
            "data" : {
               "maker_coin_htlc_pubkey" : "03de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "maker_coin_swap_contract_addr" : null,
               "maker_payment_locktime" : 1678436987,
               "maker_pubkey" : "000000000000000000000000000000000000000000000000000000000000000000",
               "secret_hash" : "f6a80c371193d6585a517f0bc1ce64a7073a0e12",
               "taker_coin_htlc_pubkey" : "03de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "taker_coin_swap_contract_addr" : "9130b257d37a52e52f21054c4da3450c72f595ce"
            },
            "type" : "Negotiated"
         },
         "timestamp" : 1678421390798
      },
      {
         "event" : {
            "data" : {
               "tx_hash" : "2f61c485b3376b69999205c0829b4728fd86dc4f5e2cff77f589d90efd74d6ac",
               "tx_hex" : "f8ae8205df85362476cf008303345094b25e20de2f2ebb4cffd4d16a55c7b395e8a9476280b844a9059cbb000000000000000000000000d8997941dd1346e9231118d5685d866294f59e5b0000000000000000000000000000000000000000000000000336efce5fcb8e66820136a0eec768ac03811e24ad839d423ead35c479cd49e6b6ec2d1bb77b297441fbf905a03d13f01115e441f201d2c63564be2534faf5a2177521d261b18ce81b315f6151"
            },
            "type" : "TakerFeeSent"
         },
         "timestamp" : 1678421392896
      },
      {
         "event" : {
            "data" : null,
            "type" : "TakerPaymentInstructionsReceived"
         },
         "timestamp" : 1678421404902
      },
      {
         "event" : {
            "data" : {
               "tx_hash" : "d237864491817cc097ce905bb54508220836c878fd0d50ca1c95ddeb2b444b64",
               "tx_hex" : "0400008085202f8907c5196772a9eb7f795a59341dfeeab9e67314e5505dc62fe4c80b6fc08f438861020000006a473044022053db1959197e45ecfcd158c7af91ad9d90e2ea57347cfdbf153870ca9de585970220643c2d2d0cf6b0142431bce9e4f58286bdaed1e4736a224ae2cf5e5aed375899012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff32a290abe1aa0d3661587c72ad35a4a540ed7ecb54bc88d0f060984db37bb766000000006a47304402205d1cca9a179ff4fbf82e16be01923a70e22494f4cd670f1b19526a08b75a24f702200da5f55afded36c8e75c8855bc8509de545eecbec4827fe1f301ed2c73edc37b012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12fffffffff2a7285ee1a15eed0edc2b33013b4e0ff00be6ac6dfbc393068a29c0ecb5739f000000006a4730440220253e7a40181cbe9382eb57840671c4a414f1a3657580570a520fbea33170095e02207375ffbb64e529a143182a9d5ecc2178292042cb28d16382de1a8fa96ac2cc78012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12fffffffff03a8bae96bef7f966a7ab5a7081dc375000c0ee254576acc0619433b88d0a85000000006a473044022063d2c9787c6104a3595ee2b65cb29cfc0f4127c2841c925a7aa3386b81fb07170220463f0e3d3af6912794b277c0e38d2e97a28048992e5f4b049f6f9d97d5428478012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff5bc87a96af36a4df9d4b3301c66ebbcf0f91ed0e0540dd2913fe0c9697829d57000000006a473044022047d5f4f449cb598fee926727bb4a7a955e896e58494199b65e31c4bb68e10fba0220752063d98c53d23500a2c71ceab66185eae8f6e1f53c4399ce580603657697e5012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff2b17abeb0eb1d2de9a3fd8ed9a5b16c60bb05463402e886378e810502e548ed2000000006b483045022100924b7b227302ea480b3bf1c9a92669fb5f4f2f6ef8da8c1034627545cd3e4c5402205ae3e8b436973066043a0e207cf4d9c5833abc6115a89ac502f9dd60e637629c012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff3792a2906f1c19d6f17401a116a39f337305e8b885301590d18cbc6efd677ceb000000006b483045022100ff3bef17f0fa819830ea5e7535810970f15a1d25d84ebea17d18408f9fe77d7d02206d3d04cf47c861b014679dd1e831fdbe492f75b6751350d212784bcaf3f7ddaa012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff0365cfe9ca0100000017a91482f08b443dd9820059b2c373e4d5ae0313245591870000000000000000166a14f6a80c371193d6585a517f0bc1ce64a7073a0e121e426c1d000000001976a9146aafbb75331085425727a78a940e9334f681b3e588ac76ab0a64000000000000000000000000000000"
            },
            "type" : "MakerPaymentReceived"
         },
         "timestamp" : 1678421404903
      },
      {
         "event" : {
            "type" : "MakerPaymentWaitConfirmStarted"
         },
         "timestamp" : 1678421404905
      },
      {
         "event" : {
            "type" : "MakerPaymentValidatedAndConfirmed"
         },
         "timestamp" : 1678421525264
      },
      {
         "event" : {
            "data" : {
               "tx_hash" : "8f0ef8a9c40ff4a0d634f6f8b14bba69833121d0a04596df85f39765e71ef039",
               "tx_hex" : "f9012e8205e0851ecc3452c0830249f0949130b257d37a52e52f21054c4da3450c72f595ce80b8c49b415b2af595a7846344c8920cb03027538b02c676341e26ce2cb15904044854dda3840300000000000000000000000000000000000000000000000ad744b8a46478e546000000000000000000000000b25e20de2f2ebb4cffd4d16a55c7b395e8a94762000000000000000000000000adb681c3a1ec9bbc4105b8e8eb5fc7178125b450f6a80c371193d6585a517f0bc1ce64a7073a0e1200000000000000000000000000000000000000000000000000000000000000000000000000000000640acc04820135a0b0fbfdd93dfd1ffbc0e6037e8cf75492bb00b9c0da2cf868a295080174b2680ba03c4ef7e93c7542f1f8ea8c597cd575fe1d27225dbb01b57667c732391f644500"
            },
            "type" : "TakerPaymentSent"
         },
         "timestamp" : 1678421528461
      },
      {
         "event" : {
            "data" : {
               "error" : "taker_swap:1603] !taker_coin.wait_for_confirmations: eth:1774] Tx receipt Receipt { transaction_hash: 0x8f0ef8a9c40ff4a0d634f6f8b14bba69833121d0a04596df85f39765e71ef039, transaction_index: 36, block_hash: Some(0x93d501ea767877a1833fca772f55eaaab20dafb9d33b4e13e81d005e6dfeaeac), block_number: Some(40170241), from: 0x15c577f4b9fbe66735a9bff9b0b5d3ea2854bfaa, to: Some(0x9130b257d37a52e52f21054c4da3450c72f595ce), cumulative_gas_used: 7266856, gas_used: Some(54368), contract_address: None, logs: [Log { address: 0x0000000000000000000000000000000000001010, topics: [0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63, 0x0000000000000000000000000000000000000000000000000000000000001010, 0x00000000000000000000000015c577f4b9fbe66735a9bff9b0b5d3ea2854bfaa, 0x000000000000000000000000f0245f6251bef9447a08766b9da2b07b28ad80b0], data: Bytes([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 99, 84, 235, 64, 209, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 134, 54, 215, 227, 101, 63, 224, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 5, 91, 26, 34, 190, 138, 177, 16, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 123, 211, 130, 248, 36, 110, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 5, 91, 36, 134, 19, 117, 241, 225, 135]), block_hash: Some(0x93d501ea767877a1833fca772f55eaaab20dafb9d33b4e13e81d005e6dfeaeac), block_number: Some(40170241), transaction_hash: Some(0x8f0ef8a9c40ff4a0d634f6f8b14bba69833121d0a04596df85f39765e71ef039), transaction_index: Some(36), log_index: Some(168), transaction_log_index: None, log_type: None, removed: Some(false) }], status: Some(0), root: None, logs_bloom: 0x00000000000000000200000000000000000000000000000000000000000000000000000000008000000000000000000000008000000000000000000000000000000080000000000000000000000000800000000000000000000100000000000000000000000000000000000000000020000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000080000200080000000000000000000000000000000000000000000000000000000004000000000000000000001000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000100000, transaction_type: Some(0), effective_gas_price: Some(132275000000) } status of REQ-PLG20 tx Bytes([143, 14, 248, 169, 196, 15, 244, 160, 214, 52, 246, 248, 177, 75, 186, 105, 131, 49, 33, 208, 160, 69, 150, 223, 133, 243, 151, 101, 231, 30, 240, 57]) is failed"
            },
            "type" : "TakerPaymentWaitConfirmFailed"
         },
         "timestamp" : 1678421543764
      },
      {
         "event" : {
            "data" : {
               "wait_until" : 1678432888
            },
            "type" : "TakerPaymentWaitRefundStarted"
         },
         "timestamp" : 1678421543766
      },
      {
         "event" : {
            "type" : "TakerPaymentRefundStarted"
         },
         "timestamp" : 1678421543768
      }
   ],
   "gui" : "AtomicDex Desktop 0.5.7.1-beta",
   "maker_amount" : "76.99287909801446790273000026965078779261488628646724563409875443550928122442960240325832185390075819",
   "maker_coin" : "KMD",
   "maker_coin_usd_price" : null,
   "mm_version" : "1.0.0-beta_10466_bugfix-wait-confirm-approval_6671a2381_Linux_CI",
   "my_order_uuid" : "1c90c366-d573-4d93-a179-d26204045e31",
   "success_events" : [
      "Started",
      "Negotiated",
      "TakerFeeSent",
      "TakerPaymentInstructionsReceived",
      "MakerPaymentReceived",
      "MakerPaymentWaitConfirmStarted",
      "MakerPaymentValidatedAndConfirmed",
      "TakerPaymentSent",
      "TakerPaymentSpent",
      "MakerPaymentSpent",
      "Finished"
   ],
   "taker_amount" : "199.9791667698661389509074550128534704370179948586118251928020565552699228791773778920308483290488432",
   "taker_coin" : "REQ-PLG20",
   "taker_coin_usd_price" : null,
   "type" : "Taker",
   "uuid" : "1c90c366-d573-4d93-a179-d26204045e31"
}

weird thing is that the TakerFeeSent was fine https://polygonscan.com/tx/0x2f61c485b3376b69999205c0829b4728fd86dc4f5e2cff77f589d90efd74d6ac and it's the same new token (REQ-PLG20)

TakerPaymentSent tx failed though: https://polygonscan.com/tx/0x8f0ef8a9c40ff4a0d634f6f8b14bba69833121d0a04596df85f39765e71ef039
with Fail with error 'AnyswapV3ERC20: request exceeds allowance'

i also can't see the approve tx on https://polygonscan.com/address/0x15c577f4b9fbe66735a9bff9b0b5d3ea2854bfaa

@shamardy
Copy link
Collaborator Author

shamardy commented Mar 10, 2023

weird thing is that the TakerFeeSent was fine https://polygonscan.com/tx/0x2f61c485b3376b69999205c0829b4728fd86dc4f5e2cff77f589d90efd74d6ac and it's the same new token (REQ-PLG20)

That is normal behaviour, taker fee is sent to the fee address straight away, no contract calls are required.

i also can't see the approve tx on https://polygonscan.com/address/0x15c577f4b9fbe66735a9bff9b0b5d3ea2854bfaa

I see the new problem now, it's related to this recently merged PR #1658 (3 days ago) where this line was added https://github.com/KomodoPlatform/atomicDEX-API/blob/6671a2381da9e5cdcb3812e53e341e29636bf1ff/mm2src/coins/eth.rs#L2887 This causes the skipping of the approval transaction if there are no watchers. Will fix it.

@shamardy
Copy link
Collaborator Author

@cipig can you please retest after the latest commit?

U256::from(ETH_GAS),
.and_then(move |approved| {
// make sure the approve tx is confirmed before sending the htlc tx
arc.wait_for_confirmations(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I decided to wait for confirmation of the approve transaction, alternatively, we can loop over the allowance fn and check until the amount is allowed. What do you think is the better solution @caglaryucekaya? checking allowance fn might be a cheaper call but I am not sure.

Copy link

@caglaryucekaya caglaryucekaya Mar 12, 2023

Choose a reason for hiding this comment

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

https://www.quicknode.com/docs/ethereum/api_credits

Quicknode has an API credit measure here for each method based on its complexity. wait_for_confirmations requires two calls at each iteration of the loop: eth_getTransactionReceipt (2 credits) and eth_blockNumber (1 credit). Allowance query requires one call eth_call which is 2 credits. So allowance call is less credits in total according to this list, and one call is better than having two separate calls in general. I think it's worth changing it to a loop over the allowance function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the detailed research/explanation for this. Will fix it :)

@cipig
Copy link
Member

cipig commented Mar 10, 2023

updated and tried again, but it failed too:

{
   "error_events" : [
      "StartFailed",
      "NegotiateFailed",
      "TakerFeeSendFailed",
      "MakerPaymentValidateFailed",
      "MakerPaymentWaitConfirmFailed",
      "TakerPaymentTransactionFailed",
      "TakerPaymentWaitConfirmFailed",
      "TakerPaymentDataSendFailed",
      "TakerPaymentWaitForSpendFailed",
      "MakerPaymentSpendFailed",
      "TakerPaymentWaitRefundStarted",
      "TakerPaymentRefundStarted",
      "TakerPaymentRefunded",
      "TakerPaymentRefundFailed",
      "TakerPaymentRefundFinished"
   ],
   "events" : [
      {
         "event" : {
            "data" : {
               "fee_to_send_taker_fee" : {
                  "amount" : "0.01430224422",
                  "coin" : "MATIC",
                  "paid_from_trading_vol" : false
               },
               "lock_duration" : 7800,
               "maker" : "de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "maker_amount" : "75.63331389201092080955875847058083203247927788219721308219079760481235292953686285410548849043498926",
               "maker_coin" : "KMD",
               "maker_coin_htlc_pubkey" : "023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "maker_coin_start_block" : 3328802,
               "maker_payment_confirmations" : 1,
               "maker_payment_requires_nota" : false,
               "maker_payment_spend_trade_fee" : {
                  "amount" : "0.00001",
                  "coin" : "KMD",
                  "paid_from_trading_vol" : true
               },
               "maker_payment_wait" : 1678469660,
               "my_persistent_pub" : "023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "p2p_privkey" : null,
               "started_at" : 1678466540,
               "taker_amount" : "199.7478284021375020296246786632390745501285347043701799485861182519280205655526992287917737789203085",
               "taker_coin" : "REQ-PLG20",
               "taker_coin_htlc_pubkey" : "023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "taker_coin_start_block" : 40189935,
               "taker_coin_swap_contract_address" : "9130b257d37a52e52f21054c4da3450c72f595ce",
               "taker_payment_confirmations" : 3,
               "taker_payment_lock" : 1678474340,
               "taker_payment_requires_nota" : false,
               "taker_payment_trade_fee" : {
                  "amount" : "0.14524595498325",
                  "coin" : "MATIC",
                  "paid_from_trading_vol" : false
               },
               "uuid" : "8a4c99fe-1259-4b63-a98c-825f86e4a552"
            },
            "type" : "Started"
         },
         "timestamp" : 1678466540405
      },
      {
         "event" : {
            "data" : {
               "maker_coin_htlc_pubkey" : "03de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "maker_coin_swap_contract_addr" : null,
               "maker_payment_locktime" : 1678482138,
               "maker_pubkey" : "000000000000000000000000000000000000000000000000000000000000000000",
               "secret_hash" : "968c433af2ef9c43a78653c7d322bd9c8f18518a",
               "taker_coin_htlc_pubkey" : "03de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "taker_coin_swap_contract_addr" : "9130b257d37a52e52f21054c4da3450c72f595ce"
            },
            "type" : "Negotiated"
         },
         "timestamp" : 1678466542415
      },
      {
         "event" : {
            "data" : {
               "tx_hash" : "54a5c1a93a375bffc65fd72cd38bed25af02901b3a3db820a4a2ba280a4378db",
               "tx_hex" : "f8ae8205e3855eccecd9408303345094b25e20de2f2ebb4cffd4d16a55c7b395e8a9476280b844a9059cbb000000000000000000000000d8997941dd1346e9231118d5685d866294f59e5b0000000000000000000000000000000000000000000000000335fc193106736a820136a0a9b8f87326a8ef306fcf870dcbb33f66c2c597c0cbe3b267cbc948aeb557f6e4a0255a0d8e644eead11e44b10d3150c782678e193a6ef47523666a08b1f58968fa"
            },
            "type" : "TakerFeeSent"
         },
         "timestamp" : 1678466547797
      },
      {
         "event" : {
            "data" : null,
            "type" : "TakerPaymentInstructionsReceived"
         },
         "timestamp" : 1678466548801
      },
      {
         "event" : {
            "data" : {
               "tx_hash" : "4aaaa665fcbd35736c31a84befd5ee633403c5587e92df77e097f1488d3e4119",
               "tx_hex" : "0400008085202f89025da0cbcf4fcf817df89f2607949fd9938125607095c5a6f7d4b4085d21bce3b4020000006b483045022100d9f4f2f509884d48fbb32ddcc5956eb26832a7ce2559eeaaabbc221abca11bbc02206fef004775b1458b3d7960a0b6eb3199bb34b4afacc9bcef37dd6df16672d6cc012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff833244e2d481e97c1735825245f26b35d9e3c41fff8e5d86a073df5b13903792000000006a473044022044e0dfe901160a699835070b94e1dcbd41ef0c069ac87a42a2da87e8d9776dc5022075eaa83a679b25ed6881c9f692be639238c1db65e7c4b016c3f3c1cdcf018d7f012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff033d47cfc20100000017a91426913b3ec620e374d46c0da89393ee23b1869de5870000000000000000166a14968c433af2ef9c43a78653c7d322bd9c8f18518abdcb5fa7010000001976a9146aafbb75331085425727a78a940e9334f681b3e588acad5b0b64000000000000000000000000000000"
            },
            "type" : "MakerPaymentReceived"
         },
         "timestamp" : 1678466548810
      },
      {
         "event" : {
            "type" : "MakerPaymentWaitConfirmStarted"
         },
         "timestamp" : 1678466548818
      },
      {
         "event" : {
            "type" : "MakerPaymentValidatedAndConfirmed"
         },
         "timestamp" : 1678466699217
      },
      {
         "event" : {
            "data" : {
               "error" : "taker_swap:1464] eth:1751] Waited too long until 839237170 for transaction SignedTransaction { transaction: UnverifiedTransaction { unsigned: Transaction { nonce: 1508, gas_price: 399135000000, gas: 46611, action: Call(0xb25e20de2f2ebb4cffd4d16a55c7b395e8a94762), value: 0, data: [9, 94, 167, 179, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 145, 48, 178, 87, 211, 122, 82, 229, 47, 33, 5, 76, 77, 163, 69, 12, 114, 245, 149, 206, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255] }, v: 310, r: 6625856435002198721221180323734758016264714164661237696688806923671811078437, s: 17740283244931943244225039159226322781357672954884302522165193860384942763021, hash: 0x68c3d603050560ab34b10a843b035088e0f3449daed8dde2e06f8cdb802843b0 }, sender: 0x15c577f4b9fbe66735a9bff9b0b5d3ea2854bfaa, public: Some(0x3c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f2890c7e83dfe4a34a21b636d8dc0074f619e962da35d4bc60d1fe88c956cafaa09e) } confirmation "
            },
            "type" : "TakerPaymentTransactionFailed"
         },
         "timestamp" : 1678466702398
      },
      {
         "event" : {
            "type" : "Finished"
         },
         "timestamp" : 1678466702400
      }
   ],
   "gui" : "AtomicDex Desktop 0.5.7.1-beta",
   "maker_amount" : "75.63331389201092080955875847058083203247927788219721308219079760481235292953686285410548849043498926",
   "maker_coin" : "KMD",
   "maker_coin_usd_price" : null,
   "mm_version" : "1.0.0-beta_10473_bugfix-wait-confirm-approval_be6edafb5_Linux_CI",
   "my_order_uuid" : "8a4c99fe-1259-4b63-a98c-825f86e4a552",
   "success_events" : [
      "Started",
      "Negotiated",
      "TakerFeeSent",
      "TakerPaymentInstructionsReceived",
      "MakerPaymentReceived",
      "MakerPaymentWaitConfirmStarted",
      "MakerPaymentValidatedAndConfirmed",
      "TakerPaymentSent",
      "TakerPaymentSpent",
      "MakerPaymentSpent",
      "Finished"
   ],
   "taker_amount" : "199.7478284021375020296246786632390745501285347043701799485861182519280205655526992287917737789203085",
   "taker_coin" : "REQ-PLG20",
   "taker_coin_usd_price" : null,
   "type" : "Taker",
   "uuid" : "8a4c99fe-1259-4b63-a98c-825f86e4a552"
}

the approve tx is now there: https://polygonscan.com/tx/0x68c3d603050560ab34b10a843b035088e0f3449daed8dde2e06f8cdb802843b0
but TakerPayment failed... it was very quick, right after approve was sent the swap failed, it didn't really wait for TakerPayment to be confirmed
i only see the approve tx on https://polygonscan.com/address/0x15c577f4b9fbe66735a9bff9b0b5d3ea2854bfaa, the TakerPayment is missing completely

@shamardy
Copy link
Collaborator Author

it was very quick, right after approve was sent the swap failed, it didn't really wait for TakerPayment to be confirmed

yes, I messed up the wait for confirmation timestamp. Will fix it, hope it's the final fix :)

@cipig
Copy link
Member

cipig commented Mar 10, 2023

yes, I messed up the wait for confirmation timestamp. Will fix it, hope it's the final fix :)

no problem, i am here and will try again :-)
i updated my comment... not sure if it's important, but i can't see any TakerPayment tx on https://polygonscan.com/address/0x15c577f4b9fbe66735a9bff9b0b5d3ea2854bfaa

@shamardy
Copy link
Collaborator Author

but i can't see any TakerPayment tx on

Yes, the wait for confirmation of the approval transaction failed / didn't really happen.

@shamardy
Copy link
Collaborator Author

it was very quick, right after approve was sent the swap failed, it didn't really wait for TakerPayment to be confirmed

Hope it's fixed in the latest commit

@shamardy
Copy link
Collaborator Author

not sure if it's important, but i can't see any TakerPayment tx on

I also fixed the error message to be more verbose.

@cipig
Copy link
Member

cipig commented Mar 10, 2023

hmmm, tried the same swap, takerpayment was ok (though since the approve already happened during last try, it is not surprising)
takerpayment: https://polygonscan.com/tx/0xdae7e065f1fa133fa0e3d7644f6fe2165f6f962263fcf658fda0c02e41a6d6e5

but now it failed on maker side, maker can't spend that takerpayment:

{
   "type" : "Maker",
   "gui" : "mpm",
   "maker_amount" : "75.40348718135140222449756185877051913932658784711776356045125342142723382741998234987164544575994030",
   "taker_amount" : "199.5167576494872144318123393316195372750642673521850899742930591259640102827763496143958868894601542",
   "events" : [
      {
         "event" : {
            "data" : {
               "taker_coin_htlc_pubkey" : "03de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "maker_coin_htlc_pubkey" : "03de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "secret" : "c3b65d519d05b0781eca87fb385ef546317b6ad25563b18f07dc2fba6466e6eb",
               "my_persistent_pub" : "03de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12",
               "maker_payment_requires_nota" : false,
               "taker_coin" : "REQ-PLG20",
               "maker_coin" : "KMD",
               "taker_coin_start_block" : 40192363,
               "maker_coin_start_block" : 3328900,
               "maker_payment_trade_fee" : {
                  "amount" : "0.00001",
                  "coin" : "KMD",
                  "paid_from_trading_vol" : false
               },
               "maker_payment_lock" : 1678487922,
               "maker_payment_confirmations" : 1,
               "started_at" : 1678472322,
               "lock_duration" : 7800,
               "taker_payment_spend_trade_fee" : {
                  "coin" : "MATIC",
                  "amount" : "0.028398645",
                  "paid_from_trading_vol" : false
               },
               "secret_hash" : "27bad525bf493187fc3fe612a28df5cd8eee5ea2",
               "p2p_privkey" : null,
               "taker_payment_confirmations" : 3,
               "uuid" : "fc4996f1-5c6f-4bb9-b743-1a39bce482a8",
               "taker_amount" : "199.5167576494872144318123393316195372750642673521850899742930591259640102827763496143958868894601542",
               "maker_amount" : "75.40348718135140222449756185877051913932658784711776356045125342142723382741998234987164544575994030",
               "taker_payment_requires_nota" : false,
               "taker" : "3c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "taker_coin_swap_contract_address" : "9130b257d37a52e52f21054c4da3450c72f595ce"
            },
            "type" : "Started"
         },
         "timestamp" : 1678472322233
      },
      {
         "timestamp" : 1678472324236,
         "event" : {
            "data" : {
               "taker_coin_htlc_pubkey" : "023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "maker_coin_htlc_pubkey" : "023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289",
               "taker_pubkey" : "000000000000000000000000000000000000000000000000000000000000000000",
               "taker_coin_swap_contract_addr" : "9130b257d37a52e52f21054c4da3450c72f595ce",
               "maker_coin_swap_contract_addr" : null,
               "taker_payment_locktime" : 1678480123
            },
            "type" : "Negotiated"
         }
      },
      {
         "event" : {
            "data" : null,
            "type" : "MakerPaymentInstructionsReceived"
         },
         "timestamp" : 1678472327465
      },
      {
         "timestamp" : 1678472327469,
         "event" : {
            "data" : {
               "tx_hash" : "fe8acee7bcd87db2dffc0220c5fdcf5ac474ee92a0b0f1f9bc74302ef17ab79c",
               "tx_hex" : "f8ae8205e58524ca6d8dc08303345094b25e20de2f2ebb4cffd4d16a55c7b395e8a9476280b844a9059cbb000000000000000000000000d8997941dd1346e9231118d5685d866294f59e5b000000000000000000000000000000000000000000000000033508ac2e6f4fae820135a09bb38238d362905cc69a01cd71d694882190c8c0c8cc28919ccae92929e49222a023eabf326f4c2ffe918b4750043cf32e14b867debc56de4801b7f422cf9bd5a3"
            },
            "type" : "TakerFeeValidated"
         }
      },
      {
         "timestamp" : 1678472327696,
         "event" : {
            "data" : {
               "tx_hex" : "0400008085202f890219413e8d48f197e077df927e58c5033463eed5ef4ba8316c7335bdfc65a6aa4a020000006a47304402203eb95b4e7ce16a00b0afc41c24231c41dc4b414eb71304fa11e5af7b3a7d8cbf022066e0e4ff9da1a123de2d8ff9723960388e7a8cc0584e2e7ec88a44b31c4121e7012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff23f7cd404375a06b37efbff3d2ff302b2c4ee5b05b8b88ee794a63876ae1c71c000000006a473044022016322ed88123d3e8de66edb51b2497fa8abb274f95e9d7b10b2c6bbccc050d6a02200e725a7b0d2d2c525d4106582950d404cb83484f123872147c5c33037f8b94c7012103de96cb66dcfaceaa8b3d4993ce8914cd5fe84e3fd53cefdae45add8032792a12ffffffff032e9770c10100000017a9142a83d07940ecc374b783425ade304ecf557696db870000000000000000166a1427bad525bf493187fc3fe612a28df5cd8eee5ea2a2a6c3cf020000001976a9146aafbb75331085425727a78a940e9334f681b3e588acd2720b64000000000000000000000000000000",
               "tx_hash" : "7cfd57462db916417bd329cf90b85df5e925bd405d6bae65ee1a8627eb82c26d"
            },
            "type" : "MakerPaymentSent"
         }
      },
      {
         "event" : {
            "data" : {
               "tx_hash" : "dae7e065f1fa133fa0e3d7644f6fe2165f6f962263fcf658fda0c02e41a6d6e5",
               "tx_hex" : "f9012e8205e68523c0e3a600830249f0949130b257d37a52e52f21054c4da3450c72f595ce80b8c49b415b2a5ac16ea0b20a5440960e2790cd6db0d78729bdcf1a14b454d90c6a4826a5b7d600000000000000000000000000000000000000000000000ad0d9e9ff4362b75f000000000000000000000000b25e20de2f2ebb4cffd4d16a55c7b395e8a94762000000000000000000000000adb681c3a1ec9bbc4105b8e8eb5fc7178125b45027bad525bf493187fc3fe612a28df5cd8eee5ea200000000000000000000000000000000000000000000000000000000000000000000000000000000640b92fb820136a07797abfbcf1fc26bb8310d46e1f9d0504f50d81d2afd469e2dd242101482b7d8a0285a8031979841c009aa0c87b88975f7c7a2d627123bb35c9807958a0fe31db9"
            },
            "type" : "TakerPaymentReceived"
         },
         "timestamp" : 1678472482091
      },
      {
         "event" : {
            "type" : "TakerPaymentWaitConfirmStarted"
         },
         "timestamp" : 1678472482096
      },
      {
         "timestamp" : 1678472498017,
         "event" : {
            "type" : "TakerPaymentValidatedAndConfirmed"
         }
      },
      {
         "event" : {
            "data" : {
               "error" : "maker_swap:1076] !taker_coin.send_maker_spends_taker_payment: eth:3226] Payment SignedTransaction { transaction: UnverifiedTransaction { unsigned: Transaction { nonce: 1510, gas_price: 153560000000, gas: 150000, action: Call(0x9130b257d37a52e52f21054c4da3450c72f595ce), value: 0, data: [155, 65, 91, 42, 90, 193, 110, 160, 178, 10, 84, 64, 150, 14, 39, 144, 205, 109, 176, 215, 135, 41, 189, 207, 26, 20, 180, 84, 217, 12, 106, 72, 38, 165, 183, 214, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 208, 217, 233, 255, 67, 98, 183, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 178, 94, 32, 222, 47, 46, 187, 76, 255, 212, 209, 106, 85, 199, 179, 149, 232, 169, 71, 98, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 173, 182, 129, 195, 161, 236, 155, 188, 65, 5, 184, 232, 235, 95, 199, 23, 129, 37, 180, 80, 39, 186, 213, 37, 191, 73, 49, 135, 252, 63, 230, 18, 162, 141, 245, 205, 142, 238, 94, 162, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 11, 146, 251] }, v: 310, r: 54093209875574860349268306821077452377815171249065048151428914128480796587992, s: 18252414939695276878685322630802245650202375204001076954701036828689023835577, hash: 0xdae7e065f1fa133fa0e3d7644f6fe2165f6f962263fcf658fda0c02e41a6d6e5 }, sender: 0x15c577f4b9fbe66735a9bff9b0b5d3ea2854bfaa, public: Some(0x3c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f2890c7e83dfe4a34a21b636d8dc0074f619e962da35d4bc60d1fe88c956cafaa09e) } state is not PAYMENT_STATE_SENT, got 0"
            },
            "type" : "TakerPaymentSpendFailed"
         },
         "timestamp" : 1678472498246
      },
      {
         "event" : {
            "type" : "MakerPaymentWaitRefundStarted",
            "data" : {
               "wait_until" : 1678491622
            }
         },
         "timestamp" : 1678472498251
      },
      {
         "event" : {
            "type" : "MakerPaymentRefundStarted"
         },
         "timestamp" : 1678472498257
      }
   ],
   "taker_coin" : "REQ-PLG20",
   "maker_coin" : "KMD",
   "uuid" : "fc4996f1-5c6f-4bb9-b743-1a39bce482a8",
   "taker_coin_usd_price" : null,
   "maker_coin_usd_price" : null,
   "success_events" : [
      "Started",
      "Negotiated",
      "MakerPaymentInstructionsReceived",
      "TakerFeeValidated",
      "MakerPaymentSent",
      "TakerPaymentReceived",
      "TakerPaymentWaitConfirmStarted",
      "TakerPaymentValidatedAndConfirmed",
      "TakerPaymentSpent",
      "TakerPaymentSpendConfirmStarted",
      "TakerPaymentSpendConfirmed",
      "Finished"
   ],
   "mm_version" : "1.0.0-beta_10480_bugfix-wait-confirm-approval_b56f307bb_Linux_CI",
   "my_order_uuid" : "47c941c6-1d65-4332-ad4a-cba21d846593",
   "error_events" : [
      "StartFailed",
      "NegotiateFailed",
      "TakerFeeValidateFailed",
      "MakerPaymentTransactionFailed",
      "MakerPaymentDataSendFailed",
      "MakerPaymentWaitConfirmFailed",
      "TakerPaymentValidateFailed",
      "TakerPaymentWaitConfirmFailed",
      "TakerPaymentSpendFailed",
      "TakerPaymentSpendConfirmFailed",
      "MakerPaymentWaitRefundStarted",
      "MakerPaymentRefundStarted",
      "MakerPaymentRefunded",
      "MakerPaymentRefundFailed",
      "MakerPaymentRefundFinished"
   ]
}

not sure if this is related to this changes, error message is the same as in #1224 state is not PAYMENT_STATE_SENT, got 0
will do some more tests after i receive the REQ-PLG20 back from this swap... will send them manually to this maker and try the opposite swap (buying the REQ-PLG20 from that maker, who doesn't have an approve tx for REQ-PLG20)

console on maker does not show anything useful:

| (2:33) [swap uuid=fc4996f1-5c6f-4bb9-b743-1a39bce482a8] Maker payment sent...
10 18:21:22, maker_swap:951] INFO Taker payment tx dae7e065f1fa133fa0e3d7644f6fe2165f6f962263fcf658fda0c02e41a6d6e5
+--- 10 18:21:24 -------
| (2:41) [swap uuid=fc4996f1-5c6f-4bb9-b743-1a39bce482a8] Taker payment wait confirm started...
| (0:01/101:19) [REQ-PLG20] Waiting for confirmations…
· 2023-03-10 18:21:37 +0000 [REQ-PLG20] Waiting for confirmations… Confirmed.
+--- 10 18:21:38 -------
| (2:55) [swap uuid=fc4996f1-5c6f-4bb9-b743-1a39bce482a8] Taker payment validated and confirmed...
+--- 10 18:21:46 -------
| (3:04) [swap uuid=fc4996f1-5c6f-4bb9-b743-1a39bce482a8] Maker payment refund started...

@cipig
Copy link
Member

cipig commented Mar 10, 2023

maybe worth doing this change too: #1630 (comment)

@cipig
Copy link
Member

cipig commented Mar 10, 2023

next problem is that the swap failed on the maker, but not yet on taker:
image
although the taker_payment locktime already expired 2h ago and maker_payment locktime 10 minutes ago:

               "taker_payment_lock" : 1678480123,
               "maker_payment_locktime" : 1678487922,

@cipig
Copy link
Member

cipig commented Mar 10, 2023

after waiting for more than 5h, i killed ADEX Desktop and after restart i was refunded right away

@cipig
Copy link
Member

cipig commented Mar 12, 2023

sent REQ-PLG20 manually to the maker and started a swap... worked fine
image

mm2 waited for the approve, payment was confirmed 5 blocks later... also fine
image

state is not PAYMENT_STATE_SENT, got 0 problem happening sometimes persists

taker not failing swap although maker failed it and locktime expired a long time ago persists, which is very dangerous since the other side (maker) could easily rob taker if he knows how

cipig
cipig previously approved these changes Mar 12, 2023
@shamardy
Copy link
Collaborator Author

maybe worth doing this change too: #1630 (comment)

Agree, I should work on it this week on another PR :)

next problem is that the swap failed on the maker, but not yet on taker:

Is this the same swap here #1706 (comment) but from the taker's side? If so, I will investigate all these problems this week and try to solve one by one starting by this #1630 (comment)

@shamardy
Copy link
Collaborator Author

@caglaryucekaya can you please take a look at this PR?

@shamardy
Copy link
Collaborator Author

@caglaryucekaya can you please take a look at this PR?

Nevermind, just saw your comment here #1706 (comment). I should fix this first before you start the review process.

]));
let value = U256::from(args.watcher_reward.unwrap_or(0));
// wait for the approval tx confirmation only half the time required for the actual htlc tx confirmation
let wait_for_approval_confirmation_until = args.wait_for_confirmation_until / 2;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@caglaryucekaya Do you think the wait period should be reduced for the approval confirmation? I don't want the check for confirmation to fail quickly if there is no new blocks for some time but if there is a problem with the approval transaction we want it to fail quickly, so that is the trade off between longer vs shorter wait time.

Choose a reason for hiding this comment

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

We could put some random limit on it, but I think we can leave it this way. If the transaction is sent successfully with enough gas and correct addresses it shouldn't fail. Are there any other reasons why it can fail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but I think we can leave it this way

Yeah, I think so too.

Are there any other reasons why it can fail?

There is a more general problem with block reorganization specially with polygon, but this should be solved using a higher value for required confs for both taker and maker and if the approve transaction disappears, dependant transactions will fail too, so I see no problem with the current approach.

U256::from(ETH_GAS),
.and_then(move |approved| {
// make sure the approve tx is confirmed before sending the htlc tx
arc.wait_for_confirmations(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the detailed research/explanation for this. Will fix it :)

@cipig
Copy link
Member

cipig commented Mar 13, 2023

Is this the same swap here #1706 (comment) but from the taker's side? If so, I will investigate all these problems this week and try to solve one by one starting by this #1630 (comment)

Yes, it was that swap.

@shamardy
Copy link
Collaborator Author

@caglaryucekaya fixed this #1706 (comment) in the latest commit. This is ready for review now :)

Copy link

@caglaryucekaya caglaryucekaya left a comment

Choose a reason for hiding this comment

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

LGTM!

@shamardy shamardy merged commit 169964e into dev Mar 13, 2023
@shamardy shamardy deleted the bugfix-wait-confirm-approval branch March 13, 2023 22:15
shamardy added a commit that referenced this pull request Mar 13, 2023
shamardy added a commit that referenced this pull request Mar 14, 2023
* add change logs for PRs merged to dev only

* remove {version} - {date} and add dev branch instead

* add ibc transfer change logs

* add lightning PR #1655 to change logs

* add changelog for #1706

* add changelog for #1694, #1665

---------

Reviewed-by: laruh, caglaryucekaya <[email protected]>
@ca333 ca333 mentioned this pull request Mar 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants