From 19a65319ee2bd120e87f1b68120fe10e8a83bcdf Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 30 Jan 2020 18:13:53 -0800 Subject: [PATCH] test and fix fork, add bigint parsing to lotus shed --- build/forks.go | 2 +- chain/stmgr/forks.go | 4 ++-- cmd/lotus-shed/bigint.go | 47 ++++++++++++++++++++++++++++++++++++++++ cmd/lotus-shed/main.go | 1 + 4 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 cmd/lotus-shed/bigint.go diff --git a/build/forks.go b/build/forks.go index 6002f89eb..02c0282bb 100644 --- a/build/forks.go +++ b/build/forks.go @@ -6,4 +6,4 @@ const ForkFrigidHeight = 7950 const ForkBootyBayHeight = 11000 -const ForkMissingSnowballs = 32000 +const ForkMissingSnowballs = 33000 diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index eb98029c6..8576b923f 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -40,7 +40,7 @@ func (sm *StateManager) handleStateForks(ctx context.Context, pstate cid.Cid, he log.Warnw("Adding more snow to the world", "height", i) pstate, err = fixTooFewSnowballs(ctx, sm, pstate) if err != nil { - return cid.Undef, xerrors.Errorf("booty bay bug fix failed: %w", err) + return cid.Undef, xerrors.Errorf("missing snowballs bug fix failed: %w", err) } } } @@ -89,7 +89,7 @@ func fixTooFewSnowballs(ctx context.Context, sm *StateManager, pstate cid.Cid) ( } spast.TotalStorage.Int = sum - nspahead, err := cst.Put(ctx, spast) + nspahead, err := cst.Put(ctx, &spast) if err != nil { return cid.Undef, err } diff --git a/cmd/lotus-shed/bigint.go b/cmd/lotus-shed/bigint.go new file mode 100644 index 000000000..3db0de68d --- /dev/null +++ b/cmd/lotus-shed/bigint.go @@ -0,0 +1,47 @@ +package main + +import ( + "encoding/base64" + "encoding/hex" + "fmt" + + "github.com/filecoin-project/lotus/chain/types" + "gopkg.in/urfave/cli.v2" +) + +var bigIntParseCmd = &cli.Command{ + Name: "bigint", + Description: "parse encoded big ints", + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "enc", + Value: "base64", + Usage: "specify input encoding to parse", + }, + }, + Action: func(cctx *cli.Context) error { + val := cctx.Args().Get(0) + + var dec []byte + switch cctx.String("enc") { + case "base64": + d, err := base64.StdEncoding.DecodeString(val) + if err != nil { + return fmt.Errorf("decoding base64 value: %w", err) + } + dec = d + case "hex": + d, err := hex.DecodeString(val) + if err != nil { + return fmt.Errorf("decoding hex value: %w", err) + } + dec = d + default: + return fmt.Errorf("unrecognized encoding: %s", cctx.String("enc")) + } + + iv := types.BigFromBytes(dec) + fmt.Println(iv.String()) + return nil + }, +} diff --git a/cmd/lotus-shed/main.go b/cmd/lotus-shed/main.go index fe8abb233..749ff2945 100644 --- a/cmd/lotus-shed/main.go +++ b/cmd/lotus-shed/main.go @@ -20,6 +20,7 @@ func main() { keyinfoCmd, peerkeyCmd, noncefix, + bigIntParseCmd, } app := &cli.App{