2017-08-31 04:08:12 +02:00
|
|
|
/* We can't seem to route the following:
|
|
|
|
*
|
|
|
|
* Expect route 03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf -> 0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae -> 02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06
|
|
|
|
*
|
|
|
|
* getchannels:
|
|
|
|
* {'channels': [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, {'active': True, 'short_id': '6989:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'flags': 0, 'destination': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, {'active': True, 'short_id': '6990:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'flags': 0, 'destination': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, {'active': True, 'short_id': '6989:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'last_update': 1504064344}]}
|
|
|
|
*/
|
|
|
|
#include <common/status.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2018-02-05 05:09:27 +01:00
|
|
|
#define status_fmt(level, fmt, ...) \
|
2017-08-31 04:08:12 +02:00
|
|
|
do { printf((fmt) ,##__VA_ARGS__); printf("\n"); } while(0)
|
|
|
|
|
|
|
|
#include "../routing.c"
|
2018-03-18 15:01:22 +01:00
|
|
|
#include "../gossip_store.c"
|
2017-08-31 04:08:12 +02:00
|
|
|
|
|
|
|
struct broadcast_state *new_broadcast_state(tal_t *ctx UNNEEDED)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AUTOGENERATED MOCKS START */
|
|
|
|
/* Generated stub for fromwire_channel_announcement */
|
2018-02-20 21:59:09 +01:00
|
|
|
bool fromwire_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *node_signature_1 UNNEEDED, secp256k1_ecdsa_signature *node_signature_2 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_1 UNNEEDED, secp256k1_ecdsa_signature *bitcoin_signature_2 UNNEEDED, u8 **features UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct pubkey *node_id_1 UNNEEDED, struct pubkey *node_id_2 UNNEEDED, struct pubkey *bitcoin_key_1 UNNEEDED, struct pubkey *bitcoin_key_2 UNNEEDED)
|
2017-08-31 04:08:12 +02:00
|
|
|
{ fprintf(stderr, "fromwire_channel_announcement called!\n"); abort(); }
|
|
|
|
/* Generated stub for fromwire_channel_update */
|
2018-02-20 21:59:09 +01:00
|
|
|
bool fromwire_channel_update(const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, u32 *timestamp UNNEEDED, u16 *flags UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED)
|
2017-08-31 04:08:12 +02:00
|
|
|
{ fprintf(stderr, "fromwire_channel_update called!\n"); abort(); }
|
2018-04-21 12:13:33 +02:00
|
|
|
/* Generated stub for fromwire_gossip_local_add_channel */
|
|
|
|
bool fromwire_gossip_local_add_channel(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED, struct bitcoin_blkid *chain_hash UNNEEDED, struct pubkey *remote_node_id UNNEEDED, u16 *cltv_expiry_delta UNNEEDED, u64 *htlc_minimum_msat UNNEEDED, u32 *fee_base_msat UNNEEDED, u32 *fee_proportional_millionths UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_gossip_local_add_channel called!\n"); abort(); }
|
2018-03-23 17:34:11 +01:00
|
|
|
/* Generated stub for fromwire_gossip_store_channel_announcement */
|
|
|
|
bool fromwire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED, u64 *satoshis UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_gossip_store_channel_announcement called!\n"); abort(); }
|
2018-03-28 12:54:09 +02:00
|
|
|
/* Generated stub for fromwire_gossip_store_channel_delete */
|
|
|
|
bool fromwire_gossip_store_channel_delete(const void *p UNNEEDED, struct short_channel_id *short_channel_id UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_gossip_store_channel_delete called!\n"); abort(); }
|
2018-03-25 18:10:00 +02:00
|
|
|
/* Generated stub for fromwire_gossip_store_channel_update */
|
|
|
|
bool fromwire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **update UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_gossip_store_channel_update called!\n"); abort(); }
|
2018-04-21 12:17:14 +02:00
|
|
|
/* Generated stub for fromwire_gossip_store_local_add_channel */
|
|
|
|
bool fromwire_gossip_store_local_add_channel(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **local_add UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_gossip_store_local_add_channel called!\n"); abort(); }
|
2018-03-25 18:23:10 +02:00
|
|
|
/* Generated stub for fromwire_gossip_store_node_announcement */
|
|
|
|
bool fromwire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, u8 **announcement UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_gossip_store_node_announcement called!\n"); abort(); }
|
2017-08-31 04:08:12 +02:00
|
|
|
/* Generated stub for fromwire_node_announcement */
|
2018-02-20 21:59:09 +01:00
|
|
|
bool fromwire_node_announcement(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, secp256k1_ecdsa_signature *signature UNNEEDED, u8 **features UNNEEDED, u32 *timestamp UNNEEDED, struct pubkey *node_id UNNEEDED, u8 rgb_color[3] UNNEEDED, u8 alias[32] UNNEEDED, u8 **addresses UNNEEDED)
|
2017-08-31 04:08:12 +02:00
|
|
|
{ fprintf(stderr, "fromwire_node_announcement called!\n"); abort(); }
|
2017-10-22 15:33:58 +02:00
|
|
|
/* Generated stub for fromwire_u8 */
|
|
|
|
u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_u8 called!\n"); abort(); }
|
2017-10-23 06:17:38 +02:00
|
|
|
/* Generated stub for fromwire_wireaddr */
|
|
|
|
bool fromwire_wireaddr(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct wireaddr *addr UNNEEDED)
|
|
|
|
{ fprintf(stderr, "fromwire_wireaddr called!\n"); abort(); }
|
2018-01-18 00:32:36 +01:00
|
|
|
/* Generated stub for onion_type_name */
|
|
|
|
const char *onion_type_name(int e UNNEEDED)
|
|
|
|
{ fprintf(stderr, "onion_type_name called!\n"); abort(); }
|
2018-01-31 17:53:50 +01:00
|
|
|
/* Generated stub for replace_broadcast */
|
2018-03-13 16:38:55 +01:00
|
|
|
bool replace_broadcast(const tal_t *ctx UNNEEDED,
|
|
|
|
struct broadcast_state *bstate UNNEEDED,
|
2018-01-31 17:53:50 +01:00
|
|
|
u64 *index UNNEEDED,
|
2018-03-13 16:41:55 +01:00
|
|
|
const u8 *payload TAKES UNNEEDED)
|
2018-01-31 17:53:50 +01:00
|
|
|
{ fprintf(stderr, "replace_broadcast called!\n"); abort(); }
|
2018-03-08 05:10:29 +01:00
|
|
|
/* Generated stub for sanitize_error */
|
|
|
|
char *sanitize_error(const tal_t *ctx UNNEEDED, const u8 *errmsg UNNEEDED,
|
|
|
|
struct channel_id *channel_id UNNEEDED)
|
|
|
|
{ fprintf(stderr, "sanitize_error called!\n"); abort(); }
|
2017-12-22 02:10:00 +01:00
|
|
|
/* Generated stub for status_failed */
|
2018-02-08 02:25:12 +01:00
|
|
|
void status_failed(enum status_failreason code UNNEEDED,
|
|
|
|
const char *fmt UNNEEDED, ...)
|
2017-12-22 02:10:00 +01:00
|
|
|
{ fprintf(stderr, "status_failed called!\n"); abort(); }
|
2018-03-08 05:10:26 +01:00
|
|
|
/* Generated stub for towire_errorfmt */
|
|
|
|
u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
|
|
|
|
const struct channel_id *channel UNNEEDED,
|
|
|
|
const char *fmt UNNEEDED, ...)
|
|
|
|
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
2018-03-23 17:34:11 +01:00
|
|
|
/* Generated stub for towire_gossip_store_channel_announcement */
|
|
|
|
u8 *towire_gossip_store_channel_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED, u64 satoshis UNNEEDED)
|
|
|
|
{ fprintf(stderr, "towire_gossip_store_channel_announcement called!\n"); abort(); }
|
2018-03-28 12:54:09 +02:00
|
|
|
/* Generated stub for towire_gossip_store_channel_delete */
|
|
|
|
u8 *towire_gossip_store_channel_delete(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED)
|
|
|
|
{ fprintf(stderr, "towire_gossip_store_channel_delete called!\n"); abort(); }
|
2018-03-25 18:10:00 +02:00
|
|
|
/* Generated stub for towire_gossip_store_channel_update */
|
|
|
|
u8 *towire_gossip_store_channel_update(const tal_t *ctx UNNEEDED, const u8 *update UNNEEDED)
|
|
|
|
{ fprintf(stderr, "towire_gossip_store_channel_update called!\n"); abort(); }
|
2018-04-21 12:17:14 +02:00
|
|
|
/* Generated stub for towire_gossip_store_local_add_channel */
|
|
|
|
u8 *towire_gossip_store_local_add_channel(const tal_t *ctx UNNEEDED, const u8 *local_add UNNEEDED)
|
|
|
|
{ fprintf(stderr, "towire_gossip_store_local_add_channel called!\n"); abort(); }
|
2018-03-25 18:23:10 +02:00
|
|
|
/* Generated stub for towire_gossip_store_node_announcement */
|
|
|
|
u8 *towire_gossip_store_node_announcement(const tal_t *ctx UNNEEDED, const u8 *announcement UNNEEDED)
|
|
|
|
{ fprintf(stderr, "towire_gossip_store_node_announcement called!\n"); abort(); }
|
2017-08-31 04:08:12 +02:00
|
|
|
/* AUTOGENERATED MOCKS END */
|
|
|
|
|
2018-03-05 17:38:21 +01:00
|
|
|
const void *trc;
|
2018-03-02 09:59:16 +01:00
|
|
|
|
2018-03-04 03:26:59 +01:00
|
|
|
static struct half_chan *
|
2018-03-02 09:59:16 +01:00
|
|
|
get_or_make_connection(struct routing_state *rstate,
|
|
|
|
const struct pubkey *from_id,
|
|
|
|
const struct pubkey *to_id,
|
|
|
|
const char *shortid)
|
|
|
|
{
|
|
|
|
struct short_channel_id scid;
|
2018-03-04 03:26:59 +01:00
|
|
|
struct chan *chan;
|
2018-03-02 09:59:17 +01:00
|
|
|
|
2018-03-02 09:59:16 +01:00
|
|
|
if (!short_channel_id_from_str(shortid, strlen(shortid), &scid))
|
|
|
|
abort();
|
2018-03-02 09:59:17 +01:00
|
|
|
chan = get_channel(rstate, &scid);
|
|
|
|
if (!chan)
|
2018-03-04 03:26:59 +01:00
|
|
|
chan = new_chan(rstate, &scid, from_id, to_id);
|
2018-03-02 09:59:17 +01:00
|
|
|
|
2018-03-04 03:26:59 +01:00
|
|
|
return &chan->half[pubkey_idx(from_id, to_id)];
|
2018-03-02 09:59:16 +01:00
|
|
|
}
|
|
|
|
|
2018-03-04 03:26:59 +01:00
|
|
|
static bool channel_is_between(const struct chan *chan,
|
2018-03-04 03:26:54 +01:00
|
|
|
const struct pubkey *a, const struct pubkey *b)
|
|
|
|
{
|
|
|
|
if (pubkey_eq(&chan->nodes[0]->id, a)
|
|
|
|
&& pubkey_eq(&chan->nodes[1]->id, b))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (pubkey_eq(&chan->nodes[0]->id, b)
|
|
|
|
&& pubkey_eq(&chan->nodes[1]->id, a))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-31 04:08:12 +02:00
|
|
|
int main(void)
|
|
|
|
{
|
2017-12-18 07:44:10 +01:00
|
|
|
static const struct bitcoin_blkid zerohash;
|
2018-03-04 03:26:59 +01:00
|
|
|
struct half_chan *nc;
|
2017-08-31 04:08:12 +02:00
|
|
|
struct routing_state *rstate;
|
|
|
|
struct pubkey a, b, c;
|
2017-12-18 05:15:38 +01:00
|
|
|
u64 fee;
|
2018-03-04 03:26:59 +01:00
|
|
|
struct chan **route;
|
2017-12-18 05:15:41 +01:00
|
|
|
const double riskfactor = 1.0 / BLOCKS_PER_YEAR / 10000;
|
2017-08-31 04:08:12 +02:00
|
|
|
|
|
|
|
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
|
|
|
| SECP256K1_CONTEXT_SIGN);
|
2018-03-15 07:10:20 +01:00
|
|
|
setup_tmpctx();
|
2017-08-31 04:08:12 +02:00
|
|
|
|
|
|
|
pubkey_from_hexstr("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf",
|
|
|
|
strlen("03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf"),
|
|
|
|
&a);
|
|
|
|
pubkey_from_hexstr("0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae",
|
|
|
|
strlen("0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae"),
|
|
|
|
&b);
|
|
|
|
pubkey_from_hexstr("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06",
|
|
|
|
strlen("02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06"),
|
|
|
|
&c);
|
|
|
|
|
2018-03-15 07:10:20 +01:00
|
|
|
rstate = new_routing_state(tmpctx, &zerohash, &a, 0);
|
2017-08-31 04:08:12 +02:00
|
|
|
|
|
|
|
/* [{'active': True, 'short_id': '6990:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'last_update': 1504064344}, */
|
2018-03-02 09:59:16 +01:00
|
|
|
nc = get_or_make_connection(rstate, &c, &b, "6990:2:1");
|
2017-08-31 04:08:12 +02:00
|
|
|
nc->active = true;
|
|
|
|
nc->base_fee = 0;
|
|
|
|
nc->proportional_fee = 10;
|
|
|
|
nc->delay = 5;
|
|
|
|
nc->flags = 1;
|
|
|
|
nc->last_timestamp = 1504064344;
|
|
|
|
|
|
|
|
/* {'active': True, 'short_id': '6989:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'flags': 0, 'destination': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, */
|
2018-03-02 09:59:16 +01:00
|
|
|
nc = get_or_make_connection(rstate, &b, &a, "6989:2:1");
|
2017-08-31 04:08:12 +02:00
|
|
|
nc->active = true;
|
|
|
|
nc->base_fee = 0;
|
|
|
|
nc->proportional_fee = 10;
|
|
|
|
nc->delay = 5;
|
|
|
|
nc->flags = 0;
|
|
|
|
nc->last_timestamp = 1504064344;
|
|
|
|
|
|
|
|
/* {'active': True, 'short_id': '6990:2:1/0', 'fee_per_kw': 10, 'delay': 5, 'flags': 0, 'destination': '02ea622d5c8d6143f15ed3ce1d501dd0d3d09d3b1c83a44d0034949f8a9ab60f06', 'source': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'last_update': 1504064344}, */
|
2018-03-02 09:59:16 +01:00
|
|
|
nc = get_or_make_connection(rstate, &b, &c, "6990:2:1");
|
2017-08-31 04:08:12 +02:00
|
|
|
nc->active = true;
|
|
|
|
nc->base_fee = 0;
|
|
|
|
nc->proportional_fee = 10;
|
|
|
|
nc->delay = 5;
|
|
|
|
nc->flags = 0;
|
|
|
|
nc->last_timestamp = 1504064344;
|
|
|
|
|
|
|
|
/* {'active': True, 'short_id': '6989:2:1/1', 'fee_per_kw': 10, 'delay': 5, 'flags': 1, 'destination': '0230ad0e74ea03976b28fda587bb75bdd357a1938af4424156a18265167f5e40ae', 'source': '03c173897878996287a8100469f954dd820fcd8941daed91c327f168f3329be0bf', 'last_update': 1504064344}]} */
|
2018-03-02 09:59:16 +01:00
|
|
|
nc = get_or_make_connection(rstate, &a, &b, "6989:2:1");
|
2017-08-31 04:08:12 +02:00
|
|
|
nc->active = true;
|
|
|
|
nc->base_fee = 0;
|
|
|
|
nc->proportional_fee = 10;
|
|
|
|
nc->delay = 5;
|
|
|
|
nc->flags = 1;
|
|
|
|
nc->last_timestamp = 1504064344;
|
|
|
|
|
2018-03-15 07:10:20 +01:00
|
|
|
route = find_route(tmpctx, rstate, &a, &c, 100000, riskfactor, 0.0, NULL, &fee);
|
2018-03-04 03:26:54 +01:00
|
|
|
assert(route);
|
|
|
|
assert(tal_count(route) == 2);
|
|
|
|
assert(channel_is_between(route[0], &a, &b));
|
|
|
|
assert(channel_is_between(route[1], &b, &c));
|
2017-08-31 04:08:12 +02:00
|
|
|
|
2018-03-15 07:10:20 +01:00
|
|
|
tal_free(tmpctx);
|
2017-09-01 06:18:54 +02:00
|
|
|
secp256k1_context_destroy(secp256k1_ctx);
|
2017-08-31 04:08:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|