@@ -2151,8 +2151,8 @@ static bool test_channel_config_crud(struct lightningd *ld, const tal_t *ctx)
21512151static bool test_htlc_crud (struct lightningd * ld , const tal_t * ctx )
21522152{
21532153 struct db_stmt * stmt ;
2154- struct htlc_in in , * hin ;
2155- struct htlc_out out , * hout ;
2154+ struct htlc_in in , in2 , * hin ;
2155+ struct htlc_out out , out2 , * hout ;
21562156 struct preimage payment_key ;
21572157 struct channel * chan = tal (ctx , struct channel );
21582158 struct peer * peer = talz (ctx , struct peer );
@@ -2174,55 +2174,61 @@ static bool test_htlc_crud(struct lightningd *ld, const tal_t *ctx)
21742174 chan -> state = CHANNELD_NORMAL ;
21752175 chan -> peer = peer ;
21762176 chan -> next_index [LOCAL ] = chan -> next_index [REMOTE ] = 1 ;
2177+ chan -> scid = tal (chan , struct short_channel_id );
21772178
21782179 memset (& in , 0 , sizeof (in ));
21792180 memset (& out , 0 , sizeof (out ));
21802181 memset (& in .payment_hash , 'A' , sizeof (struct sha256 ));
21812182 memset (& out .payment_hash , 'A' , sizeof (struct sha256 ));
21822183 memset (& payment_key , 'B' , sizeof (payment_key ));
2184+ assert (mk_short_channel_id (chan -> scid , 1 , 2 , 3 ));
21832185 in .key .id = 42 ;
21842186 in .key .channel = chan ;
2187+ in .cltv_expiry = 42 ;
21852188 in .msat = AMOUNT_MSAT (42 );
21862189
21872190 out .in = & in ;
21882191 out .key .id = 1337 ;
21892192 out .key .channel = chan ;
2193+ out .cltv_expiry = 41 ;
21902194 out .msat = AMOUNT_MSAT (41 );
21912195
21922196 /* Store the htlc_in */
21932197 CHECK_MSG (transaction_wrap (w -> db , wallet_htlc_save_in (w , chan , & in )),
21942198 tal_fmt (ctx , "Save htlc_in failed: %s" , wallet_err ));
21952199 CHECK_MSG (in .dbid != 0 , "HTLC DB ID was not set." );
2196- /* Saving again should get us a collision */
2197- CHECK_MSG (!transaction_wrap (w -> db , wallet_htlc_save_in (w , chan , & in )),
2200+ in2 = in ;
2201+ /* Saving again should get us a collision (but overwrites dbid!) */
2202+ CHECK_MSG (!transaction_wrap (w -> db , wallet_htlc_save_in (w , chan , & in2 )),
21982203 "Saving two HTLCs with the same data must not succeed." );
21992204 CHECK (wallet_err );
22002205 wallet_err = tal_free (wallet_err );
22012206
22022207 /* Update */
2203- CHECK_MSG (transaction_wrap (w -> db , wallet_htlc_update (w , in .dbid , RCVD_ADD_HTLC , NULL , 0 , 0 , NULL , NULL , & we_filled )),
2208+ CHECK_MSG (transaction_wrap (w -> db , wallet_htlc_update (w , in .dbid , RCVD_ADD_HTLC , NULL , 0 , 0 , NULL , NULL , & we_filled , in . key . id , in . key . channel , REMOTE , & in . payment_hash , in . cltv_expiry , in . msat )),
22042209 "Update HTLC with null payment_key failed" );
22052210 CHECK_MSG (
2206- transaction_wrap (w -> db , wallet_htlc_update (w , in .dbid , SENT_REMOVE_HTLC , & payment_key , 0 , 0 , NULL , NULL , & we_filled )),
2211+ transaction_wrap (w -> db , wallet_htlc_update (w , in .dbid , SENT_REMOVE_HTLC , & payment_key , 0 , 0 , NULL , NULL , & we_filled , in . key . id , in . key . channel , REMOTE , & in . payment_hash , in . cltv_expiry , in . msat )),
22072212 "Update HTLC with payment_key failed" );
22082213 onionreply = new_onionreply (tmpctx , tal_arrz (tmpctx , u8 , 100 ));
22092214 CHECK_MSG (
2210- transaction_wrap (w -> db , wallet_htlc_update (w , in .dbid , SENT_REMOVE_HTLC , NULL , 0 , 0 , onionreply , NULL , & we_filled )),
2215+ transaction_wrap (w -> db , wallet_htlc_update (w , in .dbid , SENT_REMOVE_HTLC , NULL , 0 , 0 , onionreply , NULL , & we_filled , in . key . id , in . key . channel , REMOTE , & in . payment_hash , in . cltv_expiry , in . msat )),
22112216 "Update HTLC with failonion failed" );
22122217 CHECK_MSG (
2213- transaction_wrap (w -> db , wallet_htlc_update (w , in .dbid , SENT_REMOVE_HTLC , NULL , 0 , WIRE_INVALID_ONION_VERSION , NULL , NULL , & we_filled )),
2218+ transaction_wrap (w -> db , wallet_htlc_update (w , in .dbid , SENT_REMOVE_HTLC , NULL , 0 , WIRE_INVALID_ONION_VERSION , NULL , NULL , & we_filled , in . key . id , in . key . channel , REMOTE , & in . payment_hash , in . cltv_expiry , in . msat )),
22142219 "Update HTLC with failcode failed" );
22152220
22162221 CHECK_MSG (transaction_wrap (w -> db , wallet_htlc_save_out (w , chan , & out )),
22172222 tal_fmt (ctx , "Save htlc_out failed: %s" , wallet_err ));
22182223 CHECK_MSG (out .dbid != 0 , "HTLC DB ID was not set." );
22192224
2220- CHECK_MSG (!transaction_wrap (w -> db , wallet_htlc_save_out (w , chan , & out )),
2225+ out2 = out ;
2226+ CHECK_MSG (!transaction_wrap (w -> db , wallet_htlc_save_out (w , chan , & out2 )),
22212227 "Saving two HTLCs with the same data must not succeed." );
22222228 CHECK (wallet_err );
22232229 wallet_err = tal_free (wallet_err );
22242230 CHECK_MSG (
2225- transaction_wrap (w -> db , wallet_htlc_update (w , out .dbid , SENT_ADD_ACK_REVOCATION , NULL , 0 , 0 , NULL , tal_arrz (tmpctx , u8 , 100 ), & we_filled )),
2231+ transaction_wrap (w -> db , wallet_htlc_update (w , out .dbid , SENT_ADD_ACK_REVOCATION , NULL , 0 , 0 , NULL , tal_arrz (tmpctx , u8 , 100 ), & we_filled , out . key . id , out . key . channel , REMOTE , & out . payment_hash , out . cltv_expiry , out . msat )),
22262232 "Update outgoing HTLC with failmsg failed" );
22272233
22282234 /* Attempt to load them from the DB again */
@@ -2340,6 +2346,8 @@ int main(int argc, const char *argv[])
23402346 ld = tal (tmpctx , struct lightningd );
23412347 ld -> config = test_config ;
23422348 ld -> hsm_capabilities = NULL ;
2349+ memset (& ld -> indexes [WAIT_SUBSYSTEM_HTLCS ], 0 ,
2350+ sizeof (ld -> indexes [WAIT_SUBSYSTEM_HTLCS ]));
23432351
23442352 /* Only elements in ld we should access */
23452353 ld -> peers = tal (ld , struct peer_node_id_map );
0 commit comments