multi: switch from bolt packge to bbolt package for all imports
This commit is contained in:
41 files changed
+404
-405
No files matched your search
+41
-41
@@ -495,7 +495,7 @@ func (c *OpenChannel) RefreshShortChanID() error {
|
||||
defer c.Unlock()
|
||||
|
||||
var sid lnwire.ShortChannelID
|
||||
err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -525,8 +525,8 @@ func (c *OpenChannel) RefreshShortChanID() error {
|
||||
// fetchChanBucket is a helper function that returns the bucket where a
|
||||
// channel's data resides in given: the public key for the node, the outpoint,
|
||||
// and the chainhash that the channel resides on.
|
||||
func fetchChanBucket(tx *bolt.Tx, nodeKey *btcec.PublicKey,
|
||||
outPoint *wire.OutPoint, chainHash chainhash.Hash) (*bolt.Bucket, error) {
|
||||
func fetchChanBucket(tx *bbolt.Tx, nodeKey *btcec.PublicKey,
|
||||
outPoint *wire.OutPoint, chainHash chainhash.Hash) (*bbolt.Bucket, error) {
|
||||
|
||||
// First fetch the top level bucket which stores all data related to
|
||||
// current, active channels.
|
||||
@@ -567,7 +567,7 @@ func fetchChanBucket(tx *bolt.Tx, nodeKey *btcec.PublicKey,
|
||||
// fullSync is an internal version of the FullSync method which allows callers
|
||||
// to sync the contents of an OpenChannel while re-using an existing database
|
||||
// transaction.
|
||||
func (c *OpenChannel) fullSync(tx *bolt.Tx) error {
|
||||
func (c *OpenChannel) fullSync(tx *bbolt.Tx) error {
|
||||
// First fetch the top level bucket which stores all data related to
|
||||
// current, active channels.
|
||||
openChanBucket, err := tx.CreateBucketIfNotExists(openChannelBucket)
|
||||
@@ -613,7 +613,7 @@ func (c *OpenChannel) MarkAsOpen(openLoc lnwire.ShortChannelID) error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
if err := c.Db.Update(func(tx *bolt.Tx) error {
|
||||
if err := c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -649,7 +649,7 @@ func (c *OpenChannel) MarkDataLoss(commitPoint *btcec.PublicKey) error {
|
||||
defer c.Unlock()
|
||||
|
||||
var status ChannelStatus
|
||||
if err := c.Db.Update(func(tx *bolt.Tx) error {
|
||||
if err := c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -693,7 +693,7 @@ func (c *OpenChannel) MarkDataLoss(commitPoint *btcec.PublicKey) error {
|
||||
func (c *OpenChannel) DataLossCommitPoint() (*btcec.PublicKey, error) {
|
||||
var commitPoint *btcec.PublicKey
|
||||
|
||||
err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -744,7 +744,7 @@ func (c *OpenChannel) MarkCommitmentBroadcasted() error {
|
||||
}
|
||||
|
||||
func (c *OpenChannel) putChanStatus(status ChannelStatus) error {
|
||||
if err := c.Db.Update(func(tx *bolt.Tx) error {
|
||||
if err := c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -774,7 +774,7 @@ func (c *OpenChannel) putChanStatus(status ChannelStatus) error {
|
||||
|
||||
// putChannel serializes, and stores the current state of the channel in its
|
||||
// entirety.
|
||||
func putOpenChannel(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
func putOpenChannel(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
|
||||
// First, we'll write out all the relatively static fields, that are
|
||||
// decided upon initial channel creation.
|
||||
if err := putChanInfo(chanBucket, channel); err != nil {
|
||||
@@ -798,7 +798,7 @@ func putOpenChannel(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
|
||||
// fetchOpenChannel retrieves, and deserializes (including decrypting
|
||||
// sensitive) the complete channel currently active with the passed nodeID.
|
||||
func fetchOpenChannel(chanBucket *bolt.Bucket,
|
||||
func fetchOpenChannel(chanBucket *bbolt.Bucket,
|
||||
chanPoint *wire.OutPoint) (*OpenChannel, error) {
|
||||
|
||||
channel := &OpenChannel{
|
||||
@@ -845,7 +845,7 @@ func (c *OpenChannel) SyncPending(addr net.Addr, pendingHeight uint32) error {
|
||||
|
||||
c.FundingBroadcastHeight = pendingHeight
|
||||
|
||||
return c.Db.Update(func(tx *bolt.Tx) error {
|
||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
// First, sync all the persistent channel state to disk.
|
||||
if err := c.fullSync(tx); err != nil {
|
||||
return err
|
||||
@@ -884,7 +884,7 @@ func (c *OpenChannel) UpdateCommitment(newCommitment *ChannelCommitment) error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
err := c.Db.Update(func(tx *bolt.Tx) error {
|
||||
err := c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -1303,7 +1303,7 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
return c.Db.Update(func(tx *bolt.Tx) error {
|
||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
// First, we'll grab the writable bucket where this channel's
|
||||
// data resides.
|
||||
chanBucket, err := fetchChanBucket(
|
||||
@@ -1353,7 +1353,7 @@ func (c *OpenChannel) AppendRemoteCommitChain(diff *CommitDiff) error {
|
||||
// these pointers, causing the tip and the tail to point to the same entry.
|
||||
func (c *OpenChannel) RemoteCommitChainTip() (*CommitDiff, error) {
|
||||
var cd *CommitDiff
|
||||
err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -1399,7 +1399,7 @@ func (c *OpenChannel) InsertNextRevocation(revKey *btcec.PublicKey) error {
|
||||
|
||||
c.RemoteNextRevocation = revKey
|
||||
|
||||
err := c.Db.Update(func(tx *bolt.Tx) error {
|
||||
err := c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -1429,7 +1429,7 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg) error {
|
||||
|
||||
var newRemoteCommit *ChannelCommitment
|
||||
|
||||
err := c.Db.Update(func(tx *bolt.Tx) error {
|
||||
err := c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -1537,7 +1537,7 @@ func (c *OpenChannel) LoadFwdPkgs() ([]*FwdPkg, error) {
|
||||
defer c.RUnlock()
|
||||
|
||||
var fwdPkgs []*FwdPkg
|
||||
if err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
if err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
var err error
|
||||
fwdPkgs, err = c.Packager.LoadFwdPkgs(tx)
|
||||
return err
|
||||
@@ -1555,7 +1555,7 @@ func (c *OpenChannel) AckAddHtlcs(addRefs ...AddRef) error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
return c.Db.Update(func(tx *bolt.Tx) error {
|
||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
return c.Packager.AckAddHtlcs(tx, addRefs...)
|
||||
})
|
||||
}
|
||||
@@ -1568,7 +1568,7 @@ func (c *OpenChannel) AckSettleFails(settleFailRefs ...SettleFailRef) error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
return c.Db.Update(func(tx *bolt.Tx) error {
|
||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
return c.Packager.AckSettleFails(tx, settleFailRefs...)
|
||||
})
|
||||
}
|
||||
@@ -1579,7 +1579,7 @@ func (c *OpenChannel) SetFwdFilter(height uint64, fwdFilter *PkgFilter) error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
return c.Db.Update(func(tx *bolt.Tx) error {
|
||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
return c.Packager.SetFwdFilter(tx, height, fwdFilter)
|
||||
})
|
||||
}
|
||||
@@ -1592,7 +1592,7 @@ func (c *OpenChannel) RemoveFwdPkg(height uint64) error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
return c.Db.Update(func(tx *bolt.Tx) error {
|
||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
return c.Packager.RemovePkg(tx, height)
|
||||
})
|
||||
}
|
||||
@@ -1612,7 +1612,7 @@ func (c *OpenChannel) RevocationLogTail() (*ChannelCommitment, error) {
|
||||
}
|
||||
|
||||
var commit ChannelCommitment
|
||||
if err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
if err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -1659,7 +1659,7 @@ func (c *OpenChannel) CommitmentHeight() (uint64, error) {
|
||||
defer c.RUnlock()
|
||||
|
||||
var height uint64
|
||||
err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
// Get the bucket dedicated to storing the metadata for open
|
||||
// channels.
|
||||
chanBucket, err := fetchChanBucket(
|
||||
@@ -1694,7 +1694,7 @@ func (c *OpenChannel) FindPreviousState(updateNum uint64) (*ChannelCommitment, e
|
||||
defer c.RUnlock()
|
||||
|
||||
var commit ChannelCommitment
|
||||
err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -1848,7 +1848,7 @@ func (c *OpenChannel) CloseChannel(summary *ChannelCloseSummary) error {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
|
||||
return c.Db.Update(func(tx *bolt.Tx) error {
|
||||
return c.Db.Update(func(tx *bbolt.Tx) error {
|
||||
openChanBucket := tx.Bucket(openChannelBucket)
|
||||
if openChanBucket == nil {
|
||||
return ErrNoChanDBExists
|
||||
@@ -1992,7 +1992,7 @@ func (c *OpenChannel) Snapshot() *ChannelSnapshot {
|
||||
// latest fully committed state is returned. The first commitment returned is
|
||||
// the local commitment, and the second returned is the remote commitment.
|
||||
func (c *OpenChannel) LatestCommitments() (*ChannelCommitment, *ChannelCommitment, error) {
|
||||
err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -2014,7 +2014,7 @@ func (c *OpenChannel) LatestCommitments() (*ChannelCommitment, *ChannelCommitmen
|
||||
// acting on a possible contract breach to ensure, that the caller has the most
|
||||
// up to date information required to deliver justice.
|
||||
func (c *OpenChannel) RemoteRevocationStore() (shachain.Store, error) {
|
||||
err := c.Db.View(func(tx *bolt.Tx) error {
|
||||
err := c.Db.View(func(tx *bbolt.Tx) error {
|
||||
chanBucket, err := fetchChanBucket(
|
||||
tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash,
|
||||
)
|
||||
@@ -2031,7 +2031,7 @@ func (c *OpenChannel) RemoteRevocationStore() (shachain.Store, error) {
|
||||
return c.RevocationStore, nil
|
||||
}
|
||||
|
||||
func putChannelCloseSummary(tx *bolt.Tx, chanID []byte,
|
||||
func putChannelCloseSummary(tx *bbolt.Tx, chanID []byte,
|
||||
summary *ChannelCloseSummary, lastChanState *OpenChannel) error {
|
||||
|
||||
closedChanBucket, err := tx.CreateBucketIfNotExists(closedChannelBucket)
|
||||
@@ -2110,7 +2110,7 @@ func serializeChannelCloseSummary(w io.Writer, cs *ChannelCloseSummary) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func fetchChannelCloseSummary(tx *bolt.Tx,
|
||||
func fetchChannelCloseSummary(tx *bbolt.Tx,
|
||||
chanID []byte) (*ChannelCloseSummary, error) {
|
||||
|
||||
closedChanBucket, err := tx.CreateBucketIfNotExists(closedChannelBucket)
|
||||
@@ -2217,7 +2217,7 @@ func writeChanConfig(b io.Writer, c *ChannelConfig) error {
|
||||
)
|
||||
}
|
||||
|
||||
func putChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
func putChanInfo(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
|
||||
var w bytes.Buffer
|
||||
if err := WriteElements(&w,
|
||||
channel.ChanType, channel.ChainHash, channel.FundingOutpoint,
|
||||
@@ -2260,7 +2260,7 @@ func serializeChanCommit(w io.Writer, c *ChannelCommitment) error {
|
||||
return SerializeHtlcs(w, c.Htlcs...)
|
||||
}
|
||||
|
||||
func putChanCommitment(chanBucket *bolt.Bucket, c *ChannelCommitment,
|
||||
func putChanCommitment(chanBucket *bbolt.Bucket, c *ChannelCommitment,
|
||||
local bool) error {
|
||||
|
||||
var commitKey []byte
|
||||
@@ -2278,7 +2278,7 @@ func putChanCommitment(chanBucket *bolt.Bucket, c *ChannelCommitment,
|
||||
return chanBucket.Put(commitKey, b.Bytes())
|
||||
}
|
||||
|
||||
func putChanCommitments(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
func putChanCommitments(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
|
||||
err := putChanCommitment(chanBucket, &channel.LocalCommitment, true)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -2287,7 +2287,7 @@ func putChanCommitments(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
return putChanCommitment(chanBucket, &channel.RemoteCommitment, false)
|
||||
}
|
||||
|
||||
func putChanRevocationState(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
func putChanRevocationState(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
|
||||
|
||||
var b bytes.Buffer
|
||||
err := WriteElements(
|
||||
@@ -2322,7 +2322,7 @@ func readChanConfig(b io.Reader, c *ChannelConfig) error {
|
||||
)
|
||||
}
|
||||
|
||||
func fetchChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
func fetchChanInfo(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
|
||||
infoBytes := chanBucket.Get(chanInfoKey)
|
||||
if infoBytes == nil {
|
||||
return ErrNoChanInfoFound
|
||||
@@ -2379,7 +2379,7 @@ func deserializeChanCommit(r io.Reader) (ChannelCommitment, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func fetchChanCommitment(chanBucket *bolt.Bucket, local bool) (ChannelCommitment, error) {
|
||||
func fetchChanCommitment(chanBucket *bbolt.Bucket, local bool) (ChannelCommitment, error) {
|
||||
var commitKey []byte
|
||||
if local {
|
||||
commitKey = append(chanCommitmentKey, byte(0x00))
|
||||
@@ -2396,7 +2396,7 @@ func fetchChanCommitment(chanBucket *bolt.Bucket, local bool) (ChannelCommitment
|
||||
return deserializeChanCommit(r)
|
||||
}
|
||||
|
||||
func fetchChanCommitments(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
func fetchChanCommitments(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
|
||||
var err error
|
||||
|
||||
channel.LocalCommitment, err = fetchChanCommitment(chanBucket, true)
|
||||
@@ -2411,7 +2411,7 @@ func fetchChanCommitments(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func fetchChanRevocationState(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||
func fetchChanRevocationState(chanBucket *bbolt.Bucket, channel *OpenChannel) error {
|
||||
revBytes := chanBucket.Get(revocationStateKey)
|
||||
if revBytes == nil {
|
||||
return ErrNoRevocationsFound
|
||||
@@ -2437,7 +2437,7 @@ func fetchChanRevocationState(chanBucket *bolt.Bucket, channel *OpenChannel) err
|
||||
return ReadElements(r, &channel.RemoteNextRevocation)
|
||||
}
|
||||
|
||||
func deleteOpenChannel(chanBucket *bolt.Bucket, chanPointBytes []byte) error {
|
||||
func deleteOpenChannel(chanBucket *bbolt.Bucket, chanPointBytes []byte) error {
|
||||
|
||||
if err := chanBucket.Delete(chanInfoKey); err != nil {
|
||||
return err
|
||||
@@ -2478,7 +2478,7 @@ func readLogKey(b []byte) uint64 {
|
||||
return byteOrder.Uint64(b)
|
||||
}
|
||||
|
||||
func appendChannelLogEntry(log *bolt.Bucket,
|
||||
func appendChannelLogEntry(log *bbolt.Bucket,
|
||||
commit *ChannelCommitment) error {
|
||||
|
||||
var b bytes.Buffer
|
||||
@@ -2490,7 +2490,7 @@ func appendChannelLogEntry(log *bolt.Bucket,
|
||||
return log.Put(logEntrykey[:], b.Bytes())
|
||||
}
|
||||
|
||||
func fetchChannelLogEntry(log *bolt.Bucket,
|
||||
func fetchChannelLogEntry(log *bbolt.Bucket,
|
||||
updateNum uint64) (ChannelCommitment, error) {
|
||||
|
||||
logEntrykey := makeLogKey(updateNum)
|
||||
@@ -2503,7 +2503,7 @@ func fetchChannelLogEntry(log *bolt.Bucket,
|
||||
return deserializeChanCommit(commitReader)
|
||||
}
|
||||
|
||||
func wipeChannelLogEntries(log *bolt.Bucket) error {
|
||||
func wipeChannelLogEntries(log *bbolt.Bucket) error {
|
||||
// TODO(roasbeef): comment
|
||||
|
||||
logCursor := log.Cursor()
|
||||
|
||||
+25
-25
@@ -23,7 +23,7 @@ const (
|
||||
// migration is a function which takes a prior outdated version of the database
|
||||
// instances and mutates the key/bucket structure to arrive at a more
|
||||
// up-to-date version of the database.
|
||||
type migration func(tx *bolt.Tx) error
|
||||
type migration func(tx *bbolt.Tx) error
|
||||
|
||||
type version struct {
|
||||
number uint32
|
||||
@@ -103,7 +103,7 @@ var bufPool = &sync.Pool{
|
||||
// information related to nodes, routing data, open/closed channels, fee
|
||||
// schedules, and reputation data.
|
||||
type DB struct {
|
||||
*bolt.DB
|
||||
*bbolt.DB
|
||||
dbPath string
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func Open(dbPath string) (*DB, error) {
|
||||
}
|
||||
}
|
||||
|
||||
bdb, err := bolt.Open(path, dbFilePermission, nil)
|
||||
bdb, err := bbolt.Open(path, dbFilePermission, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -146,41 +146,41 @@ func (d *DB) Path() string {
|
||||
// database. The deletion is done in a single transaction, therefore this
|
||||
// operation is fully atomic.
|
||||
func (d *DB) Wipe() error {
|
||||
return d.Update(func(tx *bolt.Tx) error {
|
||||
return d.Update(func(tx *bbolt.Tx) error {
|
||||
err := tx.DeleteBucket(openChannelBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.DeleteBucket(closedChannelBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.DeleteBucket(invoiceBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.DeleteBucket(nodeInfoBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
err = tx.DeleteBucket(nodeBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
err = tx.DeleteBucket(edgeBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
err = tx.DeleteBucket(edgeIndexBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
err = tx.DeleteBucket(graphMetaBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -200,12 +200,12 @@ func createChannelDB(dbPath string) error {
|
||||
}
|
||||
|
||||
path := filepath.Join(dbPath, dbName)
|
||||
bdb, err := bolt.Open(path, dbFilePermission, nil)
|
||||
bdb, err := bbolt.Open(path, dbFilePermission, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = bdb.Update(func(tx *bolt.Tx) error {
|
||||
err = bdb.Update(func(tx *bbolt.Tx) error {
|
||||
if _, err := tx.CreateBucket(openChannelBucket); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -302,7 +302,7 @@ func fileExists(path string) bool {
|
||||
// zero-length slice is returned.
|
||||
func (d *DB) FetchOpenChannels(nodeID *btcec.PublicKey) ([]*OpenChannel, error) {
|
||||
var channels []*OpenChannel
|
||||
err := d.View(func(tx *bolt.Tx) error {
|
||||
err := d.View(func(tx *bbolt.Tx) error {
|
||||
var err error
|
||||
channels, err = d.fetchOpenChannels(tx, nodeID)
|
||||
return err
|
||||
@@ -315,7 +315,7 @@ func (d *DB) FetchOpenChannels(nodeID *btcec.PublicKey) ([]*OpenChannel, error)
|
||||
// stored currently active/open channels associated with the target nodeID. In
|
||||
// the case that no active channels are known to have been created with this
|
||||
// node, then a zero-length slice is returned.
|
||||
func (d *DB) fetchOpenChannels(tx *bolt.Tx,
|
||||
func (d *DB) fetchOpenChannels(tx *bbolt.Tx,
|
||||
nodeID *btcec.PublicKey) ([]*OpenChannel, error) {
|
||||
|
||||
// Get the bucket dedicated to storing the metadata for open channels.
|
||||
@@ -368,7 +368,7 @@ func (d *DB) fetchOpenChannels(tx *bolt.Tx,
|
||||
// fetchNodeChannels retrieves all active channels from the target chainBucket
|
||||
// which is under a node's dedicated channel bucket. This function is typically
|
||||
// used to fetch all the active channels related to a particular node.
|
||||
func (d *DB) fetchNodeChannels(chainBucket *bolt.Bucket) ([]*OpenChannel, error) {
|
||||
func (d *DB) fetchNodeChannels(chainBucket *bbolt.Bucket) ([]*OpenChannel, error) {
|
||||
|
||||
var channels []*OpenChannel
|
||||
|
||||
@@ -464,7 +464,7 @@ func (d *DB) FetchWaitingCloseChannels() ([]*OpenChannel, error) {
|
||||
func fetchChannels(d *DB, pending, waitingClose bool) ([]*OpenChannel, error) {
|
||||
var channels []*OpenChannel
|
||||
|
||||
err := d.View(func(tx *bolt.Tx) error {
|
||||
err := d.View(func(tx *bbolt.Tx) error {
|
||||
// Get the bucket dedicated to storing the metadata for open
|
||||
// channels.
|
||||
openChanBucket := tx.Bucket(openChannelBucket)
|
||||
@@ -551,7 +551,7 @@ func fetchChannels(d *DB, pending, waitingClose bool) ([]*OpenChannel, error) {
|
||||
func (d *DB) FetchClosedChannels(pendingOnly bool) ([]*ChannelCloseSummary, error) {
|
||||
var chanSummaries []*ChannelCloseSummary
|
||||
|
||||
if err := d.View(func(tx *bolt.Tx) error {
|
||||
if err := d.View(func(tx *bbolt.Tx) error {
|
||||
closeBucket := tx.Bucket(closedChannelBucket)
|
||||
if closeBucket == nil {
|
||||
return ErrNoClosedChannels
|
||||
@@ -589,7 +589,7 @@ var ErrClosedChannelNotFound = errors.New("unable to find closed channel summary
|
||||
// point of the channel in question.
|
||||
func (d *DB) FetchClosedChannel(chanID *wire.OutPoint) (*ChannelCloseSummary, error) {
|
||||
var chanSummary *ChannelCloseSummary
|
||||
if err := d.View(func(tx *bolt.Tx) error {
|
||||
if err := d.View(func(tx *bbolt.Tx) error {
|
||||
closeBucket := tx.Bucket(closedChannelBucket)
|
||||
if closeBucket == nil {
|
||||
return ErrClosedChannelNotFound
|
||||
@@ -623,7 +623,7 @@ func (d *DB) FetchClosedChannelForID(cid lnwire.ChannelID) (
|
||||
*ChannelCloseSummary, error) {
|
||||
|
||||
var chanSummary *ChannelCloseSummary
|
||||
if err := d.View(func(tx *bolt.Tx) error {
|
||||
if err := d.View(func(tx *bbolt.Tx) error {
|
||||
closeBucket := tx.Bucket(closedChannelBucket)
|
||||
if closeBucket == nil {
|
||||
return ErrClosedChannelNotFound
|
||||
@@ -671,7 +671,7 @@ func (d *DB) FetchClosedChannelForID(cid lnwire.ChannelID) (
|
||||
// the pending funds in a channel that has been forcibly closed have been
|
||||
// swept.
|
||||
func (d *DB) MarkChanFullyClosed(chanPoint *wire.OutPoint) error {
|
||||
return d.Update(func(tx *bolt.Tx) error {
|
||||
return d.Update(func(tx *bbolt.Tx) error {
|
||||
var b bytes.Buffer
|
||||
if err := writeOutpoint(&b, chanPoint); err != nil {
|
||||
return err
|
||||
@@ -724,7 +724,7 @@ func (d *DB) MarkChanFullyClosed(chanPoint *wire.OutPoint) error {
|
||||
// pruneLinkNode determines whether we should garbage collect a link node from
|
||||
// the database due to no longer having any open channels with it. If there are
|
||||
// any left, then this acts as a no-op.
|
||||
func (d *DB) pruneLinkNode(tx *bolt.Tx, remotePub *btcec.PublicKey) error {
|
||||
func (d *DB) pruneLinkNode(tx *bbolt.Tx, remotePub *btcec.PublicKey) error {
|
||||
openChannels, err := d.fetchOpenChannels(tx, remotePub)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to fetch open channels for peer %x: "+
|
||||
@@ -744,7 +744,7 @@ func (d *DB) pruneLinkNode(tx *bolt.Tx, remotePub *btcec.PublicKey) error {
|
||||
// PruneLinkNodes attempts to prune all link nodes found within the databse with
|
||||
// whom we no longer have any open channels with.
|
||||
func (d *DB) PruneLinkNodes() error {
|
||||
return d.Update(func(tx *bolt.Tx) error {
|
||||
return d.Update(func(tx *bbolt.Tx) error {
|
||||
linkNodes, err := d.fetchAllLinkNodes(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -803,7 +803,7 @@ func (d *DB) syncVersions(versions []version) error {
|
||||
migrations, migrationVersions := getMigrationsToApply(
|
||||
versions, meta.DbVersionNumber,
|
||||
)
|
||||
return d.Update(func(tx *bolt.Tx) error {
|
||||
return d.Update(func(tx *bbolt.Tx) error {
|
||||
for i, migration := range migrations {
|
||||
if migration == nil {
|
||||
continue
|
||||
|
||||
@@ -111,7 +111,7 @@ func (f *ForwardingLog) AddForwardingEvents(events []ForwardingEvent) error {
|
||||
|
||||
var timestamp [8]byte
|
||||
|
||||
return f.db.Batch(func(tx *bolt.Tx) error {
|
||||
return f.db.Batch(func(tx *bbolt.Tx) error {
|
||||
// First, we'll fetch the bucket that stores our time series
|
||||
// log.
|
||||
logBucket, err := tx.CreateBucketIfNotExists(
|
||||
@@ -204,7 +204,7 @@ func (f *ForwardingLog) Query(q ForwardingEventQuery) (ForwardingLogTimeSlice, e
|
||||
recordsToSkip := q.IndexOffset
|
||||
recordOffset := q.IndexOffset
|
||||
|
||||
err := f.db.View(func(tx *bolt.Tx) error {
|
||||
err := f.db.View(func(tx *bbolt.Tx) error {
|
||||
// If the bucket wasn't found, then there aren't any events to
|
||||
// be returned.
|
||||
logBucket := tx.Bucket(forwardingLogBucket)
|
||||
|
||||
@@ -318,7 +318,7 @@ type SettleFailRef struct {
|
||||
type SettleFailAcker interface {
|
||||
// AckSettleFails atomically updates the settle-fail filters in *other*
|
||||
// channels' forwarding packages.
|
||||
AckSettleFails(tx *bolt.Tx, settleFailRefs ...SettleFailRef) error
|
||||
AckSettleFails(tx *bbolt.Tx, settleFailRefs ...SettleFailRef) error
|
||||
}
|
||||
|
||||
// GlobalFwdPkgReader is an interface used to retrieve the forwarding packages
|
||||
@@ -326,7 +326,7 @@ type SettleFailAcker interface {
|
||||
type GlobalFwdPkgReader interface {
|
||||
// LoadChannelFwdPkgs loads all known forwarding packages for the given
|
||||
// channel.
|
||||
LoadChannelFwdPkgs(tx *bolt.Tx,
|
||||
LoadChannelFwdPkgs(tx *bbolt.Tx,
|
||||
source lnwire.ShortChannelID) ([]*FwdPkg, error)
|
||||
}
|
||||
|
||||
@@ -357,14 +357,14 @@ func NewSwitchPackager() *SwitchPackager {
|
||||
// AckSettleFails atomically updates the settle-fail filters in *other*
|
||||
// channels' forwarding packages, to mark that the switch has received a settle
|
||||
// or fail residing in the forwarding package of a link.
|
||||
func (*SwitchPackager) AckSettleFails(tx *bolt.Tx,
|
||||
func (*SwitchPackager) AckSettleFails(tx *bbolt.Tx,
|
||||
settleFailRefs ...SettleFailRef) error {
|
||||
|
||||
return ackSettleFails(tx, settleFailRefs)
|
||||
}
|
||||
|
||||
// LoadChannelFwdPkgs loads all forwarding packages for a particular channel.
|
||||
func (*SwitchPackager) LoadChannelFwdPkgs(tx *bolt.Tx,
|
||||
func (*SwitchPackager) LoadChannelFwdPkgs(tx *bbolt.Tx,
|
||||
source lnwire.ShortChannelID) ([]*FwdPkg, error) {
|
||||
|
||||
return loadChannelFwdPkgs(tx, source)
|
||||
@@ -376,19 +376,19 @@ func (*SwitchPackager) LoadChannelFwdPkgs(tx *bolt.Tx,
|
||||
type FwdPackager interface {
|
||||
// AddFwdPkg serializes and writes a FwdPkg for this channel at the
|
||||
// remote commitment height included in the forwarding package.
|
||||
AddFwdPkg(tx *bolt.Tx, fwdPkg *FwdPkg) error
|
||||
AddFwdPkg(tx *bbolt.Tx, fwdPkg *FwdPkg) error
|
||||
|
||||
// SetFwdFilter looks up the forwarding package at the remote `height`
|
||||
// and sets the `fwdFilter`, marking the Adds for which:
|
||||
// 1) We are not the exit node
|
||||
// 2) Passed all validation
|
||||
// 3) Should be forwarded to the switch immediately after a failure
|
||||
SetFwdFilter(tx *bolt.Tx, height uint64, fwdFilter *PkgFilter) error
|
||||
SetFwdFilter(tx *bbolt.Tx, height uint64, fwdFilter *PkgFilter) error
|
||||
|
||||
// AckAddHtlcs atomically updates the add filters in this channel's
|
||||
// forwarding packages to mark the resolution of an Add that was
|
||||
// received from the remote party.
|
||||
AckAddHtlcs(tx *bolt.Tx, addRefs ...AddRef) error
|
||||
AckAddHtlcs(tx *bbolt.Tx, addRefs ...AddRef) error
|
||||
|
||||
// SettleFailAcker allows a link to acknowledge settle/fail HTLCs
|
||||
// belonging to other channels.
|
||||
@@ -396,11 +396,11 @@ type FwdPackager interface {
|
||||
|
||||
// LoadFwdPkgs loads all known forwarding packages owned by this
|
||||
// channel.
|
||||
LoadFwdPkgs(tx *bolt.Tx) ([]*FwdPkg, error)
|
||||
LoadFwdPkgs(tx *bbolt.Tx) ([]*FwdPkg, error)
|
||||
|
||||
// RemovePkg deletes a forwarding package owned by this channel at
|
||||
// the provided remote `height`.
|
||||
RemovePkg(tx *bolt.Tx, height uint64) error
|
||||
RemovePkg(tx *bbolt.Tx, height uint64) error
|
||||
}
|
||||
|
||||
// ChannelPackager is used by a channel to manage the lifecycle of its forwarding
|
||||
@@ -420,7 +420,7 @@ func NewChannelPackager(source lnwire.ShortChannelID) *ChannelPackager {
|
||||
}
|
||||
|
||||
// AddFwdPkg writes a newly locked in forwarding package to disk.
|
||||
func (*ChannelPackager) AddFwdPkg(tx *bolt.Tx, fwdPkg *FwdPkg) error {
|
||||
func (*ChannelPackager) AddFwdPkg(tx *bbolt.Tx, fwdPkg *FwdPkg) error {
|
||||
fwdPkgBkt, err := tx.CreateBucketIfNotExists(fwdPackagesKey)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -485,7 +485,7 @@ func (*ChannelPackager) AddFwdPkg(tx *bolt.Tx, fwdPkg *FwdPkg) error {
|
||||
}
|
||||
|
||||
// putLogUpdate writes an htlc to the provided `bkt`, using `index` as the key.
|
||||
func putLogUpdate(bkt *bolt.Bucket, idx uint16, htlc *LogUpdate) error {
|
||||
func putLogUpdate(bkt *bbolt.Bucket, idx uint16, htlc *LogUpdate) error {
|
||||
var b bytes.Buffer
|
||||
if err := htlc.Encode(&b); err != nil {
|
||||
return err
|
||||
@@ -497,12 +497,12 @@ func putLogUpdate(bkt *bolt.Bucket, idx uint16, htlc *LogUpdate) error {
|
||||
// LoadFwdPkgs scans the forwarding log for any packages that haven't been
|
||||
// processed, and returns their deserialized log updates in a map indexed by the
|
||||
// remote commitment height at which the updates were locked in.
|
||||
func (p *ChannelPackager) LoadFwdPkgs(tx *bolt.Tx) ([]*FwdPkg, error) {
|
||||
func (p *ChannelPackager) LoadFwdPkgs(tx *bbolt.Tx) ([]*FwdPkg, error) {
|
||||
return loadChannelFwdPkgs(tx, p.source)
|
||||
}
|
||||
|
||||
// loadChannelFwdPkgs loads all forwarding packages owned by `source`.
|
||||
func loadChannelFwdPkgs(tx *bolt.Tx, source lnwire.ShortChannelID) ([]*FwdPkg, error) {
|
||||
func loadChannelFwdPkgs(tx *bbolt.Tx, source lnwire.ShortChannelID) ([]*FwdPkg, error) {
|
||||
fwdPkgBkt := tx.Bucket(fwdPackagesKey)
|
||||
if fwdPkgBkt == nil {
|
||||
return nil, nil
|
||||
@@ -543,7 +543,7 @@ func loadChannelFwdPkgs(tx *bolt.Tx, source lnwire.ShortChannelID) ([]*FwdPkg, e
|
||||
|
||||
// loadFwPkg reads the packager's fwd pkg at a given height, and determines the
|
||||
// appropriate FwdState.
|
||||
func loadFwdPkg(fwdPkgBkt *bolt.Bucket, source lnwire.ShortChannelID,
|
||||
func loadFwdPkg(fwdPkgBkt *bbolt.Bucket, source lnwire.ShortChannelID,
|
||||
height uint64) (*FwdPkg, error) {
|
||||
|
||||
sourceKey := makeLogKey(source.ToUint64())
|
||||
@@ -649,7 +649,7 @@ func loadFwdPkg(fwdPkgBkt *bolt.Bucket, source lnwire.ShortChannelID,
|
||||
|
||||
// loadHtlcs retrieves all serialized htlcs in a bucket, returning
|
||||
// them in order of the indexes they were written under.
|
||||
func loadHtlcs(bkt *bolt.Bucket) ([]LogUpdate, error) {
|
||||
func loadHtlcs(bkt *bbolt.Bucket) ([]LogUpdate, error) {
|
||||
var htlcs []LogUpdate
|
||||
if err := bkt.ForEach(func(_, v []byte) error {
|
||||
var htlc LogUpdate
|
||||
@@ -674,7 +674,7 @@ func loadHtlcs(bkt *bolt.Bucket) ([]LogUpdate, error) {
|
||||
// leaving this channel. After a restart, we skip validation of these Adds,
|
||||
// since they are assumed to have already been validated, and make the switch or
|
||||
// outgoing link responsible for handling replays.
|
||||
func (p *ChannelPackager) SetFwdFilter(tx *bolt.Tx, height uint64,
|
||||
func (p *ChannelPackager) SetFwdFilter(tx *bbolt.Tx, height uint64,
|
||||
fwdFilter *PkgFilter) error {
|
||||
|
||||
fwdPkgBkt := tx.Bucket(fwdPackagesKey)
|
||||
@@ -713,7 +713,7 @@ func (p *ChannelPackager) SetFwdFilter(tx *bolt.Tx, height uint64,
|
||||
// AckAddHtlcs accepts a list of references to add htlcs, and updates the
|
||||
// AckAddFilter of those forwarding packages to indicate that a settle or fail
|
||||
// has been received in response to the add.
|
||||
func (p *ChannelPackager) AckAddHtlcs(tx *bolt.Tx, addRefs ...AddRef) error {
|
||||
func (p *ChannelPackager) AckAddHtlcs(tx *bbolt.Tx, addRefs ...AddRef) error {
|
||||
if len(addRefs) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -753,7 +753,7 @@ func (p *ChannelPackager) AckAddHtlcs(tx *bolt.Tx, addRefs ...AddRef) error {
|
||||
|
||||
// ackAddHtlcsAtHeight updates the AddAckFilter of a single forwarding package
|
||||
// with a list of indexes, writing the resulting filter back in its place.
|
||||
func ackAddHtlcsAtHeight(sourceBkt *bolt.Bucket, height uint64,
|
||||
func ackAddHtlcsAtHeight(sourceBkt *bbolt.Bucket, height uint64,
|
||||
indexes []uint16) error {
|
||||
|
||||
heightKey := makeLogKey(height)
|
||||
@@ -796,12 +796,12 @@ func ackAddHtlcsAtHeight(sourceBkt *bolt.Bucket, height uint64,
|
||||
// package. This should only be called after the source of the Add has locked in
|
||||
// the settle/fail, or it becomes otherwise safe to forgo retransmitting the
|
||||
// settle/fail after a restart.
|
||||
func (p *ChannelPackager) AckSettleFails(tx *bolt.Tx, settleFailRefs ...SettleFailRef) error {
|
||||
func (p *ChannelPackager) AckSettleFails(tx *bbolt.Tx, settleFailRefs ...SettleFailRef) error {
|
||||
return ackSettleFails(tx, settleFailRefs)
|
||||
}
|
||||
|
||||
// ackSettleFails persistently acknowledges a batch of settle fail references.
|
||||
func ackSettleFails(tx *bolt.Tx, settleFailRefs []SettleFailRef) error {
|
||||
func ackSettleFails(tx *bbolt.Tx, settleFailRefs []SettleFailRef) error {
|
||||
if len(settleFailRefs) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -855,7 +855,7 @@ func ackSettleFails(tx *bolt.Tx, settleFailRefs []SettleFailRef) error {
|
||||
|
||||
// ackSettleFailsAtHeight given a destination bucket, acks the provided indexes
|
||||
// at particular a height by updating the settle fail filter.
|
||||
func ackSettleFailsAtHeight(destBkt *bolt.Bucket, height uint64,
|
||||
func ackSettleFailsAtHeight(destBkt *bbolt.Bucket, height uint64,
|
||||
indexes []uint16) error {
|
||||
|
||||
heightKey := makeLogKey(height)
|
||||
@@ -895,7 +895,7 @@ func ackSettleFailsAtHeight(destBkt *bolt.Bucket, height uint64,
|
||||
|
||||
// RemovePkg deletes the forwarding package at the given height from the
|
||||
// packager's source bucket.
|
||||
func (p *ChannelPackager) RemovePkg(tx *bolt.Tx, height uint64) error {
|
||||
func (p *ChannelPackager) RemovePkg(tx *bbolt.Tx, height uint64) error {
|
||||
fwdPkgBkt := tx.Bucket(fwdPackagesKey)
|
||||
if fwdPkgBkt == nil {
|
||||
return nil
|
||||
|
||||
@@ -207,7 +207,7 @@ func TestPackagerEmptyFwdPkg(t *testing.T) {
|
||||
// Next, create and write a new forwarding package with no htlcs.
|
||||
fwdPkg := channeldb.NewFwdPkg(shortChanID, 0, nil, nil)
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AddFwdPkg(tx, fwdPkg)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to add fwd pkg: %v", err)
|
||||
@@ -226,7 +226,7 @@ func TestPackagerEmptyFwdPkg(t *testing.T) {
|
||||
|
||||
// Now, write the forwarding decision. In this case, its just an empty
|
||||
// fwd filter.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.SetFwdFilter(tx, fwdPkg.Height, fwdPkg.FwdFilter)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to set fwdfiter: %v", err)
|
||||
@@ -244,7 +244,7 @@ func TestPackagerEmptyFwdPkg(t *testing.T) {
|
||||
assertAckFilterIsFull(t, fwdPkgs[0], true)
|
||||
|
||||
// Lastly, remove the completed forwarding package from disk.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.RemovePkg(tx, fwdPkg.Height)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to remove fwdpkg: %v", err)
|
||||
@@ -279,7 +279,7 @@ func TestPackagerOnlyAdds(t *testing.T) {
|
||||
|
||||
nAdds := len(adds)
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AddFwdPkg(tx, fwdPkg)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to add fwd pkg: %v", err)
|
||||
@@ -300,7 +300,7 @@ func TestPackagerOnlyAdds(t *testing.T) {
|
||||
// added any adds to the fwdfilter, this would indicate that all of the
|
||||
// adds were 1) settled locally by this link (exit hop), or 2) the htlc
|
||||
// was failed locally.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.SetFwdFilter(tx, fwdPkg.Height, fwdPkg.FwdFilter)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to set fwdfiter: %v", err)
|
||||
@@ -324,7 +324,7 @@ func TestPackagerOnlyAdds(t *testing.T) {
|
||||
Index: uint16(i),
|
||||
}
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AckAddHtlcs(tx, addRef)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to ack add htlc: %v", err)
|
||||
@@ -343,7 +343,7 @@ func TestPackagerOnlyAdds(t *testing.T) {
|
||||
assertAckFilterIsFull(t, fwdPkgs[0], true)
|
||||
|
||||
// Lastly, remove the completed forwarding package from disk.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.RemovePkg(tx, fwdPkg.Height)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to remove fwdpkg: %v", err)
|
||||
@@ -381,7 +381,7 @@ func TestPackagerOnlySettleFails(t *testing.T) {
|
||||
|
||||
nSettleFails := len(settleFails)
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AddFwdPkg(tx, fwdPkg)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to add fwd pkg: %v", err)
|
||||
@@ -402,7 +402,7 @@ func TestPackagerOnlySettleFails(t *testing.T) {
|
||||
// added any adds to the fwdfilter, this would indicate that all of the
|
||||
// adds were 1) settled locally by this link (exit hop), or 2) the htlc
|
||||
// was failed locally.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.SetFwdFilter(tx, fwdPkg.Height, fwdPkg.FwdFilter)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to set fwdfiter: %v", err)
|
||||
@@ -428,7 +428,7 @@ func TestPackagerOnlySettleFails(t *testing.T) {
|
||||
Index: uint16(i),
|
||||
}
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AckSettleFails(tx, failSettleRef)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to ack add htlc: %v", err)
|
||||
@@ -448,7 +448,7 @@ func TestPackagerOnlySettleFails(t *testing.T) {
|
||||
assertAckFilterIsFull(t, fwdPkgs[0], true)
|
||||
|
||||
// Lastly, remove the completed forwarding package from disk.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.RemovePkg(tx, fwdPkg.Height)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to remove fwdpkg: %v", err)
|
||||
@@ -486,7 +486,7 @@ func TestPackagerAddsThenSettleFails(t *testing.T) {
|
||||
nAdds := len(adds)
|
||||
nSettleFails := len(settleFails)
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AddFwdPkg(tx, fwdPkg)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to add fwd pkg: %v", err)
|
||||
@@ -507,7 +507,7 @@ func TestPackagerAddsThenSettleFails(t *testing.T) {
|
||||
// added any adds to the fwdfilter, this would indicate that all of the
|
||||
// adds were 1) settled locally by this link (exit hop), or 2) the htlc
|
||||
// was failed locally.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.SetFwdFilter(tx, fwdPkg.Height, fwdPkg.FwdFilter)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to set fwdfiter: %v", err)
|
||||
@@ -532,7 +532,7 @@ func TestPackagerAddsThenSettleFails(t *testing.T) {
|
||||
Index: uint16(i),
|
||||
}
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AckAddHtlcs(tx, addRef)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to ack add htlc: %v", err)
|
||||
@@ -559,7 +559,7 @@ func TestPackagerAddsThenSettleFails(t *testing.T) {
|
||||
Index: uint16(i),
|
||||
}
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AckSettleFails(tx, failSettleRef)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to remove settle/fail htlc: %v", err)
|
||||
@@ -579,7 +579,7 @@ func TestPackagerAddsThenSettleFails(t *testing.T) {
|
||||
assertAckFilterIsFull(t, fwdPkgs[0], true)
|
||||
|
||||
// Lastly, remove the completed forwarding package from disk.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.RemovePkg(tx, fwdPkg.Height)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to remove fwdpkg: %v", err)
|
||||
@@ -619,7 +619,7 @@ func TestPackagerSettleFailsThenAdds(t *testing.T) {
|
||||
nAdds := len(adds)
|
||||
nSettleFails := len(settleFails)
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AddFwdPkg(tx, fwdPkg)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to add fwd pkg: %v", err)
|
||||
@@ -640,7 +640,7 @@ func TestPackagerSettleFailsThenAdds(t *testing.T) {
|
||||
// added any adds to the fwdfilter, this would indicate that all of the
|
||||
// adds were 1) settled locally by this link (exit hop), or 2) the htlc
|
||||
// was failed locally.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.SetFwdFilter(tx, fwdPkg.Height, fwdPkg.FwdFilter)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to set fwdfiter: %v", err)
|
||||
@@ -669,7 +669,7 @@ func TestPackagerSettleFailsThenAdds(t *testing.T) {
|
||||
Index: uint16(i),
|
||||
}
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AckSettleFails(tx, failSettleRef)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to remove settle/fail htlc: %v", err)
|
||||
@@ -696,7 +696,7 @@ func TestPackagerSettleFailsThenAdds(t *testing.T) {
|
||||
Index: uint16(i),
|
||||
}
|
||||
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.AckAddHtlcs(tx, addRef)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to ack add htlc: %v", err)
|
||||
@@ -716,7 +716,7 @@ func TestPackagerSettleFailsThenAdds(t *testing.T) {
|
||||
assertAckFilterIsFull(t, fwdPkgs[0], true)
|
||||
|
||||
// Lastly, remove the completed forwarding package from disk.
|
||||
if err := db.Update(func(tx *bolt.Tx) error {
|
||||
if err := db.Update(func(tx *bbolt.Tx) error {
|
||||
return packager.RemovePkg(tx, fwdPkg.Height)
|
||||
}); err != nil {
|
||||
t.Fatalf("unable to remove fwdpkg: %v", err)
|
||||
@@ -778,11 +778,11 @@ func assertSettleFailFilterIsFull(t *testing.T, fwdPkg *channeldb.FwdPkg, expect
|
||||
|
||||
// loadFwdPkgs is a helper method that reads all forwarding packages for a
|
||||
// particular packager.
|
||||
func loadFwdPkgs(t *testing.T, db *bolt.DB,
|
||||
func loadFwdPkgs(t *testing.T, db *bbolt.DB,
|
||||
packager channeldb.FwdPackager) []*channeldb.FwdPkg {
|
||||
|
||||
var fwdPkgs []*channeldb.FwdPkg
|
||||
if err := db.View(func(tx *bolt.Tx) error {
|
||||
if err := db.View(func(tx *bbolt.Tx) error {
|
||||
var err error
|
||||
fwdPkgs, err = packager.LoadFwdPkgs(tx)
|
||||
return err
|
||||
@@ -795,7 +795,7 @@ func loadFwdPkgs(t *testing.T, db *bolt.DB,
|
||||
|
||||
// makeFwdPkgDB initializes a test database for forwarding packages. If the
|
||||
// provided path is an empty, it will create a temp dir/file to use.
|
||||
func makeFwdPkgDB(t *testing.T, path string) *bolt.DB {
|
||||
func makeFwdPkgDB(t *testing.T, path string) *bbolt.DB {
|
||||
if path == "" {
|
||||
var err error
|
||||
path, err = ioutil.TempDir("", "fwdpkgdb")
|
||||
@@ -806,7 +806,7 @@ func makeFwdPkgDB(t *testing.T, path string) *bolt.DB {
|
||||
path = filepath.Join(path, "fwdpkg.db")
|
||||
}
|
||||
|
||||
db, err := bolt.Open(path, 0600, nil)
|
||||
db, err := bbolt.Open(path, 0600, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to open boltdb: %v", err)
|
||||
}
|
||||
|
||||
+58
-58
@@ -171,7 +171,7 @@ func (c *ChannelGraph) Database() *DB {
|
||||
func (c *ChannelGraph) ForEachChannel(cb func(*ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error {
|
||||
// TODO(roasbeef): ptr map to reduce # of allocs? no duplicates
|
||||
|
||||
return c.db.View(func(tx *bolt.Tx) error {
|
||||
return c.db.View(func(tx *bbolt.Tx) error {
|
||||
// First, grab the node bucket. This will be used to populate
|
||||
// the Node pointers in each edge read from disk.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -229,8 +229,8 @@ func (c *ChannelGraph) ForEachChannel(cb func(*ChannelEdgeInfo, *ChannelEdgePoli
|
||||
//
|
||||
// TODO(roasbeef): add iterator interface to allow for memory efficient graph
|
||||
// traversal when graph gets mega
|
||||
func (c *ChannelGraph) ForEachNode(tx *bolt.Tx, cb func(*bolt.Tx, *LightningNode) error) error {
|
||||
traversal := func(tx *bolt.Tx) error {
|
||||
func (c *ChannelGraph) ForEachNode(tx *bbolt.Tx, cb func(*bbolt.Tx, *LightningNode) error) error {
|
||||
traversal := func(tx *bbolt.Tx) error {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -276,7 +276,7 @@ func (c *ChannelGraph) ForEachNode(tx *bolt.Tx, cb func(*bolt.Tx, *LightningNode
|
||||
// node based off the source node.
|
||||
func (c *ChannelGraph) SourceNode() (*LightningNode, error) {
|
||||
var source *LightningNode
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
node, err := c.sourceNode(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -296,7 +296,7 @@ func (c *ChannelGraph) SourceNode() (*LightningNode, error) {
|
||||
// of the graph. The source node is treated as the center node within a
|
||||
// star-graph. This method may be used to kick off a path finding algorithm in
|
||||
// order to explore the reachability of another node based off the source node.
|
||||
func (c *ChannelGraph) sourceNode(tx *bolt.Tx) (*LightningNode, error) {
|
||||
func (c *ChannelGraph) sourceNode(tx *bbolt.Tx) (*LightningNode, error) {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -326,7 +326,7 @@ func (c *ChannelGraph) sourceNode(tx *bolt.Tx) (*LightningNode, error) {
|
||||
func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
||||
nodePubBytes := node.PubKeyBytes[:]
|
||||
|
||||
return c.db.Update(func(tx *bolt.Tx) error {
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
@@ -355,12 +355,12 @@ func (c *ChannelGraph) SetSourceNode(node *LightningNode) error {
|
||||
//
|
||||
// TODO(roasbeef): also need sig of announcement
|
||||
func (c *ChannelGraph) AddLightningNode(node *LightningNode) error {
|
||||
return c.db.Update(func(tx *bolt.Tx) error {
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
return addLightningNode(tx, node)
|
||||
})
|
||||
}
|
||||
|
||||
func addLightningNode(tx *bolt.Tx, node *LightningNode) error {
|
||||
func addLightningNode(tx *bbolt.Tx, node *LightningNode) error {
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -386,7 +386,7 @@ func addLightningNode(tx *bolt.Tx, node *LightningNode) error {
|
||||
func (c *ChannelGraph) LookupAlias(pub *btcec.PublicKey) (string, error) {
|
||||
var alias string
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return ErrGraphNodesNotFound
|
||||
@@ -419,14 +419,14 @@ func (c *ChannelGraph) LookupAlias(pub *btcec.PublicKey) (string, error) {
|
||||
// from the database according to the node's public key.
|
||||
func (c *ChannelGraph) DeleteLightningNode(nodePub *btcec.PublicKey) error {
|
||||
// TODO(roasbeef): ensure dangling edges are removed...
|
||||
return c.db.Update(func(tx *bolt.Tx) error {
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
return c.deleteLightningNode(tx, nodePub.SerializeCompressed())
|
||||
})
|
||||
}
|
||||
|
||||
// deleteLightningNode uses an existing database transaction to remove a
|
||||
// vertex/node from the database according to the node's public key.
|
||||
func (c *ChannelGraph) deleteLightningNode(tx *bolt.Tx,
|
||||
func (c *ChannelGraph) deleteLightningNode(tx *bbolt.Tx,
|
||||
compressedPubKey []byte) error {
|
||||
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -485,7 +485,7 @@ func (c *ChannelGraph) AddChannelEdge(edge *ChannelEdgeInfo) error {
|
||||
var chanKey [8]byte
|
||||
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
||||
|
||||
return c.db.Update(func(tx *bolt.Tx) error {
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -591,7 +591,7 @@ func (c *ChannelGraph) HasChannelEdge(chanID uint64) (time.Time, time.Time, bool
|
||||
exists bool
|
||||
)
|
||||
|
||||
if err := c.db.View(func(tx *bolt.Tx) error {
|
||||
if err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@@ -651,7 +651,7 @@ func (c *ChannelGraph) UpdateChannelEdge(edge *ChannelEdgeInfo) error {
|
||||
var chanKey [8]byte
|
||||
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
||||
|
||||
return c.db.Update(func(tx *bolt.Tx) error {
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -690,7 +690,7 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
||||
|
||||
var chansClosed []*ChannelEdgeInfo
|
||||
|
||||
err := c.db.Update(func(tx *bolt.Tx) error {
|
||||
err := c.db.Update(func(tx *bbolt.Tx) error {
|
||||
// First grab the edges bucket which houses the information
|
||||
// we'd like to delete
|
||||
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
||||
@@ -794,7 +794,7 @@ func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
||||
// that we only maintain a graph of reachable nodes. In the event that a pruned
|
||||
// node gains more channels, it will be re-added back to the graph.
|
||||
func (c *ChannelGraph) PruneGraphNodes() error {
|
||||
return c.db.Update(func(tx *bolt.Tx) error {
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
nodes, err := tx.CreateBucketIfNotExists(nodeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -815,8 +815,8 @@ func (c *ChannelGraph) PruneGraphNodes() error {
|
||||
// pruneGraphNodes attempts to remove any nodes from the graph who have had a
|
||||
// channel closed within the current block. If the node still has existing
|
||||
// channels in the graph, this will act as a no-op.
|
||||
func (c *ChannelGraph) pruneGraphNodes(tx *bolt.Tx, nodes *bolt.Bucket,
|
||||
edgeIndex *bolt.Bucket) error {
|
||||
func (c *ChannelGraph) pruneGraphNodes(tx *bbolt.Tx, nodes *bbolt.Bucket,
|
||||
edgeIndex *bbolt.Bucket) error {
|
||||
|
||||
log.Trace("Pruning nodes from graph with no open channels")
|
||||
|
||||
@@ -939,7 +939,7 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) ([]*ChannelEdgeInf
|
||||
// Keep track of the channels that are removed from the graph.
|
||||
var removedChans []*ChannelEdgeInfo
|
||||
|
||||
if err := c.db.Update(func(tx *bolt.Tx) error {
|
||||
if err := c.db.Update(func(tx *bbolt.Tx) error {
|
||||
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1022,7 +1022,7 @@ func (c *ChannelGraph) PruneTip() (*chainhash.Hash, uint32, error) {
|
||||
tipHeight uint32
|
||||
)
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
graphMeta := tx.Bucket(graphMetaBucket)
|
||||
if graphMeta == nil {
|
||||
return ErrGraphNotFound
|
||||
@@ -1063,7 +1063,7 @@ func (c *ChannelGraph) DeleteChannelEdge(chanPoint *wire.OutPoint) error {
|
||||
// channels
|
||||
// TODO(roasbeef): don't delete both edges?
|
||||
|
||||
return c.db.Update(func(tx *bolt.Tx) error {
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
// First grab the edges bucket which houses the information
|
||||
// we'd like to delete
|
||||
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
||||
@@ -1099,7 +1099,7 @@ func (c *ChannelGraph) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if err := c.db.View(func(tx *bolt.Tx) error {
|
||||
if err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@@ -1132,7 +1132,7 @@ func (c *ChannelGraph) ChannelID(chanPoint *wire.OutPoint) (uint64, error) {
|
||||
func (c *ChannelGraph) HighestChanID() (uint64, error) {
|
||||
var cid uint64
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@@ -1191,7 +1191,7 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(startTime, endTime time.Time) ([]Cha
|
||||
edgesSeen := make(map[uint64]struct{})
|
||||
var edgesInHorizon []ChannelEdge
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@@ -1293,7 +1293,7 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(startTime, endTime time.Time) ([]Cha
|
||||
func (c *ChannelGraph) NodeUpdatesInHorizon(startTime, endTime time.Time) ([]LightningNode, error) {
|
||||
var nodesInHorizon []LightningNode
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return ErrGraphNodesNotFound
|
||||
@@ -1355,7 +1355,7 @@ func (c *ChannelGraph) NodeUpdatesInHorizon(startTime, endTime time.Time) ([]Lig
|
||||
func (c *ChannelGraph) FilterKnownChanIDs(chanIDs []uint64) ([]uint64, error) {
|
||||
var newChanIDs []uint64
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@@ -1415,7 +1415,7 @@ func (c *ChannelGraph) FilterChannelRange(startHeight, endHeight uint32) ([]uint
|
||||
byteOrder.PutUint64(chanIDStart[:], startChanID.ToUint64())
|
||||
byteOrder.PutUint64(chanIDEnd[:], endChanID.ToUint64())
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@@ -1466,7 +1466,7 @@ func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) {
|
||||
cidBytes [8]byte
|
||||
)
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
@@ -1516,7 +1516,7 @@ func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) {
|
||||
return chanEdges, nil
|
||||
}
|
||||
|
||||
func delEdgeUpdateIndexEntry(edgesBucket *bolt.Bucket, chanID uint64,
|
||||
func delEdgeUpdateIndexEntry(edgesBucket *bbolt.Bucket, chanID uint64,
|
||||
edge1, edge2 *ChannelEdgePolicy) error {
|
||||
|
||||
// First, we'll fetch the edge update index bucket which currently
|
||||
@@ -1555,8 +1555,8 @@ func delEdgeUpdateIndexEntry(edgesBucket *bolt.Bucket, chanID uint64,
|
||||
return nil
|
||||
}
|
||||
|
||||
func delChannelByEdge(edges *bolt.Bucket, edgeIndex *bolt.Bucket,
|
||||
chanIndex *bolt.Bucket, nodes *bolt.Bucket, chanPoint *wire.OutPoint) error {
|
||||
func delChannelByEdge(edges *bbolt.Bucket, edgeIndex *bbolt.Bucket,
|
||||
chanIndex *bbolt.Bucket, nodes *bbolt.Bucket, chanPoint *wire.OutPoint) error {
|
||||
var b bytes.Buffer
|
||||
if err := writeOutpoint(&b, chanPoint); err != nil {
|
||||
return err
|
||||
@@ -1630,7 +1630,7 @@ func delChannelByEdge(edges *bolt.Bucket, edgeIndex *bolt.Bucket,
|
||||
// determined by the lexicographical ordering of the identity public keys of
|
||||
// the nodes on either side of the channel.
|
||||
func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy) error {
|
||||
return c.db.Update(func(tx *bolt.Tx) error {
|
||||
return c.db.Update(func(tx *bbolt.Tx) error {
|
||||
edges, err := tx.CreateBucketIfNotExists(edgeBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1650,7 +1650,7 @@ func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy) error {
|
||||
|
||||
// updateEdgePolicy attempts to update an edge's policy within the relevant
|
||||
// buckets using an existing database transaction.
|
||||
func updateEdgePolicy(edges, edgeIndex, nodes *bolt.Bucket,
|
||||
func updateEdgePolicy(edges, edgeIndex, nodes *bbolt.Bucket,
|
||||
edge *ChannelEdgePolicy) error {
|
||||
|
||||
// Create the channelID key be converting the channel ID
|
||||
@@ -1808,14 +1808,14 @@ func (l *LightningNode) NodeAnnouncement(signed bool) (*lnwire.NodeAnnouncement,
|
||||
// isPublic determines whether the node is seen as public within the graph from
|
||||
// the source node's point of view. An existing database transaction can also be
|
||||
// specified.
|
||||
func (l *LightningNode) isPublic(tx *bolt.Tx, sourcePubKey []byte) (bool, error) {
|
||||
func (l *LightningNode) isPublic(tx *bbolt.Tx, sourcePubKey []byte) (bool, error) {
|
||||
// In order to determine whether this node is publicly advertised within
|
||||
// the graph, we'll need to look at all of its edges and check whether
|
||||
// they extend to any other node than the source node. errDone will be
|
||||
// used to terminate the check early.
|
||||
nodeIsPublic := false
|
||||
errDone := errors.New("done")
|
||||
err := l.ForEachChannel(tx, func(_ *bolt.Tx, info *ChannelEdgeInfo,
|
||||
err := l.ForEachChannel(tx, func(_ *bbolt.Tx, info *ChannelEdgeInfo,
|
||||
_, _ *ChannelEdgePolicy) error {
|
||||
|
||||
// If this edge doesn't extend to the source node, we'll
|
||||
@@ -1852,7 +1852,7 @@ func (l *LightningNode) isPublic(tx *bolt.Tx, sourcePubKey []byte) (bool, error)
|
||||
func (c *ChannelGraph) FetchLightningNode(pub *btcec.PublicKey) (*LightningNode, error) {
|
||||
var node *LightningNode
|
||||
nodePub := pub.SerializeCompressed()
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -1898,7 +1898,7 @@ func (c *ChannelGraph) HasLightningNode(nodePub [33]byte) (time.Time, bool, erro
|
||||
exists bool
|
||||
)
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -1947,12 +1947,12 @@ func (c *ChannelGraph) HasLightningNode(nodePub [33]byte) (time.Time, bool, erro
|
||||
// should be passed as the first argument. Otherwise the first argument should
|
||||
// be nil and a fresh transaction will be created to execute the graph
|
||||
// traversal.
|
||||
func (l *LightningNode) ForEachChannel(tx *bolt.Tx,
|
||||
cb func(*bolt.Tx, *ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error {
|
||||
func (l *LightningNode) ForEachChannel(tx *bbolt.Tx,
|
||||
cb func(*bbolt.Tx, *ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error {
|
||||
|
||||
nodePub := l.PubKeyBytes[:]
|
||||
|
||||
traversal := func(tx *bolt.Tx) error {
|
||||
traversal := func(tx *bbolt.Tx) error {
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return ErrGraphNotFound
|
||||
@@ -2217,7 +2217,7 @@ func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
|
||||
// the target node in the channel. This is useful when one knows the pubkey of
|
||||
// one of the nodes, and wishes to obtain the full LightningNode for the other
|
||||
// end of the channel.
|
||||
func (c *ChannelEdgeInfo) FetchOtherNode(tx *bolt.Tx, thisNodeKey []byte) (*LightningNode, error) {
|
||||
func (c *ChannelEdgeInfo) FetchOtherNode(tx *bbolt.Tx, thisNodeKey []byte) (*LightningNode, error) {
|
||||
|
||||
// Ensure that the node passed in is actually a member of the channel.
|
||||
var targetNodeBytes [33]byte
|
||||
@@ -2231,7 +2231,7 @@ func (c *ChannelEdgeInfo) FetchOtherNode(tx *bolt.Tx, thisNodeKey []byte) (*Ligh
|
||||
}
|
||||
|
||||
var targetNode *LightningNode
|
||||
fetchNodeFunc := func(tx *bolt.Tx) error {
|
||||
fetchNodeFunc := func(tx *bbolt.Tx) error {
|
||||
// First grab the nodes bucket which stores the mapping from
|
||||
// pubKey to node information.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -2482,7 +2482,7 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) (*ChannelE
|
||||
policy2 *ChannelEdgePolicy
|
||||
)
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
// First, grab the node bucket. This will be used to populate
|
||||
// the Node pointers in each edge read from disk.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -2561,7 +2561,7 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (*ChannelEdgeInfo, *
|
||||
channelID [8]byte
|
||||
)
|
||||
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
// First, grab the node bucket. This will be used to populate
|
||||
// the Node pointers in each edge read from disk.
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
@@ -2613,7 +2613,7 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64) (*ChannelEdgeInfo, *
|
||||
// source node's point of view.
|
||||
func (c *ChannelGraph) IsPublicNode(pubKey [33]byte) (bool, error) {
|
||||
var nodeIsPublic bool
|
||||
err := c.db.View(func(tx *bolt.Tx) error {
|
||||
err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return ErrGraphNodesNotFound
|
||||
@@ -2699,7 +2699,7 @@ func (e *EdgePoint) String() string {
|
||||
// closes on the resident blockchain.
|
||||
func (c *ChannelGraph) ChannelView() ([]EdgePoint, error) {
|
||||
var edgePoints []EdgePoint
|
||||
if err := c.db.View(func(tx *bolt.Tx) error {
|
||||
if err := c.db.View(func(tx *bbolt.Tx) error {
|
||||
// We're going to iterate over the entire channel index, so
|
||||
// we'll need to fetch the edgeBucket to get to the index as
|
||||
// it's a sub-bucket.
|
||||
@@ -2762,8 +2762,8 @@ func (c *ChannelGraph) NewChannelEdgePolicy() *ChannelEdgePolicy {
|
||||
return &ChannelEdgePolicy{db: c.db}
|
||||
}
|
||||
|
||||
func putLightningNode(nodeBucket *bolt.Bucket, aliasBucket *bolt.Bucket,
|
||||
updateIndex *bolt.Bucket, node *LightningNode) error {
|
||||
func putLightningNode(nodeBucket *bbolt.Bucket, aliasBucket *bbolt.Bucket,
|
||||
updateIndex *bbolt.Bucket, node *LightningNode) error {
|
||||
|
||||
var (
|
||||
scratch [16]byte
|
||||
@@ -2885,7 +2885,7 @@ func putLightningNode(nodeBucket *bolt.Bucket, aliasBucket *bolt.Bucket,
|
||||
return nodeBucket.Put(nodePub, b.Bytes())
|
||||
}
|
||||
|
||||
func fetchLightningNode(nodeBucket *bolt.Bucket,
|
||||
func fetchLightningNode(nodeBucket *bbolt.Bucket,
|
||||
nodePub []byte) (LightningNode, error) {
|
||||
|
||||
nodeBytes := nodeBucket.Get(nodePub)
|
||||
@@ -2991,7 +2991,7 @@ func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
||||
return node, nil
|
||||
}
|
||||
|
||||
func putChanEdgeInfo(edgeIndex *bolt.Bucket, edgeInfo *ChannelEdgeInfo, chanID [8]byte) error {
|
||||
func putChanEdgeInfo(edgeIndex *bbolt.Bucket, edgeInfo *ChannelEdgeInfo, chanID [8]byte) error {
|
||||
var b bytes.Buffer
|
||||
|
||||
if _, err := b.Write(edgeInfo.NodeKey1Bytes[:]); err != nil {
|
||||
@@ -3057,7 +3057,7 @@ func putChanEdgeInfo(edgeIndex *bolt.Bucket, edgeInfo *ChannelEdgeInfo, chanID [
|
||||
return edgeIndex.Put(chanID[:], b.Bytes())
|
||||
}
|
||||
|
||||
func fetchChanEdgeInfo(edgeIndex *bolt.Bucket,
|
||||
func fetchChanEdgeInfo(edgeIndex *bbolt.Bucket,
|
||||
chanID []byte) (ChannelEdgeInfo, error) {
|
||||
|
||||
edgeInfoBytes := edgeIndex.Get(chanID)
|
||||
@@ -3146,7 +3146,7 @@ func deserializeChanEdgeInfo(r io.Reader) (ChannelEdgeInfo, error) {
|
||||
return edgeInfo, nil
|
||||
}
|
||||
|
||||
func putChanEdgePolicy(edges, nodes *bolt.Bucket, edge *ChannelEdgePolicy,
|
||||
func putChanEdgePolicy(edges, nodes *bbolt.Bucket, edge *ChannelEdgePolicy,
|
||||
from, to []byte) error {
|
||||
|
||||
var edgeKey [33 + 8]byte
|
||||
@@ -3248,7 +3248,7 @@ func putChanEdgePolicy(edges, nodes *bolt.Bucket, edge *ChannelEdgePolicy,
|
||||
|
||||
// putChanEdgePolicyUnknown marks the edge policy as unknown
|
||||
// in the edges bucket.
|
||||
func putChanEdgePolicyUnknown(edges *bolt.Bucket, channelID uint64,
|
||||
func putChanEdgePolicyUnknown(edges *bbolt.Bucket, channelID uint64,
|
||||
from []byte) error {
|
||||
|
||||
var edgeKey [33 + 8]byte
|
||||
@@ -3263,8 +3263,8 @@ func putChanEdgePolicyUnknown(edges *bolt.Bucket, channelID uint64,
|
||||
return edges.Put(edgeKey[:], unknownPolicy)
|
||||
}
|
||||
|
||||
func fetchChanEdgePolicy(edges *bolt.Bucket, chanID []byte,
|
||||
nodePub []byte, nodes *bolt.Bucket) (*ChannelEdgePolicy, error) {
|
||||
func fetchChanEdgePolicy(edges *bbolt.Bucket, chanID []byte,
|
||||
nodePub []byte, nodes *bbolt.Bucket) (*ChannelEdgePolicy, error) {
|
||||
|
||||
var edgeKey [33 + 8]byte
|
||||
copy(edgeKey[:], nodePub)
|
||||
@@ -3285,8 +3285,8 @@ func fetchChanEdgePolicy(edges *bolt.Bucket, chanID []byte,
|
||||
return deserializeChanEdgePolicy(edgeReader, nodes)
|
||||
}
|
||||
|
||||
func fetchChanEdgePolicies(edgeIndex *bolt.Bucket, edges *bolt.Bucket,
|
||||
nodes *bolt.Bucket, chanID []byte,
|
||||
func fetchChanEdgePolicies(edgeIndex *bbolt.Bucket, edges *bbolt.Bucket,
|
||||
nodes *bbolt.Bucket, chanID []byte,
|
||||
db *DB) (*ChannelEdgePolicy, *ChannelEdgePolicy, error) {
|
||||
|
||||
edgeInfo := edgeIndex.Get(chanID)
|
||||
@@ -3327,7 +3327,7 @@ func fetchChanEdgePolicies(edgeIndex *bolt.Bucket, edges *bolt.Bucket,
|
||||
}
|
||||
|
||||
func deserializeChanEdgePolicy(r io.Reader,
|
||||
nodes *bolt.Bucket) (*ChannelEdgePolicy, error) {
|
||||
nodes *bbolt.Bucket) (*ChannelEdgePolicy, error) {
|
||||
|
||||
edge := &ChannelEdgePolicy{}
|
||||
|
||||
|
||||
@@ -837,7 +837,7 @@ func TestGraphTraversal(t *testing.T) {
|
||||
|
||||
// Iterate over each node as returned by the graph, if all nodes are
|
||||
// reached, then the map created above should be empty.
|
||||
err = graph.ForEachNode(nil, func(_ *bolt.Tx, node *LightningNode) error {
|
||||
err = graph.ForEachNode(nil, func(_ *bbolt.Tx, node *LightningNode) error {
|
||||
delete(nodeIndex, node.Alias)
|
||||
return nil
|
||||
})
|
||||
@@ -933,7 +933,7 @@ func TestGraphTraversal(t *testing.T) {
|
||||
// Finally, we want to test the ability to iterate over all the
|
||||
// outgoing channels for a particular node.
|
||||
numNodeChans := 0
|
||||
err = firstNode.ForEachChannel(nil, func(_ *bolt.Tx, _ *ChannelEdgeInfo,
|
||||
err = firstNode.ForEachChannel(nil, func(_ *bbolt.Tx, _ *ChannelEdgeInfo,
|
||||
outEdge, inEdge *ChannelEdgePolicy) error {
|
||||
|
||||
// All channels between first and second node should have fully
|
||||
@@ -1006,7 +1006,7 @@ func assertNumChans(t *testing.T, graph *ChannelGraph, n int) {
|
||||
|
||||
func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
||||
numNodes := 0
|
||||
err := graph.ForEachNode(nil, func(_ *bolt.Tx, _ *LightningNode) error {
|
||||
err := graph.ForEachNode(nil, func(_ *bbolt.Tx, _ *LightningNode) error {
|
||||
numNodes++
|
||||
return nil
|
||||
})
|
||||
@@ -2015,7 +2015,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
|
||||
|
||||
checkPolicies := func(node *LightningNode, expectedIn, expectedOut bool) {
|
||||
calls := 0
|
||||
node.ForEachChannel(nil, func(_ *bolt.Tx, _ *ChannelEdgeInfo,
|
||||
node.ForEachChannel(nil, func(_ *bbolt.Tx, _ *ChannelEdgeInfo,
|
||||
outEdge, inEdge *ChannelEdgePolicy) error {
|
||||
|
||||
if !expectedOut && outEdge != nil {
|
||||
@@ -2148,7 +2148,7 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) {
|
||||
timestampSet[t] = struct{}{}
|
||||
}
|
||||
|
||||
err := db.View(func(tx *bolt.Tx) error {
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
if edges == nil {
|
||||
return ErrGraphNoEdgesFound
|
||||
|
||||
+12
-12
@@ -185,7 +185,7 @@ func (d *DB) AddInvoice(newInvoice *Invoice) (uint64, error) {
|
||||
}
|
||||
|
||||
var invoiceAddIndex uint64
|
||||
err := d.Update(func(tx *bolt.Tx) error {
|
||||
err := d.Update(func(tx *bbolt.Tx) error {
|
||||
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -265,7 +265,7 @@ func (d *DB) InvoicesAddedSince(sinceAddIndex uint64) ([]Invoice, error) {
|
||||
var startIndex [8]byte
|
||||
byteOrder.PutUint64(startIndex[:], sinceAddIndex)
|
||||
|
||||
err := d.DB.View(func(tx *bolt.Tx) error {
|
||||
err := d.DB.View(func(tx *bbolt.Tx) error {
|
||||
invoices := tx.Bucket(invoiceBucket)
|
||||
if invoices == nil {
|
||||
return ErrNoInvoicesCreated
|
||||
@@ -320,7 +320,7 @@ func (d *DB) InvoicesAddedSince(sinceAddIndex uint64) ([]Invoice, error) {
|
||||
// terms of the payment.
|
||||
func (d *DB) LookupInvoice(paymentHash [32]byte) (Invoice, error) {
|
||||
var invoice Invoice
|
||||
err := d.View(func(tx *bolt.Tx) error {
|
||||
err := d.View(func(tx *bbolt.Tx) error {
|
||||
invoices := tx.Bucket(invoiceBucket)
|
||||
if invoices == nil {
|
||||
return ErrNoInvoicesCreated
|
||||
@@ -360,7 +360,7 @@ func (d *DB) LookupInvoice(paymentHash [32]byte) (Invoice, error) {
|
||||
func (d *DB) FetchAllInvoices(pendingOnly bool) ([]Invoice, error) {
|
||||
var invoices []Invoice
|
||||
|
||||
err := d.View(func(tx *bolt.Tx) error {
|
||||
err := d.View(func(tx *bbolt.Tx) error {
|
||||
invoiceB := tx.Bucket(invoiceBucket)
|
||||
if invoiceB == nil {
|
||||
return ErrNoInvoicesCreated
|
||||
@@ -449,7 +449,7 @@ func (d *DB) QueryInvoices(q InvoiceQuery) (InvoiceSlice, error) {
|
||||
InvoiceQuery: q,
|
||||
}
|
||||
|
||||
err := d.View(func(tx *bolt.Tx) error {
|
||||
err := d.View(func(tx *bbolt.Tx) error {
|
||||
// If the bucket wasn't found, then there aren't any invoices
|
||||
// within the database yet, so we can simply exit.
|
||||
invoices := tx.Bucket(invoiceBucket)
|
||||
@@ -463,7 +463,7 @@ func (d *DB) QueryInvoices(q InvoiceQuery) (InvoiceSlice, error) {
|
||||
|
||||
// keyForIndex is a helper closure that retrieves the invoice
|
||||
// key for the given add index of an invoice.
|
||||
keyForIndex := func(c *bolt.Cursor, index uint64) []byte {
|
||||
keyForIndex := func(c *bbolt.Cursor, index uint64) []byte {
|
||||
var keyIndex [8]byte
|
||||
byteOrder.PutUint64(keyIndex[:], index)
|
||||
_, invoiceKey := c.Seek(keyIndex[:])
|
||||
@@ -472,7 +472,7 @@ func (d *DB) QueryInvoices(q InvoiceQuery) (InvoiceSlice, error) {
|
||||
|
||||
// nextKey is a helper closure to determine what the next
|
||||
// invoice key is when iterating over the invoice add index.
|
||||
nextKey := func(c *bolt.Cursor) ([]byte, []byte) {
|
||||
nextKey := func(c *bbolt.Cursor) ([]byte, []byte) {
|
||||
if q.Reversed {
|
||||
return c.Prev()
|
||||
}
|
||||
@@ -573,7 +573,7 @@ func (d *DB) SettleInvoice(paymentHash [32]byte,
|
||||
amtPaid lnwire.MilliSatoshi) (*Invoice, error) {
|
||||
|
||||
var settledInvoice *Invoice
|
||||
err := d.Update(func(tx *bolt.Tx) error {
|
||||
err := d.Update(func(tx *bbolt.Tx) error {
|
||||
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -634,7 +634,7 @@ func (d *DB) InvoicesSettledSince(sinceSettleIndex uint64) ([]Invoice, error) {
|
||||
var startIndex [8]byte
|
||||
byteOrder.PutUint64(startIndex[:], sinceSettleIndex)
|
||||
|
||||
err := d.DB.View(func(tx *bolt.Tx) error {
|
||||
err := d.DB.View(func(tx *bbolt.Tx) error {
|
||||
invoices := tx.Bucket(invoiceBucket)
|
||||
if invoices == nil {
|
||||
return ErrNoInvoicesCreated
|
||||
@@ -676,7 +676,7 @@ func (d *DB) InvoicesSettledSince(sinceSettleIndex uint64) ([]Invoice, error) {
|
||||
return settledInvoices, nil
|
||||
}
|
||||
|
||||
func putInvoice(invoices, invoiceIndex, addIndex *bolt.Bucket,
|
||||
func putInvoice(invoices, invoiceIndex, addIndex *bbolt.Bucket,
|
||||
i *Invoice, invoiceNum uint32) (uint64, error) {
|
||||
|
||||
// Create the invoice key which is just the big-endian representation
|
||||
@@ -790,7 +790,7 @@ func serializeInvoice(w io.Writer, i *Invoice) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func fetchInvoice(invoiceNum []byte, invoices *bolt.Bucket) (Invoice, error) {
|
||||
func fetchInvoice(invoiceNum []byte, invoices *bbolt.Bucket) (Invoice, error) {
|
||||
invoiceBytes := invoices.Get(invoiceNum)
|
||||
if invoiceBytes == nil {
|
||||
return Invoice{}, ErrInvoiceNotFound
|
||||
@@ -862,7 +862,7 @@ func deserializeInvoice(r io.Reader) (Invoice, error) {
|
||||
return invoice, nil
|
||||
}
|
||||
|
||||
func settleInvoice(invoices, settleIndex *bolt.Bucket, invoiceNum []byte,
|
||||
func settleInvoice(invoices, settleIndex *bbolt.Bucket, invoiceNum []byte,
|
||||
amtPaid lnwire.MilliSatoshi) (*Invoice, error) {
|
||||
|
||||
invoice, err := fetchInvoice(invoiceNum, invoices)
|
||||
|
||||
+7
-9
@@ -1,8 +1,6 @@
|
||||
package channeldb
|
||||
|
||||
import (
|
||||
"github.com/coreos/bbolt"
|
||||
)
|
||||
import "github.com/coreos/bbolt"
|
||||
|
||||
var (
|
||||
// metaBucket stores all the meta information concerning the state of
|
||||
@@ -22,10 +20,10 @@ type Meta struct {
|
||||
|
||||
// FetchMeta fetches the meta data from boltdb and returns filled meta
|
||||
// structure.
|
||||
func (d *DB) FetchMeta(tx *bolt.Tx) (*Meta, error) {
|
||||
func (d *DB) FetchMeta(tx *bbolt.Tx) (*Meta, error) {
|
||||
meta := &Meta{}
|
||||
|
||||
err := d.View(func(tx *bolt.Tx) error {
|
||||
err := d.View(func(tx *bbolt.Tx) error {
|
||||
return fetchMeta(meta, tx)
|
||||
})
|
||||
if err != nil {
|
||||
@@ -38,7 +36,7 @@ func (d *DB) FetchMeta(tx *bolt.Tx) (*Meta, error) {
|
||||
// fetchMeta is an internal helper function used in order to allow callers to
|
||||
// re-use a database transaction. See the publicly exported FetchMeta method
|
||||
// for more information.
|
||||
func fetchMeta(meta *Meta, tx *bolt.Tx) error {
|
||||
func fetchMeta(meta *Meta, tx *bbolt.Tx) error {
|
||||
metaBucket := tx.Bucket(metaBucket)
|
||||
if metaBucket == nil {
|
||||
return ErrMetaNotFound
|
||||
@@ -56,7 +54,7 @@ func fetchMeta(meta *Meta, tx *bolt.Tx) error {
|
||||
|
||||
// PutMeta writes the passed instance of the database met-data struct to disk.
|
||||
func (d *DB) PutMeta(meta *Meta) error {
|
||||
return d.Update(func(tx *bolt.Tx) error {
|
||||
return d.Update(func(tx *bbolt.Tx) error {
|
||||
return putMeta(meta, tx)
|
||||
})
|
||||
}
|
||||
@@ -64,7 +62,7 @@ func (d *DB) PutMeta(meta *Meta) error {
|
||||
// putMeta is an internal helper function used in order to allow callers to
|
||||
// re-use a database transaction. See the publicly exported PutMeta method for
|
||||
// more information.
|
||||
func putMeta(meta *Meta, tx *bolt.Tx) error {
|
||||
func putMeta(meta *Meta, tx *bbolt.Tx) error {
|
||||
metaBucket, err := tx.CreateBucketIfNotExists(metaBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -73,7 +71,7 @@ func putMeta(meta *Meta, tx *bolt.Tx) error {
|
||||
return putDbVersion(metaBucket, meta)
|
||||
}
|
||||
|
||||
func putDbVersion(metaBucket *bolt.Bucket, meta *Meta) error {
|
||||
func putDbVersion(metaBucket *bbolt.Bucket, meta *Meta) error {
|
||||
scratch := make([]byte, 4)
|
||||
byteOrder.PutUint32(scratch, meta.DbVersionNumber)
|
||||
return metaBucket.Put(dbVersionKey, scratch)
|
||||
|
||||
+12
-12
@@ -108,11 +108,11 @@ func TestOrderOfMigrations(t *testing.T) {
|
||||
versions := []version{
|
||||
{0, nil},
|
||||
{1, nil},
|
||||
{2, func(tx *bolt.Tx) error {
|
||||
{2, func(tx *bbolt.Tx) error {
|
||||
appliedMigration = 2
|
||||
return nil
|
||||
}},
|
||||
{3, func(tx *bolt.Tx) error {
|
||||
{3, func(tx *bbolt.Tx) error {
|
||||
appliedMigration = 3
|
||||
return nil
|
||||
}},
|
||||
@@ -184,7 +184,7 @@ func TestMigrationWithPanic(t *testing.T) {
|
||||
beforeMigrationFunc := func(d *DB) {
|
||||
// Insert data in database and in order then make sure that the
|
||||
// key isn't changes in case of panic or fail.
|
||||
d.Update(func(tx *bolt.Tx) error {
|
||||
d.Update(func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -197,7 +197,7 @@ func TestMigrationWithPanic(t *testing.T) {
|
||||
|
||||
// Create migration function which changes the initially created data and
|
||||
// throw the panic, in this case we pretending that something goes.
|
||||
migrationWithPanic := func(tx *bolt.Tx) error {
|
||||
migrationWithPanic := func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -218,7 +218,7 @@ func TestMigrationWithPanic(t *testing.T) {
|
||||
t.Fatal("migration panicked but version is changed")
|
||||
}
|
||||
|
||||
err = d.Update(func(tx *bolt.Tx) error {
|
||||
err = d.Update(func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -255,7 +255,7 @@ func TestMigrationWithFatal(t *testing.T) {
|
||||
afterMigration := []byte("aftermigration")
|
||||
|
||||
beforeMigrationFunc := func(d *DB) {
|
||||
d.Update(func(tx *bolt.Tx) error {
|
||||
d.Update(func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -269,7 +269,7 @@ func TestMigrationWithFatal(t *testing.T) {
|
||||
// Create migration function which changes the initially created data and
|
||||
// return the error, in this case we pretending that something goes
|
||||
// wrong.
|
||||
migrationWithFatal := func(tx *bolt.Tx) error {
|
||||
migrationWithFatal := func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -290,7 +290,7 @@ func TestMigrationWithFatal(t *testing.T) {
|
||||
t.Fatal("migration failed but version is changed")
|
||||
}
|
||||
|
||||
err = d.Update(func(tx *bolt.Tx) error {
|
||||
err = d.Update(func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -328,7 +328,7 @@ func TestMigrationWithoutErrors(t *testing.T) {
|
||||
|
||||
// Populate database with initial data.
|
||||
beforeMigrationFunc := func(d *DB) {
|
||||
d.Update(func(tx *bolt.Tx) error {
|
||||
d.Update(func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -340,7 +340,7 @@ func TestMigrationWithoutErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create migration function which changes the initially created data.
|
||||
migrationWithoutErrors := func(tx *bolt.Tx) error {
|
||||
migrationWithoutErrors := func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -362,7 +362,7 @@ func TestMigrationWithoutErrors(t *testing.T) {
|
||||
"successfully applied migration")
|
||||
}
|
||||
|
||||
err = d.Update(func(tx *bolt.Tx) error {
|
||||
err = d.Update(func(tx *bbolt.Tx) error {
|
||||
bucket, err := tx.CreateBucketIfNotExists(bucketPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -406,7 +406,7 @@ func TestMigrationReversion(t *testing.T) {
|
||||
|
||||
// Update the database metadata to point to one more than the highest
|
||||
// known version.
|
||||
err = cdb.Update(func(tx *bolt.Tx) error {
|
||||
err = cdb.Update(func(tx *bbolt.Tx) error {
|
||||
newMeta := &Meta{
|
||||
DbVersionNumber: getLatestDBVersion(dbVersions) + 1,
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
// (one for nodes and one for edges) to keep track of the last time a node or
|
||||
// edge was updated on the network. These new indexes allow us to implement the
|
||||
// new graph sync protocol added.
|
||||
func migrateNodeAndEdgeUpdateIndex(tx *bolt.Tx) error {
|
||||
func migrateNodeAndEdgeUpdateIndex(tx *bbolt.Tx) error {
|
||||
// First, we'll populating the node portion of the new index. Before we
|
||||
// can add new values to the index, we'll first create the new bucket
|
||||
// where these items will be housed.
|
||||
@@ -119,7 +119,7 @@ func migrateNodeAndEdgeUpdateIndex(tx *bolt.Tx) error {
|
||||
// invoices an index in the add and/or the settle index. Additionally, all
|
||||
// existing invoices will have their bytes padded out in order to encode the
|
||||
// add+settle index as well as the amount paid.
|
||||
func migrateInvoiceTimeSeries(tx *bolt.Tx) error {
|
||||
func migrateInvoiceTimeSeries(tx *bbolt.Tx) error {
|
||||
invoices, err := tx.CreateBucketIfNotExists(invoiceBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -238,7 +238,7 @@ func migrateInvoiceTimeSeries(tx *bolt.Tx) error {
|
||||
// migrateInvoiceTimeSeries migration. As at the time of writing, the
|
||||
// OutgoingPayment struct embeddeds an instance of the Invoice struct. As a
|
||||
// result, we also need to migrate the internal invoice to the new format.
|
||||
func migrateInvoiceTimeSeriesOutgoingPayments(tx *bolt.Tx) error {
|
||||
func migrateInvoiceTimeSeriesOutgoingPayments(tx *bbolt.Tx) error {
|
||||
payBucket := tx.Bucket(paymentBucket)
|
||||
if payBucket == nil {
|
||||
return nil
|
||||
@@ -307,7 +307,7 @@ func migrateInvoiceTimeSeriesOutgoingPayments(tx *bolt.Tx) error {
|
||||
// bucket. It ensure that edges with unknown policies will also have an entry
|
||||
// in the bucket. After the migration, there will be two edge entries for
|
||||
// every channel, regardless of whether the policies are known.
|
||||
func migrateEdgePolicies(tx *bolt.Tx) error {
|
||||
func migrateEdgePolicies(tx *bbolt.Tx) error {
|
||||
nodes := tx.Bucket(nodeBucket)
|
||||
if nodes == nil {
|
||||
return nil
|
||||
@@ -379,7 +379,7 @@ func migrateEdgePolicies(tx *bolt.Tx) error {
|
||||
// paymentStatusesMigration is a database migration intended for adding payment
|
||||
// statuses for each existing payment entity in bucket to be able control
|
||||
// transitions of statuses and prevent cases such as double payment
|
||||
func paymentStatusesMigration(tx *bolt.Tx) error {
|
||||
func paymentStatusesMigration(tx *bbolt.Tx) error {
|
||||
// Get the bucket dedicated to storing statuses of payments,
|
||||
// where a key is payment hash, value is payment status.
|
||||
paymentStatuses, err := tx.CreateBucketIfNotExists(paymentStatusBucket)
|
||||
@@ -466,7 +466,7 @@ func paymentStatusesMigration(tx *bolt.Tx) error {
|
||||
// migration also fixes the case where the public keys within edge policies were
|
||||
// being serialized with an extra byte, causing an even greater error when
|
||||
// attempting to perform the offset calculation described earlier.
|
||||
func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
|
||||
func migratePruneEdgeUpdateIndex(tx *bbolt.Tx) error {
|
||||
// To begin the migration, we'll retrieve the update index bucket. If it
|
||||
// does not exist, we have nothing left to do so we can simply exit.
|
||||
edges := tx.Bucket(edgeBucket)
|
||||
@@ -577,7 +577,7 @@ func migratePruneEdgeUpdateIndex(tx *bolt.Tx) error {
|
||||
// migrateOptionalChannelCloseSummaryFields migrates the serialized format of
|
||||
// ChannelCloseSummary to a format where optional fields' presence is indicated
|
||||
// with boolean markers.
|
||||
func migrateOptionalChannelCloseSummaryFields(tx *bolt.Tx) error {
|
||||
func migrateOptionalChannelCloseSummaryFields(tx *bbolt.Tx) error {
|
||||
closedChanBucket := tx.Bucket(closedChannelBucket)
|
||||
if closedChanBucket == nil {
|
||||
return nil
|
||||
|
||||
@@ -55,7 +55,7 @@ func TestPaymentStatusesMigration(t *testing.T) {
|
||||
// locally-sourced payment should end up with an InFlight
|
||||
// status, while the other should remain unchanged, which
|
||||
// defaults to Grounded.
|
||||
err = d.Update(func(tx *bolt.Tx) error {
|
||||
err = d.Update(func(tx *bbolt.Tx) error {
|
||||
circuits, err := tx.CreateBucketIfNotExists(
|
||||
[]byte("circuit-adds"),
|
||||
)
|
||||
@@ -382,7 +382,7 @@ func TestMigrateOptionalChannelCloseSummaryFields(t *testing.T) {
|
||||
// Get the old serialization format for this test's
|
||||
// close summary, and it to the closed channel bucket.
|
||||
old := test.oldSerialization(test.closeSummary)
|
||||
err = d.Update(func(tx *bolt.Tx) error {
|
||||
err = d.Update(func(tx *bbolt.Tx) error {
|
||||
closedChanBucket, err := tx.CreateBucketIfNotExists(
|
||||
closedChannelBucket,
|
||||
)
|
||||
@@ -418,7 +418,7 @@ func TestMigrateOptionalChannelCloseSummaryFields(t *testing.T) {
|
||||
newSerialization := b.Bytes()
|
||||
|
||||
var dbSummary []byte
|
||||
err = d.View(func(tx *bolt.Tx) error {
|
||||
err = d.View(func(tx *bbolt.Tx) error {
|
||||
closedChanBucket := tx.Bucket(closedChannelBucket)
|
||||
if closedChanBucket == nil {
|
||||
return errors.New("unable to find bucket")
|
||||
|
||||
+7
-7
@@ -101,7 +101,7 @@ func (l *LinkNode) Sync() error {
|
||||
|
||||
// Finally update the database by storing the link node and updating
|
||||
// any relevant indexes.
|
||||
return l.db.Update(func(tx *bolt.Tx) error {
|
||||
return l.db.Update(func(tx *bbolt.Tx) error {
|
||||
nodeMetaBucket := tx.Bucket(nodeInfoBucket)
|
||||
if nodeMetaBucket == nil {
|
||||
return ErrLinkNodesNotFound
|
||||
@@ -114,7 +114,7 @@ func (l *LinkNode) Sync() error {
|
||||
// putLinkNode serializes then writes the encoded version of the passed link
|
||||
// node into the nodeMetaBucket. This function is provided in order to allow
|
||||
// the ability to re-use a database transaction across many operations.
|
||||
func putLinkNode(nodeMetaBucket *bolt.Bucket, l *LinkNode) error {
|
||||
func putLinkNode(nodeMetaBucket *bbolt.Bucket, l *LinkNode) error {
|
||||
// First serialize the LinkNode into its raw-bytes encoding.
|
||||
var b bytes.Buffer
|
||||
if err := serializeLinkNode(&b, l); err != nil {
|
||||
@@ -130,12 +130,12 @@ func putLinkNode(nodeMetaBucket *bolt.Bucket, l *LinkNode) error {
|
||||
// DeleteLinkNode removes the link node with the given identity from the
|
||||
// database.
|
||||
func (db *DB) DeleteLinkNode(identity *btcec.PublicKey) error {
|
||||
return db.Update(func(tx *bolt.Tx) error {
|
||||
return db.Update(func(tx *bbolt.Tx) error {
|
||||
return db.deleteLinkNode(tx, identity)
|
||||
})
|
||||
}
|
||||
|
||||
func (db *DB) deleteLinkNode(tx *bolt.Tx, identity *btcec.PublicKey) error {
|
||||
func (db *DB) deleteLinkNode(tx *bbolt.Tx, identity *btcec.PublicKey) error {
|
||||
nodeMetaBucket := tx.Bucket(nodeInfoBucket)
|
||||
if nodeMetaBucket == nil {
|
||||
return ErrLinkNodesNotFound
|
||||
@@ -154,7 +154,7 @@ func (db *DB) FetchLinkNode(identity *btcec.PublicKey) (*LinkNode, error) {
|
||||
err error
|
||||
)
|
||||
|
||||
err = db.View(func(tx *bolt.Tx) error {
|
||||
err = db.View(func(tx *bbolt.Tx) error {
|
||||
// First fetch the bucket for storing node metadata, bailing
|
||||
// out early if it hasn't been created yet.
|
||||
nodeMetaBucket := tx.Bucket(nodeInfoBucket)
|
||||
@@ -187,7 +187,7 @@ func (db *DB) FetchLinkNode(identity *btcec.PublicKey) (*LinkNode, error) {
|
||||
// whom we have active channels with.
|
||||
func (db *DB) FetchAllLinkNodes() ([]*LinkNode, error) {
|
||||
var linkNodes []*LinkNode
|
||||
err := db.View(func(tx *bolt.Tx) error {
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
nodes, err := db.fetchAllLinkNodes(tx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -205,7 +205,7 @@ func (db *DB) FetchAllLinkNodes() ([]*LinkNode, error) {
|
||||
|
||||
// fetchAllLinkNodes uses an existing database transaction to fetch all nodes
|
||||
// with whom we have active channels with.
|
||||
func (db *DB) fetchAllLinkNodes(tx *bolt.Tx) ([]*LinkNode, error) {
|
||||
func (db *DB) fetchAllLinkNodes(tx *bbolt.Tx) ([]*LinkNode, error) {
|
||||
nodeMetaBucket := tx.Bucket(nodeInfoBucket)
|
||||
if nodeMetaBucket == nil {
|
||||
return nil, ErrLinkNodesNotFound
|
||||
|
||||
@@ -118,7 +118,7 @@ func (db *DB) AddPayment(payment *OutgoingPayment) error {
|
||||
}
|
||||
paymentBytes := b.Bytes()
|
||||
|
||||
return db.Batch(func(tx *bolt.Tx) error {
|
||||
return db.Batch(func(tx *bbolt.Tx) error {
|
||||
payments, err := tx.CreateBucketIfNotExists(paymentBucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -144,7 +144,7 @@ func (db *DB) AddPayment(payment *OutgoingPayment) error {
|
||||
func (db *DB) FetchAllPayments() ([]*OutgoingPayment, error) {
|
||||
var payments []*OutgoingPayment
|
||||
|
||||
err := db.View(func(tx *bolt.Tx) error {
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
bucket := tx.Bucket(paymentBucket)
|
||||
if bucket == nil {
|
||||
return ErrNoPaymentsCreated
|
||||
@@ -176,9 +176,9 @@ func (db *DB) FetchAllPayments() ([]*OutgoingPayment, error) {
|
||||
|
||||
// DeleteAllPayments deletes all payments from DB.
|
||||
func (db *DB) DeleteAllPayments() error {
|
||||
return db.Update(func(tx *bolt.Tx) error {
|
||||
return db.Update(func(tx *bbolt.Tx) error {
|
||||
err := tx.DeleteBucket(paymentBucket)
|
||||
if err != nil && err != bolt.ErrBucketNotFound {
|
||||
if err != nil && err != bbolt.ErrBucketNotFound {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ func (db *DB) DeleteAllPayments() error {
|
||||
// UpdatePaymentStatus sets the payment status for outgoing/finished payments in
|
||||
// local database.
|
||||
func (db *DB) UpdatePaymentStatus(paymentHash [32]byte, status PaymentStatus) error {
|
||||
return db.Batch(func(tx *bolt.Tx) error {
|
||||
return db.Batch(func(tx *bbolt.Tx) error {
|
||||
return UpdatePaymentStatusTx(tx, paymentHash, status)
|
||||
})
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func (db *DB) UpdatePaymentStatus(paymentHash [32]byte, status PaymentStatus) er
|
||||
// outgoing/finished payments in the local database. This method accepts a
|
||||
// boltdb transaction such that the operation can be composed into other
|
||||
// database transactions.
|
||||
func UpdatePaymentStatusTx(tx *bolt.Tx,
|
||||
func UpdatePaymentStatusTx(tx *bbolt.Tx,
|
||||
paymentHash [32]byte, status PaymentStatus) error {
|
||||
|
||||
paymentStatuses, err := tx.CreateBucketIfNotExists(paymentStatusBucket)
|
||||
@@ -214,7 +214,7 @@ func UpdatePaymentStatusTx(tx *bolt.Tx,
|
||||
// If status of the payment isn't found, it will default to "StatusGrounded".
|
||||
func (db *DB) FetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) {
|
||||
var paymentStatus = StatusGrounded
|
||||
err := db.View(func(tx *bolt.Tx) error {
|
||||
err := db.View(func(tx *bbolt.Tx) error {
|
||||
var err error
|
||||
paymentStatus, err = FetchPaymentStatusTx(tx, paymentHash)
|
||||
return err
|
||||
@@ -230,7 +230,7 @@ func (db *DB) FetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) {
|
||||
// outgoing payment. If status of the payment isn't found, it will default to
|
||||
// "StatusGrounded". It accepts the boltdb transactions such that this method
|
||||
// can be composed into other atomic operations.
|
||||
func FetchPaymentStatusTx(tx *bolt.Tx, paymentHash [32]byte) (PaymentStatus, error) {
|
||||
func FetchPaymentStatusTx(tx *bbolt.Tx, paymentHash [32]byte) (PaymentStatus, error) {
|
||||
// The default status for all payments that aren't recorded in database.
|
||||
var paymentStatus = StatusGrounded
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ func (s *WaitingProofStore) Add(proof *WaitingProof) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
err := s.db.Update(func(tx *bolt.Tx) error {
|
||||
err := s.db.Update(func(tx *bbolt.Tx) error {
|
||||
var err error
|
||||
var b bytes.Buffer
|
||||
|
||||
@@ -100,7 +100,7 @@ func (s *WaitingProofStore) Remove(key WaitingProofKey) error {
|
||||
return ErrWaitingProofNotFound
|
||||
}
|
||||
|
||||
err := s.db.Update(func(tx *bolt.Tx) error {
|
||||
err := s.db.Update(func(tx *bbolt.Tx) error {
|
||||
// Get or create the top bucket.
|
||||
bucket := tx.Bucket(waitingProofsBucketKey)
|
||||
if bucket == nil {
|
||||
@@ -123,7 +123,7 @@ func (s *WaitingProofStore) Remove(key WaitingProofKey) error {
|
||||
// ForAll iterates thought all waiting proofs and passing the waiting proof
|
||||
// in the given callback.
|
||||
func (s *WaitingProofStore) ForAll(cb func(*WaitingProof) error) error {
|
||||
return s.db.View(func(tx *bolt.Tx) error {
|
||||
return s.db.View(func(tx *bbolt.Tx) error {
|
||||
bucket := tx.Bucket(waitingProofsBucketKey)
|
||||
if bucket == nil {
|
||||
return ErrWaitingProofNotFound
|
||||
@@ -158,7 +158,7 @@ func (s *WaitingProofStore) Get(key WaitingProofKey) (*WaitingProof, error) {
|
||||
return nil, ErrWaitingProofNotFound
|
||||
}
|
||||
|
||||
err := s.db.View(func(tx *bolt.Tx) error {
|
||||
err := s.db.View(func(tx *bbolt.Tx) error {
|
||||
bucket := tx.Bucket(waitingProofsBucketKey)
|
||||
if bucket == nil {
|
||||
return ErrWaitingProofNotFound
|
||||
|
||||
@@ -76,7 +76,7 @@ func (d *DB) NewWitnessCache() *WitnessCache {
|
||||
//
|
||||
// TODO(roasbeef): fake closure to map instead a constructor?
|
||||
func (w *WitnessCache) AddWitness(wType WitnessType, witness []byte) error {
|
||||
return w.db.Batch(func(tx *bolt.Tx) error {
|
||||
return w.db.Batch(func(tx *bbolt.Tx) error {
|
||||
witnessBucket, err := tx.CreateBucketIfNotExists(witnessBucketKey)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -111,7 +111,7 @@ func (w *WitnessCache) AddWitness(wType WitnessType, witness []byte) error {
|
||||
// will be returned.
|
||||
func (w *WitnessCache) LookupWitness(wType WitnessType, witnessKey []byte) ([]byte, error) {
|
||||
var witness []byte
|
||||
err := w.db.View(func(tx *bolt.Tx) error {
|
||||
err := w.db.View(func(tx *bbolt.Tx) error {
|
||||
witnessBucket := tx.Bucket(witnessBucketKey)
|
||||
if witnessBucket == nil {
|
||||
return ErrNoWitnesses
|
||||
@@ -145,7 +145,7 @@ func (w *WitnessCache) LookupWitness(wType WitnessType, witnessKey []byte) ([]by
|
||||
|
||||
// DeleteWitness attempts to delete a particular witness from the database.
|
||||
func (w *WitnessCache) DeleteWitness(wType WitnessType, witnessKey []byte) error {
|
||||
return w.db.Batch(func(tx *bolt.Tx) error {
|
||||
return w.db.Batch(func(tx *bbolt.Tx) error {
|
||||
witnessBucket, err := tx.CreateBucketIfNotExists(witnessBucketKey)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -169,7 +169,7 @@ func (w *WitnessCache) DeleteWitness(wType WitnessType, witnessKey []byte) error
|
||||
// DeleteWitnessClass attempts to delete an *entire* class of witnesses. After
|
||||
// this function return with a non-nil error,
|
||||
func (w *WitnessCache) DeleteWitnessClass(wType WitnessType) error {
|
||||
return w.db.Batch(func(tx *bolt.Tx) error {
|
||||
return w.db.Batch(func(tx *bbolt.Tx) error {
|
||||
witnessBucket, err := tx.CreateBucketIfNotExists(witnessBucketKey)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user