diff --git a/autopilot/graph.go b/autopilot/graph.go index 766919ac..6ef6d61d 100644 --- a/autopilot/graph.go +++ b/autopilot/graph.go @@ -51,7 +51,7 @@ func ChannelGraphFromDatabase(db *channeldb.ChannelGraph) ChannelGraph { // channeldb.LightningNode. The wrapper method implement the autopilot.Node // interface. type dbNode struct { - tx kvdb.ReadTx + tx kvdb.RTx node *channeldb.LightningNode } @@ -84,7 +84,7 @@ func (d dbNode) Addrs() []net.Addr { // // NOTE: Part of the autopilot.Node interface. func (d dbNode) ForEachChannel(cb func(ChannelEdge) error) error { - return d.node.ForEachChannel(d.tx, func(tx kvdb.ReadTx, + return d.node.ForEachChannel(d.tx, func(tx kvdb.RTx, ei *channeldb.ChannelEdgeInfo, ep, _ *channeldb.ChannelEdgePolicy) error { // Skip channels for which no outgoing edge policy is available. @@ -121,8 +121,7 @@ func (d dbNode) ForEachChannel(cb func(ChannelEdge) error) error { // // NOTE: Part of the autopilot.ChannelGraph interface. func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error { - return d.db.ForEachNode(func(tx kvdb.ReadTx, n *channeldb.LightningNode) error { - + return d.db.ForEachNode(func(tx kvdb.RTx, n *channeldb.LightningNode) error { // We'll skip over any node that doesn't have any advertised // addresses. As we won't be able to reach them to actually // open any channels. diff --git a/breacharbiter.go b/breacharbiter.go index cebbe1cd..6924682f 100644 --- a/breacharbiter.go +++ b/breacharbiter.go @@ -1291,7 +1291,7 @@ func (rs *retributionStore) GetFinalizedTxn( chanPoint *wire.OutPoint) (*wire.MsgTx, error) { var finalTxBytes []byte - if err := kvdb.View(rs.db, func(tx kvdb.ReadTx) error { + if err := kvdb.View(rs.db, func(tx kvdb.RTx) error { justiceBkt := tx.ReadBucket(justiceTxnBucket) if justiceBkt == nil { return nil @@ -1325,7 +1325,7 @@ func (rs *retributionStore) GetFinalizedTxn( // that has already been breached. func (rs *retributionStore) IsBreached(chanPoint *wire.OutPoint) (bool, error) { var found bool - err := kvdb.View(rs.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(rs.db, func(tx kvdb.RTx) error { retBucket := tx.ReadBucket(retributionBucket) if retBucket == nil { return nil @@ -1389,7 +1389,7 @@ func (rs *retributionStore) Remove(chanPoint *wire.OutPoint) error { // ForAll iterates through all stored retributions and executes the passed // callback function on each retribution. func (rs *retributionStore) ForAll(cb func(*retributionInfo) error) error { - return kvdb.View(rs.db, func(tx kvdb.ReadTx) error { + return kvdb.View(rs.db, func(tx kvdb.RTx) error { // If the bucket does not exist, then there are no pending // retributions. retBucket := tx.ReadBucket(retributionBucket) diff --git a/chainntnfs/height_hint_cache.go b/chainntnfs/height_hint_cache.go index b80d3ea7..318b627b 100644 --- a/chainntnfs/height_hint_cache.go +++ b/chainntnfs/height_hint_cache.go @@ -148,7 +148,7 @@ func (c *HeightHintCache) CommitSpendHint(height uint32, // cache for the outpoint. func (c *HeightHintCache) QuerySpendHint(spendRequest SpendRequest) (uint32, error) { var hint uint32 - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { spendHints := tx.ReadBucket(spendHintBucket) if spendHints == nil { return ErrCorruptedHeightHintCache @@ -242,7 +242,7 @@ func (c *HeightHintCache) CommitConfirmHint(height uint32, // the cache for the transaction hash. func (c *HeightHintCache) QueryConfirmHint(confRequest ConfRequest) (uint32, error) { var hint uint32 - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { confirmHints := tx.ReadBucket(confirmHintBucket) if confirmHints == nil { return ErrCorruptedHeightHintCache diff --git a/channeldb/channel.go b/channeldb/channel.go index 2031b7b3..8b0b2bff 100644 --- a/channeldb/channel.go +++ b/channeldb/channel.go @@ -729,7 +729,7 @@ func (c *OpenChannel) RefreshShortChanID() error { c.Lock() defer c.Unlock() - err := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -755,8 +755,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 kvdb.ReadTx, nodeKey *btcec.PublicKey, - outPoint *wire.OutPoint, chainHash chainhash.Hash) (kvdb.ReadBucket, error) { +func fetchChanBucket(tx kvdb.RTx, nodeKey *btcec.PublicKey, + outPoint *wire.OutPoint, chainHash chainhash.Hash) (kvdb.RBucket, error) { // First fetch the top level bucket which stores all data related to // current, active channels. @@ -916,7 +916,7 @@ func (c *OpenChannel) MarkDataLoss(commitPoint *btcec.PublicKey) error { func (c *OpenChannel) DataLossCommitPoint() (*btcec.PublicKey, error) { var commitPoint *btcec.PublicKey - err := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -1045,7 +1045,7 @@ func (c *OpenChannel) ChanSyncMsg() (*lnwire.ChannelReestablish, error) { // active. // // NOTE: The primary mutex should already be held before this method is called. -func (c *OpenChannel) isBorked(chanBucket kvdb.ReadBucket) (bool, error) { +func (c *OpenChannel) isBorked(chanBucket kvdb.RBucket) (bool, error) { channel, err := fetchOpenChannel(chanBucket, &c.FundingOutpoint) if err != nil { return false, err @@ -1138,7 +1138,7 @@ func (c *OpenChannel) BroadcastedCooperative() (*wire.MsgTx, error) { func (c *OpenChannel) getClosingTx(key []byte) (*wire.MsgTx, error) { var closeTx *wire.MsgTx - err := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -1279,7 +1279,7 @@ func putOpenChannel(chanBucket kvdb.RwBucket, channel *OpenChannel) error { // fetchOpenChannel retrieves, and deserializes (including decrypting // sensitive) the complete channel currently active with the passed nodeID. -func fetchOpenChannel(chanBucket kvdb.ReadBucket, +func fetchOpenChannel(chanBucket kvdb.RBucket, chanPoint *wire.OutPoint) (*OpenChannel, error) { channel := &OpenChannel{ @@ -2000,7 +2000,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 := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -2037,7 +2037,7 @@ func (c *OpenChannel) RemoteCommitChainTip() (*CommitDiff, error) { // updates that still need to be signed for. func (c *OpenChannel) UnsignedAckedUpdates() ([]LogUpdate, error) { var updates []LogUpdate - err := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -2235,7 +2235,7 @@ func (c *OpenChannel) LoadFwdPkgs() ([]*FwdPkg, error) { defer c.RUnlock() var fwdPkgs []*FwdPkg - if err := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + if err := kvdb.View(c.Db, func(tx kvdb.RTx) error { var err error fwdPkgs, err = c.Packager.LoadFwdPkgs(tx) return err @@ -2311,7 +2311,7 @@ func (c *OpenChannel) RevocationLogTail() (*ChannelCommitment, error) { } var commit ChannelCommitment - if err := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + if err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -2358,7 +2358,7 @@ func (c *OpenChannel) CommitmentHeight() (uint64, error) { defer c.RUnlock() var height uint64 - err := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { // Get the bucket dedicated to storing the metadata for open // channels. chanBucket, err := fetchChanBucket( @@ -2393,7 +2393,7 @@ func (c *OpenChannel) FindPreviousState(updateNum uint64) (*ChannelCommitment, e defer c.RUnlock() var commit ChannelCommitment - err := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -2727,7 +2727,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 := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -2749,7 +2749,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 := kvdb.View(c.Db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.Db, func(tx kvdb.RTx) error { chanBucket, err := fetchChanBucket( tx, c.IdentityPub, &c.FundingOutpoint, c.ChainHash, ) @@ -3010,7 +3010,7 @@ func putOptionalUpfrontShutdownScript(chanBucket kvdb.RwBucket, key []byte, // getOptionalUpfrontShutdownScript reads the shutdown script stored under the // key provided if it is present. Upfront shutdown scripts are optional, so the // function returns with no error if the key is not present. -func getOptionalUpfrontShutdownScript(chanBucket kvdb.ReadBucket, key []byte, +func getOptionalUpfrontShutdownScript(chanBucket kvdb.RBucket, key []byte, script *lnwire.DeliveryAddress) error { // Return early if the bucket does not exit, a shutdown script was not set. @@ -3114,7 +3114,7 @@ func readChanConfig(b io.Reader, c *ChannelConfig) error { ) } -func fetchChanInfo(chanBucket kvdb.ReadBucket, channel *OpenChannel) error { +func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error { infoBytes := chanBucket.Get(chanInfoKey) if infoBytes == nil { return ErrNoChanInfoFound @@ -3181,7 +3181,7 @@ func deserializeChanCommit(r io.Reader) (ChannelCommitment, error) { return c, nil } -func fetchChanCommitment(chanBucket kvdb.ReadBucket, local bool) (ChannelCommitment, error) { +func fetchChanCommitment(chanBucket kvdb.RBucket, local bool) (ChannelCommitment, error) { var commitKey []byte if local { commitKey = append(chanCommitmentKey, byte(0x00)) @@ -3198,7 +3198,7 @@ func fetchChanCommitment(chanBucket kvdb.ReadBucket, local bool) (ChannelCommitm return deserializeChanCommit(r) } -func fetchChanCommitments(chanBucket kvdb.ReadBucket, channel *OpenChannel) error { +func fetchChanCommitments(chanBucket kvdb.RBucket, channel *OpenChannel) error { var err error // If this is a restored channel, then we don't have any commitments to @@ -3219,7 +3219,7 @@ func fetchChanCommitments(chanBucket kvdb.ReadBucket, channel *OpenChannel) erro return nil } -func fetchChanRevocationState(chanBucket kvdb.ReadBucket, channel *OpenChannel) error { +func fetchChanRevocationState(chanBucket kvdb.RBucket, channel *OpenChannel) error { revBytes := chanBucket.Get(revocationStateKey) if revBytes == nil { return ErrNoRevocationsFound @@ -3291,7 +3291,7 @@ func appendChannelLogEntry(log kvdb.RwBucket, return log.Put(logEntrykey[:], b.Bytes()) } -func fetchChannelLogEntry(log kvdb.ReadBucket, +func fetchChannelLogEntry(log kvdb.RBucket, updateNum uint64) (ChannelCommitment, error) { logEntrykey := makeLogKey(updateNum) @@ -3304,7 +3304,7 @@ func fetchChannelLogEntry(log kvdb.ReadBucket, return deserializeChanCommit(commitReader) } -func fetchThawHeight(chanBucket kvdb.ReadBucket) (uint32, error) { +func fetchThawHeight(chanBucket kvdb.RBucket) (uint32, error) { var height uint32 heightBytes := chanBucket.Get(frozenChanKey) diff --git a/channeldb/db.go b/channeldb/db.go index b6c7daf5..a1ff4215 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -394,7 +394,7 @@ func fileExists(path string) bool { // zero-length slice is returned. func (d *DB) FetchOpenChannels(nodeID *btcec.PublicKey) ([]*OpenChannel, error) { var channels []*OpenChannel - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { var err error channels, err = d.fetchOpenChannels(tx, nodeID) return err @@ -407,7 +407,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 (db *DB) fetchOpenChannels(tx kvdb.ReadTx, +func (db *DB) fetchOpenChannels(tx kvdb.RTx, nodeID *btcec.PublicKey) ([]*OpenChannel, error) { // Get the bucket dedicated to storing the metadata for open channels. @@ -460,7 +460,7 @@ func (db *DB) fetchOpenChannels(tx kvdb.ReadTx, // 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 (db *DB) fetchNodeChannels(chainBucket kvdb.ReadBucket) ([]*OpenChannel, error) { +func (db *DB) fetchNodeChannels(chainBucket kvdb.RBucket) ([]*OpenChannel, error) { var channels []*OpenChannel @@ -519,7 +519,7 @@ func (d *DB) FetchChannel(chanPoint wire.OutPoint) (*OpenChannel, error) { // structure and skipping fully decoding each channel, we save a good // bit of CPU as we don't need to do things like decompress public // keys. - chanScan := func(tx kvdb.ReadTx) error { + chanScan := func(tx kvdb.RTx) error { // Get the bucket dedicated to storing the metadata for open // channels. openChanBucket := tx.ReadBucket(openChannelBucket) @@ -675,7 +675,7 @@ func waitingCloseFilter(waitingClose bool) fetchChannelsFilter { func fetchChannels(d *DB, filters ...fetchChannelsFilter) ([]*OpenChannel, error) { var channels []*OpenChannel - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { // Get the bucket dedicated to storing the metadata for open // channels. openChanBucket := tx.ReadBucket(openChannelBucket) @@ -767,7 +767,7 @@ func fetchChannels(d *DB, filters ...fetchChannelsFilter) ([]*OpenChannel, error func (d *DB) FetchClosedChannels(pendingOnly bool) ([]*ChannelCloseSummary, error) { var chanSummaries []*ChannelCloseSummary - if err := kvdb.View(d, func(tx kvdb.ReadTx) error { + if err := kvdb.View(d, func(tx kvdb.RTx) error { closeBucket := tx.ReadBucket(closedChannelBucket) if closeBucket == nil { return ErrNoClosedChannels @@ -805,7 +805,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 := kvdb.View(d, func(tx kvdb.ReadTx) error { + if err := kvdb.View(d, func(tx kvdb.RTx) error { closeBucket := tx.ReadBucket(closedChannelBucket) if closeBucket == nil { return ErrClosedChannelNotFound @@ -839,7 +839,7 @@ func (d *DB) FetchClosedChannelForID(cid lnwire.ChannelID) ( *ChannelCloseSummary, error) { var chanSummary *ChannelCloseSummary - if err := kvdb.View(d, func(tx kvdb.ReadTx) error { + if err := kvdb.View(d, func(tx kvdb.RTx) error { closeBucket := tx.ReadBucket(closedChannelBucket) if closeBucket == nil { return ErrClosedChannelNotFound @@ -1115,7 +1115,7 @@ func (d *DB) AddrsForNode(nodePub *btcec.PublicKey) ([]net.Addr, error) { graphNode LightningNode ) - dbErr := kvdb.View(d, func(tx kvdb.ReadTx) error { + dbErr := kvdb.View(d, func(tx kvdb.RTx) error { var err error linkNode, err = fetchLinkNode(tx, nodePub) @@ -1312,8 +1312,8 @@ func getMigrationsToApply(versions []version, version uint32) ([]migration, []ui // fetchHistoricalChanBucket returns a the channel bucket for a given outpoint // from the historical channel bucket. If the bucket does not exist, // ErrNoHistoricalBucket is returned. -func fetchHistoricalChanBucket(tx kvdb.ReadTx, - outPoint *wire.OutPoint) (kvdb.ReadBucket, error) { +func fetchHistoricalChanBucket(tx kvdb.RTx, + outPoint *wire.OutPoint) (kvdb.RBucket, error) { // First fetch the top level bucket which stores all data related to // historically stored channels. @@ -1340,7 +1340,7 @@ func fetchHistoricalChanBucket(tx kvdb.ReadTx, // bucket. func (db *DB) FetchHistoricalChannel(outPoint *wire.OutPoint) (*OpenChannel, error) { var channel *OpenChannel - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { chanBucket, err := fetchHistoricalChanBucket(tx, outPoint) if err != nil { return err diff --git a/channeldb/duplicate_payments.go b/channeldb/duplicate_payments.go index c78e2804..5d23764b 100644 --- a/channeldb/duplicate_payments.go +++ b/channeldb/duplicate_payments.go @@ -61,7 +61,7 @@ type duplicateHTLCAttemptInfo struct { // fetchDuplicatePaymentStatus fetches the payment status of the payment. If the // payment isn't found, it will default to "StatusUnknown". -func fetchDuplicatePaymentStatus(bucket kvdb.ReadBucket) PaymentStatus { +func fetchDuplicatePaymentStatus(bucket kvdb.RBucket) PaymentStatus { if bucket.Get(duplicatePaymentSettleInfoKey) != nil { return StatusSucceeded } @@ -129,7 +129,7 @@ func deserializeDuplicatePaymentCreationInfo(r io.Reader) ( return c, nil } -func fetchDuplicatePayment(bucket kvdb.ReadBucket) (*MPPayment, error) { +func fetchDuplicatePayment(bucket kvdb.RBucket) (*MPPayment, error) { seqBytes := bucket.Get(duplicatePaymentSequenceKey) if seqBytes == nil { return nil, fmt.Errorf("sequence number not found") @@ -209,7 +209,7 @@ func fetchDuplicatePayment(bucket kvdb.ReadBucket) (*MPPayment, error) { return payment, nil } -func fetchDuplicatePayments(paymentHashBucket kvdb.ReadBucket) ([]*MPPayment, +func fetchDuplicatePayments(paymentHashBucket kvdb.RBucket) ([]*MPPayment, error) { var payments []*MPPayment diff --git a/channeldb/forwarding_log.go b/channeldb/forwarding_log.go index 52596956..a52848dd 100644 --- a/channeldb/forwarding_log.go +++ b/channeldb/forwarding_log.go @@ -204,7 +204,7 @@ func (f *ForwardingLog) Query(q ForwardingEventQuery) (ForwardingLogTimeSlice, e recordsToSkip := q.IndexOffset recordOffset := q.IndexOffset - err := kvdb.View(f.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(f.db, func(tx kvdb.RTx) error { // If the bucket wasn't found, then there aren't any events to // be returned. logBucket := tx.ReadBucket(forwardingLogBucket) diff --git a/channeldb/forwarding_package.go b/channeldb/forwarding_package.go index 4ddcf55b..073ff405 100644 --- a/channeldb/forwarding_package.go +++ b/channeldb/forwarding_package.go @@ -396,7 +396,7 @@ type FwdPackager interface { // LoadFwdPkgs loads all known forwarding packages owned by this // channel. - LoadFwdPkgs(tx kvdb.ReadTx) ([]*FwdPkg, error) + LoadFwdPkgs(tx kvdb.RTx) ([]*FwdPkg, error) // RemovePkg deletes a forwarding package owned by this channel at // the provided remote `height`. @@ -497,12 +497,12 @@ func putLogUpdate(bkt kvdb.RwBucket, 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 kvdb.ReadTx) ([]*FwdPkg, error) { +func (p *ChannelPackager) LoadFwdPkgs(tx kvdb.RTx) ([]*FwdPkg, error) { return loadChannelFwdPkgs(tx, p.source) } // loadChannelFwdPkgs loads all forwarding packages owned by `source`. -func loadChannelFwdPkgs(tx kvdb.ReadTx, source lnwire.ShortChannelID) ([]*FwdPkg, error) { +func loadChannelFwdPkgs(tx kvdb.RTx, source lnwire.ShortChannelID) ([]*FwdPkg, error) { fwdPkgBkt := tx.ReadBucket(fwdPackagesKey) if fwdPkgBkt == nil { return nil, nil @@ -543,7 +543,7 @@ func loadChannelFwdPkgs(tx kvdb.ReadTx, source lnwire.ShortChannelID) ([]*FwdPkg // loadFwPkg reads the packager's fwd pkg at a given height, and determines the // appropriate FwdState. -func loadFwdPkg(fwdPkgBkt kvdb.ReadBucket, source lnwire.ShortChannelID, +func loadFwdPkg(fwdPkgBkt kvdb.RBucket, source lnwire.ShortChannelID, height uint64) (*FwdPkg, error) { sourceKey := makeLogKey(source.ToUint64()) @@ -649,7 +649,7 @@ func loadFwdPkg(fwdPkgBkt kvdb.ReadBucket, 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 kvdb.ReadBucket) ([]LogUpdate, error) { +func loadHtlcs(bkt kvdb.RBucket) ([]LogUpdate, error) { var htlcs []LogUpdate if err := bkt.ForEach(func(_, v []byte) error { var htlc LogUpdate diff --git a/channeldb/forwarding_package_test.go b/channeldb/forwarding_package_test.go index ed18b6bc..031a85f2 100644 --- a/channeldb/forwarding_package_test.go +++ b/channeldb/forwarding_package_test.go @@ -782,7 +782,7 @@ func loadFwdPkgs(t *testing.T, db kvdb.Backend, packager channeldb.FwdPackager) []*channeldb.FwdPkg { var fwdPkgs []*channeldb.FwdPkg - if err := kvdb.View(db, func(tx kvdb.ReadTx) error { + if err := kvdb.View(db, func(tx kvdb.RTx) error { var err error fwdPkgs, err = packager.LoadFwdPkgs(tx) return err diff --git a/channeldb/graph.go b/channeldb/graph.go index 3722bfbd..c55e238c 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -206,7 +206,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 kvdb.View(c.db, func(tx kvdb.ReadTx) error { + return kvdb.View(c.db, func(tx kvdb.RTx) error { // First, grab the node bucket. This will be used to populate // the Node pointers in each edge read from disk. nodes := tx.ReadBucket(nodeBucket) @@ -265,8 +265,8 @@ func (c *ChannelGraph) ForEachChannel(cb func(*ChannelEdgeInfo, *ChannelEdgePoli // 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 (c *ChannelGraph) ForEachNodeChannel(tx kvdb.ReadTx, nodePub []byte, - cb func(kvdb.ReadTx, *ChannelEdgeInfo, *ChannelEdgePolicy, +func (c *ChannelGraph) ForEachNodeChannel(tx kvdb.RTx, nodePub []byte, + cb func(kvdb.RTx, *ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error { db := c.db @@ -281,7 +281,7 @@ func (c *ChannelGraph) DisabledChannelIDs() ([]uint64, error) { var disabledChanIDs []uint64 chanEdgeFound := make(map[uint64]struct{}) - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -323,8 +323,8 @@ func (c *ChannelGraph) DisabledChannelIDs() ([]uint64, error) { // // TODO(roasbeef): add iterator interface to allow for memory efficient graph // traversal when graph gets mega -func (c *ChannelGraph) ForEachNode(cb func(kvdb.ReadTx, *LightningNode) error) error { // nolint:interfacer - traversal := func(tx kvdb.ReadTx) error { +func (c *ChannelGraph) ForEachNode(cb func(kvdb.RTx, *LightningNode) error) error { // nolint:interfacer + traversal := func(tx kvdb.RTx) error { // First grab the nodes bucket which stores the mapping from // pubKey to node information. nodes := tx.ReadBucket(nodeBucket) @@ -362,7 +362,7 @@ func (c *ChannelGraph) ForEachNode(cb func(kvdb.ReadTx, *LightningNode) error) e // node based off the source node. func (c *ChannelGraph) SourceNode() (*LightningNode, error) { var source *LightningNode - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { // First grab the nodes bucket which stores the mapping from // pubKey to node information. nodes := tx.ReadBucket(nodeBucket) @@ -389,7 +389,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(nodes kvdb.ReadBucket) (*LightningNode, error) { +func (c *ChannelGraph) sourceNode(nodes kvdb.RBucket) (*LightningNode, error) { selfPub := nodes.Get(sourceKey) if selfPub == nil { return nil, ErrSourceNodeNotSet @@ -472,7 +472,7 @@ func addLightningNode(tx kvdb.RwTx, node *LightningNode) error { func (c *ChannelGraph) LookupAlias(pub *btcec.PublicKey) (string, error) { var alias string - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { nodes := tx.ReadBucket(nodeBucket) if nodes == nil { return ErrGraphNodesNotFound @@ -720,7 +720,7 @@ func (c *ChannelGraph) HasChannelEdge( return upd1Time, upd2Time, exists, isZombie, nil } - if err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + if err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -1210,7 +1210,7 @@ func (c *ChannelGraph) PruneTip() (*chainhash.Hash, uint32, error) { tipHeight uint32 ) - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { graphMeta := tx.ReadBucket(graphMetaBucket) if graphMeta == nil { return ErrGraphNotFound @@ -1308,7 +1308,7 @@ func (c *ChannelGraph) DeleteChannelEdges(chanIDs ...uint64) error { // the database, then ErrEdgeNotFound is returned. func (c *ChannelGraph) ChannelID(chanPoint *wire.OutPoint) (uint64, error) { var chanID uint64 - if err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + if err := kvdb.View(c.db, func(tx kvdb.RTx) error { var err error chanID, err = getChanID(tx, chanPoint) return err @@ -1320,7 +1320,7 @@ func (c *ChannelGraph) ChannelID(chanPoint *wire.OutPoint) (uint64, error) { } // getChanID returns the assigned channel ID for a given channel point. -func getChanID(tx kvdb.ReadTx, chanPoint *wire.OutPoint) (uint64, error) { +func getChanID(tx kvdb.RTx, chanPoint *wire.OutPoint) (uint64, error) { var b bytes.Buffer if err := writeOutpoint(&b, chanPoint); err != nil { return 0, err @@ -1353,7 +1353,7 @@ func getChanID(tx kvdb.ReadTx, chanPoint *wire.OutPoint) (uint64, error) { func (c *ChannelGraph) HighestChanID() (uint64, error) { var cid uint64 - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -1417,7 +1417,7 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(startTime, endTime time.Time) ([]Cha defer c.cacheMu.Unlock() var hits int - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -1537,7 +1537,7 @@ func (c *ChannelGraph) ChanUpdatesInHorizon(startTime, endTime time.Time) ([]Cha func (c *ChannelGraph) NodeUpdatesInHorizon(startTime, endTime time.Time) ([]LightningNode, error) { var nodesInHorizon []LightningNode - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { nodes := tx.ReadBucket(nodeBucket) if nodes == nil { return ErrGraphNodesNotFound @@ -1599,7 +1599,7 @@ func (c *ChannelGraph) NodeUpdatesInHorizon(startTime, endTime time.Time) ([]Lig func (c *ChannelGraph) FilterKnownChanIDs(chanIDs []uint64) ([]uint64, error) { var newChanIDs []uint64 - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -1675,7 +1675,7 @@ func (c *ChannelGraph) FilterChannelRange(startHeight, endHeight uint32) ([]uint byteOrder.PutUint64(chanIDStart[:], startChanID.ToUint64()) byteOrder.PutUint64(chanIDEnd[:], endChanID.ToUint64()) - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -1728,7 +1728,7 @@ func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) { cidBytes [8]byte ) - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -2127,14 +2127,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 kvdb.ReadTx, sourcePubKey []byte) (bool, error) { +func (l *LightningNode) isPublic(tx kvdb.RTx, 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(_ kvdb.ReadTx, info *ChannelEdgeInfo, + err := l.ForEachChannel(tx, func(_ kvdb.RTx, info *ChannelEdgeInfo, _, _ *ChannelEdgePolicy) error { // If this edge doesn't extend to the source node, we'll @@ -2173,12 +2173,12 @@ func (l *LightningNode) isPublic(tx kvdb.ReadTx, sourcePubKey []byte) (bool, err // 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 (c *ChannelGraph) FetchLightningNode(tx kvdb.ReadTx, nodePub route.Vertex) ( +func (c *ChannelGraph) FetchLightningNode(tx kvdb.RTx, nodePub route.Vertex) ( *LightningNode, error) { var node *LightningNode - fetchNode := func(tx kvdb.ReadTx) error { + fetchNode := func(tx kvdb.RTx) error { // First grab the nodes bucket which stores the mapping from // pubKey to node information. nodes := tx.ReadBucket(nodeBucket) @@ -2231,7 +2231,7 @@ func (c *ChannelGraph) HasLightningNode(nodePub [33]byte) (time.Time, bool, erro exists bool ) - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { // First grab the nodes bucket which stores the mapping from // pubKey to node information. nodes := tx.ReadBucket(nodeBucket) @@ -2269,10 +2269,10 @@ func (c *ChannelGraph) HasLightningNode(nodePub [33]byte) (time.Time, bool, erro // nodeTraversal is used to traverse all channels of a node given by its // public key and passes channel information into the specified callback. -func nodeTraversal(tx kvdb.ReadTx, nodePub []byte, db *DB, - cb func(kvdb.ReadTx, *ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error { +func nodeTraversal(tx kvdb.RTx, nodePub []byte, db *DB, + cb func(kvdb.RTx, *ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error { - traversal := func(tx kvdb.ReadTx) error { + traversal := func(tx kvdb.RTx) error { nodes := tx.ReadBucket(nodeBucket) if nodes == nil { return ErrGraphNotFound @@ -2367,8 +2367,8 @@ func nodeTraversal(tx kvdb.ReadTx, nodePub []byte, db *DB, // 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 kvdb.ReadTx, - cb func(kvdb.ReadTx, *ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error { +func (l *LightningNode) ForEachChannel(tx kvdb.RTx, + cb func(kvdb.RTx, *ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error { nodePub := l.PubKeyBytes[:] db := l.db @@ -2559,7 +2559,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 kvdb.ReadTx, thisNodeKey []byte) (*LightningNode, error) { +func (c *ChannelEdgeInfo) FetchOtherNode(tx kvdb.RTx, thisNodeKey []byte) (*LightningNode, error) { // Ensure that the node passed in is actually a member of the channel. var targetNodeBytes [33]byte @@ -2573,7 +2573,7 @@ func (c *ChannelEdgeInfo) FetchOtherNode(tx kvdb.ReadTx, thisNodeKey []byte) (*L } var targetNode *LightningNode - fetchNodeFunc := func(tx kvdb.ReadTx) error { + fetchNodeFunc := func(tx kvdb.RTx) error { // First grab the nodes bucket which stores the mapping from // pubKey to node information. nodes := tx.ReadBucket(nodeBucket) @@ -2872,7 +2872,7 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint, policy2 *ChannelEdgePolicy ) - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { // First, grab the node bucket. This will be used to populate // the Node pointers in each edge read from disk. nodes := tx.ReadBucket(nodeBucket) @@ -2956,7 +2956,7 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64, channelID [8]byte ) - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { // First, grab the node bucket. This will be used to populate // the Node pointers in each edge read from disk. nodes := tx.ReadBucket(nodeBucket) @@ -3046,7 +3046,7 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64, // source node's point of view. func (c *ChannelGraph) IsPublicNode(pubKey [33]byte) (bool, error) { var nodeIsPublic bool - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { nodes := tx.ReadBucket(nodeBucket) if nodes == nil { return ErrGraphNodesNotFound @@ -3132,7 +3132,7 @@ func (e *EdgePoint) String() string { // closes on the resident blockchain. func (c *ChannelGraph) ChannelView() ([]EdgePoint, error) { var edgePoints []EdgePoint - if err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + if err := kvdb.View(c.db, func(tx kvdb.RTx) 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. @@ -3249,7 +3249,7 @@ func (c *ChannelGraph) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) { pubKey1, pubKey2 [33]byte ) - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -3272,7 +3272,7 @@ func (c *ChannelGraph) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte) { // isZombieEdge returns whether an entry exists for the given channel in the // zombie index. If an entry exists, then the two node public keys corresponding // to this edge are also returned. -func isZombieEdge(zombieIndex kvdb.ReadBucket, +func isZombieEdge(zombieIndex kvdb.RBucket, chanID uint64) (bool, [33]byte, [33]byte) { var k [8]byte @@ -3293,7 +3293,7 @@ func isZombieEdge(zombieIndex kvdb.ReadBucket, // NumZombies returns the current number of zombie channels in the graph. func (c *ChannelGraph) NumZombies() (uint64, error) { var numZombies uint64 - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return nil @@ -3444,7 +3444,7 @@ func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, // no return nodeBucket.Put(nodePub, b.Bytes()) } -func fetchLightningNode(nodeBucket kvdb.ReadBucket, +func fetchLightningNode(nodeBucket kvdb.RBucket, nodePub []byte) (LightningNode, error) { nodeBytes := nodeBucket.Get(nodePub) @@ -3618,7 +3618,7 @@ func putChanEdgeInfo(edgeIndex kvdb.RwBucket, edgeInfo *ChannelEdgeInfo, chanID return edgeIndex.Put(chanID[:], b.Bytes()) } -func fetchChanEdgeInfo(edgeIndex kvdb.ReadBucket, +func fetchChanEdgeInfo(edgeIndex kvdb.RBucket, chanID []byte) (ChannelEdgeInfo, error) { edgeInfoBytes := edgeIndex.Get(chanID) @@ -3827,8 +3827,8 @@ func putChanEdgePolicyUnknown(edges kvdb.RwBucket, channelID uint64, return edges.Put(edgeKey[:], unknownPolicy) } -func fetchChanEdgePolicy(edges kvdb.ReadBucket, chanID []byte, - nodePub []byte, nodes kvdb.ReadBucket) (*ChannelEdgePolicy, error) { +func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte, + nodePub []byte, nodes kvdb.RBucket) (*ChannelEdgePolicy, error) { var edgeKey [33 + 8]byte copy(edgeKey[:], nodePub) @@ -3860,8 +3860,8 @@ func fetchChanEdgePolicy(edges kvdb.ReadBucket, chanID []byte, return ep, nil } -func fetchChanEdgePolicies(edgeIndex kvdb.ReadBucket, edges kvdb.ReadBucket, - nodes kvdb.ReadBucket, chanID []byte, +func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket, + nodes kvdb.RBucket, chanID []byte, db *DB) (*ChannelEdgePolicy, *ChannelEdgePolicy, error) { edgeInfo := edgeIndex.Get(chanID) @@ -3969,7 +3969,7 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy, } func deserializeChanEdgePolicy(r io.Reader, - nodes kvdb.ReadBucket) (*ChannelEdgePolicy, error) { + nodes kvdb.RBucket) (*ChannelEdgePolicy, error) { edge := &ChannelEdgePolicy{} diff --git a/channeldb/graph_test.go b/channeldb/graph_test.go index 1fa98118..a6c1fb0d 100644 --- a/channeldb/graph_test.go +++ b/channeldb/graph_test.go @@ -882,7 +882,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(func(_ kvdb.ReadTx, node *LightningNode) error { + err = graph.ForEachNode(func(_ kvdb.RTx, node *LightningNode) error { delete(nodeIndex, node.Alias) return nil }) @@ -978,7 +978,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(_ kvdb.ReadTx, _ *ChannelEdgeInfo, + err = firstNode.ForEachChannel(nil, func(_ kvdb.RTx, _ *ChannelEdgeInfo, outEdge, inEdge *ChannelEdgePolicy) error { // All channels between first and second node should have fully @@ -1051,7 +1051,7 @@ func assertNumChans(t *testing.T, graph *ChannelGraph, n int) { func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) { numNodes := 0 - err := graph.ForEachNode(func(_ kvdb.ReadTx, _ *LightningNode) error { + err := graph.ForEachNode(func(_ kvdb.RTx, _ *LightningNode) error { numNodes++ return nil }) @@ -2099,7 +2099,7 @@ func TestIncompleteChannelPolicies(t *testing.T) { // Ensure that channel is reported with unknown policies. checkPolicies := func(node *LightningNode, expectedIn, expectedOut bool) { calls := 0 - err := node.ForEachChannel(nil, func(_ kvdb.ReadTx, _ *ChannelEdgeInfo, + err := node.ForEachChannel(nil, func(_ kvdb.RTx, _ *ChannelEdgeInfo, outEdge, inEdge *ChannelEdgePolicy) error { if !expectedOut && outEdge != nil { @@ -2235,7 +2235,7 @@ func TestChannelEdgePruningUpdateIndexDeletion(t *testing.T) { timestampSet[t] = struct{}{} } - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { edges := tx.ReadBucket(edgeBucket) if edges == nil { return ErrGraphNoEdgesFound @@ -2844,7 +2844,7 @@ func TestEdgePolicyMissingMaxHtcl(t *testing.T) { // Attempting to deserialize these bytes should return an error. r := bytes.NewReader(stripped) - err = kvdb.View(db, func(tx kvdb.ReadTx) error { + err = kvdb.View(db, func(tx kvdb.RTx) error { nodes := tx.ReadBucket(nodeBucket) if nodes == nil { return ErrGraphNotFound diff --git a/channeldb/invoices.go b/channeldb/invoices.go index 23c10dc6..aea8ae30 100644 --- a/channeldb/invoices.go +++ b/channeldb/invoices.go @@ -485,7 +485,7 @@ func (d *DB) InvoicesAddedSince(sinceAddIndex uint64) ([]Invoice, error) { var startIndex [8]byte byteOrder.PutUint64(startIndex[:], sinceAddIndex) - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { invoices := tx.ReadBucket(invoiceBucket) if invoices == nil { return ErrNoInvoicesCreated @@ -540,7 +540,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 := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { invoices := tx.ReadBucket(invoiceBucket) if invoices == nil { return ErrNoInvoicesCreated @@ -595,7 +595,7 @@ func (d *DB) FetchAllInvoicesWithPaymentHash(pendingOnly bool) ( var result []InvoiceWithPaymentHash - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { invoices := tx.ReadBucket(invoiceBucket) if invoices == nil { return ErrNoInvoicesCreated @@ -701,7 +701,7 @@ func (d *DB) QueryInvoices(q InvoiceQuery) (InvoiceSlice, error) { InvoiceQuery: q, } - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { // If the bucket wasn't found, then there aren't any invoices // within the database yet, so we can simply exit. invoices := tx.ReadBucket(invoiceBucket) @@ -715,7 +715,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 kvdb.ReadCursor, index uint64) []byte { + keyForIndex := func(c kvdb.RCursor, index uint64) []byte { var keyIndex [8]byte byteOrder.PutUint64(keyIndex[:], index) _, invoiceKey := c.Seek(keyIndex[:]) @@ -724,7 +724,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 kvdb.ReadCursor) ([]byte, []byte) { + nextKey := func(c kvdb.RCursor) ([]byte, []byte) { if q.Reversed { return c.Prev() } @@ -883,7 +883,7 @@ func (d *DB) InvoicesSettledSince(sinceSettleIndex uint64) ([]Invoice, error) { var startIndex [8]byte byteOrder.PutUint64(startIndex[:], sinceSettleIndex) - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { invoices := tx.ReadBucket(invoiceBucket) if invoices == nil { return ErrNoInvoicesCreated @@ -1118,7 +1118,7 @@ func serializeHtlcs(w io.Writer, htlcs map[CircuitKey]*InvoiceHTLC) error { return nil } -func fetchInvoice(invoiceNum []byte, invoices kvdb.ReadBucket) (Invoice, error) { +func fetchInvoice(invoiceNum []byte, invoices kvdb.RBucket) (Invoice, error) { invoiceBytes := invoices.Get(invoiceNum) if invoiceBytes == nil { return Invoice{}, ErrInvoiceNotFound diff --git a/channeldb/kvdb/interface.go b/channeldb/kvdb/interface.go index 46aded8c..16e84285 100644 --- a/channeldb/kvdb/interface.go +++ b/channeldb/kvdb/interface.go @@ -22,7 +22,7 @@ func Update(db Backend, f func(tx RwTx) error) error { // transaction passed as a parameter. After f exits, the transaction is rolled // back. If f errors, its error is returned, not a rollback error (if any // occur). -func View(db Backend, f func(tx ReadTx) error) error { +func View(db Backend, f func(tx RTx) error) error { if extendedDB, ok := db.(ExtendedBackend); ok { return extendedDB.View(f) } @@ -81,18 +81,18 @@ var Open = walletdb.Open // themselves as a backend which implements the Backend interface. type Driver = walletdb.Driver -// ReadBucket represents a bucket (a hierarchical structure within the +// RBucket represents a bucket (a hierarchical structure within the // database) that is only allowed to perform read operations. -type ReadBucket = walletdb.ReadBucket +type RBucket = walletdb.ReadBucket -// ReadCursor represents a bucket cursor that can be positioned at the start or +// RCursor represents a bucket cursor that can be positioned at the start or // end of the bucket's key/value pairs and iterate over pairs in the bucket. // This type is only allowed to perform database read operations. -type ReadCursor = walletdb.ReadCursor +type RCursor = walletdb.ReadCursor -// ReadTx represents a database transaction that can only be used for reads. If +// RTx represents a database transaction that can only be used for reads. If // a database update must occur, use a RwTx. -type ReadTx = walletdb.ReadTx +type RTx = walletdb.ReadTx // RwBucket represents a bucket (a hierarchical structure within the database) // that is allowed to perform both read and write operations. @@ -105,7 +105,7 @@ type RwBucket = walletdb.ReadWriteBucket type RwCursor = walletdb.ReadWriteCursor // ReadWriteTx represents a database transaction that can be used for both -// reads and writes. When only reads are necessary, consider using a ReadTx +// reads and writes. When only reads are necessary, consider using a RTx // instead. type RwTx = walletdb.ReadWriteTx diff --git a/channeldb/meta.go b/channeldb/meta.go index a2dd853e..f7f9ae1e 100644 --- a/channeldb/meta.go +++ b/channeldb/meta.go @@ -22,10 +22,10 @@ type Meta struct { // FetchMeta fetches the meta data from boltdb and returns filled meta // structure. -func (d *DB) FetchMeta(tx kvdb.ReadTx) (*Meta, error) { +func (d *DB) FetchMeta(tx kvdb.RTx) (*Meta, error) { meta := &Meta{} - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { return fetchMeta(meta, tx) }) if err != nil { @@ -38,7 +38,7 @@ func (d *DB) FetchMeta(tx kvdb.ReadTx) (*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 kvdb.ReadTx) error { +func fetchMeta(meta *Meta, tx kvdb.RTx) error { metaBucket := tx.ReadBucket(metaBucket) if metaBucket == nil { return ErrMetaNotFound diff --git a/channeldb/meta_test.go b/channeldb/meta_test.go index 94801125..956ffb5d 100644 --- a/channeldb/meta_test.go +++ b/channeldb/meta_test.go @@ -481,7 +481,7 @@ func TestMigrationDryRun(t *testing.T) { // Check that version of database version is not modified. afterMigrationFunc := func(d *DB) { - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { meta, err := d.FetchMeta(nil) if err != nil { t.Fatal(err) diff --git a/channeldb/migration_01_to_11/db.go b/channeldb/migration_01_to_11/db.go index ed1239fd..f5890246 100644 --- a/channeldb/migration_01_to_11/db.go +++ b/channeldb/migration_01_to_11/db.go @@ -180,7 +180,7 @@ func fileExists(path string) bool { func (d *DB) FetchClosedChannels(pendingOnly bool) ([]*ChannelCloseSummary, error) { var chanSummaries []*ChannelCloseSummary - if err := kvdb.View(d, func(tx kvdb.ReadTx) error { + if err := kvdb.View(d, func(tx kvdb.RTx) error { closeBucket := tx.ReadBucket(closedChannelBucket) if closeBucket == nil { return ErrNoClosedChannels diff --git a/channeldb/migration_01_to_11/graph.go b/channeldb/migration_01_to_11/graph.go index 14436f58..f3b88539 100644 --- a/channeldb/migration_01_to_11/graph.go +++ b/channeldb/migration_01_to_11/graph.go @@ -175,7 +175,7 @@ func newChannelGraph(db *DB, rejectCacheSize, chanCacheSize int) *ChannelGraph { // node based off the source node. func (c *ChannelGraph) SourceNode() (*LightningNode, error) { var source *LightningNode - err := kvdb.View(c.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(c.db, func(tx kvdb.RTx) error { // First grab the nodes bucket which stores the mapping from // pubKey to node information. nodes := tx.ReadBucket(nodeBucket) @@ -202,7 +202,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(nodes kvdb.ReadBucket) (*LightningNode, error) { +func (c *ChannelGraph) sourceNode(nodes kvdb.RBucket) (*LightningNode, error) { selfPub := nodes.Get(sourceKey) if selfPub == nil { return nil, ErrSourceNodeNotSet @@ -680,7 +680,7 @@ func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, return nodeBucket.Put(nodePub, b.Bytes()) } -func fetchLightningNode(nodeBucket kvdb.ReadBucket, +func fetchLightningNode(nodeBucket kvdb.RBucket, nodePub []byte) (LightningNode, error) { nodeBytes := nodeBucket.Get(nodePub) @@ -983,8 +983,8 @@ func putChanEdgePolicyUnknown(edges kvdb.RwBucket, channelID uint64, return edges.Put(edgeKey[:], unknownPolicy) } -func fetchChanEdgePolicy(edges kvdb.ReadBucket, chanID []byte, - nodePub []byte, nodes kvdb.ReadBucket) (*ChannelEdgePolicy, error) { +func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte, + nodePub []byte, nodes kvdb.RBucket) (*ChannelEdgePolicy, error) { var edgeKey [33 + 8]byte copy(edgeKey[:], nodePub) @@ -1084,7 +1084,7 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy, } func deserializeChanEdgePolicy(r io.Reader, - nodes kvdb.ReadBucket) (*ChannelEdgePolicy, error) { + nodes kvdb.RBucket) (*ChannelEdgePolicy, error) { edge := &ChannelEdgePolicy{} diff --git a/channeldb/migration_01_to_11/invoices.go b/channeldb/migration_01_to_11/invoices.go index 7e56489b..dcba1d54 100644 --- a/channeldb/migration_01_to_11/invoices.go +++ b/channeldb/migration_01_to_11/invoices.go @@ -252,7 +252,7 @@ func validateInvoice(i *Invoice) error { func (d *DB) FetchAllInvoices(pendingOnly bool) ([]Invoice, error) { var invoices []Invoice - err := kvdb.View(d, func(tx kvdb.ReadTx) error { + err := kvdb.View(d, func(tx kvdb.RTx) error { invoiceB := tx.ReadBucket(invoiceBucket) if invoiceB == nil { return ErrNoInvoicesCreated diff --git a/channeldb/migration_01_to_11/migration_09_legacy_serialization.go b/channeldb/migration_01_to_11/migration_09_legacy_serialization.go index 3589662c..acd61b0a 100644 --- a/channeldb/migration_01_to_11/migration_09_legacy_serialization.go +++ b/channeldb/migration_01_to_11/migration_09_legacy_serialization.go @@ -104,7 +104,7 @@ func (db *DB) addPayment(payment *outgoingPayment) error { func (db *DB) fetchAllPayments() ([]*outgoingPayment, error) { var payments []*outgoingPayment - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { bucket := tx.ReadBucket(paymentBucket) if bucket == nil { return ErrNoPaymentsCreated @@ -140,7 +140,7 @@ func (db *DB) fetchAllPayments() ([]*outgoingPayment, error) { // NOTE: Deprecated. Kept around for migration purposes. func (db *DB) fetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) { var paymentStatus = StatusUnknown - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { var err error paymentStatus, err = fetchPaymentStatusTx(tx, paymentHash) return err @@ -158,7 +158,7 @@ func (db *DB) fetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) { // can be composed into other atomic operations. // // NOTE: Deprecated. Kept around for migration purposes. -func fetchPaymentStatusTx(tx kvdb.ReadTx, paymentHash [32]byte) (PaymentStatus, error) { +func fetchPaymentStatusTx(tx kvdb.RTx, paymentHash [32]byte) (PaymentStatus, error) { // The default status for all payments that aren't recorded in database. var paymentStatus = StatusUnknown @@ -375,7 +375,7 @@ func deserializeHopMigration9(r io.Reader) (*Hop, error) { func (db *DB) fetchPaymentsMigration9() ([]*Payment, error) { var payments []*Payment - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { paymentsBucket := tx.ReadBucket(paymentsRootBucket) if paymentsBucket == nil { return nil @@ -437,7 +437,7 @@ func (db *DB) fetchPaymentsMigration9() ([]*Payment, error) { return payments, nil } -func fetchPaymentMigration9(bucket kvdb.ReadBucket) (*Payment, error) { +func fetchPaymentMigration9(bucket kvdb.RBucket) (*Payment, error) { var ( err error p = &Payment{} diff --git a/channeldb/migration_01_to_11/migrations_test.go b/channeldb/migration_01_to_11/migrations_test.go index c2531b8f..6cd855e8 100644 --- a/channeldb/migration_01_to_11/migrations_test.go +++ b/channeldb/migration_01_to_11/migrations_test.go @@ -404,7 +404,7 @@ func TestMigrateOptionalChannelCloseSummaryFields(t *testing.T) { newSerialization := b.Bytes() var dbSummary []byte - err = kvdb.View(d, func(tx kvdb.ReadTx) error { + err = kvdb.View(d, func(tx kvdb.RTx) error { closedChanBucket := tx.ReadBucket(closedChannelBucket) if closedChanBucket == nil { return errors.New("unable to find bucket") @@ -503,7 +503,7 @@ func TestMigrateGossipMessageStoreKeys(t *testing.T) { // 3. The message matches the original. afterMigration := func(db *DB) { var rawMsg []byte - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { messageStore := tx.ReadBucket(messageStoreBucket) if messageStore == nil { return errors.New("message store bucket not " + diff --git a/channeldb/migration_01_to_11/payment_control.go b/channeldb/migration_01_to_11/payment_control.go index 80acf9ce..41778fe4 100644 --- a/channeldb/migration_01_to_11/payment_control.go +++ b/channeldb/migration_01_to_11/payment_control.go @@ -4,7 +4,7 @@ import "github.com/lightningnetwork/lnd/channeldb/kvdb" // fetchPaymentStatus fetches the payment status of the payment. If the payment // isn't found, it will default to "StatusUnknown". -func fetchPaymentStatus(bucket kvdb.ReadBucket) PaymentStatus { +func fetchPaymentStatus(bucket kvdb.RBucket) PaymentStatus { if bucket.Get(paymentSettleInfoKey) != nil { return StatusSucceeded } diff --git a/channeldb/migration_01_to_11/payments.go b/channeldb/migration_01_to_11/payments.go index e0b185f3..697da0e0 100644 --- a/channeldb/migration_01_to_11/payments.go +++ b/channeldb/migration_01_to_11/payments.go @@ -254,7 +254,7 @@ type Payment struct { func (db *DB) FetchPayments() ([]*Payment, error) { var payments []*Payment - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { paymentsBucket := tx.ReadBucket(paymentsRootBucket) if paymentsBucket == nil { return nil @@ -316,7 +316,7 @@ func (db *DB) FetchPayments() ([]*Payment, error) { return payments, nil } -func fetchPayment(bucket kvdb.ReadBucket) (*Payment, error) { +func fetchPayment(bucket kvdb.RBucket) (*Payment, error) { var ( err error p = &Payment{} diff --git a/channeldb/migtest/raw_db.go b/channeldb/migtest/raw_db.go index 8f3f1f22..bae5b933 100644 --- a/channeldb/migtest/raw_db.go +++ b/channeldb/migtest/raw_db.go @@ -21,7 +21,7 @@ import ( // hex("1111"): hex("5783492373"), // }, // } -func DumpDB(tx kvdb.ReadTx, rootKey []byte) error { +func DumpDB(tx kvdb.RTx, rootKey []byte) error { bucket := tx.ReadBucket(rootKey) if bucket == nil { return fmt.Errorf("bucket %v not found", string(rootKey)) @@ -30,7 +30,7 @@ func DumpDB(tx kvdb.ReadTx, rootKey []byte) error { return dumpBucket(bucket) } -func dumpBucket(bucket kvdb.ReadBucket) error { +func dumpBucket(bucket kvdb.RBucket) error { fmt.Printf("map[string]interface{} {\n") err := bucket.ForEach(func(k, v []byte) error { key := toString(k) @@ -100,7 +100,7 @@ func restoreDB(bucket kvdb.RwBucket, data map[string]interface{}) error { } // VerifyDB verifies the database against the given data set. -func VerifyDB(tx kvdb.ReadTx, rootKey []byte, data map[string]interface{}) error { +func VerifyDB(tx kvdb.RTx, rootKey []byte, data map[string]interface{}) error { bucket := tx.ReadBucket(rootKey) if bucket == nil { return fmt.Errorf("bucket %v not found", string(rootKey)) @@ -109,7 +109,7 @@ func VerifyDB(tx kvdb.ReadTx, rootKey []byte, data map[string]interface{}) error return verifyDB(bucket, data) } -func verifyDB(bucket kvdb.ReadBucket, data map[string]interface{}) error { +func verifyDB(bucket kvdb.RBucket, data map[string]interface{}) error { for k, v := range data { key := []byte(k) diff --git a/channeldb/nodes.go b/channeldb/nodes.go index 57197fb3..dcbdf63a 100644 --- a/channeldb/nodes.go +++ b/channeldb/nodes.go @@ -150,7 +150,7 @@ func (db *DB) deleteLinkNode(tx kvdb.RwTx, identity *btcec.PublicKey) error { // key cannot be found, then ErrNodeNotFound if returned. func (db *DB) FetchLinkNode(identity *btcec.PublicKey) (*LinkNode, error) { var linkNode *LinkNode - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { node, err := fetchLinkNode(tx, identity) if err != nil { return err @@ -163,7 +163,7 @@ func (db *DB) FetchLinkNode(identity *btcec.PublicKey) (*LinkNode, error) { return linkNode, err } -func fetchLinkNode(tx kvdb.ReadTx, targetPub *btcec.PublicKey) (*LinkNode, error) { +func fetchLinkNode(tx kvdb.RTx, targetPub *btcec.PublicKey) (*LinkNode, error) { // First fetch the bucket for storing node metadata, bailing out early // if it hasn't been created yet. nodeMetaBucket := tx.ReadBucket(nodeInfoBucket) @@ -191,7 +191,7 @@ func fetchLinkNode(tx kvdb.ReadTx, targetPub *btcec.PublicKey) (*LinkNode, error // whom we have active channels with. func (db *DB) FetchAllLinkNodes() ([]*LinkNode, error) { var linkNodes []*LinkNode - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { nodes, err := db.fetchAllLinkNodes(tx) if err != nil { return err @@ -209,7 +209,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 kvdb.ReadTx) ([]*LinkNode, error) { +func (db *DB) fetchAllLinkNodes(tx kvdb.RTx) ([]*LinkNode, error) { nodeMetaBucket := tx.ReadBucket(nodeInfoBucket) if nodeMetaBucket == nil { return nil, ErrLinkNodesNotFound diff --git a/channeldb/payment_control.go b/channeldb/payment_control.go index 1ba84668..99d2000c 100644 --- a/channeldb/payment_control.go +++ b/channeldb/payment_control.go @@ -462,7 +462,7 @@ func (p *PaymentControl) FetchPayment(paymentHash lntypes.Hash) ( *MPPayment, error) { var payment *MPPayment - err := kvdb.View(p.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(p.db, func(tx kvdb.RTx) error { bucket, err := fetchPaymentBucket(tx, paymentHash) if err != nil { return err @@ -494,8 +494,8 @@ func createPaymentBucket(tx kvdb.RwTx, paymentHash lntypes.Hash) ( // fetchPaymentBucket fetches the sub-bucket assigned to this payment hash. If // the bucket does not exist, it returns ErrPaymentNotInitiated. -func fetchPaymentBucket(tx kvdb.ReadTx, paymentHash lntypes.Hash) ( - kvdb.ReadBucket, error) { +func fetchPaymentBucket(tx kvdb.RTx, paymentHash lntypes.Hash) ( + kvdb.RBucket, error) { payments := tx.ReadBucket(paymentsRootBucket) if payments == nil { @@ -549,7 +549,7 @@ func nextPaymentSequence(tx kvdb.RwTx) ([]byte, error) { // fetchPaymentStatus fetches the payment status of the payment. If the payment // isn't found, it will default to "StatusUnknown". -func fetchPaymentStatus(bucket kvdb.ReadBucket) (PaymentStatus, error) { +func fetchPaymentStatus(bucket kvdb.RBucket) (PaymentStatus, error) { // Creation info should be set for all payments, regardless of state. // If not, it is unknown. if bucket.Get(paymentCreationInfoKey) == nil { @@ -609,7 +609,7 @@ type InFlightPayment struct { // FetchInFlightPayments returns all payments with status InFlight. func (p *PaymentControl) FetchInFlightPayments() ([]*InFlightPayment, error) { var inFlights []*InFlightPayment - err := kvdb.View(p.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(p.db, func(tx kvdb.RTx) error { payments := tx.ReadBucket(paymentsRootBucket) if payments == nil { return nil diff --git a/channeldb/payments.go b/channeldb/payments.go index 3956dd78..d1ec6070 100644 --- a/channeldb/payments.go +++ b/channeldb/payments.go @@ -206,7 +206,7 @@ type PaymentCreationInfo struct { func (db *DB) FetchPayments() ([]*MPPayment, error) { var payments []*MPPayment - err := kvdb.View(db, func(tx kvdb.ReadTx) error { + err := kvdb.View(db, func(tx kvdb.RTx) error { paymentsBucket := tx.ReadBucket(paymentsRootBucket) if paymentsBucket == nil { return nil @@ -253,7 +253,7 @@ func (db *DB) FetchPayments() ([]*MPPayment, error) { return payments, nil } -func fetchCreationInfo(bucket kvdb.ReadBucket) (*PaymentCreationInfo, error) { +func fetchCreationInfo(bucket kvdb.RBucket) (*PaymentCreationInfo, error) { b := bucket.Get(paymentCreationInfoKey) if b == nil { return nil, fmt.Errorf("creation info not found") @@ -263,7 +263,7 @@ func fetchCreationInfo(bucket kvdb.ReadBucket) (*PaymentCreationInfo, error) { return deserializePaymentCreationInfo(r) } -func fetchPayment(bucket kvdb.ReadBucket) (*MPPayment, error) { +func fetchPayment(bucket kvdb.RBucket) (*MPPayment, error) { seqBytes := bucket.Get(paymentSequenceKey) if seqBytes == nil { return nil, fmt.Errorf("sequence number not found") @@ -345,7 +345,7 @@ func fetchPayment(bucket kvdb.ReadBucket) (*MPPayment, error) { // fetchHtlcAttempts retrives all htlc attempts made for the payment found in // the given bucket. -func fetchHtlcAttempts(bucket kvdb.ReadBucket) ([]HTLCAttempt, error) { +func fetchHtlcAttempts(bucket kvdb.RBucket) ([]HTLCAttempt, error) { htlcs := make([]HTLCAttempt, 0) err := bucket.ForEach(func(k, _ []byte) error { @@ -388,7 +388,7 @@ func fetchHtlcAttempts(bucket kvdb.ReadBucket) ([]HTLCAttempt, error) { // fetchHtlcAttemptInfo fetches the payment attempt info for this htlc from the // bucket. -func fetchHtlcAttemptInfo(bucket kvdb.ReadBucket) (*HTLCAttemptInfo, error) { +func fetchHtlcAttemptInfo(bucket kvdb.RBucket) (*HTLCAttemptInfo, error) { b := bucket.Get(htlcAttemptInfoKey) if b == nil { return nil, errNoAttemptInfo @@ -400,7 +400,7 @@ func fetchHtlcAttemptInfo(bucket kvdb.ReadBucket) (*HTLCAttemptInfo, error) { // fetchHtlcSettleInfo retrieves the settle info for the htlc. If the htlc isn't // settled, nil is returned. -func fetchHtlcSettleInfo(bucket kvdb.ReadBucket) (*HTLCSettleInfo, error) { +func fetchHtlcSettleInfo(bucket kvdb.RBucket) (*HTLCSettleInfo, error) { b := bucket.Get(htlcSettleInfoKey) if b == nil { // Settle info is optional. @@ -413,7 +413,7 @@ func fetchHtlcSettleInfo(bucket kvdb.ReadBucket) (*HTLCSettleInfo, error) { // fetchHtlcFailInfo retrieves the failure info for the htlc. If the htlc hasn't // failed, nil is returned. -func fetchHtlcFailInfo(bucket kvdb.ReadBucket) (*HTLCFailInfo, error) { +func fetchHtlcFailInfo(bucket kvdb.RBucket) (*HTLCFailInfo, error) { b := bucket.Get(htlcFailInfoKey) if b == nil { // Fail info is optional. diff --git a/channeldb/waitingproof.go b/channeldb/waitingproof.go index dbaddaae..2ea706c8 100644 --- a/channeldb/waitingproof.go +++ b/channeldb/waitingproof.go @@ -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 kvdb.View(s.db, func(tx kvdb.ReadTx) error { + return kvdb.View(s.db, func(tx kvdb.RTx) error { bucket := tx.ReadBucket(waitingProofsBucketKey) if bucket == nil { return ErrWaitingProofNotFound @@ -158,7 +158,7 @@ func (s *WaitingProofStore) Get(key WaitingProofKey) (*WaitingProof, error) { return nil, ErrWaitingProofNotFound } - err := kvdb.View(s.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(s.db, func(tx kvdb.RTx) error { bucket := tx.ReadBucket(waitingProofsBucketKey) if bucket == nil { return ErrWaitingProofNotFound diff --git a/channeldb/witness_cache.go b/channeldb/witness_cache.go index 7f52ada5..3a91fc44 100644 --- a/channeldb/witness_cache.go +++ b/channeldb/witness_cache.go @@ -150,7 +150,7 @@ func (w *WitnessCache) LookupSha256Witness(hash lntypes.Hash) (lntypes.Preimage, // will be returned. func (w *WitnessCache) lookupWitness(wType WitnessType, witnessKey []byte) ([]byte, error) { var witness []byte - err := kvdb.View(w.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(w.db, func(tx kvdb.RTx) error { witnessBucket := tx.ReadBucket(witnessBucketKey) if witnessBucket == nil { return ErrNoWitnesses diff --git a/contractcourt/briefcase.go b/contractcourt/briefcase.go index 03a878b7..bff2f742 100644 --- a/contractcourt/briefcase.go +++ b/contractcourt/briefcase.go @@ -337,7 +337,7 @@ func newBoltArbitratorLog(db kvdb.Backend, cfg ChannelArbitratorConfig, // interface. var _ ArbitratorLog = (*boltArbitratorLog)(nil) -func fetchContractReadBucket(tx kvdb.ReadTx, scopeKey []byte) (kvdb.ReadBucket, error) { +func fetchContractReadBucket(tx kvdb.RTx, scopeKey []byte) (kvdb.RBucket, error) { scopeBucket := tx.ReadBucket(scopeKey) if scopeBucket == nil { return nil, errScopeBucketNoExist @@ -415,7 +415,7 @@ func (b *boltArbitratorLog) writeResolver(contractBucket kvdb.RwBucket, // NOTE: Part of the ContractResolver interface. func (b *boltArbitratorLog) CurrentState() (ArbitratorState, error) { var s ArbitratorState - err := kvdb.View(b.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(b.db, func(tx kvdb.RTx) error { scopeBucket := tx.ReadBucket(b.scopeKey[:]) if scopeBucket == nil { return errScopeBucketNoExist @@ -461,7 +461,7 @@ func (b *boltArbitratorLog) FetchUnresolvedContracts() ([]ContractResolver, erro Checkpoint: b.checkpointContract, } var contracts []ContractResolver - err := kvdb.View(b.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(b.db, func(tx kvdb.RTx) error { contractBucket, err := fetchContractReadBucket(tx, b.scopeKey[:]) if err != nil { return err @@ -675,7 +675,7 @@ func (b *boltArbitratorLog) LogContractResolutions(c *ContractResolutions) error // NOTE: Part of the ContractResolver interface. func (b *boltArbitratorLog) FetchContractResolutions() (*ContractResolutions, error) { c := &ContractResolutions{} - err := kvdb.View(b.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(b.db, func(tx kvdb.RTx) error { scopeBucket := tx.ReadBucket(b.scopeKey[:]) if scopeBucket == nil { return errScopeBucketNoExist @@ -774,7 +774,7 @@ func (b *boltArbitratorLog) FetchContractResolutions() (*ContractResolutions, er func (b *boltArbitratorLog) FetchChainActions() (ChainActionMap, error) { actionsMap := make(ChainActionMap) - err := kvdb.View(b.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(b.db, func(tx kvdb.RTx) error { scopeBucket := tx.ReadBucket(b.scopeKey[:]) if scopeBucket == nil { return errScopeBucketNoExist @@ -837,7 +837,7 @@ func (b *boltArbitratorLog) InsertConfirmedCommitSet(c *CommitSet) error { // NOTE: Part of the ContractResolver interface. func (b *boltArbitratorLog) FetchConfirmedCommitSet() (*CommitSet, error) { var c *CommitSet - err := kvdb.View(b.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(b.db, func(tx kvdb.RTx) error { scopeBucket := tx.ReadBucket(b.scopeKey[:]) if scopeBucket == nil { return errScopeBucketNoExist diff --git a/discovery/message_store.go b/discovery/message_store.go index 207f857f..f86ede20 100644 --- a/discovery/message_store.go +++ b/discovery/message_store.go @@ -200,7 +200,7 @@ func readMessage(msgBytes []byte) (lnwire.Message, error) { // all peers. func (s *MessageStore) Messages() (map[[33]byte][]lnwire.Message, error) { msgs := make(map[[33]byte][]lnwire.Message) - err := kvdb.View(s.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(s.db, func(tx kvdb.RTx) error { messageStore := tx.ReadBucket(messageStoreBucket) if messageStore == nil { return ErrCorruptedMessageStore @@ -238,7 +238,7 @@ func (s *MessageStore) MessagesForPeer( peerPubKey [33]byte) ([]lnwire.Message, error) { var msgs []lnwire.Message - err := kvdb.View(s.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(s.db, func(tx kvdb.RTx) error { messageStore := tx.ReadBucket(messageStoreBucket) if messageStore == nil { return ErrCorruptedMessageStore @@ -273,7 +273,7 @@ func (s *MessageStore) MessagesForPeer( // Peers returns the public key of all peers with messages within the store. func (s *MessageStore) Peers() (map[[33]byte]struct{}, error) { peers := make(map[[33]byte]struct{}) - err := kvdb.View(s.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(s.db, func(tx kvdb.RTx) error { messageStore := tx.ReadBucket(messageStoreBucket) if messageStore == nil { return ErrCorruptedMessageStore diff --git a/fundingmanager.go b/fundingmanager.go index ae7dd9d7..ac6d43c2 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -3477,7 +3477,7 @@ func (f *fundingManager) getChannelOpeningState(chanPoint *wire.OutPoint) ( var state channelOpeningState var shortChanID lnwire.ShortChannelID - err := kvdb.View(f.cfg.Wallet.Cfg.Database, func(tx kvdb.ReadTx) error { + err := kvdb.View(f.cfg.Wallet.Cfg.Database, func(tx kvdb.RTx) error { bucket := tx.ReadBucket(channelOpeningStateBucket) if bucket == nil { diff --git a/htlcswitch/decayedlog.go b/htlcswitch/decayedlog.go index 11d6054c..db27ed39 100644 --- a/htlcswitch/decayedlog.go +++ b/htlcswitch/decayedlog.go @@ -261,7 +261,7 @@ func (d *DecayedLog) Delete(hash *sphinx.HashPrefix) error { func (d *DecayedLog) Get(hash *sphinx.HashPrefix) (uint32, error) { var value uint32 - err := kvdb.View(d.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(d.db, func(tx kvdb.RTx) error { // Grab the shared hash bucket which stores the mapping from // truncated sha-256 hashes of shared secrets to CLTV's. sharedHashes := tx.ReadBucket(sharedHashBucket) diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index bbe418c9..739dc059 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -5093,7 +5093,7 @@ func (*mockPackager) AckAddHtlcs(tx kvdb.RwTx, return nil } -func (m *mockPackager) LoadFwdPkgs(tx kvdb.ReadTx) ([]*channeldb.FwdPkg, error) { +func (m *mockPackager) LoadFwdPkgs(tx kvdb.RTx) ([]*channeldb.FwdPkg, error) { if m.failLoadFwdPkgs { return nil, fmt.Errorf("failing LoadFwdPkgs") } diff --git a/htlcswitch/payment_result.go b/htlcswitch/payment_result.go index b23dbe0a..54130755 100644 --- a/htlcswitch/payment_result.go +++ b/htlcswitch/payment_result.go @@ -180,7 +180,7 @@ func (store *networkResultStore) subscribeResult(paymentID uint64) ( resultChan = make(chan *networkResult, 1) ) - err := kvdb.View(store.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(store.db, func(tx kvdb.RTx) error { var err error result, err = fetchResult(tx, paymentID) switch { @@ -226,7 +226,7 @@ func (store *networkResultStore) getResult(pid uint64) ( *networkResult, error) { var result *networkResult - err := kvdb.View(store.db, func(tx kvdb.ReadTx) error { + err := kvdb.View(store.db, func(tx kvdb.RTx) error { var err error result, err = fetchResult(tx, pid) return err @@ -238,7 +238,7 @@ func (store *networkResultStore) getResult(pid uint64) ( return result, nil } -func fetchResult(tx kvdb.ReadTx, pid uint64) (*networkResult, error) { +func fetchResult(tx kvdb.RTx, pid uint64) (*networkResult, error) { var paymentIDBytes [8]byte binary.BigEndian.PutUint64(paymentIDBytes[:], pid) diff --git a/lntest/itest/log_error_whitelist.txt b/lntest/itest/log_error_whitelist.txt index a65ce6ce..14410bf9 100644 --- a/lntest/itest/log_error_whitelist.txt +++ b/lntest/itest/log_error_whitelist.txt @@ -95,6 +95,7 @@