contractcourt: add storage for the confirmed CommitSet

In this commit, we add storage to the Briefcase for reading/writing a
confirmed CommitSet. This will be used in follow up commits to ensure
that we're able to survive restarts after we mark a channel as pending
closed. Along the way, we also re-add the FetchChainActions struct as
legacy nodes will need this storage.
This commit is contained in:
Olaoluwa Osuntokun committed 2019-05-27 15:26:44 -07:00
1 parent 086f4eb8b3
commit 364c0dd9f1
2 files changed
+257

No files matched your search

+58
View File
@@ -15,6 +15,8 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/coreos/bbolt"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwallet"
)
@@ -672,6 +674,62 @@ func TestScopeIsolation(t *testing.T) {
}
}
// TestCommitSetStorage tests that we're able to properly read/write active
// commitment sets.
func TestCommitSetStorage(t *testing.T) {
t.Parallel()
testLog, cleanUp, err := newTestBoltArbLog(
testChainHash, testChanPoint1,
)
if err != nil {
t.Fatalf("unable to create test log: %v", err)
}
defer cleanUp()
activeHTLCs := []channeldb.HTLC{
{
Amt: 1000,
OnionBlob: make([]byte, 0),
Signature: make([]byte, 0),
},
}
confTypes := []HtlcSetKey{
LocalHtlcSet, RemoteHtlcSet, RemotePendingHtlcSet,
}
for _, pendingRemote := range []bool{true, false} {
for _, confType := range confTypes {
commitSet := &CommitSet{
ConfCommitKey: &confType,
HtlcSets: make(map[HtlcSetKey][]channeldb.HTLC),
}
commitSet.HtlcSets[LocalHtlcSet] = activeHTLCs
commitSet.HtlcSets[RemoteHtlcSet] = activeHTLCs
if pendingRemote {
commitSet.HtlcSets[RemotePendingHtlcSet] = activeHTLCs
}
err := testLog.InsertConfirmedCommitSet(commitSet)
if err != nil {
t.Fatalf("unable to write commit set: %v", err)
}
diskCommitSet, err := testLog.FetchConfirmedCommitSet()
if err != nil {
t.Fatalf("unable to read commit set: %v", err)
}
if !reflect.DeepEqual(commitSet, diskCommitSet) {
t.Fatalf("commit set mismatch: expected %v, got %v",
spew.Sdump(commitSet), spew.Sdump(diskCommitSet))
}
}
}
}
func init() {
testSignDesc.KeyDesc.PubKey, _ = btcec.ParsePubKey(key1, btcec.S256())