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
1591b633
Unverified
Commit
1591b633
authored
Mar 13, 2019
by
Péter Szilágyi
Committed by
GitHub
Mar 13, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19261 from karalabe/less-blocks
core: use headers only where blocks are unnecessary
parents
aa69ec64
4f457859
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
11 deletions
+11
-11
block_validator.go
core/block_validator.go
+1
-1
blockchain.go
core/blockchain.go
+5
-5
blockchain_insert.go
core/blockchain_insert.go
+3
-3
blockchain_test.go
core/blockchain_test.go
+1
-1
types.go
core/types.go
+1
-1
No files found.
core/block_validator.go
View file @
1591b633
...
...
@@ -77,7 +77,7 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
// transition, such as amount of used gas, the receipt roots and the state root
// itself. ValidateState returns a database batch if the validation was a success
// otherwise nil and an error is returned.
func
(
v
*
BlockValidator
)
ValidateState
(
block
,
parent
*
types
.
Block
,
statedb
*
state
.
StateDB
,
receipts
types
.
Receipts
,
usedGas
uint64
)
error
{
func
(
v
*
BlockValidator
)
ValidateState
(
block
*
types
.
Block
,
statedb
*
state
.
StateDB
,
receipts
types
.
Receipts
,
usedGas
uint64
)
error
{
header
:=
block
.
Header
()
if
block
.
GasUsed
()
!=
usedGas
{
return
fmt
.
Errorf
(
"invalid gas used (remote: %d local: %d)"
,
block
.
GasUsed
(),
usedGas
)
...
...
core/blockchain.go
View file @
1591b633
...
...
@@ -1221,9 +1221,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
parent
:=
it
.
previous
()
if
parent
==
nil
{
parent
=
bc
.
Get
Block
(
block
.
ParentHash
(),
block
.
NumberU64
()
-
1
)
parent
=
bc
.
Get
Header
(
block
.
ParentHash
(),
block
.
NumberU64
()
-
1
)
}
state
,
err
:=
state
.
New
(
parent
.
Root
()
,
bc
.
stateCache
)
state
,
err
:=
state
.
New
(
parent
.
Root
,
bc
.
stateCache
)
if
err
!=
nil
{
return
it
.
index
,
events
,
coalescedLogs
,
err
}
...
...
@@ -1236,7 +1236,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
return
it
.
index
,
events
,
coalescedLogs
,
err
}
// Validate the state using the default validator
if
err
:=
bc
.
Validator
()
.
ValidateState
(
block
,
parent
,
state
,
receipts
,
usedGas
);
err
!=
nil
{
if
err
:=
bc
.
Validator
()
.
ValidateState
(
block
,
state
,
receipts
,
usedGas
);
err
!=
nil
{
bc
.
reportBlock
(
block
,
receipts
,
err
)
return
it
.
index
,
events
,
coalescedLogs
,
err
}
...
...
@@ -1368,7 +1368,7 @@ func (bc *BlockChain) insertSidechain(block *types.Block, it *insertIterator) (i
// blocks to regenerate the required state
localTd
:=
bc
.
GetTd
(
current
.
Hash
(),
current
.
NumberU64
())
if
localTd
.
Cmp
(
externTd
)
>
0
{
log
.
Info
(
"Sidechain written to disk"
,
"start"
,
it
.
first
()
.
NumberU64
(),
"end"
,
it
.
previous
()
.
Number
U64
()
,
"sidetd"
,
externTd
,
"localtd"
,
localTd
)
log
.
Info
(
"Sidechain written to disk"
,
"start"
,
it
.
first
()
.
NumberU64
(),
"end"
,
it
.
previous
()
.
Number
,
"sidetd"
,
externTd
,
"localtd"
,
localTd
)
return
it
.
index
,
nil
,
nil
,
err
}
// Gather all the sidechain hashes (full blocks may be memory heavy)
...
...
@@ -1376,7 +1376,7 @@ func (bc *BlockChain) insertSidechain(block *types.Block, it *insertIterator) (i
hashes
[]
common
.
Hash
numbers
[]
uint64
)
parent
:=
bc
.
GetHeader
(
it
.
previous
()
.
Hash
(),
it
.
previous
()
.
NumberU64
()
)
parent
:=
it
.
previous
(
)
for
parent
!=
nil
&&
!
bc
.
HasState
(
parent
.
Root
)
{
hashes
=
append
(
hashes
,
parent
.
Hash
())
numbers
=
append
(
numbers
,
parent
.
Number
.
Uint64
())
...
...
core/blockchain_insert.go
View file @
1591b633
...
...
@@ -111,12 +111,12 @@ func (it *insertIterator) next() (*types.Block, error) {
return
it
.
chain
[
it
.
index
],
it
.
validator
.
ValidateBody
(
it
.
chain
[
it
.
index
])
}
// previous returns the previous
block was being processed, or nil
func
(
it
*
insertIterator
)
previous
()
*
types
.
Block
{
// previous returns the previous
header that was being processed, or nil.
func
(
it
*
insertIterator
)
previous
()
*
types
.
Header
{
if
it
.
index
<
1
{
return
nil
}
return
it
.
chain
[
it
.
index
-
1
]
return
it
.
chain
[
it
.
index
-
1
]
.
Header
()
}
// first returns the first block in the it.
...
...
core/blockchain_test.go
View file @
1591b633
...
...
@@ -149,7 +149,7 @@ func testBlockChainImport(chain types.Blocks, blockchain *BlockChain) error {
blockchain
.
reportBlock
(
block
,
receipts
,
err
)
return
err
}
err
=
blockchain
.
validator
.
ValidateState
(
block
,
blockchain
.
GetBlockByHash
(
block
.
ParentHash
()),
statedb
,
receipts
,
usedGas
)
err
=
blockchain
.
validator
.
ValidateState
(
block
,
statedb
,
receipts
,
usedGas
)
if
err
!=
nil
{
blockchain
.
reportBlock
(
block
,
receipts
,
err
)
return
err
...
...
core/types.go
View file @
1591b633
...
...
@@ -32,7 +32,7 @@ type Validator interface {
// ValidateState validates the given statedb and optionally the receipts and
// gas used.
ValidateState
(
block
,
parent
*
types
.
Block
,
state
*
state
.
StateDB
,
receipts
types
.
Receipts
,
usedGas
uint64
)
error
ValidateState
(
block
*
types
.
Block
,
state
*
state
.
StateDB
,
receipts
types
.
Receipts
,
usedGas
uint64
)
error
}
// Processor is an interface for processing blocks using a given initial state.
...
...
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