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
d6254f82
Commit
d6254f82
authored
Sep 20, 2018
by
gary rong
Committed by
Péter Szilágyi
Sep 20, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
all: protect self-mined block during reorg (#17656)
parent
f89dce01
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
112 additions
and
48 deletions
+112
-48
simulated.go
accounts/abi/bind/backends/simulated.go
+1
-1
flags.go
cmd/utils/flags.go
+1
-1
snapshot_test.go
consensus/clique/snapshot_test.go
+1
-1
bench_test.go
core/bench_test.go
+2
-2
block_validator_test.go
core/block_validator_test.go
+4
-4
blockchain.go
core/blockchain.go
+44
-4
blockchain_test.go
core/blockchain_test.go
+16
-16
chain_makers.go
core/chain_makers.go
+1
-1
chain_makers_test.go
core/chain_makers_test.go
+1
-1
dao_test.go
core/dao_test.go
+6
-6
genesis_test.go
core/genesis_test.go
+1
-1
backend.go
eth/backend.go
+26
-2
handler_test.go
eth/handler_test.go
+1
-1
helper_test.go
eth/helper_test.go
+1
-1
helper_test.go
les/helper_test.go
+1
-1
odr_test.go
light/odr_test.go
+1
-1
trie_test.go
light/trie_test.go
+1
-1
txpool_test.go
light/txpool_test.go
+1
-1
worker_test.go
miner/worker_test.go
+1
-1
block_test_util.go
tests/block_test_util.go
+1
-1
No files found.
accounts/abi/bind/backends/simulated.go
View file @
d6254f82
...
@@ -69,7 +69,7 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
...
@@ -69,7 +69,7 @@ func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBac
database
:=
ethdb
.
NewMemDatabase
()
database
:=
ethdb
.
NewMemDatabase
()
genesis
:=
core
.
Genesis
{
Config
:
params
.
AllEthashProtocolChanges
,
GasLimit
:
gasLimit
,
Alloc
:
alloc
}
genesis
:=
core
.
Genesis
{
Config
:
params
.
AllEthashProtocolChanges
,
GasLimit
:
gasLimit
,
Alloc
:
alloc
}
genesis
.
MustCommit
(
database
)
genesis
.
MustCommit
(
database
)
blockchain
,
_
:=
core
.
NewBlockChain
(
database
,
nil
,
genesis
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
core
.
NewBlockChain
(
database
,
nil
,
genesis
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
backend
:=
&
SimulatedBackend
{
backend
:=
&
SimulatedBackend
{
database
:
database
,
database
:
database
,
...
...
cmd/utils/flags.go
View file @
d6254f82
...
@@ -1398,7 +1398,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
...
@@ -1398,7 +1398,7 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
cache
.
TrieNodeLimit
=
ctx
.
GlobalInt
(
CacheFlag
.
Name
)
*
ctx
.
GlobalInt
(
CacheGCFlag
.
Name
)
/
100
cache
.
TrieNodeLimit
=
ctx
.
GlobalInt
(
CacheFlag
.
Name
)
*
ctx
.
GlobalInt
(
CacheGCFlag
.
Name
)
/
100
}
}
vmcfg
:=
vm
.
Config
{
EnablePreimageRecording
:
ctx
.
GlobalBool
(
VMEnableDebugFlag
.
Name
)}
vmcfg
:=
vm
.
Config
{
EnablePreimageRecording
:
ctx
.
GlobalBool
(
VMEnableDebugFlag
.
Name
)}
chain
,
err
=
core
.
NewBlockChain
(
chainDb
,
cache
,
config
,
engine
,
vmcfg
)
chain
,
err
=
core
.
NewBlockChain
(
chainDb
,
cache
,
config
,
engine
,
vmcfg
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
Fatalf
(
"Can't create BlockChain: %v"
,
err
)
Fatalf
(
"Can't create BlockChain: %v"
,
err
)
}
}
...
...
consensus/clique/snapshot_test.go
View file @
d6254f82
...
@@ -448,7 +448,7 @@ func TestClique(t *testing.T) {
...
@@ -448,7 +448,7 @@ func TestClique(t *testing.T) {
batches
[
len
(
batches
)
-
1
]
=
append
(
batches
[
len
(
batches
)
-
1
],
block
)
batches
[
len
(
batches
)
-
1
]
=
append
(
batches
[
len
(
batches
)
-
1
],
block
)
}
}
// Pass all the headers through clique and ensure tallying succeeds
// Pass all the headers through clique and ensure tallying succeeds
chain
,
err
:=
core
.
NewBlockChain
(
db
,
nil
,
&
config
,
engine
,
vm
.
Config
{})
chain
,
err
:=
core
.
NewBlockChain
(
db
,
nil
,
&
config
,
engine
,
vm
.
Config
{}
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"test %d: failed to create test chain: %v"
,
i
,
err
)
t
.
Errorf
(
"test %d: failed to create test chain: %v"
,
i
,
err
)
continue
continue
...
...
core/bench_test.go
View file @
d6254f82
...
@@ -175,7 +175,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
...
@@ -175,7 +175,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
// Time the insertion of the new chain.
// Time the insertion of the new chain.
// State and blocks are stored in the same DB.
// State and blocks are stored in the same DB.
chainman
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
chainman
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
chainman
.
Stop
()
defer
chainman
.
Stop
()
b
.
ReportAllocs
()
b
.
ReportAllocs
()
b
.
ResetTimer
()
b
.
ResetTimer
()
...
@@ -287,7 +287,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
...
@@ -287,7 +287,7 @@ func benchReadChain(b *testing.B, full bool, count uint64) {
if
err
!=
nil
{
if
err
!=
nil
{
b
.
Fatalf
(
"error opening database at %v: %v"
,
dir
,
err
)
b
.
Fatalf
(
"error opening database at %v: %v"
,
dir
,
err
)
}
}
chain
,
err
:=
NewBlockChain
(
db
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{})
chain
,
err
:=
NewBlockChain
(
db
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
b
.
Fatalf
(
"error creating chain: %v"
,
err
)
b
.
Fatalf
(
"error creating chain: %v"
,
err
)
}
}
...
...
core/block_validator_test.go
View file @
d6254f82
...
@@ -42,7 +42,7 @@ func TestHeaderVerification(t *testing.T) {
...
@@ -42,7 +42,7 @@ func TestHeaderVerification(t *testing.T) {
headers
[
i
]
=
block
.
Header
()
headers
[
i
]
=
block
.
Header
()
}
}
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
// Run the header checker for blocks one-by-one, checking for both valid and invalid nonces
chain
,
_
:=
NewBlockChain
(
testdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{})
chain
,
_
:=
NewBlockChain
(
testdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
chain
.
Stop
()
defer
chain
.
Stop
()
for
i
:=
0
;
i
<
len
(
blocks
);
i
++
{
for
i
:=
0
;
i
<
len
(
blocks
);
i
++
{
...
@@ -106,11 +106,11 @@ func testHeaderConcurrentVerification(t *testing.T, threads int) {
...
@@ -106,11 +106,11 @@ func testHeaderConcurrentVerification(t *testing.T, threads int) {
var
results
<-
chan
error
var
results
<-
chan
error
if
valid
{
if
valid
{
chain
,
_
:=
NewBlockChain
(
testdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{})
chain
,
_
:=
NewBlockChain
(
testdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
_
,
results
=
chain
.
engine
.
VerifyHeaders
(
chain
,
headers
,
seals
)
_
,
results
=
chain
.
engine
.
VerifyHeaders
(
chain
,
headers
,
seals
)
chain
.
Stop
()
chain
.
Stop
()
}
else
{
}
else
{
chain
,
_
:=
NewBlockChain
(
testdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFakeFailer
(
uint64
(
len
(
headers
)
-
1
)),
vm
.
Config
{})
chain
,
_
:=
NewBlockChain
(
testdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFakeFailer
(
uint64
(
len
(
headers
)
-
1
)),
vm
.
Config
{}
,
nil
)
_
,
results
=
chain
.
engine
.
VerifyHeaders
(
chain
,
headers
,
seals
)
_
,
results
=
chain
.
engine
.
VerifyHeaders
(
chain
,
headers
,
seals
)
chain
.
Stop
()
chain
.
Stop
()
}
}
...
@@ -173,7 +173,7 @@ func testHeaderConcurrentAbortion(t *testing.T, threads int) {
...
@@ -173,7 +173,7 @@ func testHeaderConcurrentAbortion(t *testing.T, threads int) {
defer
runtime
.
GOMAXPROCS
(
old
)
defer
runtime
.
GOMAXPROCS
(
old
)
// Start the verifications and immediately abort
// Start the verifications and immediately abort
chain
,
_
:=
NewBlockChain
(
testdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFakeDelayer
(
time
.
Millisecond
),
vm
.
Config
{})
chain
,
_
:=
NewBlockChain
(
testdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFakeDelayer
(
time
.
Millisecond
),
vm
.
Config
{}
,
nil
)
defer
chain
.
Stop
()
defer
chain
.
Stop
()
abort
,
results
:=
chain
.
engine
.
VerifyHeaders
(
chain
,
headers
,
seals
)
abort
,
results
:=
chain
.
engine
.
VerifyHeaders
(
chain
,
headers
,
seals
)
...
...
core/blockchain.go
View file @
d6254f82
...
@@ -31,6 +31,7 @@ import (
...
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/common/prque"
"github.com/ethereum/go-ethereum/common/prque"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
...
@@ -128,13 +129,14 @@ type BlockChain struct {
...
@@ -128,13 +129,14 @@ type BlockChain struct {
validator
Validator
// block and state validator interface
validator
Validator
// block and state validator interface
vmConfig
vm
.
Config
vmConfig
vm
.
Config
badBlocks
*
lru
.
Cache
// Bad block cache
badBlocks
*
lru
.
Cache
// Bad block cache
isLocalFn
func
(
common
.
Address
)
bool
// Function used to determine whether the block author is a local miner account.
}
}
// NewBlockChain returns a fully initialised block chain using information
// NewBlockChain returns a fully initialised block chain using information
// available in the database. It initialises the default Ethereum Validator and
// available in the database. It initialises the default Ethereum Validator and
// Processor.
// Processor.
func
NewBlockChain
(
db
ethdb
.
Database
,
cacheConfig
*
CacheConfig
,
chainConfig
*
params
.
ChainConfig
,
engine
consensus
.
Engine
,
vmConfig
vm
.
Config
)
(
*
BlockChain
,
error
)
{
func
NewBlockChain
(
db
ethdb
.
Database
,
cacheConfig
*
CacheConfig
,
chainConfig
*
params
.
ChainConfig
,
engine
consensus
.
Engine
,
vmConfig
vm
.
Config
,
isLocalFn
func
(
common
.
Address
)
bool
)
(
*
BlockChain
,
error
)
{
if
cacheConfig
==
nil
{
if
cacheConfig
==
nil
{
cacheConfig
=
&
CacheConfig
{
cacheConfig
=
&
CacheConfig
{
TrieNodeLimit
:
256
*
1024
*
1024
,
TrieNodeLimit
:
256
*
1024
*
1024
,
...
@@ -154,6 +156,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
...
@@ -154,6 +156,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
triegc
:
prque
.
New
(
nil
),
triegc
:
prque
.
New
(
nil
),
stateCache
:
state
.
NewDatabase
(
db
),
stateCache
:
state
.
NewDatabase
(
db
),
quit
:
make
(
chan
struct
{}),
quit
:
make
(
chan
struct
{}),
isLocalFn
:
isLocalFn
,
bodyCache
:
bodyCache
,
bodyCache
:
bodyCache
,
bodyRLPCache
:
bodyRLPCache
,
bodyRLPCache
:
bodyRLPCache
,
blockCache
:
blockCache
,
blockCache
:
blockCache
,
...
@@ -967,8 +970,45 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
...
@@ -967,8 +970,45 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.
reorg
:=
externTd
.
Cmp
(
localTd
)
>
0
reorg
:=
externTd
.
Cmp
(
localTd
)
>
0
currentBlock
=
bc
.
CurrentBlock
()
currentBlock
=
bc
.
CurrentBlock
()
if
!
reorg
&&
externTd
.
Cmp
(
localTd
)
==
0
{
if
!
reorg
&&
externTd
.
Cmp
(
localTd
)
==
0
{
// Split same-difficulty blocks by number, then at random
// Split same-difficulty blocks by number, then preferentially select
reorg
=
block
.
NumberU64
()
<
currentBlock
.
NumberU64
()
||
(
block
.
NumberU64
()
==
currentBlock
.
NumberU64
()
&&
mrand
.
Float64
()
<
0.5
)
// the block generated by the local miner as the canonical block.
if
block
.
NumberU64
()
<
currentBlock
.
NumberU64
()
{
reorg
=
true
}
else
if
block
.
NumberU64
()
==
currentBlock
.
NumberU64
()
{
if
_
,
ok
:=
bc
.
engine
.
(
*
clique
.
Clique
);
ok
{
// The reason we need to disable the self-reorg preserving for clique
// is it can be probable to introduce a deadlock.
//
// e.g. If there are 7 available signers
//
// r1 A
// r2 B
// r3 C
// r4 D
// r5 A [X] F G
// r6 [X]
//
// In the round5, the inturn signer E is offline, so the worst case
// is A, F and G sign the block of round5 and reject the block of opponents
// and in the round6, the last available signer B is offline, the whole
// network is stuck.
reorg
=
mrand
.
Float64
()
<
0.5
}
else
{
currentAuthor
,
err
:=
bc
.
engine
.
Author
(
currentBlock
.
Header
())
if
err
!=
nil
{
return
NonStatTy
,
err
}
blockAuthor
,
err
:=
bc
.
engine
.
Author
(
block
.
Header
())
if
err
!=
nil
{
return
NonStatTy
,
err
}
var
currentLocal
,
blockLocal
bool
if
bc
.
isLocalFn
!=
nil
{
currentLocal
,
blockLocal
=
bc
.
isLocalFn
(
currentAuthor
),
bc
.
isLocalFn
(
blockAuthor
)
}
reorg
=
!
currentLocal
&&
(
blockLocal
||
mrand
.
Float64
()
<
0.5
)
}
}
}
}
if
reorg
{
if
reorg
{
// Reorganise the chain if the parent is not the head block
// Reorganise the chain if the parent is not the head block
...
...
core/blockchain_test.go
View file @
d6254f82
...
@@ -52,7 +52,7 @@ func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *B
...
@@ -52,7 +52,7 @@ func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *B
)
)
// Initialize a fresh chain with only a genesis block
// Initialize a fresh chain with only a genesis block
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
params
.
AllEthashProtocolChanges
,
engine
,
vm
.
Config
{})
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
params
.
AllEthashProtocolChanges
,
engine
,
vm
.
Config
{}
,
nil
)
// Create and inject the requested chain
// Create and inject the requested chain
if
n
==
0
{
if
n
==
0
{
return
db
,
blockchain
,
nil
return
db
,
blockchain
,
nil
...
@@ -523,7 +523,7 @@ func testReorgBadHashes(t *testing.T, full bool) {
...
@@ -523,7 +523,7 @@ func testReorgBadHashes(t *testing.T, full bool) {
blockchain
.
Stop
()
blockchain
.
Stop
()
// Create a new BlockChain and check that it rolled back the state.
// Create a new BlockChain and check that it rolled back the state.
ncm
,
err
:=
NewBlockChain
(
blockchain
.
db
,
nil
,
blockchain
.
chainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{})
ncm
,
err
:=
NewBlockChain
(
blockchain
.
db
,
nil
,
blockchain
.
chainConfig
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create new chain manager: %v"
,
err
)
t
.
Fatalf
(
"failed to create new chain manager: %v"
,
err
)
}
}
...
@@ -635,7 +635,7 @@ func TestFastVsFullChains(t *testing.T) {
...
@@ -635,7 +635,7 @@ func TestFastVsFullChains(t *testing.T) {
// Import the chain as an archive node for the comparison baseline
// Import the chain as an archive node for the comparison baseline
archiveDb
:=
ethdb
.
NewMemDatabase
()
archiveDb
:=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
archiveDb
)
gspec
.
MustCommit
(
archiveDb
)
archive
,
_
:=
NewBlockChain
(
archiveDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
archive
,
_
:=
NewBlockChain
(
archiveDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
archive
.
Stop
()
defer
archive
.
Stop
()
if
n
,
err
:=
archive
.
InsertChain
(
blocks
);
err
!=
nil
{
if
n
,
err
:=
archive
.
InsertChain
(
blocks
);
err
!=
nil
{
...
@@ -644,7 +644,7 @@ func TestFastVsFullChains(t *testing.T) {
...
@@ -644,7 +644,7 @@ func TestFastVsFullChains(t *testing.T) {
// Fast import the chain as a non-archive node to test
// Fast import the chain as a non-archive node to test
fastDb
:=
ethdb
.
NewMemDatabase
()
fastDb
:=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
fastDb
)
gspec
.
MustCommit
(
fastDb
)
fast
,
_
:=
NewBlockChain
(
fastDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
fast
,
_
:=
NewBlockChain
(
fastDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
fast
.
Stop
()
defer
fast
.
Stop
()
headers
:=
make
([]
*
types
.
Header
,
len
(
blocks
))
headers
:=
make
([]
*
types
.
Header
,
len
(
blocks
))
...
@@ -722,7 +722,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
...
@@ -722,7 +722,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
archiveDb
:=
ethdb
.
NewMemDatabase
()
archiveDb
:=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
archiveDb
)
gspec
.
MustCommit
(
archiveDb
)
archive
,
_
:=
NewBlockChain
(
archiveDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
archive
,
_
:=
NewBlockChain
(
archiveDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
if
n
,
err
:=
archive
.
InsertChain
(
blocks
);
err
!=
nil
{
if
n
,
err
:=
archive
.
InsertChain
(
blocks
);
err
!=
nil
{
t
.
Fatalf
(
"failed to process block %d: %v"
,
n
,
err
)
t
.
Fatalf
(
"failed to process block %d: %v"
,
n
,
err
)
}
}
...
@@ -735,7 +735,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
...
@@ -735,7 +735,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
// Import the chain as a non-archive node and ensure all pointers are updated
// Import the chain as a non-archive node and ensure all pointers are updated
fastDb
:=
ethdb
.
NewMemDatabase
()
fastDb
:=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
fastDb
)
gspec
.
MustCommit
(
fastDb
)
fast
,
_
:=
NewBlockChain
(
fastDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
fast
,
_
:=
NewBlockChain
(
fastDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
fast
.
Stop
()
defer
fast
.
Stop
()
headers
:=
make
([]
*
types
.
Header
,
len
(
blocks
))
headers
:=
make
([]
*
types
.
Header
,
len
(
blocks
))
...
@@ -756,7 +756,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
...
@@ -756,7 +756,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) {
lightDb
:=
ethdb
.
NewMemDatabase
()
lightDb
:=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
lightDb
)
gspec
.
MustCommit
(
lightDb
)
light
,
_
:=
NewBlockChain
(
lightDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
light
,
_
:=
NewBlockChain
(
lightDb
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
if
n
,
err
:=
light
.
InsertHeaderChain
(
headers
,
1
);
err
!=
nil
{
if
n
,
err
:=
light
.
InsertHeaderChain
(
headers
,
1
);
err
!=
nil
{
t
.
Fatalf
(
"failed to insert header %d: %v"
,
n
,
err
)
t
.
Fatalf
(
"failed to insert header %d: %v"
,
n
,
err
)
}
}
...
@@ -825,7 +825,7 @@ func TestChainTxReorgs(t *testing.T) {
...
@@ -825,7 +825,7 @@ func TestChainTxReorgs(t *testing.T) {
}
}
})
})
// Import the chain. This runs all block validation rules.
// Import the chain. This runs all block validation rules.
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
if
i
,
err
:=
blockchain
.
InsertChain
(
chain
);
err
!=
nil
{
if
i
,
err
:=
blockchain
.
InsertChain
(
chain
);
err
!=
nil
{
t
.
Fatalf
(
"failed to insert original chain[%d]: %v"
,
i
,
err
)
t
.
Fatalf
(
"failed to insert original chain[%d]: %v"
,
i
,
err
)
}
}
...
@@ -896,7 +896,7 @@ func TestLogReorgs(t *testing.T) {
...
@@ -896,7 +896,7 @@ func TestLogReorgs(t *testing.T) {
signer
=
types
.
NewEIP155Signer
(
gspec
.
Config
.
ChainID
)
signer
=
types
.
NewEIP155Signer
(
gspec
.
Config
.
ChainID
)
)
)
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
blockchain
.
Stop
()
defer
blockchain
.
Stop
()
rmLogsCh
:=
make
(
chan
RemovedLogsEvent
)
rmLogsCh
:=
make
(
chan
RemovedLogsEvent
)
...
@@ -943,7 +943,7 @@ func TestReorgSideEvent(t *testing.T) {
...
@@ -943,7 +943,7 @@ func TestReorgSideEvent(t *testing.T) {
signer
=
types
.
NewEIP155Signer
(
gspec
.
Config
.
ChainID
)
signer
=
types
.
NewEIP155Signer
(
gspec
.
Config
.
ChainID
)
)
)
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
blockchain
.
Stop
()
defer
blockchain
.
Stop
()
chain
,
_
:=
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
3
,
func
(
i
int
,
gen
*
BlockGen
)
{})
chain
,
_
:=
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
3
,
func
(
i
int
,
gen
*
BlockGen
)
{})
...
@@ -1072,7 +1072,7 @@ func TestEIP155Transition(t *testing.T) {
...
@@ -1072,7 +1072,7 @@ func TestEIP155Transition(t *testing.T) {
genesis
=
gspec
.
MustCommit
(
db
)
genesis
=
gspec
.
MustCommit
(
db
)
)
)
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
blockchain
.
Stop
()
defer
blockchain
.
Stop
()
blocks
,
_
:=
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
4
,
func
(
i
int
,
block
*
BlockGen
)
{
blocks
,
_
:=
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
4
,
func
(
i
int
,
block
*
BlockGen
)
{
...
@@ -1179,7 +1179,7 @@ func TestEIP161AccountRemoval(t *testing.T) {
...
@@ -1179,7 +1179,7 @@ func TestEIP161AccountRemoval(t *testing.T) {
}
}
genesis
=
gspec
.
MustCommit
(
db
)
genesis
=
gspec
.
MustCommit
(
db
)
)
)
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
blockchain
.
Stop
()
defer
blockchain
.
Stop
()
blocks
,
_
:=
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
3
,
func
(
i
int
,
block
*
BlockGen
)
{
blocks
,
_
:=
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
3
,
func
(
i
int
,
block
*
BlockGen
)
{
...
@@ -1254,7 +1254,7 @@ func TestBlockchainHeaderchainReorgConsistency(t *testing.T) {
...
@@ -1254,7 +1254,7 @@ func TestBlockchainHeaderchainReorgConsistency(t *testing.T) {
diskdb
:=
ethdb
.
NewMemDatabase
()
diskdb
:=
ethdb
.
NewMemDatabase
()
new
(
Genesis
)
.
MustCommit
(
diskdb
)
new
(
Genesis
)
.
MustCommit
(
diskdb
)
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{})
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{}
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
t
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
}
}
...
@@ -1298,7 +1298,7 @@ func TestTrieForkGC(t *testing.T) {
...
@@ -1298,7 +1298,7 @@ func TestTrieForkGC(t *testing.T) {
diskdb
:=
ethdb
.
NewMemDatabase
()
diskdb
:=
ethdb
.
NewMemDatabase
()
new
(
Genesis
)
.
MustCommit
(
diskdb
)
new
(
Genesis
)
.
MustCommit
(
diskdb
)
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{})
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{}
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
t
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
}
}
...
@@ -1337,7 +1337,7 @@ func TestLargeReorgTrieGC(t *testing.T) {
...
@@ -1337,7 +1337,7 @@ func TestLargeReorgTrieGC(t *testing.T) {
diskdb
:=
ethdb
.
NewMemDatabase
()
diskdb
:=
ethdb
.
NewMemDatabase
()
new
(
Genesis
)
.
MustCommit
(
diskdb
)
new
(
Genesis
)
.
MustCommit
(
diskdb
)
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{})
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{}
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
t
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
}
}
...
@@ -1419,7 +1419,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in
...
@@ -1419,7 +1419,7 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in
diskdb
:=
ethdb
.
NewMemDatabase
()
diskdb
:=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
diskdb
)
gspec
.
MustCommit
(
diskdb
)
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{})
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{}
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
b
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
b
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
}
}
...
...
core/chain_makers.go
View file @
d6254f82
...
@@ -177,7 +177,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
...
@@ -177,7 +177,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
genblock
:=
func
(
i
int
,
parent
*
types
.
Block
,
statedb
*
state
.
StateDB
)
(
*
types
.
Block
,
types
.
Receipts
)
{
genblock
:=
func
(
i
int
,
parent
*
types
.
Block
,
statedb
*
state
.
StateDB
)
(
*
types
.
Block
,
types
.
Receipts
)
{
// TODO(karalabe): This is needed for clique, which depends on multiple blocks.
// TODO(karalabe): This is needed for clique, which depends on multiple blocks.
// It's nonetheless ugly to spin up a blockchain here. Get rid of this somehow.
// It's nonetheless ugly to spin up a blockchain here. Get rid of this somehow.
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
config
,
engine
,
vm
.
Config
{})
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
config
,
engine
,
vm
.
Config
{}
,
nil
)
defer
blockchain
.
Stop
()
defer
blockchain
.
Stop
()
b
:=
&
BlockGen
{
i
:
i
,
parent
:
parent
,
chain
:
blocks
,
chainReader
:
blockchain
,
statedb
:
statedb
,
config
:
config
,
engine
:
engine
}
b
:=
&
BlockGen
{
i
:
i
,
parent
:
parent
,
chain
:
blocks
,
chainReader
:
blockchain
,
statedb
:
statedb
,
config
:
config
,
engine
:
engine
}
...
...
core/chain_makers_test.go
View file @
d6254f82
...
@@ -79,7 +79,7 @@ func ExampleGenerateChain() {
...
@@ -79,7 +79,7 @@ func ExampleGenerateChain() {
})
})
// Import the chain. This runs all block validation rules.
// Import the chain. This runs all block validation rules.
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
blockchain
.
Stop
()
defer
blockchain
.
Stop
()
if
i
,
err
:=
blockchain
.
InsertChain
(
chain
);
err
!=
nil
{
if
i
,
err
:=
blockchain
.
InsertChain
(
chain
);
err
!=
nil
{
...
...
core/dao_test.go
View file @
d6254f82
...
@@ -45,7 +45,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
...
@@ -45,7 +45,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
proConf
.
DAOForkBlock
=
forkBlock
proConf
.
DAOForkBlock
=
forkBlock
proConf
.
DAOForkSupport
=
true
proConf
.
DAOForkSupport
=
true
proBc
,
_
:=
NewBlockChain
(
proDb
,
nil
,
&
proConf
,
ethash
.
NewFaker
(),
vm
.
Config
{})
proBc
,
_
:=
NewBlockChain
(
proDb
,
nil
,
&
proConf
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
proBc
.
Stop
()
defer
proBc
.
Stop
()
conDb
:=
ethdb
.
NewMemDatabase
()
conDb
:=
ethdb
.
NewMemDatabase
()
...
@@ -55,7 +55,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
...
@@ -55,7 +55,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
conConf
.
DAOForkBlock
=
forkBlock
conConf
.
DAOForkBlock
=
forkBlock
conConf
.
DAOForkSupport
=
false
conConf
.
DAOForkSupport
=
false
conBc
,
_
:=
NewBlockChain
(
conDb
,
nil
,
&
conConf
,
ethash
.
NewFaker
(),
vm
.
Config
{})
conBc
,
_
:=
NewBlockChain
(
conDb
,
nil
,
&
conConf
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
conBc
.
Stop
()
defer
conBc
.
Stop
()
if
_
,
err
:=
proBc
.
InsertChain
(
prefix
);
err
!=
nil
{
if
_
,
err
:=
proBc
.
InsertChain
(
prefix
);
err
!=
nil
{
...
@@ -69,7 +69,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
...
@@ -69,7 +69,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
// Create a pro-fork block, and try to feed into the no-fork chain
// Create a pro-fork block, and try to feed into the no-fork chain
db
=
ethdb
.
NewMemDatabase
()
db
=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
db
)
gspec
.
MustCommit
(
db
)
bc
,
_
:=
NewBlockChain
(
db
,
nil
,
&
conConf
,
ethash
.
NewFaker
(),
vm
.
Config
{})
bc
,
_
:=
NewBlockChain
(
db
,
nil
,
&
conConf
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
bc
.
Stop
()
defer
bc
.
Stop
()
blocks
:=
conBc
.
GetBlocksFromHash
(
conBc
.
CurrentBlock
()
.
Hash
(),
int
(
conBc
.
CurrentBlock
()
.
NumberU64
()))
blocks
:=
conBc
.
GetBlocksFromHash
(
conBc
.
CurrentBlock
()
.
Hash
(),
int
(
conBc
.
CurrentBlock
()
.
NumberU64
()))
...
@@ -94,7 +94,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
...
@@ -94,7 +94,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
// Create a no-fork block, and try to feed into the pro-fork chain
// Create a no-fork block, and try to feed into the pro-fork chain
db
=
ethdb
.
NewMemDatabase
()
db
=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
db
)
gspec
.
MustCommit
(
db
)
bc
,
_
=
NewBlockChain
(
db
,
nil
,
&
proConf
,
ethash
.
NewFaker
(),
vm
.
Config
{})
bc
,
_
=
NewBlockChain
(
db
,
nil
,
&
proConf
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
bc
.
Stop
()
defer
bc
.
Stop
()
blocks
=
proBc
.
GetBlocksFromHash
(
proBc
.
CurrentBlock
()
.
Hash
(),
int
(
proBc
.
CurrentBlock
()
.
NumberU64
()))
blocks
=
proBc
.
GetBlocksFromHash
(
proBc
.
CurrentBlock
()
.
Hash
(),
int
(
proBc
.
CurrentBlock
()
.
NumberU64
()))
...
@@ -120,7 +120,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
...
@@ -120,7 +120,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
// Verify that contra-forkers accept pro-fork extra-datas after forking finishes
// Verify that contra-forkers accept pro-fork extra-datas after forking finishes
db
=
ethdb
.
NewMemDatabase
()
db
=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
db
)
gspec
.
MustCommit
(
db
)
bc
,
_
:=
NewBlockChain
(
db
,
nil
,
&
conConf
,
ethash
.
NewFaker
(),
vm
.
Config
{})
bc
,
_
:=
NewBlockChain
(
db
,
nil
,
&
conConf
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
bc
.
Stop
()
defer
bc
.
Stop
()
blocks
:=
conBc
.
GetBlocksFromHash
(
conBc
.
CurrentBlock
()
.
Hash
(),
int
(
conBc
.
CurrentBlock
()
.
NumberU64
()))
blocks
:=
conBc
.
GetBlocksFromHash
(
conBc
.
CurrentBlock
()
.
Hash
(),
int
(
conBc
.
CurrentBlock
()
.
NumberU64
()))
...
@@ -140,7 +140,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
...
@@ -140,7 +140,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
// Verify that pro-forkers accept contra-fork extra-datas after forking finishes
// Verify that pro-forkers accept contra-fork extra-datas after forking finishes
db
=
ethdb
.
NewMemDatabase
()
db
=
ethdb
.
NewMemDatabase
()
gspec
.
MustCommit
(
db
)
gspec
.
MustCommit
(
db
)
bc
,
_
=
NewBlockChain
(
db
,
nil
,
&
proConf
,
ethash
.
NewFaker
(),
vm
.
Config
{})
bc
,
_
=
NewBlockChain
(
db
,
nil
,
&
proConf
,
ethash
.
NewFaker
(),
vm
.
Config
{}
,
nil
)
defer
bc
.
Stop
()
defer
bc
.
Stop
()
blocks
=
proBc
.
GetBlocksFromHash
(
proBc
.
CurrentBlock
()
.
Hash
(),
int
(
proBc
.
CurrentBlock
()
.
NumberU64
()))
blocks
=
proBc
.
GetBlocksFromHash
(
proBc
.
CurrentBlock
()
.
Hash
(),
int
(
proBc
.
CurrentBlock
()
.
NumberU64
()))
...
...
core/genesis_test.go
View file @
d6254f82
...
@@ -120,7 +120,7 @@ func TestSetupGenesis(t *testing.T) {
...
@@ -120,7 +120,7 @@ func TestSetupGenesis(t *testing.T) {
// Advance to block #4, past the homestead transition block of customg.
// Advance to block #4, past the homestead transition block of customg.
genesis
:=
oldcustomg
.
MustCommit
(
db
)
genesis
:=
oldcustomg
.
MustCommit
(
db
)
bc
,
_
:=
NewBlockChain
(
db
,
nil
,
oldcustomg
.
Config
,
ethash
.
NewFullFaker
(),
vm
.
Config
{})
bc
,
_
:=
NewBlockChain
(
db
,
nil
,
oldcustomg
.
Config
,
ethash
.
NewFullFaker
(),
vm
.
Config
{}
,
nil
)
defer
bc
.
Stop
()
defer
bc
.
Stop
()
blocks
,
_
:=
GenerateChain
(
oldcustomg
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
4
,
nil
)
blocks
,
_
:=
GenerateChain
(
oldcustomg
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
4
,
nil
)
...
...
eth/backend.go
View file @
d6254f82
...
@@ -156,7 +156,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
...
@@ -156,7 +156,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
}
}
cacheConfig
=
&
core
.
CacheConfig
{
Disabled
:
config
.
NoPruning
,
TrieNodeLimit
:
config
.
TrieCache
,
TrieTimeLimit
:
config
.
TrieTimeout
}
cacheConfig
=
&
core
.
CacheConfig
{
Disabled
:
config
.
NoPruning
,
TrieNodeLimit
:
config
.
TrieCache
,
TrieTimeLimit
:
config
.
TrieTimeout
}
)
)
eth
.
blockchain
,
err
=
core
.
NewBlockChain
(
chainDb
,
cacheConfig
,
eth
.
chainConfig
,
eth
.
engine
,
vmConfig
)
eth
.
blockchain
,
err
=
core
.
NewBlockChain
(
chainDb
,
cacheConfig
,
eth
.
chainConfig
,
eth
.
engine
,
vmConfig
,
eth
.
isMinerAccount
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -334,6 +334,30 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
...
@@ -334,6 +334,30 @@ func (s *Ethereum) Etherbase() (eb common.Address, err error) {
return
common
.
Address
{},
fmt
.
Errorf
(
"etherbase must be explicitly specified"
)
return
common
.
Address
{},
fmt
.
Errorf
(
"etherbase must be explicitly specified"
)
}
}
// isMinerAccount checks whether the specified address is a miner account.
//
// This function is used during block chain reorg checking to determine
// whether a block is mined by local accounts. We regard two types of
// accounts as local account: etherbase and accounts specified via
// `txpool.locals` flag.
func
(
s
*
Ethereum
)
isMinerAccount
(
addr
common
.
Address
)
bool
{
// Check whether the given address is etherbase.
s
.
lock
.
RLock
()
etherbase
:=
s
.
etherbase
s
.
lock
.
RUnlock
()
if
addr
==
etherbase
{
return
true
}
// Check whether the given address is specified by `txpool.local`
// CLI flag.
for
_
,
account
:=
range
s
.
config
.
TxPool
.
Locals
{
if
account
==
addr
{
return
true
}
}
return
false
}
// SetEtherbase sets the mining reward address.
// SetEtherbase sets the mining reward address.
func
(
s
*
Ethereum
)
SetEtherbase
(
etherbase
common
.
Address
)
{
func
(
s
*
Ethereum
)
SetEtherbase
(
etherbase
common
.
Address
)
{
s
.
lock
.
Lock
()
s
.
lock
.
Lock
()
...
@@ -366,7 +390,7 @@ func (s *Ethereum) StartMining(threads int) error {
...
@@ -366,7 +390,7 @@ func (s *Ethereum) StartMining(threads int) error {
s
.
lock
.
RUnlock
()
s
.
lock
.
RUnlock
()
s
.
txPool
.
SetGasPrice
(
price
)
s
.
txPool
.
SetGasPrice
(
price
)
// Configure the local mining addess
// Configure the local mining add
r
ess
eb
,
err
:=
s
.
Etherbase
()
eb
,
err
:=
s
.
Etherbase
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"Cannot start mining without etherbase"
,
"err"
,
err
)
log
.
Error
(
"Cannot start mining without etherbase"
,
"err"
,
err
)
...
...
eth/handler_test.go
View file @
d6254f82
...
@@ -472,7 +472,7 @@ func testDAOChallenge(t *testing.T, localForked, remoteForked bool, timeout bool
...
@@ -472,7 +472,7 @@ func testDAOChallenge(t *testing.T, localForked, remoteForked bool, timeout bool
config
=
&
params
.
ChainConfig
{
DAOForkBlock
:
big
.
NewInt
(
1
),
DAOForkSupport
:
localForked
}
config
=
&
params
.
ChainConfig
{
DAOForkBlock
:
big
.
NewInt
(
1
),
DAOForkSupport
:
localForked
}
gspec
=
&
core
.
Genesis
{
Config
:
config
}
gspec
=
&
core
.
Genesis
{
Config
:
config
}
genesis
=
gspec
.
MustCommit
(
db
)
genesis
=
gspec
.
MustCommit
(
db
)
blockchain
,
_
=
core
.
NewBlockChain
(
db
,
nil
,
config
,
pow
,
vm
.
Config
{})
blockchain
,
_
=
core
.
NewBlockChain
(
db
,
nil
,
config
,
pow
,
vm
.
Config
{}
,
nil
)
)
)
pm
,
err
:=
NewProtocolManager
(
config
,
downloader
.
FullSync
,
DefaultConfig
.
NetworkId
,
evmux
,
new
(
testTxPool
),
pow
,
blockchain
,
db
)
pm
,
err
:=
NewProtocolManager
(
config
,
downloader
.
FullSync
,
DefaultConfig
.
NetworkId
,
evmux
,
new
(
testTxPool
),
pow
,
blockchain
,
db
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
eth/helper_test.go
View file @
d6254f82
...
@@ -59,7 +59,7 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func
...
@@ -59,7 +59,7 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func
Alloc
:
core
.
GenesisAlloc
{
testBank
:
{
Balance
:
big
.
NewInt
(
1000000
)}},
Alloc
:
core
.
GenesisAlloc
{
testBank
:
{
Balance
:
big
.
NewInt
(
1000000
)}},
}
}
genesis
=
gspec
.
MustCommit
(
db
)
genesis
=
gspec
.
MustCommit
(
db
)
blockchain
,
_
=
core
.
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
engine
,
vm
.
Config
{})
blockchain
,
_
=
core
.
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
engine
,
vm
.
Config
{}
,
nil
)
)
)
chain
,
_
:=
core
.
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
blocks
,
generator
)
chain
,
_
:=
core
.
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
blocks
,
generator
)
if
_
,
err
:=
blockchain
.
InsertChain
(
chain
);
err
!=
nil
{
if
_
,
err
:=
blockchain
.
InsertChain
(
chain
);
err
!=
nil
{
...
...
les/helper_test.go
View file @
d6254f82
...
@@ -164,7 +164,7 @@ func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *cor
...
@@ -164,7 +164,7 @@ func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *cor
if
lightSync
{
if
lightSync
{
chain
,
_
=
light
.
NewLightChain
(
odr
,
gspec
.
Config
,
engine
)
chain
,
_
=
light
.
NewLightChain
(
odr
,
gspec
.
Config
,
engine
)
}
else
{
}
else
{
blockchain
,
_
:=
core
.
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
engine
,
vm
.
Config
{})
blockchain
,
_
:=
core
.
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
engine
,
vm
.
Config
{}
,
nil
)
gchain
,
_
:=
core
.
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
blocks
,
generator
)
gchain
,
_
:=
core
.
GenerateChain
(
gspec
.
Config
,
genesis
,
ethash
.
NewFaker
(),
db
,
blocks
,
generator
)
if
_
,
err
:=
blockchain
.
InsertChain
(
gchain
);
err
!=
nil
{
if
_
,
err
:=
blockchain
.
InsertChain
(
gchain
);
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
...
light/odr_test.go
View file @
d6254f82
...
@@ -257,7 +257,7 @@ func testChainOdr(t *testing.T, protocol int, fn odrTestFn) {
...
@@ -257,7 +257,7 @@ func testChainOdr(t *testing.T, protocol int, fn odrTestFn) {
)
)
gspec
.
MustCommit
(
ldb
)
gspec
.
MustCommit
(
ldb
)
// Assemble the test environment
// Assemble the test environment
blockchain
,
_
:=
core
.
NewBlockChain
(
sdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFullFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
core
.
NewBlockChain
(
sdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFullFaker
(),
vm
.
Config
{}
,
nil
)
gchain
,
_
:=
core
.
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
ethash
.
NewFaker
(),
sdb
,
4
,
testChainGen
)
gchain
,
_
:=
core
.
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
ethash
.
NewFaker
(),
sdb
,
4
,
testChainGen
)
if
_
,
err
:=
blockchain
.
InsertChain
(
gchain
);
err
!=
nil
{
if
_
,
err
:=
blockchain
.
InsertChain
(
gchain
);
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
...
light/trie_test.go
View file @
d6254f82
...
@@ -40,7 +40,7 @@ func TestNodeIterator(t *testing.T) {
...
@@ -40,7 +40,7 @@ func TestNodeIterator(t *testing.T) {
genesis
=
gspec
.
MustCommit
(
fulldb
)
genesis
=
gspec
.
MustCommit
(
fulldb
)
)
)
gspec
.
MustCommit
(
lightdb
)
gspec
.
MustCommit
(
lightdb
)
blockchain
,
_
:=
core
.
NewBlockChain
(
fulldb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFullFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
core
.
NewBlockChain
(
fulldb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFullFaker
(),
vm
.
Config
{}
,
nil
)
gchain
,
_
:=
core
.
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
ethash
.
NewFaker
(),
fulldb
,
4
,
testChainGen
)
gchain
,
_
:=
core
.
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
ethash
.
NewFaker
(),
fulldb
,
4
,
testChainGen
)
if
_
,
err
:=
blockchain
.
InsertChain
(
gchain
);
err
!=
nil
{
if
_
,
err
:=
blockchain
.
InsertChain
(
gchain
);
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
...
light/txpool_test.go
View file @
d6254f82
...
@@ -88,7 +88,7 @@ func TestTxPool(t *testing.T) {
...
@@ -88,7 +88,7 @@ func TestTxPool(t *testing.T) {
)
)
gspec
.
MustCommit
(
ldb
)
gspec
.
MustCommit
(
ldb
)
// Assemble the test environment
// Assemble the test environment
blockchain
,
_
:=
core
.
NewBlockChain
(
sdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFullFaker
(),
vm
.
Config
{})
blockchain
,
_
:=
core
.
NewBlockChain
(
sdb
,
nil
,
params
.
TestChainConfig
,
ethash
.
NewFullFaker
(),
vm
.
Config
{}
,
nil
)
gchain
,
_
:=
core
.
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
ethash
.
NewFaker
(),
sdb
,
poolTestBlocks
,
txPoolTestChainGen
)
gchain
,
_
:=
core
.
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
ethash
.
NewFaker
(),
sdb
,
poolTestBlocks
,
txPoolTestChainGen
)
if
_
,
err
:=
blockchain
.
InsertChain
(
gchain
);
err
!=
nil
{
if
_
,
err
:=
blockchain
.
InsertChain
(
gchain
);
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
...
miner/worker_test.go
View file @
d6254f82
...
@@ -96,7 +96,7 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine
...
@@ -96,7 +96,7 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine
}
}
genesis
:=
gspec
.
MustCommit
(
db
)
genesis
:=
gspec
.
MustCommit
(
db
)
chain
,
_
:=
core
.
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
engine
,
vm
.
Config
{})
chain
,
_
:=
core
.
NewBlockChain
(
db
,
nil
,
gspec
.
Config
,
engine
,
vm
.
Config
{}
,
nil
)
txpool
:=
core
.
NewTxPool
(
testTxPoolConfig
,
chainConfig
,
chain
)
txpool
:=
core
.
NewTxPool
(
testTxPoolConfig
,
chainConfig
,
chain
)
// Generate a small n-block chain and an uncle block for it
// Generate a small n-block chain and an uncle block for it
...
...
tests/block_test_util.go
View file @
d6254f82
...
@@ -111,7 +111,7 @@ func (t *BlockTest) Run() error {
...
@@ -111,7 +111,7 @@ func (t *BlockTest) Run() error {
return
fmt
.
Errorf
(
"genesis block state root does not match test: computed=%x, test=%x"
,
gblock
.
Root
()
.
Bytes
()[
:
6
],
t
.
json
.
Genesis
.
StateRoot
[
:
6
])
return
fmt
.
Errorf
(
"genesis block state root does not match test: computed=%x, test=%x"
,
gblock
.
Root
()
.
Bytes
()[
:
6
],
t
.
json
.
Genesis
.
StateRoot
[
:
6
])
}
}
chain
,
err
:=
core
.
NewBlockChain
(
db
,
nil
,
config
,
ethash
.
NewShared
(),
vm
.
Config
{})
chain
,
err
:=
core
.
NewBlockChain
(
db
,
nil
,
config
,
ethash
.
NewShared
(),
vm
.
Config
{}
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
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