2021-01-21 14:33:52 +00:00
|
|
|
package storageadapter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
2023-01-26 15:41:28 +00:00
|
|
|
blocks "github.com/ipfs/go-libipfs/blocks"
|
2021-01-21 14:33:52 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
|
2021-01-29 20:01:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/blockstore"
|
2022-06-14 15:00:51 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
2021-01-21 14:33:52 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type apiWrapper struct {
|
|
|
|
api interface {
|
|
|
|
StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error)
|
|
|
|
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
|
|
|
ChainHasObj(context.Context, cid.Cid) (bool, error)
|
2022-06-07 03:14:16 +00:00
|
|
|
ChainPutObj(context.Context, blocks.Block) error
|
2021-01-21 14:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ca *apiWrapper) diffPreCommits(ctx context.Context, actor address.Address, pre, cur types.TipSetKey) (*miner.PreCommitChanges, error) {
|
2021-01-29 20:01:00 +00:00
|
|
|
store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(ca.api)))
|
2021-01-21 14:33:52 +00:00
|
|
|
|
|
|
|
preAct, err := ca.api.StateGetActor(ctx, actor, pre)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("getting pre actor: %w", err)
|
|
|
|
}
|
|
|
|
curAct, err := ca.api.StateGetActor(ctx, actor, cur)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("getting cur actor: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
preSt, err := miner.Load(store, preAct)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("loading miner actor: %w", err)
|
|
|
|
}
|
|
|
|
curSt, err := miner.Load(store, curAct)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("loading miner actor: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
diff, err := miner.DiffPreCommits(preSt, curSt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("diff precommits: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return diff, err
|
|
|
|
}
|