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
9addb3df
Commit
9addb3df
authored
Jul 15, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1475 from obscuren/issue1473
core: during chain reorg rewrite receipts and transactions
parents
cecc9cdd
e17d8ddb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
13 deletions
+46
-13
block_processor.go
core/block_processor.go
+2
-2
chain_manager.go
core/chain_manager.go
+7
-0
transaction_util.go
core/transaction_util.go
+37
-11
No files found.
core/block_processor.go
View file @
9addb3df
...
...
@@ -342,7 +342,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
// GetBlockReceipts returns the receipts beloniging to the block hash
func
(
sm
*
BlockProcessor
)
GetBlockReceipts
(
bhash
common
.
Hash
)
types
.
Receipts
{
if
block
:=
sm
.
ChainManager
()
.
GetBlock
(
bhash
);
block
!=
nil
{
return
Get
ReceiptsFromBlock
(
sm
.
extraDb
,
block
)
return
Get
BlockReceipts
(
sm
.
extraDb
,
block
.
Hash
()
)
}
return
nil
...
...
@@ -352,7 +352,7 @@ func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) types.Receipts {
// where it tries to get it from the (updated) method which gets them from the receipts or
// the depricated way by re-processing the block.
func
(
sm
*
BlockProcessor
)
GetLogs
(
block
*
types
.
Block
)
(
logs
state
.
Logs
,
err
error
)
{
receipts
:=
Get
ReceiptsFromBlock
(
sm
.
extraDb
,
block
)
receipts
:=
Get
BlockReceipts
(
sm
.
extraDb
,
block
.
Hash
()
)
if
len
(
receipts
)
>
0
{
// coalesce logs
for
_
,
receipt
:=
range
receipts
{
...
...
core/chain_manager.go
View file @
9addb3df
...
...
@@ -667,6 +667,8 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
queue
[
i
]
=
ChainSplitEvent
{
block
,
logs
}
queueEvent
.
splitCount
++
}
PutBlockReceipts
(
self
.
extraDb
,
block
,
receipts
)
stats
.
processed
++
}
...
...
@@ -744,7 +746,12 @@ func (self *ChainManager) merge(oldBlock, newBlock *types.Block) error {
// insert blocks. Order does not matter. Last block will be written in ImportChain itself which creates the new head properly
self
.
mu
.
Lock
()
for
_
,
block
:=
range
newChain
{
// insert the block in the canonical way, re-writing history
self
.
insert
(
block
)
// write canonical receipts and transactions
PutTransactions
(
self
.
extraDb
,
block
,
block
.
Transactions
())
PutReceipts
(
self
.
extraDb
,
GetBlockReceipts
(
self
.
extraDb
,
block
.
Hash
()))
}
self
.
mu
.
Unlock
()
...
...
core/transaction_util.go
View file @
9addb3df
...
...
@@ -24,7 +24,10 @@ import (
"github.com/ethereum/go-ethereum/rlp"
)
var
receiptsPre
=
[]
byte
(
"receipts-"
)
var
(
receiptsPre
=
[]
byte
(
"receipts-"
)
blockReceiptsPre
=
[]
byte
(
"receipts-block-"
)
)
// PutTransactions stores the transactions in the given database
func
PutTransactions
(
db
common
.
Database
,
block
*
types
.
Block
,
txs
types
.
Transactions
)
{
...
...
@@ -85,17 +88,40 @@ func GetReceipt(db common.Database, txHash common.Hash) *types.Receipt {
return
&
receipt
}
// GetReceiptFromBlock returns all receipts with the given block
func
GetReceiptsFromBlock
(
db
common
.
Database
,
block
*
types
.
Block
)
types
.
Receipts
{
// at some point we want:
//receipts := make(types.Receipts, len(block.Transactions()))
// but since we need to support legacy, we can't (yet)
var
receipts
types
.
Receipts
for
_
,
tx
:=
range
block
.
Transactions
()
{
if
receipt
:=
GetReceipt
(
db
,
tx
.
Hash
());
receipt
!=
nil
{
receipts
=
append
(
receipts
,
receipt
)
}
// GetBlockReceipts returns the receipts generated by the transactions
// included in block's given hash.
func
GetBlockReceipts
(
db
common
.
Database
,
hash
common
.
Hash
)
types
.
Receipts
{
data
,
_
:=
db
.
Get
(
append
(
blockReceiptsPre
,
hash
[
:
]
...
))
if
len
(
data
)
==
0
{
return
nil
}
var
receipts
types
.
Receipts
err
:=
rlp
.
DecodeBytes
(
data
,
&
receipts
)
if
err
!=
nil
{
glog
.
V
(
logger
.
Core
)
.
Infoln
(
"GetReceiptse err"
,
err
)
}
return
receipts
}
// PutBlockReceipts stores the block's transactions associated receipts
// and stores them by block hash in a single slice. This is required for
// forks and chain reorgs
func
PutBlockReceipts
(
db
common
.
Database
,
block
*
types
.
Block
,
receipts
types
.
Receipts
)
error
{
rs
:=
make
([]
*
types
.
ReceiptForStorage
,
len
(
receipts
))
for
i
,
receipt
:=
range
receipts
{
rs
[
i
]
=
(
*
types
.
ReceiptForStorage
)(
receipt
)
}
bytes
,
err
:=
rlp
.
EncodeToBytes
(
rs
)
if
err
!=
nil
{
return
err
}
hash
:=
block
.
Hash
()
err
=
db
.
Put
(
append
(
blockReceiptsPre
,
hash
[
:
]
...
),
bytes
)
if
err
!=
nil
{
return
err
}
return
nil
}
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