Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
007f968
lnwallet/chanfunding: remote assembler.go to interface.go
Roasbeef Mar 12, 2024
784d236
channeldb: consolidate root bucket TLVs into new struct
Roasbeef Mar 12, 2024
5d18c65
channeldb: add optional TapscriptRoot field + feature bit
Roasbeef Mar 13, 2024
733e192
input: add new tapscript root func op to GenTaprootFundingScript
Roasbeef Mar 13, 2024
1e07ba3
lnwallet/chanfunding: add optional tapscript root
Roasbeef Mar 13, 2024
7d3c83b
multi: update GenTaprootFundingScript to pass tapscript root
Roasbeef Mar 13, 2024
b8cb4e6
lnwallet: update internal funding flow w/ tapscript root
Roasbeef Mar 13, 2024
612e93e
lnwallet+peer: add tapscript root awareness to musig2 sessions
Roasbeef Mar 13, 2024
33e0cea
lnwallet: add initial unit tests for musig2+tapscript root chans
Roasbeef Mar 13, 2024
3835a51
input+lnwallet: update taproot scripts to accept optional aux leaf
Roasbeef Mar 15, 2024
0184975
channeldb: add encode/decode methods to chanAuxData
Roasbeef Mar 16, 2024
ed18daa
[temp] - tlv: add new Blob type alias
Roasbeef Mar 17, 2024
9217a24
channeldb: new custom blob nested TLV
Roasbeef Mar 17, 2024
cba0e65
input: add AuxTapLeaf type alias
Roasbeef Mar 17, 2024
0d18ae6
lnwallet+channeldb: add new AuxLeafStore for dynamic aux leaves
Roasbeef Mar 17, 2024
69567ec
fixup! channeldb: new custom blob nested TLV
Roasbeef Mar 19, 2024
84f1276
fixup! channeldb: new custom blob nested TLV
Roasbeef Mar 19, 2024
83a6cdb
tlv: add in new BigSizeT type
Roasbeef Mar 31, 2024
ae149da
channeldb: convert HTLCEntry to use tlv.RecordT
Roasbeef Mar 31, 2024
d5ba64f
channeldb: convert RevocationLog to use RecordT
Roasbeef Mar 31, 2024
1096743
channeldb: add custom blobs to RevocationLog+HTLCEntry
Roasbeef Apr 2, 2024
7a07d6c
channeldb: add HtlcIndex to HTLCEntry
Roasbeef Apr 2, 2024
be1d19f
channeldb: add a custom blob to OpenChannel
Roasbeef Apr 2, 2024
3251d34
input: add some utility type definitions for aux leaves
Roasbeef Apr 2, 2024
99db910
lnwallet: add TLV blob to PaymentDescriptor + htlc add
Roasbeef Apr 2, 2024
f0c8fb0
lnwallet: export the HtlcView struct
Roasbeef Apr 2, 2024
c813c59
lnwallet: add incoming+outgoing aux leaves to CommitAuxLeaves
Roasbeef Apr 2, 2024
eaea611
lnwallet: extend AuxLeafStore w/ additional methods
Roasbeef Apr 2, 2024
cda8d23
lnwallet: add custom tlv blob to internal commitment struct
Roasbeef Apr 2, 2024
6bf5ff6
lnwallet: thread thru input.AuxTapleaf to all relevant areas
Roasbeef Apr 2, 2024
4c00dac
lnd: add AuxLeafStore as top level commit
Roasbeef Apr 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
415 changes: 311 additions & 104 deletions channeldb/channel.go

Large diffs are not rendered by default.

40 changes: 27 additions & 13 deletions channeldb/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/channeldb/models"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnmock"
Expand Down Expand Up @@ -171,7 +172,7 @@ func fundingPointOption(chanPoint wire.OutPoint) testChannelOption {
}

// channelIDOption is an option which sets the short channel ID of the channel.
var channelIDOption = func(chanID lnwire.ShortChannelID) testChannelOption {
func channelIDOption(chanID lnwire.ShortChannelID) testChannelOption {
return func(params *testChannelParams) {
params.channel.ShortChannelID = chanID
}
Expand Down Expand Up @@ -311,6 +312,9 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
uniqueOutputIndex.Add(1)
op := wire.OutPoint{Hash: key, Index: uniqueOutputIndex.Load()}

var tapscriptRoot chainhash.Hash
copy(tapscriptRoot[:], bytes.Repeat([]byte{1}, 32))

return &OpenChannel{
ChanType: SingleFunderBit | FrozenBit,
ChainHash: key,
Expand All @@ -332,6 +336,7 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
FeePerKw: btcutil.Amount(5000),
CommitTx: channels.TestFundingTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
CustomBlob: fn.Some([]byte{1, 2, 3}),
},
RemoteCommitment: ChannelCommitment{
CommitHeight: 0,
Expand All @@ -341,6 +346,7 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
FeePerKw: btcutil.Amount(5000),
CommitTx: channels.TestFundingTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
CustomBlob: fn.Some([]byte{4, 5, 6}),
},
NumConfsRequired: 4,
RemoteCurrentRevocation: privKey.PubKey(),
Expand All @@ -353,6 +359,8 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
ThawHeight: uint32(defaultPendingHeight),
InitialLocalBalance: lnwire.MilliSatoshi(9000),
InitialRemoteBalance: lnwire.MilliSatoshi(3000),
TapscriptRoot: fn.Some(tapscriptRoot),
CustomBlob: fn.Some([]byte{1, 2, 3}),
}
}

Expand Down Expand Up @@ -560,23 +568,25 @@ func assertCommitmentEqual(t *testing.T, a, b *ChannelCommitment) {
func assertRevocationLogEntryEqual(t *testing.T, c *ChannelCommitment,
r *RevocationLog) {

t.Helper()

// Check the common fields.
require.EqualValues(
t, r.CommitTxHash, c.CommitTx.TxHash(), "CommitTx mismatch",
t, r.CommitTxHash.Val, c.CommitTx.TxHash(), "CommitTx mismatch",
)

// Now check the common fields from the HTLCs.
require.Equal(t, len(r.HTLCEntries), len(c.Htlcs), "HTLCs len mismatch")
for i, rHtlc := range r.HTLCEntries {
cHtlc := c.Htlcs[i]
require.Equal(t, rHtlc.RHash, cHtlc.RHash, "RHash mismatch")
require.Equal(t, rHtlc.Amt, cHtlc.Amt.ToSatoshis(),
require.Equal(t, rHtlc.RHash.Val[:], cHtlc.RHash[:], "RHash mismatch")
require.Equal(t, rHtlc.Amt.Val.Int(), cHtlc.Amt.ToSatoshis(),
"Amt mismatch")
require.Equal(t, rHtlc.RefundTimeout, cHtlc.RefundTimeout,
require.Equal(t, rHtlc.RefundTimeout.Val, cHtlc.RefundTimeout,
"RefundTimeout mismatch")
require.EqualValues(t, rHtlc.OutputIndex, cHtlc.OutputIndex,
require.EqualValues(t, rHtlc.OutputIndex.Val, cHtlc.OutputIndex,
"OutputIndex mismatch")
require.Equal(t, rHtlc.Incoming, cHtlc.Incoming,
require.Equal(t, rHtlc.Incoming.Val, cHtlc.Incoming,
"Incoming mismatch")
}
}
Expand Down Expand Up @@ -642,6 +652,7 @@ func TestChannelStateTransition(t *testing.T) {
CommitTx: newTx,
CommitSig: newSig,
Htlcs: htlcs,
CustomBlob: fn.Some([]byte{4, 5, 6}),
}

// First update the local node's broadcastable state and also add a
Expand Down Expand Up @@ -680,9 +691,12 @@ func TestChannelStateTransition(t *testing.T) {
// have been updated.
updatedChannel, err := cdb.FetchOpenChannels(channel.IdentityPub)
require.NoError(t, err, "unable to fetch updated channel")

assertCommitmentEqual(t, &commitment, &updatedChannel[0].LocalCommitment)

numDiskUpdates, err := updatedChannel[0].CommitmentHeight()
require.NoError(t, err, "unable to read commitment height from disk")

if numDiskUpdates != uint64(commitment.CommitHeight) {
t.Fatalf("num disk updates doesn't match: %v vs %v",
numDiskUpdates, commitment.CommitHeight)
Expand Down Expand Up @@ -788,10 +802,10 @@ func TestChannelStateTransition(t *testing.T) {

// Check the output indexes are saved as expected.
require.EqualValues(
t, dummyLocalOutputIndex, diskPrevCommit.OurOutputIndex,
t, dummyLocalOutputIndex, diskPrevCommit.OurOutputIndex.Val,
)
require.EqualValues(
t, dummyRemoteOutIndex, diskPrevCommit.TheirOutputIndex,
t, dummyRemoteOutIndex, diskPrevCommit.TheirOutputIndex.Val,
)

// The two deltas (the original vs the on-disk version) should
Expand Down Expand Up @@ -833,10 +847,10 @@ func TestChannelStateTransition(t *testing.T) {

// Check the output indexes are saved as expected.
require.EqualValues(
t, dummyLocalOutputIndex, diskPrevCommit.OurOutputIndex,
t, dummyLocalOutputIndex, diskPrevCommit.OurOutputIndex.Val,
)
require.EqualValues(
t, dummyRemoteOutIndex, diskPrevCommit.TheirOutputIndex,
t, dummyRemoteOutIndex, diskPrevCommit.TheirOutputIndex.Val,
)

assertRevocationLogEntryEqual(t, &oldRemoteCommit, prevCommit)
Expand Down Expand Up @@ -1523,14 +1537,14 @@ func TestKeyLocatorEncoding(t *testing.T) {
buf [8]byte
)

err := EKeyLocator(&b, &keyLoc, &buf)
err := eKeyLocator(&b, &keyLoc, &buf)
require.NoError(t, err, "unable to encode key locator")

// Next, we'll attempt to decode the bytes into a new KeyLocator.
r := bytes.NewReader(b.Bytes())
var decodedKeyLoc keychain.KeyLocator

err = DKeyLocator(r, &decodedKeyLoc, &buf, 8)
err = dKeyLocator(r, &decodedKeyLoc, &buf, 8)
require.NoError(t, err, "unable to decode key locator")

// Finally, we'll compare that the original KeyLocator and the decoded
Expand Down
Loading