Browse Source

wire: split onion messages from peer wire messages.

The recent update to BOLT #4 includes failure message specifications,
which are completely orthogonal to the normal ones.  Don't include
them in the gen_peer_wire_csv.

This onion_defs.h file assumes we are using 2-byte failure codes as per
the onion-failmsg-cleanup branch.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 8 years ago
parent
commit
d8feec2197
  1. 18
      wire/Makefile
  2. 29
      wire/gen_onion_wire_csv
  3. 18
      wire/onion_defs.h

18
wire/Makefile

@ -5,17 +5,22 @@ wire-wrongdir:
$(MAKE) -C .. wire-all
WIRE_HEADERS := wire/wire.h
WIRE_GEN_HEADERS := wire/gen_peer_wire.h
WIRE_GEN_HEADERS := wire/gen_peer_wire.h wire/gen_onion_wire.h
WIRE_GEN_SRC := wire/gen_peer_wire.c
WIRE_GEN_ONION_SRC := wire/gen_onion_wire.c
WIRE_SRC := wire/fromwire.c \
wire/towire.c
WIRE_OBJS := $(WIRE_SRC:.c=.o) $(WIRE_GEN_SRC:.c=.o)
WIRE_ONION_OBJS := $(WIRE_GEN_ONION_SRC:.c=.o)
# They may not have the bolts.
BOLT_EXTRACT=$(BOLTDIR)/tools/extract-formats.py
wire/gen_peer_wire_csv: FORCE
@set -e; if [ -f $(BOLT_EXTRACT) ]; then for f in $(BOLTDIR)/*.md $(BOLT_EXTRACT); do if [ $$f -nt $@ -o ! -f $@ ]; then $(BOLT_EXTRACT) --message-fields --message-types --check-alignment $(BOLTDIR)/*.md > $@; break; fi; done; fi
@set -e; if [ -f $(BOLT_EXTRACT) ]; then for f in $(BOLTDIR)/0[127]*.md $(BOLT_EXTRACT); do if [ $$f -nt $@ -o ! -f $@ ]; then $(BOLT_EXTRACT) --message-fields --message-types --check-alignment $(BOLTDIR)/0[127]*.md > $@; break; fi; done; fi
wire/gen_onion_wire_csv: FORCE
@set -e; if [ -f $(BOLT_EXTRACT) ]; then for f in $(BOLTDIR)/04*.md $(BOLT_EXTRACT); do if [ $$f -nt $@ -o ! -f $@ ]; then echo '#include <wire/onion_defs.h>' > $@ && $(BOLT_EXTRACT) --message-fields --message-types --check-alignment $(BOLTDIR)/04*.md >> $@; break; fi; done; fi
wire/gen_peer_wire.h: $(WIRE_GEN) wire/gen_peer_wire_csv
$(WIRE_GEN) --header $@ wire_type < wire/gen_peer_wire_csv > $@
@ -23,7 +28,14 @@ wire/gen_peer_wire.h: $(WIRE_GEN) wire/gen_peer_wire_csv
wire/gen_peer_wire.c: $(WIRE_GEN) wire/gen_peer_wire_csv
$(WIRE_GEN) ${@:.c=.h} wire_type < wire/gen_peer_wire_csv > $@
wire/gen_onion_wire.h: $(WIRE_GEN) wire/gen_onion_wire_csv
$(WIRE_GEN) --header $@ onion_type < wire/gen_onion_wire_csv > $@
wire/gen_onion_wire.c: $(WIRE_GEN) wire/gen_onion_wire_csv
$(WIRE_GEN) ${@:.c=.h} onion_type < wire/gen_onion_wire_csv > $@
wire/gen_peer_wire.o: wire/gen_peer_wire.h
wire/gen_onion_wire.o: wire/gen_onion_wire.h
check-source: $(WIRE_SRC:%=check-src-include-order/%) $(WIRE_HEADERS:%=check-hdr-include-order/%)
@ -33,7 +45,7 @@ check-whitespace: $(WIRE_SRC:%=check-whitespace/%) $(WIRE_HEADERS:%=check-whites
clean: wire-clean
wire-all: wire/gen_peer_wire.o wire/fromwire.o wire/towire.o
wire-all: wire/gen_peer_wire.o wire/gen_onion_wire.o wire/fromwire.o wire/towire.o
wire-clean:
$(RM) $(WIRE_OBJS) $(WIRE_GEN_SRC) $(WIRE_GEN_HEADERS) towire.c fromwire.c

29
wire/gen_onion_wire_csv

@ -0,0 +1,29 @@
#include <wire/onion_defs.h>
invalid_realm,PERM|1
temporary_node_failure,NODE|2
permanent_node_failure,PERM|NODE|2
required_node_feature_missing,PERM|NODE|3
invalid_onion_version,BADONION|PERM|4
invalid_onion_version,0,sha256-of-onion,32
invalid_onion_hmac,BADONION|PERM|5
invalid_onion_hmac,0,sha256-of-onion,32
invalid_onion_key,BADONION|PERM|6
invalid_onion_key,0,sha256-of-onion,32
temporary_channel_failure,7
permanent_channel_failure,PERM|8
required_channel_feature_missing,PERM|9
unknown_next_peer,PERM|10
amount_below_minimum,UPDATE|11
amount_below_minimum,0,htlc-msat,4
amount_below_minimum,4,len,2
fee_insufficient,UPDATE|12
fee_insufficient,0,htlc-msat,4
fee_insufficient,4,len,2
incorrect_cltv_expiry,UPDATE|13
incorrect_cltv_expiry,0,cltv-expiry,4
incorrect_cltv_expiry,4,len,2
expiry_too_soon,UPDATE|14
expiry_too_soon,0,len,2
unknown_payment_hash,PERM|15
incorrect_payment_amount,PERM|16
final_expiry_too_soon,17

18
wire/onion_defs.h

@ -0,0 +1,18 @@
/* Macro definitions for constants used in BOLT #4 */
#ifndef LIGHTNING_WIRE_ONION_DEFS_H
#define LIGHTNING_WIRE_ONION_DEFS_H
/* BOLT #4:
*
* The top byte of `failure-code` can be read as a set of flags:
* * 0x8000 (BADONION): unparsable onion, encrypted by previous node.
* * 0x4000 (PERM): permanent failure (otherwise transient)
* * 0x2000 (NODE): node failure (otherwise channel)
* * 0x1000 (UPDATE): new channel update enclosed
*/
#define BADONION 0x8000
#define PERM 0x4000
#define NODE 0x2000
#define UPDATE 0x1000
#endif /* LIGHTNING_WIRE_ONION_DEFS_H */
Loading…
Cancel
Save