chainntnfs: move cache implementation to channeldb
This commit moves the `HeightHintCache` implementation to the `channeldb` package and inverts the dependency relation between `chainntnfs` and `channeldb`. Many packages depend on channeldb for type definitions, interfaces, etc. `chainntnfs` is an example of that. `chainntnfs` defines the `SpendHintCache` and `ConfirmHintCache` interfaces but it also implments them (`HeightHintCache` struct). The implementation uses logic that should not leak from channeldb (ex: bucket paths). This makes our code highly coupled + it would not allow us to use any of these interfaces in a package that is imported by `channeldb` (circular dependency).
This commit is contained in:
10 files changed
+169
-173
No files matched your search
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -201,21 +200,6 @@ func (r ConfRequest) String() string {
|
||||
return fmt.Sprintf("script=%v", r.PkScript)
|
||||
}
|
||||
|
||||
// ConfHintKey returns the key that will be used to index the confirmation
|
||||
// request's hint within the height hint cache.
|
||||
func (r ConfRequest) ConfHintKey() ([]byte, error) {
|
||||
if r.TxID == ZeroHash {
|
||||
return r.PkScript.Script(), nil
|
||||
}
|
||||
|
||||
var txid bytes.Buffer
|
||||
if err := channeldb.WriteElement(&txid, r.TxID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return txid.Bytes(), nil
|
||||
}
|
||||
|
||||
// MatchesTx determines whether the given transaction satisfies the confirmation
|
||||
// request. If the confirmation request is for a script, then we'll check all of
|
||||
// the outputs of the transaction to determine if it matches. Otherwise, we'll
|
||||
@@ -369,22 +353,6 @@ func (r SpendRequest) String() string {
|
||||
return fmt.Sprintf("outpoint=<zero>, script=%v", r.PkScript)
|
||||
}
|
||||
|
||||
// SpendHintKey returns the key that will be used to index the spend request's
|
||||
// hint within the height hint cache.
|
||||
func (r SpendRequest) SpendHintKey() ([]byte, error) {
|
||||
if r.OutPoint == ZeroOutPoint {
|
||||
return r.PkScript.Script(), nil
|
||||
}
|
||||
|
||||
var outpoint bytes.Buffer
|
||||
err := channeldb.WriteElement(&outpoint, r.OutPoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return outpoint.Bytes(), nil
|
||||
}
|
||||
|
||||
// MatchesTx determines whether the given transaction satisfies the spend
|
||||
// request. If the spend request is for an outpoint, then we'll check all of
|
||||
// the outputs being spent by the inputs of the transaction to determine if it
|
||||
|
||||
Reference in new issue
Block a user