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
bb1641e4
Commit
bb1641e4
authored
Jun 23, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up & refactored methods
parent
299b50a0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
26 deletions
+27
-26
state_manager.go
ethchain/state_manager.go
+27
-26
No files found.
ethchain/state_manager.go
View file @
bb1641e4
...
...
@@ -143,45 +143,31 @@ done:
return
receipts
,
handled
,
unhandled
,
err
}
func
(
sm
*
StateManager
)
Process
(
block
*
Block
,
dontReact
bool
)
error
{
if
!
sm
.
bc
.
HasBlock
(
block
.
PrevHash
)
{
return
ParentError
(
block
.
PrevHash
)
}
parent
:=
sm
.
bc
.
GetBlock
(
block
.
PrevHash
)
return
sm
.
ProcessBlock
(
parent
.
State
(),
parent
,
block
,
dontReact
)
}
// Block processing and validating with a given (temporarily) state
func
(
sm
*
StateManager
)
ProcessBlock
(
state
*
State
,
parent
,
block
*
Block
,
dontReact
bool
)
(
err
error
)
{
func
(
sm
*
StateManager
)
Process
(
block
*
Block
,
dontReact
bool
)
(
err
error
)
{
// Processing a blocks may never happen simultaneously
sm
.
mutex
.
Lock
()
defer
sm
.
mutex
.
Unlock
()
hash
:=
block
.
Hash
()
if
sm
.
bc
.
HasBlock
(
hash
)
{
if
sm
.
bc
.
HasBlock
(
block
.
Hash
()
)
{
return
nil
}
if
!
sm
.
bc
.
HasBlock
(
block
.
PrevHash
)
{
return
ParentError
(
block
.
PrevHash
)
}
var
(
parent
=
sm
.
bc
.
GetBlock
(
block
.
PrevHash
)
state
=
parent
.
State
()
)
// Defer the Undo on the Trie. If the block processing happened
// we don't want to undo but since undo only happens on dirty
// nodes this won't happen because Commit would have been called
// before that.
defer
state
.
Reset
()
// 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
if
!
sm
.
bc
.
HasBlock
(
block
.
PrevHash
)
&&
sm
.
bc
.
CurrentBlock
!=
nil
{
return
ParentError
(
block
.
PrevHash
)
}
coinbase
:=
state
.
GetOrNewStateObject
(
block
.
Coinbase
)
coinbase
.
SetGasPool
(
block
.
CalcGasLimit
(
parent
))
// Process the transactions on to current block
receipts
,
_
,
_
,
_
:=
sm
.
ProcessTransactions
(
coinbase
,
state
,
block
,
parent
,
block
.
Transactions
())
receipts
,
err
:=
sm
.
ApplyDiff
(
state
,
parent
,
block
)
defer
func
()
{
if
err
!=
nil
{
if
len
(
receipts
)
==
len
(
block
.
Receipts
())
{
...
...
@@ -194,6 +180,10 @@ func (sm *StateManager) ProcessBlock(state *State, parent, block *Block, dontRea
}
}()
if
err
!=
nil
{
return
err
}
// Block validation
if
err
=
sm
.
ValidateBlock
(
block
);
err
!=
nil
{
fmt
.
Println
(
"[SM] Error validating block:"
,
err
)
...
...
@@ -237,6 +227,17 @@ func (sm *StateManager) ProcessBlock(state *State, parent, block *Block, dontRea
return
nil
}
func
(
sm
*
StateManager
)
ApplyDiff
(
state
*
State
,
parent
,
block
*
Block
)
(
receipts
Receipts
,
err
error
)
{
coinbase
:=
state
.
GetOrNewStateObject
(
block
.
Coinbase
)
coinbase
.
SetGasPool
(
block
.
CalcGasLimit
(
parent
))
// Process the transactions on to current block
receipts
,
_
,
_
,
_
=
sm
.
ProcessTransactions
(
coinbase
,
state
,
block
,
parent
,
block
.
Transactions
())
return
receipts
,
nil
}
func
(
sm
*
StateManager
)
CalculateTD
(
block
*
Block
)
bool
{
uncleDiff
:=
new
(
big
.
Int
)
for
_
,
uncle
:=
range
block
.
Uncles
{
...
...
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