Skip to content

add KCN + LCN#1277

Merged
cipig merged 2 commits intoGLEECBTC:masterfrom
JayBitron:master
Feb 17, 2025
Merged

add KCN + LCN#1277
cipig merged 2 commits intoGLEECBTC:masterfrom
JayBitron:master

Conversation

@JayBitron
Copy link
Copy Markdown

No description provided.

@smk762 smk762 requested review from cipig and gcharang February 7, 2025 00:12
@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 7, 2025

build Desktop app with the 2 coins in order to do some tests, but running into a weird problem
on CLI i can connect to the electrums like that (echo '{ "id": 1, "method": "blockchain.headers.subscribe" }'; sleep 0.5) | ncat electrum.kcnxp.com 51001, but in the app i get an error when i try to enable the coins

{
    "error": "rpc:182] dispatcher_legacy:140] legacy:148] Deactivated coin due to error in balance querying: Ok(Err(utxo_common:218] Transport(\"JsonRpcError { client_info: \\\"coin: KCN-segwit\\\", request: JsonRpcBatchRequest([JsonRpcRequest { jsonrpc: \\\"2.0\\\", id: 1, method: \\\"blockchain.scripthash.get_balance\\\", params: [String(\\\"7d073b71bf00f2fb1f87563f9fa5082ad1096ec6af8f3bf8911799429e171c3c\\\")] }, JsonRpcRequest { jsonrpc: \\\"2.0\\\", id: 2, method: \\\"blockchain.scripthash.get_balance\\\", params: [String(\\\"282d79e745d6372db531c9a111837887a42cefc72f3ff2b137506932c4f7eb94\\\")] }]), error: Internal(\\\"All servers errored: [(electrum.kcnxp.com:51002, Transport(\\\\\\\"Failed to establish connection: Temporary(\\\\\\\\\\\\\\\"Couldn't connect to the electrum server: Os { code: 111, kind: ConnectionRefused, message: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"Connection refused\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" }\\\\\\\\\\\\\\\")\\\\\\\"))]\\\") }\")))"
}

i saw that they are sometimes slow in answering, but still weird that i get "Connection refused" in the app and not a timeout

something else: the param "estimate_fee_mode": "ECONOMICAL", can be removed, it is only implemented on BTC afaik and it's not used anyway if the fee is fixed ("txfee": 1000)

@JayBitron
Copy link
Copy Markdown
Author

@cipig can you please check if there is something wrong with my setup spesmilo/electrumx#290 ?

@JayBitron
Copy link
Copy Markdown
Author

root@localhost:~# (echo '{ "id": 1, "method": "blockchain.headers.subscribe" }'; sleep 0.5) | netcat electrum.kcnxp.com 51001
{"jsonrpc":"2.0","error":{"code":-101,"message":"excessive resource usage"},"id":1}

@JayBitron
Copy link
Copy Markdown
Author

Restarted the server.
root@localhost:~# (echo '{ "id": 1, "method": "blockchain.headers.subscribe" }'; sleep 0.5) | netcat electrum.kcnxp.com 51001
{"jsonrpc":"2.0","result":{"hex":"0080002022475cb8e0e265c5be0a7bc3b42bf6286b9fe560125b64dafd1625244a38fb93e5cd98a652b807ae07dbeb246484abd4a078f732cb4a820f2e84715ea4f42ed7bb52a667f3681f1d671600d1","height":1468815},"id":1}

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 7, 2025

root@localhost:~# (echo '{ "id": 1, "method": "blockchain.headers.subscribe" }'; sleep 0.5) | netcat electrum.kcnxp.com 51001 {"jsonrpc":"2.0","error":{"code":-101,"message":"excessive resource usage"},"id":1}

that is from https://electrumx-spesmilo.readthedocs.io/en/latest/environment.html#resource-usage-limits
i disabled the limits completely on my servers, since i didn't want to spend a lot of time to find and configure sane values for that
this is how a typical config of mine looks like

COIN = BitcoinSegwit
DB_DIRECTORY = /electrumdb/BTC
DAEMON_URL = http://user:pwd@127.0.0.1:8332/
SERVICES = tcp://:10000,rpc://:8000,ssl://:20000,wss://:30000
EVENT_LOOP_POLICY = uvloop
PEER_DISCOVERY = self
MAX_SESSIONS = 5000
INITIAL_CONCURRENT = 100
COST_SOFT_LIMIT = 0
COST_HARD_LIMIT = 0
SSL_CERTFILE = /home/electrum/server.crt
SSL_KEYFILE = /home/electrum/server.key
DROP_CLIENT_UNKNOWN = true

COST_SOFT_LIMIT = 0 and COST_HARD_LIMIT = 0 disable the ressource limits

can you please check if there is something wrong with my setup spesmilo/electrumx#290 ?

when electrumx syncs to latest height, then those settings are fine
only thing is that this params

    ESTIMATE_FEE = 0.0001
    RELAY_FEE = 0.0001

are, afaik, only used when you use "DAEMON = daemon.FakeEstimateFeeDaemon"... so in this case they will not be used

@JayBitron
Copy link
Copy Markdown
Author

I updated the settings as you suggested but probably will setup a dedicated server for it since it's important.

@JayBitron
Copy link
Copy Markdown
Author

It works smoothly now. Thank you!

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 8, 2025

i am still getting the same when i want to enable KCN in Desktop:

{
    "error": "rpc:182] dispatcher_legacy:140] legacy:148] Deactivated coin due to error in balance querying: Ok(Err(utxo_common:218] Transport(\"JsonRpcError { client_info: \\\"coin: KCN-segwit\\\", request: JsonRpcBatchRequest([JsonRpcRequest { jsonrpc: \\\"2.0\\\", id: 0, method: \\\"blockchain.scripthash.get_balance\\\", params: [String(\\\"7d073b71bf00f2fb1f87563f9fa5082ad1096ec6af8f3bf8911799429e171c3c\\\")] }, JsonRpcRequest { jsonrpc: \\\"2.0\\\", id: 1, method: \\\"blockchain.scripthash.get_balance\\\", params: [String(\\\"282d79e745d6372db531c9a111837887a42cefc72f3ff2b137506932c4f7eb94\\\")] }]), error: Internal(\\\"All servers errored: [(electrum.kcnxp.com:51002, Transport(\\\\\\\"Failed to establish connection: Temporary(\\\\\\\\\\\\\\\"Couldn't connect to the electrum server: Os { code: 111, kind: ConnectionRefused, message: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"Connection refused\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" }\\\\\\\\\\\\\\\")\\\\\\\"))]\\\") }\")))"
}

on CLI it works, i can fetch balance:

(echo '{ "id": 1, "method": "server.version", "params": ["barterDEX", ["1.1", "1.5"]] }'; echo '{ "id": 1, "method": "blockchain.scripthash.get_balance", "params": ["7d073b71bf00f2fb1f87563f9fa5082ad1096ec6af8f3bf8911799429e171c3c"] }'; sleep 0.5) | ncat electrum.kcnxp.com 51001
{"jsonrpc":"2.0","result":["ElectrumX 1.16.0","1.4.3"],"id":1}
{"jsonrpc":"2.0","result":{"confirmed":0,"unconfirmed":0},"id":1}

totally weird, especially because i can enable all other coins on Desktop without problems

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 8, 2025

btw, try it out, this is Desktop version with both coins added: https://github.com/cipig/komodo-wallet-desktop/actions/runs/13179070626

@JayBitron
Copy link
Copy Markdown
Author

@cipig Thank you! I just downloaded the windows version, it works fine, it shows the balance both legacy and segwit, but both BEP20 says failed to enable them. It also doesn't show the price. Also the team is working on adding pairs on uniswap. For the electrum server, what do you recommend? I've a lot of resources on the server plenty of ports are unused.

@JayBitron
Copy link
Copy Markdown
Author

I've sent some test coins, everything works. But also icons of both are not showing.

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 8, 2025

i am still getting the same error here... looks like my IP is banned/in the resource limit thingy

@JayBitron
Copy link
Copy Markdown
Author

I've set another server up, the domain now points to two servers, alto I didn't see any IPs beside my IP, I don't think it's a resource limit thing. Also I see the desktop wallet is bypassing my openvpn revealing my real IP.

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 10, 2025

tried to enable KCN-segwit on maker nodes of mine, that run on VPS, so not on my home IP... but the result is the same as in the GUI:
curl --url "http://127.0.0.1:7783" --data "{\"method\":\"electrum\",\"coin\":\"KCN-segwit\",\"servers\":[{\"url\":\"electrum.kcnxp.com:51001\"}],\"userpass\":\"$userpass\"}"

shows error
{"error":"rpc:183] dispatcher_legacy:140] legacy:148] Deactivated coin due to error in balance querying: Ok(Err(utxo_common:219] Transport(\"JsonRpcError { client_info: \\\"coin: KCN-segwit\\\", request: JsonRpcBatchRequest([JsonRpcRequest { jsonrpc: \\\"2.0\\\", id: 0, method: \\\"blockchain.scripthash.get_balance\\\", params: [String(\\\"9542c97d3215b9ef0292d14b1d60619d982c0d99cb42f7fb8c7052069f90808b\\\")] }, JsonRpcRequest { jsonrpc: \\\"2.0\\\", id: 1, method: \\\"blockchain.scripthash.get_balance\\\", params: [String(\\\"d75f4d70e54cd1dce45c9c202a069654259b2baeca5cbff0cc19266c44cef190\\\")] }]), error: Internal(\\\"All servers errored: [(electrum.kcnxp.com:51001, Transport(\\\\\\\"Failed to establish connection: Temporary(\\\\\\\\\\\\\\\"Couldn't connect to the electrum server: Os { code: 111, kind: ConnectionRefused, message: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"Connection refused\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" }\\\\\\\\\\\\\\\")\\\\\\\"))]\\\") }\")))"}

same with LCN-segwit

curl --url "http://127.0.0.1:7783" --data "{\"method\":\"electrum\",\"coin\":\"LCN-segwit\",\"servers\":[{\"url\":\"electrum.lcnxp.com:52001\"}],\"userpass\":\"$userpass\"}"

{"error":"rpc:183] dispatcher_legacy:140] legacy:148] Deactivated coin due to error in balance querying: Ok(Err(utxo_common:219] Transport(\"JsonRpcError { client_info: \\\"coin: LCN-segwit\\\", request: JsonRpcBatchRequest([JsonRpcRequest { jsonrpc: \\\"2.0\\\", id: 0, method: \\\"blockchain.scripthash.get_balance\\\", params: [String(\\\"9542c97d3215b9ef0292d14b1d60619d982c0d99cb42f7fb8c7052069f90808b\\\")] }, JsonRpcRequest { jsonrpc: \\\"2.0\\\", id: 1, method: \\\"blockchain.scripthash.get_balance\\\", params: [String(\\\"d75f4d70e54cd1dce45c9c202a069654259b2baeca5cbff0cc19266c44cef190\\\")] }]), error: Internal(\\\"All servers errored: [(electrum.lcnxp.com:52001, Transport(\\\\\\\"Failed to establish connection: Temporary(\\\\\\\\\\\\\\\"Couldn't connect to the electrum server: Os { code: 111, kind: ConnectionRefused, message: \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"Connection refused\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\" }\\\\\\\\\\\\\\\")\\\\\\\"))]\\\") }\")))"}

Is there something between client and electrumx server? maybe some proxy?

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 10, 2025

found the problem by using telnet:

telnet electrum.kcnxp.com 51001
Trying 2a06:f902:1:100::301...
Connection failed: Connection refused
Trying 185.224.248.252...
Connected to electrum.kcnxp.com

so electrum.kcnxp.com resolves to some IPv6 address, which doesn't work... the IPv4 does work, but mm2 does not try that
i recommend to remove the IPv6 from DNS

this now also explains why it works on some PCs: those have IPv6 completely disabled

@JayBitron
Copy link
Copy Markdown
Author

ok, it should work now

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 10, 2025

thanks, electrums are working now over IPv6
tried a swap with KCN-segwit, but it failed
taker sent takerfee:

      {
         "event" : {
            "data" : {
               "tx_hash" : "f0c05d3aa338cd25b341014e5ed102a75f467026103b9140e0b390ccf2b8c9ae",
               "tx_hex" : "010000000001015b7236f14645e5f61c46280779217787be8270156fd8fc0c81609ca11d6bf5180000000000ffffffff022bdcdf06000000001976a914ca1e04745e8ca0c60d8c5881531d51bec470743f88aced64b52f1700000016001484c74592ed8ac05340906784d277ca4d4e0af08e0247304402203363c47322d134b756ad66d41c2187ccca918896d3df50dc20cadabefd8b560402204046303045c95e668d5b63986303c454a25ef20c2776ec1af8379646cd7c06510121023c5ba1d7ef6fa015eb33defb3aba2a961898a51bbb7ff30344d07ba75ad3f289f52caa67"
            },
            "type" : "TakerFeeSent"
         },
         "timestamp" : 1739205877330
      }

but maker couldn't see the tx on chain or in mempool

      {
         "event" : {
            "data" : {
               "error" : "maker_swap:777] utxo_common:2164] client:900] JsonRpcError { client_info: \"coin: KCN-segwit\", request: JsonRpcRequest { jsonrpc: \"2.0\", id: 74, method: \"blockchain.transaction.get\", params: [String(\"f0c05d3aa338cd25b341014e5ed102a75f467026103b9140e0b390ccf2b8c9ae\"), Bool(true)] }, error: Response(electrum.kcnxp.com:51001, Object({\"code\": Number(2), \"message\": String(\"daemon error: DaemonError({'code': -5, 'message': 'No such mempool or blockchain transaction. Use gettransaction for wallet transactions.'})\")})) }"
            },
            "type" : "TakerFeeValidateFailed"
         },
         "timestamp" : 1739205938338
      },

the swap therefore timed out

looks like electrum server and coin daemon there accepted the takerfee tx, but it "got lost"... when maker asked for the tx electrum/coin daemon didn't had it

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 10, 2025

found something else...
the contract address needs to be multicase, not lowercase
https://bscscan.com/address/0x848b991fb420cd59c8296143c8153477393ddcab shows 0x848B991fb420Cd59C8296143c8153477393ddcab

@JayBitron
Copy link
Copy Markdown
Author

your transaction is not lost, it uses the wrong hash https://kcnxp.com/tx/5ac64283a41dda1b11daeb1144fb853506008ba7e8ac27da8b42bf87afadfe60

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 10, 2025

your transaction is not lost, it uses the wrong hash https://kcnxp.com/tx/5ac64283a41dda1b11daeb1144fb853506008ba7e8ac27da8b42bf87afadfe60

so, what does that mean? checked the values

     "pubtype": 28,
    "p2shtype": 26,
    "wiftype": 65,

and they are the same as in wallet code
does it mean the coin uses a different tx signature method?
does it need a settings like

    "signature_version": "base",

or would it work with legacy (non-segwit)?

@JayBitron
Copy link
Copy Markdown
Author

Yes, those pubtype, p2shtype and wiftype are correct, it only generates the wrong hash id for the generated tx, the generated tx look fine, everything is accepted by the network, I also tried the blockchain.transaction.broadcas method, it looks like it works fine, it generates the correct hash.

@JayBitron
Copy link
Copy Markdown
Author

I don't think it's using the hash from electrum server, it generates its own hash, because each project has different tx id

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 10, 2025

I don't think it's using the hash from electrum server, it generates its own hash, because each project has different tx id

yes, the backend https://github.com/KomodoPlatform/komodo-defi-framework/tree/dev generates and signs the txes itself, and then broadcasts the result through electrum... so it needs to know exactly how a tx is generated

@JayBitron
Copy link
Copy Markdown
Author

JayBitron commented Feb 10, 2025

yes, the backend https://github.com/KomodoPlatform/komodo-defi-framework/tree/dev generates and signs the txes itself, and then broadcasts the result through electrum... so it needs to know exactly how a tx is generated

signature is the same as other coins, but for KCN, instead of sha256(sha256(tx)) it uses sha3_256(sha3_256(tx)) for the final tx, for LCN if (version & 0x8000) then uses sha3_256(sha3_256(tx)) otherwise uses sha256(sha256(tx))

https://github.com/JayBitron/electrumx/blob/master/electrumx/lib/tx.py#L1386C1-L1386C48

if you could add it there that would be great

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 10, 2025

signature is the same as other coins, but for KCN, instead of sha256(sha256(tx)) it uses sha3_256(sha3_256(tx)) for the final tx, for LCN if (version & 0x8000) then uses sha3_256(sha3_256(tx)) otherwise uses sha256(sha256(tx))

i am not a dev, so we need to open issue in https://github.com/KomodoPlatform/komodo-defi-framework and ask the devs to implement it
could you do that and explain them what they need to do?

@JayBitron
Copy link
Copy Markdown
Author

signature is the same as other coins, but for KCN, instead of sha256(sha256(tx)) it uses sha3_256(sha3_256(tx)) for the final tx, for LCN if (version & 0x8000) then uses sha3_256(sha3_256(tx)) otherwise uses sha256(sha256(tx))

i am not a dev, so we need to open issue in https://github.com/KomodoPlatform/komodo-defi-framework and ask the devs to implement it could you do that and explain them what they need to do?

I'm not familiar with the dex, we just need a wallet. I also fixed the contacts multi case

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 10, 2025

GLEECBTC/komodo-defi-framework#2349
till then KCN-segwit and LCN-segwit should be set to wallet-only too

@JayBitron
Copy link
Copy Markdown
Author

KomodoPlatform/komodo-defi-framework#2349 till then KCN-segwit and LCN-segwit should be set to wallet-only too

done

Copy link
Copy Markdown
Collaborator

@cipig cipig left a comment

Choose a reason for hiding this comment

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

image

@cipig cipig requested a review from smk762 February 13, 2025 18:31
@JayBitron
Copy link
Copy Markdown
Author

@cipig Is it possible for you to build the final version for both desktop and mobile please so I can send them for users to use?

@cipig
Copy link
Copy Markdown
Collaborator

cipig commented Feb 14, 2025

@cipig Is it possible for you to build the final version for both desktop and mobile please so I can send them for users to use?

I can't build official versions, i only have my own repos which i use for testing new coins, see eg https://github.com/cipig/komodo-wallet-desktop/actions

@cipig cipig merged commit 0c18d7a into GLEECBTC:master Feb 17, 2025
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.

2 participants