Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
colindickson committed Jul 16, 2024
1 parent d78f7f4 commit d7699ed
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -16,9 +17,9 @@ import (

func newScanForEmptyReceiptsCmd(logger *zap.Logger) *cobra.Command {

Check failure on line 18 in cmd/fireeth/tools_find_unknown_status.go

View workflow job for this annotation

GitHub Actions / Test (1.22.x, ubuntu-latest)

newScanForEmptyReceiptsCmd redeclared in this block
return &cobra.Command{
Use: "scan-for-empty-receipts <src-blocks-store> <start-block> <stop-block>",
Use: "find-unknown-status <src-blocks-store> <dst-store> <start-block> <stop-block>",
Short: "look for blocks with empty receipts",
Args: cobra.ExactArgs(3),
Args: cobra.ExactArgs(4),
RunE: scanForEmptyReceiptsE(logger),
}
}
Expand All @@ -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")
Expand Down Expand Up @@ -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, 100)
for {
block, err := br.Read()
if err == io.EOF {
Expand All @@ -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 {
Expand Down

0 comments on commit d7699ed

Please sign in to comment.