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

Maker payment wait refund 2 days overdue #843

Closed
cipig opened this issue Mar 4, 2021 · 16 comments · Fixed by #845
Closed

Maker payment wait refund 2 days overdue #843

cipig opened this issue Mar 4, 2021 · 16 comments · Fixed by #845
Assignees
Labels
bug Something isn't working P1

Comments

@cipig
Copy link
Member

cipig commented Mar 4, 2021

after a failed swap (TakerPaymentValidateFailed), maker waits for maker payment refund forever (looks like)
console shows this, which is 2 days ago:
| (3526:26) [swap uuid=c246d768-d951-4827-8e07-12ac8a73ea2d] Maker payment wait refund till 1614622051 started...

after restarting mm2, maker payment is refunded immediately:

      {
         "timestamp" : 1614607610619,
         "event" : {
            "type" : "TakerPaymentValidateFailed",
            "data" : {
               "error" : "lp_swap:217] Timeout (4771 > 4770)"
            }
         }
      },
      {
         "timestamp" : 1614607610620,
         "event" : {
            "type" : "MakerPaymentWaitRefundStarted",
            "data" : {
               "wait_until" : 1614622051
            }
         }
      },
      {
         "event" : {
            "data" : {
               "tx_hash" : "919f4d098ca9617ba94da18b87660ca293c3231a51d503c32cb47154a04891d8",
               "tx_hex" : "0100000001b86356ba234f36b30950c597de678d72132753fdf5abf7f3886df6cf27d7227300000000b7483045022100ff9c7c337c6b2eeca68d19f023d546b0739767a747b8e4b7f71655d24765c0af0220329f1a111b0879e24a9d548337a00127d5718afd739a96e47810e7e4f747c5f201514c6b6304ef1e3d60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a9145971accc73214b72ca62dfab1c4b0298698f8c6a8821029b1ab79d626ac4e0e2419732c0a708b9de534a3c95972a9fad626e750bfc9f35ac68feffffff012ad517f3060000001976a914124b0846223ef78130b8e544b9afc3b09988238688acef1e3d60"
            },
            "type" : "MakerPaymentRefunded"
         },
         "timestamp" : 1614817946136
      },

makerpayment DOGE: https://blockchair.com/dogecoin/transaction/7322d727cff66d88f3f7abf5fd532713728d67de97c55009b3364f23ba5663b8
makerpaymentrefund DOGE: https://blockchair.com/dogecoin/transaction/919f4d098ca9617ba94da18b87660ca293c3231a51d503c32cb47154a04891d8

@artemii235 artemii235 added the bug Something isn't working label Mar 4, 2021
@artemii235 artemii235 self-assigned this Mar 4, 2021
@artemii235
Copy link
Member

Thanks for opening the issue! I will investigate it.

@artemii235
Copy link
Member

@cipig Could you please request a block from the DOGE daemon that was close to the swap's start time and share the result?

@artemii235
Copy link
Member

The problem is Doge has a custom AuxPOW block header format. It leads to MM2 reading a random sequence of bytes as a block timestamp so it can get a number like 1977568965 as MTP. Due to recent changes, MM2 waits for MTP - payment locktime before a refund attempt so it could take years literally 🙂 I'm adding support of AuxPOW block header now and will also add a reasonable maximum for waiting time (e.g. 1 hour).

@artemii235
Copy link
Member

@cipig Could you please trigger the Doge refund in Electrum mode using the MM2 from linked PR? It should be fixed now.

@cipig
Copy link
Member Author

cipig commented Mar 4, 2021

works good now, thanks for the fix

| (0:00) [swap uuid=83392247-c3a8-4912-ab37-6f2b779fa821] Started...
04 13:38:52, maker_swap:563] Maker payment tx b383b0d9350f05ab8981062b6ba24a088a034e57dd940e59f686522e68da3928
04 13:38:52, rpc_clients:152] Waiting for tx b383b0d9350f05ab8981062b6ba24a088a034e57dd940e59f686522e68da3928 confirmations, now 0, required 2, requires_notarization false

+--- 04 15:00:13 -------
| (81:23) [swap uuid=83392247-c3a8-4912-ab37-6f2b779fa821] Maker payment wait refund till 1614884429 started...

+--- 04 18:58:37 -------
| (319:48) [swap uuid=83392247-c3a8-4912-ab37-6f2b779fa821] Maker payment wait refund till 1614884429 started...
04 18:58:50, maker_swap:804] Maker payment refund tx f7a7c2a7c5f961cb260ec9f6285b99e6df1b1d4d2511c778cbd7514be8dd495b
· 2021-03-04 18:58:50 +0000 [swap uuid=83392247-c3a8-4912-ab37-6f2b779fa821] Finished

https://blockchair.com/dogecoin/transaction/f7a7c2a7c5f961cb260ec9f6285b99e6df1b1d4d2511c778cbd7514be8dd495b

@artemii235
Copy link
Member

Thanks for the report and testing 🙂

artemii235 added a commit that referenced this issue Mar 5, 2021
…x-aux-pow

Support AuxPOW block header (DOGE). CanRefundHtlc::HaveToWait max 1 hour.
#843
@cipig
Copy link
Member Author

cipig commented Mar 22, 2021

Unfortunately this happened again, but this time with FIRO as makercoin:

| (6291:14) [swap uuid=5eee731b-4f99-4d32-b37f-5d3102215af7] Maker payment wait refund till 1616058809 started...
| (4317:42) [swap uuid=1b001143-20e2-4b99-b08f-170ef237371b] Maker payment wait refund till 1616177221 started...

this are the makerpayments:
https://explorer.firo.org/tx/37036036b179c9e6c4a7d97f89294667dc24257ed13805f70cc0f779dbe9dd19
https://explorer.firo.org/tx/42034efc62ba6c8c6744c7f8c6b418bc0c03ebb9797180b1f2eb7f3bfdd43643

maker is using electrum for FIRO

@artemii235
Copy link
Member

@cipig Could you please retest FIRO using the https://github.com/KomodoPlatform/atomicDEX-API/tree/mm2.1-fix-firo-refund branch?

@cipig
Copy link
Member Author

cipig commented Mar 23, 2021

the 2 swaps were refunded right after restart
a newly created refund situation was refunded 1 hour after the specified time

+--- 23 20:20:01 -------
| (379:54) [swap uuid=bae0b6b2-2ea3-40a5-a7d1-9573785b90f3] Maker payment wait refund till 1616527306 started...
23 20:20:08, maker_swap:811] Maker payment refund tx 9f4c078b1f544c42017c3bb1b1cc45824178f68cf8f8e63b90c7aaf5c30f96ab
· 2021-03-23 20:20:08 +0000 [swap uuid=bae0b6b2-2ea3-40a5-a7d1-9573785b90f3] Finished

1616527306 is 19:21:46

this is the relevant part from swap json:

      {
         "timestamp" : 1616508009362,
         "event" : {
            "type" : "MakerPaymentSent",
            "data" : {
               "tx_hash" : "dfae03458cd0d7a0d886c9db6816885f08d733bfe7e3e27d7b57cfe456438bf7",
               "tx_hex" : "0100000001a1c6d15b81dbccc44f8866f529ad84e4df41048ac97f5717178c2ee2012e37c7000000006b483045022100de7bab79068b2cf1bceb5fb0588bd7707d7831a9fb72d220ebe020c00a08007402203707cd137e8c55491070be67148256c16f8f5fc9f7debea8ae54be4842db3515012102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ffffffff03809698000000000017a914abdb88cbc00857a1b2805e29ebcb6d8133e3bfd6870000000000000000166a14b59abb3b9edbcb4816ea103adc733e09b1e540217ef8d202000000001976a914124b0846223ef78130b8e544b9afc3b09988238688ac69f45960"
            }
         }
      },
      {
         "event" : {
            "data" : {
               "error" : "lp_swap:214] Timeout (4771 > 4770)"
            },
            "type" : "TakerPaymentValidateFailed"
         },
         "timestamp" : 1616513798496
      },
      {
         "event" : {
            "data" : {
               "wait_until" : 1616527306
            },
            "type" : "MakerPaymentWaitRefundStarted"
         },
         "timestamp" : 1616513798497
      },
      {
         "event" : {
            "data" : {
               "tx_hex" : "0100000001f78b4356e4cf577b7de2e3e7bf33d7085f881668dbc986d8a0d7d08c4503aedf00000000b7483045022100f9a63fdd1285c89b4e4d27770c4e5149ccdea24936bb73d7ac75f5cceebcd21f02204195312e7975fac0f2b48fb99bfcc4ad5ebe19604754cda2143ed35bd241a1d101514c6b630456315a60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a914b59abb3b9edbcb4816ea103adc733e09b1e5402188210315d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732ac68feffffff0166929800000000001976a914124b0846223ef78130b8e544b9afc3b09988238688ac683f5a60",
               "tx_hash" : "9f4c078b1f544c42017c3bb1b1cc45824178f68cf8f8e63b90c7aaf5c30f96ab"
            },
            "type" : "MakerPaymentRefunded"
         },
         "timestamp" : 1616530808771
      },

artemii235 added a commit that referenced this issue Mar 24, 2021
* WIP.

* Support FIRO specific block header format
@artemii235
Copy link
Member

Thanks for testing!

a newly created refund situation was refunded 1 hour after the specified time

The specified time can be considered as approximate because we should wait for more for MTP to advance, and this time can not be calculated with 100% precision. I'm closing this issue, please feel free to reopen if you discover more of such coins.

@artemii235
Copy link
Member

Verus had similar problem, fixed in 335c960

@cipig
Copy link
Member Author

cipig commented May 2, 2021

found another coin where this is still present: SYS
| (1493:40) [swap uuid=11bc6684-41e2-4afb-8f67-eaf3a63b64b2] Maker payment wait refund till 1619884720 started...
which as of now is 20 hours ago

@artemii235
Copy link
Member

Thanks for the report, I reopen the issue until SYS is fixed.

@artemii235
Copy link
Member

@cipig Should be fixed now, could you please test the linked PR?

@cipig
Copy link
Member Author

cipig commented May 3, 2021

the refund worked fine this time, thanks for the fix

+--- 03 17:03:10 -------
| (319:48) [swap uuid=c9bae85a-c3e2-4c01-bee4-8b8dc6446544] Maker payment wait refund till 1620061502 started...
03 17:03:23, maker_swap:814] Maker payment refund tx 3c84fd6800379f9c79e84a59fec9dbe9f88ecac25f61c1e5908e0cb3102dad02
· 2021-05-03 17:03:23 +0000 [swap uuid=c9bae85a-c3e2-4c01-bee4-8b8dc6446544] Finished

artemii235 added a commit that referenced this issue May 4, 2021
* Fix Syscoin indefinite refund wait.
Ensure that p2sh spending tx locktime is below the MTP.

* Rename locktime_from_script to htlc_locktime.
@artemii235
Copy link
Member

Great, closing until we discover a new coin with such behavior:slightly_smiling_face:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1
Projects
None yet
2 participants