2020-07-27 11:57:01 +00:00
|
|
|
package rfwp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-07-27 11:57:01 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
2020-09-16 10:51:23 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-06-14 15:00:51 +00:00
|
|
|
|
2021-04-06 10:36:32 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v0api"
|
2020-07-27 11:57:01 +00:00
|
|
|
"github.com/filecoin-project/lotus/cli"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/testplans/lotus-soup/testkit"
|
2021-09-01 23:47:32 +00:00
|
|
|
tsync "github.com/filecoin-project/lotus/tools/stats/sync"
|
2020-07-27 11:57:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func FetchChainState(t *testkit.TestEnvironment, m *testkit.LotusMiner) error {
|
|
|
|
height := 0
|
|
|
|
headlag := 3
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
api := m.FullApi
|
|
|
|
|
2021-09-01 23:47:32 +00:00
|
|
|
tipsetsCh, err := tsync.BufferedTipsetChannel(ctx, &v0api.WrapperV1Full{FullNode: m.FullApi}, abi.ChainEpoch(height), headlag)
|
2020-07-27 11:57:01 +00:00
|
|
|
if err != nil {
|
2021-09-01 23:47:32 +00:00
|
|
|
|
2020-07-27 11:57:01 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for tipset := range tipsetsCh {
|
|
|
|
err := func() error {
|
|
|
|
filename := fmt.Sprintf("%s%cchain-state-%d.html", t.TestOutputsPath, os.PathSeparator, tipset.Height())
|
|
|
|
file, err := os.Create(filename)
|
|
|
|
defer file.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
stout, err := api.StateCompute(ctx, tipset.Height(), nil, tipset.Key())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
codeCache := map[address.Address]cid.Cid{}
|
|
|
|
getCode := func(addr address.Address) (cid.Cid, error) {
|
|
|
|
if c, found := codeCache[addr]; found {
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
c, err := api.StateGetActor(ctx, addr, tipset.Key())
|
|
|
|
if err != nil {
|
|
|
|
return cid.Cid{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
codeCache[addr] = c.Code
|
|
|
|
return c.Code, nil
|
|
|
|
}
|
|
|
|
|
2021-01-28 17:15:22 +00:00
|
|
|
return cli.ComputeStateHTMLTempl(file, tipset, stout, true, getCode)
|
2020-07-27 11:57:01 +00:00
|
|
|
}()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|