Merge pull request #1130 from urbit/snapdown

Download ethereum snapshot from URL
This commit is contained in:
Ted Blackman 2019-01-11 08:27:16 -08:00 committed by GitHub
commit 7be1073007
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 100 additions and 3 deletions

View File

@ -581,6 +581,7 @@
c3_o abo; // -a, abort aggressively
c3_c* pil_c; // -B, bootstrap from
c3_o bat; // -b, batch create
c3_o can; // -C, chain-only, no eth snapshot
c3_o nuu; // -c, new pier
c3_o dry; // -D, dry compute, no checkpoint
c3_o dem; // -d, daemon
@ -596,6 +597,7 @@
c3_c* key_c; // -k, private key file
c3_o net; // -L, local-only networking
c3_s rop_s; // -l, raft port
c3_c* sap_c; // -m, eth snapshot url
c3_c* nam_c; // -n, unix hostname
c3_o pro; // -P, profile
c3_s por_s; // -p, ames port

View File

@ -259,14 +259,66 @@ u3_dawn_vent(u3_noun seed)
u3_noun ship = u3h(seed);
u3_noun rank = u3do("clan:title", u3k(ship));
// load snapshot if exists
// load snapshot from file
//
if ( 0 != u3_Host.ops_u.ets_c ) {
fprintf(stderr, "boot: loading ethereum snapshot\r\n");
u3_noun raw_snap = u3ke_cue(u3m_file(u3_Host.ops_u.ets_c));
sap = u3nc(u3_nul, raw_snap);
}
// load snapshot from HTTP URL
//
// note: some duplicate code with _boot_home() in noun/manage.c
//
else if ( 0 != u3_Host.ops_u.sap_c ) {
c3_c ful_c[2048];
CURL *curl;
CURLcode result;
FILE *file;
long cod_l;
snprintf(ful_c, 2048, "%s/.urb/ethereum.snap", u3_Host.dir_c);
printf("dawn: downloading ethereum snapshot: fetching %s to %s\r\n",
u3_Host.ops_u.sap_c, ful_c);
fflush(stdout);
if ( !(curl = curl_easy_init()) ) {
fprintf(stderr, "failed to initialize libcurl\n");
fflush(stderr);
exit(1);
}
if ( !(file = fopen(ful_c, "w")) ) {
fprintf(stderr, "failed to open %s\n", ful_c);
fflush(stderr);
exit(1);
}
curl_easy_setopt(curl, CURLOPT_URL, u3_Host.ops_u.sap_c);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, file);
result = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &cod_l);
fclose(file);
if ( CURLE_OK != result ) {
fprintf(stderr, "failed to fetch %s: %s\n",
u3_Host.ops_u.sap_c, curl_easy_strerror(result));
fprintf(stderr,
"please fetch it manually and specify the location with -E\n");
exit(1);
}
if ( 300 <= cod_l ) {
fprintf(stderr, "error fetching %s: HTTP %ld\n", u3_Host.ops_u.sap_c, cod_l);
fprintf(stderr,
"please fetch it manually and specify the location with -E\n");
exit(1);
}
curl_easy_cleanup(curl);
u3_noun raw_snap = u3ke_cue(u3m_file(ful_c));
sap = u3nc(u3_nul, raw_snap);
}
// no snapshot
//
else {
printf("dawn: no ethereum snapshot specified\n");
sap = u3_nul;
}

View File

@ -75,6 +75,7 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.abo = c3n;
u3_Host.ops_u.bat = c3n;
u3_Host.ops_u.can = c3n;
u3_Host.ops_u.dem = c3n;
u3_Host.ops_u.dry = c3n;
u3_Host.ops_u.etn = c3n;
@ -97,7 +98,9 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.raf_c = 0;
u3_Host.ops_u.nam_c = 0;
while ( (ch_i=getopt(argc, argv,"G:B:K:A:H:w:u:j:e:E:f:F:k:p:LabcdgqstvxPDRS")) != -1 ) {
while ( -1 != (ch_i=getopt(argc, argv,
"G:B:K:A:H:w:u:j:e:E:f:F:k:m:p:LabcCdgqstvxPDRS")) ) {
switch ( ch_i ) {
case 'B': {
u3_Host.ops_u.pil_c = strdup(optarg);
@ -160,6 +163,10 @@ _main_getopt(c3_i argc, c3_c** argv)
u3_Host.ops_u.key_c = strdup(optarg);
break;
}
case 'm': {
u3_Host.ops_u.sap_c = strdup(optarg);
break;
}
case 'p': {
if ( c3n == _main_readw(optarg, 65536, &arg_w) ) {
return c3n;
@ -174,6 +181,7 @@ _main_getopt(c3_i argc, c3_c** argv)
case 'a': { u3_Host.ops_u.abo = c3y; break; }
case 'b': { u3_Host.ops_u.bat = c3y; break; }
case 'c': { u3_Host.ops_u.nuu = c3y; break; }
case 'C': { u3_Host.ops_u.can = c3y; break; }
case 'd': { u3_Host.ops_u.dem = c3y; break; }
case 'g': { u3_Host.ops_u.gab = c3y; break; }
case 'P': { u3_Host.ops_u.pro = c3y; break; }
@ -250,12 +258,47 @@ _main_getopt(c3_i argc, c3_c** argv)
if ( u3_Host.ops_u.nuu != c3y && u3_Host.ops_u.url_c != 0 ) {
fprintf(stderr, "-u only makes sense when bootstrapping a new instance\n");
return c3n;
}
if ( u3_Host.ops_u.nuu != c3y && u3_Host.ops_u.sap_c != 0 ) {
fprintf(stderr, "-m only makes sense when bootstrapping a new instance\n");
return c3n;
}
if ( u3_Host.ops_u.fak_c != 0 && u3_Host.ops_u.sap_c != 0 ) {
fprintf(stderr, "-m and -F cannot be used together\n");
return c3n;
}
if ( u3_Host.ops_u.ets_c != 0 && u3_Host.ops_u.sap_c != 0 ) {
fprintf(stderr, "-m and -E cannot be used together\n");
return c3n;
}
if ( u3_Host.ops_u.can == c3y && u3_Host.ops_u.sap_c != 0 ) {
fprintf(stderr, "-m and -C cannot be used together\n");
return c3n;
}
if ( u3_Host.ops_u.can == c3y && u3_Host.ops_u.ets_c != 0 ) {
fprintf(stderr, "-C and -E cannot be used together\n");
return c3n;
}
if ( u3_Host.ops_u.sap_c == 0 && u3_Host.ops_u.can == c3n ) {
u3_Host.ops_u.sap_c =
"https://bootstrap.urbit.org/urbit-" URBIT_VERSION ".snap";
}
if ( u3_Host.ops_u.url_c != 0 && u3_Host.ops_u.pil_c != 0 ) {
fprintf(stderr, "-B and -u cannot be used together\n");
return c3n;
} else if ( u3_Host.ops_u.nuu == c3y
&& u3_Host.ops_u.url_c == 0
&& u3_Host.ops_u.git == c3n ) {
u3_Host.ops_u.url_c = "https://bootstrap.urbit.org/urbit-" URBIT_VERSION ".pill";
u3_Host.ops_u.url_c =
"https://bootstrap.urbit.org/urbit-" URBIT_VERSION ".pill";
} else if ( u3_Host.ops_u.nuu == c3y
&& u3_Host.ops_u.url_c == 0