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

feat: shed: Add v13 migration to migrate-state #11601

Merged
merged 20 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
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
124 changes: 124 additions & 0 deletions cmd/lotus-shed/adl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package main

import (
"encoding/json"
"fmt"
"io"
"os"

"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/ipld/go-car"
"github.com/urfave/cli/v2"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

adt13 "github.com/filecoin-project/go-state-types/builtin/v13/util/adt"

"github.com/filecoin-project/lotus/blockstore"
"github.com/filecoin-project/lotus/chain/actors/adt"
)

var adlCmd = &cli.Command{
Name: "adl",
Usage: "adl manipulation commands",
Subcommands: []*cli.Command{
adlAmtCmd,
},
}

var adlAmtCmd = &cli.Command{
Name: "amt",
Usage: "AMT manipulation commands",
Subcommands: []*cli.Command{
adlAmtGetCmd,
},
}

var adlAmtGetCmd = &cli.Command{
Name: "get",
Usage: "Get an element from an AMT",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "car-file",
Usage: "write a car file with two hamts (use lotus-shed export-car)",
},
&cli.IntFlag{
Name: "bitwidth",
Usage: "bitwidth of the HAMT",
Value: 5,
},
&cli.StringFlag{
Name: "root",
Usage: "root cid of the HAMT",
},
&cli.Int64Flag{
Name: "key",
Usage: "key to get",
},
},
Action: func(cctx *cli.Context) error {
bs := blockstore.NewMemorySync()

f, err := os.Open(cctx.String("car-file"))
if err != nil {
return err
}
defer func(f *os.File) {
_ = f.Close()
}(f)

cr, err := car.NewCarReader(f)
if err != nil {
return err
}

for {
blk, err := cr.Next()
if err != nil {
if err == io.EOF {
break
}
return err
}

if err := bs.Put(cctx.Context, blk); err != nil {
return err
}
}

root, err := cid.Parse(cctx.String("root"))
if err != nil {
return err
}

m, err := adt13.AsArray(adt.WrapStore(cctx.Context, cbor.NewCborStore(bs)), root, cctx.Int("bitwidth"))
if err != nil {
return err
}

var out cbg.Deferred
ok, err := m.Get(cctx.Uint64("key"), &out)
if err != nil {
return err
}
if !ok {
return xerrors.Errorf("no such element")
}

fmt.Printf("RAW: %x\n", out.Raw)
fmt.Println("----")

var i interface{}
if err := cbor.DecodeInto(out.Raw, &i); err == nil {
ij, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err
}

fmt.Println(string(ij))
}

return nil
},
}
Loading
Loading