From f2340579a5d00b43006af1047f358e34d113576f Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Thu, 30 Jan 2020 14:01:15 -0800 Subject: [PATCH] Fix power calculations Signed-off-by: Jakub Sztandera --- build/forks.go | 2 ++ chain/actors/actor_miner2.go | 18 ++++++++++- chain/actors/actor_storagepower.go | 50 +++++++++++++++++++++++++----- cli/chain.go | 8 +++++ 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/build/forks.go b/build/forks.go index e57550005..6002f89eb 100644 --- a/build/forks.go +++ b/build/forks.go @@ -5,3 +5,5 @@ const ForkBlizzardHeight = 6288 const ForkFrigidHeight = 7950 const ForkBootyBayHeight = 11000 + +const ForkMissingSnowballs = 32000 diff --git a/chain/actors/actor_miner2.go b/chain/actors/actor_miner2.go index b6408621d..3fe14a6f5 100644 --- a/chain/actors/actor_miner2.go +++ b/chain/actors/actor_miner2.go @@ -33,7 +33,10 @@ func (sma StorageMinerActor2) Exports() []interface{} { //8: sma.DePledge, 9: sma.GetOwner, 10: sma.GetWorkerAddr, - 11: sma.GetPower, // TODO: Remove + 11: withUpdates( + update{0, sma.GetPower}, + update{build.ForkMissingSnowballs, sma.GetPower2}, + ), // TODO: Remove 12: sma.GetPeerID, 13: sma.GetSectorSize, 14: sma.UpdatePeerID, @@ -404,6 +407,19 @@ func (sma StorageMinerActor2) GetPower(act *types.Actor, vmctx types.VMContext, return self.Power.Bytes(), nil } +func (sma StorageMinerActor2) GetPower2(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, ActorError) { + _, self, err := loadState(vmctx) + if err != nil { + return nil, err + } + + if self.SlashedAt != 0 { + return types.NewInt(0).Bytes(), nil + } + + return self.Power.Bytes(), nil +} + func SectorIsUnique2(ctx context.Context, s types.Storage, sroot cid.Cid, sid uint64) (bool, ActorError) { found, _, _, err := GetFromSectorSet2(ctx, s, sroot, sid) if err != nil { diff --git a/chain/actors/actor_storagepower.go b/chain/actors/actor_storagepower.go index 4bd5a0cb7..3b68a6f95 100644 --- a/chain/actors/actor_storagepower.go +++ b/chain/actors/actor_storagepower.go @@ -648,6 +648,8 @@ func checkProofSubmissionsAtH(vmctx types.VMContext, self *StoragePowerState, he return aerrors.HandleExternalError(err, "failed to load proving bucket") } + forRemoval := make([]address.Address, 0) + err = bhamt.ForEach(vmctx.Context(), func(k string, val interface{}) error { _, span := trace.StartSpan(vmctx.Context(), "StoragePowerActor.CheckProofSubmissions.loop") defer span.End() @@ -657,6 +659,18 @@ func checkProofSubmissionsAtH(vmctx types.VMContext, self *StoragePowerState, he return aerrors.Escalate(err, "parsing miner address") } + if vmctx.BlockHeight() >= build.ForkMissingSnowballs { + has, aerr := MinerSetHas(vmctx, self.Miners, maddr) + if aerr != nil { + return aerr + } + + if !has { + forRemoval = append(forRemoval, maddr) + } + + } + span.AddAttributes(trace.StringAttribute("miner", maddr.String())) params, err := SerializeParams(&CheckMinerParams{NetworkPower: self.TotalStorage}) @@ -690,6 +704,24 @@ func checkProofSubmissionsAtH(vmctx types.VMContext, self *StoragePowerState, he return aerrors.HandleExternalError(err, "iterating miners in proving bucket") } + if vmctx.BlockHeight() >= build.ForkMissingSnowballs { + nBucket, err := MinerSetRemove(vmctx.Context(), vmctx, bucket, forRemoval...) + + if err != nil { + return aerrors.Wrap(err, "could not remove miners from set") + } + + eerr := buckets.Set(bucketID, nBucket) + if err != nil { + return aerrors.HandleExternalError(eerr, "could not set the bucket") + } + ncid, eerr := buckets.Flush() + if err != nil { + return aerrors.HandleExternalError(eerr, "could not flush buckets") + } + self.ProvingBuckets = ncid + } + return nil } @@ -764,19 +796,21 @@ func MinerSetAdd(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, maddr return c, nil } -func MinerSetRemove(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, maddr address.Address) (cid.Cid, aerrors.ActorError) { +func MinerSetRemove(ctx context.Context, vmctx types.VMContext, rcid cid.Cid, maddrs ...address.Address) (cid.Cid, aerrors.ActorError) { nd, err := hamt.LoadNode(ctx, vmctx.Ipld(), rcid) if err != nil { return cid.Undef, aerrors.HandleExternalError(err, "failed to load miner set") } - mkey := string(maddr.Bytes()) - switch nd.Delete(ctx, mkey) { - default: - return cid.Undef, aerrors.HandleExternalError(err, "failed to delete miner from set") - case hamt.ErrNotFound: - return cid.Undef, aerrors.New(1, "miner not found in set on delete") - case nil: + for _, maddr := range maddrs { + mkey := string(maddr.Bytes()) + switch nd.Delete(ctx, mkey) { + default: + return cid.Undef, aerrors.HandleExternalError(err, "failed to delete miner from set") + case hamt.ErrNotFound: + return cid.Undef, aerrors.New(1, "miner not found in set on delete") + case nil: + } } if err := nd.Flush(ctx); err != nil { diff --git a/cli/chain.go b/cli/chain.go index aed541f8c..b9f27a685 100644 --- a/cli/chain.go +++ b/cli/chain.go @@ -388,6 +388,14 @@ func printTipSet(format string, ts *types.TipSet) { blks += fmt.Sprintf("%s: %s,", b.Cid(), b.Miner) } blks += " ]" + + sCids := make([]string, 0, len(blks)) + + for _, c := range ts.Cids() { + sCids = append(sCids, c.String()) + } + + format = strings.ReplaceAll(format, "", strings.Join(sCids, ",")) format = strings.ReplaceAll(format, "", blks) format = strings.ReplaceAll(format, "", fmt.Sprint(ts.Blocks()[0].ParentWeight))