mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
types, rawdb, core, miner: add block location fields to receipt
This commit is contained in:
parent
836c846812
commit
d797d250e8
7 changed files with 48 additions and 0 deletions
|
|
@ -799,6 +799,11 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
|
||||||
// The transaction hash can be retrieved from the transaction itself
|
// The transaction hash can be retrieved from the transaction itself
|
||||||
receipts[j].TxHash = transactions[j].Hash()
|
receipts[j].TxHash = transactions[j].Hash()
|
||||||
|
|
||||||
|
// block location fields
|
||||||
|
receipts[j].BlockHash = block.Hash()
|
||||||
|
receipts[j].BlockNumber = block.Number()
|
||||||
|
receipts[j].TransactionIndex = big.NewInt(int64(j))
|
||||||
|
|
||||||
// The contract address can be derived from the transaction itself
|
// The contract address can be derived from the transaction itself
|
||||||
if transactions[j].To() == nil {
|
if transactions[j].To() == nil {
|
||||||
// Deriving the signer is expensive, only do if it's actually needed
|
// Deriving the signer is expensive, only do if it's actually needed
|
||||||
|
|
|
||||||
|
|
@ -306,6 +306,9 @@ func ReadReceipts(db DatabaseReader, hash common.Hash, number uint64) types.Rece
|
||||||
logIndex += 1
|
logIndex += 1
|
||||||
}
|
}
|
||||||
receipts[i] = (*types.Receipt)(receipt)
|
receipts[i] = (*types.Receipt)(receipt)
|
||||||
|
receipts[i].BlockHash = hash
|
||||||
|
receipts[i].BlockNumber = big.NewInt(0).SetUint64(number)
|
||||||
|
receipts[i].TransactionIndex = big.NewInt(int64(i))
|
||||||
}
|
}
|
||||||
return receipts
|
return receipts
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -221,6 +221,10 @@ func (self *StateDB) GetNonce(addr common.Address) uint64 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *StateDB) TxIndex() int {
|
||||||
|
return self.txIndex
|
||||||
|
}
|
||||||
|
|
||||||
func (self *StateDB) GetCode(addr common.Address) []byte {
|
func (self *StateDB) GetCode(addr common.Address) []byte {
|
||||||
stateObject := self.getStateObject(addr)
|
stateObject := self.getStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
"math/big"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StateProcessor is a basic Processor, which takes care of transitioning
|
// StateProcessor is a basic Processor, which takes care of transitioning
|
||||||
|
|
@ -121,6 +122,9 @@ func ApplyTransaction(config *params.ChainConfig, bc ChainContext, author *commo
|
||||||
// Set the receipt logs and create a bloom for filtering
|
// Set the receipt logs and create a bloom for filtering
|
||||||
receipt.Logs = statedb.GetLogs(tx.Hash())
|
receipt.Logs = statedb.GetLogs(tx.Hash())
|
||||||
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
|
||||||
|
receipt.BlockHash = header.Hash()
|
||||||
|
receipt.BlockNumber = header.Number
|
||||||
|
receipt.TransactionIndex = big.NewInt(int64(statedb.TxIndex()))
|
||||||
|
|
||||||
return receipt, gas, err
|
return receipt, gas, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ package types
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
|
@ -23,6 +24,9 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
|
||||||
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
||||||
ContractAddress common.Address `json:"contractAddress"`
|
ContractAddress common.Address `json:"contractAddress"`
|
||||||
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
GasUsed hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
||||||
|
BlockHash common.Hash `json:"blockHash,omitempty"`
|
||||||
|
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
|
||||||
|
TransactionIndex *hexutil.Big `json:"transactionIndex,omitempty"`
|
||||||
}
|
}
|
||||||
var enc Receipt
|
var enc Receipt
|
||||||
enc.PostState = r.PostState
|
enc.PostState = r.PostState
|
||||||
|
|
@ -33,6 +37,9 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
|
||||||
enc.TxHash = r.TxHash
|
enc.TxHash = r.TxHash
|
||||||
enc.ContractAddress = r.ContractAddress
|
enc.ContractAddress = r.ContractAddress
|
||||||
enc.GasUsed = hexutil.Uint64(r.GasUsed)
|
enc.GasUsed = hexutil.Uint64(r.GasUsed)
|
||||||
|
enc.BlockHash = r.BlockHash
|
||||||
|
enc.BlockNumber = (*hexutil.Big)(r.BlockNumber)
|
||||||
|
enc.TransactionIndex = (*hexutil.Big)(r.TransactionIndex)
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,6 +54,9 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
|
||||||
TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
|
TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
|
||||||
ContractAddress *common.Address `json:"contractAddress"`
|
ContractAddress *common.Address `json:"contractAddress"`
|
||||||
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
GasUsed *hexutil.Uint64 `json:"gasUsed" gencodec:"required"`
|
||||||
|
BlockHash *common.Hash `json:"blockHash,omitempty"`
|
||||||
|
BlockNumber *hexutil.Big `json:"blockNumber,omitempty"`
|
||||||
|
TransactionIndex *hexutil.Big `json:"transactionIndex,omitempty"`
|
||||||
}
|
}
|
||||||
var dec Receipt
|
var dec Receipt
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
|
|
@ -81,5 +91,14 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
|
||||||
return errors.New("missing required field 'gasUsed' for Receipt")
|
return errors.New("missing required field 'gasUsed' for Receipt")
|
||||||
}
|
}
|
||||||
r.GasUsed = uint64(*dec.GasUsed)
|
r.GasUsed = uint64(*dec.GasUsed)
|
||||||
|
if dec.BlockHash != nil {
|
||||||
|
r.BlockHash = *dec.BlockHash
|
||||||
|
}
|
||||||
|
if dec.BlockNumber != nil {
|
||||||
|
r.BlockNumber = (*big.Int)(dec.BlockNumber)
|
||||||
|
}
|
||||||
|
if dec.TransactionIndex != nil {
|
||||||
|
r.TransactionIndex = (*big.Int)(dec.TransactionIndex)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math/big"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -55,6 +56,11 @@ type Receipt struct {
|
||||||
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
||||||
ContractAddress common.Address `json:"contractAddress"`
|
ContractAddress common.Address `json:"contractAddress"`
|
||||||
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
|
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
|
||||||
|
|
||||||
|
// Block location fields - not part of the rlp
|
||||||
|
BlockHash common.Hash `json:"blockHash,omitempty"`
|
||||||
|
BlockNumber *big.Int `json:"blockNumber,omitempty"`
|
||||||
|
TransactionIndex *big.Int `json:"transactionIndex,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type receiptMarshaling struct {
|
type receiptMarshaling struct {
|
||||||
|
|
@ -62,6 +68,8 @@ type receiptMarshaling struct {
|
||||||
Status hexutil.Uint64
|
Status hexutil.Uint64
|
||||||
CumulativeGasUsed hexutil.Uint64
|
CumulativeGasUsed hexutil.Uint64
|
||||||
GasUsed hexutil.Uint64
|
GasUsed hexutil.Uint64
|
||||||
|
BlockNumber *hexutil.Big
|
||||||
|
TransactionIndex *hexutil.Big
|
||||||
}
|
}
|
||||||
|
|
||||||
// receiptRLP is the consensus encoding of a receipt.
|
// receiptRLP is the consensus encoding of a receipt.
|
||||||
|
|
|
||||||
|
|
@ -566,6 +566,11 @@ func (w *worker) resultLoop() {
|
||||||
logs []*types.Log
|
logs []*types.Log
|
||||||
)
|
)
|
||||||
for i, receipt := range task.receipts {
|
for i, receipt := range task.receipts {
|
||||||
|
// add block location fields
|
||||||
|
receipt.BlockHash = hash
|
||||||
|
receipt.BlockNumber = block.Number()
|
||||||
|
receipt.TransactionIndex = big.NewInt(int64(i))
|
||||||
|
|
||||||
receipts[i] = new(types.Receipt)
|
receipts[i] = new(types.Receipt)
|
||||||
*receipts[i] = *receipt
|
*receipts[i] = *receipt
|
||||||
// Update the block hash in all logs since it is now available and not when the
|
// Update the block hash in all logs since it is now available and not when the
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue