lotus/chain/gen/genesis/miners.go

683 lines
22 KiB
Go
Raw Normal View History

2020-02-11 20:48:03 +00:00
package genesis
import (
"bytes"
"context"
"fmt"
"math/rand"
2020-04-10 21:07:18 +00:00
"github.com/ipfs/go-cid"
2020-02-18 21:37:59 +00:00
cbor "github.com/ipfs/go-ipld-cbor"
2020-04-20 13:54:06 +00:00
cbg "github.com/whyrusleeping/cbor-gen"
2020-04-10 21:07:18 +00:00
"golang.org/x/xerrors"
2020-02-11 20:48:03 +00:00
"github.com/filecoin-project/go-address"
2022-06-14 15:00:51 +00:00
cborutil "github.com/filecoin-project/go-cbor-util"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/abi"
2022-09-06 15:49:29 +00:00
actorstypes "github.com/filecoin-project/go-state-types/actors"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/big"
2022-06-14 15:00:51 +00:00
builtintypes "github.com/filecoin-project/go-state-types/builtin"
chore: build: Merge/v22 into 21 for 23 (#10702) * chore: update ffi to increase execution parallelism * Don't enforce walking receipt tree during compaction * fix: build: drop drand incentinet servers * chore: release lotus v1.20.4 * Apply suggestions from code review Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> * feat: Introduce nv19 skeleton Update to go-state-types v0.11.0-alpha-1 Introduce dummy v11 actor bundles Make new actors adapters Add upgrade to Upgrade Schedules make jen Update to go-state-types v0.11.0-alpha-2 * feat: vm: switch to the new exec trace format (#10372) This is now "FVM" native. Changes include: 1. Don't treat "trace" messages like off-chain messages. E.g., don't include CIDs, versions, etc. 2. Include IPLD codecs where applicable. 3. Remove fields that aren't filled by the FVM (timing, some errors, code locations, etc.). * feat: implement FIP-0061 * Address review * Add and test the FIP-0061 migration * Update actors bundles to fip/20230406 * Update to go-state-types master * Update to actors v11.0.0-rc1 * - Update go state types - Keep current expiration defaults on creation, extension some tests - Update ffi * ffi experiment * Integration nv19 migration - Open splitstore in migration shed tool - Update state root version * Post rebase fixup * Fix * gen * nv19 invariant checking * Try fixig blockstore so bundle is loaded * Debug * Fix * Make butterfly upgrades happen * Another ffi experiment * Fix copy paste error * Actually schedule migration (#10656) Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * Butterfly artifacts * Set calibration net upgrade height * Review Response * Fix state tree version assert * Quick butterfly upgrade to sanity check (#10660) * Quick butterfly upgrade to sanity check * Update butterfly artifacts * Revert fake fix * Give butterfly net correct genesis * Butterfly artifacts * Give time before upgrade --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * chore:releasepolish v1.22 release (#10666) * Update butterfly artifacts * register actors v11 * Update calibration upgrade time * State inspection shed cmds * Fix * make gen * Fix swallowed errors * Lint fixup --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * v1.22.0-rc3 * bundle fix * Feat/expedite nv19 (#10681) * Update go-state-types * Modify upgrade schedule and params * Revert fip 0052 * Update gst * docsgen * fast butterfly migration to validate migration * Correct epoch to match specified date * Update actors v11 * Update changelog build version * Update butterfly artifacts * Fix lotus-miner init to work after upgrade --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * fix:deps:stable ffi for stable release (#10698) * Point to stable ffi for stable lotus release * go mod tidy --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> --------- Co-authored-by: Aayush Rajasekaran <arajasek94@gmail.com> Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> Co-authored-by: Steven Allen <steven@stebalien.com> Co-authored-by: jennijuju <jiayingw703@gmail.com>
2023-04-19 22:40:18 +00:00
power11 "github.com/filecoin-project/go-state-types/builtin/v11/power"
2022-06-14 15:00:51 +00:00
minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner"
2022-09-26 16:47:48 +00:00
markettypes "github.com/filecoin-project/go-state-types/builtin/v9/market"
2022-09-09 20:42:55 +00:00
miner9 "github.com/filecoin-project/go-state-types/builtin/v9/miner"
smoothing9 "github.com/filecoin-project/go-state-types/builtin/v9/util/smoothing"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/crypto"
2021-08-06 10:26:33 +00:00
"github.com/filecoin-project/go-state-types/network"
2020-10-08 01:09:33 +00:00
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
2022-06-14 15:00:51 +00:00
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"
chore: build: Merge/v22 into 21 for 23 (#10702) * chore: update ffi to increase execution parallelism * Don't enforce walking receipt tree during compaction * fix: build: drop drand incentinet servers * chore: release lotus v1.20.4 * Apply suggestions from code review Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> * feat: Introduce nv19 skeleton Update to go-state-types v0.11.0-alpha-1 Introduce dummy v11 actor bundles Make new actors adapters Add upgrade to Upgrade Schedules make jen Update to go-state-types v0.11.0-alpha-2 * feat: vm: switch to the new exec trace format (#10372) This is now "FVM" native. Changes include: 1. Don't treat "trace" messages like off-chain messages. E.g., don't include CIDs, versions, etc. 2. Include IPLD codecs where applicable. 3. Remove fields that aren't filled by the FVM (timing, some errors, code locations, etc.). * feat: implement FIP-0061 * Address review * Add and test the FIP-0061 migration * Update actors bundles to fip/20230406 * Update to go-state-types master * Update to actors v11.0.0-rc1 * - Update go state types - Keep current expiration defaults on creation, extension some tests - Update ffi * ffi experiment * Integration nv19 migration - Open splitstore in migration shed tool - Update state root version * Post rebase fixup * Fix * gen * nv19 invariant checking * Try fixig blockstore so bundle is loaded * Debug * Fix * Make butterfly upgrades happen * Another ffi experiment * Fix copy paste error * Actually schedule migration (#10656) Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * Butterfly artifacts * Set calibration net upgrade height * Review Response * Fix state tree version assert * Quick butterfly upgrade to sanity check (#10660) * Quick butterfly upgrade to sanity check * Update butterfly artifacts * Revert fake fix * Give butterfly net correct genesis * Butterfly artifacts * Give time before upgrade --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * chore:releasepolish v1.22 release (#10666) * Update butterfly artifacts * register actors v11 * Update calibration upgrade time * State inspection shed cmds * Fix * make gen * Fix swallowed errors * Lint fixup --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * v1.22.0-rc3 * bundle fix * Feat/expedite nv19 (#10681) * Update go-state-types * Modify upgrade schedule and params * Revert fip 0052 * Update gst * docsgen * fast butterfly migration to validate migration * Correct epoch to match specified date * Update actors v11 * Update changelog build version * Update butterfly artifacts * Fix lotus-miner init to work after upgrade --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * fix:deps:stable ffi for stable release (#10698) * Point to stable ffi for stable lotus release * go mod tidy --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> --------- Co-authored-by: Aayush Rajasekaran <arajasek94@gmail.com> Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> Co-authored-by: Steven Allen <steven@stebalien.com> Co-authored-by: jennijuju <jiayingw703@gmail.com>
2023-04-19 22:40:18 +00:00
power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power"
2021-08-06 10:26:33 +00:00
reward2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/reward"
power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power"
reward4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward"
2022-06-14 15:00:51 +00:00
builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin"
runtime7 "github.com/filecoin-project/specs-actors/v7/actors/runtime"
2020-02-11 20:48:03 +00:00
2021-08-06 10:26:33 +00:00
"github.com/filecoin-project/lotus/chain/actors/adt"
2022-06-14 15:00:51 +00:00
"github.com/filecoin-project/lotus/chain/actors/builtin"
2021-08-06 10:26:33 +00:00
"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/consensus"
2023-09-21 15:37:02 +00:00
lrand "github.com/filecoin-project/lotus/chain/rand"
2020-09-14 13:17:00 +00:00
"github.com/filecoin-project/lotus/chain/state"
2020-02-11 20:48:03 +00:00
"github.com/filecoin-project/lotus/chain/store"
2020-04-10 20:04:04 +00:00
"github.com/filecoin-project/lotus/chain/types"
2020-02-11 20:48:03 +00:00
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/chain/wallet/key"
2020-02-11 20:48:03 +00:00
"github.com/filecoin-project/lotus/genesis"
2022-06-14 15:00:51 +00:00
"github.com/filecoin-project/lotus/lib/sigs"
2020-02-11 20:48:03 +00:00
)
func MinerAddress(genesisIndex uint64) address.Address {
maddr, err := address.NewIDAddress(MinerStart + genesisIndex)
if err != nil {
panic(err)
}
return maddr
}
type fakedSigSyscalls struct {
2021-11-04 15:59:29 +00:00
runtime7.Syscalls
}
func (fss *fakedSigSyscalls) VerifySignature(signature crypto.Signature, signer address.Address, plaintext []byte) error {
return nil
}
2020-07-18 13:46:47 +00:00
func mkFakedSigSyscalls(base vm.SyscallBuilder) vm.SyscallBuilder {
2021-11-04 15:59:29 +00:00
return func(ctx context.Context, rt *vm.Runtime) runtime7.Syscalls {
2020-07-18 13:46:47 +00:00
return &fakedSigSyscalls{
base(ctx, rt),
2020-07-18 13:46:47 +00:00
}
}
}
// Note: Much of this is brittle, if the methodNum / param / return changes, it will break things
2023-05-29 22:05:42 +00:00
func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.SyscallBuilder, sroot cid.Cid, miners []genesis.Miner, nv network.Version, synthetic bool) (cid.Cid, error) {
cst := cbor.NewCborStore(cs.StateBlockstore())
2022-09-06 15:49:29 +00:00
av, err := actorstypes.VersionForNetwork(nv)
2021-08-10 17:07:30 +00:00
if err != nil {
return cid.Undef, xerrors.Errorf("failed to get network version: %w", err)
}
csc := func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) {
2020-07-25 22:29:33 +00:00
return big.Zero(), nil
}
2022-05-15 19:26:52 +00:00
newVM := func(base cid.Cid) (vm.Interface, error) {
vmopt := &vm.VMOpts{
StateBase: base,
Epoch: 0,
Rand: &fakeRand{},
Bstore: cs.StateBlockstore(),
Actors: consensus.NewActorRegistry(),
2022-05-15 19:26:52 +00:00
Syscalls: mkFakedSigSyscalls(sys),
CircSupplyCalc: csc,
NetworkVersion: nv,
BaseFee: big.Zero(),
}
return vm.NewVM(ctx, vmopt)
}
2022-05-15 19:26:52 +00:00
genesisVm, err := newVM(sroot)
2020-02-11 20:48:03 +00:00
if err != nil {
2022-05-15 19:26:52 +00:00
return cid.Undef, fmt.Errorf("creating vm: %w", err)
2020-02-11 20:48:03 +00:00
}
2020-02-12 02:13:00 +00:00
if len(miners) == 0 {
return cid.Undef, xerrors.New("no genesis miners")
2020-02-11 20:48:03 +00:00
}
minerInfos := make([]struct {
maddr address.Address
presealExp abi.ChainEpoch
2022-09-08 20:31:12 +00:00
dealIDs []abi.DealID
sectorWeight []abi.StoragePower
}, len(miners))
maxLifetime, err := policy.GetMaxSectorExpirationExtension(nv)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to get max extension: %w", err)
}
maxPeriods := maxLifetime / minertypes.WPoStProvingPeriod
2022-09-08 20:31:12 +00:00
rawPow, qaPow := big.NewInt(0), big.NewInt(0)
2020-02-12 02:13:00 +00:00
for i, m := range miners {
// Create miner through power actor
i := i
m := m
2020-02-11 20:48:03 +00:00
2023-05-29 22:05:42 +00:00
spt, err := miner.SealProofTypeFromSectorSize(m.SectorSize, nv, synthetic)
if err != nil {
return cid.Undef, err
}
2020-02-12 02:13:00 +00:00
{
chore: build: Merge/v22 into 21 for 23 (#10702) * chore: update ffi to increase execution parallelism * Don't enforce walking receipt tree during compaction * fix: build: drop drand incentinet servers * chore: release lotus v1.20.4 * Apply suggestions from code review Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> * feat: Introduce nv19 skeleton Update to go-state-types v0.11.0-alpha-1 Introduce dummy v11 actor bundles Make new actors adapters Add upgrade to Upgrade Schedules make jen Update to go-state-types v0.11.0-alpha-2 * feat: vm: switch to the new exec trace format (#10372) This is now "FVM" native. Changes include: 1. Don't treat "trace" messages like off-chain messages. E.g., don't include CIDs, versions, etc. 2. Include IPLD codecs where applicable. 3. Remove fields that aren't filled by the FVM (timing, some errors, code locations, etc.). * feat: implement FIP-0061 * Address review * Add and test the FIP-0061 migration * Update actors bundles to fip/20230406 * Update to go-state-types master * Update to actors v11.0.0-rc1 * - Update go state types - Keep current expiration defaults on creation, extension some tests - Update ffi * ffi experiment * Integration nv19 migration - Open splitstore in migration shed tool - Update state root version * Post rebase fixup * Fix * gen * nv19 invariant checking * Try fixig blockstore so bundle is loaded * Debug * Fix * Make butterfly upgrades happen * Another ffi experiment * Fix copy paste error * Actually schedule migration (#10656) Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * Butterfly artifacts * Set calibration net upgrade height * Review Response * Fix state tree version assert * Quick butterfly upgrade to sanity check (#10660) * Quick butterfly upgrade to sanity check * Update butterfly artifacts * Revert fake fix * Give butterfly net correct genesis * Butterfly artifacts * Give time before upgrade --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * chore:releasepolish v1.22 release (#10666) * Update butterfly artifacts * register actors v11 * Update calibration upgrade time * State inspection shed cmds * Fix * make gen * Fix swallowed errors * Lint fixup --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * v1.22.0-rc3 * bundle fix * Feat/expedite nv19 (#10681) * Update go-state-types * Modify upgrade schedule and params * Revert fip 0052 * Update gst * docsgen * fast butterfly migration to validate migration * Correct epoch to match specified date * Update actors v11 * Update changelog build version * Update butterfly artifacts * Fix lotus-miner init to work after upgrade --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * fix:deps:stable ffi for stable release (#10698) * Point to stable ffi for stable lotus release * go mod tidy --------- Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> --------- Co-authored-by: Aayush Rajasekaran <arajasek94@gmail.com> Co-authored-by: zenground0 <ZenGround0@users.noreply.github.com> Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> Co-authored-by: Steven Allen <steven@stebalien.com> Co-authored-by: jennijuju <jiayingw703@gmail.com>
2023-04-19 22:40:18 +00:00
var params []byte
if nv <= network.Version10 {
constructorParams := &power2.CreateMinerParams{
Owner: m.Worker,
Worker: m.Worker,
Peer: []byte(m.PeerId),
SealProofType: spt,
}
params = mustEnc(constructorParams)
} else {
ppt, err := spt.RegisteredWindowPoStProofByNetworkVersion(nv)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to convert spt to wpt: %w", err)
}
constructorParams := &power11.CreateMinerParams{
Owner: m.Worker,
Worker: m.Worker,
Peer: []byte(m.PeerId),
WindowPoStProofType: ppt,
}
params = mustEnc(constructorParams)
2020-02-11 20:48:03 +00:00
}
2022-05-15 19:26:52 +00:00
rval, err := doExecValue(ctx, genesisVm, power.Address, m.Owner, m.PowerBalance, power.Methods.CreateMiner, params)
2020-02-12 02:13:00 +00:00
if err != nil {
return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err)
}
2020-02-11 20:48:03 +00:00
var ma power0.CreateMinerReturn
if err := ma.UnmarshalCBOR(bytes.NewReader(rval)); err != nil {
2020-04-21 14:32:17 +00:00
return cid.Undef, xerrors.Errorf("unmarshaling CreateMinerReturn: %w", err)
2020-02-12 02:13:00 +00:00
}
expma := MinerAddress(uint64(i))
if ma.IDAddress != expma {
return cid.Undef, xerrors.Errorf("miner assigned wrong address: %s != %s", ma.IDAddress, expma)
2020-02-11 20:48:03 +00:00
}
minerInfos[i].maddr = ma.IDAddress
2022-05-15 19:26:52 +00:00
nh, err := genesisVm.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
}
2022-05-15 19:26:52 +00:00
nst, err := state.LoadStateTree(cst, nh)
if err != nil {
return cid.Undef, xerrors.Errorf("loading new state tree: %w", err)
}
mact, err := nst.GetActor(minerInfos[i].maddr)
if err != nil {
return cid.Undef, xerrors.Errorf("getting newly created miner actor: %w", err)
}
mst, err := miner.Load(adt.WrapStore(ctx, cst), mact)
if err != nil {
return cid.Undef, xerrors.Errorf("getting newly created miner state: %w", err)
}
pps, err := mst.GetProvingPeriodStart()
if err != nil {
return cid.Undef, xerrors.Errorf("getting newly created miner proving period start: %w", err)
}
minerInfos[i].presealExp = (maxPeriods-1)*miner0.WPoStProvingPeriod + pps - 1
2020-02-11 20:48:03 +00:00
}
2020-02-12 02:13:00 +00:00
// Add market funds
2020-02-11 20:48:03 +00:00
2020-07-28 16:16:46 +00:00
if m.MarketBalance.GreaterThan(big.Zero()) {
params := mustEnc(&minerInfos[i].maddr)
2022-05-15 19:26:52 +00:00
_, err := doExecValue(ctx, genesisVm, market.Address, m.Worker, m.MarketBalance, market.Methods.AddBalance, params)
2020-02-12 02:13:00 +00:00
if err != nil {
return cid.Undef, xerrors.Errorf("failed to create genesis miner (add balance): %w", err)
2020-02-12 02:13:00 +00:00
}
2020-02-11 20:48:03 +00:00
}
2022-09-08 20:31:12 +00:00
// Publish preseal deals, and calculate the QAPower
2020-02-11 20:48:03 +00:00
2020-02-12 02:13:00 +00:00
{
2022-04-20 21:34:28 +00:00
publish := func(params *markettypes.PublishStorageDealsParams) error {
2020-04-20 13:54:06 +00:00
fmt.Printf("publishing %d storage deals on miner %s with worker %s\n", len(params.Deals), params.Deals[0].Proposal.Provider, m.Worker)
2022-05-15 19:26:52 +00:00
ret, err := doExecValue(ctx, genesisVm, market.Address, m.Worker, big.Zero(), builtin0.MethodsMarket.PublishStorageDeals, mustEnc(params))
2020-04-20 13:54:06 +00:00
if err != nil {
return xerrors.Errorf("failed to create genesis miner (publish deals): %w", err)
2020-04-20 13:54:06 +00:00
}
retval, err := market.DecodePublishStorageDealsReturn(ret, nv)
if err != nil {
return xerrors.Errorf("failed to create genesis miner (decoding published deals): %w", err)
}
ids, err := retval.DealIDs()
if err != nil {
return xerrors.Errorf("failed to create genesis miner (getting published dealIDs): %w", err)
}
if len(ids) != len(params.Deals) {
return xerrors.Errorf("failed to create genesis miner (at least one deal was invalid on publication")
2020-04-20 13:54:06 +00:00
}
minerInfos[i].dealIDs = append(minerInfos[i].dealIDs, ids...)
2020-04-20 13:54:06 +00:00
return nil
}
2022-04-20 21:34:28 +00:00
params := &markettypes.PublishStorageDealsParams{}
2023-09-29 16:56:10 +00:00
for _, presealTmp := range m.Sectors {
preseal := presealTmp
2020-05-14 02:32:04 +00:00
preseal.Deal.VerifiedDeal = true
preseal.Deal.EndEpoch = minerInfos[i].presealExp
p := markettypes.ClientDealProposal{
Proposal: preseal.Deal,
ClientSignature: crypto.Signature{Type: crypto.SigTypeBLS},
2022-05-15 19:26:52 +00:00
}
2022-09-06 15:49:29 +00:00
if av >= actorstypes.Version8 {
buf, err := cborutil.Dump(&preseal.Deal)
if err != nil {
return cid.Undef, fmt.Errorf("failed to marshal proposal: %w", err)
}
sig, err := sigs.Sign(key.ActSigType(preseal.DealClientKey.Type), preseal.DealClientKey.PrivateKey, buf)
if err != nil {
return cid.Undef, fmt.Errorf("failed to sign proposal: %w", err)
}
p.ClientSignature = *sig
2022-05-15 19:26:52 +00:00
}
params.Deals = append(params.Deals, p)
2020-02-11 20:48:03 +00:00
2020-04-20 13:54:06 +00:00
if len(params.Deals) == cbg.MaxLength {
if err := publish(params); err != nil {
return cid.Undef, err
}
2022-04-20 21:34:28 +00:00
params = &markettypes.PublishStorageDealsParams{}
2020-04-20 13:54:06 +00:00
}
2022-09-08 20:31:12 +00:00
rawPow = big.Add(rawPow, big.NewInt(int64(m.SectorSize)))
2022-09-10 14:34:47 +00:00
sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, big.Zero(), markettypes.DealWeight(&preseal.Deal))
2022-09-08 20:31:12 +00:00
minerInfos[i].sectorWeight = append(minerInfos[i].sectorWeight, sectorWeight)
qaPow = big.Add(qaPow, sectorWeight)
2020-02-11 20:48:03 +00:00
}
2020-04-20 13:54:06 +00:00
if len(params.Deals) > 0 {
if err := publish(params); err != nil {
return cid.Undef, err
}
}
2020-02-11 20:48:03 +00:00
}
}
2020-02-11 20:48:03 +00:00
2022-09-09 20:42:55 +00:00
{
2022-05-15 19:26:52 +00:00
nh, err := genesisVm.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
}
2020-07-17 21:34:18 +00:00
2022-05-15 19:26:52 +00:00
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
}
nst, err := state.LoadStateTree(cst, nh)
if err != nil {
return cid.Undef, xerrors.Errorf("loading new state tree: %w", err)
}
pact, err := nst.GetActor(power.Address)
if err != nil {
return cid.Undef, xerrors.Errorf("getting power actor: %w", err)
}
pst, err := power.Load(adt.WrapStore(ctx, cst), pact)
if err != nil {
return cid.Undef, xerrors.Errorf("getting power state: %w", err)
}
if err = pst.SetTotalQualityAdjPower(qaPow); err != nil {
return cid.Undef, xerrors.Errorf("setting TotalQualityAdjPower in power state: %w", err)
}
if err = pst.SetTotalRawBytePower(rawPow); err != nil {
return cid.Undef, xerrors.Errorf("setting TotalRawBytePower in power state: %w", err)
}
if err = pst.SetThisEpochQualityAdjPower(qaPow); err != nil {
return cid.Undef, xerrors.Errorf("setting ThisEpochQualityAdjPower in power state: %w", err)
}
if err = pst.SetThisEpochRawBytePower(rawPow); err != nil {
return cid.Undef, xerrors.Errorf("setting ThisEpochRawBytePower in power state: %w", err)
}
pcid, err := cst.Put(ctx, pst.GetState())
if err != nil {
return cid.Undef, xerrors.Errorf("putting power state: %w", err)
}
pact.Head = pcid
2022-05-15 19:26:52 +00:00
if err = nst.SetActor(power.Address, pact); err != nil {
return cid.Undef, xerrors.Errorf("setting power state: %w", err)
}
2021-08-10 17:07:30 +00:00
rewact, err := SetupRewardActor(ctx, cs.StateBlockstore(), big.Zero(), av)
if err != nil {
return cid.Undef, xerrors.Errorf("setup reward actor: %w", err)
}
2022-05-15 19:26:52 +00:00
if err = nst.SetActor(reward.Address, rewact); err != nil {
return cid.Undef, xerrors.Errorf("set reward actor: %w", err)
}
2022-05-15 19:26:52 +00:00
nh, err = nst.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
}
genesisVm, err = newVM(nh)
if err != nil {
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
}
}
2020-02-18 21:37:59 +00:00
for i, m := range miners {
// Commit sectors
{
for pi, preseal := range m.Sectors {
chore: Merge nv22 into master (#11699) * [WIP] feat: Add nv22 skeleton Addition of Network Version 22 skeleton * update FFI * feat: drand: refactor round verification * feat: sealing: Support nv22 DDO features in the sealing pipeline (#11226) * Initial work supporting DDO pieces in lotus-miner * sealing: Update pipeline input to operate on UniversalPiece * sealing: Update pipeline checks/sealing states to operate on UniversalPiece * sealing: Make pipeline build with UniversalPiece * move PieceDealInfo out of api * make gen * make sealing pipeline unit tests pass * fix itest ensemble build * don't panic in SectorsStatus with deals * stop linter from complaining about checkPieces * fix sector import tests * mod tidy * sealing: Add logic for (pre)committing DDO sectors * sealing: state-types with method defs * DDO non-snap pipeline works(?), DDO Itests * DDO support in snapdeals pipeline * make gen * update actor bundles * update the gst market fix * fix: chain: use PreCommitSectorsBatch2 when setting up genesis * some bug fixes * integration working changes * update actor bundles * Make TestOnboardRawPieceSnap pass * Appease the linter * Make deadlines test pass with v12 actors * Update go-state-types, abstract market DealState * make gen * mod tidy, lint fixes * Fix some more tests * Bump version in master Bump version in master * Make gen Make gen * fix sender * fix: lotus-provider: Fix winning PoSt * fix: sql Scan cannot write to an object * Actually show miner-addrs in info-log Actually show miner-addrs in lotus-provider info-log * [WIP] feat: Add nv22 skeleton Addition of Network Version 22 skeleton * update FFI * ddo is now nv22 * make gen * temp actor bundle with ddo * use working go-state-types * gst with v13 market migration * update bundle, builtin.MethodsMiner.ProveCommitSectors2 -> 3 * actually working v13 migration, v13 migration itest * Address review * sealing: Correct DDO snap pledge math * itests: Mixed ddo itest * pipeline: Fix sectorWeight * sealing: convert market deals into PAMs in mixed sectors * sealing: make market to ddo conversion work * fix lint * update gst * Update actors and GST to lastest integ branch * commit batcher: Update ProveCommitSectors3Params builder logic * make gen * use builtin-actors master * ddo: address review * itests: Add commd assertions to ddo tests * make gen * gst with fixed types * config knobs for RequireActivationSuccess * storage: Drop obsolete flaky tasts --------- Co-authored-by: Jennifer Wang <jiayingw703@gmail.com> Co-authored-by: Aayush <arajasek94@gmail.com> Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai> Co-authored-by: Phi <orjan.roren@gmail.com> Co-authored-by: Andrew Jackson (Ajax) <snadrus@gmail.com> Co-authored-by: TippyFlits <james.bluett@protocol.ai> * feat: implement FIP-0063 * chore: deps: update to go-multiaddr v0.12.2 (#11602) * feat: fvm: update the FVM/FFI to v4.1 (#11608) (#11612) This: 1. Adds nv22 support. 2. Updates the message tracing format. Co-authored-by: Steven Allen <steven@stebalien.com> * AggregateProofType nil when doing batch updates Use latest nv22 go-state-types version with matching update * Update to v13.0.0-rc.2 bundle * chore: Upgrade heights and codename Update upgrade heights Co-Authored-By: Steven Allen <steven@stebalien.com> * Update epoch after nv22 DRAND switch Update epoch after nv22 DRAND switch * Update Mango codename to Phoneix Make the codename for the Drand-change inline with Dragon style. * Add UpgradePhoenixHeight to API params * set UpgradePhoenixHeight to be one hour after Dragon * Make gen Make gen and UpgradePhoenixHeight in butterfly and local devnet to be in line with Calibration and Mainnet * Update epoch heights (#11637) Update epoch heights * new: add forest bootstrap nodes (#11636) Signed-off-by: samuelarogbonlo <sbayo971@gmail.com> * Merge pull request #11491 from filecoin-project/fix/remove-decommissioned-pl-bootstrap-nodes Remove PL operated bootstrap nodes from mainnet.pi * feat: api: new verified registry methods to get all allocations and claims (#11631) * new verireg methods * update changelog and add itest * update itest and cli * update new method's support till v9 * remove gateway APIs * fix cli internal var names * chore:: backport #11609 to the feat/nv22 branch (#11644) * feat: api: improve the correctness of Eth's trace_block (#11609) * Improve the correctness of Eth's trace_block - Improve encoding/decoding of parameters and return values: - Encode "native" parameters and return values with Solidity ABI. - Correctly decode parameters to "create" calls. - Use the correct (ish) output for "create" calls. - Handle all forms of "create". - Make robust with respect to reverts: - Use the actor ID/address from the trace instead of looking it up in the state-tree (may not exist in the state-tree due to a revert). - Gracefully handle failed actor/contract creation. - Improve performance: - We avoid looking anything up in the state-tree when translating the trace, which should significantly improve performance. - Improve code readability: - Remove all "backtracking" logic. - Use an "environment" struct to store temporary state instead of attaching it to the trace. - Fix random bugs: - Fix an allocation bug in the "address" logic (need to set the capacity before modifying the slice). - Improved error checking/handling. - Use correct types for `trace_block` action/results (create, call, etc.). - And use the correct types for Result/Action structs instead of reusing the same "Call" action every time. - Improve error messages. * Make gen Make gen --------- Co-authored-by: Steven Allen <steven@stebalien.com> * fix: add UpgradePhoenixHeight to StateGetNetworkParams (#11648) * chore: deps: update to go-state-types v13.0.0-rc.1 * do NOT update the cache when running the real migration * Merge pull request #11632 from hanabi1224/hm/drand-test feat: drand quicknet: allow scheduling drand quicknet upgrade before nv22 on 2k devnet * chore: deps: update to go-state-types v13.0.0-rc.2 chore: deps: update to go-state-types v13.0.0-rc.2 * feat: set migration config UpgradeEpoch for v13 actors upgrade * Built-in actor events first draft * itest for DDO non-market verified data w/ builtin actor events * Tests for builtin actor events API * Clean up DDO+Events tests, add lots of explainer comments * Minor tweaks to events types * Avoid duplicate messages when looking for receipts * Rename internal events modules for clarity * Adjust actor event API after review * s/ActorEvents/Events/g in global config * Manage event sending rate for SubscribeActorEvents * Terminate SubscribeActorEvents chan when at max height * Document future API changes * More clarity in actor event API docs * More post-review changes, lots of tests for SubscribeActorEvents Use BlockDelay as the window for receiving events on the SubscribeActorEvents channel. We expect the user to have received the initial batch of historical events (if any) in one block's time. For real-time events we expect them to not fall behind by roughly one block's time. * Remove duplicate code from actor event type marshalling tests Reduce verbosity and remove duplicate test logic from actor event types JSON marshalling tests. * Rename actor events test to follow go convention Add missing `s` to `actor_events` test file to follow golang convention used across the repo. * Run actor events table tests in deterministic order Refactor `map` usage for actor event table tests to ensure deterministic test execution order, making debugging potential issues easier. If non-determinism is a target, leverage Go's built-in parallel testing capabilities. * Reduce scope for filter removal failure when getting actor events Use a fresh context to remove the temporary filter installed solely to get the actor events. This should reduce chances of failure in a case where the original context may be expired/cancelled. Refactor removal into a `defer` statement for a more readable, concise return statement. * Use fixed RNG seed for actor event tests Improve determinism in actor event tests by using a fixed RNG seed. This makes up a more reproducible test suit. * Use provided libraries to assert eventual conditions Use the functionalities already provided by `testify` to assert eventual conditions, and remove the use of `time.Sleep`. Remove duplicate code in utility functions that are already defined. Refactor assertion helper functions to use consistent terminology: "require" implies fatal error, whereas "assert" implies error where the test may proceed executing. * Update changelog for actor events APIs * Fix concerns and docs identified by review * Update actor bundle to v13.0.0-rc3 Update actor bundle to v13.0.0-rc3 * Prep Lotus v1.26.0-rc1 - For sanity reverting the mainnet upgrade epoch to 99999999, and then only set it when cutting the final release -Update Calibnet CIDs to v13.0.0-rc3 - Add GetActorEvents, SubscribeActorEvents, GetAllClaims and GetAllAllocations methods to the changelog Co-Authored-By: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Masih H. Derkani <m@derkani.org> * Make gen Make gen * fix: beacon: validate drand change at nv16 correctly * bump to v1.26.0-rc2 * test: cleanup ddo verified itest, extract steps to functions also add allocation-removed event case * test: extract verified DDO test to separate file, add more checks * test: add additional actor events checks * Add verification for "deal-activated" actor event * docs(drand): document the meaning of "IsChained" (#11692) * Resolve conflicts I encountered multiple issues when trying to run make gen. And these changes fixed a couple of them: - go mod tidy - Remove RaftState/RaftLeader - Revert `if ts.Height() > claim.TermMax+claim.TermStart || !cctx.IsSet("expired")` to the what is in the release/v1.26.0: `if tsHeight > val.TermMax || !expired` * fixup imports, make jen * Update version Update version in master to v1.27.0-dev * Update node/impl/full/dummy.go Co-authored-by: Łukasz Magiera <magik6k@users.noreply.github.com> * Adjust ListClaimsCmd Adjust ListClaimsCmd according to review --------- Signed-off-by: samuelarogbonlo <sbayo971@gmail.com> Co-authored-by: TippyFlits <james.bluett@protocol.ai> Co-authored-by: Aayush <arajasek94@gmail.com> Co-authored-by: Łukasz Magiera <magik6k@users.noreply.github.com> Co-authored-by: Jennifer Wang <jiayingw703@gmail.com> Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai> Co-authored-by: Andrew Jackson (Ajax) <snadrus@gmail.com> Co-authored-by: Steven Allen <steven@stebalien.com> Co-authored-by: Rod Vagg <rod@vagg.org> Co-authored-by: Samuel Arogbonlo <47984109+samuelarogbonlo@users.noreply.github.com> Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Co-authored-by: tom123222 <160735201+tom123222@users.noreply.github.com> Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com> Co-authored-by: Masih H. Derkani <m@derkani.org> Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com>
2024-03-12 09:33:58 +00:00
var paramEnc []byte
var preCommitMethodNum abi.MethodNum
if nv >= network.Version22 {
paramEnc = mustEnc(&miner.PreCommitSectorBatchParams2{
Sectors: []miner.SectorPreCommitInfo{
{
SealProof: preseal.ProofType,
SectorNumber: preseal.SectorID,
SealedCID: preseal.CommR,
SealRandEpoch: -1,
DealIDs: []abi.DealID{minerInfos[i].dealIDs[pi]},
Expiration: minerInfos[i].presealExp, // TODO: Allow setting externally!
UnsealedCid: &preseal.CommD,
},
},
})
preCommitMethodNum = builtintypes.MethodsMiner.PreCommitSectorBatch2
} else {
paramEnc = mustEnc(&minertypes.SectorPreCommitInfo{
SealProof: preseal.ProofType,
SectorNumber: preseal.SectorID,
SealedCID: preseal.CommR,
SealRandEpoch: -1,
DealIDs: []abi.DealID{minerInfos[i].dealIDs[pi]},
Expiration: minerInfos[i].presealExp, // TODO: Allow setting externally!
})
preCommitMethodNum = builtintypes.MethodsMiner.PreCommitSector
}
2020-04-10 20:04:04 +00:00
2022-09-08 20:31:12 +00:00
sectorWeight := minerInfos[i].sectorWeight[pi]
// we've added fake power for this sector above, remove it now
2022-05-15 19:26:52 +00:00
nh, err := genesisVm.Flush(ctx)
2020-02-18 21:37:59 +00:00
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
2020-02-18 21:37:59 +00:00
}
2022-05-15 19:26:52 +00:00
nst, err := state.LoadStateTree(cst, nh)
if err != nil {
return cid.Undef, xerrors.Errorf("loading new state tree: %w", err)
}
pact, err := nst.GetActor(power.Address)
if err != nil {
return cid.Undef, xerrors.Errorf("getting power actor: %w", err)
}
pst, err := power.Load(adt.WrapStore(ctx, cst), pact)
if err != nil {
return cid.Undef, xerrors.Errorf("getting power state: %w", err)
}
pc, err := pst.TotalPower()
if err != nil {
return cid.Undef, xerrors.Errorf("getting total power: %w", err)
}
if err = pst.SetTotalRawBytePower(types.BigSub(pc.RawBytePower, types.NewInt(uint64(m.SectorSize)))); err != nil {
return cid.Undef, xerrors.Errorf("setting TotalRawBytePower in power state: %w", err)
}
if err = pst.SetTotalQualityAdjPower(types.BigSub(pc.QualityAdjPower, sectorWeight)); err != nil {
return cid.Undef, xerrors.Errorf("setting TotalQualityAdjPower in power state: %w", err)
}
pcid, err := cst.Put(ctx, pst.GetState())
if err != nil {
return cid.Undef, xerrors.Errorf("putting power state: %w", err)
}
pact.Head = pcid
2022-05-15 19:26:52 +00:00
if err = nst.SetActor(power.Address, pact); err != nil {
return cid.Undef, xerrors.Errorf("setting power state: %w", err)
}
2022-05-15 19:26:52 +00:00
nh, err = nst.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
}
genesisVm, err = newVM(nh)
if err != nil {
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
}
baselinePower, rewardSmoothed, err := currentEpochBlockReward(ctx, genesisVm, minerInfos[i].maddr, av)
if err != nil {
return cid.Undef, xerrors.Errorf("getting current epoch reward: %w", err)
2020-02-18 21:37:59 +00:00
}
2022-05-15 19:26:52 +00:00
tpow, err := currentTotalPower(ctx, genesisVm, minerInfos[i].maddr)
if err != nil {
return cid.Undef, xerrors.Errorf("getting current total power: %w", err)
}
2020-02-18 21:37:59 +00:00
2022-09-08 20:31:12 +00:00
pcd := miner9.PreCommitDepositForPower(smoothing9.FilterEstimate(rewardSmoothed), smoothing9.FilterEstimate(*tpow.QualityAdjPowerSmoothed), miner9.QAPowerMax(m.SectorSize))
2020-08-18 17:35:46 +00:00
2022-09-08 20:31:12 +00:00
pledge := miner9.InitialPledgeForPower(
2020-07-28 18:55:20 +00:00
sectorWeight,
baselinePower,
2022-09-08 20:31:12 +00:00
smoothing9.FilterEstimate(rewardSmoothed),
smoothing9.FilterEstimate(*tpow.QualityAdjPowerSmoothed),
2022-05-15 19:26:52 +00:00
big.Zero(),
2020-07-28 18:55:20 +00:00
)
2020-07-28 14:36:32 +00:00
2020-08-18 17:35:46 +00:00
pledge = big.Add(pcd, pledge)
chore: Merge nv22 into master (#11699) * [WIP] feat: Add nv22 skeleton Addition of Network Version 22 skeleton * update FFI * feat: drand: refactor round verification * feat: sealing: Support nv22 DDO features in the sealing pipeline (#11226) * Initial work supporting DDO pieces in lotus-miner * sealing: Update pipeline input to operate on UniversalPiece * sealing: Update pipeline checks/sealing states to operate on UniversalPiece * sealing: Make pipeline build with UniversalPiece * move PieceDealInfo out of api * make gen * make sealing pipeline unit tests pass * fix itest ensemble build * don't panic in SectorsStatus with deals * stop linter from complaining about checkPieces * fix sector import tests * mod tidy * sealing: Add logic for (pre)committing DDO sectors * sealing: state-types with method defs * DDO non-snap pipeline works(?), DDO Itests * DDO support in snapdeals pipeline * make gen * update actor bundles * update the gst market fix * fix: chain: use PreCommitSectorsBatch2 when setting up genesis * some bug fixes * integration working changes * update actor bundles * Make TestOnboardRawPieceSnap pass * Appease the linter * Make deadlines test pass with v12 actors * Update go-state-types, abstract market DealState * make gen * mod tidy, lint fixes * Fix some more tests * Bump version in master Bump version in master * Make gen Make gen * fix sender * fix: lotus-provider: Fix winning PoSt * fix: sql Scan cannot write to an object * Actually show miner-addrs in info-log Actually show miner-addrs in lotus-provider info-log * [WIP] feat: Add nv22 skeleton Addition of Network Version 22 skeleton * update FFI * ddo is now nv22 * make gen * temp actor bundle with ddo * use working go-state-types * gst with v13 market migration * update bundle, builtin.MethodsMiner.ProveCommitSectors2 -> 3 * actually working v13 migration, v13 migration itest * Address review * sealing: Correct DDO snap pledge math * itests: Mixed ddo itest * pipeline: Fix sectorWeight * sealing: convert market deals into PAMs in mixed sectors * sealing: make market to ddo conversion work * fix lint * update gst * Update actors and GST to lastest integ branch * commit batcher: Update ProveCommitSectors3Params builder logic * make gen * use builtin-actors master * ddo: address review * itests: Add commd assertions to ddo tests * make gen * gst with fixed types * config knobs for RequireActivationSuccess * storage: Drop obsolete flaky tasts --------- Co-authored-by: Jennifer Wang <jiayingw703@gmail.com> Co-authored-by: Aayush <arajasek94@gmail.com> Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai> Co-authored-by: Phi <orjan.roren@gmail.com> Co-authored-by: Andrew Jackson (Ajax) <snadrus@gmail.com> Co-authored-by: TippyFlits <james.bluett@protocol.ai> * feat: implement FIP-0063 * chore: deps: update to go-multiaddr v0.12.2 (#11602) * feat: fvm: update the FVM/FFI to v4.1 (#11608) (#11612) This: 1. Adds nv22 support. 2. Updates the message tracing format. Co-authored-by: Steven Allen <steven@stebalien.com> * AggregateProofType nil when doing batch updates Use latest nv22 go-state-types version with matching update * Update to v13.0.0-rc.2 bundle * chore: Upgrade heights and codename Update upgrade heights Co-Authored-By: Steven Allen <steven@stebalien.com> * Update epoch after nv22 DRAND switch Update epoch after nv22 DRAND switch * Update Mango codename to Phoneix Make the codename for the Drand-change inline with Dragon style. * Add UpgradePhoenixHeight to API params * set UpgradePhoenixHeight to be one hour after Dragon * Make gen Make gen and UpgradePhoenixHeight in butterfly and local devnet to be in line with Calibration and Mainnet * Update epoch heights (#11637) Update epoch heights * new: add forest bootstrap nodes (#11636) Signed-off-by: samuelarogbonlo <sbayo971@gmail.com> * Merge pull request #11491 from filecoin-project/fix/remove-decommissioned-pl-bootstrap-nodes Remove PL operated bootstrap nodes from mainnet.pi * feat: api: new verified registry methods to get all allocations and claims (#11631) * new verireg methods * update changelog and add itest * update itest and cli * update new method's support till v9 * remove gateway APIs * fix cli internal var names * chore:: backport #11609 to the feat/nv22 branch (#11644) * feat: api: improve the correctness of Eth's trace_block (#11609) * Improve the correctness of Eth's trace_block - Improve encoding/decoding of parameters and return values: - Encode "native" parameters and return values with Solidity ABI. - Correctly decode parameters to "create" calls. - Use the correct (ish) output for "create" calls. - Handle all forms of "create". - Make robust with respect to reverts: - Use the actor ID/address from the trace instead of looking it up in the state-tree (may not exist in the state-tree due to a revert). - Gracefully handle failed actor/contract creation. - Improve performance: - We avoid looking anything up in the state-tree when translating the trace, which should significantly improve performance. - Improve code readability: - Remove all "backtracking" logic. - Use an "environment" struct to store temporary state instead of attaching it to the trace. - Fix random bugs: - Fix an allocation bug in the "address" logic (need to set the capacity before modifying the slice). - Improved error checking/handling. - Use correct types for `trace_block` action/results (create, call, etc.). - And use the correct types for Result/Action structs instead of reusing the same "Call" action every time. - Improve error messages. * Make gen Make gen --------- Co-authored-by: Steven Allen <steven@stebalien.com> * fix: add UpgradePhoenixHeight to StateGetNetworkParams (#11648) * chore: deps: update to go-state-types v13.0.0-rc.1 * do NOT update the cache when running the real migration * Merge pull request #11632 from hanabi1224/hm/drand-test feat: drand quicknet: allow scheduling drand quicknet upgrade before nv22 on 2k devnet * chore: deps: update to go-state-types v13.0.0-rc.2 chore: deps: update to go-state-types v13.0.0-rc.2 * feat: set migration config UpgradeEpoch for v13 actors upgrade * Built-in actor events first draft * itest for DDO non-market verified data w/ builtin actor events * Tests for builtin actor events API * Clean up DDO+Events tests, add lots of explainer comments * Minor tweaks to events types * Avoid duplicate messages when looking for receipts * Rename internal events modules for clarity * Adjust actor event API after review * s/ActorEvents/Events/g in global config * Manage event sending rate for SubscribeActorEvents * Terminate SubscribeActorEvents chan when at max height * Document future API changes * More clarity in actor event API docs * More post-review changes, lots of tests for SubscribeActorEvents Use BlockDelay as the window for receiving events on the SubscribeActorEvents channel. We expect the user to have received the initial batch of historical events (if any) in one block's time. For real-time events we expect them to not fall behind by roughly one block's time. * Remove duplicate code from actor event type marshalling tests Reduce verbosity and remove duplicate test logic from actor event types JSON marshalling tests. * Rename actor events test to follow go convention Add missing `s` to `actor_events` test file to follow golang convention used across the repo. * Run actor events table tests in deterministic order Refactor `map` usage for actor event table tests to ensure deterministic test execution order, making debugging potential issues easier. If non-determinism is a target, leverage Go's built-in parallel testing capabilities. * Reduce scope for filter removal failure when getting actor events Use a fresh context to remove the temporary filter installed solely to get the actor events. This should reduce chances of failure in a case where the original context may be expired/cancelled. Refactor removal into a `defer` statement for a more readable, concise return statement. * Use fixed RNG seed for actor event tests Improve determinism in actor event tests by using a fixed RNG seed. This makes up a more reproducible test suit. * Use provided libraries to assert eventual conditions Use the functionalities already provided by `testify` to assert eventual conditions, and remove the use of `time.Sleep`. Remove duplicate code in utility functions that are already defined. Refactor assertion helper functions to use consistent terminology: "require" implies fatal error, whereas "assert" implies error where the test may proceed executing. * Update changelog for actor events APIs * Fix concerns and docs identified by review * Update actor bundle to v13.0.0-rc3 Update actor bundle to v13.0.0-rc3 * Prep Lotus v1.26.0-rc1 - For sanity reverting the mainnet upgrade epoch to 99999999, and then only set it when cutting the final release -Update Calibnet CIDs to v13.0.0-rc3 - Add GetActorEvents, SubscribeActorEvents, GetAllClaims and GetAllAllocations methods to the changelog Co-Authored-By: Jiaying Wang <42981373+jennijuju@users.noreply.github.com> * Update CHANGELOG.md Co-authored-by: Masih H. Derkani <m@derkani.org> * Make gen Make gen * fix: beacon: validate drand change at nv16 correctly * bump to v1.26.0-rc2 * test: cleanup ddo verified itest, extract steps to functions also add allocation-removed event case * test: extract verified DDO test to separate file, add more checks * test: add additional actor events checks * Add verification for "deal-activated" actor event * docs(drand): document the meaning of "IsChained" (#11692) * Resolve conflicts I encountered multiple issues when trying to run make gen. And these changes fixed a couple of them: - go mod tidy - Remove RaftState/RaftLeader - Revert `if ts.Height() > claim.TermMax+claim.TermStart || !cctx.IsSet("expired")` to the what is in the release/v1.26.0: `if tsHeight > val.TermMax || !expired` * fixup imports, make jen * Update version Update version in master to v1.27.0-dev * Update node/impl/full/dummy.go Co-authored-by: Łukasz Magiera <magik6k@users.noreply.github.com> * Adjust ListClaimsCmd Adjust ListClaimsCmd according to review --------- Signed-off-by: samuelarogbonlo <sbayo971@gmail.com> Co-authored-by: TippyFlits <james.bluett@protocol.ai> Co-authored-by: Aayush <arajasek94@gmail.com> Co-authored-by: Łukasz Magiera <magik6k@users.noreply.github.com> Co-authored-by: Jennifer Wang <jiayingw703@gmail.com> Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai> Co-authored-by: Andrew Jackson (Ajax) <snadrus@gmail.com> Co-authored-by: Steven Allen <steven@stebalien.com> Co-authored-by: Rod Vagg <rod@vagg.org> Co-authored-by: Samuel Arogbonlo <47984109+samuelarogbonlo@users.noreply.github.com> Co-authored-by: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Co-authored-by: tom123222 <160735201+tom123222@users.noreply.github.com> Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com> Co-authored-by: Masih H. Derkani <m@derkani.org> Co-authored-by: Jiaying Wang <42981373+jennijuju@users.noreply.github.com>
2024-03-12 09:33:58 +00:00
_, err = doExecValue(ctx, genesisVm, minerInfos[i].maddr, m.Worker, pledge, preCommitMethodNum, paramEnc)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err)
}
2020-02-18 21:37:59 +00:00
// Commit one-by-one, otherwise pledge math tends to explode
2021-09-30 00:44:27 +00:00
var paramBytes []byte
2022-09-06 15:49:29 +00:00
if av >= actorstypes.Version6 {
2021-09-30 00:44:27 +00:00
// TODO: fixup
confirmParams := &builtin6.ConfirmSectorProofsParams{
Sectors: []abi.SectorNumber{preseal.SectorID},
}
paramBytes = mustEnc(confirmParams)
} else {
confirmParams := &builtin0.ConfirmSectorProofsParams{
Sectors: []abi.SectorNumber{preseal.SectorID},
}
paramBytes = mustEnc(confirmParams)
}
2022-05-15 19:26:52 +00:00
_, err = doExecValue(ctx, genesisVm, minerInfos[i].maddr, power.Address, big.Zero(), builtintypes.MethodsMiner.ConfirmSectorProofsValid, paramBytes)
2020-02-19 19:26:11 +00:00
if err != nil {
return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err)
2020-02-19 19:26:11 +00:00
}
2022-09-06 15:49:29 +00:00
if av >= actorstypes.Version2 {
2021-08-06 10:26:33 +00:00
// 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,
}
2022-05-15 19:26:52 +00:00
_, err = doExecValue(ctx, genesisVm, power.Address, minerInfos[i].maddr, big.Zero(), power.Methods.UpdateClaimedPower, mustEnc(claimParams))
if err != nil {
return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err)
}
2022-05-15 19:26:52 +00:00
nh, err := genesisVm.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
}
2022-05-15 19:26:52 +00:00
nst, err := state.LoadStateTree(cst, nh)
if err != nil {
return cid.Undef, xerrors.Errorf("loading new state tree: %w", err)
}
mact, err := nst.GetActor(minerInfos[i].maddr)
if err != nil {
return cid.Undef, xerrors.Errorf("getting miner actor: %w", err)
}
mst, err := miner.Load(adt.WrapStore(ctx, cst), mact)
if err != nil {
return cid.Undef, xerrors.Errorf("getting miner state: %w", err)
}
if err = mst.EraseAllUnproven(); err != nil {
return cid.Undef, xerrors.Errorf("failed to erase unproven sectors: %w", err)
}
mcid, err := cst.Put(ctx, mst.GetState())
if err != nil {
return cid.Undef, xerrors.Errorf("putting miner state: %w", err)
}
mact.Head = mcid
2022-05-15 19:26:52 +00:00
if err = nst.SetActor(minerInfos[i].maddr, mact); err != nil {
return cid.Undef, xerrors.Errorf("setting miner state: %w", err)
}
2022-05-15 19:26:52 +00:00
nh, err = nst.Flush(ctx)
if err != nil {
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
}
genesisVm, err = newVM(nh)
if err != nil {
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
}
}
2020-02-18 21:37:59 +00:00
}
2020-02-11 20:48:03 +00:00
}
}
// Sanity-check total network power
2022-05-15 19:26:52 +00:00
nh, err := genesisVm.Flush(ctx)
if err != nil {
2022-05-15 19:26:52 +00:00
return cid.Undef, fmt.Errorf("flushing vm: %w", err)
}
2022-05-15 19:26:52 +00:00
nst, err := state.LoadStateTree(cst, nh)
if err != nil {
return cid.Undef, xerrors.Errorf("loading new state tree: %w", err)
}
pact, err := nst.GetActor(power.Address)
if err != nil {
return cid.Undef, xerrors.Errorf("getting power actor: %w", err)
}
pst, err := power.Load(adt.WrapStore(ctx, cst), pact)
if err != nil {
return cid.Undef, xerrors.Errorf("getting power state: %w", err)
}
pc, err := pst.TotalPower()
if err != nil {
return cid.Undef, xerrors.Errorf("getting total power: %w", err)
}
if !pc.RawBytePower.Equals(rawPow) {
return cid.Undef, xerrors.Errorf("TotalRawBytePower (%s) doesn't match previously calculated rawPow (%s)", pc.RawBytePower, rawPow)
}
if !pc.QualityAdjPower.Equals(qaPow) {
return cid.Undef, xerrors.Errorf("QualityAdjPower (%s) doesn't match previously calculated qaPow (%s)", pc.QualityAdjPower, qaPow)
}
2020-03-11 07:29:17 +00:00
2020-07-10 05:07:22 +00:00
// TODO: Should we re-ConstructState for the reward actor using rawPow as currRealizedPower here?
2022-05-15 19:26:52 +00:00
c, err := genesisVm.Flush(ctx)
2020-04-21 14:32:17 +00:00
if err != nil {
2020-04-21 21:38:26 +00:00
return cid.Undef, xerrors.Errorf("flushing vm: %w", err)
2020-04-21 14:32:17 +00:00
}
2022-05-15 19:26:52 +00:00
2020-04-21 14:32:17 +00:00
return c, nil
2020-02-11 20:48:03 +00:00
}
2023-09-21 15:37:02 +00:00
var _ lrand.Rand = new(fakeRand)
// TODO: copied from actors test harness, deduplicate or remove from here
type fakeRand struct{}
2023-09-21 15:37:02 +00:00
func (fr *fakeRand) GetChainRandomness(ctx context.Context, randEpoch abi.ChainEpoch) ([32]byte, error) {
2020-08-12 02:47:45 +00:00
out := make([]byte, 32)
2020-08-24 10:51:55 +00:00
_, _ = rand.New(rand.NewSource(int64(randEpoch * 1000))).Read(out) //nolint
2023-09-21 15:37:02 +00:00
return *(*[32]byte)(out), nil
2020-08-12 02:47:45 +00:00
}
2023-09-21 15:37:02 +00:00
func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, randEpoch abi.ChainEpoch) ([32]byte, error) {
out := make([]byte, 32)
2020-08-24 10:51:55 +00:00
_, _ = rand.New(rand.NewSource(int64(randEpoch))).Read(out) //nolint
2023-09-21 15:37:02 +00:00
return *(*[32]byte)(out), nil
}
2022-05-15 19:26:52 +00:00
func currentTotalPower(ctx context.Context, vm vm.Interface, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) {
2020-10-08 01:09:33 +00:00
pwret, err := doExecValue(ctx, vm, power.Address, maddr, big.Zero(), builtin0.MethodsPower.CurrentTotalPower, nil)
if err != nil {
return nil, err
}
var pwr power0.CurrentTotalPowerReturn
if err := pwr.UnmarshalCBOR(bytes.NewReader(pwret)); err != nil {
return nil, err
}
return &pwr, nil
}
2022-09-06 15:49:29 +00:00
func currentEpochBlockReward(ctx context.Context, vm vm.Interface, maddr address.Address, av actorstypes.Version) (abi.StoragePower, builtin.FilterEstimate, error) {
rwret, err := doExecValue(ctx, vm, reward.Address, maddr, big.Zero(), reward.Methods.ThisEpochReward, nil)
if err != nil {
return big.Zero(), builtin.FilterEstimate{}, err
}
// TODO: This hack should move to reward actor wrapper
2021-08-06 10:26:33 +00:00
switch av {
2022-09-06 15:49:29 +00:00
case actorstypes.Version0:
var epochReward reward0.ThisEpochRewardReturn
if err := epochReward.UnmarshalCBOR(bytes.NewReader(rwret)); err != nil {
return big.Zero(), builtin.FilterEstimate{}, err
}
2022-04-20 21:34:28 +00:00
return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(*epochReward.ThisEpochRewardSmoothed), nil
2022-09-06 15:49:29 +00:00
case actorstypes.Version2:
2021-08-06 10:26:33 +00:00
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
if err := epochReward.UnmarshalCBOR(bytes.NewReader(rwret)); err != nil {
return big.Zero(), builtin.FilterEstimate{}, err
}
return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(epochReward.ThisEpochRewardSmoothed), nil
}