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
fb4113da
Commit
fb4113da
authored
Oct 29, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PoC 7 updates
* Bloom * Block restructure * Receipts
parent
665a4464
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
219 additions
and
135 deletions
+219
-135
block.go
ethchain/block.go
+75
-69
bloom9.go
ethchain/bloom9.go
+19
-12
chain_manager.go
ethchain/chain_manager.go
+2
-2
filter.go
ethchain/filter.go
+8
-8
genesis.go
ethchain/genesis.go
+8
-3
state_manager.go
ethchain/state_manager.go
+17
-9
state_transition.go
ethchain/state_transition.go
+2
-8
transaction.go
ethchain/transaction.go
+33
-19
miner.go
ethminer/miner.go
+1
-1
trie.go
ethtrie/trie.go
+11
-0
rlp.go
ethutil/rlp.go
+6
-0
value.go
ethutil/value.go
+4
-0
log.go
vm/log.go
+31
-2
vm_debug.go
vm/vm_debug.go
+2
-2
No files found.
ethchain/block.go
View file @
fb4113da
...
@@ -96,9 +96,10 @@ type Block struct {
...
@@ -96,9 +96,10 @@ type Block struct {
// Block Nonce for verification
// Block Nonce for verification
Nonce
ethutil
.
Bytes
Nonce
ethutil
.
Bytes
// List of transactions and/or contracts
// List of transactions and/or contracts
transactions
[]
*
Transaction
transactions
Transactions
receipts
[]
*
Receipt
receipts
Receipts
TxSha
[]
byte
TxSha
,
ReceiptSha
[]
byte
LogsBloom
[]
byte
}
}
func
NewBlockFromBytes
(
raw
[]
byte
)
*
Block
{
func
NewBlockFromBytes
(
raw
[]
byte
)
*
Block
{
...
@@ -151,7 +152,7 @@ func (block *Block) Hash() ethutil.Bytes {
...
@@ -151,7 +152,7 @@ func (block *Block) Hash() ethutil.Bytes {
func
(
block
*
Block
)
HashNoNonce
()
[]
byte
{
func
(
block
*
Block
)
HashNoNonce
()
[]
byte
{
return
ethcrypto
.
Sha3
(
ethutil
.
Encode
([]
interface
{}{
block
.
PrevHash
,
return
ethcrypto
.
Sha3
(
ethutil
.
Encode
([]
interface
{}{
block
.
PrevHash
,
block
.
UncleSha
,
block
.
Coinbase
,
block
.
state
.
Trie
.
Root
,
block
.
UncleSha
,
block
.
Coinbase
,
block
.
state
.
Trie
.
Root
,
block
.
Tx
Sha
,
block
.
Difficulty
,
block
.
Number
,
block
.
MinGasPrice
,
block
.
Receipt
Sha
,
block
.
Difficulty
,
block
.
Number
,
block
.
MinGasPrice
,
block
.
GasLimit
,
block
.
GasUsed
,
block
.
Time
,
block
.
Extra
}))
block
.
GasLimit
,
block
.
GasUsed
,
block
.
Time
,
block
.
Extra
}))
}
}
...
@@ -191,9 +192,9 @@ func (block *Block) BlockInfo() BlockInfo {
...
@@ -191,9 +192,9 @@ func (block *Block) BlockInfo() BlockInfo {
}
}
func
(
self
*
Block
)
GetTransaction
(
hash
[]
byte
)
*
Transaction
{
func
(
self
*
Block
)
GetTransaction
(
hash
[]
byte
)
*
Transaction
{
for
_
,
receipt
:=
range
self
.
receipt
s
{
for
_
,
tx
:=
range
self
.
transaction
s
{
if
bytes
.
Compare
(
receipt
.
T
x
.
Hash
(),
hash
)
==
0
{
if
bytes
.
Compare
(
t
x
.
Hash
(),
hash
)
==
0
{
return
receipt
.
T
x
return
t
x
}
}
}
}
...
@@ -236,10 +237,7 @@ func (block *Block) rlpUncles() interface{} {
...
@@ -236,10 +237,7 @@ func (block *Block) rlpUncles() interface{} {
func
(
block
*
Block
)
SetUncles
(
uncles
[]
*
Block
)
{
func
(
block
*
Block
)
SetUncles
(
uncles
[]
*
Block
)
{
block
.
Uncles
=
uncles
block
.
Uncles
=
uncles
// Sha of the concatenated uncles
block
.
UncleSha
=
ethcrypto
.
Sha3
(
ethutil
.
Encode
(
block
.
rlpUncles
()))
if
len
(
uncles
)
>
0
{
block
.
UncleSha
=
ethcrypto
.
Sha3
(
ethutil
.
Encode
(
block
.
rlpUncles
()))
}
}
}
func
(
self
*
Block
)
SetReceipts
(
receipts
[]
*
Receipt
,
txs
[]
*
Transaction
)
{
func
(
self
*
Block
)
SetReceipts
(
receipts
[]
*
Receipt
,
txs
[]
*
Transaction
)
{
...
@@ -249,32 +247,20 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) {
...
@@ -249,32 +247,20 @@ func (self *Block) SetReceipts(receipts []*Receipt, txs []*Transaction) {
func
(
block
*
Block
)
setTransactions
(
txs
[]
*
Transaction
)
{
func
(
block
*
Block
)
setTransactions
(
txs
[]
*
Transaction
)
{
block
.
transactions
=
txs
block
.
transactions
=
txs
}
func
CreateTxSha
(
receipts
Receipts
)
(
sha
[]
byte
)
{
trie
:=
ethtrie
.
New
(
ethutil
.
Config
.
Db
,
""
)
for
i
,
receipt
:=
range
receipts
{
trie
.
Update
(
string
(
ethutil
.
NewValue
(
i
)
.
Encode
()),
string
(
ethutil
.
NewValue
(
receipt
.
RlpData
())
.
Encode
()))
}
switch
trie
.
Root
.
(
type
)
{
block
.
LogsBloom
=
CreateBloom
(
txs
)
case
string
:
}
sha
=
[]
byte
(
trie
.
Root
.
(
string
))
case
[]
byte
:
sha
=
trie
.
Root
.
([]
byte
)
default
:
panic
(
fmt
.
Sprintf
(
"invalid root type %T"
,
trie
.
Root
))
}
return
sha
func
(
self
*
Block
)
SetTransactionHash
(
transactions
Transactions
)
{
self
.
TxSha
=
DeriveSha
(
transactions
)
}
}
func
(
self
*
Block
)
Set
Tx
Hash
(
receipts
Receipts
)
{
func
(
self
*
Block
)
Set
Receipt
Hash
(
receipts
Receipts
)
{
self
.
TxSha
=
CreateTx
Sha
(
receipts
)
self
.
ReceiptSha
=
Derive
Sha
(
receipts
)
}
}
func
(
block
*
Block
)
Value
()
*
ethutil
.
Value
{
func
(
block
*
Block
)
Value
()
*
ethutil
.
Value
{
return
ethutil
.
NewValue
([]
interface
{}{
block
.
header
(),
block
.
rlpReceipts
()
,
block
.
rlpUncles
()})
return
ethutil
.
NewValue
([]
interface
{}{
block
.
header
(),
block
.
transactions
,
block
.
rlpUncles
()})
}
}
func
(
block
*
Block
)
RlpEncode
()
[]
byte
{
func
(
block
*
Block
)
RlpEncode
()
[]
byte
{
...
@@ -289,33 +275,20 @@ func (block *Block) RlpDecode(data []byte) {
...
@@ -289,33 +275,20 @@ func (block *Block) RlpDecode(data []byte) {
}
}
func
(
block
*
Block
)
RlpValueDecode
(
decoder
*
ethutil
.
Value
)
{
func
(
block
*
Block
)
RlpValueDecode
(
decoder
*
ethutil
.
Value
)
{
header
:=
decoder
.
Get
(
0
)
block
.
setHeader
(
decoder
.
Get
(
0
))
block
.
PrevHash
=
header
.
Get
(
0
)
.
Bytes
()
block
.
UncleSha
=
header
.
Get
(
1
)
.
Bytes
()
block
.
Coinbase
=
header
.
Get
(
2
)
.
Bytes
()
block
.
state
=
ethstate
.
New
(
ethtrie
.
New
(
ethutil
.
Config
.
Db
,
header
.
Get
(
3
)
.
Val
))
block
.
TxSha
=
header
.
Get
(
4
)
.
Bytes
()
block
.
Difficulty
=
header
.
Get
(
5
)
.
BigInt
()
block
.
Number
=
header
.
Get
(
6
)
.
BigInt
()
//fmt.Printf("#%v : %x\n", block.Number, block.Coinbase)
block
.
MinGasPrice
=
header
.
Get
(
7
)
.
BigInt
()
block
.
GasLimit
=
header
.
Get
(
8
)
.
BigInt
()
block
.
GasUsed
=
header
.
Get
(
9
)
.
BigInt
()
block
.
Time
=
int64
(
header
.
Get
(
10
)
.
BigInt
()
.
Uint64
())
block
.
Extra
=
header
.
Get
(
11
)
.
Str
()
block
.
Nonce
=
header
.
Get
(
12
)
.
Bytes
()
// Tx list might be empty if this is an uncle. Uncles only have their
// Tx list might be empty if this is an uncle. Uncles only have their
// header set.
// header set.
if
decoder
.
Get
(
1
)
.
IsNil
()
==
false
{
// Yes explicitness
if
decoder
.
Get
(
1
)
.
IsNil
()
==
false
{
// Yes explicitness
receipts
:=
decoder
.
Get
(
1
)
//receipts := decoder.Get(1)
block
.
transactions
=
make
([]
*
Transaction
,
receipts
.
Len
())
//block.receipts = make([]*Receipt, receipts.Len())
block
.
receipts
=
make
([]
*
Receipt
,
receipts
.
Len
())
it
:=
decoder
.
Get
(
1
)
.
NewIterator
()
for
i
:=
0
;
i
<
receipts
.
Len
();
i
++
{
block
.
transactions
=
make
(
Transactions
,
it
.
Len
())
receipt
:=
NewRecieptFromValue
(
receipts
.
Get
(
i
))
for
it
.
Next
()
{
block
.
transactions
[
i
]
=
receipt
.
Tx
block
.
transactions
[
it
.
Idx
()]
=
NewTransactionFromValue
(
it
.
Value
())
block
.
receipts
[
i
]
=
receipt
//receipt := NewRecieptFromValue(receipts.Get(i))
//block.transactions[i] = receipt.Tx
//block.receipts[i] = receipt
}
}
}
}
...
@@ -330,22 +303,27 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) {
...
@@ -330,22 +303,27 @@ func (block *Block) RlpValueDecode(decoder *ethutil.Value) {
}
}
func
(
self
*
Block
)
setHeader
(
header
*
ethutil
.
Value
)
{
self
.
PrevHash
=
header
.
Get
(
0
)
.
Bytes
()
self
.
UncleSha
=
header
.
Get
(
1
)
.
Bytes
()
self
.
Coinbase
=
header
.
Get
(
2
)
.
Bytes
()
self
.
state
=
ethstate
.
New
(
ethtrie
.
New
(
ethutil
.
Config
.
Db
,
header
.
Get
(
3
)
.
Val
))
self
.
TxSha
=
header
.
Get
(
4
)
.
Bytes
()
self
.
ReceiptSha
=
header
.
Get
(
5
)
.
Bytes
()
self
.
LogsBloom
=
header
.
Get
(
6
)
.
Bytes
()
self
.
Difficulty
=
header
.
Get
(
7
)
.
BigInt
()
self
.
Number
=
header
.
Get
(
8
)
.
BigInt
()
self
.
MinGasPrice
=
header
.
Get
(
9
)
.
BigInt
()
self
.
GasLimit
=
header
.
Get
(
10
)
.
BigInt
()
self
.
GasUsed
=
header
.
Get
(
11
)
.
BigInt
()
self
.
Time
=
int64
(
header
.
Get
(
12
)
.
BigInt
()
.
Uint64
())
self
.
Extra
=
header
.
Get
(
13
)
.
Str
()
self
.
Nonce
=
header
.
Get
(
14
)
.
Bytes
()
}
func
NewUncleBlockFromValue
(
header
*
ethutil
.
Value
)
*
Block
{
func
NewUncleBlockFromValue
(
header
*
ethutil
.
Value
)
*
Block
{
block
:=
&
Block
{}
block
:=
&
Block
{}
block
.
setHeader
(
header
)
block
.
PrevHash
=
header
.
Get
(
0
)
.
Bytes
()
block
.
UncleSha
=
header
.
Get
(
1
)
.
Bytes
()
block
.
Coinbase
=
header
.
Get
(
2
)
.
Bytes
()
block
.
state
=
ethstate
.
New
(
ethtrie
.
New
(
ethutil
.
Config
.
Db
,
header
.
Get
(
3
)
.
Val
))
block
.
TxSha
=
header
.
Get
(
4
)
.
Bytes
()
block
.
Difficulty
=
header
.
Get
(
5
)
.
BigInt
()
block
.
Number
=
header
.
Get
(
6
)
.
BigInt
()
block
.
MinGasPrice
=
header
.
Get
(
7
)
.
BigInt
()
block
.
GasLimit
=
header
.
Get
(
8
)
.
BigInt
()
block
.
GasUsed
=
header
.
Get
(
9
)
.
BigInt
()
block
.
Time
=
int64
(
header
.
Get
(
10
)
.
BigInt
()
.
Uint64
())
block
.
Extra
=
header
.
Get
(
11
)
.
Str
()
block
.
Nonce
=
header
.
Get
(
12
)
.
Bytes
()
return
block
return
block
}
}
...
@@ -376,8 +354,12 @@ func (block *Block) header() []interface{} {
...
@@ -376,8 +354,12 @@ func (block *Block) header() []interface{} {
block
.
Coinbase
,
block
.
Coinbase
,
// root state
// root state
block
.
state
.
Trie
.
Root
,
block
.
state
.
Trie
.
Root
,
//
Sha of tx
//
tx root
block
.
TxSha
,
block
.
TxSha
,
// Sha of tx
block
.
ReceiptSha
,
// Bloom
block
.
LogsBloom
,
// Current block Difficulty
// Current block Difficulty
block
.
Difficulty
,
block
.
Difficulty
,
// The block number
// The block number
...
@@ -404,7 +386,9 @@ func (block *Block) String() string {
...
@@ -404,7 +386,9 @@ func (block *Block) String() string {
UncleSha: %x
UncleSha: %x
Coinbase: %x
Coinbase: %x
Root: %x
Root: %x
TxSha: %x
TxSha %x
ReceiptSha: %x
Bloom: %x
Difficulty: %v
Difficulty: %v
Number: %v
Number: %v
MinGas: %v
MinGas: %v
...
@@ -422,6 +406,8 @@ func (block *Block) String() string {
...
@@ -422,6 +406,8 @@ func (block *Block) String() string {
block
.
Coinbase
,
block
.
Coinbase
,
block
.
state
.
Trie
.
Root
,
block
.
state
.
Trie
.
Root
,
block
.
TxSha
,
block
.
TxSha
,
block
.
ReceiptSha
,
block
.
LogsBloom
,
block
.
Difficulty
,
block
.
Difficulty
,
block
.
Number
,
block
.
Number
,
block
.
MinGasPrice
,
block
.
MinGasPrice
,
...
@@ -437,3 +423,23 @@ func (block *Block) String() string {
...
@@ -437,3 +423,23 @@ func (block *Block) String() string {
func
(
self
*
Block
)
Size
()
ethutil
.
StorageSize
{
func
(
self
*
Block
)
Size
()
ethutil
.
StorageSize
{
return
ethutil
.
StorageSize
(
len
(
self
.
RlpEncode
()))
return
ethutil
.
StorageSize
(
len
(
self
.
RlpEncode
()))
}
}
/*
func DeriveReceiptHash(receipts Receipts) (sha []byte) {
trie := ethtrie.New(ethutil.Config.Db, "")
for i, receipt := range receipts {
trie.Update(string(ethutil.NewValue(i).Encode()), string(ethutil.NewValue(receipt.RlpData()).Encode()))
}
switch trie.Root.(type) {
case string:
sha = []byte(trie.Root.(string))
case []byte:
sha = trie.Root.([]byte)
default:
panic(fmt.Sprintf("invalid root type %T", trie.Root))
}
return sha
}
*/
ethchain/bloom9.go
View file @
fb4113da
package
ethchain
package
ethchain
import
"github.com/ethereum/go-ethereum/vm"
import
(
"math/big"
func
CreateBloom
(
txs
Transactions
)
uint64
{
"github.com/ethereum/go-ethereum/vm"
var
bin
uint64
)
func
CreateBloom
(
txs
Transactions
)
[]
byte
{
bin
:=
new
(
big
.
Int
)
for
_
,
tx
:=
range
txs
{
for
_
,
tx
:=
range
txs
{
bin
|=
logsBloom
(
tx
.
logs
)
bin
.
Or
(
bin
,
LogsBloom
(
tx
.
logs
)
)
}
}
return
bin
return
bin
.
Bytes
()
}
}
func
logsBloom
(
logs
[]
vm
.
Log
)
uint64
{
func
LogsBloom
(
logs
[]
vm
.
Log
)
*
big
.
Int
{
var
bin
uint64
bin
:=
new
(
big
.
Int
)
for
_
,
log
:=
range
logs
{
for
_
,
log
:=
range
logs
{
data
:=
[][]
byte
{
log
.
Address
}
data
:=
[][]
byte
{
log
.
Address
}
for
_
,
topic
:=
range
log
.
Topics
{
for
_
,
topic
:=
range
log
.
Topics
{
data
=
append
(
data
,
topic
.
Bytes
()
)
data
=
append
(
data
,
topic
)
}
}
data
=
append
(
data
,
log
.
Data
)
data
=
append
(
data
,
log
.
Data
)
for
_
,
b
:=
range
data
{
for
_
,
b
:=
range
data
{
bin
|=
bloom9
(
b
)
bin
.
Or
(
bin
,
bloom9
(
b
)
)
}
}
}
}
return
bin
return
bin
}
}
func
bloom9
(
b
[]
byte
)
uint64
{
func
bloom9
(
b
[]
byte
)
*
big
.
Int
{
var
r
uint64
r
:=
new
(
big
.
Int
)
for
_
,
i
:=
range
[]
int
{
0
,
2
,
4
}
{
for
_
,
i
:=
range
[]
int
{
0
,
2
,
4
}
{
r
|=
1
<<
(
uint64
(
b
[
i
+
1
])
+
256
*
(
uint64
(
b
[
i
])
&
1
))
t
:=
big
.
NewInt
(
1
)
//r |= 1 << (uint64(b[i+1]) + 256*(uint64(b[i])&1))
r
.
Or
(
r
,
t
.
Rsh
(
t
,
uint
(
b
[
i
+
1
])
+
256
*
(
uint
(
b
[
i
])
&
1
)))
}
}
return
r
return
r
...
...
ethchain/chain_manager.go
View file @
fb4113da
...
@@ -87,8 +87,8 @@ func (bc *ChainManager) Reset() {
...
@@ -87,8 +87,8 @@ func (bc *ChainManager) Reset() {
bc
.
genesisBlock
.
state
.
Trie
.
Sync
()
bc
.
genesisBlock
.
state
.
Trie
.
Sync
()
// Prepare the genesis block
// Prepare the genesis block
bc
.
Add
(
bc
.
genesisBlock
)
bc
.
Add
(
bc
.
genesisBlock
)
fk
:=
append
([]
byte
(
"bloom"
),
bc
.
genesisBlock
.
Hash
()
...
)
//
fk := append([]byte("bloom"), bc.genesisBlock.Hash()...)
bc
.
Ethereum
.
Db
()
.
Put
(
fk
,
make
([]
byte
,
255
))
//
bc.Ethereum.Db().Put(fk, make([]byte, 255))
bc
.
CurrentBlock
=
bc
.
genesisBlock
bc
.
CurrentBlock
=
bc
.
genesisBlock
bc
.
SetTotalDifficulty
(
ethutil
.
Big
(
"0"
))
bc
.
SetTotalDifficulty
(
ethutil
.
Big
(
"0"
))
...
...
ethchain/filter.go
View file @
fb4113da
...
@@ -2,7 +2,6 @@ package ethchain
...
@@ -2,7 +2,6 @@ package ethchain
import
(
import
(
"bytes"
"bytes"
"fmt"
"math"
"math"
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethstate"
...
@@ -171,13 +170,14 @@ func (self *Filter) FilterMessages(msgs []*ethstate.Message) []*ethstate.Message
...
@@ -171,13 +170,14 @@ func (self *Filter) FilterMessages(msgs []*ethstate.Message) []*ethstate.Message
}
}
func
(
self
*
Filter
)
bloomFilter
(
block
*
Block
)
bool
{
func
(
self
*
Filter
)
bloomFilter
(
block
*
Block
)
bool
{
fk
:=
append
([]
byte
(
"bloom"
),
block
.
Hash
()
...
)
//fk := append([]byte("bloom"), block.Hash()...)
bin
,
err
:=
self
.
eth
.
Db
()
.
Get
(
fk
)
//bin, err := self.eth.Db().Get(fk)
if
err
!=
nil
{
//if err != nil {
fmt
.
Println
(
err
)
// fmt.Println(err)
}
//}
bloom
:=
NewBloomFilter
(
bin
)
// TODO update to the new bloom filter
bloom
:=
NewBloomFilter
(
nil
)
var
fromIncluded
,
toIncluded
bool
var
fromIncluded
,
toIncluded
bool
if
len
(
self
.
from
)
>
0
{
if
len
(
self
.
from
)
>
0
{
...
...
ethchain/genesis.go
View file @
fb4113da
...
@@ -13,19 +13,24 @@ import (
...
@@ -13,19 +13,24 @@ import (
var
ZeroHash256
=
make
([]
byte
,
32
)
var
ZeroHash256
=
make
([]
byte
,
32
)
var
ZeroHash160
=
make
([]
byte
,
20
)
var
ZeroHash160
=
make
([]
byte
,
20
)
var
ZeroHash512
=
make
([]
byte
,
64
)
var
EmptyShaList
=
ethcrypto
.
Sha3
(
ethutil
.
Encode
([]
interface
{}{}))
var
EmptyShaList
=
ethcrypto
.
Sha3
(
ethutil
.
Encode
([]
interface
{}{}))
var
GenesisHeader
=
[]
interface
{}{
var
GenesisHeader
=
[]
interface
{}{
// Previous hash (none)
// Previous hash (none)
ZeroHash256
,
ZeroHash256
,
// Empty uncles
// Empty uncles
""
,
EmptyShaList
,
// Coinbase
// Coinbase
ZeroHash160
,
ZeroHash160
,
// Root state
// Root state
""
,
EmptyShaList
,
// tx sha
// tx sha
""
,
EmptyShaList
,
// receipt list
EmptyShaList
,
// bloom
ZeroHash512
,
// Difficulty
// Difficulty
//ethutil.BigPow(2, 22),
//ethutil.BigPow(2, 22),
big
.
NewInt
(
131072
),
big
.
NewInt
(
131072
),
...
...
ethchain/state_manager.go
View file @
fb4113da
...
@@ -173,8 +173,9 @@ done:
...
@@ -173,8 +173,9 @@ done:
state
.
Update
()
state
.
Update
()
txGas
.
Sub
(
txGas
,
st
.
gas
)
txGas
.
Sub
(
txGas
,
st
.
gas
)
accumelative
:=
new
(
big
.
Int
)
.
Set
(
totalUsedGas
.
Add
(
totalUsedGas
,
txGas
))
cumulative
:=
new
(
big
.
Int
)
.
Set
(
totalUsedGas
.
Add
(
totalUsedGas
,
txGas
))
receipt
:=
&
Receipt
{
tx
,
ethutil
.
CopyBytes
(
state
.
Root
()
.
([]
byte
)),
accumelative
}
//receipt := &Receipt{tx, ethutil.CopyBytes(state.Root().([]byte)), accumelative}
receipt
:=
&
Receipt
{
ethutil
.
CopyBytes
(
state
.
Root
()
.
([]
byte
)),
cumulative
,
LogsBloom
(
tx
.
logs
)
.
Bytes
(),
tx
.
logs
}
if
i
<
len
(
block
.
Receipts
())
{
if
i
<
len
(
block
.
Receipts
())
{
original
:=
block
.
Receipts
()[
i
]
original
:=
block
.
Receipts
()[
i
]
...
@@ -183,7 +184,7 @@ done:
...
@@ -183,7 +184,7 @@ done:
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
err
:=
fmt
.
Errorf
(
"#%d receipt failed (r) %v ~ %x <=> (c) %v ~ %x (%x...)"
,
i
+
1
,
original
.
CumulativeGasUsed
,
original
.
PostState
[
0
:
4
],
receipt
.
CumulativeGasUsed
,
receipt
.
PostState
[
0
:
4
],
receipt
.
T
x
.
Hash
()[
0
:
4
])
err
:=
fmt
.
Errorf
(
"#%d receipt failed (r) %v ~ %x <=> (c) %v ~ %x (%x...)"
,
i
+
1
,
original
.
CumulativeGasUsed
,
original
.
PostState
[
0
:
4
],
receipt
.
CumulativeGasUsed
,
receipt
.
PostState
[
0
:
4
],
t
x
.
Hash
()[
0
:
4
])
return
nil
,
nil
,
nil
,
nil
,
err
return
nil
,
nil
,
nil
,
nil
,
err
}
}
...
@@ -235,14 +236,19 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
...
@@ -235,14 +236,19 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
fmt
.
Printf
(
"## %x %x ##
\n
"
,
block
.
Hash
(),
block
.
Number
)
fmt
.
Printf
(
"## %x %x ##
\n
"
,
block
.
Hash
(),
block
.
Number
)
}
}
txSha
:=
DeriveSha
(
block
.
transactions
)
if
bytes
.
Compare
(
txSha
,
block
.
TxSha
)
!=
0
{
return
fmt
.
Errorf
(
"Error validating transaction sha. Received %x, got %x"
,
block
.
ReceiptSha
,
txSha
)
}
receipts
,
err
:=
sm
.
ApplyDiff
(
state
,
parent
,
block
)
receipts
,
err
:=
sm
.
ApplyDiff
(
state
,
parent
,
block
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
txSha
:=
CreateTx
Sha
(
receipts
)
receiptSha
:=
Derive
Sha
(
receipts
)
if
bytes
.
Compare
(
txSha
,
block
.
Tx
Sha
)
!=
0
{
if
bytes
.
Compare
(
receiptSha
,
block
.
Receipt
Sha
)
!=
0
{
return
fmt
.
Errorf
(
"Error validating
tx sha. Received %x, got %x"
,
block
.
TxSha
,
tx
Sha
)
return
fmt
.
Errorf
(
"Error validating
receipt sha. Received %x, got %x"
,
block
.
ReceiptSha
,
receipt
Sha
)
}
}
// Block validation
// Block validation
...
@@ -271,13 +277,15 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
...
@@ -271,13 +277,15 @@ func (sm *StateManager) Process(block *Block, dontReact bool) (err error) {
// Add the block to the chain
// Add the block to the chain
sm
.
bc
.
Add
(
block
)
sm
.
bc
.
Add
(
block
)
// TODO at this point we should also insert LOGS in to a database
sm
.
transState
=
state
.
Copy
()
sm
.
transState
=
state
.
Copy
()
// Create a bloom bin for this block
// Create a bloom bin for this block
filter
:=
sm
.
createBloomFilter
(
state
)
//
filter := sm.createBloomFilter(state)
// Persist the data
// Persist the data
fk
:=
append
([]
byte
(
"bloom"
),
block
.
Hash
()
...
)
//
fk := append([]byte("bloom"), block.Hash()...)
sm
.
eth
.
Db
()
.
Put
(
fk
,
filter
.
Bin
())
//
sm.eth.Db().Put(fk, filter.Bin())
statelogger
.
Infof
(
"Imported block #%d (%x...)
\n
"
,
block
.
Number
,
block
.
Hash
()[
0
:
4
])
statelogger
.
Infof
(
"Imported block #%d (%x...)
\n
"
,
block
.
Number
,
block
.
Hash
()[
0
:
4
])
if
dontReact
==
false
{
if
dontReact
==
false
{
...
...
ethchain/state_transition.go
View file @
fb4113da
...
@@ -5,7 +5,6 @@ import (
...
@@ -5,7 +5,6 @@ import (
"math/big"
"math/big"
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethstate"
"github.com/ethereum/go-ethereum/ethtrie"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/vm"
"github.com/ethereum/go-ethereum/vm"
)
)
...
@@ -231,11 +230,9 @@ func (self *StateTransition) TransitionState() (err error) {
...
@@ -231,11 +230,9 @@ func (self *StateTransition) TransitionState() (err error) {
msg
.
Output
=
ret
msg
.
Output
=
ret
}
else
{
}
else
{
// Add default LOG
// Add default LOG. Default = big(sender.addr) + 1
// PUSH1 1 CALLER ADD LOG1
addr
:=
ethutil
.
BigD
(
sender
.
Address
())
addr
:=
ethutil
.
BigD
(
sender
.
Address
())
addr
.
Add
(
addr
,
ethutil
.
Big1
)
tx
.
addLog
(
vm
.
Log
{
sender
.
Address
(),
[][]
byte
{
addr
.
Add
(
addr
,
ethutil
.
Big1
)
.
Bytes
()},
nil
})
tx
.
addLog
(
vm
.
Log
{
sender
.
Address
(),
[]
*
big
.
Int
{
addr
},
nil
})
}
}
}
}
...
@@ -250,9 +247,7 @@ func (self *StateTransition) Eval(msg *ethstate.Message, script []byte, context
...
@@ -250,9 +247,7 @@ func (self *StateTransition) Eval(msg *ethstate.Message, script []byte, context
callerClosure
=
vm
.
NewClosure
(
msg
,
transactor
,
context
,
script
,
self
.
gas
,
self
.
gasPrice
)
callerClosure
=
vm
.
NewClosure
(
msg
,
transactor
,
context
,
script
,
self
.
gas
,
self
.
gasPrice
)
)
)
//vm := vm.New(env, vm.Type(ethutil.Config.VmType))
evm
:=
vm
.
New
(
env
,
vm
.
DebugVmTy
)
evm
:=
vm
.
New
(
env
,
vm
.
DebugVmTy
)
ret
,
_
,
err
=
callerClosure
.
Call
(
evm
,
self
.
tx
.
Data
)
ret
,
_
,
err
=
callerClosure
.
Call
(
evm
,
self
.
tx
.
Data
)
return
return
...
@@ -264,7 +259,6 @@ func MakeContract(tx *Transaction, state *ethstate.State) *ethstate.StateObject
...
@@ -264,7 +259,6 @@ func MakeContract(tx *Transaction, state *ethstate.State) *ethstate.StateObject
contract
:=
state
.
GetOrNewStateObject
(
addr
)
contract
:=
state
.
GetOrNewStateObject
(
addr
)
contract
.
InitCode
=
tx
.
Data
contract
.
InitCode
=
tx
.
Data
contract
.
State
=
ethstate
.
New
(
ethtrie
.
New
(
ethutil
.
Config
.
Db
,
""
))
return
contract
return
contract
}
}
ethchain/transaction.go
View file @
fb4113da
...
@@ -113,7 +113,8 @@ func (tx *Transaction) PublicKey() []byte {
...
@@ -113,7 +113,8 @@ func (tx *Transaction) PublicKey() []byte {
sig
:=
append
(
r
,
s
...
)
sig
:=
append
(
r
,
s
...
)
sig
=
append
(
sig
,
tx
.
v
-
27
)
sig
=
append
(
sig
,
tx
.
v
-
27
)
pubkey
,
_
:=
secp256k1
.
RecoverPubkey
(
hash
,
sig
)
pubkey
:=
ethcrypto
.
Ecrecover
(
append
(
hash
,
sig
...
))
//pubkey, _ := secp256k1.RecoverPubkey(hash, sig)
return
pubkey
return
pubkey
}
}
...
@@ -208,11 +209,11 @@ func (tx *Transaction) String() string {
...
@@ -208,11 +209,11 @@ func (tx *Transaction) String() string {
}
}
type
Receipt
struct
{
type
Receipt
struct
{
Tx
*
Transaction
PostState
[]
byte
PostState
[]
byte
CumulativeGasUsed
*
big
.
Int
CumulativeGasUsed
*
big
.
Int
Bloom
[]
byte
Logs
vm
.
Logs
}
}
type
Receipts
[]
*
Receipt
func
NewRecieptFromValue
(
val
*
ethutil
.
Value
)
*
Receipt
{
func
NewRecieptFromValue
(
val
*
ethutil
.
Value
)
*
Receipt
{
r
:=
&
Receipt
{}
r
:=
&
Receipt
{}
...
@@ -222,25 +223,22 @@ func NewRecieptFromValue(val *ethutil.Value) *Receipt {
...
@@ -222,25 +223,22 @@ func NewRecieptFromValue(val *ethutil.Value) *Receipt {
}
}
func
(
self
*
Receipt
)
RlpValueDecode
(
decoder
*
ethutil
.
Value
)
{
func
(
self
*
Receipt
)
RlpValueDecode
(
decoder
*
ethutil
.
Value
)
{
self
.
Tx
=
NewTransactionFromValue
(
decoder
.
Get
(
0
))
self
.
PostState
=
decoder
.
Get
(
0
)
.
Bytes
()
self
.
PostState
=
decoder
.
Get
(
1
)
.
Bytes
()
self
.
CumulativeGasUsed
=
decoder
.
Get
(
1
)
.
BigInt
()
self
.
CumulativeGasUsed
=
decoder
.
Get
(
2
)
.
BigInt
()
self
.
Bloom
=
decoder
.
Get
(
2
)
.
Bytes
()
it
:=
decoder
.
Get
(
3
)
.
NewIterator
()
for
it
.
Next
()
{
self
.
Logs
=
append
(
self
.
Logs
,
vm
.
NewLogFromValue
(
it
.
Value
()))
}
}
}
func
(
self
*
Receipt
)
RlpData
()
interface
{}
{
func
(
self
*
Receipt
)
RlpData
()
interface
{}
{
return
[]
interface
{}{
self
.
Tx
.
RlpData
(),
self
.
PostState
,
self
.
CumulativeGasUsed
}
return
[]
interface
{}{
self
.
PostState
,
self
.
CumulativeGasUsed
,
self
.
Bloom
,
self
.
Logs
.
RlpData
()
}
}
}
func
(
self
*
Receipt
)
String
()
string
{
func
(
self
*
Receipt
)
RlpEncode
()
[]
byte
{
return
fmt
.
Sprintf
(
`
return
ethutil
.
Encode
(
self
.
RlpData
())
R
Tx:[ %v]
PostState: 0x%x
CumulativeGasUsed: %v
`
,
self
.
Tx
,
self
.
PostState
,
self
.
CumulativeGasUsed
)
}
}
func
(
self
*
Receipt
)
Cmp
(
other
*
Receipt
)
bool
{
func
(
self
*
Receipt
)
Cmp
(
other
*
Receipt
)
bool
{
...
@@ -251,11 +249,27 @@ func (self *Receipt) Cmp(other *Receipt) bool {
...
@@ -251,11 +249,27 @@ func (self *Receipt) Cmp(other *Receipt) bool {
return
true
return
true
}
}
type
Receipts
[]
*
Receipt
func
(
self
Receipts
)
Len
()
int
{
return
len
(
self
)
}
func
(
self
Receipts
)
GetRlp
(
i
int
)
[]
byte
{
return
ethutil
.
Rlp
(
self
[
i
])
}
// Transaction slice type for basic sorting
// Transaction slice type for basic sorting
type
Transactions
[]
*
Transaction
type
Transactions
[]
*
Transaction
func
(
s
Transactions
)
Len
()
int
{
return
len
(
s
)
}
func
(
self
Transactions
)
RlpData
()
interface
{}
{
func
(
s
Transactions
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
// Marshal the transactions of this block
enc
:=
make
([]
interface
{},
len
(
self
))
for
i
,
tx
:=
range
self
{
// Cast it to a string (safe)
enc
[
i
]
=
tx
.
RlpData
()
}
return
enc
}
func
(
s
Transactions
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
Transactions
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
func
(
s
Transactions
)
GetRlp
(
i
int
)
[]
byte
{
return
ethutil
.
Rlp
(
s
[
i
])
}
type
TxByNonce
struct
{
Transactions
}
type
TxByNonce
struct
{
Transactions
}
...
...
ethminer/miner.go
View file @
fb4113da
...
@@ -187,7 +187,7 @@ func (self *Miner) mineNewBlock() {
...
@@ -187,7 +187,7 @@ func (self *Miner) mineNewBlock() {
}
}
self
.
ethereum
.
TxPool
()
.
RemoveSet
(
erroneous
)
self
.
ethereum
.
TxPool
()
.
RemoveSet
(
erroneous
)
self
.
txs
=
append
(
txs
,
unhandledTxs
...
)
self
.
txs
=
append
(
txs
,
unhandledTxs
...
)
self
.
block
.
Set
Tx
Hash
(
receipts
)
self
.
block
.
Set
Receipt
Hash
(
receipts
)
// Set the transactions to the block so the new SHA3 can be calculated
// Set the transactions to the block so the new SHA3 can be calculated
self
.
block
.
SetReceipts
(
receipts
,
txs
)
self
.
block
.
SetReceipts
(
receipts
,
txs
)
...
...
ethtrie/trie.go
View file @
fb4113da
...
@@ -219,6 +219,17 @@ func (t *Trie) Delete(key string) {
...
@@ -219,6 +219,17 @@ func (t *Trie) Delete(key string) {
}
}
}
}
func
(
self
*
Trie
)
GetRoot
()
[]
byte
{
switch
self
.
Root
.
(
type
)
{
case
string
:
return
[]
byte
(
self
.
Root
.
(
string
))
case
[]
byte
:
return
self
.
Root
.
([]
byte
)
default
:
panic
(
fmt
.
Sprintf
(
"invalid root type %T"
,
self
.
Root
))
}
}
// Simple compare function which creates a rlp value out of the evaluated objects
// Simple compare function which creates a rlp value out of the evaluated objects
func
(
t
*
Trie
)
Cmp
(
trie
*
Trie
)
bool
{
func
(
t
*
Trie
)
Cmp
(
trie
*
Trie
)
bool
{
return
ethutil
.
NewValue
(
t
.
Root
)
.
Cmp
(
ethutil
.
NewValue
(
trie
.
Root
))
return
ethutil
.
NewValue
(
t
.
Root
)
.
Cmp
(
ethutil
.
NewValue
(
trie
.
Root
))
...
...
ethutil/rlp.go
View file @
fb4113da
...
@@ -15,6 +15,10 @@ type RlpEncodeDecode interface {
...
@@ -15,6 +15,10 @@ type RlpEncodeDecode interface {
RlpValue
()
[]
interface
{}
RlpValue
()
[]
interface
{}
}
}
type
RlpEncodable
interface
{
RlpData
()
interface
{}
}
func
Rlp
(
encoder
RlpEncode
)
[]
byte
{
func
Rlp
(
encoder
RlpEncode
)
[]
byte
{
return
encoder
.
RlpEncode
()
return
encoder
.
RlpEncode
()
}
}
...
@@ -100,6 +104,8 @@ func Encode(object interface{}) []byte {
...
@@ -100,6 +104,8 @@ func Encode(object interface{}) []byte {
switch
t
:=
object
.
(
type
)
{
switch
t
:=
object
.
(
type
)
{
case
*
Value
:
case
*
Value
:
buff
.
Write
(
Encode
(
t
.
Raw
()))
buff
.
Write
(
Encode
(
t
.
Raw
()))
case
RlpEncodable
:
buff
.
Write
(
Encode
(
t
.
RlpData
()))
// Code dup :-/
// Code dup :-/
case
int
:
case
int
:
buff
.
Write
(
Encode
(
big
.
NewInt
(
int64
(
t
))))
buff
.
Write
(
Encode
(
big
.
NewInt
(
int64
(
t
))))
...
...
ethutil/value.go
View file @
fb4113da
...
@@ -377,6 +377,10 @@ func (val *Value) NewIterator() *ValueIterator {
...
@@ -377,6 +377,10 @@ func (val *Value) NewIterator() *ValueIterator {
return
&
ValueIterator
{
value
:
val
}
return
&
ValueIterator
{
value
:
val
}
}
}
func
(
it
*
ValueIterator
)
Len
()
int
{
return
it
.
value
.
Len
()
}
func
(
it
*
ValueIterator
)
Next
()
bool
{
func
(
it
*
ValueIterator
)
Next
()
bool
{
if
it
.
idx
>=
it
.
value
.
Len
()
{
if
it
.
idx
>=
it
.
value
.
Len
()
{
return
false
return
false
...
...
vm/log.go
View file @
fb4113da
package
vm
package
vm
import
"
math/big
"
import
"
github.com/ethereum/go-ethereum/ethutil
"
type
Log
struct
{
type
Log
struct
{
Address
[]
byte
Address
[]
byte
Topics
[]
*
big
.
Int
Topics
[]
[]
byte
Data
[]
byte
Data
[]
byte
}
}
func
NewLogFromValue
(
decoder
*
ethutil
.
Value
)
Log
{
log
:=
Log
{
Address
:
decoder
.
Get
(
0
)
.
Bytes
(),
Data
:
decoder
.
Get
(
2
)
.
Bytes
(),
}
it
:=
decoder
.
Get
(
1
)
.
NewIterator
()
for
it
.
Next
()
{
log
.
Topics
=
append
(
log
.
Topics
,
it
.
Value
()
.
Bytes
())
}
return
log
}
func
(
self
Log
)
RlpData
()
interface
{}
{
return
[]
interface
{}{
self
.
Address
,
ethutil
.
ByteSliceToInterface
(
self
.
Topics
),
self
.
Data
}
}
type
Logs
[]
Log
func
(
self
Logs
)
RlpData
()
interface
{}
{
data
:=
make
([]
interface
{},
len
(
self
))
for
i
,
log
:=
range
self
{
data
[
i
]
=
log
.
RlpData
()
}
return
data
}
vm/vm_debug.go
View file @
fb4113da
...
@@ -704,11 +704,11 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
...
@@ -704,11 +704,11 @@ func (self *DebugVm) RunClosure(closure *Closure) (ret []byte, err error) {
self
.
Printf
(
" => [%d] %x [0] %x"
,
n
,
x
.
Bytes
(),
y
.
Bytes
())
self
.
Printf
(
" => [%d] %x [0] %x"
,
n
,
x
.
Bytes
(),
y
.
Bytes
())
case
LOG0
,
LOG1
,
LOG2
,
LOG3
,
LOG4
:
case
LOG0
,
LOG1
,
LOG2
,
LOG3
,
LOG4
:
n
:=
int
(
op
-
LOG0
)
n
:=
int
(
op
-
LOG0
)
topics
:=
make
([]
*
big
.
Int
,
n
)
topics
:=
make
([]
[]
byte
,
n
)
mSize
,
mStart
:=
stack
.
Pop
()
.
Int64
(),
stack
.
Pop
()
.
Int64
()
mSize
,
mStart
:=
stack
.
Pop
()
.
Int64
(),
stack
.
Pop
()
.
Int64
()
data
:=
mem
.
Geti
(
mStart
,
mSize
)
data
:=
mem
.
Geti
(
mStart
,
mSize
)
for
i
:=
0
;
i
<
n
;
i
++
{
for
i
:=
0
;
i
<
n
;
i
++
{
topics
[
i
]
=
stack
.
Pop
()
topics
[
i
]
=
stack
.
Pop
()
.
Bytes
()
}
}
self
.
env
.
AddLog
(
Log
{
closure
.
Address
(),
topics
,
data
})
self
.
env
.
AddLog
(
Log
{
closure
.
Address
(),
topics
,
data
})
case
MLOAD
:
case
MLOAD
:
...
...
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