From f3e60b800ac9e5b5a1b44dbe70f77a0111e3cd31 Mon Sep 17 00:00:00 2001 From: Fang Date: Mon, 17 Dec 2018 13:20:49 +0100 Subject: [PATCH 1/7] Rename hull to point in Ethereum boot logic --- vere/dawn.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vere/dawn.c b/vere/dawn.c index 2611b28d4a..d4b66e67a1 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -299,21 +299,21 @@ u3_dawn_vent(u3_noun seed) } { - // +hull:constitution:ethe: on-chain state + // +point:constitution:ethe: on-chain state // u3_noun hul; if ( c3y == u3_Host.ops_u.etn ) { fprintf(stderr, "boot: extracting public keys from snapshot\r\n"); - hul = _dawn_need_unit(u3dc("hull:snap:dawn", u3k(ship), u3k(u3t(sap))), + hul = _dawn_need_unit(u3dc("point:snap:dawn", u3k(ship), u3k(u3t(sap))), "boot: failed to extract " "public keys from snapshot"); } else if ( c3__pawn == rank ) { - // irrelevant, just bunt +hull + // irrelevant, just bunt +point // - hul = u3v_wish("*hull:constitution:ethe"); + hul = u3v_wish("*point:constitution:ethe"); } else { u3_noun who; @@ -338,10 +338,10 @@ u3_dawn_vent(u3_noun seed) } { - u3_noun oct = u3dc("hull:give:dawn", u3k(bok), u3k(who)); + u3_noun oct = u3dc("point:give:dawn", u3k(bok), u3k(who)); u3_noun luh = _dawn_eth_rpc(url_c, u3k(oct)); - hul = _dawn_need_unit(u3dc("hull:take:dawn", u3k(ship), u3k(luh)), + hul = _dawn_need_unit(u3dc("point:take:dawn", u3k(ship), u3k(luh)), "boot: failed to retrieve public keys"); u3z(oct); u3z(luh); } @@ -368,7 +368,7 @@ u3_dawn_vent(u3_noun seed) } // (unit ship): sponsor - // produced by +veri:dawn to avoid coupling to +hull structure + // produced by +veri:dawn to avoid coupling to +point structure // XX reconsider // pon = u3k(u3t(sas)); From 61b95566122925e89ffe69e0f2985c21d1354e08 Mon Sep 17 00:00:00 2001 From: Isaac Visintainer Date: Mon, 17 Dec 2018 16:59:24 -0800 Subject: [PATCH 2/7] fix _raft_lame bug --- vere/raft.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vere/raft.c b/vere/raft.c index ee8dade84e..8c12b1ac64 100644 --- a/vere/raft.c +++ b/vere/raft.c @@ -1481,7 +1481,7 @@ _raft_sure(u3_noun ovo, u3_noun vir, u3_noun cor) /* _raft_lame(): handle an application failure. */ -static u3_noun +static u3_weak _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) { u3_noun bov, gon; @@ -1548,7 +1548,7 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) uL(fprintf(uH, "crude: punted\n")); // c3_assert(!"crud"); - return u3_nul; + return u3_none; } } } @@ -1556,7 +1556,7 @@ _raft_lame(u3_noun ovo, u3_noun why, u3_noun tan) /* _raft_punk(): insert and apply an input ovum (unprotected). */ -static u3_noun +static u3_weak _raft_punk(u3_noun ovo) { #ifdef U3_EVENT_TIME_DEBUG From e53b0497a2fbdf80e363c7f6b51457028828c5f3 Mon Sep 17 00:00:00 2001 From: Fang Date: Tue, 18 Dec 2018 10:47:27 +0100 Subject: [PATCH 3/7] Rename hul to pot, to match renaming of hull to point --- vere/dawn.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/vere/dawn.c b/vere/dawn.c index d4b66e67a1..cdbfc47210 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -301,19 +301,19 @@ u3_dawn_vent(u3_noun seed) { // +point:constitution:ethe: on-chain state // - u3_noun hul; + u3_noun pot; if ( c3y == u3_Host.ops_u.etn ) { fprintf(stderr, "boot: extracting public keys from snapshot\r\n"); - hul = _dawn_need_unit(u3dc("point:snap:dawn", u3k(ship), u3k(u3t(sap))), + pot = _dawn_need_unit(u3dc("point:snap:dawn", u3k(ship), u3k(u3t(sap))), "boot: failed to extract " "public keys from snapshot"); } else if ( c3__pawn == rank ) { // irrelevant, just bunt +point // - hul = u3v_wish("*point:constitution:ethe"); + pot = u3v_wish("*point:constitution:ethe"); } else { u3_noun who; @@ -341,7 +341,7 @@ u3_dawn_vent(u3_noun seed) u3_noun oct = u3dc("point:give:dawn", u3k(bok), u3k(who)); u3_noun luh = _dawn_eth_rpc(url_c, u3k(oct)); - hul = _dawn_need_unit(u3dc("point:take:dawn", u3k(ship), u3k(luh)), + pot = _dawn_need_unit(u3dc("point:take:dawn", u3k(ship), u3k(luh)), "boot: failed to retrieve public keys"); u3z(oct); u3z(luh); } @@ -359,7 +359,7 @@ u3_dawn_vent(u3_noun seed) // (each sponsor=(unit ship) error=@tas) // - u3_noun sas = u3dt("veri:dawn", u3k(seed), u3k(hul), u3k(liv)); + u3_noun sas = u3dt("veri:dawn", u3k(seed), u3k(pot), u3k(liv)); if ( c3n == u3h(sas) ) { // bails, won't return @@ -373,7 +373,7 @@ u3_dawn_vent(u3_noun seed) // pon = u3k(u3t(sas)); - u3z(hul); u3z(liv); u3z(sas); + u3z(pot); u3z(liv); u3z(sas); } // (map ship [=life =pass]): galaxy table From a09e2b78184777eb19f8782e76caa6c4bc2e92b5 Mon Sep 17 00:00:00 2001 From: Fang Date: Fri, 21 Dec 2018 18:00:48 +0100 Subject: [PATCH 4/7] Update comments in dawn to reflect changes in urbit/arvo#958 --- vere/dawn.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vere/dawn.c b/vere/dawn.c index cdbfc47210..0da25c0715 100644 --- a/vere/dawn.c +++ b/vere/dawn.c @@ -357,7 +357,7 @@ u3_dawn_vent(u3_noun seed) fprintf(stderr, "boot: verifying keys\r\n"); - // (each sponsor=(unit ship) error=@tas) + // (each sponsor=ship error=@tas) // u3_noun sas = u3dt("veri:dawn", u3k(seed), u3k(pot), u3k(liv)); @@ -367,7 +367,7 @@ u3_dawn_vent(u3_noun seed) return u3_none; } - // (unit ship): sponsor + // ship: sponsor // produced by +veri:dawn to avoid coupling to +point structure // XX reconsider // From c7d2256e03009a54a0177af2a3cb230f9252650f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Thu, 27 Dec 2018 17:22:46 -0800 Subject: [PATCH 5/7] Use c3_fpurge --- vere/sist.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vere/sist.c b/vere/sist.c index cbfa17f322..55d2e09e41 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -13,8 +13,6 @@ #include "vere/vere.h" #if defined(U3_OS_linux) -#include -#define fpurge(fd) __fpurge(fd) #define DEVRANDOM "/dev/urandom" #else #define DEVRANDOM "/dev/random" @@ -361,7 +359,7 @@ _sist_text(c3_c* pom_c) printf("%s: ", pom_c); paw_c[0] = 0; - fpurge(stdin); + c3_fpurge(stdin); fgets(paw_c, 179, stdin); if ( '\n' == paw_c[0] ) { From fbd5d4e2adaeccbce417ef528597c9869503774b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Thu, 27 Dec 2018 17:22:50 -0800 Subject: [PATCH 6/7] Capture errors within uH / uL --- vere/sist.c | 75 ++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/vere/sist.c b/vere/sist.c index 55d2e09e41..755c34c3a3 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -40,18 +40,15 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w) lar_u.len_w = len_w; if ( -1 == lseek64(lug_u->fid_i, 4ULL * tar_d, SEEK_SET) ) { - perror("lseek"); - uL(fprintf(uH, "sist_pack: seek failed\n")); + uL(fprintf(uH, "sist_pack: seek failed, lseek: %s\n", strerror(errno))); c3_assert(0); } if ( sizeof(lar_u) != write(lug_u->fid_i, &lar_u, sizeof(lar_u)) ) { - perror("write"); - uL(fprintf(uH, "sist_pack: write failed\n")); + uL(fprintf(uH, "sist_pack: write failed, write: %s\n", strerror(errno))); c3_assert(0); } if ( -1 == lseek64(lug_u->fid_i, 4ULL * lug_u->len_d, SEEK_SET) ) { - perror("lseek"); - uL(fprintf(uH, "sist_pack: seek failed\n")); + uL(fprintf(uH, "sist_pack: seek failed, lseek: %s\n", strerror(errno))); c3_assert(0); } #if 0 @@ -63,8 +60,7 @@ u3_sist_pack(c3_w tem_w, c3_w typ_w, c3_w* bob_w, c3_w len_w) lar_u.mug_w)); #endif if ( (4 * len_w) != write(lug_u->fid_i, bob_w, (4 * len_w)) ) { - perror("write"); - uL(fprintf(uH, "sist_pack: write failed\n")); + uL(fprintf(uH, "sist_pack: write failed, write: %s\n", strerror(errno))); c3_assert(0); } lug_u->len_d += (c3_d)(lar_u.len_w + c3_wiseof(lar_u)); @@ -100,20 +96,19 @@ u3_sist_put(const c3_c* key_c, const c3_y* val_y, size_t siz_i) c3_assert(ret_i < 2048); if ( (fid_i = open(ful_c, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0 ) { - uL(fprintf(uH, "sist: could not put %s\n", key_c)); - perror("open"); + uL(fprintf(uH, "sist: could not put %s: %s\n", key_c, strerror(errno))); u3_lo_bail(); } if ( (ret_i = write(fid_i, val_y, siz_i)) != siz_i ) { uL(fprintf(uH, "sist: could not write %s\n", key_c)); if ( ret_i < 0 ) { - perror("write"); + uL(fprintf(uH, "write: %s\n", strerror(errno))); } u3_lo_bail(); } ret_i = c3_sync(fid_i); if ( ret_i < 0 ) { - perror("sync"); + uL(fprintf(uH, "sync: %s\n", strerror(errno))); } ret_i = close(fid_i); c3_assert(0 == ret_i); @@ -136,8 +131,7 @@ u3_sist_has(const c3_c* key_c) return -1; } else { - uL(fprintf(uH, "sist: could not stat %s\n", key_c)); - perror("stat"); + uL(fprintf(uH, "sist: could not stat %s: %s\n", key_c, strerror(errno))); u3_lo_bail(); } } @@ -161,19 +155,17 @@ u3_sist_get(const c3_c* key_c, c3_y* val_y) c3_assert(ret_i < 2048); if ( (fid_i = open(ful_c, O_RDONLY)) < 0 ) { - uL(fprintf(uH, "sist: could not get %s\n", key_c)); - perror("open"); + uL(fprintf(uH, "sist: could not get %s: %s\n", key_c, strerror(errno))); u3_lo_bail(); } if ( (ret_i = fstat(fid_i, &sat_u)) < 0 ) { - uL(fprintf(uH, "sist: could not stat %s\n", key_c)); - perror("fstat"); + uL(fprintf(uH, "sist: could not stat %s: %s\n", key_c, strerror(errno))); u3_lo_bail(); } if ( (ret_i = read(fid_i, val_y, sat_u.st_size)) != sat_u.st_size ) { uL(fprintf(uH, "sist: could not read %s\n", key_c)); if ( ret_i < 0 ) { - perror("read"); + uL(fprintf(uH, "read: %s\n", strerror(errno))); } u3_lo_bail(); } @@ -197,8 +189,8 @@ u3_sist_nil(const c3_c* key_c) return; } else { - uL(fprintf(uH, "sist: could not unlink %s\n", key_c)); - perror("unlink"); + uL(fprintf(uH, "sist: could not unlink %s: %s\n", key_c, + strerror(errno))); u3_lo_bail(); } } @@ -620,8 +612,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) c3_assert(led_u.mag_l == u3r_mug('f')); if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - uL(fprintf(uH, "rest_nuu failed (a)\n")); - perror("lseek64"); + uL(fprintf(uH, "rest_nuu failed (a), lseek64: %s\n", strerror(errno))); u3_lo_bail(); } @@ -634,13 +625,11 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) tar_d = (end_d - (c3_d)c3_wiseof(u3_olar)); if ( -1 == lseek64(fid_i, 4ULL * tar_d, SEEK_SET) ) { - uL(fprintf(uH, "rest_nuu failed (b)\n")); - perror("lseek64"); + uL(fprintf(uH, "rest_nuu failed (b), lseek64: %s\n", strerror(errno))); u3_lo_bail(); } if ( sizeof(u3_olar) != read(fid_i, &lar_u, sizeof(u3_olar)) ) { - uL(fprintf(uH, "rest_nuu failed (c)\n")); - perror("read"); + uL(fprintf(uH, "rest_nuu failed (c), read: %s\n", strerror(errno))); u3_lo_bail(); } @@ -653,13 +642,11 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) end_d = (tar_d - (c3_d)lar_u.len_w); if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - uL(fprintf(uH, "rest_nuu failed (e)\n")); - perror("lseek64"); + uL(fprintf(uH, "rest_nuu failed (e), lseek64: %s\n", strerror(errno))); u3_lo_bail(); } if ( (4 * lar_u.len_w) != read(fid_i, img_w, (4 * lar_u.len_w)) ) { - uL(fprintf(uH, "rest_nuu failed (f)\n")); - perror("read"); + uL(fprintf(uH, "rest_nuu failed (f), read: %s\n", strerror(errno))); u3_lo_bail(); } @@ -675,8 +662,7 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) } if ( 0 != close(fid_i) ) { - uL(fprintf(uH, "rest: could not close\n")); - perror("close"); + uL(fprintf(uH, "rest: could not close, close: %s\n", strerror(errno))); u3_lo_bail(); } @@ -684,15 +670,14 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) c3_assert(ret_i < 2048); if ( (fud_i = open(nuu_c, O_CREAT | O_TRUNC | O_RDWR, 0600)) < 0 ) { - uL(fprintf(uH, "rest: can't open record (%s)\n", nuu_c)); - perror("open"); + uL(fprintf(uH, "rest: can't open record (%s), open: %s\n", nuu_c, + strerror(errno))); u3_lo_bail(); } led_u.mag_l = u3r_mug('g'); if ( (sizeof(led_u) != write(fud_i, &led_u, sizeof(led_u))) ) { - uL(fprintf(uH, "rest: can't write header\n")); - perror("write"); + uL(fprintf(uH, "rest: can't write header, write: %s\n", strerror(errno))); u3_lo_bail(); } @@ -722,13 +707,11 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) u3z(ovo); if ( (lar_u.len_w << 2) != write(fud_i, img_w, lar_u.len_w << 2) ) { - uL(fprintf(uH, "rest_nuu failed (h)\n")); - perror("write"); + uL(fprintf(uH, "rest_nuu failed (h), write: %s\n", strerror(errno))); u3_lo_bail(); } if ( sizeof(u3_ular) != write(fud_i, &lar_u, sizeof(u3_ular)) ) { - uL(fprintf(uH, "rest_nuu failed (i)\n")); - perror("write"); + uL(fprintf(uH, "rest_nuu failed (i), write: %s\n", strerror(errno))); u3_lo_bail(); } @@ -738,13 +721,11 @@ _sist_rest_nuu(u3_ulog* lug_u, u3_uled led_u, c3_c* old_c) } } if ( 0 != rename(nuu_c, old_c) ) { - uL(fprintf(uH, "rest_nuu failed (k)\n")); - perror("rename"); + uL(fprintf(uH, "rest_nuu failed (k), rename: %s\n", strerror(errno))); u3_lo_bail(); } if ( -1 == lseek64(fud_i, sizeof(u3_uled), SEEK_SET) ) { - uL(fprintf(uH, "rest_nuu failed (l)\n")); - perror("lseek64"); + uL(fprintf(uH, "rest_nuu failed (l), lseek64: %s\n", strerror(errno))); u3_lo_bail(); } lug_u->fid_i = fud_i; @@ -880,8 +861,8 @@ _sist_rest() ent_d = 0; if ( -1 == lseek64(fid_i, 4ULL * end_d, SEEK_SET) ) { - fprintf(stderr, "end_d %" PRIu64 "\n", end_d); - perror("lseek"); + uL(fprintf(uH, "end_d %" PRIu64 ", lseek64: %s\n", end_d, + strerror(errno))); uL(fprintf(uH, "record (%s) is corrupt (c)\n", ful_c)); u3_lo_bail(); } From ceba869a91cb4e95d116679b964759f163373556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Thu, 27 Dec 2018 17:22:52 -0800 Subject: [PATCH 7/7] Eliminate extra c3_rand call --- vere/sist.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/vere/sist.c b/vere/sist.c index 755c34c3a3..6a9c57cebe 100644 --- a/vere/sist.c +++ b/vere/sist.c @@ -542,23 +542,15 @@ _sist_zest() u3Z->lug_u.fid_i = fid_i; } - // Generate a 31-bit salt. + // Generate a 31-bit salt and 64-bit passcode. // { - c3_w rad_w[16]; + u3_noun pas; + c3_w rad_w[16]; c3_rand(rad_w); sal_l = (0x7fffffff & rad_w[0]); - } - - // Create and save a passcode. - // - { - c3_w rad_w[16]; - u3_noun pas; - - c3_rand(rad_w); - pas = u3i_words(2, rad_w); + pas = u3i_words(2, rad_w + 1); u3A->key = _sist_fatt(sal_l, u3k(pas)); _sist_fast(pas, u3r_mug(u3A->key));