mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
channel: change initialization to have explicit local amount, and commot indices.
This is useful for restoration. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
a6b03dec15
commit
4151135be2
@ -137,8 +137,10 @@ struct channel *new_channel(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
u64 push_msat,
|
||||
u64 local_msatoshi,
|
||||
u32 feerate_per_kw,
|
||||
u64 local_commit_index,
|
||||
u64 remote_commit_index,
|
||||
const struct channel_config *local,
|
||||
const struct channel_config *remote,
|
||||
const struct basepoints *local_basepoints,
|
||||
@ -155,7 +157,7 @@ struct channel *new_channel(const tal_t *ctx,
|
||||
return tal_free(channel);
|
||||
|
||||
channel->funding_msat = funding_satoshis * 1000;
|
||||
if (push_msat > channel->funding_msat)
|
||||
if (local_msatoshi > channel->funding_msat)
|
||||
return tal_free(channel);
|
||||
|
||||
channel->funder = funder;
|
||||
@ -169,16 +171,15 @@ struct channel *new_channel(const tal_t *ctx,
|
||||
= channel->view[REMOTE].feerate_per_kw
|
||||
= feerate_per_kw;
|
||||
|
||||
channel->view[funder].owed_msat[funder]
|
||||
= channel->view[!funder].owed_msat[funder]
|
||||
= channel->funding_msat - push_msat;
|
||||
channel->view[funder].owed_msat[!funder]
|
||||
= channel->view[!funder].owed_msat[!funder]
|
||||
= push_msat;
|
||||
channel->view[LOCAL].owed_msat[LOCAL]
|
||||
= channel->view[REMOTE].owed_msat[LOCAL]
|
||||
= local_msatoshi;
|
||||
channel->view[REMOTE].owed_msat[REMOTE]
|
||||
= channel->view[LOCAL].owed_msat[REMOTE]
|
||||
= channel->funding_msat - local_msatoshi;
|
||||
|
||||
channel->view[LOCAL].commitment_number
|
||||
= channel->view[REMOTE].commitment_number
|
||||
= 0;
|
||||
channel->view[LOCAL].commitment_number = local_commit_index;
|
||||
channel->view[REMOTE].commitment_number = remote_commit_index;
|
||||
|
||||
channel->basepoints[LOCAL] = *local_basepoints;
|
||||
channel->basepoints[REMOTE] = *remote_basepoints;
|
||||
|
@ -124,8 +124,10 @@ static inline u16 to_self_delay(const struct channel *channel, enum side side)
|
||||
* @funding_txid: The commitment transaction id.
|
||||
* @funding_txout: The commitment transaction output number.
|
||||
* @funding_satoshis: The commitment transaction amount.
|
||||
* @push_msat: The amount the initator gives to the other side.
|
||||
* @local_msatoshi: The amount for the local side (remainder goes to remote)
|
||||
* @feerate_per_kw: feerate per kiloweight (satoshis)
|
||||
* @local_commit_index: local commitment number
|
||||
* @remote_commit_index: remote commitment number
|
||||
* @local: local channel configuration
|
||||
* @remote: remote channel configuration
|
||||
* @local_basepoints: local basepoints.
|
||||
@ -140,8 +142,10 @@ struct channel *new_channel(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
u64 push_msat,
|
||||
u64 local_msatoshi,
|
||||
u32 feerate_per_kw,
|
||||
u64 local_commit_index,
|
||||
u64 remote_commit_index,
|
||||
const struct channel_config *local,
|
||||
const struct channel_config *remote,
|
||||
const struct basepoints *local_basepoints,
|
||||
|
@ -1216,6 +1216,7 @@ static void init_channel(struct peer *peer)
|
||||
struct basepoints points[NUM_SIDES];
|
||||
u64 funding_satoshi, push_msat;
|
||||
u16 funding_txout;
|
||||
u64 local_msatoshi;
|
||||
struct pubkey funding_pubkey[NUM_SIDES];
|
||||
struct sha256_double funding_txid;
|
||||
bool am_funder;
|
||||
@ -1258,8 +1259,16 @@ static void init_channel(struct peer *peer)
|
||||
type_to_string(trc, struct pubkey,
|
||||
&peer->old_per_commit[LOCAL]));
|
||||
|
||||
if (am_funder)
|
||||
local_msatoshi = funding_satoshi * 1000 - push_msat;
|
||||
else
|
||||
local_msatoshi = push_msat;
|
||||
|
||||
peer->channel = new_channel(peer, &funding_txid, funding_txout,
|
||||
funding_satoshi, push_msat, peer->fee_base,
|
||||
funding_satoshi,
|
||||
local_msatoshi,
|
||||
peer->fee_base,
|
||||
0, 0,
|
||||
&peer->conf[LOCAL], &peer->conf[REMOTE],
|
||||
&points[LOCAL], &points[REMOTE],
|
||||
&funding_pubkey[LOCAL],
|
||||
|
@ -339,8 +339,10 @@ static u8 *funder_channel(struct state *state,
|
||||
&state->funding_txid,
|
||||
state->funding_txout,
|
||||
state->funding_satoshis,
|
||||
state->push_msat,
|
||||
state->funding_satoshis * 1000
|
||||
- state->push_msat,
|
||||
state->feerate_per_kw,
|
||||
0, 0,
|
||||
&state->localconf,
|
||||
state->remoteconf,
|
||||
ours, &theirs,
|
||||
@ -595,6 +597,7 @@ static u8 *fundee_channel(struct state *state,
|
||||
state->funding_satoshis,
|
||||
state->push_msat,
|
||||
state->feerate_per_kw,
|
||||
0, 0,
|
||||
&state->localconf,
|
||||
state->remoteconf,
|
||||
ours, &theirs,
|
||||
|
@ -403,6 +403,8 @@ int main(void)
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* commitment_number: 42
|
||||
*...
|
||||
* name: simple commitment tx with no HTLCs
|
||||
* to_local_msat: 7000000000
|
||||
* to_remote_msat: 3000000000
|
||||
@ -413,28 +415,23 @@ int main(void)
|
||||
to_remote_msat = 3000000000;
|
||||
feerate_per_kw = 15000;
|
||||
lchannel = new_channel(tmpctx, &funding_txid, funding_output_index,
|
||||
funding_amount_satoshi, to_remote_msat,
|
||||
funding_amount_satoshi, to_local_msat,
|
||||
feerate_per_kw,
|
||||
42, 0,
|
||||
local_config,
|
||||
remote_config,
|
||||
&localbase, &remotebase,
|
||||
&local_funding_pubkey, &remote_funding_pubkey,
|
||||
LOCAL);
|
||||
|
||||
rchannel = new_channel(tmpctx, &funding_txid, funding_output_index,
|
||||
funding_amount_satoshi, to_remote_msat,
|
||||
feerate_per_kw,
|
||||
0, 42,
|
||||
remote_config,
|
||||
local_config,
|
||||
&remotebase, &localbase,
|
||||
&remote_funding_pubkey, &local_funding_pubkey,
|
||||
REMOTE);
|
||||
/* BOLT #3:
|
||||
*
|
||||
* commitment_number: 42
|
||||
*/
|
||||
lchannel->view[LOCAL].commitment_number
|
||||
= rchannel->view[REMOTE].commitment_number = 42;
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user