Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
nucleo
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blockchain
nucleo
Commits
ac1cbdee
Commit
ac1cbdee
authored
3 years ago
by
Robert Martin-Legene
Browse files
Options
Downloads
Patches
Plain Diff
Importdb
parent
a30719bd
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/bfa
+39
-24
39 additions, 24 deletions
bin/bfa
with
39 additions
and
24 deletions
bin/bfa
+
39
−
24
View file @
ac1cbdee
...
@@ -139,7 +139,7 @@ function graceful
...
@@ -139,7 +139,7 @@ function graceful
if
[
-z
"
$pids
"
]
if
[
-z
"
$pids
"
]
then
then
echo
"Nothing to send signals to."
>
&2
echo
"Nothing to send signals to."
>
&2
exit
1
return
fi
fi
sendsig
-TERM
"
$pids
"
sendsig
-TERM
"
$pids
"
sleep
1
sleep
1
...
@@ -170,15 +170,15 @@ function initdb
...
@@ -170,15 +170,15 @@ function initdb
register_subcommand
'exportdb'
'exportdb'
'Export blockchain in chunks of 1 million blocks per file.'
register_subcommand
'exportdb'
'exportdb'
'Export blockchain in chunks of 1 million blocks per file.'
function
exportdb
function
exportdb
{
{
local
delta
maxblocks blockstart toblock filename
local
million
maxblocks blockstart toblock filename
delta
=
1000000
million
=
1000000
graceful
graceful
maxblocks
=
$(
bfageth
--exec
'eth.blockNumber'
console 2> /dev/null
)
maxblocks
=
$(
bfageth
--exec
'eth.blockNumber'
console 2> /dev/null
)
# 0 is genesis.. shouldn't dump that
# 0 is genesis.. shouldn't dump that
blockstart
=
1
blockstart
=
1
while
[
"
$blockstart
"
-lt
"
$maxblocks
"
]
while
[
"
$blockstart
"
-lt
"
$maxblocks
"
]
do
do
toblock
=
$((
blockstart
+
delta
-
1
))
toblock
=
$((
blockstart
+
million
-
1
))
test
"
$toblock
"
-gt
"
$maxblocks
"
&&
test
"
$toblock
"
-gt
"
$maxblocks
"
&&
toblock
=
$maxblocks
toblock
=
$maxblocks
printf
-v
filename
'bfa2018.blocks.%09d-%09d.export.gz'
"
$blockstart
"
"
$toblock
"
printf
-v
filename
'bfa2018.blocks.%09d-%09d.export.gz'
"
$blockstart
"
"
$toblock
"
...
@@ -194,28 +194,43 @@ function exportdb
...
@@ -194,28 +194,43 @@ function exportdb
register_subcommand
'importdb'
'importdb'
'Import blocks safely from previous block exports.'
register_subcommand
'importdb'
'importdb'
'Import blocks safely from previous block exports.'
function
importdb
function
importdb
{
{
local
dumpurl
delta
blockstart
toblock
local
dumpurl
million
blockstart
continue_at haveblocks theirsize oursize
dumpurl
=
"https://s3.wasabisys.com/bfa/blockdumps"
dumpurl
=
"https://s3.wasabisys.com/bfa/blockdumps"
delta
=
1000000
million
=
1000000
graceful
graceful
blockstart
=
1
haveblocks
=
$(
bfageth
--exec
'eth.blockNumber'
console 2> /dev/null
)
blockstart
=
$((
haveblocks/million
*
million+1
))
while
:
while
:
do
do
toblock
=
$((
blockstart
+
delta
-
1
))
printf
-v
filename
'bfa2018.blocks.%09d-%09d.export.gz'
"
$blockstart
"
"
$((
blockstart
+
million
-
1
))
"
printf
-v
filename
'bfa2018.blocks.%09d-%09d.export.gz'
"
$blockstart
"
"
$toblock
"
blockstart
=
$((
blockstart
+
million
))
curl
--fail
"
${
dumpurl
}
/
${
filename
}
"
||
break
read
-r
theirsize < <
(
curl
--head
"
${
dumpurl
}
/
${
filename
}
"
2>/dev/null |
grep
-i
'^Content-Length: '
|
head
-1
)
blockstart
=
$((
toblock
+
1
))
if
[
-z
"
$theirsize
"
]
then
break
else
theirsize
=
"
${
theirsize
//*
:
}
"
# remove trailing newline
theirsize
=
"
${
theirsize
%
$'
\r
'
}
"
fi
#
if
[
-r
"
$filename
"
]
then
oursize
=
$(
stat
-c
%s
"
$filename
"
)
continue_at
=
"--continue-at
$oursize
"
else
oursize
=
0
continue_at
=
fi
if
[
"
${
oursize
:-
0
}
"
-lt
"
$theirsize
"
]
then
echo
"Downloading
$filename
"
curl
--fail
$continue_at
-o
"
$filename
"
"
${
dumpurl
}
/
${
filename
}
"
||
break
fi
# shellcheck disable=SC2086
bfageth import <
(
gzip
-dc
"
$filename
"
)
rm
-f
"
$filename
"
done
done
geth
--networkid
"
${
BFANETWORKID
}
"
--datadir
"
${
BFANODEDIR
}
"
--syncmode
"full"
--gcmode
"archive"
import <
(
n
=
1
printf
-v
filename
'bfa2018.blocks.%09d-%09d.export.gz'
"
$n
"
"
$((
n
+
delta
-
1
))
"
while
gzip
-dc
"
$filename
"
2>/dev/null
do
n
=
$((
n
+
delta
))
printf
-v
filename
'bfa2018.blocks.%09d-%09d.export.gz'
"
$n
"
"
$((
n
+
delta
-
1
))
"
done
true
)
}
}
register_subcommand
'syncmode'
'admin_syncmode'
'Set initial synchronization mode.'
register_subcommand
'syncmode'
'admin_syncmode'
'Set initial synchronization mode.'
...
@@ -381,7 +396,7 @@ function bfageth
...
@@ -381,7 +396,7 @@ function bfageth
echo
"You should not run this command without any arguments. Start the background processes with start.sh instead."
>
&2
echo
"You should not run this command without any arguments. Start the background processes with start.sh instead."
>
&2
exit
1
exit
1
fi
fi
exec
geth
--config
"
${
BFANETWORKDIR
}
/config.localhost+full+archive"
"
$@
"
geth
--config
"
${
BFANETWORKDIR
}
/config.localhost+full+archive"
"
$@
"
}
}
function
bfaadmin
function
bfaadmin
...
@@ -427,7 +442,7 @@ function main
...
@@ -427,7 +442,7 @@ function main
test
-n
"
$cmd
"
||
_usage
test
-n
"
$cmd
"
||
_usage
test
-n
"
${
commands
[
$cmd
]
}
"
||
_usage
test
-n
"
${
commands
[
$cmd
]
}
"
||
_usage
# shellcheck disable=SC2086
# shellcheck disable=SC2086
eval
${
commands
[
$cmd
]
}
"
$
*
"
eval
${
commands
[
$cmd
]
}
"
$
@
"
;;
;;
'admin.sh'
)
'admin.sh'
)
bfaadmin
"
$@
"
bfaadmin
"
$@
"
...
@@ -441,4 +456,4 @@ function main
...
@@ -441,4 +456,4 @@ function main
esac
esac
}
}
main
"
$
*
"
main
"
$
@
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment