mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 09:34:24 +01:00
protocol: add open-complete.
This is where we expose the revocation preimages for the escape transactions. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
53
test-cli/check-open-complete.c
Normal file
53
test-cli/check-open-complete.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <ccan/crypto/shachain/shachain.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <ccan/opt/opt.h>
|
||||
#include <ccan/structeq/structeq.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/read_write_all/read_write_all.h>
|
||||
#include "lightning.pb-c.h"
|
||||
#include "bitcoin/base58.h"
|
||||
#include "pkt.h"
|
||||
#include "bitcoin/script.h"
|
||||
#include "bitcoin/address.h"
|
||||
#include "bitcoin/tx.h"
|
||||
#include "bitcoin/pubkey.h"
|
||||
#include "bitcoin/privkey.h"
|
||||
#include "bitcoin/shadouble.h"
|
||||
#include "protobuf_convert.h"
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Create message to reveal escape preimage to invalidate our escape txs. */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const tal_t *ctx = tal_arr(NULL, char, 0);
|
||||
OpenChannel *o2;
|
||||
OpenComplete *c;
|
||||
struct sha256 escape_secret, escape_hash, expect;
|
||||
|
||||
err_set_progname(argv[0]);
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"<our-escape-secret>\n"
|
||||
"A test program to create an open-complete message on stdout.",
|
||||
"Print this message.");
|
||||
|
||||
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||
|
||||
if (argc != 3)
|
||||
opt_usage_exit_fail("Expected 2 arguments");
|
||||
|
||||
o2 = pkt_from_file(argv[1], PKT__PKT_OPEN)->open;
|
||||
c = pkt_from_file(argv[2], PKT__PKT_OPEN_COMPLETE)->open_complete;
|
||||
proto_to_sha256(c->escape_preimage, &escape_secret);
|
||||
proto_to_sha256(o2->escape_hash, &expect);
|
||||
|
||||
/* Get hash from escape secret. */
|
||||
sha256(&escape_hash, escape_secret.u.u8, sizeof(escape_secret.u.u8));
|
||||
if (!structeq(&escape_hash, &expect))
|
||||
errx(1, "Invalid escape preimage");
|
||||
|
||||
tal_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
50
test-cli/open-complete.c
Normal file
50
test-cli/open-complete.c
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <ccan/crypto/shachain/shachain.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <ccan/opt/opt.h>
|
||||
#include <ccan/str/hex/hex.h>
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/read_write_all/read_write_all.h>
|
||||
#include "lightning.pb-c.h"
|
||||
#include "bitcoin/base58.h"
|
||||
#include "pkt.h"
|
||||
#include "bitcoin/script.h"
|
||||
#include "bitcoin/address.h"
|
||||
#include "bitcoin/tx.h"
|
||||
#include "bitcoin/pubkey.h"
|
||||
#include "bitcoin/privkey.h"
|
||||
#include "bitcoin/shadouble.h"
|
||||
#include "protobuf_convert.h"
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
/* Create message to reveal escape preimage to invalidate our escape txs. */
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const tal_t *ctx = tal_arr(NULL, char, 0);
|
||||
struct sha256 escape_secret;
|
||||
struct pkt *pkt;
|
||||
|
||||
err_set_progname(argv[0]);
|
||||
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||
"<our-escape-secret>\n"
|
||||
"A test program to create an open-complete message on stdout.",
|
||||
"Print this message.");
|
||||
|
||||
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||
|
||||
if (argc != 2)
|
||||
opt_usage_exit_fail("Expected 1 argument");
|
||||
|
||||
if (!hex_decode(argv[1], strlen(argv[1]), &escape_secret,
|
||||
sizeof(escape_secret)))
|
||||
errx(1, "Invalid escape hash '%s' - need 256 hex bits", argv[1]);
|
||||
|
||||
pkt = open_complete_pkt(ctx, &escape_secret);
|
||||
|
||||
if (!write_all(STDOUT_FILENO, pkt, pkt_totlen(pkt)))
|
||||
err(1, "Writing out packet");
|
||||
|
||||
tal_free(ctx);
|
||||
return 0;
|
||||
}
|
||||
@@ -113,6 +113,14 @@ $CLI sendrawtransaction `cut -d: -f1 B-anchor.tx` > B-anchor.txid
|
||||
|
||||
# while [ 0$($CLI getrawtransaction $(cat A-anchor.txid) 1 | sed -n 's/.*"confirmations" : \([0-9]*\),/\1/p') -lt $($PREFIX ./get-anchor-depth B-open.pb) ]; do scripts/generate-block.sh; done
|
||||
|
||||
# Tell other side that channel is open.
|
||||
$PREFIX ./open-complete $A_ESCSECRET > A-open-complete.pb
|
||||
$PREFIX ./open-complete $B_ESCSECRET > B-open-complete.pb
|
||||
|
||||
# Each side checks that escape preimage is correct.
|
||||
$PREFIX ./check-open-complete B-open.pb B-open-complete.pb
|
||||
$PREFIX ./check-open-complete A-open.pb A-open-complete.pb
|
||||
|
||||
# Just for testing, generate the first transaction.
|
||||
$PREFIX ./create-commit-tx A-open.pb B-open.pb A-anchor-id.pb B-anchor-id.pb $A_TMPKEY B-commit-sig.pb > A-commit-0.tx
|
||||
|
||||
|
||||
Reference in New Issue
Block a user