|
|
@ -205,8 +205,7 @@ static struct utxo *wallet_stmt2output(const tal_t *ctx, struct db_stmt *stmt) |
|
|
|
} |
|
|
|
|
|
|
|
/* This column can be null if 0.9.1 db or below. */ |
|
|
|
utxo->reserved_til = tal(utxo, u32); |
|
|
|
*utxo->reserved_til = db_column_int_or_default(stmt, 13, 0); |
|
|
|
utxo->reserved_til = db_column_int_or_default(stmt, 13, 0); |
|
|
|
|
|
|
|
return utxo; |
|
|
|
} |
|
|
@ -434,10 +433,7 @@ static void db_set_utxo(struct db *db, const struct utxo *utxo) |
|
|
|
db, SQL("UPDATE outputs SET status=?, reserved_til=?" |
|
|
|
"WHERE prev_out_tx=? AND prev_out_index=?")); |
|
|
|
db_bind_int(stmt, 0, output_status_in_db(utxo->status)); |
|
|
|
if (utxo->reserved_til) |
|
|
|
db_bind_int(stmt, 1, *utxo->reserved_til); |
|
|
|
else |
|
|
|
db_bind_null(stmt, 1); |
|
|
|
db_bind_int(stmt, 1, utxo->reserved_til); |
|
|
|
db_bind_txid(stmt, 2, &utxo->txid); |
|
|
|
db_bind_int(stmt, 3, utxo->outnum); |
|
|
|
db_exec_prepared_v2(take(stmt)); |
|
|
@ -445,11 +441,6 @@ static void db_set_utxo(struct db *db, const struct utxo *utxo) |
|
|
|
|
|
|
|
bool wallet_reserve_utxo(struct wallet *w, struct utxo *utxo, u32 current_height) |
|
|
|
{ |
|
|
|
u32 reservation_height; |
|
|
|
|
|
|
|
if (utxo->status == output_state_reserved) |
|
|
|
assert(utxo->reserved_til); |
|
|
|
|
|
|
|
switch (utxo->status) { |
|
|
|
case output_state_spent: |
|
|
|
return false; |
|
|
@ -461,15 +452,12 @@ bool wallet_reserve_utxo(struct wallet *w, struct utxo *utxo, u32 current_height |
|
|
|
} |
|
|
|
|
|
|
|
/* We simple increase existing reservations, which DTRT if we unreserve */ |
|
|
|
if (utxo->reserved_til |
|
|
|
&& *utxo->reserved_til >= current_height) |
|
|
|
reservation_height = *utxo->reserved_til + RESERVATION_INC; |
|
|
|
if (utxo->reserved_til >= current_height) |
|
|
|
utxo->reserved_til += RESERVATION_INC; |
|
|
|
else |
|
|
|
reservation_height = current_height + RESERVATION_INC; |
|
|
|
utxo->reserved_til = current_height + RESERVATION_INC; |
|
|
|
|
|
|
|
utxo->status = output_state_reserved; |
|
|
|
tal_free(utxo->reserved_til); |
|
|
|
utxo->reserved_til = tal_dup(utxo, u32, &reservation_height); |
|
|
|
|
|
|
|
db_set_utxo(w->db, utxo); |
|
|
|
|
|
|
@ -478,23 +466,16 @@ bool wallet_reserve_utxo(struct wallet *w, struct utxo *utxo, u32 current_height |
|
|
|
|
|
|
|
void wallet_unreserve_utxo(struct wallet *w, struct utxo *utxo, u32 current_height) |
|
|
|
{ |
|
|
|
if (utxo->status == output_state_reserved) { |
|
|
|
/* FIXME: old code didn't set reserved_til, so fake it here */ |
|
|
|
if (!utxo->reserved_til) |
|
|
|
utxo->reserved_til = tal_dup(utxo, u32, ¤t_height); |
|
|
|
assert(utxo->reserved_til); |
|
|
|
} |
|
|
|
|
|
|
|
if (utxo->status != output_state_reserved) |
|
|
|
fatal("UTXO %s:%u is not reserved", |
|
|
|
type_to_string(tmpctx, struct bitcoin_txid, &utxo->txid), |
|
|
|
utxo->outnum); |
|
|
|
|
|
|
|
if (*utxo->reserved_til <= current_height + RESERVATION_INC) { |
|
|
|
if (utxo->reserved_til <= current_height + RESERVATION_INC) { |
|
|
|
utxo->status = output_state_available; |
|
|
|
utxo->reserved_til = tal_free(utxo->reserved_til); |
|
|
|
utxo->reserved_til = 0; |
|
|
|
} else |
|
|
|
*utxo->reserved_til -= RESERVATION_INC; |
|
|
|
utxo->reserved_til -= RESERVATION_INC; |
|
|
|
|
|
|
|
db_set_utxo(w->db, utxo); |
|
|
|
} |
|
|
|