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
de2da4fd
Commit
de2da4fd
authored
Jul 03, 2014
by
zelig
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of github.com:ethereum/eth-go into feature/clientid
parents
198e5eea
5d671392
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
68 additions
and
48 deletions
+68
-48
state.go
ethchain/state.go
+1
-5
state_manager.go
ethchain/state_manager.go
+9
-0
state_transition.go
ethchain/state_transition.go
+5
-12
vm.go
ethchain/vm.go
+36
-26
crypto.go
ethcrypto/crypto.go
+3
-5
trie.go
ethtrie/trie.go
+14
-0
No files found.
ethchain/state.go
View file @
de2da4fd
...
...
@@ -93,10 +93,6 @@ func (self *State) ResetStateObject(stateObject *StateObject) {
func
(
self
*
State
)
UpdateStateObject
(
stateObject
*
StateObject
)
{
addr
:=
stateObject
.
Address
()
if
self
.
stateObjects
[
string
(
addr
)]
==
nil
{
self
.
stateObjects
[
string
(
addr
)]
=
stateObject
}
ethutil
.
Config
.
Db
.
Put
(
ethcrypto
.
Sha3Bin
(
stateObject
.
Script
()),
stateObject
.
Script
())
self
.
trie
.
Update
(
string
(
addr
),
string
(
stateObject
.
RlpEncode
()))
...
...
@@ -131,7 +127,7 @@ func (self *State) GetOrNewStateObject(addr []byte) *StateObject {
}
func
(
self
*
State
)
NewStateObject
(
addr
[]
byte
)
*
StateObject
{
//
statelogger.Infof("(+) %x\n", addr)
statelogger
.
Infof
(
"(+) %x
\n
"
,
addr
)
stateObject
:=
NewStateObject
(
addr
)
self
.
stateObjects
[
string
(
addr
)]
=
stateObject
...
...
ethchain/state_manager.go
View file @
de2da4fd
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"math/big"
...
...
@@ -205,7 +206,15 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
return
err
}
if
ethutil
.
Config
.
Paranoia
{
valid
,
_
:=
ethtrie
.
ParanoiaCheck
(
state
.
trie
)
if
!
valid
{
err
=
fmt
.
Errorf
(
"PARANOIA: World state trie corruption"
)
}
}
if
!
block
.
State
()
.
Cmp
(
state
)
{
err
=
fmt
.
Errorf
(
"Invalid merkle root.
\n
rec: %x
\n
is: %x"
,
block
.
State
()
.
trie
.
Root
,
state
.
trie
.
Root
)
return
}
...
...
ethchain/state_transition.go
View file @
de2da4fd
package
ethchain
import
(
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
...
...
@@ -54,6 +53,7 @@ func (self *StateTransition) Sender() *StateObject {
}
self
.
sen
=
self
.
state
.
GetAccount
(
self
.
tx
.
Sender
())
return
self
.
sen
}
func
(
self
*
StateTransition
)
Receiver
()
*
StateObject
{
...
...
@@ -264,23 +264,16 @@ func Call(vm *Vm, closure *Closure, data []byte) (ret []byte, err error, deepErr
ret
,
_
,
err
=
closure
.
Call
(
vm
,
data
)
deepErr
=
vm
.
err
!=
nil
Paranoia
:=
ethutil
.
Config
.
Paranoia
if
Paranoia
{
if
ethutil
.
Config
.
Paranoia
{
var
(
context
=
closure
.
object
trie
=
context
.
state
.
trie
trie2
=
ethtrie
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
)
)
trie
.
NewIterator
()
.
Each
(
func
(
key
string
,
v
*
ethutil
.
Value
)
{
trie2
.
Update
(
key
,
v
.
Str
())
})
a
:=
ethutil
.
NewValue
(
trie2
.
Root
)
.
Bytes
()
b
:=
ethutil
.
NewValue
(
context
.
state
.
trie
.
Root
)
.
Bytes
()
if
bytes
.
Compare
(
a
,
b
)
!=
0
{
valid
,
t2
:=
ethtrie
.
ParanoiaCheck
(
trie
)
if
!
valid
{
// TODO FIXME ASAP
context
.
state
.
trie
=
t
rie
2
context
.
state
.
trie
=
t2
/*
statelogger.Debugf("(o): %x\n", trie.Root)
trie.NewIterator().Each(func(key string, v *ethutil.Value) {
...
...
ethchain/vm.go
View file @
de2da4fd
...
...
@@ -35,7 +35,6 @@ func CalculateTxGas(initSize *big.Int) *big.Int {
}
type
Vm
struct
{
txPool
*
TxPool
// Stack for processing contracts
stack
*
Stack
// non-persistent key/value memory storage
...
...
@@ -617,48 +616,59 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
case
CREATE
:
require
(
3
)
value
:=
stack
.
Pop
()
size
,
offset
:=
stack
.
Popn
()
var
(
err
error
value
=
stack
.
Pop
()
size
,
offset
=
stack
.
Popn
()
// Snapshot the current stack so we are able to
// revert back to it later.
snapshot
:=
vm
.
state
.
Copy
()
// Snapshot the current stack so we are able to
// revert back to it later.
snapshot
=
vm
.
state
.
Copy
()
)
// Generate a new address
addr
:=
ethcrypto
.
CreateAddress
(
closure
.
caller
.
Address
(),
closure
.
caller
.
N
())
addr
:=
ethcrypto
.
CreateAddress
(
closure
.
object
.
Address
(),
closure
.
object
.
Nonce
)
for
i
:=
uint64
(
0
);
vm
.
state
.
GetStateObject
(
addr
)
!=
nil
;
i
++
{
ethcrypto
.
CreateAddress
(
closure
.
object
.
Address
(),
closure
.
object
.
Nonce
+
i
)
}
closure
.
object
.
Nonce
++
vm
.
Printf
(
" (*) %x"
,
addr
)
.
Endl
()
// Create a new contract
contract
:=
vm
.
state
.
NewStateObject
(
addr
)
contract
.
Amount
=
value
// Set the init script
contract
.
initScript
=
ethutil
.
BigD
(
mem
.
Get
(
offset
.
Int64
(),
size
.
Int64
()))
.
Bytes
()
// Transfer all remaining gas to the new
// contract so it may run the init script
gas
:=
new
(
big
.
Int
)
.
Set
(
closure
.
Gas
)
// Create the closure
c
:=
NewClosure
(
closure
.
caller
,
closure
.
Object
(),
contract
.
initScript
,
vm
.
state
,
gas
,
closure
.
Price
)
// Call the closure and set the return value as
// main script.
var
err
error
c
.
Script
,
gas
,
err
=
c
.
Call
(
vm
,
nil
)
if
contract
.
Amount
.
Cmp
(
value
)
>=
0
{
closure
.
object
.
SubAmount
(
value
)
contract
.
AddAmount
(
value
)
// Set the init script
contract
.
initScript
=
mem
.
Get
(
offset
.
Int64
(),
size
.
Int64
())
// Transfer all remaining gas to the new
// contract so it may run the init script
gas
:=
new
(
big
.
Int
)
.
Set
(
closure
.
Gas
)
closure
.
UseGas
(
closure
.
Gas
)
// Create the closure
c
:=
NewClosure
(
closure
,
contract
,
contract
.
initScript
,
vm
.
state
,
gas
,
closure
.
Price
)
// Call the closure and set the return value as
// main script.
contract
.
script
,
err
,
_
=
Call
(
vm
,
c
,
nil
)
}
else
{
err
=
fmt
.
Errorf
(
"Insufficient funds to transfer value. Req %v, has %v"
,
value
,
closure
.
object
.
Amount
)
}
if
err
!=
nil
{
stack
.
Push
(
ethutil
.
BigFalse
)
// Revert the state as it was before.
vm
.
state
.
Set
(
snapshot
)
vm
.
Printf
(
"CREATE err %v"
,
err
)
}
else
{
stack
.
Push
(
ethutil
.
BigD
(
addr
))
vm
.
Printf
(
"CREATE success"
)
}
vm
.
Endl
()
case
CALL
:
require
(
7
)
...
...
ethcrypto/crypto.go
View file @
de2da4fd
...
...
@@ -3,8 +3,8 @@ package ethcrypto
import
(
"code.google.com/p/go.crypto/ripemd160"
"crypto/sha256"
"github.com/ethereum/eth-go/ethutil"
"github.com/obscuren/sha3"
"math/big"
)
func
Sha256Bin
(
data
[]
byte
)
[]
byte
{
...
...
@@ -28,8 +28,6 @@ func Sha3Bin(data []byte) []byte {
}
// Creates an ethereum address given the bytes and the nonce
func
CreateAddress
(
b
[]
byte
,
nonce
*
big
.
Int
)
[]
byte
{
addrBytes
:=
append
(
b
,
nonce
.
Bytes
()
...
)
return
Sha3Bin
(
addrBytes
)[
12
:
]
func
CreateAddress
(
b
[]
byte
,
nonce
uint64
)
[]
byte
{
return
Sha3Bin
(
ethutil
.
NewValue
([]
interface
{}{
b
,
nonce
})
.
Encode
())[
12
:
]
}
ethtrie/trie.go
View file @
de2da4fd
package
ethtrie
import
(
"bytes"
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethutil"
...
...
@@ -8,6 +9,19 @@ import (
"sync"
)
func
ParanoiaCheck
(
t1
*
Trie
)
(
bool
,
*
Trie
)
{
t2
:=
NewTrie
(
ethutil
.
Config
.
Db
,
""
)
t1
.
NewIterator
()
.
Each
(
func
(
key
string
,
v
*
ethutil
.
Value
)
{
t2
.
Update
(
key
,
v
.
Str
())
})
a
:=
ethutil
.
NewValue
(
t2
.
Root
)
.
Bytes
()
b
:=
ethutil
.
NewValue
(
t1
.
Root
)
.
Bytes
()
return
bytes
.
Compare
(
a
,
b
)
==
0
,
t2
}
func
(
s
*
Cache
)
Len
()
int
{
return
len
(
s
.
nodes
)
}
...
...
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