@@ -512,6 +512,7 @@ where
512512 full : bool ,
513513 ) -> RpcResult < Option < RpcBlock < T :: NetworkTypes > > > {
514514 trace ! ( target: "rpc::eth" , ?number, ?full, "Serving eth_getBlockByNumber" ) ;
515+ check_pending_tag ( & number) ?;
515516 Ok ( EthBlocks :: rpc_block ( self , number. into ( ) , full) . await ?)
516517 }
517518
@@ -527,6 +528,7 @@ where
527528 number : BlockNumberOrTag ,
528529 ) -> RpcResult < Option < U256 > > {
529530 trace ! ( target: "rpc::eth" , ?number, "Serving eth_getBlockTransactionCountByNumber" ) ;
531+ check_pending_tag ( & number) ?;
530532 Ok ( EthBlocks :: block_transaction_count ( self , number. into ( ) ) . await ?. map ( U256 :: from) )
531533 }
532534
@@ -547,6 +549,7 @@ where
547549 number : BlockNumberOrTag ,
548550 ) -> RpcResult < Option < U256 > > {
549551 trace ! ( target: "rpc::eth" , ?number, "Serving eth_getUncleCountByBlockNumber" ) ;
552+ check_pending_tag ( & number) ?;
550553
551554 if let Some ( block) = self . block_by_number ( number, false ) . await ? {
552555 Ok ( Some ( U256 :: from ( block. uncles . len ( ) ) ) )
@@ -581,6 +584,7 @@ where
581584 index : Index ,
582585 ) -> RpcResult < Option < RpcBlock < T :: NetworkTypes > > > {
583586 trace ! ( target: "rpc::eth" , ?number, ?index, "Serving eth_getUncleByBlockNumberAndIndex" ) ;
587+ check_pending_tag ( & number) ?;
584588 Ok ( EthBlocks :: ommer_by_block_and_index ( self , number. into ( ) , index) . await ?)
585589 }
586590
@@ -640,6 +644,7 @@ where
640644 index : Index ,
641645 ) -> RpcResult < Option < Bytes > > {
642646 trace ! ( target: "rpc::eth" , ?number, ?index, "Serving eth_getRawTransactionByBlockNumberAndIndex" ) ;
647+ check_pending_tag ( & number) ?;
643648 Ok ( EthTransactions :: raw_transaction_by_block_and_tx_index (
644649 self ,
645650 number. into ( ) ,
@@ -655,6 +660,7 @@ where
655660 index : Index ,
656661 ) -> RpcResult < Option < RpcTransaction < T :: NetworkTypes > > > {
657662 trace ! ( target: "rpc::eth" , ?number, ?index, "Serving eth_getTransactionByBlockNumberAndIndex" ) ;
663+ check_pending_tag ( & number) ?;
658664 Ok ( EthTransactions :: transaction_by_block_and_tx_index ( self , number. into ( ) , index. into ( ) )
659665 . await ?)
660666 }
@@ -674,6 +680,7 @@ where
674680 number : BlockNumberOrTag ,
675681 ) -> RpcResult < Option < Vec < RpcTransaction < T :: NetworkTypes > > > > {
676682 trace ! ( target: "rpc::eth" , ?number, "Serving eth_getTransactionsByBlockNumber" ) ;
683+ check_pending_tag ( & number) ?;
677684 Ok ( EthTransactions :: transactions_by_block_id ( self , number. into ( ) ) . await ?)
678685 }
679686
@@ -759,6 +766,7 @@ where
759766 block_number : BlockNumberOrTag ,
760767 ) -> RpcResult < Option < RpcHeader < T :: NetworkTypes > > > {
761768 trace ! ( target: "rpc::eth" , ?block_number, "Serving eth_getHeaderByNumber" ) ;
769+ check_pending_tag ( & block_number) ?;
762770 Ok ( EthBlocks :: rpc_block_header ( self , block_number. into ( ) ) . await ?)
763771 }
764772
@@ -889,6 +897,7 @@ where
889897 reward_percentiles : Option < Vec < f64 > > ,
890898 ) -> RpcResult < FeeHistory > {
891899 trace ! ( target: "rpc::eth" , ?block_count, ?newest_block, ?reward_percentiles, "Serving eth_feeHistory" ) ;
900+ check_pending_tag ( & newest_block) ?;
892901 Ok ( EthFees :: fee_history ( self , block_count. to ( ) , newest_block, reward_percentiles) . await ?)
893902 }
894903
@@ -1010,3 +1019,12 @@ where
10101019 Ok ( bal. map ( |b : BlockAccessList | alloy_rlp:: encode ( b) . into ( ) ) )
10111020 }
10121021}
1022+
1023+ /// Helper function to check if `BlockNumberOrTag` is pending and return error if so
1024+ fn check_pending_tag ( block_number : & BlockNumberOrTag ) -> RpcResult < ( ) > {
1025+ if matches ! ( block_number, BlockNumberOrTag :: Pending ) {
1026+ Err ( internal_rpc_err ( "Unsupported pending tag" ) )
1027+ } else {
1028+ Ok ( ( ) )
1029+ }
1030+ }
0 commit comments