mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 01:27:38 +00:00
rpctest: Add rpctest get block by number (#8476)
This commit is contained in:
parent
e04dee12fd
commit
93be5ecddc
@ -82,6 +82,19 @@ func main() {
|
|||||||
}
|
}
|
||||||
with(benchEthGetBlockByHash, withErigonUrl, withGethUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile, withLatest)
|
with(benchEthGetBlockByHash, withErigonUrl, withGethUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile, withLatest)
|
||||||
|
|
||||||
|
var benchEthGetBlockByNumber2Cmd = &cobra.Command{
|
||||||
|
Use: "benchEthGetBlockByNumber2",
|
||||||
|
Short: "",
|
||||||
|
Long: ``,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
err := rpctest.BenchEthGetBlockByNumber2(erigonURL, gethURL, needCompare, latest, blockFrom, blockTo, recordFile, errorFile)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error(err.Error())
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
with(benchEthGetBlockByNumber2Cmd, withErigonUrl, withGethUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile, withLatest)
|
||||||
|
|
||||||
var benchEthGetTransactionByHashCmd = &cobra.Command{
|
var benchEthGetTransactionByHashCmd = &cobra.Command{
|
||||||
Use: "benchEthGetTransactionByHash",
|
Use: "benchEthGetTransactionByHash",
|
||||||
Short: "",
|
Short: "",
|
||||||
@ -328,6 +341,7 @@ func main() {
|
|||||||
rootCmd.Flags().Uint64Var(&blockTo, "blockTo", 2101000, "Block number to end test generation at")
|
rootCmd.Flags().Uint64Var(&blockTo, "blockTo", 2101000, "Block number to end test generation at")
|
||||||
|
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
|
benchEthGetBlockByNumber2Cmd,
|
||||||
benchEthGetBlockByHash,
|
benchEthGetBlockByHash,
|
||||||
benchEthCallCmd,
|
benchEthCallCmd,
|
||||||
benchEthGetTransactionByHashCmd,
|
benchEthGetTransactionByHashCmd,
|
||||||
|
108
cmd/rpctest/rpctest/bench_ethgetblockbynumber.go
Normal file
108
cmd/rpctest/rpctest/bench_ethgetblockbynumber.go
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
package rpctest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BenchEthGetBlockByNumber compares response of Erigon with Geth
|
||||||
|
// but also can be used for comparing RPCDaemon with Geth or infura
|
||||||
|
// parameters:
|
||||||
|
// needCompare - if false - doesn't call Erigon and doesn't compare responses
|
||||||
|
//
|
||||||
|
// false value - to generate vegeta files, it's faster but we can generate vegeta files for Geth and Erigon
|
||||||
|
// recordFile stores all eth_call returned with success
|
||||||
|
// errorFile stores information when erigon and geth doesn't return same data
|
||||||
|
func BenchEthGetBlockByNumber2(erigonURL, gethURL string, needCompare, latest bool, blockFrom, blockTo uint64, recordFileName string, errorFileName string) error {
|
||||||
|
setRoutes(erigonURL, gethURL)
|
||||||
|
var client = &http.Client{
|
||||||
|
Timeout: time.Second * 600,
|
||||||
|
}
|
||||||
|
|
||||||
|
var rec *bufio.Writer
|
||||||
|
var errs *bufio.Writer
|
||||||
|
var resultsCh chan CallResult = nil
|
||||||
|
var nBlocks = 0
|
||||||
|
|
||||||
|
if errorFileName != "" {
|
||||||
|
f, err := os.Create(errorFileName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Cannot create file %s for errorFile: %v\n", errorFileName, err)
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
errs = bufio.NewWriter(f)
|
||||||
|
defer errs.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
if recordFileName != "" {
|
||||||
|
frec, errRec := os.Create(recordFileName)
|
||||||
|
if errRec != nil {
|
||||||
|
return fmt.Errorf("Cannot create file %s for errorFile: %v\n", recordFileName, errRec)
|
||||||
|
}
|
||||||
|
defer frec.Close()
|
||||||
|
rec = bufio.NewWriter(frec)
|
||||||
|
defer rec.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
if !needCompare {
|
||||||
|
resultsCh = make(chan CallResult, 1000)
|
||||||
|
defer close(resultsCh)
|
||||||
|
go vegetaWrite(true, []string{"eth_getBlockByNumber"}, resultsCh)
|
||||||
|
}
|
||||||
|
var res CallResult
|
||||||
|
|
||||||
|
reqGen := &RequestGenerator{
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
|
||||||
|
reqGen.reqID++
|
||||||
|
|
||||||
|
for bn := blockFrom; bn <= blockTo; bn++ {
|
||||||
|
reqGen.reqID++
|
||||||
|
var b EthBlockByNumber
|
||||||
|
res = reqGen.Erigon("eth_getBlockByNumber", reqGen.getBlockByNumber(bn, true /* withTxs */), &b)
|
||||||
|
if res.Err != nil {
|
||||||
|
return fmt.Errorf("Could not retrieve block (Erigon) %d: %v\n", bn, res.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if b.Error != nil {
|
||||||
|
return fmt.Errorf("Error retrieving block (Erigon): %d %s\n", b.Error.Code, b.Error.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
if needCompare {
|
||||||
|
var bg EthBlockByNumber
|
||||||
|
res = reqGen.Geth("eth_getBlockByNumber", reqGen.getBlockByNumber(bn, true /* withTxs */), &bg)
|
||||||
|
if res.Err != nil {
|
||||||
|
return fmt.Errorf("Could not retrieve block (geth) %d: %v\n", bn, res.Err)
|
||||||
|
}
|
||||||
|
if bg.Error != nil {
|
||||||
|
return fmt.Errorf("Error retrieving block (geth): %d %s\n", bg.Error.Code, bg.Error.Message)
|
||||||
|
}
|
||||||
|
if !compareBlocks(&b, &bg) {
|
||||||
|
if rec != nil {
|
||||||
|
fmt.Fprintf(rec, "Block difference for block=%d\n", bn)
|
||||||
|
rec.Flush()
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("Block difference for %d\n", bn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqGen.reqID++
|
||||||
|
nBlocks++
|
||||||
|
var request string
|
||||||
|
request = reqGen.getBlockByNumber(bn, true)
|
||||||
|
errCtx := fmt.Sprintf(" bn=%d ", bn)
|
||||||
|
|
||||||
|
if err := requestAndCompare(request, "eth_getBlockByNumber", errCtx, reqGen, needCompare, rec, errs, resultsCh); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("\nProcessed Blocks: ", nBlocks)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user