Browse Source

protobuf: remove

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
committed by Christian Decker
parent
commit
8088e5cadb
  1. 38
      INSTALL.md
  2. 28
      Makefile
  3. 2
      README.md
  4. 2
      close_tx.c
  5. 1
      close_tx.h
  6. 1
      daemon/Makefile
  7. 65
      daemon/packets.h
  8. 1
      daemon/routing.c
  9. 3016
      lightning.pb-c.c
  10. 1290
      lightning.pb-c.h
  11. 262
      lightning.proto
  12. 8
      lightningd/lightningd.c
  13. 206
      protobuf_convert.c
  14. 45
      protobuf_convert.h
  15. 1
      type_to_string.c

38
INSTALL.md

@ -2,8 +2,6 @@ Library Requirements
-------------------- --------------------
You will need several development libraries: You will need several development libraries:
* libprotoc: the Google protocol buffer v2 library, 2.6.0 or above.
* protobuf-c: version 1.1.0 or above.
* libsqlite3: for database support. * libsqlite3: for database support.
* libgmp: for secp256k1 * libgmp: for secp256k1
@ -15,12 +13,12 @@ For actually doing development and running the tests, you will also need:
You will also need a version of bitcoind with segregated witness support, You will also need a version of bitcoind with segregated witness support,
such as the 0.13 or above. such as the 0.13 or above.
To Build on Ubuntu 16.04 To Build on Ubuntu 15.10 or above
--------------------- ---------------------
Get dependencies: Get dependencies:
``` ```
sudo apt-get install -y autoconf build-essential git libtool libprotobuf-c-dev libgmp-dev libsqlite3-dev python3 net-tools sudo apt-get install -y autoconf build-essential git libtool libgmp-dev libsqlite3-dev python3 net-tools
``` ```
If you don't have Bitcoin installed locally you'll need to install that as well: If you don't have Bitcoin installed locally you'll need to install that as well:
@ -56,35 +54,3 @@ bitcoind &
``` ```
**Note**: You may need to include `testnet=1` in `bitcoin.conf` **Note**: You may need to include `testnet=1` in `bitcoin.conf`
To Build on Ubuntu 15.10
------------------------
Build protobuf-c dependency (>= 1.1.0):
```
sudo apt-get install libprotoc-dev
git clone https://github.com/protobuf-c/protobuf-c.git
cd protobuf-c
./autogen.sh
./configure
make
make install
cd ../
```
Clone lightning:
```
git clone https://github.com/ElementsProject/lightning.git
cd lighting
```
Build lightning:
```
make
```
Running lightning:
```
bitcoind
export LD_LIBRARY_PATH=/usr/local/lib
./lightningd/lightningd
./daemon/lightning-cli help
```

28
Makefile

@ -1,9 +1,6 @@
#! /usr/bin/make #! /usr/bin/make
NAME=Bitcoin Savings & Trust Daily Interest II NAME=Bitcoin Savings & Trust Daily Interest II
# Needs to have oneof support: Ubuntu vivid's is too old :(
PROTOCC:=protoc-c
# We use our own internal ccan copy. # We use our own internal ccan copy.
CCANDIR := ccan CCANDIR := ccan
@ -60,12 +57,6 @@ CORE_TX_SRC := \
CORE_TX_OBJS := $(CORE_TX_SRC:.c=.o) CORE_TX_OBJS := $(CORE_TX_SRC:.c=.o)
CORE_PROTOBUF_SRC := \
lightning.pb-c.c \
protobuf_convert.c
CORE_PROTOBUF_OBJS := $(CORE_PROTOBUF_SRC:.c=.o)
CCAN_OBJS := \ CCAN_OBJS := \
ccan-asort.o \ ccan-asort.o \
ccan-autodata.o \ ccan-autodata.o \
@ -189,13 +180,11 @@ CORE_TX_HEADERS := close_tx.h \
CORE_HEADERS := \ CORE_HEADERS := \
opt_bits.h \ opt_bits.h \
overflows.h \ overflows.h \
protobuf_convert.h \
type_to_string.h \ type_to_string.h \
utils.h \ utils.h \
version.h version.h
GEN_HEADERS := gen_version.h \ GEN_HEADERS := gen_version.h
lightning.pb-c.h
LIBSODIUM_HEADERS := libsodium/src/libsodium/include/sodium.h LIBSODIUM_HEADERS := libsodium/src/libsodium/include/sodium.h
LIBWALLY_HEADERS := libwally-core/include/wally_bip32.h \ LIBWALLY_HEADERS := libwally-core/include/wally_bip32.h \
@ -214,7 +203,7 @@ CWARNFLAGS := -Werror -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations
CDEBUGFLAGS := -std=gnu11 -g -fstack-protector CDEBUGFLAGS := -std=gnu11 -g -fstack-protector
CFLAGS := $(CWARNFLAGS) $(CDEBUGFLAGS) -I $(CCANDIR) -I libwally-core/src/secp256k1/include/ -I libwally-core/include/ -I libsodium/src/libsodium/include/ -I . $(FEATURES) $(COVFLAGS) -DSHACHAIN_BITS=48 CFLAGS := $(CWARNFLAGS) $(CDEBUGFLAGS) -I $(CCANDIR) -I libwally-core/src/secp256k1/include/ -I libwally-core/include/ -I libsodium/src/libsodium/include/ -I . $(FEATURES) $(COVFLAGS) -DSHACHAIN_BITS=48
LDLIBS := -lprotobuf-c -lgmp -lsqlite3 $(COVFLAGS) LDLIBS := -lgmp -lsqlite3 $(COVFLAGS)
$(PROGRAMS): CFLAGS+=-I. $(PROGRAMS): CFLAGS+=-I.
default: $(PROGRAMS) doc-all default: $(PROGRAMS) doc-all
@ -232,7 +221,7 @@ CHANGED_FROM_GIT = [ x"`git log $@ | head -n1`" != x"`git log $< | head -n1`" -o
$(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(CDUMP_OBJS) $(HELPER_OBJS) $(BITCOIN_OBJS) $(TEST_PROGRAMS:=.o) ccan/ccan/cdump/tools/cdump-enumstr.o: $(CCAN_HEADERS) $(CCAN_OBJS) $(CCAN_SHACHAIN48_OBJ) $(CDUMP_OBJS) $(HELPER_OBJS) $(BITCOIN_OBJS) $(TEST_PROGRAMS:=.o) ccan/ccan/cdump/tools/cdump-enumstr.o: $(CCAN_HEADERS)
# Except for CCAN, everything depends on bitcoin/ and core headers. # Except for CCAN, everything depends on bitcoin/ and core headers.
$(HELPER_OBJS) $(CORE_OBJS) $(CORE_TX_OBJS) $(CORE_PROTOBUF_OBJS) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(WALLET_LIB_OBJS) $(TEST_PROGRAMS:=.o): $(BITCOIN_HEADERS) $(CORE_HEADERS) $(CCAN_HEADERS) $(GEN_HEADERS) $(LIBBASE58_HEADERS) $(LIBSODIUM_HEADERS) $(LIBWALLY_HEADERS) $(HELPER_OBJS) $(CORE_OBJS) $(CORE_TX_OBJS) $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(WALLET_LIB_OBJS) $(TEST_PROGRAMS:=.o): $(BITCOIN_HEADERS) $(CORE_HEADERS) $(CCAN_HEADERS) $(GEN_HEADERS) $(LIBBASE58_HEADERS) $(LIBSODIUM_HEADERS) $(LIBWALLY_HEADERS)
test-protocol: test/test_protocol test-protocol: test/test_protocol
set -e; TMP=`mktemp`; for f in test/commits/*.script; do if ! $(VALGRIND) test/test_protocol < $$f > $$TMP; then echo "test/test_protocol < $$f FAILED" >&2; exit 1; fi; diff -u $$TMP $$f.expected; done; rm $$TMP set -e; TMP=`mktemp`; for f in test/commits/*.script; do if ! $(VALGRIND) test/test_protocol < $$f > $$TMP; then echo "test/test_protocol < $$f FAILED" >&2; exit 1; fi; diff -u $$TMP $$f.expected; done; rm $$TMP
@ -255,7 +244,7 @@ check-hdr-include-order/%: %
# Make sure Makefile includes all headers. # Make sure Makefile includes all headers.
check-makefile: check-makefile:
@if [ "`echo bitcoin/*.h`" != "$(BITCOIN_HEADERS)" ]; then echo BITCOIN_HEADERS incorrect; exit 1; fi @if [ "`echo bitcoin/*.h`" != "$(BITCOIN_HEADERS)" ]; then echo BITCOIN_HEADERS incorrect; exit 1; fi
@if [ x"`ls *.h | grep -v ^gen_ | fgrep -v lightning.pb-c.h`" != x"`echo $(CORE_HEADERS) $(CORE_TX_HEADERS) | tr ' ' '\n' | LC_ALL=C sort`" ]; then echo CORE_HEADERS incorrect; exit 1; fi @if [ x"`ls *.h | grep -v ^gen_`" != x"`echo $(CORE_HEADERS) $(CORE_TX_HEADERS) | tr ' ' '\n' | LC_ALL=C sort`" ]; then echo CORE_HEADERS incorrect; exit 1; fi
@if [ x"$(CCANDIR)/config.h `find $(CCANDIR)/ccan -name '*.h' | grep -v /test/ | LC_ALL=C sort | tr '\n' ' '`" != x"$(CCAN_HEADERS) " ]; then echo CCAN_HEADERS incorrect; exit 1; fi @if [ x"$(CCANDIR)/config.h `find $(CCANDIR)/ccan -name '*.h' | grep -v /test/ | LC_ALL=C sort | tr '\n' ' '`" != x"$(CCAN_HEADERS) " ]; then echo CCAN_HEADERS incorrect; exit 1; fi
# Any mention of BOLT# must be followed by an exact quote, modulo whitepace. # Any mention of BOLT# must be followed by an exact quote, modulo whitepace.
@ -265,7 +254,7 @@ bolt-check/%: % bolt-precheck tools/check-bolt
bolt-precheck: bolt-precheck:
@rm -rf .tmp.lightningrfc; if [ ! -d $(BOLTDIR) ]; then echo Not checking BOLT references: BOLTDIR $(BOLTDIR) does not exist >&2; exit 0; fi; set -e; if [ -n "$(BOLTVERSION)" ]; then git clone -q -b $(BOLTVERSION) $(BOLTDIR) .tmp.lightningrfc; else cp -a $(BOLTDIR) .tmp.lightningrfc; fi @rm -rf .tmp.lightningrfc; if [ ! -d $(BOLTDIR) ]; then echo Not checking BOLT references: BOLTDIR $(BOLTDIR) does not exist >&2; exit 0; fi; set -e; if [ -n "$(BOLTVERSION)" ]; then git clone -q -b $(BOLTVERSION) $(BOLTDIR) .tmp.lightningrfc; else cp -a $(BOLTDIR) .tmp.lightningrfc; fi
check-source-bolt: $(CORE_SRC:%=bolt-check/%) $(CORE_TX_SRC:%=bolt-check/%) $(CORE_PROTOBUF_SRC:%=bolt-check/%) $(CORE_HEADERS:%=bolt-check/%) $(TEST_PROGRAMS:%=bolt-check/%.c) check-source-bolt: $(CORE_SRC:%=bolt-check/%) $(CORE_TX_SRC:%=bolt-check/%) $(CORE_HEADERS:%=bolt-check/%) $(TEST_PROGRAMS:%=bolt-check/%.c)
tools/check-bolt: tools/check-bolt.o $(CCAN_OBJS) tools/check-bolt: tools/check-bolt.o $(CCAN_OBJS)
@ -274,12 +263,11 @@ tools/check-bolt.o: $(CCAN_HEADERS)
check-whitespace/%: % check-whitespace/%: %
@if grep -Hn '[ ]$$' $<; then echo Extraneous whitespace found >&2; exit 1; fi @if grep -Hn '[ ]$$' $<; then echo Extraneous whitespace found >&2; exit 1; fi
check-whitespace: check-whitespace/Makefile check-whitespace/tools/check-bolt.c $(CORE_SRC:%=check-whitespace/%) $(CORE_TX_SRC:%=check-whitespace/%) $(CORE_PROTOBUF_SRC:%=check-whitespace/%) $(CORE_HEADERS:%=check-whitespace/%) check-whitespace: check-whitespace/Makefile check-whitespace/tools/check-bolt.c $(CORE_SRC:%=check-whitespace/%) $(CORE_TX_SRC:%=check-whitespace/%) $(CORE_HEADERS:%=check-whitespace/%)
check-source: check-makefile check-source-bolt check-whitespace \ check-source: check-makefile check-source-bolt check-whitespace \
$(CORE_SRC:%=check-src-include-order/%) \ $(CORE_SRC:%=check-src-include-order/%) \
$(CORE_TX_SRC:%=check-src-include-order/%) \ $(CORE_TX_SRC:%=check-src-include-order/%) \
$(CORE_PROTOBUF_SRC:%=check-src-include-order/%) \
$(BITCOIN_SRC:%=check-src-include-order/%) \ $(BITCOIN_SRC:%=check-src-include-order/%) \
$(CORE_HEADERS:%=check-hdr-include-order/%) \ $(CORE_HEADERS:%=check-hdr-include-order/%) \
$(CORE_TX_HEADERS:%=check-hdr-include-order/%) \ $(CORE_TX_HEADERS:%=check-hdr-include-order/%) \
@ -320,9 +308,6 @@ libsecp256k1.% libwallycore.%: libwally-core/src/secp256k1/libsecp256k1.la libwa
libwally-core/src/libwallycore.% libwally-core/src/secp256k1/libsecp256k1.%: $(LIBWALLY_HEADERS) $(LIBSECP_HEADERS) libwally-core/src/libwallycore.% libwally-core/src/secp256k1/libsecp256k1.%: $(LIBWALLY_HEADERS) $(LIBSECP_HEADERS)
cd libwally-core && ./tools/autogen.sh && ./configure CC="$(CC)" --enable-static=yes --enable-shared=no --libdir=`pwd`/.. && $(MAKE) cd libwally-core && ./tools/autogen.sh && ./configure CC="$(CC)" --enable-static=yes --enable-shared=no --libdir=`pwd`/.. && $(MAKE)
lightning.pb-c.c lightning.pb-c.h: lightning.proto
@if $(CHANGED_FROM_GIT); then echo $(PROTOCC) lightning.proto --c_out=.; $(PROTOCC) lightning.proto --c_out=.; else touch $@; fi
$(TEST_PROGRAMS): % : %.o $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) lightningd/sphinx.o utils.o version.o libwallycore.a libsecp256k1.a libsodium.a $(TEST_PROGRAMS): % : %.o $(BITCOIN_OBJS) $(LIBBASE58_OBJS) $(WIRE_OBJS) $(CCAN_OBJS) lightningd/sphinx.o utils.o version.o libwallycore.a libsecp256k1.a libsodium.a
ccan/config.h: ccan/tools/configurator/configurator ccan/config.h: ccan/tools/configurator/configurator
@ -363,7 +348,6 @@ distclean: clean
maintainer-clean: distclean maintainer-clean: distclean
@echo 'This command is intended for maintainers to use; it' @echo 'This command is intended for maintainers to use; it'
@echo 'deletes files that may need special tools to rebuild.' @echo 'deletes files that may need special tools to rebuild.'
$(RM) lightning.pb-c.c lightning.pb-c.h
clean: daemon-clean wire-clean clean: daemon-clean wire-clean
$(MAKE) -C secp256k1/ clean || true $(MAKE) -C secp256k1/ clean || true

2
README.md

@ -23,7 +23,7 @@ Please refer to the [installation documentation](INSTALL.md) for detailed instru
For the impatient here's the gist of it for Ubuntu and Debian: For the impatient here's the gist of it for Ubuntu and Debian:
``` ```
sudo apt-get install -y autoconf git build-essential libtool libprotobuf-c-dev libgmp-dev libsqlite3-dev python python3 sudo apt-get install -y autoconf git build-essential libtool libgmp-dev libsqlite3-dev python python3
git clone https://github.com/ElementsProject/lightning.git git clone https://github.com/ElementsProject/lightning.git
cd lightning cd lightning
make make

2
close_tx.c

@ -2,7 +2,7 @@
#include "bitcoin/tx.h" #include "bitcoin/tx.h"
#include "close_tx.h" #include "close_tx.h"
#include "permute_tx.h" #include "permute_tx.h"
#include "protobuf_convert.h" #include <assert.h>
struct bitcoin_tx *create_close_tx(const tal_t *ctx, struct bitcoin_tx *create_close_tx(const tal_t *ctx,
const u8 *our_script, const u8 *our_script,

1
close_tx.h

@ -1,7 +1,6 @@
#ifndef LIGHTNING_CLOSE_TX_H #ifndef LIGHTNING_CLOSE_TX_H
#define LIGHTNING_CLOSE_TX_H #define LIGHTNING_CLOSE_TX_H
#include "config.h" #include "config.h"
#include "lightning.pb-c.h"
#include <ccan/short_types/short_types.h> #include <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h> #include <ccan/tal/tal.h>

1
daemon/Makefile

@ -59,7 +59,6 @@ DAEMON_HEADERS := \
daemon/netaddr.h \ daemon/netaddr.h \
daemon/opt_time.h \ daemon/opt_time.h \
daemon/options.h \ daemon/options.h \
daemon/packets.h \
daemon/pseudorand.h \ daemon/pseudorand.h \
daemon/routing.h \ daemon/routing.h \
daemon/timeout.h \ daemon/timeout.h \

65
daemon/packets.h

@ -1,65 +0,0 @@
#ifndef LIGHTNING_DAEMON_PACKETS_H
#define LIGHTNING_DAEMON_PACKETS_H
#include "config.h"
#include "lightning.pb-c.h"
struct commit_info;
struct htlc;
struct peer;
struct preimage;
struct sha256;
/* Send various kinds of packets */
void queue_pkt_open(struct peer *peer, bool offer_anchor);
void queue_pkt_anchor(struct peer *peer);
void queue_pkt_open_commit_sig(struct peer *peer);
void queue_pkt_open_complete(struct peer *peer);
void queue_pkt_htlc_add(struct peer *peer, struct htlc *htlc);
void queue_pkt_htlc_fulfill(struct peer *peer, struct htlc *htlc);
void queue_pkt_htlc_fail(struct peer *peer, struct htlc *htlc);
void queue_pkt_feechange(struct peer *peer, u64 feerate);
void queue_pkt_commit(struct peer *peer, const secp256k1_ecdsa_signature *sig);
void queue_pkt_revocation(struct peer *peer,
const struct sha256 *preimage,
const struct sha256 *next_hash);
void queue_pkt_close_shutdown(struct peer *peer);
void queue_pkt_close_signature(struct peer *peer);
void queue_pkt_nested(struct peer *peer, int type, const u8 *nested_pkt);
Pkt *pkt_err(struct peer *peer, const char *msg, ...);
Pkt *pkt_init(struct peer *peer, u64 ack);
void queue_pkt_err(struct peer *peer, Pkt *err);
Pkt *pkt_err_unexpected(struct peer *peer, const Pkt *pkt);
/* Process various packets: return an error packet on failure. */
Pkt *accept_pkt_open(struct peer *peer, const Pkt *pkt,
struct sha256 *revocation_hash,
struct sha256 *next_revocation_hash);
Pkt *accept_pkt_anchor(struct peer *peer, const Pkt *pkt);
Pkt *accept_pkt_open_commit_sig(struct peer *peer, const Pkt *pkt,
secp256k1_ecdsa_signature *sig);
Pkt *accept_pkt_open_complete(struct peer *peer, const Pkt *pkt);
Pkt *accept_pkt_htlc_add(struct peer *peer, const Pkt *pkt, struct htlc **h);
Pkt *accept_pkt_htlc_fail(struct peer *peer, const Pkt *pkt, struct htlc **h,
u8 **fail);
Pkt *accept_pkt_htlc_fulfill(struct peer *peer, const Pkt *pkt, struct htlc **h,
struct preimage *r);
Pkt *accept_pkt_update_fee(struct peer *peer, const Pkt *pkt, u64 *feerate);
Pkt *accept_pkt_update_accept(struct peer *peer, const Pkt *pkt);
Pkt *accept_pkt_commit(struct peer *peer, const Pkt *pkt,
secp256k1_ecdsa_signature *sig);
Pkt *accept_pkt_revocation(struct peer *peer, const Pkt *pkt);
Pkt *accept_pkt_close_shutdown(struct peer *peer, const Pkt *pkt);
#endif /* LIGHTNING_DAEMON_PACKETS_H */

1
daemon/routing.c

@ -1,7 +1,6 @@
#include "lightningd.h" #include "lightningd.h"
#include "log.h" #include "log.h"
#include "overflows.h" #include "overflows.h"
#include "packets.h"
#include "pseudorand.h" #include "pseudorand.h"
#include "routing.h" #include "routing.h"
#include "wire/gen_peer_wire.h" #include "wire/gen_peer_wire.h"

3016
lightning.pb-c.c

File diff suppressed because it is too large

1290
lightning.pb-c.h

File diff suppressed because it is too large

262
lightning.proto

@ -1,262 +0,0 @@
syntax = "proto2";
// The outer layer handles encryption, authentication and message
// boundaries.
//
// Helper Types
//
// Protobufs don't have fixed-length fields, so these are a hack.
message sha256_hash {
required fixed64 a = 1;
required fixed64 b = 2;
required fixed64 c = 3;
required fixed64 d = 4;
}
message preimage {
required fixed64 a = 1;
required fixed64 b = 2;
required fixed64 c = 3;
required fixed64 d = 4;
}
message signature {
required fixed64 r1 = 1;
required fixed64 r2 = 2;
required fixed64 r3 = 3;
required fixed64 r4 = 4;
required fixed64 s1 = 5;
required fixed64 s2 = 6;
required fixed64 s3 = 7;
required fixed64 s4 = 8;
}
message locktime {
oneof locktime {
uint32 seconds = 1;
uint32 blocks = 2;
}
}
// Pubkey for commitment transaction input.
message bitcoin_pubkey {
// Must be 33 bytes.
required bytes key = 1;
}
// How much a node charges (or pays!) for sending.
message funding {
// Base amount (in satoshi).
optional int64 fixed = 1 [ default = 0 ];
// This is charge per millionth of a satoshi.
optional int32 per_micro_satoshi = 2 [ default = 0 ];
}
//
// Packet Types
//
// Set channel params.
message authenticate {
// Which node this is.
required bitcoin_pubkey node_id = 1;
// Signature of your session key. */
required signature session_sig = 2;
};
// We're authenticated. Here's what we've received already.
message init {
// How many update_commit and update_revocation messages already received
required uint64 ack = 1;
// What features do we support (odd) and require (even)
optional bytes features = 2;
};
// Set channel params.
message open_channel {
// Relative locktime for outputs going to us.
required locktime delay = 1;
// Hash for revoking first commitment transaction.
required sha256_hash revocation_hash = 2;
// Hash for revoking second commitment transaction.
required sha256_hash next_revocation_hash = 8;
// Pubkey for anchor to pay into commitment tx.
required bitcoin_pubkey commit_key = 3;
// How to pay money to us from commit_tx.
required bitcoin_pubkey final_key = 4;
enum anchor_offer {
// I will create the anchor
WILL_CREATE_ANCHOR = 1;
// I won't create the anchor
WONT_CREATE_ANCHOR = 2;
}
required anchor_offer anch = 5;
// How far must anchor be buried before we consider channel live?
optional uint32 min_depth = 6 [ default = 0 ];
// How much fee would I like on commitment tx?
required uint64 initial_fee_rate = 7;
}
// Whoever is supplying anchor sends this.
message open_anchor {
// Transaction ID of anchor.
required sha256_hash txid = 1;
// Which output is going to the 2 of 2.
required uint32 output_index = 2;
// Amount of anchor output.
required uint64 amount = 3;
}
// Reply: signature for your initial commitment tx
message open_commit_sig {
required signature sig = 1;
}
// Indicates we've seen anchor reach min-depth.
message open_complete {
// Block it went into.
optional sha256_hash blockid = 1;
// FIXME: add a merkle proof plus block headers here?
}
message route_step {
// Where to next?
oneof next {
// Actually, this is the last one
bool end = 1;
// Next lightning node.
bitcoin_pubkey bitcoin = 2;
// Other realms go here...
}
// How much to forward (difference is fee)
required uint32 amount = 4;
};
message route {
repeated route_step steps = 1;
};
message routing {
required bytes info = 1;
}
// Start a new commitment tx to add an HTLC me -> you.
message update_add_htlc {
// Unique identifier for this HTLC.
required uint64 id = 1;
// Amount for htlc (millisatoshi)
required uint32 amount_msat = 2;
// Hash for HTLC R value.
required sha256_hash r_hash = 3;
// Time at which HTLC expires (absolute)
required locktime expiry = 4;
// Onion-wrapped routing information.
required routing route = 5;
}
// Complete your HTLC: I have the R value, pay me!
message update_fulfill_htlc {
// Which HTLC
required uint64 id = 1;
// HTLC payment_preimage.
required preimage r = 2;
}
// This is encrypted in fail_reason.
message fail_info {
required bitcoin_pubkey id = 1;
required uint32 error_code = 2;
optional string reason = 3;
}
message fail_reason {
required bytes info = 1;
}
message update_fail_htlc {
// Which HTLC
required uint64 id = 1;
// Reason for failure (for relay to initial node)
required fail_reason reason = 2;
}
// Fee rate change proposal
message update_fee {
required uint32 fee_rate = 1;
}
// Commit all the staged changes.
message update_commit {
// Signature for your new commitment tx (if any outputs are HTLCs or to you)
optional signature sig = 1;
}
// Complete the update.
message update_revocation {
// Hash preimage which revokes old commitment tx.
required sha256_hash revocation_preimage = 1;
// Revocation hash for my next commit transaction
required sha256_hash next_revocation_hash = 2;
}
// Start clearing out the channel HTLCs so we can close it
message close_shutdown {
// Output script for mutual close tx.
required bytes scriptPubkey = 1;
}
message close_signature {
// Fee in satoshis.
required uint64 close_fee = 1;
// Signature on the close transaction.
required signature sig = 2;
}
// This means we're going to hang up; it's to help diagnose only!
message error {
optional string problem = 1;
}
// Nested message to transport standard protocol messages through the legacy transport
message nested_pkt {
required uint32 type = 1;
required bytes inner_pkt = 2;
}
// This is the union which defines all of them
message pkt {
oneof pkt {
// Start of connection
authenticate auth = 50;
init init = 51;
// Opening
open_channel open = 20;
open_anchor open_anchor = 21;
open_commit_sig open_commit_sig = 22;
open_complete open_complete = 23;
// Updating (most common)
update_add_htlc update_add_htlc = 2;
update_fulfill_htlc update_fulfill_htlc = 3;
update_fail_htlc update_fail_htlc = 4;
update_fee update_fee = 5;
update_commit update_commit = 6;
update_revocation update_revocation = 7;
// Closing
close_shutdown close_shutdown = 30;
close_signature close_signature = 31;
// Unexpected issue.
error error = 40;
// Shim to upgrade to new packet format
nested_pkt nested = 128;
}
}

8
lightningd/lightningd.c

@ -88,14 +88,6 @@ bool db_remove_invoice(struct lightningd_state *dstate,
return true; return true;
} }
#include <daemon/packets.h>
void queue_pkt_nested(struct peer *peer,
int type,
const u8 *nested_pkt)
{
FIXME_IMPLEMENT();
}
static struct lightningd *new_lightningd(const tal_t *ctx) static struct lightningd *new_lightningd(const tal_t *ctx)
{ {
struct lightningd *ld = tal(ctx, struct lightningd); struct lightningd *ld = tal(ctx, struct lightningd);

206
protobuf_convert.c

@ -1,206 +0,0 @@
#include "bitcoin/locktime.h"
#include "bitcoin/preimage.h"
#include "bitcoin/pubkey.h"
#include "bitcoin/signature.h"
#include "protobuf_convert.h"
#include "type_to_string.h"
#include "utils.h"
#include <ccan/crypto/sha256/sha256.h>
Signature *signature_to_proto(const tal_t *ctx, const secp256k1_ecdsa_signature *sig)
{
u8 compact[64];
Signature *pb = tal(ctx, Signature);
signature__init(pb);
assert(sig_valid(sig));
secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx,
compact, sig);
/* Kill me now... */
memcpy(&pb->r1, compact, 8);
memcpy(&pb->r2, compact + 8, 8);
memcpy(&pb->r3, compact + 16, 8);
memcpy(&pb->r4, compact + 24, 8);
memcpy(&pb->s1, compact + 32, 8);
memcpy(&pb->s2, compact + 40, 8);
memcpy(&pb->s3, compact + 48, 8);
memcpy(&pb->s4, compact + 56, 8);
return pb;
}
bool proto_to_signature(const Signature *pb, secp256k1_ecdsa_signature *sig)
{
u8 compact[64];
/* Kill me again. */
memcpy(compact, &pb->r1, 8);
memcpy(compact + 8, &pb->r2, 8);
memcpy(compact + 16, &pb->r3, 8);
memcpy(compact + 24, &pb->r4, 8);
memcpy(compact + 32, &pb->s1, 8);
memcpy(compact + 40, &pb->s2, 8);
memcpy(compact + 48, &pb->s3, 8);
memcpy(compact + 56, &pb->s4, 8);
if (secp256k1_ecdsa_signature_parse_compact(secp256k1_ctx,
sig, compact)
!= 1)
return false;
return sig_valid(sig);
}
BitcoinPubkey *pubkey_to_proto(const tal_t *ctx, const struct pubkey *key)
{
BitcoinPubkey *p = tal(ctx, BitcoinPubkey);
bitcoin_pubkey__init(p);
p->key.len = PUBKEY_DER_LEN;
p->key.data = tal_arr(p, u8, p->key.len);
pubkey_to_der(p->key.data, key);
return p;
}
bool proto_to_pubkey(const BitcoinPubkey *pb, struct pubkey *key)
{
return pubkey_from_der(pb->key.data, pb->key.len, key);
}
Sha256Hash *sha256_to_proto(const tal_t *ctx, const struct sha256 *hash)
{
Sha256Hash *h = tal(ctx, Sha256Hash);
sha256_hash__init(h);
/* Kill me now... */
memcpy(&h->a, hash->u.u8, 8);
memcpy(&h->b, hash->u.u8 + 8, 8);
memcpy(&h->c, hash->u.u8 + 16, 8);
memcpy(&h->d, hash->u.u8 + 24, 8);
return h;
}
void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash)
{
/* Kill me again. */
memcpy(hash->u.u8, &pb->a, 8);
memcpy(hash->u.u8 + 8, &pb->b, 8);
memcpy(hash->u.u8 + 16, &pb->c, 8);
memcpy(hash->u.u8 + 24, &pb->d, 8);
}
Preimage *preimage_to_proto(const tal_t *ctx, const struct preimage *r)
{
Preimage *pb = tal(ctx, Preimage);
preimage__init(pb);
/* Kill me now... */
memcpy(&pb->a, r->r, 8);
memcpy(&pb->b, r->r + 8, 8);
memcpy(&pb->c, r->r + 16, 8);
memcpy(&pb->d, r->r + 24, 8);
return pb;
}
void proto_to_preimage(const Preimage *pb, struct preimage *r)
{
/* Kill me again. */
memcpy(r->r, &pb->a, 8);
memcpy(r->r + 8, &pb->b, 8);
memcpy(r->r + 16, &pb->c, 8);
memcpy(r->r + 24, &pb->d, 8);
}
bool proto_to_rel_locktime(const Locktime *l, struct rel_locktime *locktime)
{
switch (l->locktime_case) {
case LOCKTIME__LOCKTIME_SECONDS:
return seconds_to_rel_locktime(l->seconds, locktime);
case LOCKTIME__LOCKTIME_BLOCKS:
return blocks_to_rel_locktime(l->blocks, locktime);
default:
return false;
}
}
bool proto_to_abs_locktime(const Locktime *l, struct abs_locktime *locktime)
{
switch (l->locktime_case) {
case LOCKTIME__LOCKTIME_SECONDS:
return seconds_to_abs_locktime(l->seconds, locktime);
case LOCKTIME__LOCKTIME_BLOCKS:
return blocks_to_abs_locktime(l->blocks, locktime);
default:
return false;
}
}
Locktime *rel_locktime_to_proto(const tal_t *ctx,
const struct rel_locktime *locktime)
{
Locktime *l = tal(ctx, Locktime);
locktime__init(l);
if (rel_locktime_is_seconds(locktime)) {
l->locktime_case = LOCKTIME__LOCKTIME_SECONDS;
l->seconds = rel_locktime_to_seconds(locktime);
} else {
l->locktime_case = LOCKTIME__LOCKTIME_BLOCKS;
l->blocks = rel_locktime_to_blocks(locktime);
}
return l;
}
Locktime *abs_locktime_to_proto(const tal_t *ctx,
const struct abs_locktime *locktime)
{
Locktime *l = tal(ctx, Locktime);
locktime__init(l);
if (abs_locktime_is_seconds(locktime)) {
l->locktime_case = LOCKTIME__LOCKTIME_SECONDS;
l->seconds = abs_locktime_to_seconds(locktime);
} else {
l->locktime_case = LOCKTIME__LOCKTIME_BLOCKS;
l->blocks = abs_locktime_to_blocks(locktime);
}
return l;
}
static void *proto_tal_alloc(void *allocator_data, size_t size)
{
return tal_arr(allocator_data, char, size);
}
static void proto_tal_free(void *allocator_data, void *pointer)
{
tal_free(pointer);
}
/* Get allocator so decoded protobuf will be tal off it. */
struct ProtobufCAllocator *make_prototal(const tal_t *ctx)
{
struct ProtobufCAllocator *prototal;
prototal = tal(ctx, struct ProtobufCAllocator);
prototal->alloc = proto_tal_alloc;
prototal->free = proto_tal_free;
prototal->allocator_data = tal(prototal, char);
return prototal;
}
/* Now steal object off of allocator (and free prototal) */
void steal_from_prototal(const tal_t *ctx, struct ProtobufCAllocator *prototal,
const void *pb)
{
tal_steal(ctx, pb);
tal_steal(pb, prototal->allocator_data);
tal_free(prototal);
}
REGISTER_TYPE_TO_HEXSTR(preimage);

45
protobuf_convert.h

@ -1,45 +0,0 @@
#ifndef LIGHTNING_PROTOBUF_CONVERT_H
#define LIGHTNING_PROTOBUF_CONVERT_H
#include "config.h"
#include "lightning.pb-c.h"
#include <ccan/tal/tal.h>
#include <secp256k1.h>
#include <stdbool.h>
/* Convert to-from protobuf to internal representation. */
Signature *signature_to_proto(const tal_t *ctx,
const secp256k1_ecdsa_signature *sig);
bool proto_to_signature(const Signature *pb,
secp256k1_ecdsa_signature *sig);
/* Convert to-from protobuf to internal representation. */
struct pubkey;
BitcoinPubkey *pubkey_to_proto(const tal_t *ctx,
const struct pubkey *key);
bool proto_to_pubkey(const BitcoinPubkey *pb, struct pubkey *key);
/* Useful helper for allocating & populating a protobuf Sha256Hash */
struct sha256;
Sha256Hash *sha256_to_proto(const tal_t *ctx, const struct sha256 *hash);
void proto_to_sha256(const Sha256Hash *pb, struct sha256 *hash);
struct preimage;
Preimage *preimage_to_proto(const tal_t *ctx, const struct preimage *r);
void proto_to_preimage(const Preimage *pb, struct preimage *r);
struct rel_locktime;
struct abs_locktime;
bool proto_to_rel_locktime(const Locktime *l, struct rel_locktime *locktime);
bool proto_to_abs_locktime(const Locktime *l, struct abs_locktime *locktime);
Locktime *rel_locktime_to_proto(const tal_t *ctx,
const struct rel_locktime *locktime);
Locktime *abs_locktime_to_proto(const tal_t *ctx,
const struct abs_locktime *locktime);
/* Get allocator so decoded protobuf will be tal off it. */
struct ProtobufCAllocator *make_prototal(const tal_t *ctx);
/* Now steal object off of allocator (and free prototal) */
void steal_from_prototal(const tal_t *ctx, struct ProtobufCAllocator *prototal,
const void *pb);
#endif /* LIGHTNING_PROTOBUF_CONVERT_H */

1
type_to_string.c

@ -2,7 +2,6 @@
#include "bitcoin/pubkey.h" #include "bitcoin/pubkey.h"
#include "bitcoin/tx.h" #include "bitcoin/tx.h"
#include "daemon/htlc.h" #include "daemon/htlc.h"
#include "protobuf_convert.h"
#include "type_to_string.h" #include "type_to_string.h"
#include "utils.h" #include "utils.h"
#include <ccan/tal/str/str.h> #include <ccan/tal/str/str.h>

Loading…
Cancel
Save