Commit Graph

60 Commits

Author SHA1 Message Date
Micah Lerner
1295bfe096 channeldb: fix channel_test scoping error 2017-12-03 16:34:52 -08:00
Olaoluwa Osuntokun
12e5951434
channeldb: extend ChannelConfig with new HtlcBasePoint key 2017-11-16 20:00:01 -08:00
Olaoluwa Osuntokun
6f51b941df
multi: fix linter errors 2017-11-10 19:51:13 -08:00
Olaoluwa Osuntokun
29f2f88abc
channeldb: expand TestChannelStateTransition to expertise new state transition related methods
In this commit we’ve extended the TestChannelStateTransition method to
exercise the new state transition related messages. This includes
ensuring that when we add a new dangling commitment, and then the
remote party revokes it, then the on-disk state is update accordingly.
2017-11-10 19:50:50 -08:00
Olaoluwa Osuntokun
da7a5f7c4e
channeldb: update tests to respect new API's 2017-11-10 19:50:49 -08:00
Andrey Samokhvalov
7aa7cb1caf channeldb: add persistance of the onion blob
In this commit htlc channeldb representation have been augmented
with onion blob field, and (de)serialisaion functions have been changed
to make the onion blob persistant.
2017-11-09 16:38:58 -08:00
Jim Posen
a13ad0a339 multi: Fix various typos. 2017-10-25 13:20:54 -07:00
Olaoluwa Osuntokun
74470cf7d0
channeldb: update ChannelConstraints+OpenChannel to use lnwire.MilliSatoshi 2017-08-22 00:52:17 -07:00
Olaoluwa Osuntokun
88c15abeef
channeldb: remove RevocationDelay field from the HTLC struct
This commit removes the RevocationDelay field from the HTLC struct as
with the latest commitment transaction scheme, it is no longer needed.
This is due to the fact the the delay is now observed when an on-chain
HTLC claim is attempted, rather than from Shane the HTLC itself has
been broadcast.
2017-07-30 17:48:32 -07:00
Olaoluwa Osuntokun
5ad6c23848
channeldb: update tests to reflect latest OpenChannel/HTLC API changes 2017-07-30 17:48:26 -07:00
Olaoluwa Osuntokun
1be4d67ce4
multi: run all test instances in parallel 2017-06-17 01:00:07 +02: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
75d5396445
channeldb: change MinFeePerKb to FeePerKw in OpenChannel struct
This commit modifies the name of a field in the OpenChannel struct to
better reflect its actual usage within this protocol. The FeePerKw
represents the amount of satoshi to be paid as fees per kilo-weight.
This field is set at the opening of a transaction and will be able to
be updated properly via the usage of the update_fee method.
2017-05-16 18:44:01 -07:00
Olaoluwa Osuntokun
68dbbb046b
channeldb: add total time locked balance to CloseChannelSummary
This commit adds the total time locked balance of a closed channel at
closure time to the CloseChannelSummary struct. With this information,
we now provide sub-systems within the daemon further knowledge which
can aide them in properly handling querying for the state of pending
close transactions, or if they should watch a channel for closure or
not.
2017-05-14 19:03:08 -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
35fd800083
channeldb: add test for new channel closure persistence 2017-05-04 17:39:05 -07:00
Olaoluwa Osuntokun
c9511da22f
channeldb: add new method to channel state, RevocationLogTail
This commit adds a new method to the channel state: RevocationLogTail.
This new method will return the information concerning the latest
revoked state of the remote party’s commitment chain.

This new data can be used to properly initialize the states of the
in-memory commitment chains on node start up.
2017-03-24 16:09:14 -07:00
Andrey Samokhvalov
f2843dd4c9 lnd: fix gofmt warnings 2017-03-13 16:30:23 -07:00
Olaoluwa Osuntokun
9adc5f6484
lnwallet+channeldb: update callers to shachain API changes 2017-02-24 16:31:45 -08:00
bryanvu
59763ebc7e channeldb: persist numConfsRequired in OpenChannel.
When a pending channel is persisted and then reloaded upon system startup
it's necessary to also persist the number of confirmations that will be required
before the pending channel can be opened.
2017-02-24 11:37:33 -08: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
Andrey Samokhvalov
f86557c3e4 channeldb+lnwallet: replace elkrem with shachain
In this commit the initial implementation of revocation hash
generation 'elkrem' was replaced with 'shachain' Rusty Russel
implementation which currently enshrined in the spec. This alghoritm has
the same asymptotic characteristics but has more complex scheme
to determine wish hash we can drop and what needs to be stored
in order to be able to achive full compression.
2017-02-22 16:49:29 -08:00
Christopher Jämthagen
97aa478ce1 channeldb: change [4]byte obsfucator to [6]byte in test 2017-02-22 15:46:59 -08:00
Olaoluwa Osuntokun
bcde70e74a
channeldb: fix bug when writing revocation log states
This commit fixes a bug that was introduced when we moved to using
64-bit integers for storing the revocation log state. When we made this
change, we forgot to increase the size of the buffer which stores the
key for the particular channel state from 40 to 44 bytes to account for
the 4 additional bytes in the new 64-bit integer.

This bug has been fixed by properly sizing the key buffer. We’ve also
added an additional test to ensure that we retrieve the proper state
after multiple state updates.
2017-02-21 01:43:31 -08:00
Olaoluwa Osuntokun
d87e795e2a
channeldb: ensure all state is deleted for a channel by CloseChannel
This commit addresses some lingering TODO’s which ensure that related
state to a channel is properly deleted by the CloseChannel method.
Previously the values for the respective dust-limits of either side,
the on-disk HTLC’s, and any entries the revocation log for the channel
weren’t being properly deleted.

Additionally, we now modify the checks within the unit tests to ensure
that we can still read the channel from disk w/o running into an error
(thought the slice will be blank), and also the the revocation log is
properly garbage collected.
2017-02-07 16:40:46 -08:00
Trevin Hofmann
40c7bac3aa multi: fix a variety of typos throughout the repo 2017-01-17 17:02:56 -08:00
Olaoluwa Osuntokun
5affed38fc
multi: update btcsuite API's to latest upstream changes
This commit makes a large number of minor changes concerning API usage
within the deamon to match the latest version on the upstream btcsuite
libraries.

The major changes are the switch from wire.ShaHash to chainhash.Hash,
and that wire.NewMsgTx() now takes a paramter indicating the version of
the transaction to be created.
2017-01-05 13:56:34 -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
587bde5636
channeldb: ensure the cleanUp func is always run during tests 2016-12-27 16:43:17 -08:00
Andrey Samokhvalov
202fce5501 channeldb: add TheirDustLimit and OurDustLimit fields in OpenChannel 2016-12-13 11:01:57 -08:00
Olaoluwa Osuntokun
60946e4ddc
channeldb: add method to OpenChannel for querying num updates
This commit adds a new method to the `OpenChannel` struct:
CommitmentHeight(). This method allows multiple callers holding the
same instance of an OpenChannel struct tied to the same on-disk channel
to consistently query the current commitment height for a channel. Such
a modification will prove useful later as sections of the code-base are
separated in order to allow more vigilant watching of channel breaches.
2016-11-27 19:10:13 -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
81e65e00e5
channeldb: include the output index within stored HTLC's 2016-11-17 18:32:55 -08:00
Olaoluwa Osuntokun
66571e4464
channeldb: add new field to store the state hint obsfucator 2016-11-15 18:51:54 -08:00
Olaoluwa Osuntokun
bc3e16dd13
channeldb: explicitly store if we're the channel initiator or not
This commit modifies the existing OpenChannel struct slightly to store
a bool which indicates if we were the one who initially initiated the
channel or not. This information is relevant as in the current draft of
the specification, much of the fee related negotiation is contingent on
who initiated the channel.
2016-11-15 18:50:31 -08:00
Olaoluwa Osuntokun
9b41d814dc
channeldb: remove TotalNetFees from OpenChannel
This commit removes all prior fee tracking attributes along with the
persistence code from OpenChannel. The rationale is that fees actually
don’t exist at the channel level, and instead should be tracked at
higher level of abstraction as fees come from the inbound/outbound
satoshi spread.
2016-11-15 18:47:14 -08:00
Olaoluwa Osuntokun
729e586eb6
channeldb: store an enum indicating channel type in OpenChannel
This commit modifies the OpenChannel struct along with all related
persistent to additional store a single byte which indicates the exact
type of the channel. This may be useful in the future as higher level
behavior may change depending on the precise type of the channel.
2016-11-15 17:41:27 -08: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
andrew.shvv
e515710a7d multi: use witnessScript everywhere instead of redeemScript
This commit consists of a mass variable renaming to call the pkScript being executed for segwit outputs the `witnessScript` instead of `redeemScript`. The latter naming convention is generally considered to be reserved for the context of BIP 16 execution. With segwit to be deployed soon, we should be using the correct terminology uniformly through the codebase. 

In addition some minor typos throughout the codebase has been fixed.
2016-10-15 16:02:09 -07:00
Olaoluwa Osuntokun
e60778a867
channeldb: split RecordChannelDelta into two distinct methods
This commit splits the previously added RecordChannelDelta method into
two distinct methods: UpdateCommitment and AppendToRevocationLog. The
former method is to be used once the local party revokes their current
commitment, and the latter method to be used once the remote party
revokes their current commitment.

With the addition of the UpdateCommitment method, the active HTLC’s
from the local node’s point of view are now persisted to disk.
Snapshots returned by the channel now also includes the current set of
active HTLC’s. In order to maintain thread safety the channels mutex is
now grabbed within methods which modify/read state but don’t do so
solely via a boltDB transaction.

The tests have been updated to account for the storage of HTLC’s needed
in order to assert proper behavior.
2016-09-12 19:07:00 -07:00
Olaoluwa Osuntokun
e83a6a0f6c
channeldb: remove revocation keys from channel deltas
This commit removes the revocation hash/keys from the channel deltas.
In the case of an uncooperative closure, we can efficiently re-generate
the proper elkrem pre-image so this storage was completely unnecessary
2016-09-12 19:06:52 -07:00
Olaoluwa Osuntokun
c1b98da530
channeldb: also pass in current tx and sig into RecordChannelDelta 2016-09-12 19:06:49 -07:00
Olaoluwa Osuntokun
6684f6aedf
channeldb: implement commitment state update log
This commit implements a state update log which is intended the record
the relevant information for each state transition on disk. For each
state transition a delta should be written recording the new state. A
new method is also provided which is able to retrieve a previous
channel state based on a state update #.

At the moment no measures has been taken to optimize the space
utilization of each update on disk. There are several low-hanging
fruits which can be addressed at a later point. Ultimately the update
log itself should be implemented with an append-only flat file at the
storage level. In any case, the high level abstraction should be able
to maintained independent of differences in the on-disk format itself.
2016-09-12 19:06:44 -07:00
Olaoluwa Osuntokun
bdb6566076
channeldb: only store public keys for multi-sig + commitment keys
This commit removes the storage+encryption of private keys within
channeldb. We no longer need to encrypt these secrets before storing as
the base wallet is now expected to retain full control of these secrets
rather than the database.

As a result, we now only store public keys within the database.
2016-09-08 12:25:12 -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
Olaoluwa Osuntokun
1f7d9b6425
channeldb: also store their current revocation hash
We now also store their current revocation hash which is given to us
along with the revocation key once an initial HTLC is added to a
commitment transaction.
2016-07-05 16:48:31 -07:00
Olaoluwa Osuntokun
06af4b130f
channeldb: remove theirCommitTx, store latest commit sig 2016-07-05 16:44:52 -07:00
Olaoluwa Osuntokun
582b83ada3
channeldb: update channel state to revocation keys + new elkrem API
This commit updates the stored on-disk channel state to store a current
revocation key rather than a revocation hash. This change coincides
with the new commitment transaction format which uses revocation keys
rather than hashes.

Additionally, this commit updates the decoding/encoding of local+remote
elkrem trees to the latest changes in the elkrem API.
2016-06-30 11:40:12 -07:00
Olaoluwa Osuntokun
1a48db3039
channeldb: stored un-revoked hashes are now 32 bytes 2016-06-26 22:59:02 -07:00