mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
daemons: use amount_msat/amount_sat in all internal wire transfers.
As a side-effect of using amount_msat in gossipd/routing.c, we explicitly handle overflows and don't need to pre-prune ridiculous-fee channels. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -8,6 +8,7 @@ ALL_TEST_PROGRAMS += $(LIGHTNINGD_TEST_PROGRAMS)
|
||||
ALL_OBJS += $(LIGHTNINGD_TEST_OBJS)
|
||||
|
||||
LIGHTNINGD_TEST_COMMON_OBJS := \
|
||||
common/amount.o \
|
||||
common/bech32.o \
|
||||
common/daemon_conn.o \
|
||||
common/htlc_state.o \
|
||||
|
||||
@@ -6,18 +6,6 @@
|
||||
bool deprecated_apis = false;
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for amount_msat_greater */
|
||||
bool amount_msat_greater(struct amount_msat a UNNEEDED, struct amount_msat b UNNEEDED)
|
||||
{ fprintf(stderr, "amount_msat_greater called!\n"); abort(); }
|
||||
/* Generated stub for amount_msat_sub_sat */
|
||||
bool amount_msat_sub_sat(struct amount_msat *val UNNEEDED,
|
||||
struct amount_msat a UNNEEDED,
|
||||
struct amount_sat b UNNEEDED)
|
||||
{ fprintf(stderr, "amount_msat_sub_sat called!\n"); abort(); }
|
||||
/* Generated stub for amount_sat_to_msat */
|
||||
bool amount_sat_to_msat(struct amount_msat *msat UNNEEDED,
|
||||
struct amount_sat sat UNNEEDED)
|
||||
{ fprintf(stderr, "amount_sat_to_msat called!\n"); abort(); }
|
||||
/* Generated stub for bitcoind_gettxout */
|
||||
void bitcoind_gettxout(struct bitcoind *bitcoind UNNEEDED,
|
||||
const struct bitcoin_txid *txid UNNEEDED, const u32 outnum UNNEEDED,
|
||||
@@ -355,9 +343,6 @@ struct command_result *param_u64(struct command *cmd UNNEEDED, const char *name
|
||||
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
uint64_t **num UNNEEDED)
|
||||
{ fprintf(stderr, "param_u64 called!\n"); abort(); }
|
||||
/* Generated stub for parse_amount_msat */
|
||||
bool parse_amount_msat(struct amount_msat *msat UNNEEDED, const char *s UNNEEDED, size_t slen UNNEEDED)
|
||||
{ fprintf(stderr, "parse_amount_msat called!\n"); abort(); }
|
||||
/* Generated stub for peer_memleak_done */
|
||||
void peer_memleak_done(struct command *cmd UNNEEDED, struct subd *leaker UNNEEDED)
|
||||
{ fprintf(stderr, "peer_memleak_done called!\n"); abort(); }
|
||||
@@ -437,7 +422,7 @@ u8 *towire_gossip_get_incoming_channels(const tal_t *ctx UNNEEDED, const bool *p
|
||||
u8 *towire_hsm_get_channel_basepoints(const tal_t *ctx UNNEEDED, const struct pubkey *peerid UNNEEDED, u64 dbid UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_get_channel_basepoints called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_commitment_tx */
|
||||
u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct pubkey *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, u64 funding_amount UNNEEDED)
|
||||
u8 *towire_hsm_sign_commitment_tx(const tal_t *ctx UNNEEDED, const struct pubkey *peer_id UNNEEDED, u64 channel_dbid UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, const struct pubkey *remote_funding_key UNNEEDED, struct amount_sat funding_amount UNNEEDED)
|
||||
{ fprintf(stderr, "towire_hsm_sign_commitment_tx called!\n"); abort(); }
|
||||
/* Generated stub for towire_hsm_sign_invoice */
|
||||
u8 *towire_hsm_sign_invoice(const tal_t *ctx UNNEEDED, const u8 *u5bytes UNNEEDED, const u8 *hrp UNNEEDED)
|
||||
@@ -598,9 +583,9 @@ static void add_peer(struct lightningd *ld, int n, enum channel_state state,
|
||||
c->state = state;
|
||||
c->owner = connected ? (void *)peer : NULL;
|
||||
/* Channel has incoming capacity n*1000 - 1 millisatoshi */
|
||||
c->funding_satoshi = n+1;
|
||||
c->our_msatoshi = 1;
|
||||
c->our_config.channel_reserve.satoshis = 1;
|
||||
c->funding.satoshis = n+1;
|
||||
c->our_msat = AMOUNT_MSAT(1);
|
||||
c->our_config.channel_reserve = AMOUNT_SAT(1);
|
||||
list_add_tail(&peer->channels, &c->list);
|
||||
}
|
||||
|
||||
@@ -630,47 +615,47 @@ int main(void)
|
||||
|
||||
inchans = tal_arr(tmpctx, struct route_info, 0);
|
||||
/* Nothing to choose from -> NULL result. */
|
||||
assert(select_inchan(tmpctx, ld, 0, inchans, &any_offline) == NULL);
|
||||
assert(select_inchan(tmpctx, ld, AMOUNT_MSAT(0), inchans, &any_offline) == NULL);
|
||||
assert(any_offline == false);
|
||||
|
||||
/* inchan but no peer -> NULL result. */
|
||||
add_inchan(&inchans, 0);
|
||||
assert(select_inchan(tmpctx, ld, 0, inchans, &any_offline) == NULL);
|
||||
assert(select_inchan(tmpctx, ld, AMOUNT_MSAT(0), inchans, &any_offline) == NULL);
|
||||
assert(any_offline == false);
|
||||
|
||||
/* connected peer but no inchan -> NULL result. */
|
||||
add_peer(ld, 1, CHANNELD_NORMAL, false);
|
||||
assert(select_inchan(tmpctx, ld, 0, inchans, &any_offline) == NULL);
|
||||
assert(select_inchan(tmpctx, ld, AMOUNT_MSAT(0), inchans, &any_offline) == NULL);
|
||||
assert(any_offline == false);
|
||||
|
||||
/* inchan but peer awaiting lockin -> NULL result. */
|
||||
add_peer(ld, 0, CHANNELD_AWAITING_LOCKIN, true);
|
||||
assert(select_inchan(tmpctx, ld, 0, inchans, &any_offline) == NULL);
|
||||
assert(select_inchan(tmpctx, ld, AMOUNT_MSAT(0), inchans, &any_offline) == NULL);
|
||||
assert(any_offline == false);
|
||||
|
||||
/* inchan but peer not connected -> NULL result. */
|
||||
add_inchan(&inchans, 1);
|
||||
assert(select_inchan(tmpctx, ld, 0, inchans, &any_offline) == NULL);
|
||||
assert(select_inchan(tmpctx, ld, AMOUNT_MSAT(0), inchans, &any_offline) == NULL);
|
||||
assert(any_offline == true);
|
||||
|
||||
/* Finally, a correct peer! */
|
||||
add_inchan(&inchans, 2);
|
||||
add_peer(ld, 2, CHANNELD_NORMAL, true);
|
||||
|
||||
ret = select_inchan(tmpctx, ld, 0, inchans, &any_offline);
|
||||
ret = select_inchan(tmpctx, ld, AMOUNT_MSAT(0), inchans, &any_offline);
|
||||
assert(tal_count(ret) == 1);
|
||||
assert(tal_count(ret[0]) == 1);
|
||||
assert(any_offline == true);
|
||||
assert(route_info_eq(ret[0], &inchans[2]));
|
||||
|
||||
/* Not if we ask for too much! Reserve is 1 satoshi */
|
||||
ret = select_inchan(tmpctx, ld, 1999, inchans, &any_offline);
|
||||
ret = select_inchan(tmpctx, ld, AMOUNT_MSAT(1999), inchans, &any_offline);
|
||||
assert(tal_count(ret) == 1);
|
||||
assert(tal_count(ret[0]) == 1);
|
||||
assert(any_offline == false); /* Other candidate insufficient funds. */
|
||||
assert(route_info_eq(ret[0], &inchans[2]));
|
||||
|
||||
ret = select_inchan(tmpctx, ld, 2000, inchans, &any_offline);
|
||||
ret = select_inchan(tmpctx, ld, AMOUNT_MSAT(2000), inchans, &any_offline);
|
||||
assert(ret == NULL);
|
||||
assert(any_offline == false); /* Other candidate insufficient funds. */
|
||||
|
||||
@@ -679,7 +664,7 @@ int main(void)
|
||||
add_peer(ld, 3, CHANNELD_NORMAL, true);
|
||||
|
||||
for (size_t i = n = 0; i < 1000; i++) {
|
||||
ret = select_inchan(tmpctx, ld, 1000, inchans, &any_offline);
|
||||
ret = select_inchan(tmpctx, ld, AMOUNT_MSAT(1000), inchans, &any_offline);
|
||||
assert(tal_count(ret) == 1);
|
||||
assert(tal_count(ret[0]) == 1);
|
||||
assert(any_offline == false); /* Other candidate insufficient funds. */
|
||||
@@ -695,7 +680,7 @@ int main(void)
|
||||
n, 1000 - n);
|
||||
|
||||
for (size_t i = n = 0; i < 1000; i++) {
|
||||
ret = select_inchan(tmpctx, ld, 1499, inchans, &any_offline);
|
||||
ret = select_inchan(tmpctx, ld, AMOUNT_MSAT(1499), inchans, &any_offline);
|
||||
assert(tal_count(ret) == 1);
|
||||
assert(tal_count(ret[0]) == 1);
|
||||
assert(any_offline == false); /* Other candidate insufficient funds. */
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
#include "../json.c"
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for amount_sat_to_msat */
|
||||
bool amount_sat_to_msat(struct amount_msat *msat UNNEEDED,
|
||||
struct amount_sat sat UNNEEDED)
|
||||
{ fprintf(stderr, "amount_sat_to_msat called!\n"); abort(); }
|
||||
/* Generated stub for db_begin_transaction_ */
|
||||
void db_begin_transaction_(struct db *db UNNEEDED, const char *location UNNEEDED)
|
||||
{ fprintf(stderr, "db_begin_transaction_ called!\n"); abort(); }
|
||||
|
||||
Reference in New Issue
Block a user