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
42c8afd4
Commit
42c8afd4
authored
Sep 29, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: differentiate receipt concensus and storage decoding
parent
b99fe27f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
110 additions
and
77 deletions
+110
-77
block_processor.go
core/block_processor.go
+2
-2
block_processor_test.go
core/block_processor_test.go
+2
-2
chain_makers.go
core/chain_makers.go
+1
-1
transaction_util.go
core/transaction_util.go
+7
-3
bloom9.go
core/types/bloom9.go
+1
-1
receipt.go
core/types/receipt.go
+74
-48
log.go
core/vm/log.go
+20
-17
filter.go
eth/filters/filter.go
+1
-1
parsing.go
rpc/api/parsing.go
+2
-2
No files found.
core/block_processor.go
View file @
42c8afd4
...
...
@@ -111,7 +111,7 @@ func (self *BlockProcessor) ApplyTransaction(gp GasPool, statedb *state.StateDB,
}
logs
:=
statedb
.
GetLogs
(
tx
.
Hash
())
receipt
.
SetLogs
(
logs
)
receipt
.
Logs
=
logs
receipt
.
Bloom
=
types
.
CreateBloom
(
types
.
Receipts
{
receipt
})
glog
.
V
(
logger
.
Debug
)
.
Infoln
(
receipt
)
...
...
@@ -364,7 +364,7 @@ func (sm *BlockProcessor) GetLogs(block *types.Block) (logs vm.Logs, err error)
receipts
:=
GetBlockReceipts
(
sm
.
chainDb
,
block
.
Hash
())
// coalesce logs
for
_
,
receipt
:=
range
receipts
{
logs
=
append
(
logs
,
receipt
.
Logs
()
...
)
logs
=
append
(
logs
,
receipt
.
Logs
...
)
}
return
logs
,
nil
}
...
...
core/block_processor_test.go
View file @
42c8afd4
...
...
@@ -70,7 +70,7 @@ func TestPutReceipt(t *testing.T) {
hash
[
0
]
=
2
receipt
:=
new
(
types
.
Receipt
)
receipt
.
SetLogs
(
vm
.
Logs
{
&
vm
.
Log
{
receipt
.
Logs
=
vm
.
Logs
{
&
vm
.
Log
{
Address
:
addr
,
Topics
:
[]
common
.
Hash
{
hash
},
Data
:
[]
byte
(
"hi"
),
...
...
@@ -79,7 +79,7 @@ func TestPutReceipt(t *testing.T) {
TxIndex
:
0
,
BlockHash
:
hash
,
Index
:
0
,
}}
)
}}
PutReceipts
(
db
,
types
.
Receipts
{
receipt
})
receipt
=
GetReceipt
(
db
,
common
.
Hash
{})
...
...
core/chain_makers.go
View file @
42c8afd4
...
...
@@ -99,7 +99,7 @@ func (b *BlockGen) AddTx(tx *types.Transaction) {
b
.
header
.
GasUsed
.
Add
(
b
.
header
.
GasUsed
,
gas
)
receipt
:=
types
.
NewReceipt
(
root
.
Bytes
(),
b
.
header
.
GasUsed
)
logs
:=
b
.
statedb
.
GetLogs
(
tx
.
Hash
())
receipt
.
SetLogs
(
logs
)
receipt
.
Logs
=
logs
receipt
.
Bloom
=
types
.
CreateBloom
(
types
.
Receipts
{
receipt
})
b
.
txs
=
append
(
b
.
txs
,
tx
)
b
.
receipts
=
append
(
b
.
receipts
,
receipt
)
...
...
core/transaction_util.go
View file @
42c8afd4
...
...
@@ -140,12 +140,16 @@ func GetBlockReceipts(db ethdb.Database, hash common.Hash) types.Receipts {
if
len
(
data
)
==
0
{
return
nil
}
r
eceipts
:=
new
(
types
.
Receipts
)
if
err
:=
rlp
.
DecodeBytes
(
data
,
receipt
s
);
err
!=
nil
{
r
s
:=
[]
*
types
.
ReceiptForStorage
{}
if
err
:=
rlp
.
DecodeBytes
(
data
,
&
r
s
);
err
!=
nil
{
glog
.
V
(
logger
.
Error
)
.
Infof
(
"invalid receipt array RLP for hash %x: %v"
,
hash
,
err
)
return
nil
}
return
*
receipts
receipts
:=
make
(
types
.
Receipts
,
len
(
rs
))
for
i
,
receipt
:=
range
rs
{
receipts
[
i
]
=
(
*
types
.
Receipt
)(
receipt
)
}
return
receipts
}
// PutBlockReceipts stores the block's transactions associated receipts
...
...
core/types/bloom9.go
View file @
42c8afd4
...
...
@@ -72,7 +72,7 @@ func (b Bloom) TestBytes(test []byte) bool {
func
CreateBloom
(
receipts
Receipts
)
Bloom
{
bin
:=
new
(
big
.
Int
)
for
_
,
receipt
:=
range
receipts
{
bin
.
Or
(
bin
,
LogsBloom
(
receipt
.
l
ogs
))
bin
.
Or
(
bin
,
LogsBloom
(
receipt
.
L
ogs
))
}
return
BytesToBloom
(
bin
.
Bytes
())
...
...
core/types/receipt.go
View file @
42c8afd4
...
...
@@ -17,7 +17,6 @@
package
types
import
(
"bytes"
"fmt"
"io"
"math/big"
...
...
@@ -27,89 +26,116 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
// Receipt represents the results of a transaction.
type
Receipt
struct
{
// Consensus fields
PostState
[]
byte
CumulativeGasUsed
*
big
.
Int
Bloom
Bloom
TxHash
common
.
Hash
ContractAddress
common
.
Address
logs
vm
.
Logs
GasUsed
*
big
.
Int
Logs
vm
.
Logs
// Implementation fields
TxHash
common
.
Hash
ContractAddress
common
.
Address
GasUsed
*
big
.
Int
}
// NewReceipt creates a barebone transaction receipt, copying the init fields.
func
NewReceipt
(
root
[]
byte
,
cumalativeGasUsed
*
big
.
Int
)
*
Receipt
{
return
&
Receipt
{
PostState
:
common
.
CopyBytes
(
root
),
CumulativeGasUsed
:
new
(
big
.
Int
)
.
Set
(
cumalativeGasUsed
)}
}
func
(
self
*
Receipt
)
SetLogs
(
logs
vm
.
Logs
)
{
self
.
logs
=
logs
}
func
(
self
*
Receipt
)
Logs
()
vm
.
Logs
{
return
self
.
logs
}
func
(
self
*
Receipt
)
EncodeRLP
(
w
io
.
Writer
)
error
{
return
rlp
.
Encode
(
w
,
[]
interface
{}{
self
.
PostState
,
self
.
CumulativeGasUsed
,
self
.
Bloom
,
self
.
logs
})
// EncodeRLP implements rlp.Encoder, and flattens the consensus fields of a receipt
// into an RLP stream.
func
(
r
*
Receipt
)
EncodeRLP
(
w
io
.
Writer
)
error
{
return
rlp
.
Encode
(
w
,
[]
interface
{}{
r
.
PostState
,
r
.
CumulativeGasUsed
,
r
.
Bloom
,
r
.
Logs
})
}
func
(
self
*
Receipt
)
DecodeRLP
(
s
*
rlp
.
Stream
)
error
{
var
r
struct
{
// DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt
// from an RLP stream.
func
(
r
*
Receipt
)
DecodeRLP
(
s
*
rlp
.
Stream
)
error
{
var
receipt
struct
{
PostState
[]
byte
CumulativeGasUsed
*
big
.
Int
Bloom
Bloom
TxHash
common
.
Hash
ContractAddress
common
.
Address
Logs
vm
.
Logs
GasUsed
*
big
.
Int
}
if
err
:=
s
.
Decode
(
&
r
);
err
!=
nil
{
if
err
:=
s
.
Decode
(
&
r
eceipt
);
err
!=
nil
{
return
err
}
self
.
PostState
,
self
.
CumulativeGasUsed
,
self
.
Bloom
,
self
.
TxHash
,
self
.
ContractAddress
,
self
.
logs
,
self
.
GasUsed
=
r
.
PostState
,
r
.
CumulativeGasUsed
,
r
.
Bloom
,
r
.
TxHash
,
r
.
ContractAddress
,
r
.
Logs
,
r
.
GasUsed
r
.
PostState
,
r
.
CumulativeGasUsed
,
r
.
Bloom
,
r
.
Logs
=
receipt
.
PostState
,
receipt
.
CumulativeGasUsed
,
receipt
.
Bloom
,
receipt
.
Logs
return
nil
}
type
ReceiptForStorage
Receipt
func
(
self
*
ReceiptForStorage
)
EncodeRLP
(
w
io
.
Writer
)
error
{
storageLogs
:=
make
([]
*
vm
.
LogForStorage
,
len
(
self
.
logs
))
for
i
,
log
:=
range
self
.
logs
{
storageLogs
[
i
]
=
(
*
vm
.
LogForStorage
)(
log
)
}
return
rlp
.
Encode
(
w
,
[]
interface
{}{
self
.
PostState
,
self
.
CumulativeGasUsed
,
self
.
Bloom
,
self
.
TxHash
,
self
.
ContractAddress
,
storageLogs
,
self
.
GasUsed
})
}
func
(
self
*
Receipt
)
RlpEncode
()
[]
byte
{
bytes
,
err
:=
rlp
.
EncodeToBytes
(
self
)
// RlpEncode implements common.RlpEncode required for SHA derivation.
func
(
r
*
Receipt
)
RlpEncode
()
[]
byte
{
bytes
,
err
:=
rlp
.
EncodeToBytes
(
r
)
if
err
!=
nil
{
fmt
.
Println
(
"TMP -- RECEIPT ENCODE ERROR"
,
err
)
panic
(
err
)
}
return
bytes
}
func
(
self
*
Receipt
)
Cmp
(
other
*
Receipt
)
bool
{
if
bytes
.
Compare
(
self
.
PostState
,
other
.
PostState
)
!=
0
{
return
false
}
// String implements the Stringer interface.
func
(
r
*
Receipt
)
String
()
string
{
return
fmt
.
Sprintf
(
"receipt{med=%x cgas=%v bloom=%x logs=%v}"
,
r
.
PostState
,
r
.
CumulativeGasUsed
,
r
.
Bloom
,
r
.
Logs
)
}
return
true
// ReceiptForStorage is a wrapper around a Receipt that flattens and parses the
// entire content of a receipt, opposed to only the consensus fields originally.
type
ReceiptForStorage
Receipt
// EncodeRLP implements rlp.Encoder, and flattens all content fields of a receipt
// into an RLP stream.
func
(
r
*
ReceiptForStorage
)
EncodeRLP
(
w
io
.
Writer
)
error
{
logs
:=
make
([]
*
vm
.
LogForStorage
,
len
(
r
.
Logs
))
for
i
,
log
:=
range
r
.
Logs
{
logs
[
i
]
=
(
*
vm
.
LogForStorage
)(
log
)
}
return
rlp
.
Encode
(
w
,
[]
interface
{}{
r
.
PostState
,
r
.
CumulativeGasUsed
,
r
.
Bloom
,
r
.
TxHash
,
r
.
ContractAddress
,
logs
,
r
.
GasUsed
})
}
func
(
self
*
Receipt
)
String
()
string
{
return
fmt
.
Sprintf
(
"receipt{med=%x cgas=%v bloom=%x logs=%v}"
,
self
.
PostState
,
self
.
CumulativeGasUsed
,
self
.
Bloom
,
self
.
logs
)
// DecodeRLP implements rlp.Decoder, and loads the consensus fields of a receipt
// from an RLP stream.
func
(
r
*
ReceiptForStorage
)
DecodeRLP
(
s
*
rlp
.
Stream
)
error
{
var
receipt
struct
{
PostState
[]
byte
CumulativeGasUsed
*
big
.
Int
Bloom
Bloom
TxHash
common
.
Hash
ContractAddress
common
.
Address
Logs
[]
*
vm
.
LogForStorage
GasUsed
*
big
.
Int
}
if
err
:=
s
.
Decode
(
&
receipt
);
err
!=
nil
{
return
err
}
// Assign the consensus fields
r
.
PostState
,
r
.
CumulativeGasUsed
,
r
.
Bloom
=
receipt
.
PostState
,
receipt
.
CumulativeGasUsed
,
receipt
.
Bloom
r
.
Logs
=
make
(
vm
.
Logs
,
len
(
receipt
.
Logs
))
for
i
,
log
:=
range
receipt
.
Logs
{
r
.
Logs
[
i
]
=
(
*
vm
.
Log
)(
log
)
}
// Assign the implementation fields
r
.
TxHash
,
r
.
ContractAddress
,
r
.
GasUsed
=
receipt
.
TxHash
,
receipt
.
ContractAddress
,
receipt
.
GasUsed
return
nil
}
// Receipts is a wrapper around a Receipt array to implement types.DerivableList.
type
Receipts
[]
*
Receipt
func
(
self
Receipts
)
RlpEncode
()
[]
byte
{
bytes
,
err
:=
rlp
.
EncodeToBytes
(
self
)
// RlpEncode implements common.RlpEncode required for SHA derivation.
func
(
r
Receipts
)
RlpEncode
()
[]
byte
{
bytes
,
err
:=
rlp
.
EncodeToBytes
(
r
)
if
err
!=
nil
{
fmt
.
Println
(
"TMP -- RECEIPTS ENCODE ERROR"
,
err
)
panic
(
err
)
}
return
bytes
}
func
(
self
Receipts
)
Len
()
int
{
return
len
(
self
)
}
func
(
self
Receipts
)
GetRlp
(
i
int
)
[]
byte
{
return
common
.
Rlp
(
self
[
i
])
}
// Len returns the number of receipts in this list.
func
(
r
Receipts
)
Len
()
int
{
return
len
(
r
)
}
// GetRlp returns the RLP encoding of one receipt from the list.
func
(
r
Receipts
)
GetRlp
(
i
int
)
[]
byte
{
return
common
.
Rlp
(
r
[
i
])
}
core/vm/log.go
View file @
42c8afd4
...
...
@@ -40,27 +40,30 @@ func NewLog(address common.Address, topics []common.Hash, data []byte, number ui
return
&
Log
{
Address
:
address
,
Topics
:
topics
,
Data
:
data
,
Number
:
number
}
}
func
(
self
*
Log
)
EncodeRLP
(
w
io
.
Writer
)
error
{
return
rlp
.
Encode
(
w
,
[]
interface
{}{
self
.
Address
,
self
.
Topics
,
self
.
Data
})
func
(
l
*
Log
)
EncodeRLP
(
w
io
.
Writer
)
error
{
return
rlp
.
Encode
(
w
,
[]
interface
{}{
l
.
Address
,
l
.
Topics
,
l
.
Data
})
}
func
(
self
*
Log
)
String
()
string
{
return
fmt
.
Sprintf
(
`log: %x %x %x %x %d %x %d`
,
self
.
Address
,
self
.
Topics
,
self
.
Data
,
self
.
TxHash
,
self
.
TxIndex
,
self
.
BlockHash
,
self
.
Index
)
func
(
l
*
Log
)
DecodeRLP
(
s
*
rlp
.
Stream
)
error
{
var
log
struct
{
Address
common
.
Address
Topics
[]
common
.
Hash
Data
[]
byte
}
if
err
:=
s
.
Decode
(
&
log
);
err
!=
nil
{
return
err
}
l
.
Address
,
l
.
Topics
,
l
.
Data
=
log
.
Address
,
log
.
Topics
,
log
.
Data
return
nil
}
func
(
l
*
Log
)
String
()
string
{
return
fmt
.
Sprintf
(
`log: %x %x %x %x %d %x %d`
,
l
.
Address
,
l
.
Topics
,
l
.
Data
,
l
.
TxHash
,
l
.
TxIndex
,
l
.
BlockHash
,
l
.
Index
)
}
type
Logs
[]
*
Log
// LogForStorage is a wrapper around a Log that flattens and parses the entire
// content of a log, opposed to only the consensus fields originally (by hiding
// the rlp interface methods).
type
LogForStorage
Log
func
(
self
*
LogForStorage
)
EncodeRLP
(
w
io
.
Writer
)
error
{
return
rlp
.
Encode
(
w
,
[]
interface
{}{
self
.
Address
,
self
.
Topics
,
self
.
Data
,
self
.
Number
,
self
.
TxHash
,
self
.
TxIndex
,
self
.
BlockHash
,
self
.
Index
,
})
}
eth/filters/filter.go
View file @
42c8afd4
...
...
@@ -138,7 +138,7 @@ func (self *Filter) getLogs(start, end uint64) (logs vm.Logs) {
unfiltered
vm
.
Logs
)
for
_
,
receipt
:=
range
receipts
{
unfiltered
=
append
(
unfiltered
,
receipt
.
Logs
()
...
)
unfiltered
=
append
(
unfiltered
,
receipt
.
Logs
...
)
}
logs
=
append
(
logs
,
self
.
FilterLogs
(
unfiltered
)
...
)
}
...
...
rpc/api/parsing.go
View file @
42c8afd4
...
...
@@ -453,8 +453,8 @@ func NewReceiptRes(rec *types.Receipt) *ReceiptRes {
v
.
ContractAddress
=
newHexData
(
rec
.
ContractAddress
)
}
logs
:=
make
([]
interface
{},
len
(
rec
.
Logs
()
))
for
i
,
log
:=
range
rec
.
Logs
()
{
logs
:=
make
([]
interface
{},
len
(
rec
.
Logs
))
for
i
,
log
:=
range
rec
.
Logs
{
logs
[
i
]
=
NewLogRes
(
log
)
}
v
.
Logs
=
&
logs
...
...
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