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
6625b6ff
Commit
6625b6ff
authored
Mar 30, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed to new mutan API
parent
b8886522
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
25 deletions
+28
-25
state_manager.go
ethchain/state_manager.go
+13
-13
vm_test.go
ethchain/vm_test.go
+15
-12
No files found.
ethchain/state_manager.go
View file @
6625b6ff
...
@@ -100,16 +100,21 @@ func (sm *StateManager) MakeContract(tx *Transaction) {
...
@@ -100,16 +100,21 @@ func (sm *StateManager) MakeContract(tx *Transaction) {
}
}
}
}
// Apply transactions uses the transaction passed to it and applies them onto
// the current processing state.
func
(
sm
*
StateManager
)
ApplyTransactions
(
block
*
Block
,
txs
[]
*
Transaction
)
{
func
(
sm
*
StateManager
)
ApplyTransactions
(
block
*
Block
,
txs
[]
*
Transaction
)
{
// Process each transaction/contract
// Process each transaction/contract
for
_
,
tx
:=
range
txs
{
for
_
,
tx
:=
range
txs
{
// If there's no recipient, it's a contract
// If there's no recipient, it's a contract
// Check if this is a contract creation traction and if so
// create a contract of this tx.
if
tx
.
IsContract
()
{
if
tx
.
IsContract
()
{
sm
.
MakeContract
(
tx
)
sm
.
MakeContract
(
tx
)
//XXX block.MakeContract(tx)
}
else
{
}
else
{
// Figure out if the address this transaction was sent to is a
// contract or an actual account. In case of a contract, we process that
// contract instead of moving funds between accounts.
if
contract
:=
sm
.
procState
.
GetContract
(
tx
.
Recipient
);
contract
!=
nil
{
if
contract
:=
sm
.
procState
.
GetContract
(
tx
.
Recipient
);
contract
!=
nil
{
//XXX if contract := block.state.GetContract(tx.Recipient); contract != nil {
sm
.
ProcessContract
(
contract
,
tx
,
block
)
sm
.
ProcessContract
(
contract
,
tx
,
block
)
}
else
{
}
else
{
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
block
)
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
block
)
...
@@ -172,14 +177,12 @@ func (sm *StateManager) ProcessBlock(block *Block) error {
...
@@ -172,14 +177,12 @@ func (sm *StateManager) ProcessBlock(block *Block) error {
// if !sm.compState.Cmp(sm.procState)
// if !sm.compState.Cmp(sm.procState)
if
!
sm
.
compState
.
Cmp
(
sm
.
procState
)
{
if
!
sm
.
compState
.
Cmp
(
sm
.
procState
)
{
//XXX return fmt.Errorf("Invalid merkle root. Expected %x, got %x", block.State().trie.Root, sm.bc.CurrentBlock.State().trie.Root)
return
fmt
.
Errorf
(
"Invalid merkle root. Expected %x, got %x"
,
sm
.
compState
.
trie
.
Root
,
sm
.
procState
.
trie
.
Root
)
return
fmt
.
Errorf
(
"Invalid merkle root. Expected %x, got %x"
,
sm
.
compState
.
trie
.
Root
,
sm
.
procState
.
trie
.
Root
)
}
}
// Calculate the new total difficulty and sync back to the db
// Calculate the new total difficulty and sync back to the db
if
sm
.
CalculateTD
(
block
)
{
if
sm
.
CalculateTD
(
block
)
{
// Sync the current block's state to the database and cancelling out the deferred Undo
// Sync the current block's state to the database and cancelling out the deferred Undo
//XXX sm.bc.CurrentBlock.Sync()
sm
.
procState
.
Sync
()
sm
.
procState
.
Sync
()
// Broadcast the valid block back to the wire
// Broadcast the valid block back to the wire
...
@@ -273,12 +276,10 @@ func CalculateUncleReward(block *Block) *big.Int {
...
@@ -273,12 +276,10 @@ func CalculateUncleReward(block *Block) *big.Int {
func
(
sm
*
StateManager
)
AccumelateRewards
(
block
*
Block
)
error
{
func
(
sm
*
StateManager
)
AccumelateRewards
(
block
*
Block
)
error
{
// Get the coinbase rlp data
// Get the coinbase rlp data
//XXX addr := processor.state.GetAccount(block.Coinbase)
addr
:=
sm
.
procState
.
GetAccount
(
block
.
Coinbase
)
addr
:=
sm
.
procState
.
GetAccount
(
block
.
Coinbase
)
// Reward amount of ether to the coinbase address
// Reward amount of ether to the coinbase address
addr
.
AddFee
(
CalculateBlockReward
(
block
,
len
(
block
.
Uncles
)))
addr
.
AddFee
(
CalculateBlockReward
(
block
,
len
(
block
.
Uncles
)))
//XXX processor.state.UpdateAccount(block.Coinbase, addr)
sm
.
procState
.
UpdateAccount
(
block
.
Coinbase
,
addr
)
sm
.
procState
.
UpdateAccount
(
block
.
Coinbase
,
addr
)
for
_
,
uncle
:=
range
block
.
Uncles
{
for
_
,
uncle
:=
range
block
.
Uncles
{
...
@@ -298,13 +299,12 @@ func (sm *StateManager) Stop() {
...
@@ -298,13 +299,12 @@ func (sm *StateManager) Stop() {
func
(
sm
*
StateManager
)
ProcessContract
(
contract
*
Contract
,
tx
*
Transaction
,
block
*
Block
)
{
func
(
sm
*
StateManager
)
ProcessContract
(
contract
*
Contract
,
tx
*
Transaction
,
block
*
Block
)
{
// Recovering function in case the VM had any errors
// Recovering function in case the VM had any errors
/*
defer
func
()
{
defer func() {
if
r
:=
recover
();
r
!=
nil
{
if r := recover(); r != nil {
fmt
.
Println
(
"Recovered from VM execution with err ="
,
r
)
fmt.Println("Recovered from VM execution with err =", r)
}
}
}()
}()
*/
caller
:=
sm
.
procState
.
GetAccount
(
tx
.
Sender
())
caller
:=
sm
.
procState
.
GetAccount
(
tx
.
Sender
())
closure
:=
NewClosure
(
caller
,
contract
,
sm
.
procState
,
tx
.
Gas
,
tx
.
Value
)
closure
:=
NewClosure
(
caller
,
contract
,
sm
.
procState
,
tx
.
Gas
,
tx
.
Value
)
vm
:=
NewVm
(
sm
.
procState
,
RuntimeVars
{
vm
:=
NewVm
(
sm
.
procState
,
RuntimeVars
{
...
...
ethchain/vm_test.go
View file @
6625b6ff
...
@@ -81,18 +81,21 @@ func TestRun4(t *testing.T) {
...
@@ -81,18 +81,21 @@ func TestRun4(t *testing.T) {
db
,
_
:=
ethdb
.
NewMemDatabase
()
db
,
_
:=
ethdb
.
NewMemDatabase
()
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
mutan
.
NewCompiler
()
.
Compile
(
strings
.
NewReader
(
`
mutan
.
Compile
(
strings
.
NewReader
(
`
a = 1337
a = 1337
c = 1
c = 1
store[0] = 50
store[0] = 50
d = store[0]
d = store[0]
`
))
`
),
false
)
asm
,
_
:=
mutan
.
NewCompiler
()
.
Compile
(
strings
.
NewReader
(
`
asm
,
err
:=
mutan
.
Compile
(
strings
.
NewReader
(
`
a = 3 + 3
a = 3 + 3
store[1000] = a
store[1000] = a
store[1000]
store[1000]
`
))
`
),
false
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
asm
=
append
(
asm
,
"LOG"
)
asm
=
append
(
asm
,
"LOG"
)
fmt
.
Println
(
asm
)
fmt
.
Println
(
asm
)
...
...
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