Skip to content

Commit

Permalink
fetch block receipts by block number
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Dec 18, 2024
1 parent 103f236 commit 835af35
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions txbuilder/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ func (pool *TxPool) processBlock(blockNumber uint64) error {
}

txCount := len(blockBody.Transactions())
receipts := pool.getBlockReceipts(blockBody.Hash(), txCount)
receipts, err := pool.getBlockReceipts(blockNumber, txCount)
if receipts == nil {
return fmt.Errorf("could not load block receipts")
return fmt.Errorf("could not load block receipts: %w", err)
}

loadingTime := time.Since(t1)
Expand Down Expand Up @@ -237,32 +237,37 @@ func (pool *TxPool) getBlockBody(blockNumber uint64) *types.Block {
return nil
}

func (pool *TxPool) getBlockReceipts(blockHash common.Hash, txCount int) []*types.Receipt {
func (pool *TxPool) getBlockReceipts(blockNumber uint64, txCount int) ([]*types.Receipt, error) {
clientCount := pool.options.GetClientCountFn()

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

var receiptErr error
blockNum := rpc.BlockNumber(blockNumber)

for i := 0; i < clientCount; i++ {
client := pool.options.GetClientFn(i, false)
if client == nil {
continue
}

blockReceipts, err := client.client.BlockReceipts(ctx, rpc.BlockNumberOrHash{
BlockHash: &blockHash,
BlockNumber: &blockNum,
})
if err == nil {
if err != nil {
receiptErr = err
} else {
if len(blockReceipts) != txCount {
logrus.Warnf("block %v has %v receipts, expected %v", blockHash, len(blockReceipts), txCount)
logrus.Warnf("block %v has %v receipts, expected %v", blockNumber, len(blockReceipts), txCount)
continue
}

return blockReceipts
return blockReceipts, nil
}
}

return nil
return nil, receiptErr
}

func (pool *TxPool) getWallet(address common.Address) *Wallet {
Expand Down

0 comments on commit 835af35

Please sign in to comment.