From 9fd80d9c50c7fcaa6d9df1c03b4e2670df09cdee Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 09:38:02 +1000 Subject: [PATCH 01/15] add toolbox cli; add precommit stuck cmd --- cmd/toolbox/main.go | 137 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 cmd/toolbox/main.go diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go new file mode 100644 index 000000000..6d1864e8c --- /dev/null +++ b/cmd/toolbox/main.go @@ -0,0 +1,137 @@ +package main + +import ( + "context" + "fmt" + "os" + "os/signal" + + logging "github.com/ipfs/go-log/v2" + "github.com/urfave/cli/v2" + + "github.com/filecoin-project/go-address" + + "github.com/filecoin-project/curio/build" + "github.com/filecoin-project/curio/deps" +) + +var log = logging.Logger("toolbox") + +func main() { + local := []*cli.Command{ + precommitStuckCmd, + } + + app := &cli.App{ + Name: "toolbox", + Usage: "Some tools to fix some problems", + Version: build.UserVersion(), + EnableBashCompletion: true, + Commands: local, + Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "repo", + EnvVars: []string{"LOTUS_PATH"}, + Hidden: true, + Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME + }, + &cli.StringFlag{ + Name: "log-level", + Value: "info", + }, + &cli.StringFlag{ + Name: "actor", + Required: os.Getenv("LOTUS_DOCS_GENERATION") != "1", + Usage: "miner actor to manage", + EnvVars: []string{"SP_ADDRESS"}, + }, + }, + Before: func(cctx *cli.Context) error { + return logging.SetLogLevel("toolbox", cctx.String("toolbox")) + }, + } + + // terminate early on ctrl+c + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt) + ctx, cancel := context.WithCancel(context.Background()) + go func() { + <-c + cancel() + fmt.Println("Received interrupt, shutting down... Press CTRL+C again to force shutdown") + <-c + fmt.Println("Forcing stop") + os.Exit(1) + }() + + if err := app.RunContext(ctx, os.Args); err != nil { + log.Errorf("%+v", err) + os.Exit(1) + return + } + +} + +func SPTActorGetter(cctx *cli.Context) (address.Address, error) { + addr, err := address.NewFromString(cctx.String("actor")) + if err != nil { + return address.Undef, fmt.Errorf("parsing address: %w", err) + } + return addr, nil +} + +var precommitStuckCmd = &cli.Command{ + Name: "precommit-stuck", + Usage: "Perform db operations to fix issues with precommit messages getting stuck", + Action: func(cctx *cli.Context) error { + db, err := deps.MakeDB(cctx) + if err != nil { + log.Error(err) + return err + } + + // retrieve messages from curio.message_waits which does not have a executed_tsk_cid + var msgs []struct { + SignedMsgCID string `db:"signed_message_cid"` + PrecommitMsgCID *string `db:"precommit_msg_cid"` + CommitMsgCID *string `db:"commit_msg_cid"` + + ExecutedTskCID string `db:"executed_tsk_cid"` + ExecutedTskEpoch int64 `db:"executed_tsk_epoch"` + ExecutedMsgCID string `db:"executed_msg_cid"` + + ExecutedRcptExitCode int64 `db:"executed_rcpt_exitcode"` + ExecutedRcptGasUsed int64 `db:"executed_rcpt_gas_used"` + } + + err = db.Select(cctx.Context, &msgs, `SELECT spipeline.precommit_msg_cid, spipeline.commit_msg_cid, executed_tsk_cid, executed_tsk_epoch, executed_msg_cid, executed_rcpt_exitcode, executed_rcpt_gas_used + FROM sectors_sdr_pipeline spipeline + JOIN message_waits ON spipeline.precommit_msg_cid = message_waits.signed_message_cid + WHERE executed_tsk_cid IS NOT NULL`) + if err != nil { + log.Errorw("failed to query message_waits", "error", err) + } + + for _, msg := range msgs { + fmt.Println(msg) + } + // x := []string{"bafy2bzacedehedwzrygquxxhu4ws2nyfmdv5k3ylx76ywngp2xkfszwvbpn3s", "bafy2bzaceaa57zjswk4iaco2wg5f47egtcxu3m7crbwpz3ooc4hlczzwwb64e", "bafy2bzacedzt6c2egc264vob4e76llgdhvfb4awfqqpii44r3canihhcjyywk", "bafy2bzacecfew4ke47l7hdqcews46xw4enhsawbtkewnu7aomob5275bdpe4q", "bafy2bzacecbzyyokd2hxtpdophhiy5aown6yybkmhnnta7n5wo5u6p55k5zry", "bafy2bzaceasvkpeltvbuqrd4y5em235fbxvihtzb5ijbkfwpr53oufyitrcaq"} + // var tskey []cid.Cid + // for _, s := range x { + // bcid, err := cid.Parse(s) + // if err != nil { + // return err + // } + // tskey = append(tskey, bcid) + // } + + // tsk := types.NewTipSetKey(tskey...) + + // tcid, err := tsk.Cid() + // if err != nil { + // return err + // } + // fmt.Println(tcid.String()) + return nil + }, +} From e6e32954974f729c4d4775614e73f7f6b555d93b Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 09:38:27 +1000 Subject: [PATCH 02/15] add toolbox cli; add precommit stuck cmd --- cmd/toolbox/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index 6d1864e8c..dbb04ca15 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -115,7 +115,7 @@ var precommitStuckCmd = &cli.Command{ for _, msg := range msgs { fmt.Println(msg) } - // x := []string{"bafy2bzacedehedwzrygquxxhu4ws2nyfmdv5k3ylx76ywngp2xkfszwvbpn3s", "bafy2bzaceaa57zjswk4iaco2wg5f47egtcxu3m7crbwpz3ooc4hlczzwwb64e", "bafy2bzacedzt6c2egc264vob4e76llgdhvfb4awfqqpii44r3canihhcjyywk", "bafy2bzacecfew4ke47l7hdqcews46xw4enhsawbtkewnu7aomob5275bdpe4q", "bafy2bzacecbzyyokd2hxtpdophhiy5aown6yybkmhnnta7n5wo5u6p55k5zry", "bafy2bzaceasvkpeltvbuqrd4y5em235fbxvihtzb5ijbkfwpr53oufyitrcaq"} + // x := []string{} // var tskey []cid.Cid // for _, s := range x { // bcid, err := cid.Parse(s) From 60bf6bbb8301d2c1674f14df6448afedf6836343 Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:17:50 +1000 Subject: [PATCH 03/15] add toolbox to makefile; fix query --- Makefile | 10 ++++++++-- cmd/toolbox/main.go | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 4eee42436..7d0295a21 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,12 @@ sptool: $(BUILD_DEPS) .PHONY: sptool BINS+=sptool +toolbox: $(BUILD_DEPS) + rm -f toolbox + $(GOCC) build $(GOFLAGS) -o toolbox ./cmd/toolbox +.PHONY: toolbox +BINS+=toolbox + ifeq ($(shell uname),Linux) batchdep: build/.supraseal-install @@ -130,7 +136,7 @@ debug: build 2k: GOFLAGS+=-tags=2k 2k: build -all: build +all: build .PHONY: all build: curio sptool @@ -218,7 +224,7 @@ docsgen-openrpc: docsgen-openrpc-curio @echo "FixImports will run only from the 'make gen' target" .PHONY: docsgen-openrpc -docsgen-openrpc-bin: api-gen +docsgen-openrpc-bin: api-gen $(GOCC) build $(GOFLAGS) -o docgen-openrpc ./api/docgen-openrpc/cmd docsgen-openrpc-curio: docsgen-openrpc-bin diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index dbb04ca15..b823f526e 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -107,9 +107,10 @@ var precommitStuckCmd = &cli.Command{ err = db.Select(cctx.Context, &msgs, `SELECT spipeline.precommit_msg_cid, spipeline.commit_msg_cid, executed_tsk_cid, executed_tsk_epoch, executed_msg_cid, executed_rcpt_exitcode, executed_rcpt_gas_used FROM sectors_sdr_pipeline spipeline JOIN message_waits ON spipeline.precommit_msg_cid = message_waits.signed_message_cid - WHERE executed_tsk_cid IS NOT NULL`) + WHERE executed_tsk_cid IS NULL`) if err != nil { log.Errorw("failed to query message_waits", "error", err) + return err } for _, msg := range msgs { From e4daba8f8270b0bef163b10ca529ad056d05f8d6 Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:23:04 +1000 Subject: [PATCH 04/15] fix indenting --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7d0295a21..3c3e93d11 100644 --- a/Makefile +++ b/Makefile @@ -96,8 +96,8 @@ sptool: $(BUILD_DEPS) BINS+=sptool toolbox: $(BUILD_DEPS) - rm -f toolbox - $(GOCC) build $(GOFLAGS) -o toolbox ./cmd/toolbox + rm -f toolbox + $(GOCC) build $(GOFLAGS) -o toolbox ./cmd/toolbox .PHONY: toolbox BINS+=toolbox From aeef23e1779d822eeda4031ea9903e4e70b74d5b Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:23:47 +1000 Subject: [PATCH 05/15] fix indenting --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3c3e93d11..98517e44b 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ BINS+=sptool toolbox: $(BUILD_DEPS) rm -f toolbox - $(GOCC) build $(GOFLAGS) -o toolbox ./cmd/toolbox + $(GOCC) build $(GOFLAGS) -o toolbox ./cmd/toolbox .PHONY: toolbox BINS+=toolbox From 009a2701747fdd85a8e3895cdaf34facc51f778a Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:25:21 +1000 Subject: [PATCH 06/15] use standard string instead of pointer --- cmd/toolbox/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index b823f526e..1346fde51 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -92,9 +92,9 @@ var precommitStuckCmd = &cli.Command{ // retrieve messages from curio.message_waits which does not have a executed_tsk_cid var msgs []struct { - SignedMsgCID string `db:"signed_message_cid"` - PrecommitMsgCID *string `db:"precommit_msg_cid"` - CommitMsgCID *string `db:"commit_msg_cid"` + SignedMsgCID string `db:"signed_message_cid"` + PrecommitMsgCID string `db:"precommit_msg_cid"` + CommitMsgCID string `db:"commit_msg_cid"` ExecutedTskCID string `db:"executed_tsk_cid"` ExecutedTskEpoch int64 `db:"executed_tsk_epoch"` From 675916faaa20411491694d0f941c17e4756d302b Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:30:10 +1000 Subject: [PATCH 07/15] use pointer so they are nullable --- cmd/toolbox/main.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index 1346fde51..89b65f3ac 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -92,16 +92,16 @@ var precommitStuckCmd = &cli.Command{ // retrieve messages from curio.message_waits which does not have a executed_tsk_cid var msgs []struct { - SignedMsgCID string `db:"signed_message_cid"` - PrecommitMsgCID string `db:"precommit_msg_cid"` - CommitMsgCID string `db:"commit_msg_cid"` + SignedMsgCID *string `db:"signed_message_cid"` + PrecommitMsgCID *string `db:"precommit_msg_cid"` + CommitMsgCID *string `db:"commit_msg_cid"` - ExecutedTskCID string `db:"executed_tsk_cid"` - ExecutedTskEpoch int64 `db:"executed_tsk_epoch"` - ExecutedMsgCID string `db:"executed_msg_cid"` + ExecutedTskCID *string `db:"executed_tsk_cid"` + ExecutedTskEpoch int64 `db:"executed_tsk_epoch"` + ExecutedMsgCID *string `db:"executed_msg_cid"` - ExecutedRcptExitCode int64 `db:"executed_rcpt_exitcode"` - ExecutedRcptGasUsed int64 `db:"executed_rcpt_gas_used"` + ExecutedRcptExitCode *int64 `db:"executed_rcpt_exitcode"` + ExecutedRcptGasUsed *int64 `db:"executed_rcpt_gas_used"` } err = db.Select(cctx.Context, &msgs, `SELECT spipeline.precommit_msg_cid, spipeline.commit_msg_cid, executed_tsk_cid, executed_tsk_epoch, executed_msg_cid, executed_rcpt_exitcode, executed_rcpt_gas_used From 5a3a7b7bb757cd1608d216aa7db83d70834d7dff Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:31:19 +1000 Subject: [PATCH 08/15] use pointer so they are nullable --- cmd/toolbox/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index 89b65f3ac..eb99a59c3 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -97,7 +97,7 @@ var precommitStuckCmd = &cli.Command{ CommitMsgCID *string `db:"commit_msg_cid"` ExecutedTskCID *string `db:"executed_tsk_cid"` - ExecutedTskEpoch int64 `db:"executed_tsk_epoch"` + ExecutedTskEpoch *int64 `db:"executed_tsk_epoch"` ExecutedMsgCID *string `db:"executed_msg_cid"` ExecutedRcptExitCode *int64 `db:"executed_rcpt_exitcode"` From 8e3a95a4cc3b69524b5950055429b347e0f92191 Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:46:10 +1000 Subject: [PATCH 09/15] use filfox api to confirm message type of cid --- cmd/toolbox/main.go | 98 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index eb99a59c3..1c52b20b3 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -2,7 +2,10 @@ package main import ( "context" + "encoding/json" "fmt" + "io" + "net/http" "os" "os/signal" @@ -113,9 +116,17 @@ var precommitStuckCmd = &cli.Command{ return err } + // check if cid is associated with a precommit msg onchain via filfox api + var ffmsgs []FilfoxMsg for _, msg := range msgs { - fmt.Println(msg) + ffmsg, err := filfoxMessage(*msg.PrecommitMsgCID) + if err != nil { + return err + } + fmt.Println(ffmsg) + ffmsgs = append(ffmsgs, ffmsg) } + // x := []string{} // var tskey []cid.Cid // for _, s := range x { @@ -136,3 +147,88 @@ var precommitStuckCmd = &cli.Command{ return nil }, } + +func req(url string) ([]byte, error) { + method := "GET" + client := &http.Client{} + req, err := http.NewRequest(method, url, nil) + if err != nil { + return nil, err + } + res, err := client.Do(req) + if err != nil { + return nil, err + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + return nil, err + } + return body, nil +} + +type FilfoxMsg struct { + Cid string `json:"cid,omitempty"` + Height int `json:"height,omitempty"` + Timestamp int `json:"timestamp,omitempty"` + Confirmations int `json:"confirmations,omitempty"` + Blocks []string `json:"blocks,omitempty"` + Version int `json:"version,omitempty"` + From string `json:"from,omitempty"` + FromID string `json:"fromId,omitempty"` + FromActor string `json:"fromActor,omitempty"` + To string `json:"to,omitempty"` + ToID string `json:"toId,omitempty"` + ToActor string `json:"toActor,omitempty"` + Nonce int `json:"nonce,omitempty"` + Value string `json:"value,omitempty"` + GasLimit int `json:"gasLimit,omitempty"` + GasFeeCap string `json:"gasFeeCap,omitempty"` + GasPremium string `json:"gasPremium,omitempty"` + Method string `json:"method,omitempty"` + MethodNumber int `json:"methodNumber,omitempty"` + EvmMethod string `json:"evmMethod,omitempty"` + Params string `json:"params,omitempty"` + Receipt struct { + ExitCode int `json:"exitCode,omitempty"` + Return string `json:"return,omitempty"` + GasUsed int `json:"gasUsed,omitempty"` + } `json:"receipt,omitempty"` + Size int `json:"size,omitempty"` + Error string `json:"error,omitempty"` + BaseFee string `json:"baseFee,omitempty"` + Fee struct { + BaseFeeBurn string `json:"baseFeeBurn,omitempty"` + OverEstimationBurn string `json:"overEstimationBurn,omitempty"` + MinerPenalty string `json:"minerPenalty,omitempty"` + MinerTip string `json:"minerTip,omitempty"` + Refund string `json:"refund,omitempty"` + } `json:"fee,omitempty"` + Transfers []struct { + From string `json:"from,omitempty"` + FromID string `json:"fromId,omitempty"` + To string `json:"to,omitempty"` + ToID string `json:"toId,omitempty"` + Value string `json:"value,omitempty"` + Type string `json:"type,omitempty"` + } `json:"transfers,omitempty"` + EthTransactionHash string `json:"ethTransactionHash,omitempty"` + EventLogCount int `json:"eventLogCount,omitempty"` + SubcallCount int `json:"subcallCount,omitempty"` + TokenTransfers []any `json:"tokenTransfers,omitempty"` +} + +func filfoxMessage(cid string) (FilfoxMsg, error) { + url := fmt.Sprintf("https://filfox.info/api/v1/message/%s", cid) + body, err := req(url) + if err != nil { + return FilfoxMsg{}, err + } + var resp FilfoxMsg + err = json.Unmarshal(body, &resp) + if err != nil { + return FilfoxMsg{}, err + } + return resp, nil +} From 25aec19e72b2f24ed3b19c9dd0bbcf4d745647c0 Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:51:14 +1000 Subject: [PATCH 10/15] generate executed_tsk_cid --- cmd/toolbox/main.go | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index 1c52b20b3..bf528008f 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -9,10 +9,12 @@ import ( "os" "os/signal" + "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "github.com/urfave/cli/v2" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/curio/build" "github.com/filecoin-project/curio/deps" @@ -117,33 +119,33 @@ var precommitStuckCmd = &cli.Command{ } // check if cid is associated with a precommit msg onchain via filfox api - var ffmsgs []FilfoxMsg + var pcmsgs []string for _, msg := range msgs { ffmsg, err := filfoxMessage(*msg.PrecommitMsgCID) if err != nil { return err } - fmt.Println(ffmsg) - ffmsgs = append(ffmsgs, ffmsg) + if ffmsg.MethodNumber == 28 { + pcmsgs = append(pcmsgs, *msg.PrecommitMsgCID) + } + } + + var tskey []cid.Cid + for _, s := range pcmsgs { + bcid, err := cid.Parse(s) + if err != nil { + return err + } + tskey = append(tskey, bcid) } - // x := []string{} - // var tskey []cid.Cid - // for _, s := range x { - // bcid, err := cid.Parse(s) - // if err != nil { - // return err - // } - // tskey = append(tskey, bcid) - // } - - // tsk := types.NewTipSetKey(tskey...) - - // tcid, err := tsk.Cid() - // if err != nil { - // return err - // } - // fmt.Println(tcid.String()) + tsk := types.NewTipSetKey(tskey...) + + tcid, err := tsk.Cid() + if err != nil { + return err + } + fmt.Println(tcid.String()) return nil }, } From bdb51525746325d67d2fb6b45bc70f49ca78f21c Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 10:52:37 +1000 Subject: [PATCH 11/15] keep filfox json around --- cmd/toolbox/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index bf528008f..95a7c7910 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -120,6 +120,7 @@ var precommitStuckCmd = &cli.Command{ // check if cid is associated with a precommit msg onchain via filfox api var pcmsgs []string + var ffmsgs []FilfoxMsg for _, msg := range msgs { ffmsg, err := filfoxMessage(*msg.PrecommitMsgCID) if err != nil { @@ -127,6 +128,7 @@ var precommitStuckCmd = &cli.Command{ } if ffmsg.MethodNumber == 28 { pcmsgs = append(pcmsgs, *msg.PrecommitMsgCID) + ffmsgs = append(ffmsgs, ffmsg) } } From 1d0e1242f023d541fde94207b88397d9ee1e999e Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 12:52:34 +1000 Subject: [PATCH 12/15] add sql update of message_waits --- cmd/toolbox/main.go | 93 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 19 deletions(-) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index 95a7c7910..3958afb83 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -8,12 +8,14 @@ import ( "net/http" "os" "os/signal" + "strconv" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "github.com/urfave/cli/v2" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/curio/build" @@ -119,35 +121,52 @@ var precommitStuckCmd = &cli.Command{ } // check if cid is associated with a precommit msg onchain via filfox api - var pcmsgs []string - var ffmsgs []FilfoxMsg for _, msg := range msgs { ffmsg, err := filfoxMessage(*msg.PrecommitMsgCID) if err != nil { return err } if ffmsg.MethodNumber == 28 { - pcmsgs = append(pcmsgs, *msg.PrecommitMsgCID) - ffmsgs = append(ffmsgs, ffmsg) - } - } + var tskey []cid.Cid + for _, s := range ffmsg.Blocks { + bcid, err := cid.Parse(s) + if err != nil { + return err + } + tskey = append(tskey, bcid) + } - var tskey []cid.Cid - for _, s := range pcmsgs { - bcid, err := cid.Parse(s) - if err != nil { - return err - } - tskey = append(tskey, bcid) - } + tsk := types.NewTipSetKey(tskey...) - tsk := types.NewTipSetKey(tskey...) + tcid, err := tsk.Cid() + if err != nil { + return err + } + fmt.Println(tcid.String()) + + emsg, err := ffMsg2Message(ffmsg) + if err != nil { + return err + } + execMsg, err := json.Marshal(emsg) + if err != nil { + return err + } + + // once all the variables are gathered call the following for each msg + _, err = db.Exec(cctx.Context, `UPDATE message_waits SET + waiter_machine_id = NULL, + executed_tsk_cid = $1, executed_tsk_epoch = $2, + executed_msg_cid = $3, executed_msg_data = $4, + executed_rcpt_exitcode = $5, executed_rcpt_return = $6, executed_rcpt_gas_used = $7 + WHERE signed_message_cid = $8`, + tcid, ffmsg.Height, msg, execMsg, + 0, ffmsg.Receipt.Return, ffmsg.Receipt.GasUsed, + *msg.PrecommitMsgCID) + } - tcid, err := tsk.Cid() - if err != nil { - return err } - fmt.Println(tcid.String()) + return nil }, } @@ -236,3 +255,39 @@ func filfoxMessage(cid string) (FilfoxMsg, error) { } return resp, nil } + +func ffMsg2Message(ffmsg FilfoxMsg) (types.Message, error) { + to, err := address.NewFromString(ffmsg.To) + if err != nil { + return types.Message{}, err + } + from, err := address.NewFromString(ffmsg.From) + if err != nil { + return types.Message{}, err + } + value, err := strconv.Atoi(ffmsg.Value) + if err != nil { + return types.Message{}, err + } + gasfee, err := strconv.Atoi(ffmsg.GasFeeCap) + if err != nil { + return types.Message{}, err + } + gasprem, err := strconv.Atoi(ffmsg.GasPremium) + if err != nil { + return types.Message{}, err + } + + return types.Message{ + Version: uint64(ffmsg.Version), + To: to, + From: from, + Nonce: uint64(ffmsg.Nonce), + Value: abi.NewTokenAmount(int64(value)), + GasLimit: int64(ffmsg.GasLimit), + GasFeeCap: abi.NewTokenAmount(int64(gasfee)), + GasPremium: abi.NewTokenAmount(int64(gasprem)), + Method: abi.MethodNum(ffmsg.MethodNumber), + Params: []byte(ffmsg.Params), + }, nil +} From 3a3ac2f733af54dbc5a64713e5597539f67a7da4 Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 13:30:07 +1000 Subject: [PATCH 13/15] add error handling --- cmd/toolbox/main.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index 3958afb83..07d5b2f1a 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -163,6 +163,10 @@ var precommitStuckCmd = &cli.Command{ tcid, ffmsg.Height, msg, execMsg, 0, ffmsg.Receipt.Return, ffmsg.Receipt.GasUsed, *msg.PrecommitMsgCID) + if err != nil { + log.Error(err) + return err + } } } From fe90bc440251f550612aae06594a02a28d9f0d69 Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Wed, 16 Oct 2024 13:34:00 +1000 Subject: [PATCH 14/15] fix msg to cid --- cmd/toolbox/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/toolbox/main.go b/cmd/toolbox/main.go index 07d5b2f1a..c3f8d78d7 100644 --- a/cmd/toolbox/main.go +++ b/cmd/toolbox/main.go @@ -160,7 +160,7 @@ var precommitStuckCmd = &cli.Command{ executed_msg_cid = $3, executed_msg_data = $4, executed_rcpt_exitcode = $5, executed_rcpt_return = $6, executed_rcpt_gas_used = $7 WHERE signed_message_cid = $8`, - tcid, ffmsg.Height, msg, execMsg, + tcid, ffmsg.Height, ffmsg.Cid, execMsg, 0, ffmsg.Receipt.Return, ffmsg.Receipt.GasUsed, *msg.PrecommitMsgCID) if err != nil { From 7cf37de378125eb9374570edb22ea1072bb142d8 Mon Sep 17 00:00:00 2001 From: Adrian Lanzafame Date: Thu, 17 Oct 2024 10:07:08 +1000 Subject: [PATCH 15/15] move toolbox cmd under sptool --- Makefile | 6 -- cmd/sptool/main.go | 1 + cmd/{toolbox/main.go => sptool/toolbox.go} | 84 +++------------------- documentation/en/curio-cli/sptool.md | 29 ++++++++ 4 files changed, 41 insertions(+), 79 deletions(-) rename cmd/{toolbox/main.go => sptool/toolbox.go} (78%) diff --git a/Makefile b/Makefile index 98517e44b..ca5d84d49 100644 --- a/Makefile +++ b/Makefile @@ -95,12 +95,6 @@ sptool: $(BUILD_DEPS) .PHONY: sptool BINS+=sptool -toolbox: $(BUILD_DEPS) - rm -f toolbox - $(GOCC) build $(GOFLAGS) -o toolbox ./cmd/toolbox -.PHONY: toolbox -BINS+=toolbox - ifeq ($(shell uname),Linux) batchdep: build/.supraseal-install diff --git a/cmd/sptool/main.go b/cmd/sptool/main.go index 4361a4b06..bf77df75c 100644 --- a/cmd/sptool/main.go +++ b/cmd/sptool/main.go @@ -24,6 +24,7 @@ func main() { spcli.InfoCmd(SPTActorGetter), sectorsCmd, provingCmd, + toolboxCmd, //multiSigCmd, } diff --git a/cmd/toolbox/main.go b/cmd/sptool/toolbox.go similarity index 78% rename from cmd/toolbox/main.go rename to cmd/sptool/toolbox.go index c3f8d78d7..316744889 100644 --- a/cmd/toolbox/main.go +++ b/cmd/sptool/toolbox.go @@ -1,95 +1,33 @@ package main import ( - "context" "encoding/json" "fmt" "io" "net/http" - "os" - "os/signal" "strconv" "github.com/ipfs/go-cid" - logging "github.com/ipfs/go-log/v2" "github.com/urfave/cli/v2" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/curio/build" "github.com/filecoin-project/curio/deps" -) - -var log = logging.Logger("toolbox") - -func main() { - local := []*cli.Command{ - precommitStuckCmd, - } - app := &cli.App{ - Name: "toolbox", - Usage: "Some tools to fix some problems", - Version: build.UserVersion(), - EnableBashCompletion: true, - Commands: local, - Flags: []cli.Flag{ - &cli.StringFlag{ - Name: "repo", - EnvVars: []string{"LOTUS_PATH"}, - Hidden: true, - Value: "~/.lotus", // TODO: Consider XDG_DATA_HOME - }, - &cli.StringFlag{ - Name: "log-level", - Value: "info", - }, - &cli.StringFlag{ - Name: "actor", - Required: os.Getenv("LOTUS_DOCS_GENERATION") != "1", - Usage: "miner actor to manage", - EnvVars: []string{"SP_ADDRESS"}, - }, - }, - Before: func(cctx *cli.Context) error { - return logging.SetLogLevel("toolbox", cctx.String("toolbox")) - }, - } - - // terminate early on ctrl+c - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - ctx, cancel := context.WithCancel(context.Background()) - go func() { - <-c - cancel() - fmt.Println("Received interrupt, shutting down... Press CTRL+C again to force shutdown") - <-c - fmt.Println("Forcing stop") - os.Exit(1) - }() - - if err := app.RunContext(ctx, os.Args); err != nil { - log.Errorf("%+v", err) - os.Exit(1) - return - } - -} + "github.com/filecoin-project/lotus/chain/types" +) -func SPTActorGetter(cctx *cli.Context) (address.Address, error) { - addr, err := address.NewFromString(cctx.String("actor")) - if err != nil { - return address.Undef, fmt.Errorf("parsing address: %w", err) - } - return addr, nil +var toolboxCmd = &cli.Command{ + Name: "toolbox", + Usage: "some tools to fix some problems", + Subcommands: []*cli.Command{ + msgFinderCmd, + }, } - -var precommitStuckCmd = &cli.Command{ - Name: "precommit-stuck", - Usage: "Perform db operations to fix issues with precommit messages getting stuck", +var msgFinderCmd = &cli.Command{ + Name: "msg-finder", + Usage: "Perform db operations to fix issues with messages getting stuck", Action: func(cctx *cli.Context) error { db, err := deps.MakeDB(cctx) if err != nil { diff --git a/documentation/en/curio-cli/sptool.md b/documentation/en/curio-cli/sptool.md index dc7cd45bf..6dc8a2842 100644 --- a/documentation/en/curio-cli/sptool.md +++ b/documentation/en/curio-cli/sptool.md @@ -14,6 +14,7 @@ COMMANDS: info Print miner actor info sectors interact with sector store proving View proving information + toolbox some tools to fix some problems help, h Shows a list of commands or help for one command GLOBAL OPTIONS: @@ -489,3 +490,31 @@ USAGE: OPTIONS: --help, -h show help ``` + +## sptool toolbox +``` +NAME: + sptool toolbox - some tools to fix some problems + +USAGE: + sptool toolbox command [command options] [arguments...] + +COMMANDS: + msg-finder Perform db operations to fix issues with messages getting stuck + help, h Shows a list of commands or help for one command + +OPTIONS: + --help, -h show help +``` + +### sptool toolbox msg-finder +``` +NAME: + sptool toolbox msg-finder - Perform db operations to fix issues with messages getting stuck + +USAGE: + sptool toolbox msg-finder [command options] [arguments...] + +OPTIONS: + --help, -h show help +```