Skip to content

Commit

Permalink
Shed: Add a util to calculate total burn for a list of msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Dec 13, 2021
1 parent c7d3a76 commit 164dbc9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
65 changes: 65 additions & 0 deletions cmd/lotus-shed/burnfees.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import (
"bufio"
"fmt"
"os"

"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"
)

var burnFeesCmd = &cli.Command{
Name: "burn-fees",
Usage: "Given a csv list of messages, calculate the total FIL burned",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return fmt.Errorf("must pass csv")
}

file, err := os.Open(cctx.Args().First())
if err != nil {
log.Fatal(err)
}

defer file.Close()

api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := lcli.ReqContext(cctx)

scanner := bufio.NewScanner(file)
totalBurn := big.Zero()
for scanner.Scan() {
msg := build.MustParseCid(scanner.Text())
ir, err := api.StateReplay(ctx, types.EmptyTSK, msg)

if err != nil {
return err
}

for _, im := range ir.ExecutionTrace.Subcalls {
if im.Msg.To == builtin.BurntFundsActorAddr {
totalBurn = big.Add(totalBurn, im.Msg.Value)
}
}

}

if err := scanner.Err(); err != nil {
log.Fatal(err)
}

fmt.Println("total burn: ", totalBurn)

return nil
},
}
1 change: 1 addition & 0 deletions cmd/lotus-shed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func main() {
chainCmd,
balancerCmd,
terminationsCmd,
burnFeesCmd,
}

app := &cli.App{
Expand Down

0 comments on commit 164dbc9

Please sign in to comment.