mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-11 03:12:54 +02:00
lnwallet: add utility functions for obfuscated commitment state hints
This commit adds two utility functions along with corresponding tests for adding obfuscated state number hints to each commitment transaction. Such a feature reduces the search time to recover the necessary material to punish a counterpaty for broadcasting an invalid state from O(N), to O(1), where N is the number of states in the channel’s transcript. By encoding the obsfucated state number, either side is able to quickly obtain the ncessary state to excerise “justice”.
This commit is contained in:
@@ -83,7 +83,7 @@ func TestCommitmentSpendValidation(t *testing.T) {
|
||||
sweepTx.TxIn[0].Sequence = lockTimeToSequence(false, csvTimeout)
|
||||
signDesc := &SignDescriptor{
|
||||
WitnessScript: delayScript,
|
||||
SigHashes: txscript.NewTxSigHashes(sweepTx),
|
||||
SigHashes: txscript.NewTxSigHashes(sweepTx),
|
||||
Output: &wire.TxOut{
|
||||
Value: int64(channelBalance),
|
||||
},
|
||||
@@ -536,3 +536,26 @@ func TestHTLCReceiverSpendValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommitTxStateHint(t *testing.T) {
|
||||
commitTx := wire.NewMsgTx()
|
||||
commitTx.AddTxIn(&wire.TxIn{})
|
||||
|
||||
var obsfucator [StateHintSize]byte
|
||||
copy(obsfucator[:], testHdSeed[:StateHintSize])
|
||||
|
||||
for i := 0; i < 10000; i++ {
|
||||
stateNum := uint32(i)
|
||||
|
||||
err := setStateNumHint(commitTx, stateNum, obsfucator)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to set state num %v: %v", i, err)
|
||||
}
|
||||
|
||||
extractedStateNum := getStateNumHint(commitTx, obsfucator)
|
||||
if extractedStateNum != stateNum {
|
||||
t.Fatalf("state number mismatched, expected %v, got %v",
|
||||
stateNum, extractedStateNum)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user