Commit Graph

63 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
6f60f139f4 multi: switch over import paths from roasbeef/* to btcsuite/* 2018-07-13 17:05:39 -07:00
Olaoluwa Osuntokun
19d84dd1cc
channeldb: add new migration to finalize invoice migration for outgoing payments
In this commit, we migrate the database away from a partially migrated
state. In a prior commit, we migrated the database in order to update
the Invoice struct with three new fields: add index, settle index, paid
amt.  However, it was overlooked that the OutgoingPayment struct also
embedded an Invoice within it. As a result, nodes that upgraded to the
first migration found themselves unable to start up, or call
listpayments, as the internal invoice within the OutgoignPayment hadn't
yet been updated.  This would result in an OOM typically as we went to
allocate a slice with a integer that should have been small, but may
have ended up actually being a set of random bytes, so a very large
number.

In this commit, we finish the DB migration by also migrating the
internal invoice within each OutgoingPayment.

Fixes #1538.
Fixes #1546.
2018-07-12 00:22:28 -07:00
Olaoluwa Osuntokun
dbf7e4525a
lntest: ensure we always cancel active streaming notifications 2018-07-06 12:21:54 -07:00
Olaoluwa Osuntokun
12e73f55e9
channeldb: add database migration for new node+edge update indexes
In this commit, we add a new database migration required to update old
database to the version of the database that tracks the update index for
the nodes and edge policies. The migration is straight forward, we
simply need to populate the new indexes for the all the nodes, and then
all the edges.
2018-05-31 16:30:54 -07:00
Johan T. Halseth
0735b8e0b7
channeldb: add method for fetching channels waiting for closing tx
This commit adds a new method FetchWaitingCloseChannels to the database,
used for fetching OpenChannels that have a ChanStatus != Default. These
are channels that are borked, or have had a commitment broadcasted, and
is now waiting for it to confirm.

The fetchChannels method is rewritten to return channels exclusively
based on wheter they are pending or waitingClose.
2018-04-25 09:37:25 +02:00
Olaoluwa Osuntokun
7a13378671
channeldb+contractcourt: add additional logging around co-op channel closes 2018-04-12 17:13:37 -07:00
Olaoluwa Osuntokun
800eea931f
build+multi: switch from bolt to bbolt
In this commit, we switch from boltbd/bolt to coreos/bbolt as the
former is no longer being actively maintained.
2018-03-10 19:01:13 -08:00
Daniel McNally
8543497dcc multi: fixing it's/its typos in comments 2018-02-06 19:13:07 -08:00
Conner Fromknecht
926949ef0f
channeldb/db: adds FetchClosedChannel
This commit adds a FetchClosedChannel method to the
channeldb, which allows querying based on a known
channel point. This will be used in the nursery to
load channel close summaries, which can be used to
provide more accurate height hints when recovering
from failures.
2018-01-24 15:38:50 -08:00
Conner Fromknecht
95b788e9a6
channeldb/db: exposes Path method, useful for testing 2018-01-05 13:47:17 -08:00
Matt Drollette
adf0d98194 multi: fix several typos in godoc comments 2017-12-17 18:40:05 -08:00
Olaoluwa Osuntokun
6f51b941df
multi: fix linter errors 2017-11-10 19:51:13 -08:00
Olaoluwa Osuntokun
06e6649da5
channeldb: update channel closing methods to respect new on-disk structure 2017-11-10 19:50:50 -08:00
Olaoluwa Osuntokun
385818307b
channeldb: update FetchOpenChannel to traverse new chain bucket 2017-11-10 19:50:49 -08:00
Olaoluwa Osuntokun
2dcd82e779
channeldb: add new MarkAsOpen method to OpenChannel struct
In this commit we add a new MarkAsOpen method to the OpenChannel
struct. This method replaces the existing MarkChannelAsOpen method
which targeted the database struct itself.
2017-11-10 19:50:44 -08:00
Conner Fromknecht
6ffe33f01a lnw+ba+utxon+cdb: reverts OutPoint and TxOut encoding 2017-08-25 17:56:50 -07:00
Philip Hayes
f0aa186a56 channeldb+utxonursery+lnwire: use lnwire's OutPoint,TxOut serialization 2017-08-25 17:56:50 -07:00
Olaoluwa Osuntokun
1fb9d2e44e
channeldb: reset database version back to zero
As we removed the prior migration in an earlier commit, we now reset
the version of the database back to zero (no migrations needed).
2017-07-30 17:48:04 -07:00
Olaoluwa Osuntokun
4b8d052afc
channeldb: replace opening height will short chan ID in OpenChannel
This commit modifies the OpenChannel struct to include the full short
channel ID rather than simply the opening height. This new field will
be needed by an upcoming change to uniformly switch to using short
channel ID’s when forwarding HTLC’s due to the change in per-hop
payloads.
2017-06-16 22:28:58 +02:00
Olaoluwa Osuntokun
66ba2e862c
channeldb: store the funding transaction broadcast height for channels
This commit expands the field within the OpenChannel struct in order to
start tracking the height that the funding transaction was initially
broadcast. Other sub-systems within lnd can now use this data to give a
more accurate height hint to the ChainNotifier, or to use during the
funding workflow to decide if a channel should be forgotten after it
fails to confirm for N blocks.
2017-06-05 19:15:44 -07:00
Olaoluwa Osuntokun
a5113c2439
channeldb+funding: track opening height using MarkChannelAsOpen
This commit modifies the OpenChannel structure on-disk to also track
that opening height of a channel. This change is being made in order to
make and more light client friendly. A follow up commit will modify
several areas of the codebase to use this new functionality.
2017-05-11 15:20:33 -07:00
Olaoluwa Osuntokun
826dbbd1f7
channeldb: add new method to db, MarkChanFullyClosed
This commit adds a new method to the database which allows callers to
mark a channel as fully closed once certain conditions have been
reached. If a channel was cooperatively closed, then it can be marked
as fully closed as soon as the channel has been confirmed. If the
channel was marked as force closed, then it should be marked as closed
as soon as _all_ the funds in limbo have been swept.
2017-05-04 17:39:03 -07:00
Olaoluwa Osuntokun
f2f3774cec
channeldb: add new method to db, FetchClosedChannels
This commit builds upon the prior commit by adding a new method to
allows callers to query the state of all closed (fully) and pending
closed channel within the database.
2017-05-04 17:39:00 -07:00
Andrey Samokhvalov
61991a1c89 lnd: fix latest goclean.sh lint warning 2017-03-13 16:30:23 -07:00
Andrey Samokhvalov
fd97a4bd19 lnd: partially fix golint warnings 2017-03-13 16:30:23 -07:00
Andrey Samokhvalov
8fb54782e2 lnd: fix gosimple warnings 2017-03-13 16:30:23 -07:00
bryanvu
3e02ea11ef channeldb: added isPending flag and queries
In order to facilitate persistence during the funding process, added
the isPending flag to channels so that when the daemon restarts, we can
properly re-initialize the chain notifier and update the state of
channels that were going through the funding process.
2017-02-24 11:37:33 -08:00
Olaoluwa Osuntokun
59615b3cb2
channedb: add db migration for databases before delivery script bug fix 2017-02-08 13:05:45 -08:00
Olaoluwa Osuntokun
e8e53a4b91
channeldb: fix channel corruption bug upon channel closure
This commit fixes a bug which would previously lead to corruption of
the channel state when a node had one or more channels open and one of
them was closed either forcibly or cooperatively. The source of the bug
itself as a typo: rather than using the construed `deliveryKey`
variable to fetch/put/delete the delivery scripts, `deliveryScriptsKey`
(the key prefix itself) as used. This bug would cause the database to
be unable to read _any_ channel from the database after one was
deleted, as each channel would actually be reading/writing-to the
_exact same_ delivery script.

The fix for the bug itself is simple: eliminate the typo.
2017-02-07 19:54:51 -08:00
Olaoluwa Osuntokun
7f98e8e5f1
channeldb: fix warnings found by go vet 2017-02-07 16:52:04 -08:00
Olaoluwa Osuntokun
5889331422
channeldb: improve error messages when unable to read channel 2017-02-07 16:41:20 -08:00
Trevin Hofmann
40c7bac3aa multi: fix a variety of typos throughout the repo 2017-01-17 17:02:56 -08:00
Olaoluwa Osuntokun
68ed4f3661
channeldb: ensure the edge index bucket is created during creation
Previously, the edge index bucket which maps a channelPoint ->
channelID wasn’t properly created one start up during the initial
creation of the database. This caused some extraneous failure as
queries would unnecessarily fail with bucket non-existence errors.

To fix this we now properly create the bucket on start up if the
database doesn’t exist, and also properly delete the bucket within the
Wipe() function.
2016-12-27 16:44:10 -08:00
Olaoluwa Osuntokun
597b4ee3d3
channeldb: Open is no longer dependant on a specific set of chain params 2016-12-27 16:43:19 -08:00
Olaoluwa Osuntokun
12538ea922
channeldb: add support for channel graph pruning
This commit adds support for channel graph pruning, which is the method
used to keep the channel graph in sync with the current UTXO state. As
the channel graph is essentially simply a subset of the UTXO set, by
evaluating the channel graph with the set of outfits spent within a
block, then we’re able to prune channels that’ve been closed by
spending their funding outpoint. A new method `PruneGraph` has been
provided which implements the described functionality.

Upon start up any upper routing layers should sync forward in the chain
pruning the channel graph with each newly found block. In order to
facilitate such channel graph reconciliation a new method `PruneTip`
has been added which allows callers to query current pruning state of
the channel graph.
2016-12-27 16:43:12 -08:00
Olaoluwa Osuntokun
e39dc9eec1
channeldb: add storage of an on-disk directed channel graph
This commit introduces a new capability to the database: storage of an
on-disk directed channel graph. The on-disk representation of the graph
within boltdb is essentially a modified adjacency list which separates
the storage of the edge’s existence and the storage of the edge
information itself.

The new objects provided within he ChannelGraph carry an API which
facilitates easy graph traversal via their ForEach* methods. As a
result, path finding algorithms will be able to be expressed in a
natural way using the range methods as a for-range language extension
within Go.

Additionally caching will likely be added either at this layer or the
layer above (the RoutingManager) in order keep queries and outgoing
payments speedy. In a future commit a new set of RPC’s to query the
state of a particular edge or node will also be added.
2016-12-07 22:50:19 -08:00
Olaoluwa Osuntokun
5a668c9321
channeldb: fully initialize meta-data bucket during DB creation 2016-11-27 18:49:09 -08:00
Olaoluwa Osuntokun
7454b7df95
channeldb: slightly refactor the [Fetch|Put]Meta methods
This commit performs a slight refactoring of the internals (and API) of
the [Fetch|Put]Meta methods. The changes are rather minor and simply
eliminate the conditional branching structure with usage of an internal
function. This new form is much easier to follow.
2016-11-27 18:44:23 -08:00
Olaoluwa Osuntokun
5b2f9a5b69
channeldb: modify base DB version to start at 0, not 1 2016-11-27 18:37:13 -08:00
Olaoluwa Osuntokun
1e710b73a0
channeldb: properly handle ErrMetaNotFound error within syncVersions 2016-11-27 18:36:24 -08:00
Olaoluwa Osuntokun
8312ce587a
channeldb: embed the instance of boltb within DB struct
This commit modifies the composition of the boltdb pointer within the
DB struct to use embedding.

The rationale for this change is that the daemon may soon store some
semi-transient items within the database which requires us to expose
the boltdb’s transaction API. The logic for serialization of this data
will likely lie outside of the channeldb package as the items that may
be stored in the future will be specific to the current sub-systems
within the daemon and not generic channel related data.
2016-11-27 18:35:55 -08:00
Olaoluwa Osuntokun
b70d1f8cfe
channeldb: move .SyncVersions() into .Open(), minor migration cleanups
This commit unexports the SyncVerions PR, in favor of making it private
and moving it into the .Open() method. With this change, callers no
longer need worry about ensuring the database version is up to sync
before usage, as it will happen automatically once the database is
opened.

This commit also unexports some additional variables within the package
that don’t need be consumed by the public, and exports the
DbVersionNumber attribute on the meta struct. Finally some minor
formatting fixes have neen carried out to ensure the new code more
closely matches the style of the rest of the codebase.
2016-11-22 16:00:02 -06:00
Andrey Samokhvalov
c53ea091dd channeldb: added channeldb versioning
In this commit the upgrade mechanism for database was added which makes he current schema rigid and upgradeable. Additional bucket 'metaBucket' was added which stores
    key that house meta-data related to the current/version state of the database. 'createChannelDB' was modified to create this new bucket+key during initializing. Also
    backup logic was added which makes a complete copy of the current database during migration process and restore the previous version of database if migration failed.
2016-11-22 15:25:21 -06:00
Olaoluwa Osuntokun
8a4ba58d5b
channeldb: ensure the nodeInfoBucket is deleted within .Wipe() 2016-11-07 18:19:05 -08:00
Olaoluwa Osuntokun
9191fbd317
channeldb: add FetchAllChannels method to return all active channels
This commit introduces a new method to channeldb: ‘FetchAllChannels’.
This method can be used to obtain the state of all active (currently
open) channels within the database. This method can be used for compute
basic channel-based metrics or exposed as an RPC in order to allow
clients to display/query channel data.
2016-10-26 14:53:26 -07:00
Olaoluwa Osuntokun
cb328e65c4
channeldb: switch to using a full public key to identity channel->node
This commit slightly modifies the existing structure of the channeldb
scheme to replace the former concept of a “nodeID” with simply the
compressed public key of the remote node. This change paves the way for
adding useful indexes mapping a node to all it’s active channels and
the other way around.

Additionally, the current channeldb code was written before it was
agreed by many of those implementing Lightning that a node’s ID will
simply be its compressed public key.
2016-10-25 16:11:30 -07:00
Olaoluwa Osuntokun
d109bd9298
channeldb: add bucket for storing p2p counterparty meta-data
This commit adds a new bucket to the database which is dedicated to
storing data pertaining to p2p related reachability for direct channel
counter parties. The data stored in this new bucket can be used within
heuristics when deciding to unilaterally close a channel due to
inactivity. Additionally, all known reachable IP addresses for a
particular LinkNode are to be stored and updated within the database in
order to facilitate the establishment of persistent connections to
direct channel counter parties.
2016-10-25 16:06:32 -07:00
Olaoluwa Osuntokun
62b37f45f5
channeldb: include in the invoice bucket when wiping and initializing the db 2016-09-23 15:06:06 -07:00
Olaoluwa Osuntokun
2235785ed8
channeldb: add some missing nil checks 2016-09-12 19:06:57 -07:00
Olaoluwa Osuntokun
dc00514c42 channeldb: remove EncryptorDecryptor interface
This commit removes the EncryptorDecryptor interface, and all related
usage within channeldb. This interface is no longer needed as wallet
specific secrets such as private keys are no longer stored within the
database.
2016-09-08 12:22:12 -07:00