Commit Graph
100 Commits
Author SHA1 Message Date
Olaoluwa Osuntokun 7a14b6bb32 Merge pull request #778 from cfromknecht/switch-wallet-api
Switch Persistence [2.5/4]: Establish Switch-Sphinx-Wallet APIs for Switch Persistence
2018-03-09 18:08:31 -08:00
Olaoluwa Osuntokun 7bad5458d7 Merge pull request #777 from cfromknecht/fwdpkg-staging
Switch Persistence [2/4] Infra for Forwarding Packages
2018-03-09 16:15:46 -08:00
Olaoluwa Osuntokun 759d2c9134 Merge pull request #665 from wilmerpaulino/close-all-channels
cmd/lncli: add closeallchannels command
2018-03-09 15:52:21 -08:00
Olaoluwa Osuntokun e184bbcb54 funding: don't case to a net.TCPAddr to support tor stream isolation
In this commit, we fix an existing bug in the funding manager, that can
be triggered if the user is connecting to a node over Tor, and then
attempts to open a channel. An existing fix was added for the case that
the receiving node established the channel, but this now makes that case
symmetric.
2018-03-09 14:22:23 -08:00
Olaoluwa Osuntokun 51a3cab39c htlcswitch: fix race in forwarding log test by grabbing log mtx 2018-03-08 20:11:49 -08:00
Olaoluwa Osuntokun 649be5ee0b Merge pull request #775 from cfromknecht/sphinx-replay
Switch Persistence [1/4]: Infra for Sphinx Batched Decoding and Replay Protection
2018-03-08 23:03:01 -05:00
Olaoluwa Osuntokun 855e85511e Merge pull request #779 from Roasbeef/unsigned-msat-and-fee-fixes
lnwire+lnwallet+htlcswitch: modify lnwire.MilliSatoshi to be unsigned, fix fee related bugs that emerged
2018-03-08 22:28:16 -05:00
Olaoluwa Osuntokun 30c92ea7f1 Merge pull request #808 from cfromknecht/upd-btcwallet-for-deadlock-fix
update btcwallet+keychain to include waddrmgr deadlock fix
2018-03-08 21:04:30 -05:00
Olaoluwa Osuntokun 97b7eb226d lnrpc: update photo comments to fix api.lightning.community tool 2018-03-08 17:06:34 -08:00
Olaoluwa Osuntokun 8d35ea381e zpay32: remove test case with negative amt 2018-03-08 12:50:50 -05:00
Olaoluwa Osuntokun 7031b5d217 htlcswitch: modify forwarding fee assertion to compare emperical fees
In this commit, we fix a bug that was uncovered by the recent change to
lnwire.MilliSatoshi. Rather than manually compute the diff in fees,
we’ll directly compare the fee that is given against the fee that we
expect.
2018-03-08 12:50:49 -05:00
Olaoluwa Osuntokun b8d0df998a lnwallet: when validating fee updates, ensure newFee < balance 2018-03-08 12:50:49 -05:00
Olaoluwa Osuntokun ac90a8288e lnwallet: precalculate fees in mSAT to avoid multiple conversions 2018-03-08 12:50:49 -05:00
Olaoluwa Osuntokun 217166fb10 lnwallet: within validateCommitmentSanity check for balance underflow
In this commit, we add an additional check within
validateCommitmentSanity due to the recent change to unsigned integers
for peer balances in the channel state machine. If after evaluation
(just applying HTLC updates), the balances are negative, then we’ll
return ErrBelowChanReserve.
2018-03-08 12:50:48 -05:00
Olaoluwa Osuntokun 5f5e4554cb lnwallet: if the initiator is unable to pay fees, then consume their entire output
In this commit, we add logic to account for an edge case in the
protocol. If they initiator if unable to pay the fees for a commitment,
then their *entire* output is meant to go to fees. The recent change to
properly interpret balances as unsigned integers (within the protocol)
let to the discovery of this missed edge case.
2018-03-08 12:50:48 -05:00
Olaoluwa Osuntokun 19bc477b9a lnwallet: update interface tests to account for recent lnwire.MilliSatoshi change
lnwire.MilliSatoshi is now a signed integer, as a result, we’ll return
a different error if our balances go to negative due to the inability
to pay a the set fee.
2018-03-08 12:50:48 -05:00
Olaoluwa Osuntokun 8425a35684 lnwallet: in NewChannelReservation ensure commit fees are payable
In this commit, we fix a bug introduced by the recent change of
lnwire.MilliSatoshi to be an unsigned integer. After this change an
integer underflow was left undetected, as a result we’ll now
momentarily cast to a signed integer in order to ensure that both sides
can pay the proper fee.
2018-03-08 12:50:47 -05:00
Olaoluwa Osuntokun 5ecef17e0f lnwallet: modify logging to display mSAT amount if funding constrains invalid 2018-03-08 12:50:47 -05:00
Olaoluwa Osuntokun f83d56c91f lnwire: modify lnwire.MilliSatoshi to be an unsigned integer
In this commit, we modify lnwire.MilliSatoshi to be an unsigned
integer. We do this as all values within the specification are meant to
be unsigned unless otherwise specified. Our usage of signed integers to
this date has caused some compatibility issues with the other
implementations, so this is the first step to reconciling these
compatibility issues.
2018-03-07 13:29:58 -05:00
Olaoluwa Osuntokun 116406c7ec Merge pull request #769 from Roasbeef/new-lightning-key-derivation
multi: modify key derivation to be fully deterministic, remove p2pkh, wallet now witness only
2018-03-06 17:21:55 -05:00
Olaoluwa Osuntokun 1c5f1885d9 Merge pull request #784 from halseth/protocol-errors
Wire protocol errors
2018-03-06 16:54:49 -05:00
Olaoluwa Osuntokun 18e9475a9a lnwallet/btcwallet: grab best header timestamp directly from wallet
In this commit, we modify the way we obtain the current best header
timestamp. In doing this, we fix an intermittent flake that would pop
up at times on the integration tests. This could occur as if the wallet
was lagging behind the chain backend for a re-org, then a hash that the
backend knew of, may not be known by the wallet.

To remedy this, we’ll take advantage of a recent change to btcwallet to
actually include the timestamp in its sync state.
2018-03-06 16:04:07 -05:00
Olaoluwa Osuntokun 78cbe7a141 lnd: verify proper keychain derivation version upon initial creation 2018-03-06 16:04:06 -05:00
Olaoluwa Osuntokun dc2404f289 contractcourt: update test due to recent SignDescriptor API changes 2018-03-06 16:04:06 -05:00
Olaoluwa Osuntokun d98e7a730d lnwallet: update integration tests due to recent API changes 2018-03-06 16:04:06 -05:00
Olaoluwa Osuntokun 7edca37918 build: update to use latest btcwallet with scoped key managers 2018-03-06 16:04:05 -05:00
Olaoluwa Osuntokun 9981c4ce38 lnd: populate the secret key ring in the lnwallet config 2018-03-06 16:04:05 -05:00
Olaoluwa Osuntokun 78ef09c9d3 cmd/lncli: remove the --witness_only flag from walletbalance
This flag is no longer needed, as the call will now only return the
active segwit balance.
2018-03-06 16:04:05 -05:00
Olaoluwa Osuntokun f2192f1b90 cmd/lncli: remove p2pkh as an option for the new address command 2018-03-06 16:04:05 -05:00
Olaoluwa Osuntokun 1669e3d5ec lnd: use first key in keychain.KeyFamilyNodeKey as our nodeID
In this commit, we update lnd to now access the deterministic
keychain.KeyRing struct in order to obtain our identity public key.
With this change, if the user recovers their wallet with the same seed,
then they’ll have access to the same prior node identity. This change
also makes it easy for us to support node key rotation in the future by
bumping up our requested index.
2018-03-06 16:04:04 -05:00
Olaoluwa Osuntokun b41222b316 rpc: update RPC server to disallow p2pkh adds, assume segwit for ConfirmedBalance 2018-03-06 16:04:04 -05:00
Olaoluwa Osuntokun 525cca02e2 lnrpc: remove the PUBKEY_HASH adds type, WalletBalance is segwit by default 2018-03-06 16:04:04 -05:00
Olaoluwa Osuntokun a144018e98 lnwallet: remove p2pkh as an address type, wallet is now pure segwit
In this commit, we modify the mechanics of the wallet to only allow
derivation of segwit-like addresses. Additionally, the ConfirmedBalance
method on the WalletController now only has a single argument, as it’s
assumed that the wallet is itself only concerned with segwit outputs.
2018-03-06 16:04:03 -05:00
Olaoluwa Osuntokun 4b20e805fe multi: update packages due to recent SignDescriptor and WalletController changes 2018-03-06 16:04:03 -05:00
Olaoluwa Osuntokun 0d1a40fb46 lnwallet: update tests due to recent API changes 2018-03-06 16:04:03 -05:00
Olaoluwa Osuntokun 5b063a0691 lnwallet: modify the way we derive revocation roots to be deterministic
In this commit, we modify the way we generate the secrets for
revocation roots to be fully deterministic. Rather than use a special
key and derive all sub-roots from that (mixing in some “salts”), we’ll
use the proper keychain.KeyFamily instead. This ensures that given a
static description of the channel, we’re able to re-derive our
revocation root properly.
2018-03-06 16:04:02 -05:00
Olaoluwa Osuntokun a41f00e2d6 lnwallet: update funding flow to utilize keychain.KeyRing
In this commit, we modify the funding flow process to obtain all keys
necessary from the keychain.KeyRing interface. This ensure that all
keys we generate are fully deterministic.
2018-03-06 16:04:02 -05:00
Olaoluwa Osuntokun fe12c908f8 lnwallet: add an instance of keychain.SecretKeyRing to the Config struct 2018-03-06 16:04:02 -05:00
Olaoluwa Osuntokun 22ee0a7576 lnwallet: update state machine due to channeldb and SignDescriptor changes 2018-03-06 16:04:02 -05:00
Olaoluwa Osuntokun 705661a39e channeldb: replace raw keys in ChannelConfig with keychain.KeyDescriptor
In this commit, we remove references to raw keys from the main
ChannelConfig struct and instead replace it with usage of
keychain.KeyDescriptor. We do this, as the ChannelConfig as it stands
is a near complete static description of a channel. In the future, it
will be possible to export these static descriptions as backups. We
prefer the KeyDescriptor of a plain PublicKey, as the KeyLocator
portion of the struct allows a stateless signer to re-derive the keys
as needed when signing.
2018-03-06 16:04:01 -05:00
Olaoluwa Osuntokun af1fd65655 lnwallet/btcwallet: update Signer implementation to use keychain.KeyDescriptor 2018-03-06 16:04:01 -05:00
Olaoluwa Osuntokun a0dc06b954 lnwallet: update script_utils and tests due to SignDescriptor API change 2018-03-06 16:04:01 -05:00
Olaoluwa Osuntokun 73dd1536ed lnwallet: update signdescriptor_test.go due to latest API changes 2018-03-06 16:04:00 -05:00
Olaoluwa Osuntokun 9ccdcaf747 lnwallet: update the SignDescriptor struct to use keychain.KeyDescriptor
In this commit, we update the SignDescriptor struct to instead use the
keychain.KeyDescriptor struct inplace of a raw public key. We do this
as this allows for a recovery mode, where the caller doesn’t know what
key was used exactly, but remembers the precise KeyDescriptor. A
stateless signer is still able to re-derive the proper key, as it’s
given the full path.
2018-03-06 16:04:00 -05:00
Olaoluwa Osuntokun 93280ad60a lnwallet/btcwallet: update implementation to account for recent API changes
The new version of the internal core of btcwallet now uses KeyScopes
rather than address types to derive particular addresses. As a result,
in this commit, we update our API usage to ensure that proper addresses
are still derived.
2018-03-06 16:04:00 -05:00
Olaoluwa Osuntokun 6290a520fd lnwallet/btcwallet: remove pruned interface methods
These methods are no longer a part of the interface. As a result, we
can safely delete them.
2018-03-06 16:04:00 -05:00
Olaoluwa Osuntokun a26367f3cb lnwallet: remove NewRawKey and FetchRootKey from the WalletController interface
In this commit, we remove two methods from the WalletController
interface which were previously used by the funding reservation process
(NewRawKey) and the p2p network (FetchRootKey) in order to derive
various keys for operation. This methods are no longer necessary as the
KeyRing interface implements the functionality in a deterministic
manner.
2018-03-06 16:03:59 -05:00
Olaoluwa Osuntokun cd068d8888 keychain: add initial set up interface-level tests 2018-03-06 16:03:59 -05:00
Olaoluwa Osuntokun d6f54b30fc keychain: add a btcwallet implementation of the KeyRing and SecretKeyRing interfaces 2018-03-06 16:03:59 -05:00
Olaoluwa Osuntokun aebe7f35dc keychain: introduce new package for deterministic key derivation + seed
In this commit, we add a new package to lnd: the keychain package. The
role of this package is to house all the interfaces that lnd will use
to generate the various keys it needs to create contracts and operate
within the network. Additionally, we also use this package to define a
deterministic key derivation scheme, that can be implemented by any
software/hardware that partially understands BIP43-like derivation.

The first version (v0) of the keychain schema is very simple. We re-use
BIP43, with a slight twist. Re-using BIP43 lets us leverage all the
existing libraries out there as far as compatibility. The purpose used
is 1017, and the coin type, the particular coin type of the chain where
the keys are meant to be used. Within our schema, we define multiple
“key families”. Each key family is actually just manifested as a new
“account” within the BIP44/43 family. With this schema, if we have
static description of the keys used within a channel, given the seed,
and the “KeyLocator”, we can re-derive all keys necessary be able to
re-sign for the channel.
2018-03-06 16:03:58 -05:00
Olaoluwa Osuntokun 614e0b3816 Merge pull request #787 from Roasbeef/switch-revenue-stats
lnrpc+htlcswitch+channeldb: add new forwarding log time series and query interface
2018-03-06 15:19:07 -05:00
Olaoluwa Osuntokun b6713724ed Merge pull request #781 from Roasbeef/gossiper-skip-validation-if-stale
routing+gossiper: avoid unnecessarily validating sigs for announcement that is "stale"
2018-03-06 15:02:04 -05:00
Olaoluwa Osuntokun 8306273329 cmd/lncli: add new fwdinghistory command 2018-03-06 13:56:13 -05:00
Olaoluwa Osuntokun 643159caff test: extend testMultiHopPayments to check feereport and forwarding history 2018-03-06 13:56:13 -05:00
Olaoluwa Osuntokun 02852cdc3b rpc: implement new ForwardingHistory command 2018-03-06 13:56:12 -05:00
Olaoluwa Osuntokun 06c1030999 rpc: populate new day, week, and month fee sums in FeeReport 2018-03-06 13:56:12 -05:00
Olaoluwa Osuntokun a540003bb9 server: set the FwdingLog attribute in the switch's config 2018-03-06 13:56:12 -05:00
Olaoluwa Osuntokun 36f214f48c lnrpc: add ForwardingHistory for querying payment circuit time series
In this commit, we add a new method to the RPC service:
ForwardingHistory. This method will allow callers to query for the
completed payment circuits in a particular time slice, skip a series of
events, and also paginate within a time slice.
2018-03-06 13:56:12 -05:00
Olaoluwa Osuntokun ff720e1252 lnrpc: extend the FeeReportResponse to include fee revenue sums 2018-03-06 13:56:11 -05:00
Olaoluwa Osuntokun 473dfd115b htlcswitch: add set of tests for the forwarding log 2018-03-06 13:56:11 -05:00
Olaoluwa Osuntokun ad522a72c1 htlcswitch: add new ticker in switch to batch log forwarding events
In this commit, we extend the switch as is, to record details
concerning settled payment circuits. To do this, we introduce a new
interface to the package: the ForwardingLog. This is a tiny interface
that simply lets us abstract away the details of the storage backing of
the forwarding log.

Each time we receive a successful HTLC settle, we’ll log the full
details (chans, fees, time) as a pending forwarding log entry. Every 15
seconds, we’ll then batch flush out these entries to disk. When we’re
exiting, we’ll try to flush out all entries to ensure everything gets
recorded to disk.
2018-03-06 13:56:11 -05:00
Olaoluwa Osuntokun 6f11fee1a4 htlcswitch: when forwarding htlcs, set the incomingHtlcAmt 2018-03-06 13:56:10 -05:00
Olaoluwa Osuntokun d377ffafdd htlcswitch: populate the incoming+outgoing in the payment circuit 2018-03-06 13:56:10 -05:00
Olaoluwa Osuntokun 157e052958 htlcswitch: add the incoming payment amount to the htlcPacket
We’ll need this value within the link+switch in order to fully populate
the forwarding event that will be generated if this HTLC circuit is
successfully completed.
2018-03-06 13:56:10 -05:00
Olaoluwa Osuntokun 2b8cad2f08 htlcswitch: add incoming+outgoing amounts to the PaymentCircuit
In this commit, we add the incoming+outgoing amounts if the HTLC’s that
the payment circuit consists of. With these new fields, we’ll be able
to populate the forwarding event log once the payment circuit has been
successfully completed.
2018-03-06 13:56:09 -05:00
Olaoluwa Osuntokun 744cfd2ce5 channeldb: add a set of initial tests for the ForwardingLog 2018-03-06 13:56:09 -05:00
Olaoluwa Osuntokun f2cd668bcf channeldb: add new ForwardingLog storage namespace
In this commit, we add a new storage namespace to channeldb: the
ForwardingLog. This log will be used by higher level sub-systems to log
each successfully completed HTLC. Each payment circuit will be
summarized as a “ForwardingEvent”. A series of events can then be
queried via a time slice query. In a time slice query, the caller
specifies a time range, a number of events to skip, and the max number
of events to return. Each query will return the index of the final
item. As we have a max number of events we’ll return in a response,
callers may need to use this last offset index to seek further by
skipping that number of entries. Combining these fields, callers are
able to query the time series, skipping an arbitrary amount of events,
and capping the max number of returned events.
2018-03-06 13:56:06 -05:00
Olaoluwa Osuntokun e7e4cdcf49 discovery: avoid always validating ECDSA sigs by asking router if item is fresh
In this commit, we reduce the amount of unnecessary work that the
gossiper can carry out. When CPU profiling some nodes, I noticed that
we’d spend a lot of time validating the signatures for an announcement,
only to realize that the router already had it.

To remedy this, we’ll use the new methods added to the channel router
in order to avoid unnecessarily validating an announcement that is
actually stale. This should reduce memory usage (since it uses big
int’s under the scenes), and also idle CPU usage.
2018-03-06 13:34:51 -05:00
Olaoluwa Osuntokun aa0410c90a routing: add new methods to check the freshness of an edge/node
In this commit, we add a set of new methods to check the freshness of
an edge/node. This will allow callers to skip expensive validation in
the case that the router already knows of an item, or knows of a
fresher version of that time.

A set of tests have been added to ensure basic correctness of these new
methods.
2018-03-06 13:34:48 -05:00
Olaoluwa Osuntokun 61a7556931 Merge pull request #719 from Roasbeef/rpc-seed
lnrpc+walletunlocker: extend wallet creation to allow user generated entropy + entropy restore (BIP 39)
2018-03-05 15:56:41 -05:00
Olaoluwa Osuntokun 3356a370c7 cmd/lncli: extend initial wallet creation with aezeed seed support
In this commit, we extend the `lncli create` command to allow users to
specify their own side (if they want). In the case that the user
*doesn’t* specify their own seed, we’ll return the entropy generated by
the wallet in a 24-word mnemonic format for easy backup.

With this change, it’s now possible for users to restore an existing lnd
wallet seed.
2018-03-05 11:07:07 -05:00
Olaoluwa Osuntokun d8ce90306d lnwallet/btcwallet: during initial creation catch the case of an existing wallet
In this commit, due to the recent changes within lnd itself, it may be
possible that a wallet already exists when the wallet has been signaled
to be created. As a result, *always* open the wallet ourselves, but
allow an existing wallet to already be in place.
2018-03-05 11:07:07 -05:00
Olaoluwa Osuntokun 6289a2fb84 lnd: move seed generation outside wallet to allow for user supplied entropy
In this commit, we extend the initial wallet creation set up case with
the goal of giving the user the ability to restore a prior wallet from
seed, or obtain the mnemonic for a newly generated wallet.

As the WalletUnlocker has been extended to allow passing a user source
of entropy, if this is detected, then we’ll use BIP39 to covert it into
an HD wallet seed. Otherwise, we’ll generate our own entropy, then
convert that into the wallet seed.

In order to make this change, we’ll now manually create the default
wallet ourselves. In the case that the user didn’t provide their own
seed, we’ll send the seed we generated back to the user. This will allow
frontends to display the newly generated seed to the end user.
2018-03-05 11:07:06 -05:00
Olaoluwa Osuntokun 428693cb6e walletunlocker: modify service to implement new 2-step wallet creation
In this commit, we extend the UnlockerService to account for the new
changes in the lnrpc definition. Setting up the daemon for the first
time is now two step process: first the user will generate a new seed
via the GenSeed method, then the user will present this new seed (and
optional pass) to the InitWallet method which then will finalize the
wallet creation.

This two step process ensures that we don't commit the wallet changes
in the case that the user doesn't actually "ACK" the new seed.

In the case that the user already has an existing seed, they can
re-enter it and skip straight to the InitWallet step.

We also update the tests to account for the new API changes.
2018-03-05 11:07:06 -05:00
Olaoluwa Osuntokun 7f953bf0b9 lnrpc: revamp the WalletUnlocker service to have a two-stage init
In this commit, we revamp the WalletUnlocker service to now have a
two-stage init process.

The first (optional) is for the user instantiating a new lnd instance to
call the GenSeed method with an optional aezeed passphrase. The response
to this will be a freshly generated aezeed mnemonic along with the
original enciphered seed.

The second step will be the actual wallet initaliztion. By separating
this step from seed generation, UI's will be able to ensure that the
user has written down the seed, before proceeding and committing the
seed to the internal wallet. The new method InitWallet accepts a wallet
passphrase, the aezeed mnemonic, and the optional passphrase.
2018-03-05 11:07:01 -05:00
Olaoluwa Osuntokun 294447fe2f Merge pull request #803 from cfromknecht/glide-crypto-x-version
glide: add explicit version to x/crypto deps
2018-03-05 10:29:33 -05:00
Olaoluwa Osuntokun 1ba399267b Merge pull request #773 from Roasbeef/aezeed
aezeed: add new package implementing the aezeed cipher seed scheme
2018-03-01 17:53:56 -08:00
Olaoluwa Osuntokun d65fe83a59 build: add aez and bstream to glide 2018-03-01 17:10:54 -08:00
Olaoluwa Osuntokun 120cebef77 aezeed: add a set of benchmarks
In this commit we add a set of benchmarks to be able to measure the
enciphering and deciphering speed of the current scheme with the
current scrypt parameters.

On my laptop I get about 100ms per attempt:
⛰ go test -run=XXX -bench=.

goos: darwin
goarch: amd64
pkg: github.com/lightningnetwork/lnd/aezeed
BenchmarkToMnenonic-4     	      10	 102287840 ns/op
BenchmarkFromMnenonic-4   	      10	 105874973 ns/op
PASS
ok  	github.com/lightningnetwork/lnd/aezeed	3.036s
2018-03-01 17:10:54 -08:00
Olaoluwa Osuntokun eb3b5196e1 aezeed: add comprehensive, mostly property-based tests 2018-03-01 17:10:53 -08:00
Olaoluwa Osuntokun ffac0336e6 aezeed: add new package implementing the aezeed cipher seed scheme
In this commit, we add a new package implementing the aezeed cipher
seed scheme. This is a new scheme developed that aims to overcome the
two major short comings of BIP39: a lack of a version, and a lack of a
wallet birthday. A lack a version means that wallets may not
necessarily know *how* to re-derive addresses during the recovery
process. A lack of a birthday means that wallets don’t know how far
back to look in the chain to ensure that they derive *all* the proper
user addresses.

The aezeed scheme addresses these two drawbacks and adds a number of
desirable features. First, we start with the following plaintext seed:
{1 byte internal version || 2 byte timestamp || 16 bytes of entropy}.

The version field is for wallets to be able to know *how* to re-derive
the keys of the wallet.

The 2 byte timestamp is expressed in Bitcoin Days Genesis, meaning that
the number of days since the timestamp in Bitcoin’s genesis block. This
allow us to save space, and also avoid using a wasteful level of
granularity. With the currently, this can express time up until 2188.

Finally, the entropy is raw entropy that should be used to derive
wallet’s HD root.

Next, we’ll take the plaintext seed described above and encipher it to
procure a final cipher text. We’ll then take this cipher text (the
CipherSeed) and encode that using a 24-word mnemonic. The enciphering
process takes a user defined passphrase. If no passphrase is provided,
then the string “aezeed” will be used.

To encipher a plaintext seed (19 bytes) to arrive at an enciphered
cipher seed (33 bytes), we apply the following operations:
   * First we take the external version an append it to our buffer. The
external version describes *how* we encipher. For the first version
(version 0), we’ll use scrypt(n=32768, r=8, p=1) and aezeed.
  * Next, we’ll use scrypt (with the version 9 params) to generate a
strong key for encryption. We’ll generate a 32-byte key using 5 bytes
as a salt. The usage of the salt is meant to make the creation of
rainbow tables infeasible.
  * Next, the enciphering process. We use aezeed, modern AEAD with
nonce-misuse resistance properties. The important trait we exploit is
that it’s an *arbitrary input length block cipher*. Additionally, it
has what’s essentially a configurable MAC size. In our scheme we’ll use
a value of 4, which acts as a 32-bit checksum. We’ll encrypt with our
generated seed, and use an AD of (version || salt). We'll them compute a
checksum over all the data, using crc-32, appending the result to the
end.
  * Finally, we’ll encode this 33-byte cipher text using the default
world list of BIP 39 to produce 24 english words.

The `aezeed` cipher seed scheme has a few cool properties, notably:
   * The mnemonic itself is a cipher text, meaning leaving it in
plaintext is advisable if the user also set a passphrase. This is in
contrast to BIP 39 where the mnemonic alone (without a passphrase) may
be sufficient to steal funds.
   * A cipherseed can be modified to *change* the passphrase. This
means that if the users wants a stronger passphrase, they can decipher
(with the old passphrase), then encipher (with a new passphrase).
Compared to BIP 39, where if the users used a passphrase, since the
mapping is one way, they can’t change the passphrase of their existing
HD key chain.
  * A cipher seed can be *upgraded*. Since we have an external version,
offline tools can be provided to decipher using the old params, and
encipher using the new params. In the future if we change ciphers,
change scrypt, or just the parameters of scrypt, then users can easily
upgrade their seed with an offline tool.
  * We're able to verify that a user has input the incorrect passphrase,
and that the user has input the incorrect mnemonic independently.
2018-03-01 17:10:50 -08:00
Olaoluwa Osuntokun a9dc4f80f2 chainntnfs/neutrinonotify: log height hint for spend notifications 2018-03-01 16:49:28 -08:00
Olaoluwa Osuntokun 9479b085e2 Merge pull request #785 from brndnmtthws/master
Add more details on using macaroons with GRPC.
2018-02-28 19:27:13 -08:00
Olaoluwa Osuntokun f7ec490f44 Merge pull request #762 from halseth/fee-estimator
Add types for representing fee rates
2018-02-26 17:22:50 -08:00
Olaoluwa Osuntokun 7f04d927a0 rpc: fix queryroutes bug that assumed precise number of returned routes
In this commit, we fix a bug in the query routes RPC that could at
times lead to a panic. This would happen if the number of returned
routes was less than the number of expected routes. To remedy this,
we’ll return the minimum of the number of requested routes, and the
number of routes actually returned.
2018-02-26 16:31:50 -08:00
Olaoluwa Osuntokun 158c78da60 lnd: remove invalid cipher suite 2018-02-26 13:29:19 -08:00
Olaoluwa Osuntokun c846c4d2e0 lnd: correct typo in cipher suite sets, use sha2 2018-02-26 13:04:52 -08:00
Olaoluwa Osuntokun 94746c2d12 Merge pull request #780 from Roasbeef/brontide-reduce-allocs
brontide: reduce memory allocs by using static buf for next header+msg
2018-02-26 13:04:27 -08:00
Olaoluwa Osuntokun 0c16ab6b32 brontide: reduce memory allocs by using static buf for next header+msg
In this commit, we reduce the total number of allocations that a
brontide session will incur over its lifetime. Profiling on one of my
nodes showed that we were generating a lot of garbage due to
re-creating a 65KB buffer to read the next message each time the
ReadMessage method was called.

To reduce the total number of memory allocations, we’ll now simply
re-use a buffer for both the cipher text header, and the cipher text
itself.
2018-02-24 19:30:45 -08:00
Olaoluwa Osuntokun e5f9b28e39 Merge pull request #776 from Roasbeef/rpc-ec-cert
lnd: switch to using ECC certs for the rpcserver
2018-02-24 13:14:54 -08:00
Olaoluwa Osuntokun f7eeea71e2 lnd: switch to using ECC certs for the rpcserver
In this commit, we modify our initial cert generation to *only* generate
and advertise cipher suites that purely use ECC. We do this is as
switching to ECC results in much faster startup time for a fresh
installation, and is also more modern crypto.  # Please enter the commit
message for your changes. Lines starting
2018-02-23 18:24:23 -08:00
Olaoluwa Osuntokun 83b779dcdf build: update glide to latest btcwallet
In this commit, we update glide to the latest version of btcwallet that
includes fixes for better fee estimation, and also fixes to ensure that
transaction broadcast is reliable across all current backend
implementations.
2018-02-23 16:48:51 -08:00
Olaoluwa Osuntokun f815c6ca14 Merge pull request #774 from halseth/reservation-cancellation
Reservation cancellation during failing funding flow
2018-02-23 15:36:11 -08:00
Olaoluwa Osuntokun 1c3dbb2543 Merge pull request #771 from cfromknecht/report-double-spend-for-brar
lnwallet/btcwallet/btcwallet: adds extra double spend case
2018-02-20 22:06:19 -08:00
Olaoluwa Osuntokun 34efb380be lnwallet: update interface tests due to recent API change 2018-02-20 19:16:14 -08:00
Olaoluwa Osuntokun d5923f3832 Merge pull request #594 from halseth/publish-transaction-error-codes
Ignore ErrRejectDuplicate errors
2018-02-20 19:05:53 -08:00
Olaoluwa Osuntokun 2a61ccec96 chainntnfs: fix new golang 1.10 vet/test warning 2018-02-19 18:06:35 -08:00
Olaoluwa Osuntokun 236d53785d docs: update docs to recommend golang 1.10 2018-02-19 17:44:03 -08:00
Olaoluwa Osuntokun 7f0dd8f28f build: update travis to build against golang 1.10+1.9.4 2018-02-19 17:32:54 -08:00
Olaoluwa Osuntokun 39f9ae7cac build: update to version of golang fork with golang 1.10 bug fix
In this commit, we update the commit of my btcd fork as the saltiest
commit includes a fix for a breaking change (or bug fix). After this
commit, we’ll able to run the set of integration tests with golfing
1.10.
2018-02-19 17:32:43 -08:00