KomodoPlatform / komodo-defi-framework

This is the official Komodo DeFi Framework repository
https://komodoplatform.com/en/docs/komodo-defi-framework/
102 stars 94 forks source link

MakerPaymentRefundFailed for BCH with `bad-txns-nonfinal` #544

Closed cipig closed 3 years ago

cipig commented 4 years ago

The MakerPaymentRefund of a interrupted swap failed

         "event" : {
            "data" : {
               "error" : "maker_swap:580] !maker_coin.send_maker_refunds_payment: utxo:1080] rpc_clients:314] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"1.0\", id: \"0\", method: \"sendrawtransaction\", params: [String(\"0100000001d2977ac3dacbba5bec97b2ba70a6d38d9b82adaccc4f28b43b9a7c1402e6dd8900000000b748304502210095e05494bc6bda926908780b56d2b2c28ef0fbe654902aea4fc0bf7e1e168196022066c42403e557119fc5f120d9f167c417c0b6e45ef4f9272e0416cdf9e836f5c441514c6b630493437f5db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914c47db374575110d2d4990542a0b5f5d46c4367088821027b73ef0dfc05e472048712c36128844b92958dc4d6693aa2c06fcd20d95d85aeac68feffffff013145d301000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88acfa437f5d\")] }, error: Transport(\"rpc_clients:266] Rpc request JsonRpcRequest { jsonrpc: \\\"1.0\\\", id: \\\"0\\\", method: \\\"sendrawtransaction\\\", params: [String(\\\"0100000001d2977ac3dacbba5bec97b2ba70a6d38d9b82adaccc4f28b43b9a7c1402e6dd8900000000b748304502210095e05494bc6bda926908780b56d2b2c28ef0fbe654902aea4fc0bf7e1e168196022066c42403e557119fc5f120d9f167c417c0b6e45ef4f9272e0416cdf9e836f5c441514c6b630493437f5db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914c47db374575110d2d4990542a0b5f5d46c4367088821027b73ef0dfc05e472048712c36128844b92958dc4d6693aa2c06fcd20d95d85aeac68feffffff013145d301000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88acfa437f5d\\\")] } failed with HTTP status code 500 Internal Server Error, response body: {\\\"result\\\":null,\\\"error\\\":{\\\"code\\\":-26,\\\"message\\\":\\\"bad-txns-nonfinal, non-final transaction (code 64)\\\"},\\\"id\\\":\\\"0\\\"}\\n\") }"
            },
            "type" : "MakerPaymentRefundFailed"
         },
         "timestamp" : 1568625162834

The reason the swap failed initially was that the Taker apparently stopped his node in the middle of the swap. The initial MakerPayment took 1.5h because there was no new block during that time on the BCH chain (Tx was confirmed in the first block that came after that gap).

This is the entire swap log: ab40f146-ec98-497f-8e8e-d38c78b4361b.txt

After calling curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"recover_funds_of_swap\",\"params\":{\"uuid\":\"ab40f146-ec98-497f-8e8e-d38c78b4361b\"}}" | json_pp the failed MakerPaymentRefund was sent out:

{
   "result" : {
      "coin" : "BCH",
      "tx_hex" : "0100000001d2977ac3dacbba5bec97b2ba70a6d38d9b82adaccc4f28b43b9a7c1402e6dd8900000000b647304402204c68ee10ccb8faf455573a4228312456b760ac37bbf22a080113b9e492dfd2b502203f4442e50263af40b4819f7e2eb3ef3c90f5812c53a7cd134cb07ffda45d5c9141514c6b630493437f5db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914c47db374575110d2d4990542a0b5f5d46c4367088821027b73ef0dfc05e472048712c36128844b92958dc4d6693aa2c06fcd20d95d85aeac68feffffff013145d301000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac2b867f5d",
      "action" : "RefundedMyPayment",
      "tx_hash" : "67ae764420c83117eeb406f6e7c0d4f7e0fec438e4e644e5e8d2bae031ed5144"
   }
}
cipig commented 4 years ago

I have another such error, also with BCH

         "timestamp" : 1572262095098,
         "event" : {
            "data" : {
               "error" : "maker_swap:626] !maker_coin.send_maker_refunds_payment: utxo:1084] rpc_clients:331] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"1.0\", id: \"0\", method: \"sendrawtransaction\", params: [String(\"01000000015b6ccd18cc1d492732d3ee2f4409a59a57a240ac5d6590ba8d70a42add08dffe00000000b647304402200fcc045f61a160d04306f1d5e7e08dda9899ee5fa14ada65e99ed7c417e103f3022053387384f12f1e6de173ab49441811beca1f10d1e29098628af6ffc9171c80d741514c6b630455c2b65db1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a91417f69325017aaffc87cd9e9fcdb163339bda9b548821027b73ef0dfc05e472048712c36128844b92958dc4d6693aa2c06fcd20d95d85aeac68feffffff011999d301000000001976a914124b0846223ef78130b8e544b9afc3b09988238688acbfc2b65d\")] }, error: Transport(\"rpc_clients:283] Rpc request JsonRpcRequest { jsonrpc: \\\"1.0\\\", id: \\\"0\\\", method: \\\"sendrawtransaction\\\", params: [String(\\\"01000000015b6ccd18cc1d492732d3ee2f4409a59a57a240ac5d6590ba8d70a42add08dffe00000000b647304402200fcc045f61a160d04306f1d5e7e08dda9899ee5fa14ada65e99ed7c417e103f3022053387384f12f1e6de173ab49441811beca1f10d1e29098628af6ffc9171c80d741514c6b630455c2b65db1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a91417f69325017aaffc87cd9e9fcdb163339bda9b548821027b73ef0dfc05e472048712c36128844b92958dc4d6693aa2c06fcd20d95d85aeac68feffffff011999d301000000001976a914124b0846223ef78130b8e544b9afc3b09988238688acbfc2b65d\\\")] } failed with HTTP status code 500 Internal Server Error, response body: {\\\"result\\\":null,\\\"error\\\":{\\\"code\\\":-26,\\\"message\\\":\\\"bad-txns-nonfinal, non-final transaction (code 64)\\\"},\\\"id\\\":\\\"0\\\"}\\n\") }"
            },
            "type" : "MakerPaymentRefundFailed"

recover_funds_of_swap helped

cipig commented 4 years ago

i have another MakerPaymentRefundFailed on BTC with non-final

         "timestamp" : 1574065685885,
         "event" : {
            "data" : {
               "error" : "maker_swap:626] !maker_coin.send_maker_refunds_payment: utxo:1084] rpc_clients:331] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"1.0\", id: \"0\", method: \"sendrawtransaction\", params: [String(\"01000000016bfa3e75de569f312a9045593a28d27e48b056154d6b25b5ceb11b4e77a2108500000000b64730440220745ef83d54b50243a911021ab20606b0ba6388e84dee46ef675c0a15c402fde9022005dfc9e16066fc9d5d4f7e4eae4496c99fde0768bbb7f2565428e17d701ad46d01514c6b63049a47d25db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a91481149d928d8658b610280b44e559c2c83bb95b30882103faa0ad92c52eff8ec865891112be670a3fa57ca2f806fce0efa8bedd09a84962ac68feffffff01e5d61000000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac0548d25d\")] }, error: Transport(\"rpc_clients:283] Rpc request JsonRpcRequest { jsonrpc: \\\"1.0\\\", id: \\\"0\\\", method: \\\"sendrawtransaction\\\", params: [String(\\\"01000000016bfa3e75de569f312a9045593a28d27e48b056154d6b25b5ceb11b4e77a2108500000000b64730440220745ef83d54b50243a911021ab20606b0ba6388e84dee46ef675c0a15c402fde9022005dfc9e16066fc9d5d4f7e4eae4496c99fde0768bbb7f2565428e17d701ad46d01514c6b63049a47d25db17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a91481149d928d8658b610280b44e559c2c83bb95b30882103faa0ad92c52eff8ec865891112be670a3fa57ca2f806fce0efa8bedd09a84962ac68feffffff01e5d61000000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac0548d25d\\\")] } failed with HTTP status code 500 Internal Server Error, response body: {\\\"result\\\":null,\\\"error\\\":{\\\"code\\\":-26,\\\"message\\\":\\\"non-final (code 64)\\\"},\\\"id\\\":\\\"0\\\"}\\n\") }"
            },
            "type" : "MakerPaymentRefundFailed"
         }

calling recover_funds_of_swap does not help and shows the same error

cipig commented 4 years ago

had a couple of MakerPaymentRefundFailed today, but on KMD, with non-mandatory-script-verify-flag (Locktime requirement not satisfied) don't know if it is the same problem... here is a collection

            "type" : "MakerPaymentRefundFailed",
            "data" : {
               "error" : "maker_swap:678] !maker_coin.send_maker_refunds_payment: utxo:1092] rpc_clients:398] JsonRpcError { client_info: \"coin: KMD\", request: JsonRpcRequest { jsonrpc: \"1.0\", id: \"0\", method: \"sendrawtransaction\", params: [String(\"0400008085202f8901fc75e03cb9ea406cf260a886b9bea014721a31c6ab7c6459697f0c04235af19b00000000b647304402203ef4b3a5a40401a1c686c3d3669385c2e08277d3d08ae0ebfb111301625772b702200aed311cd96f563d885ed4a0314971cefc3947e5b99ccb241da4cc722700853701514c6b63041227a25eb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914d22dc955578f5c9d51ed8a16c90f635a45912d1a882102599282b47dc5c01fbcf26dafe5852457e3347cb0703f8c830b6560e75c9f71bbac68ffffffff01b0e92300000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac912da25e000000000000000000000000000000\")] }, error: Transport(\"rpc_clients:348] Rpc request JsonRpcRequest { jsonrpc: \\\"1.0\\\", id: \\\"0\\\", method: \\\"sendrawtransaction\\\", params: [String(\\\"0400008085202f8901fc75e03cb9ea406cf260a886b9bea014721a31c6ab7c6459697f0c04235af19b00000000b647304402203ef4b3a5a40401a1c686c3d3669385c2e08277d3d08ae0ebfb111301625772b702200aed311cd96f563d885ed4a0314971cefc3947e5b99ccb241da4cc722700853701514c6b63041227a25eb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914d22dc955578f5c9d51ed8a16c90f635a45912d1a882102599282b47dc5c01fbcf26dafe5852457e3347cb0703f8c830b6560e75c9f71bbac68ffffffff01b0e92300000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac912da25e000000000000000000000000000000\\\")] } failed with HTTP status code 500 Internal Server Error, response body: {\\\"result\\\":null,\\\"error\\\":{\\\"code\\\":-26,\\\"message\\\":\\\"64: non-mandatory-script-verify-flag (Locktime requirement not satisfied)\\\"},\\\"id\\\":\\\"0\\\"}\\n\") }"

            "type" : "MakerPaymentRefundFailed",
            "data" : {
               "error" : "maker_swap:678] !maker_coin.send_maker_refunds_payment: utxo:1092] rpc_clients:398] JsonRpcError { client_info: \"coin: KMD\", request: JsonRpcRequest { jsonrpc: \"1.0\", id: \"0\", method: \"sendrawtransaction\", params: [String(\"0400008085202f8901c7e46a0913e3f42a3a0684b481fd478b3b0ca84d19c7e36ce58f8a060d14d40d00000000b7483045022100d6f42c76a6946c8a8722538ced42ebf992812f7d9457c2feb0c401dee8216bf202206dc0e2a5b34b6d08c7cae9a084aa229136abedfbda74373dc641ff5c3a4b01d901514c6b63049623a25eb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914730611b152c6fa21abaa1582ab4853897ffbd822882102599282b47dc5c01fbcf26dafe5852457e3347cb0703f8c830b6560e75c9f71bbac68ffffffff0100d46f00000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac112aa25e000000000000000000000000000000\")] }, error: Transport(\"rpc_clients:348] Rpc request JsonRpcRequest { jsonrpc: \\\"1.0\\\", id: \\\"0\\\", method: \\\"sendrawtransaction\\\", params: [String(\\\"0400008085202f8901c7e46a0913e3f42a3a0684b481fd478b3b0ca84d19c7e36ce58f8a060d14d40d00000000b7483045022100d6f42c76a6946c8a8722538ced42ebf992812f7d9457c2feb0c401dee8216bf202206dc0e2a5b34b6d08c7cae9a084aa229136abedfbda74373dc641ff5c3a4b01d901514c6b63049623a25eb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914730611b152c6fa21abaa1582ab4853897ffbd822882102599282b47dc5c01fbcf26dafe5852457e3347cb0703f8c830b6560e75c9f71bbac68ffffffff0100d46f00000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac112aa25e000000000000000000000000000000\\\")] } failed with HTTP status code 500 Internal Server Error, response body: {\\\"result\\\":null,\\\"error\\\":{\\\"code\\\":-26,\\\"message\\\":\\\"64: non-mandatory-script-verify-flag (Locktime requirement not satisfied)\\\"},\\\"id\\\":\\\"0\\\"}\\n\") }"

calling recover_funds_of_swap shows the same error...

this is the complete json of such a swap 5725e6f6-f452-450e-929a-34f40cdc4393.txt

happens on HUSH too

            "type" : "MakerPaymentRefundFailed",
            "data" : {
               "error" : "maker_swap:678] !maker_coin.send_maker_refunds_payment: utxo:1092] rpc_clients:398] JsonRpcError { client_info: \"coin: HUSH\", request: JsonRpcRequest { jsonrpc: \"1.0\", id: \"0\", method: \"sendrawtransaction\", params: [String(\"0400008085202f89012cdf721a45f9a071b7d03e13f4609be2b2d76f93373dd0638952a5b34b8f150300000000b64730440220031aeea9649910a1000ed98fb239d6a0f1c0c0b99a23925fee1fc6f0d3ccc41d0220593cb954eaa63918056fccb52bf697ea2bad4ac14a01f1e3090808a6198f218301514c6b63042ac3a45eb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914fb3841343e45e9fdc96e88d9cf706ea77b617ccf88210207498d311ebd9f103a079527870908d52ed6664f7b1a79ffc00e261d32de74caac68ffffffff015b3c7ffe070000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac95c3a45e000000000000000000000000000000\")] }, error: Transport(\"rpc_clients:348] Rpc request JsonRpcRequest { jsonrpc: \\\"1.0\\\", id: \\\"0\\\", method: \\\"sendrawtransaction\\\", params: [String(\\\"0400008085202f89012cdf721a45f9a071b7d03e13f4609be2b2d76f93373dd0638952a5b34b8f150300000000b64730440220031aeea9649910a1000ed98fb239d6a0f1c0c0b99a23925fee1fc6f0d3ccc41d0220593cb954eaa63918056fccb52bf697ea2bad4ac14a01f1e3090808a6198f218301514c6b63042ac3a45eb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914fb3841343e45e9fdc96e88d9cf706ea77b617ccf88210207498d311ebd9f103a079527870908d52ed6664f7b1a79ffc00e261d32de74caac68ffffffff015b3c7ffe070000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac95c3a45e000000000000000000000000000000\\\")] } failed with HTTP status code 500 Internal Server Error, response body: {\\\"result\\\":null,\\\"error\\\":{\\\"code\\\":-26,\\\"message\\\":\\\"64: non-mandatory-script-verify-flag (Locktime requirement not satisfied)\\\"},\\\"id\\\":\\\"0\\\"}\\n\") }"
cipig commented 4 years ago

i can't recover any of the above funds... some of them are 3 days old, so waiting does not seem to help

artemii235 commented 4 years ago

The bug appeared during refactoring, function sending maker refund transaction is using final sequence so locktime is ignored by coin daemon. Will fix asap.

artemii235 commented 4 years ago

Should be fixed now, I've added the integration test covering this case so it will never happen again. Could you please update and retry recovering your KMD? Please keep this issue open afterwards because it's also related to another problem.

cipig commented 4 years ago

that was fast :-) thanks a lot, it works

curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"recover_funds_of_swap\",\"params\":{\"uuid\":\"a39e2ea2-adfb-4e4d-b108-5766404ae5c6\"}}" | json_pp
{
   "result" : {
      "tx_hash" : "08aab7766a36ed3ee15e289a46ce26e1d642b53caa9a977b7c69caa78d574ac9",
      "tx_hex" : "0400008085202f8901c7e46a0913e3f42a3a0684b481fd478b3b0ca84d19c7e36ce58f8a060d14d40d00000000b647304402206c7ab691a8d6ad6372689ec5ad99b397a03c2a8e5df2b2d067e80aedfa6a84bb0220581ee6444e08a9470b881e81ad594487ded01798015c951f4cfc415c5c5bd9aa01514c6b63049623a25eb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a914730611b152c6fa21abaa1582ab4853897ffbd822882102599282b47dc5c01fbcf26dafe5852457e3347cb0703f8c830b6560e75c9f71bbac68feffffff0100d46f00000000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac1bd9a65e000000000000000000000000000000",
      "action" : "RefundedMyPayment",
      "coin" : "KMD"
   }
}
cipig commented 4 years ago

TakerPaymentRefundFailed on BTC with same non-final from a user

            "event": {
              "data": {
                "error": "taker_swap:854] utxo:1031] rpc_clients:938] JsonRpcError { request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"537242\", method: \"blockchain.transaction.broadcast\", params: [String(\"0100000001c8fbbe1a1abb35fecea258e17ce73c9312b15a22a3d9ba0f639a4f060a0371ae00000000b6473044022046b1960b8a86b0fc3e3dd08d5028a799e0e0f7d64a06acceb7ffb057b812f9e00220027b2c691a7a72f7950c0261e357bbcbecedce7493c2aea9b9043e675e7e57cd01514c6b6304091eaf5eb175210252d4d314bf1eca9c5ee6795e7102eb5dc0b5384dd3dd320f2a2be047dc899676ac6782012088a91462f012a8663f5501fe7b404caaba817b5d0f16348821026bdba9a6c9abe82de0b67c6b243cfe6c72b28368ae69e9f3f09ec4220740cac5ac68feffffff01719e5300000000001976a91499dfbd9c066b8312fcdd7b3ecf0e736701a93b0188ac751eaf5e\")] }, error: Response(Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\nnon-final (code 64)\\n[0100000001c8fbbe1a1abb35fecea258e17ce73c9312b15a22a3d9ba0f639a4f060a0371ae00000000b6473044022046b1960b8a86b0fc3e3dd08d5028a799e0e0f7d64a06acceb7ffb057b812f9e00220027b2c691a7a72f7950c0261e357bbcbecedce7493c2aea9b9043e675e7e57cd01514c6b6304091eaf5eb175210252d4d314bf1eca9c5ee6795e7102eb5dc0b5384dd3dd320f2a2be047dc899676ac6782012088a91462f012a8663f5501fe7b404caaba817b5d0f16348821026bdba9a6c9abe82de0b67c6b243cfe6c72b28368ae69e9f3f09ec4220740cac5ac68feffffff01719e5300000000001976a91499dfbd9c066b8312fcdd7b3ecf0e736701a93b0188ac751eaf5e]\")})) }"
              },
              "type": "TakerPaymentRefundFailed"
            },
            "timestamp": 1588538501335

https://pastebin.com/raw/7as9iQ2L

calling recover_funds_of_swap later returned him his BTC

cipig commented 4 years ago

Had a lot more of this errors in the last month... many with OOT, but also the usual ones with BCH... eg:

curl -s --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"recover_funds_of_swap\",\"params\":{\"uuid\":\"a115ea57-4d8d-43b0-99d1-bce40bda509b\"}}" | json_pp
{
   "error" : "rpc:338] lp_swap:824] lp_swap:508] maker_swap:922] utxo:1331] rpc_clients:460] JsonRpcError { client_info: \"coin: OOT\", request: JsonRpcRequest { jsonrpc: \"1.0\", id: \"0\", method: \"sendrawtransaction\", params: [String(\"0100000001d7978f2d30cd413b6cb85cf519733f96068a71cfcd6613f551b6af3f665094b400000000b647304402205b2b4bbc07ef088b3ecfbaf3ccf1af3ccba2465088ed2d8a5f96964db0478eaa022019a6472ab1c7bfe54657aa1a423e28f2c1903ff231761b21b965097bc60c83ac01514c6b630473b8225fb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a91487c0c8f033193917fa3391348bb9d79bb48c7202882102ed4faa2511d2f2e3551f221bd17421a7f9b306bee09f083c2772b67242dfbc80ac68feffffff0158be8694030000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac9714245f\")] }, error: Transport(\"rpc_clients:395] Rpc request JsonRpcRequest { jsonrpc: \\\"1.0\\\", id: \\\"0\\\", method: \\\"sendrawtransaction\\\", params: [String(\\\"0100000001d7978f2d30cd413b6cb85cf519733f96068a71cfcd6613f551b6af3f665094b400000000b647304402205b2b4bbc07ef088b3ecfbaf3ccf1af3ccba2465088ed2d8a5f96964db0478eaa022019a6472ab1c7bfe54657aa1a423e28f2c1903ff231761b21b965097bc60c83ac01514c6b630473b8225fb17521031bb83b58ec130e28e0a6d5d2acf2eb01b0d3f1670e021d47d31db8a858219da8ac6782012088a91487c0c8f033193917fa3391348bb9d79bb48c7202882102ed4faa2511d2f2e3551f221bd17421a7f9b306bee09f083c2772b67242dfbc80ac68feffffff0158be8694030000001976a914c3f710deb7320b0efa6edb14e3ebeeb9155fa90d88ac9714245f\\\")] } failed with HTTP status code 500 Internal Server Error, response body: {\\\"result\\\":null,\\\"error\\\":{\\\"code\\\":-26,\\\"message\\\":\\\"64: non-final\\\"},\\\"id\\\":\\\"0\\\"}\\n\") }"

is this also dependant on the number of blocks mined between swap start and swap end/failed or recover_funds_of_swap call? OOT chain is not really active, so very few blocks there... if i make some blocks (by sending out txs, because on-demand-mining), i can also recover the funds, the recover_funds_of_swap works then... wonder if this also applies to BCH...

artemii235 commented 4 years ago

Hi, I guess the reason is MM2 sets locktime as now - 3600 as recommended in https://github.com/bitcoin/bitcoin/blob/master/doc/release-notes/release-notes-0.11.2.md#bip113-mempool-only-locktime-enforcement-using-getmediantimepast

To compensate, subtract one hour (3,600 seconds) from your locktimes to allow those transactions to be included in mempools at approximately the expected time.

But this doesn't work sometimes as MTP can be behind now - 3600 resulting into non-final errors. I'm going to fix this in MM2 on this week to ensure that locktime < current MTP requirement is always met.

cipig commented 3 years ago

this non-final errors on MakerPaymentRefund are happening on KMD smartchains that are almost not advancing, like MGW and BOTS (last block 17h ago) here are 2 examples from a user

{
    "error": "rpc:233] lp_swap:979] lp_swap:664] taker_swap:1267] utxo_common:753] rpc_clients:1440] JsonRpcError { client_info: "coin: MGW", request: JsonRpcRequest { jsonrpc: "2.0", id: "13999", method: "blockchain.transaction.broadcast", params: [String("0400008085202f89013e55f06c6d7399045895fd2df53f1d4e0bf2884c8b7c1fb421ae457a78b7c6f800000000b7483045022100dc8353ae65cf4f104442807dd58655c66f0466567f6061c58a63f69aa0c62fd5022077a3515f408f3c944d7d83fa11db53b5365af4287e5ec73628dfab7f2653595301514c6b6304b2cbd35fb175210324a4f663398392243f137b0f2f2942f1cb7ba431baaee5989e9120091da6a8adac6782012088a9140d07039f8de33f3a6d30c818d4b8965f88ff4ba78821038f5fd70e8f97942913ceae60365c9a8ad26fa28733d1885c710b9036b6bffbabac68feffffff015a9bb940070000001976a914622ae63119368c1b43325cce2855e6dd26b30b9a88ac93cdd35f000000000000000000000000000000")] }, error: Response(electrum2.cipig.net:10015, Object({"code": Number(1), "message": String("the transaction was rejected by network rules.\n\n64: non-final\n[0400008085202f89013e55f06c6d7399045895fd2df53f1d4e0bf2884c8b7c1fb421ae457a78b7c6f800000000b7483045022100dc8353ae65cf4f104442807dd58655c66f0466567f6061c58a63f69aa0c62fd5022077a3515f408f3c944d7d83fa11db53b5365af4287e5ec73628dfab7f2653595301514c6b6304b2cbd35fb175210324a4f663398392243f137b0f2f2942f1cb7ba431baaee5989e9120091da6a8adac6782012088a9140d07039f8de33f3a6d30c818d4b8965f88ff4ba78821038f5fd70e8f97942913ceae60365c9a8ad26fa28733d1885c710b9036b6bffbabac68feffffff015a9bb940070000001976a914622ae63119368c1b43325cce2855e6dd26b30b9a88ac93cdd35f000000000000000000000000000000]")})) }"
}
{
    "error": "rpc:233] lp_swap:979] lp_swap:664] taker_swap:1267] utxo_common:753] rpc_clients:1440] JsonRpcError { client_info: "coin: BOTS", request: JsonRpcRequest { jsonrpc: "2.0", id: "13904", method: "blockchain.transaction.broadcast", params: [String("0400008085202f890139a393342f9144e397dbdba293f1624803d29705fe8a37c3ad74d26f018d2b1e00000000b7483045022100eae328f0ec1eb9f0370c78d7d9f06e0fbf19436c626f31fb0c265b478992e7ae02206df771c4e252e8c45caf2e8689946d7e6c9275b43625c8183d08c76d7db1fbdd01514c6b63049ac9d35fb175210324a4f663398392243f137b0f2f2942f1cb7ba431baaee5989e9120091da6a8adac6782012088a9146f576ac25d196ba39b94990a1c912a5fc6f95e0a8821038f5fd70e8f97942913ceae60365c9a8ad26fa28733d1885c710b9036b6bffbabac68feffffff01282416e3010000001976a914622ae63119368c1b43325cce2855e6dd26b30b9a88acbdcdd35f000000000000000000000000000000")] }, error: Response(electrum2.cipig.net:10007, Object({"code": Number(1), "message": String("the transaction was rejected by network rules.\n\n64: non-final\n[0400008085202f890139a393342f9144e397dbdba293f1624803d29705fe8a37c3ad74d26f018d2b1e00000000b7483045022100eae328f0ec1eb9f0370c78d7d9f06e0fbf19436c626f31fb0c265b478992e7ae02206df771c4e252e8c45caf2e8689946d7e6c9275b43625c8183d08c76d7db1fbdd01514c6b63049ac9d35fb175210324a4f663398392243f137b0f2f2942f1cb7ba431baaee5989e9120091da6a8adac6782012088a9146f576ac25d196ba39b94990a1c912a5fc6f95e0a8821038f5fd70e8f97942913ceae60365c9a8ad26fa28733d1885c710b9036b6bffbabac68feffffff01282416e3010000001976a914622ae63119368c1b43325cce2855e6dd26b30b9a88acbdcdd35f000000000000000000000000000000]")})) }"
}

if i do some transactions and advance the chain, the MakerPaymentRefund works @artemii235 did you implement the change mentioned in your last post? would it help in this cases too or are they different? how many blocks must there be between failure and refundable?

artemii235 commented 3 years ago

@cipig I have not implemented the mentioned change yet, the task got lost in a flow. I have scheduled it for next week.

artemii235 commented 3 years ago

@cipig Could you please test the refunds on https://github.com/KomodoPlatform/atomicDEX-API/tree/mm2.1-fix-refund-non-final branch? If you need help to trigger a refund condition please let me know.

these non-final errors on MakerPaymentRefund are happening on KMD smart chains that are almost not advancing, like MGW and BOTS (last block 17h ago)

It is still a big problem for non-advancing (on-demand) chains because median time past is not advancing as well.

how many blocks must there be between failure and refundable?

6 blocks with timestamp >= payment lock in case coin use 11 blocks to calculate MTP.

cipig commented 3 years ago

tested with BCH and it works fine... had 2 BCH refunds that were failing

09aec30b-c583-4d91-b3b7-46a098c56d08
{
   "error" : "rpc:244] lp_swap:1296] lp_swap:863] maker_swap:988] utxo_common:852] rpc_clients:1496] JsonRpcError { client_info: \"coin: BCH\", request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"82788\", method: \"blockchain.transaction.broadcast\", params: [String(\"010000000177b1ee09dc3e32c96a34c3f3c86851d02a7623427a6348c6d3a43642bf8888ce00000000b7483045022100ed1df4a7836aeebd9be900b7b49d601fb0dd228d74b6ecc15719670b83764e9802204e6e09bdc8b939eb966ab15658704e93843eb170733878da9c610868c2235a1841514c6b630455de2b60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a9141921380dcebb95656083418a0f878c0b2cbadccd8821033694e7701298800aa58ffd8d5ecb6ca2facf87b01888e2bf21d2860516486366ac68feffffff0160dfdb00000000001976a914124b0846223ef78130b8e544b9afc3b09988238688acdfec2b60\")] }, error: Response(electrum3.cipig.net:10055, Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\n64: non-final\\n[010000000177b1ee09dc3e32c96a34c3f3c86851d02a7623427a6348c6d3a43642bf8888ce00000000b7483045022100ed1df4a7836aeebd9be900b7b49d601fb0dd228d74b6ecc15719670b83764e9802204e6e09bdc8b939eb966ab15658704e93843eb170733878da9c610868c2235a1841514c6b630455de2b60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a9141921380dcebb95656083418a0f878c0b2cbadccd8821033694e7701298800aa58ffd8d5ecb6ca2facf87b01888e2bf21d2860516486366ac68feffffff0160dfdb00000000001976a914124b0846223ef78130b8e544b9afc3b09988238688acdfec2b60]\")})) }"
}

e5a09bbe-9c73-4980-941b-e9cd2333946f
{
   "error" : "rpc:244] lp_swap:1296] lp_swap:863] maker_swap:988] utxo_common:852] rpc_clients:1496] JsonRpcError { client_info: \"coin: BCH\", request: JsonRpcRequest { jsonrpc: \"2.0\", id: \"82800\", method: \"blockchain.transaction.broadcast\", params: [String(\"0100000001342826094a85b1f82160a81f879fb5c8ca5fb3f4e87d68343b661136820ab5ad00000000b6473044022044fe18525ea549ca33dc9c38489adefe226f3bec8a2783ffe48ca142847dc9ff02200cdfffcf82aa720326d8a49958042b5bd1a1ef66267643b5ba4e8c0f6db2844541514c6b6304b6e72b60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a914df9032af526e6d619bb93a4fc1d24e7fb02d12df8821033694e7701298800aa58ffd8d5ecb6ca2facf87b01888e2bf21d2860516486366ac68feffffff01a974de00000000001976a914124b0846223ef78130b8e544b9afc3b09988238688acdfec2b60\")] }, error: Response(electrum3.cipig.net:10055, Object({\"code\": Number(1), \"message\": String(\"the transaction was rejected by network rules.\\n\\n64: non-final\\n[0100000001342826094a85b1f82160a81f879fb5c8ca5fb3f4e87d68343b661136820ab5ad00000000b6473044022044fe18525ea549ca33dc9c38489adefe226f3bec8a2783ffe48ca142847dc9ff02200cdfffcf82aa720326d8a49958042b5bd1a1ef66267643b5ba4e8c0f6db2844541514c6b6304b6e72b60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a914df9032af526e6d619bb93a4fc1d24e7fb02d12df8821033694e7701298800aa58ffd8d5ecb6ca2facf87b01888e2bf21d2860516486366ac68feffffff01a974de00000000001976a914124b0846223ef78130b8e544b9afc3b09988238688acdfec2b60]\")})) }"
}

after update both were refunded correctly

09aec30b-c583-4d91-b3b7-46a098c56d08
{
   "result" : {
      "action" : "RefundedMyPayment",
      "tx_hex" : "010000000177b1ee09dc3e32c96a34c3f3c86851d02a7623427a6348c6d3a43642bf8888ce00000000b7483045022100ce72671543b220c8543fec3d2f43ac0d48af85a344ca2d26193ab8e8e67261ab02202523868317a815f1f9653136375112d9f58509a8b72412bb4b8884fe5b0ecf1941514c6b630455de2b60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a9141921380dcebb95656083418a0f878c0b2cbadccd8821033694e7701298800aa58ffd8d5ecb6ca2facf87b01888e2bf21d2860516486366ac68feffffff0160dfdb00000000001976a914124b0846223ef78130b8e544b9afc3b09988238688ac55de2b60",
      "tx_hash" : "0cc5f8d16b97fc3c9e3f24c3e900296bc04c01c4b9b1de572bbac8bc4c44a0dc",
      "coin" : "BCH"
   }
}

e5a09bbe-9c73-4980-941b-e9cd2333946f
{
   "result" : {
      "tx_hex" : "0100000001342826094a85b1f82160a81f879fb5c8ca5fb3f4e87d68343b661136820ab5ad00000000b64730440220323cd10d1b0bb59d9d01193057baa7646d81871e8150bd8817aab0d01b1be5be0220685b76e92362dea078cdbcba06920fe2205a3a40159bc83f498c81e4ade05d3441514c6b6304b6e72b60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a914df9032af526e6d619bb93a4fc1d24e7fb02d12df8821033694e7701298800aa58ffd8d5ecb6ca2facf87b01888e2bf21d2860516486366ac68feffffff01a974de00000000001976a914124b0846223ef78130b8e544b9afc3b09988238688acb6e72b60",
      "tx_hash" : "5af5bab60a5987cecab386017f2ec5e6aecfb193c2fd97b01853464c8a66bef2",
      "coin" : "BCH",
      "action" : "RefundedMyPayment"
   }
}
artemii235 commented 3 years ago

@cipig Thanks for testing! Could you please also start a new BCH swap and force a refund for it? We need to be sure that MM2 now correctly waits for MTP to advance during the swap.

cipig commented 3 years ago

looks good... i killed mm2 on taker after MakerPayment (BCH) was sent and the refund on maker worked without error automatically on the specified time

console on maker

+--- 18 18:58:26 -------
| (1115:21) [swap uuid=1fe17846-0553-4ecd-aaf7-28e59bd99413] Maker payment wait refund till 1613673885 started...
18 18:58:28, maker_swap:796] Maker payment refund tx 88495ffd23b0203a59539a35274ef9650d7c9babad803d7a3bcc2c678467c0c2
· 2021-02-18 18:58:28 +0000 [swap uuid=1fe17846-0553-4ecd-aaf7-28e59bd99413] Finished

JSON

      {
         "timestamp" : 1613674708615,
         "event" : {
            "data" : {
               "tx_hex" : "010000000181516db4954f1620f4cf12d8eafb2cabffeff4892d848ac1c34bdba443c2cc3c00000000b7483045022100ca60db827c3ec4383653c7f92e81c7a0132e43a9784f2b4f0a486818ef316834022032348d5eabcc541a1731589ccb5c0314bd5d1b465a9891896e1e44b00929f7e941514c6b630429a72e60b1752102dbd8c73e2e80e4f3cf88d2f04a9d2d0df4269496608b14a3e17556fdcb01e0c1ac6782012088a9148e6ca639072fbc2d997f2b1c3428dc3b000cff6188210315d9c51c657ab1be4ae9d3ab6e76a619d3bccfe830d5363fa168424c0d044732ac68feffffff01cf330c00000000001976a914124b0846223ef78130b8e544b9afc3b09988238688ac29a72e60",
               "tx_hash" : "88495ffd23b0203a59539a35274ef9650d7c9babad803d7a3bcc2c678467c0c2"
            },
            "type" : "MakerPaymentRefunded"
         }
      },

https://blockchair.com/bitcoin-cash/transaction/88495ffd23b0203a59539a35274ef9650d7c9babad803d7a3bcc2c678467c0c2

artemii235 commented 3 years ago

@cipig Thanks a lot for testing!