mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-03 13:14:22 +01:00
lightningd/channel: convert to subd.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -10,8 +10,7 @@ lightningd/channel-all: lightningd/lightningd_channel
|
||||
|
||||
# lightningd/channel needs these:
|
||||
LIGHTNINGD_CHANNEL_HEADERS_GEN := \
|
||||
lightningd/channel/gen_channel_control_wire.h \
|
||||
lightningd/channel/gen_channel_status_wire.h
|
||||
lightningd/channel/gen_channel_wire.h
|
||||
|
||||
LIGHTNINGD_CHANNEL_HEADERS_NOGEN :=
|
||||
|
||||
@@ -36,17 +35,11 @@ LIGHTNINGD_HEADERS_NOGEN += $(LIGHTNINGD_CHANNEL_HEADERS_NOGEN)
|
||||
|
||||
$(LIGHTNINGD_CHANNEL_OBJS): $(LIGHTNINGD_HEADERS)
|
||||
|
||||
lightningd/channel/gen_channel_control_wire.h: $(WIRE_GEN) lightningd/channel/channel_control_wire.csv
|
||||
$(WIRE_GEN) --header $@ channel_control_wire_type < lightningd/channel/channel_control_wire.csv > $@
|
||||
lightningd/channel/gen_channel_wire.h: $(WIRE_GEN) lightningd/channel/channel_wire.csv
|
||||
$(WIRE_GEN) --header $@ channel_wire_type < lightningd/channel/channel_wire.csv > $@
|
||||
|
||||
lightningd/channel/gen_channel_control_wire.c: $(WIRE_GEN) lightningd/channel/channel_control_wire.csv
|
||||
$(WIRE_GEN) ${@:.c=.h} channel_control_wire_type < lightningd/channel/channel_control_wire.csv > $@
|
||||
|
||||
lightningd/channel/gen_channel_status_wire.h: $(WIRE_GEN) lightningd/channel/channel_status_wire.csv
|
||||
$(WIRE_GEN) --header $@ channel_status_wire_type < lightningd/channel/channel_status_wire.csv > $@
|
||||
|
||||
lightningd/channel/gen_channel_status_wire.c: $(WIRE_GEN) lightningd/channel/channel_status_wire.csv
|
||||
$(WIRE_GEN) ${@:.c=.h} channel_status_wire_type < lightningd/channel/channel_status_wire.csv > $@
|
||||
lightningd/channel/gen_channel_wire.c: $(WIRE_GEN) lightningd/channel/channel_wire.csv
|
||||
$(WIRE_GEN) ${@:.c=.h} channel_wire_type < lightningd/channel/channel_wire.csv > $@
|
||||
|
||||
LIGHTNINGD_CHANNEL_OBJS := $(LIGHTNINGD_CHANNEL_SRC:.c=.o) $(LIGHTNINGD_CHANNEL_GEN_SRC:.c=.o)
|
||||
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <lightningd/channel.h>
|
||||
#include <lightningd/channel/gen_channel_control_wire.h>
|
||||
#include <lightningd/channel/gen_channel_status_wire.h>
|
||||
#include <lightningd/channel/gen_channel_wire.h>
|
||||
#include <lightningd/commit_tx.h>
|
||||
#include <lightningd/crypto_sync.h>
|
||||
#include <lightningd/cryptomsg.h>
|
||||
@@ -28,8 +27,7 @@
|
||||
#include <wire/wire_io.h>
|
||||
#include <wire/wire_sync.h>
|
||||
|
||||
/* Stdout == status, stdin == requests, 3 == peer */
|
||||
#define STATUS_FD STDOUT_FILENO
|
||||
/* stdin == requests, 3 == peer */
|
||||
#define REQ_FD STDIN_FILENO
|
||||
#define PEER_FD 3
|
||||
|
||||
@@ -176,7 +174,7 @@ int main(int argc, char *argv[])
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN);
|
||||
status_setup(STATUS_FD);
|
||||
status_setup(REQ_FD);
|
||||
peer->peer_out = tal_arr(peer, const u8 *, 0);
|
||||
init_peer_crypto_state(peer, &peer->pcs);
|
||||
peer->funding_locked[LOCAL] = peer->funding_locked[REMOTE] = false;
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
# Shouldn't happen
|
||||
channel_bad_command,0x8000
|
||||
# Also shouldn't happen
|
||||
channel_hsm_failed,0x8001
|
||||
|
||||
# These are due to peer.
|
||||
channel_peer_write_failed,0x8010
|
||||
channel_peer_read_failed,0x8011
|
||||
channel_peer_bad_message,0x8012
|
||||
|
||||
# Received funding_locked
|
||||
channel_received_funding_locked,1
|
||||
# Received and sent fundin_locked
|
||||
channel_normal_operation,2
|
||||
|
@@ -1,3 +1,18 @@
|
||||
# Shouldn't happen
|
||||
channel_bad_command,0x8000
|
||||
# Also shouldn't happen
|
||||
channel_hsm_failed,0x8001
|
||||
|
||||
# These are due to peer.
|
||||
channel_peer_write_failed,0x8010
|
||||
channel_peer_read_failed,0x8011
|
||||
channel_peer_bad_message,0x8012
|
||||
|
||||
# Received funding_locked
|
||||
channel_received_funding_locked,1000
|
||||
# Received and sent funding_locked
|
||||
channel_normal_operation,1001
|
||||
|
||||
#include <lightningd/cryptomsg.h>
|
||||
#include <lightningd/channel_config.h>
|
||||
|
||||
|
@@ -16,8 +16,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <lightningd/build_utxos.h>
|
||||
#include <lightningd/channel.h>
|
||||
#include <lightningd/channel/gen_channel_control_wire.h>
|
||||
#include <lightningd/channel/gen_channel_status_wire.h>
|
||||
#include <lightningd/channel/gen_channel_wire.h>
|
||||
#include <lightningd/funding_tx.h>
|
||||
#include <lightningd/gossip/gen_gossip_wire.h>
|
||||
#include <lightningd/handshake/gen_handshake_wire.h>
|
||||
@@ -550,8 +549,9 @@ static enum watch_result funding_depth_cb(struct peer *peer,
|
||||
}
|
||||
|
||||
peer_set_condition(peer, "Funding tx reached depth %u", depth);
|
||||
subdaemon_req(peer->owner, take(towire_channel_funding_locked(peer)),
|
||||
-1, NULL, NULL, NULL);
|
||||
/* FIXME: subdaemon */
|
||||
subd_send_msg((struct subd *)peer->owner,
|
||||
take(towire_channel_funding_locked(peer)));
|
||||
return DELETE_WATCH;
|
||||
}
|
||||
|
||||
@@ -598,11 +598,11 @@ static bool opening_got_hsm_funding_sig(struct subd *hsm, const u8 *resp,
|
||||
return true;
|
||||
}
|
||||
|
||||
static enum subdaemon_status update_channel_status(struct subdaemon *sd,
|
||||
const u8 *msg,
|
||||
int unused)
|
||||
static enum subd_msg_ret update_channel_status(struct subd *sd,
|
||||
const u8 *msg,
|
||||
int unused)
|
||||
{
|
||||
enum channel_status_wire_type t = fromwire_peektype(msg);
|
||||
enum channel_wire_type t = fromwire_peektype(msg);
|
||||
|
||||
switch (t) {
|
||||
case WIRE_CHANNEL_RECEIVED_FUNDING_LOCKED:
|
||||
@@ -617,10 +617,13 @@ static enum subdaemon_status update_channel_status(struct subdaemon *sd,
|
||||
case WIRE_CHANNEL_PEER_WRITE_FAILED:
|
||||
case WIRE_CHANNEL_PEER_READ_FAILED:
|
||||
case WIRE_CHANNEL_PEER_BAD_MESSAGE:
|
||||
/* And we never get these from channeld. */
|
||||
case WIRE_CHANNEL_INIT:
|
||||
case WIRE_CHANNEL_FUNDING_LOCKED:
|
||||
break;
|
||||
}
|
||||
|
||||
return STATUS_COMPLETE;
|
||||
return SUBD_COMPLETE;
|
||||
}
|
||||
|
||||
/* opening is done, start lightningd_channel for peer. */
|
||||
@@ -635,10 +638,9 @@ static void peer_start_channeld(struct peer *peer, bool am_funder,
|
||||
u8 *msg;
|
||||
|
||||
/* Normal channel daemon. */
|
||||
peer->owner = new_subdaemon(peer->ld, peer->ld,
|
||||
peer->owner = (struct subdaemon *)new_subd(peer->ld, peer->ld,
|
||||
"lightningd_channel", peer,
|
||||
channel_status_wire_type_name,
|
||||
channel_control_wire_type_name,
|
||||
channel_wire_type_name,
|
||||
update_channel_status, NULL,
|
||||
peer->fd, -1);
|
||||
if (!peer->owner) {
|
||||
@@ -671,7 +673,8 @@ static void peer_start_channeld(struct peer *peer, bool am_funder,
|
||||
peer->seed);
|
||||
|
||||
/* We don't expect a response: we are triggered by funding_depth_cb. */
|
||||
subdaemon_req(peer->owner, take(msg), -1, NULL, NULL, NULL);
|
||||
/* FIXME: subdaemon */
|
||||
subd_send_msg((struct subd *)peer->owner, take(msg));
|
||||
}
|
||||
|
||||
static bool opening_release_tx(struct subd *opening, const u8 *resp,
|
||||
|
||||
Reference in New Issue
Block a user