diff --git a/anchor.c b/anchor.c index 17bce4a4e..73097a78a 100644 --- a/anchor.c +++ b/anchor.c @@ -56,8 +56,8 @@ struct bitcoin_tx *anchor_tx_create(const tal_t *ctx, return tal_free(tx); /* Pubkeys both valid, right? */ - if (!proto_to_pubkey(o1->anchor->pubkey, &key1) - || !proto_to_pubkey(o2->anchor->pubkey, &key2)) + if (!proto_to_pubkey(o1->commit_key, &key1) + || !proto_to_pubkey(o2->commit_key, &key2)) return tal_free(tx); /* Make the 2 of 2 payment for the commitment txs. */ diff --git a/close_tx.c b/close_tx.c index 7ee22b8bb..a382bb39e 100644 --- a/close_tx.c +++ b/close_tx.c @@ -29,9 +29,9 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx, tx->input[0].input_amount = input_amount; /* Outputs goes to final pubkey */ - if (!proto_to_pubkey(ours->final, &ourkey)) + if (!proto_to_pubkey(ours->final_key, &ourkey)) return tal_free(tx); - if (!proto_to_pubkey(theirs->final, &theirkey)) + if (!proto_to_pubkey(theirs->final_key, &theirkey)) return tal_free(tx); /* delta must make sense. */ diff --git a/commit_tx.c b/commit_tx.c index f28cc3e8b..50bb07e69 100644 --- a/commit_tx.c +++ b/commit_tx.c @@ -32,9 +32,9 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx, tx->input[0].input_amount = ours->anchor->total + theirs->anchor->total; /* Output goes to our final pubkeys */ - if (!proto_to_pubkey(ours->final, &ourkey)) + if (!proto_to_pubkey(ours->final_key, &ourkey)) return tal_free(tx); - if (!proto_to_pubkey(theirs->final, &theirkey)) + if (!proto_to_pubkey(theirs->final_key, &theirkey)) return tal_free(tx); if (!proto_to_locktime(theirs, &locktime)) @@ -57,7 +57,7 @@ struct bitcoin_tx *create_commit_tx(const tal_t *ctx, tx->output[0].amount += delta; /* Second output is a P2SH payment to them. */ - if (!proto_to_pubkey(theirs->final, &to_me)) + if (!proto_to_pubkey(theirs->final_key, &to_me)) return tal_free(tx); tx->output[1].script = scriptpubkey_p2sh(ctx, bitcoin_redeem_single(ctx, diff --git a/lightning.pb-c.c b/lightning.pb-c.c index daef8682e..20e257233 100644 --- a/lightning.pb-c.c +++ b/lightning.pb-c.c @@ -1153,7 +1153,7 @@ const ProtobufCMessageDescriptor change__descriptor = (ProtobufCMessageInit) change__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor anchor__field_descriptors[6] = +static const ProtobufCFieldDescriptor anchor__field_descriptors[5] = { { "inputs", @@ -1191,18 +1191,6 @@ static const ProtobufCFieldDescriptor anchor__field_descriptors[6] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, - { - "pubkey", - 5, - PROTOBUF_C_LABEL_REQUIRED, - PROTOBUF_C_TYPE_MESSAGE, - 0, /* quantifier_offset */ - offsetof(Anchor, pubkey), - &bitcoin_pubkey__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, { "fee", 8, @@ -1230,19 +1218,18 @@ static const ProtobufCFieldDescriptor anchor__field_descriptors[6] = }; static const unsigned anchor__field_indices_by_name[] = { 1, /* field[1] = change */ - 4, /* field[4] = fee */ + 3, /* field[3] = fee */ 0, /* field[0] = inputs */ - 5, /* field[5] = min_confirms */ - 3, /* field[3] = pubkey */ + 4, /* field[4] = min_confirms */ 2, /* field[2] = total */ }; static const ProtobufCIntRange anchor__number_ranges[4 + 1] = { { 1, 0 }, { 4, 2 }, - { 8, 4 }, - { 10, 5 }, - { 0, 6 } + { 8, 3 }, + { 10, 4 }, + { 0, 5 } }; const ProtobufCMessageDescriptor anchor__descriptor = { @@ -1252,15 +1239,27 @@ const ProtobufCMessageDescriptor anchor__descriptor = "Anchor", "", sizeof(Anchor), - 6, + 5, anchor__field_descriptors, anchor__field_indices_by_name, 4, anchor__number_ranges, (ProtobufCMessageInit) anchor__init, NULL,NULL,NULL /* reserved[123] */ }; -static const ProtobufCFieldDescriptor open_channel__field_descriptors[6] = +static const ProtobufCFieldDescriptor open_channel__field_descriptors[7] = { + { + "final_key", + 1, + PROTOBUF_C_LABEL_REQUIRED, + PROTOBUF_C_TYPE_MESSAGE, + 0, /* quantifier_offset */ + offsetof(OpenChannel, final_key), + &bitcoin_pubkey__descriptor, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, { "locktime_seconds", 2, @@ -1298,12 +1297,12 @@ static const ProtobufCFieldDescriptor open_channel__field_descriptors[6] = 0,NULL,NULL /* reserved1,reserved2, etc */ }, { - "final", + "commit_key", 5, PROTOBUF_C_LABEL_REQUIRED, PROTOBUF_C_TYPE_MESSAGE, 0, /* quantifier_offset */ - offsetof(OpenChannel, final), + offsetof(OpenChannel, commit_key), &bitcoin_pubkey__descriptor, NULL, 0, /* flags */ @@ -1335,17 +1334,18 @@ static const ProtobufCFieldDescriptor open_channel__field_descriptors[6] = }, }; static const unsigned open_channel__field_indices_by_name[] = { - 5, /* field[5] = anchor */ - 4, /* field[4] = commitment_fee */ - 3, /* field[3] = final */ - 1, /* field[1] = locktime_blocks */ - 0, /* field[0] = locktime_seconds */ - 2, /* field[2] = revocation_hash */ + 6, /* field[6] = anchor */ + 4, /* field[4] = commit_key */ + 5, /* field[5] = commitment_fee */ + 0, /* field[0] = final_key */ + 2, /* field[2] = locktime_blocks */ + 1, /* field[1] = locktime_seconds */ + 3, /* field[3] = revocation_hash */ }; static const ProtobufCIntRange open_channel__number_ranges[1 + 1] = { - { 2, 0 }, - { 0, 6 } + { 1, 0 }, + { 0, 7 } }; const ProtobufCMessageDescriptor open_channel__descriptor = { @@ -1355,7 +1355,7 @@ const ProtobufCMessageDescriptor open_channel__descriptor = "OpenChannel", "", sizeof(OpenChannel), - 6, + 7, open_channel__field_descriptors, open_channel__field_indices_by_name, 1, open_channel__number_ranges, diff --git a/lightning.pb-c.h b/lightning.pb-c.h index e86c0e0c5..9f72fe799 100644 --- a/lightning.pb-c.h +++ b/lightning.pb-c.h @@ -142,10 +142,6 @@ struct _Anchor */ size_t n_inputs; BitcoinInput **inputs; - /* - * Pubkey for anchor to pay to for commitment tx (p2sh) - */ - BitcoinPubkey *pubkey; /* * Any change from anchor (in case we don't want to use them all) */ @@ -165,7 +161,7 @@ struct _Anchor }; #define ANCHOR__INIT \ { PROTOBUF_C_MESSAGE_INIT (&anchor__descriptor) \ - , 0,NULL, NULL, NULL, 0, 0, 0 } + , 0,NULL, NULL, 0, 0, 0 } typedef enum { @@ -184,10 +180,14 @@ struct _OpenChannel * Hash seed for revoking commitment transactions. */ Sha256Hash *revocation_hash; + /* + * Pubkey for anchor to pay to for commitment tx (p2sh) + */ + BitcoinPubkey *commit_key; /* * How to pay money to us from commit_tx. */ - BitcoinPubkey *final; + BitcoinPubkey *final_key; /* * How much transaction fee we'll pay for commitment txs. */ @@ -204,7 +204,7 @@ struct _OpenChannel }; #define OPEN_CHANNEL__INIT \ { PROTOBUF_C_MESSAGE_INIT (&open_channel__descriptor) \ - , NULL, NULL, 0, NULL, OPEN_CHANNEL__LOCKTIME__NOT_SET, {} } + , NULL, NULL, NULL, 0, NULL, OPEN_CHANNEL__LOCKTIME__NOT_SET, {} } /* diff --git a/lightning.proto b/lightning.proto index b50b05e8a..467cfd257 100644 --- a/lightning.proto +++ b/lightning.proto @@ -52,8 +52,6 @@ message change { message anchor { // 0 or more unspent inputs we want to use for anchor. repeated bitcoin_input inputs = 1; - // Pubkey for anchor to pay to for commitment tx (p2sh) - required bitcoin_pubkey pubkey = 5; // Any change from anchor (in case we don't want to use them all) optional change change = 2; // How much transaction fee we'll pay in the anchor tx. @@ -77,8 +75,10 @@ message open_channel { } // Hash seed for revoking commitment transactions. required sha256_hash revocation_hash = 4; + // Pubkey for anchor to pay into commitment tx. + required bitcoin_pubkey commit_key = 5; // How to pay money to us from commit_tx. - required bitcoin_pubkey final = 5; + required bitcoin_pubkey final_key = 1; // How much transaction fee we'll pay for commitment txs. required uint64 commitment_fee = 6; // The anchor transaction details. diff --git a/pkt.c b/pkt.c index 7c315b444..a3991e386 100644 --- a/pkt.c +++ b/pkt.c @@ -33,7 +33,8 @@ static struct pkt *to_pkt(const tal_t *ctx, Pkt__PktCase type, void *msg) struct pkt *openchannel_pkt(const tal_t *ctx, const struct sha256 *revocation_hash, - const struct pubkey *to_me, + const struct pubkey *commit, + const struct pubkey *final, u64 commitment_fee, u32 rel_locktime_seconds, Anchor *anchor) @@ -42,10 +43,10 @@ struct pkt *openchannel_pkt(const tal_t *ctx, /* Required fields must be set: pack functions don't check! */ assert(anchor->inputs); - assert(anchor->pubkey); o.revocation_hash = sha256_to_proto(ctx, revocation_hash); - o.final = pubkey_to_proto(ctx, to_me); + o.commit_key = pubkey_to_proto(ctx, commit); + o.final_key = pubkey_to_proto(ctx, final); o.commitment_fee = commitment_fee; o.anchor = anchor; o.locktime_case = OPEN_CHANNEL__LOCKTIME_LOCKTIME_SECONDS; diff --git a/pkt.h b/pkt.h index 20d7fd066..575150a46 100644 --- a/pkt.h +++ b/pkt.h @@ -32,14 +32,16 @@ struct pubkey; * openchannel_pkt - create an openchannel message * @ctx: tal context to allocate off. * @revocation_hash: first hash value generated from seed. - * @to_me: the pubkey for the commit transactions' P2SH output. + * @commit: the pubkey for the anchor transactions' P2SH output. + * @final: the pubkey for the commit transactions' P2SH output. * @commitment_fee: the fee to use for commitment tx. * @rel_locktime_seconds: relative seconds for commitment locktime. * @anchor: the anchor transaction details. */ struct pkt *openchannel_pkt(const tal_t *ctx, const struct sha256 *revocation_hash, - const struct pubkey *to_me, + const struct pubkey *commit, + const struct pubkey *final, u64 commitment_fee, u32 rel_locktime_seconds, Anchor *anchor); diff --git a/test-cli/check-commit-sig.c b/test-cli/check-commit-sig.c index 9593478c8..b83578465 100644 --- a/test-cli/check-commit-sig.c +++ b/test-cli/check-commit-sig.c @@ -54,8 +54,8 @@ int main(int argc, char *argv[]) errx(1, "Private key '%s' not on testnet!", argv[4]); /* Pubkey well-formed? */ - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) - errx(1, "Invalid anchor-2 key"); + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) + errx(1, "Invalid o2 commit_key"); /* Get the transaction ID of the anchor. */ anchor = anchor_tx_create(ctx, o1, o2, &inmap, &outmap); diff --git a/test-cli/close-channel.c b/test-cli/close-channel.c index eef274fab..ae32e61a8 100644 --- a/test-cli/close-channel.c +++ b/test-cli/close-channel.c @@ -68,13 +68,13 @@ int main(int argc, char *argv[]) } /* Get pubkeys */ - if (!proto_to_pubkey(o1->anchor->pubkey, &pubkey2)) + if (!proto_to_pubkey(o1->commit_key, &pubkey2)) errx(1, "Invalid o1 commit pubkey"); if (pubkey_len(&pubkey1) != pubkey_len(&pubkey2) || memcmp(pubkey1.key, pubkey2.key, pubkey_len(&pubkey2)) != 0) errx(1, "o1 pubkey != this privkey"); - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) - errx(1, "Invalid o2 final pubkey"); + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) + errx(1, "Invalid o2 commit pubkey"); /* This is what the anchor pays to; figure out whick output. */ redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2); diff --git a/test-cli/create-close-tx.c b/test-cli/create-close-tx.c index e7f081691..613038287 100644 --- a/test-cli/create-close-tx.c +++ b/test-cli/create-close-tx.c @@ -53,10 +53,10 @@ int main(int argc, char *argv[]) bitcoin_txid(anchor, &anchor_txid); /* Pubkeys well-formed? */ - if (!proto_to_pubkey(o1->anchor->pubkey, &pubkey1)) - errx(1, "Invalid anchor-1 key"); - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) - errx(1, "Invalid anchor-2 key"); + if (!proto_to_pubkey(o1->commit_key, &pubkey1)) + errx(1, "Invalid o1 commit_key"); + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) + errx(1, "Invalid o2 commit_key"); /* Get delta by accumulting all the updates. */ delta = 0; diff --git a/test-cli/create-commit-spend-tx.c b/test-cli/create-commit-spend-tx.c index b2a65a975..b6407e8e1 100644 --- a/test-cli/create-commit-spend-tx.c +++ b/test-cli/create-commit-spend-tx.c @@ -70,12 +70,12 @@ int main(int argc, char *argv[]) errx(1, "Invalid bitcoin pubkey '%s'", argv[5]); /* Get pubkeys */ - if (!proto_to_pubkey(o1->final, &pubkey2)) + if (!proto_to_pubkey(o1->final_key, &pubkey2)) errx(1, "Invalid o1 final pubkey"); if (pubkey_len(&pubkey1) != pubkey_len(&pubkey2) || memcmp(pubkey1.key, pubkey2.key, pubkey_len(&pubkey2)) != 0) errx(1, "o1 pubkey != this privkey"); - if (!proto_to_pubkey(o2->final, &pubkey2)) + if (!proto_to_pubkey(o2->final_key, &pubkey2)) errx(1, "Invalid o2 final pubkey"); /* o1 gives us the revocation hash */ diff --git a/test-cli/create-commit-tx.c b/test-cli/create-commit-tx.c index a93e1d0a9..bd66f5ced 100644 --- a/test-cli/create-commit-tx.c +++ b/test-cli/create-commit-tx.c @@ -58,13 +58,13 @@ int main(int argc, char *argv[]) errx(1, "Private key '%s' not on testnet!", argv[4]); /* Get pubkeys */ - if (!proto_to_pubkey(o1->anchor->pubkey, &pubkey2)) - errx(1, "Invalid o1 anchor pubkey"); + if (!proto_to_pubkey(o1->commit_key, &pubkey2)) + errx(1, "Invalid o1 commit pubkey"); if (pubkey_len(&pubkey1) != pubkey_len(&pubkey2) || memcmp(pubkey1.key, pubkey2.key, pubkey_len(&pubkey2)) != 0) errx(1, "o1 pubkey != this privkey"); - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) - errx(1, "Invalid o2 anchor pubkey"); + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) + errx(1, "Invalid o2 commit pubkey"); /* Their signature comes from open-commit or from update-accept. */ sig2.stype = SIGHASH_ALL; diff --git a/test-cli/create-steal-tx.c b/test-cli/create-steal-tx.c index 3c5c4f2e4..c414c3787 100644 --- a/test-cli/create-steal-tx.c +++ b/test-cli/create-steal-tx.c @@ -74,12 +74,12 @@ int main(int argc, char *argv[]) errx(1, "Invalid bitcoin pubkey '%s'", argv[6]); /* Get pubkeys */ - if (!proto_to_pubkey(o1->final, &pubkey2)) + if (!proto_to_pubkey(o1->final_key, &pubkey2)) errx(1, "Invalid o1 final pubkey"); if (pubkey_len(&pubkey1) != pubkey_len(&pubkey2) || memcmp(pubkey1.key, pubkey2.key, pubkey_len(&pubkey2)) != 0) errx(1, "o1 pubkey != this privkey"); - if (!proto_to_pubkey(o2->final, &pubkey2)) + if (!proto_to_pubkey(o2->final_key, &pubkey2)) errx(1, "Invalid o2 final pubkey"); /* Now, which commit output? Match redeem script. */ diff --git a/test-cli/open-channel.c b/test-cli/open-channel.c index 71c6ca65f..e8af836b1 100644 --- a/test-cli/open-channel.c +++ b/test-cli/open-channel.c @@ -132,7 +132,6 @@ int main(int argc, char *argv[]) anchor.n_inputs = (argc - 6); anchor.inputs = tal_arr(ctx, BitcoinInput *, anchor.n_inputs); - anchor.pubkey = pubkey_to_proto(ctx, &commitkey); total_in = 0; for (i = 0; i < anchor.n_inputs; i++) { @@ -160,7 +159,7 @@ int main(int argc, char *argv[]) sha256(&revocation_hash, revocation_hash.u.u8, sizeof(revocation_hash.u.u8)); - pkt = openchannel_pkt(ctx, &revocation_hash, &outkey, + pkt = openchannel_pkt(ctx, &revocation_hash, &commitkey, &outkey, commit_tx_fee, locktime_seconds, &anchor); if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt))) diff --git a/test-cli/open-commit-sig.c b/test-cli/open-commit-sig.c index d959cc286..1367c0ea1 100644 --- a/test-cli/open-commit-sig.c +++ b/test-cli/open-commit-sig.c @@ -74,7 +74,7 @@ int main(int argc, char *argv[]) (long long)o2->commitment_fee); /* Their pubkey must be valid */ - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) errx(1, "Invalid public open-channel-file2"); /* Sign it for them. */ diff --git a/test-cli/update-channel-accept.c b/test-cli/update-channel-accept.c index 8e483c3a4..a36333dfe 100644 --- a/test-cli/update-channel-accept.c +++ b/test-cli/update-channel-accept.c @@ -76,13 +76,13 @@ int main(int argc, char *argv[]) revocation_hash.u.u8, sizeof(revocation_hash.u.u8)); /* Get pubkeys */ - if (!proto_to_pubkey(o1->anchor->pubkey, &pubkey2)) + if (!proto_to_pubkey(o1->commit_key, &pubkey2)) errx(1, "Invalid o1 commit pubkey"); if (pubkey_len(&pubkey1) != pubkey_len(&pubkey2) || memcmp(pubkey1.key, pubkey2.key, pubkey_len(&pubkey2)) != 0) errx(1, "o1 pubkey != this privkey"); - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) - errx(1, "Invalid o2 final pubkey"); + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) + errx(1, "Invalid o2 commit pubkey"); /* This is what the anchor pays to; figure out whick output. */ redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2); diff --git a/test-cli/update-channel-complete.c b/test-cli/update-channel-complete.c index 6c45fc02c..dcbd35b62 100644 --- a/test-cli/update-channel-complete.c +++ b/test-cli/update-channel-complete.c @@ -89,10 +89,10 @@ int main(int argc, char *argv[]) errx(1, "Their preimage was incorrect"); /* Get pubkeys */ - if (!proto_to_pubkey(o1->anchor->pubkey, &pubkey1)) + if (!proto_to_pubkey(o1->commit_key, &pubkey1)) errx(1, "Invalid o1 commit pubkey"); - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) - errx(1, "Invalid o2 final pubkey"); + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) + errx(1, "Invalid o2 commit pubkey"); /* This is what the anchor pays to; figure out whick output. */ redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2); diff --git a/test-cli/update-channel-signature.c b/test-cli/update-channel-signature.c index 40d0968a3..5248a2519 100644 --- a/test-cli/update-channel-signature.c +++ b/test-cli/update-channel-signature.c @@ -80,13 +80,13 @@ int main(int argc, char *argv[]) shachain_from_seed(&seed, argc - 7 - 1, &preimage); /* Get pubkeys */ - if (!proto_to_pubkey(o1->anchor->pubkey, &pubkey2)) + if (!proto_to_pubkey(o1->commit_key, &pubkey2)) errx(1, "Invalid o1 commit pubkey"); if (pubkey_len(&pubkey1) != pubkey_len(&pubkey2) || memcmp(pubkey1.key, pubkey2.key, pubkey_len(&pubkey2)) != 0) errx(1, "o1 pubkey != this privkey"); - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) - errx(1, "Invalid o2 final pubkey"); + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) + errx(1, "Invalid o2 commit pubkey"); /* This is what the anchor pays to; figure out whick output. */ redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2); @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) errx(1, "Delta too large"); /* Their pubkey must be valid */ - if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) + if (!proto_to_pubkey(o2->commit_key, &pubkey2)) errx(1, "Invalid public open-channel-file2"); /* Sign it for them. */