[
CommerceBlock has launched a brand new atomic swap protocol for using state chains on its Mercury Layer protocol. The HSM Server has launched performance to assist atomic swapping of two state chains, in addition to to implement atomic swaps of 1 state chain for Lightning funds. That is the primary instance of a concretely outlined and constructed interplay between Statechain and the Lightning Community. Synergy between the 2 protocols has been envisioned because the idea of Statechain was initially proposed by Ruben Somsen, particularly as a strategy to resolve the limitation of transferring your complete Statechain UTXO without delay.
Fundamental Statechain Swap
To assist the brand new swap protocol, the HSM server wants so as to add some new fields to its database entries monitoring every statechain it’s facilitating. To facilitate statechain to statechain swaps, the server wants to trace:
- Batch_ID: A worth for associative state chains being modified in a batch.
- Batch-time: The time that begins a counter after which the statechain may be “reclaimed” if a swap fails.
- Locked: A worth indicating whether or not the state chain is locked and restricted from common transfers.
This permits the HSM server to trace and implement all variables crucial to make sure a safe atomic swap. When initiating a swap, customers should talk straight with one another to determine a shared batch_ID between them. From this level they alternate all the required info wanted to facilitate regular state chain switch, and ship that info in addition to the batch_id and batch-time to the server. They basically begin the common switch course of, but in addition connect variables to linking completely different state chains collectively to take part within the swap and the way lengthy the timeout interval for that’s.
At this level the server will implement a lock on every statechain utilizing the identical batch_ID all through the switch course of. The server is not going to approve any transfers till the timeout expires, or all state chains utilizing the identical batch_ID in its database are unlocked by the present house owners. One good factor about the way in which HSM implements the swap logic is that it doesn't matter who contacts the server first. When the server receives a message utilizing a batch_ID, it checks every statechain in its database and if there may be already an current batch-time for that batch_ID it units it as the identical. This ensures that irrespective of who registers the swap first, all of them use the identical time worth for the timeout perform.
At this level every shopper concerned within the swap checks and downloads the messages that initiated the switch protocol, and upon verifying that they’re appropriate, requests the server to unlock its statechain, eradicating the switch restrictions. Sends a message. Each time somebody makes an attempt to finalize a switch on the receiver facet of any statechain concerned in a swap, the server checks to make sure that all statechains with the identical batch_ID have been unlocked. If even one with the corresponding batch_id continues to be locked the server is not going to finalize the switch of any of them. If a swap just isn’t profitable earlier than the timeout, the server will proceed to ban finalizing swap transfers, however will let current house owners provoke a brand new switch for themselves, successfully canceling the swap.
electrical latch
Lightning Latch performance, swapping statechain for Lightning funds, works the identical means as a statechain to statechain swap. Listed below are the brand new fields that servers might want to monitor for Lightning Swap:
- Batch_ID: A worth for associative state chains being modified in a batch.
- Batch-time: The time that begins a counter after which the statechain may be “reclaimed” if a swap fails.
- Pre-Picture: The pre-image of Lightning Funds, which is generated by the HSM server.
- lock_1 and lock_2: There are two lock fields for Lightning Swap, one approved by every person concerned.
Like Statechain to Statechain swaps, customers set up and share a random batch_ID. The present statechain proprietor then sends a message to the server with the batch_ID and statechain and requests that it generate a hashlock preimage for Lightning funds. This person creates a Lightning Bill utilizing this preimage, and one other person contacts the server to verify that she or he generated the preimage. The present statechain proprietor then initiates the statechain switch course of and uploads the switch message to the server.
After that is confirmed, one other person making an attempt to swap for the state chain initiates a Lightning cost. Right now solely the server is preimaged, so the Statechain proprietor can not finalize the cost but. The present proprietor sends an unlock message to the server to take away the primary lock on the blockchain after confirming the pending Lightning cost. The receiver in the end verifies the switch message, and the server additionally releases its lock if the message is official.
Now after each locks are eliminated, the HSM server will challenge the preimage to the present statechain proprietor to finalize the Lightning cost, and finalize the statechain switch to the receiver.
This scheme requires belief within the statechain operator to perform actually, however it’s basically no change to the pre-existing belief mannequin of utilizing statechains normally. At no time does the operator have management over customers' funds, nor do they study something about Lightning cost particulars.
What’s it good for?
This scheme may be very completely different from the initially offered interplay between state chains and Lightning channels, which supersedes one over the opposite, however at the same time as a easy place to begin it provides purposeful utility for current Lightning customers. Rebalancing channels is a crucial factor for a lot of nodes, if capability is totally pushed to at least one facet or the opposite the usefulness of that channel for routing funds turns into restricted. As on-chain charges enhance and make swaps out and in of the Lightning Community costlier, many companies and customers have began utilizing Liquid as a mechanism for this.
Statechains present an alternate mechanism to federated sidechains to cut back a few of the charge bills related to channel stability administration. As an alternative of swapping straight into the principle chain or utilizing a sidechain, funds may be swapped to a statechain and held till the funds should be swapped again right into a channel. The identical financial savings in charges may be achieved whereas sustaining the flexibility to unilaterally declare your funds on the principle chain.
One other doable use case (set off warning) can be the potential of extra environment friendly markets for buying and selling ordinals. Since ordinals are merely an index scheme that tracks the paths of particular satoshis backward in transaction historical past, they are often simply eliminated off-chain on the state chain. This mobility together with Lightning Latch may enable cheaper and sooner off-chain purchases of ordinals. One can create a market the place they are often bought off-chain immediately on the Lightning Community.
Additionally it is doable sooner or later if Lightning purchasers may in some way pay attention to which statechain operators particular Lightning nodes belief in routing funds by passing the statechain between completely different nodes as a substitute of utilizing conventional Lightning channels. Latches can be utilized for help.
On the pure statechain to statechain switch entrance, it provides the flexibility for a message passing layer to recreate the system mixing cash off-chain, much like the native mixing performance in CommerceBlock's first statechain implementation.
Whereas it is a quite simple place to begin, the Lightning Latch and Statechain Swap performance opens the primary doorways to Statechain being built-in into the prevailing Lightning Community – and different related layers coming sooner or later – in a means that brings all of them collectively seamlessly. Permits to combine and act as a single community by way of cost routing and liquidity administration. At the same time as we debate the necessity and usefulness of contracts, there may be nonetheless loads of room to proceed constructing with what we have already got.
You possibly can hear the CommerceBlock staff clarify the reasoning past the protocol right here:
speak to the physician @Teatrevethan About why lightning bolt ought to be made @mercurylayer #Bitcoin #layer2 pic.twitter.com/CKVG9aHTQ6
– Nicholas Gregory (@gregory_nico) 15 March 2024
For extra technical explanations, right here:
We are going to study concerning the technicalities of how lightning latch will work. @Teatrevethan However @mercurylayer #Bitcoin #layer2 pic.twitter.com/aQIcjh2ukq
– Nicholas Gregory (@gregory_nico) 16 March 2024