channeldb/graphdb: move outpoint ser/deser funcs to graphdb

We have the same helpers for writing and reading a wire.Outpoint type
defined separately in a couple places. We will want to use these from
the graph db package soon though so instead of defining them again
there, this commit unifies things and creates a single exported set of
helpers. The next commit will make use of these.
This commit is contained in:
Elle Mouton committed 2024-11-28 13:34:08 +02:00
1 parent 3365461500
commit 382539a6eb
7 files changed
+69 -52

No files matched your search

+15 -7
View File
@@ -30,6 +30,7 @@ import (
"github.com/lightningnetwork/lnd/channeldb/migration33"
"github.com/lightningnetwork/lnd/channeldb/migration_01_to_11"
"github.com/lightningnetwork/lnd/clock"
graphdb "github.com/lightningnetwork/lnd/graph/db"
"github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
@@ -646,7 +647,9 @@ func (c *ChannelStateDB) fetchNodeChannels(chainBucket kvdb.RBucket) (
chanBucket := chainBucket.NestedReadBucket(chanPoint)
var outPoint wire.OutPoint
err := readOutpoint(bytes.NewReader(chanPoint), &outPoint)
err := graphdb.ReadOutpoint(
bytes.NewReader(chanPoint), &outPoint,
)
if err != nil {
return err
}
@@ -675,7 +678,8 @@ func (c *ChannelStateDB) FetchChannel(tx kvdb.RTx, chanPoint wire.OutPoint) (
*OpenChannel, error) {
var targetChanPoint bytes.Buffer
if err := writeOutpoint(&targetChanPoint, &chanPoint); err != nil {
err := graphdb.WriteOutpoint(&targetChanPoint, &chanPoint)
if err != nil {
return nil, err
}
@@ -709,7 +713,9 @@ func (c *ChannelStateDB) FetchChannelByID(tx kvdb.RTx, id lnwire.ChannelID) (
)
err := chainBkt.ForEach(func(k, _ []byte) error {
var outPoint wire.OutPoint
err := readOutpoint(bytes.NewReader(k), &outPoint)
err := graphdb.ReadOutpoint(
bytes.NewReader(k), &outPoint,
)
if err != nil {
return err
}
@@ -1089,7 +1095,7 @@ func (c *ChannelStateDB) FetchClosedChannel(chanID *wire.OutPoint) (
var b bytes.Buffer
var err error
if err = writeOutpoint(&b, chanID); err != nil {
if err = graphdb.WriteOutpoint(&b, chanID); err != nil {
return err
}
@@ -1131,7 +1137,9 @@ func (c *ChannelStateDB) FetchClosedChannelForID(cid lnwire.ChannelID) (
// We scan over all possible candidates for this channel ID.
for ; op != nil && bytes.Compare(cid[:30], op[:30]) <= 0; op, c = cursor.Next() {
var outPoint wire.OutPoint
err := readOutpoint(bytes.NewReader(op), &outPoint)
err := graphdb.ReadOutpoint(
bytes.NewReader(op), &outPoint,
)
if err != nil {
return err
}
@@ -1173,7 +1181,7 @@ func (c *ChannelStateDB) MarkChanFullyClosed(chanPoint *wire.OutPoint) error {
)
err := kvdb.Update(c.backend, func(tx kvdb.RwTx) error {
var b bytes.Buffer
if err := writeOutpoint(&b, chanPoint); err != nil {
if err := graphdb.WriteOutpoint(&b, chanPoint); err != nil {
return err
}
@@ -1693,7 +1701,7 @@ func fetchHistoricalChanBucket(tx kvdb.RTx,
// With the bucket for the node and chain fetched, we can now go down
// another level, for the channel itself.
var chanPointBuf bytes.Buffer
if err := writeOutpoint(&chanPointBuf, outPoint); err != nil {
if err := graphdb.WriteOutpoint(&chanPointBuf, outPoint); err != nil {
return nil, err
}
chanBucket := historicalChanBucket.NestedReadBucket(