Skip to content

Commit

Permalink
Merge pull request ethereum#587 from maticnetwork/shivam/POS-991
Browse files Browse the repository at this point in the history
add : statesync tx added to GetBlockTransactionCount rpc
  • Loading branch information
0xsharma authored Nov 21, 2022
2 parents 72831c1 + 5f8f898 commit aece5ca
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,26 @@ type PublicTransactionPoolAPI struct {
signer types.Signer
}

// returns block transactions along with state-sync transaction if present
// nolint: unparam
func (api *PublicTransactionPoolAPI) getAllBlockTransactions(ctx context.Context, block *types.Block) (types.Transactions, bool) {
txs := block.Transactions()

stateSyncPresent := false

borReceipt := rawdb.ReadBorReceipt(api.b.ChainDb(), block.Hash(), block.NumberU64())
if borReceipt != nil {
txHash := types.GetDerivedBorTxHash(types.BorReceiptKey(block.Number().Uint64(), block.Hash()))
if txHash != (common.Hash{}) {
borTx, _, _, _, _ := api.b.GetBorBlockTransactionWithBlockHash(ctx, txHash, block.Hash())
txs = append(txs, borTx)
stateSyncPresent = true
}
}

return txs, stateSyncPresent
}

// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI {
// The signer used by the API should always be the 'latest' known one because we expect
Expand All @@ -1626,7 +1646,8 @@ func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransa
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.Context, blockNr rpc.BlockNumber) *hexutil.Uint {
if block, _ := s.b.BlockByNumber(ctx, blockNr); block != nil {
n := hexutil.Uint(len(block.Transactions()))
txs, _ := s.getAllBlockTransactions(ctx, block)
n := hexutil.Uint(len(txs))
return &n
}
return nil
Expand All @@ -1635,7 +1656,8 @@ func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByNumber(ctx context.
// GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.
func (s *PublicTransactionPoolAPI) GetBlockTransactionCountByHash(ctx context.Context, blockHash common.Hash) *hexutil.Uint {
if block, _ := s.b.BlockByHash(ctx, blockHash); block != nil {
n := hexutil.Uint(len(block.Transactions()))
txs, _ := s.getAllBlockTransactions(ctx, block)
n := hexutil.Uint(len(txs))
return &n
}
return nil
Expand Down

0 comments on commit aece5ca

Please sign in to comment.