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
0415e4a6
Commit
0415e4a6
authored
Jul 17, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed coinbase copy in state
parent
ed3424ff
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
19 deletions
+29
-19
state.go
ethchain/state.go
+2
-1
state_manager.go
ethchain/state_manager.go
+3
-1
state_object.go
ethchain/state_object.go
+6
-3
state_transition.go
ethchain/state_transition.go
+17
-13
vm.go
ethchain/vm.go
+1
-1
No files found.
ethchain/state.go
View file @
0415e4a6
...
...
@@ -61,6 +61,7 @@ func (self *State) UpdateStateObject(stateObject *StateObject) {
addr
:=
stateObject
.
Address
()
ethutil
.
Config
.
Db
.
Put
(
ethcrypto
.
Sha3Bin
(
stateObject
.
Script
()),
stateObject
.
Script
())
fmt
.
Printf
(
"balance %v %p
\n
"
,
stateObject
.
Amount
,
stateObject
)
self
.
trie
.
Update
(
string
(
addr
),
string
(
stateObject
.
RlpEncode
()))
...
...
@@ -174,7 +175,7 @@ func (s *State) Reset() {
func
(
s
*
State
)
Sync
()
{
// Sync all nested states
for
_
,
stateObject
:=
range
s
.
stateObjects
{
s
.
UpdateStateObject
(
stateObject
)
//
s.UpdateStateObject(stateObject)
if
stateObject
.
state
==
nil
{
continue
...
...
ethchain/state_manager.go
View file @
0415e4a6
...
...
@@ -120,7 +120,9 @@ func (self *StateManager) ProcessTransactions(coinbase *StateObject, state *Stat
done
:
for
i
,
tx
:=
range
txs
{
txGas
:=
new
(
big
.
Int
)
.
Set
(
tx
.
Gas
)
st
:=
NewStateTransition
(
coinbase
,
tx
,
state
,
block
)
cb
:=
state
.
GetStateObject
(
coinbase
.
Address
())
st
:=
NewStateTransition
(
cb
,
tx
,
state
,
block
)
//fmt.Printf("#%d\n", i+1)
err
=
st
.
TransitionState
()
if
err
!=
nil
{
...
...
ethchain/state_object.go
View file @
0415e4a6
...
...
@@ -80,6 +80,7 @@ func NewStateObject(addr []byte) *StateObject {
object
:=
&
StateObject
{
address
:
address
,
Amount
:
new
(
big
.
Int
),
gasPool
:
new
(
big
.
Int
)}
object
.
state
=
NewState
(
ethtrie
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
))
object
.
storage
=
make
(
Storage
)
object
.
gasPool
=
new
(
big
.
Int
)
return
object
}
...
...
@@ -183,7 +184,7 @@ func (self *StateObject) Sync() {
fmt.Printf("%x %x %x\n", self.Address(), []byte(key), value.Bytes())
})
*/
//
fmt.Printf("%x @:%x\n", self.Address(), self.state.Root())
fmt
.
Printf
(
"%x @:%x
\n
"
,
self
.
Address
(),
self
.
state
.
Root
())
}
func
(
c
*
StateObject
)
GetInstr
(
pc
*
big
.
Int
)
*
ethutil
.
Value
{
...
...
@@ -197,13 +198,13 @@ func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
func
(
c
*
StateObject
)
AddAmount
(
amount
*
big
.
Int
)
{
c
.
SetAmount
(
new
(
big
.
Int
)
.
Add
(
c
.
Amount
,
amount
))
statelogger
.
Debug
Detail
f
(
"%x: #%d %v (+ %v)
\n
"
,
c
.
Address
(),
c
.
Nonce
,
c
.
Amount
,
amount
)
statelogger
.
Debugf
(
"%x: #%d %v (+ %v)
\n
"
,
c
.
Address
(),
c
.
Nonce
,
c
.
Amount
,
amount
)
}
func
(
c
*
StateObject
)
SubAmount
(
amount
*
big
.
Int
)
{
c
.
SetAmount
(
new
(
big
.
Int
)
.
Sub
(
c
.
Amount
,
amount
))
statelogger
.
Debug
Detail
f
(
"%x: #%d %v (- %v)
\n
"
,
c
.
Address
(),
c
.
Nonce
,
c
.
Amount
,
amount
)
statelogger
.
Debugf
(
"%x: #%d %v (- %v)
\n
"
,
c
.
Address
(),
c
.
Nonce
,
c
.
Amount
,
amount
)
}
func
(
c
*
StateObject
)
SetAmount
(
amount
*
big
.
Int
)
{
...
...
@@ -266,6 +267,7 @@ func (self *StateObject) Copy() *StateObject {
stateObject
.
script
=
ethutil
.
CopyBytes
(
self
.
script
)
stateObject
.
initScript
=
ethutil
.
CopyBytes
(
self
.
initScript
)
stateObject
.
storage
=
self
.
storage
.
Copy
()
stateObject
.
gasPool
.
Set
(
self
.
gasPool
)
return
stateObject
}
...
...
@@ -324,6 +326,7 @@ func (c *StateObject) RlpDecode(data []byte) {
c
.
Amount
=
decoder
.
Get
(
1
)
.
BigInt
()
c
.
state
=
NewState
(
ethtrie
.
NewTrie
(
ethutil
.
Config
.
Db
,
decoder
.
Get
(
2
)
.
Interface
()))
c
.
storage
=
make
(
map
[
string
]
*
ethutil
.
Value
)
c
.
gasPool
=
new
(
big
.
Int
)
c
.
ScriptHash
=
decoder
.
Get
(
3
)
.
Bytes
()
...
...
ethchain/state_transition.go
View file @
0415e4a6
...
...
@@ -42,7 +42,7 @@ func (self *StateTransition) Coinbase() *StateObject {
return
self
.
cb
}
self
.
cb
=
self
.
state
.
Get
Accoun
t
(
self
.
coinbase
)
self
.
cb
=
self
.
state
.
Get
OrNewStateObjec
t
(
self
.
coinbase
)
return
self
.
cb
}
func
(
self
*
StateTransition
)
Sender
()
*
StateObject
{
...
...
@@ -50,7 +50,7 @@ func (self *StateTransition) Sender() *StateObject {
return
self
.
sen
}
self
.
sen
=
self
.
state
.
Get
Accoun
t
(
self
.
tx
.
Sender
())
self
.
sen
=
self
.
state
.
Get
OrNewStateObjec
t
(
self
.
tx
.
Sender
())
return
self
.
sen
}
...
...
@@ -63,7 +63,7 @@ func (self *StateTransition) Receiver() *StateObject {
return
self
.
rec
}
self
.
rec
=
self
.
state
.
Get
Accoun
t
(
self
.
tx
.
Recipient
)
self
.
rec
=
self
.
state
.
Get
OrNewStateObjec
t
(
self
.
tx
.
Recipient
)
return
self
.
rec
}
...
...
@@ -174,13 +174,16 @@ func (self *StateTransition) TransitionState() (err error) {
return
}
/* FIXME
* If tx goes TO "0", goes OOG during init, reverse changes, but initial endowment should happen. The ether is lost forever
*/
var
snapshot
*
State
if
sender
.
Amount
.
Cmp
(
self
.
value
)
<
0
{
return
fmt
.
Errorf
(
"Insufficient funds to transfer value. Req %v, has %v"
,
self
.
value
,
sender
.
Amount
)
}
var
snapshot
*
State
// If the receiver is nil it's a contract (\0*32).
if
tx
.
CreatesContract
()
{
// Subtract the (irreversible) amount from the senders account
sender
.
SubAmount
(
self
.
value
)
snapshot
=
self
.
state
.
Copy
()
// Create a new state object for the contract
...
...
@@ -189,16 +192,17 @@ func (self *StateTransition) TransitionState() (err error) {
if
receiver
==
nil
{
return
fmt
.
Errorf
(
"Unable to create contract"
)
}
// Add the amount to receivers account which should conclude this transaction
receiver
.
AddAmount
(
self
.
value
)
}
else
{
receiver
=
self
.
Receiver
()
}
// Transfer value from sender to receiver
if
err
=
self
.
transferValue
(
sender
,
receiver
);
err
!=
nil
{
retur
n
}
// Subtract the amount from the senders account
sender
.
SubAmount
(
self
.
value
)
// Add the amount to receivers account which should conclude this transactio
n
receiver
.
AddAmount
(
self
.
value
)
if
snapshot
==
nil
{
snapshot
=
self
.
state
.
Copy
()
}
...
...
ethchain/vm.go
View file @
0415e4a6
...
...
@@ -456,7 +456,7 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
case
BYTE
:
require
(
2
)
val
,
th
:=
stack
.
Popn
()
if
th
.
Cmp
(
big
.
NewInt
(
32
))
<
0
{
if
th
.
Cmp
(
big
.
NewInt
(
32
))
<
0
&&
th
.
Cmp
(
big
.
NewInt
(
int64
(
len
(
val
.
Bytes
()))))
<
0
{
byt
:=
big
.
NewInt
(
int64
(
val
.
Bytes
()[
th
.
Int64
()]))
stack
.
Push
(
byt
)
...
...
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