Commit Graph

180 Commits

Author SHA1 Message Date
Christian Decker da183c22a0 db: Cleanup all remaining traces of hex-encoded values
In addition we also set some of the test values to a pattern instead
of just `memset`ting it to 0, which may hide some crossed lines.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-31 22:43:47 +00:00
Christian Decker c1d364c5fb wallet: Migrate channel persistence to native sqlite3 binding
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-31 22:43:47 +00:00
Christian Decker 33da7f50c7 db: Added short_channel_id, tx, pubkey and signature primitives
We use these quite often and it is cumbersome having to do these
simple conversions inline, so just expose pseudo-sqlite3 methods to
bind and extract from/to a stmt.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-31 22:43:47 +00:00
Christian Decker b267b24c08 db: db_exec_prepared takes ownership of the statement
Technically it's the caller that'll own the statement, but it is nice
to have db_exec_prepared dispose of it.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-31 22:43:47 +00:00
Rusty Russell 48cedef756 peer_control: remove unique_id field.
It's now completely useless.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-24 16:12:22 +02:00
Rusty Russell 8f057f7fc7 Revert "gossip: send the *other* node's cltv_expiry_delta in channel_announce."
This reverts commit 297e278132.
2017-10-11 11:54:50 +02:00
Rusty Russell 297e278132 gossip: send the *other* node's cltv_expiry_delta in channel_announce.
Include tests from example doc.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-10-10 20:17:37 +02:00
Christian Decker 048680d0f2 db: Add db_prepare and db_exec_prepared to expose native binding
This makes executing a query/command a two step process, but allows us
to use the native binding and avoid having to build queries as SQL
strings. Two major advantages are that we are no longer vulnerable to
SQL injections and that we do not have to hex-encode binary fields
like private keys, hashes, and routing onions, halving the storage
requirements for those.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-09 11:51:13 +10:30
Christian Decker 067d2d7435 db: Added table for invoices
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-09 11:51:13 +10:30
Christian Decker 4114f6f79b db: Clear errors before executing new query
This was causing me some trouble by making it look like the last query
failed, when it really was an old one. No need to drag failures around
for longer than needed.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-09 11:51:13 +10:30
Christian Decker b8fa765c3f wallet: Add primitives to store htlcs in the database
Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-09 11:51:13 +10:30
Christian Decker 3dda72c885 db: Create table for HTLCs
Also added a small warning to one of the used enums not to reorder or
insert values. They'd break the update path.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-10-09 11:51:13 +10:30
Rusty Russell 8375857116 common: absorb remaining files from daemon/
Also, we split the more sophisticated json_add helpers to avoid pulling in
everything into lightning-cli, and unify the routines to print struct
short_channel_id (it's ':',  not '/' too).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-29 17:54:14 +02:00
Rusty Russell 1396cf6249 lightningd: remove num_revocations_received.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-23 17:38:22 +02:00
Christian Decker 4e6f9787b6 wallet: unique_id is not the same as dbid
They happen to advance at the same pace but mixing them may have
unforeseen consequences, and I have done so a few times already so
this explicitly separates them.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2017-08-23 10:23:54 +09:30
Christian Decker 1a94e7282b db: Make peers unique by node_id
We should only ever have a single entry for each node_id, enforcing
this on the DB.
2017-08-23 10:23:54 +09:30
Rusty Russell 893335244d openingd: supply initial tx as well as signature.
And store in peer->last_tx/peer->last_sig like all other places,
that way we broadcast it if we need to.

Note: the removal of tmpctx in funder_channel() is needed because we
use txs[0], which was allocated off tmpctx.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-20 13:06:41 +09:30
Rusty Russell dbfac68c3f lightningd: keep last valid tx, and its signature.
This avoids us having to reconstruct it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
2017-08-20 13:06:41 +09:30
Christian Decker 1ac10716be wallet: Add closing parameters to channel state
I must have missed these before, so adding them now.
2017-08-10 12:34:58 +09:30
Christian Decker cc5af13e05 wallet: Implement channel_config persistence 2017-08-10 12:34:58 +09:30
Christian Decker cfe87b16c3 db: Do not exit transaction on failure
Automatically exiting the DB transaction upon any failure is strange
since it'll kill any later attempt to commit. The commit itself should
be used to verify that everything was ok.
2017-08-10 12:34:58 +09:30
Christian Decker 5912c68185 db: Add a hexval helper to decode hex values from db into fields
This is going to be handy pretty soon. Channels are almost fully
blobs...
2017-08-10 12:34:58 +09:30
Christian Decker 33ffb53d9e db: Added schema for peers and channels 2017-08-10 12:34:58 +09:30
Christian Decker 416d6bf860 db: Enable foreign keys and cascade on shachain delete
Should make maintenance a bit easier.
2017-08-10 12:34:58 +09:30
Christian Decker b0c64909e7 wallet: Added database schema for shachain persistence 2017-08-10 12:34:58 +09:30
Christian Decker 1522eee528 unittests: Test some more of the db primitives. 2017-06-23 16:02:20 +09:30
Christian Decker 257ecf6222 wallet: Helper to store/retrieve persistent vars to/from DB
Not the nicest code, but it allows us to store the bip32_max_index so
that we don't forget our addresses upon restart. We could have done
the same by retrieving the max index from our index, but then we'd
forget addresses that don't have an associated output. Conversion
to/from string is so that we can store arbitrary one off values in the
DB in the future, independent of type.
2017-06-06 09:16:10 +09:30
Christian Decker 19a4e7f542 wallet: Expose transactional interface for db 2017-06-06 09:16:10 +09:30
Christian Decker 9882a9fb29 wallet: Start the wallet interface and link it into lightningd
The database is hidden behind the wallet interface, which has all the
wallet specific functionality. First up is the tracking of outputs.
2017-06-06 09:16:10 +09:30
Christian Decker 80436d06cb wallet: Create and manage a sqlite3 database for the wallet 2017-06-06 09:16:10 +09:30