Skip to content

Commit

Permalink
feat: shed: Add v13 migration to migrate-state (#11601)
Browse files Browse the repository at this point in the history
* shed: Add v13 migration to migrate-state

* shed: some ADL tools, update GST

* shed: diff hamt address mode

* shed migration debug tooling

* shed migration: market diff on error

* shed: Fix cached migration diff

* shed: Diff deal states on bad migration

* shed: Use std json

* shed: Drill in the migration diff more

* shed: Show proposals in migration market diff

* shed: Show added provider sectors diff

* shed: hamts are hard to use

* update  gst

* update gst

* update gst

* update GST with fixed invartiant

* go mod tidy
  • Loading branch information
magik6k authored Mar 21, 2024
1 parent 1b66824 commit 734db29
Show file tree
Hide file tree
Showing 5 changed files with 782 additions and 2 deletions.
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

0 comments on commit 734db29

Please sign in to comment.