Browse Source

common/utxo: make commitment_point optional in close_info.

We don't rotate key for option_static_remotekey, so we don't need
this point for such channels.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
travis-debug
Rusty Russell 5 years ago
committed by neil saitug
parent
commit
160f27061e
  1. 12
      common/utxo.c
  2. 3
      common/utxo.h
  3. 2
      hsmd/hsmd.c
  4. 2
      onchaind/onchain_wire.csv
  5. 27
      wallet/test/run-wallet.c
  6. 13
      wallet/wallet.c

12
common/utxo.c

@ -20,7 +20,9 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo)
if (is_unilateral_close) {
towire_u64(pptr, utxo->close_info->channel_id);
towire_node_id(pptr, &utxo->close_info->peer_id);
towire_pubkey(pptr, &utxo->close_info->commitment_point);
towire_bool(pptr, utxo->close_info->commitment_point != NULL);
if (utxo->close_info->commitment_point)
towire_pubkey(pptr, utxo->close_info->commitment_point);
}
}
@ -42,7 +44,13 @@ struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
utxo->close_info = tal(utxo, struct unilateral_close_info);
utxo->close_info->channel_id = fromwire_u64(ptr, max);
fromwire_node_id(ptr, max, &utxo->close_info->peer_id);
fromwire_pubkey(ptr, max, &utxo->close_info->commitment_point);
if (fromwire_bool(ptr, max)) {
utxo->close_info->commitment_point = tal(utxo,
struct pubkey);
fromwire_pubkey(ptr, max,
utxo->close_info->commitment_point);
} else
utxo->close_info->commitment_point = NULL;
} else {
utxo->close_info = NULL;
}

3
common/utxo.h

@ -17,7 +17,8 @@ struct ext_key;
struct unilateral_close_info {
u64 channel_id;
struct node_id peer_id;
struct pubkey commitment_point;
/* NULL if this is an option_static_remotekey commitment */
struct pubkey *commitment_point;
};
struct utxo {

2
hsmd/hsmd.c

@ -1386,7 +1386,7 @@ static void hsm_unilateral_close_privkey(struct privkey *dst,
derive_basepoints(&channel_seed, NULL, &basepoints, &secrets, NULL);
if (!derive_simple_privkey(&secrets.payment_basepoint_secret,
&basepoints.payment, &info->commitment_point,
&basepoints.payment, info->commitment_point,
dst)) {
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Deriving unilateral_close_privkey");

2
onchaind/onchain_wire.csv

@ -91,7 +91,7 @@ msgtype,onchain_all_irrevocably_resolved,5011
msgtype,onchain_add_utxo,5012
msgdata,onchain_add_utxo,prev_out_tx,bitcoin_txid,
msgdata,onchain_add_utxo,prev_out_index,u32,
msgdata,onchain_add_utxo,per_commit_point,pubkey,
msgdata,onchain_add_utxo,per_commit_point,?pubkey,
msgdata,onchain_add_utxo,value,amount_sat,
msgdata,onchain_add_utxo,blockheight,u32,
msgdata,onchain_add_utxo,len,u16,

Can't render this file because it has a wrong number of fields in line 5.

27
wallet/test/run-wallet.c

@ -784,7 +784,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
u.close_info = tal(w, struct unilateral_close_info);
u.close_info->channel_id = 42;
u.close_info->peer_id = id;
u.close_info->commitment_point = pk;
u.close_info->commitment_point = &pk;
CHECK_MSG(wallet_add_utxo(w, &u, p2sh_wpkh),
"wallet_add_utxo with close_info");
@ -796,7 +796,7 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
u = *utxos[1];
CHECK(u.close_info->channel_id == 42 &&
pubkey_eq(&u.close_info->commitment_point, &pk) &&
pubkey_eq(u.close_info->commitment_point, &pk) &&
node_id_eq(&u.close_info->peer_id, &id));
/* Now un-reserve them for the tests below */
tal_free(utxos);
@ -826,6 +826,29 @@ static bool test_wallet_outputs(struct lightningd *ld, const tal_t *ctx)
output_state_spent),
"could not change output state ignoring oldstate");
/* Attempt to save an UTXO with close_info set, no commitment_point */
memset(&u.txid, 2, sizeof(u.txid));
u.amount = AMOUNT_SAT(5);
u.close_info = tal(w, struct unilateral_close_info);
u.close_info->channel_id = 42;
u.close_info->peer_id = id;
u.close_info->commitment_point = NULL;
CHECK_MSG(wallet_add_utxo(w, &u, p2sh_wpkh),
"wallet_add_utxo with close_info no commitment_point");
/* Now select it */
utxos = wallet_select_coins(w, w, AMOUNT_SAT(5), 0, 21,
0 /* no confirmations required */,
&fee_estimate, &change_satoshis);
CHECK(utxos && tal_count(utxos) == 2);
u = *utxos[1];
CHECK(u.close_info->channel_id == 42 &&
u.close_info->commitment_point == NULL &&
node_id_eq(&u.close_info->peer_id, &id));
/* Now un-reserve them */
tal_free(utxos);
db_commit_transaction(w->db);
return true;
}

13
wallet/wallet.c

@ -111,7 +111,10 @@ bool wallet_add_utxo(struct wallet *w, struct utxo *utxo,
if (utxo->close_info) {
db_bind_u64(stmt, 6, utxo->close_info->channel_id);
db_bind_node_id(stmt, 7, &utxo->close_info->peer_id);
db_bind_pubkey(stmt, 8, &utxo->close_info->commitment_point);
if (utxo->close_info->commitment_point)
db_bind_pubkey(stmt, 8, utxo->close_info->commitment_point);
else
db_bind_null(stmt, 8);
} else {
db_bind_null(stmt, 6);
db_bind_null(stmt, 7);
@ -155,7 +158,13 @@ static struct utxo *wallet_stmt2output(const tal_t *ctx, struct db_stmt *stmt)
utxo->close_info = tal(utxo, struct unilateral_close_info);
utxo->close_info->channel_id = db_column_u64(stmt, 6);
db_column_node_id(stmt, 7, &utxo->close_info->peer_id);
db_column_pubkey(stmt, 8, &utxo->close_info->commitment_point);
if (!db_column_is_null(stmt, 8)) {
utxo->close_info->commitment_point
= tal(utxo->close_info, struct pubkey);
db_column_pubkey(stmt, 8,
utxo->close_info->commitment_point);
} else
utxo->close_info->commitment_point = NULL;
} else {
utxo->close_info = NULL;
}

Loading…
Cancel
Save