Skip to content

Commit 59dda21

Browse files
authored
feat(dumpblocks): add --only-tx-hashes flag to return only tx hashes when dumping blocks (#730)
* dumpblocks: add --only-tx-hashes flag to return only tx hashes when dumping blocks * make gen-doc
1 parent 15ac729 commit 59dda21

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

cmd/dumpblocks/dumpblocks.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type (
3232
BatchSize uint64
3333
Threads uint
3434
ShouldDumpBlocks bool
35+
OnlyTxHashes bool
3536
ShouldDumpReceipts bool
3637
Filename string
3738
Mode string
@@ -87,7 +88,7 @@ var DumpblocksCmd = &cobra.Command{
8788
defer wg.Done()
8889
for {
8990
failCount := 0
90-
blocks, err := util.GetBlockRange(ctx, rangeStart, rangeEnd, ec)
91+
blocks, err := util.GetBlockRange(ctx, rangeStart, rangeEnd, ec, inputDumpblocks.OnlyTxHashes)
9192
if err != nil {
9293
failCount = failCount + 1
9394
if failCount > 5 {
@@ -146,6 +147,7 @@ func init() {
146147
f.StringVarP(&inputDumpblocks.RpcUrl, "rpc-url", "r", "http://localhost:8545", "the RPC endpoint URL")
147148
f.UintVarP(&inputDumpblocks.Threads, "concurrency", "c", 1, "how many go routines to leverage")
148149
f.BoolVarP(&inputDumpblocks.ShouldDumpBlocks, "dump-blocks", "B", true, "dump blocks to output")
150+
f.BoolVar(&inputDumpblocks.OnlyTxHashes, "only-tx-hashes", false, "dump blocks will output only the tx hashes instead of the full tx body")
149151
f.BoolVar(&inputDumpblocks.ShouldDumpReceipts, "dump-receipts", true, "dump receipts to output")
150152
f.StringVarP(&inputDumpblocks.Filename, "filename", "f", "", "where to write the output to (default stdout)")
151153
f.StringVarP(&inputDumpblocks.Mode, "mode", "m", "json", "the output format [json, proto]")

cmd/loadtest/output.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func summarizeTransactions(ctx context.Context, c *ethclient.Client, rpc *ethrpc
320320
if err != nil {
321321
return err
322322
}
323-
rawBlocks, err := util.GetBlockRange(ctx, startBlockNumber, lastBlockNumber, rpc)
323+
rawBlocks, err := util.GetBlockRange(ctx, startBlockNumber, lastBlockNumber, rpc, false)
324324
if err != nil {
325325
return err
326326
}

cmd/loadtest/recall.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ package loadtest
33
import (
44
"context"
55
"encoding/json"
6+
"math/big"
7+
"strings"
8+
69
"github.com/0xPolygon/polygon-cli/rpctypes"
710
"github.com/0xPolygon/polygon-cli/util"
811
ethtypes "github.com/ethereum/go-ethereum/core/types"
912
"github.com/ethereum/go-ethereum/ethclient"
1013
ethrpc "github.com/ethereum/go-ethereum/rpc"
11-
"math/big"
12-
"strings"
1314
)
1415

1516
// TODO allow this to be pre-specified with an input file
16-
func getRecentBlocks(ctx context.Context, ec *ethclient.Client, c *ethrpc.Client) ([]*json.RawMessage, error) {
17+
func getRecentBlocks(ctx context.Context, ec *ethclient.Client, c *ethrpc.Client, onlyTxHashes bool) ([]*json.RawMessage, error) {
1718
bn, err := ec.BlockNumber(ctx)
1819
if err != nil {
1920
return nil, err
@@ -22,12 +23,12 @@ func getRecentBlocks(ctx context.Context, ec *ethclient.Client, c *ethrpc.Client
2223
// FIXME the batch size of 25 is hard coded and probably should at least be a constant or a parameter. This limit is
2324
// different than the actual json RPC batch size of 999. Because we're fetching blocks, its' more likely that we hit
2425
// a response size limit rather than a batch length limit
25-
rawBlocks, err := util.GetBlockRangeInPages(ctx, bn-inputLoadTestParams.RecallLength, bn, 25, c)
26+
rawBlocks, err := util.GetBlockRangeInPages(ctx, bn-inputLoadTestParams.RecallLength, bn, 25, c, onlyTxHashes)
2627
return rawBlocks, err
2728
}
2829

2930
func getRecallTransactions(ctx context.Context, c *ethclient.Client, rpc *ethrpc.Client) ([]rpctypes.PolyTransaction, error) {
30-
rb, err := getRecentBlocks(ctx, c, rpc)
31+
rb, err := getRecentBlocks(ctx, c, rpc, false)
3132
if err != nil {
3233
return nil, err
3334
}
@@ -60,7 +61,7 @@ type IndexedActivity struct {
6061
}
6162

6263
func getIndexedRecentActivity(ctx context.Context, ec *ethclient.Client, c *ethrpc.Client) (*IndexedActivity, error) {
63-
blockData, err := getRecentBlocks(ctx, ec, c)
64+
blockData, err := getRecentBlocks(ctx, ec, c, false)
6465
if err != nil {
6566
return nil, err
6667
}

doc/polycli_dumpblocks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ To solve this, add the unknown fields to the `.proto` files and recompile them (
8282
-F, --filter string filter output based on tx to and from (not setting a filter means all are allowed) (default "{}")
8383
-h, --help help for dumpblocks
8484
-m, --mode string the output format [json, proto] (default "json")
85+
--only-tx-hashes dump blocks will output only the tx hashes instead of the full tx body
8586
-r, --rpc-url string the RPC endpoint URL (default "http://localhost:8545")
8687
```
8788

util/util.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@ func EcrecoverTx(tx *types.Transaction) ([]byte, error) {
6060
return from.Bytes(), nil
6161
}
6262

63-
func GetBlockRange(ctx context.Context, from, to uint64, c *ethrpc.Client) ([]*json.RawMessage, error) {
63+
func GetBlockRange(ctx context.Context, from, to uint64, c *ethrpc.Client, onlyTxHashes bool) ([]*json.RawMessage, error) {
6464
blms := make([]ethrpc.BatchElem, 0)
6565
for i := from; i <= to; i = i + 1 {
6666
r := new(json.RawMessage)
6767
var err error
6868
blms = append(blms, ethrpc.BatchElem{
6969
Method: "eth_getBlockByNumber",
70-
Args: []interface{}{"0x" + strconv.FormatUint(i, 16), true},
70+
Args: []interface{}{"0x" + strconv.FormatUint(i, 16), !onlyTxHashes},
7171
Result: r,
7272
Error: err,
7373
})
@@ -92,7 +92,7 @@ func GetBlockRange(ctx context.Context, from, to uint64, c *ethrpc.Client) ([]*j
9292
return blocks, nil
9393
}
9494

95-
func GetBlockRangeInPages(ctx context.Context, from, to, pageSize uint64, c *ethrpc.Client) ([]*json.RawMessage, error) {
95+
func GetBlockRangeInPages(ctx context.Context, from, to, pageSize uint64, c *ethrpc.Client, onlyTxHashes bool) ([]*json.RawMessage, error) {
9696
var allBlocks []*json.RawMessage
9797

9898
for i := from; i <= to; i += pageSize {
@@ -101,7 +101,7 @@ func GetBlockRangeInPages(ctx context.Context, from, to, pageSize uint64, c *eth
101101
end = to
102102
}
103103

104-
blocks, err := GetBlockRange(ctx, i, end, c)
104+
blocks, err := GetBlockRange(ctx, i, end, c, onlyTxHashes)
105105
if err != nil {
106106
return nil, err
107107
}

0 commit comments

Comments
 (0)