9
9
#include <ccan/mem/mem.h>
10
10
#include <ccan/noerr/noerr.h>
11
11
#include <ccan/read_write_all/read_write_all.h>
12
+ #include <ccan/structeq/structeq.h>
12
13
#include <ccan/take/take.h>
13
14
#include <ccan/tal/str/str.h>
14
15
#include <ccan/timer/timer.h>
@@ -737,6 +738,48 @@ static void handle_get_update(struct peer *peer, const u8 *msg)
737
738
daemon_conn_send (peer -> remote , take (msg ));
738
739
}
739
740
741
+ static void handle_local_add_channel (struct peer * peer , u8 * msg )
742
+ {
743
+ struct routing_state * rstate = peer -> daemon -> rstate ;
744
+ struct short_channel_id scid ;
745
+ struct sha256_double chain_hash ;
746
+ struct pubkey remote_node_id ;
747
+ u16 flags , cltv_expiry_delta , direction ;
748
+ u32 fee_base_msat , fee_proportional_millionths ;
749
+ u64 htlc_minimum_msat ;
750
+ struct node_connection * c ;
751
+
752
+ if (!fromwire_gossip_local_add_channel (
753
+ msg , NULL , & scid , & chain_hash , & remote_node_id , & flags ,
754
+ & cltv_expiry_delta , & htlc_minimum_msat , & fee_base_msat ,
755
+ & fee_proportional_millionths )) {
756
+ status_trace ("Unable to parse local_add_channel message: %s" , tal_hex (msg , msg ));
757
+ return ;
758
+ }
759
+
760
+ if (!structeq (& chain_hash , & rstate -> chain_hash )) {
761
+ status_trace ("Received channel_announcement for unknown chain %s" ,
762
+ type_to_string (msg , struct sha256_double ,& chain_hash ));
763
+ return ;
764
+ }
765
+
766
+ if (get_connection_by_scid (rstate , & scid , 0 ) || get_connection_by_scid (rstate , & scid , 0 )) {
767
+ status_trace ("Attempted to local_add_channel a know channel" );
768
+ return ;
769
+ }
770
+
771
+ direction = get_channel_direction (& rstate -> local_id , & remote_node_id );
772
+ c = half_add_connection (rstate , & rstate -> local_id , & remote_node_id , & scid , direction );
773
+
774
+ c -> active = true;
775
+ c -> last_timestamp = 0 ;
776
+ c -> delay = cltv_expiry_delta ;
777
+ c -> htlc_minimum_msat = htlc_minimum_msat ;
778
+ c -> base_fee = fee_base_msat ;
779
+ c -> proportional_fee = fee_proportional_millionths ;
780
+ status_trace ("Added and updated local channel %s/%d" , type_to_string (msg , struct short_channel_id , & scid ), direction );
781
+ }
782
+
740
783
/**
741
784
* owner_msg_in - Called by the `peer->owner_conn` upon receiving a
742
785
* message
@@ -753,7 +796,15 @@ static struct io_plan *owner_msg_in(struct io_conn *conn,
753
796
handle_gossip_msg (peer -> daemon , dc -> msg_in );
754
797
} else if (type == WIRE_GOSSIP_GET_UPDATE ) {
755
798
handle_get_update (peer , dc -> msg_in );
799
+ } else if (type == WIRE_GOSSIP_LOCAL_ADD_CHANNEL ) {
800
+ handle_local_add_channel (peer , dc -> msg_in );
801
+ } else {
802
+ status_failed (
803
+ STATUS_FAIL_INTERNAL_ERROR ,
804
+ "Gossip received unknown message of type %s from owner" ,
805
+ gossip_wire_type_name (type ));
756
806
}
807
+
757
808
return daemon_conn_read_next (conn , dc );
758
809
}
759
810
0 commit comments