Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2059,7 +2059,7 @@ func (bc *BlockChain) collectLogs(hash common.Hash, removed bool) []*types.Log {
receipts := rawdb.ReadReceipts(bc.db, hash, *number, bc.chainConfig)

// Append bor receipt
borReceipt := rawdb.ReadBorReceipt(bc.db, hash, *number)
borReceipt := rawdb.ReadBorReceipt(bc.db, hash, *number, bc.chainConfig)
if borReceipt != nil {
receipts = append(receipts, borReceipt)
}
Expand Down
2 changes: 1 addition & 1 deletion core/bor_blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (bc *BlockChain) GetBorReceiptByHash(hash common.Hash) *types.Receipt {
}

// read bor reciept by hash and number
receipt := rawdb.ReadBorReceipt(bc.db, hash, *number)
receipt := rawdb.ReadBorReceipt(bc.db, hash, *number, bc.chainConfig)
if receipt == nil {
return nil
}
Expand Down
24 changes: 12 additions & 12 deletions core/rawdb/bor_receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
)

Expand Down Expand Up @@ -52,15 +53,9 @@ func ReadBorReceiptRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.Raw
// First try to look up the data in ancient database. Extra hash
// comparison is necessary since ancient database only maintains
// the canonical data.
data, _ := db.Ancient(freezerBorReceiptTable, number)
if len(data) > 0 {
h, _ := db.Ancient(freezerHashTable, number)
if common.BytesToHash(h) == hash {
return data
}
}
// Then try to look up the data in leveldb.
data, _ = db.Get(borReceiptKey(number, hash))

// Look up the data in leveldb.
data, _ := db.Get(borReceiptKey(number, hash))
if len(data) > 0 {
return data
}
Expand Down Expand Up @@ -101,7 +96,12 @@ func ReadRawBorReceipt(db ethdb.Reader, hash common.Hash, number uint64) *types.
// ReadBorReceipt retrieves all the bor block receipts belonging to a block, including
// its correspoinding metadata fields. If it is unable to populate these metadata
// fields then nil is returned.
func ReadBorReceipt(db ethdb.Reader, hash common.Hash, number uint64) *types.Receipt {
func ReadBorReceipt(db ethdb.Reader, hash common.Hash, number uint64, config *params.ChainConfig) *types.Receipt {

if config != nil && !config.Bor.IsSprintStart(number, config.Bor.CalculateSprint(number)) {
return nil
}

// We're deriving many fields from the block body, retrieve beside the receipt
borReceipt := ReadRawBorReceipt(db, hash, number)
if borReceipt == nil {
Expand All @@ -114,8 +114,8 @@ func ReadBorReceipt(db ethdb.Reader, hash common.Hash, number uint64) *types.Rec
return nil
}

body := ReadBody(db, hash, number)
if body == nil {
body := HasBody(db, hash, number)
if !body {
log.Error("Missing body but have bor receipt", "hash", hash, "number", number)
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion eth/filters/test_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (b *TestBackend) GetBorBlockReceipt(ctx context.Context, hash common.Hash)
return &types.Receipt{}, nil
}

receipt := rawdb.ReadBorReceipt(b.DB, hash, *number)
receipt := rawdb.ReadBorReceipt(b.DB, hash, *number, nil)
if receipt == nil {
return &types.Receipt{}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (api *API) getAllBlockTransactions(ctx context.Context, block *types.Block)

stateSyncPresent := false

borReceipt := rawdb.ReadBorReceipt(api.backend.ChainDb(), block.Hash(), block.NumberU64())
borReceipt := rawdb.ReadBorReceipt(api.backend.ChainDb(), block.Hash(), block.NumberU64(), api.backend.ChainConfig())
if borReceipt != nil {
txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash()))
if txHash != (common.Hash{}) {
Expand Down
16 changes: 8 additions & 8 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func (s *PublicBlockChainAPI) GetTransactionReceiptsByBlock(ctx context.Context,

var txHash common.Hash

borReceipt := rawdb.ReadBorReceipt(s.b.ChainDb(), block.Hash(), block.NumberU64())
borReceipt := rawdb.ReadBorReceipt(s.b.ChainDb(), block.Hash(), block.NumberU64(), s.b.ChainConfig())
if borReceipt != nil {
receipts = append(receipts, borReceipt)
txHash = types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash()))
Expand Down Expand Up @@ -1453,18 +1453,18 @@ func newRPCPendingTransaction(tx *types.Transaction, current *types.Header, conf
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64, config *params.ChainConfig, db ethdb.Database) *RPCTransaction {
txs := b.Transactions()

borReceipt := rawdb.ReadBorReceipt(db, b.Hash(), b.NumberU64())
if index >= uint64(len(txs)+1) {
return nil
}

borReceipt := rawdb.ReadBorReceipt(db, b.Hash(), b.NumberU64(), config)
if borReceipt != nil {
tx, _, _, _ := rawdb.ReadBorTransaction(db, borReceipt.TxHash)

if tx != nil {
txs = append(txs, tx)
}
}

if index >= uint64(len(txs)) {
return nil
}
return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index, b.BaseFee(), config)
}

Expand Down Expand Up @@ -1602,7 +1602,7 @@ func (api *PublicTransactionPoolAPI) getAllBlockTransactions(ctx context.Context

stateSyncPresent := false

borReceipt := rawdb.ReadBorReceipt(api.b.ChainDb(), block.Hash(), block.NumberU64())
borReceipt := rawdb.ReadBorReceipt(api.b.ChainDb(), block.Hash(), block.NumberU64(), api.b.ChainConfig())
if borReceipt != nil {
txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash()))
if txHash != (common.Hash{}) {
Expand Down Expand Up @@ -1772,7 +1772,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha

if borTx {
// Fetch bor block receipt
receipt = rawdb.ReadBorReceipt(s.b.ChainDb(), blockHash, blockNumber)
receipt = rawdb.ReadBorReceipt(s.b.ChainDb(), blockHash, blockNumber, s.b.ChainConfig())
} else {
receipts, err := s.b.GetReceipts(ctx, blockHash)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,10 @@ func (c *BorConfig) IsDelhi(number *big.Int) bool {
return isForked(c.DelhiBlock, number)
}

func (c *BorConfig) IsSprintStart(number, sprint uint64) bool {
return number%sprint == 0
}

func (c *BorConfig) calculateBorConfigHelper(field map[string]uint64, number uint64) uint64 {
keys := make([]string, 0, len(field))
for k := range field {
Expand Down