Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slot to cid index for split files #168

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 42 additions & 27 deletions cmd-x-index-sig2cid.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func newCmd_Index_sig2cid() *cli.Command {
var network indexes.Network
return &cli.Command{
Name: "sig-to-cid",
Description: "Given a CAR file containing a Solana epoch, create an index of the file that maps transaction signatures to CIDs.",
ArgsUsage: "<car-path> <index-dir>",
Description: "Given one or more CAR files containing a Solana epoch, create an index of the file that maps transaction signatures to CIDs. If multiple CAR files are provided, each of them is expected to correspond to a single Subset.",
ArgsUsage: "<car-path>... <index-dir>",
Before: func(c *cli.Context) error {
if network == "" {
network = indexes.NetworkMainnet
Expand Down Expand Up @@ -56,8 +56,13 @@ func newCmd_Index_sig2cid() *cli.Command {
},
Subcommands: []*cli.Command{},
Action: func(c *cli.Context) error {
carPath := c.Args().Get(0)
indexDir := c.Args().Get(1)
args := c.Args()
if args.Len() < 2 {
return fmt.Errorf("at least one CAR file and an index directory are required")
}

carFiles := args.Slice()[:args.Len()-1]
indexDir := args.Get(args.Len() - 1)
tmpDir := c.String("tmp-dir")

if ok, err := isDirectory(indexDir); err != nil {
Expand All @@ -66,38 +71,48 @@ func newCmd_Index_sig2cid() *cli.Command {
return fmt.Errorf("index-dir is not a directory")
}

// Sort CAR files
sortedCarFiles, err := SortCarFiles(carFiles)
if err != nil {
return fmt.Errorf("failed to sort CAR files: %w", err)
}

{
startedAt := time.Now()
defer func() {
klog.Infof("Finished in %s", time.Since(startedAt))
}()
klog.Infof("Creating Sig-to-CID index for %s", carPath)
indexFilepath, err := CreateIndex_sig2cid(
context.TODO(),
epoch,
network,
tmpDir,
carPath,
indexDir,
)
if err != nil {
panic(err)
}
klog.Info("Index created")
if verify {
klog.Infof("Verifying index for %s located at %s", carPath, indexFilepath)
startedAt := time.Now()
defer func() {
klog.Infof("Finished in %s", time.Since(startedAt))
}()
err := VerifyIndex_sig2cid(context.TODO(), carPath, indexFilepath)

for _, carPath := range sortedCarFiles {
klog.Infof("Creating Sig-to-CID index for %s", carPath)
indexFilepath, err := CreateIndex_sig2cid(
context.TODO(),
epoch,
network,
tmpDir,
carPath,
indexDir,
)
if err != nil {
return cli.Exit(err, 1)
panic(err)
}
klog.Info("Index created for %s", carPath)
if verify {
klog.Infof("Verifying index for %s located at %s", carPath, indexFilepath)
startedAt := time.Now()
defer func() {
klog.Infof("Finished in %s", time.Since(startedAt))
}()
err := VerifyIndex_sig2cid(context.TODO(), carPath, indexFilepath)
if err != nil {
return cli.Exit(err, 1)
}
klog.Info("Index verified")
return nil
}
klog.Info("Index verified")
return nil
}
}
klog.Info("Index created for all CAR files")
return nil
},
}
Expand Down
Loading