@@ -426,7 +426,7 @@ func TestEth2DeepReorg(t *testing.T) {
426426}
427427
428428// startEthService creates a full node instance for testing.
429- func startEthService (t * testing.T , genesis * core.Genesis , blocks []* types.Block ) (* node.Node , * eth.Ethereum ) {
429+ func startEthService (t testing.TB , genesis * core.Genesis , blocks []* types.Block ) (* node.Node , * eth.Ethereum ) {
430430 t .Helper ()
431431
432432 n , err := node .New (& node.Config {
@@ -1873,7 +1873,7 @@ func makeMultiBlobTx(chainConfig *params.ChainConfig, nonce uint64, blobCount in
18731873 return types .MustSignNewTx (key , types .LatestSigner (chainConfig ), blobtx )
18741874}
18751875
1876- func newGetBlobEnv (t * testing.T , version byte ) (* node.Node , * ConsensusAPI ) {
1876+ func newGetBlobEnv (t testing.TB , version byte ) (* node.Node , * ConsensusAPI ) {
18771877 var (
18781878 // Create a database pre-initialize with a genesis block
18791879 config = * params .MergedTestChainConfig
@@ -2045,36 +2045,57 @@ func TestGetBlobsV2(t *testing.T) {
20452045 },
20462046 }
20472047 for i , suite := range suites {
2048- // Fill the request for retrieving blobs
2049- var (
2050- vhashes []common.Hash
2051- expect []* engine.BlobAndProofV2
2052- )
2053- // fill missing blob
2054- if suite .fillRandom {
2055- vhashes = append (vhashes , testrand .Hash ())
2056- }
2057- for j := suite .start ; j < suite .limit ; j ++ {
2058- vhashes = append (vhashes , testBlobVHashes [j ])
2059- var cellProofs []hexutil.Bytes
2060- for _ , proof := range testBlobCellProofs [j ] {
2061- cellProofs = append (cellProofs , proof [:])
2048+ runGetBlobsV2 (t , api , suite .start , suite .limit , suite .fillRandom , fmt .Sprintf ("suite=%d" , i ))
2049+ }
2050+ }
2051+
2052+ // Benchmark GetBlobsV2 internals
2053+ // Note that this is not an RPC-level benchmark, so JSON-RPC overhead is not included.
2054+ func BenchmarkGetBlobsV2 (b * testing.B ) {
2055+ n , api := newGetBlobEnv (b , 1 )
2056+ defer n .Close ()
2057+
2058+ // for blobs in [1, 2, 4, 6], print string and run benchmark
2059+ for _ , blobs := range []int {1 , 2 , 4 , 6 } {
2060+ name := fmt .Sprintf ("blobs=%d" , blobs )
2061+ b .Run (name , func (b * testing.B ) {
2062+ for b .Loop () {
2063+ runGetBlobsV2 (b , api , 0 , blobs , false , name )
20622064 }
2063- expect = append (expect , & engine.BlobAndProofV2 {
2064- Blob : testBlobs [j ][:],
2065- CellProofs : cellProofs ,
2066- })
2067- }
2068- result , err := api .GetBlobsV2 (vhashes )
2069- if err != nil {
2070- t .Errorf ("Unexpected error for case %d, %v" , i , err )
2071- }
2072- // null is responded if any blob is missing
2073- if suite .fillRandom {
2074- expect = nil
2075- }
2076- if ! reflect .DeepEqual (result , expect ) {
2077- t .Fatalf ("Unexpected result for case %d" , i )
2078- }
2065+ })
2066+ }
2067+ }
2068+
2069+ func runGetBlobsV2 (t testing.TB , api * ConsensusAPI , start , limit int , fillRandom bool , name string ) {
2070+ // Fill the request for retrieving blobs
2071+ var (
2072+ vhashes []common.Hash
2073+ expect []* engine.BlobAndProofV2
2074+ )
2075+ // fill missing blob
2076+ if fillRandom {
2077+ vhashes = append (vhashes , testrand .Hash ())
2078+ }
2079+ for j := start ; j < limit ; j ++ {
2080+ vhashes = append (vhashes , testBlobVHashes [j ])
2081+ var cellProofs []hexutil.Bytes
2082+ for _ , proof := range testBlobCellProofs [j ] {
2083+ cellProofs = append (cellProofs , proof [:])
2084+ }
2085+ expect = append (expect , & engine.BlobAndProofV2 {
2086+ Blob : testBlobs [j ][:],
2087+ CellProofs : cellProofs ,
2088+ })
2089+ }
2090+ result , err := api .GetBlobsV2 (vhashes )
2091+ if err != nil {
2092+ t .Errorf ("Unexpected error for case %s, %v" , name , err )
2093+ }
2094+ // null is responded if any blob is missing
2095+ if fillRandom {
2096+ expect = nil
2097+ }
2098+ if ! reflect .DeepEqual (result , expect ) {
2099+ t .Fatalf ("Unexpected result for case %s" , name )
20792100 }
20802101}
0 commit comments