mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-21 23:04:22 +01:00
protocol: switch to single-funder anchor model.
Most complex change was gather_updates(), which handles all the "what is the current state of the channel" logic for our dumb test utils. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/read_write_all/read_write_all.h>
|
||||
#include "lightning.pb-c.h"
|
||||
#include "anchor.h"
|
||||
#include "bitcoin/base58.h"
|
||||
#include "pkt.h"
|
||||
#include "bitcoin/script.h"
|
||||
@@ -17,6 +16,7 @@
|
||||
#include "bitcoin/privkey.h"
|
||||
#include "find_p2sh_out.h"
|
||||
#include "protobuf_convert.h"
|
||||
#include "gather_updates.h"
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@@ -24,54 +24,48 @@ int main(int argc, char *argv[])
|
||||
const tal_t *ctx = tal_arr(NULL, char, 0);
|
||||
struct sha256 seed, revocation_hash, their_rhash;
|
||||
OpenChannel *o1, *o2;
|
||||
Update *update;
|
||||
struct bitcoin_tx *anchor, *commit;
|
||||
struct sha256_double anchor_txid;
|
||||
OpenAnchor *a;
|
||||
struct bitcoin_tx *commit;
|
||||
struct pkt *pkt;
|
||||
struct bitcoin_signature sig;
|
||||
struct privkey privkey;
|
||||
bool testnet;
|
||||
uint64_t num_updates;
|
||||
struct pubkey pubkey1, pubkey2;
|
||||
u8 *redeemscript;
|
||||
int64_t delta;
|
||||
size_t i, p2sh_out;
|
||||
uint64_t our_amount, their_amount;
|
||||
|
||||
err_set_progname(argv[0]);
|
||||
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"<seed> <anchor-tx> <open-channel-file1> <open-channel-file2> <commit-privkey> <update-protobuf> [previous-updates]\n"
|
||||
"<seed> <open-channel-file1> <open-channel-file2> <open-anchor-file> <commit-privkey> <all-updates...>\n"
|
||||
"Accept a new update message",
|
||||
"Print this message.");
|
||||
|
||||
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||
|
||||
if (argc < 6)
|
||||
opt_usage_exit_fail("Expected 5+ arguments");
|
||||
if (argc < 7)
|
||||
opt_usage_exit_fail("Expected 6+ arguments");
|
||||
|
||||
if (!hex_decode(argv[1], strlen(argv[1]), &seed, sizeof(seed)))
|
||||
errx(1, "Invalid seed '%s' - need 256 hex bits", argv[1]);
|
||||
|
||||
anchor = bitcoin_tx_from_file(ctx, argv[2]);
|
||||
bitcoin_txid(anchor, &anchor_txid);
|
||||
o1 = pkt_from_file(argv[3], PKT__PKT_OPEN)->open;
|
||||
o2 = pkt_from_file(argv[4], PKT__PKT_OPEN)->open;
|
||||
o1 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||
o2 = pkt_from_file(argv[3], PKT__PKT_OPEN)->open;
|
||||
a = pkt_from_file(argv[4], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
||||
|
||||
if (!key_from_base58(argv[5], strlen(argv[5]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[5]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[5]);
|
||||
|
||||
update = pkt_from_file(argv[6], PKT__PKT_UPDATE)->update;
|
||||
|
||||
/* Figure out cumulative delta since anchor. */
|
||||
delta = update->delta;
|
||||
for (i = 7; i < argc; i++) {
|
||||
Update *u = pkt_from_file(argv[i], PKT__PKT_UPDATE)->update;
|
||||
delta += u->delta;
|
||||
}
|
||||
num_updates = gather_updates(o1, o2, a, argv + 6,
|
||||
&our_amount, &their_amount,
|
||||
NULL, &their_rhash, NULL);
|
||||
|
||||
/* Get next revocation hash. */
|
||||
shachain_from_seed(&seed, argc - 6, &revocation_hash);
|
||||
shachain_from_seed(&seed, num_updates, &revocation_hash);
|
||||
sha256(&revocation_hash,
|
||||
revocation_hash.u.u8, sizeof(revocation_hash.u.u8));
|
||||
|
||||
@@ -86,12 +80,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* This is what the anchor pays to; figure out whick output. */
|
||||
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
||||
p2sh_out = find_p2sh_out(anchor, redeemscript);
|
||||
|
||||
/* Now create THEIR new commitment tx to spend 2/2 output of anchor. */
|
||||
proto_to_sha256(update->revocation_hash, &their_rhash);
|
||||
commit = create_commit_tx(ctx, o2, o1, &their_rhash, delta,
|
||||
&anchor_txid, p2sh_out);
|
||||
commit = create_commit_tx(ctx, o2, o1, a, &their_rhash,
|
||||
their_amount, our_amount);
|
||||
|
||||
/* If contributions don't exceed fees, this fails. */
|
||||
if (!commit)
|
||||
|
||||
Reference in New Issue
Block a user