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
c3fabfe0
Commit
c3fabfe0
authored
Jan 12, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed validation
parent
406adb45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
3 deletions
+20
-3
block_manager.go
block_manager.go
+20
-3
No files found.
block_manager.go
View file @
c3fabfe0
...
@@ -24,11 +24,20 @@ func NewBlockChain() *BlockChain {
...
@@ -24,11 +24,20 @@ func NewBlockChain() *BlockChain {
bc
.
TD
=
new
(
big
.
Int
)
bc
.
TD
=
new
(
big
.
Int
)
bc
.
TD
.
SetBytes
(
ethutil
.
Config
.
Db
.
LastKnownTD
())
bc
.
TD
.
SetBytes
(
ethutil
.
Config
.
Db
.
LastKnownTD
())
// TODO get last block from the database
//bc.LastBlock = bc.genesisBlock
return
bc
return
bc
}
}
func
(
bc
*
BlockChain
)
HasBlock
(
hash
string
)
bool
{
func
(
bc
*
BlockChain
)
HasBlock
(
hash
string
)
bool
{
return
bc
.
LastBlock
.
State
()
.
Get
(
hash
)
!=
""
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
hash
))
return
len
(
data
)
!=
0
}
func
(
bc
*
BlockChain
)
GenesisBlock
()
*
ethutil
.
Block
{
return
bc
.
genesisBlock
}
}
type
BlockManager
struct
{
type
BlockManager
struct
{
...
@@ -107,6 +116,10 @@ func (bm *BlockManager) CalculateTD(block *ethutil.Block) bool {
...
@@ -107,6 +116,10 @@ func (bm *BlockManager) CalculateTD(block *ethutil.Block) bool {
// Set the new total difficulty back to the block chain
// Set the new total difficulty back to the block chain
bm
.
bc
.
TD
=
td
bm
.
bc
.
TD
=
td
if
Debug
{
log
.
Println
(
"TD(block) ="
,
td
)
}
return
true
return
true
}
}
...
@@ -122,7 +135,8 @@ func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error {
...
@@ -122,7 +135,8 @@ func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error {
// Check if we have the parent hash, if it isn't known we discard it
// Check if we have the parent hash, if it isn't known we discard it
// Reasons might be catching up or simply an invalid block
// Reasons might be catching up or simply an invalid block
if
!
bm
.
bc
.
HasBlock
(
block
.
PrevHash
)
{
if
bm
.
bc
.
LastBlock
!=
nil
&&
block
.
PrevHash
==
""
&&
!
bm
.
bc
.
HasBlock
(
block
.
PrevHash
)
{
return
errors
.
New
(
"Block's parent unknown"
)
return
errors
.
New
(
"Block's parent unknown"
)
}
}
...
@@ -139,10 +153,13 @@ func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error {
...
@@ -139,10 +153,13 @@ func (bm *BlockManager) ValidateBlock(block *ethutil.Block) error {
}
}
// Verify the nonce of the block. Return an error if it's not valid
// Verify the nonce of the block. Return an error if it's not valid
if
!
DaggerVerify
(
ethutil
.
BigD
(
block
.
Hash
()),
block
.
Difficulty
,
block
.
Nonce
)
{
if
bm
.
bc
.
LastBlock
!=
nil
&&
block
.
PrevHash
==
""
&&
!
DaggerVerify
(
ethutil
.
BigD
(
block
.
Hash
()),
block
.
Difficulty
,
block
.
Nonce
)
{
return
errors
.
New
(
"Block's nonce is invalid"
)
return
errors
.
New
(
"Block's nonce is invalid"
)
}
}
log
.
Println
(
"Block validation PASSED"
)
return
nil
return
nil
}
}
...
...
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