|
|
@ -9,12 +9,12 @@ import ( |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/core/state" |
|
|
|
"github.com/ethereum/go-ethereum/core/state" |
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/event" |
|
|
|
"github.com/ethereum/go-ethereum/event" |
|
|
|
"github.com/ethereum/go-ethereum/logger" |
|
|
|
"github.com/ethereum/go-ethereum/logger" |
|
|
|
"github.com/ethereum/go-ethereum/logger/glog" |
|
|
|
"github.com/ethereum/go-ethereum/logger/glog" |
|
|
|
"github.com/ethereum/go-ethereum/params" |
|
|
|
"github.com/ethereum/go-ethereum/params" |
|
|
|
"github.com/ethereum/go-ethereum/pow" |
|
|
|
"github.com/ethereum/go-ethereum/pow" |
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
|
|
|
|
"gopkg.in/fatih/set.v0" |
|
|
|
"gopkg.in/fatih/set.v0" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -24,8 +24,6 @@ const ( |
|
|
|
BlockChainVersion = 3 |
|
|
|
BlockChainVersion = 3 |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var receiptsPre = []byte("receipts-") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type BlockProcessor struct { |
|
|
|
type BlockProcessor struct { |
|
|
|
db common.Database |
|
|
|
db common.Database |
|
|
|
extraDb common.Database |
|
|
|
extraDb common.Database |
|
|
@ -83,6 +81,12 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, stated |
|
|
|
|
|
|
|
|
|
|
|
usedGas.Add(usedGas, gas) |
|
|
|
usedGas.Add(usedGas, gas) |
|
|
|
receipt := types.NewReceipt(statedb.Root().Bytes(), usedGas) |
|
|
|
receipt := types.NewReceipt(statedb.Root().Bytes(), usedGas) |
|
|
|
|
|
|
|
receipt.TxHash = tx.Hash() |
|
|
|
|
|
|
|
if MessageCreatesContract(tx) { |
|
|
|
|
|
|
|
from, _ := tx.From() |
|
|
|
|
|
|
|
receipt.ContractAddress = crypto.CreateAddress(from, tx.Nonce()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
logs := statedb.GetLogs(tx.Hash()) |
|
|
|
logs := statedb.GetLogs(tx.Hash()) |
|
|
|
receipt.SetLogs(logs) |
|
|
|
receipt.SetLogs(logs) |
|
|
|
receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) |
|
|
|
receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) |
|
|
@ -319,16 +323,20 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetBlockReceipts returns the receipts beloniging to the block hash
|
|
|
|
// GetBlockReceipts returns the receipts beloniging to the block hash
|
|
|
|
func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) (receipts types.Receipts, err error) { |
|
|
|
func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) types.Receipts { |
|
|
|
return getBlockReceipts(sm.extraDb, bhash) |
|
|
|
if block := sm.ChainManager().GetBlock(bhash); block != nil { |
|
|
|
|
|
|
|
return GetReceiptsFromBlock(sm.extraDb, block) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetLogs returns the logs of the given block. This method is using a two step approach
|
|
|
|
// GetLogs returns the logs of the given block. This method is using a two step approach
|
|
|
|
// where it tries to get it from the (updated) method which gets them from the receipts or
|
|
|
|
// 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.
|
|
|
|
// the depricated way by re-processing the block.
|
|
|
|
func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err error) { |
|
|
|
func (sm *BlockProcessor) GetLogs(block *types.Block) (logs state.Logs, err error) { |
|
|
|
receipts, err := sm.GetBlockReceipts(block.Hash()) |
|
|
|
receipts := GetReceiptsFromBlock(sm.extraDb, block) |
|
|
|
if err == nil && len(receipts) > 0 { |
|
|
|
if len(receipts) > 0 { |
|
|
|
// coalesce logs
|
|
|
|
// coalesce logs
|
|
|
|
for _, receipt := range receipts { |
|
|
|
for _, receipt := range receipts { |
|
|
|
logs = append(logs, receipt.Logs()...) |
|
|
|
logs = append(logs, receipt.Logs()...) |
|
|
@ -391,15 +399,3 @@ func ValidateHeader(pow pow.PoW, block *types.Header, parent *types.Block, check |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func getBlockReceipts(db common.Database, bhash common.Hash) (receipts types.Receipts, err error) { |
|
|
|
|
|
|
|
var rdata []byte |
|
|
|
|
|
|
|
rdata, err = db.Get(append(receiptsPre, bhash[:]...)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err == nil { |
|
|
|
|
|
|
|
err = rlp.DecodeBytes(rdata, &receipts) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
glog.V(logger.Detail).Infof("getBlockReceipts error %v\n", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|