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
13cc220c
Commit
13cc220c
authored
Jul 21, 2014
by
zelig
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of github.com:ethereum/eth-go into feature/ethutil-refactor
parents
1e4af85a
8f91d47b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
68 additions
and
33 deletions
+68
-33
block.go
ethchain/block.go
+28
-5
state.go
ethchain/state.go
+2
-12
state_manager.go
ethchain/state_manager.go
+8
-13
state_object.go
ethchain/state_object.go
+26
-0
vm.go
ethchain/vm.go
+1
-1
miner.go
ethminer/miner.go
+1
-0
types.go
ethpub/types.go
+2
-2
No files found.
ethchain/block.go
View file @
13cc220c
...
...
@@ -7,7 +7,7 @@ import (
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
"math/big"
"strconv"
_
"strconv"
"time"
)
...
...
@@ -252,20 +252,43 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) {
func
(
block
*
Block
)
setTransactions
(
txs
[]
*
Transaction
)
{
block
.
transactions
=
txs
/*
trie := ethtrie.NewTrie(ethutil.Config.Db, "")
for i, tx := range txs {
trie.Update(strconv.Itoa(i), string(tx.RlpEncode()))
}
switch trie.Root.(type) {
case string:
block.TxSha = []byte(trie.Root.(string))
case []byte:
block.TxSha = trie.Root.([]byte)
default:
panic(fmt.Sprintf("invalid root type %T", trie.Root))
}
*/
}
func
CreateTxSha
(
receipts
Receipts
)
(
sha
[]
byte
)
{
trie
:=
ethtrie
.
NewTrie
(
ethutil
.
Config
.
Db
,
""
)
for
i
,
tx
:=
range
tx
s
{
trie
.
Update
(
str
conv
.
Itoa
(
i
),
string
(
tx
.
Rlp
Encode
()))
for
i
,
receipt
:=
range
receipt
s
{
trie
.
Update
(
str
ing
(
ethutil
.
NewValue
(
i
)
.
Encode
()),
string
(
ethutil
.
NewValue
(
receipt
.
RlpData
())
.
Encode
()))
}
switch
trie
.
Root
.
(
type
)
{
case
string
:
block
.
TxS
ha
=
[]
byte
(
trie
.
Root
.
(
string
))
s
ha
=
[]
byte
(
trie
.
Root
.
(
string
))
case
[]
byte
:
block
.
TxS
ha
=
trie
.
Root
.
([]
byte
)
s
ha
=
trie
.
Root
.
([]
byte
)
default
:
panic
(
fmt
.
Sprintf
(
"invalid root type %T"
,
trie
.
Root
))
}
return
sha
}
func
(
self
*
Block
)
SetTxHash
(
receipts
Receipts
)
{
self
.
TxSha
=
CreateTxSha
(
receipts
)
}
func
(
block
*
Block
)
Value
()
*
ethutil
.
Value
{
...
...
ethchain/state.go
View file @
13cc220c
package
ethchain
import
(
"fmt"
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
...
...
@@ -27,12 +26,6 @@ func NewState(trie *ethtrie.Trie) *State {
return
&
State
{
trie
:
trie
,
stateObjects
:
make
(
map
[
string
]
*
StateObject
),
manifest
:
NewManifest
()}
}
// Iterate over each storage address and yield callback
func
(
s
*
State
)
EachStorage
(
cb
ethtrie
.
EachCallback
)
{
it
:=
s
.
trie
.
NewIterator
()
it
.
Each
(
cb
)
}
// Retrieve the balance from the given address or 0 if object not found
func
(
self
*
State
)
GetBalance
(
addr
[]
byte
)
*
big
.
Int
{
stateObject
:=
self
.
GetStateObject
(
addr
)
...
...
@@ -214,11 +207,8 @@ func (self *State) Update() {
// Debug stuff
func
(
self
*
State
)
CreateOutputForDiff
()
{
for
addr
,
stateObject
:=
range
self
.
stateObjects
{
fmt
.
Printf
(
"%x %x %x %x
\n
"
,
addr
,
stateObject
.
state
.
Root
(),
stateObject
.
Amount
.
Bytes
(),
stateObject
.
Nonce
)
stateObject
.
state
.
EachStorage
(
func
(
addr
string
,
value
*
ethutil
.
Value
)
{
fmt
.
Printf
(
"%x %x
\n
"
,
addr
,
value
.
Bytes
())
})
for
_
,
stateObject
:=
range
self
.
stateObjects
{
stateObject
.
CreateOutputForDiff
()
}
}
...
...
ethchain/state_manager.go
View file @
13cc220c
...
...
@@ -201,11 +201,16 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
fmt
.
Printf
(
"## %x %x ##
\n
"
,
block
.
Hash
(),
block
.
Number
)
}
_
,
err
=
sm
.
ApplyDiff
(
state
,
parent
,
block
)
receipts
,
err
:
=
sm
.
ApplyDiff
(
state
,
parent
,
block
)
if
err
!=
nil
{
return
err
}
txSha
:=
CreateTxSha
(
receipts
)
if
bytes
.
Compare
(
txSha
,
block
.
TxSha
)
!=
0
{
return
fmt
.
Errorf
(
"Error validating tx sha. Received %x, got %x"
,
block
.
TxSha
,
txSha
)
}
// Block validation
if
err
=
sm
.
ValidateBlock
(
block
);
err
!=
nil
{
statelogger
.
Errorln
(
"Error validating block:"
,
err
)
...
...
@@ -219,17 +224,7 @@ 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
}
...
...
@@ -312,9 +307,9 @@ func (sm *StateManager) ValidateBlock(block *Block) error {
}
}
diff
:=
block
.
Time
-
sm
.
bc
.
Current
Block
.
Time
diff
:=
block
.
Time
-
previous
Block
.
Time
if
diff
<
0
{
return
ValidationError
(
"Block timestamp less then prev block %v
"
,
diff
)
return
ValidationError
(
"Block timestamp less then prev block %v
(%v - %v)"
,
diff
,
block
.
Time
,
sm
.
bc
.
CurrentBlock
.
Time
)
}
/* XXX
...
...
ethchain/state_object.go
View file @
13cc220c
...
...
@@ -151,6 +151,24 @@ func (self *StateObject) setStorage(k []byte, value *ethutil.Value) {
*/
}
// Iterate over each storage address and yield callback
func
(
self
*
StateObject
)
EachStorage
(
cb
ethtrie
.
EachCallback
)
{
// First loop over the uncommit/cached values in storage
for
key
,
value
:=
range
self
.
storage
{
// XXX Most iterators Fns as it stands require encoded values
encoded
:=
ethutil
.
NewValue
(
value
.
Encode
())
cb
(
key
,
encoded
)
}
it
:=
self
.
state
.
trie
.
NewIterator
()
it
.
Each
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
// If it's cached don't call the callback.
if
self
.
storage
[
key
]
==
nil
{
cb
(
key
,
value
)
}
})
}
func
(
self
*
StateObject
)
Sync
()
{
/*
fmt.Println("############# BEFORE ################")
...
...
@@ -303,6 +321,14 @@ func (c *StateObject) Init() Code {
return
c
.
initScript
}
// Debug stuff
func
(
self
*
StateObject
)
CreateOutputForDiff
()
{
fmt
.
Printf
(
"%x %x %x %x
\n
"
,
self
.
Address
(),
self
.
state
.
Root
(),
self
.
Amount
.
Bytes
(),
self
.
Nonce
)
self
.
EachStorage
(
func
(
addr
string
,
value
*
ethutil
.
Value
)
{
fmt
.
Printf
(
"%x %x
\n
"
,
addr
,
value
.
Bytes
())
})
}
//
// Encoding
//
...
...
ethchain/vm.go
View file @
13cc220c
...
...
@@ -158,7 +158,7 @@ func (vm *Vm) RunClosure(closure *Closure) (ret []byte, err error) {
switch
op
{
case
STOP
,
RETURN
,
SUICIDE
:
closure
.
object
.
Sync
()
closure
.
object
.
state
.
EachStorage
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
closure
.
object
.
EachStorage
(
func
(
key
string
,
value
*
ethutil
.
Value
)
{
value
.
Decode
()
fmt
.
Printf
(
"%x %x
\n
"
,
new
(
big
.
Int
)
.
SetBytes
([]
byte
(
key
))
.
Bytes
(),
value
.
Bytes
())
})
...
...
ethminer/miner.go
View file @
13cc220c
...
...
@@ -172,6 +172,7 @@ func (self *Miner) mineNewBlock() {
logger
.
Debugln
(
err
)
}
self
.
txs
=
append
(
txs
,
unhandledTxs
...
)
self
.
block
.
SetTxHash
(
receipts
)
// Set the transactions to the block so the new SHA3 can be calculated
self
.
block
.
SetReceipts
(
receipts
,
txs
)
...
...
ethpub/types.go
View file @
13cc220c
...
...
@@ -215,7 +215,7 @@ func (c *PStateObject) IsContract() bool {
}
func
(
self
*
PStateObject
)
EachStorage
(
cb
ethtrie
.
EachCallback
)
{
self
.
object
.
State
()
.
EachStorage
(
cb
)
self
.
object
.
EachStorage
(
cb
)
}
type
KeyVal
struct
{
...
...
@@ -226,7 +226,7 @@ type KeyVal struct {
func
(
c
*
PStateObject
)
StateKeyVal
(
asJson
bool
)
interface
{}
{
var
values
[]
KeyVal
if
c
.
object
!=
nil
{
c
.
object
.
State
()
.
EachStorage
(
func
(
name
string
,
value
*
ethutil
.
Value
)
{
c
.
object
.
EachStorage
(
func
(
name
string
,
value
*
ethutil
.
Value
)
{
values
=
append
(
values
,
KeyVal
{
name
,
ethutil
.
Bytes2Hex
(
value
.
Bytes
())})
})
}
...
...
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