Fix ADT uses
This commit is contained in:
parent
ac8aaf2739
commit
bb3789b130
@ -20,7 +20,6 @@ import (
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/state"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
@ -173,7 +172,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
||||
}
|
||||
|
||||
// update power claims
|
||||
pledge := big.Zero()
|
||||
{
|
||||
err = vm.MutateState(ctx, builtin.StoragePowerActorAddr, func(cst cbor.IpldStore, st *power.State) error {
|
||||
weight := &power.SectorStorageWeightDesc{
|
||||
@ -182,15 +180,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
||||
DealWeight: dealWeight,
|
||||
}
|
||||
|
||||
// TODO: This is almost definitely not correct
|
||||
circSupply := types.BigMul(types.NewInt(build.TotalFilecoin-build.MiningRewardTotal), types.NewInt(build.FilecoinPrecision))
|
||||
totalPledge := types.NewInt(3)
|
||||
perEpochReward := types.NewInt(9)
|
||||
|
||||
qapower := power.QAPowerForWeight(weight)
|
||||
pledge = power.InitialPledgeForWeight(qapower, st.TotalQualityAdjPower, circSupply, totalPledge, perEpochReward)
|
||||
|
||||
err := st.AddToClaim(&state.AdtStore{cst}, maddr, types.NewInt(uint64(weight.SectorSize)), qapower, pledge)
|
||||
err := st.AddToClaim(&state.AdtStore{cst}, maddr, types.NewInt(uint64(weight.SectorSize)), qapower)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("add to claim: %w", err)
|
||||
}
|
||||
@ -215,7 +207,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
|
||||
},
|
||||
ActivationEpoch: 0,
|
||||
DealWeight: dealWeight,
|
||||
PledgeRequirement: pledge,
|
||||
DeclaredFaultEpoch: -1,
|
||||
DeclaredFaultDuration: -1,
|
||||
}
|
||||
|
@ -17,12 +17,14 @@ func SetupRewardActor(bs bstore.Blockstore) (*types.Actor, error) {
|
||||
cst := cbor.NewCborStore(bs)
|
||||
|
||||
as := store.ActorStore(context.TODO(), bs)
|
||||
emv, err := adt.MakeEmptyMultimap(as)
|
||||
emv := adt.MakeEmptyMultimap(as)
|
||||
|
||||
r, err := emv.Root()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
st := reward.ConstructState(emv.Root())
|
||||
st := reward.ConstructState(r)
|
||||
hcid, err := cst.Put(context.TODO(), st)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -721,7 +721,10 @@ func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address,
|
||||
|
||||
var out api.MarketBalance
|
||||
|
||||
et := adt.AsBalanceTable(sm.cs.Store(ctx), state.EscrowTable)
|
||||
et, err := adt.AsBalanceTable(sm.cs.Store(ctx), state.EscrowTable)
|
||||
if err != nil {
|
||||
return api.MarketBalance{}, err
|
||||
}
|
||||
ehas, err := et.Has(addr)
|
||||
if err != nil {
|
||||
return api.MarketBalance{}, err
|
||||
@ -735,7 +738,10 @@ func (sm *StateManager) MarketBalance(ctx context.Context, addr address.Address,
|
||||
out.Escrow = big.Zero()
|
||||
}
|
||||
|
||||
lt := adt.AsBalanceTable(sm.cs.Store(ctx), state.LockedTable)
|
||||
lt, err := adt.AsBalanceTable(sm.cs.Store(ctx), state.LockedTable)
|
||||
if err != nil {
|
||||
return api.MarketBalance{}, err
|
||||
}
|
||||
lhas, err := lt.Has(addr)
|
||||
if err != nil {
|
||||
return api.MarketBalance{}, err
|
||||
|
@ -86,8 +86,13 @@ func getPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr addres
|
||||
|
||||
var mpow big.Int
|
||||
if maddr != address.Undef {
|
||||
cm, err := adt.AsMap(sm.cs.Store(ctx), ps.Claims)
|
||||
if err != nil {
|
||||
return types.BigInt{}, types.BigInt{}, err
|
||||
}
|
||||
|
||||
var claim power.Claim
|
||||
if _, err := adt.AsMap(sm.cs.Store(ctx), ps.Claims).Get(adt.AddrKey(maddr), &claim); err != nil {
|
||||
if _, err := cm.Get(adt.AddrKey(maddr), &claim); err != nil {
|
||||
return big.Zero(), big.Zero(), err
|
||||
}
|
||||
|
||||
@ -219,7 +224,12 @@ func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, ma
|
||||
}
|
||||
|
||||
store := sm.cs.Store(ctx)
|
||||
claims := adt.AsMap(store, spas.Claims)
|
||||
|
||||
claims, err := adt.AsMap(store, spas.Claims)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
ok, err := claims.Get(power.AddrKey(maddr), nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -272,7 +282,11 @@ func GetStorageDeal(ctx context.Context, sm *StateManager, dealId abi.DealID, ts
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sa := market.AsDealStateArray(sm.ChainStore().Store(ctx), state.States)
|
||||
sa, err := market.AsDealStateArray(sm.ChainStore().Store(ctx), state.States)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
st, err := sa.Get(dealId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -290,8 +304,13 @@ func ListMinerActors(ctx context.Context, sm *StateManager, ts *types.TipSet) ([
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m, err := adt.AsMap(sm.cs.Store(ctx), state.Claims)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var miners []address.Address
|
||||
err := adt.AsMap(sm.cs.Store(ctx), state.Claims).ForEach(nil, func(k string) error {
|
||||
err = m.ForEach(nil, func(k string) error {
|
||||
a, err := address.NewFromBytes([]byte(k))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -480,8 +480,13 @@ func (syncer *Syncer) minerIsValid(ctx context.Context, maddr address.Address, b
|
||||
return err
|
||||
}
|
||||
|
||||
cm, err := adt.AsMap(syncer.store.Store(ctx), spast.Claims)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var claim power.Claim
|
||||
exist, err := adt.AsMap(syncer.store.Store(ctx), spast.Claims).Get(adt.AddrKey(maddr), &claim)
|
||||
exist, err := cm.Get(adt.AddrKey(maddr), &claim)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -785,7 +785,7 @@ var slashConsensusFault = &cli.Command{
|
||||
ArgsUsage: "[blockCid1 blockCid2]",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "miner",
|
||||
Name: "miner",
|
||||
Usage: "Miner address",
|
||||
},
|
||||
},
|
||||
|
@ -16,16 +16,6 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-amt-ipld/v2"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/reward"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/gen"
|
||||
"github.com/filecoin-project/lotus/chain/state"
|
||||
@ -35,6 +25,13 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/vm"
|
||||
"github.com/filecoin-project/lotus/chain/wallet"
|
||||
"github.com/filecoin-project/lotus/lib/bufbstore"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||
)
|
||||
|
||||
type StateAPI struct {
|
||||
@ -615,40 +612,3 @@ func (a *StateAPI) MsigGetAvailableBalance(ctx context.Context, addr address.Add
|
||||
minBalance = types.BigMul(minBalance, types.NewInt(uint64(offset)))
|
||||
return types.BigSub(act.Balance, minBalance), nil
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateListRewards(ctx context.Context, miner address.Address, tsk types.TipSetKey) ([]reward.Reward, error) {
|
||||
ts, err := a.Chain.GetTipSetFromKey(tsk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var st reward.State
|
||||
if _, err := a.StateManager.LoadActorState(ctx, builtin.RewardActorAddr, &st, ts); err != nil {
|
||||
return nil, xerrors.Errorf("failed to load reward actor state: %w", err)
|
||||
}
|
||||
|
||||
as := store.ActorStore(ctx, a.Chain.Blockstore())
|
||||
rmap := adt.AsMultimap(as, st.RewardMap)
|
||||
rewards, found, err := rmap.Get(adt.AddrKey(miner))
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to get rewards set for miner: %w", err)
|
||||
}
|
||||
|
||||
if !found {
|
||||
return nil, xerrors.Errorf("no rewards found for miner")
|
||||
}
|
||||
|
||||
var out []reward.Reward
|
||||
|
||||
var r reward.Reward
|
||||
err = rewards.ForEach(&r, func(i int64) error {
|
||||
or := r
|
||||
out = append(out, or)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("rewards.ForEach failed: %w", err)
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
@ -129,8 +129,12 @@ func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr a
|
||||
return nil, xerrors.Errorf("handleSealFailed(%d): temp error: unmarshaling miner state: %+v", sectorNumber, err)
|
||||
}
|
||||
|
||||
precommits, err := adt.AsMap(store.ActorStore(ctx, apibstore.NewAPIBlockstore(s.delegate)), state.PreCommittedSectors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pci miner.SectorPreCommitOnChainInfo
|
||||
precommits := adt.AsMap(store.ActorStore(ctx, apibstore.NewAPIBlockstore(s.delegate)), state.PreCommittedSectors)
|
||||
if _, err := precommits.Get(adt.UIntKey(uint64(sectorNumber)), &pci); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user