fix genesis for actors v2

This commit is contained in:
Steven Allen 2021-08-06 03:26:33 -07:00
parent 9911ab1000
commit 3235dbfaee

View File

@ -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"
@ -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"
@ -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,
@ -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,
@ -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,
@ -584,7 +587,8 @@ 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 {
@ -592,6 +596,14 @@ func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Addre
}
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