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
5ceb1620
Commit
5ceb1620
authored
May 20, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed couple issues
* (imp) Lock / RLock tries * (fix) stack
parent
e8b45852
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
26 deletions
+71
-26
stack.go
ethchain/stack.go
+1
-1
state_manager.go
ethchain/state_manager.go
+25
-21
state_object_test.go
ethchain/state_object_test.go
+28
-1
vm.go
ethchain/vm.go
+2
-0
vm_test.go
ethchain/vm_test.go
+6
-3
miner.go
ethminer/miner.go
+1
-0
trie.go
ethutil/trie.go
+8
-0
No files found.
ethchain/stack.go
View file @
5ceb1620
...
@@ -65,7 +65,7 @@ func (st *Stack) Peekn() (*big.Int, *big.Int) {
...
@@ -65,7 +65,7 @@ func (st *Stack) Peekn() (*big.Int, *big.Int) {
}
}
func
(
st
*
Stack
)
Push
(
d
*
big
.
Int
)
{
func
(
st
*
Stack
)
Push
(
d
*
big
.
Int
)
{
st
.
data
=
append
(
st
.
data
,
d
)
st
.
data
=
append
(
st
.
data
,
new
(
big
.
Int
)
.
Set
(
d
)
)
}
}
func
(
st
*
Stack
)
Get
(
amount
*
big
.
Int
)
[]
*
big
.
Int
{
func
(
st
*
Stack
)
Get
(
amount
*
big
.
Int
)
[]
*
big
.
Int
{
...
...
ethchain/state_manager.go
View file @
5ceb1620
...
@@ -100,30 +100,34 @@ func (sm *StateManager) MakeContract(state *State, tx *Transaction) *StateObject
...
@@ -100,30 +100,34 @@ func (sm *StateManager) MakeContract(state *State, tx *Transaction) *StateObject
func
(
sm
*
StateManager
)
ApplyTransactions
(
state
*
State
,
block
*
Block
,
txs
[]
*
Transaction
)
{
func
(
sm
*
StateManager
)
ApplyTransactions
(
state
*
State
,
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
sm
.
ApplyTransaction
(
state
,
block
,
tx
)
// Check if this is a contract creation traction and if so
}
// create a contract of this tx.
}
if
tx
.
IsContract
()
{
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
block
,
false
)
func
(
sm
*
StateManager
)
ApplyTransaction
(
state
*
State
,
block
*
Block
,
tx
*
Transaction
)
{
if
err
==
nil
{
// If there's no recipient, it's a contract
contract
:=
sm
.
MakeContract
(
state
,
tx
)
// Check if this is a contract creation traction and if so
if
contract
!=
nil
{
// create a contract of this tx.
sm
.
EvalScript
(
state
,
contract
.
Init
(),
contract
,
tx
,
block
)
if
tx
.
IsContract
()
{
}
else
{
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
block
,
false
)
ethutil
.
Config
.
Log
.
Infoln
(
"[STATE] Unable to create contract"
)
if
err
==
nil
{
}
contract
:=
sm
.
MakeContract
(
state
,
tx
)
if
contract
!=
nil
{
sm
.
EvalScript
(
state
,
contract
.
Init
(),
contract
,
tx
,
block
)
}
else
{
}
else
{
ethutil
.
Config
.
Log
.
Infoln
(
"[STATE]
contract create:"
,
err
)
ethutil
.
Config
.
Log
.
Infoln
(
"[STATE]
Unable to create contract"
)
}
}
}
else
{
}
else
{
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
block
,
false
)
ethutil
.
Config
.
Log
.
Infoln
(
"[STATE] contract create:"
,
err
)
contract
:=
state
.
GetStateObject
(
tx
.
Recipient
)
}
ethutil
.
Config
.
Log
.
Debugf
(
"contract recip %x
\n
"
,
tx
.
Recipient
)
}
else
{
if
err
==
nil
&&
len
(
contract
.
Script
())
>
0
{
err
:=
sm
.
Ethereum
.
TxPool
()
.
ProcessTransaction
(
tx
,
block
,
false
)
sm
.
EvalScript
(
state
,
contract
.
Script
(),
contract
,
tx
,
block
)
contract
:=
state
.
GetStateObject
(
tx
.
Recipient
)
}
else
if
err
!=
nil
{
ethutil
.
Config
.
Log
.
Debugf
(
"contract recip %x
\n
"
,
tx
.
Recipient
)
ethutil
.
Config
.
Log
.
Infoln
(
"[STATE] process:"
,
err
)
if
err
==
nil
&&
len
(
contract
.
Script
())
>
0
{
}
sm
.
EvalScript
(
state
,
contract
.
Script
(),
contract
,
tx
,
block
)
}
else
if
err
!=
nil
{
ethutil
.
Config
.
Log
.
Infoln
(
"[STATE] process:"
,
err
)
}
}
}
}
}
}
...
...
ethchain/state_object_test.go
View file @
5ceb1620
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"fmt"
"fmt"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"math/big"
"testing"
"testing"
)
)
...
@@ -21,5 +22,31 @@ func TestSync(t *testing.T) {
...
@@ -21,5 +22,31 @@ func TestSync(t *testing.T) {
state
.
Sync
()
state
.
Sync
()
object
:=
state
.
GetStateObject
([]
byte
(
"aa"
))
object
:=
state
.
GetStateObject
([]
byte
(
"aa"
))
fmt
.
Printf
(
"%x
\n
"
,
object
.
Script
())
if
len
(
object
.
Script
())
==
0
{
t
.
Fail
()
}
}
func
TestObjectGet
(
t
*
testing
.
T
)
{
ethutil
.
ReadConfig
(
""
,
ethutil
.
LogStd
)
db
,
_
:=
ethdb
.
NewMemDatabase
()
ethutil
.
Config
.
Db
=
db
state
:=
NewState
(
ethutil
.
NewTrie
(
db
,
""
))
contract
:=
NewContract
([]
byte
(
"aa"
),
ethutil
.
Big1
,
ZeroHash256
)
state
.
UpdateStateObject
(
contract
)
contract
=
state
.
GetStateObject
([]
byte
(
"aa"
))
contract
.
SetStorage
(
big
.
NewInt
(
0
),
ethutil
.
NewValue
(
"hello"
))
o
:=
contract
.
GetMem
(
big
.
NewInt
(
0
))
fmt
.
Println
(
o
)
state
.
UpdateStateObject
(
contract
)
contract
.
SetStorage
(
big
.
NewInt
(
0
),
ethutil
.
NewValue
(
"hello00"
))
contract
=
state
.
GetStateObject
([]
byte
(
"aa"
))
o
=
contract
.
GetMem
(
big
.
NewInt
(
0
))
fmt
.
Println
(
"after"
,
o
)
}
}
ethchain/vm.go
View file @
5ceb1620
...
@@ -390,10 +390,12 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
...
@@ -390,10 +390,12 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
require
(
1
)
require
(
1
)
loc
:=
stack
.
Pop
()
loc
:=
stack
.
Pop
()
val
:=
closure
.
GetMem
(
loc
)
val
:=
closure
.
GetMem
(
loc
)
//fmt.Println("get", val.BigInt(), "@", loc)
stack
.
Push
(
val
.
BigInt
())
stack
.
Push
(
val
.
BigInt
())
case
oSSTORE
:
case
oSSTORE
:
require
(
2
)
require
(
2
)
val
,
loc
:=
stack
.
Popn
()
val
,
loc
:=
stack
.
Popn
()
//fmt.Println("storing", val, "@", loc)
closure
.
SetStorage
(
loc
,
ethutil
.
NewValue
(
val
))
closure
.
SetStorage
(
loc
,
ethutil
.
NewValue
(
val
))
// Add the change to manifest
// Add the change to manifest
...
...
ethchain/vm_test.go
View file @
5ceb1620
package
ethchain
package
ethchain
/*
import (
import (
_ "bytes"
_ "bytes"
"fmt"
"fmt"
...
@@ -23,10 +24,11 @@ func TestRun4(t *testing.T) {
...
@@ -23,10 +24,11 @@ func TestRun4(t *testing.T) {
if a > b {
if a > b {
int32 c = this.caller()
int32 c = this.caller()
}
}
E
xit()
e
xit()
`), false)
`), false)
tx := NewContractCreationTx(ethutil.Big("0"), ethutil.Big("1000"), ethutil.Big("100"), script, nil)
tx := NewContractCreationTx(ethutil.Big("0"), ethutil.Big("1000"), ethutil.Big("100"), script, nil)
addr
:=
tx
.
Hash
()[
12
:
]
tx.Sign(ContractAddr)
addr := tx.CreationAddress()
contract := MakeContract(tx, state)
contract := MakeContract(tx, state)
state.UpdateStateObject(contract)
state.UpdateStateObject(contract)
fmt.Printf("%x\n", addr)
fmt.Printf("%x\n", addr)
...
@@ -34,7 +36,7 @@ func TestRun4(t *testing.T) {
...
@@ -34,7 +36,7 @@ func TestRun4(t *testing.T) {
callerScript, err := mutan.Compile(strings.NewReader(`
callerScript, err := mutan.Compile(strings.NewReader(`
// Check if there's any cash in the initial store
// Check if there's any cash in the initial store
if this.store[1000] == 0 {
if this.store[1000] == 0 {
this.store[1000] = 10
^
20
this.store[1000] = 10
**
20
}
}
...
@@ -93,3 +95,4 @@ func TestRun4(t *testing.T) {
...
@@ -93,3 +95,4 @@ func TestRun4(t *testing.T) {
}
}
fmt.Println("account.Amount =", account.Amount)
fmt.Println("account.Amount =", account.Amount)
}
}
*/
ethminer/miner.go
View file @
5ceb1620
...
@@ -102,6 +102,7 @@ func (miner *Miner) listener() {
...
@@ -102,6 +102,7 @@ func (miner *Miner) listener() {
}
}
if
found
==
false
{
if
found
==
false
{
miner
.
block
.
Undo
()
//log.Infoln("[MINER] We did not know about this transaction, adding")
//log.Infoln("[MINER] We did not know about this transaction, adding")
miner
.
txs
=
append
(
miner
.
txs
,
tx
)
miner
.
txs
=
append
(
miner
.
txs
,
tx
)
miner
.
block
=
miner
.
ethereum
.
BlockChain
()
.
NewBlock
(
miner
.
coinbase
,
miner
.
txs
)
miner
.
block
=
miner
.
ethereum
.
BlockChain
()
.
NewBlock
(
miner
.
coinbase
,
miner
.
txs
)
...
...
ethutil/trie.go
View file @
5ceb1620
...
@@ -3,6 +3,7 @@ package ethutil
...
@@ -3,6 +3,7 @@ package ethutil
import
(
import
(
"fmt"
"fmt"
"reflect"
"reflect"
"sync"
)
)
// TODO
// TODO
...
@@ -113,6 +114,7 @@ func (cache *Cache) Undo() {
...
@@ -113,6 +114,7 @@ func (cache *Cache) Undo() {
// Please note that the data isn't persisted unless `Sync` is
// Please note that the data isn't persisted unless `Sync` is
// explicitly called.
// explicitly called.
type
Trie
struct
{
type
Trie
struct
{
mut
sync
.
RWMutex
prevRoot
interface
{}
prevRoot
interface
{}
Root
interface
{}
Root
interface
{}
//db Database
//db Database
...
@@ -157,12 +159,18 @@ func (t *Trie) Cache() *Cache {
...
@@ -157,12 +159,18 @@ func (t *Trie) Cache() *Cache {
* Public (query) interface functions
* Public (query) interface functions
*/
*/
func
(
t
*
Trie
)
Update
(
key
string
,
value
string
)
{
func
(
t
*
Trie
)
Update
(
key
string
,
value
string
)
{
t
.
mut
.
Lock
()
defer
t
.
mut
.
Unlock
()
k
:=
CompactHexDecode
(
key
)
k
:=
CompactHexDecode
(
key
)
t
.
Root
=
t
.
UpdateState
(
t
.
Root
,
k
,
value
)
t
.
Root
=
t
.
UpdateState
(
t
.
Root
,
k
,
value
)
}
}
func
(
t
*
Trie
)
Get
(
key
string
)
string
{
func
(
t
*
Trie
)
Get
(
key
string
)
string
{
t
.
mut
.
RLock
()
defer
t
.
mut
.
RUnlock
()
k
:=
CompactHexDecode
(
key
)
k
:=
CompactHexDecode
(
key
)
c
:=
NewValue
(
t
.
GetState
(
t
.
Root
,
k
))
c
:=
NewValue
(
t
.
GetState
(
t
.
Root
,
k
))
...
...
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