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
655e9425
Commit
655e9425
authored
Feb 18, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added GetBlock GetUncle with OOB guard
parent
be90ad89
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
9 deletions
+59
-9
block_processor.go
core/block_processor.go
+5
-1
block_processor_test.go
core/block_processor_test.go
+34
-0
chain_manager.go
core/chain_manager.go
+8
-8
block.go
core/types/block.go
+12
-0
No files found.
core/block_processor.go
View file @
655e9425
...
@@ -250,7 +250,11 @@ func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
...
@@ -250,7 +250,11 @@ func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
}
}
if
block
.
Time
()
>
time
.
Now
()
.
Unix
()
{
if
block
.
Time
()
>
time
.
Now
()
.
Unix
()
{
return
fmt
.
Errorf
(
"block time is in the future"
)
return
BlockFutureErr
}
if
new
(
big
.
Int
)
.
Sub
(
block
.
Number
(),
parent
.
Number
())
.
Cmp
(
big
.
NewInt
(
1
))
!=
0
{
return
BlockNumberErr
}
}
// 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
...
...
core/block_processor_test.go
0 → 100644
View file @
655e9425
package
core
import
(
"math/big"
"testing"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
)
func
proc
()
(
*
BlockProcessor
,
*
ChainManager
)
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
var
mux
event
.
TypeMux
chainMan
:=
NewChainManager
(
db
,
&
mux
)
return
NewBlockProcessor
(
db
,
nil
,
chainMan
,
&
mux
),
chainMan
}
func
TestNumber
(
t
*
testing
.
T
)
{
bp
,
chain
:=
proc
()
block1
:=
chain
.
NewBlock
(
nil
)
block1
.
Header
()
.
Number
=
big
.
NewInt
(
3
)
err
:=
bp
.
ValidateBlock
(
block1
,
chain
.
Genesis
())
if
err
!=
BlockNumberErr
{
t
.
Errorf
(
"expected block number error"
)
}
block1
=
chain
.
NewBlock
(
nil
)
err
=
bp
.
ValidateBlock
(
block1
,
chain
.
Genesis
())
if
err
==
BlockNumberErr
{
t
.
Errorf
(
"didn't expect block number error"
)
}
}
core/chain_manager.go
View file @
655e9425
...
@@ -87,6 +87,14 @@ type ChainManager struct {
...
@@ -87,6 +87,14 @@ type ChainManager struct {
transState
*
state
.
StateDB
transState
*
state
.
StateDB
}
}
func
NewChainManager
(
db
ethutil
.
Database
,
mux
*
event
.
TypeMux
)
*
ChainManager
{
bc
:=
&
ChainManager
{
db
:
db
,
genesisBlock
:
GenesisBlock
(
db
),
eventMux
:
mux
}
bc
.
setLastBlock
()
bc
.
transState
=
bc
.
State
()
.
Copy
()
return
bc
}
func
(
self
*
ChainManager
)
Td
()
*
big
.
Int
{
func
(
self
*
ChainManager
)
Td
()
*
big
.
Int
{
self
.
mu
.
RLock
()
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
defer
self
.
mu
.
RUnlock
()
...
@@ -108,14 +116,6 @@ func (self *ChainManager) CurrentBlock() *types.Block {
...
@@ -108,14 +116,6 @@ func (self *ChainManager) CurrentBlock() *types.Block {
return
self
.
currentBlock
return
self
.
currentBlock
}
}
func
NewChainManager
(
db
ethutil
.
Database
,
mux
*
event
.
TypeMux
)
*
ChainManager
{
bc
:=
&
ChainManager
{
db
:
db
,
genesisBlock
:
GenesisBlock
(
db
),
eventMux
:
mux
}
bc
.
setLastBlock
()
bc
.
transState
=
bc
.
State
()
.
Copy
()
return
bc
}
func
(
self
*
ChainManager
)
Status
()
(
td
*
big
.
Int
,
currentBlock
[]
byte
,
genesisBlock
[]
byte
)
{
func
(
self
*
ChainManager
)
Status
()
(
td
*
big
.
Int
,
currentBlock
[]
byte
,
genesisBlock
[]
byte
)
{
self
.
mu
.
RLock
()
self
.
mu
.
RLock
()
defer
self
.
mu
.
RUnlock
()
defer
self
.
mu
.
RUnlock
()
...
...
core/types/block.go
View file @
655e9425
...
@@ -185,6 +185,18 @@ func (self *Block) GasUsed() *big.Int { return self.header.GasUsed }
...
@@ -185,6 +185,18 @@ func (self *Block) GasUsed() *big.Int { return self.header.GasUsed }
func
(
self
*
Block
)
Root
()
[]
byte
{
return
self
.
header
.
Root
}
func
(
self
*
Block
)
Root
()
[]
byte
{
return
self
.
header
.
Root
}
func
(
self
*
Block
)
SetRoot
(
root
[]
byte
)
{
self
.
header
.
Root
=
root
}
func
(
self
*
Block
)
SetRoot
(
root
[]
byte
)
{
self
.
header
.
Root
=
root
}
func
(
self
*
Block
)
Size
()
ethutil
.
StorageSize
{
return
ethutil
.
StorageSize
(
len
(
ethutil
.
Encode
(
self
)))
}
func
(
self
*
Block
)
Size
()
ethutil
.
StorageSize
{
return
ethutil
.
StorageSize
(
len
(
ethutil
.
Encode
(
self
)))
}
func
(
self
*
Block
)
GetTransaction
(
i
int
)
*
Transaction
{
if
len
(
self
.
transactions
)
>
i
{
return
self
.
transactions
[
i
]
}
return
nil
}
func
(
self
*
Block
)
GetUncle
(
i
int
)
*
Header
{
if
len
(
self
.
uncles
)
>
i
{
return
self
.
uncles
[
i
]
}
return
nil
}
// Implement pow.Block
// Implement pow.Block
func
(
self
*
Block
)
Difficulty
()
*
big
.
Int
{
return
self
.
header
.
Difficulty
}
func
(
self
*
Block
)
Difficulty
()
*
big
.
Int
{
return
self
.
header
.
Difficulty
}
...
...
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