Merge pull request #1091 from urbit/dawn-take-error

adds more rudimentary error handle to pre-boot validation
This commit is contained in:
Joe Bryan 2018-12-07 14:28:11 -05:00 committed by GitHub
commit e3f2519055
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -164,6 +164,24 @@ _dawn_fail(u3_noun who, u3_noun rac, u3_noun sas)
u3_lo_bail();
}
/* _dawn_need_unit(): produce a value or print error and exit
*/
static u3_noun
_dawn_need_unit(u3_noun nit, c3_c* msg_c)
{
if ( u3_nul == nit ) {
fprintf(stderr, "%s\r\n", msg_c);
// bails, won't return
u3_lo_bail();
return u3_none;
}
else {
u3_noun pro = u3k(u3t(nit));
u3z(nit);
return pro;
}
}
/* _dawn_purl(): ethereum gateway url as (unit purl)
*/
static u3_noun
@ -269,15 +287,19 @@ u3_dawn_vent(u3_noun seed)
//
if ( c3y == u3_Host.ops_u.etn ) {
fprintf(stderr, "boot: extracting block from snapshot\r\n");
bok = u3do("bloq:snap:dawn", u3k(u3t(sap)));
bok = _dawn_need_unit(u3do("bloq:snap:dawn", u3k(u3t(sap))),
"boot: failed to extract "
"block from snapshot");
}
else {
fprintf(stderr, "boot: retrieving latest block\r\n");
u3_noun oct = u3v_wish("bloq:give:dawn");
u3_noun kob = _dawn_eth_rpc(url_c, u3k(oct));
bok = u3do("bloq:take:dawn", u3k(kob));
bok = _dawn_need_unit(u3do("bloq:take:dawn", u3k(kob)),
"boot: block retrieval failed");
u3z(oct); u3z(kob);
}
@ -287,7 +309,11 @@ u3_dawn_vent(u3_noun seed)
u3_noun hul;
if ( c3y == u3_Host.ops_u.etn ) {
hul = u3dc("hull:snap:dawn", u3k(ship), u3k(u3t(sap)));
fprintf(stderr, "boot: extracting public keys from snapshot\r\n");
hul = _dawn_need_unit(u3dc("hull:snap:dawn", u3k(ship), u3k(u3t(sap))),
"boot: failed to extract "
"public keys from snapshot");
}
else if ( c3__pawn == rank ) {
// irrelevant, just bunt +hull
@ -295,32 +321,39 @@ u3_dawn_vent(u3_noun seed)
hul = u3v_wish("*hull:constitution:ethe");
}
else {
u3_noun oct;
u3_noun who;
if ( c3__earl == rank ) {
u3_noun seg = u3do("^sein:title", u3k(ship));
u3_noun ges = u3dc("scot", 'p', u3k(seg));
c3_c* seg_c = u3r_string(ges);
who = u3do("^sein:title", u3k(ship));
{
u3_noun seg = u3dc("scot", 'p', u3k(who));
c3_c* seg_c = u3r_string(seg);
fprintf(stderr, "boot: retrieving %s's public keys (for %s)\r\n",
seg_c, u3_Host.ops_u.who_c);
oct = u3dc("hull:give:dawn", u3k(bok), u3k(seg));
free(seg_c);
u3z(seg); u3z(ges);
u3z(seg);
}
}
else {
who = u3k(ship);
fprintf(stderr, "boot: retrieving %s's public keys\r\n",
u3_Host.ops_u.who_c);
oct = u3dc("hull:give:dawn", u3k(bok), u3k(ship));
}
{
u3_noun oct = u3dc("hull:give:dawn", u3k(bok), u3k(who));
u3_noun luh = _dawn_eth_rpc(url_c, u3k(oct));
hul = u3dc("hull:take:dawn", u3k(ship), u3k(luh));
hul = _dawn_need_unit(u3dc("hull:take:dawn", u3k(ship), u3k(luh)),
"boot: failed to retrieve public keys");
u3z(oct); u3z(luh);
}
u3z(who);
}
// +live:dawn: network state
// XX actually make request
//
@ -351,15 +384,20 @@ u3_dawn_vent(u3_noun seed)
// (map ship [=life =pass]): galaxy table
//
if ( c3y == u3_Host.ops_u.etn ) {
zar = u3do("czar:snap:dawn", u3k(u3t(sap)));
fprintf(stderr, "boot: extracting galaxy table from snapshot\r\n");
zar = _dawn_need_unit(u3do("czar:snap:dawn", u3k(u3t(sap))),
"boot: failed to extract "
"galaxy table from snapshot");
}
else {
fprintf(stderr, "boot: retrieving galaxy table\r\n");
u3_noun oct = u3do("czar:give:dawn", u3k(bok));
u3_noun raz = _dawn_eth_rpc(url_c, u3k(oct));
zar = u3do("czar:take:dawn", u3k(raz));
zar = _dawn_need_unit(u3do("czar:take:dawn", u3k(raz)),
"boot: failed to retrieve galaxy table");
u3z(oct); u3z(raz);
}
@ -369,15 +407,20 @@ u3_dawn_vent(u3_noun seed)
tuf = _dawn_turf(u3_Host.ops_u.dns_c);
}
else if ( c3y == u3_Host.ops_u.etn ) {
tuf = u3do("turf:snap:dawn", u3k(u3t(sap)));
fprintf(stderr, "boot: extracting network domains from snapshot\r\n");
tuf = _dawn_need_unit(u3do("turf:snap:dawn", u3k(u3t(sap))),
"boot: failed to extract "
"network domains from snapshot");
}
else {
fprintf(stderr, "boot: retrieving network domains\r\n");
u3_noun oct = u3do("turf:give:dawn", u3k(bok));
u3_noun fut = _dawn_eth_rpc(url_c, u3k(oct));
tuf = u3do("turf:take:dawn", u3k(fut));
tuf = _dawn_need_unit(u3do("turf:take:dawn", u3k(fut)),
"boot: failed to retrieve network domains");
u3z(oct); u3z(fut);
}