@ -33,8 +33,8 @@ struct pending_cannouncement {
/* Unpacked fields here */
struct short_channel_id short_channel_id ;
struct pubkey node_id_1 ;
struct pubkey node_id_2 ;
struct node_id node_id_1 ;
struct node_id node_id_2 ;
struct pubkey bitcoin_key_1 ;
struct pubkey bitcoin_key_2 ;
@ -50,21 +50,21 @@ struct pending_cannouncement {
} ;
struct pending_node_announce {
struct pubkey nodeid ;
struct node_id nodeid ;
u8 * node_announcement ;
u32 timestamp ;
} ;
static const struct pubkey *
static const struct node_id *
pending_node_announce_keyof ( const struct pending_node_announce * a )
{
return & a - > nodeid ;
}
static bool pending_node_announce_eq ( const struct pending_node_announce * pna ,
const struct pubkey * key )
const struct node_id * pc )
{
return pubkey _eq( & pna - > nodeid , key ) ;
return node_id _eq( & pna - > nodeid , pc ) ;
}
HTABLE_DEFINE_TYPE ( struct pending_node_announce , pending_node_announce_keyof ,
@ -147,7 +147,7 @@ struct chan *next_chan(const struct node *node, struct chan_map_iter *i)
struct routing_state * new_routing_state ( const tal_t * ctx ,
const struct chainparams * chainparams ,
const struct pubkey * local_id ,
const struct node_id * local_id ,
u32 prune_timeout ,
const u32 * dev_gossip_time ,
const struct amount_sat * dev_unknown_channel_satoshis )
@ -181,19 +181,19 @@ struct routing_state *new_routing_state(const tal_t *ctx,
}
const struct pubkey * node_map_keyof_node ( const struct node * n )
const struct node_id * node_map_keyof_node ( const struct node * n )
{
return & n - > id ;
}
size_t node_map_hash_key ( const struct pubkey * key )
size_t node_map_hash_key ( const struct node_id * pc )
{
return siphash24 ( siphash_seed ( ) , key , sizeof ( * key ) ) ;
return siphash24 ( siphash_seed ( ) , pc - > k , sizeof ( pc - > k ) ) ;
}
bool node_map_node_eq ( const struct node * n , const struct pubkey * key )
bool node_map_node_eq ( const struct node * n , const struct node_id * pc )
{
return pubkey _eq( & n - > id , key ) ;
return node_id _eq( & n - > id , pc ) ;
}
@ -212,13 +212,14 @@ static void destroy_node(struct node *node, struct routing_state *rstate)
chan_map_clear ( & node - > chans . map ) ;
}
struct node * get_node ( struct routing_state * rstate , const struct pubkey * id )
struct node * get_node ( struct routing_state * rstate ,
const struct node_id * id )
{
return node_map_get ( rstate - > nodes , id ) ;
}
static struct node * new_node ( struct routing_state * rstate ,
const struct pubkey * id )
const struct node_id * id )
{
struct node * n ;
@ -373,12 +374,12 @@ static void bad_gossip_order(const u8 *msg, const char *source,
struct chan * new_chan ( struct routing_state * rstate ,
const struct short_channel_id * scid ,
const struct pubkey * id1 ,
const struct pubkey * id2 ,
const struct node_id * id1 ,
const struct node_id * id2 ,
struct amount_sat satoshis )
{
struct chan * chan = tal ( rstate , struct chan ) ;
int n1idx = pubkey _idx( id1 , id2 ) ;
int n1idx = node_id _idx( id1 , id2 ) ;
struct node * n1 , * n2 ;
/* We should never add a channel twice */
@ -537,7 +538,7 @@ static void bfg_one_edge(struct node *node,
if ( amount_msat_less ( this_total , curr_total ) ) {
SUPERVERBOSE ( " ...%s can reach here hoplen %zu "
" total %s risk %s " ,
type_to_string ( tmpctx , struct pubkey ,
type_to_string ( tmpctx , struct node_id ,
& src - > id ) ,
h ,
type_to_string ( tmpctx , struct amount_msat ,
@ -561,7 +562,7 @@ static bool hc_is_routable(const struct chan *chan, int idx)
/* riskfactor is already scaled to per-block amount */
static struct chan * *
find_route ( const tal_t * ctx , struct routing_state * rstate ,
const struct pubkey * from , const struct pubkey * to ,
const struct node_id * from , const struct node_id * to ,
struct amount_msat msat ,
double riskfactor ,
double fuzz , const struct siphash_seed * base_seed ,
@ -581,15 +582,15 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
if ( ! src ) {
status_info ( " find_route: cannot find %s " ,
type_to_string ( tmpctx , struct pubkey , to ) ) ;
type_to_string ( tmpctx , struct node_id , to ) ) ;
return NULL ;
} else if ( ! dst ) {
status_info ( " find_route: cannot find myself (%s) " ,
type_to_string ( tmpctx , struct pubkey , to ) ) ;
type_to_string ( tmpctx , struct node_id , to ) ) ;
return NULL ;
} else if ( dst = = src ) {
status_info ( " find_route: this is %s, refusing to create empty route " ,
type_to_string ( tmpctx , struct pubkey , to ) ) ;
type_to_string ( tmpctx , struct node_id , to ) ) ;
return NULL ;
}
@ -622,7 +623,7 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
int idx = half_chan_to ( n , chan ) ;
SUPERVERBOSE ( " Node %s edge %s " ,
type_to_string ( tmpctx , struct pubkey ,
type_to_string ( tmpctx , struct node_id ,
& n - > id ) ,
type_to_string ( tmpctx ,
struct short_channel_id ,
@ -666,7 +667,7 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
/* No route? */
if ( amount_msat_greater_eq ( best_total , INFINITE ) ) {
status_trace ( " find_route: No route to %s " ,
type_to_string ( tmpctx , struct pubkey , to ) ) ;
type_to_string ( tmpctx , struct node_id , to ) ) ;
return NULL ;
}
@ -692,9 +693,20 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
return route ;
}
/* Checks that key is valid, and signed this hash */
static bool check_signed_hash_nodeid ( const struct sha256_double * hash ,
const secp256k1_ecdsa_signature * signature ,
const struct node_id * id )
{
struct pubkey key ;
return pubkey_from_node_id ( & key , id )
& & check_signed_hash ( hash , signature , & key ) ;
}
/* Verify the signature of a channel_update message */
static u8 * check_channel_update ( const tal_t * ctx ,
const struct pubkey * node_key ,
const struct node_id * node_id ,
const secp256k1_ecdsa_signature * node_sig ,
const u8 * update )
{
@ -703,7 +715,7 @@ static u8 *check_channel_update(const tal_t *ctx,
struct sha256_double hash ;
sha256_double ( & hash , update + offset , tal_count ( update ) - offset ) ;
if ( ! check_signed_hash ( & hash , node_sig , node_key ) )
if ( ! check_signed_hash_nodeid ( & hash , node_sig , node_id ) )
return towire_errorfmt ( ctx , NULL ,
" Bad signature for %s hash %s "
" on channel_update %s " ,
@ -718,7 +730,7 @@ static u8 *check_channel_update(const tal_t *ctx,
}
static u8 * check_channel_announcement ( const tal_t * ctx ,
const struct pubkey * node1_key , const struct pubkey * node2_key ,
const struct node_id * node1_id , const struct node_id * node2_id ,
const struct pubkey * bitcoin1_key , const struct pubkey * bitcoin2_key ,
const secp256k1_ecdsa_signature * node1_sig ,
const secp256k1_ecdsa_signature * node2_sig ,
@ -731,7 +743,7 @@ static u8 *check_channel_announcement(const tal_t *ctx,
sha256_double ( & hash , announcement + offset ,
tal_count ( announcement ) - offset ) ;
if ( ! check_signed_hash ( & hash , node1_sig , node1_key ) ) {
if ( ! check_signed_hash_nodeid ( & hash , node1_sig , node1_id ) ) {
return towire_errorfmt ( ctx , NULL ,
" Bad node_signature_1 %s hash %s "
" on node_announcement %s " ,
@ -743,7 +755,7 @@ static u8 *check_channel_announcement(const tal_t *ctx,
& hash ) ,
tal_hex ( ctx , announcement ) ) ;
}
if ( ! check_signed_hash ( & hash , node2_sig , node2_key ) ) {
if ( ! check_signed_hash_nodeid ( & hash , node2_sig , node2_id ) ) {
return towire_errorfmt ( ctx , NULL ,
" Bad node_signature_2 %s hash %s "
" on node_announcement %s " ,
@ -782,7 +794,7 @@ static u8 *check_channel_announcement(const tal_t *ctx,
return NULL ;
}
static void add_pending_node_announcement ( struct routing_state * rstate , struct pubkey * nodeid )
static void add_pending_node_announcement ( struct routing_state * rstate , struct node_id * nodeid )
{
struct pending_node_announce * pna = tal ( rstate , struct pending_node_announce ) ;
pna - > nodeid = * nodeid ;
@ -792,7 +804,7 @@ static void add_pending_node_announcement(struct routing_state *rstate, struct p
}
static void process_pending_node_announcement ( struct routing_state * rstate ,
struct pubkey * nodeid )
struct node_id * nodeid )
{
struct pending_node_announce * pna = pending_node_map_get ( rstate - > pending_node_map , nodeid ) ;
if ( ! pna )
@ -802,7 +814,7 @@ static void process_pending_node_announcement(struct routing_state *rstate,
u8 * err ;
SUPERVERBOSE (
" Processing deferred node_announcement for node %s " ,
type_to_string ( pna , struct pubkey , nodeid ) ) ;
type_to_string ( pna , struct node_id , nodeid ) ) ;
/* Should not error, since we processed it before */
err = handle_node_announcement ( rstate , pna - > node_announcement ) ;
@ -838,8 +850,8 @@ static void destroy_pending_cannouncement(struct pending_cannouncement *pending,
static bool is_local_channel ( const struct routing_state * rstate ,
const struct chan * chan )
{
return pubkey _eq( & chan - > nodes [ 0 ] - > id , & rstate - > local_id )
| | pubkey _eq( & chan - > nodes [ 1 ] - > id , & rstate - > local_id ) ;
return node_id _eq( & chan - > nodes [ 0 ] - > id , & rstate - > local_id )
| | node_id _eq( & chan - > nodes [ 1 ] - > id , & rstate - > local_id ) ;
}
static void add_channel_announce_to_broadcast ( struct routing_state * rstate ,
@ -873,16 +885,20 @@ bool routing_add_channel_announcement(struct routing_state *rstate,
u8 * features ;
struct bitcoin_blkid chain_hash ;
struct short_channel_id scid ;
struct pubkey node_id_1 ;
struct pubkey node_id_2 ;
struct node_id node_id_1 ;
struct node_id node_id_2 ;
struct pubkey bitcoin_key_1 ;
struct pubkey bitcoin_key_2 ;
/* FIXME */
struct pubkey pk1 , pk2 ;
if ( ! fromwire_channel_announcement (
tmpctx , msg , & node_signature_1 , & node_signature_2 ,
& bitcoin_signature_1 , & bitcoin_signature_2 , & features , & chain_hash ,
& scid , & node_id_1 , & node_id_ 2, & bitcoin_key_1 , & bitcoin_key_2 ) )
& scid , & pk1 , & pk 2, & bitcoin_key_1 , & bitcoin_key_2 ) )
return false ;
node_id_from_pubkey ( & node_id_1 , & pk1 ) ;
node_id_from_pubkey ( & node_id_2 , & pk2 ) ;
/* The channel may already exist if it was non-public from
* local_add_channel ( ) ; normally we don ' t accept new
@ -926,6 +942,8 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
announce , tal_count ( announce ) , 0 ) ;
pending - > update_timestamps [ 0 ] = pending - > update_timestamps [ 1 ] = 0 ;
/* FIXME */
struct pubkey pk1 , pk2 ;
if ( ! fromwire_channel_announcement ( pending , pending - > announce ,
& node_signature_1 ,
& node_signature_2 ,
@ -934,8 +952,7 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
& features ,
& chain_hash ,
& pending - > short_channel_id ,
& pending - > node_id_1 ,
& pending - > node_id_2 ,
& pk1 , & pk2 ,
& pending - > bitcoin_key_1 ,
& pending - > bitcoin_key_2 ) ) {
err = towire_errorfmt ( rstate , NULL ,
@ -943,6 +960,8 @@ u8 *handle_channel_announcement(struct routing_state *rstate,
tal_hex ( pending , pending - > announce ) ) ;
goto malformed ;
}
node_id_from_pubkey ( & pending - > node_id_1 , & pk1 ) ;
node_id_from_pubkey ( & pending - > node_id_2 , & pk2 ) ;
/* If a prior txout lookup failed there is little point it trying
* again . Just drop the announcement and walk away whistling . Any non - 0
@ -1481,17 +1500,20 @@ bool routing_add_node_announcement(struct routing_state *rstate, const u8 *msg T
struct node * node ;
secp256k1_ecdsa_signature signature ;
u32 timestamp ;
struct pubkey node_id ;
struct node_id node_id ;
u8 rgb_color [ 3 ] ;
u8 alias [ 32 ] ;
u8 * features , * addresses ;
struct wireaddr * wireaddrs ;
/* FIXME */
struct pubkey pk ;
if ( ! fromwire_node_announcement ( tmpctx , msg ,
& signature , & features , & timestamp ,
& node_id , rgb_color , alias ,
& pk , rgb_color , alias ,
& addresses ) )
return false ;
node_id_from_pubkey ( & node_id , & pk ) ;
node = get_node ( rstate , & node_id ) ;
@ -1528,7 +1550,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
struct node * node ;
secp256k1_ecdsa_signature signature ;
u32 timestamp ;
struct pubkey node_id ;
struct node_id node_id ;
u8 rgb_color [ 3 ] ;
u8 alias [ 32 ] ;
u8 * features , * addresses ;
@ -1538,9 +1560,11 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
bool applied ;
serialized = tal_dup_arr ( tmpctx , u8 , node_ann , len , 0 ) ;
/* FIXME */
struct pubkey pk ;
if ( ! fromwire_node_announcement ( tmpctx , serialized ,
& signature , & features , & timestamp ,
& node_id , rgb_color , alias ,
& pk , rgb_color , alias ,
& addresses ) ) {
/* BOLT #7:
*
@ -1553,6 +1577,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
tal_hex ( tmpctx , node_ann ) ) ;
return err ;
}
node_id_from_pubkey ( & node_id , & pk ) ;
/* BOLT #7:
*
@ -1565,13 +1590,13 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
*/
if ( ! features_supported ( features , NULL ) ) {
status_trace ( " Ignoring node announcement for node %s, unsupported features %s. " ,
type_to_string ( tmpctx , struct pubkey , & node_id ) ,
type_to_string ( tmpctx , struct node_id , & node_id ) ,
tal_hex ( tmpctx , features ) ) ;
return NULL ;
}
sha256_double ( & hash , serialized + 66 , tal_count ( serialized ) - 66 ) ;
if ( ! check_signed_hash ( & hash , & signature , & node_id ) ) {
if ( ! check_signed_hash_nodeid ( & hash , & signature , & node_id ) ) {
/* BOLT #7:
*
* - if ` signature ` is not a valid signature , using
@ -1628,12 +1653,12 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
& node_id ) ;
if ( ! pna ) {
bad_gossip_order ( serialized , " node_announcement " ,
type_to_string ( tmpctx , struct pubkey ,
type_to_string ( tmpctx , struct node_id ,
& node_id ) ) ;
} else if ( pna - > timestamp < timestamp ) {
SUPERVERBOSE (
" Deferring node_announcement for node %s " ,
type_to_string ( tmpctx , struct pubkey , & node_id ) ) ;
type_to_string ( tmpctx , struct node_id , & node_id ) ) ;
pna - > timestamp = timestamp ;
tal_free ( pna - > node_announcement ) ;
pna - > node_announcement = tal_dup_arr ( pna , u8 , node_ann ,
@ -1649,7 +1674,7 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
}
status_trace ( " Received node_announcement for node %s " ,
type_to_string ( tmpctx , struct pubkey , & node_id ) ) ;
type_to_string ( tmpctx , struct node_id , & node_id ) ) ;
applied = routing_add_node_announcement ( rstate , serialized ) ;
assert ( applied ) ;
@ -1657,8 +1682,8 @@ u8 *handle_node_announcement(struct routing_state *rstate, const u8 *node_ann)
}
struct route_hop * get_route ( const tal_t * ctx , struct routing_state * rstate ,
const struct pubkey * source ,
const struct pubkey * destination ,
const struct node_id * source ,
const struct node_id * destination ,
struct amount_msat msat , double riskfactor ,
u32 final_cltv ,
double fuzz , u64 seed ,
@ -1733,13 +1758,13 @@ struct route_hop *get_route(const tal_t *ctx, struct routing_state *rstate,
total_delay + = c - > delay ;
n = other_node ( n , route [ i ] ) ;
}
assert ( pubkey _eq( & n - > id , source ) ) ;
assert ( node_id _eq( & n - > id , source ) ) ;
return hops ;
}
void routing_failure ( struct routing_state * rstate ,
const struct pubkey * erring_node_pubkey ,
const struct node_id * erring_node_id ,
const struct short_channel_id * scid ,
int erring_direction ,
enum onion_type failcode ,
@ -1749,7 +1774,7 @@ void routing_failure(struct routing_state *rstate,
" erring node %s, "
" channel %s/%u " ,
( int ) failcode , onion_type_name ( failcode ) ,
type_to_string ( tmpctx , struct pubkey , erring_node_pubkey ) ,
type_to_string ( tmpctx , struct node_id , erring_node_id ) ,
type_to_string ( tmpctx , struct short_channel_id , scid ) ,
erring_direction ) ;
@ -1775,18 +1800,18 @@ void routing_failure(struct routing_state *rstate,
return ;
if ( failcode & NODE ) {
struct node * node = get_node ( rstate , erring_node_pubkey ) ;
struct node * node = get_node ( rstate , erring_node_id ) ;
if ( ! node ) {
status_unusual ( " routing_failure: Erring node %s not in map " ,
type_to_string ( tmpctx , struct pubkey ,
erring_node_pubkey ) ) ;
type_to_string ( tmpctx , struct node_id ,
erring_node_id ) ) ;
} else {
struct chan_map_iter i ;
struct chan * c ;
status_trace ( " Deleting node %s " ,
type_to_string ( tmpctx ,
struct pubkey ,
struct node_id ,
& node - > id ) ) ;
for ( c = first_chan ( node , & i ) ; c ; c = next_chan ( node , & i ) ) {
/* Set it up to be pruned. */
@ -1806,8 +1831,8 @@ void routing_failure(struct routing_state *rstate,
/* This error can be triggered by sendpay if caller
* uses the wrong key for dest . */
if ( failcode = = WIRE_INVALID_ONION_HMAC
& & ! pubkey _eq( & chan - > nodes [ ! erring_direction ] - > id ,
erring_node_pubkey ) )
& & ! node_id _eq( & chan - > nodes [ ! erring_direction ] - > id ,
erring_node_id ) )
return ;
status_trace ( " Deleting channel %s " ,
@ -1879,7 +1904,7 @@ void memleak_remove_routing_tables(struct htable *memtable,
bool handle_local_add_channel ( struct routing_state * rstate , const u8 * msg )
{
struct short_channel_id scid ;
struct pubkey remote_node_id ;
struct node_id remote_node_id ;
struct amount_sat sat ;
if ( ! fromwire_gossipd_local_add_channel ( msg , & scid , & remote_node_id ,