Skip to content

Commit

Permalink
Merge branch 'feature/account-resolver' of github.com:streamingfast/f…
Browse files Browse the repository at this point in the history
…irehose-solana into feature/account-resolver
  • Loading branch information
Eduard-Voiculescu committed Sep 1, 2023
2 parents 2124afc + 21aa7e9 commit 2209c05
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ for instructions to keep up to date.

* Migrated to firehose-core
* change block reader-node block encoding from hex to base64

* Added support for address lookup in the `reader-bt` app and tools `tablelookup`

## v0.2.2-rc1

Expand Down
7 changes: 7 additions & 0 deletions accountresolver/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ func (p *Processor) ProcessMergeBlocks(ctx context.Context, sourceStore dstore.S
startBlockNum := p.cursor.slotNum - p.cursor.slotNum%100
paddedBlockNum := fmt.Sprintf("%010d", startBlockNum)

p.logger.Info("Processing merge blocks", zap.Uint64("cursor_block_num", p.cursor.slotNum), zap.String("first_merge_filename", paddedBlockNum))

err := sourceStore.WalkFrom(ctx, "", paddedBlockNum, func(filename string) error {
p.logger.Debug("processing merge block file", zap.String("filename", filename))
return p.processMergeBlocksFile(ctx, filename, sourceStore, destinationStore)
})

if err != nil {
return fmt.Errorf("walking merge block sourceStore: %w", err)
}

p.logger.Info("Done processing merge blocks")

return nil
}

Expand All @@ -67,6 +73,7 @@ func (p *Processor) processMergeBlocksFile(ctx context.Context, filename string,
if err != nil {
return fmt.Errorf("converting filename to block number: %w", err)
}

reader, err := sourceStore.OpenObject(ctx, filename)
if err != nil {
return fmt.Errorf("opening merge block file %s: %w", filename, err)
Expand Down
27 changes: 21 additions & 6 deletions cmd/firesol/tablelookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/streamingfast/dstore"
accountsresolver "github.com/streamingfast/firehose-solana/accountresolver"
kvstore "github.com/streamingfast/kvdb/store"
Expand All @@ -23,6 +25,11 @@ func newProcessAddressLookupCmd(logger *zap.Logger, tracer logging.Tracer) *cobr
func processAddressLookupE(logger *zap.Logger, tracer logging.Tracer) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

cmd.Flags().VisitAll(func(flag *pflag.Flag) {
logger.Info("flag", zap.String("flag", flag.Name), zap.Reflect("value", flag.Value))
})

sourceStore, err := dstore.NewDBinStore(args[0])
if err != nil {
return fmt.Errorf("unable to create sourceStore: %w", err)
Expand All @@ -38,17 +45,25 @@ func processAddressLookupE(logger *zap.Logger, tracer logging.Tracer) func(cmd *
return fmt.Errorf("unable to create sourceStore: %w", err)
}

//todo: discover cursor from kv
cursor := accountsresolver.NewCursor(154655004, nil)
fmt.Println("Default Cursor", cursor)
processor := accountsresolver.NewProcessor("reproc", cursor, accountsresolver.NewKVDBAccountsResolver(db), logger)
resolver := accountsresolver.NewKVDBAccountsResolver(db)
cursor, err := resolver.GetCursor(ctx, "reproc")
if err != nil {
return fmt.Errorf("unable to get cursor: %w", err)
}

if cursor == nil {
logger.Info("No cursor found, starting from beginning")
cursor = accountsresolver.NewCursor(154655004, nil)
}

fmt.Println("Cursor", cursor)
processor := accountsresolver.NewProcessor("reproc", cursor, resolver, logger)

//todo: needs a destination sourceStore to write the merge blocks with the address lookup resolved
err = processor.ProcessMergeBlocks(ctx, sourceStore, destinationStore)
if err != nil {
return fmt.Errorf("unable to process merge blocks: %w", err)
}

logger.Info("All done. Goodbye!")
return nil
}
}

0 comments on commit 2209c05

Please sign in to comment.