mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-10 06:07:16 +01:00
watchtower: convert JusticeKit to interface
In this commit, we convert the `JusticeKit` struct to an interface. Then, we add two implementations of that interface: 1) The `legacyJusticeKit` which implements all the methods of `JusticeKit` 2) The `anchorJusticKit` which wraps the `legacyJusticeKit` and just re-implements the `ToRemoteOutputSpendInfo` method since.
This commit is contained in:
@@ -1201,7 +1201,10 @@ func randCommittedUpdateForChannel(t *testing.T, chanID lnwire.ChannelID,
|
||||
_, err := io.ReadFull(crand.Reader, hint[:])
|
||||
require.NoError(t, err)
|
||||
|
||||
encBlob := make([]byte, blob.Size(blob.FlagCommitOutputs.Type()))
|
||||
kit, err := blob.AnchorCommitment.EmptyJusticeKit()
|
||||
require.NoError(t, err)
|
||||
|
||||
encBlob := make([]byte, blob.Size(kit))
|
||||
_, err = io.ReadFull(crand.Reader, encBlob)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -1229,7 +1232,10 @@ func randCommittedUpdateForChanWithHeight(t *testing.T, chanID lnwire.ChannelID,
|
||||
_, err := io.ReadFull(crand.Reader, hint[:])
|
||||
require.NoError(t, err)
|
||||
|
||||
encBlob := make([]byte, blob.Size(blob.FlagCommitOutputs.Type()))
|
||||
kit, err := blob.AnchorCommitment.EmptyJusticeKit()
|
||||
require.NoError(t, err)
|
||||
|
||||
encBlob := make([]byte, blob.Size(kit))
|
||||
_, err = io.ReadFull(crand.Reader, encBlob)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -240,9 +240,19 @@ func (t *TowerDB) InsertStateUpdate(update *SessionStateUpdate) (uint16, error)
|
||||
return err
|
||||
}
|
||||
|
||||
commitType, err := session.Policy.BlobType.CommitmentType(nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
kit, err := commitType.EmptyJusticeKit()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Assert that the blob is the correct size for the session's
|
||||
// blob type.
|
||||
expBlobSize := blob.Size(session.Policy.BlobType)
|
||||
expBlobSize := blob.Size(kit)
|
||||
if len(update.EncryptedBlob) != expBlobSize {
|
||||
return ErrInvalidBlobSize
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
testBlob = make([]byte, blob.Size(blob.TypeAltruistCommit))
|
||||
testBlob = make(
|
||||
[]byte, blob.NonceSize+blob.V0PlaintextSize+
|
||||
blob.CiphertextExpansion,
|
||||
)
|
||||
)
|
||||
|
||||
// dbInit is a closure used to initialize a watchtower.DB instance.
|
||||
@@ -737,7 +740,8 @@ func updateFromInt(id *wtdb.SessionID, i int,
|
||||
copy(hint[:4], id[:4])
|
||||
binary.BigEndian.PutUint16(hint[4:6], uint16(i))
|
||||
|
||||
blobSize := blob.Size(blob.TypeAltruistCommit)
|
||||
kit, _ := blob.AnchorCommitment.EmptyJusticeKit()
|
||||
blobSize := blob.Size(kit)
|
||||
|
||||
return &wtdb.SessionStateUpdate{
|
||||
ID: *id,
|
||||
|
||||
Reference in New Issue
Block a user