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
04364124
Unverified
Commit
04364124
authored
Feb 08, 2019
by
Péter Szilágyi
Committed by
GitHub
Feb 08, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18988 from holiman/repro18977
core: repro #18977
parents
4f3d22f0
940e3170
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
12 deletions
+73
-12
blockchain.go
core/blockchain.go
+17
-11
blockchain_test.go
core/blockchain_test.go
+55
-0
chain_makers.go
core/chain_makers.go
+1
-1
No files found.
core/blockchain.go
View file @
04364124
...
...
@@ -979,11 +979,16 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
triedb
.
Cap
(
limit
-
ethdb
.
IdealBatchSize
)
}
// Find the next state trie we need to commit
header
:=
bc
.
GetHeaderByNumber
(
current
-
triesInMemory
)
chosen
:=
header
.
Number
.
Uint64
()
chosen
:=
current
-
triesInMemory
// If we exceeded out time allowance, flush an entire trie to disk
if
bc
.
gcproc
>
bc
.
cacheConfig
.
TrieTimeLimit
{
// If the header is missing (canonical chain behind), we're reorging a low
// diff sidechain. Suspend committing until this operation is completed.
header
:=
bc
.
GetHeaderByNumber
(
chosen
)
if
header
==
nil
{
log
.
Warn
(
"Reorg in progress, trie commit postponed"
,
"number"
,
chosen
)
}
else
{
// If we're exceeding limits but haven't reached a large enough memory gap,
// warn the user that the system is becoming unstable.
if
chosen
<
lastWrite
+
triesInMemory
&&
bc
.
gcproc
>=
2
*
bc
.
cacheConfig
.
TrieTimeLimit
{
...
...
@@ -994,6 +999,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
lastWrite
=
chosen
bc
.
gcproc
=
0
}
}
// Garbage collect anything below our required write retention
for
!
bc
.
triegc
.
Empty
()
{
root
,
number
:=
bc
.
triegc
.
Pop
()
...
...
@@ -1324,7 +1330,7 @@ func (bc *BlockChain) insertSidechain(block *types.Block, it *insertIterator) (i
if
err
:=
bc
.
WriteBlockWithoutState
(
block
,
externTd
);
err
!=
nil
{
return
it
.
index
,
nil
,
nil
,
err
}
log
.
Debug
(
"In
ser
ted sidechain block"
,
"number"
,
block
.
Number
(),
"hash"
,
block
.
Hash
(),
log
.
Debug
(
"In
jec
ted sidechain block"
,
"number"
,
block
.
Number
(),
"hash"
,
block
.
Hash
(),
"diff"
,
block
.
Difficulty
(),
"elapsed"
,
common
.
PrettyDuration
(
time
.
Since
(
start
)),
"txs"
,
len
(
block
.
Transactions
()),
"gas"
,
block
.
GasUsed
(),
"uncles"
,
len
(
block
.
Uncles
()),
"root"
,
block
.
Root
())
...
...
core/blockchain_test.go
View file @
04364124
...
...
@@ -1483,3 +1483,58 @@ func BenchmarkBlockChain_1x1000Executions(b *testing.B) {
benchmarkLargeNumberOfValueToNonexisting
(
b
,
numTxs
,
numBlocks
,
recipientFn
,
dataFn
)
}
// Tests that importing a very large side fork, which is larger than the canon chain,
// but where the difficulty per block is kept low: this means that it will not
// overtake the 'canon' chain until after it's passed canon by about 200 blocks.
//
// Details at:
// - https://github.com/ethereum/go-ethereum/issues/18977
// - https://github.com/ethereum/go-ethereum/pull/18988
func
TestLowDiffLongChain
(
t
*
testing
.
T
)
{
// Generate a canonical chain to act as the main dataset
engine
:=
ethash
.
NewFaker
()
db
:=
ethdb
.
NewMemDatabase
()
genesis
:=
new
(
Genesis
)
.
MustCommit
(
db
)
// We must use a pretty long chain to ensure that the fork doesn't overtake us
// until after at least 128 blocks post tip
blocks
,
_
:=
GenerateChain
(
params
.
TestChainConfig
,
genesis
,
engine
,
db
,
6
*
triesInMemory
,
func
(
i
int
,
b
*
BlockGen
)
{
b
.
SetCoinbase
(
common
.
Address
{
1
})
b
.
OffsetTime
(
-
9
)
})
// Import the canonical chain
diskdb
:=
ethdb
.
NewMemDatabase
()
new
(
Genesis
)
.
MustCommit
(
diskdb
)
chain
,
err
:=
NewBlockChain
(
diskdb
,
nil
,
params
.
TestChainConfig
,
engine
,
vm
.
Config
{},
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to create tester chain: %v"
,
err
)
}
if
n
,
err
:=
chain
.
InsertChain
(
blocks
);
err
!=
nil
{
t
.
Fatalf
(
"block %d: failed to insert into chain: %v"
,
n
,
err
)
}
// Generate fork chain, starting from an early block
parent
:=
blocks
[
10
]
fork
,
_
:=
GenerateChain
(
params
.
TestChainConfig
,
parent
,
engine
,
db
,
8
*
triesInMemory
,
func
(
i
int
,
b
*
BlockGen
)
{
b
.
SetCoinbase
(
common
.
Address
{
2
})
})
// And now import the fork
if
i
,
err
:=
chain
.
InsertChain
(
fork
);
err
!=
nil
{
t
.
Fatalf
(
"block %d: failed to insert into chain: %v"
,
i
,
err
)
}
head
:=
chain
.
CurrentBlock
()
if
got
:=
fork
[
len
(
fork
)
-
1
]
.
Hash
();
got
!=
head
.
Hash
()
{
t
.
Fatalf
(
"head wrong, expected %x got %x"
,
head
.
Hash
(),
got
)
}
// Sanity check that all the canonical numbers are present
header
:=
chain
.
CurrentHeader
()
for
number
:=
head
.
NumberU64
();
number
>
0
;
number
--
{
if
hash
:=
chain
.
GetHeaderByNumber
(
number
)
.
Hash
();
hash
!=
header
.
Hash
()
{
t
.
Fatalf
(
"header %d: canonical hash mismatch: have %x, want %x"
,
number
,
hash
,
header
.
Hash
())
}
header
=
chain
.
GetHeader
(
header
.
ParentHash
,
number
-
1
)
}
}
core/chain_makers.go
View file @
04364124
...
...
@@ -149,7 +149,7 @@ func (b *BlockGen) PrevBlock(index int) *types.Block {
// associated difficulty. It's useful to test scenarios where forking is not
// tied to chain length directly.
func
(
b
*
BlockGen
)
OffsetTime
(
seconds
int64
)
{
b
.
header
.
Time
.
Add
(
b
.
header
.
Time
,
new
(
big
.
Int
)
.
SetInt64
(
seconds
))
b
.
header
.
Time
.
Add
(
b
.
header
.
Time
,
big
.
NewInt
(
seconds
))
if
b
.
header
.
Time
.
Cmp
(
b
.
parent
.
Header
()
.
Time
)
<=
0
{
panic
(
"block time out of range"
)
}
...
...
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