Skip to content

Commit

Permalink
fix genesis for actors v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Aug 11, 2021
1 parent 498644a commit 5ee73d9
Showing 1 changed file with 42 additions and 30 deletions.
72 changes: 42 additions & 30 deletions chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@ import (
"fmt"
"math/rand"

power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power"

reward4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward"

market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market"

"github.com/filecoin-project/lotus/chain/actors"

"github.com/filecoin-project/lotus/chain/actors/builtin"

"github.com/filecoin-project/lotus/chain/actors/policy"

"github.com/filecoin-project/lotus/chain/actors/adt"

"github.com/filecoin-project/go-state-types/network"

market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"

"github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"

"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"

"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
cbg "github.com/whyrusleeping/cbor-gen"
Expand All @@ -39,12 +15,28 @@ import (
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/filecoin-project/go-state-types/network"

builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
power0 "github.com/filecoin-project/specs-actors/actors/builtin/power"
reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward"
market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market"
reward2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/reward"
market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market"
power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power"
reward4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward"
runtime5 "github.com/filecoin-project/specs-actors/v5/actors/runtime"

"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
"github.com/filecoin-project/lotus/chain/actors/policy"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
Expand Down Expand Up @@ -404,8 +396,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err)
}

if av > actors.Version2 {
// post v2, we need to explicitly Claim this power since ConfirmSectorProofsValid doesn't do it anymore
if av >= actors.Version2 {
// post v0, we need to explicitly Claim this power since ConfirmSectorProofsValid doesn't do it anymore
claimParams := &power4.UpdateClaimedPowerParams{
RawByteDelta: types.NewInt(uint64(m.SectorSize)),
QualityAdjustedDelta: sectorWeight,
Expand Down Expand Up @@ -537,7 +529,6 @@ func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs [
SectorExpiry: sectorExpiry,
}

var dealWeights market0.VerifyDealsForActivationReturn
ret, err := doExecValue(ctx, vm,
market.Address,
maddr,
Expand All @@ -548,11 +539,23 @@ func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs [
if err != nil {
return big.Zero(), big.Zero(), err
}
if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret)); err != nil {
var weight, verifiedWeight abi.DealWeight
if av < actors.Version2 {
var dealWeights market0.VerifyDealsForActivationReturn
err = dealWeights.UnmarshalCBOR(bytes.NewReader(ret))
weight = dealWeights.DealWeight
verifiedWeight = dealWeights.VerifiedDealWeight
} else {
var dealWeights market2.VerifyDealsForActivationReturn
err = dealWeights.UnmarshalCBOR(bytes.NewReader(ret))
weight = dealWeights.DealWeight
verifiedWeight = dealWeights.VerifiedDealWeight
}
if err != nil {
return big.Zero(), big.Zero(), err
}

return dealWeights.DealWeight, dealWeights.VerifiedDealWeight, nil
return weight, verifiedWeight, nil
}
params := &market4.VerifyDealsForActivationParams{Sectors: []market4.SectorDeals{{
SectorExpiry: sectorExpiry,
Expand Down Expand Up @@ -584,14 +587,23 @@ func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Addre
}

// TODO: This hack should move to reward actor wrapper
if av <= actors.Version2 {
switch av {
case actors.Version0:
var epochReward reward0.ThisEpochRewardReturn

if err := epochReward.UnmarshalCBOR(bytes.NewReader(rwret)); err != nil {
return big.Zero(), builtin.FilterEstimate{}, err
}

return epochReward.ThisEpochBaselinePower, *epochReward.ThisEpochRewardSmoothed, nil
case actors.Version2:
var epochReward reward2.ThisEpochRewardReturn

if err := epochReward.UnmarshalCBOR(bytes.NewReader(rwret)); err != nil {
return big.Zero(), builtin.FilterEstimate{}, err
}

return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(epochReward.ThisEpochRewardSmoothed), nil
}

var epochReward reward4.ThisEpochRewardReturn
Expand Down

0 comments on commit 5ee73d9

Please sign in to comment.