Propagate spec actor types more
This commit is contained in:
parent
526cfea568
commit
0aaf7b25a9
@ -141,7 +141,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
||||
}
|
||||
|
||||
// Create empty market actor
|
||||
marketact, err := SetupStorageMarketActor(bs, template.Miners)
|
||||
marketact, err := SetupStorageMarketActor(bs)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("setup storage market actor: %w", err)
|
||||
}
|
||||
|
@ -3,18 +3,14 @@ package genesis
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||
"github.com/ipfs/go-hamt-ipld"
|
||||
bstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/vm"
|
||||
)
|
||||
|
||||
func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
||||
@ -48,48 +44,3 @@ func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) {
|
||||
Balance: types.NewInt(0),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func adjustStoragePowerTracking(vm *vm.VM, cst cbor.IpldStore, from, to address.Address) error {
|
||||
ctx := context.TODO()
|
||||
act, err := vm.StateTree().GetActor(actors.StoragePowerAddress)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("loading storage power actor: %w", err)
|
||||
}
|
||||
|
||||
var spst market.State
|
||||
if err := cst.Get(ctx, act.Head, &spst); err != nil {
|
||||
return xerrors.Errorf("loading storage power actor state: %w", err)
|
||||
}
|
||||
|
||||
miners, err := hamt.LoadNode(ctx, cst, spst.Miners)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("loading miner set: %w", err)
|
||||
}
|
||||
|
||||
if err := miners.Delete(ctx, string(from.Bytes())); err != nil {
|
||||
return xerrors.Errorf("deleting from spa set: %w", err)
|
||||
}
|
||||
|
||||
if err := miners.Set(ctx, string(to.Bytes()), uint64(1)); err != nil {
|
||||
return xerrors.Errorf("failed setting miner: %w", err)
|
||||
}
|
||||
|
||||
if err := miners.Flush(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nminerscid, err := cst.Put(ctx, miners)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
spst.Miners = nminerscid
|
||||
|
||||
nhead, err := cst.Put(ctx, &spst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
act.Head = nhead
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -3,62 +3,29 @@ package genesis
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/go-amt-ipld/v2"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
bstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/genesis"
|
||||
)
|
||||
|
||||
func SetupStorageMarketActor(bs bstore.Blockstore, miners []genesis.Miner) (*types.Actor, error) {
|
||||
ctx := context.TODO()
|
||||
func SetupStorageMarketActor(bs bstore.Blockstore) (*types.Actor, error) {
|
||||
cst := cbor.NewCborStore(bs)
|
||||
ast := store.ActorStore(context.TODO(), bs)
|
||||
|
||||
cdeals := make([]cbg.CBORMarshaler, len(deals))
|
||||
sdeals := make([]cbg.CBORMarshaler, len(deals))
|
||||
for i, deal := range deals {
|
||||
d := deal // copy
|
||||
|
||||
cdeals[i] = &d
|
||||
sdeals[i] = &market.DealState{
|
||||
SectorStartEpoch: 1,
|
||||
LastUpdatedEpoch: -1,
|
||||
SlashEpoch: -1,
|
||||
}
|
||||
}
|
||||
|
||||
dealAmt, err := amt.FromArray(ctx, cst, cdeals)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("amt build failed: %w", err)
|
||||
}
|
||||
|
||||
stateAmt, err := amt.FromArray(ctx, cst, sdeals)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("amt build failed: %w", err)
|
||||
}
|
||||
|
||||
sms, err := market.ConstructState(ast)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sms.Proposals = dealAmt
|
||||
sms.States = stateAmt
|
||||
|
||||
stcid, err := cst.Put(context.TODO(), sms)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: MARKET BALANCES!!!!!!111
|
||||
|
||||
act := &types.Actor{
|
||||
Code: actors.StorageMarketCodeCid,
|
||||
Head: stcid,
|
||||
|
@ -20,7 +20,7 @@ func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate
|
||||
ctx, span := trace.StartSpan(ctx, "statemanager.CallRaw")
|
||||
defer span.End()
|
||||
|
||||
vmi, err := vm.NewVM(bstate, bheight, r, actors.NetworkAddress, sm.cs.Blockstore(), sm.cs.VMSys())
|
||||
vmi, err := vm.NewVM(bstate, bheight, r, actors.SystemAddress, sm.cs.Blockstore(), sm.cs.VMSys())
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to set up vm: %w", err)
|
||||
}
|
||||
|
@ -152,13 +152,13 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("instantiating VM failed: %w", err)
|
||||
}
|
||||
|
||||
netact, err := vmi.StateTree().GetActor(actors.NetworkAddress)
|
||||
rewardActor, err := vmi.StateTree().GetActor(actors.RewardActor)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
|
||||
}
|
||||
reward := vm.MiningReward(netact.Balance)
|
||||
reward := vm.MiningReward(rewardActor.Balance)
|
||||
for tsi, b := range blks {
|
||||
netact, err = vmi.StateTree().GetActor(actors.NetworkAddress)
|
||||
rewardActor, err = vmi.StateTree().GetActor(actors.RewardActor)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
|
||||
}
|
||||
@ -174,15 +174,14 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get miner owner actor")
|
||||
}
|
||||
|
||||
if err := vm.Transfer(netact, act, reward); err != nil {
|
||||
if err := vm.Transfer(rewardActor, act, reward); err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to deduct funds from network actor: %w", err)
|
||||
}
|
||||
|
||||
// all block miners created a valid post, go update the actor state
|
||||
panic("sys actor call")
|
||||
postSubmitMsg := &types.Message{
|
||||
From: actors.NetworkAddress,
|
||||
Nonce: netact.Nonce,
|
||||
From: actors.SystemAddress,
|
||||
Nonce: rewardActor.Nonce,
|
||||
To: b.Miner,
|
||||
Method: builtin.MethodsMiner.OnVerifiedElectionPoSt,
|
||||
GasPrice: types.NewInt(0),
|
||||
|
@ -295,7 +295,7 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch,
|
||||
}
|
||||
|
||||
r := store.NewChainRand(sm.cs, ts.Cids(), height)
|
||||
vmi, err := vm.NewVM(fstate, height, r, actors.NetworkAddress, sm.cs.Blockstore(), sm.cs.VMSys())
|
||||
vmi, err := vm.NewVM(fstate, height, r, actors.SystemAddress, sm.cs.Blockstore(), sm.cs.VMSys())
|
||||
if err != nil {
|
||||
return cid.Undef, err
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func (cs *ChainStore) call(ctx context.Context, msg *types.Message, ts *types.Ti
|
||||
|
||||
r := NewChainRand(cs, ts.Cids(), ts.Height())
|
||||
|
||||
vmi, err := vm.NewVM(bstate, ts.Height(), r, actors.NetworkAddress, cs.bs, cs.vmcalls)
|
||||
vmi, err := vm.NewVM(bstate, ts.Height(), r, actors.SystemAddress, cs.bs, cs.vmcalls)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to set up vm: %w", err)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package vm
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/account"
|
||||
"github.com/ipfs/go-cid"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
|
||||
@ -54,7 +55,7 @@ func makeActor(st *state.StateTree, addr address.Address) (*types.Actor, aerrors
|
||||
}
|
||||
|
||||
func NewBLSAccountActor(st *state.StateTree, addr address.Address) (*types.Actor, aerrors.ActorError) {
|
||||
var acstate actors.AccountActorState
|
||||
var acstate account.State
|
||||
acstate.Address = addr
|
||||
|
||||
c, err := st.Store.Put(context.TODO(), &acstate)
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
@ -152,7 +151,7 @@ func (ssh *shimStateHandle) Create(obj vmr.CBORMarshaler) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := ssh.rs.vmctx.Storage().Commit(actors.EmptyCBOR, c); err != nil {
|
||||
if err := ssh.rs.vmctx.Storage().Commit(cid.Undef, c); err != nil { // todo: empty cbor thing may have been here for a good reason
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"math/big"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/account"
|
||||
block "github.com/ipfs/go-block-format"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
hamt "github.com/ipfs/go-hamt-ipld"
|
||||
@ -220,7 +221,7 @@ func ResolveToKeyAddr(state types.StateTree, cst cbor.IpldStore, addr address.Ad
|
||||
return address.Undef, aerrors.New(1, "address was not for an account actor")
|
||||
}
|
||||
|
||||
var aast actors.AccountActorState
|
||||
var aast account.State
|
||||
if err := cst.Get(context.TODO(), act.Head, &aast); err != nil {
|
||||
return address.Undef, aerrors.Escalate(err, fmt.Sprintf("failed to get account actor state for %s", addr))
|
||||
}
|
||||
|
@ -102,7 +102,6 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error {
|
||||
if maj != cbg.MajUnsignedInt {
|
||||
return fmt.Errorf("wrong type for uint64 field")
|
||||
}
|
||||
t.BlockHeight = uint64(extra)
|
||||
// t.TicketBytes ([]uint8) (slice)
|
||||
case "TicketBytes":
|
||||
|
||||
|
@ -49,6 +49,7 @@ type sealingApi interface { // TODO: trim down
|
||||
ChainGetTipSetByHeight(context.Context, abi.ChainEpoch, *types.TipSet) (*types.TipSet, error)
|
||||
ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error)
|
||||
ChainReadObj(context.Context, cid.Cid) ([]byte, error)
|
||||
ChainHasObj(context.Context, cid.Cid) (bool, error)
|
||||
|
||||
WalletSign(context.Context, address.Address, []byte) (*types.Signature, error)
|
||||
WalletBalance(context.Context, address.Address) (types.BigInt, error)
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/go-sectorbuilder/fs"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
@ -76,7 +77,7 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er
|
||||
commD: rspco.CommD[:],
|
||||
commR: rspco.CommR[:],
|
||||
ticket: SealTicket{
|
||||
BlockHeight: ticket.BlockHeight,
|
||||
BlockHeight: abi.ChainEpoch(ticket.BlockHeight),
|
||||
TicketBytes: ticket.TicketBytes[:],
|
||||
},
|
||||
})
|
||||
@ -116,7 +117,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
msg := &types.Message{
|
||||
To: m.maddr,
|
||||
From: m.worker,
|
||||
Method: actors.MAMethods.PreCommitSector,
|
||||
Method: builtin.MethodsMiner.PreCommitSector,
|
||||
Params: enc,
|
||||
Value: types.NewInt(0), // TODO: need to ensure sufficient collateral
|
||||
GasLimit: types.NewInt(1000000 /* i dont know help */),
|
||||
@ -187,13 +188,12 @@ func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo)
|
||||
|
||||
// TODO: Consider splitting states and persist proof for faster recovery
|
||||
|
||||
/*params := &actors.SectorProveCommitInfo{
|
||||
Proof: proof,
|
||||
SectorID: sector.SectorID,
|
||||
DealIDs: sector.deals(),
|
||||
}*/
|
||||
params := &miner.ProveCommitSectorParams{
|
||||
SectorNumber: sector.SectorID,
|
||||
Proof: abi.SealProof{ProofBytes:proof},
|
||||
}
|
||||
|
||||
enc, aerr := actors.SerializeParams(nil) // TODO: REFACTOR: Fix
|
||||
enc, aerr := actors.SerializeParams(params)
|
||||
if aerr != nil {
|
||||
return ctx.Send(SectorCommitFailed{xerrors.Errorf("could not serialize commit sector parameters: %w", aerr)})
|
||||
}
|
||||
@ -201,7 +201,7 @@ func (m *Sealing) handleCommitting(ctx statemachine.Context, sector SectorInfo)
|
||||
msg := &types.Message{
|
||||
To: m.maddr,
|
||||
From: m.worker,
|
||||
Method: actors.MAMethods.ProveCommitSector,
|
||||
Method: builtin.MethodsMiner.ProveCommitSector,
|
||||
Params: enc,
|
||||
Value: types.NewInt(0), // TODO: need to ensure sufficient collateral
|
||||
GasLimit: types.NewInt(1000000 /* i dont know help */),
|
||||
@ -260,10 +260,13 @@ func (m *Sealing) handleFaulty(ctx statemachine.Context, sector SectorInfo) erro
|
||||
// TODO: check if the fault has already been reported, and that this sector is even valid
|
||||
|
||||
// TODO: coalesce faulty sector reporting
|
||||
bf := types.NewBitField()
|
||||
bf.Set(uint64(sector.SectorID))
|
||||
/*bf := types.NewBitField()
|
||||
bf.Set(uint64(sector.SectorID))*/
|
||||
|
||||
enc, aerr := actors.SerializeParams(&actors.DeclareFaultsParams{bf})
|
||||
enc, aerr := actors.SerializeParams(&miner.DeclareTemporaryFaultsParams{
|
||||
SectorNumbers: []abi.SectorNumber{sector.SectorID},
|
||||
Duration: 99999999, // TODO: This is very unlikely to be the correct number
|
||||
})
|
||||
if aerr != nil {
|
||||
return xerrors.Errorf("failed to serialize declare fault params: %w", aerr)
|
||||
}
|
||||
@ -271,7 +274,7 @@ func (m *Sealing) handleFaulty(ctx statemachine.Context, sector SectorInfo) erro
|
||||
msg := &types.Message{
|
||||
To: m.maddr,
|
||||
From: m.worker,
|
||||
Method: actors.MAMethods.DeclareFaults,
|
||||
Method: builtin.MethodsMiner.DeclareTemporaryFaults,
|
||||
Params: enc,
|
||||
Value: types.NewInt(0), // TODO: need to ensure sufficient collateral
|
||||
GasLimit: types.NewInt(1000000 /* i dont know help */),
|
||||
|
@ -2,13 +2,17 @@ package sealing
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/api/apibstore"
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/lib/statemachine"
|
||||
)
|
||||
|
||||
@ -28,7 +32,7 @@ func failedCooldown(ctx statemachine.Context, sector SectorInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Sealing) checkPreCommitted(ctx statemachine.Context, sector SectorInfo) (*actors.PreCommittedSector, bool) {
|
||||
func (m *Sealing) checkPreCommitted(ctx statemachine.Context, sector SectorInfo) (*miner.SectorPreCommitOnChainInfo, bool) {
|
||||
act, err := m.api.StateGetActor(ctx.Context(), m.maddr, nil)
|
||||
if err != nil {
|
||||
log.Errorf("handleSealFailed(%d): temp error: %+v", sector.SectorID, err)
|
||||
@ -47,14 +51,14 @@ func (m *Sealing) checkPreCommitted(ctx statemachine.Context, sector SectorInfo)
|
||||
return nil, true
|
||||
}
|
||||
|
||||
pci, found := state.PreCommittedSectors[fmt.Sprint(sector.SectorID)]
|
||||
if found {
|
||||
// TODO: If not expired yet, we can just try reusing sealticket
|
||||
log.Warnf("sector %d found in miner preseal array", sector.SectorID)
|
||||
return pci, true
|
||||
var pci miner.SectorPreCommitOnChainInfo
|
||||
precommits := adt.AsMap(store.ActorStore(ctx.Context(), apibstore.NewAPIBlockstore(m.api)), state.PreCommittedSectors)
|
||||
if _, err := precommits.Get(adt.IntKey(sector.SectorID), &pci); err != nil {
|
||||
log.Error(err)
|
||||
return nil, true
|
||||
}
|
||||
|
||||
return nil, false
|
||||
return &pci, false
|
||||
}
|
||||
|
||||
func (m *Sealing) handleSealFailed(ctx statemachine.Context, sector SectorInfo) error {
|
||||
@ -92,8 +96,13 @@ func (m *Sealing) handlePreCommitFailed(ctx statemachine.Context, sector SectorI
|
||||
return nil // TODO: SeedWait needs this currently
|
||||
}
|
||||
|
||||
if string(pci.Info.CommR) != string(sector.CommR) {
|
||||
log.Warn("sector %d is precommitted on chain, with different CommR: %x != %x", sector.SectorID, pci.Info.CommR, sector.CommR)
|
||||
pciR, err := commcid.CIDToReplicaCommitmentV1(pci.Info.SealedCID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if string(pciR) != string(sector.CommR) {
|
||||
log.Warn("sector %d is precommitted on chain, with different CommR: %x != %x", sector.SectorID, pciR, sector.CommR)
|
||||
return nil // TODO: remove when the actor allows re-precommit
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user