@ -16,6 +16,14 @@
/* 365.25 * 24 * 60 / 10 */
# define BLOCKS_PER_YEAR 52596
static struct node_map * empty_node_map ( const tal_t * ctx )
{
struct node_map * map = tal ( ctx , struct node_map ) ;
node_map_init ( map ) ;
tal_add_destructor ( map , node_map_clear ) ;
return map ;
}
struct routing_state * new_routing_state ( const tal_t * ctx ,
const struct sha256_double * chain_hash )
{
@ -42,20 +50,6 @@ bool node_map_node_eq(const struct node *n, const secp256k1_pubkey *key)
return structeq ( & n - > id . pubkey , key ) ;
}
struct node_map * empty_node_map ( const tal_t * ctx )
{
struct node_map * map = tal ( ctx , struct node_map ) ;
node_map_init ( map ) ;
tal_add_destructor ( map , node_map_clear ) ;
return map ;
}
struct node * get_node ( struct routing_state * rstate ,
const struct pubkey * id )
{
return node_map_get ( rstate - > nodes , & id - > pubkey ) ;
}
static void destroy_node ( struct node * node )
{
/* These remove themselves from the array. */
@ -65,8 +59,14 @@ static void destroy_node(struct node *node)
tal_free ( node - > out [ 0 ] ) ;
}
struct node * new _node( struct routing_state * rstate ,
static struct node * get _node( struct routing_state * rstate ,
const struct pubkey * id )
{
return node_map_get ( rstate - > nodes , & id - > pubkey ) ;
}
static struct node * new_node ( struct routing_state * rstate ,
const struct pubkey * id )
{
struct node * n ;
@ -86,22 +86,6 @@ struct node *new_node(struct routing_state *rstate,
return n ;
}
struct node * add_node (
struct routing_state * rstate ,
const struct pubkey * pk )
{
struct node * n = get_node ( rstate , pk ) ;
if ( ! n ) {
n = new_node ( rstate , pk ) ;
status_trace ( " Creating new node %s " ,
type_to_string ( trc , struct pubkey , pk ) ) ;
} else {
status_trace ( " Update existing node %s " ,
type_to_string ( trc , struct pubkey , pk ) ) ;
}
return n ;
}
static bool remove_conn_from_array ( struct node_connection * * * conns ,
struct node_connection * nc )
{
@ -127,9 +111,9 @@ static void destroy_connection(struct node_connection *nc)
abort ( ) ;
}
struct node_connection * get_connection ( struct routing_state * rstate ,
const struct pubkey * from_id ,
const struct pubkey * to_id )
static struct node_connection * get_connection ( struct routing_state * rstate ,
const struct pubkey * from_id ,
const struct pubkey * to_id )
{
int i , n ;
struct node * from , * to ;
@ -232,61 +216,11 @@ struct node_connection *half_add_connection(struct routing_state *rstate,
nc - > active = false ;
nc - > flags = flags ;
nc - > last_timestamp = - 1 ;
nc - > min_blocks = 0 ;
return nc ;
}
/* Updates existing route if required. */
struct node_connection * add_connection ( struct routing_state * rstate ,
const struct pubkey * from ,
const struct pubkey * to ,
u32 base_fee , s32 proportional_fee ,
u32 delay , u32 min_blocks )
{
struct node_connection * c = get_or_make_connection ( rstate , from , to ) ;
c - > base_fee = base_fee ;
c - > proportional_fee = proportional_fee ;
c - > delay = delay ;
c - > min_blocks = min_blocks ;
c - > active = true ;
memset ( & c - > short_channel_id , 0 , sizeof ( c - > short_channel_id ) ) ;
c - > flags = get_channel_direction ( from , to ) ;
return c ;
}
void remove_connection ( struct routing_state * rstate ,
const struct pubkey * src , const struct pubkey * dst )
{
struct node * from , * to ;
size_t i , num_edges ;
status_trace ( " Removing route from %s to %s " ,
type_to_string ( trc , struct pubkey , src ) ,
type_to_string ( trc , struct pubkey , dst ) ) ;
from = get_node ( rstate , src ) ;
to = get_node ( rstate , dst ) ;
if ( ! from | | ! to ) {
status_trace ( " Not found: src=%p dst=%p " , from , to ) ;
return ;
}
num_edges = tal_count ( from - > out ) ;
for ( i = 0 ; i < num_edges ; i + + ) {
if ( from - > out [ i ] - > dst ! = to )
continue ;
status_trace ( " Matched route %zu of %zu " , i , num_edges ) ;
/* Destructor makes it delete itself */
tal_free ( from - > out [ i ] ) ;
return ;
}
status_trace ( " None of %zu routes matched " , num_edges ) ;
}
/* Too big to reach, but don't overflow if added. */
# define INFINITE 0x3FFFFFFFFFFFFFFFULL
@ -358,7 +292,7 @@ static void bfg_one_edge(struct node *node, size_t edgenum, double riskfactor)
}
}
struct node_connection *
static struct node_connection *
find_route ( const tal_t * ctx , struct routing_state * rstate ,
const struct pubkey * from , const struct pubkey * to , u64 msatoshi ,
double riskfactor , s64 * fee , struct node_connection * * * route )
@ -466,11 +400,11 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
return first_conn ;
}
bool add_channel_direction ( struct routing_state * rstate ,
const struct pubkey * from ,
const struct pubkey * to ,
const struct short_channel_id * short_channel_id ,
const u8 * announcement )
static bool add_channel_direction ( struct routing_state * rstate ,
const struct pubkey * from ,
const struct pubkey * to ,
const struct short_channel_id * short_channel_id ,
const u8 * announcement )
{
struct node_connection * c = get_connection ( rstate , from , to ) ;
u16 direction = get_channel_direction ( from , to ) ;
@ -917,8 +851,6 @@ struct route_hop *get_route(tal_t *ctx, struct routing_state *rstate,
total_amount + = connection_fee ( route [ i ] , total_amount ) ;
total_delay + = route [ i ] - > delay ;
if ( total_delay < route [ i ] - > min_blocks )
total_delay = route [ i ] - > min_blocks ;
hops [ i + 1 ] . delay = total_delay ;
}
/* Backfill the first hop manually */