From 1561ffaea0a3aa6d2aeca257b45b39ec1e412bab Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 21 Feb 2019 14:21:28 +0100 Subject: [PATCH] hooks: Add cltv_expiry_delta to the htlc_accepted hook MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian Decker Suggested-by: Corné Plooy <@bitonic-cjp> --- lightningd/peer_htlcs.c | 4 +++- lightningd/test/run-find_my_abspath.c | 5 ----- lightningd/test/run-invoice-select-inchan.c | 5 ----- wallet/test/run-wallet.c | 17 ++++++++--------- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/lightningd/peer_htlcs.c b/lightningd/peer_htlcs.c index cb3ce44d9..76c3a20d7 100644 --- a/lightningd/peer_htlcs.c +++ b/lightningd/peer_htlcs.c @@ -715,6 +715,7 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p, { const struct route_step *rs = p->route_step; const struct htlc_in *hin = p->hin; + s32 expiry = hin->cltv_expiry, blockheight = p->ld->topology->tip->height; json_object_start(s, "onion"); if (rs->hop_data.realm == 0x00) { @@ -732,7 +733,8 @@ static void htlc_accepted_hook_serialize(struct htlc_accepted_hook_payload *p, json_object_start(s, "htlc"); json_add_amount_msat_only(s, "amount", hin->msat); - json_add_u64(s, "cltv_expiry", hin->cltv_expiry); + json_add_u32(s, "cltv_expiry", expiry); + json_add_s32(s, "cltv_expiry_relative", expiry - blockheight); json_add_hex(s, "payment_hash", hin->payment_hash.u.u8, sizeof(hin->payment_hash)); json_object_end(s); } diff --git a/lightningd/test/run-find_my_abspath.c b/lightningd/test/run-find_my_abspath.c index 113a19538..7ca42d4d0 100644 --- a/lightningd/test/run-find_my_abspath.c +++ b/lightningd/test/run-find_my_abspath.c @@ -170,11 +170,6 @@ const char *version(void) /* Generated stub for wallet_blocks_heights */ void wallet_blocks_heights(struct wallet *w UNNEEDED, u32 def UNNEEDED, u32 *min UNNEEDED, u32 *max UNNEEDED) { fprintf(stderr, "wallet_blocks_heights called!\n"); abort(); } -/* Generated stub for wallet_invoice_autoclean */ -void wallet_invoice_autoclean(struct wallet * wallet UNNEEDED, - u64 cycle_seconds UNNEEDED, - u64 expired_by UNNEEDED) -{ fprintf(stderr, "wallet_invoice_autoclean called!\n"); abort(); } /* Generated stub for wallet_network_check */ bool wallet_network_check(struct wallet *w UNNEEDED, const struct chainparams *chainparams UNNEEDED) diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 714714055..ebb2bd283 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -478,11 +478,6 @@ bool wallet_htlcs_load_for_channel(struct wallet *wallet UNNEEDED, struct htlc_in_map *htlcs_in UNNEEDED, struct htlc_out_map *htlcs_out UNNEEDED) { fprintf(stderr, "wallet_htlcs_load_for_channel called!\n"); abort(); } -/* Generated stub for wallet_invoice_autoclean */ -void wallet_invoice_autoclean(struct wallet * wallet UNNEEDED, - u64 cycle_seconds UNNEEDED, - u64 expired_by UNNEEDED) -{ fprintf(stderr, "wallet_invoice_autoclean called!\n"); abort(); } /* Generated stub for wallet_invoice_create */ bool wallet_invoice_create(struct wallet *wallet UNNEEDED, struct invoice *pinvoice UNNEEDED, diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 2706ff4a1..ed33afa2d 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -112,11 +112,6 @@ u32 get_block_height(const struct chain_topology *topo UNNEEDED) /* Generated stub for get_chainparams */ const struct chainparams *get_chainparams(const struct lightningd *ld UNNEEDED) { fprintf(stderr, "get_chainparams called!\n"); abort(); } -/* Generated stub for invoices_autoclean_set */ -void invoices_autoclean_set(struct invoices *invoices UNNEEDED, - u64 cycle_seconds UNNEEDED, - u64 expired_by UNNEEDED) -{ fprintf(stderr, "invoices_autoclean_set called!\n"); abort(); } /* Generated stub for invoices_create */ bool invoices_create(struct invoices *invoices UNNEEDED, struct invoice *pinvoice UNNEEDED, @@ -255,6 +250,10 @@ void json_add_node_id(struct json_stream *response UNNEEDED, void json_add_num(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, unsigned int value UNNEEDED) { fprintf(stderr, "json_add_num called!\n"); abort(); } +/* Generated stub for json_add_s32 */ +void json_add_s32(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, + int32_t value UNNEEDED) +{ fprintf(stderr, "json_add_s32 called!\n"); abort(); } /* Generated stub for json_add_short_channel_id */ void json_add_short_channel_id(struct json_stream *response UNNEEDED, const char *fieldname UNNEEDED, @@ -271,6 +270,10 @@ void json_add_timeabs(struct json_stream *result UNNEEDED, const char *fieldname void json_add_txid(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, const struct bitcoin_txid *txid UNNEEDED) { fprintf(stderr, "json_add_txid called!\n"); abort(); } +/* Generated stub for json_add_u32 */ +void json_add_u32(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, + uint32_t value UNNEEDED) +{ fprintf(stderr, "json_add_u32 called!\n"); abort(); } /* Generated stub for json_add_u64 */ void json_add_u64(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED, uint64_t value UNNEEDED) @@ -332,10 +335,6 @@ bool json_to_number(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, /* Generated stub for json_to_preimage */ bool json_to_preimage(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, struct preimage *preimage UNNEEDED) { fprintf(stderr, "json_to_preimage called!\n"); abort(); } -/* Generated stub for json_to_pubkey */ -bool json_to_pubkey(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, - struct pubkey *pubkey UNNEEDED) -{ fprintf(stderr, "json_to_pubkey called!\n"); abort(); } /* Generated stub for json_to_short_channel_id */ bool json_to_short_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED, struct short_channel_id *scid UNNEEDED,