Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
29ab1fa8
Commit
29ab1fa8
authored
Jun 30, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core, cmd/geth: recover by number
parent
be935bff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
2 deletions
+34
-2
main.go
cmd/geth/main.go
+24
-0
chain_manager.go
core/chain_manager.go
+10
-2
No files found.
cmd/geth/main.go
View file @
29ab1fa8
...
...
@@ -39,6 +39,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/comms"
...
...
@@ -68,6 +69,15 @@ func init() {
app
.
Action
=
run
app
.
HideVersion
=
true
// we have a command to print the version
app
.
Commands
=
[]
cli
.
Command
{
{
Action
:
blockRecovery
,
Name
:
"recover"
,
Usage
:
"attempts to recover a corrupted database by setting a new block head by number"
,
Description
:
`
The recover commands will attempt to read out the last
block based on that.
`
,
},
blocktestCommand
,
importCommand
,
exportCommand
,
...
...
@@ -439,6 +449,20 @@ func unlockAccount(ctx *cli.Context, am *accounts.Manager, account string) (pass
return
}
func
blockRecovery
(
ctx
*
cli
.
Context
)
{
num
:=
ctx
.
Args
()
.
First
()
if
len
(
ctx
.
Args
())
<
1
{
glog
.
Fatal
(
"recover requires block number"
)
}
cfg
:=
utils
.
MakeEthConfig
(
ClientIdentifier
,
nodeNameVersion
,
ctx
)
ethereum
,
err
:=
eth
.
New
(
cfg
)
if
err
!=
nil
{
utils
.
Fatalf
(
"%v"
,
err
)
}
ethereum
.
ChainManager
()
.
Recover
(
common
.
String2Big
(
num
)
.
Uint64
())
}
func
startEth
(
ctx
*
cli
.
Context
,
eth
*
eth
.
Ethereum
)
{
// Start Ethereum itself
...
...
core/chain_manager.go
View file @
29ab1fa8
...
...
@@ -238,6 +238,16 @@ func (self *ChainManager) setTransState(statedb *state.StateDB) {
self
.
transState
=
statedb
}
func
(
bc
*
ChainManager
)
Recover
(
num
uint64
)
{
block
:=
bc
.
GetBlockByNumber
(
num
)
if
block
!=
nil
{
bc
.
insert
(
block
)
glog
.
Infof
(
"Recovery succesful. New HEAD %x
\n
"
,
block
.
Hash
())
}
else
{
glog
.
Fatalln
(
"Recovery failed"
)
}
}
func
(
bc
*
ChainManager
)
recover
()
bool
{
data
,
_
:=
bc
.
blockDb
.
Get
([]
byte
(
"checkpoint"
))
if
len
(
data
)
!=
0
{
...
...
@@ -261,8 +271,6 @@ func (bc *ChainManager) setLastState() {
if
len
(
data
)
!=
0
{
block
:=
bc
.
GetBlock
(
common
.
BytesToHash
(
data
))
if
block
!=
nil
{
bc
.
blockDb
.
Put
([]
byte
(
"checkpoint"
),
block
.
Hash
()
.
Bytes
())
bc
.
currentBlock
=
block
bc
.
lastBlockHash
=
block
.
Hash
()
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment