cnct+lnwl+hswc: use lntypes.Preimage for witness beacon
This commit is contained in:
16 files changed
+126
-114
No files matched your search
+2
-2
@@ -5577,12 +5577,12 @@ func extractHtlcResolutions(feePerKw SatPerKWeight, ourCommit bool,
|
||||
// We'll now query the preimage cache for the preimage
|
||||
// for this HTLC. If it's present then we can fully
|
||||
// populate this resolution.
|
||||
preimage, _ := pCache.LookupPreimage(htlc.RHash[:])
|
||||
preimage, _ := pCache.LookupPreimage(htlc.RHash)
|
||||
|
||||
// Otherwise, we'll create an incoming HTLC resolution
|
||||
// as we can satisfy the contract.
|
||||
var pre [32]byte
|
||||
copy(pre[:], preimage)
|
||||
copy(pre[:], preimage[:])
|
||||
ihr, err := newIncomingHtlcResolution(
|
||||
signer, localChanCfg, commitHash, &htlc, keyRing,
|
||||
feePerKw, dustLimit, uint32(csvDelay), ourCommit,
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@@ -584,7 +585,7 @@ func TestForceClose(t *testing.T) {
|
||||
|
||||
// Before we force close Alice's channel, we'll add the pre-image of
|
||||
// Bob's HTLC to her preimage cache.
|
||||
aliceChannel.pCache.AddPreimages(preimageBob[:])
|
||||
aliceChannel.pCache.AddPreimages(lntypes.Preimage(preimageBob))
|
||||
|
||||
// With the cache populated, we'll now attempt the force close
|
||||
// initiated by Alice.
|
||||
@@ -4953,7 +4954,7 @@ func TestChannelUnilateralCloseHtlcResolution(t *testing.T) {
|
||||
// Now that Bob has force closed, we'll modify Alice's pre image cache
|
||||
// such that she now gains the ability to also settle the incoming HTLC
|
||||
// from Bob.
|
||||
aliceChannel.pCache.AddPreimages(preimageBob[:])
|
||||
aliceChannel.pCache.AddPreimages(lntypes.Preimage(preimageBob))
|
||||
|
||||
// We'll then use Bob's transaction to trigger a spend notification for
|
||||
// Alice.
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
)
|
||||
|
||||
// AddressType is an enum-like type which denotes the possible address types
|
||||
@@ -272,15 +273,12 @@ type PreimageCache interface {
|
||||
// LookupPreimage attempts to look up a preimage according to its hash.
|
||||
// If found, the preimage is returned along with true for the second
|
||||
// argument. Otherwise, it'll return false.
|
||||
LookupPreimage(hash []byte) ([]byte, bool)
|
||||
LookupPreimage(hash lntypes.Hash) (lntypes.Preimage, bool)
|
||||
|
||||
// AddPreimages adds a batch of newly discovered preimages to the global
|
||||
// cache, and also signals any subscribers of the newly discovered
|
||||
// witness.
|
||||
//
|
||||
// NOTE: The backing slice of MUST NOT be modified, otherwise the
|
||||
// subscribers may be notified of the incorrect preimages.
|
||||
AddPreimages(preimages ...[]byte) error
|
||||
AddPreimages(preimages ...lntypes.Preimage) error
|
||||
}
|
||||
|
||||
// WalletDriver represents a "driver" for a particular concrete
|
||||
|
||||
+21
-14
@@ -3,7 +3,6 @@ package lnwallet
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
@@ -18,6 +17,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/keychain"
|
||||
"github.com/lightningnetwork/lnd/lntypes"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
)
|
||||
@@ -301,10 +301,7 @@ func CreateTestChannels() (*LightningChannel, *LightningChannel, func(), error)
|
||||
aliceSigner := &input.MockSigner{Privkeys: aliceKeys}
|
||||
bobSigner := &input.MockSigner{Privkeys: bobKeys}
|
||||
|
||||
pCache := &mockPreimageCache{
|
||||
// hash -> preimage
|
||||
preimageMap: make(map[[32]byte][]byte),
|
||||
}
|
||||
pCache := newMockPreimageCache()
|
||||
|
||||
// TODO(roasbeef): make mock version of pre-image store
|
||||
|
||||
@@ -389,26 +386,36 @@ func initRevocationWindows(chanA, chanB *LightningChannel) error {
|
||||
|
||||
type mockPreimageCache struct {
|
||||
sync.Mutex
|
||||
preimageMap map[[32]byte][]byte
|
||||
preimageMap map[lntypes.Hash]lntypes.Preimage
|
||||
}
|
||||
|
||||
func (m *mockPreimageCache) LookupPreimage(hash []byte) ([]byte, bool) {
|
||||
func newMockPreimageCache() *mockPreimageCache {
|
||||
return &mockPreimageCache{
|
||||
preimageMap: make(map[lntypes.Hash]lntypes.Preimage),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *mockPreimageCache) LookupPreimage(
|
||||
hash lntypes.Hash) (lntypes.Preimage, bool) {
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
var h [32]byte
|
||||
copy(h[:], hash)
|
||||
|
||||
p, ok := m.preimageMap[h]
|
||||
p, ok := m.preimageMap[hash]
|
||||
return p, ok
|
||||
}
|
||||
|
||||
func (m *mockPreimageCache) AddPreimages(preimages ...[]byte) error {
|
||||
func (m *mockPreimageCache) AddPreimages(preimages ...lntypes.Preimage) error {
|
||||
preimageCopies := make([]lntypes.Preimage, 0, len(preimages))
|
||||
for _, preimage := range preimages {
|
||||
preimageCopies = append(preimageCopies, preimage)
|
||||
}
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
for _, preimage := range preimages {
|
||||
m.preimageMap[sha256.Sum256(preimage)] = preimage
|
||||
for _, preimage := range preimageCopies {
|
||||
m.preimageMap[preimage.Hash()] = preimage
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -780,10 +780,7 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
pCache := &mockPreimageCache{
|
||||
// hash -> preimage
|
||||
preimageMap: make(map[[32]byte][]byte),
|
||||
}
|
||||
pCache := newMockPreimageCache()
|
||||
|
||||
for i, test := range testCases {
|
||||
expectedCommitmentTx, err := txFromHex(test.expectedCommitmentTxHex)
|
||||
|
||||
Reference in new issue
Block a user