diff --git a/cmd/rpctest/main.go b/cmd/rpctest/main.go index 5ce6a6c71..78eb87af2 100644 --- a/cmd/rpctest/main.go +++ b/cmd/rpctest/main.go @@ -290,6 +290,19 @@ func main() { } with(benchTraceFilterCmd, withGethUrl, withErigonUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile) + var benchDebugTraceBlockByNumberCmd = &cobra.Command{ + Use: "benchDebugTraceBlockByNumber", + Short: "", + Long: ``, + Run: func(cmd *cobra.Command, args []string) { + err := rpctest.BenchDebugTraceBlockByNumber(erigonURL, gethURL, needCompare, blockFrom, blockTo, recordFile, errorFile) + if err != nil { + logger.Error(err.Error()) + } + }, + } + with(benchDebugTraceBlockByNumberCmd, withErigonUrl, withGethUrl, withNeedCompare, withBlockNum, withRecord, withErrorFile, withLatest) + var benchTxReceiptCmd = &cobra.Command{ Use: "benchTxReceipt", Short: "", @@ -384,6 +397,7 @@ func main() { benchTraceCallManyCmd, benchTraceBlockCmd, benchTraceFilterCmd, + benchDebugTraceBlockByNumberCmd, benchTxReceiptCmd, compareAccountRange, benchTraceReplayTransactionCmd, diff --git a/cmd/rpctest/rpctest/bench_debugTraceBlockByNumber.go b/cmd/rpctest/rpctest/bench_debugTraceBlockByNumber.go new file mode 100644 index 000000000..39b92bd1d --- /dev/null +++ b/cmd/rpctest/rpctest/bench_debugTraceBlockByNumber.go @@ -0,0 +1,58 @@ +package rpctest + +import ( + "bufio" + "fmt" + "net/http" + "os" + "time" +) + +func BenchDebugTraceBlockByNumber(erigonUrl, gethUrl string, needCompare bool, blockFrom uint64, blockTo uint64, recordFileName string, errorFileName string) error { + setRoutes(erigonUrl, gethUrl) + var client = &http.Client{ + Timeout: time.Second * 600, + } + + var rec *bufio.Writer + if recordFileName != "" { + f, err := os.Create(recordFileName) + if err != nil { + return fmt.Errorf("Cannot create file %s for recording: %v\n", recordFileName, err) + } + defer f.Close() + rec = bufio.NewWriter(f) + defer rec.Flush() + } + var errs *bufio.Writer + if errorFileName != "" { + ferr, err := os.Create(errorFileName) + if err != nil { + return fmt.Errorf("Cannot create file %s for error output: %v\n", errorFileName, err) + } + defer ferr.Close() + errs = bufio.NewWriter(ferr) + defer errs.Flush() + } + + var resultsCh chan CallResult = nil + if !needCompare { + resultsCh = make(chan CallResult, 1000) + defer close(resultsCh) + go vegetaWrite(true, []string{"debug_traceBlockByNumber"}, resultsCh) + } + + reqGen := &RequestGenerator{ + client: client, + } + + for bn := blockFrom; bn < blockTo; bn++ { + reqGen.reqID++ + request := reqGen.debugTraceBlockByNumber(bn) + errCtx := fmt.Sprintf("block %d", bn) + if err := requestAndCompare(request, "debug_traceBlockByNumber", errCtx, reqGen, needCompare, rec, errs, resultsCh); err != nil { + return err + } + } + return nil +} diff --git a/cmd/rpctest/rpctest/request_generator.go b/cmd/rpctest/rpctest/request_generator.go index 67c699529..4016bebc5 100644 --- a/cmd/rpctest/rpctest/request_generator.go +++ b/cmd/rpctest/rpctest/request_generator.go @@ -3,11 +3,12 @@ package rpctest import ( "encoding/base64" "fmt" - "github.com/ledgerwatch/erigon-lib/common/hexutil" "net/http" "strings" "time" + "github.com/ledgerwatch/erigon-lib/common/hexutil" + "github.com/valyala/fastjson" libcommon "github.com/ledgerwatch/erigon-lib/common" @@ -58,6 +59,11 @@ func (g *RequestGenerator) traceBlockByHash(hash string) string { return fmt.Sprintf(template, hash, g.reqID) } +func (g *RequestGenerator) debugTraceBlockByNumber(blockNum uint64) string { + const template = `{"jsonrpc":"2.0","method":"debug_traceBlockByNumber","params":[%d],"id":%d}` + return fmt.Sprintf(template, blockNum, g.reqID) +} + func (g *RequestGenerator) traceTransaction(hash string) string { const template = `{"jsonrpc":"2.0","method":"debug_traceTransaction","params":["%s"],"id":%d}` return fmt.Sprintf(template, hash, g.reqID)