-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
190 lines (171 loc) · 5.52 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package main
import (
"context"
"fmt"
"os"
"os/signal"
"strconv"
"syscall"
filexp "github.com/aschmahmann/filexp/internal"
"github.com/aschmahmann/filexp/internal/state"
filaddr "github.com/filecoin-project/go-address"
filbuiltin "github.com/filecoin-project/go-state-types/builtin"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
)
var log = filexp.Logger
// 20 is considered good for WdPoST: https://github.com/filecoin-project/builtin-actors/blob/v13.0.0/runtime/src/runtime/policy.rs#L290-L293
// nevertheless bump to 30 as per https://filecoinproject.slack.com/archives/C02D73MHM63/p1718762303033709?thread_ts=1718693790.469889&cid=C02D73MHM63
var defaultRpcLookbackEpochs = uint(30)
const chainLoveURL = "https://api.chain.love/"
var stateFlags = []cli.Flag{
&cli.PathFlag{
Name: "car",
Usage: "Path to state snapshot CAR, tipset inferred from car root",
},
&cli.StringSliceFlag{
Name: "tipset-cids",
Usage: "Specific tipset CIDs to get directly over libp2p",
},
&cli.StringFlag{
Name: "rpc-endpoint",
Usage: "Filecoin RPC API endpoint to determine current tipset",
},
&cli.StringFlag{
Name: "rpc-fullnode",
Usage: "Filecoin Full Node RPC API, to use as source of current tipset and all IPLD blocks",
},
&cli.UintFlag{
Name: "lookback-epochs",
Usage: "How many epochs to look back when pulling state from the network",
Value: defaultRpcLookbackEpochs,
DefaultText: fmt.Sprintf("%d epochs / %s minutes",
defaultRpcLookbackEpochs,
strconv.FormatFloat(float64(defaultRpcLookbackEpochs*filbuiltin.EpochDurationSeconds)/60, 'f', -1, 64),
),
},
&cli.BoolFlag{
Name: "trust-chainlove",
Usage: "Equivalent to --rpc-endpoint=https://api.chain.love",
},
}
func main() {
logging.SetLogLevel("*", "INFO")
// the network stack is incredibly chatty: silence it all
for _, c := range []string{"bitswap", "dht", "dht/RtRefreshManager", "routing/http/contentrouter", "net/identify", "bs:sess", "bitswap/session", "bitswap_network", "bitswap/network", "bitswap-client", "bitswap/client", "bitswap/client/msgq", "swarm2", "connmgr", "canonical-log"} {
logging.SetLogLevel(c, "ERROR")
}
app := &cli.App{
Name: "filexp",
Usage: "explore filecoin state",
Commands: []*cli.Command{
{
Name: "get-balance",
Usage: "<actor>",
Description: "Get the balance for a given actor",
Flags: append([]cli.Flag{}, stateFlags...),
Action: func(cctx *cli.Context) error {
actorAddr, err := filaddr.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
bg, ts, err := getAnchorPoint(cctx)
if err != nil {
return err
}
defer bg.LogStats()
return state.GetBalance(cctx.Context, bg, ts, actorAddr)
},
},
{
Name: "fil-to-eth-address",
Usage: "<fX....>",
Description: "Converts an fX address to a 0x one if possible",
Flags: append([]cli.Flag{}, stateFlags...),
Action: filToEthAddr,
},
{
Name: "addresses",
Usage: "<address>",
Description: "Lists all the address types associated with an fX or 0x address. Note: will not back calculate fX addresses for f0 or masked ID 0x addresses",
Flags: append([]cli.Flag{}, stateFlags...),
Action: filAddrs,
},
{
Name: "msig-coins",
Usage: "<signer-address>",
Description: "Add up all of the coins controlled by multisigs with the given signer and signing threshold of 1",
Flags: append([]cli.Flag{}, stateFlags...),
Action: func(cctx *cli.Context) error {
signerAddr, err := filaddr.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
bg, ts, err := getAnchorPoint(cctx)
if err != nil {
return err
}
defer bg.LogStats()
return state.GetCoins(cctx.Context, bg, ts, signerAddr)
},
},
{
Name: "enumerate-actors",
Description: "List all actors",
Flags: append([]cli.Flag{
&cli.BoolFlag{
Name: "count-only",
Value: false,
DefaultText: "will not emit the actor IDs, and just count them",
},
}, stateFlags...),
Action: func(cctx *cli.Context) error {
bg, ts, err := getAnchorPoint(cctx)
if err != nil {
return err
}
defer bg.LogStats()
return state.GetActors(cctx.Context, bg, ts, cctx.Bool("count-only"))
},
},
{
Name: "fevm-exec",
Description: "Execute a read-only FVM actor",
Usage: "<eth-addr> <eth-data>",
Flags: append(append([]cli.Flag{}, stateFlags...),
&cli.PathFlag{
Name: "output",
Usage: "The path for an output CAR containing the data loaded while computing the result (is not output if undefined)",
}),
Action: cmdFevmExec,
},
{
Name: "fevm-daemon",
Description: "Start a daemon that will respond to Ethereum JSON RPC calls. Note: passing an RPC endpoint enables real-time updates and lookback-epochs is not supported",
Usage: "[port]",
Flags: append([]cli.Flag{}, stateFlags...),
Action: cmdFevmDaemon,
},
},
}
topCtx, topCtxShutdown := context.WithCancel(context.Background())
// sighandler
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs,
syscall.SIGTERM,
syscall.SIGINT,
syscall.SIGHUP,
syscall.SIGPIPE,
)
// wait
s := <-sigs
log.Warnf("process received %s, cleaning up...", decodeSigname(s))
topCtxShutdown()
}()
// end of sighandler
if err := app.RunContext(topCtx, os.Args); err != nil {
log.Fatalf("%+v", err)
os.Exit(1)
}
}