diff --git a/cmd/fireeth/main.go b/cmd/fireeth/main.go index fbeada0..ac747ae 100644 --- a/cmd/fireeth/main.go +++ b/cmd/fireeth/main.go @@ -110,7 +110,7 @@ func Chain() *firecore.Chain[*pbeth.Block] { parent.AddCommand(newPollRPCBlocksCmd(zlog)) parent.AddCommand(newPollerCmd(zlog, tracer)) parent.AddCommand(newOptimismPollerCmd(zlog, tracer)) - parent.AddCommand(newScanForEmptyReceiptsCmd(zlog)) + parent.AddCommand(newScanForUnknownStatusCmd(zlog)) registerGethEnforcePeersCmd(parent, chain.BinaryName(), zlog, tracer) diff --git a/cmd/fireeth/tools_find_empty_reciepts.go b/cmd/fireeth/tools_find_unknown_status.go similarity index 71% rename from cmd/fireeth/tools_find_empty_reciepts.go rename to cmd/fireeth/tools_find_unknown_status.go index 431058a..b35f9ee 100644 --- a/cmd/fireeth/tools_find_empty_reciepts.go +++ b/cmd/fireeth/tools_find_unknown_status.go @@ -1,11 +1,12 @@ package main import ( + "bytes" + "encoding/json" "fmt" "io" "github.com/streamingfast/bstream" - pbbstream "github.com/streamingfast/bstream/pb/sf/bstream/v1" pbeth "github.com/streamingfast/firehose-ethereum/types/pb/sf/ethereum/type/v2" "github.com/spf13/cobra" @@ -14,16 +15,16 @@ import ( "go.uber.org/zap" ) -func newScanForEmptyReceiptsCmd(logger *zap.Logger) *cobra.Command { +func newScanForUnknownStatusCmd(logger *zap.Logger) *cobra.Command { return &cobra.Command{ - Use: "scan-for-empty-receipts ", + Use: "find-unknown-status ", Short: "look for blocks with empty receipts", - Args: cobra.ExactArgs(3), - RunE: scanForEmptyReceiptsE(logger), + Args: cobra.ExactArgs(4), + RunE: scanForUnknownStatusE(logger), } } -func scanForEmptyReceiptsE(logger *zap.Logger) firecore.CommandExecutor { +func scanForUnknownStatusE(logger *zap.Logger) firecore.CommandExecutor { return func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() @@ -32,8 +33,13 @@ func scanForEmptyReceiptsE(logger *zap.Logger) firecore.CommandExecutor { return fmt.Errorf("unable to create source store: %w", err) } - start := mustParseUint64(args[1]) - stop := mustParseUint64(args[2]) + outputStore, err := dstore.NewDBinStore(args[1]) + if err != nil { + return fmt.Errorf("unable to create output store: %w", err) + } + + start := mustParseUint64(args[2]) + stop := mustParseUint64(args[3]) if stop <= start { return fmt.Errorf("stop block must be greater than start block") @@ -66,7 +72,7 @@ func scanForEmptyReceiptsE(logger *zap.Logger) firecore.CommandExecutor { return fmt.Errorf("creating block reader: %w", err) } - blocks := make([]*pbbstream.Block, 100) + blocks := make([]uint64, 0, 100) for { block, err := br.Read() if err == io.EOF { @@ -81,12 +87,21 @@ func scanForEmptyReceiptsE(logger *zap.Logger) firecore.CommandExecutor { for _, trace := range ethBlock.TransactionTraces { if trace.Status == pbeth.TransactionTraceStatus_UNKNOWN { - blocks = append(blocks, block) + blocks = append(blocks, block.Number) logger.Info("found block with empty receipt", zap.Uint64("block_num", ethBlock.Number)) break } } } + + if len(blocks) > 0 { + data, _ := json.Marshal(blocks) + err = outputStore.WriteObject(ctx, fmt.Sprintf("%010d_%d.json", startBlock, len(blocks)), bytes.NewBuffer(data)) + if err != nil { + return fmt.Errorf("failed to write output file: %w", err) + } + } + return nil }) if err != nil && err != io.EOF {