@@ -609,13 +609,26 @@ static struct channel *wallet_stmt2channel(const tal_t *ctx, struct wallet *w, s
609609 remote_shutdown_scriptpubkey = sqlite3_column_arr (tmpctx , stmt , 28 , u8 );
610610
611611 /* Do we have a last_sent_commit, if yes, populate */
612- if (sqlite3_column_type (stmt , 30 ) != SQLITE_NULL ) {
612+ if (sqlite3_column_type (stmt , 41 ) != SQLITE_NULL ) {
613+ const u8 * cursor = sqlite3_column_blob (stmt , 41 );
614+ size_t len = sqlite3_column_bytes (stmt , 41 );
615+ size_t n = 0 ;
616+ last_sent_commit = tal_arr (tmpctx , struct changed_htlc , n );
617+ while (len ) {
618+ tal_resize (& last_sent_commit , n + 1 );
619+ fromwire_changed_htlc (& cursor , & len ,
620+ & last_sent_commit [n ++ ]);
621+ }
622+ } else
623+ last_sent_commit = NULL ;
624+
625+ #ifdef COMPAT_V060
626+ if (!last_sent_commit && sqlite3_column_type (stmt , 30 ) != SQLITE_NULL ) {
613627 last_sent_commit = tal (tmpctx , struct changed_htlc );
614628 last_sent_commit -> newstate = sqlite3_column_int64 (stmt , 30 );
615629 last_sent_commit -> id = sqlite3_column_int64 (stmt , 31 );
616- } else {
617- last_sent_commit = NULL ;
618630 }
631+ #endif
619632
620633 if (sqlite3_column_type (stmt , 40 ) != SQLITE_NULL ) {
621634 future_per_commitment_point = tal (tmpctx , struct pubkey );
@@ -715,7 +728,8 @@ static const char *channel_fields =
715728 /*30*/ "last_sent_commit_state, last_sent_commit_id, "
716729 /*32*/ "last_tx, last_sig, last_was_revoke, first_blocknum, "
717730 /*36*/ "min_possible_feerate, max_possible_feerate, "
718- /*38*/ "msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point " ;
731+ /*38*/ "msatoshi_to_us_min, msatoshi_to_us_max, future_per_commitment_point, "
732+ /*41*/ "last_sent_commit" ;
719733
720734bool wallet_channels_load_active (const tal_t * ctx , struct wallet * w )
721735{
@@ -893,6 +907,7 @@ u64 wallet_get_channel_dbid(struct wallet *wallet)
893907void wallet_channel_save (struct wallet * w , struct channel * chan )
894908{
895909 sqlite3_stmt * stmt ;
910+ u8 * last_sent_commit ;
896911 assert (chan -> first_blocknum );
897912
898913 wallet_channel_config_save (w , & chan -> our_config );
@@ -996,17 +1011,23 @@ void wallet_channel_save(struct wallet *w, struct channel *chan)
9961011 db_exec_prepared (w -> db , stmt );
9971012
9981013 /* If we have a last_sent_commit, store it */
999- if (chan -> last_sent_commit ) {
1000- stmt = db_prepare (w -> db ,
1001- "UPDATE channels SET"
1002- " last_sent_commit_state=?,"
1003- " last_sent_commit_id=?"
1004- " WHERE id=?" );
1005- sqlite3_bind_int (stmt , 1 , chan -> last_sent_commit -> newstate );
1006- sqlite3_bind_int64 (stmt , 2 , chan -> last_sent_commit -> id );
1007- sqlite3_bind_int64 (stmt , 3 , chan -> dbid );
1008- db_exec_prepared (w -> db , stmt );
1009- }
1014+ last_sent_commit = tal_arr (tmpctx , u8 , 0 );
1015+ for (size_t i = 0 ; i < tal_count (chan -> last_sent_commit ); i ++ )
1016+ towire_changed_htlc (& last_sent_commit ,
1017+ & chan -> last_sent_commit [i ]);
1018+
1019+ stmt = db_prepare (w -> db ,
1020+ "UPDATE channels SET"
1021+ " last_sent_commit=?"
1022+ " WHERE id=?" );
1023+ if (tal_count (last_sent_commit ))
1024+ sqlite3_bind_blob (stmt , 1 ,
1025+ last_sent_commit , tal_count (last_sent_commit ),
1026+ SQLITE_TRANSIENT );
1027+ else
1028+ sqlite3_bind_null (stmt , 1 );
1029+ sqlite3_bind_int64 (stmt , 2 , chan -> dbid );
1030+ db_exec_prepared (w -> db , stmt );
10101031}
10111032
10121033void wallet_channel_insert (struct wallet * w , struct channel * chan )
0 commit comments