Merge pull request #587 from maticnetwork/shivam/POS-991

add : statesync tx added to GetBlockTransactionCount rpc
This commit is contained in:
SHIVAM SHARMA 2022-11-21 22:55:15 +05:30 committed by GitHub
commit aece5ca954
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
@ -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
@ -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