-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8edb117
commit 635d7b3
Showing
12 changed files
with
437 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/urfave/cli/v2" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func newCmd_Index_slot2cid() *cli.Command { | ||
var verify bool | ||
return &cli.Command{ | ||
Name: "slot-to-cid", | ||
Description: "Given a CAR file containing a Solana epoch, create an index of the file that maps slot numbers to CIDs.", | ||
ArgsUsage: "<car-path> <index-dir>", | ||
Before: func(c *cli.Context) error { | ||
return nil | ||
}, | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: "verify", | ||
Usage: "verify the index after creating it", | ||
Destination: &verify, | ||
}, | ||
}, | ||
Subcommands: []*cli.Command{}, | ||
Action: func(c *cli.Context) error { | ||
carPath := c.Args().Get(0) | ||
indexDir := c.Args().Get(1) | ||
|
||
{ | ||
startedAt := time.Now() | ||
defer func() { | ||
klog.Infof("Finished in %s", time.Since(startedAt)) | ||
}() | ||
klog.Infof("Creating Slot-to-CID index for %s", carPath) | ||
indexFilepath, err := CreateIndex_slot2cid( | ||
context.TODO(), | ||
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_slot2cid(context.TODO(), carPath, indexFilepath) | ||
if err != nil { | ||
return cli.Exit(err, 1) | ||
} | ||
klog.Info("Index verified") | ||
return nil | ||
} | ||
} | ||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/urfave/cli/v2" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func newCmd_VerifyIndex_slot2cid() *cli.Command { | ||
return &cli.Command{ | ||
Name: "slot-to-cid", | ||
Description: "Verify the index of the CAR file that maps slot numbers to CIDs.", | ||
ArgsUsage: "<car-path> <index-file-path>", | ||
Before: func(c *cli.Context) error { | ||
return nil | ||
}, | ||
Flags: []cli.Flag{}, | ||
Action: func(c *cli.Context) error { | ||
carPath := c.Args().Get(0) | ||
indexFilePath := c.Args().Get(1) | ||
{ | ||
startedAt := time.Now() | ||
defer func() { | ||
klog.Infof("Finished in %s", time.Since(startedAt)) | ||
}() | ||
klog.Infof("Verifying Slot-to-CID index for %s", carPath) | ||
err := VerifyIndex_slot2cid(context.TODO(), carPath, indexFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
klog.Info("Index verified successfully") | ||
} | ||
return nil | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.