Skip to content

Commit

Permalink
Merge pull request #8 from dflate/wip_tests_py
Browse files Browse the repository at this point in the history
[WIP] code checks, run-bins and py's from test to work with Groestlcoin
  • Loading branch information
gruve-p authored Sep 27, 2018
2 parents 8fcbbce + cb948f8 commit 55d1d6e
Show file tree
Hide file tree
Showing 21 changed files with 236 additions and 421 deletions.
109 changes: 58 additions & 51 deletions channeld/test/run-full_channel.c

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions common/test/run-bolt11.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ static void test_b11(const char *b11str,
struct bolt11 *b11;
char *fail;
char *reproduce;

b11 = bolt11_decode(tmpctx, b11str, hashed_desc, &fail);
if (!b11)
errx(1, "%s:%u:%s", __FILE__, __LINE__, fail);
Expand Down Expand Up @@ -160,7 +159,7 @@ int main(void)
* * `ca784w`: Bech32 checksum
*/
b11 = new_bolt11(tmpctx, NULL);
b11->chain = chainparams_for_network("bitcoin");
b11->chain = chainparams_for_network("groestlcoin");
b11->timestamp = 1496314658;
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
strlen("0001020304050607080900010203040506070809000102030405060708090102"),
Expand All @@ -169,7 +168,7 @@ int main(void)
b11->receiver_id = node;
b11->description = "Please consider supporting this project";

test_b11("lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w", b11, NULL);
test_b11("lngrs1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaqry7cu947rc3snaedmjtmauuslg0glcq6w7t9njkwxpql8zataj6jkcj02tcrskffaahc7570mjv50gt0nku23r8e30gazgndd50cucgplz6udt", b11, NULL);

/* BOLT #11:
*
Expand All @@ -194,7 +193,7 @@ int main(void)
*/
msatoshi = 2500 * (1000ULL * 100000000) / 1000000;
b11 = new_bolt11(tmpctx, &msatoshi);
b11->chain = chainparams_for_network("bitcoin");
b11->chain = chainparams_for_network("groestlcoin");
b11->timestamp = 1496314658;
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
strlen("0001020304050607080900010203040506070809000102030405060708090102"),
Expand All @@ -204,7 +203,7 @@ int main(void)
b11->description = "1 cup coffee";
b11->expiry = 60;

test_b11("lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaztrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspfj9srp", b11, NULL);
test_b11("lngrs2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpu9qesh2z5s6s0vjmq05mva9wp7l2pynjm2x3wf8zcj4kfa040wqzprsmyrdeuc8l7eemqt56r3srwvjetej72xdhnr4r74nellv7hlkgqqscvgy", b11, NULL);

/* BOLT #11:
*
Expand All @@ -226,15 +225,18 @@ int main(void)
*/
msatoshi = 20 * (1000ULL * 100000000) / 1000;
b11 = new_bolt11(tmpctx, &msatoshi);
b11->chain = chainparams_for_network("bitcoin");
b11->chain = chainparams_for_network("groestlcoin");
b11->timestamp = 1496314658;
if (!hex_decode("0001020304050607080900010203040506070809000102030405060708090102",
strlen("0001020304050607080900010203040506070809000102030405060708090102"),
&b11->payment_hash, sizeof(b11->payment_hash)))
abort();
b11->receiver_id = node;
b11->description_hash = tal(b11, struct sha256);
test_b11("lnbc20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqscc6gd6ql3jrc5yzme8v4ntcewwz5cnw92tz0pc8qcuufvq7khhr8wpald05e92xw006sq94mg8v2ndf4sefvf9sygkshp5zfem29trqq2yxxz7", b11, "One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon");

//sha256(b11->description_hash, "One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon", strlen("One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon"));

test_b11("lngrs20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqsey8q96sq3fth032rsqpl8vedajcpxapcfgpv2m3sj8xgpdpv8vy38dv68hsj2dhfwpyh2g5a9ppmyv05df4sv8p4dtftpegp94dr4gqp6ek8hs", b11, "One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon");

/* FIXME: Test the others! */
wally_cleanup(0);
Expand Down
10 changes: 5 additions & 5 deletions doc/lightning-listfunds.7
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: lightning-listfunds
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\" Date: 09/18/2018
.\" Date: 09/27/2018
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "LIGHTNING\-LISTFUNDS" "7" "09/18/2018" "\ \&" "\ \&"
.TH "LIGHTNING\-LISTFUNDS" "7" "09/27/2018" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -131,7 +131,7 @@ Each entry in \fIchannels\fR will include:
.IP \(bu 2.3
.\}
\fIchannel_sat\fR
\- available satoshis on our node\(cqs end of the channel (values rounded to the nearest satoshi as internal storage is in millisatoshi)\&.
\- available gro's on our node\(cqs end of the channel (values rounded to the nearest gro as internal storage is in milligro)\&.
.RE
.sp
.RS 4
Expand All @@ -142,8 +142,8 @@ Each entry in \fIchannels\fR will include:
.sp -1
.IP \(bu 2.3
.\}
\fIchannel_total_sat\fR
\- total channel value in satoshi (values rounded to the nearest satoshi as internal storage is in millisatoshi)\&.
\fIchannel_total_gro\fR
\-channel value in gro (values rounded to the nearest gro as internal storage is in milligro)\&.
.RE
.sp
.RS 4
Expand Down
8 changes: 4 additions & 4 deletions doc/lightning-listfunds.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ Each entry in 'channels' will include:
- 'short_channel_id' - as per BOLT 7 (representing the block, transaction
number and output index of the channel funding transaction).

- 'channel_sat' - available satoshis on our node's end of the channel
(values rounded to the nearest satoshi as internal storage is in millisatoshi).
- 'channel_sat' - available gro's on our node's end of the channel
(values rounded to the nearest gro as internal storage is in milligro).

- 'channel_total_sat' - total channel value in satoshi
(values rounded to the nearest satoshi as internal storage is in millisatoshi).
- 'channel_total_gro' -channel value in gro
(values rounded to the nearest gro's as internal storage is in milligro).

- 'funding_txid' - funding transaction id.

Expand Down
8 changes: 4 additions & 4 deletions doc/lightningd-config.5
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: lightningd-config
.\" Author: [see the "AUTHOR" section]
.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
.\" Date: 09/07/2018
.\" Date: 09/22/2018
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
.TH "LIGHTNINGD\-CONFIG" "5" "09/07/2018" "\ \&" "\ \&"
.TH "LIGHTNINGD\-CONFIG" "5" "09/22/2018" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -183,10 +183,10 @@ Up to 32 UTF\-8 characters to tag your node\&. Completely silly, since anyone ca
.PP
\fBfee\-base\fR=\fIMILLISATOSHI\fR
.RS 4
The base fee to charge for every payment which passes through\&. Note that millisatoshis are a very, very small unit!
The base fee to charge for every payment which passes through\&. Note that milligro's are a very, very small unit!
.RE
.PP
\fBfee\-per\-satoshi\fR=\fIMILLIONTHS\fR
\fBfee\-per\-gro\fR=\fIMILLIONTHS\fR
.RS 4
This is the proportional fee to charge for every payment which passes through\&. As percentages are too coarse, it\(cqs in millionths, so 10000 is 1%, 1000 is 0\&.1%\&.
.RE
Expand Down
4 changes: 2 additions & 2 deletions doc/lightningd-config.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ Lightning node customization options:

*fee-base*='MILLISATOSHI'::
The base fee to charge for every payment which passes through. Note that
millisatoshis are a very, very small unit!
milligro are a very, very small unit!

*fee-per-satoshi*='MILLIONTHS'::
*fee-per-gro*='MILLIONTHS'::
This is the proportional fee to charge for every payment which passes
through. As percentages are too coarse, it's in millionths, so 10000
is 1%, 1000 is 0.1%.
Expand Down
6 changes: 3 additions & 3 deletions gossipd/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#define SUPERVERBOSE(...)
#endif

/* 365.25 * 24 * 60 / 10 */
#define BLOCKS_PER_YEAR 52596
/* 365.25 * 24 * 60 Groestlcoin */
#define BLOCKS_PER_YEAR 525960

/* For overflow avoidance, we never deal with msatoshi > 40 bits. */
#define MAX_MSATOSHI (1ULL << 40)
Expand Down Expand Up @@ -530,7 +530,7 @@ find_route(const tal_t *ctx, struct routing_state *rstate,
}

/* No route? */
if (dst->bfg[best].total >= INFINITE) {
if ((dst->bfg[best].total) >= INFINITE) {
status_trace("find_route: No route to %s",
type_to_string(tmpctx, struct pubkey, to));
return NULL;
Expand Down
22 changes: 12 additions & 10 deletions lightningd/test/run-funding_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,22 @@ int main(void)

/* BOLT #3:
*
* Block 1 coinbase transaction: 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000
* Block 1 coinbase transaction: 01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100002cd6e2150000232102a74321b69723e7574510f2a96d3becea672dd465c747bc6b23b9771a4d02e48aac00000000
*/

input = bitcoin_tx_from_hex(tmpctx,
"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000",
strlen("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100f2052a010000001976a9143ca33c2e4446f4a305f23c80df8ad1afdcf652f988ac00000000"));
"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100002cd6e2150000232102a74321b69723e7574510f2a96d3becea672dd465c747bc6b23b9771a4d02e48aac00000000",
strlen("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510101ffffffff0100002cd6e2150000232102a74321b69723e7574510f2a96d3becea672dd465c747bc6b23b9771a4d02e48aac00000000"));
assert(input);

/* BOLT #3:
* Block 1 coinbase privkey: 6bd078650fcee8444e4e09825227b801a1ca928debb750eb36e6d56124bb20e801
* # privkey in base58: cRCH7YNcarfvaiY1GWUKQrRGmoezvfAiqHtdRvxe16shzbd7LDMz
* Block 1 coinbase privkey: 8344ce325246cce131a4785b3878daef212643c2d62aa23e170f05f38258807901
* # privkey in base58: cRysUDzUoa5BqfvaQnLwQ5aXGXsKD4Hh8Ai3sK6UYSx1CNyLBA2q
*/
if (!key_from_base58("cRCH7YNcarfvaiY1GWUKQrRGmoezvfAiqHtdRvxe16shzbd7LDMz", strlen("cRCH7YNcarfvaiY1GWUKQrRGmoezvfAiqHtdRvxe16shzbd7LDMz"),
if (!key_from_base58("cRysUDzUoa5BqfvaQnLwQ5aXGXsKD4Hh8Ai3sK6UYSx1CNyLBA2q",strlen("cRysUDzUoa5BqfvaQnLwQ5aXGXsKD4Hh8Ai3sK6UYSx1CNyLBA2q"),
&testnet, &input_privkey, &inputkey))
abort();
/* testnet coinbase */
assert(testnet);
printf("* Block 1 coinbase privkey: %s\n",
type_to_string(tmpctx, struct privkey, &input_privkey));
Expand All @@ -88,18 +90,18 @@ int main(void)
* local_funding_pubkey: 023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb
* remote_funding_pubkey: 030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c1
*/
if (!pubkey_from_hexstr("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb",
strlen("023da092f6980e58d2c037173180e9a465476026ee50f96695963e8efe436f54eb"),
if (!pubkey_from_hexstr("0282600e6ffb205676f45b19bd4ff3bd7b0980dcb8d7979fe988516d7e7e95db27",
strlen("0282600e6ffb205676f45b19bd4ff3bd7b0980dcb8d7979fe988516d7e7e95db27"),
&local_funding_pubkey))
abort();
if (!pubkey_from_hexstr("030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c1",
if (!pubkey_from_hexstr("0282600e6ffb205676f45b19bd4ff3bd7b0980dcb8d7979fe988516d7e7e95db27",
strlen("030e9f7b623d2ccc7c9bd44d66d5ce21ce504c0acf6385a132cec6d3c39fa711c1"),
&remote_funding_pubkey))
abort();

bitcoin_txid(input, &utxo.txid);
utxo.outnum = 0;
utxo.amount = 5000000000;
utxo.amount = 24064000000000;
utxo.is_p2sh = false;
utxo.close_info = NULL;
funding_satoshis = 10000000;
Expand Down
44 changes: 26 additions & 18 deletions onchaind/test/run-grind_feerate.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ void subdaemon_setup(int argc UNNEEDED, char *argv[])
{ fprintf(stderr, "subdaemon_setup called!\n"); abort(); }
/* Generated stub for to_self_wscript */
u8 *to_self_wscript(const tal_t *ctx UNNEEDED,
u16 to_self_delay UNNEEDED,
const struct keyset *keyset UNNEEDED)
u16 to_self_delay UNNEEDED,
const struct keyset *keyset UNNEEDED)
{ fprintf(stderr, "to_self_wscript called!\n"); abort(); }
/* Generated stub for towire_hsm_get_per_commitment_point */
u8 *towire_hsm_get_per_commitment_point(const tal_t *ctx UNNEEDED, u64 n UNNEEDED)
Expand Down Expand Up @@ -168,39 +168,47 @@ int main(int argc, char *argv[])
secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
| SECP256K1_CONTEXT_SIGN);
setup_tmpctx();
tx = bitcoin_tx_from_hex(tmpctx, "0200000001e1ebca08cf1c301ac563580a1126d5c8fcb0e5e2043230b852c726553caf1e1d0000000000000000000160ae0a000000000022002082e03c5a9cb79c82cd5a0572dc175290bc044609aabe9cc852d61927436041796d000000",
strlen("0200000001e1ebca08cf1c301ac563580a1126d5c8fcb0e5e2043230b852c726553caf1e1d0000000000000000000160ae0a000000000022002082e03c5a9cb79c82cd5a0572dc175290bc044609aabe9cc852d61927436041796d000000"));
tx->input[0].amount = tal(tx, u64);
*tx->input[0].amount = 700000;
der = tal_hexdata(tmpctx, "30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9",
strlen("30450221009b2e0eef267b94c3899fb0dc7375012e2cee4c10348a068fe78d1b82b4b14036022077c3fad3adac2ddf33f415e45f0daf6658b7a0b09647de4443938ae2dbafe2b9"));
tx = tal(tmpctx, struct bitcoin_tx);
tx = bitcoin_tx_from_hex(tmpctx, "0200000001ce636f4eb66fe1bbbe43a11681d0b81a487675ff75f14e715722862594191d7200000000000000000001470f01000000000022002093f19f3548788064102caddb3c496e94635cf35e0d43edc1eea5c7739462d04600000000",
strlen("0200000001ce636f4eb66fe1bbbe43a11681d0b81a487675ff75f14e715722862594191d7200000000000000000001470f01000000000022002093f19f3548788064102caddb3c496e94635cf35e0d43edc1eea5c7739462d04600000000"));


tx->input[0].amount = tal(tmpctx, u64);
*tx->input[0].amount = 70150;

der = tal_hexdata(tmpctx, "304402206758f025f30bfd6f11fa44dbb8ae132ad9c7c89ca172b743d99bcbbcc703a75302200cadb8f7c52522d23344ce1bf4c285a983c717b52bc89b58a94130184058d434",
strlen("304402206758f025f30bfd6f11fa44dbb8ae132ad9c7c89ca172b743d99bcbbcc703a75302200cadb8f7c52522d23344ce1bf4c285a983c717b52bc89b58a94130184058d434"));

if (!signature_from_der(der, tal_count(der), &sig))
abort();

wscript = tal_hexdata(tmpctx, "76a914a8c40c334351dbe8e5908544f1c98fbcfb8719fc8763ac6721038ffd2621647812011960152bfb79c5a2787dfe6c4f37e2222547de054432eb7f7c820120876475527c2103cf8e2f193a6aed60db80af75f3c8d59c2de735b299b7c7083527be9bd23b77a852ae67a914b8bcd51efa35be1e50ae2d5f72f4500acb005c9c88ac6868", strlen("76a914a8c40c334351dbe8e5908544f1c98fbcfb8719fc8763ac6721038ffd2621647812011960152bfb79c5a2787dfe6c4f37e2222547de054432eb7f7c820120876475527c2103cf8e2f193a6aed60db80af75f3c8d59c2de735b299b7c7083527be9bd23b77a852ae67a914b8bcd51efa35be1e50ae2d5f72f4500acb005c9c88ac6868"));
if (!pubkey_from_hexstr("038ffd2621647812011960152bfb79c5a2787dfe6c4f37e2222547de054432eb7f",
strlen("038ffd2621647812011960152bfb79c5a2787dfe6c4f37e2222547de054432eb7f"),
&htlc_key))
abort();
wscript = tal_hexdata(tmpctx, "76a9142a85f084bb57555fd20c30dbfb96106fa9b972838763ac67210232974d5858c34a8a69c7b708857a72717daca1bcc312904b5a3ef5304ea5ca8f7c8201208763a9148ddc0fc0ec8c58afab6bb7475f84be60e8e754d488527c21036879c3877d39229bf960b60a11c73560aa8dbd2439b8560c08964385bac79a1352ae6775020a01b175ac6868",strlen("76a9142a85f084bb57555fd20c30dbfb96106fa9b972838763ac67210232974d5858c34a8a69c7b708857a72717daca1bcc312904b5a3ef5304ea5ca8f7c8201208763a9148ddc0fc0ec8c58afab6bb7475f84be60e8e754d488527c21036879c3877d39229bf960b60a11c73560aa8dbd2439b8560c08964385bac79a1352ae6775020a01b175ac6868"));

if (!pubkey_from_hexstr("0232974d5858c34a8a69c7b708857a72717daca1bcc312904b5a3ef5304ea5ca8f",
strlen("0232974d5858c34a8a69c7b708857a72717daca1bcc312904b5a3ef5304ea5ca8f"),
&htlc_key))
abort();
/* Dance around a little because keyset is const */
keys = tal(tmpctx, struct keyset);
keys->other_htlc_key = htlc_key;
keyset = keys;


if (argc > 1)
iterations = atoi(argv[1]);
max_possible_feerate = 250000;
max_possible_feerate = 2000;
min_possible_feerate = max_possible_feerate + 1 - iterations;

start = time_now();

fee = grind_htlc_tx_fee(tx, &sig, wscript, 663);
end = time_now();
assert(fee == 165750);

assert(fee == 703);
printf("%u iterations in %"PRIu64" msec = %"PRIu64" nsec each\n",
iterations,
time_to_msec(time_between(end, start)),
time_to_nsec(time_divide(time_between(end, start), iterations)));
iterations,
time_to_msec(time_between(end, start)),
time_to_nsec(time_divide(time_between(end, start), iterations)));

tal_free(tmpctx);
secp256k1_context_destroy(secp256k1_ctx);
Expand Down
Loading

0 comments on commit 55d1d6e

Please sign in to comment.