Ethereum: How to convert channel id from c-lightning to lnd?
I would be happy to help you convert channel IDs from C-Lightning to LND. Here is a step-by-step guide on how to do it:
Supporting Channel IDs
In both C-Lightning and LND, channel IDs are used to identify and manage payment channels between users. The format of the ID is usually as follows:
Channel ID (height, block number, slot number, transaction hash)
For example, a common C-Lightning channel ID might be 505580x1917x1.
Converting C-Lightning to LND
To convert a C-Lightning channel ID to an LND-compatible format, you will need to perform the following steps:
Step 1: Parse the C-Lightning channel ID
First, parse the C-Lightning channel ID string into its components:
height (x): 505580
block number (x): 1917
slot number (x): 1
transaction hash (x): ?
Note that in LND, we will focus on the height
, block number
, and slot
fields.
Step 2: Convert to LND-compatible format
To convert the parsed values to an LND-compatible format, use the following formula:
channel_id = (height 60) + (block_number 10^15) + slot
Here is a breakdown of the formula:
(height
60) calculates the total number of units in the channel by multiplying the height
field by 60.
(block_number
10^15) converts the block number to an LND-compatible format, where each block has 10^15 units. This is done by shifting the block number 15 bits to the left (i.e. dividing it by 1000000) and then multiplying by 10^15.
Step 3: Calculate the Channel ID
Now that we have the parsed values and the conversion formula, let’s calculate the LND-compatible channel ID:
channel_id = (505580 60) + (1917 10^15) + slot
Calculate the channel ID using the formula above.
Step 4: Add a unique identifier
To make the channel ID more readable and useful, add a unique identifier to each channel. This can be done by appending a suffix to the channel ID:
channel_id = "LND Channel ID: "
For example, if our channel ID is 505580x1917x1
, we would append x
to get 505580x1917x2
.
Example Use Case
Suppose you have a C-Lightning channel with the following values:
height (x): 506000
block number (x): 1928
slot number (x): 2
transaction hash (x): ?
Using the above formula, we can calculate the LND-compatible channel ID as follows:
channel_id = (506000 60) + (1928 10^15) + 2
The result would be 31168000
for our example channel.
By following these steps, you should have an LND-compatible channel ID for your C-Lightning channels.