From 61fdd9bd0685aa2d4fd2aa6412fd850e81336df5 Mon Sep 17 00:00:00 2001 From: Frrist Date: Tue, 5 Jul 2022 15:51:50 -0700 Subject: [PATCH] Support network version 16 (#988) * deps: update to lotus v0.16.0 * refactor: remove unused actor gen code * chore: update actor code generator for v8 * gen: init actor accessors * gen: market actor accessors * gen: multisig actor accessors * gen: power actor accessors * gen: reward actor accessors * gen verifreg actor accessors * gen: miner actor accessors * chore: update miner state extractors - required due to changes in miner actor gen accessors * chore: update market actor extractors - required for market actor gen accessors * gen: builtin accessors * refactor: remove unused map opts lookup - actor accessors now return map opt values * chore: update message test deps - use v8 actor structs * feat: add actor CID lookups - replace with https://github.com/filecoin-project/lotus/pull/8941 when lotus v1.17.0 is cut * chore: update lens interface to match lotus api - required due to lotus update v1.16.0 * refactor: register new actor code in processor * fix: update parsed message extractor with new exitcode * fix: only init VM for network version prior to 13 - ensures we can process message on FVM upgrade boundary * Add is_string column to market_deal_proposal model (#1015) * chore: add is_string column to market_deal_proposal model * fix: many incorrect pointer equality comparisons (#1018) * fix: many incorrect pointer equality comparisons --- chain/actors/actors.go | 332 ++++++++++ chain/actors/adt/adt.go | 90 +-- chain/actors/agen/generator/gen.go | 10 +- chain/actors/builtin/account/account.go | 102 --- .../actors/builtin/account/actor.go.template | 50 -- .../actors/builtin/account/state.go.template | 31 - chain/actors/builtin/account/v0.go | 31 - chain/actors/builtin/account/v2.go | 31 - chain/actors/builtin/account/v3.go | 31 - chain/actors/builtin/account/v4.go | 31 - chain/actors/builtin/account/v5.go | 31 - chain/actors/builtin/account/v6.go | 31 - chain/actors/builtin/account/v7.go | 31 - chain/actors/builtin/builtin.go | 222 +------ chain/actors/builtin/builtin.go.template | 83 +-- chain/actors/builtin/cron/actor.go.template | 22 - chain/actors/builtin/cron/cron.go | 31 - chain/actors/builtin/init/actor.go.template | 89 ++- chain/actors/builtin/init/diff.go | 31 +- chain/actors/builtin/init/init.go | 141 +++-- chain/actors/builtin/init/state.go.template | 111 +++- chain/actors/builtin/init/v0.go | 75 ++- chain/actors/builtin/init/v2.go | 75 ++- chain/actors/builtin/init/v3.go | 74 ++- chain/actors/builtin/init/v4.go | 74 ++- chain/actors/builtin/init/v5.go | 74 ++- chain/actors/builtin/init/v6.go | 74 ++- chain/actors/builtin/init/v7.go | 74 ++- chain/actors/builtin/init/v8.go | 151 +++++ chain/actors/builtin/market/actor.go.template | 166 +++-- chain/actors/builtin/market/market.go | 177 ++---- chain/actors/builtin/market/state.go.template | 173 ++--- chain/actors/builtin/market/v0.go | 152 ++--- chain/actors/builtin/market/v2.go | 152 ++--- chain/actors/builtin/market/v3.go | 147 ++--- chain/actors/builtin/market/v4.go | 147 ++--- chain/actors/builtin/market/v5.go | 147 ++--- chain/actors/builtin/market/v6.go | 147 ++--- chain/actors/builtin/market/v7.go | 147 ++--- chain/actors/builtin/market/v8.go | 224 +++++++ chain/actors/builtin/miner/actor.go.template | 224 +++---- chain/actors/builtin/miner/diff.go | 34 +- chain/actors/builtin/miner/miner.go | 268 ++++---- chain/actors/builtin/miner/mocks/state.go | 158 +++-- chain/actors/builtin/miner/state.go.template | 131 ++-- chain/actors/builtin/miner/utils.go | 69 -- chain/actors/builtin/miner/v0.go | 103 +-- chain/actors/builtin/miner/v2.go | 99 +-- chain/actors/builtin/miner/v3.go | 98 +-- chain/actors/builtin/miner/v4.go | 98 +-- chain/actors/builtin/miner/v5.go | 98 +-- chain/actors/builtin/miner/v6.go | 98 +-- chain/actors/builtin/miner/v7.go | 98 +-- chain/actors/builtin/miner/v8.go | 597 ++++++++++++++++++ .../actors/builtin/multisig/actor.go.template | 87 ++- chain/actors/builtin/multisig/diff.go | 29 +- .../builtin/multisig/message.go.template | 148 ----- chain/actors/builtin/multisig/message0.go | 144 ----- chain/actors/builtin/multisig/message2.go | 73 --- chain/actors/builtin/multisig/message3.go | 73 --- chain/actors/builtin/multisig/message4.go | 73 --- chain/actors/builtin/multisig/message5.go | 73 --- chain/actors/builtin/multisig/message6.go | 73 --- chain/actors/builtin/multisig/message7.go | 73 --- chain/actors/builtin/multisig/multisig.go | 149 ++--- .../actors/builtin/multisig/state.go.template | 60 +- chain/actors/builtin/multisig/v0.go | 42 +- chain/actors/builtin/multisig/v2.go | 42 +- chain/actors/builtin/multisig/v3.go | 41 +- chain/actors/builtin/multisig/v4.go | 41 +- chain/actors/builtin/multisig/v5.go | 41 +- chain/actors/builtin/multisig/v6.go | 41 +- chain/actors/builtin/multisig/v7.go | 41 +- chain/actors/builtin/multisig/v8.go | 131 ++++ chain/actors/builtin/paych/actor.go.template | 140 ---- .../actors/builtin/paych/message.go.template | 81 --- chain/actors/builtin/paych/message0.go | 78 --- chain/actors/builtin/paych/message2.go | 78 --- chain/actors/builtin/paych/message3.go | 78 --- chain/actors/builtin/paych/message4.go | 78 --- chain/actors/builtin/paych/message5.go | 78 --- chain/actors/builtin/paych/message6.go | 78 --- chain/actors/builtin/paych/message7.go | 78 --- chain/actors/builtin/paych/mock/mock.go | 92 --- chain/actors/builtin/paych/paych.go | 245 ------- chain/actors/builtin/paych/state.go.template | 134 ---- chain/actors/builtin/paych/v0.go | 115 ---- chain/actors/builtin/paych/v2.go | 115 ---- chain/actors/builtin/paych/v3.go | 115 ---- chain/actors/builtin/paych/v4.go | 115 ---- chain/actors/builtin/paych/v5.go | 115 ---- chain/actors/builtin/paych/v6.go | 115 ---- chain/actors/builtin/paych/v7.go | 131 ---- chain/actors/builtin/power/actor.go.template | 61 +- chain/actors/builtin/power/diff.go | 32 +- chain/actors/builtin/power/power.go | 93 +-- chain/actors/builtin/power/state.go.template | 70 +- chain/actors/builtin/power/v0.go | 49 +- chain/actors/builtin/power/v2.go | 49 +- chain/actors/builtin/power/v3.go | 48 +- chain/actors/builtin/power/v4.go | 48 +- chain/actors/builtin/power/v5.go | 48 +- chain/actors/builtin/power/v6.go | 48 +- chain/actors/builtin/power/v7.go | 48 +- chain/actors/builtin/power/v8.go | 186 ++++++ chain/actors/builtin/reward/actor.go.template | 58 +- chain/actors/builtin/reward/reward.go | 91 +-- chain/actors/builtin/reward/state.go.template | 20 + chain/actors/builtin/reward/v0.go | 20 + chain/actors/builtin/reward/v2.go | 20 + chain/actors/builtin/reward/v3.go | 20 + chain/actors/builtin/reward/v4.go | 20 + chain/actors/builtin/reward/v5.go | 20 + chain/actors/builtin/reward/v6.go | 20 + chain/actors/builtin/reward/v7.go | 20 + chain/actors/builtin/reward/v8.go | 109 ++++ .../actors/builtin/verifreg/actor.go.template | 66 +- chain/actors/builtin/verifreg/diff.go | 44 +- .../actors/builtin/verifreg/state.go.template | 96 ++- chain/actors/builtin/verifreg/util.go | 1 + chain/actors/builtin/verifreg/v0.go | 68 +- chain/actors/builtin/verifreg/v2.go | 68 +- chain/actors/builtin/verifreg/v3.go | 67 +- chain/actors/builtin/verifreg/v4.go | 67 +- chain/actors/builtin/verifreg/v5.go | 67 +- chain/actors/builtin/verifreg/v6.go | 67 +- chain/actors/builtin/verifreg/v7.go | 67 +- chain/actors/builtin/verifreg/v8.go | 110 ++++ chain/actors/builtin/verifreg/verifreg.go | 99 +-- chain/actors/policy/policy.go | 439 ------------- chain/actors/policy/policy.go.template | 240 ------- chain/actors/policy/policy_test.go | 70 -- chain/actors/version.go | 39 -- chain/indexer/integrated/processor/state.go | 148 ++--- .../processor/state_internal_test.go | 25 +- .../integrated/processor/state_test.go | 23 +- extern/filecoin-ffi | 2 +- go.mod | 38 +- go.sum | 88 ++- lens/interface.go | 2 +- lens/lily/impl.go | 1 + lens/util/repo.go | 91 +-- model/actors/market/dealproposal.go | 6 +- schemas/v1/7_market_proposal_label.go | 13 + tasks/actorstate/market/context.go | 3 + tasks/actorstate/market/deal_proposal.go | 95 +-- tasks/actorstate/miner/context.go | 61 +- tasks/actorstate/miner/deadline_info.go | 8 +- tasks/actorstate/miner/fee_debt.go | 2 +- tasks/actorstate/miner/info.go | 18 +- tasks/actorstate/miner/locked_funds.go | 6 +- tasks/actorstate/miner/post.go | 3 +- tasks/actorstate/miner/precommit.go | 6 +- tasks/actorstate/miner/sector_events.go | 3 +- tasks/actorstate/miner/sector_events_test.go | 13 +- tasks/actorstate/multisig/multisig.go | 54 +- tasks/actorstate/power/power.go | 50 +- tasks/actorstate/verifreg/verifreg.go | 54 +- tasks/messages/message_test.go | 21 +- tasks/messages/parsedmessage/task.go | 11 +- 160 files changed, 6411 insertions(+), 7026 deletions(-) create mode 100644 chain/actors/actors.go delete mode 100644 chain/actors/builtin/account/account.go delete mode 100644 chain/actors/builtin/account/actor.go.template delete mode 100644 chain/actors/builtin/account/state.go.template delete mode 100644 chain/actors/builtin/account/v0.go delete mode 100644 chain/actors/builtin/account/v2.go delete mode 100644 chain/actors/builtin/account/v3.go delete mode 100644 chain/actors/builtin/account/v4.go delete mode 100644 chain/actors/builtin/account/v5.go delete mode 100644 chain/actors/builtin/account/v6.go delete mode 100644 chain/actors/builtin/account/v7.go delete mode 100644 chain/actors/builtin/cron/actor.go.template delete mode 100644 chain/actors/builtin/cron/cron.go create mode 100644 chain/actors/builtin/init/v8.go create mode 100644 chain/actors/builtin/market/v8.go delete mode 100644 chain/actors/builtin/miner/utils.go create mode 100644 chain/actors/builtin/miner/v8.go delete mode 100644 chain/actors/builtin/multisig/message.go.template delete mode 100644 chain/actors/builtin/multisig/message0.go delete mode 100644 chain/actors/builtin/multisig/message2.go delete mode 100644 chain/actors/builtin/multisig/message3.go delete mode 100644 chain/actors/builtin/multisig/message4.go delete mode 100644 chain/actors/builtin/multisig/message5.go delete mode 100644 chain/actors/builtin/multisig/message6.go delete mode 100644 chain/actors/builtin/multisig/message7.go create mode 100644 chain/actors/builtin/multisig/v8.go delete mode 100644 chain/actors/builtin/paych/actor.go.template delete mode 100644 chain/actors/builtin/paych/message.go.template delete mode 100644 chain/actors/builtin/paych/message0.go delete mode 100644 chain/actors/builtin/paych/message2.go delete mode 100644 chain/actors/builtin/paych/message3.go delete mode 100644 chain/actors/builtin/paych/message4.go delete mode 100644 chain/actors/builtin/paych/message5.go delete mode 100644 chain/actors/builtin/paych/message6.go delete mode 100644 chain/actors/builtin/paych/message7.go delete mode 100644 chain/actors/builtin/paych/mock/mock.go delete mode 100644 chain/actors/builtin/paych/paych.go delete mode 100644 chain/actors/builtin/paych/state.go.template delete mode 100644 chain/actors/builtin/paych/v0.go delete mode 100644 chain/actors/builtin/paych/v2.go delete mode 100644 chain/actors/builtin/paych/v3.go delete mode 100644 chain/actors/builtin/paych/v4.go delete mode 100644 chain/actors/builtin/paych/v5.go delete mode 100644 chain/actors/builtin/paych/v6.go delete mode 100644 chain/actors/builtin/paych/v7.go create mode 100644 chain/actors/builtin/power/v8.go create mode 100644 chain/actors/builtin/reward/v8.go create mode 100644 chain/actors/builtin/verifreg/v8.go delete mode 100644 chain/actors/policy/policy.go delete mode 100644 chain/actors/policy/policy.go.template delete mode 100644 chain/actors/policy/policy_test.go delete mode 100644 chain/actors/version.go create mode 100644 schemas/v1/7_market_proposal_label.go diff --git a/chain/actors/actors.go b/chain/actors/actors.go new file mode 100644 index 000000000..780945be8 --- /dev/null +++ b/chain/actors/actors.go @@ -0,0 +1,332 @@ +package actors + +import ( + "github.com/filecoin-project/lotus/chain/actors" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" + builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" + builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" + builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + "github.com/ipfs/go-cid" +) + +type Version int + +var LatestVersion = 8 + +var Versions = []int{0, 2, 3, 4, 5, 6, 7, 8} + +const ( + Version0 Version = 0 + Version2 Version = 2 + Version3 Version = 3 + Version4 Version = 4 + Version5 Version = 5 + Version6 Version = 6 + Version7 Version = 7 + Version8 Version = 8 +) +const ( + AccountKey = "account" + CronKey = "cron" + InitKey = "init" + MarketKey = "storagemarket" + MinerKey = "storageminer" + MultisigKey = "multisig" + PaychKey = "paymentchannel" + PowerKey = "storagepower" + RewardKey = "reward" + SystemKey = "system" + VerifregKey = "verifiedregistry" +) + +// GetActorCodeID looks up a builtin actor's code CID by actor version and canonical actor name. +func GetActorCodeID(av Version, name string) (cid.Cid, bool) { + // Actors V8 and above + if c, ok := actors.GetActorCodeID(actors.Version(av), name); ok { + return c, true + } + + // Actors V7 and lower + switch name { + + case AccountKey: + switch av { + + case Version0: + return builtin0.AccountActorCodeID, true + + case Version2: + return builtin2.AccountActorCodeID, true + + case Version3: + return builtin3.AccountActorCodeID, true + + case Version4: + return builtin4.AccountActorCodeID, true + + case Version5: + return builtin5.AccountActorCodeID, true + + case Version6: + return builtin6.AccountActorCodeID, true + + case Version7: + return builtin7.AccountActorCodeID, true + } + + case CronKey: + switch av { + + case Version0: + return builtin0.CronActorCodeID, true + + case Version2: + return builtin2.CronActorCodeID, true + + case Version3: + return builtin3.CronActorCodeID, true + + case Version4: + return builtin4.CronActorCodeID, true + + case Version5: + return builtin5.CronActorCodeID, true + + case Version6: + return builtin6.CronActorCodeID, true + + case Version7: + return builtin7.CronActorCodeID, true + } + + case InitKey: + switch av { + + case Version0: + return builtin0.InitActorCodeID, true + + case Version2: + return builtin2.InitActorCodeID, true + + case Version3: + return builtin3.InitActorCodeID, true + + case Version4: + return builtin4.InitActorCodeID, true + + case Version5: + return builtin5.InitActorCodeID, true + + case Version6: + return builtin6.InitActorCodeID, true + + case Version7: + return builtin7.InitActorCodeID, true + } + + case MarketKey: + switch av { + + case Version0: + return builtin0.StorageMarketActorCodeID, true + + case Version2: + return builtin2.StorageMarketActorCodeID, true + + case Version3: + return builtin3.StorageMarketActorCodeID, true + + case Version4: + return builtin4.StorageMarketActorCodeID, true + + case Version5: + return builtin5.StorageMarketActorCodeID, true + + case Version6: + return builtin6.StorageMarketActorCodeID, true + + case Version7: + return builtin7.StorageMarketActorCodeID, true + } + + case MinerKey: + switch av { + + case Version0: + return builtin0.StorageMinerActorCodeID, true + + case Version2: + return builtin2.StorageMinerActorCodeID, true + + case Version3: + return builtin3.StorageMinerActorCodeID, true + + case Version4: + return builtin4.StorageMinerActorCodeID, true + + case Version5: + return builtin5.StorageMinerActorCodeID, true + + case Version6: + return builtin6.StorageMinerActorCodeID, true + + case Version7: + return builtin7.StorageMinerActorCodeID, true + } + + case MultisigKey: + switch av { + + case Version0: + return builtin0.MultisigActorCodeID, true + + case Version2: + return builtin2.MultisigActorCodeID, true + + case Version3: + return builtin3.MultisigActorCodeID, true + + case Version4: + return builtin4.MultisigActorCodeID, true + + case Version5: + return builtin5.MultisigActorCodeID, true + + case Version6: + return builtin6.MultisigActorCodeID, true + + case Version7: + return builtin7.MultisigActorCodeID, true + } + + case PaychKey: + switch av { + + case Version0: + return builtin0.PaymentChannelActorCodeID, true + + case Version2: + return builtin2.PaymentChannelActorCodeID, true + + case Version3: + return builtin3.PaymentChannelActorCodeID, true + + case Version4: + return builtin4.PaymentChannelActorCodeID, true + + case Version5: + return builtin5.PaymentChannelActorCodeID, true + + case Version6: + return builtin6.PaymentChannelActorCodeID, true + + case Version7: + return builtin7.PaymentChannelActorCodeID, true + } + + case PowerKey: + switch av { + + case Version0: + return builtin0.StoragePowerActorCodeID, true + + case Version2: + return builtin2.StoragePowerActorCodeID, true + + case Version3: + return builtin3.StoragePowerActorCodeID, true + + case Version4: + return builtin4.StoragePowerActorCodeID, true + + case Version5: + return builtin5.StoragePowerActorCodeID, true + + case Version6: + return builtin6.StoragePowerActorCodeID, true + + case Version7: + return builtin7.StoragePowerActorCodeID, true + } + + case RewardKey: + switch av { + + case Version0: + return builtin0.RewardActorCodeID, true + + case Version2: + return builtin2.RewardActorCodeID, true + + case Version3: + return builtin3.RewardActorCodeID, true + + case Version4: + return builtin4.RewardActorCodeID, true + + case Version5: + return builtin5.RewardActorCodeID, true + + case Version6: + return builtin6.RewardActorCodeID, true + + case Version7: + return builtin7.RewardActorCodeID, true + } + + case SystemKey: + switch av { + + case Version0: + return builtin0.SystemActorCodeID, true + + case Version2: + return builtin2.SystemActorCodeID, true + + case Version3: + return builtin3.SystemActorCodeID, true + + case Version4: + return builtin4.SystemActorCodeID, true + + case Version5: + return builtin5.SystemActorCodeID, true + + case Version6: + return builtin6.SystemActorCodeID, true + + case Version7: + return builtin7.SystemActorCodeID, true + } + + case VerifregKey: + switch av { + + case Version0: + return builtin0.VerifiedRegistryActorCodeID, true + + case Version2: + return builtin2.VerifiedRegistryActorCodeID, true + + case Version3: + return builtin3.VerifiedRegistryActorCodeID, true + + case Version4: + return builtin4.VerifiedRegistryActorCodeID, true + + case Version5: + return builtin5.VerifiedRegistryActorCodeID, true + + case Version6: + return builtin6.VerifiedRegistryActorCodeID, true + + case Version7: + return builtin7.VerifiedRegistryActorCodeID, true + } + } + + return cid.Undef, false +} diff --git a/chain/actors/adt/adt.go b/chain/actors/adt/adt.go index f9de39996..b128a0420 100644 --- a/chain/actors/adt/adt.go +++ b/chain/actors/adt/adt.go @@ -2,22 +2,10 @@ package adt import ( "bytes" - "crypto/sha256" - "fmt" - - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - "github.com/ipfs/go-cid" - sha256simd "github.com/minio/sha256-simd" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "github.com/ipfs/go-cid" ) type Map interface { @@ -41,6 +29,8 @@ type Array interface { ForEach(v cbor.Unmarshaler, fn func(idx int64) error) error } +type MapHashFunc func([]byte) []byte + type MapOpts struct { Bitwidth int HashFunc MapHashFunc @@ -57,77 +47,3 @@ func (m *MapOpts) Equal(o *MapOpts) bool { return true } - -func MapOptsForActorCode(c cid.Cid) (*MapOpts, error) { - switch c { - // v0 - // https://github.com/filecoin-project/specs-actors/blob/v0.9.14/actors/util/adt/map.go#L22 - case builtin0.InitActorCodeID, builtin0.StorageMarketActorCodeID, builtin0.StorageMinerActorCodeID, builtin0.MultisigActorCodeID, builtin0.StoragePowerActorCodeID, builtin0.VerifiedRegistryActorCodeID: - return &MapOpts{ - Bitwidth: 5, - HashFunc: Map0ShaHashFunc, - }, nil - - // v2 - // https://github.com/filecoin-project/specs-actors/blob/v2.3.5/actors/util/adt/map.go#L22 - case builtin2.InitActorCodeID, builtin2.StorageMarketActorCodeID, builtin2.StorageMinerActorCodeID, builtin2.MultisigActorCodeID, builtin2.StoragePowerActorCodeID, builtin2.VerifiedRegistryActorCodeID: - return &MapOpts{ - Bitwidth: 5, - HashFunc: Map2ShaHashFunc, - }, nil - - // v3 - // https://github.com/filecoin-project/specs-actors/blob/v3.1.1/actors/util/adt/map.go - case builtin3.InitActorCodeID, builtin3.StorageMarketActorCodeID, builtin3.StorageMinerActorCodeID, builtin3.MultisigActorCodeID, builtin3.StoragePowerActorCodeID, builtin3.VerifiedRegistryActorCodeID: - return &MapOpts{ - Bitwidth: builtin3.DefaultHamtBitwidth, - HashFunc: Map2ShaHashFunc, - }, nil - - // v4 - // https://github.com/filecoin-project/specs-actors/blob/v4.0.1/actors/util/adt/map.go#L17 - case builtin4.InitActorCodeID, builtin4.StorageMarketActorCodeID, builtin4.StorageMinerActorCodeID, builtin4.MultisigActorCodeID, builtin4.StoragePowerActorCodeID, builtin4.VerifiedRegistryActorCodeID: - return &MapOpts{ - Bitwidth: builtin4.DefaultHamtBitwidth, - HashFunc: Map2ShaHashFunc, - }, nil - - // v5 - // https://github.com/filecoin-project/specs-actors/blob/v5-rc-3/actors/util/adt/map.go#L17 - case builtin5.InitActorCodeID, builtin5.StorageMarketActorCodeID, builtin5.StorageMinerActorCodeID, builtin5.MultisigActorCodeID, builtin5.StoragePowerActorCodeID, builtin5.VerifiedRegistryActorCodeID: - return &MapOpts{ - Bitwidth: builtin5.DefaultHamtBitwidth, - HashFunc: Map2ShaHashFunc, - }, nil - - // v6 - // https://github.com/filecoin-project/specs-actors/blob/v6/actors/util/adt/map.go#L17 - case builtin6.InitActorCodeID, builtin6.StorageMarketActorCodeID, builtin6.StorageMinerActorCodeID, builtin6.MultisigActorCodeID, builtin6.StoragePowerActorCodeID, builtin6.VerifiedRegistryActorCodeID: - return &MapOpts{ - Bitwidth: builtin6.DefaultHamtBitwidth, - HashFunc: Map2ShaHashFunc, - }, nil - - // v7 - // https://github.com/filecoin-project/specs-actors/blob/v7/actors/util/adt/map.go#L17 - case builtin7.InitActorCodeID, builtin7.StorageMarketActorCodeID, builtin7.StorageMinerActorCodeID, builtin7.MultisigActorCodeID, builtin7.StoragePowerActorCodeID, builtin7.VerifiedRegistryActorCodeID: - return &MapOpts{ - Bitwidth: builtin7.DefaultHamtBitwidth, - HashFunc: Map2ShaHashFunc, - }, nil - } - - return nil, fmt.Errorf("actor code unknown or doesn't have Map: %s", c) -} - -type MapHashFunc func([]byte) []byte - -var Map0ShaHashFunc MapHashFunc = func(input []byte) []byte { - res := sha256simd.Sum256(input) - return res[:] -} - -var Map2ShaHashFunc MapHashFunc = func(input []byte) []byte { - res := sha256.Sum256(input) - return res[:] -} diff --git a/chain/actors/agen/generator/gen.go b/chain/actors/agen/generator/gen.go index ee0de1527..abc06679a 100644 --- a/chain/actors/agen/generator/gen.go +++ b/chain/actors/agen/generator/gen.go @@ -9,9 +9,9 @@ import ( "text/template" ) -var latestVersion = 7 +var latestVersion = 8 -var versions = []int{0, 2, 3, 4, 5, 6, latestVersion} +var versions = []int{0, 2, 3, 4, 5, 6, 7, latestVersion} var versionImports = map[int]string{ 0: "/", @@ -20,17 +20,15 @@ var versionImports = map[int]string{ 4: "/v4/", 5: "/v5/", 6: "/v6/", - latestVersion: "/v7/", + 7: "/v7/", + latestVersion: "/v8/", } var actors = map[string][]int{ - "account": versions, - "cron": versions, "init": versions, "market": versions, "miner": versions, "multisig": versions, - "paych": versions, "power": versions, "reward": versions, "verifreg": versions, diff --git a/chain/actors/builtin/account/account.go b/chain/actors/builtin/account/account.go deleted file mode 100644 index 6e757122c..000000000 --- a/chain/actors/builtin/account/account.go +++ /dev/null @@ -1,102 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/cbor" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" - - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" -) - -func init() { - - builtin.RegisterActorState(builtin0.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) - - builtin.RegisterActorState(builtin3.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) - - builtin.RegisterActorState(builtin5.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) - - builtin.RegisterActorState(builtin6.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) - - builtin.RegisterActorState(builtin7.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} - -var Methods = builtin4.MethodsAccount - -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.AccountActorCodeID, - builtin2.AccountActorCodeID, - builtin3.AccountActorCodeID, - builtin4.AccountActorCodeID, - builtin5.AccountActorCodeID, - builtin6.AccountActorCodeID, - builtin7.AccountActorCodeID, - } -} - -func Load(store adt.Store, act *types.Actor) (State, error) { - switch act.Code { - - case builtin0.AccountActorCodeID: - return load0(store, act.Head) - - case builtin2.AccountActorCodeID: - return load2(store, act.Head) - - case builtin3.AccountActorCodeID: - return load3(store, act.Head) - - case builtin4.AccountActorCodeID: - return load4(store, act.Head) - - case builtin5.AccountActorCodeID: - return load5(store, act.Head) - - case builtin6.AccountActorCodeID: - return load6(store, act.Head) - - case builtin7.AccountActorCodeID: - return load7(store, act.Head) - - } - return nil, fmt.Errorf("unknown actor code %s", act.Code) -} - -type State interface { - cbor.Marshaler - - PubkeyAddress() (address.Address, error) -} diff --git a/chain/actors/builtin/account/actor.go.template b/chain/actors/builtin/account/actor.go.template deleted file mode 100644 index b422e5071..000000000 --- a/chain/actors/builtin/account/actor.go.template +++ /dev/null @@ -1,50 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/cbor" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" -{{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" -{{- end}} -) - -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} - -var Methods = builtin4.MethodsAccount - -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.AccountActorCodeID, - {{- end}} - } -} - -func Load(store adt.Store, act *types.Actor) (State, error) { - switch act.Code { -{{range .versions}} - case builtin{{.}}.AccountActorCodeID: - return load{{.}}(store, act.Head) -{{end}} - } - return nil, fmt.Errorf("unknown actor code %s", act.Code) -} - -type State interface { - cbor.Marshaler - - PubkeyAddress() (address.Address, error) -} diff --git a/chain/actors/builtin/account/state.go.template b/chain/actors/builtin/account/state.go.template deleted file mode 100644 index dd2fb06eb..000000000 --- a/chain/actors/builtin/account/state.go.template +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "github.com/filecoin-project/go-address" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lily/chain/actors/adt" - - account{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/account" -) - -var _ State = (*state{{.v}})(nil) - -func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { - out := state{{.v}}{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -type state{{.v}} struct { - account{{.v}}.State - store adt.Store -} - -func (s *state{{.v}}) PubkeyAddress() (address.Address, error) { - return s.Address, nil -} diff --git a/chain/actors/builtin/account/v0.go b/chain/actors/builtin/account/v0.go deleted file mode 100644 index e3c80ebe1..000000000 --- a/chain/actors/builtin/account/v0.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "github.com/filecoin-project/go-address" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lily/chain/actors/adt" - - account0 "github.com/filecoin-project/specs-actors/actors/builtin/account" -) - -var _ State = (*state0)(nil) - -func load0(store adt.Store, root cid.Cid) (State, error) { - out := state0{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -type state0 struct { - account0.State - store adt.Store -} - -func (s *state0) PubkeyAddress() (address.Address, error) { - return s.Address, nil -} diff --git a/chain/actors/builtin/account/v2.go b/chain/actors/builtin/account/v2.go deleted file mode 100644 index 3bce52d95..000000000 --- a/chain/actors/builtin/account/v2.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "github.com/filecoin-project/go-address" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lily/chain/actors/adt" - - account2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/account" -) - -var _ State = (*state2)(nil) - -func load2(store adt.Store, root cid.Cid) (State, error) { - out := state2{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -type state2 struct { - account2.State - store adt.Store -} - -func (s *state2) PubkeyAddress() (address.Address, error) { - return s.Address, nil -} diff --git a/chain/actors/builtin/account/v3.go b/chain/actors/builtin/account/v3.go deleted file mode 100644 index 9e7140fc6..000000000 --- a/chain/actors/builtin/account/v3.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "github.com/filecoin-project/go-address" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lily/chain/actors/adt" - - account3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/account" -) - -var _ State = (*state3)(nil) - -func load3(store adt.Store, root cid.Cid) (State, error) { - out := state3{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -type state3 struct { - account3.State - store adt.Store -} - -func (s *state3) PubkeyAddress() (address.Address, error) { - return s.Address, nil -} diff --git a/chain/actors/builtin/account/v4.go b/chain/actors/builtin/account/v4.go deleted file mode 100644 index e62f9b332..000000000 --- a/chain/actors/builtin/account/v4.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "github.com/filecoin-project/go-address" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lily/chain/actors/adt" - - account4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/account" -) - -var _ State = (*state4)(nil) - -func load4(store adt.Store, root cid.Cid) (State, error) { - out := state4{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -type state4 struct { - account4.State - store adt.Store -} - -func (s *state4) PubkeyAddress() (address.Address, error) { - return s.Address, nil -} diff --git a/chain/actors/builtin/account/v5.go b/chain/actors/builtin/account/v5.go deleted file mode 100644 index 27bf059f8..000000000 --- a/chain/actors/builtin/account/v5.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "github.com/filecoin-project/go-address" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lily/chain/actors/adt" - - account5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/account" -) - -var _ State = (*state5)(nil) - -func load5(store adt.Store, root cid.Cid) (State, error) { - out := state5{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -type state5 struct { - account5.State - store adt.Store -} - -func (s *state5) PubkeyAddress() (address.Address, error) { - return s.Address, nil -} diff --git a/chain/actors/builtin/account/v6.go b/chain/actors/builtin/account/v6.go deleted file mode 100644 index cfaf2b2f4..000000000 --- a/chain/actors/builtin/account/v6.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "github.com/filecoin-project/go-address" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lily/chain/actors/adt" - - account6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/account" -) - -var _ State = (*state6)(nil) - -func load6(store adt.Store, root cid.Cid) (State, error) { - out := state6{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -type state6 struct { - account6.State - store adt.Store -} - -func (s *state6) PubkeyAddress() (address.Address, error) { - return s.Address, nil -} diff --git a/chain/actors/builtin/account/v7.go b/chain/actors/builtin/account/v7.go deleted file mode 100644 index 86ce47551..000000000 --- a/chain/actors/builtin/account/v7.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package account - -import ( - "github.com/filecoin-project/go-address" - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/lily/chain/actors/adt" - - account7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/account" -) - -var _ State = (*state7)(nil) - -func load7(store adt.Store, root cid.Cid) (State, error) { - out := state7{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -type state7 struct { - account7.State - store adt.Store -} - -func (s *state7) PubkeyAddress() (address.Address, error) { - return s.Address, nil -} diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index 0836160e4..991390225 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -29,48 +29,30 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" smoothing7 "github.com/filecoin-project/specs-actors/v7/actors/util/smoothing" + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" + smoothing8 "github.com/filecoin-project/specs-actors/v8/actors/util/smoothing" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - - "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" - proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" -) - -var SystemActorAddr = builtin7.SystemActorAddr -var BurntFundsActorAddr = builtin7.BurntFundsActorAddr -var CronActorAddr = builtin7.CronActorAddr -var SaftAddress = makeAddress("t0122") -var ReserveAddress = makeAddress("t090") -var RootVerifierAddress = makeAddress("t080") - -var ( - ExpectedLeadersPerEpoch = builtin7.ExpectedLeadersPerEpoch + miner8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/miner" + proof8 "github.com/filecoin-project/specs-actors/v8/actors/runtime/proof" ) const ( - EpochDurationSeconds = builtin7.EpochDurationSeconds - EpochsInDay = builtin7.EpochsInDay - SecondsInDay = builtin7.SecondsInDay -) - -const ( - MethodSend = builtin7.MethodSend - MethodConstructor = builtin7.MethodConstructor + EpochDurationSeconds = builtin8.EpochDurationSeconds ) // These are all just type aliases across actor versions. In the future, that might change // and we might need to do something fancier. -type SectorInfo = proof7.SectorInfo -type ExtendedSectorInfo = proof7.ExtendedSectorInfo -type PoStProof = proof7.PoStProof +type PoStProof = proof8.PoStProof type FilterEstimate = smoothing0.FilterEstimate func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower { - return miner7.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) + return miner8.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) } func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate { @@ -115,23 +97,19 @@ func FromV7FilterEstimate(v7 smoothing7.FilterEstimate) FilterEstimate { } -type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) +func FromV8FilterEstimate(v8 smoothing8.FilterEstimate) FilterEstimate { -var ActorStateLoaders = make(map[cid.Cid]ActorStateLoader) + return (FilterEstimate)(v8) -func RegisterActorState(code cid.Cid, loader ActorStateLoader) { - ActorStateLoaders[code] = loader } -func Load(store adt.Store, act *types.Actor) (cbor.Marshaler, error) { - loader, found := ActorStateLoaders[act.Code] - if !found { - return nil, fmt.Errorf("unknown actor code %s", act.Code) - } - return loader(store, act.Head) -} +type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) func ActorNameByCode(c cid.Cid) string { + if name, version, ok := actors.GetActorMetaByCode(c); ok { + return fmt.Sprintf("fil/%d/%s", version, name) + } + switch { case builtin0.IsBuiltinActor(c): @@ -155,6 +133,9 @@ func ActorNameByCode(c cid.Cid) string { case builtin7.IsBuiltinActor(c): return builtin7.ActorNameByCode(c) + case builtin8.IsBuiltinActor(c): + return builtin8.ActorNameByCode(c) + default: return "" } @@ -176,171 +157,6 @@ func ActorFamily(name string) string { return name[idx+1:] } -func IsBuiltinActor(c cid.Cid) bool { - - if builtin0.IsBuiltinActor(c) { - return true - } - - if builtin2.IsBuiltinActor(c) { - return true - } - - if builtin3.IsBuiltinActor(c) { - return true - } - - if builtin4.IsBuiltinActor(c) { - return true - } - - if builtin5.IsBuiltinActor(c) { - return true - } - - if builtin6.IsBuiltinActor(c) { - return true - } - - if builtin7.IsBuiltinActor(c) { - return true - } - - return false -} - -func IsAccountActor(c cid.Cid) bool { - - if c == builtin0.AccountActorCodeID { - return true - } - - if c == builtin2.AccountActorCodeID { - return true - } - - if c == builtin3.AccountActorCodeID { - return true - } - - if c == builtin4.AccountActorCodeID { - return true - } - - if c == builtin5.AccountActorCodeID { - return true - } - - if c == builtin6.AccountActorCodeID { - return true - } - - if c == builtin7.AccountActorCodeID { - return true - } - - return false -} - -func IsStorageMinerActor(c cid.Cid) bool { - - if c == builtin0.StorageMinerActorCodeID { - return true - } - - if c == builtin2.StorageMinerActorCodeID { - return true - } - - if c == builtin3.StorageMinerActorCodeID { - return true - } - - if c == builtin4.StorageMinerActorCodeID { - return true - } - - if c == builtin5.StorageMinerActorCodeID { - return true - } - - if c == builtin6.StorageMinerActorCodeID { - return true - } - - if c == builtin7.StorageMinerActorCodeID { - return true - } - - return false -} - -func IsMultisigActor(c cid.Cid) bool { - - if c == builtin0.MultisigActorCodeID { - return true - } - - if c == builtin2.MultisigActorCodeID { - return true - } - - if c == builtin3.MultisigActorCodeID { - return true - } - - if c == builtin4.MultisigActorCodeID { - return true - } - - if c == builtin5.MultisigActorCodeID { - return true - } - - if c == builtin6.MultisigActorCodeID { - return true - } - - if c == builtin7.MultisigActorCodeID { - return true - } - - return false -} - -func IsPaymentChannelActor(c cid.Cid) bool { - - if c == builtin0.PaymentChannelActorCodeID { - return true - } - - if c == builtin2.PaymentChannelActorCodeID { - return true - } - - if c == builtin3.PaymentChannelActorCodeID { - return true - } - - if c == builtin4.PaymentChannelActorCodeID { - return true - } - - if c == builtin5.PaymentChannelActorCodeID { - return true - } - - if c == builtin6.PaymentChannelActorCodeID { - return true - } - - if c == builtin7.PaymentChannelActorCodeID { - return true - } - - return false -} - func makeAddress(addr string) address.Address { ret, err := address.NewFromString(addr) if err != nil { diff --git a/chain/actors/builtin/builtin.go.template b/chain/actors/builtin/builtin.go.template index b8836e782..87aff6a72 100644 --- a/chain/actors/builtin/builtin.go.template +++ b/chain/actors/builtin/builtin.go.template @@ -13,10 +13,10 @@ import ( smoothing{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/util/smoothing" {{end}} + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" - "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lily/chain/actors/adt" @@ -24,32 +24,13 @@ import ( proof{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/runtime/proof" ) -var SystemActorAddr = builtin{{.latestVersion}}.SystemActorAddr -var BurntFundsActorAddr = builtin{{.latestVersion}}.BurntFundsActorAddr -var CronActorAddr = builtin{{.latestVersion}}.CronActorAddr -var SaftAddress = makeAddress("t0122") -var ReserveAddress = makeAddress("t090") -var RootVerifierAddress = makeAddress("t080") - -var ( - ExpectedLeadersPerEpoch = builtin{{.latestVersion}}.ExpectedLeadersPerEpoch -) - const ( EpochDurationSeconds = builtin{{.latestVersion}}.EpochDurationSeconds - EpochsInDay = builtin{{.latestVersion}}.EpochsInDay - SecondsInDay = builtin{{.latestVersion}}.SecondsInDay ) -const ( - MethodSend = builtin{{.latestVersion}}.MethodSend - MethodConstructor = builtin{{.latestVersion}}.MethodConstructor -) // These are all just type aliases across actor versions. In the future, that might change // and we might need to do something fancier. -type SectorInfo = proof{{.latestVersion}}.SectorInfo -type ExtendedSectorInfo = proof{{.latestVersion}}.ExtendedSectorInfo type PoStProof = proof{{.latestVersion}}.PoStProof type FilterEstimate = smoothing0.FilterEstimate @@ -69,23 +50,13 @@ func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) -var ActorStateLoaders = make(map[cid.Cid]ActorStateLoader) - -func RegisterActorState(code cid.Cid, loader ActorStateLoader) { - ActorStateLoaders[code] = loader -} - -func Load(store adt.Store, act *types.Actor) (cbor.Marshaler, error) { - loader, found := ActorStateLoaders[act.Code] - if !found { - return nil, fmt.Errorf("unknown actor code %s", act.Code) +func ActorNameByCode(c cid.Cid) string { + if name, version, ok := actors.GetActorMetaByCode(c); ok { + return fmt.Sprintf("fil/%d/%s", version, name) } - return loader(store, act.Head) -} -func ActorNameByCode(c cid.Cid) string { switch { - {{range .versions}} + {{range .versions}} case builtin{{.}}.IsBuiltinActor(c): return builtin{{.}}.ActorNameByCode(c) {{end}} @@ -110,50 +81,6 @@ func ActorFamily(name string) string { return name[idx+1:] } -func IsBuiltinActor(c cid.Cid) bool { - {{range .versions}} - if builtin{{.}}.IsBuiltinActor(c) { - return true - } - {{end}} - return false -} - -func IsAccountActor(c cid.Cid) bool { - {{range .versions}} - if c == builtin{{.}}.AccountActorCodeID { - return true - } - {{end}} - return false -} - -func IsStorageMinerActor(c cid.Cid) bool { - {{range .versions}} - if c == builtin{{.}}.StorageMinerActorCodeID { - return true - } - {{end}} - return false -} - -func IsMultisigActor(c cid.Cid) bool { - {{range .versions}} - if c == builtin{{.}}.MultisigActorCodeID { - return true - } - {{end}} - return false -} - -func IsPaymentChannelActor(c cid.Cid) bool { - {{range .versions}} - if c == builtin{{.}}.PaymentChannelActorCodeID { - return true - } - {{end}} - return false -} func makeAddress(addr string) address.Address { ret, err := address.NewFromString(addr) diff --git a/chain/actors/builtin/cron/actor.go.template b/chain/actors/builtin/cron/actor.go.template deleted file mode 100644 index 92b2261d5..000000000 --- a/chain/actors/builtin/cron/actor.go.template +++ /dev/null @@ -1,22 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package cron - -import ( - "github.com/ipfs/go-cid" - -{{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" -{{- end}} -) - -var ( - Address = builtin{{.latestVersion}}.CronActorAddr - Methods = builtin{{.latestVersion}}.MethodsCron -) - -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.CronActorCodeID, - {{- end}} - } -} diff --git a/chain/actors/builtin/cron/cron.go b/chain/actors/builtin/cron/cron.go deleted file mode 100644 index 6daf59081..000000000 --- a/chain/actors/builtin/cron/cron.go +++ /dev/null @@ -1,31 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package cron - -import ( - "github.com/ipfs/go-cid" - - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" -) - -var ( - Address = builtin7.CronActorAddr - Methods = builtin7.MethodsCron -) - -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.CronActorCodeID, - builtin2.CronActorCodeID, - builtin3.CronActorCodeID, - builtin4.CronActorCodeID, - builtin5.CronActorCodeID, - builtin6.CronActorCodeID, - builtin7.CronActorCodeID, - } -} diff --git a/chain/actors/builtin/init/actor.go.template b/chain/actors/builtin/init/actor.go.template index 6caaac48f..481e8adc2 100644 --- a/chain/actors/builtin/init/actor.go.template +++ b/chain/actors/builtin/init/actor.go.template @@ -2,56 +2,73 @@ package init import ( - "fmt" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" "github.com/ipfs/go-cid" + lotusactors "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" - - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" -{{- end}} -) + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" +{{end}} -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} + "github.com/filecoin-project/lily/chain/actors" +) var ( Address = builtin{{.latestVersion}}.InitActorAddr Methods = builtin{{.latestVersion}}.MethodsInit ) -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.InitActorCodeID, - {{- end}} - } -} - func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.InitKey { + return nil, fmt.Errorf("actor code is not init: %s", name) + } + + switch actors.Version(av) { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.InitActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.InitActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, networkName string) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store, networkName) +{{end}} +} + return nil, fmt.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version ResolveAddress(address address.Address) (address.Address, bool, error) MapAddressToNewID(address address.Address) (address.Address, error) @@ -67,5 +84,31 @@ type State interface { // Sets the network's name. This should only be used on upgrade/fork. SetNetworkName(name string) error - addressMap() (adt.Map, error) + // Sets the next ID for the init actor. This should only be used for testing. + SetNextID(id abi.ActorID) error + + // Sets the address map for the init actor. This should only be used for testing. + SetAddressMap(mcid cid.Cid) error + + AddressMap() (adt.Map, error) + AddressMapBitWidth() int + AddressMapHashFunction() func(input []byte) []byte + + GetState() interface{} +} + + +func AllCodes() []cid.Cid { + return []cid.Cid{ {{range .versions}} + (&state{{.}}{}).Code(), + {{- end}} + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + {{- range .versions}} + actors.Version{{.}}: (&state{{.}}{}).Code(), + {{- end}} + } } diff --git a/chain/actors/builtin/init/diff.go b/chain/actors/builtin/init/diff.go index 013f3e3f4..6f75d5aca 100644 --- a/chain/actors/builtin/init/diff.go +++ b/chain/actors/builtin/init/diff.go @@ -7,12 +7,13 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-hamt-ipld/v3" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/adt/diff" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" logging "github.com/ipfs/go-log/v2" typegen "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors/adt/diff" ) var log = logging.Logger("lily/actors") @@ -24,28 +25,26 @@ type AddressMapChanges struct { } func DiffAddressMap(ctx context.Context, store adt.Store, pre, cur State) (*AddressMapChanges, error) { - preOpts, err := adt.MapOptsForActorCode(pre.Code()) - if err != nil { - return nil, err - } - - curOpts, err := adt.MapOptsForActorCode(cur.Code()) + prem, err := pre.AddressMap() if err != nil { return nil, err } - prem, err := pre.addressMap() - if err != nil { - return nil, err - } - - curm, err := cur.addressMap() + curm, err := cur.AddressMap() if err != nil { return nil, err } mapDiffer := NewAddressMapDiffer(pre, cur) - if requiresLegacyDiffing(pre, cur, preOpts, curOpts) { + if requiresLegacyDiffing(pre, cur, + &adt.MapOpts{ + Bitwidth: pre.AddressMapBitWidth(), + HashFunc: pre.AddressMapHashFunction(), + }, + &adt.MapOpts{ + Bitwidth: cur.AddressMapBitWidth(), + HashFunc: cur.AddressMapHashFunction(), + }) { log.Warnw("actor HAMT opts differ, running slower generic map diff", "preCID", pre.Code(), "curCID", cur.Code()) if err := diff.CompareMap(prem, curm, mapDiffer); err != nil { return nil, err @@ -53,7 +52,7 @@ func DiffAddressMap(ctx context.Context, store adt.Store, pre, cur State) (*Addr return mapDiffer.Results, nil } - changes, err := diff.Hamt(ctx, prem, curm, store, store, hamt.UseTreeBitWidth(preOpts.Bitwidth), hamt.UseHashFunction(hamt.HashFunc(preOpts.HashFunc))) + changes, err := diff.Hamt(ctx, prem, curm, store, store, hamt.UseTreeBitWidth(pre.AddressMapBitWidth()), hamt.UseHashFunction(pre.AddressMapHashFunction())) if err != nil { return nil, err } diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 34635369a..7a5fcc964 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -9,70 +9,49 @@ import ( "github.com/filecoin-project/go-state-types/cbor" "github.com/ipfs/go-cid" + lotusactors "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" -) -func init() { + builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - builtin.RegisterActorState(builtin0.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) + builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - builtin.RegisterActorState(builtin2.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) + builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - builtin.RegisterActorState(builtin3.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" - builtin.RegisterActorState(builtin4.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) + "github.com/filecoin-project/lily/chain/actors" +) - builtin.RegisterActorState(builtin5.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) +var ( + Address = builtin8.InitActorAddr + Methods = builtin8.MethodsInit +) - builtin.RegisterActorState(builtin6.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.InitKey { + return nil, fmt.Errorf("actor code is not init: %s", name) + } - builtin.RegisterActorState(builtin7.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} + switch actors.Version(av) { -var ( - Address = builtin7.InitActorAddr - Methods = builtin7.MethodsInit -) + case actors.Version8: + return load8(store, act.Head) -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.InitActorCodeID, - builtin2.InitActorCodeID, - builtin3.InitActorCodeID, - builtin4.InitActorCodeID, - builtin5.InitActorCodeID, - builtin6.InitActorCodeID, - builtin7.InitActorCodeID, + } } -} -func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { case builtin0.InitActorCodeID: @@ -97,13 +76,47 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, networkName string) (State, error) { + switch av { + + case actors.Version0: + return make0(store, networkName) + + case actors.Version2: + return make2(store, networkName) + + case actors.Version3: + return make3(store, networkName) + + case actors.Version4: + return make4(store, networkName) + + case actors.Version5: + return make5(store, networkName) + + case actors.Version6: + return make6(store, networkName) + + case actors.Version7: + return make7(store, networkName) + + case actors.Version8: + return make8(store, networkName) + + } + return nil, fmt.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version ResolveAddress(address address.Address) (address.Address, bool, error) MapAddressToNewID(address address.Address) (address.Address, error) @@ -119,5 +132,41 @@ type State interface { // Sets the network's name. This should only be used on upgrade/fork. SetNetworkName(name string) error - addressMap() (adt.Map, error) + // Sets the next ID for the init actor. This should only be used for testing. + SetNextID(id abi.ActorID) error + + // Sets the address map for the init actor. This should only be used for testing. + SetAddressMap(mcid cid.Cid) error + + AddressMap() (adt.Map, error) + AddressMapBitWidth() int + AddressMapHashFunction() func(input []byte) []byte + + GetState() interface{} +} + +func AllCodes() []cid.Cid { + return []cid.Cid{ + (&state0{}).Code(), + (&state2{}).Code(), + (&state3{}).Code(), + (&state4{}).Code(), + (&state5{}).Code(), + (&state6{}).Code(), + (&state7{}).Code(), + (&state8{}).Code(), + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + actors.Version0: (&state0{}).Code(), + actors.Version2: (&state2{}).Code(), + actors.Version3: (&state3{}).Code(), + actors.Version4: (&state4{}).Code(), + actors.Version5: (&state5{}).Code(), + actors.Version6: (&state6{}).Code(), + actors.Version7: (&state7{}).Code(), + actors.Version8: (&state8{}).Code(), + } } diff --git a/chain/actors/builtin/init/state.go.template b/chain/actors/builtin/init/state.go.template index fe773440d..11d6bf3a3 100644 --- a/chain/actors/builtin/init/state.go.template +++ b/chain/actors/builtin/init/state.go.template @@ -1,21 +1,39 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package init import ( "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" - - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" - - init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init" - adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" +{{if (le .v 1)}} + sha256simd "github.com/minio/sha256-simd" +{{else}} + "crypto/sha256" +{{end}} + +{{if (le .v 7)}} + {{if (le .v 2)}} + init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{else}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{end}} +{{else}} + init{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}init" + adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt" + builtin{{.v}} "github.com/filecoin-project/go-state-types/builtin" +{{end}} ) var _ State = (*state{{.v}})(nil) @@ -29,15 +47,31 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store, networkName string) (State, error) { + out := state{{.v}}{store: store} + {{if (le .v 2)}} + mr, err := adt{{.v}}.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *init{{.v}}.ConstructState(mr, networkName) + {{else}} + s, err := init{{.v}}.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + {{end}} + return &out, nil +} + type state{{.v}} struct { init{{.v}}.State store adt.Store } -func (s *state{{.v}}) Code() cid.Cid { - return builtin{{.v}}.InitActorCodeID -} - func (s *state{{.v}}) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } @@ -70,6 +104,11 @@ func (s *state{{.v}}) SetNetworkName(name string) error { return nil } +func (s *state{{.v}}) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) { m, err := adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) if err != nil { @@ -88,6 +127,54 @@ func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state{{.v}}) addressMap() (adt.Map, error) { - return adt{{.v}}.AsMap(s.store, s.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) +func (s *state{{.v}}) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state{{.v}}) AddressMap() (adt.Map, error) { + return adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) +} + +func (s *state{{.v}}) AddressMapBitWidth() int { + {{if (ge .v 3)}} + return builtin{{.v}}.DefaultHamtBitwidth + {{else}} + return 5 + {{end}} +} + +func (s *state{{.v}}) AddressMapHashFunction() func(input []byte) []byte { + {{if (le .v 1)}} + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + {{else}} + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + {{end}} +} + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} + +func (s *state{{.v}}) ActorKey() string { + return actors.InitKey +} + +func (s *state{{.v}}) ActorVersion() actors.Version { + return actors.Version{{.v}} +} + +func (s *state{{.v}}) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code } diff --git a/chain/actors/builtin/init/v0.go b/chain/actors/builtin/init/v0.go index 46548fc26..718152205 100644 --- a/chain/actors/builtin/init/v0.go +++ b/chain/actors/builtin/init/v0.go @@ -1,18 +1,20 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package init import ( "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" - - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + sha256simd "github.com/minio/sha256-simd" init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -29,15 +31,24 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store, networkName string) (State, error) { + out := state0{store: store} + + mr, err := adt0.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *init0.ConstructState(mr, networkName) + + return &out, nil +} + type state0 struct { init0.State store adt.Store } -func (s *state0) Code() cid.Cid { - return builtin0.InitActorCodeID -} - func (s *state0) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } @@ -70,6 +81,11 @@ func (s *state0) SetNetworkName(name string) error { return nil } +func (s *state0) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state0) Remove(addrs ...address.Address) (err error) { m, err := adt0.AsMap(s.store, s.State.AddressMap) if err != nil { @@ -88,6 +104,47 @@ func (s *state0) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state0) addressMap() (adt.Map, error) { - return adt0.AsMap(s.store, s.AddressMap) +func (s *state0) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state0) AddressMap() (adt.Map, error) { + return adt0.AsMap(s.store, s.State.AddressMap) +} + +func (s *state0) AddressMapBitWidth() int { + + return 5 + +} + +func (s *state0) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + +} + +func (s *state0) GetState() interface{} { + return &s.State +} + +func (s *state0) ActorKey() string { + return actors.InitKey +} + +func (s *state0) ActorVersion() actors.Version { + return actors.Version0 +} + +func (s *state0) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code } diff --git a/chain/actors/builtin/init/v2.go b/chain/actors/builtin/init/v2.go index 9d5aef2c0..f50267816 100644 --- a/chain/actors/builtin/init/v2.go +++ b/chain/actors/builtin/init/v2.go @@ -1,18 +1,20 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package init import ( "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" - - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "crypto/sha256" init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init" adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" @@ -29,15 +31,24 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store, networkName string) (State, error) { + out := state2{store: store} + + mr, err := adt2.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *init2.ConstructState(mr, networkName) + + return &out, nil +} + type state2 struct { init2.State store adt.Store } -func (s *state2) Code() cid.Cid { - return builtin2.InitActorCodeID -} - func (s *state2) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } @@ -70,6 +81,11 @@ func (s *state2) SetNetworkName(name string) error { return nil } +func (s *state2) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state2) Remove(addrs ...address.Address) (err error) { m, err := adt2.AsMap(s.store, s.State.AddressMap) if err != nil { @@ -88,6 +104,47 @@ func (s *state2) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state2) addressMap() (adt.Map, error) { - return adt2.AsMap(s.store, s.AddressMap) +func (s *state2) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state2) AddressMap() (adt.Map, error) { + return adt2.AsMap(s.store, s.State.AddressMap) +} + +func (s *state2) AddressMapBitWidth() int { + + return 5 + +} + +func (s *state2) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state2) GetState() interface{} { + return &s.State +} + +func (s *state2) ActorKey() string { + return actors.InitKey +} + +func (s *state2) ActorVersion() actors.Version { + return actors.Version2 +} + +func (s *state2) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code } diff --git a/chain/actors/builtin/init/v3.go b/chain/actors/builtin/init/v3.go index fd813c62c..e182154cd 100644 --- a/chain/actors/builtin/init/v3.go +++ b/chain/actors/builtin/init/v3.go @@ -1,19 +1,22 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package init import ( "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init" adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" ) @@ -29,15 +32,24 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store, networkName string) (State, error) { + out := state3{store: store} + + s, err := init3.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state3 struct { init3.State store adt.Store } -func (s *state3) Code() cid.Cid { - return builtin3.InitActorCodeID -} - func (s *state3) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } @@ -70,6 +82,11 @@ func (s *state3) SetNetworkName(name string) error { return nil } +func (s *state3) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state3) Remove(addrs ...address.Address) (err error) { m, err := adt3.AsMap(s.store, s.State.AddressMap, builtin3.DefaultHamtBitwidth) if err != nil { @@ -88,6 +105,47 @@ func (s *state3) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state3) addressMap() (adt.Map, error) { - return adt3.AsMap(s.store, s.AddressMap, builtin3.DefaultHamtBitwidth) +func (s *state3) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state3) AddressMap() (adt.Map, error) { + return adt3.AsMap(s.store, s.State.AddressMap, builtin3.DefaultHamtBitwidth) +} + +func (s *state3) AddressMapBitWidth() int { + + return builtin3.DefaultHamtBitwidth + +} + +func (s *state3) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state3) GetState() interface{} { + return &s.State +} + +func (s *state3) ActorKey() string { + return actors.InitKey +} + +func (s *state3) ActorVersion() actors.Version { + return actors.Version3 +} + +func (s *state3) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code } diff --git a/chain/actors/builtin/init/v4.go b/chain/actors/builtin/init/v4.go index 8c3ef09a0..989ff582f 100644 --- a/chain/actors/builtin/init/v4.go +++ b/chain/actors/builtin/init/v4.go @@ -1,19 +1,22 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package init import ( "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - init4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" ) @@ -29,15 +32,24 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store, networkName string) (State, error) { + out := state4{store: store} + + s, err := init4.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state4 struct { init4.State store adt.Store } -func (s *state4) Code() cid.Cid { - return builtin4.InitActorCodeID -} - func (s *state4) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } @@ -70,6 +82,11 @@ func (s *state4) SetNetworkName(name string) error { return nil } +func (s *state4) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state4) Remove(addrs ...address.Address) (err error) { m, err := adt4.AsMap(s.store, s.State.AddressMap, builtin4.DefaultHamtBitwidth) if err != nil { @@ -88,6 +105,47 @@ func (s *state4) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state4) addressMap() (adt.Map, error) { - return adt4.AsMap(s.store, s.AddressMap, builtin4.DefaultHamtBitwidth) +func (s *state4) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state4) AddressMap() (adt.Map, error) { + return adt4.AsMap(s.store, s.State.AddressMap, builtin4.DefaultHamtBitwidth) +} + +func (s *state4) AddressMapBitWidth() int { + + return builtin4.DefaultHamtBitwidth + +} + +func (s *state4) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state4) GetState() interface{} { + return &s.State +} + +func (s *state4) ActorKey() string { + return actors.InitKey +} + +func (s *state4) ActorVersion() actors.Version { + return actors.Version4 +} + +func (s *state4) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code } diff --git a/chain/actors/builtin/init/v5.go b/chain/actors/builtin/init/v5.go index 0d3c817c4..f2132861a 100644 --- a/chain/actors/builtin/init/v5.go +++ b/chain/actors/builtin/init/v5.go @@ -1,19 +1,22 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package init import ( "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - init5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) @@ -29,15 +32,24 @@ func load5(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make5(store adt.Store, networkName string) (State, error) { + out := state5{store: store} + + s, err := init5.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state5 struct { init5.State store adt.Store } -func (s *state5) Code() cid.Cid { - return builtin5.InitActorCodeID -} - func (s *state5) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } @@ -70,6 +82,11 @@ func (s *state5) SetNetworkName(name string) error { return nil } +func (s *state5) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state5) Remove(addrs ...address.Address) (err error) { m, err := adt5.AsMap(s.store, s.State.AddressMap, builtin5.DefaultHamtBitwidth) if err != nil { @@ -88,6 +105,47 @@ func (s *state5) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state5) addressMap() (adt.Map, error) { - return adt5.AsMap(s.store, s.AddressMap, builtin5.DefaultHamtBitwidth) +func (s *state5) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state5) AddressMap() (adt.Map, error) { + return adt5.AsMap(s.store, s.State.AddressMap, builtin5.DefaultHamtBitwidth) +} + +func (s *state5) AddressMapBitWidth() int { + + return builtin5.DefaultHamtBitwidth + +} + +func (s *state5) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state5) GetState() interface{} { + return &s.State +} + +func (s *state5) ActorKey() string { + return actors.InitKey +} + +func (s *state5) ActorVersion() actors.Version { + return actors.Version5 +} + +func (s *state5) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code } diff --git a/chain/actors/builtin/init/v6.go b/chain/actors/builtin/init/v6.go index 6fb3ade00..fe903c7e6 100644 --- a/chain/actors/builtin/init/v6.go +++ b/chain/actors/builtin/init/v6.go @@ -1,19 +1,22 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package init import ( "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - init6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/init" adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt" ) @@ -29,15 +32,24 @@ func load6(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make6(store adt.Store, networkName string) (State, error) { + out := state6{store: store} + + s, err := init6.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state6 struct { init6.State store adt.Store } -func (s *state6) Code() cid.Cid { - return builtin6.InitActorCodeID -} - func (s *state6) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } @@ -70,6 +82,11 @@ func (s *state6) SetNetworkName(name string) error { return nil } +func (s *state6) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state6) Remove(addrs ...address.Address) (err error) { m, err := adt6.AsMap(s.store, s.State.AddressMap, builtin6.DefaultHamtBitwidth) if err != nil { @@ -88,6 +105,47 @@ func (s *state6) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state6) addressMap() (adt.Map, error) { - return adt6.AsMap(s.store, s.AddressMap, builtin6.DefaultHamtBitwidth) +func (s *state6) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state6) AddressMap() (adt.Map, error) { + return adt6.AsMap(s.store, s.State.AddressMap, builtin6.DefaultHamtBitwidth) +} + +func (s *state6) AddressMapBitWidth() int { + + return builtin6.DefaultHamtBitwidth + +} + +func (s *state6) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state6) GetState() interface{} { + return &s.State +} + +func (s *state6) ActorKey() string { + return actors.InitKey +} + +func (s *state6) ActorVersion() actors.Version { + return actors.Version6 +} + +func (s *state6) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code } diff --git a/chain/actors/builtin/init/v7.go b/chain/actors/builtin/init/v7.go index 8cb02ce64..c78346af8 100644 --- a/chain/actors/builtin/init/v7.go +++ b/chain/actors/builtin/init/v7.go @@ -1,19 +1,22 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package init import ( "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init" adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt" ) @@ -29,15 +32,24 @@ func load7(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make7(store adt.Store, networkName string) (State, error) { + out := state7{store: store} + + s, err := init7.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state7 struct { init7.State store adt.Store } -func (s *state7) Code() cid.Cid { - return builtin7.InitActorCodeID -} - func (s *state7) ResolveAddress(address address.Address) (address.Address, bool, error) { return s.State.ResolveAddress(s.store, address) } @@ -70,6 +82,11 @@ func (s *state7) SetNetworkName(name string) error { return nil } +func (s *state7) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state7) Remove(addrs ...address.Address) (err error) { m, err := adt7.AsMap(s.store, s.State.AddressMap, builtin7.DefaultHamtBitwidth) if err != nil { @@ -88,6 +105,47 @@ func (s *state7) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state7) addressMap() (adt.Map, error) { - return adt7.AsMap(s.store, s.AddressMap, builtin7.DefaultHamtBitwidth) +func (s *state7) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state7) AddressMap() (adt.Map, error) { + return adt7.AsMap(s.store, s.State.AddressMap, builtin7.DefaultHamtBitwidth) +} + +func (s *state7) AddressMapBitWidth() int { + + return builtin7.DefaultHamtBitwidth + +} + +func (s *state7) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state7) GetState() interface{} { + return &s.State +} + +func (s *state7) ActorKey() string { + return actors.InitKey +} + +func (s *state7) ActorVersion() actors.Version { + return actors.Version7 +} + +func (s *state7) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code } diff --git a/chain/actors/builtin/init/v8.go b/chain/actors/builtin/init/v8.go new file mode 100644 index 000000000..f8cc09f20 --- /dev/null +++ b/chain/actors/builtin/init/v8.go @@ -0,0 +1,151 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. + +package init + +import ( + "fmt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/node/modules/dtypes" + + "crypto/sha256" + + builtin8 "github.com/filecoin-project/go-state-types/builtin" + init8 "github.com/filecoin-project/go-state-types/builtin/v8/init" + adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt" +) + +var _ State = (*state8)(nil) + +func load8(store adt.Store, root cid.Cid) (State, error) { + out := state8{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make8(store adt.Store, networkName string) (State, error) { + out := state8{store: store} + + s, err := init8.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state8 struct { + init8.State + store adt.Store +} + +func (s *state8) ResolveAddress(address address.Address) (address.Address, bool, error) { + return s.State.ResolveAddress(s.store, address) +} + +func (s *state8) MapAddressToNewID(address address.Address) (address.Address, error) { + return s.State.MapAddressToNewID(s.store, address) +} + +func (s *state8) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error { + addrs, err := adt8.AsMap(s.store, s.State.AddressMap, builtin8.DefaultHamtBitwidth) + if err != nil { + return err + } + var actorID cbg.CborInt + return addrs.ForEach(&actorID, func(key string) error { + addr, err := address.NewFromBytes([]byte(key)) + if err != nil { + return err + } + return cb(abi.ActorID(actorID), addr) + }) +} + +func (s *state8) NetworkName() (dtypes.NetworkName, error) { + return dtypes.NetworkName(s.State.NetworkName), nil +} + +func (s *state8) SetNetworkName(name string) error { + s.State.NetworkName = name + return nil +} + +func (s *state8) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + +func (s *state8) Remove(addrs ...address.Address) (err error) { + m, err := adt8.AsMap(s.store, s.State.AddressMap, builtin8.DefaultHamtBitwidth) + if err != nil { + return err + } + for _, addr := range addrs { + if err = m.Delete(abi.AddrKey(addr)); err != nil { + return fmt.Errorf("failed to delete entry for address: %s; err: %w", addr, err) + } + } + amr, err := m.Root() + if err != nil { + return fmt.Errorf("failed to get address map root: %w", err) + } + s.State.AddressMap = amr + return nil +} + +func (s *state8) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state8) AddressMap() (adt.Map, error) { + return adt8.AsMap(s.store, s.State.AddressMap, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) AddressMapBitWidth() int { + + return builtin8.DefaultHamtBitwidth + +} + +func (s *state8) AddressMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state8) GetState() interface{} { + return &s.State +} + +func (s *state8) ActorKey() string { + return actors.InitKey +} + +func (s *state8) ActorVersion() actors.Version { + return actors.Version8 +} + +func (s *state8) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/actor.go.template b/chain/actors/builtin/market/actor.go.template index cc1d66ff9..727216585 100644 --- a/chain/actors/builtin/market/actor.go.template +++ b/chain/actors/builtin/market/actor.go.template @@ -1,81 +1,82 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( - "fmt" + "unicode/utf8" + + "golang.org/x/xerrors" + "github.com/ipfs/go-cid" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/cbor" - "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" - market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + market{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin{{import .latestVersion}}market" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" -{{- end}} + {{if (ge . 8)}} + builtintypes{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{end}} +{{end}} + "github.com/filecoin-project/lotus/chain/actors/adt" + lotusactors "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" + "github.com/filecoin-project/lily/chain/actors" ) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} - var ( - Address = builtin{{.latestVersion}}.StorageMarketActorAddr - Methods = builtin{{.latestVersion}}.MethodsMarket + Address = builtintypes{{.latestVersion}}.StorageMarketActorAddr + Methods = builtintypes{{.latestVersion}}.MethodsMarket ) -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.StorageMarketActorCodeID, - {{- end}} - } -} - func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.MarketKey { + return nil, xerrors.Errorf("actor code is not market: %s", name) + } + + switch actors.Version(av) { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.StorageMarketActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.StorageMarketActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} } - return nil, fmt.Errorf("unknown actor code %s", act.Code) + + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } type State interface { cbor.Marshaler + Code() cid.Cid - BalancesChanged(State) (bool, error) - EscrowTable() (BalanceTable, error) - LockedTable() (BalanceTable, error) - TotalLocked() (abi.TokenAmount, error) + ActorKey() string + ActorVersion() actors.Version + StatesChanged(State) (bool, error) States() (DealStates, error) ProposalsChanged(State) (bool, error) Proposals() (DealProposals, error) - VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, - ) (weight, verifiedWeight abi.DealWeight, err error) - NextID() (abi.DealID, error) DealProposalsAmtBitwidth() int DealStatesAmtBitwidth() int } -type BalanceTable interface { - ForEach(cb func(address.Address, abi.TokenAmount) error) error - Get(key address.Address) (abi.TokenAmount, error) -} - type DealStates interface { ForEach(cb func(id abi.DealID, ds DealState) error) error Get(id abi.DealID) (*DealState, bool, error) @@ -85,88 +86,65 @@ type DealStates interface { } type DealProposals interface { - ForEach(cb func(id abi.DealID, dp DealProposal) error) error - Get(id abi.DealID) (*DealProposal, bool, error) + ForEach(cb func(id abi.DealID, dp market{{.latestVersion}}.DealProposal) error) error + Get(id abi.DealID) (*market{{.latestVersion}}.DealProposal, bool, error) array() adt.Array - decode(*cbg.Deferred) (*DealProposal, error) + decode(*cbg.Deferred) (*market{{.latestVersion}}.DealProposal, error) } -type PublishStorageDealsParams = market0.PublishStorageDealsParams -type PublishStorageDealsReturn = market0.PublishStorageDealsReturn -type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams -type WithdrawBalanceParams = market0.WithdrawBalanceParams -type ClientDealProposal = market0.ClientDealProposal +type DealProposal = market{{.latestVersion}}.DealProposal -type DealState struct { - SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector - LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated - SlashEpoch abi.ChainEpoch // -1 if deal never slashed -} - -type DealProposal struct { - PieceCID cid.Cid - PieceSize abi.PaddedPieceSize - VerifiedDeal bool - Client address.Address - Provider address.Address - Label string - StartEpoch abi.ChainEpoch - EndEpoch abi.ChainEpoch - StoragePricePerEpoch abi.TokenAmount - ProviderCollateral abi.TokenAmount - ClientCollateral abi.TokenAmount -} +type DealState = market{{.latestVersion}}.DealState type DealStateChanges struct { - Added []DealIDState + Added []DealIDState Modified []DealStateChange - Removed []DealIDState + Removed []DealIDState } type DealIDState struct { - ID abi.DealID + ID abi.DealID Deal DealState } // DealStateChange is a change in deal state from -> to type DealStateChange struct { - ID abi.DealID + ID abi.DealID From *DealState - To *DealState + To *DealState } type DealProposalChanges struct { - Added []ProposalIDState + Added []ProposalIDState Removed []ProposalIDState } type ProposalIDState struct { - ID abi.DealID - Proposal DealProposal + ID abi.DealID + Proposal market{{.latestVersion}}.DealProposal } -func EmptyDealState() *DealState { - return &DealState{ - SectorStartEpoch: -1, - SlashEpoch: -1, - LastUpdatedEpoch: -1, +func labelFromGoString(s string) (market{{.latestVersion}}.DealLabel, error) { + if utf8.ValidString(s) { + return market{{.latestVersion}}.NewLabelFromString(s) + } else { + return market{{.latestVersion}}.NewLabelFromBytes([]byte(s)) } } -// returns the earned fees and pending fees for a given deal -func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, abi.TokenAmount) { - tf := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(deal.EndEpoch-deal.StartEpoch))) - - ef := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(height-deal.StartEpoch))) - if ef.LessThan(big.Zero()) { - ef = big.Zero() - } - - if ef.GreaterThan(tf) { - ef = tf - } +func AllCodes() []cid.Cid { + return []cid.Cid{ {{range .versions}} + (&state{{.}}{}).Code(), + {{- end}} + } +} - return ef, big.Sub(tf, ef) +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + {{- range .versions}} + actors.Version{{.}}: (&state{{.}}{}).Code(), + {{- end}} + } } diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index 23dd1905b..3ac68c214 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -1,81 +1,61 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( - "fmt" + "unicode/utf8" + + "github.com/ipfs/go-cid" + "golang.org/x/xerrors" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/cbor" - "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" - market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" + builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" + builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" + builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + builtintypes8 "github.com/filecoin-project/go-state-types/builtin" + + lotusactors "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" + "github.com/filecoin-project/lily/chain/actors" ) -func init() { - - builtin.RegisterActorState(builtin0.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) - - builtin.RegisterActorState(builtin3.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) - - builtin.RegisterActorState(builtin5.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) +var ( + Address = builtintypes8.StorageMarketActorAddr + Methods = builtintypes8.MethodsMarket +) - builtin.RegisterActorState(builtin6.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.MarketKey { + return nil, xerrors.Errorf("actor code is not market: %s", name) + } - builtin.RegisterActorState(builtin7.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} + switch actors.Version(av) { -var ( - Address = builtin7.StorageMarketActorAddr - Methods = builtin7.MethodsMarket -) + case actors.Version8: + return load8(store, act.Head) -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.StorageMarketActorCodeID, - builtin2.StorageMarketActorCodeID, - builtin3.StorageMarketActorCodeID, - builtin4.StorageMarketActorCodeID, - builtin5.StorageMarketActorCodeID, - builtin6.StorageMarketActorCodeID, - builtin7.StorageMarketActorCodeID, + } } -} -func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { case builtin0.StorageMarketActorCodeID: @@ -100,34 +80,26 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } - return nil, fmt.Errorf("unknown actor code %s", act.Code) + + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } type State interface { cbor.Marshaler + Code() cid.Cid - BalancesChanged(State) (bool, error) - EscrowTable() (BalanceTable, error) - LockedTable() (BalanceTable, error) - TotalLocked() (abi.TokenAmount, error) + ActorKey() string + ActorVersion() actors.Version + StatesChanged(State) (bool, error) States() (DealStates, error) ProposalsChanged(State) (bool, error) Proposals() (DealProposals, error) - VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, - ) (weight, verifiedWeight abi.DealWeight, err error) - NextID() (abi.DealID, error) DealProposalsAmtBitwidth() int DealStatesAmtBitwidth() int } -type BalanceTable interface { - ForEach(cb func(address.Address, abi.TokenAmount) error) error - Get(key address.Address) (abi.TokenAmount, error) -} - type DealStates interface { ForEach(cb func(id abi.DealID, ds DealState) error) error Get(id abi.DealID) (*DealState, bool, error) @@ -137,39 +109,16 @@ type DealStates interface { } type DealProposals interface { - ForEach(cb func(id abi.DealID, dp DealProposal) error) error - Get(id abi.DealID) (*DealProposal, bool, error) + ForEach(cb func(id abi.DealID, dp market8.DealProposal) error) error + Get(id abi.DealID) (*market8.DealProposal, bool, error) array() adt.Array - decode(*cbg.Deferred) (*DealProposal, error) + decode(*cbg.Deferred) (*market8.DealProposal, error) } -type PublishStorageDealsParams = market0.PublishStorageDealsParams -type PublishStorageDealsReturn = market0.PublishStorageDealsReturn -type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams -type WithdrawBalanceParams = market0.WithdrawBalanceParams - -type ClientDealProposal = market0.ClientDealProposal +type DealProposal = market8.DealProposal -type DealState struct { - SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector - LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated - SlashEpoch abi.ChainEpoch // -1 if deal never slashed -} - -type DealProposal struct { - PieceCID cid.Cid - PieceSize abi.PaddedPieceSize - VerifiedDeal bool - Client address.Address - Provider address.Address - Label string - StartEpoch abi.ChainEpoch - EndEpoch abi.ChainEpoch - StoragePricePerEpoch abi.TokenAmount - ProviderCollateral abi.TokenAmount - ClientCollateral abi.TokenAmount -} +type DealState = market8.DealState type DealStateChanges struct { Added []DealIDState @@ -196,29 +145,39 @@ type DealProposalChanges struct { type ProposalIDState struct { ID abi.DealID - Proposal DealProposal + Proposal market8.DealProposal } -func EmptyDealState() *DealState { - return &DealState{ - SectorStartEpoch: -1, - SlashEpoch: -1, - LastUpdatedEpoch: -1, +func labelFromGoString(s string) (market8.DealLabel, error) { + if utf8.ValidString(s) { + return market8.NewLabelFromString(s) + } else { + return market8.NewLabelFromBytes([]byte(s)) } } -// returns the earned fees and pending fees for a given deal -func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, abi.TokenAmount) { - tf := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(deal.EndEpoch-deal.StartEpoch))) - - ef := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(height-deal.StartEpoch))) - if ef.LessThan(big.Zero()) { - ef = big.Zero() +func AllCodes() []cid.Cid { + return []cid.Cid{ + (&state0{}).Code(), + (&state2{}).Code(), + (&state3{}).Code(), + (&state4{}).Code(), + (&state5{}).Code(), + (&state6{}).Code(), + (&state7{}).Code(), + (&state8{}).Code(), } +} - if ef.GreaterThan(tf) { - ef = tf +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + actors.Version0: (&state0{}).Code(), + actors.Version2: (&state2{}).Code(), + actors.Version3: (&state3{}).Code(), + actors.Version4: (&state4{}).Code(), + actors.Version5: (&state5{}).Code(), + actors.Version6: (&state6{}).Code(), + actors.Version7: (&state7{}).Code(), + actors.Version8: (&state8{}).Code(), } - - return ef, big.Sub(tf, ef) } diff --git a/chain/actors/builtin/market/state.go.template b/chain/actors/builtin/market/state.go.template index 7201c9cf5..af356e13d 100644 --- a/chain/actors/builtin/market/state.go.template +++ b/chain/actors/builtin/market/state.go.template @@ -1,21 +1,26 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( "bytes" + "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" +{{if (le .v 7)}} market{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/market" adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" +{{else}} + market{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}market" + adt{{.v}} "github.com/filecoin-project/go-state-types/builtin/v8/util/adt" +{{end}} ) var _ State = (*state{{.v}})(nil) @@ -29,29 +34,34 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -type state{{.v}} struct { - market{{.v}}.State - store adt.Store -} +func make{{.v}}(store adt.Store) (State, error) { + out := state{{.v}}{store: store} + {{if (le .v 2)}} + ea, err := adt{{.v}}.MakeEmptyArray(store).Root() + if err != nil { + return nil, err + } -func (s *state{{.v}}) Code() cid.Cid { - return builtin{{.v}}.StorageMarketActorCodeID -} + em, err := adt{{.v}}.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } -func (s *state{{.v}}) TotalLocked() (abi.TokenAmount, error) { - fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, s.TotalClientStorageFee) - return fml, nil + out.State = *market{{.v}}.ConstructState(ea, em, em) + {{else}} + s, err := market{{.v}}.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + {{end}} + return &out, nil } -func (s *state{{.v}}) BalancesChanged(otherState State) (bool, error) { - otherState{{.v}}, ok := otherState.(*state{{.v}}) - if !ok { - // there's no way to compare different versions of the state, so let's - // just say that means the state of balances has changed - return true, nil - } - return !s.State.EscrowTable.Equals(otherState{{.v}}.State.EscrowTable) || !s.State.LockedTable.Equals(otherState{{.v}}.State.LockedTable), nil +type state{{.v}} struct { + market{{.v}}.State + store adt.Store } func (s *state{{.v}}) StatesChanged(otherState State) (bool, error) { @@ -90,49 +100,6 @@ func (s *state{{.v}}) Proposals() (DealProposals, error) { return &dealProposals{{.v}}{proposalArray}, nil } -func (s *state{{.v}}) EscrowTable() (BalanceTable, error) { - bt, err := adt{{.v}}.AsBalanceTable(s.store, s.State.EscrowTable) - if err != nil { - return nil, err - } - return &balanceTable{{.v}}{bt}, nil -} - -func (s *state{{.v}}) LockedTable() (BalanceTable, error) { - bt, err := adt{{.v}}.AsBalanceTable(s.store, s.State.LockedTable) - if err != nil { - return nil, err - } - return &balanceTable{{.v}}{bt}, nil -} - -func (s *state{{.v}}) VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw{{if (ge .v 2)}}, _{{end}}, err := market{{.v}}.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err -} - -func (s *state{{.v}}) NextID() (abi.DealID, error) { - return s.State.NextID, nil -} - -type balanceTable{{.v}} struct { - *adt{{.v}}.BalanceTable -} - -func (bt *balanceTable{{.v}}) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*adt{{.v}}.Map)(bt.BalanceTable) - var ta abi.TokenAmount - return asMap.ForEach(&ta, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - return cb(a, ta) - }) -} - type dealStates{{.v}} struct { adt.Array } @@ -171,7 +138,7 @@ func (s *dealStates{{.v}}) array() adt.Array { } func fromV{{.v}}DealState(v{{.v}} market{{.v}}.DealState) DealState { - return (DealState)(v{{.v}}) + return (DealState)(v{{.v}}) } type dealProposals{{.v}} struct { @@ -187,14 +154,24 @@ func (s *dealProposals{{.v}}) Get(dealID abi.DealID) (*DealProposal, bool, error if !found { return nil, false, nil } - proposal := fromV{{.v}}DealProposal(proposal{{.v}}) - return &proposal, true, nil + + proposal, err := fromV{{.v}}DealProposal(proposal{{.v}}) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + + return &proposal, true, nil } func (s *dealProposals{{.v}}) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { var dp{{.v}} market{{.v}}.DealProposal return s.Array.ForEach(&dp{{.v}}, func(idx int64) error { - return cb(abi.DealID(idx), fromV{{.v}}DealProposal(dp{{.v}})) + dp, err := fromV{{.v}}DealProposal(dp{{.v}}) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) }) } @@ -203,18 +180,48 @@ func (s *dealProposals{{.v}}) decode(val *cbg.Deferred) (*DealProposal, error) { if err := dp{{.v}}.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV{{.v}}DealProposal(dp{{.v}}) - return &dp, nil + + dp, err := fromV{{.v}}DealProposal(dp{{.v}}) + if err != nil { + return nil, err + } + + return &dp, nil } func (s *dealProposals{{.v}}) array() adt.Array { return s.Array } -func fromV{{.v}}DealProposal(v{{.v}} market{{.v}}.DealProposal) DealProposal { - return (DealProposal)(v{{.v}}) +func fromV{{.v}}DealProposal(v{{.v}} market{{.v}}.DealProposal) (DealProposal, error) { + {{if (le .v 7)}} + label, err := labelFromGoString(v{{.v}}.Label) + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + {{else}} + label := v{{.v}}.Label + {{end}} + + return DealProposal{ + PieceCID: v{{.v}}.PieceCID, + PieceSize: v{{.v}}.PieceSize, + VerifiedDeal: v{{.v}}.VerifiedDeal, + Client: v{{.v}}.Client, + Provider: v{{.v}}.Provider, + + Label: label, + + StartEpoch: v{{.v}}.StartEpoch, + EndEpoch: v{{.v}}.EndEpoch, + StoragePricePerEpoch: v{{.v}}.StoragePricePerEpoch, + + ProviderCollateral: v{{.v}}.ProviderCollateral, + ClientCollateral: v{{.v}}.ClientCollateral, + }, nil } + func (s *state{{.v}}) DealProposalsAmtBitwidth() int { return {{if (ge .v 3)}}market{{.v}}.ProposalsAmtBitwidth{{else}}3{{end}} } @@ -223,3 +230,19 @@ func (s *state{{.v}}) DealStatesAmtBitwidth() int { return {{if (ge .v 3)}}market{{.v}}.StatesAmtBitwidth{{else}}3{{end}} } +func (s *state{{.v}}) ActorKey() string { + return actors.MarketKey +} + +func (s *state{{.v}}) ActorVersion() actors.Version { + return actors.Version{{.v}} +} + +func (s *state{{.v}}) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 753e8282b..1c9699a3a 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -1,19 +1,19 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( "bytes" + "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) @@ -29,29 +29,27 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -type state0 struct { - market0.State - store adt.Store -} +func make0(store adt.Store) (State, error) { + out := state0{store: store} -func (s *state0) Code() cid.Cid { - return builtin0.StorageMarketActorCodeID -} + ea, err := adt0.MakeEmptyArray(store).Root() + if err != nil { + return nil, err + } + + em, err := adt0.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *market0.ConstructState(ea, em, em) -func (s *state0) TotalLocked() (abi.TokenAmount, error) { - fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, s.TotalClientStorageFee) - return fml, nil + return &out, nil } -func (s *state0) BalancesChanged(otherState State) (bool, error) { - otherState0, ok := otherState.(*state0) - if !ok { - // there's no way to compare different versions of the state, so let's - // just say that means the state of balances has changed - return true, nil - } - return !s.State.EscrowTable.Equals(otherState0.State.EscrowTable) || !s.State.LockedTable.Equals(otherState0.State.LockedTable), nil +type state0 struct { + market0.State + store adt.Store } func (s *state0) StatesChanged(otherState State) (bool, error) { @@ -90,49 +88,6 @@ func (s *state0) Proposals() (DealProposals, error) { return &dealProposals0{proposalArray}, nil } -func (s *state0) EscrowTable() (BalanceTable, error) { - bt, err := adt0.AsBalanceTable(s.store, s.State.EscrowTable) - if err != nil { - return nil, err - } - return &balanceTable0{bt}, nil -} - -func (s *state0) LockedTable() (BalanceTable, error) { - bt, err := adt0.AsBalanceTable(s.store, s.State.LockedTable) - if err != nil { - return nil, err - } - return &balanceTable0{bt}, nil -} - -func (s *state0) VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, err := market0.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err -} - -func (s *state0) NextID() (abi.DealID, error) { - return s.State.NextID, nil -} - -type balanceTable0 struct { - *adt0.BalanceTable -} - -func (bt *balanceTable0) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*adt0.Map)(bt.BalanceTable) - var ta abi.TokenAmount - return asMap.ForEach(&ta, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - return cb(a, ta) - }) -} - type dealStates0 struct { adt.Array } @@ -187,14 +142,24 @@ func (s *dealProposals0) Get(dealID abi.DealID) (*DealProposal, bool, error) { if !found { return nil, false, nil } - proposal := fromV0DealProposal(proposal0) + + proposal, err := fromV0DealProposal(proposal0) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + return &proposal, true, nil } func (s *dealProposals0) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { var dp0 market0.DealProposal return s.Array.ForEach(&dp0, func(idx int64) error { - return cb(abi.DealID(idx), fromV0DealProposal(dp0)) + dp, err := fromV0DealProposal(dp0) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) }) } @@ -203,7 +168,12 @@ func (s *dealProposals0) decode(val *cbg.Deferred) (*DealProposal, error) { if err := dp0.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV0DealProposal(dp0) + + dp, err := fromV0DealProposal(dp0) + if err != nil { + return nil, err + } + return &dp, nil } @@ -211,8 +181,29 @@ func (s *dealProposals0) array() adt.Array { return s.Array } -func fromV0DealProposal(v0 market0.DealProposal) DealProposal { - return (DealProposal)(v0) +func fromV0DealProposal(v0 market0.DealProposal) (DealProposal, error) { + + label, err := labelFromGoString(v0.Label) + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v0.PieceCID, + PieceSize: v0.PieceSize, + VerifiedDeal: v0.VerifiedDeal, + Client: v0.Client, + Provider: v0.Provider, + + Label: label, + + StartEpoch: v0.StartEpoch, + EndEpoch: v0.EndEpoch, + StoragePricePerEpoch: v0.StoragePricePerEpoch, + + ProviderCollateral: v0.ProviderCollateral, + ClientCollateral: v0.ClientCollateral, + }, nil } func (s *state0) DealProposalsAmtBitwidth() int { @@ -222,3 +213,20 @@ func (s *state0) DealProposalsAmtBitwidth() int { func (s *state0) DealStatesAmtBitwidth() int { return 3 } + +func (s *state0) ActorKey() string { + return actors.MarketKey +} + +func (s *state0) ActorVersion() actors.Version { + return actors.Version0 +} + +func (s *state0) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/v2.go b/chain/actors/builtin/market/v2.go index 47b1a9514..f30cae73f 100644 --- a/chain/actors/builtin/market/v2.go +++ b/chain/actors/builtin/market/v2.go @@ -1,19 +1,19 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( "bytes" + "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" ) @@ -29,29 +29,27 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -type state2 struct { - market2.State - store adt.Store -} +func make2(store adt.Store) (State, error) { + out := state2{store: store} -func (s *state2) Code() cid.Cid { - return builtin2.StorageMarketActorCodeID -} + ea, err := adt2.MakeEmptyArray(store).Root() + if err != nil { + return nil, err + } + + em, err := adt2.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *market2.ConstructState(ea, em, em) -func (s *state2) TotalLocked() (abi.TokenAmount, error) { - fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, s.TotalClientStorageFee) - return fml, nil + return &out, nil } -func (s *state2) BalancesChanged(otherState State) (bool, error) { - otherState2, ok := otherState.(*state2) - if !ok { - // there's no way to compare different versions of the state, so let's - // just say that means the state of balances has changed - return true, nil - } - return !s.State.EscrowTable.Equals(otherState2.State.EscrowTable) || !s.State.LockedTable.Equals(otherState2.State.LockedTable), nil +type state2 struct { + market2.State + store adt.Store } func (s *state2) StatesChanged(otherState State) (bool, error) { @@ -90,49 +88,6 @@ func (s *state2) Proposals() (DealProposals, error) { return &dealProposals2{proposalArray}, nil } -func (s *state2) EscrowTable() (BalanceTable, error) { - bt, err := adt2.AsBalanceTable(s.store, s.State.EscrowTable) - if err != nil { - return nil, err - } - return &balanceTable2{bt}, nil -} - -func (s *state2) LockedTable() (BalanceTable, error) { - bt, err := adt2.AsBalanceTable(s.store, s.State.LockedTable) - if err != nil { - return nil, err - } - return &balanceTable2{bt}, nil -} - -func (s *state2) VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market2.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err -} - -func (s *state2) NextID() (abi.DealID, error) { - return s.State.NextID, nil -} - -type balanceTable2 struct { - *adt2.BalanceTable -} - -func (bt *balanceTable2) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*adt2.Map)(bt.BalanceTable) - var ta abi.TokenAmount - return asMap.ForEach(&ta, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - return cb(a, ta) - }) -} - type dealStates2 struct { adt.Array } @@ -187,14 +142,24 @@ func (s *dealProposals2) Get(dealID abi.DealID) (*DealProposal, bool, error) { if !found { return nil, false, nil } - proposal := fromV2DealProposal(proposal2) + + proposal, err := fromV2DealProposal(proposal2) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + return &proposal, true, nil } func (s *dealProposals2) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { var dp2 market2.DealProposal return s.Array.ForEach(&dp2, func(idx int64) error { - return cb(abi.DealID(idx), fromV2DealProposal(dp2)) + dp, err := fromV2DealProposal(dp2) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) }) } @@ -203,7 +168,12 @@ func (s *dealProposals2) decode(val *cbg.Deferred) (*DealProposal, error) { if err := dp2.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV2DealProposal(dp2) + + dp, err := fromV2DealProposal(dp2) + if err != nil { + return nil, err + } + return &dp, nil } @@ -211,8 +181,29 @@ func (s *dealProposals2) array() adt.Array { return s.Array } -func fromV2DealProposal(v2 market2.DealProposal) DealProposal { - return (DealProposal)(v2) +func fromV2DealProposal(v2 market2.DealProposal) (DealProposal, error) { + + label, err := labelFromGoString(v2.Label) + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v2.PieceCID, + PieceSize: v2.PieceSize, + VerifiedDeal: v2.VerifiedDeal, + Client: v2.Client, + Provider: v2.Provider, + + Label: label, + + StartEpoch: v2.StartEpoch, + EndEpoch: v2.EndEpoch, + StoragePricePerEpoch: v2.StoragePricePerEpoch, + + ProviderCollateral: v2.ProviderCollateral, + ClientCollateral: v2.ClientCollateral, + }, nil } func (s *state2) DealProposalsAmtBitwidth() int { @@ -222,3 +213,20 @@ func (s *state2) DealProposalsAmtBitwidth() int { func (s *state2) DealStatesAmtBitwidth() int { return 3 } + +func (s *state2) ActorKey() string { + return actors.MarketKey +} + +func (s *state2) ActorVersion() actors.Version { + return actors.Version2 +} + +func (s *state2) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/v3.go b/chain/actors/builtin/market/v3.go index 2678259b8..7b290c6e7 100644 --- a/chain/actors/builtin/market/v3.go +++ b/chain/actors/builtin/market/v3.go @@ -1,19 +1,19 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( "bytes" + "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" market3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/market" adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" ) @@ -29,29 +29,22 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -type state3 struct { - market3.State - store adt.Store -} +func make3(store adt.Store) (State, error) { + out := state3{store: store} -func (s *state3) Code() cid.Cid { - return builtin3.StorageMarketActorCodeID -} + s, err := market3.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s -func (s *state3) TotalLocked() (abi.TokenAmount, error) { - fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, s.TotalClientStorageFee) - return fml, nil + return &out, nil } -func (s *state3) BalancesChanged(otherState State) (bool, error) { - otherState3, ok := otherState.(*state3) - if !ok { - // there's no way to compare different versions of the state, so let's - // just say that means the state of balances has changed - return true, nil - } - return !s.State.EscrowTable.Equals(otherState3.State.EscrowTable) || !s.State.LockedTable.Equals(otherState3.State.LockedTable), nil +type state3 struct { + market3.State + store adt.Store } func (s *state3) StatesChanged(otherState State) (bool, error) { @@ -90,49 +83,6 @@ func (s *state3) Proposals() (DealProposals, error) { return &dealProposals3{proposalArray}, nil } -func (s *state3) EscrowTable() (BalanceTable, error) { - bt, err := adt3.AsBalanceTable(s.store, s.State.EscrowTable) - if err != nil { - return nil, err - } - return &balanceTable3{bt}, nil -} - -func (s *state3) LockedTable() (BalanceTable, error) { - bt, err := adt3.AsBalanceTable(s.store, s.State.LockedTable) - if err != nil { - return nil, err - } - return &balanceTable3{bt}, nil -} - -func (s *state3) VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market3.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err -} - -func (s *state3) NextID() (abi.DealID, error) { - return s.State.NextID, nil -} - -type balanceTable3 struct { - *adt3.BalanceTable -} - -func (bt *balanceTable3) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*adt3.Map)(bt.BalanceTable) - var ta abi.TokenAmount - return asMap.ForEach(&ta, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - return cb(a, ta) - }) -} - type dealStates3 struct { adt.Array } @@ -187,14 +137,24 @@ func (s *dealProposals3) Get(dealID abi.DealID) (*DealProposal, bool, error) { if !found { return nil, false, nil } - proposal := fromV3DealProposal(proposal3) + + proposal, err := fromV3DealProposal(proposal3) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + return &proposal, true, nil } func (s *dealProposals3) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { var dp3 market3.DealProposal return s.Array.ForEach(&dp3, func(idx int64) error { - return cb(abi.DealID(idx), fromV3DealProposal(dp3)) + dp, err := fromV3DealProposal(dp3) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) }) } @@ -203,7 +163,12 @@ func (s *dealProposals3) decode(val *cbg.Deferred) (*DealProposal, error) { if err := dp3.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV3DealProposal(dp3) + + dp, err := fromV3DealProposal(dp3) + if err != nil { + return nil, err + } + return &dp, nil } @@ -211,8 +176,29 @@ func (s *dealProposals3) array() adt.Array { return s.Array } -func fromV3DealProposal(v3 market3.DealProposal) DealProposal { - return (DealProposal)(v3) +func fromV3DealProposal(v3 market3.DealProposal) (DealProposal, error) { + + label, err := labelFromGoString(v3.Label) + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v3.PieceCID, + PieceSize: v3.PieceSize, + VerifiedDeal: v3.VerifiedDeal, + Client: v3.Client, + Provider: v3.Provider, + + Label: label, + + StartEpoch: v3.StartEpoch, + EndEpoch: v3.EndEpoch, + StoragePricePerEpoch: v3.StoragePricePerEpoch, + + ProviderCollateral: v3.ProviderCollateral, + ClientCollateral: v3.ClientCollateral, + }, nil } func (s *state3) DealProposalsAmtBitwidth() int { @@ -222,3 +208,20 @@ func (s *state3) DealProposalsAmtBitwidth() int { func (s *state3) DealStatesAmtBitwidth() int { return market3.StatesAmtBitwidth } + +func (s *state3) ActorKey() string { + return actors.MarketKey +} + +func (s *state3) ActorVersion() actors.Version { + return actors.Version3 +} + +func (s *state3) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/v4.go b/chain/actors/builtin/market/v4.go index 4cd00ba3a..1257ce046 100644 --- a/chain/actors/builtin/market/v4.go +++ b/chain/actors/builtin/market/v4.go @@ -1,19 +1,19 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( "bytes" + "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" ) @@ -29,29 +29,22 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -type state4 struct { - market4.State - store adt.Store -} +func make4(store adt.Store) (State, error) { + out := state4{store: store} -func (s *state4) Code() cid.Cid { - return builtin4.StorageMarketActorCodeID -} + s, err := market4.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s -func (s *state4) TotalLocked() (abi.TokenAmount, error) { - fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, s.TotalClientStorageFee) - return fml, nil + return &out, nil } -func (s *state4) BalancesChanged(otherState State) (bool, error) { - otherState4, ok := otherState.(*state4) - if !ok { - // there's no way to compare different versions of the state, so let's - // just say that means the state of balances has changed - return true, nil - } - return !s.State.EscrowTable.Equals(otherState4.State.EscrowTable) || !s.State.LockedTable.Equals(otherState4.State.LockedTable), nil +type state4 struct { + market4.State + store adt.Store } func (s *state4) StatesChanged(otherState State) (bool, error) { @@ -90,49 +83,6 @@ func (s *state4) Proposals() (DealProposals, error) { return &dealProposals4{proposalArray}, nil } -func (s *state4) EscrowTable() (BalanceTable, error) { - bt, err := adt4.AsBalanceTable(s.store, s.State.EscrowTable) - if err != nil { - return nil, err - } - return &balanceTable4{bt}, nil -} - -func (s *state4) LockedTable() (BalanceTable, error) { - bt, err := adt4.AsBalanceTable(s.store, s.State.LockedTable) - if err != nil { - return nil, err - } - return &balanceTable4{bt}, nil -} - -func (s *state4) VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market4.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err -} - -func (s *state4) NextID() (abi.DealID, error) { - return s.State.NextID, nil -} - -type balanceTable4 struct { - *adt4.BalanceTable -} - -func (bt *balanceTable4) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*adt4.Map)(bt.BalanceTable) - var ta abi.TokenAmount - return asMap.ForEach(&ta, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - return cb(a, ta) - }) -} - type dealStates4 struct { adt.Array } @@ -187,14 +137,24 @@ func (s *dealProposals4) Get(dealID abi.DealID) (*DealProposal, bool, error) { if !found { return nil, false, nil } - proposal := fromV4DealProposal(proposal4) + + proposal, err := fromV4DealProposal(proposal4) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + return &proposal, true, nil } func (s *dealProposals4) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { var dp4 market4.DealProposal return s.Array.ForEach(&dp4, func(idx int64) error { - return cb(abi.DealID(idx), fromV4DealProposal(dp4)) + dp, err := fromV4DealProposal(dp4) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) }) } @@ -203,7 +163,12 @@ func (s *dealProposals4) decode(val *cbg.Deferred) (*DealProposal, error) { if err := dp4.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV4DealProposal(dp4) + + dp, err := fromV4DealProposal(dp4) + if err != nil { + return nil, err + } + return &dp, nil } @@ -211,8 +176,29 @@ func (s *dealProposals4) array() adt.Array { return s.Array } -func fromV4DealProposal(v4 market4.DealProposal) DealProposal { - return (DealProposal)(v4) +func fromV4DealProposal(v4 market4.DealProposal) (DealProposal, error) { + + label, err := labelFromGoString(v4.Label) + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v4.PieceCID, + PieceSize: v4.PieceSize, + VerifiedDeal: v4.VerifiedDeal, + Client: v4.Client, + Provider: v4.Provider, + + Label: label, + + StartEpoch: v4.StartEpoch, + EndEpoch: v4.EndEpoch, + StoragePricePerEpoch: v4.StoragePricePerEpoch, + + ProviderCollateral: v4.ProviderCollateral, + ClientCollateral: v4.ClientCollateral, + }, nil } func (s *state4) DealProposalsAmtBitwidth() int { @@ -222,3 +208,20 @@ func (s *state4) DealProposalsAmtBitwidth() int { func (s *state4) DealStatesAmtBitwidth() int { return market4.StatesAmtBitwidth } + +func (s *state4) ActorKey() string { + return actors.MarketKey +} + +func (s *state4) ActorVersion() actors.Version { + return actors.Version4 +} + +func (s *state4) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/v5.go b/chain/actors/builtin/market/v5.go index 4e1e80c9a..a18868d5a 100644 --- a/chain/actors/builtin/market/v5.go +++ b/chain/actors/builtin/market/v5.go @@ -1,19 +1,19 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( "bytes" + "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" market5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) @@ -29,29 +29,22 @@ func load5(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -type state5 struct { - market5.State - store adt.Store -} +func make5(store adt.Store) (State, error) { + out := state5{store: store} -func (s *state5) Code() cid.Cid { - return builtin5.StorageMarketActorCodeID -} + s, err := market5.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s -func (s *state5) TotalLocked() (abi.TokenAmount, error) { - fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, s.TotalClientStorageFee) - return fml, nil + return &out, nil } -func (s *state5) BalancesChanged(otherState State) (bool, error) { - otherState5, ok := otherState.(*state5) - if !ok { - // there's no way to compare different versions of the state, so let's - // just say that means the state of balances has changed - return true, nil - } - return !s.State.EscrowTable.Equals(otherState5.State.EscrowTable) || !s.State.LockedTable.Equals(otherState5.State.LockedTable), nil +type state5 struct { + market5.State + store adt.Store } func (s *state5) StatesChanged(otherState State) (bool, error) { @@ -90,49 +83,6 @@ func (s *state5) Proposals() (DealProposals, error) { return &dealProposals5{proposalArray}, nil } -func (s *state5) EscrowTable() (BalanceTable, error) { - bt, err := adt5.AsBalanceTable(s.store, s.State.EscrowTable) - if err != nil { - return nil, err - } - return &balanceTable5{bt}, nil -} - -func (s *state5) LockedTable() (BalanceTable, error) { - bt, err := adt5.AsBalanceTable(s.store, s.State.LockedTable) - if err != nil { - return nil, err - } - return &balanceTable5{bt}, nil -} - -func (s *state5) VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market5.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err -} - -func (s *state5) NextID() (abi.DealID, error) { - return s.State.NextID, nil -} - -type balanceTable5 struct { - *adt5.BalanceTable -} - -func (bt *balanceTable5) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*adt5.Map)(bt.BalanceTable) - var ta abi.TokenAmount - return asMap.ForEach(&ta, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - return cb(a, ta) - }) -} - type dealStates5 struct { adt.Array } @@ -187,14 +137,24 @@ func (s *dealProposals5) Get(dealID abi.DealID) (*DealProposal, bool, error) { if !found { return nil, false, nil } - proposal := fromV5DealProposal(proposal5) + + proposal, err := fromV5DealProposal(proposal5) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + return &proposal, true, nil } func (s *dealProposals5) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { var dp5 market5.DealProposal return s.Array.ForEach(&dp5, func(idx int64) error { - return cb(abi.DealID(idx), fromV5DealProposal(dp5)) + dp, err := fromV5DealProposal(dp5) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) }) } @@ -203,7 +163,12 @@ func (s *dealProposals5) decode(val *cbg.Deferred) (*DealProposal, error) { if err := dp5.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV5DealProposal(dp5) + + dp, err := fromV5DealProposal(dp5) + if err != nil { + return nil, err + } + return &dp, nil } @@ -211,8 +176,29 @@ func (s *dealProposals5) array() adt.Array { return s.Array } -func fromV5DealProposal(v5 market5.DealProposal) DealProposal { - return (DealProposal)(v5) +func fromV5DealProposal(v5 market5.DealProposal) (DealProposal, error) { + + label, err := labelFromGoString(v5.Label) + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v5.PieceCID, + PieceSize: v5.PieceSize, + VerifiedDeal: v5.VerifiedDeal, + Client: v5.Client, + Provider: v5.Provider, + + Label: label, + + StartEpoch: v5.StartEpoch, + EndEpoch: v5.EndEpoch, + StoragePricePerEpoch: v5.StoragePricePerEpoch, + + ProviderCollateral: v5.ProviderCollateral, + ClientCollateral: v5.ClientCollateral, + }, nil } func (s *state5) DealProposalsAmtBitwidth() int { @@ -222,3 +208,20 @@ func (s *state5) DealProposalsAmtBitwidth() int { func (s *state5) DealStatesAmtBitwidth() int { return market5.StatesAmtBitwidth } + +func (s *state5) ActorKey() string { + return actors.MarketKey +} + +func (s *state5) ActorVersion() actors.Version { + return actors.Version5 +} + +func (s *state5) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/v6.go b/chain/actors/builtin/market/v6.go index dafbeeb36..eaa559212 100644 --- a/chain/actors/builtin/market/v6.go +++ b/chain/actors/builtin/market/v6.go @@ -1,19 +1,19 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( "bytes" + "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" market6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/market" adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt" ) @@ -29,29 +29,22 @@ func load6(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -type state6 struct { - market6.State - store adt.Store -} +func make6(store adt.Store) (State, error) { + out := state6{store: store} -func (s *state6) Code() cid.Cid { - return builtin6.StorageMarketActorCodeID -} + s, err := market6.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s -func (s *state6) TotalLocked() (abi.TokenAmount, error) { - fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, s.TotalClientStorageFee) - return fml, nil + return &out, nil } -func (s *state6) BalancesChanged(otherState State) (bool, error) { - otherState6, ok := otherState.(*state6) - if !ok { - // there's no way to compare different versions of the state, so let's - // just say that means the state of balances has changed - return true, nil - } - return !s.State.EscrowTable.Equals(otherState6.State.EscrowTable) || !s.State.LockedTable.Equals(otherState6.State.LockedTable), nil +type state6 struct { + market6.State + store adt.Store } func (s *state6) StatesChanged(otherState State) (bool, error) { @@ -90,49 +83,6 @@ func (s *state6) Proposals() (DealProposals, error) { return &dealProposals6{proposalArray}, nil } -func (s *state6) EscrowTable() (BalanceTable, error) { - bt, err := adt6.AsBalanceTable(s.store, s.State.EscrowTable) - if err != nil { - return nil, err - } - return &balanceTable6{bt}, nil -} - -func (s *state6) LockedTable() (BalanceTable, error) { - bt, err := adt6.AsBalanceTable(s.store, s.State.LockedTable) - if err != nil { - return nil, err - } - return &balanceTable6{bt}, nil -} - -func (s *state6) VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market6.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err -} - -func (s *state6) NextID() (abi.DealID, error) { - return s.State.NextID, nil -} - -type balanceTable6 struct { - *adt6.BalanceTable -} - -func (bt *balanceTable6) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*adt6.Map)(bt.BalanceTable) - var ta abi.TokenAmount - return asMap.ForEach(&ta, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - return cb(a, ta) - }) -} - type dealStates6 struct { adt.Array } @@ -187,14 +137,24 @@ func (s *dealProposals6) Get(dealID abi.DealID) (*DealProposal, bool, error) { if !found { return nil, false, nil } - proposal := fromV6DealProposal(proposal6) + + proposal, err := fromV6DealProposal(proposal6) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + return &proposal, true, nil } func (s *dealProposals6) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { var dp6 market6.DealProposal return s.Array.ForEach(&dp6, func(idx int64) error { - return cb(abi.DealID(idx), fromV6DealProposal(dp6)) + dp, err := fromV6DealProposal(dp6) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) }) } @@ -203,7 +163,12 @@ func (s *dealProposals6) decode(val *cbg.Deferred) (*DealProposal, error) { if err := dp6.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV6DealProposal(dp6) + + dp, err := fromV6DealProposal(dp6) + if err != nil { + return nil, err + } + return &dp, nil } @@ -211,8 +176,29 @@ func (s *dealProposals6) array() adt.Array { return s.Array } -func fromV6DealProposal(v6 market6.DealProposal) DealProposal { - return (DealProposal)(v6) +func fromV6DealProposal(v6 market6.DealProposal) (DealProposal, error) { + + label, err := labelFromGoString(v6.Label) + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v6.PieceCID, + PieceSize: v6.PieceSize, + VerifiedDeal: v6.VerifiedDeal, + Client: v6.Client, + Provider: v6.Provider, + + Label: label, + + StartEpoch: v6.StartEpoch, + EndEpoch: v6.EndEpoch, + StoragePricePerEpoch: v6.StoragePricePerEpoch, + + ProviderCollateral: v6.ProviderCollateral, + ClientCollateral: v6.ClientCollateral, + }, nil } func (s *state6) DealProposalsAmtBitwidth() int { @@ -222,3 +208,20 @@ func (s *state6) DealProposalsAmtBitwidth() int { func (s *state6) DealStatesAmtBitwidth() int { return market6.StatesAmtBitwidth } + +func (s *state6) ActorKey() string { + return actors.MarketKey +} + +func (s *state6) ActorVersion() actors.Version { + return actors.Version6 +} + +func (s *state6) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/v7.go b/chain/actors/builtin/market/v7.go index 51a209e92..d25b689c5 100644 --- a/chain/actors/builtin/market/v7.go +++ b/chain/actors/builtin/market/v7.go @@ -1,19 +1,19 @@ // Code generated by: `make actors-gen`. DO NOT EDIT. + package market import ( "bytes" + "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market" adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt" ) @@ -29,29 +29,22 @@ func load7(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -type state7 struct { - market7.State - store adt.Store -} +func make7(store adt.Store) (State, error) { + out := state7{store: store} -func (s *state7) Code() cid.Cid { - return builtin7.StorageMarketActorCodeID -} + s, err := market7.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s -func (s *state7) TotalLocked() (abi.TokenAmount, error) { - fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) - fml = types.BigAdd(fml, s.TotalClientStorageFee) - return fml, nil + return &out, nil } -func (s *state7) BalancesChanged(otherState State) (bool, error) { - otherState7, ok := otherState.(*state7) - if !ok { - // there's no way to compare different versions of the state, so let's - // just say that means the state of balances has changed - return true, nil - } - return !s.State.EscrowTable.Equals(otherState7.State.EscrowTable) || !s.State.LockedTable.Equals(otherState7.State.LockedTable), nil +type state7 struct { + market7.State + store adt.Store } func (s *state7) StatesChanged(otherState State) (bool, error) { @@ -90,49 +83,6 @@ func (s *state7) Proposals() (DealProposals, error) { return &dealProposals7{proposalArray}, nil } -func (s *state7) EscrowTable() (BalanceTable, error) { - bt, err := adt7.AsBalanceTable(s.store, s.State.EscrowTable) - if err != nil { - return nil, err - } - return &balanceTable7{bt}, nil -} - -func (s *state7) LockedTable() (BalanceTable, error) { - bt, err := adt7.AsBalanceTable(s.store, s.State.LockedTable) - if err != nil { - return nil, err - } - return &balanceTable7{bt}, nil -} - -func (s *state7) VerifyDealsForActivation( - minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, -) (weight, verifiedWeight abi.DealWeight, err error) { - w, vw, _, err := market7.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) - return w, vw, err -} - -func (s *state7) NextID() (abi.DealID, error) { - return s.State.NextID, nil -} - -type balanceTable7 struct { - *adt7.BalanceTable -} - -func (bt *balanceTable7) ForEach(cb func(address.Address, abi.TokenAmount) error) error { - asMap := (*adt7.Map)(bt.BalanceTable) - var ta abi.TokenAmount - return asMap.ForEach(&ta, func(key string) error { - a, err := address.NewFromBytes([]byte(key)) - if err != nil { - return err - } - return cb(a, ta) - }) -} - type dealStates7 struct { adt.Array } @@ -187,14 +137,24 @@ func (s *dealProposals7) Get(dealID abi.DealID) (*DealProposal, bool, error) { if !found { return nil, false, nil } - proposal := fromV7DealProposal(proposal7) + + proposal, err := fromV7DealProposal(proposal7) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + return &proposal, true, nil } func (s *dealProposals7) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { var dp7 market7.DealProposal return s.Array.ForEach(&dp7, func(idx int64) error { - return cb(abi.DealID(idx), fromV7DealProposal(dp7)) + dp, err := fromV7DealProposal(dp7) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) }) } @@ -203,7 +163,12 @@ func (s *dealProposals7) decode(val *cbg.Deferred) (*DealProposal, error) { if err := dp7.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return nil, err } - dp := fromV7DealProposal(dp7) + + dp, err := fromV7DealProposal(dp7) + if err != nil { + return nil, err + } + return &dp, nil } @@ -211,8 +176,29 @@ func (s *dealProposals7) array() adt.Array { return s.Array } -func fromV7DealProposal(v7 market7.DealProposal) DealProposal { - return (DealProposal)(v7) +func fromV7DealProposal(v7 market7.DealProposal) (DealProposal, error) { + + label, err := labelFromGoString(v7.Label) + if err != nil { + return DealProposal{}, xerrors.Errorf("error setting deal label: %w", err) + } + + return DealProposal{ + PieceCID: v7.PieceCID, + PieceSize: v7.PieceSize, + VerifiedDeal: v7.VerifiedDeal, + Client: v7.Client, + Provider: v7.Provider, + + Label: label, + + StartEpoch: v7.StartEpoch, + EndEpoch: v7.EndEpoch, + StoragePricePerEpoch: v7.StoragePricePerEpoch, + + ProviderCollateral: v7.ProviderCollateral, + ClientCollateral: v7.ClientCollateral, + }, nil } func (s *state7) DealProposalsAmtBitwidth() int { @@ -222,3 +208,20 @@ func (s *state7) DealProposalsAmtBitwidth() int { func (s *state7) DealStatesAmtBitwidth() int { return market7.StatesAmtBitwidth } + +func (s *state7) ActorKey() string { + return actors.MarketKey +} + +func (s *state7) ActorVersion() actors.Version { + return actors.Version7 +} + +func (s *state7) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/market/v8.go b/chain/actors/builtin/market/v8.go new file mode 100644 index 000000000..d5aee0d68 --- /dev/null +++ b/chain/actors/builtin/market/v8.go @@ -0,0 +1,224 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. + +package market + +import ( + "bytes" + "fmt" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" + adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt" +) + +var _ State = (*state8)(nil) + +func load8(store adt.Store, root cid.Cid) (State, error) { + out := state8{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make8(store adt.Store) (State, error) { + out := state8{store: store} + + s, err := market8.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + +type state8 struct { + market8.State + store adt.Store +} + +func (s *state8) StatesChanged(otherState State) (bool, error) { + otherState8, ok := otherState.(*state8) + if !ok { + // there's no way to compare different versions of the state, so let's + // just say that means the state of balances has changed + return true, nil + } + return !s.State.States.Equals(otherState8.State.States), nil +} + +func (s *state8) States() (DealStates, error) { + stateArray, err := adt8.AsArray(s.store, s.State.States, market8.StatesAmtBitwidth) + if err != nil { + return nil, err + } + return &dealStates8{stateArray}, nil +} + +func (s *state8) ProposalsChanged(otherState State) (bool, error) { + otherState8, ok := otherState.(*state8) + if !ok { + // there's no way to compare different versions of the state, so let's + // just say that means the state of balances has changed + return true, nil + } + return !s.State.Proposals.Equals(otherState8.State.Proposals), nil +} + +func (s *state8) Proposals() (DealProposals, error) { + proposalArray, err := adt8.AsArray(s.store, s.State.Proposals, market8.ProposalsAmtBitwidth) + if err != nil { + return nil, err + } + return &dealProposals8{proposalArray}, nil +} + +type dealStates8 struct { + adt.Array +} + +func (s *dealStates8) Get(dealID abi.DealID) (*DealState, bool, error) { + var deal8 market8.DealState + found, err := s.Array.Get(uint64(dealID), &deal8) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + deal := fromV8DealState(deal8) + return &deal, true, nil +} + +func (s *dealStates8) ForEach(cb func(dealID abi.DealID, ds DealState) error) error { + var ds8 market8.DealState + return s.Array.ForEach(&ds8, func(idx int64) error { + return cb(abi.DealID(idx), fromV8DealState(ds8)) + }) +} + +func (s *dealStates8) decode(val *cbg.Deferred) (*DealState, error) { + var ds8 market8.DealState + if err := ds8.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err + } + ds := fromV8DealState(ds8) + return &ds, nil +} + +func (s *dealStates8) array() adt.Array { + return s.Array +} + +func fromV8DealState(v8 market8.DealState) DealState { + return (DealState)(v8) +} + +type dealProposals8 struct { + adt.Array +} + +func (s *dealProposals8) Get(dealID abi.DealID) (*DealProposal, bool, error) { + var proposal8 market8.DealProposal + found, err := s.Array.Get(uint64(dealID), &proposal8) + if err != nil { + return nil, false, err + } + if !found { + return nil, false, nil + } + + proposal, err := fromV8DealProposal(proposal8) + if err != nil { + return nil, true, xerrors.Errorf("decoding proposal: %w", err) + } + + return &proposal, true, nil +} + +func (s *dealProposals8) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error { + var dp8 market8.DealProposal + return s.Array.ForEach(&dp8, func(idx int64) error { + dp, err := fromV8DealProposal(dp8) + if err != nil { + return xerrors.Errorf("decoding proposal: %w", err) + } + + return cb(abi.DealID(idx), dp) + }) +} + +func (s *dealProposals8) decode(val *cbg.Deferred) (*DealProposal, error) { + var dp8 market8.DealProposal + if err := dp8.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return nil, err + } + + dp, err := fromV8DealProposal(dp8) + if err != nil { + return nil, err + } + + return &dp, nil +} + +func (s *dealProposals8) array() adt.Array { + return s.Array +} + +func fromV8DealProposal(v8 market8.DealProposal) (DealProposal, error) { + + label := v8.Label + + return DealProposal{ + PieceCID: v8.PieceCID, + PieceSize: v8.PieceSize, + VerifiedDeal: v8.VerifiedDeal, + Client: v8.Client, + Provider: v8.Provider, + + Label: label, + + StartEpoch: v8.StartEpoch, + EndEpoch: v8.EndEpoch, + StoragePricePerEpoch: v8.StoragePricePerEpoch, + + ProviderCollateral: v8.ProviderCollateral, + ClientCollateral: v8.ClientCollateral, + }, nil +} + +func (s *state8) DealProposalsAmtBitwidth() int { + return market8.ProposalsAmtBitwidth +} + +func (s *state8) DealStatesAmtBitwidth() int { + return market8.StatesAmtBitwidth +} + +func (s *state8) ActorKey() string { + return actors.MarketKey +} + +func (s *state8) ActorVersion() actors.Version { + return actors.Version8 +} + +func (s *state8) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/actor.go.template b/chain/actors/builtin/miner/actor.go.template index 42c751954..4c380c992 100644 --- a/chain/actors/builtin/miner/actor.go.template +++ b/chain/actors/builtin/miner/actor.go.template @@ -2,79 +2,75 @@ package miner import ( -"fmt" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" - "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" + lotusactors "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lily/chain/actors" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/ipfs/go-cid" + "golang.org/x/xerrors" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/go-state-types/proof" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" + miner{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin{{import .latestVersion}}miner" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" - - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" -{{- end}} + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{end}} +{{end}} ) -func init() { +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.MinerKey { + return nil, xerrors.Errorf("actor code is not miner: %s", name) + } + + switch actors.Version(av) { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + + switch act.Code { {{range .versions}} - builtin.RegisterActorState(builtin{{.}}.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) + {{if (le . 7)}} + case builtin{{.}}.StorageMinerActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} -} - -var Methods = builtin{{.latestVersion}}.MethodsMiner + } -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.StorageMinerActorCodeID, - {{- end}} - } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } -// Unchanged between v0, v2, v3, and v4 actors -var WPoStProvingPeriod = miner0.WPoStProvingPeriod -var WPoStPeriodDeadlines = miner0.WPoStPeriodDeadlines -var WPoStChallengeWindow = miner0.WPoStChallengeWindow -var WPoStChallengeLookback = miner0.WPoStChallengeLookback -var FaultDeclarationCutoff = miner0.FaultDeclarationCutoff - -const MinSectorExpiration = miner0.MinSectorExpiration - -// Not used / checked in v0 -// TODO: Abstract over network versions -var DeclarationsMax = miner2.DeclarationsMax -var AddressedSectorsMax = miner2.AddressedSectorsMax - -func Load(store adt.Store, act *types.Actor) (State, error) { - switch act.Code { +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { {{range .versions}} - case builtin{{.}}.StorageMinerActorCodeID: - return load{{.}}(store, act.Head) + case actors.Version{{.}}: + return make{{.}}(store) {{end}} } - return nil, fmt.Errorf("unknown actor code %s", act.Code) + return nil, xerrors.Errorf("unknown actor version %d", av) } type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version // Total available balance to spend. AvailableBalance(abi.TokenAmount) (abi.TokenAmount, error) @@ -87,18 +83,20 @@ type State interface { GetSector(abi.SectorNumber) (*SectorOnChainInfo, error) FindSector(abi.SectorNumber) (*SectorLocation, error) GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) - GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) - ForEachPrecommittedSector(func(SectorPreCommitOnChainInfo) error) error + GetPrecommittedSector(abi.SectorNumber) (*miner{{.latestVersion}}.SectorPreCommitOnChainInfo, error) + ForEachPrecommittedSector(func(miner{{.latestVersion}}.SectorPreCommitOnChainInfo) error) error LoadSectors(sectorNos *bitfield.BitField) ([]*SectorOnChainInfo, error) NumLiveSectors() (uint64, error) IsAllocated(abi.SectorNumber) (bool, error) - // UnallocatedSectorNumbers returns up to count unallocated sector numbers (or less than - // count if there aren't enough). + // UnallocatedSectorNumbers returns up to count unallocated sector numbers (or less than + // count if there aren't enough). UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) GetAllocatedSectors() (*bitfield.BitField, error) // Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors GetProvingPeriodStart() (abi.ChainEpoch, error) + // Testing only + EraseAllUnproven() error LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error @@ -111,15 +109,17 @@ type State interface { DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) DeadlineCronActive() (bool, error) - SectorsAmtBitwidth() int - GetState() interface{} // Diff helpers. Used by Diff* functions internally. - SectorArray() (adt.Array, error) + SectorsArray() (adt.Array, error) + SectorsAmtBitwidth() int DecodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error) - PreCommitMap() (adt.Map, error) - DecodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error) + + PrecommitsMap() (adt.Map, error) + PrecommitsMapBitWidth() int + PrecommitsMapHashFunction() func(input []byte) []byte + DecodeSectorPreCommitOnChainInfo(*cbg.Deferred) (miner{{.latestVersion}}.SectorPreCommitOnChainInfo, error) } type Deadline interface { @@ -156,44 +156,7 @@ type Partition interface { UnprovenSectors() (bitfield.BitField, error) } - -type SectorOnChainInfo struct { - SectorNumber abi.SectorNumber - SealProof abi.RegisteredSealProof - SealedCID cid.Cid - DealIDs []abi.DealID - Activation abi.ChainEpoch - Expiration abi.ChainEpoch - DealWeight abi.DealWeight - VerifiedDealWeight abi.DealWeight - InitialPledge abi.TokenAmount - ExpectedDayReward abi.TokenAmount - ExpectedStoragePledge abi.TokenAmount - SectorKeyCID *cid.Cid -} - -type SectorPreCommitInfo = miner0.SectorPreCommitInfo - -type SectorPreCommitOnChainInfo struct { - Info SectorPreCommitInfo - PreCommitDeposit abi.TokenAmount - PreCommitEpoch abi.ChainEpoch - DealWeight abi.DealWeight - VerifiedDealWeight abi.DealWeight -} - -type PoStPartition = miner0.PoStPartition -type RecoveryDeclaration = miner0.RecoveryDeclaration -type FaultDeclaration = miner0.FaultDeclaration - -// Params -type DeclareFaultsParams = miner0.DeclareFaultsParams -type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams -type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams -type ProveCommitSectorParams = miner0.ProveCommitSectorParams -type DisputeWindowedPoStParams = miner3.DisputeWindowedPoStParams -type ProveCommitAggregateParams = miner5.ProveCommitAggregateParams -type ProveReplicaUpdatesParams = miner7.ProveReplicaUpdatesParams +type SectorOnChainInfo = miner{{.latestVersion}}.SectorOnChainInfo func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { // We added support for the new proofs in network version 7, and removed support for the old @@ -211,7 +174,7 @@ func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.Re case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: return abi.RegisteredSealProof_StackedDrg64GiBV1, nil default: - return -1, fmt.Errorf("unrecognized window post type: %d", proof) + return -1, xerrors.Errorf("unrecognized window post type: %d", proof) } } @@ -227,7 +190,7 @@ func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.Re case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil default: - return -1, fmt.Errorf("unrecognized window post type: %d", proof) + return -1, xerrors.Errorf("unrecognized window post type: %d", proof) } } @@ -244,37 +207,13 @@ func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: return abi.RegisteredPoStProof_StackedDrgWinning64GiBV1, nil default: - return -1, fmt.Errorf("unknown proof type %d", proof) + return -1, xerrors.Errorf("unknown proof type %d", proof) } } -type MinerInfo struct { - Owner address.Address // Must be an ID-address. - Worker address.Address // Must be an ID-address. - NewWorker address.Address // Must be an ID-address. - ControlAddresses []address.Address // Must be an ID-addresses. - WorkerChangeEpoch abi.ChainEpoch - PeerId *peer.ID - Multiaddrs []abi.Multiaddrs - WindowPoStProofType abi.RegisteredPoStProof - SectorSize abi.SectorSize - WindowPoStPartitionSectors uint64 - ConsensusFaultElapsed abi.ChainEpoch -} - -func (mi MinerInfo) IsController(addr address.Address) bool { - if addr == mi.Owner || addr == mi.Worker { - return true - } - - for _, ca := range mi.ControlAddresses { - if addr == ca { - return true - } - } - - return false -} +type MinerInfo = miner{{.latestVersion}}.MinerInfo +type WorkerKeyChange = miner{{.latestVersion}}.WorkerKeyChange +type WindowPostVerifyInfo = proof.WindowPoStVerifyInfo type SectorExpiration struct { OnTime abi.ChainEpoch @@ -289,21 +228,14 @@ type SectorLocation struct { Partition uint64 } -type SectorChanges struct { - Added []SectorOnChainInfo - Extended []SectorModification - Snapped []SectorModification - Removed []SectorOnChainInfo -} - -type SectorModification struct { +type SectorExtensions struct { From SectorOnChainInfo To SectorOnChainInfo } type PreCommitChanges struct { - Added []SectorPreCommitOnChainInfo - Removed []SectorPreCommitOnChainInfo + Added []miner{{.latestVersion}}.SectorPreCommitOnChainInfo + Removed []miner{{.latestVersion}}.SectorPreCommitOnChainInfo } type LockedFunds struct { @@ -315,3 +247,31 @@ type LockedFunds struct { func (lf LockedFunds) TotalLockedFunds() abi.TokenAmount { return big.Add(lf.VestingFunds, big.Add(lf.InitialPledgeRequirement, lf.PreCommitDeposits)) } + +type SectorChanges struct { + Added []SectorOnChainInfo + Extended []SectorModification + Snapped []SectorModification + Removed []SectorOnChainInfo +} + +type SectorModification struct { + From SectorOnChainInfo + To SectorOnChainInfo +} + + +func AllCodes() []cid.Cid { + return []cid.Cid{ {{range .versions}} + (&state{{.}}{}).Code(), + {{- end}} + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + {{- range .versions}} + actors.Version{{.}}: (&state{{.}}{}).Code(), + {{- end}} + } +} diff --git a/chain/actors/builtin/miner/diff.go b/chain/actors/builtin/miner/diff.go index a0b159111..eb8763d86 100644 --- a/chain/actors/builtin/miner/diff.go +++ b/chain/actors/builtin/miner/diff.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-amt-ipld/v4" "github.com/filecoin-project/go-hamt-ipld/v3" "github.com/filecoin-project/go-state-types/abi" + miner8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" cbg "github.com/whyrusleeping/cbor-gen" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -21,27 +22,26 @@ import ( func DiffPreCommits(ctx context.Context, store adt.Store, pre, cur State) (*PreCommitChanges, error) { ctx, span := otel.Tracer("").Start(ctx, "DiffPreCommits") defer span.End() - prep, err := pre.PreCommitMap() + prep, err := pre.PrecommitsMap() if err != nil { return nil, err } - curp, err := cur.PreCommitMap() - if err != nil { - return nil, err - } - - preOpts, err := adt.MapOptsForActorCode(pre.Code()) - if err != nil { - return nil, err - } - curOpts, err := adt.MapOptsForActorCode(cur.Code()) + curp, err := cur.PrecommitsMap() if err != nil { return nil, err } diffContainer := NewPreCommitDiffContainer(pre, cur) - if MapRequiresLegacyDiffing(pre, cur, preOpts, curOpts) { + if MapRequiresLegacyDiffing(pre, cur, + &adt.MapOpts{ + Bitwidth: pre.SectorsAmtBitwidth(), + HashFunc: pre.PrecommitsMapHashFunction(), + }, + &adt.MapOpts{ + Bitwidth: cur.PrecommitsMapBitWidth(), + HashFunc: cur.PrecommitsMapHashFunction(), + }) { if span.IsRecording() { span.SetAttributes(attribute.String("diff", "slow")) } @@ -55,7 +55,7 @@ func DiffPreCommits(ctx context.Context, store adt.Store, pre, cur State) (*PreC span.SetAttributes(attribute.String("diff", "fast")) } - changes, err := diff.Hamt(ctx, prep, curp, store, store, hamt.UseHashFunction(hamt.HashFunc(preOpts.HashFunc)), hamt.UseTreeBitWidth(preOpts.Bitwidth)) + changes, err := diff.Hamt(ctx, prep, curp, store, store, hamt.UseHashFunction(pre.PrecommitsMapHashFunction()), hamt.UseTreeBitWidth(pre.PrecommitsMapBitWidth())) if err != nil { return nil, err } @@ -90,8 +90,8 @@ func MakeSectorChanges() *SectorChanges { func MakePreCommitChanges() *PreCommitChanges { return &PreCommitChanges{ - Added: []SectorPreCommitOnChainInfo{}, - Removed: []SectorPreCommitOnChainInfo{}, + Added: []miner8.SectorPreCommitOnChainInfo{}, + Removed: []miner8.SectorPreCommitOnChainInfo{}, } } @@ -141,12 +141,12 @@ func (m *preCommitDiffContainer) Remove(key string, val *cbg.Deferred) error { func DiffSectors(ctx context.Context, store adt.Store, pre, cur State) (*SectorChanges, error) { ctx, span := otel.Tracer("").Start(ctx, "DiffSectors") defer span.End() - pres, err := pre.SectorArray() + pres, err := pre.SectorsArray() if err != nil { return nil, err } - curs, err := cur.SectorArray() + curs, err := cur.SectorsArray() if err != nil { return nil, err } diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 8d53e56f8..b92f75774 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -2,100 +2,53 @@ package miner import ( - "fmt" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lily/chain/actors" + lotusactors "github.com/filecoin-project/lotus/chain/actors" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/go-state-types/proof" + miner8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" - - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" + builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" + builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" + builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" ) -func init() { - - builtin.RegisterActorState(builtin0.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) - - builtin.RegisterActorState(builtin3.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) - - builtin.RegisterActorState(builtin5.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) - - builtin.RegisterActorState(builtin6.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.MinerKey { + return nil, xerrors.Errorf("actor code is not miner: %s", name) + } - builtin.RegisterActorState(builtin7.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) + switch actors.Version(av) { -} + case actors.Version8: + return load8(store, act.Head) -var Methods = builtin7.MethodsMiner - -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.StorageMinerActorCodeID, - builtin2.StorageMinerActorCodeID, - builtin3.StorageMinerActorCodeID, - builtin4.StorageMinerActorCodeID, - builtin5.StorageMinerActorCodeID, - builtin6.StorageMinerActorCodeID, - builtin7.StorageMinerActorCodeID, + } } -} -// Unchanged between v0, v2, v3, and v4 actors -var WPoStProvingPeriod = miner0.WPoStProvingPeriod -var WPoStPeriodDeadlines = miner0.WPoStPeriodDeadlines -var WPoStChallengeWindow = miner0.WPoStChallengeWindow -var WPoStChallengeLookback = miner0.WPoStChallengeLookback -var FaultDeclarationCutoff = miner0.FaultDeclarationCutoff - -const MinSectorExpiration = miner0.MinSectorExpiration - -// Not used / checked in v0 -// TODO: Abstract over network versions -var DeclarationsMax = miner2.DeclarationsMax -var AddressedSectorsMax = miner2.AddressedSectorsMax - -func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { case builtin0.StorageMinerActorCodeID: @@ -120,13 +73,47 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } - return nil, fmt.Errorf("unknown actor code %s", act.Code) + + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { + + case actors.Version0: + return make0(store) + + case actors.Version2: + return make2(store) + + case actors.Version3: + return make3(store) + + case actors.Version4: + return make4(store) + + case actors.Version5: + return make5(store) + + case actors.Version6: + return make6(store) + + case actors.Version7: + return make7(store) + + case actors.Version8: + return make8(store) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) } type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version // Total available balance to spend. AvailableBalance(abi.TokenAmount) (abi.TokenAmount, error) @@ -139,8 +126,8 @@ type State interface { GetSector(abi.SectorNumber) (*SectorOnChainInfo, error) FindSector(abi.SectorNumber) (*SectorLocation, error) GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error) - GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) - ForEachPrecommittedSector(func(SectorPreCommitOnChainInfo) error) error + GetPrecommittedSector(abi.SectorNumber) (*miner8.SectorPreCommitOnChainInfo, error) + ForEachPrecommittedSector(func(miner8.SectorPreCommitOnChainInfo) error) error LoadSectors(sectorNos *bitfield.BitField) ([]*SectorOnChainInfo, error) NumLiveSectors() (uint64, error) IsAllocated(abi.SectorNumber) (bool, error) @@ -151,6 +138,8 @@ type State interface { // Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors GetProvingPeriodStart() (abi.ChainEpoch, error) + // Testing only + EraseAllUnproven() error LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error @@ -163,15 +152,17 @@ type State interface { DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) DeadlineCronActive() (bool, error) - SectorsAmtBitwidth() int - GetState() interface{} // Diff helpers. Used by Diff* functions internally. - SectorArray() (adt.Array, error) + SectorsArray() (adt.Array, error) + SectorsAmtBitwidth() int DecodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error) - PreCommitMap() (adt.Map, error) - DecodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error) + + PrecommitsMap() (adt.Map, error) + PrecommitsMapBitWidth() int + PrecommitsMapHashFunction() func(input []byte) []byte + DecodeSectorPreCommitOnChainInfo(*cbg.Deferred) (miner8.SectorPreCommitOnChainInfo, error) } type Deadline interface { @@ -208,43 +199,7 @@ type Partition interface { UnprovenSectors() (bitfield.BitField, error) } -type SectorOnChainInfo struct { - SectorNumber abi.SectorNumber - SealProof abi.RegisteredSealProof - SealedCID cid.Cid - DealIDs []abi.DealID - Activation abi.ChainEpoch - Expiration abi.ChainEpoch - DealWeight abi.DealWeight - VerifiedDealWeight abi.DealWeight - InitialPledge abi.TokenAmount - ExpectedDayReward abi.TokenAmount - ExpectedStoragePledge abi.TokenAmount - SectorKeyCID *cid.Cid -} - -type SectorPreCommitInfo = miner0.SectorPreCommitInfo - -type SectorPreCommitOnChainInfo struct { - Info SectorPreCommitInfo - PreCommitDeposit abi.TokenAmount - PreCommitEpoch abi.ChainEpoch - DealWeight abi.DealWeight - VerifiedDealWeight abi.DealWeight -} - -type PoStPartition = miner0.PoStPartition -type RecoveryDeclaration = miner0.RecoveryDeclaration -type FaultDeclaration = miner0.FaultDeclaration - -// Params -type DeclareFaultsParams = miner0.DeclareFaultsParams -type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams -type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams -type ProveCommitSectorParams = miner0.ProveCommitSectorParams -type DisputeWindowedPoStParams = miner3.DisputeWindowedPoStParams -type ProveCommitAggregateParams = miner5.ProveCommitAggregateParams -type ProveReplicaUpdatesParams = miner7.ProveReplicaUpdatesParams +type SectorOnChainInfo = miner8.SectorOnChainInfo func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredSealProof, error) { // We added support for the new proofs in network version 7, and removed support for the old @@ -262,7 +217,7 @@ func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.Re case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: return abi.RegisteredSealProof_StackedDrg64GiBV1, nil default: - return -1, fmt.Errorf("unrecognized window post type: %d", proof) + return -1, xerrors.Errorf("unrecognized window post type: %d", proof) } } @@ -278,7 +233,7 @@ func PreferredSealProofTypeFromWindowPoStType(nver network.Version, proof abi.Re case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil default: - return -1, fmt.Errorf("unrecognized window post type: %d", proof) + return -1, xerrors.Errorf("unrecognized window post type: %d", proof) } } @@ -295,37 +250,13 @@ func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1: return abi.RegisteredPoStProof_StackedDrgWinning64GiBV1, nil default: - return -1, fmt.Errorf("unknown proof type %d", proof) + return -1, xerrors.Errorf("unknown proof type %d", proof) } } -type MinerInfo struct { - Owner address.Address // Must be an ID-address. - Worker address.Address // Must be an ID-address. - NewWorker address.Address // Must be an ID-address. - ControlAddresses []address.Address // Must be an ID-addresses. - WorkerChangeEpoch abi.ChainEpoch - PeerId *peer.ID - Multiaddrs []abi.Multiaddrs - WindowPoStProofType abi.RegisteredPoStProof - SectorSize abi.SectorSize - WindowPoStPartitionSectors uint64 - ConsensusFaultElapsed abi.ChainEpoch -} - -func (mi MinerInfo) IsController(addr address.Address) bool { - if addr == mi.Owner || addr == mi.Worker { - return true - } - - for _, ca := range mi.ControlAddresses { - if addr == ca { - return true - } - } - - return false -} +type MinerInfo = miner8.MinerInfo +type WorkerKeyChange = miner8.WorkerKeyChange +type WindowPostVerifyInfo = proof.WindowPoStVerifyInfo type SectorExpiration struct { OnTime abi.ChainEpoch @@ -340,21 +271,14 @@ type SectorLocation struct { Partition uint64 } -type SectorChanges struct { - Added []SectorOnChainInfo - Extended []SectorModification - Snapped []SectorModification - Removed []SectorOnChainInfo -} - -type SectorModification struct { +type SectorExtensions struct { From SectorOnChainInfo To SectorOnChainInfo } type PreCommitChanges struct { - Added []SectorPreCommitOnChainInfo - Removed []SectorPreCommitOnChainInfo + Added []miner8.SectorPreCommitOnChainInfo + Removed []miner8.SectorPreCommitOnChainInfo } type LockedFunds struct { @@ -366,3 +290,41 @@ type LockedFunds struct { func (lf LockedFunds) TotalLockedFunds() abi.TokenAmount { return big.Add(lf.VestingFunds, big.Add(lf.InitialPledgeRequirement, lf.PreCommitDeposits)) } + +type SectorChanges struct { + Added []SectorOnChainInfo + Extended []SectorModification + Snapped []SectorModification + Removed []SectorOnChainInfo +} + +type SectorModification struct { + From SectorOnChainInfo + To SectorOnChainInfo +} + +func AllCodes() []cid.Cid { + return []cid.Cid{ + (&state0{}).Code(), + (&state2{}).Code(), + (&state3{}).Code(), + (&state4{}).Code(), + (&state5{}).Code(), + (&state6{}).Code(), + (&state7{}).Code(), + (&state8{}).Code(), + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + actors.Version0: (&state0{}).Code(), + actors.Version2: (&state2{}).Code(), + actors.Version3: (&state3{}).Code(), + actors.Version4: (&state4{}).Code(), + actors.Version5: (&state5{}).Code(), + actors.Version6: (&state6{}).Code(), + actors.Version7: (&state7{}).Code(), + actors.Version8: (&state8{}).Code(), + } +} diff --git a/chain/actors/builtin/miner/mocks/state.go b/chain/actors/builtin/miner/mocks/state.go index 2964d5a6d..39051335b 100644 --- a/chain/actors/builtin/miner/mocks/state.go +++ b/chain/actors/builtin/miner/mocks/state.go @@ -4,7 +4,9 @@ package mocks import ( abi "github.com/filecoin-project/go-state-types/abi" - adt "github.com/filecoin-project/lily/chain/actors/adt" + actors "github.com/filecoin-project/lily/chain/actors" + + adt "github.com/filecoin-project/lotus/chain/actors/adt" big "github.com/filecoin-project/go-state-types/big" @@ -21,6 +23,8 @@ import ( mock "github.com/stretchr/testify/mock" typegen "github.com/whyrusleeping/cbor-gen" + + v8miner "github.com/filecoin-project/go-state-types/builtin/v8/miner" ) // State is an autogenerated mock type for the State type @@ -28,6 +32,34 @@ type State struct { mock.Mock } +// ActorKey provides a mock function with given fields: +func (_m *State) ActorKey() string { + ret := _m.Called() + + var r0 string + if rf, ok := ret.Get(0).(func() string); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(string) + } + + return r0 +} + +// ActorVersion provides a mock function with given fields: +func (_m *State) ActorVersion() actors.Version { + ret := _m.Called() + + var r0 actors.Version + if rf, ok := ret.Get(0).(func() actors.Version); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(actors.Version) + } + + return r0 +} + // AvailableBalance provides a mock function with given fields: _a0 func (_m *State) AvailableBalance(_a0 big.Int) (big.Int, error) { ret := _m.Called(_a0) @@ -129,14 +161,14 @@ func (_m *State) DeadlinesChanged(_a0 miner.State) (bool, error) { } // DecodeSectorOnChainInfo provides a mock function with given fields: _a0 -func (_m *State) DecodeSectorOnChainInfo(_a0 *typegen.Deferred) (miner.SectorOnChainInfo, error) { +func (_m *State) DecodeSectorOnChainInfo(_a0 *typegen.Deferred) (v8miner.SectorOnChainInfo, error) { ret := _m.Called(_a0) - var r0 miner.SectorOnChainInfo - if rf, ok := ret.Get(0).(func(*typegen.Deferred) miner.SectorOnChainInfo); ok { + var r0 v8miner.SectorOnChainInfo + if rf, ok := ret.Get(0).(func(*typegen.Deferred) v8miner.SectorOnChainInfo); ok { r0 = rf(_a0) } else { - r0 = ret.Get(0).(miner.SectorOnChainInfo) + r0 = ret.Get(0).(v8miner.SectorOnChainInfo) } var r1 error @@ -150,14 +182,14 @@ func (_m *State) DecodeSectorOnChainInfo(_a0 *typegen.Deferred) (miner.SectorOnC } // DecodeSectorPreCommitOnChainInfo provides a mock function with given fields: _a0 -func (_m *State) DecodeSectorPreCommitOnChainInfo(_a0 *typegen.Deferred) (miner.SectorPreCommitOnChainInfo, error) { +func (_m *State) DecodeSectorPreCommitOnChainInfo(_a0 *typegen.Deferred) (v8miner.SectorPreCommitOnChainInfo, error) { ret := _m.Called(_a0) - var r0 miner.SectorPreCommitOnChainInfo - if rf, ok := ret.Get(0).(func(*typegen.Deferred) miner.SectorPreCommitOnChainInfo); ok { + var r0 v8miner.SectorPreCommitOnChainInfo + if rf, ok := ret.Get(0).(func(*typegen.Deferred) v8miner.SectorPreCommitOnChainInfo); ok { r0 = rf(_a0) } else { - r0 = ret.Get(0).(miner.SectorPreCommitOnChainInfo) + r0 = ret.Get(0).(v8miner.SectorPreCommitOnChainInfo) } var r1 error @@ -170,6 +202,20 @@ func (_m *State) DecodeSectorPreCommitOnChainInfo(_a0 *typegen.Deferred) (miner. return r0, r1 } +// EraseAllUnproven provides a mock function with given fields: +func (_m *State) EraseAllUnproven() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + // FeeDebt provides a mock function with given fields: func (_m *State) FeeDebt() (big.Int, error) { ret := _m.Called() @@ -229,11 +275,11 @@ func (_m *State) ForEachDeadline(cb func(uint64, miner.Deadline) error) error { } // ForEachPrecommittedSector provides a mock function with given fields: _a0 -func (_m *State) ForEachPrecommittedSector(_a0 func(miner.SectorPreCommitOnChainInfo) error) error { +func (_m *State) ForEachPrecommittedSector(_a0 func(v8miner.SectorPreCommitOnChainInfo) error) error { ret := _m.Called(_a0) var r0 error - if rf, ok := ret.Get(0).(func(func(miner.SectorPreCommitOnChainInfo) error) error); ok { + if rf, ok := ret.Get(0).(func(func(v8miner.SectorPreCommitOnChainInfo) error) error); ok { r0 = rf(_a0) } else { r0 = ret.Error(0) @@ -266,15 +312,15 @@ func (_m *State) GetAllocatedSectors() (*bitfield.BitField, error) { } // GetPrecommittedSector provides a mock function with given fields: _a0 -func (_m *State) GetPrecommittedSector(_a0 abi.SectorNumber) (*miner.SectorPreCommitOnChainInfo, error) { +func (_m *State) GetPrecommittedSector(_a0 abi.SectorNumber) (*v8miner.SectorPreCommitOnChainInfo, error) { ret := _m.Called(_a0) - var r0 *miner.SectorPreCommitOnChainInfo - if rf, ok := ret.Get(0).(func(abi.SectorNumber) *miner.SectorPreCommitOnChainInfo); ok { + var r0 *v8miner.SectorPreCommitOnChainInfo + if rf, ok := ret.Get(0).(func(abi.SectorNumber) *v8miner.SectorPreCommitOnChainInfo); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*miner.SectorPreCommitOnChainInfo) + r0 = ret.Get(0).(*v8miner.SectorPreCommitOnChainInfo) } } @@ -310,15 +356,15 @@ func (_m *State) GetProvingPeriodStart() (abi.ChainEpoch, error) { } // GetSector provides a mock function with given fields: _a0 -func (_m *State) GetSector(_a0 abi.SectorNumber) (*miner.SectorOnChainInfo, error) { +func (_m *State) GetSector(_a0 abi.SectorNumber) (*v8miner.SectorOnChainInfo, error) { ret := _m.Called(_a0) - var r0 *miner.SectorOnChainInfo - if rf, ok := ret.Get(0).(func(abi.SectorNumber) *miner.SectorOnChainInfo); ok { + var r0 *v8miner.SectorOnChainInfo + if rf, ok := ret.Get(0).(func(abi.SectorNumber) *v8miner.SectorOnChainInfo); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*miner.SectorOnChainInfo) + r0 = ret.Get(0).(*v8miner.SectorOnChainInfo) } } @@ -372,14 +418,14 @@ func (_m *State) GetState() interface{} { } // Info provides a mock function with given fields: -func (_m *State) Info() (miner.MinerInfo, error) { +func (_m *State) Info() (v8miner.MinerInfo, error) { ret := _m.Called() - var r0 miner.MinerInfo - if rf, ok := ret.Get(0).(func() miner.MinerInfo); ok { + var r0 v8miner.MinerInfo + if rf, ok := ret.Get(0).(func() v8miner.MinerInfo); ok { r0 = rf() } else { - r0 = ret.Get(0).(miner.MinerInfo) + r0 = ret.Get(0).(v8miner.MinerInfo) } var r1 error @@ -437,15 +483,15 @@ func (_m *State) LoadDeadline(idx uint64) (miner.Deadline, error) { } // LoadSectors provides a mock function with given fields: sectorNos -func (_m *State) LoadSectors(sectorNos *bitfield.BitField) ([]*miner.SectorOnChainInfo, error) { +func (_m *State) LoadSectors(sectorNos *bitfield.BitField) ([]*v8miner.SectorOnChainInfo, error) { ret := _m.Called(sectorNos) - var r0 []*miner.SectorOnChainInfo - if rf, ok := ret.Get(0).(func(*bitfield.BitField) []*miner.SectorOnChainInfo); ok { + var r0 []*v8miner.SectorOnChainInfo + if rf, ok := ret.Get(0).(func(*bitfield.BitField) []*v8miner.SectorOnChainInfo); ok { r0 = rf(sectorNos) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*miner.SectorOnChainInfo) + r0 = ret.Get(0).([]*v8miner.SectorOnChainInfo) } } @@ -557,8 +603,8 @@ func (_m *State) NumLiveSectors() (uint64, error) { return r0, r1 } -// PreCommitMap provides a mock function with given fields: -func (_m *State) PreCommitMap() (adt.Map, error) { +// PrecommitsMap provides a mock function with given fields: +func (_m *State) PrecommitsMap() (adt.Map, error) { ret := _m.Called() var r0 adt.Map @@ -580,27 +626,34 @@ func (_m *State) PreCommitMap() (adt.Map, error) { return r0, r1 } -// SectorArray provides a mock function with given fields: -func (_m *State) SectorArray() (adt.Array, error) { +// PrecommitsMapBitWidth provides a mock function with given fields: +func (_m *State) PrecommitsMapBitWidth() int { ret := _m.Called() - var r0 adt.Array - if rf, ok := ret.Get(0).(func() adt.Array); ok { + var r0 int + if rf, ok := ret.Get(0).(func() int); ok { r0 = rf() } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(adt.Array) - } + r0 = ret.Get(0).(int) } - var r1 error - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() + return r0 +} + +// PrecommitsMapHashFunction provides a mock function with given fields: +func (_m *State) PrecommitsMapHashFunction() func([]byte) []byte { + ret := _m.Called() + + var r0 func([]byte) []byte + if rf, ok := ret.Get(0).(func() func([]byte) []byte); ok { + r0 = rf() } else { - r1 = ret.Error(1) + if ret.Get(0) != nil { + r0 = ret.Get(0).(func([]byte) []byte) + } } - return r0, r1 + return r0 } // SectorsAmtBitwidth provides a mock function with given fields: @@ -617,6 +670,29 @@ func (_m *State) SectorsAmtBitwidth() int { return r0 } +// SectorsArray provides a mock function with given fields: +func (_m *State) SectorsArray() (adt.Array, error) { + ret := _m.Called() + + var r0 adt.Array + if rf, ok := ret.Get(0).(func() adt.Array); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(adt.Array) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // UnallocatedSectorNumbers provides a mock function with given fields: count func (_m *State) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) { ret := _m.Called(count) diff --git a/chain/actors/builtin/miner/state.go.template b/chain/actors/builtin/miner/state.go.template index e70dc601c..b028e9f78 100644 --- a/chain/actors/builtin/miner/state.go.template +++ b/chain/actors/builtin/miner/state.go.template @@ -8,20 +8,38 @@ import ( {{if (le .v 1)}} "github.com/filecoin-project/go-state-types/big" {{end}} - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" - rle "github.com/filecoin-project/go-bitfield/rle" + rle "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + "github.com/filecoin-project/lily/chain/actors" - "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" - miner{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/miner" - adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" +{{if (le .v 1)}} + sha256simd "github.com/minio/sha256-simd" +{{else}} + "crypto/sha256" +{{end}} + +{{if (le .v 7)}} + {{if (le .v 2)}} + miner{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/miner" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{else}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + miner{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/miner" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{end}} +{{else}} + miner{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}miner" + adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt" + builtin{{.v}} "github.com/filecoin-project/go-state-types/builtin" +{{end}} ) var _ State = (*state{{.v}})(nil) @@ -35,6 +53,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store) (State, error) { + out := state{{.v}}{store: store} + out.State = miner{{.v}}.State{} + return &out, nil +} + type state{{.v}} struct { miner{{.v}}.State store adt.Store @@ -50,18 +74,10 @@ type partition{{.v}} struct { store adt.Store } -func (s *state{{.v}}) Code() cid.Cid { - return builtin{{.v}}.StorageMinerActorCodeID -} - -func (s *state{{.v}}) SectorsAmtBitwidth() int { - return {{if (ge .v 3)}}miner{{.v}}.SectorsAmtBitwidth{{else}}3{{end}} -} - func (s *state{{.v}}) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("failed to get available balance: %w", r) + err = xerrors.Errorf("failed to get available balance: %w", r) available = abi.NewTokenAmount(0) } }() @@ -206,12 +222,12 @@ func (s *state{{.v}}) GetSectorExpiration(num abi.SectorNumber) (*SectorExpirati return nil, err } if out.Early == 0 && out.OnTime == 0 { - return nil, fmt.Errorf("failed to find sector %d", num) + return nil, xerrors.Errorf("failed to find sector %d", num) } return &out, nil } -func (s *state{{.v}}) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state{{.v}}) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -222,7 +238,7 @@ func (s *state{{.v}}) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCom return &ret, nil } -func (s *state{{.v}}) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { +func (s *state{{.v}}) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { {{if (ge .v 3) -}} precommitted, err := adt{{.v}}.AsMap(s.store, s.State.PreCommittedSectors, builtin{{.v}}.DefaultHamtBitwidth) {{- else -}} @@ -390,10 +406,6 @@ func (s *state{{.v}}) Info() (MinerInfo, error) { return MinerInfo{}, err } - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } {{if (le .v 2)}} wpp, err := info.SealProofType.RegisteredWindowPoStProof() if err != nil { @@ -405,10 +417,9 @@ func (s *state{{.v}}) Info() (MinerInfo, error) { Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, - WorkerChangeEpoch: -1, + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), - PeerId: pid, + PeerId: info.PeerId, Multiaddrs: info.Multiaddrs, WindowPoStProofType: {{if (ge .v 3)}}info.WindowPoStProofType{{else}}wpp{{end}}, SectorSize: info.SectorSize, @@ -416,11 +427,6 @@ func (s *state{{.v}}) Info() (MinerInfo, error) { ConsensusFaultElapsed: {{if (ge .v 2)}}info.ConsensusFaultElapsed{{else}}-1{{end}}, } - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - return mi, nil } @@ -432,7 +438,7 @@ func (s *state{{.v}}) DeadlineCronActive() (bool, error) { return {{if (ge .v 4)}}s.State.DeadlineCronActive{{else}}true{{end}}, nil{{if (lt .v 4)}} // always active in this version{{end}} } -func (s *state{{.v}}) SectorArray() (adt.Array, error) { +func (s *state{{.v}}) SectorsArray() (adt.Array, error) { return adt{{.v}}.AsArray(s.store, s.Sectors{{if (ge .v 3)}}, miner{{.v}}.SectorsAmtBitwidth{{end}}) } @@ -446,15 +452,37 @@ func (s *state{{.v}}) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainI return fromV{{.v}}SectorOnChainInfo(si), nil } -func (s *state{{.v}}) PreCommitMap() (adt.Map, error) { +func (s *state{{.v}}) PrecommitsMap() (adt.Map, error) { return adt{{.v}}.AsMap(s.store, s.PreCommittedSectors{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) } -func (s *state{{.v}}) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +func (s *state{{.v}}) PrecommitsMapBitWidth() int { + {{if (ge .v 3)}} + return builtin{{.v}}.DefaultHamtBitwidth + {{else}} + return 5 + {{end}} +} + +func (s *state{{.v}}) PrecommitsMapHashFunction() func(input []byte) []byte { + {{if (le .v 1)}} + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + {{else}} + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + {{end}} +} + +func (s *state{{.v}}) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { var sp miner{{.v}}.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { - return SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } return fromV{{.v}}SectorPreCommitOnChainInfo(sp), nil @@ -585,20 +613,37 @@ func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorO return info } -func fromV{{.v}}SectorPreCommitOnChainInfo(v{{.v}} miner{{.v}}.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { -{{if (ge .v 2)}} - return SectorPreCommitOnChainInfo{ - Info: (SectorPreCommitInfo)(v{{.v}}.Info), +func fromV{{.v}}SectorPreCommitOnChainInfo(v{{.v}} miner{{.v}}.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v{{.v}}.Info), PreCommitDeposit: v{{.v}}.PreCommitDeposit, PreCommitEpoch: v{{.v}}.PreCommitEpoch, DealWeight: v{{.v}}.DealWeight, VerifiedDealWeight: v{{.v}}.VerifiedDealWeight, } -{{else}} - return (SectorPreCommitOnChainInfo)(v0) -{{end}} } func (s *state{{.v}}) GetState() interface{} { return &s.State -} \ No newline at end of file +} + +func (s *state{{.v}}) SectorsAmtBitwidth() int { + return {{if (ge .v 3)}}miner{{.v}}.SectorsAmtBitwidth{{else}}3{{end}} +} + +func (s *state{{.v}}) ActorKey() string { + return actors.MinerKey +} + +func (s *state{{.v}}) ActorVersion() actors.Version { + return actors.Version{{.v}} +} + +func (s *state{{.v}}) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/utils.go b/chain/actors/builtin/miner/utils.go deleted file mode 100644 index 53e6f8d5c..000000000 --- a/chain/actors/builtin/miner/utils.go +++ /dev/null @@ -1,69 +0,0 @@ -package miner - -import ( - "fmt" - - "github.com/filecoin-project/go-bitfield" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/network" -) - -func AllPartSectors(mas State, sget func(Partition) (bitfield.BitField, error)) (bitfield.BitField, error) { - var parts []bitfield.BitField - - err := mas.ForEachDeadline(func(dlidx uint64, dl Deadline) error { - return dl.ForEachPartition(func(partidx uint64, part Partition) error { - s, err := sget(part) - if err != nil { - return fmt.Errorf("getting sector list (dl: %d, part %d): %w", dlidx, partidx, err) - } - - parts = append(parts, s) - return nil - }) - }) - if err != nil { - return bitfield.BitField{}, err - } - - return bitfield.MultiMerge(parts...) -} - -// SealProofTypeFromSectorSize returns preferred seal proof type for creating -// new miner actors and new sectors -func SealProofTypeFromSectorSize(ssize abi.SectorSize, nv network.Version) (abi.RegisteredSealProof, error) { - switch { - case nv < network.Version7: - switch ssize { - case 2 << 10: - return abi.RegisteredSealProof_StackedDrg2KiBV1, nil - case 8 << 20: - return abi.RegisteredSealProof_StackedDrg8MiBV1, nil - case 512 << 20: - return abi.RegisteredSealProof_StackedDrg512MiBV1, nil - case 32 << 30: - return abi.RegisteredSealProof_StackedDrg32GiBV1, nil - case 64 << 30: - return abi.RegisteredSealProof_StackedDrg64GiBV1, nil - default: - return 0, fmt.Errorf("unsupported sector size for miner: %v", ssize) - } - case nv >= network.Version7: - switch ssize { - case 2 << 10: - return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil - case 8 << 20: - return abi.RegisteredSealProof_StackedDrg8MiBV1_1, nil - case 512 << 20: - return abi.RegisteredSealProof_StackedDrg512MiBV1_1, nil - case 32 << 30: - return abi.RegisteredSealProof_StackedDrg32GiBV1_1, nil - case 64 << 30: - return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil - default: - return 0, fmt.Errorf("unsupported sector size for miner: %v", ssize) - } - } - - return 0, fmt.Errorf("unsupported network version") -} diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 9a29034c1..b0edaa276 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -8,18 +8,20 @@ import ( "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" rle "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lily/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" + + sha256simd "github.com/minio/sha256-simd" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) @@ -35,6 +37,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store) (State, error) { + out := state0{store: store} + out.State = miner0.State{} + return &out, nil +} + type state0 struct { miner0.State store adt.Store @@ -50,18 +58,10 @@ type partition0 struct { store adt.Store } -func (s *state0) Code() cid.Cid { - return builtin0.StorageMinerActorCodeID -} - -func (s *state0) SectorsAmtBitwidth() int { - return 3 -} - func (s *state0) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("failed to get available balance: %w", r) + err = xerrors.Errorf("failed to get available balance: %w", r) available = abi.NewTokenAmount(0) } }() @@ -196,12 +196,12 @@ func (s *state0) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e return nil, err } if out.Early == 0 && out.OnTime == 0 { - return nil, fmt.Errorf("failed to find sector %d", num) + return nil, xerrors.Errorf("failed to find sector %d", num) } return &out, nil } -func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -212,7 +212,7 @@ func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state0) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { +func (s *state0) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { precommitted, err := adt0.AsMap(s.store, s.State.PreCommittedSectors) if err != nil { return err @@ -376,11 +376,6 @@ func (s *state0) Info() (MinerInfo, error) { return MinerInfo{}, err } - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } - wpp, err := info.SealProofType.RegisteredWindowPoStProof() if err != nil { return MinerInfo{}, err @@ -391,10 +386,9 @@ func (s *state0) Info() (MinerInfo, error) { Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, - WorkerChangeEpoch: -1, + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), - PeerId: pid, + PeerId: info.PeerId, Multiaddrs: info.Multiaddrs, WindowPoStProofType: wpp, SectorSize: info.SectorSize, @@ -402,11 +396,6 @@ func (s *state0) Info() (MinerInfo, error) { ConsensusFaultElapsed: -1, } - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - return mi, nil } @@ -418,7 +407,7 @@ func (s *state0) DeadlineCronActive() (bool, error) { return true, nil // always active in this version } -func (s *state0) SectorArray() (adt.Array, error) { +func (s *state0) SectorsArray() (adt.Array, error) { return adt0.AsArray(s.store, s.Sectors) } @@ -432,15 +421,30 @@ func (s *state0) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, return fromV0SectorOnChainInfo(si), nil } -func (s *state0) PreCommitMap() (adt.Map, error) { +func (s *state0) PrecommitsMap() (adt.Map, error) { return adt0.AsMap(s.store, s.PreCommittedSectors) } -func (s *state0) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +func (s *state0) PrecommitsMapBitWidth() int { + + return 5 + +} + +func (s *state0) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + +} + +func (s *state0) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { var sp miner0.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { - return SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } return fromV0SectorPreCommitOnChainInfo(sp), nil @@ -526,12 +530,37 @@ func fromV0SectorOnChainInfo(v0 miner0.SectorOnChainInfo) SectorOnChainInfo { return info } -func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { - - return (SectorPreCommitOnChainInfo)(v0) - +func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v0.Info), + PreCommitDeposit: v0.PreCommitDeposit, + PreCommitEpoch: v0.PreCommitEpoch, + DealWeight: v0.DealWeight, + VerifiedDealWeight: v0.VerifiedDealWeight, + } } func (s *state0) GetState() interface{} { return &s.State } + +func (s *state0) SectorsAmtBitwidth() int { + return 3 +} + +func (s *state0) ActorKey() string { + return actors.MinerKey +} + +func (s *state0) ActorVersion() actors.Version { + return actors.Version0 +} + +func (s *state0) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/v2.go b/chain/actors/builtin/miner/v2.go index dc4617b89..3d3efcae6 100644 --- a/chain/actors/builtin/miner/v2.go +++ b/chain/actors/builtin/miner/v2.go @@ -6,18 +6,20 @@ import ( "errors" "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" rle "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lily/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" + + "crypto/sha256" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" ) @@ -33,6 +35,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store) (State, error) { + out := state2{store: store} + out.State = miner2.State{} + return &out, nil +} + type state2 struct { miner2.State store adt.Store @@ -48,18 +56,10 @@ type partition2 struct { store adt.Store } -func (s *state2) Code() cid.Cid { - return builtin2.StorageMinerActorCodeID -} - -func (s *state2) SectorsAmtBitwidth() int { - return 3 -} - func (s *state2) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("failed to get available balance: %w", r) + err = xerrors.Errorf("failed to get available balance: %w", r) available = abi.NewTokenAmount(0) } }() @@ -194,12 +194,12 @@ func (s *state2) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e return nil, err } if out.Early == 0 && out.OnTime == 0 { - return nil, fmt.Errorf("failed to find sector %d", num) + return nil, xerrors.Errorf("failed to find sector %d", num) } return &out, nil } -func (s *state2) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state2) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -210,7 +210,7 @@ func (s *state2) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state2) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { +func (s *state2) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { precommitted, err := adt2.AsMap(s.store, s.State.PreCommittedSectors) if err != nil { return err @@ -374,11 +374,6 @@ func (s *state2) Info() (MinerInfo, error) { return MinerInfo{}, err } - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } - wpp, err := info.SealProofType.RegisteredWindowPoStProof() if err != nil { return MinerInfo{}, err @@ -389,10 +384,9 @@ func (s *state2) Info() (MinerInfo, error) { Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, - WorkerChangeEpoch: -1, + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), - PeerId: pid, + PeerId: info.PeerId, Multiaddrs: info.Multiaddrs, WindowPoStProofType: wpp, SectorSize: info.SectorSize, @@ -400,11 +394,6 @@ func (s *state2) Info() (MinerInfo, error) { ConsensusFaultElapsed: info.ConsensusFaultElapsed, } - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - return mi, nil } @@ -416,7 +405,7 @@ func (s *state2) DeadlineCronActive() (bool, error) { return true, nil // always active in this version } -func (s *state2) SectorArray() (adt.Array, error) { +func (s *state2) SectorsArray() (adt.Array, error) { return adt2.AsArray(s.store, s.Sectors) } @@ -430,15 +419,30 @@ func (s *state2) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, return fromV2SectorOnChainInfo(si), nil } -func (s *state2) PreCommitMap() (adt.Map, error) { +func (s *state2) PrecommitsMap() (adt.Map, error) { return adt2.AsMap(s.store, s.PreCommittedSectors) } -func (s *state2) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +func (s *state2) PrecommitsMapBitWidth() int { + + return 5 + +} + +func (s *state2) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state2) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { var sp miner2.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { - return SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } return fromV2SectorPreCommitOnChainInfo(sp), nil @@ -556,18 +560,37 @@ func fromV2SectorOnChainInfo(v2 miner2.SectorOnChainInfo) SectorOnChainInfo { return info } -func fromV2SectorPreCommitOnChainInfo(v2 miner2.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { - - return SectorPreCommitOnChainInfo{ - Info: (SectorPreCommitInfo)(v2.Info), +func fromV2SectorPreCommitOnChainInfo(v2 miner2.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v2.Info), PreCommitDeposit: v2.PreCommitDeposit, PreCommitEpoch: v2.PreCommitEpoch, DealWeight: v2.DealWeight, VerifiedDealWeight: v2.VerifiedDealWeight, } - } func (s *state2) GetState() interface{} { return &s.State } + +func (s *state2) SectorsAmtBitwidth() int { + return 3 +} + +func (s *state2) ActorKey() string { + return actors.MinerKey +} + +func (s *state2) ActorVersion() actors.Version { + return actors.Version2 +} + +func (s *state2) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/v3.go b/chain/actors/builtin/miner/v3.go index 5cc82196b..47c5b7b87 100644 --- a/chain/actors/builtin/miner/v3.go +++ b/chain/actors/builtin/miner/v3.go @@ -6,16 +6,19 @@ import ( "errors" "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" rle "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lily/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" + + "crypto/sha256" builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" @@ -33,6 +36,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store) (State, error) { + out := state3{store: store} + out.State = miner3.State{} + return &out, nil +} + type state3 struct { miner3.State store adt.Store @@ -48,18 +57,10 @@ type partition3 struct { store adt.Store } -func (s *state3) Code() cid.Cid { - return builtin3.StorageMinerActorCodeID -} - -func (s *state3) SectorsAmtBitwidth() int { - return miner3.SectorsAmtBitwidth -} - func (s *state3) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("failed to get available balance: %w", r) + err = xerrors.Errorf("failed to get available balance: %w", r) available = abi.NewTokenAmount(0) } }() @@ -194,12 +195,12 @@ func (s *state3) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e return nil, err } if out.Early == 0 && out.OnTime == 0 { - return nil, fmt.Errorf("failed to find sector %d", num) + return nil, xerrors.Errorf("failed to find sector %d", num) } return &out, nil } -func (s *state3) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state3) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -210,7 +211,7 @@ func (s *state3) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state3) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { +func (s *state3) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { precommitted, err := adt3.AsMap(s.store, s.State.PreCommittedSectors, builtin3.DefaultHamtBitwidth) if err != nil { return err @@ -374,20 +375,14 @@ func (s *state3) Info() (MinerInfo, error) { return MinerInfo{}, err } - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } - mi := MinerInfo{ Owner: info.Owner, Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, - WorkerChangeEpoch: -1, + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), - PeerId: pid, + PeerId: info.PeerId, Multiaddrs: info.Multiaddrs, WindowPoStProofType: info.WindowPoStProofType, SectorSize: info.SectorSize, @@ -395,11 +390,6 @@ func (s *state3) Info() (MinerInfo, error) { ConsensusFaultElapsed: info.ConsensusFaultElapsed, } - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - return mi, nil } @@ -411,7 +401,7 @@ func (s *state3) DeadlineCronActive() (bool, error) { return true, nil // always active in this version } -func (s *state3) SectorArray() (adt.Array, error) { +func (s *state3) SectorsArray() (adt.Array, error) { return adt3.AsArray(s.store, s.Sectors, miner3.SectorsAmtBitwidth) } @@ -425,15 +415,30 @@ func (s *state3) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, return fromV3SectorOnChainInfo(si), nil } -func (s *state3) PreCommitMap() (adt.Map, error) { +func (s *state3) PrecommitsMap() (adt.Map, error) { return adt3.AsMap(s.store, s.PreCommittedSectors, builtin3.DefaultHamtBitwidth) } -func (s *state3) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +func (s *state3) PrecommitsMapBitWidth() int { + + return builtin3.DefaultHamtBitwidth + +} + +func (s *state3) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state3) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { var sp miner3.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { - return SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } return fromV3SectorPreCommitOnChainInfo(sp), nil @@ -555,18 +560,37 @@ func fromV3SectorOnChainInfo(v3 miner3.SectorOnChainInfo) SectorOnChainInfo { return info } -func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { - - return SectorPreCommitOnChainInfo{ - Info: (SectorPreCommitInfo)(v3.Info), +func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v3.Info), PreCommitDeposit: v3.PreCommitDeposit, PreCommitEpoch: v3.PreCommitEpoch, DealWeight: v3.DealWeight, VerifiedDealWeight: v3.VerifiedDealWeight, } - } func (s *state3) GetState() interface{} { return &s.State } + +func (s *state3) SectorsAmtBitwidth() int { + return miner3.SectorsAmtBitwidth +} + +func (s *state3) ActorKey() string { + return actors.MinerKey +} + +func (s *state3) ActorVersion() actors.Version { + return actors.Version3 +} + +func (s *state3) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/v4.go b/chain/actors/builtin/miner/v4.go index f6622d5ae..d166ead36 100644 --- a/chain/actors/builtin/miner/v4.go +++ b/chain/actors/builtin/miner/v4.go @@ -6,16 +6,19 @@ import ( "errors" "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" rle "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lily/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" + + "crypto/sha256" builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" @@ -33,6 +36,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store) (State, error) { + out := state4{store: store} + out.State = miner4.State{} + return &out, nil +} + type state4 struct { miner4.State store adt.Store @@ -48,18 +57,10 @@ type partition4 struct { store adt.Store } -func (s *state4) Code() cid.Cid { - return builtin4.StorageMinerActorCodeID -} - -func (s *state4) SectorsAmtBitwidth() int { - return miner4.SectorsAmtBitwidth -} - func (s *state4) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("failed to get available balance: %w", r) + err = xerrors.Errorf("failed to get available balance: %w", r) available = abi.NewTokenAmount(0) } }() @@ -194,12 +195,12 @@ func (s *state4) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e return nil, err } if out.Early == 0 && out.OnTime == 0 { - return nil, fmt.Errorf("failed to find sector %d", num) + return nil, xerrors.Errorf("failed to find sector %d", num) } return &out, nil } -func (s *state4) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state4) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -210,7 +211,7 @@ func (s *state4) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state4) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { +func (s *state4) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { precommitted, err := adt4.AsMap(s.store, s.State.PreCommittedSectors, builtin4.DefaultHamtBitwidth) if err != nil { return err @@ -374,20 +375,14 @@ func (s *state4) Info() (MinerInfo, error) { return MinerInfo{}, err } - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } - mi := MinerInfo{ Owner: info.Owner, Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, - WorkerChangeEpoch: -1, + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), - PeerId: pid, + PeerId: info.PeerId, Multiaddrs: info.Multiaddrs, WindowPoStProofType: info.WindowPoStProofType, SectorSize: info.SectorSize, @@ -395,11 +390,6 @@ func (s *state4) Info() (MinerInfo, error) { ConsensusFaultElapsed: info.ConsensusFaultElapsed, } - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - return mi, nil } @@ -411,7 +401,7 @@ func (s *state4) DeadlineCronActive() (bool, error) { return s.State.DeadlineCronActive, nil } -func (s *state4) SectorArray() (adt.Array, error) { +func (s *state4) SectorsArray() (adt.Array, error) { return adt4.AsArray(s.store, s.Sectors, miner4.SectorsAmtBitwidth) } @@ -425,15 +415,30 @@ func (s *state4) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, return fromV4SectorOnChainInfo(si), nil } -func (s *state4) PreCommitMap() (adt.Map, error) { +func (s *state4) PrecommitsMap() (adt.Map, error) { return adt4.AsMap(s.store, s.PreCommittedSectors, builtin4.DefaultHamtBitwidth) } -func (s *state4) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +func (s *state4) PrecommitsMapBitWidth() int { + + return builtin4.DefaultHamtBitwidth + +} + +func (s *state4) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state4) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { var sp miner4.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { - return SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } return fromV4SectorPreCommitOnChainInfo(sp), nil @@ -555,18 +560,37 @@ func fromV4SectorOnChainInfo(v4 miner4.SectorOnChainInfo) SectorOnChainInfo { return info } -func fromV4SectorPreCommitOnChainInfo(v4 miner4.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { - - return SectorPreCommitOnChainInfo{ - Info: (SectorPreCommitInfo)(v4.Info), +func fromV4SectorPreCommitOnChainInfo(v4 miner4.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v4.Info), PreCommitDeposit: v4.PreCommitDeposit, PreCommitEpoch: v4.PreCommitEpoch, DealWeight: v4.DealWeight, VerifiedDealWeight: v4.VerifiedDealWeight, } - } func (s *state4) GetState() interface{} { return &s.State } + +func (s *state4) SectorsAmtBitwidth() int { + return miner4.SectorsAmtBitwidth +} + +func (s *state4) ActorKey() string { + return actors.MinerKey +} + +func (s *state4) ActorVersion() actors.Version { + return actors.Version4 +} + +func (s *state4) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/v5.go b/chain/actors/builtin/miner/v5.go index 397c81202..e36e8eb3e 100644 --- a/chain/actors/builtin/miner/v5.go +++ b/chain/actors/builtin/miner/v5.go @@ -6,16 +6,19 @@ import ( "errors" "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" rle "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lily/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" + + "crypto/sha256" builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" @@ -33,6 +36,12 @@ func load5(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make5(store adt.Store) (State, error) { + out := state5{store: store} + out.State = miner5.State{} + return &out, nil +} + type state5 struct { miner5.State store adt.Store @@ -48,18 +57,10 @@ type partition5 struct { store adt.Store } -func (s *state5) Code() cid.Cid { - return builtin5.StorageMinerActorCodeID -} - -func (s *state5) SectorsAmtBitwidth() int { - return miner5.SectorsAmtBitwidth -} - func (s *state5) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("failed to get available balance: %w", r) + err = xerrors.Errorf("failed to get available balance: %w", r) available = abi.NewTokenAmount(0) } }() @@ -194,12 +195,12 @@ func (s *state5) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e return nil, err } if out.Early == 0 && out.OnTime == 0 { - return nil, fmt.Errorf("failed to find sector %d", num) + return nil, xerrors.Errorf("failed to find sector %d", num) } return &out, nil } -func (s *state5) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state5) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -210,7 +211,7 @@ func (s *state5) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state5) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { +func (s *state5) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { precommitted, err := adt5.AsMap(s.store, s.State.PreCommittedSectors, builtin5.DefaultHamtBitwidth) if err != nil { return err @@ -374,20 +375,14 @@ func (s *state5) Info() (MinerInfo, error) { return MinerInfo{}, err } - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } - mi := MinerInfo{ Owner: info.Owner, Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, - WorkerChangeEpoch: -1, + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), - PeerId: pid, + PeerId: info.PeerId, Multiaddrs: info.Multiaddrs, WindowPoStProofType: info.WindowPoStProofType, SectorSize: info.SectorSize, @@ -395,11 +390,6 @@ func (s *state5) Info() (MinerInfo, error) { ConsensusFaultElapsed: info.ConsensusFaultElapsed, } - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - return mi, nil } @@ -411,7 +401,7 @@ func (s *state5) DeadlineCronActive() (bool, error) { return s.State.DeadlineCronActive, nil } -func (s *state5) SectorArray() (adt.Array, error) { +func (s *state5) SectorsArray() (adt.Array, error) { return adt5.AsArray(s.store, s.Sectors, miner5.SectorsAmtBitwidth) } @@ -425,15 +415,30 @@ func (s *state5) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, return fromV5SectorOnChainInfo(si), nil } -func (s *state5) PreCommitMap() (adt.Map, error) { +func (s *state5) PrecommitsMap() (adt.Map, error) { return adt5.AsMap(s.store, s.PreCommittedSectors, builtin5.DefaultHamtBitwidth) } -func (s *state5) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +func (s *state5) PrecommitsMapBitWidth() int { + + return builtin5.DefaultHamtBitwidth + +} + +func (s *state5) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state5) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { var sp miner5.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { - return SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } return fromV5SectorPreCommitOnChainInfo(sp), nil @@ -555,18 +560,37 @@ func fromV5SectorOnChainInfo(v5 miner5.SectorOnChainInfo) SectorOnChainInfo { return info } -func fromV5SectorPreCommitOnChainInfo(v5 miner5.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { - - return SectorPreCommitOnChainInfo{ - Info: (SectorPreCommitInfo)(v5.Info), +func fromV5SectorPreCommitOnChainInfo(v5 miner5.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v5.Info), PreCommitDeposit: v5.PreCommitDeposit, PreCommitEpoch: v5.PreCommitEpoch, DealWeight: v5.DealWeight, VerifiedDealWeight: v5.VerifiedDealWeight, } - } func (s *state5) GetState() interface{} { return &s.State } + +func (s *state5) SectorsAmtBitwidth() int { + return miner5.SectorsAmtBitwidth +} + +func (s *state5) ActorKey() string { + return actors.MinerKey +} + +func (s *state5) ActorVersion() actors.Version { + return actors.Version5 +} + +func (s *state5) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/v6.go b/chain/actors/builtin/miner/v6.go index 0e06518e2..b3ced7c53 100644 --- a/chain/actors/builtin/miner/v6.go +++ b/chain/actors/builtin/miner/v6.go @@ -6,16 +6,19 @@ import ( "errors" "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" rle "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lily/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" + + "crypto/sha256" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" miner6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner" @@ -33,6 +36,12 @@ func load6(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make6(store adt.Store) (State, error) { + out := state6{store: store} + out.State = miner6.State{} + return &out, nil +} + type state6 struct { miner6.State store adt.Store @@ -48,18 +57,10 @@ type partition6 struct { store adt.Store } -func (s *state6) Code() cid.Cid { - return builtin6.StorageMinerActorCodeID -} - -func (s *state6) SectorsAmtBitwidth() int { - return miner6.SectorsAmtBitwidth -} - func (s *state6) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("failed to get available balance: %w", r) + err = xerrors.Errorf("failed to get available balance: %w", r) available = abi.NewTokenAmount(0) } }() @@ -194,12 +195,12 @@ func (s *state6) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e return nil, err } if out.Early == 0 && out.OnTime == 0 { - return nil, fmt.Errorf("failed to find sector %d", num) + return nil, xerrors.Errorf("failed to find sector %d", num) } return &out, nil } -func (s *state6) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state6) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -210,7 +211,7 @@ func (s *state6) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state6) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { +func (s *state6) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { precommitted, err := adt6.AsMap(s.store, s.State.PreCommittedSectors, builtin6.DefaultHamtBitwidth) if err != nil { return err @@ -374,20 +375,14 @@ func (s *state6) Info() (MinerInfo, error) { return MinerInfo{}, err } - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } - mi := MinerInfo{ Owner: info.Owner, Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, - WorkerChangeEpoch: -1, + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), - PeerId: pid, + PeerId: info.PeerId, Multiaddrs: info.Multiaddrs, WindowPoStProofType: info.WindowPoStProofType, SectorSize: info.SectorSize, @@ -395,11 +390,6 @@ func (s *state6) Info() (MinerInfo, error) { ConsensusFaultElapsed: info.ConsensusFaultElapsed, } - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - return mi, nil } @@ -411,7 +401,7 @@ func (s *state6) DeadlineCronActive() (bool, error) { return s.State.DeadlineCronActive, nil } -func (s *state6) SectorArray() (adt.Array, error) { +func (s *state6) SectorsArray() (adt.Array, error) { return adt6.AsArray(s.store, s.Sectors, miner6.SectorsAmtBitwidth) } @@ -425,15 +415,30 @@ func (s *state6) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, return fromV6SectorOnChainInfo(si), nil } -func (s *state6) PreCommitMap() (adt.Map, error) { +func (s *state6) PrecommitsMap() (adt.Map, error) { return adt6.AsMap(s.store, s.PreCommittedSectors, builtin6.DefaultHamtBitwidth) } -func (s *state6) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +func (s *state6) PrecommitsMapBitWidth() int { + + return builtin6.DefaultHamtBitwidth + +} + +func (s *state6) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state6) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { var sp miner6.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { - return SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } return fromV6SectorPreCommitOnChainInfo(sp), nil @@ -555,18 +560,37 @@ func fromV6SectorOnChainInfo(v6 miner6.SectorOnChainInfo) SectorOnChainInfo { return info } -func fromV6SectorPreCommitOnChainInfo(v6 miner6.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { - - return SectorPreCommitOnChainInfo{ - Info: (SectorPreCommitInfo)(v6.Info), +func fromV6SectorPreCommitOnChainInfo(v6 miner6.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v6.Info), PreCommitDeposit: v6.PreCommitDeposit, PreCommitEpoch: v6.PreCommitEpoch, DealWeight: v6.DealWeight, VerifiedDealWeight: v6.VerifiedDealWeight, } - } func (s *state6) GetState() interface{} { return &s.State } + +func (s *state6) SectorsAmtBitwidth() int { + return miner6.SectorsAmtBitwidth +} + +func (s *state6) ActorKey() string { + return actors.MinerKey +} + +func (s *state6) ActorVersion() actors.Version { + return actors.Version6 +} + +func (s *state6) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/v7.go b/chain/actors/builtin/miner/v7.go index b56b53959..d6a51232a 100644 --- a/chain/actors/builtin/miner/v7.go +++ b/chain/actors/builtin/miner/v7.go @@ -6,16 +6,19 @@ import ( "errors" "fmt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" rle "github.com/filecoin-project/go-bitfield/rle" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" - "github.com/filecoin-project/lily/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" + + "crypto/sha256" builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" @@ -33,6 +36,12 @@ func load7(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make7(store adt.Store) (State, error) { + out := state7{store: store} + out.State = miner7.State{} + return &out, nil +} + type state7 struct { miner7.State store adt.Store @@ -48,18 +57,10 @@ type partition7 struct { store adt.Store } -func (s *state7) Code() cid.Cid { - return builtin7.StorageMinerActorCodeID -} - -func (s *state7) SectorsAmtBitwidth() int { - return miner7.SectorsAmtBitwidth -} - func (s *state7) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { defer func() { if r := recover(); r != nil { - err = fmt.Errorf("failed to get available balance: %w", r) + err = xerrors.Errorf("failed to get available balance: %w", r) available = abi.NewTokenAmount(0) } }() @@ -193,12 +194,12 @@ func (s *state7) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e return nil, err } if out.Early == 0 && out.OnTime == 0 { - return nil, fmt.Errorf("failed to find sector %d", num) + return nil, xerrors.Errorf("failed to find sector %d", num) } return &out, nil } -func (s *state7) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) { +func (s *state7) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { info, ok, err := s.State.GetPrecommittedSector(s.store, num) if !ok || err != nil { return nil, err @@ -209,7 +210,7 @@ func (s *state7) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn return &ret, nil } -func (s *state7) ForEachPrecommittedSector(cb func(SectorPreCommitOnChainInfo) error) error { +func (s *state7) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { precommitted, err := adt7.AsMap(s.store, s.State.PreCommittedSectors, builtin7.DefaultHamtBitwidth) if err != nil { return err @@ -373,20 +374,14 @@ func (s *state7) Info() (MinerInfo, error) { return MinerInfo{}, err } - var pid *peer.ID - if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { - pid = &peerID - } - mi := MinerInfo{ Owner: info.Owner, Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, - WorkerChangeEpoch: -1, + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), - PeerId: pid, + PeerId: info.PeerId, Multiaddrs: info.Multiaddrs, WindowPoStProofType: info.WindowPoStProofType, SectorSize: info.SectorSize, @@ -394,11 +389,6 @@ func (s *state7) Info() (MinerInfo, error) { ConsensusFaultElapsed: info.ConsensusFaultElapsed, } - if info.PendingWorkerKey != nil { - mi.NewWorker = info.PendingWorkerKey.NewWorker - mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt - } - return mi, nil } @@ -410,7 +400,7 @@ func (s *state7) DeadlineCronActive() (bool, error) { return s.State.DeadlineCronActive, nil } -func (s *state7) SectorArray() (adt.Array, error) { +func (s *state7) SectorsArray() (adt.Array, error) { return adt7.AsArray(s.store, s.Sectors, miner7.SectorsAmtBitwidth) } @@ -424,15 +414,30 @@ func (s *state7) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, return fromV7SectorOnChainInfo(si), nil } -func (s *state7) PreCommitMap() (adt.Map, error) { +func (s *state7) PrecommitsMap() (adt.Map, error) { return adt7.AsMap(s.store, s.PreCommittedSectors, builtin7.DefaultHamtBitwidth) } -func (s *state7) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +func (s *state7) PrecommitsMapBitWidth() int { + + return builtin7.DefaultHamtBitwidth + +} + +func (s *state7) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state7) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { var sp miner7.SectorPreCommitOnChainInfo err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) if err != nil { - return SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } return fromV7SectorPreCommitOnChainInfo(sp), nil @@ -556,18 +561,37 @@ func fromV7SectorOnChainInfo(v7 miner7.SectorOnChainInfo) SectorOnChainInfo { return info } -func fromV7SectorPreCommitOnChainInfo(v7 miner7.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { - - return SectorPreCommitOnChainInfo{ - Info: (SectorPreCommitInfo)(v7.Info), +func fromV7SectorPreCommitOnChainInfo(v7 miner7.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v7.Info), PreCommitDeposit: v7.PreCommitDeposit, PreCommitEpoch: v7.PreCommitEpoch, DealWeight: v7.DealWeight, VerifiedDealWeight: v7.VerifiedDealWeight, } - } func (s *state7) GetState() interface{} { return &s.State } + +func (s *state7) SectorsAmtBitwidth() int { + return miner7.SectorsAmtBitwidth +} + +func (s *state7) ActorKey() string { + return actors.MinerKey +} + +func (s *state7) ActorVersion() actors.Version { + return actors.Version7 +} + +func (s *state7) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/miner/v8.go b/chain/actors/builtin/miner/v8.go new file mode 100644 index 000000000..39eb329d0 --- /dev/null +++ b/chain/actors/builtin/miner/v8.go @@ -0,0 +1,597 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package miner + +import ( + "bytes" + "errors" + "fmt" + + "github.com/filecoin-project/go-bitfield" + rle "github.com/filecoin-project/go-bitfield/rle" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/dline" + "github.com/filecoin-project/lily/chain/actors" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/lotus/chain/actors/adt" + + "crypto/sha256" + + builtin8 "github.com/filecoin-project/go-state-types/builtin" + miner8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" + adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt" +) + +var _ State = (*state8)(nil) + +func load8(store adt.Store, root cid.Cid) (State, error) { + out := state8{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make8(store adt.Store) (State, error) { + out := state8{store: store} + out.State = miner8.State{} + return &out, nil +} + +type state8 struct { + miner8.State + store adt.Store +} + +type deadline8 struct { + miner8.Deadline + store adt.Store +} + +type partition8 struct { + miner8.Partition + store adt.Store +} + +func (s *state8) AvailableBalance(bal abi.TokenAmount) (available abi.TokenAmount, err error) { + defer func() { + if r := recover(); r != nil { + err = xerrors.Errorf("failed to get available balance: %w", r) + available = abi.NewTokenAmount(0) + } + }() + // this panics if the miner doesnt have enough funds to cover their locked pledge + available, err = s.GetAvailableBalance(bal) + return available, err +} + +func (s *state8) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.CheckVestedFunds(s.store, epoch) +} + +func (s *state8) LockedFunds() (LockedFunds, error) { + return LockedFunds{ + VestingFunds: s.State.LockedFunds, + InitialPledgeRequirement: s.State.InitialPledge, + PreCommitDeposits: s.State.PreCommitDeposits, + }, nil +} + +func (s *state8) FeeDebt() (abi.TokenAmount, error) { + return s.State.FeeDebt, nil +} + +func (s *state8) InitialPledge() (abi.TokenAmount, error) { + return s.State.InitialPledge, nil +} + +func (s *state8) PreCommitDeposits() (abi.TokenAmount, error) { + return s.State.PreCommitDeposits, nil +} + +func (s *state8) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) { + info, ok, err := s.State.GetSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + ret := fromV8SectorOnChainInfo(*info) + return &ret, nil +} + +func (s *state8) FindSector(num abi.SectorNumber) (*SectorLocation, error) { + dlIdx, partIdx, err := s.State.FindSector(s.store, num) + if err != nil { + return nil, err + } + return &SectorLocation{ + Deadline: dlIdx, + Partition: partIdx, + }, nil +} + +func (s *state8) NumLiveSectors() (uint64, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return 0, err + } + var total uint64 + if err := dls.ForEach(s.store, func(dlIdx uint64, dl *miner8.Deadline) error { + total += dl.LiveSectors + return nil + }); err != nil { + return 0, err + } + return total, nil +} + +// GetSectorExpiration returns the effective expiration of the given sector. +// +// If the sector does not expire early, the Early expiration field is 0. +func (s *state8) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return nil, err + } + // NOTE: this can be optimized significantly. + // 1. If the sector is non-faulty, it will expire on-time (can be + // learned from the sector info). + // 2. If it's faulty, it will expire early within the first 42 entries + // of the expiration queue. + + stopErr := errors.New("stop") + out := SectorExpiration{} + err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner8.Deadline) error { + partitions, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + quant := s.State.QuantSpecForDeadline(dlIdx) + var part miner8.Partition + return partitions.ForEach(&part, func(partIdx int64) error { + if found, err := part.Sectors.IsSet(uint64(num)); err != nil { + return err + } else if !found { + return nil + } + if found, err := part.Terminated.IsSet(uint64(num)); err != nil { + return err + } else if found { + // already terminated + return stopErr + } + + q, err := miner8.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant, miner8.PartitionExpirationAmtBitwidth) + if err != nil { + return err + } + var exp miner8.ExpirationSet + return q.ForEach(&exp, func(epoch int64) error { + if early, err := exp.EarlySectors.IsSet(uint64(num)); err != nil { + return err + } else if early { + out.Early = abi.ChainEpoch(epoch) + return nil + } + if onTime, err := exp.OnTimeSectors.IsSet(uint64(num)); err != nil { + return err + } else if onTime { + out.OnTime = abi.ChainEpoch(epoch) + return stopErr + } + return nil + }) + }) + }) + if err == stopErr { + err = nil + } + if err != nil { + return nil, err + } + if out.Early == 0 && out.OnTime == 0 { + return nil, xerrors.Errorf("failed to find sector %d", num) + } + return &out, nil +} + +func (s *state8) GetPrecommittedSector(num abi.SectorNumber) (*minertypes.SectorPreCommitOnChainInfo, error) { + info, ok, err := s.State.GetPrecommittedSector(s.store, num) + if !ok || err != nil { + return nil, err + } + + ret := fromV8SectorPreCommitOnChainInfo(*info) + + return &ret, nil +} + +func (s *state8) ForEachPrecommittedSector(cb func(minertypes.SectorPreCommitOnChainInfo) error) error { + precommitted, err := adt8.AsMap(s.store, s.State.PreCommittedSectors, builtin8.DefaultHamtBitwidth) + if err != nil { + return err + } + + var info miner8.SectorPreCommitOnChainInfo + if err := precommitted.ForEach(&info, func(_ string) error { + return cb(fromV8SectorPreCommitOnChainInfo(info)) + }); err != nil { + return err + } + + return nil +} + +func (s *state8) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) { + sectors, err := miner8.LoadSectors(s.store, s.State.Sectors) + if err != nil { + return nil, err + } + + // If no sector numbers are specified, load all. + if snos == nil { + infos := make([]*SectorOnChainInfo, 0, sectors.Length()) + var info8 miner8.SectorOnChainInfo + if err := sectors.ForEach(&info8, func(_ int64) error { + info := fromV8SectorOnChainInfo(info8) + infos = append(infos, &info) + return nil + }); err != nil { + return nil, err + } + return infos, nil + } + + // Otherwise, load selected. + infos8, err := sectors.Load(*snos) + if err != nil { + return nil, err + } + infos := make([]*SectorOnChainInfo, len(infos8)) + for i, info8 := range infos8 { + info := fromV8SectorOnChainInfo(*info8) + infos[i] = &info + } + return infos, nil +} + +func (s *state8) loadAllocatedSectorNumbers() (bitfield.BitField, error) { + var allocatedSectors bitfield.BitField + err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors) + return allocatedSectors, err +} + +func (s *state8) IsAllocated(num abi.SectorNumber) (bool, error) { + allocatedSectors, err := s.loadAllocatedSectorNumbers() + if err != nil { + return false, err + } + + return allocatedSectors.IsSet(uint64(num)) +} + +func (s *state8) GetProvingPeriodStart() (abi.ChainEpoch, error) { + return s.State.ProvingPeriodStart, nil +} + +func (s *state8) UnallocatedSectorNumbers(count int) ([]abi.SectorNumber, error) { + allocatedSectors, err := s.loadAllocatedSectorNumbers() + if err != nil { + return nil, err + } + + allocatedRuns, err := allocatedSectors.RunIterator() + if err != nil { + return nil, err + } + + unallocatedRuns, err := rle.Subtract( + &rle.RunSliceIterator{Runs: []rle.Run{{Val: true, Len: abi.MaxSectorNumber}}}, + allocatedRuns, + ) + if err != nil { + return nil, err + } + + iter, err := rle.BitsFromRuns(unallocatedRuns) + if err != nil { + return nil, err + } + + sectors := make([]abi.SectorNumber, 0, count) + for iter.HasNext() && len(sectors) < count { + nextNo, err := iter.Next() + if err != nil { + return nil, err + } + sectors = append(sectors, abi.SectorNumber(nextNo)) + } + + return sectors, nil +} + +func (s *state8) GetAllocatedSectors() (*bitfield.BitField, error) { + var allocatedSectors bitfield.BitField + if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil { + return nil, err + } + + return &allocatedSectors, nil +} + +func (s *state8) LoadDeadline(idx uint64) (Deadline, error) { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return nil, err + } + dl, err := dls.LoadDeadline(s.store, idx) + if err != nil { + return nil, err + } + return &deadline8{*dl, s.store}, nil +} + +func (s *state8) ForEachDeadline(cb func(uint64, Deadline) error) error { + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + return dls.ForEach(s.store, func(i uint64, dl *miner8.Deadline) error { + return cb(i, &deadline8{*dl, s.store}) + }) +} + +func (s *state8) NumDeadlines() (uint64, error) { + return miner8.WPoStPeriodDeadlines, nil +} + +func (s *state8) DeadlinesChanged(other State) (bool, error) { + other8, ok := other.(*state8) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + + return !s.State.Deadlines.Equals(other8.Deadlines), nil +} + +func (s *state8) MinerInfoChanged(other State) (bool, error) { + other0, ok := other.(*state8) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.Info.Equals(other0.State.Info), nil +} + +func (s *state8) Info() (MinerInfo, error) { + info, err := s.State.GetInfo(s.store) + if err != nil { + return MinerInfo{}, err + } + + mi := MinerInfo{ + Owner: info.Owner, + Worker: info.Worker, + ControlAddresses: info.ControlAddresses, + + PendingWorkerKey: (*WorkerKeyChange)(info.PendingWorkerKey), + + PeerId: info.PeerId, + Multiaddrs: info.Multiaddrs, + WindowPoStProofType: info.WindowPoStProofType, + SectorSize: info.SectorSize, + WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, + ConsensusFaultElapsed: info.ConsensusFaultElapsed, + } + + return mi, nil +} + +func (s *state8) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) { + return s.State.RecordedDeadlineInfo(epoch), nil +} + +func (s *state8) DeadlineCronActive() (bool, error) { + return s.State.DeadlineCronActive, nil +} + +func (s *state8) SectorsArray() (adt.Array, error) { + return adt8.AsArray(s.store, s.Sectors, miner8.SectorsAmtBitwidth) +} + +func (s *state8) DecodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) { + var si miner8.SectorOnChainInfo + err := si.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return SectorOnChainInfo{}, err + } + + return fromV8SectorOnChainInfo(si), nil +} + +func (s *state8) PrecommitsMap() (adt.Map, error) { + return adt8.AsMap(s.store, s.PreCommittedSectors, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) PrecommitsMapBitWidth() int { + + return builtin8.DefaultHamtBitwidth + +} + +func (s *state8) PrecommitsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state8) DecodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (minertypes.SectorPreCommitOnChainInfo, error) { + var sp miner8.SectorPreCommitOnChainInfo + err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw)) + if err != nil { + return minertypes.SectorPreCommitOnChainInfo{}, err + } + + return fromV8SectorPreCommitOnChainInfo(sp), nil +} + +func (s *state8) EraseAllUnproven() error { + + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + + err = dls.ForEach(s.store, func(dindx uint64, dl *miner8.Deadline) error { + ps, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + + var part miner8.Partition + err = ps.ForEach(&part, func(pindx int64) error { + _ = part.ActivateUnproven() + err = ps.Set(uint64(pindx), &part) + return nil + }) + + if err != nil { + return err + } + + dl.Partitions, err = ps.Root() + if err != nil { + return err + } + + return dls.UpdateDeadline(s.store, dindx, dl) + }) + if err != nil { + return err + } + + return s.State.SaveDeadlines(s.store, dls) + +} + +func (d *deadline8) LoadPartition(idx uint64) (Partition, error) { + p, err := d.Deadline.LoadPartition(d.store, idx) + if err != nil { + return nil, err + } + return &partition8{*p, d.store}, nil +} + +func (d *deadline8) ForEachPartition(cb func(uint64, Partition) error) error { + ps, err := d.Deadline.PartitionsArray(d.store) + if err != nil { + return err + } + var part miner8.Partition + return ps.ForEach(&part, func(i int64) error { + return cb(uint64(i), &partition8{part, d.store}) + }) +} + +func (d *deadline8) PartitionsChanged(other Deadline) (bool, error) { + other8, ok := other.(*deadline8) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + + return !d.Deadline.Partitions.Equals(other8.Deadline.Partitions), nil +} + +func (d *deadline8) PartitionsPoSted() (bitfield.BitField, error) { + return d.Deadline.PartitionsPoSted, nil +} + +func (d *deadline8) DisputableProofCount() (uint64, error) { + + ops, err := d.OptimisticProofsSnapshotArray(d.store) + if err != nil { + return 0, err + } + + return ops.Length(), nil + +} + +func (p *partition8) AllSectors() (bitfield.BitField, error) { + return p.Partition.Sectors, nil +} + +func (p *partition8) FaultySectors() (bitfield.BitField, error) { + return p.Partition.Faults, nil +} + +func (p *partition8) RecoveringSectors() (bitfield.BitField, error) { + return p.Partition.Recoveries, nil +} + +func (p *partition8) UnprovenSectors() (bitfield.BitField, error) { + return p.Partition.Unproven, nil +} + +func fromV8SectorOnChainInfo(v8 miner8.SectorOnChainInfo) SectorOnChainInfo { + info := SectorOnChainInfo{ + SectorNumber: v8.SectorNumber, + SealProof: v8.SealProof, + SealedCID: v8.SealedCID, + DealIDs: v8.DealIDs, + Activation: v8.Activation, + Expiration: v8.Expiration, + DealWeight: v8.DealWeight, + VerifiedDealWeight: v8.VerifiedDealWeight, + InitialPledge: v8.InitialPledge, + ExpectedDayReward: v8.ExpectedDayReward, + ExpectedStoragePledge: v8.ExpectedStoragePledge, + + SectorKeyCID: v8.SectorKeyCID, + } + return info +} + +func fromV8SectorPreCommitOnChainInfo(v8 miner8.SectorPreCommitOnChainInfo) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ + Info: (minertypes.SectorPreCommitInfo)(v8.Info), + PreCommitDeposit: v8.PreCommitDeposit, + PreCommitEpoch: v8.PreCommitEpoch, + DealWeight: v8.DealWeight, + VerifiedDealWeight: v8.VerifiedDealWeight, + } +} + +func (s *state8) GetState() interface{} { + return &s.State +} + +func (s *state8) SectorsAmtBitwidth() int { + return miner8.SectorsAmtBitwidth +} + +func (s *state8) ActorKey() string { + return actors.MinerKey +} + +func (s *state8) ActorVersion() actors.Version { + return actors.Version8 +} + +func (s *state8) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/actor.go.template b/chain/actors/builtin/multisig/actor.go.template index e6b3540ab..a50dd0173 100644 --- a/chain/actors/builtin/multisig/actor.go.template +++ b/chain/actors/builtin/multisig/actor.go.template @@ -19,32 +19,46 @@ import ( "github.com/filecoin-project/lotus/chain/types" + lotusactors "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" ) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.MultisigKey { + return nil, fmt.Errorf("actor code is not multisig: %s", name) + } + + switch actors.Version(av) { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.MultisigActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.MultisigActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } type State interface { cbor.Marshaler - Code() cid.Cid + Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error) StartEpoch() (abi.ChainEpoch, error) @@ -56,7 +70,9 @@ type State interface { ForEachPendingTxn(func(id int64, txn Transaction) error) error PendingTxnChanged(State) (bool, error) - transactions() (adt.Map, error) + PendingTransactionsMap() (adt.Map, error) + PendingTransactionsMapBitWidth() int + PendingTransactionsMapHashFunction() func(input []byte) []byte decodeTransaction(val *cbg.Deferred) (Transaction, error) } @@ -64,40 +80,6 @@ type Transaction = msig{{.latestVersion}}.Transaction var Methods = builtin{{.latestVersion}}.MethodsMultisig -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.MultisigActorCodeID, - {{- end}} - } -} - -func Message(version actors.Version, from address.Address) MessageBuilder { - switch version { -{{range .versions}} - case actors.Version{{.}}: - return message{{.}}{{"{"}}{{if (ge . 2)}}message0{from}{{else}}from{{end}}} -{{end}} default: - panic(fmt.Sprintf("unsupported actors version: %d", version)) - } -} - -type MessageBuilder interface { - // Create a new multisig with the specified parameters. - Create(signers []address.Address, threshold uint64, - vestingStart, vestingDuration abi.ChainEpoch, - initialAmount abi.TokenAmount) (*types.Message, error) - - // Propose a transaction to the given multisig. - Propose(msig, target address.Address, amt abi.TokenAmount, - method abi.MethodNum, params []byte) (*types.Message, error) - - // Approve a multisig transaction. The "hash" is optional. - Approve(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error) - - // Cancel a multisig transaction. The "hash" is optional. - Cancel(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error) -} - // these types are the same between v0 and v6 type ProposalHashData = msig{{.latestVersion}}.ProposalHashData type ProposeReturn = msig{{.latestVersion}}.ProposeReturn @@ -128,3 +110,18 @@ func txnParams(id uint64, data *ProposalHashData) ([]byte, error) { return actors.SerializeParams(¶ms) } + +func AllCodes() []cid.Cid { + return []cid.Cid{ {{range .versions}} + (&state{{.}}{}).Code(), + {{- end}} + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + {{- range .versions}} + actors.Version{{.}}: (&state{{.}}{}).Code(), + {{- end}} + } +} diff --git a/chain/actors/builtin/multisig/diff.go b/chain/actors/builtin/multisig/diff.go index 545db7ea3..854c68024 100644 --- a/chain/actors/builtin/multisig/diff.go +++ b/chain/actors/builtin/multisig/diff.go @@ -6,11 +6,12 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-hamt-ipld/v3" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/adt/diff" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors/adt/diff" ) type PendingTransactionChanges struct { @@ -31,33 +32,33 @@ type TransactionModification struct { } func DiffPendingTransactions(ctx context.Context, store adt.Store, pre, cur State) (*PendingTransactionChanges, error) { - pret, err := pre.transactions() + pret, err := pre.PendingTransactionsMap() if err != nil { return nil, err } - curt, err := cur.transactions() + curt, err := cur.PendingTransactionsMap() if err != nil { return nil, err } - preOpts, err := adt.MapOptsForActorCode(pre.Code()) - if err != nil { - return nil, err - } - curOpts, err := adt.MapOptsForActorCode(cur.Code()) - if err != nil { - return nil, err - } diffContainer := NewTransactionDiffContainer(pre, cur) - if requiresLegacyDiffing(pre, cur, preOpts, curOpts) { + if requiresLegacyDiffing(pre, cur, + &adt.MapOpts{ + Bitwidth: pre.PendingTransactionsMapBitWidth(), + HashFunc: pre.PendingTransactionsMapHashFunction(), + }, + &adt.MapOpts{ + Bitwidth: cur.PendingTransactionsMapBitWidth(), + HashFunc: pre.PendingTransactionsMapHashFunction(), + }) { if err := diff.CompareMap(pret, curt, diffContainer); err != nil { return nil, err } return diffContainer.Results, nil } - changes, err := diff.Hamt(ctx, pret, curt, store, store, hamt.UseTreeBitWidth(preOpts.Bitwidth), hamt.UseHashFunction(hamt.HashFunc(preOpts.HashFunc))) + changes, err := diff.Hamt(ctx, pret, curt, store, store, hamt.UseTreeBitWidth(pre.PendingTransactionsMapBitWidth()), hamt.UseHashFunction(pre.PendingTransactionsMapHashFunction())) if err != nil { return nil, err } diff --git a/chain/actors/builtin/multisig/message.go.template b/chain/actors/builtin/multisig/message.go.template deleted file mode 100644 index ddefa157c..000000000 --- a/chain/actors/builtin/multisig/message.go.template +++ /dev/null @@ -1,148 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package multisig - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" - init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init" - multisig{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message{{.v}} struct{ {{if (ge .v 2)}}message0{{else}}from address.Address{{end}} } - -func (m message{{.v}}) Create( - signers []address.Address, threshold uint64, - unlockStart, unlockDuration abi.ChainEpoch, - initialAmount abi.TokenAmount, -) (*types.Message, error) { - - lenAddrs := uint64(len(signers)) - - if lenAddrs < threshold { - return nil, fmt.Errorf("cannot require signing of more addresses than provided for multisig") - } - - if threshold == 0 { - threshold = lenAddrs - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } -{{if (le .v 1)}} - if unlockStart != 0 { - return nil, fmt.Errorf("actors v0 does not support a non-zero vesting start time") - } -{{end}} - // Set up constructor parameters for multisig - msigParams := &multisig{{.v}}.ConstructorParams{ - Signers: signers, - NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration,{{if (ge .v 2)}} - StartEpoch: unlockStart,{{end}} - } - - enc, actErr := actors.SerializeParams(msigParams) - if actErr != nil { - return nil, actErr - } - - // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init{{.v}}.ExecParams{ - CodeCID: builtin{{.v}}.MultisigActorCodeID, - ConstructorParams: enc, - } - - enc, actErr = actors.SerializeParams(execParams) - if actErr != nil { - return nil, actErr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Method: builtin{{.v}}.MethodsInit.Exec, - Params: enc, - Value: initialAmount, - }, nil -} - -{{if (le .v 1)}} - -func (m message0) Propose(msig, to address.Address, amt abi.TokenAmount, - method abi.MethodNum, params []byte) (*types.Message, error) { - - if msig == address.Undef { - return nil, fmt.Errorf("must provide a multisig address for proposal") - } - - if to == address.Undef { - return nil, fmt.Errorf("must provide a target address for proposal") - } - - if amt.Sign() == -1 { - return nil, fmt.Errorf("must provide a non-negative amount for proposed send") - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - enc, actErr := actors.SerializeParams(&multisig0.ProposeParams{ - To: to, - Value: amt, - Method: method, - Params: params, - }) - if actErr != nil { - return nil, fmt.Errorf("failed to serialize parameters: %w", actErr) - } - - return &types.Message{ - To: msig, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin0.MethodsMultisig.Propose, - Params: enc, - }, nil -} - -func (m message0) Approve(msig address.Address, txID uint64, hashData *ProposalHashData) (*types.Message, error) { - enc, err := txnParams(txID, hashData) - if err != nil { - return nil, err - } - - return &types.Message{ - To: msig, - From: m.from, - Value: types.NewInt(0), - Method: builtin0.MethodsMultisig.Approve, - Params: enc, - }, nil -} - -func (m message0) Cancel(msig address.Address, txID uint64, hashData *ProposalHashData) (*types.Message, error) { - enc, err := txnParams(txID, hashData) - if err != nil { - return nil, err - } - - return &types.Message{ - To: msig, - From: m.from, - Value: types.NewInt(0), - Method: builtin0.MethodsMultisig.Cancel, - Params: enc, - }, nil -} -{{end}} diff --git a/chain/actors/builtin/multisig/message0.go b/chain/actors/builtin/multisig/message0.go deleted file mode 100644 index f1fc97b93..000000000 --- a/chain/actors/builtin/multisig/message0.go +++ /dev/null @@ -1,144 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package multisig - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" - multisig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message0 struct{ from address.Address } - -func (m message0) Create( - signers []address.Address, threshold uint64, - unlockStart, unlockDuration abi.ChainEpoch, - initialAmount abi.TokenAmount, -) (*types.Message, error) { - - lenAddrs := uint64(len(signers)) - - if lenAddrs < threshold { - return nil, fmt.Errorf("cannot require signing of more addresses than provided for multisig") - } - - if threshold == 0 { - threshold = lenAddrs - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - if unlockStart != 0 { - return nil, fmt.Errorf("actors v0 does not support a non-zero vesting start time") - } - - // Set up constructor parameters for multisig - msigParams := &multisig0.ConstructorParams{ - Signers: signers, - NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration, - } - - enc, actErr := actors.SerializeParams(msigParams) - if actErr != nil { - return nil, actErr - } - - // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init0.ExecParams{ - CodeCID: builtin0.MultisigActorCodeID, - ConstructorParams: enc, - } - - enc, actErr = actors.SerializeParams(execParams) - if actErr != nil { - return nil, actErr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Method: builtin0.MethodsInit.Exec, - Params: enc, - Value: initialAmount, - }, nil -} - -func (m message0) Propose(msig, to address.Address, amt abi.TokenAmount, - method abi.MethodNum, params []byte) (*types.Message, error) { - - if msig == address.Undef { - return nil, fmt.Errorf("must provide a multisig address for proposal") - } - - if to == address.Undef { - return nil, fmt.Errorf("must provide a target address for proposal") - } - - if amt.Sign() == -1 { - return nil, fmt.Errorf("must provide a non-negative amount for proposed send") - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - enc, actErr := actors.SerializeParams(&multisig0.ProposeParams{ - To: to, - Value: amt, - Method: method, - Params: params, - }) - if actErr != nil { - return nil, fmt.Errorf("failed to serialize parameters: %w", actErr) - } - - return &types.Message{ - To: msig, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin0.MethodsMultisig.Propose, - Params: enc, - }, nil -} - -func (m message0) Approve(msig address.Address, txID uint64, hashData *ProposalHashData) (*types.Message, error) { - enc, err := txnParams(txID, hashData) - if err != nil { - return nil, err - } - - return &types.Message{ - To: msig, - From: m.from, - Value: types.NewInt(0), - Method: builtin0.MethodsMultisig.Approve, - Params: enc, - }, nil -} - -func (m message0) Cancel(msig address.Address, txID uint64, hashData *ProposalHashData) (*types.Message, error) { - enc, err := txnParams(txID, hashData) - if err != nil { - return nil, err - } - - return &types.Message{ - To: msig, - From: m.from, - Value: types.NewInt(0), - Method: builtin0.MethodsMultisig.Cancel, - Params: enc, - }, nil -} diff --git a/chain/actors/builtin/multisig/message2.go b/chain/actors/builtin/multisig/message2.go deleted file mode 100644 index 2be30dab4..000000000 --- a/chain/actors/builtin/multisig/message2.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package multisig - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init" - multisig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message2 struct{ message0 } - -func (m message2) Create( - signers []address.Address, threshold uint64, - unlockStart, unlockDuration abi.ChainEpoch, - initialAmount abi.TokenAmount, -) (*types.Message, error) { - - lenAddrs := uint64(len(signers)) - - if lenAddrs < threshold { - return nil, fmt.Errorf("cannot require signing of more addresses than provided for multisig") - } - - if threshold == 0 { - threshold = lenAddrs - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - // Set up constructor parameters for multisig - msigParams := &multisig2.ConstructorParams{ - Signers: signers, - NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration, - StartEpoch: unlockStart, - } - - enc, actErr := actors.SerializeParams(msigParams) - if actErr != nil { - return nil, actErr - } - - // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init2.ExecParams{ - CodeCID: builtin2.MultisigActorCodeID, - ConstructorParams: enc, - } - - enc, actErr = actors.SerializeParams(execParams) - if actErr != nil { - return nil, actErr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Method: builtin2.MethodsInit.Exec, - Params: enc, - Value: initialAmount, - }, nil -} diff --git a/chain/actors/builtin/multisig/message3.go b/chain/actors/builtin/multisig/message3.go deleted file mode 100644 index 061243d63..000000000 --- a/chain/actors/builtin/multisig/message3.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package multisig - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init" - multisig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message3 struct{ message0 } - -func (m message3) Create( - signers []address.Address, threshold uint64, - unlockStart, unlockDuration abi.ChainEpoch, - initialAmount abi.TokenAmount, -) (*types.Message, error) { - - lenAddrs := uint64(len(signers)) - - if lenAddrs < threshold { - return nil, fmt.Errorf("cannot require signing of more addresses than provided for multisig") - } - - if threshold == 0 { - threshold = lenAddrs - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - // Set up constructor parameters for multisig - msigParams := &multisig3.ConstructorParams{ - Signers: signers, - NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration, - StartEpoch: unlockStart, - } - - enc, actErr := actors.SerializeParams(msigParams) - if actErr != nil { - return nil, actErr - } - - // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init3.ExecParams{ - CodeCID: builtin3.MultisigActorCodeID, - ConstructorParams: enc, - } - - enc, actErr = actors.SerializeParams(execParams) - if actErr != nil { - return nil, actErr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Method: builtin3.MethodsInit.Exec, - Params: enc, - Value: initialAmount, - }, nil -} diff --git a/chain/actors/builtin/multisig/message4.go b/chain/actors/builtin/multisig/message4.go deleted file mode 100644 index 4fdccc9ab..000000000 --- a/chain/actors/builtin/multisig/message4.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package multisig - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - init4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - multisig4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message4 struct{ message0 } - -func (m message4) Create( - signers []address.Address, threshold uint64, - unlockStart, unlockDuration abi.ChainEpoch, - initialAmount abi.TokenAmount, -) (*types.Message, error) { - - lenAddrs := uint64(len(signers)) - - if lenAddrs < threshold { - return nil, fmt.Errorf("cannot require signing of more addresses than provided for multisig") - } - - if threshold == 0 { - threshold = lenAddrs - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - // Set up constructor parameters for multisig - msigParams := &multisig4.ConstructorParams{ - Signers: signers, - NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration, - StartEpoch: unlockStart, - } - - enc, actErr := actors.SerializeParams(msigParams) - if actErr != nil { - return nil, actErr - } - - // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init4.ExecParams{ - CodeCID: builtin4.MultisigActorCodeID, - ConstructorParams: enc, - } - - enc, actErr = actors.SerializeParams(execParams) - if actErr != nil { - return nil, actErr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Method: builtin4.MethodsInit.Exec, - Params: enc, - Value: initialAmount, - }, nil -} diff --git a/chain/actors/builtin/multisig/message5.go b/chain/actors/builtin/multisig/message5.go deleted file mode 100644 index cfe16919d..000000000 --- a/chain/actors/builtin/multisig/message5.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package multisig - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - init5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" - multisig5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message5 struct{ message0 } - -func (m message5) Create( - signers []address.Address, threshold uint64, - unlockStart, unlockDuration abi.ChainEpoch, - initialAmount abi.TokenAmount, -) (*types.Message, error) { - - lenAddrs := uint64(len(signers)) - - if lenAddrs < threshold { - return nil, fmt.Errorf("cannot require signing of more addresses than provided for multisig") - } - - if threshold == 0 { - threshold = lenAddrs - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - // Set up constructor parameters for multisig - msigParams := &multisig5.ConstructorParams{ - Signers: signers, - NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration, - StartEpoch: unlockStart, - } - - enc, actErr := actors.SerializeParams(msigParams) - if actErr != nil { - return nil, actErr - } - - // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init5.ExecParams{ - CodeCID: builtin5.MultisigActorCodeID, - ConstructorParams: enc, - } - - enc, actErr = actors.SerializeParams(execParams) - if actErr != nil { - return nil, actErr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Method: builtin5.MethodsInit.Exec, - Params: enc, - Value: initialAmount, - }, nil -} diff --git a/chain/actors/builtin/multisig/message6.go b/chain/actors/builtin/multisig/message6.go deleted file mode 100644 index 837803e01..000000000 --- a/chain/actors/builtin/multisig/message6.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package multisig - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - init6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/init" - multisig6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message6 struct{ message0 } - -func (m message6) Create( - signers []address.Address, threshold uint64, - unlockStart, unlockDuration abi.ChainEpoch, - initialAmount abi.TokenAmount, -) (*types.Message, error) { - - lenAddrs := uint64(len(signers)) - - if lenAddrs < threshold { - return nil, fmt.Errorf("cannot require signing of more addresses than provided for multisig") - } - - if threshold == 0 { - threshold = lenAddrs - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - // Set up constructor parameters for multisig - msigParams := &multisig6.ConstructorParams{ - Signers: signers, - NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration, - StartEpoch: unlockStart, - } - - enc, actErr := actors.SerializeParams(msigParams) - if actErr != nil { - return nil, actErr - } - - // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init6.ExecParams{ - CodeCID: builtin6.MultisigActorCodeID, - ConstructorParams: enc, - } - - enc, actErr = actors.SerializeParams(execParams) - if actErr != nil { - return nil, actErr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Method: builtin6.MethodsInit.Exec, - Params: enc, - Value: initialAmount, - }, nil -} diff --git a/chain/actors/builtin/multisig/message7.go b/chain/actors/builtin/multisig/message7.go deleted file mode 100644 index 3a3e08999..000000000 --- a/chain/actors/builtin/multisig/message7.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package multisig - -import ( - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init" - multisig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message7 struct{ message0 } - -func (m message7) Create( - signers []address.Address, threshold uint64, - unlockStart, unlockDuration abi.ChainEpoch, - initialAmount abi.TokenAmount, -) (*types.Message, error) { - - lenAddrs := uint64(len(signers)) - - if lenAddrs < threshold { - return nil, fmt.Errorf("cannot require signing of more addresses than provided for multisig") - } - - if threshold == 0 { - threshold = lenAddrs - } - - if m.from == address.Undef { - return nil, fmt.Errorf("must provide source address") - } - - // Set up constructor parameters for multisig - msigParams := &multisig7.ConstructorParams{ - Signers: signers, - NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration, - StartEpoch: unlockStart, - } - - enc, actErr := actors.SerializeParams(msigParams) - if actErr != nil { - return nil, actErr - } - - // new actors are created by invoking 'exec' on the init actor with the constructor params - execParams := &init7.ExecParams{ - CodeCID: builtin7.MultisigActorCodeID, - ConstructorParams: enc, - } - - enc, actErr = actors.SerializeParams(execParams) - if actErr != nil { - return nil, actErr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Method: builtin7.MethodsInit.Exec, - Params: enc, - Value: initialAmount, - }, nil -} diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go index 283a1be39..42643a6db 100644 --- a/chain/actors/builtin/multisig/multisig.go +++ b/chain/actors/builtin/multisig/multisig.go @@ -12,7 +12,7 @@ import ( "github.com/filecoin-project/go-state-types/cbor" "github.com/ipfs/go-cid" - msig7 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" + msig8 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" @@ -21,46 +21,29 @@ import ( builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" + lotusactors "github.com/filecoin-project/lotus/chain/actors" ) -func init() { - - builtin.RegisterActorState(builtin0.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) - - builtin.RegisterActorState(builtin3.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.MultisigKey { + return nil, fmt.Errorf("actor code is not multisig: %s", name) + } - builtin.RegisterActorState(builtin5.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) + switch actors.Version(av) { - builtin.RegisterActorState(builtin6.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) + case actors.Version8: + return load8(store, act.Head) - builtin.RegisterActorState(builtin7.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} + } + } -func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { case builtin0.MultisigActorCodeID: @@ -85,6 +68,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } @@ -92,6 +76,8 @@ type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error) StartEpoch() (abi.ChainEpoch, error) @@ -103,80 +89,25 @@ type State interface { ForEachPendingTxn(func(id int64, txn Transaction) error) error PendingTxnChanged(State) (bool, error) - transactions() (adt.Map, error) + PendingTransactionsMap() (adt.Map, error) + PendingTransactionsMapBitWidth() int + PendingTransactionsMapHashFunction() func(input []byte) []byte decodeTransaction(val *cbg.Deferred) (Transaction, error) } -type Transaction = msig7.Transaction - -var Methods = builtin7.MethodsMultisig - -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.MultisigActorCodeID, - builtin2.MultisigActorCodeID, - builtin3.MultisigActorCodeID, - builtin4.MultisigActorCodeID, - builtin5.MultisigActorCodeID, - builtin6.MultisigActorCodeID, - builtin7.MultisigActorCodeID, - } -} - -func Message(version actors.Version, from address.Address) MessageBuilder { - switch version { - - case actors.Version0: - return message0{from} - - case actors.Version2: - return message2{message0{from}} +type Transaction = msig8.Transaction - case actors.Version3: - return message3{message0{from}} - - case actors.Version4: - return message4{message0{from}} - - case actors.Version5: - return message5{message0{from}} - - case actors.Version6: - return message6{message0{from}} - - case actors.Version7: - return message7{message0{from}} - default: - panic(fmt.Sprintf("unsupported actors version: %d", version)) - } -} - -type MessageBuilder interface { - // Create a new multisig with the specified parameters. - Create(signers []address.Address, threshold uint64, - vestingStart, vestingDuration abi.ChainEpoch, - initialAmount abi.TokenAmount) (*types.Message, error) - - // Propose a transaction to the given multisig. - Propose(msig, target address.Address, amt abi.TokenAmount, - method abi.MethodNum, params []byte) (*types.Message, error) - - // Approve a multisig transaction. The "hash" is optional. - Approve(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error) - - // Cancel a multisig transaction. The "hash" is optional. - Cancel(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error) -} +var Methods = builtin8.MethodsMultisig // these types are the same between v0 and v6 -type ProposalHashData = msig7.ProposalHashData -type ProposeReturn = msig7.ProposeReturn -type ProposeParams = msig7.ProposeParams -type ApproveReturn = msig7.ApproveReturn -type TxnIDParams = msig7.TxnIDParams +type ProposalHashData = msig8.ProposalHashData +type ProposeReturn = msig8.ProposeReturn +type ProposeParams = msig8.ProposeParams +type ApproveReturn = msig8.ApproveReturn +type TxnIDParams = msig8.TxnIDParams func txnParams(id uint64, data *ProposalHashData) ([]byte, error) { - params := msig7.TxnIDParams{ID: msig7.TxnID(id)} + params := msig8.TxnIDParams{ID: msig8.TxnID(id)} if data != nil { if data.Requester.Protocol() != address.ID { return nil, fmt.Errorf("proposer address must be an ID address, was %s", data.Requester) @@ -197,3 +128,29 @@ func txnParams(id uint64, data *ProposalHashData) ([]byte, error) { return actors.SerializeParams(¶ms) } + +func AllCodes() []cid.Cid { + return []cid.Cid{ + (&state0{}).Code(), + (&state2{}).Code(), + (&state3{}).Code(), + (&state4{}).Code(), + (&state5{}).Code(), + (&state6{}).Code(), + (&state7{}).Code(), + (&state8{}).Code(), + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + actors.Version0: (&state0{}).Code(), + actors.Version2: (&state2{}).Code(), + actors.Version3: (&state3{}).Code(), + actors.Version4: (&state4{}).Code(), + actors.Version5: (&state5{}).Code(), + actors.Version6: (&state6{}).Code(), + actors.Version7: (&state7{}).Code(), + actors.Version8: (&state8{}).Code(), + } +} diff --git a/chain/actors/builtin/multisig/state.go.template b/chain/actors/builtin/multisig/state.go.template index c7e013b85..00e8a2ac0 100644 --- a/chain/actors/builtin/multisig/state.go.template +++ b/chain/actors/builtin/multisig/state.go.template @@ -12,11 +12,22 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" - msig{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/multisig" + {{if (le .v 1)}} + sha256simd "github.com/minio/sha256-simd" + {{else}} + "crypto/sha256" + {{end}} + + {{if (le .v 2)}} + msig{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/multisig" + {{else}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + msig{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/multisig" + {{end}} ) var _ State = (*state{{.v}})(nil) @@ -35,10 +46,6 @@ type state{{.v}} struct { store adt.Store } -func (s *state{{.v}}) Code() cid.Cid { - return builtin{{.v}}.MultisigActorCodeID -} - func (s *state{{.v}}) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } @@ -87,10 +94,32 @@ func (s *state{{.v}}) PendingTxnChanged(other State) (bool, error) { return !s.State.PendingTxns.Equals(other{{.v}}.PendingTxns), nil } -func (s *state{{.v}}) transactions() (adt.Map, error) { +func (s *state{{.v}}) PendingTransactionsMap() (adt.Map, error) { return adt{{.v}}.AsMap(s.store, s.PendingTxns{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) } +func (s *state{{.v}}) PendingTransactionsMapBitWidth() int { + {{if (ge .v 3)}} + return builtin{{.v}}.DefaultHamtBitwidth + {{else}} + return 5 + {{end}} +} + +func (s *state{{.v}}) PendingTransactionsMapHashFunction() func(input []byte) []byte { + {{if (le .v 1)}} + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + {{else}} + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + {{end}} +} + func (s *state{{.v}}) decodeTransaction(val *cbg.Deferred) (Transaction, error) { var tx msig{{.v}}.Transaction if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -98,3 +127,20 @@ func (s *state{{.v}}) decodeTransaction(val *cbg.Deferred) (Transaction, error) } return tx, nil } + +func (s *state{{.v}}) ActorKey() string { + return actors.MultisigKey +} + +func (s *state{{.v}}) ActorVersion() actors.Version { + return actors.Version{{.v}} +} + +func (s *state{{.v}}) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go index 3d42def2d..dab209de7 100644 --- a/chain/actors/builtin/multisig/v0.go +++ b/chain/actors/builtin/multisig/v0.go @@ -10,12 +10,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + sha256simd "github.com/minio/sha256-simd" + msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" ) @@ -35,10 +37,6 @@ type state0 struct { store adt.Store } -func (s *state0) Code() cid.Cid { - return builtin0.MultisigActorCodeID -} - func (s *state0) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } @@ -87,10 +85,25 @@ func (s *state0) PendingTxnChanged(other State) (bool, error) { return !s.State.PendingTxns.Equals(other0.PendingTxns), nil } -func (s *state0) transactions() (adt.Map, error) { +func (s *state0) PendingTransactionsMap() (adt.Map, error) { return adt0.AsMap(s.store, s.PendingTxns) } +func (s *state0) PendingTransactionsMapBitWidth() int { + + return 5 + +} + +func (s *state0) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + +} + func (s *state0) decodeTransaction(val *cbg.Deferred) (Transaction, error) { var tx msig0.Transaction if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -98,3 +111,20 @@ func (s *state0) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state0) ActorKey() string { + return actors.MultisigKey +} + +func (s *state0) ActorVersion() actors.Version { + return actors.Version0 +} + +func (s *state0) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/v2.go b/chain/actors/builtin/multisig/v2.go index 60e6c2765..15efe6431 100644 --- a/chain/actors/builtin/multisig/v2.go +++ b/chain/actors/builtin/multisig/v2.go @@ -10,12 +10,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "crypto/sha256" + msig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig" ) @@ -35,10 +37,6 @@ type state2 struct { store adt.Store } -func (s *state2) Code() cid.Cid { - return builtin2.MultisigActorCodeID -} - func (s *state2) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } @@ -87,10 +85,25 @@ func (s *state2) PendingTxnChanged(other State) (bool, error) { return !s.State.PendingTxns.Equals(other2.PendingTxns), nil } -func (s *state2) transactions() (adt.Map, error) { +func (s *state2) PendingTransactionsMap() (adt.Map, error) { return adt2.AsMap(s.store, s.PendingTxns) } +func (s *state2) PendingTransactionsMapBitWidth() int { + + return 5 + +} + +func (s *state2) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state2) decodeTransaction(val *cbg.Deferred) (Transaction, error) { var tx msig2.Transaction if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -98,3 +111,20 @@ func (s *state2) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state2) ActorKey() string { + return actors.MultisigKey +} + +func (s *state2) ActorVersion() actors.Version { + return actors.Version2 +} + +func (s *state2) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/v3.go b/chain/actors/builtin/multisig/v3.go index 24a692bf4..d4979a7b4 100644 --- a/chain/actors/builtin/multisig/v3.go +++ b/chain/actors/builtin/multisig/v3.go @@ -10,11 +10,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" msig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig" ) @@ -35,10 +38,6 @@ type state3 struct { store adt.Store } -func (s *state3) Code() cid.Cid { - return builtin3.MultisigActorCodeID -} - func (s *state3) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } @@ -87,10 +86,25 @@ func (s *state3) PendingTxnChanged(other State) (bool, error) { return !s.State.PendingTxns.Equals(other3.PendingTxns), nil } -func (s *state3) transactions() (adt.Map, error) { +func (s *state3) PendingTransactionsMap() (adt.Map, error) { return adt3.AsMap(s.store, s.PendingTxns, builtin3.DefaultHamtBitwidth) } +func (s *state3) PendingTransactionsMapBitWidth() int { + + return builtin3.DefaultHamtBitwidth + +} + +func (s *state3) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state3) decodeTransaction(val *cbg.Deferred) (Transaction, error) { var tx msig3.Transaction if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -98,3 +112,20 @@ func (s *state3) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state3) ActorKey() string { + return actors.MultisigKey +} + +func (s *state3) ActorVersion() actors.Version { + return actors.Version3 +} + +func (s *state3) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/v4.go b/chain/actors/builtin/multisig/v4.go index 5efd1d1da..ba1968286 100644 --- a/chain/actors/builtin/multisig/v4.go +++ b/chain/actors/builtin/multisig/v4.go @@ -10,11 +10,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" msig4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" ) @@ -35,10 +38,6 @@ type state4 struct { store adt.Store } -func (s *state4) Code() cid.Cid { - return builtin4.MultisigActorCodeID -} - func (s *state4) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } @@ -87,10 +86,25 @@ func (s *state4) PendingTxnChanged(other State) (bool, error) { return !s.State.PendingTxns.Equals(other4.PendingTxns), nil } -func (s *state4) transactions() (adt.Map, error) { +func (s *state4) PendingTransactionsMap() (adt.Map, error) { return adt4.AsMap(s.store, s.PendingTxns, builtin4.DefaultHamtBitwidth) } +func (s *state4) PendingTransactionsMapBitWidth() int { + + return builtin4.DefaultHamtBitwidth + +} + +func (s *state4) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state4) decodeTransaction(val *cbg.Deferred) (Transaction, error) { var tx msig4.Transaction if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -98,3 +112,20 @@ func (s *state4) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state4) ActorKey() string { + return actors.MultisigKey +} + +func (s *state4) ActorVersion() actors.Version { + return actors.Version4 +} + +func (s *state4) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/v5.go b/chain/actors/builtin/multisig/v5.go index f6d09d820..692727f6e 100644 --- a/chain/actors/builtin/multisig/v5.go +++ b/chain/actors/builtin/multisig/v5.go @@ -10,11 +10,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" msig5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" ) @@ -35,10 +38,6 @@ type state5 struct { store adt.Store } -func (s *state5) Code() cid.Cid { - return builtin5.MultisigActorCodeID -} - func (s *state5) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } @@ -87,10 +86,25 @@ func (s *state5) PendingTxnChanged(other State) (bool, error) { return !s.State.PendingTxns.Equals(other5.PendingTxns), nil } -func (s *state5) transactions() (adt.Map, error) { +func (s *state5) PendingTransactionsMap() (adt.Map, error) { return adt5.AsMap(s.store, s.PendingTxns, builtin5.DefaultHamtBitwidth) } +func (s *state5) PendingTransactionsMapBitWidth() int { + + return builtin5.DefaultHamtBitwidth + +} + +func (s *state5) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state5) decodeTransaction(val *cbg.Deferred) (Transaction, error) { var tx msig5.Transaction if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -98,3 +112,20 @@ func (s *state5) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state5) ActorKey() string { + return actors.MultisigKey +} + +func (s *state5) ActorVersion() actors.Version { + return actors.Version5 +} + +func (s *state5) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/v6.go b/chain/actors/builtin/multisig/v6.go index 81eb98fdf..e953b4875 100644 --- a/chain/actors/builtin/multisig/v6.go +++ b/chain/actors/builtin/multisig/v6.go @@ -10,11 +10,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" msig6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/multisig" ) @@ -35,10 +38,6 @@ type state6 struct { store adt.Store } -func (s *state6) Code() cid.Cid { - return builtin6.MultisigActorCodeID -} - func (s *state6) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } @@ -87,10 +86,25 @@ func (s *state6) PendingTxnChanged(other State) (bool, error) { return !s.State.PendingTxns.Equals(other6.PendingTxns), nil } -func (s *state6) transactions() (adt.Map, error) { +func (s *state6) PendingTransactionsMap() (adt.Map, error) { return adt6.AsMap(s.store, s.PendingTxns, builtin6.DefaultHamtBitwidth) } +func (s *state6) PendingTransactionsMapBitWidth() int { + + return builtin6.DefaultHamtBitwidth + +} + +func (s *state6) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state6) decodeTransaction(val *cbg.Deferred) (Transaction, error) { var tx msig6.Transaction if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -98,3 +112,20 @@ func (s *state6) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state6) ActorKey() string { + return actors.MultisigKey +} + +func (s *state6) ActorVersion() actors.Version { + return actors.Version6 +} + +func (s *state6) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/v7.go b/chain/actors/builtin/multisig/v7.go index 2d5ac80c7..26ae095f7 100644 --- a/chain/actors/builtin/multisig/v7.go +++ b/chain/actors/builtin/multisig/v7.go @@ -10,11 +10,14 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" msig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig" ) @@ -35,10 +38,6 @@ type state7 struct { store adt.Store } -func (s *state7) Code() cid.Cid { - return builtin7.MultisigActorCodeID -} - func (s *state7) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil } @@ -87,10 +86,25 @@ func (s *state7) PendingTxnChanged(other State) (bool, error) { return !s.State.PendingTxns.Equals(other7.PendingTxns), nil } -func (s *state7) transactions() (adt.Map, error) { +func (s *state7) PendingTransactionsMap() (adt.Map, error) { return adt7.AsMap(s.store, s.PendingTxns, builtin7.DefaultHamtBitwidth) } +func (s *state7) PendingTransactionsMapBitWidth() int { + + return builtin7.DefaultHamtBitwidth + +} + +func (s *state7) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state7) decodeTransaction(val *cbg.Deferred) (Transaction, error) { var tx msig7.Transaction if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -98,3 +112,20 @@ func (s *state7) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state7) ActorKey() string { + return actors.MultisigKey +} + +func (s *state7) ActorVersion() actors.Version { + return actors.Version7 +} + +func (s *state7) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/multisig/v8.go b/chain/actors/builtin/multisig/v8.go new file mode 100644 index 000000000..5de1df377 --- /dev/null +++ b/chain/actors/builtin/multisig/v8.go @@ -0,0 +1,131 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package multisig + +import ( + "bytes" + "encoding/binary" + "fmt" + + adt8 "github.com/filecoin-project/specs-actors/v8/actors/util/adt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lily/chain/actors/adt" + + "crypto/sha256" + + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" + msig8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/multisig" +) + +var _ State = (*state8)(nil) + +func load8(store adt.Store, root cid.Cid) (State, error) { + out := state8{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state8 struct { + msig8.State + store adt.Store +} + +func (s *state8) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) { + return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil +} + +func (s *state8) StartEpoch() (abi.ChainEpoch, error) { + return s.State.StartEpoch, nil +} + +func (s *state8) UnlockDuration() (abi.ChainEpoch, error) { + return s.State.UnlockDuration, nil +} + +func (s *state8) InitialBalance() (abi.TokenAmount, error) { + return s.State.InitialBalance, nil +} + +func (s *state8) Threshold() (uint64, error) { + return s.State.NumApprovalsThreshold, nil +} + +func (s *state8) Signers() ([]address.Address, error) { + return s.State.Signers, nil +} + +func (s *state8) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error { + arr, err := adt8.AsMap(s.store, s.State.PendingTxns, builtin8.DefaultHamtBitwidth) + if err != nil { + return err + } + var out msig8.Transaction + return arr.ForEach(&out, func(key string) error { + txid, n := binary.Varint([]byte(key)) + if n <= 0 { + return fmt.Errorf("invalid pending transaction key: %v", key) + } + return cb(txid, (Transaction)(out)) //nolint:unconvert + }) +} + +func (s *state8) PendingTxnChanged(other State) (bool, error) { + other8, ok := other.(*state8) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.PendingTxns.Equals(other8.PendingTxns), nil +} + +func (s *state8) PendingTransactionsMap() (adt.Map, error) { + return adt8.AsMap(s.store, s.PendingTxns, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) PendingTransactionsMapBitWidth() int { + + return builtin8.DefaultHamtBitwidth + +} + +func (s *state8) PendingTransactionsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state8) decodeTransaction(val *cbg.Deferred) (Transaction, error) { + var tx msig8.Transaction + if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return Transaction{}, err + } + return tx, nil +} + +func (s *state8) ActorKey() string { + return actors.MultisigKey +} + +func (s *state8) ActorVersion() actors.Version { + return actors.Version8 +} + +func (s *state8) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/paych/actor.go.template b/chain/actors/builtin/paych/actor.go.template deleted file mode 100644 index e150a569a..000000000 --- a/chain/actors/builtin/paych/actor.go.template +++ /dev/null @@ -1,140 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "encoding/base64" - "fmt" - - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - big "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-state-types/cbor" - "github.com/ipfs/go-cid" - ipldcbor "github.com/ipfs/go-ipld-cbor" - - paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" -{{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" -{{- end}} - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" -) - -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.PaymentChannelActorCodeID, - {{- end}} - } -} - -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} - -// Load returns an abstract copy of payment channel state, irregardless of actor version -func Load(store adt.Store, act *types.Actor) (State, error) { - switch act.Code { -{{range .versions}} - case builtin{{.}}.PaymentChannelActorCodeID: - return load{{.}}(store, act.Head) -{{end}} - } - return nil, fmt.Errorf("unknown actor code %s", act.Code) -} - -func MakeState(store adt.Store, av actors.Version) (State, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return make{{.}}(store) -{{end}} -} - return nil, fmt.Errorf("unknown actor version %d", av) -} - -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.PaymentChannelActorCodeID, nil -{{end}} - } - - return cid.Undef, fmt.Errorf("unknown actor version %d", av) -} - -// State is an abstract version of payment channel state that works across -// versions -type State interface { - cbor.Marshaler - // Channel owner, who has funded the actor - From() (address.Address, error) - // Recipient of payouts from channel - To() (address.Address, error) - - // Height at which the channel can be `Collected` - SettlingAt() (abi.ChainEpoch, error) - - // Amount successfully redeemed through the payment channel, paid out on `Collect()` - ToSend() (abi.TokenAmount, error) - - // Get total number of lanes - LaneCount() (uint64, error) - - // Iterate lane states - ForEachLaneState(cb func(idx uint64, dl LaneState) error) error - - GetState() interface{} -} - -// LaneState is an abstract copy of the state of a single lane -type LaneState interface { - Redeemed() (big.Int, error) - Nonce() (uint64, error) -} - -type SignedVoucher = paych0.SignedVoucher -type ModVerifyParams = paych0.ModVerifyParams - -// DecodeSignedVoucher decodes base64 encoded signed voucher. -func DecodeSignedVoucher(s string) (*SignedVoucher, error) { - data, err := base64.RawURLEncoding.DecodeString(s) - if err != nil { - return nil, err - } - - var sv SignedVoucher - if err := ipldcbor.DecodeInto(data, &sv); err != nil { - return nil, err - } - - return &sv, nil -} - -var Methods = builtin{{.latestVersion}}.MethodsPaych - -func Message(version actors.Version, from address.Address) MessageBuilder { - switch version { -{{range .versions}} - case actors.Version{{.}}: - return message{{.}}{from} -{{end}} - default: - panic(fmt.Sprintf("unsupported actors version: %d", version)) - } -} - -type MessageBuilder interface { - Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) - Update(paych address.Address, voucher *SignedVoucher, secret []byte) (*types.Message, error) - Settle(paych address.Address) (*types.Message, error) - Collect(paych address.Address) (*types.Message, error) -} diff --git a/chain/actors/builtin/paych/message.go.template b/chain/actors/builtin/paych/message.go.template deleted file mode 100644 index 7e8e88f2e..000000000 --- a/chain/actors/builtin/paych/message.go.template +++ /dev/null @@ -1,81 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" - init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init" - paych{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/paych" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - - -type message{{.v}} struct{ from address.Address } - -func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych{{.v}}.ConstructorParams{From: m.from, To: to}) - if aerr != nil { - return nil, aerr - } - enc, aerr := actors.SerializeParams(&init{{.v}}.ExecParams{ - CodeCID: builtin{{.v}}.PaymentChannelActorCodeID, - ConstructorParams: params, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, - Method: builtin{{.v}}.MethodsInit.Exec, - Params: enc, - }, nil -} - -func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych{{.v}}.UpdateChannelStateParams{ - {{if (ge .v 7)}} - Sv: toV{{.v}}SignedVoucher(*sv), - {{else}} - Sv: *sv, - {{end}} - Secret: secret, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin{{.v}}.MethodsPaych.UpdateChannelState, - Params: params, - }, nil -} - -func (m message{{.v}}) Settle(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin{{.v}}.MethodsPaych.Settle, - }, nil -} - -func (m message{{.v}}) Collect(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin{{.v}}.MethodsPaych.Collect, - }, nil -} diff --git a/chain/actors/builtin/paych/message0.go b/chain/actors/builtin/paych/message0.go deleted file mode 100644 index d6292682b..000000000 --- a/chain/actors/builtin/paych/message0.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - init0 "github.com/filecoin-project/specs-actors/actors/builtin/init" - paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message0 struct{ from address.Address } - -func (m message0) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych0.ConstructorParams{From: m.from, To: to}) - if aerr != nil { - return nil, aerr - } - enc, aerr := actors.SerializeParams(&init0.ExecParams{ - CodeCID: builtin0.PaymentChannelActorCodeID, - ConstructorParams: params, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, - Method: builtin0.MethodsInit.Exec, - Params: enc, - }, nil -} - -func (m message0) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych0.UpdateChannelStateParams{ - - Sv: *sv, - - Secret: secret, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin0.MethodsPaych.UpdateChannelState, - Params: params, - }, nil -} - -func (m message0) Settle(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin0.MethodsPaych.Settle, - }, nil -} - -func (m message0) Collect(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin0.MethodsPaych.Collect, - }, nil -} diff --git a/chain/actors/builtin/paych/message2.go b/chain/actors/builtin/paych/message2.go deleted file mode 100644 index d5327025c..000000000 --- a/chain/actors/builtin/paych/message2.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - init2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/init" - paych2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/paych" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message2 struct{ from address.Address } - -func (m message2) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych2.ConstructorParams{From: m.from, To: to}) - if aerr != nil { - return nil, aerr - } - enc, aerr := actors.SerializeParams(&init2.ExecParams{ - CodeCID: builtin2.PaymentChannelActorCodeID, - ConstructorParams: params, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, - Method: builtin2.MethodsInit.Exec, - Params: enc, - }, nil -} - -func (m message2) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych2.UpdateChannelStateParams{ - - Sv: *sv, - - Secret: secret, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin2.MethodsPaych.UpdateChannelState, - Params: params, - }, nil -} - -func (m message2) Settle(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin2.MethodsPaych.Settle, - }, nil -} - -func (m message2) Collect(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin2.MethodsPaych.Collect, - }, nil -} diff --git a/chain/actors/builtin/paych/message3.go b/chain/actors/builtin/paych/message3.go deleted file mode 100644 index c3e2a7f56..000000000 --- a/chain/actors/builtin/paych/message3.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init" - paych3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/paych" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message3 struct{ from address.Address } - -func (m message3) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych3.ConstructorParams{From: m.from, To: to}) - if aerr != nil { - return nil, aerr - } - enc, aerr := actors.SerializeParams(&init3.ExecParams{ - CodeCID: builtin3.PaymentChannelActorCodeID, - ConstructorParams: params, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, - Method: builtin3.MethodsInit.Exec, - Params: enc, - }, nil -} - -func (m message3) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych3.UpdateChannelStateParams{ - - Sv: *sv, - - Secret: secret, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin3.MethodsPaych.UpdateChannelState, - Params: params, - }, nil -} - -func (m message3) Settle(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin3.MethodsPaych.Settle, - }, nil -} - -func (m message3) Collect(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin3.MethodsPaych.Collect, - }, nil -} diff --git a/chain/actors/builtin/paych/message4.go b/chain/actors/builtin/paych/message4.go deleted file mode 100644 index 5315c6b08..000000000 --- a/chain/actors/builtin/paych/message4.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - init4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/init" - paych4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message4 struct{ from address.Address } - -func (m message4) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych4.ConstructorParams{From: m.from, To: to}) - if aerr != nil { - return nil, aerr - } - enc, aerr := actors.SerializeParams(&init4.ExecParams{ - CodeCID: builtin4.PaymentChannelActorCodeID, - ConstructorParams: params, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, - Method: builtin4.MethodsInit.Exec, - Params: enc, - }, nil -} - -func (m message4) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych4.UpdateChannelStateParams{ - - Sv: *sv, - - Secret: secret, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin4.MethodsPaych.UpdateChannelState, - Params: params, - }, nil -} - -func (m message4) Settle(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin4.MethodsPaych.Settle, - }, nil -} - -func (m message4) Collect(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin4.MethodsPaych.Collect, - }, nil -} diff --git a/chain/actors/builtin/paych/message5.go b/chain/actors/builtin/paych/message5.go deleted file mode 100644 index ba75b6a3e..000000000 --- a/chain/actors/builtin/paych/message5.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - init5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/init" - paych5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message5 struct{ from address.Address } - -func (m message5) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych5.ConstructorParams{From: m.from, To: to}) - if aerr != nil { - return nil, aerr - } - enc, aerr := actors.SerializeParams(&init5.ExecParams{ - CodeCID: builtin5.PaymentChannelActorCodeID, - ConstructorParams: params, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, - Method: builtin5.MethodsInit.Exec, - Params: enc, - }, nil -} - -func (m message5) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych5.UpdateChannelStateParams{ - - Sv: *sv, - - Secret: secret, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin5.MethodsPaych.UpdateChannelState, - Params: params, - }, nil -} - -func (m message5) Settle(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin5.MethodsPaych.Settle, - }, nil -} - -func (m message5) Collect(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin5.MethodsPaych.Collect, - }, nil -} diff --git a/chain/actors/builtin/paych/message6.go b/chain/actors/builtin/paych/message6.go deleted file mode 100644 index 5318c9c1d..000000000 --- a/chain/actors/builtin/paych/message6.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - init6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/init" - paych6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/paych" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message6 struct{ from address.Address } - -func (m message6) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych6.ConstructorParams{From: m.from, To: to}) - if aerr != nil { - return nil, aerr - } - enc, aerr := actors.SerializeParams(&init6.ExecParams{ - CodeCID: builtin6.PaymentChannelActorCodeID, - ConstructorParams: params, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, - Method: builtin6.MethodsInit.Exec, - Params: enc, - }, nil -} - -func (m message6) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych6.UpdateChannelStateParams{ - - Sv: *sv, - - Secret: secret, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin6.MethodsPaych.UpdateChannelState, - Params: params, - }, nil -} - -func (m message6) Settle(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin6.MethodsPaych.Settle, - }, nil -} - -func (m message6) Collect(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin6.MethodsPaych.Collect, - }, nil -} diff --git a/chain/actors/builtin/paych/message7.go b/chain/actors/builtin/paych/message7.go deleted file mode 100644 index 7f88f8425..000000000 --- a/chain/actors/builtin/paych/message7.go +++ /dev/null @@ -1,78 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - init7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/init" - paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" -) - -type message7 struct{ from address.Address } - -func (m message7) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych7.ConstructorParams{From: m.from, To: to}) - if aerr != nil { - return nil, aerr - } - enc, aerr := actors.SerializeParams(&init7.ExecParams{ - CodeCID: builtin7.PaymentChannelActorCodeID, - ConstructorParams: params, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, - Method: builtin7.MethodsInit.Exec, - Params: enc, - }, nil -} - -func (m message7) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { - params, aerr := actors.SerializeParams(&paych7.UpdateChannelStateParams{ - - Sv: toV7SignedVoucher(*sv), - - Secret: secret, - }) - if aerr != nil { - return nil, aerr - } - - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin7.MethodsPaych.UpdateChannelState, - Params: params, - }, nil -} - -func (m message7) Settle(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin7.MethodsPaych.Settle, - }, nil -} - -func (m message7) Collect(paych address.Address) (*types.Message, error) { - return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), - Method: builtin7.MethodsPaych.Collect, - }, nil -} diff --git a/chain/actors/builtin/paych/mock/mock.go b/chain/actors/builtin/paych/mock/mock.go deleted file mode 100644 index c9b359b1b..000000000 --- a/chain/actors/builtin/paych/mock/mock.go +++ /dev/null @@ -1,92 +0,0 @@ -package mock - -import ( - "io" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/lily/chain/actors/builtin/paych" -) - -type mockState struct { - from address.Address - to address.Address - settlingAt abi.ChainEpoch - toSend abi.TokenAmount - lanes map[uint64]paych.LaneState -} - -func (ms *mockState) GetState() interface{} { - return ms -} - -type mockLaneState struct { - redeemed big.Int - nonce uint64 -} - -// NewMockPayChState constructs a state for a payment channel with the set fixed values -// that satisfies the paych.State interface. -func NewMockPayChState(from address.Address, - to address.Address, - settlingAt abi.ChainEpoch, - lanes map[uint64]paych.LaneState, -) paych.State { - return &mockState{from: from, to: to, settlingAt: settlingAt, toSend: big.NewInt(0), lanes: lanes} -} - -// NewMockLaneState constructs a state for a payment channel lane with the set fixed values -// that satisfies the paych.LaneState interface. Useful for populating lanes when -// calling NewMockPayChState -func NewMockLaneState(redeemed big.Int, nonce uint64) paych.LaneState { - return &mockLaneState{redeemed, nonce} -} - -func (ms *mockState) MarshalCBOR(io.Writer) error { - panic("not implemented") -} - -// Channel owner, who has funded the actor -func (ms *mockState) From() (address.Address, error) { - return ms.from, nil -} - -// Recipient of payouts from channel -func (ms *mockState) To() (address.Address, error) { - return ms.to, nil -} - -// Height at which the channel can be `Collected` -func (ms *mockState) SettlingAt() (abi.ChainEpoch, error) { - return ms.settlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (ms *mockState) ToSend() (abi.TokenAmount, error) { - return ms.toSend, nil -} - -// Get total number of lanes -func (ms *mockState) LaneCount() (uint64, error) { - return uint64(len(ms.lanes)), nil -} - -// Iterate lane states -func (ms *mockState) ForEachLaneState(cb func(idx uint64, dl paych.LaneState) error) error { - var lastErr error - for lane, state := range ms.lanes { - if err := cb(lane, state); err != nil { - lastErr = err - } - } - return lastErr -} - -func (mls *mockLaneState) Redeemed() (big.Int, error) { - return mls.redeemed, nil -} - -func (mls *mockLaneState) Nonce() (uint64, error) { - return mls.nonce, nil -} diff --git a/chain/actors/builtin/paych/paych.go b/chain/actors/builtin/paych/paych.go deleted file mode 100644 index 03a6769ad..000000000 --- a/chain/actors/builtin/paych/paych.go +++ /dev/null @@ -1,245 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "encoding/base64" - "fmt" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - big "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/go-state-types/cbor" - "github.com/ipfs/go-cid" - ipldcbor "github.com/ipfs/go-ipld-cbor" - - paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" - - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - - "github.com/filecoin-project/lotus/chain/types" - - "github.com/filecoin-project/lily/chain/actors" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" -) - -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.PaymentChannelActorCodeID, - builtin2.PaymentChannelActorCodeID, - builtin3.PaymentChannelActorCodeID, - builtin4.PaymentChannelActorCodeID, - builtin5.PaymentChannelActorCodeID, - builtin6.PaymentChannelActorCodeID, - builtin7.PaymentChannelActorCodeID, - } -} - -func init() { - - builtin.RegisterActorState(builtin0.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) - - builtin.RegisterActorState(builtin3.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) - - builtin.RegisterActorState(builtin5.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) - - builtin.RegisterActorState(builtin6.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) - - builtin.RegisterActorState(builtin7.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} - -// Load returns an abstract copy of payment channel state, irregardless of actor version -func Load(store adt.Store, act *types.Actor) (State, error) { - switch act.Code { - - case builtin0.PaymentChannelActorCodeID: - return load0(store, act.Head) - - case builtin2.PaymentChannelActorCodeID: - return load2(store, act.Head) - - case builtin3.PaymentChannelActorCodeID: - return load3(store, act.Head) - - case builtin4.PaymentChannelActorCodeID: - return load4(store, act.Head) - - case builtin5.PaymentChannelActorCodeID: - return load5(store, act.Head) - - case builtin6.PaymentChannelActorCodeID: - return load6(store, act.Head) - - case builtin7.PaymentChannelActorCodeID: - return load7(store, act.Head) - - } - return nil, fmt.Errorf("unknown actor code %s", act.Code) -} - -func MakeState(store adt.Store, av actors.Version) (State, error) { - switch av { - - case actors.Version0: - return make0(store) - - case actors.Version2: - return make2(store) - - case actors.Version3: - return make3(store) - - case actors.Version4: - return make4(store) - - case actors.Version5: - return make5(store) - - case actors.Version6: - return make6(store) - - case actors.Version7: - return make7(store) - - } - return nil, fmt.Errorf("unknown actor version %d", av) -} - -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.PaymentChannelActorCodeID, nil - - case actors.Version2: - return builtin2.PaymentChannelActorCodeID, nil - - case actors.Version3: - return builtin3.PaymentChannelActorCodeID, nil - - case actors.Version4: - return builtin4.PaymentChannelActorCodeID, nil - - case actors.Version5: - return builtin5.PaymentChannelActorCodeID, nil - - case actors.Version6: - return builtin6.PaymentChannelActorCodeID, nil - - case actors.Version7: - return builtin7.PaymentChannelActorCodeID, nil - - } - - return cid.Undef, fmt.Errorf("unknown actor version %d", av) -} - -// State is an abstract version of payment channel state that works across -// versions -type State interface { - cbor.Marshaler - // Channel owner, who has funded the actor - From() (address.Address, error) - // Recipient of payouts from channel - To() (address.Address, error) - - // Height at which the channel can be `Collected` - SettlingAt() (abi.ChainEpoch, error) - - // Amount successfully redeemed through the payment channel, paid out on `Collect()` - ToSend() (abi.TokenAmount, error) - - // Get total number of lanes - LaneCount() (uint64, error) - - // Iterate lane states - ForEachLaneState(cb func(idx uint64, dl LaneState) error) error - - GetState() interface{} -} - -// LaneState is an abstract copy of the state of a single lane -type LaneState interface { - Redeemed() (big.Int, error) - Nonce() (uint64, error) -} - -type SignedVoucher = paych0.SignedVoucher -type ModVerifyParams = paych0.ModVerifyParams - -// DecodeSignedVoucher decodes base64 encoded signed voucher. -func DecodeSignedVoucher(s string) (*SignedVoucher, error) { - data, err := base64.RawURLEncoding.DecodeString(s) - if err != nil { - return nil, err - } - - var sv SignedVoucher - if err := ipldcbor.DecodeInto(data, &sv); err != nil { - return nil, err - } - - return &sv, nil -} - -var Methods = builtin7.MethodsPaych - -func Message(version actors.Version, from address.Address) MessageBuilder { - switch version { - - case actors.Version0: - return message0{from} - - case actors.Version2: - return message2{from} - - case actors.Version3: - return message3{from} - - case actors.Version4: - return message4{from} - - case actors.Version5: - return message5{from} - - case actors.Version6: - return message6{from} - - case actors.Version7: - return message7{from} - - default: - panic(fmt.Sprintf("unsupported actors version: %d", version)) - } -} - -type MessageBuilder interface { - Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) - Update(paych address.Address, voucher *SignedVoucher, secret []byte) (*types.Message, error) - Settle(paych address.Address) (*types.Message, error) - Collect(paych address.Address) (*types.Message, error) -} diff --git a/chain/actors/builtin/paych/state.go.template b/chain/actors/builtin/paych/state.go.template deleted file mode 100644 index 2dfb76d05..000000000 --- a/chain/actors/builtin/paych/state.go.template +++ /dev/null @@ -1,134 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - - "github.com/filecoin-project/lily/chain/actors/adt" - - paych{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/paych" - adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" -) - - -var _ State = (*state{{.v}})(nil) - -func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { - out := state{{.v}}{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -func make{{.v}}(store adt.Store) (State, error) { - out := state{{.v}}{store: store} - out.State = paych{{.v}}.State{} - return &out, nil -} - -type state{{.v}} struct { - paych{{.v}}.State - store adt.Store - lsAmt *adt{{.v}}.Array -} - -// Channel owner, who has funded the actor -func (s *state{{.v}}) From() (address.Address, error) { - return s.State.From, nil -} - -// Recipient of payouts from channel -func (s *state{{.v}}) To() (address.Address, error) { - return s.State.To, nil -} - -// Height at which the channel can be `Collected` -func (s *state{{.v}}) SettlingAt() (abi.ChainEpoch, error) { - return s.State.SettlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state{{.v}}) ToSend() (abi.TokenAmount, error) { - return s.State.ToSend, nil -} - -func (s *state{{.v}}) getOrLoadLsAmt() (*adt{{.v}}.Array, error) { - if s.lsAmt != nil { - return s.lsAmt, nil - } - - // Get the lane state from the chain - lsamt, err := adt{{.v}}.AsArray(s.store, s.State.LaneStates{{if (ge .v 3)}}, paych{{.v}}.LaneStatesAmtBitwidth{{end}}) - if err != nil { - return nil, err - } - - s.lsAmt = lsamt - return lsamt, nil -} - -// Get total number of lanes -func (s *state{{.v}}) LaneCount() (uint64, error) { - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return 0, err - } - return lsamt.Length(), nil -} - -func (s *state{{.v}}) GetState() interface{} { - return &s.State -} - -// Iterate lane states -func (s *state{{.v}}) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { - // Get the lane state from the chain - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return err - } - - // Note: we use a map instead of an array to store laneStates because the - // client sets the lane ID (the index) and potentially they could use a - // very large index. - var ls paych{{.v}}.LaneState - return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &laneState{{.v}}{ls}) - }) -} - -type laneState{{.v}} struct { - paych{{.v}}.LaneState -} - -func (ls *laneState{{.v}}) Redeemed() (big.Int, error) { - return ls.LaneState.Redeemed, nil -} - -func (ls *laneState{{.v}}) Nonce() (uint64, error) { - return ls.LaneState.Nonce, nil -} - -{{if (ge .v 7)}} -func toV{{.v}}SignedVoucher(sv SignedVoucher) paych{{.v}}.SignedVoucher { - return paych{{.v}}.SignedVoucher{ - ChannelAddr: sv.ChannelAddr, - TimeLockMin: sv.TimeLockMin, - TimeLockMax: sv.TimeLockMax, - SecretHash: sv.SecretPreimage, - Extra: sv.Extra, - Lane: sv.Lane, - Nonce: sv.Nonce, - Amount: sv.Amount, - MinSettleHeight: sv.MinSettleHeight, - Merges: sv.Merges, - Signature: sv.Signature, - } -} -{{end}} diff --git a/chain/actors/builtin/paych/v0.go b/chain/actors/builtin/paych/v0.go deleted file mode 100644 index 7a1105339..000000000 --- a/chain/actors/builtin/paych/v0.go +++ /dev/null @@ -1,115 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - - "github.com/filecoin-project/lily/chain/actors/adt" - - paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" - adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" -) - -var _ State = (*state0)(nil) - -func load0(store adt.Store, root cid.Cid) (State, error) { - out := state0{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -func make0(store adt.Store) (State, error) { - out := state0{store: store} - out.State = paych0.State{} - return &out, nil -} - -type state0 struct { - paych0.State - store adt.Store - lsAmt *adt0.Array -} - -// Channel owner, who has funded the actor -func (s *state0) From() (address.Address, error) { - return s.State.From, nil -} - -// Recipient of payouts from channel -func (s *state0) To() (address.Address, error) { - return s.State.To, nil -} - -// Height at which the channel can be `Collected` -func (s *state0) SettlingAt() (abi.ChainEpoch, error) { - return s.State.SettlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state0) ToSend() (abi.TokenAmount, error) { - return s.State.ToSend, nil -} - -func (s *state0) getOrLoadLsAmt() (*adt0.Array, error) { - if s.lsAmt != nil { - return s.lsAmt, nil - } - - // Get the lane state from the chain - lsamt, err := adt0.AsArray(s.store, s.State.LaneStates) - if err != nil { - return nil, err - } - - s.lsAmt = lsamt - return lsamt, nil -} - -// Get total number of lanes -func (s *state0) LaneCount() (uint64, error) { - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return 0, err - } - return lsamt.Length(), nil -} - -func (s *state0) GetState() interface{} { - return &s.State -} - -// Iterate lane states -func (s *state0) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { - // Get the lane state from the chain - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return err - } - - // Note: we use a map instead of an array to store laneStates because the - // client sets the lane ID (the index) and potentially they could use a - // very large index. - var ls paych0.LaneState - return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &laneState0{ls}) - }) -} - -type laneState0 struct { - paych0.LaneState -} - -func (ls *laneState0) Redeemed() (big.Int, error) { - return ls.LaneState.Redeemed, nil -} - -func (ls *laneState0) Nonce() (uint64, error) { - return ls.LaneState.Nonce, nil -} diff --git a/chain/actors/builtin/paych/v2.go b/chain/actors/builtin/paych/v2.go deleted file mode 100644 index 45ef4c17a..000000000 --- a/chain/actors/builtin/paych/v2.go +++ /dev/null @@ -1,115 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - - "github.com/filecoin-project/lily/chain/actors/adt" - - paych2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/paych" - adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" -) - -var _ State = (*state2)(nil) - -func load2(store adt.Store, root cid.Cid) (State, error) { - out := state2{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -func make2(store adt.Store) (State, error) { - out := state2{store: store} - out.State = paych2.State{} - return &out, nil -} - -type state2 struct { - paych2.State - store adt.Store - lsAmt *adt2.Array -} - -// Channel owner, who has funded the actor -func (s *state2) From() (address.Address, error) { - return s.State.From, nil -} - -// Recipient of payouts from channel -func (s *state2) To() (address.Address, error) { - return s.State.To, nil -} - -// Height at which the channel can be `Collected` -func (s *state2) SettlingAt() (abi.ChainEpoch, error) { - return s.State.SettlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state2) ToSend() (abi.TokenAmount, error) { - return s.State.ToSend, nil -} - -func (s *state2) getOrLoadLsAmt() (*adt2.Array, error) { - if s.lsAmt != nil { - return s.lsAmt, nil - } - - // Get the lane state from the chain - lsamt, err := adt2.AsArray(s.store, s.State.LaneStates) - if err != nil { - return nil, err - } - - s.lsAmt = lsamt - return lsamt, nil -} - -// Get total number of lanes -func (s *state2) LaneCount() (uint64, error) { - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return 0, err - } - return lsamt.Length(), nil -} - -func (s *state2) GetState() interface{} { - return &s.State -} - -// Iterate lane states -func (s *state2) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { - // Get the lane state from the chain - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return err - } - - // Note: we use a map instead of an array to store laneStates because the - // client sets the lane ID (the index) and potentially they could use a - // very large index. - var ls paych2.LaneState - return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &laneState2{ls}) - }) -} - -type laneState2 struct { - paych2.LaneState -} - -func (ls *laneState2) Redeemed() (big.Int, error) { - return ls.LaneState.Redeemed, nil -} - -func (ls *laneState2) Nonce() (uint64, error) { - return ls.LaneState.Nonce, nil -} diff --git a/chain/actors/builtin/paych/v3.go b/chain/actors/builtin/paych/v3.go deleted file mode 100644 index 5db377e33..000000000 --- a/chain/actors/builtin/paych/v3.go +++ /dev/null @@ -1,115 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - - "github.com/filecoin-project/lily/chain/actors/adt" - - paych3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/paych" - adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" -) - -var _ State = (*state3)(nil) - -func load3(store adt.Store, root cid.Cid) (State, error) { - out := state3{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -func make3(store adt.Store) (State, error) { - out := state3{store: store} - out.State = paych3.State{} - return &out, nil -} - -type state3 struct { - paych3.State - store adt.Store - lsAmt *adt3.Array -} - -// Channel owner, who has funded the actor -func (s *state3) From() (address.Address, error) { - return s.State.From, nil -} - -// Recipient of payouts from channel -func (s *state3) To() (address.Address, error) { - return s.State.To, nil -} - -// Height at which the channel can be `Collected` -func (s *state3) SettlingAt() (abi.ChainEpoch, error) { - return s.State.SettlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state3) ToSend() (abi.TokenAmount, error) { - return s.State.ToSend, nil -} - -func (s *state3) getOrLoadLsAmt() (*adt3.Array, error) { - if s.lsAmt != nil { - return s.lsAmt, nil - } - - // Get the lane state from the chain - lsamt, err := adt3.AsArray(s.store, s.State.LaneStates, paych3.LaneStatesAmtBitwidth) - if err != nil { - return nil, err - } - - s.lsAmt = lsamt - return lsamt, nil -} - -// Get total number of lanes -func (s *state3) LaneCount() (uint64, error) { - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return 0, err - } - return lsamt.Length(), nil -} - -func (s *state3) GetState() interface{} { - return &s.State -} - -// Iterate lane states -func (s *state3) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { - // Get the lane state from the chain - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return err - } - - // Note: we use a map instead of an array to store laneStates because the - // client sets the lane ID (the index) and potentially they could use a - // very large index. - var ls paych3.LaneState - return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &laneState3{ls}) - }) -} - -type laneState3 struct { - paych3.LaneState -} - -func (ls *laneState3) Redeemed() (big.Int, error) { - return ls.LaneState.Redeemed, nil -} - -func (ls *laneState3) Nonce() (uint64, error) { - return ls.LaneState.Nonce, nil -} diff --git a/chain/actors/builtin/paych/v4.go b/chain/actors/builtin/paych/v4.go deleted file mode 100644 index 3fe0b2e80..000000000 --- a/chain/actors/builtin/paych/v4.go +++ /dev/null @@ -1,115 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - - "github.com/filecoin-project/lily/chain/actors/adt" - - paych4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/paych" - adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" -) - -var _ State = (*state4)(nil) - -func load4(store adt.Store, root cid.Cid) (State, error) { - out := state4{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -func make4(store adt.Store) (State, error) { - out := state4{store: store} - out.State = paych4.State{} - return &out, nil -} - -type state4 struct { - paych4.State - store adt.Store - lsAmt *adt4.Array -} - -// Channel owner, who has funded the actor -func (s *state4) From() (address.Address, error) { - return s.State.From, nil -} - -// Recipient of payouts from channel -func (s *state4) To() (address.Address, error) { - return s.State.To, nil -} - -// Height at which the channel can be `Collected` -func (s *state4) SettlingAt() (abi.ChainEpoch, error) { - return s.State.SettlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state4) ToSend() (abi.TokenAmount, error) { - return s.State.ToSend, nil -} - -func (s *state4) getOrLoadLsAmt() (*adt4.Array, error) { - if s.lsAmt != nil { - return s.lsAmt, nil - } - - // Get the lane state from the chain - lsamt, err := adt4.AsArray(s.store, s.State.LaneStates, paych4.LaneStatesAmtBitwidth) - if err != nil { - return nil, err - } - - s.lsAmt = lsamt - return lsamt, nil -} - -// Get total number of lanes -func (s *state4) LaneCount() (uint64, error) { - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return 0, err - } - return lsamt.Length(), nil -} - -func (s *state4) GetState() interface{} { - return &s.State -} - -// Iterate lane states -func (s *state4) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { - // Get the lane state from the chain - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return err - } - - // Note: we use a map instead of an array to store laneStates because the - // client sets the lane ID (the index) and potentially they could use a - // very large index. - var ls paych4.LaneState - return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &laneState4{ls}) - }) -} - -type laneState4 struct { - paych4.LaneState -} - -func (ls *laneState4) Redeemed() (big.Int, error) { - return ls.LaneState.Redeemed, nil -} - -func (ls *laneState4) Nonce() (uint64, error) { - return ls.LaneState.Nonce, nil -} diff --git a/chain/actors/builtin/paych/v5.go b/chain/actors/builtin/paych/v5.go deleted file mode 100644 index ae9c104e3..000000000 --- a/chain/actors/builtin/paych/v5.go +++ /dev/null @@ -1,115 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - - "github.com/filecoin-project/lily/chain/actors/adt" - - paych5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych" - adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt" -) - -var _ State = (*state5)(nil) - -func load5(store adt.Store, root cid.Cid) (State, error) { - out := state5{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -func make5(store adt.Store) (State, error) { - out := state5{store: store} - out.State = paych5.State{} - return &out, nil -} - -type state5 struct { - paych5.State - store adt.Store - lsAmt *adt5.Array -} - -// Channel owner, who has funded the actor -func (s *state5) From() (address.Address, error) { - return s.State.From, nil -} - -// Recipient of payouts from channel -func (s *state5) To() (address.Address, error) { - return s.State.To, nil -} - -// Height at which the channel can be `Collected` -func (s *state5) SettlingAt() (abi.ChainEpoch, error) { - return s.State.SettlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state5) ToSend() (abi.TokenAmount, error) { - return s.State.ToSend, nil -} - -func (s *state5) getOrLoadLsAmt() (*adt5.Array, error) { - if s.lsAmt != nil { - return s.lsAmt, nil - } - - // Get the lane state from the chain - lsamt, err := adt5.AsArray(s.store, s.State.LaneStates, paych5.LaneStatesAmtBitwidth) - if err != nil { - return nil, err - } - - s.lsAmt = lsamt - return lsamt, nil -} - -// Get total number of lanes -func (s *state5) LaneCount() (uint64, error) { - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return 0, err - } - return lsamt.Length(), nil -} - -func (s *state5) GetState() interface{} { - return &s.State -} - -// Iterate lane states -func (s *state5) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { - // Get the lane state from the chain - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return err - } - - // Note: we use a map instead of an array to store laneStates because the - // client sets the lane ID (the index) and potentially they could use a - // very large index. - var ls paych5.LaneState - return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &laneState5{ls}) - }) -} - -type laneState5 struct { - paych5.LaneState -} - -func (ls *laneState5) Redeemed() (big.Int, error) { - return ls.LaneState.Redeemed, nil -} - -func (ls *laneState5) Nonce() (uint64, error) { - return ls.LaneState.Nonce, nil -} diff --git a/chain/actors/builtin/paych/v6.go b/chain/actors/builtin/paych/v6.go deleted file mode 100644 index f024fc791..000000000 --- a/chain/actors/builtin/paych/v6.go +++ /dev/null @@ -1,115 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - - "github.com/filecoin-project/lily/chain/actors/adt" - - paych6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/paych" - adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt" -) - -var _ State = (*state6)(nil) - -func load6(store adt.Store, root cid.Cid) (State, error) { - out := state6{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -func make6(store adt.Store) (State, error) { - out := state6{store: store} - out.State = paych6.State{} - return &out, nil -} - -type state6 struct { - paych6.State - store adt.Store - lsAmt *adt6.Array -} - -// Channel owner, who has funded the actor -func (s *state6) From() (address.Address, error) { - return s.State.From, nil -} - -// Recipient of payouts from channel -func (s *state6) To() (address.Address, error) { - return s.State.To, nil -} - -// Height at which the channel can be `Collected` -func (s *state6) SettlingAt() (abi.ChainEpoch, error) { - return s.State.SettlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state6) ToSend() (abi.TokenAmount, error) { - return s.State.ToSend, nil -} - -func (s *state6) getOrLoadLsAmt() (*adt6.Array, error) { - if s.lsAmt != nil { - return s.lsAmt, nil - } - - // Get the lane state from the chain - lsamt, err := adt6.AsArray(s.store, s.State.LaneStates, paych6.LaneStatesAmtBitwidth) - if err != nil { - return nil, err - } - - s.lsAmt = lsamt - return lsamt, nil -} - -// Get total number of lanes -func (s *state6) LaneCount() (uint64, error) { - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return 0, err - } - return lsamt.Length(), nil -} - -func (s *state6) GetState() interface{} { - return &s.State -} - -// Iterate lane states -func (s *state6) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { - // Get the lane state from the chain - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return err - } - - // Note: we use a map instead of an array to store laneStates because the - // client sets the lane ID (the index) and potentially they could use a - // very large index. - var ls paych6.LaneState - return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &laneState6{ls}) - }) -} - -type laneState6 struct { - paych6.LaneState -} - -func (ls *laneState6) Redeemed() (big.Int, error) { - return ls.LaneState.Redeemed, nil -} - -func (ls *laneState6) Nonce() (uint64, error) { - return ls.LaneState.Nonce, nil -} diff --git a/chain/actors/builtin/paych/v7.go b/chain/actors/builtin/paych/v7.go deleted file mode 100644 index 6f5a44ed5..000000000 --- a/chain/actors/builtin/paych/v7.go +++ /dev/null @@ -1,131 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package paych - -import ( - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - - "github.com/filecoin-project/lily/chain/actors/adt" - - paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych" - adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt" -) - -var _ State = (*state7)(nil) - -func load7(store adt.Store, root cid.Cid) (State, error) { - out := state7{store: store} - err := store.Get(store.Context(), root, &out) - if err != nil { - return nil, err - } - return &out, nil -} - -func make7(store adt.Store) (State, error) { - out := state7{store: store} - out.State = paych7.State{} - return &out, nil -} - -type state7 struct { - paych7.State - store adt.Store - lsAmt *adt7.Array -} - -// Channel owner, who has funded the actor -func (s *state7) From() (address.Address, error) { - return s.State.From, nil -} - -// Recipient of payouts from channel -func (s *state7) To() (address.Address, error) { - return s.State.To, nil -} - -// Height at which the channel can be `Collected` -func (s *state7) SettlingAt() (abi.ChainEpoch, error) { - return s.State.SettlingAt, nil -} - -// Amount successfully redeemed through the payment channel, paid out on `Collect()` -func (s *state7) ToSend() (abi.TokenAmount, error) { - return s.State.ToSend, nil -} - -func (s *state7) getOrLoadLsAmt() (*adt7.Array, error) { - if s.lsAmt != nil { - return s.lsAmt, nil - } - - // Get the lane state from the chain - lsamt, err := adt7.AsArray(s.store, s.State.LaneStates, paych7.LaneStatesAmtBitwidth) - if err != nil { - return nil, err - } - - s.lsAmt = lsamt - return lsamt, nil -} - -// Get total number of lanes -func (s *state7) LaneCount() (uint64, error) { - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return 0, err - } - return lsamt.Length(), nil -} - -func (s *state7) GetState() interface{} { - return &s.State -} - -// Iterate lane states -func (s *state7) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { - // Get the lane state from the chain - lsamt, err := s.getOrLoadLsAmt() - if err != nil { - return err - } - - // Note: we use a map instead of an array to store laneStates because the - // client sets the lane ID (the index) and potentially they could use a - // very large index. - var ls paych7.LaneState - return lsamt.ForEach(&ls, func(i int64) error { - return cb(uint64(i), &laneState7{ls}) - }) -} - -type laneState7 struct { - paych7.LaneState -} - -func (ls *laneState7) Redeemed() (big.Int, error) { - return ls.LaneState.Redeemed, nil -} - -func (ls *laneState7) Nonce() (uint64, error) { - return ls.LaneState.Nonce, nil -} - -func toV7SignedVoucher(sv SignedVoucher) paych7.SignedVoucher { - return paych7.SignedVoucher{ - ChannelAddr: sv.ChannelAddr, - TimeLockMin: sv.TimeLockMin, - TimeLockMax: sv.TimeLockMax, - SecretHash: sv.SecretPreimage, - Extra: sv.Extra, - Lane: sv.Lane, - Nonce: sv.Nonce, - Amount: sv.Amount, - MinSettleHeight: sv.MinSettleHeight, - Merges: sv.Merges, - Signature: sv.Signature, - } -} diff --git a/chain/actors/builtin/power/actor.go.template b/chain/actors/builtin/power/actor.go.template index 8e4ac4f0a..fefbb29d0 100644 --- a/chain/actors/builtin/power/actor.go.template +++ b/chain/actors/builtin/power/actor.go.template @@ -6,6 +6,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" + lotusactors "github.com/filecoin-project/lotus/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" @@ -19,34 +20,40 @@ import ( {{range .versions}} builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" {{- end}} -) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} + "github.com/filecoin-project/lily/chain/actors" +) var ( Address = builtin{{.latestVersion}}.StoragePowerActorAddr Methods = builtin{{.latestVersion}}.MethodsPower ) -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.StoragePowerActorCodeID, - {{- end}} - } -} - func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.PowerKey { + return nil, fmt.Errorf("actor code is not power: %s", name) + } + + switch actors.Version(av) { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.StoragePowerActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.StoragePowerActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } @@ -54,6 +61,8 @@ type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version TotalLocked() (abi.TokenAmount, error) TotalPower() (Claim, error) @@ -70,7 +79,9 @@ type State interface { ClaimsChanged(State) (bool, error) // Diff helpers. Used by Diff* functions internally. - claims() (adt.Map, error) + ClaimsMap() (adt.Map, error) + ClaimsMapBitWidth() int + ClaimsMapHashFunction() func(input []byte) []byte decodeClaim(*cbg.Deferred) (Claim, error) } @@ -88,3 +99,19 @@ func AddClaims(a Claim, b Claim) Claim { QualityAdjPower: big.Add(a.QualityAdjPower, b.QualityAdjPower), } } + +func AllCodes() []cid.Cid { + return []cid.Cid{ {{range .versions}} + (&state{{.}}{}).Code(), + {{- end}} + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + {{- range .versions}} + actors.Version{{.}}: (&state{{.}}{}).Code(), + {{- end}} + } +} + diff --git a/chain/actors/builtin/power/diff.go b/chain/actors/builtin/power/diff.go index 2304f8898..d53e2ac53 100644 --- a/chain/actors/builtin/power/diff.go +++ b/chain/actors/builtin/power/diff.go @@ -6,11 +6,12 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-hamt-ipld/v3" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/adt/diff" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors/adt/diff" ) type ClaimChanges struct { @@ -31,36 +32,33 @@ type ClaimInfo struct { } func DiffClaims(ctx context.Context, store adt.Store, pre, cur State) (*ClaimChanges, error) { - prec, err := pre.claims() - if err != nil { - return nil, err - } - - curc, err := cur.claims() + prec, err := pre.ClaimsMap() if err != nil { return nil, err } - preOpts, err := adt.MapOptsForActorCode(pre.Code()) - if err != nil { - return nil, err - } - - curOpts, err := adt.MapOptsForActorCode(cur.Code()) + curc, err := cur.ClaimsMap() if err != nil { return nil, err } diffContainer := NewClaimDiffContainer(pre, cur) - - if requiresLegacyDiffing(pre, cur, preOpts, curOpts) { + if requiresLegacyDiffing(pre, cur, + &adt.MapOpts{ + Bitwidth: pre.ClaimsMapBitWidth(), + HashFunc: pre.ClaimsMapHashFunction(), + }, + &adt.MapOpts{ + Bitwidth: cur.ClaimsMapBitWidth(), + HashFunc: cur.ClaimsMapHashFunction(), + }) { if err := diff.CompareMap(prec, curc, diffContainer); err != nil { return nil, err } return diffContainer.Results, nil } - changes, err := diff.Hamt(ctx, prec, curc, store, store, hamt.UseTreeBitWidth(preOpts.Bitwidth), hamt.UseHashFunction(hamt.HashFunc(preOpts.HashFunc))) + changes, err := diff.Hamt(ctx, prec, curc, store, store, hamt.UseTreeBitWidth(pre.ClaimsMapBitWidth()), hamt.UseHashFunction(pre.ClaimsMapHashFunction())) if err != nil { return nil, err } diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 2354121ce..a9590d277 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -6,6 +6,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" + lotusactors "github.com/filecoin-project/lotus/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" @@ -24,57 +25,30 @@ import ( builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" -) - -func init() { - - builtin.RegisterActorState(builtin0.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" - builtin.RegisterActorState(builtin3.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) + "github.com/filecoin-project/lily/chain/actors" +) - builtin.RegisterActorState(builtin5.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) +var ( + Address = builtin8.StoragePowerActorAddr + Methods = builtin8.MethodsPower +) - builtin.RegisterActorState(builtin6.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.PowerKey { + return nil, fmt.Errorf("actor code is not power: %s", name) + } - builtin.RegisterActorState(builtin7.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} + switch actors.Version(av) { -var ( - Address = builtin7.StoragePowerActorAddr - Methods = builtin7.MethodsPower -) + case actors.Version8: + return load8(store, act.Head) -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.StoragePowerActorCodeID, - builtin2.StoragePowerActorCodeID, - builtin3.StoragePowerActorCodeID, - builtin4.StoragePowerActorCodeID, - builtin5.StoragePowerActorCodeID, - builtin6.StoragePowerActorCodeID, - builtin7.StoragePowerActorCodeID, + } } -} -func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { case builtin0.StoragePowerActorCodeID: @@ -99,6 +73,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } @@ -106,6 +81,8 @@ type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version TotalLocked() (abi.TokenAmount, error) TotalPower() (Claim, error) @@ -122,7 +99,9 @@ type State interface { ClaimsChanged(State) (bool, error) // Diff helpers. Used by Diff* functions internally. - claims() (adt.Map, error) + ClaimsMap() (adt.Map, error) + ClaimsMapBitWidth() int + ClaimsMapHashFunction() func(input []byte) []byte decodeClaim(*cbg.Deferred) (Claim, error) } @@ -140,3 +119,29 @@ func AddClaims(a Claim, b Claim) Claim { QualityAdjPower: big.Add(a.QualityAdjPower, b.QualityAdjPower), } } + +func AllCodes() []cid.Cid { + return []cid.Cid{ + (&state0{}).Code(), + (&state2{}).Code(), + (&state3{}).Code(), + (&state4{}).Code(), + (&state5{}).Code(), + (&state6{}).Code(), + (&state7{}).Code(), + (&state8{}).Code(), + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + actors.Version0: (&state0{}).Code(), + actors.Version2: (&state2{}).Code(), + actors.Version3: (&state3{}).Code(), + actors.Version4: (&state4{}).Code(), + actors.Version5: (&state5{}).Code(), + actors.Version6: (&state6{}).Code(), + actors.Version7: (&state7{}).Code(), + actors.Version8: (&state8{}).Code(), + } +} diff --git a/chain/actors/builtin/power/state.go.template b/chain/actors/builtin/power/state.go.template index 370e9b7e4..530f4029a 100644 --- a/chain/actors/builtin/power/state.go.template +++ b/chain/actors/builtin/power/state.go.template @@ -3,18 +3,31 @@ package power import ( "bytes" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" - power{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/power" - adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{if (le .v 1)}} + sha256simd "github.com/minio/sha256-simd" + {{else}} + "crypto/sha256" + {{end}} + + {{if (le .v 2)}} + power{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/power" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{else}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + power{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/power" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{end}} ) var _ State = (*state{{.v}})(nil) @@ -33,10 +46,6 @@ type state{{.v}} struct { store adt.Store } -func (s *state{{.v}}) Code() cid.Cid { - return builtin{{.v}}.StoragePowerActorCodeID -} - func (s *state{{.v}}) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } @@ -57,7 +66,7 @@ func (s *state{{.v}}) TotalCommitted() (Claim, error) { } func (s *state{{.v}}) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return Claim{}, false, err } @@ -85,7 +94,7 @@ func (s *state{{.v}}) MinerCounts() (uint64, uint64, error) { } func (s *state{{.v}}) ListAllMiners() ([]address.Address, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return nil, err } @@ -107,7 +116,7 @@ func (s *state{{.v}}) ListAllMiners() ([]address.Address, error) { } func (s *state{{.v}}) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return err } @@ -134,10 +143,32 @@ func (s *state{{.v}}) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other{{.v}}.State.Claims), nil } -func (s *state{{.v}}) claims() (adt.Map, error) { +func (s *state{{.v}}) ClaimsMap() (adt.Map, error) { return adt{{.v}}.AsMap(s.store, s.Claims{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) } +func (s *state{{.v}}) ClaimsMapBitWidth() int { + {{if (ge .v 3)}} + return builtin{{.v}}.DefaultHamtBitwidth + {{else}} + return 5 + {{end}} +} + +func (s *state{{.v}}) ClaimsMapHashFunction() func(input []byte) []byte { + {{if (le .v 1)}} + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + {{else}} + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + {{end}} +} + func (s *state{{.v}}) decodeClaim(val *cbg.Deferred) (Claim, error) { var ci power{{.v}}.Claim if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -152,3 +183,20 @@ func fromV{{.v}}Claim(v{{.v}} power{{.v}}.Claim) Claim { QualityAdjPower: v{{.v}}.QualityAdjPower, } } + +func (s *state{{.v}}) ActorKey() string { + return actors.PowerKey +} + +func (s *state{{.v}}) ActorVersion() actors.Version { + return actors.Version{{.v}} +} + +func (s *state{{.v}}) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index fef474baf..3114f41bb 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -3,16 +3,19 @@ package power import ( "bytes" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + sha256simd "github.com/minio/sha256-simd" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) @@ -33,10 +36,6 @@ type state0 struct { store adt.Store } -func (s *state0) Code() cid.Cid { - return builtin0.StoragePowerActorCodeID -} - func (s *state0) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } @@ -57,7 +56,7 @@ func (s *state0) TotalCommitted() (Claim, error) { } func (s *state0) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return Claim{}, false, err } @@ -85,7 +84,7 @@ func (s *state0) MinerCounts() (uint64, uint64, error) { } func (s *state0) ListAllMiners() ([]address.Address, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return nil, err } @@ -107,7 +106,7 @@ func (s *state0) ListAllMiners() ([]address.Address, error) { } func (s *state0) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return err } @@ -134,10 +133,25 @@ func (s *state0) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other0.State.Claims), nil } -func (s *state0) claims() (adt.Map, error) { +func (s *state0) ClaimsMap() (adt.Map, error) { return adt0.AsMap(s.store, s.Claims) } +func (s *state0) ClaimsMapBitWidth() int { + + return 5 + +} + +func (s *state0) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + +} + func (s *state0) decodeClaim(val *cbg.Deferred) (Claim, error) { var ci power0.Claim if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -152,3 +166,20 @@ func fromV0Claim(v0 power0.Claim) Claim { QualityAdjPower: v0.QualityAdjPower, } } + +func (s *state0) ActorKey() string { + return actors.PowerKey +} + +func (s *state0) ActorVersion() actors.Version { + return actors.Version0 +} + +func (s *state0) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/v2.go b/chain/actors/builtin/power/v2.go index 34516f553..a2667421e 100644 --- a/chain/actors/builtin/power/v2.go +++ b/chain/actors/builtin/power/v2.go @@ -3,16 +3,19 @@ package power import ( "bytes" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "crypto/sha256" + power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power" adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" ) @@ -33,10 +36,6 @@ type state2 struct { store adt.Store } -func (s *state2) Code() cid.Cid { - return builtin2.StoragePowerActorCodeID -} - func (s *state2) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } @@ -57,7 +56,7 @@ func (s *state2) TotalCommitted() (Claim, error) { } func (s *state2) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return Claim{}, false, err } @@ -85,7 +84,7 @@ func (s *state2) MinerCounts() (uint64, uint64, error) { } func (s *state2) ListAllMiners() ([]address.Address, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return nil, err } @@ -107,7 +106,7 @@ func (s *state2) ListAllMiners() ([]address.Address, error) { } func (s *state2) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return err } @@ -134,10 +133,25 @@ func (s *state2) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other2.State.Claims), nil } -func (s *state2) claims() (adt.Map, error) { +func (s *state2) ClaimsMap() (adt.Map, error) { return adt2.AsMap(s.store, s.Claims) } +func (s *state2) ClaimsMapBitWidth() int { + + return 5 + +} + +func (s *state2) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state2) decodeClaim(val *cbg.Deferred) (Claim, error) { var ci power2.Claim if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -152,3 +166,20 @@ func fromV2Claim(v2 power2.Claim) Claim { QualityAdjPower: v2.QualityAdjPower, } } + +func (s *state2) ActorKey() string { + return actors.PowerKey +} + +func (s *state2) ActorVersion() actors.Version { + return actors.Version2 +} + +func (s *state2) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/v3.go b/chain/actors/builtin/power/v3.go index ce30dfb4d..dcc8fa9a3 100644 --- a/chain/actors/builtin/power/v3.go +++ b/chain/actors/builtin/power/v3.go @@ -3,15 +3,19 @@ package power import ( "bytes" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" + "crypto/sha256" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" power3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/power" adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" @@ -33,10 +37,6 @@ type state3 struct { store adt.Store } -func (s *state3) Code() cid.Cid { - return builtin3.StoragePowerActorCodeID -} - func (s *state3) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } @@ -57,7 +57,7 @@ func (s *state3) TotalCommitted() (Claim, error) { } func (s *state3) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return Claim{}, false, err } @@ -85,7 +85,7 @@ func (s *state3) MinerCounts() (uint64, uint64, error) { } func (s *state3) ListAllMiners() ([]address.Address, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (s *state3) ListAllMiners() ([]address.Address, error) { } func (s *state3) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return err } @@ -134,10 +134,25 @@ func (s *state3) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other3.State.Claims), nil } -func (s *state3) claims() (adt.Map, error) { +func (s *state3) ClaimsMap() (adt.Map, error) { return adt3.AsMap(s.store, s.Claims, builtin3.DefaultHamtBitwidth) } +func (s *state3) ClaimsMapBitWidth() int { + + return builtin3.DefaultHamtBitwidth + +} + +func (s *state3) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state3) decodeClaim(val *cbg.Deferred) (Claim, error) { var ci power3.Claim if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -152,3 +167,20 @@ func fromV3Claim(v3 power3.Claim) Claim { QualityAdjPower: v3.QualityAdjPower, } } + +func (s *state3) ActorKey() string { + return actors.PowerKey +} + +func (s *state3) ActorVersion() actors.Version { + return actors.Version3 +} + +func (s *state3) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/v4.go b/chain/actors/builtin/power/v4.go index e4ca11628..e47e89392 100644 --- a/chain/actors/builtin/power/v4.go +++ b/chain/actors/builtin/power/v4.go @@ -3,15 +3,19 @@ package power import ( "bytes" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" + "crypto/sha256" + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" @@ -33,10 +37,6 @@ type state4 struct { store adt.Store } -func (s *state4) Code() cid.Cid { - return builtin4.StoragePowerActorCodeID -} - func (s *state4) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } @@ -57,7 +57,7 @@ func (s *state4) TotalCommitted() (Claim, error) { } func (s *state4) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return Claim{}, false, err } @@ -85,7 +85,7 @@ func (s *state4) MinerCounts() (uint64, uint64, error) { } func (s *state4) ListAllMiners() ([]address.Address, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (s *state4) ListAllMiners() ([]address.Address, error) { } func (s *state4) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return err } @@ -134,10 +134,25 @@ func (s *state4) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other4.State.Claims), nil } -func (s *state4) claims() (adt.Map, error) { +func (s *state4) ClaimsMap() (adt.Map, error) { return adt4.AsMap(s.store, s.Claims, builtin4.DefaultHamtBitwidth) } +func (s *state4) ClaimsMapBitWidth() int { + + return builtin4.DefaultHamtBitwidth + +} + +func (s *state4) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state4) decodeClaim(val *cbg.Deferred) (Claim, error) { var ci power4.Claim if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -152,3 +167,20 @@ func fromV4Claim(v4 power4.Claim) Claim { QualityAdjPower: v4.QualityAdjPower, } } + +func (s *state4) ActorKey() string { + return actors.PowerKey +} + +func (s *state4) ActorVersion() actors.Version { + return actors.Version4 +} + +func (s *state4) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/v5.go b/chain/actors/builtin/power/v5.go index e29d9f4d2..0a707602f 100644 --- a/chain/actors/builtin/power/v5.go +++ b/chain/actors/builtin/power/v5.go @@ -3,15 +3,19 @@ package power import ( "bytes" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" + "crypto/sha256" + builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" power5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/power" adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt" @@ -33,10 +37,6 @@ type state5 struct { store adt.Store } -func (s *state5) Code() cid.Cid { - return builtin5.StoragePowerActorCodeID -} - func (s *state5) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } @@ -57,7 +57,7 @@ func (s *state5) TotalCommitted() (Claim, error) { } func (s *state5) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return Claim{}, false, err } @@ -85,7 +85,7 @@ func (s *state5) MinerCounts() (uint64, uint64, error) { } func (s *state5) ListAllMiners() ([]address.Address, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (s *state5) ListAllMiners() ([]address.Address, error) { } func (s *state5) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return err } @@ -134,10 +134,25 @@ func (s *state5) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other5.State.Claims), nil } -func (s *state5) claims() (adt.Map, error) { +func (s *state5) ClaimsMap() (adt.Map, error) { return adt5.AsMap(s.store, s.Claims, builtin5.DefaultHamtBitwidth) } +func (s *state5) ClaimsMapBitWidth() int { + + return builtin5.DefaultHamtBitwidth + +} + +func (s *state5) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state5) decodeClaim(val *cbg.Deferred) (Claim, error) { var ci power5.Claim if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -152,3 +167,20 @@ func fromV5Claim(v5 power5.Claim) Claim { QualityAdjPower: v5.QualityAdjPower, } } + +func (s *state5) ActorKey() string { + return actors.PowerKey +} + +func (s *state5) ActorVersion() actors.Version { + return actors.Version5 +} + +func (s *state5) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/v6.go b/chain/actors/builtin/power/v6.go index 3b70dd6ac..9f8cd02bc 100644 --- a/chain/actors/builtin/power/v6.go +++ b/chain/actors/builtin/power/v6.go @@ -3,15 +3,19 @@ package power import ( "bytes" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" + "crypto/sha256" + builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" power6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/power" adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt" @@ -33,10 +37,6 @@ type state6 struct { store adt.Store } -func (s *state6) Code() cid.Cid { - return builtin6.StoragePowerActorCodeID -} - func (s *state6) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } @@ -57,7 +57,7 @@ func (s *state6) TotalCommitted() (Claim, error) { } func (s *state6) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return Claim{}, false, err } @@ -85,7 +85,7 @@ func (s *state6) MinerCounts() (uint64, uint64, error) { } func (s *state6) ListAllMiners() ([]address.Address, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (s *state6) ListAllMiners() ([]address.Address, error) { } func (s *state6) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return err } @@ -134,10 +134,25 @@ func (s *state6) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other6.State.Claims), nil } -func (s *state6) claims() (adt.Map, error) { +func (s *state6) ClaimsMap() (adt.Map, error) { return adt6.AsMap(s.store, s.Claims, builtin6.DefaultHamtBitwidth) } +func (s *state6) ClaimsMapBitWidth() int { + + return builtin6.DefaultHamtBitwidth + +} + +func (s *state6) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state6) decodeClaim(val *cbg.Deferred) (Claim, error) { var ci power6.Claim if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -152,3 +167,20 @@ func fromV6Claim(v6 power6.Claim) Claim { QualityAdjPower: v6.QualityAdjPower, } } + +func (s *state6) ActorKey() string { + return actors.PowerKey +} + +func (s *state6) ActorVersion() actors.Version { + return actors.Version6 +} + +func (s *state6) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/v7.go b/chain/actors/builtin/power/v7.go index a54e4aed3..5010ab0a4 100644 --- a/chain/actors/builtin/power/v7.go +++ b/chain/actors/builtin/power/v7.go @@ -3,15 +3,19 @@ package power import ( "bytes" + "fmt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" + "crypto/sha256" + builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" power7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/power" adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt" @@ -33,10 +37,6 @@ type state7 struct { store adt.Store } -func (s *state7) Code() cid.Cid { - return builtin7.StoragePowerActorCodeID -} - func (s *state7) TotalLocked() (abi.TokenAmount, error) { return s.TotalPledgeCollateral, nil } @@ -57,7 +57,7 @@ func (s *state7) TotalCommitted() (Claim, error) { } func (s *state7) MinerPower(addr address.Address) (Claim, bool, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return Claim{}, false, err } @@ -85,7 +85,7 @@ func (s *state7) MinerCounts() (uint64, uint64, error) { } func (s *state7) ListAllMiners() ([]address.Address, error) { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return nil, err } @@ -107,7 +107,7 @@ func (s *state7) ListAllMiners() ([]address.Address, error) { } func (s *state7) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { - claims, err := s.claims() + claims, err := s.ClaimsMap() if err != nil { return err } @@ -134,10 +134,25 @@ func (s *state7) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other7.State.Claims), nil } -func (s *state7) claims() (adt.Map, error) { +func (s *state7) ClaimsMap() (adt.Map, error) { return adt7.AsMap(s.store, s.Claims, builtin7.DefaultHamtBitwidth) } +func (s *state7) ClaimsMapBitWidth() int { + + return builtin7.DefaultHamtBitwidth + +} + +func (s *state7) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + func (s *state7) decodeClaim(val *cbg.Deferred) (Claim, error) { var ci power7.Claim if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { @@ -152,3 +167,20 @@ func fromV7Claim(v7 power7.Claim) Claim { QualityAdjPower: v7.QualityAdjPower, } } + +func (s *state7) ActorKey() string { + return actors.PowerKey +} + +func (s *state7) ActorVersion() actors.Version { + return actors.Version7 +} + +func (s *state7) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/power/v8.go b/chain/actors/builtin/power/v8.go new file mode 100644 index 000000000..a8796f25a --- /dev/null +++ b/chain/actors/builtin/power/v8.go @@ -0,0 +1,186 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package power + +import ( + "bytes" + "fmt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lily/chain/actors" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors/builtin" + + "crypto/sha256" + + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" + power8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/power" + adt8 "github.com/filecoin-project/specs-actors/v8/actors/util/adt" +) + +var _ State = (*state8)(nil) + +func load8(store adt.Store, root cid.Cid) (State, error) { + out := state8{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state8 struct { + power8.State + store adt.Store +} + +func (s *state8) TotalLocked() (abi.TokenAmount, error) { + return s.TotalPledgeCollateral, nil +} + +func (s *state8) TotalPower() (Claim, error) { + return Claim{ + RawBytePower: s.TotalRawBytePower, + QualityAdjPower: s.TotalQualityAdjPower, + }, nil +} + +// Committed power to the network. Includes miners below the minimum threshold. +func (s *state8) TotalCommitted() (Claim, error) { + return Claim{ + RawBytePower: s.TotalBytesCommitted, + QualityAdjPower: s.TotalQABytesCommitted, + }, nil +} + +func (s *state8) MinerPower(addr address.Address) (Claim, bool, error) { + claims, err := s.ClaimsMap() + if err != nil { + return Claim{}, false, err + } + var claim power8.Claim + ok, err := claims.Get(abi.AddrKey(addr), &claim) + if err != nil { + return Claim{}, false, err + } + return Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }, ok, nil +} + +func (s *state8) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) { + return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) +} + +func (s *state8) TotalPowerSmoothed() (builtin.FilterEstimate, error) { + return builtin.FromV8FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil +} + +func (s *state8) MinerCounts() (uint64, uint64, error) { + return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil +} + +func (s *state8) ListAllMiners() ([]address.Address, error) { + claims, err := s.ClaimsMap() + if err != nil { + return nil, err + } + + var miners []address.Address + err = claims.ForEach(nil, func(k string) error { + a, err := address.NewFromBytes([]byte(k)) + if err != nil { + return err + } + miners = append(miners, a) + return nil + }) + if err != nil { + return nil, err + } + + return miners, nil +} + +func (s *state8) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { + claims, err := s.ClaimsMap() + if err != nil { + return err + } + + var claim power8.Claim + return claims.ForEach(&claim, func(k string) error { + a, err := address.NewFromBytes([]byte(k)) + if err != nil { + return err + } + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + }) +} + +func (s *state8) ClaimsChanged(other State) (bool, error) { + other8, ok := other.(*state8) + if !ok { + // treat an upgrade as a change, always + return true, nil + } + return !s.State.Claims.Equals(other8.State.Claims), nil +} + +func (s *state8) ClaimsMap() (adt.Map, error) { + return adt8.AsMap(s.store, s.Claims, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) ClaimsMapBitWidth() int { + + return builtin8.DefaultHamtBitwidth + +} + +func (s *state8) ClaimsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state8) decodeClaim(val *cbg.Deferred) (Claim, error) { + var ci power8.Claim + if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { + return Claim{}, err + } + return fromV8Claim(ci), nil +} + +func fromV8Claim(v8 power8.Claim) Claim { + return Claim{ + RawBytePower: v8.RawBytePower, + QualityAdjPower: v8.QualityAdjPower, + } +} + +func (s *state8) ActorKey() string { + return actors.PowerKey +} + +func (s *state8) ActorVersion() actors.Version { + return actors.Version8 +} + +func (s *state8) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/actor.go.template b/chain/actors/builtin/reward/actor.go.template index 7a1dde25f..f40163914 100644 --- a/chain/actors/builtin/reward/actor.go.template +++ b/chain/actors/builtin/reward/actor.go.template @@ -14,42 +14,53 @@ import ( "github.com/filecoin-project/lotus/chain/types" + lotusactors "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" -) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} + "github.com/filecoin-project/lily/chain/actors" +) var ( Address = builtin{{.latestVersion}}.RewardActorAddr Methods = builtin{{.latestVersion}}.MethodsReward ) -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.RewardActorCodeID, - {{- end}} - } -} - func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.RewardKey { + return nil, fmt.Errorf("actor code is not reward: %s", name) + } + + switch actors.Version(av) { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.RewardActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.RewardActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } type State interface { cbor.Marshaler + Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version + ThisEpochBaselinePower() (abi.StoragePower, error) ThisEpochReward() (abi.StoragePower, error) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) @@ -67,3 +78,18 @@ type State interface { } type AwardBlockRewardParams = reward0.AwardBlockRewardParams + +func AllCodes() []cid.Cid { + return []cid.Cid{ {{range .versions}} + (&state{{.}}{}).Code(), + {{- end}} + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + {{- range .versions}} + actors.Version{{.}}: (&state{{.}}{}).Code(), + {{- end}} + } +} diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index 0b3f7afe8..7e0f9567e 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -16,62 +16,36 @@ import ( builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" -) - -func init() { - - builtin.RegisterActorState(builtin0.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) + lotusactors "github.com/filecoin-project/lotus/chain/actors" - builtin.RegisterActorState(builtin3.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) + "github.com/filecoin-project/lily/chain/actors" +) - builtin.RegisterActorState(builtin5.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) +var ( + Address = builtin8.RewardActorAddr + Methods = builtin8.MethodsReward +) - builtin.RegisterActorState(builtin6.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.RewardKey { + return nil, fmt.Errorf("actor code is not reward: %s", name) + } - builtin.RegisterActorState(builtin7.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} + switch actors.Version(av) { -var ( - Address = builtin7.RewardActorAddr - Methods = builtin7.MethodsReward -) + case actors.Version8: + return load8(store, act.Head) -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.RewardActorCodeID, - builtin2.RewardActorCodeID, - builtin3.RewardActorCodeID, - builtin4.RewardActorCodeID, - builtin5.RewardActorCodeID, - builtin6.RewardActorCodeID, - builtin7.RewardActorCodeID, + } } -} -func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { case builtin0.RewardActorCodeID: @@ -96,12 +70,17 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } type State interface { cbor.Marshaler + Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version + ThisEpochBaselinePower() (abi.StoragePower, error) ThisEpochReward() (abi.StoragePower, error) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) @@ -119,3 +98,29 @@ type State interface { } type AwardBlockRewardParams = reward0.AwardBlockRewardParams + +func AllCodes() []cid.Cid { + return []cid.Cid{ + (&state0{}).Code(), + (&state2{}).Code(), + (&state3{}).Code(), + (&state4{}).Code(), + (&state5{}).Code(), + (&state6{}).Code(), + (&state7{}).Code(), + (&state8{}).Code(), + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + actors.Version0: (&state0{}).Code(), + actors.Version2: (&state2{}).Code(), + actors.Version3: (&state3{}).Code(), + actors.Version4: (&state4{}).Code(), + actors.Version5: (&state5{}).Code(), + actors.Version6: (&state6{}).Code(), + actors.Version7: (&state7{}).Code(), + actors.Version8: (&state8{}).Code(), + } +} diff --git a/chain/actors/builtin/reward/state.go.template b/chain/actors/builtin/reward/state.go.template index 1ff44073c..5167bb68a 100644 --- a/chain/actors/builtin/reward/state.go.template +++ b/chain/actors/builtin/reward/state.go.template @@ -2,10 +2,13 @@ package reward import ( + "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/builtin" miner{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/miner" @@ -102,3 +105,20 @@ func (s *state{{.v}}) PreCommitDepositForPower(networkQAPower builtin.FilterEsti }, sectorWeight), nil } + +func (s *state{{.v}}) ActorKey() string { + return actors.RewardKey +} + +func (s *state{{.v}}) ActorVersion() actors.Version { + return actors.Version{{.v}} +} + +func (s *state{{.v}}) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index 633ac50b2..0fc72e8a8 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -2,9 +2,12 @@ package reward import ( + "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" @@ -84,3 +87,20 @@ func (s *state0) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state0) ActorKey() string { + return actors.RewardKey +} + +func (s *state0) ActorVersion() actors.Version { + return actors.Version0 +} + +func (s *state0) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/v2.go b/chain/actors/builtin/reward/v2.go index 1aacf10ed..9ad0e9a44 100644 --- a/chain/actors/builtin/reward/v2.go +++ b/chain/actors/builtin/reward/v2.go @@ -2,9 +2,12 @@ package reward import ( + "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" @@ -87,3 +90,20 @@ func (s *state2) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state2) ActorKey() string { + return actors.RewardKey +} + +func (s *state2) ActorVersion() actors.Version { + return actors.Version2 +} + +func (s *state2) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/v3.go b/chain/actors/builtin/reward/v3.go index dda40bc3b..ad1eeb765 100644 --- a/chain/actors/builtin/reward/v3.go +++ b/chain/actors/builtin/reward/v3.go @@ -2,9 +2,12 @@ package reward import ( + "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" @@ -87,3 +90,20 @@ func (s *state3) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state3) ActorKey() string { + return actors.RewardKey +} + +func (s *state3) ActorVersion() actors.Version { + return actors.Version3 +} + +func (s *state3) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/v4.go b/chain/actors/builtin/reward/v4.go index 9bc064db8..0efc834ab 100644 --- a/chain/actors/builtin/reward/v4.go +++ b/chain/actors/builtin/reward/v4.go @@ -2,9 +2,12 @@ package reward import ( + "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" @@ -87,3 +90,20 @@ func (s *state4) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state4) ActorKey() string { + return actors.RewardKey +} + +func (s *state4) ActorVersion() actors.Version { + return actors.Version4 +} + +func (s *state4) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/v5.go b/chain/actors/builtin/reward/v5.go index d36d46193..c97fc6030 100644 --- a/chain/actors/builtin/reward/v5.go +++ b/chain/actors/builtin/reward/v5.go @@ -2,9 +2,12 @@ package reward import ( + "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" @@ -87,3 +90,20 @@ func (s *state5) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state5) ActorKey() string { + return actors.RewardKey +} + +func (s *state5) ActorVersion() actors.Version { + return actors.Version5 +} + +func (s *state5) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/v6.go b/chain/actors/builtin/reward/v6.go index dd549e162..62d73b9eb 100644 --- a/chain/actors/builtin/reward/v6.go +++ b/chain/actors/builtin/reward/v6.go @@ -2,9 +2,12 @@ package reward import ( + "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" @@ -87,3 +90,20 @@ func (s *state6) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state6) ActorKey() string { + return actors.RewardKey +} + +func (s *state6) ActorVersion() actors.Version { + return actors.Version6 +} + +func (s *state6) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/v7.go b/chain/actors/builtin/reward/v7.go index 91026ba45..6f68142f5 100644 --- a/chain/actors/builtin/reward/v7.go +++ b/chain/actors/builtin/reward/v7.go @@ -2,9 +2,12 @@ package reward import ( + "fmt" + "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" "github.com/filecoin-project/lily/chain/actors/builtin" @@ -87,3 +90,20 @@ func (s *state7) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state7) ActorKey() string { + return actors.RewardKey +} + +func (s *state7) ActorVersion() actors.Version { + return actors.Version7 +} + +func (s *state7) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/reward/v8.go b/chain/actors/builtin/reward/v8.go new file mode 100644 index 000000000..ac5d8a762 --- /dev/null +++ b/chain/actors/builtin/reward/v8.go @@ -0,0 +1,109 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package reward + +import ( + "fmt" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lily/chain/actors" + "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors/builtin" + + miner8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/miner" + reward8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/reward" + smoothing8 "github.com/filecoin-project/specs-actors/v8/actors/util/smoothing" +) + +var _ State = (*state8)(nil) + +func load8(store adt.Store, root cid.Cid) (State, error) { + out := state8{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state8 struct { + reward8.State + store adt.Store +} + +func (s *state8) ThisEpochReward() (abi.TokenAmount, error) { + return s.State.ThisEpochReward, nil +} + +func (s *state8) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { + + return builtin.FilterEstimate{ + PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate, + VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate, + }, nil + +} + +func (s *state8) ThisEpochBaselinePower() (abi.StoragePower, error) { + return s.State.ThisEpochBaselinePower, nil +} + +func (s *state8) TotalStoragePowerReward() (abi.TokenAmount, error) { + return s.State.TotalStoragePowerReward, nil +} + +func (s *state8) EffectiveBaselinePower() (abi.StoragePower, error) { + return s.State.EffectiveBaselinePower, nil +} + +func (s *state8) EffectiveNetworkTime() (abi.ChainEpoch, error) { + return s.State.EffectiveNetworkTime, nil +} + +func (s *state8) CumsumBaseline() (reward8.Spacetime, error) { + return s.State.CumsumBaseline, nil +} + +func (s *state8) CumsumRealized() (reward8.Spacetime, error) { + return s.State.CumsumRealized, nil +} + +func (s *state8) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) { + return miner8.InitialPledgeForPower( + qaPower, + s.State.ThisEpochBaselinePower, + s.State.ThisEpochRewardSmoothed, + smoothing8.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + circSupply, + ), nil +} + +func (s *state8) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) { + return miner8.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed, + smoothing8.FilterEstimate{ + PositionEstimate: networkQAPower.PositionEstimate, + VelocityEstimate: networkQAPower.VelocityEstimate, + }, + sectorWeight), nil +} + +func (s *state8) ActorKey() string { + return actors.RewardKey +} + +func (s *state8) ActorVersion() actors.Version { + return actors.Version8 +} + +func (s *state8) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/actor.go.template b/chain/actors/builtin/verifreg/actor.go.template index 78614be75..74c19b519 100644 --- a/chain/actors/builtin/verifreg/actor.go.template +++ b/chain/actors/builtin/verifreg/actor.go.template @@ -15,37 +15,41 @@ import ( "github.com/filecoin-project/lotus/chain/types" + lotusactors "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" ) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}} -} - var ( Address = builtin{{.latestVersion}}.VerifiedRegistryActorAddr Methods = builtin{{.latestVersion}}.MethodsVerifiedRegistry ) -func AllCodes() []cid.Cid { - return []cid.Cid{ {{range .versions}} - builtin{{.}}.VerifiedRegistryActorCodeID, - {{- end}} - } -} - func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.VerifregKey { + return nil, fmt.Errorf("actor code is not verifreg: %s", name) + } + + switch actors.Version(av) { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.VerifiedRegistryActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.VerifiedRegistryActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } @@ -53,6 +57,8 @@ type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version RootKey() (address.Address, error) VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error) @@ -60,8 +66,13 @@ type State interface { ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error - verifiers() (adt.Map, error) - verifiedClients() (adt.Map, error) + VerifiersMap() (adt.Map, error) + VerifiersMapBitWidth() int + VerifiersMapHashFunction() func(input []byte) []byte + + VerifiedClientsMap() (adt.Map, error) + VerifiedClientsMapBitWidth() int + VerifiedClientsMapHashFunction() func(input []byte) []byte } type VerifierInfo struct { @@ -79,3 +90,18 @@ type VerifierChanges struct { Modified []VerifierChange Removed []VerifierInfo } + +func AllCodes() []cid.Cid { + return []cid.Cid{ {{range .versions}} + (&state{{.}}{}).Code(), + {{- end}} + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + {{- range .versions}} + actors.Version{{.}}: (&state{{.}}{}).Code(), + {{- end}} + } +} diff --git a/chain/actors/builtin/verifreg/diff.go b/chain/actors/builtin/verifreg/diff.go index b2549797c..e2c71b907 100644 --- a/chain/actors/builtin/verifreg/diff.go +++ b/chain/actors/builtin/verifreg/diff.go @@ -7,60 +7,68 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-hamt-ipld/v3" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/adt/diff" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" cbg "github.com/whyrusleeping/cbor-gen" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" + + "github.com/filecoin-project/lily/chain/actors/adt" + "github.com/filecoin-project/lily/chain/actors/adt/diff" ) func DiffVerifiers(ctx context.Context, store adt.Store, pre, cur State) (*VerifierChanges, error) { ctx, span := otel.Tracer("").Start(ctx, "DiffVerifiers") defer span.End() - prev, err := pre.verifiers() + preMap, err := pre.VerifiersMap() if err != nil { return nil, err } - curv, err := cur.verifiers() + curMap, err := cur.VerifiersMap() if err != nil { return nil, err } - return diffVerifierMap(ctx, store, pre, cur, prev, curv) + return diffVerifierMap(ctx, store, pre, cur, preMap, curMap, + &adt.MapOpts{ + Bitwidth: pre.VerifiersMapBitWidth(), + HashFunc: pre.VerifiersMapHashFunction(), + }, + &adt.MapOpts{ + Bitwidth: cur.VerifiersMapBitWidth(), + HashFunc: cur.VerifiersMapHashFunction(), + }) } func DiffVerifiedClients(ctx context.Context, store adt.Store, pre, cur State) (*VerifierChanges, error) { ctx, span := otel.Tracer("").Start(ctx, "DiffVerifiedClients") defer span.End() - prec, err := pre.verifiedClients() + preMap, err := pre.VerifiedClientsMap() if err != nil { return nil, err } - curc, err := cur.verifiedClients() + curMap, err := cur.VerifiedClientsMap() if err != nil { return nil, err } - return diffVerifierMap(ctx, store, pre, cur, prec, curc) + return diffVerifierMap(ctx, store, pre, cur, preMap, curMap, + &adt.MapOpts{ + Bitwidth: pre.VerifiedClientsMapBitWidth(), + HashFunc: pre.VerifiedClientsMapHashFunction(), + }, + &adt.MapOpts{ + Bitwidth: cur.VerifiedClientsMapBitWidth(), + HashFunc: cur.VerifiedClientsMapHashFunction(), + }) } -func diffVerifierMap(ctx context.Context, store adt.Store, pre, cur State, preM, curM adt.Map) (*VerifierChanges, error) { +func diffVerifierMap(ctx context.Context, store adt.Store, pre, cur State, preM, curM adt.Map, preOpts, curOpts *adt.MapOpts) (*VerifierChanges, error) { ctx, span := otel.Tracer("").Start(ctx, "diffStates") defer span.End() - preOpts, err := adt.MapOptsForActorCode(pre.Code()) - if err != nil { - return nil, err - } - curOpts, err := adt.MapOptsForActorCode(cur.Code()) - if err != nil { - return nil, err - } - diffContainer := NewVerifierDiffContainer(pre, cur) if mapRequiresLegacyDiffing(pre, cur, preOpts, curOpts) { if span.IsRecording() { diff --git a/chain/actors/builtin/verifreg/state.go.template b/chain/actors/builtin/verifreg/state.go.template index c47faaae5..dbc413c67 100644 --- a/chain/actors/builtin/verifreg/state.go.template +++ b/chain/actors/builtin/verifreg/state.go.template @@ -2,6 +2,8 @@ package verifreg import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -9,9 +11,20 @@ import ( "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" - verifreg{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/verifreg" - adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{if (le .v 1)}} + sha256simd "github.com/minio/sha256-simd" + {{else}} + "crypto/sha256" + {{end}} + + {{if (le .v 2)}} + verifreg{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/verifreg" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{else}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + verifreg{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/verifreg" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" + {{end}} ) var _ State = (*state{{.v}})(nil) @@ -30,34 +43,91 @@ type state{{.v}} struct { store adt.Store } -func (s *state{{.v}}) Code() cid.Cid { - return builtin{{.v}}.VerifiedRegistryActorCodeID -} - func (s *state{{.v}}) RootKey() (address.Address, error) { return s.State.RootKey, nil } func (s *state{{.v}}) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version{{.v}}, s.verifiedClients, addr) + return getDataCap(s.store, actors.Version{{.v}}, s.VerifiedClientsMap, addr) } func (s *state{{.v}}) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version{{.v}}, s.verifiers, addr) + return getDataCap(s.store, actors.Version{{.v}}, s.VerifiersMap, addr) } func (s *state{{.v}}) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version{{.v}}, s.verifiers, cb) + return forEachCap(s.store, actors.Version{{.v}}, s.VerifiersMap, cb) } func (s *state{{.v}}) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version{{.v}}, s.verifiedClients, cb) + return forEachCap(s.store, actors.Version{{.v}}, s.VerifiedClientsMap, cb) } -func (s *state{{.v}}) verifiedClients() (adt.Map, error) { +func (s *state{{.v}}) VerifiedClientsMap() (adt.Map, error) { return adt{{.v}}.AsMap(s.store, s.VerifiedClients{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) } -func (s *state{{.v}}) verifiers() (adt.Map, error) { +func (s *state{{.v}}) VerifiedClientsMapBitWidth() int { + {{if (ge .v 3)}} + return builtin{{.v}}.DefaultHamtBitwidth + {{else}} + return 5 + {{end}} +} + +func (s *state{{.v}}) VerifiedClientsMapHashFunction() func(input []byte) []byte { + {{if (le .v 1)}} + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + {{else}} + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + {{end}} +} + +func (s *state{{.v}}) VerifiersMap() (adt.Map, error) { return adt{{.v}}.AsMap(s.store, s.Verifiers{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) } + +func (s *state{{.v}}) VerifiersMapBitWidth() int { + {{if (ge .v 3)}} + return builtin{{.v}}.DefaultHamtBitwidth + {{else}} + return 5 + {{end}} +} + +func (s *state{{.v}}) VerifiersMapHashFunction() func(input []byte) []byte { + {{if (le .v 1)}} + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + {{else}} + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + {{end}} +} + +func (s *state{{.v}}) ActorKey() string { + return actors.VerifregKey +} + +func (s *state{{.v}}) ActorVersion() actors.Version { + return actors.Version{{.v}} +} + +func (s *state{{.v}}) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/util.go b/chain/actors/builtin/verifreg/util.go index af692593b..934a8c246 100644 --- a/chain/actors/builtin/verifreg/util.go +++ b/chain/actors/builtin/verifreg/util.go @@ -8,6 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lily/chain/actors" + "github.com/filecoin-project/lily/chain/actors/adt" ) diff --git a/chain/actors/builtin/verifreg/v0.go b/chain/actors/builtin/verifreg/v0.go index 307770347..3dc4e983a 100644 --- a/chain/actors/builtin/verifreg/v0.go +++ b/chain/actors/builtin/verifreg/v0.go @@ -2,6 +2,8 @@ package verifreg import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -9,7 +11,8 @@ import ( "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + sha256simd "github.com/minio/sha256-simd" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) @@ -30,34 +33,77 @@ type state0 struct { store adt.Store } -func (s *state0) Code() cid.Cid { - return builtin0.VerifiedRegistryActorCodeID -} - func (s *state0) RootKey() (address.Address, error) { return s.State.RootKey, nil } func (s *state0) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version0, s.verifiedClients, addr) + return getDataCap(s.store, actors.Version0, s.VerifiedClientsMap, addr) } func (s *state0) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version0, s.verifiers, addr) + return getDataCap(s.store, actors.Version0, s.VerifiersMap, addr) } func (s *state0) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version0, s.verifiers, cb) + return forEachCap(s.store, actors.Version0, s.VerifiersMap, cb) } func (s *state0) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version0, s.verifiedClients, cb) + return forEachCap(s.store, actors.Version0, s.VerifiedClientsMap, cb) } -func (s *state0) verifiedClients() (adt.Map, error) { +func (s *state0) VerifiedClientsMap() (adt.Map, error) { return adt0.AsMap(s.store, s.VerifiedClients) } -func (s *state0) verifiers() (adt.Map, error) { +func (s *state0) VerifiedClientsMapBitWidth() int { + + return 5 + +} + +func (s *state0) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + +} + +func (s *state0) VerifiersMap() (adt.Map, error) { return adt0.AsMap(s.store, s.Verifiers) } + +func (s *state0) VerifiersMapBitWidth() int { + + return 5 + +} + +func (s *state0) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256simd.Sum256(input) + return res[:] + } + +} + +func (s *state0) ActorKey() string { + return actors.VerifregKey +} + +func (s *state0) ActorVersion() actors.Version { + return actors.Version0 +} + +func (s *state0) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/v2.go b/chain/actors/builtin/verifreg/v2.go index 7d6fef041..3814ed7bc 100644 --- a/chain/actors/builtin/verifreg/v2.go +++ b/chain/actors/builtin/verifreg/v2.go @@ -2,6 +2,8 @@ package verifreg import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -9,7 +11,8 @@ import ( "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "crypto/sha256" + verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg" adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" ) @@ -30,34 +33,77 @@ type state2 struct { store adt.Store } -func (s *state2) Code() cid.Cid { - return builtin2.VerifiedRegistryActorCodeID -} - func (s *state2) RootKey() (address.Address, error) { return s.State.RootKey, nil } func (s *state2) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version2, s.verifiedClients, addr) + return getDataCap(s.store, actors.Version2, s.VerifiedClientsMap, addr) } func (s *state2) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version2, s.verifiers, addr) + return getDataCap(s.store, actors.Version2, s.VerifiersMap, addr) } func (s *state2) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version2, s.verifiers, cb) + return forEachCap(s.store, actors.Version2, s.VerifiersMap, cb) } func (s *state2) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version2, s.verifiedClients, cb) + return forEachCap(s.store, actors.Version2, s.VerifiedClientsMap, cb) } -func (s *state2) verifiedClients() (adt.Map, error) { +func (s *state2) VerifiedClientsMap() (adt.Map, error) { return adt2.AsMap(s.store, s.VerifiedClients) } -func (s *state2) verifiers() (adt.Map, error) { +func (s *state2) VerifiedClientsMapBitWidth() int { + + return 5 + +} + +func (s *state2) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state2) VerifiersMap() (adt.Map, error) { return adt2.AsMap(s.store, s.Verifiers) } + +func (s *state2) VerifiersMapBitWidth() int { + + return 5 + +} + +func (s *state2) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state2) ActorKey() string { + return actors.VerifregKey +} + +func (s *state2) ActorVersion() actors.Version { + return actors.Version2 +} + +func (s *state2) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/v3.go b/chain/actors/builtin/verifreg/v3.go index 5863301c2..a7761c44f 100644 --- a/chain/actors/builtin/verifreg/v3.go +++ b/chain/actors/builtin/verifreg/v3.go @@ -2,6 +2,8 @@ package verifreg import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -9,6 +11,8 @@ import ( "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" verifreg3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/verifreg" adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" @@ -30,34 +34,77 @@ type state3 struct { store adt.Store } -func (s *state3) Code() cid.Cid { - return builtin3.VerifiedRegistryActorCodeID -} - func (s *state3) RootKey() (address.Address, error) { return s.State.RootKey, nil } func (s *state3) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version3, s.verifiedClients, addr) + return getDataCap(s.store, actors.Version3, s.VerifiedClientsMap, addr) } func (s *state3) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version3, s.verifiers, addr) + return getDataCap(s.store, actors.Version3, s.VerifiersMap, addr) } func (s *state3) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version3, s.verifiers, cb) + return forEachCap(s.store, actors.Version3, s.VerifiersMap, cb) } func (s *state3) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version3, s.verifiedClients, cb) + return forEachCap(s.store, actors.Version3, s.VerifiedClientsMap, cb) } -func (s *state3) verifiedClients() (adt.Map, error) { +func (s *state3) VerifiedClientsMap() (adt.Map, error) { return adt3.AsMap(s.store, s.VerifiedClients, builtin3.DefaultHamtBitwidth) } -func (s *state3) verifiers() (adt.Map, error) { +func (s *state3) VerifiedClientsMapBitWidth() int { + + return builtin3.DefaultHamtBitwidth + +} + +func (s *state3) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state3) VerifiersMap() (adt.Map, error) { return adt3.AsMap(s.store, s.Verifiers, builtin3.DefaultHamtBitwidth) } + +func (s *state3) VerifiersMapBitWidth() int { + + return builtin3.DefaultHamtBitwidth + +} + +func (s *state3) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state3) ActorKey() string { + return actors.VerifregKey +} + +func (s *state3) ActorVersion() actors.Version { + return actors.Version3 +} + +func (s *state3) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/v4.go b/chain/actors/builtin/verifreg/v4.go index 0d87d29d4..9b3bfe27c 100644 --- a/chain/actors/builtin/verifreg/v4.go +++ b/chain/actors/builtin/verifreg/v4.go @@ -2,6 +2,8 @@ package verifreg import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -9,6 +11,8 @@ import ( "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" @@ -30,34 +34,77 @@ type state4 struct { store adt.Store } -func (s *state4) Code() cid.Cid { - return builtin4.VerifiedRegistryActorCodeID -} - func (s *state4) RootKey() (address.Address, error) { return s.State.RootKey, nil } func (s *state4) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version4, s.verifiedClients, addr) + return getDataCap(s.store, actors.Version4, s.VerifiedClientsMap, addr) } func (s *state4) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version4, s.verifiers, addr) + return getDataCap(s.store, actors.Version4, s.VerifiersMap, addr) } func (s *state4) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version4, s.verifiers, cb) + return forEachCap(s.store, actors.Version4, s.VerifiersMap, cb) } func (s *state4) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version4, s.verifiedClients, cb) + return forEachCap(s.store, actors.Version4, s.VerifiedClientsMap, cb) } -func (s *state4) verifiedClients() (adt.Map, error) { +func (s *state4) VerifiedClientsMap() (adt.Map, error) { return adt4.AsMap(s.store, s.VerifiedClients, builtin4.DefaultHamtBitwidth) } -func (s *state4) verifiers() (adt.Map, error) { +func (s *state4) VerifiedClientsMapBitWidth() int { + + return builtin4.DefaultHamtBitwidth + +} + +func (s *state4) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state4) VerifiersMap() (adt.Map, error) { return adt4.AsMap(s.store, s.Verifiers, builtin4.DefaultHamtBitwidth) } + +func (s *state4) VerifiersMapBitWidth() int { + + return builtin4.DefaultHamtBitwidth + +} + +func (s *state4) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state4) ActorKey() string { + return actors.VerifregKey +} + +func (s *state4) ActorVersion() actors.Version { + return actors.Version4 +} + +func (s *state4) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/v5.go b/chain/actors/builtin/verifreg/v5.go index 72485db84..cebe9bdf9 100644 --- a/chain/actors/builtin/verifreg/v5.go +++ b/chain/actors/builtin/verifreg/v5.go @@ -2,6 +2,8 @@ package verifreg import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -9,6 +11,8 @@ import ( "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" verifreg5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt" @@ -30,34 +34,77 @@ type state5 struct { store adt.Store } -func (s *state5) Code() cid.Cid { - return builtin5.VerifiedRegistryActorCodeID -} - func (s *state5) RootKey() (address.Address, error) { return s.State.RootKey, nil } func (s *state5) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version5, s.verifiedClients, addr) + return getDataCap(s.store, actors.Version5, s.VerifiedClientsMap, addr) } func (s *state5) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version5, s.verifiers, addr) + return getDataCap(s.store, actors.Version5, s.VerifiersMap, addr) } func (s *state5) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version5, s.verifiers, cb) + return forEachCap(s.store, actors.Version5, s.VerifiersMap, cb) } func (s *state5) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version5, s.verifiedClients, cb) + return forEachCap(s.store, actors.Version5, s.VerifiedClientsMap, cb) } -func (s *state5) verifiedClients() (adt.Map, error) { +func (s *state5) VerifiedClientsMap() (adt.Map, error) { return adt5.AsMap(s.store, s.VerifiedClients, builtin5.DefaultHamtBitwidth) } -func (s *state5) verifiers() (adt.Map, error) { +func (s *state5) VerifiedClientsMapBitWidth() int { + + return builtin5.DefaultHamtBitwidth + +} + +func (s *state5) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state5) VerifiersMap() (adt.Map, error) { return adt5.AsMap(s.store, s.Verifiers, builtin5.DefaultHamtBitwidth) } + +func (s *state5) VerifiersMapBitWidth() int { + + return builtin5.DefaultHamtBitwidth + +} + +func (s *state5) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state5) ActorKey() string { + return actors.VerifregKey +} + +func (s *state5) ActorVersion() actors.Version { + return actors.Version5 +} + +func (s *state5) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/v6.go b/chain/actors/builtin/verifreg/v6.go index 416c45568..e0d16a81d 100644 --- a/chain/actors/builtin/verifreg/v6.go +++ b/chain/actors/builtin/verifreg/v6.go @@ -2,6 +2,8 @@ package verifreg import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -9,6 +11,8 @@ import ( "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" verifreg6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/verifreg" adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt" @@ -30,34 +34,77 @@ type state6 struct { store adt.Store } -func (s *state6) Code() cid.Cid { - return builtin6.VerifiedRegistryActorCodeID -} - func (s *state6) RootKey() (address.Address, error) { return s.State.RootKey, nil } func (s *state6) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version6, s.verifiedClients, addr) + return getDataCap(s.store, actors.Version6, s.VerifiedClientsMap, addr) } func (s *state6) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version6, s.verifiers, addr) + return getDataCap(s.store, actors.Version6, s.VerifiersMap, addr) } func (s *state6) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version6, s.verifiers, cb) + return forEachCap(s.store, actors.Version6, s.VerifiersMap, cb) } func (s *state6) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version6, s.verifiedClients, cb) + return forEachCap(s.store, actors.Version6, s.VerifiedClientsMap, cb) } -func (s *state6) verifiedClients() (adt.Map, error) { +func (s *state6) VerifiedClientsMap() (adt.Map, error) { return adt6.AsMap(s.store, s.VerifiedClients, builtin6.DefaultHamtBitwidth) } -func (s *state6) verifiers() (adt.Map, error) { +func (s *state6) VerifiedClientsMapBitWidth() int { + + return builtin6.DefaultHamtBitwidth + +} + +func (s *state6) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state6) VerifiersMap() (adt.Map, error) { return adt6.AsMap(s.store, s.Verifiers, builtin6.DefaultHamtBitwidth) } + +func (s *state6) VerifiersMapBitWidth() int { + + return builtin6.DefaultHamtBitwidth + +} + +func (s *state6) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state6) ActorKey() string { + return actors.VerifregKey +} + +func (s *state6) ActorVersion() actors.Version { + return actors.Version6 +} + +func (s *state6) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/v7.go b/chain/actors/builtin/verifreg/v7.go index bb4dda6ae..db902780f 100644 --- a/chain/actors/builtin/verifreg/v7.go +++ b/chain/actors/builtin/verifreg/v7.go @@ -2,6 +2,8 @@ package verifreg import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -9,6 +11,8 @@ import ( "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" + "crypto/sha256" + builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg" adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt" @@ -30,34 +34,77 @@ type state7 struct { store adt.Store } -func (s *state7) Code() cid.Cid { - return builtin7.VerifiedRegistryActorCodeID -} - func (s *state7) RootKey() (address.Address, error) { return s.State.RootKey, nil } func (s *state7) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version7, s.verifiedClients, addr) + return getDataCap(s.store, actors.Version7, s.VerifiedClientsMap, addr) } func (s *state7) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { - return getDataCap(s.store, actors.Version7, s.verifiers, addr) + return getDataCap(s.store, actors.Version7, s.VerifiersMap, addr) } func (s *state7) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version7, s.verifiers, cb) + return forEachCap(s.store, actors.Version7, s.VerifiersMap, cb) } func (s *state7) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { - return forEachCap(s.store, actors.Version7, s.verifiedClients, cb) + return forEachCap(s.store, actors.Version7, s.VerifiedClientsMap, cb) } -func (s *state7) verifiedClients() (adt.Map, error) { +func (s *state7) VerifiedClientsMap() (adt.Map, error) { return adt7.AsMap(s.store, s.VerifiedClients, builtin7.DefaultHamtBitwidth) } -func (s *state7) verifiers() (adt.Map, error) { +func (s *state7) VerifiedClientsMapBitWidth() int { + + return builtin7.DefaultHamtBitwidth + +} + +func (s *state7) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state7) VerifiersMap() (adt.Map, error) { return adt7.AsMap(s.store, s.Verifiers, builtin7.DefaultHamtBitwidth) } + +func (s *state7) VerifiersMapBitWidth() int { + + return builtin7.DefaultHamtBitwidth + +} + +func (s *state7) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state7) ActorKey() string { + return actors.VerifregKey +} + +func (s *state7) ActorVersion() actors.Version { + return actors.Version7 +} + +func (s *state7) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/v8.go b/chain/actors/builtin/verifreg/v8.go new file mode 100644 index 000000000..ad4de4e3e --- /dev/null +++ b/chain/actors/builtin/verifreg/v8.go @@ -0,0 +1,110 @@ +// Code generated by: `make actors-gen`. DO NOT EDIT. +package verifreg + +import ( + "fmt" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lily/chain/actors" + "github.com/filecoin-project/lily/chain/actors/adt" + + "crypto/sha256" + + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" + verifreg8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/verifreg" + adt8 "github.com/filecoin-project/specs-actors/v8/actors/util/adt" +) + +var _ State = (*state8)(nil) + +func load8(store adt.Store, root cid.Cid) (State, error) { + out := state8{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +type state8 struct { + verifreg8.State + store adt.Store +} + +func (s *state8) RootKey() (address.Address, error) { + return s.State.RootKey, nil +} + +func (s *state8) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actors.Version8, s.VerifiedClientsMap, addr) +} + +func (s *state8) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actors.Version8, s.VerifiersMap, addr) +} + +func (s *state8) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, actors.Version8, s.VerifiersMap, cb) +} + +func (s *state8) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, actors.Version8, s.VerifiedClientsMap, cb) +} + +func (s *state8) VerifiedClientsMap() (adt.Map, error) { + return adt8.AsMap(s.store, s.VerifiedClients, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) VerifiedClientsMapBitWidth() int { + + return builtin8.DefaultHamtBitwidth + +} + +func (s *state8) VerifiedClientsMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state8) VerifiersMap() (adt.Map, error) { + return adt8.AsMap(s.store, s.Verifiers, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) VerifiersMapBitWidth() int { + + return builtin8.DefaultHamtBitwidth + +} + +func (s *state8) VerifiersMapHashFunction() func(input []byte) []byte { + + return func(input []byte) []byte { + res := sha256.Sum256(input) + return res[:] + } + +} + +func (s *state8) ActorKey() string { + return actors.VerifregKey +} + +func (s *state8) ActorVersion() actors.Version { + return actors.Version8 +} + +func (s *state8) Code() cid.Cid { + code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey()) + if !ok { + panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion())) + } + + return code +} diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index 585e36be9..7b1698ae5 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -17,63 +17,34 @@ import ( builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + builtin8 "github.com/filecoin-project/specs-actors/v8/actors/builtin" "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lily/chain/actors" "github.com/filecoin-project/lily/chain/actors/adt" - "github.com/filecoin-project/lily/chain/actors/builtin" + lotusactors "github.com/filecoin-project/lotus/chain/actors" ) -func init() { - - builtin.RegisterActorState(builtin0.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) - - builtin.RegisterActorState(builtin3.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) - - builtin.RegisterActorState(builtin5.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) - - builtin.RegisterActorState(builtin6.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) +var ( + Address = builtin8.VerifiedRegistryActorAddr + Methods = builtin8.MethodsVerifiedRegistry +) - builtin.RegisterActorState(builtin7.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := lotusactors.GetActorMetaByCode(act.Code); ok { + if name != actors.VerifregKey { + return nil, fmt.Errorf("actor code is not verifreg: %s", name) + } -} + switch actors.Version(av) { -var ( - Address = builtin7.VerifiedRegistryActorAddr - Methods = builtin7.MethodsVerifiedRegistry -) + case actors.Version8: + return load8(store, act.Head) -func AllCodes() []cid.Cid { - return []cid.Cid{ - builtin0.VerifiedRegistryActorCodeID, - builtin2.VerifiedRegistryActorCodeID, - builtin3.VerifiedRegistryActorCodeID, - builtin4.VerifiedRegistryActorCodeID, - builtin5.VerifiedRegistryActorCodeID, - builtin6.VerifiedRegistryActorCodeID, - builtin7.VerifiedRegistryActorCodeID, + } } -} -func Load(store adt.Store, act *types.Actor) (State, error) { switch act.Code { case builtin0.VerifiedRegistryActorCodeID: @@ -98,6 +69,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, fmt.Errorf("unknown actor code %s", act.Code) } @@ -105,6 +77,8 @@ type State interface { cbor.Marshaler Code() cid.Cid + ActorKey() string + ActorVersion() actors.Version RootKey() (address.Address, error) VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error) @@ -112,8 +86,13 @@ type State interface { ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error - verifiers() (adt.Map, error) - verifiedClients() (adt.Map, error) + VerifiersMap() (adt.Map, error) + VerifiersMapBitWidth() int + VerifiersMapHashFunction() func(input []byte) []byte + + VerifiedClientsMap() (adt.Map, error) + VerifiedClientsMapBitWidth() int + VerifiedClientsMapHashFunction() func(input []byte) []byte } type VerifierInfo struct { @@ -131,3 +110,29 @@ type VerifierChanges struct { Modified []VerifierChange Removed []VerifierInfo } + +func AllCodes() []cid.Cid { + return []cid.Cid{ + (&state0{}).Code(), + (&state2{}).Code(), + (&state3{}).Code(), + (&state4{}).Code(), + (&state5{}).Code(), + (&state6{}).Code(), + (&state7{}).Code(), + (&state8{}).Code(), + } +} + +func VersionCodes() map[actors.Version]cid.Cid { + return map[actors.Version]cid.Cid{ + actors.Version0: (&state0{}).Code(), + actors.Version2: (&state2{}).Code(), + actors.Version3: (&state3{}).Code(), + actors.Version4: (&state4{}).Code(), + actors.Version5: (&state5{}).Code(), + actors.Version6: (&state6{}).Code(), + actors.Version7: (&state7{}).Code(), + actors.Version8: (&state8{}).Code(), + } +} diff --git a/chain/actors/policy/policy.go b/chain/actors/policy/policy.go deleted file mode 100644 index 2b22a11de..000000000 --- a/chain/actors/policy/policy.go +++ /dev/null @@ -1,439 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package policy - -import ( - "sort" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lily/chain/actors" - - 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" - verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg" - - builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - market3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/market" - miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" - verifreg3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/verifreg" - - builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" - miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" - - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - market5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - verifreg5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg" - - builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - market6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/market" - miner6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner" - verifreg6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/verifreg" - - builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market" - miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" - verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg" - - paych7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/paych" -) - -const ( - ChainFinality = miner7.ChainFinality - SealRandomnessLookback = ChainFinality - PaychSettleDelay = paych7.SettleDelay - MaxPreCommitRandomnessLookback = builtin7.EpochsInDay + SealRandomnessLookback -) - -// SetSupportedProofTypes sets supported proof types, across all actor versions. -// This should only be used for testing. - -func SetSupportedProofTypes(types ...abi.RegisteredSealProof) { - - miner0.SupportedProofTypes = make(map[abi.RegisteredSealProof]struct{}, len(types)) - - miner2.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - miner2.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) - miner2.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - - miner3.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - miner3.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) - miner3.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - - miner4.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - miner4.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) - miner4.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - - miner5.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - - miner6.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - - miner7.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - - AddSupportedProofTypes(types...) -} - -// AddSupportedProofTypes sets supported proof types, across all actor versions. -// This should only be used for testing. -func AddSupportedProofTypes(types ...abi.RegisteredSealProof) { - for _, t := range types { - if t >= abi.RegisteredSealProof_StackedDrg2KiBV1_1 { - panic("must specify v1 proof types only") - } - // Set for all miner versions. - - miner0.SupportedProofTypes[t] = struct{}{} - - miner2.PreCommitSealProofTypesV0[t] = struct{}{} - miner2.PreCommitSealProofTypesV7[t] = struct{}{} - miner2.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - miner2.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - - miner3.PreCommitSealProofTypesV0[t] = struct{}{} - miner3.PreCommitSealProofTypesV7[t] = struct{}{} - miner3.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - miner3.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - - miner4.PreCommitSealProofTypesV0[t] = struct{}{} - miner4.PreCommitSealProofTypesV7[t] = struct{}{} - miner4.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - miner4.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - - miner5.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - - miner6.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - - miner7.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - - } -} - -// SetPreCommitChallengeDelay sets the pre-commit challenge delay across all -// actors versions. Use for testing. -func SetPreCommitChallengeDelay(delay abi.ChainEpoch) { - // Set for all miner versions. - - miner0.PreCommitChallengeDelay = delay - - miner2.PreCommitChallengeDelay = delay - - miner3.PreCommitChallengeDelay = delay - - miner4.PreCommitChallengeDelay = delay - - miner5.PreCommitChallengeDelay = delay - - miner6.PreCommitChallengeDelay = delay - - miner7.PreCommitChallengeDelay = delay - -} - -// TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay. -func GetPreCommitChallengeDelay() abi.ChainEpoch { - return miner7.PreCommitChallengeDelay -} - -// SetConsensusMinerMinPower sets the minimum power of an individual miner must -// meet for leader election, across all actor versions. This should only be used -// for testing. -func SetConsensusMinerMinPower(p abi.StoragePower) { - - power0.ConsensusMinerMinPower = p - - for _, policy := range builtin2.SealProofPolicies { - policy.ConsensusMinerMinPower = p - } - - for _, policy := range builtin3.PoStProofPolicies { - policy.ConsensusMinerMinPower = p - } - - for _, policy := range builtin4.PoStProofPolicies { - policy.ConsensusMinerMinPower = p - } - - for _, policy := range builtin5.PoStProofPolicies { - policy.ConsensusMinerMinPower = p - } - - for _, policy := range builtin6.PoStProofPolicies { - policy.ConsensusMinerMinPower = p - } - - for _, policy := range builtin7.PoStProofPolicies { - policy.ConsensusMinerMinPower = p - } - -} - -// SetMinVerifiedDealSize sets the minimum size of a verified deal. This should -// only be used for testing. -func SetMinVerifiedDealSize(size abi.StoragePower) { - - verifreg0.MinVerifiedDealSize = size - - verifreg2.MinVerifiedDealSize = size - - verifreg3.MinVerifiedDealSize = size - - verifreg4.MinVerifiedDealSize = size - - verifreg5.MinVerifiedDealSize = size - - verifreg6.MinVerifiedDealSize = size - - verifreg7.MinVerifiedDealSize = size - -} - -func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) abi.ChainEpoch { - switch ver { - - case actors.Version0: - - return miner0.MaxSealDuration[t] - - case actors.Version2: - - return miner2.MaxProveCommitDuration[t] - - case actors.Version3: - - return miner3.MaxProveCommitDuration[t] - - case actors.Version4: - - return miner4.MaxProveCommitDuration[t] - - case actors.Version5: - - return miner5.MaxProveCommitDuration[t] - - case actors.Version6: - - return miner6.MaxProveCommitDuration[t] - - case actors.Version7: - - return miner7.MaxProveCommitDuration[t] - - default: - panic("unsupported actors version") - } -} - -func DealProviderCollateralBounds( - size abi.PaddedPieceSize, verified bool, - rawBytePower, qaPower, baselinePower abi.StoragePower, - circulatingFil abi.TokenAmount, nwVer network.Version, -) (min, max abi.TokenAmount) { - switch actors.VersionForNetwork(nwVer) { - - case actors.Version0: - - return market0.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer) - - case actors.Version2: - - return market2.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) - - case actors.Version3: - - return market3.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) - - case actors.Version4: - - return market4.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) - - case actors.Version5: - - return market5.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) - - case actors.Version6: - - return market6.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) - - case actors.Version7: - - return market7.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) - - default: - panic("unsupported actors version") - } -} - -func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) { - return market7.DealDurationBounds(pieceSize) -} - -// Sets the challenge window and scales the proving period to match (such that -// there are always 48 challenge windows in a proving period). -func SetWPoStChallengeWindow(period abi.ChainEpoch) { - - miner0.WPoStChallengeWindow = period - miner0.WPoStProvingPeriod = period * abi.ChainEpoch(miner0.WPoStPeriodDeadlines) - - miner2.WPoStChallengeWindow = period - miner2.WPoStProvingPeriod = period * abi.ChainEpoch(miner2.WPoStPeriodDeadlines) - - miner3.WPoStChallengeWindow = period - miner3.WPoStProvingPeriod = period * abi.ChainEpoch(miner3.WPoStPeriodDeadlines) - - // by default, this is 2x finality which is 30 periods. - // scale it if we're scaling the challenge period. - miner3.WPoStDisputeWindow = period * 30 - - miner4.WPoStChallengeWindow = period - miner4.WPoStProvingPeriod = period * abi.ChainEpoch(miner4.WPoStPeriodDeadlines) - - // by default, this is 2x finality which is 30 periods. - // scale it if we're scaling the challenge period. - miner4.WPoStDisputeWindow = period * 30 - - miner5.WPoStChallengeWindow = period - miner5.WPoStProvingPeriod = period * abi.ChainEpoch(miner5.WPoStPeriodDeadlines) - - // by default, this is 2x finality which is 30 periods. - // scale it if we're scaling the challenge period. - miner5.WPoStDisputeWindow = period * 30 - - miner6.WPoStChallengeWindow = period - miner6.WPoStProvingPeriod = period * abi.ChainEpoch(miner6.WPoStPeriodDeadlines) - - // by default, this is 2x finality which is 30 periods. - // scale it if we're scaling the challenge period. - miner6.WPoStDisputeWindow = period * 30 - - miner7.WPoStChallengeWindow = period - miner7.WPoStProvingPeriod = period * abi.ChainEpoch(miner7.WPoStPeriodDeadlines) - - // by default, this is 2x finality which is 30 periods. - // scale it if we're scaling the challenge period. - miner7.WPoStDisputeWindow = period * 30 - -} - -func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { - if nwVer <= network.Version3 { - return 10 - } - - // NOTE: if this ever changes, adjust it in a (*Miner).mineOne() logline as well - return ChainFinality -} - -func GetMaxSectorExpirationExtension() abi.ChainEpoch { - return miner7.MaxSectorExpirationExtension -} - -// TODO: we'll probably need to abstract over this better in the future. -func GetMaxPoStPartitions(p abi.RegisteredPoStProof) (int, error) { - sectorsPerPart, err := builtin7.PoStProofWindowPoStPartitionSectors(p) - if err != nil { - return 0, err - } - return int(miner7.AddressedSectorsMax / sectorsPerPart), nil -} - -func GetDefaultSectorSize() abi.SectorSize { - // supported sector sizes are the same across versions. - szs := make([]abi.SectorSize, 0, len(miner7.PreCommitSealProofTypesV8)) - for spt := range miner7.PreCommitSealProofTypesV8 { - ss, err := spt.SectorSize() - if err != nil { - panic(err) - } - - szs = append(szs, ss) - } - - sort.Slice(szs, func(i, j int) bool { - return szs[i] < szs[j] - }) - - return szs[0] -} - -func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) abi.ChainEpoch { - if nwVer <= network.Version10 { - // Version 4 was last version to handle network < 11 - return builtin4.SealProofPoliciesV0[proof].SectorMaxLifetime - } - - return builtin7.SealProofPoliciesV11[proof].SectorMaxLifetime -} - -func GetAddressedSectorsMax(nwVer network.Version) int { - switch actors.VersionForNetwork(nwVer) { - - case actors.Version0: - return miner0.AddressedSectorsMax - - case actors.Version2: - return miner2.AddressedSectorsMax - - case actors.Version3: - return miner3.AddressedSectorsMax - - case actors.Version4: - return miner4.AddressedSectorsMax - - case actors.Version5: - return miner5.AddressedSectorsMax - - case actors.Version6: - return miner6.AddressedSectorsMax - - case actors.Version7: - return miner7.AddressedSectorsMax - - default: - panic("unsupported network version") - } -} - -func GetDeclarationsMax(nwVer network.Version) int { - switch actors.VersionForNetwork(nwVer) { - - case actors.Version0: - - // TODO: Should we instead panic here since the concept doesn't exist yet? - return miner0.AddressedPartitionsMax - - case actors.Version2: - - return miner2.DeclarationsMax - - case actors.Version3: - - return miner3.DeclarationsMax - - case actors.Version4: - - return miner4.DeclarationsMax - - case actors.Version5: - - return miner5.DeclarationsMax - - case actors.Version6: - - return miner6.DeclarationsMax - - case actors.Version7: - - return miner7.DeclarationsMax - - default: - panic("unsupported network version") - } -} diff --git a/chain/actors/policy/policy.go.template b/chain/actors/policy/policy.go.template deleted file mode 100644 index 7cc22aa96..000000000 --- a/chain/actors/policy/policy.go.template +++ /dev/null @@ -1,240 +0,0 @@ -// Code generated by: `make actors-gen`. DO NOT EDIT. -package policy - -import ( - "sort" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lily/chain/actors" - - {{range .versions}} - {{if (ge . 2)}} builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" {{end}} - market{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/market" - miner{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/miner" - verifreg{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/verifreg" - {{if (eq . 0)}} power{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/power" {{end}} - {{end}} - - paych{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/paych" -) - -const ( - ChainFinality = miner{{.latestVersion}}.ChainFinality - SealRandomnessLookback = ChainFinality - PaychSettleDelay = paych{{.latestVersion}}.SettleDelay - MaxPreCommitRandomnessLookback = builtin{{.latestVersion}}.EpochsInDay + SealRandomnessLookback -) - -// SetSupportedProofTypes sets supported proof types, across all actor versions. -// This should only be used for testing. - -func SetSupportedProofTypes(types ...abi.RegisteredSealProof) { - {{range .versions}} - {{if (eq . 0)}} - miner{{.}}.SupportedProofTypes = make(map[abi.RegisteredSealProof]struct{}, len(types)) - {{else if (lt . 5)}} - miner{{.}}.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - miner{{.}}.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) - miner{{.}}.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - {{else}} - miner{{.}}.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - {{end}} - {{end}} - - AddSupportedProofTypes(types...) -} - -// AddSupportedProofTypes sets supported proof types, across all actor versions. -// This should only be used for testing. -func AddSupportedProofTypes(types ...abi.RegisteredSealProof) { - for _, t := range types { - if t >= abi.RegisteredSealProof_StackedDrg2KiBV1_1 { - panic("must specify v1 proof types only") - } - // Set for all miner versions. - - {{range .versions}} - {{if (eq . 0)}} - miner{{.}}.SupportedProofTypes[t] = struct{}{} - {{else if (lt . 5)}} - miner{{.}}.PreCommitSealProofTypesV0[t] = struct{}{} - miner{{.}}.PreCommitSealProofTypesV7[t] = struct{}{} - miner{{.}}.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - miner{{.}}.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - {{else}} - miner{{.}}.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - {{end}} - {{end}} - } -} - -// SetPreCommitChallengeDelay sets the pre-commit challenge delay across all -// actors versions. Use for testing. -func SetPreCommitChallengeDelay(delay abi.ChainEpoch) { - // Set for all miner versions. - {{range .versions}} - miner{{.}}.PreCommitChallengeDelay = delay - {{end}} -} - -// TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay. -func GetPreCommitChallengeDelay() abi.ChainEpoch { - return miner{{.latestVersion}}.PreCommitChallengeDelay -} - -// SetConsensusMinerMinPower sets the minimum power of an individual miner must -// meet for leader election, across all actor versions. This should only be used -// for testing. -func SetConsensusMinerMinPower(p abi.StoragePower) { - {{range .versions}} - {{if (eq . 0)}} - power{{.}}.ConsensusMinerMinPower = p - {{else if (eq . 2)}} - for _, policy := range builtin{{.}}.SealProofPolicies { - policy.ConsensusMinerMinPower = p - } - {{else}} - for _, policy := range builtin{{.}}.PoStProofPolicies { - policy.ConsensusMinerMinPower = p - } - {{end}} - {{end}} -} - -// SetMinVerifiedDealSize sets the minimum size of a verified deal. This should -// only be used for testing. -func SetMinVerifiedDealSize(size abi.StoragePower) { - {{range .versions}} - verifreg{{.}}.MinVerifiedDealSize = size - {{end}} -} - -func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) abi.ChainEpoch { - switch ver { - {{range .versions}} - case actors.Version{{.}}: - {{if (eq . 0)}} - return miner{{.}}.MaxSealDuration[t] - {{else}} - return miner{{.}}.MaxProveCommitDuration[t] - {{end}} - {{end}} - default: - panic("unsupported actors version") - } -} - -func DealProviderCollateralBounds( - size abi.PaddedPieceSize, verified bool, - rawBytePower, qaPower, baselinePower abi.StoragePower, - circulatingFil abi.TokenAmount, nwVer network.Version, -) (min, max abi.TokenAmount) { - switch actors.VersionForNetwork(nwVer) { - {{range .versions}} - case actors.Version{{.}}: - {{if (eq . 0)}} - return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer) - {{else}} - return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) - {{end}} - {{end}} - default: - panic("unsupported actors version") - } -} - -func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) { - return market{{.latestVersion}}.DealDurationBounds(pieceSize) -} - -// Sets the challenge window and scales the proving period to match (such that -// there are always 48 challenge windows in a proving period). -func SetWPoStChallengeWindow(period abi.ChainEpoch) { - {{range .versions}} - miner{{.}}.WPoStChallengeWindow = period - miner{{.}}.WPoStProvingPeriod = period * abi.ChainEpoch(miner{{.}}.WPoStPeriodDeadlines) - {{if (ge . 3)}} - // by default, this is 2x finality which is 30 periods. - // scale it if we're scaling the challenge period. - miner{{.}}.WPoStDisputeWindow = period * 30 - {{end}} - {{end}} -} - -func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { - if nwVer <= network.Version3 { - return 10 - } - - // NOTE: if this ever changes, adjust it in a (*Miner).mineOne() logline as well - return ChainFinality -} - -func GetMaxSectorExpirationExtension() abi.ChainEpoch { - return miner{{.latestVersion}}.MaxSectorExpirationExtension -} - -// TODO: we'll probably need to abstract over this better in the future. -func GetMaxPoStPartitions(p abi.RegisteredPoStProof) (int, error) { - sectorsPerPart, err := builtin{{.latestVersion}}.PoStProofWindowPoStPartitionSectors(p) - if err != nil { - return 0, err - } - return int(miner{{.latestVersion}}.AddressedSectorsMax / sectorsPerPart), nil -} - -func GetDefaultSectorSize() abi.SectorSize { - // supported sector sizes are the same across versions. - szs := make([]abi.SectorSize, 0, len(miner{{.latestVersion}}.PreCommitSealProofTypesV8)) - for spt := range miner{{.latestVersion}}.PreCommitSealProofTypesV8 { - ss, err := spt.SectorSize() - if err != nil { - panic(err) - } - - szs = append(szs, ss) - } - - sort.Slice(szs, func(i, j int) bool { - return szs[i] < szs[j] - }) - - return szs[0] -} - -func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) abi.ChainEpoch { - if nwVer <= network.Version10 { - // Version 4 was last version to handle network < 11 - return builtin4.SealProofPoliciesV0[proof].SectorMaxLifetime - } - - return builtin{{.latestVersion}}.SealProofPoliciesV11[proof].SectorMaxLifetime -} - -func GetAddressedSectorsMax(nwVer network.Version) int { - switch actors.VersionForNetwork(nwVer) { - {{range .versions}} - case actors.Version{{.}}: - return miner{{.}}.AddressedSectorsMax - {{end}} - default: - panic("unsupported network version") - } -} - -func GetDeclarationsMax(nwVer network.Version) int { - switch actors.VersionForNetwork(nwVer) { - {{range .versions}} - case actors.Version{{.}}: - {{if (eq . 0)}} - // TODO: Should we instead panic here since the concept doesn't exist yet? - return miner{{.}}.AddressedPartitionsMax - {{else}} - return miner{{.}}.DeclarationsMax - {{end}} - {{end}} - default: - panic("unsupported network version") - } -} diff --git a/chain/actors/policy/policy_test.go b/chain/actors/policy/policy_test.go deleted file mode 100644 index 24e47aaa0..000000000 --- a/chain/actors/policy/policy_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package policy - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/filecoin-project/go-state-types/abi" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" - verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - paych2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/paych" - verifreg2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/verifreg" -) - -func TestSupportedProofTypes(t *testing.T) { - var oldTypes []abi.RegisteredSealProof - for t := range miner0.SupportedProofTypes { - oldTypes = append(oldTypes, t) - } - t.Cleanup(func() { - SetSupportedProofTypes(oldTypes...) - }) - - SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg2KiBV1) - require.EqualValues(t, - miner0.SupportedProofTypes, - map[abi.RegisteredSealProof]struct{}{ - abi.RegisteredSealProof_StackedDrg2KiBV1: {}, - }, - ) - AddSupportedProofTypes(abi.RegisteredSealProof_StackedDrg8MiBV1) - require.EqualValues(t, - miner0.SupportedProofTypes, - map[abi.RegisteredSealProof]struct{}{ - abi.RegisteredSealProof_StackedDrg2KiBV1: {}, - abi.RegisteredSealProof_StackedDrg8MiBV1: {}, - }, - ) -} - -// Tests assumptions about policies being the same between actor versions. -func TestAssumptions(t *testing.T) { - require.EqualValues(t, miner0.SupportedProofTypes, miner2.PreCommitSealProofTypesV0) - require.Equal(t, miner0.PreCommitChallengeDelay, miner2.PreCommitChallengeDelay) - require.Equal(t, miner0.MaxSectorExpirationExtension, miner2.MaxSectorExpirationExtension) - require.Equal(t, miner0.ChainFinality, miner2.ChainFinality) - require.Equal(t, miner0.WPoStChallengeWindow, miner2.WPoStChallengeWindow) - require.Equal(t, miner0.WPoStProvingPeriod, miner2.WPoStProvingPeriod) - require.Equal(t, miner0.WPoStPeriodDeadlines, miner2.WPoStPeriodDeadlines) - require.Equal(t, miner0.AddressedSectorsMax, miner2.AddressedSectorsMax) - require.Equal(t, paych0.SettleDelay, paych2.SettleDelay) - require.True(t, verifreg0.MinVerifiedDealSize.Equals(verifreg2.MinVerifiedDealSize)) -} - -func TestPartitionSizes(t *testing.T) { - for _, p := range abi.SealProofInfos { - sizeNew, err := builtin2.PoStProofWindowPoStPartitionSectors(p.WindowPoStProof) - require.NoError(t, err) - sizeOld, err := builtin0.PoStProofWindowPoStPartitionSectors(p.WindowPoStProof) - if err != nil { - // new proof type. - continue - } - require.Equal(t, sizeOld, sizeNew) - } -} diff --git a/chain/actors/version.go b/chain/actors/version.go deleted file mode 100644 index fe0fab2b2..000000000 --- a/chain/actors/version.go +++ /dev/null @@ -1,39 +0,0 @@ -package actors - -import ( - "fmt" - - "github.com/filecoin-project/go-state-types/network" -) - -type Version int - -const ( - Version0 Version = 0 - Version2 Version = 2 - Version3 Version = 3 - Version4 Version = 4 - Version5 Version = 5 - Version6 Version = 6 - Version7 Version = 7 -) - -// Converts a network version into an actors adt version. -func VersionForNetwork(version network.Version) Version { - switch version { - case network.Version0, network.Version1, network.Version2, network.Version3: - return Version0 - case network.Version4, network.Version5, network.Version6, network.Version7, network.Version8, network.Version9: - return Version2 - case network.Version10, network.Version11: - return Version3 - case network.Version12: - return Version4 - case network.Version13: - return Version5 - case network.Version14: - return Version6 - default: - panic(fmt.Sprintf("unsupported network version %d", version)) - } -} diff --git a/chain/indexer/integrated/processor/state.go b/chain/indexer/integrated/processor/state.go index 875128177..f18e782d6 100644 --- a/chain/indexer/integrated/processor/state.go +++ b/chain/indexer/integrated/processor/state.go @@ -13,26 +13,18 @@ import ( "go.opencensus.io/tag" "go.opentelemetry.io/otel" - saminer1 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - saminer2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - saminer3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" - saminer4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - saminer5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - saminer6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner" - saminer7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" - - init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" - "github.com/filecoin-project/lily/chain/actors/builtin/market" - "github.com/filecoin-project/lily/chain/actors/builtin/miner" - "github.com/filecoin-project/lily/chain/actors/builtin/multisig" - "github.com/filecoin-project/lily/chain/actors/builtin/power" - "github.com/filecoin-project/lily/chain/actors/builtin/reward" - "github.com/filecoin-project/lily/chain/actors/builtin/verifreg" - "github.com/filecoin-project/lily/chain/indexer/tasktype" - "github.com/filecoin-project/lily/metrics" - "github.com/filecoin-project/lily/model" - visormodel "github.com/filecoin-project/lily/model/visor" + // actor accessors + actors "github.com/filecoin-project/lily/chain/actors" + initactors "github.com/filecoin-project/lily/chain/actors/builtin/init" + marketactors "github.com/filecoin-project/lily/chain/actors/builtin/market" + mineractors "github.com/filecoin-project/lily/chain/actors/builtin/miner" + multisigactors "github.com/filecoin-project/lily/chain/actors/builtin/multisig" + poweractors "github.com/filecoin-project/lily/chain/actors/builtin/power" + rewardactors "github.com/filecoin-project/lily/chain/actors/builtin/reward" + verifregactors "github.com/filecoin-project/lily/chain/actors/builtin/verifreg" + "github.com/filecoin-project/lily/tasks" + // actor tasks "github.com/filecoin-project/lily/tasks/actorstate" inittask "github.com/filecoin-project/lily/tasks/actorstate/init_" markettask "github.com/filecoin-project/lily/tasks/actorstate/market" @@ -42,21 +34,28 @@ import ( rawtask "github.com/filecoin-project/lily/tasks/actorstate/raw" rewardtask "github.com/filecoin-project/lily/tasks/actorstate/reward" verifregtask "github.com/filecoin-project/lily/tasks/actorstate/verifreg" - "github.com/filecoin-project/lily/tasks/blocks/drand" - "github.com/filecoin-project/lily/tasks/blocks/headers" - "github.com/filecoin-project/lily/tasks/blocks/parents" - "github.com/filecoin-project/lily/tasks/chaineconomics" - "github.com/filecoin-project/lily/tasks/consensus" - "github.com/filecoin-project/lily/tasks/indexer" - "github.com/filecoin-project/lily/tasks/messageexecutions/internalmessage" - "github.com/filecoin-project/lily/tasks/messageexecutions/internalparsedmessage" - "github.com/filecoin-project/lily/tasks/messages/blockmessage" - "github.com/filecoin-project/lily/tasks/messages/gaseconomy" - "github.com/filecoin-project/lily/tasks/messages/gasoutput" - "github.com/filecoin-project/lily/tasks/messages/message" - "github.com/filecoin-project/lily/tasks/messages/parsedmessage" - "github.com/filecoin-project/lily/tasks/messages/receipt" - "github.com/filecoin-project/lily/tasks/msapprovals" + + // chain state tasks + drandtask "github.com/filecoin-project/lily/tasks/blocks/drand" + headerstask "github.com/filecoin-project/lily/tasks/blocks/headers" + parentstask "github.com/filecoin-project/lily/tasks/blocks/parents" + chainecontask "github.com/filecoin-project/lily/tasks/chaineconomics" + consensustask "github.com/filecoin-project/lily/tasks/consensus" + indexertask "github.com/filecoin-project/lily/tasks/indexer" + imtask "github.com/filecoin-project/lily/tasks/messageexecutions/internalmessage" + ipmtask "github.com/filecoin-project/lily/tasks/messageexecutions/internalparsedmessage" + bmtask "github.com/filecoin-project/lily/tasks/messages/blockmessage" + gasecontask "github.com/filecoin-project/lily/tasks/messages/gaseconomy" + gasouttask "github.com/filecoin-project/lily/tasks/messages/gasoutput" + messagetask "github.com/filecoin-project/lily/tasks/messages/message" + parentmessagetask "github.com/filecoin-project/lily/tasks/messages/parsedmessage" + receipttask "github.com/filecoin-project/lily/tasks/messages/receipt" + msapprovaltask "github.com/filecoin-project/lily/tasks/msapprovals" + + "github.com/filecoin-project/lily/chain/indexer/tasktype" + "github.com/filecoin-project/lily/metrics" + "github.com/filecoin-project/lily/model" + visormodel "github.com/filecoin-project/lily/model/visor" ) type TipSetProcessor interface { @@ -407,51 +406,52 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // case tasktype.MinerCurrentDeadlineInfo: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - miner.AllCodes(), minertask.DeadlineInfoExtractor{}, + mineractors.AllCodes(), minertask.DeadlineInfoExtractor{}, )) case tasktype.MinerFeeDebt: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - miner.AllCodes(), minertask.FeeDebtExtractor{}, + mineractors.AllCodes(), minertask.FeeDebtExtractor{}, )) case tasktype.MinerInfo: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - miner.AllCodes(), minertask.InfoExtractor{}, + mineractors.AllCodes(), minertask.InfoExtractor{}, )) case tasktype.MinerLockedFund: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - miner.AllCodes(), minertask.LockedFundsExtractor{}, + mineractors.AllCodes(), minertask.LockedFundsExtractor{}, )) case tasktype.MinerPreCommitInfo: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - miner.AllCodes(), minertask.PreCommitInfoExtractor{}, + mineractors.AllCodes(), minertask.PreCommitInfoExtractor{}, )) case tasktype.MinerSectorDeal: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - miner.AllCodes(), minertask.SectorDealsExtractor{}, + mineractors.AllCodes(), minertask.SectorDealsExtractor{}, )) case tasktype.MinerSectorEvent: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - miner.AllCodes(), minertask.SectorEventsExtractor{}, + mineractors.AllCodes(), minertask.SectorEventsExtractor{}, )) case tasktype.MinerSectorPost: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - miner.AllCodes(), minertask.PoStExtractor{}, + mineractors.AllCodes(), minertask.PoStExtractor{}, )) case tasktype.MinerSectorInfoV1_6: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewCustomTypedActorExtractorMap( map[cid.Cid][]actorstate.ActorStateExtractor{ - saminer1.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer2.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer3.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer4.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer5.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer6.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, + mineractors.VersionCodes()[actors.Version0]: {minertask.SectorInfoExtractor{}}, + mineractors.VersionCodes()[actors.Version2]: {minertask.SectorInfoExtractor{}}, + mineractors.VersionCodes()[actors.Version3]: {minertask.SectorInfoExtractor{}}, + mineractors.VersionCodes()[actors.Version4]: {minertask.SectorInfoExtractor{}}, + mineractors.VersionCodes()[actors.Version5]: {minertask.SectorInfoExtractor{}}, + mineractors.VersionCodes()[actors.Version6]: {minertask.SectorInfoExtractor{}}, }, )) case tasktype.MinerSectorInfoV7: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewCustomTypedActorExtractorMap( map[cid.Cid][]actorstate.ActorStateExtractor{ - saminer7.Actor{}.Code(): {minertask.V7SectorInfoExtractor{}}, + mineractors.VersionCodes()[actors.Version7]: {minertask.V7SectorInfoExtractor{}}, + mineractors.VersionCodes()[actors.Version8]: {minertask.V7SectorInfoExtractor{}}, }, )) @@ -460,12 +460,12 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // case tasktype.PowerActorClaim: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - power.AllCodes(), + poweractors.AllCodes(), powertask.ClaimedPowerExtractor{}, )) case tasktype.ChainPower: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - power.AllCodes(), + poweractors.AllCodes(), powertask.ChainPowerExtractor{}, )) @@ -474,7 +474,7 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // case tasktype.ChainReward: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - reward.AllCodes(), + rewardactors.AllCodes(), rewardtask.RewardExtractor{}, )) @@ -483,7 +483,7 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // case tasktype.IdAddress: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - init_.AllCodes(), + initactors.AllCodes(), inittask.InitExtractor{}, )) @@ -492,12 +492,12 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // case tasktype.MarketDealState: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - market.AllCodes(), + marketactors.AllCodes(), markettask.DealStateExtractor{}, )) case tasktype.MarketDealProposal: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - market.AllCodes(), + marketactors.AllCodes(), markettask.DealProposalExtractor{}, )) @@ -506,7 +506,7 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // case tasktype.MultisigTransaction: out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( - multisig.AllCodes(), + multisigactors.AllCodes(), multisigtask.MultiSigActorExtractor{}, )) @@ -514,11 +514,13 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // Verified Registry // case tasktype.VerifiedRegistryVerifier: - out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap(verifreg.AllCodes(), + out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( + verifregactors.AllCodes(), verifregtask.VerifierExtractor{}, )) case tasktype.VerifiedRegistryVerifiedClient: - out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap(verifreg.AllCodes(), + out.ActorProcessors[t] = actorstate.NewTask(api, actorstate.NewTypedActorExtractorMap( + verifregactors.AllCodes(), verifregtask.ClientExtractor{}, )) @@ -538,41 +540,41 @@ func MakeProcessors(api tasks.DataSource, indexerTasks []string) (*IndexerProces // Messages // case tasktype.Message: - out.TipsetsProcessors[t] = message.NewTask(api) + out.TipsetsProcessors[t] = messagetask.NewTask(api) case tasktype.GasOutputs: - out.TipsetsProcessors[t] = gasoutput.NewTask(api) + out.TipsetsProcessors[t] = gasouttask.NewTask(api) case tasktype.BlockMessage: - out.TipsetsProcessors[t] = blockmessage.NewTask(api) + out.TipsetsProcessors[t] = bmtask.NewTask(api) case tasktype.ParsedMessage: - out.TipsetsProcessors[t] = parsedmessage.NewTask(api) + out.TipsetsProcessors[t] = parentmessagetask.NewTask(api) case tasktype.Receipt: - out.TipsetsProcessors[t] = receipt.NewTask(api) + out.TipsetsProcessors[t] = receipttask.NewTask(api) case tasktype.InternalMessage: - out.TipsetsProcessors[t] = internalmessage.NewTask(api) + out.TipsetsProcessors[t] = imtask.NewTask(api) case tasktype.InternalParsedMessage: - out.TipsetsProcessors[t] = internalparsedmessage.NewTask(api) + out.TipsetsProcessors[t] = ipmtask.NewTask(api) case tasktype.MessageGasEconomy: - out.TipsetsProcessors[t] = gaseconomy.NewTask(api) + out.TipsetsProcessors[t] = gasecontask.NewTask(api) case tasktype.MultisigApproval: - out.TipsetsProcessors[t] = msapprovals.NewTask(api) + out.TipsetsProcessors[t] = msapprovaltask.NewTask(api) // // Blocks // case tasktype.BlockHeader: - out.TipsetProcessors[t] = headers.NewTask() + out.TipsetProcessors[t] = headerstask.NewTask() case tasktype.BlockParent: - out.TipsetProcessors[t] = parents.NewTask() + out.TipsetProcessors[t] = parentstask.NewTask() case tasktype.DrandBlockEntrie: - out.TipsetProcessors[t] = drand.NewTask() + out.TipsetProcessors[t] = drandtask.NewTask() case tasktype.ChainEconomics: - out.TipsetProcessors[t] = chaineconomics.NewTask(api) + out.TipsetProcessors[t] = chainecontask.NewTask(api) case tasktype.ChainConsensus: - out.TipsetProcessors[t] = consensus.NewTask(api) + out.TipsetProcessors[t] = consensustask.NewTask(api) case BuiltinTaskName: - out.ReportProcessors[t] = indexer.NewTask(api) + out.ReportProcessors[t] = indexertask.NewTask(api) default: return nil, fmt.Errorf("unknown task: %s", t) } diff --git a/chain/indexer/integrated/processor/state_internal_test.go b/chain/indexer/integrated/processor/state_internal_test.go index 0fd577abc..5eb65184e 100644 --- a/chain/indexer/integrated/processor/state_internal_test.go +++ b/chain/indexer/integrated/processor/state_internal_test.go @@ -3,16 +3,10 @@ package processor import ( "testing" - saminer1 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - saminer2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - saminer3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" - saminer4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - saminer5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - saminer6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner" - saminer7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" + "github.com/filecoin-project/lily/chain/actors" init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" "github.com/filecoin-project/lily/chain/actors/builtin/market" "github.com/filecoin-project/lily/chain/actors/builtin/miner" @@ -21,6 +15,7 @@ import ( "github.com/filecoin-project/lily/chain/actors/builtin/reward" "github.com/filecoin-project/lily/chain/actors/builtin/verifreg" "github.com/filecoin-project/lily/chain/indexer/tasktype" + "github.com/filecoin-project/lily/tasks/actorstate" inittask "github.com/filecoin-project/lily/tasks/actorstate/init_" markettask "github.com/filecoin-project/lily/tasks/actorstate/market" @@ -30,6 +25,7 @@ import ( rawtask "github.com/filecoin-project/lily/tasks/actorstate/raw" rewardtask "github.com/filecoin-project/lily/tasks/actorstate/reward" verifregtask "github.com/filecoin-project/lily/tasks/actorstate/verifreg" + "github.com/filecoin-project/lily/tasks/blocks/drand" "github.com/filecoin-project/lily/tasks/blocks/headers" "github.com/filecoin-project/lily/tasks/blocks/parents" @@ -81,17 +77,18 @@ func TestNewProcessor(t *testing.T) { require.Equal(t, actorstate.NewTask(nil, actorstate.NewTypedActorExtractorMap(miner.AllCodes(), minertask.PoStExtractor{})), proc.actorProcessors[tasktype.MinerSectorPost]) require.Equal(t, actorstate.NewTask(nil, actorstate.NewCustomTypedActorExtractorMap( map[cid.Cid][]actorstate.ActorStateExtractor{ - saminer1.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer2.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer3.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer4.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer5.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer6.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version0]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version2]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version3]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version4]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version5]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version6]: {minertask.SectorInfoExtractor{}}, }, )), proc.actorProcessors[tasktype.MinerSectorInfoV1_6]) require.Equal(t, actorstate.NewTask(nil, actorstate.NewCustomTypedActorExtractorMap( map[cid.Cid][]actorstate.ActorStateExtractor{ - saminer7.Actor{}.Code(): {minertask.V7SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version7]: {minertask.V7SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version8]: {minertask.V7SectorInfoExtractor{}}, }, )), proc.actorProcessors[tasktype.MinerSectorInfoV7]) require.Equal(t, actorstate.NewTask(nil, actorstate.NewTypedActorExtractorMap(power.AllCodes(), powertask.ClaimedPowerExtractor{})), proc.actorProcessors[tasktype.PowerActorClaim]) diff --git a/chain/indexer/integrated/processor/state_test.go b/chain/indexer/integrated/processor/state_test.go index 6579a3e3b..dac45dee2 100644 --- a/chain/indexer/integrated/processor/state_test.go +++ b/chain/indexer/integrated/processor/state_test.go @@ -3,16 +3,10 @@ package processor_test import ( "testing" - saminer1 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - saminer2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - saminer3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner" - saminer4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner" - saminer5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - saminer6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner" - saminer7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" + "github.com/filecoin-project/lily/chain/actors" init_ "github.com/filecoin-project/lily/chain/actors/builtin/init" "github.com/filecoin-project/lily/chain/actors/builtin/market" "github.com/filecoin-project/lily/chain/actors/builtin/miner" @@ -90,12 +84,12 @@ func TestMakeProcessorsActors(t *testing.T) { taskName: tasktype.MinerSectorInfoV1_6, extractor: actorstate.NewCustomTypedActorExtractorMap( map[cid.Cid][]actorstate.ActorStateExtractor{ - saminer1.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer2.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer3.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer4.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer5.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, - saminer6.Actor{}.Code(): {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version0]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version2]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version3]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version4]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version5]: {minertask.SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version6]: {minertask.SectorInfoExtractor{}}, }, ), }, @@ -103,7 +97,8 @@ func TestMakeProcessorsActors(t *testing.T) { taskName: tasktype.MinerSectorInfoV7, extractor: actorstate.NewCustomTypedActorExtractorMap( map[cid.Cid][]actorstate.ActorStateExtractor{ - saminer7.Actor{}.Code(): {minertask.V7SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version7]: {minertask.V7SectorInfoExtractor{}}, + miner.VersionCodes()[actors.Version8]: {minertask.V7SectorInfoExtractor{}}, }, ), }, diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index cd52de8db..943e33574 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit cd52de8dbcf117109c8d6f02c17e855ccdc0497c +Subproject commit 943e33574dcacd940edff0cf414c82e656bdaeb3 diff --git a/go.mod b/go.mod index b052c7ef7..55f7f46bd 100644 --- a/go.mod +++ b/go.mod @@ -13,15 +13,15 @@ require ( github.com/filecoin-project/go-hamt-ipld/v3 v3.1.1-0.20220505191157-d7766f8628ec github.com/filecoin-project/go-jsonrpc v0.1.5 github.com/filecoin-project/go-paramfetch v0.0.4 - github.com/filecoin-project/go-state-types v0.1.3 - github.com/filecoin-project/lotus v1.15.3 - github.com/filecoin-project/specs-actors v0.9.14 + github.com/filecoin-project/go-state-types v0.1.10 + github.com/filecoin-project/lotus v1.16.0 + github.com/filecoin-project/specs-actors v0.9.15 github.com/filecoin-project/specs-actors/v2 v2.3.6 - github.com/filecoin-project/specs-actors/v3 v3.1.1 - github.com/filecoin-project/specs-actors/v4 v4.0.1 - github.com/filecoin-project/specs-actors/v5 v5.0.4 - github.com/filecoin-project/specs-actors/v6 v6.0.1 - github.com/filecoin-project/specs-actors/v7 v7.0.0 + github.com/filecoin-project/specs-actors/v3 v3.1.2 + github.com/filecoin-project/specs-actors/v4 v4.0.2 + github.com/filecoin-project/specs-actors/v5 v5.0.6 + github.com/filecoin-project/specs-actors/v6 v6.0.2 + github.com/filecoin-project/specs-actors/v7 v7.0.1 github.com/gammazero/workerpool v1.1.2 github.com/go-pg/migrations/v8 v8.0.1 github.com/go-pg/pg/v10 v10.10.6 @@ -45,7 +45,7 @@ require ( github.com/raulk/clock v1.1.0 github.com/stretchr/testify v1.7.1 github.com/urfave/cli/v2 v2.8.0 - github.com/whyrusleeping/cbor-gen v0.0.0-20220302191723-37c43cae8e14 + github.com/whyrusleeping/cbor-gen v0.0.0-20220323183124-98fa8256a799 go.opencensus.io v0.23.0 go.opentelemetry.io/otel v1.3.0 go.opentelemetry.io/otel/bridge/opencensus v0.25.0 @@ -64,6 +64,7 @@ require k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 require ( github.com/filecoin-project/go-amt-ipld/v4 v4.0.1-0.20220601173204-7b82b2c4bc9c + github.com/filecoin-project/specs-actors/v8 v8.0.0 github.com/hibiken/asynq v0.23.0 github.com/hibiken/asynq/x v0.0.0-20220413130846-5c723f597e01 github.com/jedib0t/go-pretty/v6 v6.2.7 @@ -124,17 +125,17 @@ require ( github.com/filecoin-project/go-ds-versioning v0.1.1 // indirect github.com/filecoin-project/go-fil-commcid v0.1.0 // indirect github.com/filecoin-project/go-fil-commp-hashhash v0.1.0 // indirect - github.com/filecoin-project/go-fil-markets v1.20.1 // indirect + github.com/filecoin-project/go-fil-markets v1.20.1-v16-2 // indirect github.com/filecoin-project/go-hamt-ipld v0.1.5 // indirect github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 // indirect - github.com/filecoin-project/go-legs v0.3.7 // indirect + github.com/filecoin-project/go-legs v0.3.10 // indirect github.com/filecoin-project/go-padreader v0.0.1 // indirect github.com/filecoin-project/go-statemachine v1.0.2 // indirect github.com/filecoin-project/go-statestore v0.2.0 // indirect github.com/filecoin-project/go-storedcounter v0.1.0 // indirect github.com/filecoin-project/index-provider v0.5.0 // indirect github.com/filecoin-project/pubsub v1.0.0 // indirect - github.com/filecoin-project/specs-storage v0.2.4 // indirect + github.com/filecoin-project/specs-storage v0.4.1 // indirect github.com/filecoin-project/storetheindex v0.3.5 // indirect github.com/flynn/noise v1.0.0 // indirect github.com/francoispqt/gojay v1.2.13 // indirect @@ -229,7 +230,7 @@ require ( github.com/libp2p/go-conn-security-multistream v0.3.0 // indirect github.com/libp2p/go-eventbus v0.2.1 // indirect github.com/libp2p/go-flow-metrics v0.0.3 // indirect - github.com/libp2p/go-libp2p v0.19.3 // indirect + github.com/libp2p/go-libp2p v0.19.4 // indirect github.com/libp2p/go-libp2p-asn-util v0.1.0 // indirect github.com/libp2p/go-libp2p-blankhost v0.3.0 // indirect github.com/libp2p/go-libp2p-connmgr v0.3.1 // indirect @@ -263,7 +264,7 @@ require ( github.com/libp2p/go-stream-muxer-multistream v0.4.0 // indirect github.com/libp2p/go-tcp-transport v0.5.1 // indirect github.com/libp2p/go-ws-transport v0.6.0 // indirect - github.com/libp2p/go-yamux/v3 v3.1.1 // indirect + github.com/libp2p/go-yamux/v3 v3.1.2 // indirect github.com/lucas-clemente/quic-go v0.27.1 // indirect github.com/lucasb-eyer/go-colorful v1.0.3 // indirect github.com/magefile/mage v1.9.0 // indirect @@ -303,7 +304,6 @@ require ( github.com/prometheus/procfs v0.7.3 // indirect github.com/prometheus/statsd_exporter v0.21.0 // indirect github.com/raulk/go-watchdog v1.2.0 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/rivo/uniseg v0.2.0 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect github.com/rs/cors v1.7.0 // indirect @@ -315,7 +315,6 @@ require ( github.com/spf13/cast v1.3.1 // indirect github.com/stretchr/objx v0.2.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect - github.com/tj/go-spin v1.1.0 // indirect github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.0.1 // indirect @@ -330,8 +329,6 @@ require ( github.com/whyrusleeping/ledger-filecoin-go v0.9.1-0.20201010031517-c3dcc1bddce4 // indirect github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee // indirect - github.com/xlab/c-for-go v0.0.0-20201112171043-ea6dce5809cb // indirect - github.com/xlab/pkgconfig v0.0.0-20170226114623-cea12a0fd245 // indirect github.com/zondax/hid v0.9.0 // indirect github.com/zondax/ledger-go v0.12.1 // indirect go.opentelemetry.io/otel/metric v0.25.0 // indirect @@ -355,11 +352,6 @@ require ( howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect lukechampine.com/blake3 v1.1.7 // indirect mellium.im/sasl v0.2.1 // indirect - modernc.org/cc v1.0.0 // indirect - modernc.org/golex v1.0.1 // indirect - modernc.org/mathutil v1.1.1 // indirect - modernc.org/strutil v1.1.0 // indirect - modernc.org/xc v1.0.0 // indirect ) replace ( diff --git a/go.sum b/go.sum index 733d23e15..b5c62db26 100644 --- a/go.sum +++ b/go.sum @@ -348,8 +348,8 @@ github.com/filecoin-project/go-fil-commcid v0.1.0 h1:3R4ds1A9r6cr8mvZBfMYxTS88Oq github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-commp-hashhash v0.1.0 h1:imrrpZWEHRnNqqv0tN7LXep5bFEVOVmQWHJvl2mgsGo= github.com/filecoin-project/go-fil-commp-hashhash v0.1.0/go.mod h1:73S8WSEWh9vr0fDJVnKADhfIv/d6dCbAGaAGWbdJEI8= -github.com/filecoin-project/go-fil-markets v1.20.1 h1:DwrFuNIWC0a2c2ESpHtdEMH3QCpR/hoZ5DwjNT+VJ+E= -github.com/filecoin-project/go-fil-markets v1.20.1/go.mod h1:QV767KIWHrikVK8R0u2wTc5wkee4gXOf5/AfxDoQckw= +github.com/filecoin-project/go-fil-markets v1.20.1-v16-2 h1:uZHJav35gTGcm2CwY8B+V6fQO9aB1YeUYid2jkb6jXE= +github.com/filecoin-project/go-fil-markets v1.20.1-v16-2/go.mod h1:JLP8bltMbPVhOULcHxE+QFg3b8/a9J8NbcA6Qf69W0k= github.com/filecoin-project/go-hamt-ipld v0.1.5 h1:uoXrKbCQZ49OHpsTCkrThPNelC4W3LPEk0OrS/ytIBM= github.com/filecoin-project/go-hamt-ipld v0.1.5/go.mod h1:6Is+ONR5Cd5R6XZoCse1CWaXZc0Hdb/JeX+EQCQzX24= github.com/filecoin-project/go-hamt-ipld/v2 v2.0.0 h1:b3UDemBYN2HNfk3KOXNuxgTTxlWi3xVvbQP0IT38fvM= @@ -361,8 +361,9 @@ github.com/filecoin-project/go-hamt-ipld/v3 v3.1.1-0.20220505191157-d7766f8628ec github.com/filecoin-project/go-indexer-core v0.2.8/go.mod h1:IagNfTdFuX4057kla43PjRCn3yBuUiZgIxuA0hTUamY= github.com/filecoin-project/go-jsonrpc v0.1.5 h1:ckxqZ09ivBAVf5CSmxxrqqNHC7PJm3GYGtYKiNQ+vGk= github.com/filecoin-project/go-jsonrpc v0.1.5/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= -github.com/filecoin-project/go-legs v0.3.7 h1:yfm7fx+iy1nPtgPEQ6kQjvhoJOVbXide50STYdy+yos= github.com/filecoin-project/go-legs v0.3.7/go.mod h1:pgekGm8/gKY5zCtQ/qGAoSjGP92wTLFqpO3GPHeu8YU= +github.com/filecoin-project/go-legs v0.3.10 h1:B14z78do63gkxf5Br7rPnxZsZk/m9PR3Mx5aOf2WTIs= +github.com/filecoin-project/go-legs v0.3.10/go.mod h1:5psVRe2nRQDa3PDtcd+2Ud4CirxOr2DI5VsDVMq7sIk= github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20/go.mod h1:mPn+LRRd5gEKNAtc+r3ScpW2JRU/pj4NBKdADYWHiak= github.com/filecoin-project/go-padreader v0.0.1 h1:8h2tVy5HpoNbr2gBRr+WD6zV6VD6XHig+ynSGJg8ZOs= github.com/filecoin-project/go-padreader v0.0.1/go.mod h1:VYVPJqwpsfmtoHnAmPx6MUwmrK6HIcDqZJiuZhtmfLQ= @@ -373,11 +374,14 @@ github.com/filecoin-project/go-state-types v0.0.0-20200928172055-2df22083d8ab/go github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-state-types v0.1.1-0.20210810190654-139e0e79e69e/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= -github.com/filecoin-project/go-state-types v0.1.1/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= -github.com/filecoin-project/go-state-types v0.1.3 h1:rzIJyQo5HO2ptc8Jcu8P0qTutnI7NWwTle54eAHoNO0= github.com/filecoin-project/go-state-types v0.1.3/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= +github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4IrzznwS98X5XW/irUP3Lhxg= +github.com/filecoin-project/go-state-types v0.1.5/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= +github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= +github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= +github.com/filecoin-project/go-state-types v0.1.10 h1:YrrJWWh2fU4VPhwHyPlDK5I4mB7bqgnRd3HCm9IOwIU= +github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig= -github.com/filecoin-project/go-statemachine v1.0.1/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= github.com/filecoin-project/go-statemachine v1.0.2-0.20220322104818-27f8fbb86dfd/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc= github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= @@ -388,32 +392,38 @@ github.com/filecoin-project/go-storedcounter v0.1.0 h1:Mui6wSUBC+cQGHbDUBcO7rfh5 github.com/filecoin-project/go-storedcounter v0.1.0/go.mod h1:4ceukaXi4vFURIoxYMfKzaRF5Xv/Pinh2oTnoxpv+z8= github.com/filecoin-project/index-provider v0.5.0 h1:k2C1RFvOvxmA2i8bhmkb3b4qun7RDRDzzs/y25/TwQg= github.com/filecoin-project/index-provider v0.5.0/go.mod h1:KHVrP2vU3YuScb+fawObwTFoR882up9U07kk0ZrfP0c= -github.com/filecoin-project/lotus v1.15.3 h1:kFZafnUwbinMZGp49dTkEpRXyj8H9L9jlRwZIL2QVf8= -github.com/filecoin-project/lotus v1.15.3/go.mod h1:8vKV/W9aHJQ9AVGY1uYg7xCsSLWeCYJCX1jacBCsUYQ= +github.com/filecoin-project/lotus v1.16.0 h1:CbCXSoAMHV2Nx9eI6lP0NbRefvnWp4WTZjvOlcqpT/k= +github.com/filecoin-project/lotus v1.16.0/go.mod h1:JVXUiVE0BFW4DeQSElzJ9nCEIFJnBuwo2habuVGpF0c= github.com/filecoin-project/pubsub v1.0.0 h1:ZTmT27U07e54qV1mMiQo4HDr0buo8I1LDHBYLXlsNXM= github.com/filecoin-project/pubsub v1.0.0/go.mod h1:GkpB33CcUtUNrLPhJgfdy4FDx4OMNR9k+46DHx/Lqrg= github.com/filecoin-project/specs-actors v0.9.13/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao= -github.com/filecoin-project/specs-actors v0.9.14 h1:68PVstg2UB3ZsMLF+DKFTAs/YKsqhKWynkr0IqmVRQY= -github.com/filecoin-project/specs-actors v0.9.14/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao= +github.com/filecoin-project/specs-actors v0.9.15-0.20220514164640-94e0d5e123bd/go.mod h1:pjGEe3QlWtK20ju/aFRsiArbMX6Cn8rqEhhsiCM9xYE= +github.com/filecoin-project/specs-actors v0.9.15 h1:3VpKP5/KaDUHQKAMOg4s35g/syDaEBueKLws0vbsjMc= +github.com/filecoin-project/specs-actors v0.9.15/go.mod h1:pjGEe3QlWtK20ju/aFRsiArbMX6Cn8rqEhhsiCM9xYE= github.com/filecoin-project/specs-actors/v2 v2.3.5-0.20210114162132-5b58b773f4fb/go.mod h1:LljnY2Mn2homxZsmokJZCpRuhOPxfXhvcek5gWkmqAc= github.com/filecoin-project/specs-actors/v2 v2.3.6 h1:UxnWTfQd7JsOae39/aHCK0m1IBjdcyymCJfqxuSkn+g= github.com/filecoin-project/specs-actors/v2 v2.3.6/go.mod h1:DJMpxVRXvev9t8P0XWA26RmTzN+MHiL9IlItVLT0zUc= github.com/filecoin-project/specs-actors/v3 v3.1.0/go.mod h1:mpynccOLlIRy0QnR008BwYBwT9fen+sPR13MA1VmMww= -github.com/filecoin-project/specs-actors/v3 v3.1.1 h1:BE8fsns1GnEOxt1DTE5LxBK2FThXtWmCChgcJoHTg0E= -github.com/filecoin-project/specs-actors/v3 v3.1.1/go.mod h1:mpynccOLlIRy0QnR008BwYBwT9fen+sPR13MA1VmMww= +github.com/filecoin-project/specs-actors/v3 v3.1.2 h1:Gq3gAbvdGLA/D0GKz1IJfewt9Fh7gA32TPt46Xv+1Cw= +github.com/filecoin-project/specs-actors/v3 v3.1.2/go.mod h1:uOJn+m6W8OW/1mdWMEvxeM1cjQPxmps7s1Z4bJ9V4kY= github.com/filecoin-project/specs-actors/v4 v4.0.0/go.mod h1:TkHXf/l7Wyw4ZejyXIPS2rK8bBO0rdwhTZyQQgaglng= -github.com/filecoin-project/specs-actors/v4 v4.0.1 h1:AiWrtvJZ63MHGe6rn7tPu4nSUY8bA1KDNszqJaD5+Fg= -github.com/filecoin-project/specs-actors/v4 v4.0.1/go.mod h1:TkHXf/l7Wyw4ZejyXIPS2rK8bBO0rdwhTZyQQgaglng= -github.com/filecoin-project/specs-actors/v5 v5.0.4 h1:OY7BdxJWlUfUFXWV/kpNBYGXNPasDIedf42T3sGx08s= +github.com/filecoin-project/specs-actors/v4 v4.0.2 h1:VTsv30kIf1Keo8Jlu6Omco+2Ud0pG4EN5UAzyYCibh8= +github.com/filecoin-project/specs-actors/v4 v4.0.2/go.mod h1:zT0GVFxwFS93prGK0b/rMd1sePjRQKfAuodQ9DFAd6Y= github.com/filecoin-project/specs-actors/v5 v5.0.4/go.mod h1:5BAKRAMsOOlD8+qCw4UvT/lTLInCJ3JwOWZbX8Ipwq4= +github.com/filecoin-project/specs-actors/v5 v5.0.5/go.mod h1:dnfda2U+0ZidVnZJ44fnLMa3Mbyzwx51iW/brSsS+nc= +github.com/filecoin-project/specs-actors/v5 v5.0.6 h1:TLtA9hT3pHQF5vB83GmB+m6anw9u6MjdT+VVn/lyC+c= +github.com/filecoin-project/specs-actors/v5 v5.0.6/go.mod h1:myb/UGwESp0V1f1BACXSUrFgTWLvGUoG0ZZH7eqriFM= github.com/filecoin-project/specs-actors/v6 v6.0.0/go.mod h1:V1AYfi5GkHXipx1mnVivoICZh3wtwPxDVuds+fbfQtk= -github.com/filecoin-project/specs-actors/v6 v6.0.1 h1:laxvHNsvrq83Y9n+W7znVCePi3oLyRf0Rkl4jFO8Wew= github.com/filecoin-project/specs-actors/v6 v6.0.1/go.mod h1:V1AYfi5GkHXipx1mnVivoICZh3wtwPxDVuds+fbfQtk= -github.com/filecoin-project/specs-actors/v7 v7.0.0-rc1.0.20220118005651-2470cb39827e/go.mod h1:TA5FwCna+Yi36POaT7SLKXsgEDvJwc0V/L6ZsO19B9M= -github.com/filecoin-project/specs-actors/v7 v7.0.0 h1:FQN7tjt3o68hfb3qLFSJBoLMuOFY0REkFVLO/zXj8RU= +github.com/filecoin-project/specs-actors/v6 v6.0.2 h1:K1xPRJoW5PBvb08QF9+4w1AjcnqwR6BjTmeltQFCvWo= +github.com/filecoin-project/specs-actors/v6 v6.0.2/go.mod h1:wnfVvPnYmzPZilNvSqCSSA/ZQX3rdV/U/Vf9EIoQhrI= github.com/filecoin-project/specs-actors/v7 v7.0.0/go.mod h1:TA5FwCna+Yi36POaT7SLKXsgEDvJwc0V/L6ZsO19B9M= -github.com/filecoin-project/specs-storage v0.2.4 h1:acymZwLVQm6bLKPtS5OqmVBuG2GDLna+pECDVMN1vto= -github.com/filecoin-project/specs-storage v0.2.4/go.mod h1:6cc/lncmAxMUocPi0z1EPCX63beIX7F7UnlmUZ3hLQo= +github.com/filecoin-project/specs-actors/v7 v7.0.1 h1:w72xCxijK7xs1qzmJiw+WYJaVt2EPHN8oiwpA1Ay3/4= +github.com/filecoin-project/specs-actors/v7 v7.0.1/go.mod h1:tPLEYXoXhcpyLh69Ccq91SOuLXsPWjHiY27CzawjUEk= +github.com/filecoin-project/specs-actors/v8 v8.0.0 h1:c6NztoE4J5j7KvIfGmx9XW9o5aszPl6DU0M4xDqAJVU= +github.com/filecoin-project/specs-actors/v8 v8.0.0/go.mod h1:UYIPg65iPWoFw5NEftREdJwv9b/5yaLKdCgTvNI/2FA= +github.com/filecoin-project/specs-storage v0.4.1 h1:yvLEaLZj8f+uByhNC4mFOtCUyL2wQku+NGBp6hjTe9M= +github.com/filecoin-project/specs-storage v0.4.1/go.mod h1:Z2eK6uMwAOSLjek6+sy0jNV2DSsMEENziMUz0GHRFBw= github.com/filecoin-project/storetheindex v0.3.5 h1:KoS9TvjPm6zIZfUH8atAHJbVHOO7GTP1MdTG+v0eE+Q= github.com/filecoin-project/storetheindex v0.3.5/go.mod h1:0r3d0kSpK63O6AvLr1CjAINLi+nWD49clzcnKV+GLpI= github.com/filecoin-project/test-vectors/schema v0.0.5/go.mod h1:iQ9QXLpYWL3m7warwvK1JC/pTri8mnfEmKygNDqqY6E= @@ -1111,8 +1121,9 @@ github.com/libp2p/go-libp2p v0.16.0/go.mod h1:ump42BsirwAWxKzsCiFnTtN1Yc+DuPu76f github.com/libp2p/go-libp2p v0.17.0/go.mod h1:Fkin50rsGdv5mm5BshBUtPRZknt9esfmYXBOYcwOTgw= github.com/libp2p/go-libp2p v0.18.0-rc1/go.mod h1:RgYlH7IIWHXREimC92bw5Lg1V2R5XmSzuLHb5fTnr+8= github.com/libp2p/go-libp2p v0.18.0-rc3/go.mod h1:WYL+Xw1iuwi6rdfzw5VIEpD+HqzYucHZ6fcUuumbI3M= -github.com/libp2p/go-libp2p v0.19.3 h1:LqjvuBWdyYSqvkH4VVYxA78Fkphzg2Pq86VMnilqgkw= -github.com/libp2p/go-libp2p v0.19.3/go.mod h1:AGlPVLjh0+6jvEtf+a2gZEux7yHJrYXnG9IC7wcQ2NY= +github.com/libp2p/go-libp2p v0.18.0-rc5/go.mod h1:aZPS5l84bDvCvP4jkyEUT/J6YOpUq33Fgqrs3K59mpI= +github.com/libp2p/go-libp2p v0.19.4 h1:50YL0YwPhWKDd+qbZQDEdnsmVAAkaCQrWUjpdHv4hNA= +github.com/libp2p/go-libp2p v0.19.4/go.mod h1:MIt8y481VDhUe4ErWi1a4bvt/CjjFfOq6kZTothWIXY= github.com/libp2p/go-libp2p-asn-util v0.0.0-20200825225859-85005c6cf052/go.mod h1:nRMRTab+kZuk0LnKZpxhOVH/ndsdr2Nr//Zltc/vwgo= github.com/libp2p/go-libp2p-asn-util v0.1.0 h1:rABPCO77SjdbJ/eJ/ynIo8vWICy1VEnL5JAxJbQLo1E= github.com/libp2p/go-libp2p-asn-util v0.1.0/go.mod h1:wu+AnM9Ii2KgO5jMmS1rz9dvzTdj8BXqsPR9HR0XB7I= @@ -1276,6 +1287,7 @@ github.com/libp2p/go-libp2p-quic-transport v0.13.0/go.mod h1:39/ZWJ1TW/jx1iFkKzz github.com/libp2p/go-libp2p-quic-transport v0.15.0/go.mod h1:wv4uGwjcqe8Mhjj7N/Ic0aKjA+/10UnMlSzLO0yRpYQ= github.com/libp2p/go-libp2p-quic-transport v0.15.2/go.mod h1:wv4uGwjcqe8Mhjj7N/Ic0aKjA+/10UnMlSzLO0yRpYQ= github.com/libp2p/go-libp2p-quic-transport v0.16.0/go.mod h1:1BXjVMzr+w7EkPfiHkKnwsWjPjtfaNT0q8RS3tGDvEQ= +github.com/libp2p/go-libp2p-quic-transport v0.16.1/go.mod h1:1BXjVMzr+w7EkPfiHkKnwsWjPjtfaNT0q8RS3tGDvEQ= github.com/libp2p/go-libp2p-quic-transport v0.17.0 h1:yFh4Gf5MlToAYLuw/dRvuzYd1EnE2pX3Lq1N6KDiWRQ= github.com/libp2p/go-libp2p-quic-transport v0.17.0/go.mod h1:x4pw61P3/GRCcSLypcQJE/Q2+E9f4X+5aRcZLXf20LM= github.com/libp2p/go-libp2p-record v0.0.1/go.mod h1:grzqg263Rug/sRex85QrDOLntdFAymLDLm7lxMgU79Q= @@ -1369,6 +1381,7 @@ github.com/libp2p/go-libp2p-yamux v0.6.0/go.mod h1:MRhd6mAYnFRnSISp4M8i0ClV/j+mW github.com/libp2p/go-libp2p-yamux v0.7.0/go.mod h1:fMyA0CsPfHkIuBU0wjRGrCjTBFiXTXxG0k5M4ETv+08= github.com/libp2p/go-libp2p-yamux v0.8.0/go.mod h1:yTkPgN2ib8FHyU1ZcVD7aelzyAqXXwEPbyx+aSKm9h8= github.com/libp2p/go-libp2p-yamux v0.8.1/go.mod h1:rUozF8Jah2dL9LLGyBaBeTQeARdwhefMCTQVQt6QobE= +github.com/libp2p/go-libp2p-yamux v0.8.2/go.mod h1:rUozF8Jah2dL9LLGyBaBeTQeARdwhefMCTQVQt6QobE= github.com/libp2p/go-libp2p-yamux v0.9.1 h1:oplewiRix8s45SOrI30rCPZG5mM087YZp+VYhXAh4+c= github.com/libp2p/go-libp2p-yamux v0.9.1/go.mod h1:wRc6wvyxQINFcKe7daL4BeQ02Iyp+wxyC8WCNfngBrA= github.com/libp2p/go-maddr-filter v0.0.1/go.mod h1:6eT12kSQMA9x2pvFQa+xesMKUBlj9VImZbj3B9FBH/Q= @@ -1471,8 +1484,9 @@ github.com/libp2p/go-yamux/v2 v2.2.0/go.mod h1:3So6P6TV6r75R9jiBpiIKgU/66lOarCZj github.com/libp2p/go-yamux/v2 v2.3.0/go.mod h1:iTU+lOIn/2h0AgKcL49clNTwfEw+WSfDYrXe05EyKIs= github.com/libp2p/go-yamux/v3 v3.0.1/go.mod h1:s2LsDhHbh+RfCsQoICSYt58U2f8ijtPANFD8BmE74Bo= github.com/libp2p/go-yamux/v3 v3.0.2/go.mod h1:s2LsDhHbh+RfCsQoICSYt58U2f8ijtPANFD8BmE74Bo= -github.com/libp2p/go-yamux/v3 v3.1.1 h1:X0qSVodCZciOu/f4KTp9V+O0LAqcqP2tdaUGB0+0lng= github.com/libp2p/go-yamux/v3 v3.1.1/go.mod h1:jeLEQgLXqE2YqX1ilAClIfCMDY+0uXQUKmmb/qp0gT4= +github.com/libp2p/go-yamux/v3 v3.1.2 h1:lNEy28MBk1HavUAlzKgShp+F6mn/ea1nDYWftZhFW9Q= +github.com/libp2p/go-yamux/v3 v3.1.2/go.mod h1:jeLEQgLXqE2YqX1ilAClIfCMDY+0uXQUKmmb/qp0gT4= github.com/libp2p/zeroconf/v2 v2.1.1/go.mod h1:fuJqLnUwZTshS3U/bMRJ3+ow/v9oid1n0DmyYyNO1Xs= github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= @@ -1837,8 +1851,6 @@ github.com/raulk/clock v1.1.0/go.mod h1:3MpVxdZ/ODBQDxbN+kzshf5OSZwPjtMDx6BBXBmO github.com/raulk/go-watchdog v1.2.0 h1:konN75pw2BMmZ+AfuAm5rtFsWcJpKF3m02rKituuXNo= github.com/raulk/go-watchdog v1.2.0/go.mod h1:lzSbAl5sh4rtI8tYHU01BWIDzgzqaQLj6RcA1i4mlqI= github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk= -github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -1957,8 +1969,6 @@ github.com/texttheater/golang-levenshtein v0.0.0-20180516184445-d188e65d659e/go. github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/tj/go-spin v1.1.0 h1:lhdWZsvImxvZ3q1C5OIB7d72DuOwP4O2NdBg9PyzNds= -github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKwh4= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo= github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs= @@ -2029,10 +2039,10 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20200826160007-0b9f6c5fb163/go.mod h1:f github.com/whyrusleeping/cbor-gen v0.0.0-20210118024343-169e9d70c0c2/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/cbor-gen v0.0.0-20210303213153-67a261a1d291/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= -github.com/whyrusleeping/cbor-gen v0.0.0-20210713220151-be142a5ae1a8/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/cbor-gen v0.0.0-20220224212727-7a699437a831/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= -github.com/whyrusleeping/cbor-gen v0.0.0-20220302191723-37c43cae8e14 h1:vo2wkP2ceHyGyZwFFtAabpot03EeSxxwAe57pOI9E/4= github.com/whyrusleeping/cbor-gen v0.0.0-20220302191723-37c43cae8e14/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= +github.com/whyrusleeping/cbor-gen v0.0.0-20220323183124-98fa8256a799 h1:DOOT2B85S0tHoLGTzV+FakaSSihgRCVwZkjqKQP5L/w= +github.com/whyrusleeping/cbor-gen v0.0.0-20220323183124-98fa8256a799/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E= github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8= github.com/whyrusleeping/go-ctrlnet v0.0.0-20180313164037-f564fbbdaa95/go.mod h1:SJqKCCPXRfBFCwXjfNT/skfsceF7+MBFLI2OrvuRA7g= @@ -2053,10 +2063,6 @@ github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee h1:lYbXeSv github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee/go.mod h1:m2aV4LZI4Aez7dP5PMyVKEHhUyEJ/RjmPEDOpDvudHg= github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xlab/c-for-go v0.0.0-20201112171043-ea6dce5809cb h1:/7/dQyiKnxAOj9L69FhST7uMe17U015XPzX7cy+5ykM= -github.com/xlab/c-for-go v0.0.0-20201112171043-ea6dce5809cb/go.mod h1:pbNsDSxn1ICiNn9Ct4ZGNrwzfkkwYbx/lw8VuyutFIg= -github.com/xlab/pkgconfig v0.0.0-20170226114623-cea12a0fd245 h1:Sw125DKxZhPUI4JLlWugkzsrlB50jR9v2khiD9FxuSo= -github.com/xlab/pkgconfig v0.0.0-20170226114623-cea12a0fd245/go.mod h1:C+diUUz7pxhNY6KAoLgrTYARGWnt82zWTylZlxT92vk= github.com/xorcare/golden v0.6.0/go.mod h1:7T39/ZMvaSEZlBPoYfVFmsBLmUl3uz9IuzWj/U6FtvQ= github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542 h1:oWgZJmC1DorFZDpfMfWg7xk29yEOZiXmo/wZl+utTI8= github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542/go.mod h1:7T39/ZMvaSEZlBPoYfVFmsBLmUl3uz9IuzWj/U6FtvQ= @@ -2221,7 +2227,6 @@ golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrb golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20181106170214-d68db9428509/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -2552,7 +2557,6 @@ golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200711155855-7342f9734a7d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= @@ -2742,20 +2746,6 @@ lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0= lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w= mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ= -modernc.org/cc v1.0.0 h1:nPibNuDEx6tvYrUAtvDTTw98rx5juGsa5zuDnKwEEQQ= -modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw= -modernc.org/fileutil v1.0.0/go.mod h1:JHsWpkrk/CnVV1H/eGlFf85BEpfkrp56ro8nojIq9Q8= -modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk= -modernc.org/golex v1.0.1 h1:EYKY1a3wStt0RzHaH8mdSRNg78Ub0OHxYfCRWw35YtM= -modernc.org/golex v1.0.1/go.mod h1:QCA53QtsT1NdGkaZZkF5ezFwk4IXh4BGNafAARTC254= -modernc.org/lex v1.0.0/go.mod h1:G6rxMTy3cH2iA0iXL/HRRv4Znu8MK4higxph/lE7ypk= -modernc.org/lexer v1.0.0/go.mod h1:F/Dld0YKYdZCLQ7bD0USbWL4YKCyTDRDHiDTOs0q0vk= -modernc.org/mathutil v1.1.1 h1:FeylZSVX8S+58VsyJlkEj2bcpdytmp9MmDKZkKx8OIE= -modernc.org/mathutil v1.1.1/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= -modernc.org/strutil v1.1.0 h1:+1/yCzZxY2pZwwrsbH+4T7BQMoLQ9QiBshRC9eicYsc= -modernc.org/strutil v1.1.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs= -modernc.org/xc v1.0.0 h1:7ccXrupWZIS3twbUGrtKmHS2DXY6xegFua+6O3xgAFU= -modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I= pgregory.net/rapid v0.4.7/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/lens/interface.go b/lens/interface.go index 056b074fe..dbc1b270d 100644 --- a/lens/interface.go +++ b/lens/interface.go @@ -51,7 +51,7 @@ type StateAPI interface { StateMinerPower(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*api.MinerPower, error) - StateMarketDeals(context.Context, types.TipSetKey) (map[string]api.MarketDeal, error) + StateMarketDeals(context.Context, types.TipSetKey) (map[string]*api.MarketDeal, error) StateReadState(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*api.ActorState, error) StateGetReceipt(ctx context.Context, bcid cid.Cid, tsk types.TipSetKey) (*types.MessageReceipt, error) diff --git a/lens/lily/impl.go b/lens/lily/impl.go index d2a11d6bf..c8899cc7f 100644 --- a/lens/lily/impl.go +++ b/lens/lily/impl.go @@ -37,6 +37,7 @@ import ( "github.com/filecoin-project/lily/storage" ) +var _ lens.API = (*LilyNodeAPI)(nil) var _ LilyAPI = (*LilyNodeAPI)(nil) type LilyNodeAPI struct { diff --git a/lens/util/repo.go b/lens/util/repo.go index e9ca53fbf..d160883cb 100644 --- a/lens/util/repo.go +++ b/lens/util/repo.go @@ -10,6 +10,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/exitcode" + "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" cbg "github.com/whyrusleeping/cbor-gen" @@ -159,54 +160,64 @@ func GetExecutedAndBlockMessagesForTipset(ctx context.Context, cs *store.ChainSt return nil, fmt.Errorf("mismatching number of receipts: got %d wanted %d", rs.Length(), len(emsgs)) } - filVested, err := sm.GetFilVested(ctx, current.Height()) - if err != nil { - return nil, err - } // Create a skeleton vm just for calling ShouldBurn // NB: VM is only required to process state prior to network v13 - vmi, err := vm.NewVM(ctx, &vm.VMOpts{ - StateBase: current.ParentState(), - Epoch: current.Height(), - Bstore: cs.StateBlockstore(), - NetworkVersion: DefaultNetwork.Version(ctx, current.Height()), - Actors: filcns.NewActorRegistry(), - Syscalls: sm.Syscalls, - CircSupplyCalc: sm.GetVMCirculatingSupply, - BaseFee: current.Blocks()[0].ParentBaseFee, - FilVested: filVested, - }) - if err != nil { - return nil, fmt.Errorf("creating temporary vm: %w", err) - } + if DefaultNetwork.Version(ctx, executed.Height()) <= network.Version12 { + vmi, err := vm.NewVM(ctx, &vm.VMOpts{ + StateBase: current.ParentState(), + Epoch: current.Height(), + Bstore: cs.StateBlockstore(), + Actors: filcns.NewActorRegistry(), + Syscalls: sm.Syscalls, + CircSupplyCalc: sm.GetVMCirculatingSupply, + NetworkVersion: DefaultNetwork.Version(ctx, current.Height()), + BaseFee: current.Blocks()[0].ParentBaseFee, + }) + if err != nil { + return nil, fmt.Errorf("creating temporary vm: %w", err) + } + parentStateTree, err := state.LoadStateTree(cs.ActorStore(ctx), executed.ParentState()) + if err != nil { + return nil, fmt.Errorf("load state tree: %w", err) + } + span.AddEvent("loaded parent state tree") - parentStateTree, err := state.LoadStateTree(cs.ActorStore(ctx), executed.ParentState()) - if err != nil { - return nil, fmt.Errorf("load state tree: %w", err) - } - span.AddEvent("loaded parent state tree") + vmw := &vmWrapper{vm: vmi} + // Receipts are in same order as BlockMsgsForTipset + for _, em := range emsgs { + var r types.MessageReceipt + if found, err := rs.Get(em.Index, &r); err != nil { + return nil, err + } else if !found { + return nil, fmt.Errorf("failed to find receipt %d", em.Index) + } + em.Receipt = &r - vmw := &vmWrapper{vm: vmi} + burn, err := vmw.ShouldBurn(ctx, parentStateTree, em.Message, em.Receipt.ExitCode) + if err != nil { + return nil, fmt.Errorf("deciding whether should burn failed: %w", err) + } - // Receipts are in same order as BlockMsgsForTipset - for _, em := range emsgs { - var r types.MessageReceipt - if found, err := rs.Get(em.Index, &r); err != nil { - return nil, err - } else if !found { - return nil, fmt.Errorf("failed to find receipt %d", em.Index) + em.GasOutputs = vm.ComputeGasOutputs(em.Receipt.GasUsed, em.Message.GasLimit, em.BlockHeader.ParentBaseFee, em.Message.GasFeeCap, em.Message.GasPremium, burn) + span.AddEvent("computed executed message gas usage") } - em.Receipt = &r - - burn, err := vmw.ShouldBurn(ctx, parentStateTree, em.Message, em.Receipt.ExitCode) - if err != nil { - return nil, fmt.Errorf("deciding whether should burn failed: %w", err) + } else { + // Receipts are in same order as BlockMsgsForTipset + for _, em := range emsgs { + var r types.MessageReceipt + if found, err := rs.Get(em.Index, &r); err != nil { + return nil, err + } else if !found { + return nil, fmt.Errorf("failed to find receipt %d", em.Index) + } + em.Receipt = &r + // always burn after Network Verions 12 + shouldBurn := true + em.GasOutputs = vm.ComputeGasOutputs(em.Receipt.GasUsed, em.Message.GasLimit, em.BlockHeader.ParentBaseFee, em.Message.GasFeeCap, em.Message.GasPremium, shouldBurn) } - - em.GasOutputs = vm.ComputeGasOutputs(em.Receipt.GasUsed, em.Message.GasLimit, em.BlockHeader.ParentBaseFee, em.Message.GasFeeCap, em.Message.GasPremium, burn) + span.AddEvent("computed executed message gas usage") } - span.AddEvent("computed executed message gas usage") blkMsgs := make([]*lens.BlockMessages, len(current.Blocks())) for idx, blk := range current.Blocks() { @@ -286,7 +297,7 @@ func MethodAndParamsForMessage(m *types.Message, destCode cid.Cid) (string, stri return "", "", fmt.Errorf("unknown method for actor type %s: %d", destCode.String(), int64(m.Method)) } if err != nil { - log.Warnf("failed to parse parameters of message %s: %v", m.Cid, err) + log.Warnf("failed to parse parameters of message %s: %v", m.Cid().String(), err) // this can occur when the message is not valid cbor return method, "", err } diff --git a/model/actors/market/dealproposal.go b/model/actors/market/dealproposal.go index 237ac6c3b..704ca07c6 100644 --- a/model/actors/market/dealproposal.go +++ b/model/actors/market/dealproposal.go @@ -46,8 +46,12 @@ type MarketDealProposal struct { // Deal is with a verified provider. IsVerified bool `pg:",notnull,use_zero"` - // An arbitrary client chosen label to apply to the deal. + // An arbitrary client chosen label to apply to the deal. The value is base64 encoded before persisting. Label string + + // When true Label contains a valid UTF-8 string encoded in base64. When false Label contains raw bytes encoded in base64. + // Related to FIP: https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0027.md + IsString bool } func (dp *MarketDealProposal) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { diff --git a/schemas/v1/7_market_proposal_label.go b/schemas/v1/7_market_proposal_label.go new file mode 100644 index 000000000..009ca56c0 --- /dev/null +++ b/schemas/v1/7_market_proposal_label.go @@ -0,0 +1,13 @@ +package v1 + +func init() { + patches.Register( + 7, + ` +ALTER TABLE {{ .SchemaName | default "public"}}.market_deal_proposals +ADD COLUMN is_string BOOLEAN; + +COMMENT ON COLUMN {{ .SchemaName | default "public"}}.market_deal_proposals.is_string IS 'When true Label contains a valid UTF-8 string encoded in base64. When false Label contains raw bytes encoded in base64. Required by FIP: 27'; +`, + ) +} diff --git a/tasks/actorstate/market/context.go b/tasks/actorstate/market/context.go index cb2419914..58138b732 100644 --- a/tasks/actorstate/market/context.go +++ b/tasks/actorstate/market/context.go @@ -66,6 +66,9 @@ func (m *MarketStateExtractionContext) IsGenesis() bool { // - s is a valid utf8 string by removing any ill formed bytes. // - s does not contain any nil (\x00) bytes because postgres doesn't support storing NULL (\0x00) characters in text fields. func SanitizeLabel(s string) string { + if s == "" { + return s + } s = strings.Replace(s, "\000", "", -1) if utf8.ValidString(s) { return s diff --git a/tasks/actorstate/market/deal_proposal.go b/tasks/actorstate/market/deal_proposal.go index 1711786b5..a12ee870f 100644 --- a/tasks/actorstate/market/deal_proposal.go +++ b/tasks/actorstate/market/deal_proposal.go @@ -2,6 +2,7 @@ package market import ( "context" + "encoding/base64" "fmt" "github.com/filecoin-project/go-state-types/abi" @@ -34,55 +35,72 @@ func (DealProposalExtractor) Extract(ctx context.Context, a actorstate.ActorInfo return nil, err } - currDealProposals, err := ec.CurrState.Proposals() - if err != nil { - return nil, fmt.Errorf("loading current market deal proposals: %w", err) - } - + var dealProposals []market.ProposalIDState + // if this is genesis iterator actors current state. if ec.IsGenesis() { - var out marketmodel.MarketDealProposals + currDealProposals, err := ec.CurrState.Proposals() + if err != nil { + return nil, fmt.Errorf("loading current market deal proposals: %w", err) + } + if err := currDealProposals.ForEach(func(id abi.DealID, dp market.DealProposal) error { - out = append(out, &marketmodel.MarketDealProposal{ - Height: int64(ec.CurrTs.Height()), - DealID: uint64(id), - StateRoot: ec.CurrTs.ParentState().String(), - PaddedPieceSize: uint64(dp.PieceSize), - UnpaddedPieceSize: uint64(dp.PieceSize.Unpadded()), - StartEpoch: int64(dp.StartEpoch), - EndEpoch: int64(dp.EndEpoch), - ClientID: dp.Client.String(), - ProviderID: dp.Provider.String(), - ClientCollateral: dp.ClientCollateral.String(), - ProviderCollateral: dp.ProviderCollateral.String(), - StoragePricePerEpoch: dp.StoragePricePerEpoch.String(), - PieceCID: dp.PieceCID.String(), - IsVerified: dp.VerifiedDeal, - Label: SanitizeLabel(dp.Label), + dealProposals = append(dealProposals, market.ProposalIDState{ + ID: id, + Proposal: dp, }) return nil }); err != nil { - return nil, fmt.Errorf("walking current deal states: %w", err) + return nil, err + } + } else { + // else diff the actor against previous state and collect any additions that occurred. + changed, err := ec.CurrState.ProposalsChanged(ec.PrevState) + if err != nil { + return nil, fmt.Errorf("checking for deal proposal changes: %w", err) + } + if !changed { + return nil, nil } - return out, nil - } + changes, err := market.DiffDealProposals(ctx, ec.Store, ec.PrevState, ec.CurrState) + if err != nil { + return nil, fmt.Errorf("diffing deal proposals: %w", err) + } - changed, err := ec.CurrState.ProposalsChanged(ec.PrevState) - if err != nil { - return nil, fmt.Errorf("checking for deal proposal changes: %w", err) + for _, change := range changes.Added { + dealProposals = append(dealProposals, market.ProposalIDState{ + ID: change.ID, + Proposal: change.Proposal, + }) + } } - if !changed { - return nil, nil - } + out := make(marketmodel.MarketDealProposals, len(dealProposals)) + for idx, add := range dealProposals { + var isString bool + var base64Label string + if add.Proposal.Label.IsString() { + labelString, err := add.Proposal.Label.ToString() + if err != nil { + return nil, fmt.Errorf("deal proposal (ID: %d) label is not a string despite claiming it is (developer error?)", add.ID) + } - changes, err := market.DiffDealProposals(ctx, ec.Store, ec.PrevState, ec.CurrState) - if err != nil { - return nil, fmt.Errorf("diffing deal states: %w", err) - } + isString = true + base64Label = base64.StdEncoding.EncodeToString([]byte(SanitizeLabel(labelString))) + + } else if add.Proposal.Label.IsBytes() { + labelBytes, err := add.Proposal.Label.ToBytes() + if err != nil { + return nil, fmt.Errorf("deal proposal (ID: %d) label is not bytes despit claiming it is (developer error?)", add.ID) + } - out := make(marketmodel.MarketDealProposals, len(changes.Added)) - for idx, add := range changes.Added { + isString = false + base64Label = base64.StdEncoding.EncodeToString(labelBytes) + + } else { + // TODO this should never happen, but if it does it indicates a logic. + return nil, fmt.Errorf("deal proposal (ID: %d) label is neither bytes nor string (DEVELOPER ERROR)", add.ID) + } out[idx] = &marketmodel.MarketDealProposal{ Height: int64(ec.CurrTs.Height()), DealID: uint64(add.ID), @@ -98,7 +116,8 @@ func (DealProposalExtractor) Extract(ctx context.Context, a actorstate.ActorInfo StoragePricePerEpoch: add.Proposal.StoragePricePerEpoch.String(), PieceCID: add.Proposal.PieceCID.String(), IsVerified: add.Proposal.VerifiedDeal, - Label: SanitizeLabel(add.Proposal.Label), + Label: base64Label, + IsString: isString, } } return out, nil diff --git a/tasks/actorstate/miner/context.go b/tasks/actorstate/miner/context.go index 99bfbfc2f..f1895571d 100644 --- a/tasks/actorstate/miner/context.go +++ b/tasks/actorstate/miner/context.go @@ -21,39 +21,35 @@ func NewMinerStateExtractionContext(ctx context.Context, a actorstate.ActorInfo, return nil, fmt.Errorf("loading current miner state: %w", err) } - prevTipset := a.Current - prevState := curState - if a.Current.Height() != 1 { - prevTipset = a.Executed - - prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key()) - if err != nil { - // if the actor exists in the current state and not in the parent state then the - // actor was created in the current state. - if err == types.ErrActorNotFound { - return &MinerStateExtractionContext{ - PrevState: prevState, - PrevTs: prevTipset, - CurrActor: &a.Actor, - CurrState: curState, - CurrTs: a.Current, - }, nil - } - return nil, fmt.Errorf("loading previous miner %s at tipset %s epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err) + prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key()) + if err != nil { + // actor doesn't exist yet, may have just been created. + if err == types.ErrActorNotFound { + return &MinerStateExtractionContext{ + PrevTs: a.Executed, + CurrActor: &a.Actor, + CurrState: curState, + CurrTs: a.Current, + PrevState: nil, + PreviousStatePresent: false, + }, nil } + return nil, fmt.Errorf("loading previous miner %s at tipset %s epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err) + } - prevState, err = node.MinerLoad(node.Store(), prevActor) - if err != nil { - return nil, fmt.Errorf("loading previous miner actor state: %w", err) - } + // actor exists in previous state, load it. + prevState, err := node.MinerLoad(node.Store(), prevActor) + if err != nil { + return nil, fmt.Errorf("loading previous miner actor state: %w", err) } return &MinerStateExtractionContext{ - PrevState: prevState, - PrevTs: prevTipset, - CurrActor: &a.Actor, - CurrState: curState, - CurrTs: a.Current, + PrevState: prevState, + PrevTs: a.Executed, + CurrActor: &a.Actor, + CurrState: curState, + CurrTs: a.Current, + PreviousStatePresent: true, }, nil } @@ -61,11 +57,12 @@ type MinerStateExtractionContext struct { PrevState miner.State PrevTs *types.TipSet - CurrActor *types.Actor - CurrState miner.State - CurrTs *types.TipSet + CurrActor *types.Actor + CurrState miner.State + CurrTs *types.TipSet + PreviousStatePresent bool } func (m *MinerStateExtractionContext) HasPreviousState() bool { - return !(m.CurrTs.Height() == 1 || m.PrevState == m.CurrState) + return m.PreviousStatePresent } diff --git a/tasks/actorstate/miner/deadline_info.go b/tasks/actorstate/miner/deadline_info.go index e3b13cee7..76f884d0f 100644 --- a/tasks/actorstate/miner/deadline_info.go +++ b/tasks/actorstate/miner/deadline_info.go @@ -36,11 +36,17 @@ func (DeadlineInfoExtractor) Extract(ctx context.Context, a actorstate.ActorInfo if err != nil { return nil, err } - if prevDeadlineInfo == currDeadlineInfo { + // TODO implement equality function + // dereference pointers to check equality + // if these are different then return a model in the bottom of function + if prevDeadlineInfo != nil && + currDeadlineInfo != nil && + *prevDeadlineInfo == *currDeadlineInfo { return nil, nil } } + // if there is no previous state and the deadlines have changed, return a model return &minermodel.MinerCurrentDeadlineInfo{ Height: int64(ec.CurrTs.Height()), MinerID: a.Address.String(), diff --git a/tasks/actorstate/miner/fee_debt.go b/tasks/actorstate/miner/fee_debt.go index a6c0bcdd4..0a7c9a25f 100644 --- a/tasks/actorstate/miner/fee_debt.go +++ b/tasks/actorstate/miner/fee_debt.go @@ -36,7 +36,7 @@ func (FeeDebtExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, nod if err != nil { return nil, fmt.Errorf("loading previous miner fee debt: %w", err) } - if prevDebt == currDebt { + if prevDebt.Equals(currDebt) { return nil, nil } } diff --git a/tasks/actorstate/miner/info.go b/tasks/actorstate/miner/info.go index eb07fe834..a04edcec8 100644 --- a/tasks/actorstate/miner/info.go +++ b/tasks/actorstate/miner/info.go @@ -6,6 +6,7 @@ import ( "github.com/filecoin-project/go-address" logging "github.com/ipfs/go-log/v2" + "github.com/libp2p/go-libp2p-core/peer" maddr "github.com/multiformats/go-multiaddr" "go.opentelemetry.io/otel" "go.uber.org/zap" @@ -46,8 +47,12 @@ func (InfoExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, node a } var newWorker string - if newInfo.NewWorker != address.Undef { - newWorker = newInfo.NewWorker.String() + var newWorkerEpoch int64 + if pendingWorkerKey := newInfo.PendingWorkerKey; pendingWorkerKey != nil { + if pendingWorkerKey.NewWorker != address.Undef { + newWorker = pendingWorkerKey.NewWorker.String() + } + newWorkerEpoch = int64(pendingWorkerKey.EffectiveAt) } var newCtrlAddresses []string @@ -72,7 +77,7 @@ func (InfoExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, node a OwnerID: newInfo.Owner.String(), WorkerID: newInfo.Worker.String(), NewWorker: newWorker, - WorkerChangeEpoch: int64(newInfo.WorkerChangeEpoch), + WorkerChangeEpoch: newWorkerEpoch, ConsensusFaultedElapsed: int64(newInfo.ConsensusFaultElapsed), ControlAddresses: newCtrlAddresses, MultiAddresses: newMultiAddrs, @@ -80,7 +85,12 @@ func (InfoExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, node a } if newInfo.PeerId != nil { - mi.PeerID = newInfo.PeerId.String() + newPeerID, err := peer.IDFromBytes(newInfo.PeerId) + if err != nil { + log.Warnw("failed to decode miner peerID", "miner", a.Address, "head", a.Actor.Head.String(), "error", err) + } else { + mi.PeerID = newPeerID.String() + } } return mi, nil diff --git a/tasks/actorstate/miner/locked_funds.go b/tasks/actorstate/miner/locked_funds.go index 750a01bc9..0e3c4d0f8 100644 --- a/tasks/actorstate/miner/locked_funds.go +++ b/tasks/actorstate/miner/locked_funds.go @@ -36,7 +36,11 @@ func (LockedFundsExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, if err != nil { return nil, fmt.Errorf("loading previous miner locked funds: %w", err) } - if prevLocked == currLocked { + + // if all values are equal there is no change. + if prevLocked.VestingFunds.Equals(currLocked.VestingFunds) && + prevLocked.PreCommitDeposits.Equals(currLocked.PreCommitDeposits) && + prevLocked.InitialPledgeRequirement.Equals(currLocked.InitialPledgeRequirement) { return nil, nil } } diff --git a/tasks/actorstate/miner/post.go b/tasks/actorstate/miner/post.go index 8b650fa85..711533e25 100644 --- a/tasks/actorstate/miner/post.go +++ b/tasks/actorstate/miner/post.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" "go.opentelemetry.io/otel" "go.uber.org/zap" @@ -64,7 +65,7 @@ func (PoStExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, node a if msg.Receipt == nil || msg.Receipt.ExitCode.IsError() { return nil } - params := miner.SubmitWindowedPoStParams{} + params := minertypes.SubmitWindowedPoStParams{} if err := params.UnmarshalCBOR(bytes.NewBuffer(msg.Message.Params)); err != nil { return fmt.Errorf("unmarshal post params: %w", err) } diff --git a/tasks/actorstate/miner/precommit.go b/tasks/actorstate/miner/precommit.go index 65c26a143..9aa18028c 100644 --- a/tasks/actorstate/miner/precommit.go +++ b/tasks/actorstate/miner/precommit.go @@ -4,10 +4,10 @@ import ( "context" "fmt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" "go.opentelemetry.io/otel" "go.uber.org/zap" - "github.com/filecoin-project/lily/chain/actors/builtin/miner" "github.com/filecoin-project/lily/model" minermodel "github.com/filecoin-project/lily/model/actors/miner" "github.com/filecoin-project/lily/tasks/actorstate" @@ -28,9 +28,9 @@ func (PreCommitInfoExtractor) Extract(ctx context.Context, a actorstate.ActorInf return nil, fmt.Errorf("creating miner state extraction context: %w", err) } - var preCommits []miner.SectorPreCommitOnChainInfo + var preCommits []minertypes.SectorPreCommitOnChainInfo if !ec.HasPreviousState() { - if err := ec.CurrState.ForEachPrecommittedSector(func(info miner.SectorPreCommitOnChainInfo) error { + if err := ec.CurrState.ForEachPrecommittedSector(func(info minertypes.SectorPreCommitOnChainInfo) error { preCommits = append(preCommits, info) return nil }); err != nil { diff --git a/tasks/actorstate/miner/sector_events.go b/tasks/actorstate/miner/sector_events.go index 0b2d38e49..77c4b74d4 100644 --- a/tasks/actorstate/miner/sector_events.go +++ b/tasks/actorstate/miner/sector_events.go @@ -6,6 +6,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" "go.opentelemetry.io/otel" "go.uber.org/zap" @@ -47,7 +48,7 @@ func (SectorEventsExtractor) Extract(ctx context.Context, a actorstate.ActorInfo } preCommitChanges = miner.MakePreCommitChanges() - if err = extState.CurrentState().ForEachPrecommittedSector(func(info miner.SectorPreCommitOnChainInfo) error { + if err = extState.CurrentState().ForEachPrecommittedSector(func(info minertypes.SectorPreCommitOnChainInfo) error { preCommitChanges.Added = append(preCommitChanges.Added, info) return nil }); err != nil { diff --git a/tasks/actorstate/miner/sector_events_test.go b/tasks/actorstate/miner/sector_events_test.go index d1af5d33b..f2940dd30 100644 --- a/tasks/actorstate/miner/sector_events_test.go +++ b/tasks/actorstate/miner/sector_events_test.go @@ -8,6 +8,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/ipfs/go-cid" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -421,8 +422,8 @@ func generateFakeSectorOnChainInfos(sectors map[uint64][]abi.DealID) []miner.Sec return out } -func generateFakeSectorPreCommitInfo(sectorNumber uint64) miner.SectorPreCommitInfo { - return miner.SectorPreCommitInfo{ +func generateFakeSectorPreCommitInfo(sectorNumber uint64) minertypes.SectorPreCommitInfo { + return minertypes.SectorPreCommitInfo{ SealProof: 0, SectorNumber: abi.SectorNumber(sectorNumber), SealedCID: cid.Undef, @@ -436,8 +437,8 @@ func generateFakeSectorPreCommitInfo(sectorNumber uint64) miner.SectorPreCommitI } } -func generateFakeSectorPreCommitOnChainInfo(sectorNumber uint64) miner.SectorPreCommitOnChainInfo { - return miner.SectorPreCommitOnChainInfo{ +func generateFakeSectorPreCommitOnChainInfo(sectorNumber uint64) minertypes.SectorPreCommitOnChainInfo { + return minertypes.SectorPreCommitOnChainInfo{ Info: generateFakeSectorPreCommitInfo(sectorNumber), PreCommitDeposit: abi.NewTokenAmount(0), PreCommitEpoch: 0, @@ -447,8 +448,8 @@ func generateFakeSectorPreCommitOnChainInfo(sectorNumber uint64) miner.SectorPre } func generateFakeSectorPreCommitChanges(add uint64, rm uint64) *miner.PreCommitChanges { - added := make([]miner.SectorPreCommitOnChainInfo, add) - removed := make([]miner.SectorPreCommitOnChainInfo, rm) + added := make([]minertypes.SectorPreCommitOnChainInfo, add) + removed := make([]minertypes.SectorPreCommitOnChainInfo, rm) for i := uint64(0); i < add; i++ { added[i] = generateFakeSectorPreCommitOnChainInfo(i) } diff --git a/tasks/actorstate/multisig/multisig.go b/tasks/actorstate/multisig/multisig.go index 54e5ff365..a739bcb65 100644 --- a/tasks/actorstate/multisig/multisig.go +++ b/tasks/actorstate/multisig/multisig.go @@ -119,11 +119,12 @@ type MsigExtractionContext struct { CurrState multisig.State CurrTs *types.TipSet - Store adt.Store + Store adt.Store + PreviousStatePresent bool } func (m *MsigExtractionContext) HasPreviousState() bool { - return !(m.CurrTs.Height() == 1 || m.CurrState == m.PrevState) + return m.PreviousStatePresent } func NewMultiSigExtractionContext(ctx context.Context, a actorstate.ActorInfo, node actorstate.ActorStateAPI) (*MsigExtractionContext, error) { @@ -132,35 +133,34 @@ func NewMultiSigExtractionContext(ctx context.Context, a actorstate.ActorInfo, n return nil, fmt.Errorf("loading current multisig state at head %s: %w", a.Actor.Head, err) } - prevState := curState - if a.Current.Height() != 1 { - prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key()) - if err != nil { - // if the actor exists in the current state and not in the parent state then the - // actor was created in the current state. - if err == types.ErrActorNotFound { - return &MsigExtractionContext{ - PrevState: prevState, - CurrActor: &a.Actor, - CurrState: curState, - CurrTs: a.Current, - Store: node.Store(), - }, nil - } - return nil, fmt.Errorf("loading previous multisig %s at tipset %s epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err) + prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key()) + if err != nil { + // actor doesn't exist yet, may have just been created. + if err == types.ErrActorNotFound { + return &MsigExtractionContext{ + CurrActor: &a.Actor, + CurrState: curState, + CurrTs: a.Current, + Store: node.Store(), + PrevState: nil, + PreviousStatePresent: false, + }, nil } + return nil, fmt.Errorf("loading previous multisig %s from parent tipset %s current epoch %d: %w", a.Address, a.Executed.Key(), a.Current.Height(), err) + } - prevState, err = multisig.Load(node.Store(), prevActor) - if err != nil { - return nil, fmt.Errorf("loading previous multisig actor state: %w", err) - } + // actor exists in previous state, load it. + prevState, err := multisig.Load(node.Store(), prevActor) + if err != nil { + return nil, fmt.Errorf("loading previous multisig actor state: %w", err) } return &MsigExtractionContext{ - PrevState: prevState, - CurrActor: &a.Actor, - CurrState: curState, - CurrTs: a.Current, - Store: node.Store(), + PrevState: prevState, + CurrActor: &a.Actor, + CurrState: curState, + CurrTs: a.Current, + Store: node.Store(), + PreviousStatePresent: true, }, nil } diff --git a/tasks/actorstate/power/power.go b/tasks/actorstate/power/power.go index 899948cb4..40ead37de 100644 --- a/tasks/actorstate/power/power.go +++ b/tasks/actorstate/power/power.go @@ -25,33 +25,32 @@ func NewPowerStateExtractionContext(ctx context.Context, a actorstate.ActorInfo, return nil, fmt.Errorf("loading current power state: %w", err) } - prevState := curState - if a.Current.Height() != 1 { - prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key()) - if err != nil { - // if the actor exists in the current state and not in the parent state then the - // actor was created in the current state. - if err == types.ErrActorNotFound { - return &PowerStateExtractionContext{ - PrevState: prevState, - CurrState: curState, - CurrTs: a.Current, - Store: node.Store(), - }, nil - } - return nil, fmt.Errorf("loading previous power actor at tipset %s epoch %d: %w", a.Executed.Key(), a.Current.Height(), err) + prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key()) + if err != nil { + // actor doesn't exist yet, may have just been created. + if err == types.ErrActorNotFound { + return &PowerStateExtractionContext{ + CurrState: curState, + CurrTs: a.Current, + Store: node.Store(), + PrevState: nil, + PreviousStatePresent: false, + }, nil } + return nil, fmt.Errorf("loading previous power actor from parent tipset %s current epoch %d: %w", a.Executed.Key(), a.Current.Height(), err) + } - prevState, err = power.Load(node.Store(), prevActor) - if err != nil { - return nil, fmt.Errorf("loading previous power actor state: %w", err) - } + // actor exists in previous state, load it. + prevState, err := power.Load(node.Store(), prevActor) + if err != nil { + return nil, fmt.Errorf("loading previous power actor state: %w", err) } return &PowerStateExtractionContext{ - PrevState: prevState, - CurrState: curState, - CurrTs: a.Current, - Store: node.Store(), + PrevState: prevState, + CurrState: curState, + CurrTs: a.Current, + Store: node.Store(), + PreviousStatePresent: true, }, nil } @@ -60,11 +59,12 @@ type PowerStateExtractionContext struct { CurrState power.State CurrTs *types.TipSet - Store adt.Store + Store adt.Store + PreviousStatePresent bool } func (p *PowerStateExtractionContext) HasPreviousState() bool { - return !(p.CurrTs.Height() == 1 || p.PrevState == p.CurrState) + return p.PreviousStatePresent } func (StoragePowerExtractor) Extract(ctx context.Context, a actorstate.ActorInfo, node actorstate.ActorStateAPI) (model.Persistable, error) { diff --git a/tasks/actorstate/verifreg/verifreg.go b/tasks/actorstate/verifreg/verifreg.go index d381841cd..e16dd7f8c 100644 --- a/tasks/actorstate/verifreg/verifreg.go +++ b/tasks/actorstate/verifreg/verifreg.go @@ -20,11 +20,12 @@ type VerifiedRegistryExtractionContext struct { PrevState, CurrState verifreg.State PrevTs, CurrTs *types.TipSet - Store adt.Store + Store adt.Store + PreviousStatePresent bool } func (v *VerifiedRegistryExtractionContext) HasPreviousState() bool { - return !(v.CurrTs.Height() == 1 || v.PrevState == v.CurrState) + return v.PreviousStatePresent } func NewVerifiedRegistryExtractorContext(ctx context.Context, a actorstate.ActorInfo, node actorstate.ActorStateAPI) (*VerifiedRegistryExtractionContext, error) { @@ -33,35 +34,34 @@ func NewVerifiedRegistryExtractorContext(ctx context.Context, a actorstate.Actor return nil, fmt.Errorf("loading current verified registry state: %w", err) } - prevState := curState - if a.Current.Height() != 0 { - prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key()) - if err != nil { - // if the actor exists in the current state and not in the parent state then the - // actor was created in the current state. - if err == types.ErrActorNotFound { - return &VerifiedRegistryExtractionContext{ - PrevState: prevState, - CurrState: curState, - PrevTs: a.Executed, - CurrTs: a.Current, - Store: node.Store(), - }, nil - } - return nil, fmt.Errorf("loading previous verified registry actor at tipset %s epoch %d: %w", a.Executed.Key(), a.Current.Height(), err) + prevActor, err := node.Actor(ctx, a.Address, a.Executed.Key()) + if err != nil { + // actor doesn't exist yet, may have just been created. + if err == types.ErrActorNotFound { + return &VerifiedRegistryExtractionContext{ + CurrState: curState, + PrevTs: a.Executed, + CurrTs: a.Current, + Store: node.Store(), + PrevState: nil, + PreviousStatePresent: false, + }, nil } + return nil, fmt.Errorf("loading previous verified registry actor from parent tipset %s current height epoch %d: %w", a.Executed.Key(), a.Current.Height(), err) + } - prevState, err = verifreg.Load(node.Store(), prevActor) - if err != nil { - return nil, fmt.Errorf("loading previous verified registry state: %w", err) - } + // actor exists in previous state, load it. + prevState, err := verifreg.Load(node.Store(), prevActor) + if err != nil { + return nil, fmt.Errorf("loading previous verified registry state: %w", err) } return &VerifiedRegistryExtractionContext{ - PrevState: prevState, - CurrState: curState, - PrevTs: a.Executed, - CurrTs: a.Current, - Store: node.Store(), + PrevState: prevState, + CurrState: curState, + PrevTs: a.Executed, + CurrTs: a.Current, + Store: node.Store(), + PreviousStatePresent: true, }, nil } diff --git a/tasks/messages/message_test.go b/tasks/messages/message_test.go index 07a17a5e6..436af4c2e 100644 --- a/tasks/messages/message_test.go +++ b/tasks/messages/message_test.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/big" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/go-state-types/cbor" "github.com/filecoin-project/go-state-types/crypto" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" @@ -19,8 +20,6 @@ import ( paych6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/paych" "github.com/filecoin-project/lily/chain/actors/builtin" - "github.com/filecoin-project/lily/chain/actors/builtin/market" - miner "github.com/filecoin-project/lily/chain/actors/builtin/miner" "github.com/filecoin-project/lily/lens/util" "github.com/filecoin-project/go-address" @@ -151,10 +150,10 @@ func TestParseMessageParams(t *testing.T) { name: "issue-741", method: 4, actorCode: builtin3.StorageMarketActorCodeID, - params: mustMarshalCbor(t, &market.PublishStorageDealsParams{ - Deals: []market.ClientDealProposal{ + params: mustMarshalCbor(t, &market0.PublishStorageDealsParams{ + Deals: []market0.ClientDealProposal{ { - Proposal: market0.DealProposal(market.DealProposal{ + Proposal: market0.DealProposal{ PieceCID: mustDecodeCID(t, "baga6ea4seaqgqzxo27ongakwwef5x3cihl6fgritvgeq5akvjqij6lpgofsogiq"), PieceSize: 1310720, VerifiedDeal: false, @@ -166,7 +165,7 @@ func TestParseMessageParams(t *testing.T) { StoragePricePerEpoch: abi.NewTokenAmount(61035), ProviderCollateral: abi.NewTokenAmount(0), ClientCollateral: abi.NewTokenAmount(0), - }), + }, ClientSignature: crypto.Signature{ Type: 1, Data: mustDecodeBase64(t, "9a8sdvutVlu0fizD0JmqZjKJaQLj3W3ZtJ2yTReIry8kZ8cDa33V3Pe0sdZzSjz9mRdM/KPm1jL/PZhqpDeYNwE="), @@ -186,9 +185,9 @@ func TestParseMessageParams(t *testing.T) { name: "SubmitWindowedPost", method: 5, actorCode: builtin3.StorageMinerActorCodeID, - params: mustMarshalCbor(t, &miner.SubmitWindowedPoStParams{ + params: mustMarshalCbor(t, &minertypes.SubmitWindowedPoStParams{ Deadline: 38, - Partitions: []miner.PoStPartition{ + Partitions: []minertypes.PoStPartition{ { Index: 0, Skipped: bitfield.BitField{}, @@ -213,7 +212,7 @@ func TestParseMessageParams(t *testing.T) { name: "ProveCommitSector", method: 7, actorCode: builtin3.StorageMinerActorCodeID, - params: mustMarshalCbor(t, &miner.ProveCommitSectorParams{ + params: mustMarshalCbor(t, &minertypes.ProveCommitSectorParams{ SectorNumber: 299696, Proof: mustDecodeBase64(t, "qQivfx+qvAuqHK0rjSgJp3X2lXhojZQ8bID1YfxkY2bWFZC7grR/uoTi7ABpl8/JpLoi+nLVysf3nTDjvL5gwn0MabsuhPohs2A2jh7CVJ2uxsJqb+VB2ddt9e9lNhDSCnESHbfULN+kAAi4Entznpg6Mt2yza7WB4W3kWsd9tMaUHtDBkgljqp5r1383PohhOq61f3zZqVzgVKXrhCCiLhgnE+VnJOLT75Yp6kwk43htZ4hjfhYBnyhLH02f3EcpXZqbgbyVkzZz9Tar9VZaQgjVA0gQHfbcAr+3KkBzF5RVR4y9nCFEm8LwZBh1MVfoREN+8GvO/+b+QAlGWtAl3qSPqVrv2jrOi6ZQiRsh9JfnK2G5BqRzZIAqsHVwC7CAoWBpO0k4J69rrSI7cJKvMBLpi2hAoKW7vPfqNnYlIhkBLpTdRPlqBNwLnCJNOJkqTt3jV2Yk2129d42w0ub6iqmcVJ0mZgoEm613i0GFyReCKYUuxBo92rtAMtvvm+gpvpxMoouay8Q+zx6rGFLppDxTWV4qacFY20MU+HiBsrOT1LsK7W3kuzsMmmX8qiTtENDwxGNXEHzH0TBpgHcBxaapoT67+2uNBxzvxp2Qz0mpaVG7zc+NWU2NrgwWZjwAog82PQ9hG8JsCgNyEQ0TDmZkW3jC3lw24MeP1L0iE7asIEaFFoxuLLhPX4IkTcFuCoUjmIX4+r+4UwGAdjN+uVN699B+zTWBO6VBlQfcQGNt8O64MfWA2GGDz2ZxD1glIaTs84kMbJWYhvNTUB0DKurVFwd0XRUglwaqmot93bdJaDx8T+ckdZIjcf5g2m6hqHWoojB4BB/ChcdwIeSayS8ZkXZVL1zutS0IQUqJmSxXKMBPNRwJDLs/fXsG43cCNphNGlQwCUcQR83/zeJJwDsLL9TP/HhZv/9Jz+qE/Jy4SDFt86Xe4NHTzhW1UX6gHCynnwxnPX+c+K7gKjMAy3VHiDs0UvXthK3MykfhopE/yZ+A/srFR5nHvIcNOrUpotXHJ0i/FyQMpI0dcx+/fZJN9muAj/B5Rz5W8gu09/sZtnCSkY7zUp5vVf3xwImjCsKcPjHqWSXcKOmgxfasVsjnh6svMAfOxIoYUUBGqEl9gGoqrZLbAvrqxjwnsvYEFStEsy2xKcfFo3ePf0Y25AtuopmSS05x0Koruriqm5jiMzD4XuW5wlq1vhzvwdjgLXI+9DuuVZzFumliQ4ji1dEK+S3CjCR3vdB9DLyEAfx3JYXm2WmrYS/7tNL6zr1hwkxLxNNF1C6nZS1auqDy+7s0EO76kog40M6OjU36PI5es4AgQz8SOg7JsVSUOAAsR/KcJTiYCOuu40HegtuHjZmd6QHORKCVozBb2aN4Fw4o0mp7oAOXDktXhigoo20AFZQqkRF6q2vdVGuuvA3KQFLCMno7jOIJq6c1WJvzpUTqwW21vzFjIsEaf8qsZn8sLZT4X5RefmjYkNeAqhLpj2JVzssinHmJFOkf27zncA1sDIYbtpyItbin3Vsf2Czt07aNVlHc2y5OW+v971vXDaYYK6EVE5oPsMglzMBuOd7/T33ivpN8P8/8STRpwsjhKzx4ncTY49Xiyb94dQ/9Q6FMJL1evAr4j/Wk890SehB3ZAU6SezFwCc5rNw6SbyBzyoU9lNSB08EPKU1yQs7hVvJpIKgPDzsYFeC/ih3EMFzXCQ4HP2hRNunZQ6TO6sgFQbjkngn+OsjvTnYNdFe9QvL3FX4J/GKz0+jpg6v6d3UGi0lwaysoA8UaBBWL8gpkaN3FSCgHrnXl1WwmYLcy5retuuaYGiKzuV4/LKdbCzkgGTVgBFgLK+ezGfwGkwt/kijeNzusq9jLGFtdwSlAoNJBSBYKxXSt90eNIaykWubPH8kNyMt3riE3G+BMj2GT4w255uu9/XrgrlY9cNxEkWIMfQKgb8EXs9V6JzynrSP9lMmyEvGn6omCGuHOP9sXybEHes1NsXaypo9vUCa/sP31i8l2Fo6ZWqevFXSm6YFr8mgNDpag8DnyOMruN4lEk+1/2ZaP9TUPTyAoUzy/2VRQtqV2fmD0641o9SC3BHnpeWhtKZA5tWECKxhJqqsR2Y0gExlsjk7wcD2yoMG8jKIPbyhHo0DozNQyfS1stV0++AefkycOBvZFzrHjtqGNSuolwIUxvwoBnbZxIm1HTL100JGXFsgAapfJrv3K2dklRvWtBGpOg0tn/A4+LMroq/ye2qmvO56WV8DGq7Hxs5vql50OBRS95niIPth0I9zh4KZ9m2qDvjU0JPWfyag+0giQEp4RF+GUzaAG4aVPQ+EouDs32itpF7glJ2hIx5kUquehUTVsShWDevtzD+lCdRuMykpr9kQM+/6JHsnhP3Vb1LXU8RpLvD76xwhDax6xkXD33qrWYQKSa4WDfQAIJLpP7JLKt4sUrWEGfnU2v5sYQRVfCoKNTD8J67DB4oEBSnoyPNIlk7M2lCGAsekPRFBke56rwbMH6Iw3HG0GQ4qU0xLJAOmiFu3d8qmN73232UcIHb+dvsQF0uVSgu"), }), @@ -226,8 +225,8 @@ func TestParseMessageParams(t *testing.T) { name: "DeclareFaultsRecovered", method: 11, actorCode: builtin5.StorageMinerActorCodeID, - params: mustMarshalCbor(t, &miner.DeclareFaultsRecoveredParams{ - Recoveries: []miner.RecoveryDeclaration{ + params: mustMarshalCbor(t, &minertypes.DeclareFaultsRecoveredParams{ + Recoveries: []minertypes.RecoveryDeclaration{ { Deadline: 1, Partition: 1, diff --git a/tasks/messages/parsedmessage/task.go b/tasks/messages/parsedmessage/task.go index 580059329..d462305aa 100644 --- a/tasks/messages/parsedmessage/task.go +++ b/tasks/messages/parsedmessage/task.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" + logging "github.com/ipfs/go-log/v2" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" @@ -18,6 +19,8 @@ import ( "github.com/filecoin-project/lily/tasks/messages" ) +var log = logging.Logger("lily/tasks/parsedmsg") + type Task struct { node tasks.DataSource } @@ -94,9 +97,14 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut } parsedMessageResults = append(parsedMessageResults, pm) } else { - if m.Receipt.ExitCode == exitcode.ErrSerialization || m.Receipt.ExitCode == exitcode.ErrIllegalArgument || m.Receipt.ExitCode == exitcode.SysErrInvalidMethod { + if m.Receipt.ExitCode == exitcode.ErrSerialization || + m.Receipt.ExitCode == exitcode.ErrIllegalArgument || + m.Receipt.ExitCode == exitcode.SysErrInvalidMethod || + // UsrErrUnsupportedMethod TODO: https://github.com/filecoin-project/go-state-types/pull/44 + m.Receipt.ExitCode == exitcode.ExitCode(22) { // ignore the parse error since the params are probably malformed, as reported by the vm } else { + log.Errorw("parsing message", "error", err, "cid", m.Message.Cid().String(), "receipt", m.Receipt) errorsDetected = append(errorsDetected, &messages.MessageError{ Cid: m.Cid, Error: fmt.Errorf("failed to parse message params: %w", err).Error(), @@ -110,6 +118,7 @@ func (t *Task) ProcessTipSets(ctx context.Context, current *types.TipSet, execut // If the message was executed it means we are out of step with Lotus behaviour somehow. This probably // indicates that Lily actor type detection is out of date. if m.Receipt.ExitCode == 0 { + log.Errorw("parsing message", "error", err, "cid", m.Message.Cid().String(), "receipt", m.Receipt) errorsDetected = append(errorsDetected, &messages.MessageError{ Cid: m.Cid, Error: fmt.Errorf("failed to parse message params: missing to actor code").Error(),