Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi: rename kvdb Read* types to R* #4252

Merged
merged 4 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions autopilot/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions breacharbiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions chainntnfs/height_hint_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions channeldb/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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.
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
24 changes: 12 additions & 12 deletions channeldb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions channeldb/duplicate_payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Loading