Is there a way to tell (probabilistically, maybe) by looking at an on-chain transaction that it is related to Lightning (is [likely to be] a channel opening or closure)?


A lightning funding transaction is a P2WSH transaction, which appears on chain as paying to some random-looking script hash, but the redeemScript which can unlock and spend the money is not revealed on chain until the transaction gets spent (which is when the channel gets closed in Lightning's case).

You can recreate the redeemScript if you know the funding public keys used for it, which are broadcast over Lightning's gossip network as part of a channel_announcement message. If you take the two funding public keys, where the first key is the lexicographically lesser of the two, the redeemScript is simply:

OP_2 <pubKey1> <pubKey2> OP_2 OP_CHECKMULTISIG

By hashing this and comparing it to the hash the unspent P2WSH transaction spends to, you can verify that the transaction is a Lightning channel.

But without knowledge of those funding public keys (private channels or non-lightning txs), you cannot know the content of the redeemScript until the transaction is spent.


This question seems very similar to Extract lightning network funding transactions with python bitcoin blockchain parser lib in which the answer was given that you cannot really scan the blockchain for lightning channels.

However there is more to add:

The situation becomes worse with 2p ecdsa or scriptless scripts via which you can theoretically open a channel and close it via P2PKH transaction. The same holds true when Bitcoin gets its soft fork for schnorr signatures. In that way those tx (or smart contacts) become indistinguishable from regular Bitcoin txs.

But : you can look at the gossip protocol of the lightning network for open channels. Assume you have a full history of open and closed channels (which would not include private channels) you could probably run some machine learning algorithms / classifier to create a probabilistic model. Assuming most channels are public you should have a relatively good training / test set. However as long as channels are not closed all tx are P2WSH tx which are not insistinguishable as mentioned by the above linked thread. So a machine learning model would only make sense (if at all) to detect former / closed channels.

  • Doesn't "some machine learning algorithms / classifier" work under the assumption that there is some hidden pattern in the data which we just don't see? Where does the pattern come from in this use case, when the data is some random keys and hashes? – Sergei Tikhomirov May 8 at 15:17
  • 1
    In the witness scripts that you see after the channel is closed. In there you would find a certain structure for the outputs, timelock and htlcs. On the other hand you could probably just look for such patterns right away without machine learning. Actually we could compare how many such txs we find with the number of previously closed lightning channels and see how accurate they would be. Also this would /should only work for force close and unilateral closes. The machine learning part was only suggested because you specifically asked for probabilisitic model. Wouldn't really recommend that. – Rene Pickhardt May 8 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.