good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
c6881be2
Unverified
Commit
c6881be2
authored
Apr 3, 2020
by
Jaynti Kanani
Committed by
GitHub
Apr 3, 2020
Browse files
Options
Downloads
Plain Diff
Merge pull request #40 from maticnetwork/dev-import-state
MAT-872: Fix import/export state with bor
parents
a14bfacf
11bbf0df
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
cmd/bor/chaincmd.go
+6
-5
6 additions, 5 deletions
cmd/bor/chaincmd.go
cmd/utils/flags.go
+53
-3
53 additions, 3 deletions
cmd/utils/flags.go
eth/backend.go
+4
-0
4 additions, 0 deletions
eth/backend.go
with
63 additions
and
8 deletions
cmd/bor/chaincmd.go
+
6
−
5
View file @
c6881be2
...
...
@@ -61,7 +61,7 @@ It expects the genesis file as argument.`,
Action
:
utils
.
MigrateFlags
(
importChain
),
Name
:
"import"
,
Usage
:
"Import a blockchain file"
,
ArgsUsage
:
"<filename> (<filename 2> ... <filename N>) "
,
ArgsUsage
:
"<filename> (<filename 2> ... <filename N>)
<genesisPath>
"
,
Flags
:
[]
cli
.
Flag
{
utils
.
DataDirFlag
,
utils
.
CacheFlag
,
...
...
@@ -228,8 +228,8 @@ func initGenesis(ctx *cli.Context) error {
}
func
importChain
(
ctx
*
cli
.
Context
)
error
{
if
len
(
ctx
.
Args
())
<
1
{
utils
.
Fatalf
(
"This command requires a
n
argument."
)
if
len
(
ctx
.
Args
())
<
2
{
utils
.
Fatalf
(
"This command requires a
tleast 2
argument
s
."
)
}
stack
:=
makeFullNode
(
ctx
)
defer
stack
.
Close
()
...
...
@@ -255,12 +255,13 @@ func importChain(ctx *cli.Context) error {
// Import the chain
start
:=
time
.
Now
()
if
len
(
ctx
.
Args
())
==
1
{
// ArgsUsage: "<filename> (<filename 2> ... <filename N>) <genesisPath>",
if
len
(
ctx
.
Args
())
==
2
{
if
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
());
err
!=
nil
{
log
.
Error
(
"Import error"
,
"err"
,
err
)
}
}
else
{
for
_
,
arg
:=
range
ctx
.
Args
()
{
for
_
,
arg
:=
range
ctx
.
Args
()
[
:
len
(
ctx
.
Args
())
-
1
]
{
if
err
:=
utils
.
ImportChain
(
chain
,
arg
);
err
!=
nil
{
log
.
Error
(
"Import error"
,
"file"
,
arg
,
"err"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
cmd/utils/flags.go
+
53
−
3
View file @
c6881be2
...
...
@@ -19,6 +19,7 @@ package utils
import
(
"crypto/ecdsa"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
...
...
@@ -34,6 +35,7 @@ import (
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/common/fdlimit"
"github.com/maticnetwork/bor/consensus"
"github.com/maticnetwork/bor/consensus/bor"
"github.com/maticnetwork/bor/consensus/clique"
"github.com/maticnetwork/bor/consensus/ethash"
...
...
@@ -47,6 +49,8 @@ import (
"github.com/maticnetwork/bor/ethdb"
"github.com/maticnetwork/bor/ethstats"
"github.com/maticnetwork/bor/graphql"
pcsclite
"github.com/gballet/go-libpcsclite"
"github.com/maticnetwork/bor/les"
"github.com/maticnetwork/bor/log"
"github.com/maticnetwork/bor/metrics"
...
...
@@ -61,7 +65,6 @@ import (
"github.com/maticnetwork/bor/params"
"github.com/maticnetwork/bor/rpc"
whisper
"github.com/maticnetwork/bor/whisper/whisperv6"
pcsclite
"github.com/gballet/go-libpcsclite"
cli
"gopkg.in/urfave/cli.v1"
)
...
...
@@ -1658,19 +1661,63 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis {
return
genesis
}
func
getGenesis
(
genesisPath
string
)
*
core
.
Genesis
{
log
.
Info
(
"Reading genesis at "
,
"file"
,
genesisPath
)
file
,
_
:=
os
.
Open
(
genesisPath
)
defer
file
.
Close
()
genesis
:=
new
(
core
.
Genesis
)
json
.
NewDecoder
(
file
)
.
Decode
(
genesis
)
return
genesis
}
// MakeChain creates a chain manager from set command line flags.
func
MakeChain
(
ctx
*
cli
.
Context
,
stack
*
node
.
Node
)
(
chain
*
core
.
BlockChain
,
chainDb
ethdb
.
Database
)
{
// expecting the last argument to be the genesis file
genesis
:=
getGenesis
(
ctx
.
Args
()
.
Get
(
len
(
ctx
.
Args
())
-
1
))
var
err
error
chainDb
=
MakeChainDatabase
(
ctx
,
stack
)
config
,
_
,
err
:=
core
.
SetupGenesisBlock
(
chainDb
,
MakeG
enesis
(
ctx
)
)
config
,
_
,
err
:=
core
.
SetupGenesisBlock
(
chainDb
,
g
enesis
)
if
err
!=
nil
{
Fatalf
(
"%v"
,
err
)
}
var
engine
consensus
.
Engine
var
ethereum
*
eth
.
Ethereum
if
config
.
Clique
!=
nil
{
engine
=
clique
.
New
(
config
.
Clique
,
chainDb
)
}
else
if
config
.
Bor
!=
nil
{
engine
=
bor
.
New
(
config
,
chainDb
,
nil
)
cfg
:=
&
eth
.
Config
{
Genesis
:
genesis
}
workspace
,
err
:=
ioutil
.
TempDir
(
""
,
"console-tester-"
)
if
err
!=
nil
{
Fatalf
(
"failed to create temporary keystore: %v"
,
err
)
}
// Create a networkless protocol stack and start an Ethereum service within
stack
,
err
:=
node
.
New
(
&
node
.
Config
{
DataDir
:
workspace
,
UseLightweightKDF
:
true
,
Name
:
"console-tester"
})
if
err
!=
nil
{
Fatalf
(
"failed to create node: %v"
,
err
)
}
err
=
stack
.
Register
(
func
(
ctx
*
node
.
ServiceContext
)
(
node
.
Service
,
error
)
{
s
,
err
:=
eth
.
New
(
ctx
,
cfg
)
return
s
,
err
})
if
err
!=
nil
{
Fatalf
(
"failed to register Ethereum protocol: %v"
,
err
)
}
// Start the node and assemble the JavaScript console around it
if
err
=
stack
.
Start
();
err
!=
nil
{
Fatalf
(
"failed to start test stack: %v"
,
err
)
}
_
,
err
=
stack
.
Attach
()
if
err
!=
nil
{
Fatalf
(
"failed to attach to node: %v"
,
err
)
}
stack
.
Service
(
&
ethereum
)
engine
=
ethereum
.
Engine
()
.
(
*
bor
.
Bor
)
}
else
{
engine
=
ethash
.
NewFaker
()
if
!
ctx
.
GlobalBool
(
FakePoWFlag
.
Name
)
{
...
...
@@ -1702,6 +1749,9 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
}
vmcfg
:=
vm
.
Config
{
EnablePreimageRecording
:
ctx
.
GlobalBool
(
VMEnableDebugFlag
.
Name
)}
chain
,
err
=
core
.
NewBlockChain
(
chainDb
,
cache
,
config
,
engine
,
vmcfg
,
nil
)
if
ethereum
!=
nil
{
ethereum
.
SetBlockchain
(
chain
)
}
if
err
!=
nil
{
Fatalf
(
"Can't create BlockChain: %v"
,
err
)
}
...
...
This diff is collapsed.
Click to expand it.
eth/backend.go
+
4
−
0
View file @
c6881be2
...
...
@@ -231,6 +231,10 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return
eth
,
nil
}
func
(
s
*
Ethereum
)
SetBlockchain
(
blockchain
*
core
.
BlockChain
)
{
s
.
blockchain
=
blockchain
}
func
makeExtraData
(
extra
[]
byte
)
[]
byte
{
if
len
(
extra
)
==
0
{
// create default extradata
...
...
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