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
f7789220
Commit
f7789220
authored
Dec 02, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set proper message value
parent
edc52bdc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
34 deletions
+32
-34
block.go
chain/block.go
+2
-0
block_manager.go
chain/block_manager.go
+29
-27
state_transition.go
chain/state_transition.go
+0
-6
cmd.go
cmd/utils/cmd.go
+1
-1
No files found.
chain/block.go
View file @
f7789220
...
@@ -97,6 +97,8 @@ type Block struct {
...
@@ -97,6 +97,8 @@ type Block struct {
receipts
Receipts
receipts
Receipts
TxSha
,
ReceiptSha
[]
byte
TxSha
,
ReceiptSha
[]
byte
LogsBloom
[]
byte
LogsBloom
[]
byte
Reward
*
big
.
Int
}
}
func
NewBlockFromBytes
(
raw
[]
byte
)
*
Block
{
func
NewBlockFromBytes
(
raw
[]
byte
)
*
Block
{
...
...
chain/block_manager.go
View file @
f7789220
...
@@ -117,6 +117,19 @@ func (sm *BlockManager) ChainManager() *ChainManager {
...
@@ -117,6 +117,19 @@ func (sm *BlockManager) ChainManager() *ChainManager {
return
sm
.
bc
return
sm
.
bc
}
}
func
(
sm
*
BlockManager
)
TransitionState
(
statedb
*
state
.
State
,
parent
,
block
*
Block
)
(
receipts
Receipts
,
err
error
)
{
coinbase
:=
statedb
.
GetOrNewStateObject
(
block
.
Coinbase
)
coinbase
.
SetGasPool
(
block
.
CalcGasLimit
(
parent
))
// Process the transactions on to current block
receipts
,
_
,
_
,
_
,
err
=
sm
.
ProcessTransactions
(
coinbase
,
statedb
,
block
,
parent
,
block
.
Transactions
())
if
err
!=
nil
{
return
nil
,
err
}
return
receipts
,
nil
}
func
(
self
*
BlockManager
)
ProcessTransactions
(
coinbase
*
state
.
StateObject
,
state
*
state
.
State
,
block
,
parent
*
Block
,
txs
Transactions
)
(
Receipts
,
Transactions
,
Transactions
,
Transactions
,
error
)
{
func
(
self
*
BlockManager
)
ProcessTransactions
(
coinbase
*
state
.
StateObject
,
state
*
state
.
State
,
block
,
parent
*
Block
,
txs
Transactions
)
(
Receipts
,
Transactions
,
Transactions
,
Transactions
,
error
)
{
var
(
var
(
receipts
Receipts
receipts
Receipts
...
@@ -124,6 +137,7 @@ func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state
...
@@ -124,6 +137,7 @@ func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state
erroneous
Transactions
erroneous
Transactions
totalUsedGas
=
big
.
NewInt
(
0
)
totalUsedGas
=
big
.
NewInt
(
0
)
err
error
err
error
cumulativeSum
=
new
(
big
.
Int
)
)
)
done
:
done
:
...
@@ -155,6 +169,7 @@ done:
...
@@ -155,6 +169,7 @@ done:
}
}
txGas
.
Sub
(
txGas
,
st
.
gas
)
txGas
.
Sub
(
txGas
,
st
.
gas
)
cumulativeSum
.
Add
(
cumulativeSum
,
new
(
big
.
Int
)
.
Mul
(
txGas
,
tx
.
GasPrice
))
// Update the state with pending changes
// Update the state with pending changes
state
.
Update
(
txGas
)
state
.
Update
(
txGas
)
...
@@ -174,6 +189,7 @@ done:
...
@@ -174,6 +189,7 @@ done:
}
}
}
}
block
.
Reward
=
cumulativeSum
block
.
GasUsed
=
totalUsedGas
block
.
GasUsed
=
totalUsedGas
return
receipts
,
handled
,
unhandled
,
erroneous
,
err
return
receipts
,
handled
,
unhandled
,
erroneous
,
err
...
@@ -211,7 +227,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
...
@@ -211,7 +227,7 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
fmt
.
Printf
(
"## %x %x ##
\n
"
,
block
.
Hash
(),
block
.
Number
)
fmt
.
Printf
(
"## %x %x ##
\n
"
,
block
.
Hash
(),
block
.
Number
)
}
}
_
,
err
=
sm
.
ApplyDiff
(
state
,
parent
,
block
)
_
,
err
=
sm
.
TransitionState
(
state
,
parent
,
block
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
...
@@ -275,27 +291,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
...
@@ -275,27 +291,6 @@ func (sm *BlockManager) ProcessWithParent(block, parent *Block) (td *big.Int, me
}
}
}
}
func
(
sm
*
BlockManager
)
ApplyDiff
(
statedb
*
state
.
State
,
parent
,
block
*
Block
)
(
receipts
Receipts
,
err
error
)
{
coinbase
:=
statedb
.
GetOrNewStateObject
(
block
.
Coinbase
)
coinbase
.
SetGasPool
(
block
.
CalcGasLimit
(
parent
))
// Process the transactions on to current block
receipts
,
_
,
_
,
_
,
err
=
sm
.
ProcessTransactions
(
coinbase
,
statedb
,
block
,
parent
,
block
.
Transactions
())
if
err
!=
nil
{
return
nil
,
err
}
statedb
.
Manifest
()
.
AddMessage
(
&
state
.
Message
{
To
:
block
.
Coinbase
,
From
:
block
.
Coinbase
,
Input
:
nil
,
Origin
:
nil
,
Block
:
block
.
Hash
(),
Timestamp
:
block
.
Time
,
Coinbase
:
block
.
Coinbase
,
Number
:
block
.
Number
,
Value
:
new
(
big
.
Int
),
})
return
receipts
,
nil
}
func
(
sm
*
BlockManager
)
CalculateTD
(
block
*
Block
)
(
*
big
.
Int
,
bool
)
{
func
(
sm
*
BlockManager
)
CalculateTD
(
block
*
Block
)
(
*
big
.
Int
,
bool
)
{
uncleDiff
:=
new
(
big
.
Int
)
uncleDiff
:=
new
(
big
.
Int
)
for
_
,
uncle
:=
range
block
.
Uncles
{
for
_
,
uncle
:=
range
block
.
Uncles
{
...
@@ -345,7 +340,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *Block) error {
...
@@ -345,7 +340,7 @@ func (sm *BlockManager) ValidateBlock(block, parent *Block) error {
return
nil
return
nil
}
}
func
(
sm
*
BlockManager
)
AccumelateRewards
(
state
*
state
.
State
,
block
,
parent
*
Block
)
error
{
func
(
sm
*
BlockManager
)
AccumelateRewards
(
state
db
*
state
.
State
,
block
,
parent
*
Block
)
error
{
reward
:=
new
(
big
.
Int
)
.
Set
(
BlockReward
)
reward
:=
new
(
big
.
Int
)
.
Set
(
BlockReward
)
knownUncles
:=
ethutil
.
Set
(
parent
.
Uncles
)
knownUncles
:=
ethutil
.
Set
(
parent
.
Uncles
)
...
@@ -374,17 +369,25 @@ func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Blo
...
@@ -374,17 +369,25 @@ func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Blo
r
:=
new
(
big
.
Int
)
r
:=
new
(
big
.
Int
)
r
.
Mul
(
BlockReward
,
big
.
NewInt
(
15
))
.
Div
(
r
,
big
.
NewInt
(
16
))
r
.
Mul
(
BlockReward
,
big
.
NewInt
(
15
))
.
Div
(
r
,
big
.
NewInt
(
16
))
uncleAccount
:=
state
.
GetAccount
(
uncle
.
Coinbase
)
uncleAccount
:=
state
db
.
GetAccount
(
uncle
.
Coinbase
)
uncleAccount
.
AddAmount
(
r
)
uncleAccount
.
AddAmount
(
r
)
reward
.
Add
(
reward
,
new
(
big
.
Int
)
.
Div
(
BlockReward
,
big
.
NewInt
(
32
)))
reward
.
Add
(
reward
,
new
(
big
.
Int
)
.
Div
(
BlockReward
,
big
.
NewInt
(
32
)))
}
}
// Get the account associated with the coinbase
// Get the account associated with the coinbase
account
:=
state
.
GetAccount
(
block
.
Coinbase
)
account
:=
state
db
.
GetAccount
(
block
.
Coinbase
)
// Reward amount of ether to the coinbase address
// Reward amount of ether to the coinbase address
account
.
AddAmount
(
reward
)
account
.
AddAmount
(
reward
)
statedb
.
Manifest
()
.
AddMessage
(
&
state
.
Message
{
To
:
block
.
Coinbase
,
From
:
block
.
Coinbase
,
Input
:
nil
,
Origin
:
nil
,
Block
:
block
.
Hash
(),
Timestamp
:
block
.
Time
,
Coinbase
:
block
.
Coinbase
,
Number
:
block
.
Number
,
Value
:
new
(
big
.
Int
)
.
Add
(
reward
,
block
.
Reward
),
})
return
nil
return
nil
}
}
...
@@ -402,8 +405,7 @@ func (sm *BlockManager) GetMessages(block *Block) (messages []*state.Message, er
...
@@ -402,8 +405,7 @@ func (sm *BlockManager) GetMessages(block *Block) (messages []*state.Message, er
defer
state
.
Reset
()
defer
state
.
Reset
()
sm
.
ApplyDiff
(
state
,
parent
,
block
)
sm
.
TransitionState
(
state
,
parent
,
block
)
sm
.
AccumelateRewards
(
state
,
block
,
parent
)
sm
.
AccumelateRewards
(
state
,
block
,
parent
)
return
state
.
Manifest
()
.
Messages
,
nil
return
state
.
Manifest
()
.
Messages
,
nil
...
...
chain/state_transition.go
View file @
f7789220
...
@@ -168,12 +168,6 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -168,12 +168,6 @@ func (self *StateTransition) TransitionState() (err error) {
return
return
}
}
//dataPrice := big.NewInt(int64(len(self.data)))
//dataPrice.Mul(dataPrice, vm.GasData)
//if err = self.UseGas(dataPrice); err != nil {
// return
//}
if
sender
.
Balance
()
.
Cmp
(
self
.
value
)
<
0
{
if
sender
.
Balance
()
.
Cmp
(
self
.
value
)
<
0
{
return
fmt
.
Errorf
(
"Insufficient funds to transfer value. Req %v, has %v"
,
self
.
value
,
sender
.
Balance
)
return
fmt
.
Errorf
(
"Insufficient funds to transfer value. Req %v, has %v"
,
self
.
value
,
sender
.
Balance
)
}
}
...
...
cmd/utils/cmd.go
View file @
f7789220
...
@@ -317,7 +317,7 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
...
@@ -317,7 +317,7 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
parent
:=
ethereum
.
ChainManager
()
.
GetBlock
(
block
.
PrevHash
)
parent
:=
ethereum
.
ChainManager
()
.
GetBlock
(
block
.
PrevHash
)
_
,
err
:=
ethereum
.
BlockManager
()
.
ApplyDiff
(
parent
.
State
(),
parent
,
block
)
_
,
err
:=
ethereum
.
BlockManager
()
.
TransitionState
(
parent
.
State
(),
parent
,
block
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
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