diff --git a/.circleci/config.yml b/.circleci/config.yml index c218331ee..c2ce75f9c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -83,7 +83,6 @@ commands: name: fetch all tags command: | git fetch --all - packer_build: description: "Run a packer build" parameters: @@ -197,6 +196,7 @@ jobs: environment: TEST_RUSTPROOFS_LOGS: << parameters.proofs-log-test >> SKIP_CONFORMANCE: "1" + LOTUS_SRC_DIR: /home/circleci/project command: | mkdir -p /tmp/test-reports/<< parameters.suite >> mkdir -p /tmp/test-artifacts @@ -223,7 +223,7 @@ jobs: test-conformance: description: | - Run tests using a corpus of interoperable test vectors for Filecoin + Run tests using a corpus of interoperable test vectors for Filecoin implementations to test their correctness and compliance with the Filecoin specifications. parameters: @@ -803,6 +803,11 @@ workflows: suite: itest-deals_concurrent target: "./itests/deals_concurrent_test.go" + - test: + name: test-itest-deals_invalid_utf8_label + suite: itest-deals_invalid_utf8_label + target: "./itests/deals_invalid_utf8_label_test.go" + - test: name: test-itest-deals_max_staging_deals suite: itest-deals_max_staging_deals @@ -863,6 +868,11 @@ workflows: suite: itest-get_messages_in_ts target: "./itests/get_messages_in_ts_test.go" + - test: + name: test-itest-lite_migration + suite: itest-lite_migration + target: "./itests/lite_migration_test.go" + - test: name: test-itest-lookup_robust_address suite: itest-lookup_robust_address diff --git a/.circleci/template.yml b/.circleci/template.yml index 233771988..437eec9d3 100644 --- a/.circleci/template.yml +++ b/.circleci/template.yml @@ -83,7 +83,6 @@ commands: name: fetch all tags command: | git fetch --all - packer_build: description: "Run a packer build" parameters: @@ -197,6 +196,7 @@ jobs: environment: TEST_RUSTPROOFS_LOGS: << parameters.proofs-log-test >> SKIP_CONFORMANCE: "1" + LOTUS_SRC_DIR: /home/circleci/project command: | mkdir -p /tmp/test-reports/<< parameters.suite >> mkdir -p /tmp/test-artifacts @@ -223,7 +223,7 @@ jobs: test-conformance: description: | - Run tests using a corpus of interoperable test vectors for Filecoin + Run tests using a corpus of interoperable test vectors for Filecoin implementations to test their correctness and compliance with the Filecoin specifications. parameters: diff --git a/.gitignore b/.gitignore index a6fab7331..1db5e2858 100644 --- a/.gitignore +++ b/.gitignore @@ -41,7 +41,6 @@ build/paramfetch.sh /darwin /linux *.snap -build/builtin-actors *-fuzz.zip /chain/types/work_msg/ @@ -49,3 +48,6 @@ bin/ipget bin/tmp/* .idea scratchpad + +build/builtin-actors/v* +build/builtin-actors/*.car diff --git a/CHANGELOG.md b/CHANGELOG.md index 90448bbeb..7225afd86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,113 @@ # Lotus changelog +# 1.16.0 / 2022-06-24 + + +This is a MANDATORY release of Lotus that introduces [Filecoin network v16, +codenamed the Skyr upgrade](https://github.com/filecoin-project/community/discussions/74?sort=new#discussioncomment-2392151). + +The network is scheduled to upgrade to nv16 at epoch 1960320, on July 6th at 2022-07-06T14:00:00Z. All node operators, including storage providers, must upgrade to this release (or a later release) before that time. Storage providers must update their daemons, miners, market and worker(s). + +Your lotus node will switch from the Legacy VM (that depended on go-based specs-actors) to Filecoin Virtual Machine FVM (that uses Rust-based builtin-actors) atomically upon the upgrade. + +The Skyr upgrade introduces the following FIPs, enhancements and bug fixes, delivered in [built-actors v8](https://github.com/filecoin-project/builtin-actors/releases/tag/v8.0.0) and [ref-fvm v1.0.0](https://github.com/filecoin-project/ref-fvm/releases/tag/fvm%40v1.0.0):, + +- [FIP-0030](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0030.md) +- [FIP-0031](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0031.md) +- [FIP-0032](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0032.md)) +- [FIP-0027](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0027.md) +- [Bug fix for the ProveReplicaUpdates method](https://github.com/filecoin-project/builtin-actors/pull/138) +- [New proofs version for SnarkPack](https://github.com/filecoin-project/builtin-actors/pull/474/commits/3027c365f516e1cba6f156d4fb9dbd8c893d5b62) + + +## 🆕 Things you may wanna know + +### Actor Code CIDs + +As stated in [FIP-0031](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0031.md)- [structure of the code cid](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0031.md#structure-of-code-cids), system actors' code CIDs will be real content-addressing + +For lotus users, we are making the change minimal for you. This means the `CODE` output when you run `lotus state get-actor` will now be the actual CID that represents the executable code for the actor, followed by wrapped synthetic id like the ones you've got before, i.e `fil/8/system`. + +Moreover, this also means that in the future, whenever the actor code changes, the CID changes accordingly, and a network upgrade is needed for the network participants to have consensus over what executable code we should use for each system actor. + +### Built-in actor bundles + +As the network introduces FVM, it's also switching from spec-actor (written in GoLang) to [built-in actor](https://github.com/filecoin-project/builtin-actors) (written in rust), in which the latter comes with[ importable bundles](https://github.com/filecoin-project/builtin-actors#importable-bundle). This means, like filecoin proof parameters, node operators now also need to fetch the actor bundles according to the network versions for the nodes to remain operational. + +Bundles for all networks(mainnet, calibnet, and etc) are included in the lotus source tree (`build/actors/`) and embedded on build. Lotus verifies that the bundle CIDs are the right ones upon build & upgrade against the values in `build/builtin_actors_gen.go`, according to the network you are building. You may also check the bundle manifest CID matches the bundle gen-ed values by running `lotus state actor-cids --network-version 16`. + +The manifest CID & full list of actor code CIDs for nv16 using v8.0.0 is: + +``` + "_manifest": "bafy2bzacebogjbpiemi7npzxchgcjjki3tfxon4ims55obfyfleqntteljsea" + "account": "bafk2bzacedudbf7fc5va57t3tmo63snmt3en4iaidv4vo3qlyacbxaa6hlx6y" + "cron": "bafk2bzacecqb3eolfurehny6yp7tgmapib4ocazo5ilkopjce2c7wc2bcec62" + "init": "bafk2bzaceaipvjhoxmtofsnv3aj6gj5ida4afdrxa4ewku2hfipdlxpaektlw" + "multisig": "bafk2bzacebhldfjuy4o5v7amrhp5p2gzv2qo5275jut4adnbyp56fxkwy5fag" + "paymentchannel": "bafk2bzacebalad3f72wyk7qyilvfjijcwubdspytnyzlrhvn73254gqis44rq" + "reward": "bafk2bzacecwzzxlgjiavnc3545cqqil3cmq4hgpvfp2crguxy2pl5ybusfsbe" + "storagemarket": "bafk2bzacediohrxkp2fbsl4yj4jlupjdkgsiwqb4zuezvinhdo2j5hrxco62q" + "storageminer": "bafk2bzacecgnynvd3tene3bvqoknuspit56canij5bpra6wl4mrq2mxxwriyu" + "storagepower": "bafk2bzacebjvqva6ppvysn5xpmiqcdfelwbbcxmghx5ww6hr37cgred6dyrpm" + "system": "bafk2bzacedwq5uppsw7vp55zpj7jdieizirmldceehu6wvombw3ixq2tcq57w" + "verifiedregistry": "bafk2bzaceb3zbkjz3auizmoln2unmxep7dyfcmsre64vnqfhdyh7rkqfoxlw4" +``` + +All bundles are also available at https://github.com/filecoin-project/builtin-actors/releases, thus you can also manually download the bundles and place them in the right path. + +Note: use customized bundle will risk you to lose sync with the network! + +To get Code CIDs: +- api:`StateActorCodeCIDs` +- cli: `lotus state actor-cids` +- cli: `lotus-shed cid inspect-bundle` + +### Execution Trace + +For developers that are dependent on lotus execution trace, you will need to enable `LOTUS_VM_ENABLE_TRACING` envvar to get the exact execution trace response as before. Without the envvar enabled, `Subcall` details, Duration` and `GasCharges` fields will be missing from the new FVM trace. + +### Deal Proposal Migration + +All deal proposals with non-utf8 string as the label in the metadata store will perform a light migration to new format as defined in [v1.1.1](https://github.com/filecoin-project/go-fil-markets/pull/721). + +## Others +- Resource manager is now only enabled by default on full daemon node. You can enable it manually for other nodes by setting env var `LOTUS_RCMGR` to `1`. +- Fix: drand: calculation of round from Filecoin epochs ([filecoin-project/lotus#8606](https://github.com/filecoin-project/lotus/pull/8606)) + +## Dependency Update +- chore: deps: update to go-libp2p v0.19.4 ([filecoin-project/lotus#8801](https://github.com/filecoin-project/lotus/pull/8801)) +- github.com/filecoin-project/go-fil-markets (v1.20.1 -> v1.20.1-v16-2): +- github.com/filecoin-project/go-legs (v0.3.7 -> v0.3.10): +- github.com/filecoin-project/go-state-types (v0.1.8 -> v0.1.10): +- github.com/filecoin-project/specs-storage (v0.2.4 -> v0.4.1): + +## Contributors + +| Contributor | Commits | Lines ± | Files Changed | +|-------------|---------|---------|---------------| +| @geoff-vball | 37 | +10565/-8454 | 150 | +| @arajasek | 33 | +7964/-6340 | 473 | +| @arajasek | 37 | +6220/-6976 | 457 | +| @vyzo | 135 | +7287/-5380 | 546 | +| @ZenGround0 | 19 | +5958/-2920 | 226 | +| @stebalien | 18 | +1566/-1101 | 116 | +| Alex | 5 | +323/-2304 | 32 | +| @zenground0 | 9 | +583/-358 | 56 | +| @jennijuju | 5 | +853/-27 | 19 | +| @jennijuju | 24 | +392/-201 | 60 | +| Marco Munizaga | 3 | +236/-83 | 5 | +| @raulk| 9 | +93/-15 | 15 | +| @travisperson | 3 | +37/-37 | 12 | +| @Kubuxu | 1 | +41/-5 | 1 | +| @koalacxr | 1 | +29/-13 | 3 | +| @gammazero | 2 | +18/-10 | 4 | +| Peter Rabbitson | 1 | +5/-3 | 1 | +| Steve Loeppky | 1 | +6/-0 | 1 | +| @masih | 1 | +3/-3 | 2 | +| @magik6k | 1 | +4/-0 | 1 | +| @jennijuju | 1 | +2/-2 | 1 | +| tian zhou | 1 | +1/-1 | 1 | + # 1.15.3 / 2022-05-31 This is an optional release of lotus that include new APIs, some improvements and bug fixes. @@ -75,7 +183,7 @@ This is an optional release of lotus that include new APIs, some improvements an # 1.15.2 / 2022-05-06 -This is a highly recommended feature lotus release v1.15.2. This feature release introduces many new features and for SPs, including PoSt workers, sealing scheduler, snap deal queue and so on. +This is a highly recommended feature lotus release v1.15.2. This feature release introduces many new features and for SPs, including PoSt workers, sealing scheduler, snap deal queue and so on. Note: You need to be using go v1.17.9&up from this release onwards. @@ -233,31 +341,31 @@ This feature release introduces Index Provider, GraphSync v2, and many other lat ### 🔥🔥🔥 FVM (Experimental) 🔥🔥🔥 - feat: fvm: FVM integration ([filecoin-project/lotus#8332](https://github.com/filecoin-project/lotus/pull/8332)) -The lotus team is excited to announce the launch of experimental non-programmable FVM on mainnet. By enabling `"LOTUS_USE_FVM_EXPERIMENTAL=1` envvar, the lotus daemon will be running the [WASM-compiled built-in actors](https://github.com/filecoin-project/builtin-actors) that is compatible with the existing chain(Network v15 OhSnap). If you are trying it out and having any questions or feedbacks, please leave a comment [here](https://github.com/filecoin-project/lotus/discussions/8334)! + The lotus team is excited to announce the launch of experimental non-programmable FVM on mainnet. By enabling `"LOTUS_USE_FVM_EXPERIMENTAL=1` envvar, the lotus daemon will be running the [WASM-compiled built-in actors](https://github.com/filecoin-project/builtin-actors) that is compatible with the existing chain(Network v15 OhSnap). If you are trying it out and having any questions or feedbacks, please leave a comment [here](https://github.com/filecoin-project/lotus/discussions/8334)! - chore: FVM: log when fvm is used([filecoin-project/lotus#8363](https://github.com/filecoin-project/lotus/pull/8363)) - chore: ffi: the latest fvm release([filecoin-project/lotus#8382](https://github.com/filecoin-project/lotus/pull/8382)) - + ### 🌟🌟🌟 Index Provider (Production Ready!) 🌟🌟🌟 - feat: markets: Integrate index ingest protocol and retrieve by any CID ([filecoin-project/lotus#7313](https://github.com/filecoin-project/lotus/pull/7313)) -More and more useful data is being stored on Filecoin via deals made by clients to Storage Providers. The goal is that this content is discoverable when people need them. To achieve that goal, one of the projects [the Bedrock team](https://www.notion.so/pl-strflt/Bedrock-2e956d5d8143432080a1d84435ccf0ff) is working on is building an Indexer Ecosystem, a project that's focus on content addressing on Filecoin, then potentially have interoperability with IPFS in the future and eventually serve the retrieval market. The Indexer Ecosystem high level architecture overview diagram can be found [here](https://github.com/filecoin-project/storetheindex/blob/main/doc/indexer_ecosys.png) and a detailed write up about can be found [here](https://www.notion.so/pl-strflt/Introducing-Indexer-to-SP-90bf296794174a8281c121d4ce6747a0). +More and more useful data is being stored on Filecoin via deals made by clients to Storage Providers. The goal is that this content is discoverable when people need them. To achieve that goal, one of the projects [the Bedrock team](https://www.notion.so/pl-strflt/Bedrock-2e956d5d8143432080a1d84435ccf0ff) is working on is building an Indexer Ecosystem, a project that's focus on content addressing on Filecoin, then potentially have interoperability with IPFS in the future and eventually serve the retrieval market. The Indexer Ecosystem high level architecture overview diagram can be found [here](https://github.com/filecoin-project/storetheindex/blob/main/doc/indexer_ecosys.png) and a detailed write up about can be found [here](https://www.notion.so/pl-strflt/Introducing-Indexer-to-SP-90bf296794174a8281c121d4ce6747a0). That being said, with this release, lotus Storage Providers can easily become an Index Provider and serve the Indexer Content Addressing System. Index Providers generate advertisements from the deals made by a storage provider and announces the data to the indexer nodes for further processing: - To learn more about *what is an Index Provider and how to be an Index Provider*, read it [here](https://lotus.filecoin.io/storage-providers/operate/index-provider/) in lotus docuementation. - An [one-off migration](https://lotus.filecoin.io/storage-providers/operate/index-provider/#first-time-migration) is needed in order for a Storage Provider to become an Index Provider and announce the proper formatted index. It's *highly recommended* for all Index Provider to do a [force bulk initialization](https://lotus.filecoin.io/storage-providers/configure/dagstore/#forcing-bulk-initialization) to enable index announcement on all existing deals. - Note that the Initialization places IO workload on your storage system. SP should set a proper `concurrency` based on your hardware or can stop/start initialization at their wish/convenience as proving deadlines approach and elapse, to avoid IOPS starvation or competition with window PoSt. -- After the first one-time migration, being an Index Provider barely puts any extra usage on SP's market system. +- After the first one-time migration, being an Index Provider barely puts any extra usage on SP's market system. - You can find the testing result by SPX fellows [here](https://github.com/filecoin-project/lotus/discussions/8087). - -We recommend all Storage Providers that are serving deals in the Filecoin network to become a Index Provider, make the data you are storing discoverable for the retrieval market and retrieval clients! - - If you have any questions about becoming an index provider, or the indexer system in general, leave a comment [here](https://github.com/filecoin-project/lotus/discussions/8341). - - Follow the indexer project at https://github.com/filecoin-project/go-indexer-core. - - If you have any feature request or bug reports of running an index provider, create an issue in https://github.com/filecoin-project/index-provider. - - You may also join the #storetheindex channel in the Filecoin Slack to engage with the team & the community! + +We recommend all Storage Providers that are serving deals in the Filecoin network to become a Index Provider, make the data you are storing discoverable for the retrieval market and retrieval clients! +- If you have any questions about becoming an index provider, or the indexer system in general, leave a comment [here](https://github.com/filecoin-project/lotus/discussions/8341). +- Follow the indexer project at https://github.com/filecoin-project/go-indexer-core. +- If you have any feature request or bug reports of running an index provider, create an issue in https://github.com/filecoin-project/index-provider. +- You may also join the #storetheindex channel in the Filecoin Slack to engage with the team & the community! ### ❗️❗️❗️ Dag Migration For New CAR index format in DagStore ❗️❗️❗️ The index provider leverages the latest CARv2 indexing format `MultihashIndexSorted`, which stores the multihash code as well as the digest of all CIDs in a CAR file. Thus, all Storage Providers SHOULD perform an one-off DAG mirgation to regenerate DagStore CARv2 indices. You have to do it to become an index provider, failing to do so may also impact your future deal making. -Follow the instruction [here](https://lotus.filecoin.io/storage-providers/operate/index-provider/) to perform the migration. +Follow the instruction [here](https://lotus.filecoin.io/storage-providers/operate/index-provider/) to perform the migration. ## New Features - feat: sealing: Sector upgrade queue ([filecoin-project/lotus#8333](https://github.com/filecoin-project/lotus/pull/8333)) @@ -297,7 +405,7 @@ Follow the instruction [here](https://lotus.filecoin.io/storage-providers/operat ## Bug Fixes - fix: FVM: add finality check for consensus faults #8452 - fix: market: Reuse the market PubSub in index provider #8451 -- fix: market: set all index provider options based on lotus config #8444 +- fix: market: set all index provider options based on lotus config #8444 - fix: sealing: Fix PR1 worker selection (#8421) - fix: miner: dead loop on removing sector (#8421) - fix: sealing: Remove sector copies from workers after snapdeals ([filecoin-project/lotus#8331](https://github.com/filecoin-project/lotus/pull/8331)) diff --git a/Makefile b/Makefile index 6d5a466b5..5aab3c170 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ CLEAN+=build/.update-modules deps: $(BUILD_DEPS) .PHONY: deps -build-devnets: build lotus-seed lotus-shed lotus-wallet lotus-gateway +build-devnets: build lotus-seed lotus-shed lotus-wallet lotus-gateway lotus-fountain lotus-stats .PHONY: build-devnets debug: GOFLAGS+=-tags=debug @@ -169,7 +169,7 @@ BINS+=lotus-fountain lotus-bench: rm -f lotus-bench - $(GOCC) build -o lotus-bench ./cmd/lotus-bench + $(GOCC) build $(GOFLAGS) -o lotus-bench ./cmd/lotus-bench .PHONY: lotus-bench BINS+=lotus-bench @@ -295,6 +295,12 @@ actors-gen: $(GOCC) run ./chain/actors/agen $(GOCC) fmt ./... +bundle-gen: + $(GOCC) run ./gen/bundle + $(GOCC) fmt ./build/... +.PHONY: bundle-gen + + api-gen: $(GOCC) run ./gen/api goimports -w api @@ -341,7 +347,7 @@ docsgen-openrpc-worker: docsgen-openrpc-bin .PHONY: docsgen docsgen-md-bin docsgen-openrpc-bin -gen: actors-gen type-gen method-gen cfgdoc-gen docsgen api-gen circleci +gen: actors-gen type-gen method-gen cfgdoc-gen docsgen api-gen circleci bundle-gen @echo ">>> IF YOU'VE MODIFIED THE CLI OR CONFIG, REMEMBER TO ALSO MAKE docsgen-cli" .PHONY: gen diff --git a/api/api_full.go b/api/api_full.go index 2a113dbaf..ce010b0c7 100644 --- a/api/api_full.go +++ b/api/api_full.go @@ -6,6 +6,9 @@ import ( "fmt" "time" + abinetwork "github.com/filecoin-project/go-state-types/network" + + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" @@ -20,11 +23,12 @@ import ( "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/storagemarket" + "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" apitypes "github.com/filecoin-project/lotus/api/types" "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/lotus/chain/actors/builtin/market" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" @@ -37,6 +41,7 @@ import ( type ChainIO interface { ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainHasObj(context.Context, cid.Cid) (bool, error) + ChainPutObj(context.Context, blocks.Block) error } const LookbackNoLimit = abi.ChainEpoch(-1) @@ -122,6 +127,9 @@ type FullNode interface { // ChainHasObj checks if a given CID exists in the chain blockstore. ChainHasObj(context.Context, cid.Cid) (bool, error) //perm:read + // ChainPutObj puts a given object into the block store + ChainPutObj(context.Context, blocks.Block) error //perm:admin + // ChainStatObj returns statistics about the graph referenced by 'obj'. // If 'base' is also specified, then the returned stat will be a diff // between the two objects. @@ -170,14 +178,6 @@ type FullNode interface { // ChainBlockstoreInfo returns some basic information about the blockstore ChainBlockstoreInfo(context.Context) (map[string]interface{}, error) //perm:read - // MethodGroup: Beacon - // The Beacon method group contains methods for interacting with the random beacon (DRAND) - - // BeaconGetEntry returns the beacon entry for the given filecoin epoch. If - // the entry has not yet been produced, the call will block until the entry - // becomes available - BeaconGetEntry(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) //perm:read - // GasEstimateFeeCap estimates gas fee cap GasEstimateFeeCap(context.Context, *types.Message, int64, types.TipSetKey) (types.BigInt, error) //perm:read @@ -443,7 +443,7 @@ type FullNode interface { // StateMinerPower returns the power of the indicated miner StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error) //perm:read // StateMinerInfo returns info about the indicated miner - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) //perm:read + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (MinerInfo, error) //perm:read // StateMinerDeadlines returns all the proving deadlines for the given miner StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]Deadline, error) //perm:read // StateMinerPartitions returns all partitions in the specified deadline @@ -469,9 +469,9 @@ type FullNode interface { // expiration epoch StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) //perm:read // StateSectorExpiration returns epoch at which given sector will expire - StateSectorExpiration(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorExpiration, error) //perm:read + StateSectorExpiration(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*lminer.SectorExpiration, error) //perm:read // StateSectorPartition finds deadline/partition with the specified sector - StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) //perm:read + StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*lminer.SectorLocation, error) //perm:read // StateSearchMsg looks back up to limit epochs in the chain for a message, and returns its receipt and the tipset where it was executed // // NOTE: If a replacing message is found on chain, this method will return @@ -517,7 +517,7 @@ type FullNode interface { // StateMarketParticipants returns the Escrow and Locked balances of every participant in the Storage Market StateMarketParticipants(context.Context, types.TipSetKey) (map[string]MarketBalance, error) //perm:read // StateMarketDeals returns information about every deal in the Storage Market - StateMarketDeals(context.Context, types.TipSetKey) (map[string]MarketDeal, error) //perm:read + StateMarketDeals(context.Context, types.TipSetKey) (map[string]*MarketDeal, error) //perm:read // StateMarketStorageDeal returns information about the indicated deal StateMarketStorageDeal(context.Context, abi.DealID, types.TipSetKey) (*MarketDeal, error) //perm:read // StateLookupID retrieves the ID address of the given address @@ -586,12 +586,19 @@ type FullNode interface { StateVMCirculatingSupplyInternal(context.Context, types.TipSetKey) (CirculatingSupply, error) //perm:read // StateNetworkVersion returns the network version at the given tipset StateNetworkVersion(context.Context, types.TipSetKey) (apitypes.NetworkVersion, error) //perm:read + // StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version + StateActorCodeCIDs(context.Context, abinetwork.Version) (map[string]cid.Cid, error) //perm:read // StateGetRandomnessFromTickets is used to sample the chain for randomness. StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) //perm:read // StateGetRandomnessFromBeacon is used to sample the beacon for randomness. StateGetRandomnessFromBeacon(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) //perm:read + // StateGetBeaconEntry returns the beacon entry for the given filecoin epoch. If + // the entry has not yet been produced, the call will block until the entry + // becomes available + StateGetBeaconEntry(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) //perm:read + // StateGetNetworkParams return current network params StateGetNetworkParams(ctx context.Context) (*NetworkParams, error) //perm:read diff --git a/api/api_gateway.go b/api/api_gateway.go index be4b3b83c..d96508194 100644 --- a/api/api_gateway.go +++ b/api/api_gateway.go @@ -3,14 +3,15 @@ package api import ( "context" + blocks "github.com/ipfs/go-block-format" "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/dline" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" apitypes "github.com/filecoin-project/lotus/api/types" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" ) @@ -30,6 +31,7 @@ import ( type Gateway interface { ChainHasObj(context.Context, cid.Cid) (bool, error) + ChainPutObj(context.Context, blocks.Block) error ChainHead(ctx context.Context) (*types.TipSet, error) ChainGetParentMessages(context.Context, cid.Cid) ([]Message, error) ChainGetParentReceipts(context.Context, cid.Cid) ([]*types.MessageReceipt, error) @@ -56,7 +58,7 @@ type Gateway interface { StateLookupID(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (MarketBalance, error) StateMarketStorageDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*MarketDeal, error) - StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) + StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (MinerInfo, error) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*dline.Info, error) StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error) StateNetworkVersion(context.Context, types.TipSetKey) (apitypes.NetworkVersion, error) diff --git a/api/api_storage.go b/api/api_storage.go index 5785ede1f..38184fcdc 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -5,8 +5,8 @@ import ( "context" "time" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/google/uuid" "github.com/ipfs/go-cid" @@ -15,8 +15,8 @@ import ( "github.com/filecoin-project/go-address" datatransfer "github.com/filecoin-project/go-data-transfer" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/builtin/v8/market" abinetwork "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/go-fil-markets/piecestore" @@ -165,7 +165,7 @@ type StorageMiner interface { StorageStat(ctx context.Context, id storiface.ID) (fsutil.FsStat, error) //perm:admin MarketImportDealData(ctx context.Context, propcid cid.Cid, path string) error //perm:write - MarketListDeals(ctx context.Context) ([]MarketDeal, error) //perm:read + MarketListDeals(ctx context.Context) ([]*MarketDeal, error) //perm:read MarketListRetrievalDeals(ctx context.Context) ([]retrievalmarket.ProviderDealState, error) //perm:read MarketGetDealUpdates(ctx context.Context) (<-chan storagemarket.MinerDeal, error) //perm:read MarketListIncompleteDeals(ctx context.Context) ([]storagemarket.MinerDeal, error) //perm:read @@ -242,7 +242,7 @@ type StorageMiner interface { RuntimeSubsystems(ctx context.Context) (MinerSubsystems, error) //perm:read DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error //perm:admin - DealsList(ctx context.Context) ([]MarketDeal, error) //perm:admin + DealsList(ctx context.Context) ([]*MarketDeal, error) //perm:admin DealsConsiderOnlineStorageDeals(context.Context) (bool, error) //perm:admin DealsSetConsiderOnlineStorageDeals(context.Context, bool) error //perm:admin DealsConsiderOnlineRetrievalDeals(context.Context) (bool, error) //perm:admin diff --git a/api/api_worker.go b/api/api_worker.go index cd4cde151..33668c0b8 100644 --- a/api/api_worker.go +++ b/api/api_worker.go @@ -3,12 +3,12 @@ package api import ( "context" + "github.com/filecoin-project/go-state-types/proof" + "github.com/google/uuid" "github.com/ipfs/go-cid" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" - "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" "github.com/filecoin-project/specs-storage/storage" diff --git a/api/cbor_gen.go b/api/cbor_gen.go index eb4c34f8a..40982779e 100644 --- a/api/cbor_gen.go +++ b/api/cbor_gen.go @@ -9,8 +9,8 @@ import ( "sort" abi "github.com/filecoin-project/go-state-types/abi" - market "github.com/filecoin-project/specs-actors/actors/builtin/market" - paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + market "github.com/filecoin-project/go-state-types/builtin/v8/market" + paych "github.com/filecoin-project/go-state-types/builtin/v8/paych" cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" @@ -26,25 +26,26 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{163}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{163}); err != nil { return err } - scratch := make([]byte, 9) - // t.Channel (address.Address) (struct) if len("Channel") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Channel\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Channel"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Channel"))); err != nil { return err } if _, err := io.WriteString(w, string("Channel")); err != nil { return err } - if err := t.Channel.MarshalCBOR(w); err != nil { + if err := t.Channel.MarshalCBOR(cw); err != nil { return err } @@ -53,14 +54,14 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"WaitSentinel\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("WaitSentinel"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("WaitSentinel"))); err != nil { return err } if _, err := io.WriteString(w, string("WaitSentinel")); err != nil { return err } - if err := cbg.WriteCidBuf(scratch, w, t.WaitSentinel); err != nil { + if err := cbg.WriteCid(cw, t.WaitSentinel); err != nil { return xerrors.Errorf("failed to write cid field t.WaitSentinel: %w", err) } @@ -69,7 +70,7 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Vouchers\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Vouchers"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Vouchers"))); err != nil { return err } if _, err := io.WriteString(w, string("Vouchers")); err != nil { @@ -80,27 +81,32 @@ func (t *PaymentInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Vouchers was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Vouchers))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Vouchers))); err != nil { return err } for _, v := range t.Vouchers { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } return nil } -func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { +func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) (err error) { *t = PaymentInfo{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -115,7 +121,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -129,7 +135,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.Channel.UnmarshalCBOR(br); err != nil { + if err := t.Channel.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Channel: %w", err) } @@ -139,7 +145,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.WaitSentinel: %w", err) } @@ -150,7 +156,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { // t.Vouchers ([]*paych.SignedVoucher) (slice) case "Vouchers": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -170,7 +176,7 @@ func (t *PaymentInfo) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v paych.SignedVoucher - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -190,25 +196,26 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{163}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{163}); err != nil { return err } - scratch := make([]byte, 9) - // t.SectorID (abi.SectorNumber) (uint64) if len("SectorID") > cbg.MaxLength { return xerrors.Errorf("Value in field \"SectorID\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SectorID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("SectorID"))); err != nil { return err } if _, err := io.WriteString(w, string("SectorID")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorID)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.SectorID)); err != nil { return err } @@ -217,14 +224,14 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Offset\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Offset"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Offset"))); err != nil { return err } if _, err := io.WriteString(w, string("Offset")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Offset)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Offset)); err != nil { return err } @@ -233,30 +240,35 @@ func (t *SealedRef) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Size\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Size"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Size"))); err != nil { return err } if _, err := io.WriteString(w, string("Size")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Size)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Size)); err != nil { return err } return nil } -func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { +func (t *SealedRef) UnmarshalCBOR(r io.Reader) (err error) { *t = SealedRef{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -271,7 +283,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -285,7 +297,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -300,7 +312,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -315,7 +327,7 @@ func (t *SealedRef) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -339,18 +351,19 @@ func (t *SealedRefs) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{161}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{161}); err != nil { return err } - scratch := make([]byte, 9) - // t.Refs ([]api.SealedRef) (slice) if len("Refs") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Refs\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Refs"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Refs"))); err != nil { return err } if _, err := io.WriteString(w, string("Refs")); err != nil { @@ -361,27 +374,32 @@ func (t *SealedRefs) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Refs was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Refs))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Refs))); err != nil { return err } for _, v := range t.Refs { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } return nil } -func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error { +func (t *SealedRefs) UnmarshalCBOR(r io.Reader) (err error) { *t = SealedRefs{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -396,7 +414,7 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -408,7 +426,7 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error { // t.Refs ([]api.SealedRef) (slice) case "Refs": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -428,7 +446,7 @@ func (t *SealedRefs) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v SealedRef - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -448,18 +466,19 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{162}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{162}); err != nil { return err } - scratch := make([]byte, 9) - // t.Value (abi.SealRandomness) (slice) if len("Value") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Value\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Value"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Value"))); err != nil { return err } if _, err := io.WriteString(w, string("Value")); err != nil { @@ -470,11 +489,11 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Value was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Value))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Value))); err != nil { return err } - if _, err := w.Write(t.Value[:]); err != nil { + if _, err := cw.Write(t.Value[:]); err != nil { return err } @@ -483,7 +502,7 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Epoch\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Epoch"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Epoch"))); err != nil { return err } if _, err := io.WriteString(w, string("Epoch")); err != nil { @@ -491,27 +510,32 @@ func (t *SealTicket) MarshalCBOR(w io.Writer) error { } if t.Epoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Epoch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Epoch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Epoch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Epoch-1)); err != nil { return err } } return nil } -func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { +func (t *SealTicket) UnmarshalCBOR(r io.Reader) (err error) { *t = SealTicket{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -526,7 +550,7 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -538,7 +562,7 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { // t.Value (abi.SealRandomness) (slice) case "Value": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -554,13 +578,13 @@ func (t *SealTicket) UnmarshalCBOR(r io.Reader) error { t.Value = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Value[:]); err != nil { + if _, err := io.ReadFull(cr, t.Value[:]); err != nil { return err } // t.Epoch (abi.ChainEpoch) (int64) case "Epoch": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -597,18 +621,19 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{162}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{162}); err != nil { return err } - scratch := make([]byte, 9) - // t.Value (abi.InteractiveSealRandomness) (slice) if len("Value") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Value\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Value"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Value"))); err != nil { return err } if _, err := io.WriteString(w, string("Value")); err != nil { @@ -619,11 +644,11 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Value was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Value))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Value))); err != nil { return err } - if _, err := w.Write(t.Value[:]); err != nil { + if _, err := cw.Write(t.Value[:]); err != nil { return err } @@ -632,7 +657,7 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Epoch\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Epoch"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Epoch"))); err != nil { return err } if _, err := io.WriteString(w, string("Epoch")); err != nil { @@ -640,27 +665,32 @@ func (t *SealSeed) MarshalCBOR(w io.Writer) error { } if t.Epoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Epoch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Epoch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Epoch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Epoch-1)); err != nil { return err } } return nil } -func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { +func (t *SealSeed) UnmarshalCBOR(r io.Reader) (err error) { *t = SealSeed{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -675,7 +705,7 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -687,7 +717,7 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { // t.Value (abi.InteractiveSealRandomness) (slice) case "Value": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -703,13 +733,13 @@ func (t *SealSeed) UnmarshalCBOR(r io.Reader) error { t.Value = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Value[:]); err != nil { + if _, err := io.ReadFull(cr, t.Value[:]); err != nil { return err } // t.Epoch (abi.ChainEpoch) (int64) case "Epoch": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -746,18 +776,19 @@ func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{165}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{165}); err != nil { return err } - scratch := make([]byte, 9) - // t.PublishCid (cid.Cid) (struct) if len("PublishCid") > cbg.MaxLength { return xerrors.Errorf("Value in field \"PublishCid\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PublishCid"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PublishCid"))); err != nil { return err } if _, err := io.WriteString(w, string("PublishCid")); err != nil { @@ -765,11 +796,11 @@ func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { } if t.PublishCid == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.PublishCid); err != nil { + if err := cbg.WriteCid(cw, *t.PublishCid); err != nil { return xerrors.Errorf("failed to write cid field t.PublishCid: %w", err) } } @@ -779,14 +810,14 @@ func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"DealID\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("DealID"))); err != nil { return err } if _, err := io.WriteString(w, string("DealID")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.DealID)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.DealID)); err != nil { return err } @@ -795,14 +826,14 @@ func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"DealProposal\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealProposal"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("DealProposal"))); err != nil { return err } if _, err := io.WriteString(w, string("DealProposal")); err != nil { return err } - if err := t.DealProposal.MarshalCBOR(w); err != nil { + if err := t.DealProposal.MarshalCBOR(cw); err != nil { return err } @@ -811,14 +842,14 @@ func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"DealSchedule\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealSchedule"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("DealSchedule"))); err != nil { return err } if _, err := io.WriteString(w, string("DealSchedule")); err != nil { return err } - if err := t.DealSchedule.MarshalCBOR(w); err != nil { + if err := t.DealSchedule.MarshalCBOR(cw); err != nil { return err } @@ -827,7 +858,7 @@ func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"KeepUnsealed\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("KeepUnsealed"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("KeepUnsealed"))); err != nil { return err } if _, err := io.WriteString(w, string("KeepUnsealed")); err != nil { @@ -840,16 +871,21 @@ func (t *PieceDealInfo) MarshalCBOR(w io.Writer) error { return nil } -func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { +func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) (err error) { *t = PieceDealInfo{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -864,7 +900,7 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -878,16 +914,16 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.PublishCid: %w", err) } @@ -901,7 +937,7 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -916,16 +952,16 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.DealProposal = new(market.DealProposal) - if err := t.DealProposal.UnmarshalCBOR(br); err != nil { + if err := t.DealProposal.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.DealProposal pointer: %w", err) } } @@ -936,7 +972,7 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.DealSchedule.UnmarshalCBOR(br); err != nil { + if err := t.DealSchedule.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.DealSchedule: %w", err) } @@ -944,7 +980,7 @@ func (t *PieceDealInfo) UnmarshalCBOR(r io.Reader) error { // t.KeepUnsealed (bool) (bool) case "KeepUnsealed": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -973,18 +1009,19 @@ func (t *DealSchedule) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{162}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{162}); err != nil { return err } - scratch := make([]byte, 9) - // t.StartEpoch (abi.ChainEpoch) (int64) if len("StartEpoch") > cbg.MaxLength { return xerrors.Errorf("Value in field \"StartEpoch\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("StartEpoch"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("StartEpoch"))); err != nil { return err } if _, err := io.WriteString(w, string("StartEpoch")); err != nil { @@ -992,11 +1029,11 @@ func (t *DealSchedule) MarshalCBOR(w io.Writer) error { } if t.StartEpoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.StartEpoch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.StartEpoch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.StartEpoch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.StartEpoch-1)); err != nil { return err } } @@ -1006,7 +1043,7 @@ func (t *DealSchedule) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"EndEpoch\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("EndEpoch"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("EndEpoch"))); err != nil { return err } if _, err := io.WriteString(w, string("EndEpoch")); err != nil { @@ -1014,27 +1051,32 @@ func (t *DealSchedule) MarshalCBOR(w io.Writer) error { } if t.EndEpoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.EndEpoch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.EndEpoch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.EndEpoch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.EndEpoch-1)); err != nil { return err } } return nil } -func (t *DealSchedule) UnmarshalCBOR(r io.Reader) error { +func (t *DealSchedule) UnmarshalCBOR(r io.Reader) (err error) { *t = DealSchedule{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -1049,7 +1091,7 @@ func (t *DealSchedule) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -1061,7 +1103,7 @@ func (t *DealSchedule) UnmarshalCBOR(r io.Reader) error { // t.StartEpoch (abi.ChainEpoch) (int64) case "StartEpoch": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1087,7 +1129,7 @@ func (t *DealSchedule) UnmarshalCBOR(r io.Reader) error { // t.EndEpoch (abi.ChainEpoch) (int64) case "EndEpoch": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index a15d4623e..928e5b808 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -28,6 +28,7 @@ import ( filestore "github.com/filecoin-project/go-fil-markets/filestore" "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-jsonrpc/auth" + blocks "github.com/ipfs/go-block-format" textselector "github.com/ipld/go-ipld-selector-text-lite" "github.com/filecoin-project/go-state-types/abi" @@ -95,6 +96,9 @@ func init() { apiSelExample := api.Selector("Links/21/Hash/Links/42/Hash") clientEvent := retrievalmarket.ClientEventDealAccepted + block := blocks.Block(&blocks.BasicBlock{}) + ExampleValues[reflect.TypeOf(&block).Elem()] = block + addExample(bitfield.NewFromSet([]uint64{5})) addExample(abi.RegisteredSealProof_StackedDrg32GiBV1_1) addExample(abi.RegisteredPoStProof_StackedDrgWindow32GiBV1) @@ -146,6 +150,10 @@ func init() { addExample(map[string]api.MarketDeal{ "t026363": ExampleValue("init", reflect.TypeOf(api.MarketDeal{}), nil).(api.MarketDeal), }) + addExample(map[string]*api.MarketDeal{ + "t026363": ExampleValue("init", reflect.TypeOf(&api.MarketDeal{}), nil).(*api.MarketDeal), + }) + addExample(map[string]api.MarketBalance{ "t026363": ExampleValue("init", reflect.TypeOf(api.MarketBalance{}), nil).(api.MarketBalance), }) @@ -188,6 +196,7 @@ func init() { addExample(&si) addExample(retrievalmarket.DealID(5)) addExample(abi.ActorID(1000)) + addExample(map[string]cid.Cid{}) addExample(map[string][]api.SealedRef{ "98000": { api.SealedRef{ diff --git a/api/mocks/mock_full.go b/api/mocks/mock_full.go index f8ab754ed..d122b4b10 100644 --- a/api/mocks/mock_full.go +++ b/api/mocks/mock_full.go @@ -17,20 +17,21 @@ import ( auth "github.com/filecoin-project/go-jsonrpc/auth" abi "github.com/filecoin-project/go-state-types/abi" big "github.com/filecoin-project/go-state-types/big" + miner "github.com/filecoin-project/go-state-types/builtin/v8/miner" + paych "github.com/filecoin-project/go-state-types/builtin/v8/paych" crypto "github.com/filecoin-project/go-state-types/crypto" dline "github.com/filecoin-project/go-state-types/dline" network "github.com/filecoin-project/go-state-types/network" api "github.com/filecoin-project/lotus/api" apitypes "github.com/filecoin-project/lotus/api/types" - miner "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + miner0 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" types "github.com/filecoin-project/lotus/chain/types" alerting "github.com/filecoin-project/lotus/journal/alerting" dtypes "github.com/filecoin-project/lotus/node/modules/dtypes" imports "github.com/filecoin-project/lotus/node/repo/imports" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" + blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" metrics "github.com/libp2p/go-libp2p-core/metrics" network0 "github.com/libp2p/go-libp2p-core/network" @@ -91,21 +92,6 @@ func (mr *MockFullNodeMockRecorder) AuthVerify(arg0, arg1 interface{}) *gomock.C return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AuthVerify", reflect.TypeOf((*MockFullNode)(nil).AuthVerify), arg0, arg1) } -// BeaconGetEntry mocks base method. -func (m *MockFullNode) BeaconGetEntry(arg0 context.Context, arg1 abi.ChainEpoch) (*types.BeaconEntry, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "BeaconGetEntry", arg0, arg1) - ret0, _ := ret[0].(*types.BeaconEntry) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// BeaconGetEntry indicates an expected call of BeaconGetEntry. -func (mr *MockFullNodeMockRecorder) BeaconGetEntry(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BeaconGetEntry", reflect.TypeOf((*MockFullNode)(nil).BeaconGetEntry), arg0, arg1) -} - // ChainBlockstoreInfo mocks base method. func (m *MockFullNode) ChainBlockstoreInfo(arg0 context.Context) (map[string]interface{}, error) { m.ctrl.T.Helper() @@ -389,6 +375,20 @@ func (mr *MockFullNodeMockRecorder) ChainNotify(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainNotify", reflect.TypeOf((*MockFullNode)(nil).ChainNotify), arg0) } +// ChainPutObj mocks base method. +func (m *MockFullNode) ChainPutObj(arg0 context.Context, arg1 blocks.Block) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChainPutObj", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// ChainPutObj indicates an expected call of ChainPutObj. +func (mr *MockFullNodeMockRecorder) ChainPutObj(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainPutObj", reflect.TypeOf((*MockFullNode)(nil).ChainPutObj), arg0, arg1) +} + // ChainReadObj mocks base method. func (m *MockFullNode) ChainReadObj(arg0 context.Context, arg1 cid.Cid) ([]byte, error) { m.ctrl.T.Helper() @@ -2271,6 +2271,21 @@ func (mr *MockFullNodeMockRecorder) StateAccountKey(arg0, arg1, arg2 interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateAccountKey", reflect.TypeOf((*MockFullNode)(nil).StateAccountKey), arg0, arg1, arg2) } +// StateActorCodeCIDs mocks base method. +func (m *MockFullNode) StateActorCodeCIDs(arg0 context.Context, arg1 network.Version) (map[string]cid.Cid, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateActorCodeCIDs", arg0, arg1) + ret0, _ := ret[0].(map[string]cid.Cid) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateActorCodeCIDs indicates an expected call of StateActorCodeCIDs. +func (mr *MockFullNodeMockRecorder) StateActorCodeCIDs(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateActorCodeCIDs", reflect.TypeOf((*MockFullNode)(nil).StateActorCodeCIDs), arg0, arg1) +} + // StateAllMinerFaults mocks base method. func (m *MockFullNode) StateAllMinerFaults(arg0 context.Context, arg1 abi.ChainEpoch, arg2 types.TipSetKey) ([]*api.Fault, error) { m.ctrl.T.Helper() @@ -2406,6 +2421,21 @@ func (mr *MockFullNodeMockRecorder) StateGetActor(arg0, arg1, arg2 interface{}) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetActor", reflect.TypeOf((*MockFullNode)(nil).StateGetActor), arg0, arg1, arg2) } +// StateGetBeaconEntry mocks base method. +func (m *MockFullNode) StateGetBeaconEntry(arg0 context.Context, arg1 abi.ChainEpoch) (*types.BeaconEntry, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateGetBeaconEntry", arg0, arg1) + ret0, _ := ret[0].(*types.BeaconEntry) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateGetBeaconEntry indicates an expected call of StateGetBeaconEntry. +func (mr *MockFullNodeMockRecorder) StateGetBeaconEntry(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateGetBeaconEntry", reflect.TypeOf((*MockFullNode)(nil).StateGetBeaconEntry), arg0, arg1) +} + // StateGetNetworkParams mocks base method. func (m *MockFullNode) StateGetNetworkParams(arg0 context.Context) (*api.NetworkParams, error) { m.ctrl.T.Helper() @@ -2542,10 +2572,10 @@ func (mr *MockFullNodeMockRecorder) StateMarketBalance(arg0, arg1, arg2 interfac } // StateMarketDeals mocks base method. -func (m *MockFullNode) StateMarketDeals(arg0 context.Context, arg1 types.TipSetKey) (map[string]api.MarketDeal, error) { +func (m *MockFullNode) StateMarketDeals(arg0 context.Context, arg1 types.TipSetKey) (map[string]*api.MarketDeal, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMarketDeals", arg0, arg1) - ret0, _ := ret[0].(map[string]api.MarketDeal) + ret0, _ := ret[0].(map[string]*api.MarketDeal) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -2647,10 +2677,10 @@ func (mr *MockFullNodeMockRecorder) StateMinerFaults(arg0, arg1, arg2 interface{ } // StateMinerInfo mocks base method. -func (m *MockFullNode) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (miner.MinerInfo, error) { +func (m *MockFullNode) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (api.MinerInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInfo", arg0, arg1, arg2) - ret0, _ := ret[0].(miner.MinerInfo) + ret0, _ := ret[0].(api.MinerInfo) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -2662,7 +2692,7 @@ func (mr *MockFullNodeMockRecorder) StateMinerInfo(arg0, arg1, arg2 interface{}) } // StateMinerInitialPledgeCollateral mocks base method. -func (m *MockFullNode) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner0.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { +func (m *MockFullNode) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInitialPledgeCollateral", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(big.Int) @@ -2707,7 +2737,7 @@ func (mr *MockFullNodeMockRecorder) StateMinerPower(arg0, arg1, arg2 interface{} } // StateMinerPreCommitDepositForPower mocks base method. -func (m *MockFullNode) StateMinerPreCommitDepositForPower(arg0 context.Context, arg1 address.Address, arg2 miner0.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { +func (m *MockFullNode) StateMinerPreCommitDepositForPower(arg0 context.Context, arg1 address.Address, arg2 miner.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerPreCommitDepositForPower", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(big.Int) @@ -2872,10 +2902,10 @@ func (mr *MockFullNodeMockRecorder) StateSearchMsg(arg0, arg1, arg2, arg3, arg4 } // StateSectorExpiration mocks base method. -func (m *MockFullNode) StateSectorExpiration(arg0 context.Context, arg1 address.Address, arg2 abi.SectorNumber, arg3 types.TipSetKey) (*miner.SectorExpiration, error) { +func (m *MockFullNode) StateSectorExpiration(arg0 context.Context, arg1 address.Address, arg2 abi.SectorNumber, arg3 types.TipSetKey) (*miner0.SectorExpiration, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateSectorExpiration", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(*miner.SectorExpiration) + ret0, _ := ret[0].(*miner0.SectorExpiration) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -2902,10 +2932,10 @@ func (mr *MockFullNodeMockRecorder) StateSectorGetInfo(arg0, arg1, arg2, arg3 in } // StateSectorPartition mocks base method. -func (m *MockFullNode) StateSectorPartition(arg0 context.Context, arg1 address.Address, arg2 abi.SectorNumber, arg3 types.TipSetKey) (*miner.SectorLocation, error) { +func (m *MockFullNode) StateSectorPartition(arg0 context.Context, arg1 address.Address, arg2 abi.SectorNumber, arg3 types.TipSetKey) (*miner0.SectorLocation, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateSectorPartition", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(*miner.SectorLocation) + ret0, _ := ret[0].(*miner0.SectorLocation) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/api/proxy_gen.go b/api/proxy_gen.go index 7542ac367..42932135c 100644 --- a/api/proxy_gen.go +++ b/api/proxy_gen.go @@ -15,13 +15,15 @@ import ( "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-jsonrpc/auth" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" abinetwork "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/proof" apitypes "github.com/filecoin-project/lotus/api/types" "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" @@ -30,9 +32,9 @@ import ( "github.com/filecoin-project/lotus/journal/alerting" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/repo/imports" - "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" "github.com/filecoin-project/specs-storage/storage" "github.com/google/uuid" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" metrics "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/network" @@ -47,6 +49,8 @@ type ChainIOStruct struct { Internal struct { ChainHasObj func(p0 context.Context, p1 cid.Cid) (bool, error) `` + ChainPutObj func(p0 context.Context, p1 blocks.Block) error `` + ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `` } } @@ -102,8 +106,6 @@ type FullNodeStruct struct { NetStruct Internal struct { - BeaconGetEntry func(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) `perm:"read"` - ChainBlockstoreInfo func(p0 context.Context) (map[string]interface{}, error) `perm:"read"` ChainCheckBlockstore func(p0 context.Context) error `perm:"admin"` @@ -142,6 +144,8 @@ type FullNodeStruct struct { ChainNotify func(p0 context.Context) (<-chan []*HeadChange, error) `perm:"read"` + ChainPutObj func(p0 context.Context, p1 blocks.Block) error `perm:"admin"` + ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `perm:"read"` ChainSetHead func(p0 context.Context, p1 types.TipSetKey) error `perm:"admin"` @@ -334,6 +338,8 @@ type FullNodeStruct struct { StateAccountKey func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (address.Address, error) `perm:"read"` + StateActorCodeCIDs func(p0 context.Context, p1 abinetwork.Version) (map[string]cid.Cid, error) `perm:"read"` + StateAllMinerFaults func(p0 context.Context, p1 abi.ChainEpoch, p2 types.TipSetKey) ([]*Fault, error) `perm:"read"` StateCall func(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (*InvocResult, error) `perm:"read"` @@ -352,6 +358,8 @@ type FullNodeStruct struct { StateGetActor func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*types.Actor, error) `perm:"read"` + StateGetBeaconEntry func(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) `perm:"read"` + StateGetNetworkParams func(p0 context.Context) (*NetworkParams, error) `perm:"read"` StateGetRandomnessFromBeacon func(p0 context.Context, p1 crypto.DomainSeparationTag, p2 abi.ChainEpoch, p3 []byte, p4 types.TipSetKey) (abi.Randomness, error) `perm:"read"` @@ -370,7 +378,7 @@ type FullNodeStruct struct { StateMarketBalance func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (MarketBalance, error) `perm:"read"` - StateMarketDeals func(p0 context.Context, p1 types.TipSetKey) (map[string]MarketDeal, error) `perm:"read"` + StateMarketDeals func(p0 context.Context, p1 types.TipSetKey) (map[string]*MarketDeal, error) `perm:"read"` StateMarketParticipants func(p0 context.Context, p1 types.TipSetKey) (map[string]MarketBalance, error) `perm:"read"` @@ -384,7 +392,7 @@ type FullNodeStruct struct { StateMinerFaults func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (bitfield.BitField, error) `perm:"read"` - StateMinerInfo func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) `perm:"read"` + StateMinerInfo func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (MinerInfo, error) `perm:"read"` StateMinerInitialPledgeCollateral func(p0 context.Context, p1 address.Address, p2 miner.SectorPreCommitInfo, p3 types.TipSetKey) (types.BigInt, error) `perm:"read"` @@ -414,11 +422,11 @@ type FullNodeStruct struct { StateSearchMsg func(p0 context.Context, p1 types.TipSetKey, p2 cid.Cid, p3 abi.ChainEpoch, p4 bool) (*MsgLookup, error) `perm:"read"` - StateSectorExpiration func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorExpiration, error) `perm:"read"` + StateSectorExpiration func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorExpiration, error) `perm:"read"` StateSectorGetInfo func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"` - StateSectorPartition func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorLocation, error) `perm:"read"` + StateSectorPartition func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorLocation, error) `perm:"read"` StateSectorPreCommitInfo func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` @@ -510,6 +518,8 @@ type GatewayStruct struct { ChainNotify func(p0 context.Context) (<-chan []*HeadChange, error) `` + ChainPutObj func(p0 context.Context, p1 blocks.Block) error `` + ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `` GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) `` @@ -538,7 +548,7 @@ type GatewayStruct struct { StateMarketStorageDeal func(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*MarketDeal, error) `` - StateMinerInfo func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) `` + StateMinerInfo func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (MinerInfo, error) `` StateMinerPower func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*MinerPower, error) `` @@ -677,7 +687,7 @@ type StorageMinerStruct struct { DealsImportData func(p0 context.Context, p1 cid.Cid, p2 string) error `perm:"admin"` - DealsList func(p0 context.Context) ([]MarketDeal, error) `perm:"admin"` + DealsList func(p0 context.Context) ([]*MarketDeal, error) `perm:"admin"` DealsPieceCidBlocklist func(p0 context.Context) ([]cid.Cid, error) `perm:"admin"` @@ -715,7 +725,7 @@ type StorageMinerStruct struct { MarketListDataTransfers func(p0 context.Context) ([]DataTransferChannel, error) `perm:"write"` - MarketListDeals func(p0 context.Context) ([]MarketDeal, error) `perm:"read"` + MarketListDeals func(p0 context.Context) ([]*MarketDeal, error) `perm:"read"` MarketListIncompleteDeals func(p0 context.Context) ([]storagemarket.MinerDeal, error) `perm:"read"` @@ -976,6 +986,17 @@ func (s *ChainIOStub) ChainHasObj(p0 context.Context, p1 cid.Cid) (bool, error) return false, ErrNotSupported } +func (s *ChainIOStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + if s.Internal.ChainPutObj == nil { + return ErrNotSupported + } + return s.Internal.ChainPutObj(p0, p1) +} + +func (s *ChainIOStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + return ErrNotSupported +} + func (s *ChainIOStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { if s.Internal.ChainReadObj == nil { return *new([]byte), ErrNotSupported @@ -1097,17 +1118,6 @@ func (s *CommonStub) Version(p0 context.Context) (APIVersion, error) { return *new(APIVersion), ErrNotSupported } -func (s *FullNodeStruct) BeaconGetEntry(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) { - if s.Internal.BeaconGetEntry == nil { - return nil, ErrNotSupported - } - return s.Internal.BeaconGetEntry(p0, p1) -} - -func (s *FullNodeStub) BeaconGetEntry(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) { - return nil, ErrNotSupported -} - func (s *FullNodeStruct) ChainBlockstoreInfo(p0 context.Context) (map[string]interface{}, error) { if s.Internal.ChainBlockstoreInfo == nil { return *new(map[string]interface{}), ErrNotSupported @@ -1317,6 +1327,17 @@ func (s *FullNodeStub) ChainNotify(p0 context.Context) (<-chan []*HeadChange, er return nil, ErrNotSupported } +func (s *FullNodeStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + if s.Internal.ChainPutObj == nil { + return ErrNotSupported + } + return s.Internal.ChainPutObj(p0, p1) +} + +func (s *FullNodeStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + return ErrNotSupported +} + func (s *FullNodeStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { if s.Internal.ChainReadObj == nil { return *new([]byte), ErrNotSupported @@ -2373,6 +2394,17 @@ func (s *FullNodeStub) StateAccountKey(p0 context.Context, p1 address.Address, p return *new(address.Address), ErrNotSupported } +func (s *FullNodeStruct) StateActorCodeCIDs(p0 context.Context, p1 abinetwork.Version) (map[string]cid.Cid, error) { + if s.Internal.StateActorCodeCIDs == nil { + return *new(map[string]cid.Cid), ErrNotSupported + } + return s.Internal.StateActorCodeCIDs(p0, p1) +} + +func (s *FullNodeStub) StateActorCodeCIDs(p0 context.Context, p1 abinetwork.Version) (map[string]cid.Cid, error) { + return *new(map[string]cid.Cid), ErrNotSupported +} + func (s *FullNodeStruct) StateAllMinerFaults(p0 context.Context, p1 abi.ChainEpoch, p2 types.TipSetKey) ([]*Fault, error) { if s.Internal.StateAllMinerFaults == nil { return *new([]*Fault), ErrNotSupported @@ -2472,6 +2504,17 @@ func (s *FullNodeStub) StateGetActor(p0 context.Context, p1 address.Address, p2 return nil, ErrNotSupported } +func (s *FullNodeStruct) StateGetBeaconEntry(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) { + if s.Internal.StateGetBeaconEntry == nil { + return nil, ErrNotSupported + } + return s.Internal.StateGetBeaconEntry(p0, p1) +} + +func (s *FullNodeStub) StateGetBeaconEntry(p0 context.Context, p1 abi.ChainEpoch) (*types.BeaconEntry, error) { + return nil, ErrNotSupported +} + func (s *FullNodeStruct) StateGetNetworkParams(p0 context.Context) (*NetworkParams, error) { if s.Internal.StateGetNetworkParams == nil { return nil, ErrNotSupported @@ -2571,15 +2614,15 @@ func (s *FullNodeStub) StateMarketBalance(p0 context.Context, p1 address.Address return *new(MarketBalance), ErrNotSupported } -func (s *FullNodeStruct) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]MarketDeal, error) { +func (s *FullNodeStruct) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]*MarketDeal, error) { if s.Internal.StateMarketDeals == nil { - return *new(map[string]MarketDeal), ErrNotSupported + return *new(map[string]*MarketDeal), ErrNotSupported } return s.Internal.StateMarketDeals(p0, p1) } -func (s *FullNodeStub) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]MarketDeal, error) { - return *new(map[string]MarketDeal), ErrNotSupported +func (s *FullNodeStub) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]*MarketDeal, error) { + return *new(map[string]*MarketDeal), ErrNotSupported } func (s *FullNodeStruct) StateMarketParticipants(p0 context.Context, p1 types.TipSetKey) (map[string]MarketBalance, error) { @@ -2648,15 +2691,15 @@ func (s *FullNodeStub) StateMinerFaults(p0 context.Context, p1 address.Address, return *new(bitfield.BitField), ErrNotSupported } -func (s *FullNodeStruct) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) { +func (s *FullNodeStruct) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (MinerInfo, error) { if s.Internal.StateMinerInfo == nil { - return *new(miner.MinerInfo), ErrNotSupported + return *new(MinerInfo), ErrNotSupported } return s.Internal.StateMinerInfo(p0, p1, p2) } -func (s *FullNodeStub) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) { - return *new(miner.MinerInfo), ErrNotSupported +func (s *FullNodeStub) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (MinerInfo, error) { + return *new(MinerInfo), ErrNotSupported } func (s *FullNodeStruct) StateMinerInitialPledgeCollateral(p0 context.Context, p1 address.Address, p2 miner.SectorPreCommitInfo, p3 types.TipSetKey) (types.BigInt, error) { @@ -2813,14 +2856,14 @@ func (s *FullNodeStub) StateSearchMsg(p0 context.Context, p1 types.TipSetKey, p2 return nil, ErrNotSupported } -func (s *FullNodeStruct) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorExpiration, error) { +func (s *FullNodeStruct) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorExpiration, error) { if s.Internal.StateSectorExpiration == nil { return nil, ErrNotSupported } return s.Internal.StateSectorExpiration(p0, p1, p2, p3) } -func (s *FullNodeStub) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorExpiration, error) { +func (s *FullNodeStub) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorExpiration, error) { return nil, ErrNotSupported } @@ -2835,14 +2878,14 @@ func (s *FullNodeStub) StateSectorGetInfo(p0 context.Context, p1 address.Address return nil, ErrNotSupported } -func (s *FullNodeStruct) StateSectorPartition(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorLocation, error) { +func (s *FullNodeStruct) StateSectorPartition(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorLocation, error) { if s.Internal.StateSectorPartition == nil { return nil, ErrNotSupported } return s.Internal.StateSectorPartition(p0, p1, p2, p3) } -func (s *FullNodeStub) StateSectorPartition(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorLocation, error) { +func (s *FullNodeStub) StateSectorPartition(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorLocation, error) { return nil, ErrNotSupported } @@ -3286,6 +3329,17 @@ func (s *GatewayStub) ChainNotify(p0 context.Context) (<-chan []*HeadChange, err return nil, ErrNotSupported } +func (s *GatewayStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + if s.Internal.ChainPutObj == nil { + return ErrNotSupported + } + return s.Internal.ChainPutObj(p0, p1) +} + +func (s *GatewayStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + return ErrNotSupported +} + func (s *GatewayStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { if s.Internal.ChainReadObj == nil { return *new([]byte), ErrNotSupported @@ -3440,15 +3494,15 @@ func (s *GatewayStub) StateMarketStorageDeal(p0 context.Context, p1 abi.DealID, return nil, ErrNotSupported } -func (s *GatewayStruct) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) { +func (s *GatewayStruct) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (MinerInfo, error) { if s.Internal.StateMinerInfo == nil { - return *new(miner.MinerInfo), ErrNotSupported + return *new(MinerInfo), ErrNotSupported } return s.Internal.StateMinerInfo(p0, p1, p2) } -func (s *GatewayStub) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) { - return *new(miner.MinerInfo), ErrNotSupported +func (s *GatewayStub) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (MinerInfo, error) { + return *new(MinerInfo), ErrNotSupported } func (s *GatewayStruct) StateMinerPower(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*MinerPower, error) { @@ -4067,15 +4121,15 @@ func (s *StorageMinerStub) DealsImportData(p0 context.Context, p1 cid.Cid, p2 st return ErrNotSupported } -func (s *StorageMinerStruct) DealsList(p0 context.Context) ([]MarketDeal, error) { +func (s *StorageMinerStruct) DealsList(p0 context.Context) ([]*MarketDeal, error) { if s.Internal.DealsList == nil { - return *new([]MarketDeal), ErrNotSupported + return *new([]*MarketDeal), ErrNotSupported } return s.Internal.DealsList(p0) } -func (s *StorageMinerStub) DealsList(p0 context.Context) ([]MarketDeal, error) { - return *new([]MarketDeal), ErrNotSupported +func (s *StorageMinerStub) DealsList(p0 context.Context) ([]*MarketDeal, error) { + return *new([]*MarketDeal), ErrNotSupported } func (s *StorageMinerStruct) DealsPieceCidBlocklist(p0 context.Context) ([]cid.Cid, error) { @@ -4276,15 +4330,15 @@ func (s *StorageMinerStub) MarketListDataTransfers(p0 context.Context) ([]DataTr return *new([]DataTransferChannel), ErrNotSupported } -func (s *StorageMinerStruct) MarketListDeals(p0 context.Context) ([]MarketDeal, error) { +func (s *StorageMinerStruct) MarketListDeals(p0 context.Context) ([]*MarketDeal, error) { if s.Internal.MarketListDeals == nil { - return *new([]MarketDeal), ErrNotSupported + return *new([]*MarketDeal), ErrNotSupported } return s.Internal.MarketListDeals(p0) } -func (s *StorageMinerStub) MarketListDeals(p0 context.Context) ([]MarketDeal, error) { - return *new([]MarketDeal), ErrNotSupported +func (s *StorageMinerStub) MarketListDeals(p0 context.Context) ([]*MarketDeal, error) { + return *new([]*MarketDeal), ErrNotSupported } func (s *StorageMinerStruct) MarketListIncompleteDeals(p0 context.Context) ([]storagemarket.MinerDeal, error) { diff --git a/api/types.go b/api/types.go index d0b7c7cb9..865ed48a1 100644 --- a/api/types.go +++ b/api/types.go @@ -5,6 +5,8 @@ import ( "fmt" "time" + "github.com/filecoin-project/go-address" + "github.com/libp2p/go-libp2p-core/network" datatransfer "github.com/filecoin-project/go-data-transfer" @@ -286,6 +288,20 @@ type ExportRef struct { DealID retrievalmarket.DealID } +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 +} + type NetworkParams struct { NetworkName dtypes.NetworkName BlockDelaySecs uint64 diff --git a/api/v0api/full.go b/api/v0api/full.go index c1aa69a77..c9b156b71 100644 --- a/api/v0api/full.go +++ b/api/v0api/full.go @@ -3,6 +3,8 @@ package v0api import ( "context" + abinetwork "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" datatransfer "github.com/filecoin-project/go-data-transfer" @@ -11,14 +13,16 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" textselector "github.com/ipld/go-ipld-selector-text-lite" "github.com/libp2p/go-libp2p-core/peer" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/lotus/api" apitypes "github.com/filecoin-project/lotus/api/types" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" marketevents "github.com/filecoin-project/lotus/markets/loggers" "github.com/filecoin-project/lotus/node/modules/dtypes" @@ -109,6 +113,9 @@ type FullNode interface { // ChainDeleteObj deletes node referenced by the given CID ChainDeleteObj(context.Context, cid.Cid) error //perm:admin + // ChainPutObj puts and object into the blockstore + ChainPutObj(context.Context, blocks.Block) error + // ChainHasObj checks if a given CID exists in the chain blockstore. ChainHasObj(context.Context, cid.Cid) (bool, error) //perm:read @@ -416,7 +423,7 @@ type FullNode interface { // StateMinerPower returns the power of the indicated miner StateMinerPower(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) //perm:read // StateMinerInfo returns info about the indicated miner - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) //perm:read + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) //perm:read // StateMinerDeadlines returns all the proving deadlines for the given miner StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error) //perm:read // StateMinerPartitions returns all partitions in the specified deadline @@ -442,9 +449,9 @@ type FullNode interface { // expiration epoch StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) //perm:read // StateSectorExpiration returns epoch at which given sector will expire - StateSectorExpiration(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorExpiration, error) //perm:read + StateSectorExpiration(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*lminer.SectorExpiration, error) //perm:read // StateSectorPartition finds deadline/partition with the specified sector - StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) //perm:read + StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*lminer.SectorLocation, error) //perm:read // StateSearchMsg searches for a message in the chain, and returns its receipt and the tipset where it was executed // // NOTE: If a replacing message is found on chain, this method will return @@ -521,7 +528,7 @@ type FullNode interface { // StateMarketParticipants returns the Escrow and Locked balances of every participant in the Storage Market StateMarketParticipants(context.Context, types.TipSetKey) (map[string]api.MarketBalance, error) //perm:read // StateMarketDeals returns information about every deal in the Storage Market - StateMarketDeals(context.Context, types.TipSetKey) (map[string]api.MarketDeal, error) //perm:read + StateMarketDeals(context.Context, types.TipSetKey) (map[string]*api.MarketDeal, error) //perm:read // StateMarketStorageDeal returns information about the indicated deal StateMarketStorageDeal(context.Context, abi.DealID, types.TipSetKey) (*api.MarketDeal, error) //perm:read // StateLookupID retrieves the ID address of the given address @@ -598,6 +605,8 @@ type FullNode interface { StateVMCirculatingSupplyInternal(context.Context, types.TipSetKey) (api.CirculatingSupply, error) //perm:read // StateNetworkVersion returns the network version at the given tipset StateNetworkVersion(context.Context, types.TipSetKey) (apitypes.NetworkVersion, error) //perm:read + // StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version + StateActorCodeCIDs(context.Context, abinetwork.Version) (map[string]cid.Cid, error) //perm:read // StateGetRandomnessFromTickets is used to sample the chain for randomness. StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) //perm:read diff --git a/api/v0api/gateway.go b/api/v0api/gateway.go index e3ba56899..70994c740 100644 --- a/api/v0api/gateway.go +++ b/api/v0api/gateway.go @@ -3,6 +3,7 @@ package v0api import ( "context" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" "github.com/filecoin-project/go-address" @@ -10,8 +11,8 @@ import ( "github.com/filecoin-project/go-state-types/dline" abinetwork "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" ) @@ -34,6 +35,7 @@ import ( type Gateway interface { ChainHasObj(context.Context, cid.Cid) (bool, error) + ChainPutObj(context.Context, blocks.Block) error ChainHead(ctx context.Context) (*types.TipSet, error) ChainGetBlockMessages(context.Context, cid.Cid) (*api.BlockMessages, error) ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.Message, error) @@ -54,7 +56,7 @@ type Gateway interface { StateLookupID(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MarketBalance, error) StateMarketStorageDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*api.MarketDeal, error) - StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) + StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*dline.Info, error) StateMinerPower(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) StateNetworkVersion(context.Context, types.TipSetKey) (abinetwork.Version, error) diff --git a/api/v0api/proxy_gen.go b/api/v0api/proxy_gen.go index 6ac74904f..65fe996a9 100644 --- a/api/v0api/proxy_gen.go +++ b/api/v0api/proxy_gen.go @@ -11,17 +11,19 @@ import ( "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" abinetwork "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/api" apitypes "github.com/filecoin-project/lotus/api/types" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" marketevents "github.com/filecoin-project/lotus/markets/loggers" "github.com/filecoin-project/lotus/node/modules/dtypes" "github.com/filecoin-project/lotus/node/repo/imports" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" "golang.org/x/xerrors" @@ -73,6 +75,8 @@ type FullNodeStruct struct { ChainNotify func(p0 context.Context) (<-chan []*api.HeadChange, error) `perm:"read"` + ChainPutObj func(p0 context.Context, p1 blocks.Block) error `` + ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `perm:"read"` ChainSetHead func(p0 context.Context, p1 types.TipSetKey) error `perm:"admin"` @@ -251,6 +255,8 @@ type FullNodeStruct struct { StateAccountKey func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (address.Address, error) `perm:"read"` + StateActorCodeCIDs func(p0 context.Context, p1 abinetwork.Version) (map[string]cid.Cid, error) `perm:"read"` + StateAllMinerFaults func(p0 context.Context, p1 abi.ChainEpoch, p2 types.TipSetKey) ([]*api.Fault, error) `perm:"read"` StateCall func(p0 context.Context, p1 *types.Message, p2 types.TipSetKey) (*api.InvocResult, error) `perm:"read"` @@ -285,7 +291,7 @@ type FullNodeStruct struct { StateMarketBalance func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (api.MarketBalance, error) `perm:"read"` - StateMarketDeals func(p0 context.Context, p1 types.TipSetKey) (map[string]api.MarketDeal, error) `perm:"read"` + StateMarketDeals func(p0 context.Context, p1 types.TipSetKey) (map[string]*api.MarketDeal, error) `perm:"read"` StateMarketParticipants func(p0 context.Context, p1 types.TipSetKey) (map[string]api.MarketBalance, error) `perm:"read"` @@ -299,7 +305,7 @@ type FullNodeStruct struct { StateMinerFaults func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (bitfield.BitField, error) `perm:"read"` - StateMinerInfo func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) `perm:"read"` + StateMinerInfo func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (api.MinerInfo, error) `perm:"read"` StateMinerInitialPledgeCollateral func(p0 context.Context, p1 address.Address, p2 miner.SectorPreCommitInfo, p3 types.TipSetKey) (types.BigInt, error) `perm:"read"` @@ -331,11 +337,11 @@ type FullNodeStruct struct { StateSearchMsgLimited func(p0 context.Context, p1 cid.Cid, p2 abi.ChainEpoch) (*api.MsgLookup, error) `perm:"read"` - StateSectorExpiration func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorExpiration, error) `perm:"read"` + StateSectorExpiration func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorExpiration, error) `perm:"read"` StateSectorGetInfo func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"` - StateSectorPartition func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorLocation, error) `perm:"read"` + StateSectorPartition func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorLocation, error) `perm:"read"` StateSectorPreCommitInfo func(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"` @@ -419,6 +425,8 @@ type GatewayStruct struct { ChainNotify func(p0 context.Context) (<-chan []*api.HeadChange, error) `` + ChainPutObj func(p0 context.Context, p1 blocks.Block) error `` + ChainReadObj func(p0 context.Context, p1 cid.Cid) ([]byte, error) `` GasEstimateMessageGas func(p0 context.Context, p1 *types.Message, p2 *api.MessageSendSpec, p3 types.TipSetKey) (*types.Message, error) `` @@ -447,7 +455,7 @@ type GatewayStruct struct { StateMarketStorageDeal func(p0 context.Context, p1 abi.DealID, p2 types.TipSetKey) (*api.MarketDeal, error) `` - StateMinerInfo func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) `` + StateMinerInfo func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (api.MinerInfo, error) `` StateMinerPower func(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*api.MinerPower, error) `` @@ -681,6 +689,17 @@ func (s *FullNodeStub) ChainNotify(p0 context.Context) (<-chan []*api.HeadChange return nil, ErrNotSupported } +func (s *FullNodeStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + if s.Internal.ChainPutObj == nil { + return ErrNotSupported + } + return s.Internal.ChainPutObj(p0, p1) +} + +func (s *FullNodeStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + return ErrNotSupported +} + func (s *FullNodeStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { if s.Internal.ChainReadObj == nil { return *new([]byte), ErrNotSupported @@ -1660,6 +1679,17 @@ func (s *FullNodeStub) StateAccountKey(p0 context.Context, p1 address.Address, p return *new(address.Address), ErrNotSupported } +func (s *FullNodeStruct) StateActorCodeCIDs(p0 context.Context, p1 abinetwork.Version) (map[string]cid.Cid, error) { + if s.Internal.StateActorCodeCIDs == nil { + return *new(map[string]cid.Cid), ErrNotSupported + } + return s.Internal.StateActorCodeCIDs(p0, p1) +} + +func (s *FullNodeStub) StateActorCodeCIDs(p0 context.Context, p1 abinetwork.Version) (map[string]cid.Cid, error) { + return *new(map[string]cid.Cid), ErrNotSupported +} + func (s *FullNodeStruct) StateAllMinerFaults(p0 context.Context, p1 abi.ChainEpoch, p2 types.TipSetKey) ([]*api.Fault, error) { if s.Internal.StateAllMinerFaults == nil { return *new([]*api.Fault), ErrNotSupported @@ -1847,15 +1877,15 @@ func (s *FullNodeStub) StateMarketBalance(p0 context.Context, p1 address.Address return *new(api.MarketBalance), ErrNotSupported } -func (s *FullNodeStruct) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]api.MarketDeal, error) { +func (s *FullNodeStruct) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]*api.MarketDeal, error) { if s.Internal.StateMarketDeals == nil { - return *new(map[string]api.MarketDeal), ErrNotSupported + return *new(map[string]*api.MarketDeal), ErrNotSupported } return s.Internal.StateMarketDeals(p0, p1) } -func (s *FullNodeStub) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]api.MarketDeal, error) { - return *new(map[string]api.MarketDeal), ErrNotSupported +func (s *FullNodeStub) StateMarketDeals(p0 context.Context, p1 types.TipSetKey) (map[string]*api.MarketDeal, error) { + return *new(map[string]*api.MarketDeal), ErrNotSupported } func (s *FullNodeStruct) StateMarketParticipants(p0 context.Context, p1 types.TipSetKey) (map[string]api.MarketBalance, error) { @@ -1924,15 +1954,15 @@ func (s *FullNodeStub) StateMinerFaults(p0 context.Context, p1 address.Address, return *new(bitfield.BitField), ErrNotSupported } -func (s *FullNodeStruct) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) { +func (s *FullNodeStruct) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (api.MinerInfo, error) { if s.Internal.StateMinerInfo == nil { - return *new(miner.MinerInfo), ErrNotSupported + return *new(api.MinerInfo), ErrNotSupported } return s.Internal.StateMinerInfo(p0, p1, p2) } -func (s *FullNodeStub) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) { - return *new(miner.MinerInfo), ErrNotSupported +func (s *FullNodeStub) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (api.MinerInfo, error) { + return *new(api.MinerInfo), ErrNotSupported } func (s *FullNodeStruct) StateMinerInitialPledgeCollateral(p0 context.Context, p1 address.Address, p2 miner.SectorPreCommitInfo, p3 types.TipSetKey) (types.BigInt, error) { @@ -2100,14 +2130,14 @@ func (s *FullNodeStub) StateSearchMsgLimited(p0 context.Context, p1 cid.Cid, p2 return nil, ErrNotSupported } -func (s *FullNodeStruct) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorExpiration, error) { +func (s *FullNodeStruct) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorExpiration, error) { if s.Internal.StateSectorExpiration == nil { return nil, ErrNotSupported } return s.Internal.StateSectorExpiration(p0, p1, p2, p3) } -func (s *FullNodeStub) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorExpiration, error) { +func (s *FullNodeStub) StateSectorExpiration(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorExpiration, error) { return nil, ErrNotSupported } @@ -2122,14 +2152,14 @@ func (s *FullNodeStub) StateSectorGetInfo(p0 context.Context, p1 address.Address return nil, ErrNotSupported } -func (s *FullNodeStruct) StateSectorPartition(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorLocation, error) { +func (s *FullNodeStruct) StateSectorPartition(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorLocation, error) { if s.Internal.StateSectorPartition == nil { return nil, ErrNotSupported } return s.Internal.StateSectorPartition(p0, p1, p2, p3) } -func (s *FullNodeStub) StateSectorPartition(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*miner.SectorLocation, error) { +func (s *FullNodeStub) StateSectorPartition(p0 context.Context, p1 address.Address, p2 abi.SectorNumber, p3 types.TipSetKey) (*lminer.SectorLocation, error) { return nil, ErrNotSupported } @@ -2529,6 +2559,17 @@ func (s *GatewayStub) ChainNotify(p0 context.Context) (<-chan []*api.HeadChange, return nil, ErrNotSupported } +func (s *GatewayStruct) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + if s.Internal.ChainPutObj == nil { + return ErrNotSupported + } + return s.Internal.ChainPutObj(p0, p1) +} + +func (s *GatewayStub) ChainPutObj(p0 context.Context, p1 blocks.Block) error { + return ErrNotSupported +} + func (s *GatewayStruct) ChainReadObj(p0 context.Context, p1 cid.Cid) ([]byte, error) { if s.Internal.ChainReadObj == nil { return *new([]byte), ErrNotSupported @@ -2683,15 +2724,15 @@ func (s *GatewayStub) StateMarketStorageDeal(p0 context.Context, p1 abi.DealID, return nil, ErrNotSupported } -func (s *GatewayStruct) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) { +func (s *GatewayStruct) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (api.MinerInfo, error) { if s.Internal.StateMinerInfo == nil { - return *new(miner.MinerInfo), ErrNotSupported + return *new(api.MinerInfo), ErrNotSupported } return s.Internal.StateMinerInfo(p0, p1, p2) } -func (s *GatewayStub) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (miner.MinerInfo, error) { - return *new(miner.MinerInfo), ErrNotSupported +func (s *GatewayStub) StateMinerInfo(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (api.MinerInfo, error) { + return *new(api.MinerInfo), ErrNotSupported } func (s *GatewayStruct) StateMinerPower(p0 context.Context, p1 address.Address, p2 types.TipSetKey) (*api.MinerPower, error) { diff --git a/api/v0api/v0mocks/mock_full.go b/api/v0api/v0mocks/mock_full.go index 7301b8aec..9fbd57794 100644 --- a/api/v0api/v0mocks/mock_full.go +++ b/api/v0api/v0mocks/mock_full.go @@ -17,22 +17,23 @@ import ( auth "github.com/filecoin-project/go-jsonrpc/auth" abi "github.com/filecoin-project/go-state-types/abi" big "github.com/filecoin-project/go-state-types/big" + miner "github.com/filecoin-project/go-state-types/builtin/v8/miner" + paych "github.com/filecoin-project/go-state-types/builtin/v8/paych" crypto "github.com/filecoin-project/go-state-types/crypto" dline "github.com/filecoin-project/go-state-types/dline" network "github.com/filecoin-project/go-state-types/network" api "github.com/filecoin-project/lotus/api" apitypes "github.com/filecoin-project/lotus/api/types" v0api "github.com/filecoin-project/lotus/api/v0api" - miner "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + miner0 "github.com/filecoin-project/lotus/chain/actors/builtin/miner" types "github.com/filecoin-project/lotus/chain/types" alerting "github.com/filecoin-project/lotus/journal/alerting" marketevents "github.com/filecoin-project/lotus/markets/loggers" dtypes "github.com/filecoin-project/lotus/node/modules/dtypes" imports "github.com/filecoin-project/lotus/node/repo/imports" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" gomock "github.com/golang/mock/gomock" uuid "github.com/google/uuid" + blocks "github.com/ipfs/go-block-format" cid "github.com/ipfs/go-cid" metrics "github.com/libp2p/go-libp2p-core/metrics" network0 "github.com/libp2p/go-libp2p-core/network" @@ -377,6 +378,20 @@ func (mr *MockFullNodeMockRecorder) ChainNotify(arg0 interface{}) *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainNotify", reflect.TypeOf((*MockFullNode)(nil).ChainNotify), arg0) } +// ChainPutObj mocks base method. +func (m *MockFullNode) ChainPutObj(arg0 context.Context, arg1 blocks.Block) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "ChainPutObj", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// ChainPutObj indicates an expected call of ChainPutObj. +func (mr *MockFullNodeMockRecorder) ChainPutObj(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ChainPutObj", reflect.TypeOf((*MockFullNode)(nil).ChainPutObj), arg0, arg1) +} + // ChainReadObj mocks base method. func (m *MockFullNode) ChainReadObj(arg0 context.Context, arg1 cid.Cid) ([]byte, error) { m.ctrl.T.Helper() @@ -2155,6 +2170,21 @@ func (mr *MockFullNodeMockRecorder) StateAccountKey(arg0, arg1, arg2 interface{} return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateAccountKey", reflect.TypeOf((*MockFullNode)(nil).StateAccountKey), arg0, arg1, arg2) } +// StateActorCodeCIDs mocks base method. +func (m *MockFullNode) StateActorCodeCIDs(arg0 context.Context, arg1 network.Version) (map[string]cid.Cid, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "StateActorCodeCIDs", arg0, arg1) + ret0, _ := ret[0].(map[string]cid.Cid) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// StateActorCodeCIDs indicates an expected call of StateActorCodeCIDs. +func (mr *MockFullNodeMockRecorder) StateActorCodeCIDs(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StateActorCodeCIDs", reflect.TypeOf((*MockFullNode)(nil).StateActorCodeCIDs), arg0, arg1) +} + // StateAllMinerFaults mocks base method. func (m *MockFullNode) StateAllMinerFaults(arg0 context.Context, arg1 abi.ChainEpoch, arg2 types.TipSetKey) ([]*api.Fault, error) { m.ctrl.T.Helper() @@ -2411,10 +2441,10 @@ func (mr *MockFullNodeMockRecorder) StateMarketBalance(arg0, arg1, arg2 interfac } // StateMarketDeals mocks base method. -func (m *MockFullNode) StateMarketDeals(arg0 context.Context, arg1 types.TipSetKey) (map[string]api.MarketDeal, error) { +func (m *MockFullNode) StateMarketDeals(arg0 context.Context, arg1 types.TipSetKey) (map[string]*api.MarketDeal, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMarketDeals", arg0, arg1) - ret0, _ := ret[0].(map[string]api.MarketDeal) + ret0, _ := ret[0].(map[string]*api.MarketDeal) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -2516,10 +2546,10 @@ func (mr *MockFullNodeMockRecorder) StateMinerFaults(arg0, arg1, arg2 interface{ } // StateMinerInfo mocks base method. -func (m *MockFullNode) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (miner.MinerInfo, error) { +func (m *MockFullNode) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 types.TipSetKey) (api.MinerInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInfo", arg0, arg1, arg2) - ret0, _ := ret[0].(miner.MinerInfo) + ret0, _ := ret[0].(api.MinerInfo) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -2531,7 +2561,7 @@ func (mr *MockFullNodeMockRecorder) StateMinerInfo(arg0, arg1, arg2 interface{}) } // StateMinerInitialPledgeCollateral mocks base method. -func (m *MockFullNode) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner0.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { +func (m *MockFullNode) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInitialPledgeCollateral", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(big.Int) @@ -2576,7 +2606,7 @@ func (mr *MockFullNodeMockRecorder) StateMinerPower(arg0, arg1, arg2 interface{} } // StateMinerPreCommitDepositForPower mocks base method. -func (m *MockFullNode) StateMinerPreCommitDepositForPower(arg0 context.Context, arg1 address.Address, arg2 miner0.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { +func (m *MockFullNode) StateMinerPreCommitDepositForPower(arg0 context.Context, arg1 address.Address, arg2 miner.SectorPreCommitInfo, arg3 types.TipSetKey) (big.Int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerPreCommitDepositForPower", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(big.Int) @@ -2756,10 +2786,10 @@ func (mr *MockFullNodeMockRecorder) StateSearchMsgLimited(arg0, arg1, arg2 inter } // StateSectorExpiration mocks base method. -func (m *MockFullNode) StateSectorExpiration(arg0 context.Context, arg1 address.Address, arg2 abi.SectorNumber, arg3 types.TipSetKey) (*miner.SectorExpiration, error) { +func (m *MockFullNode) StateSectorExpiration(arg0 context.Context, arg1 address.Address, arg2 abi.SectorNumber, arg3 types.TipSetKey) (*miner0.SectorExpiration, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateSectorExpiration", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(*miner.SectorExpiration) + ret0, _ := ret[0].(*miner0.SectorExpiration) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -2786,10 +2816,10 @@ func (mr *MockFullNodeMockRecorder) StateSectorGetInfo(arg0, arg1, arg2, arg3 in } // StateSectorPartition mocks base method. -func (m *MockFullNode) StateSectorPartition(arg0 context.Context, arg1 address.Address, arg2 abi.SectorNumber, arg3 types.TipSetKey) (*miner.SectorLocation, error) { +func (m *MockFullNode) StateSectorPartition(arg0 context.Context, arg1 address.Address, arg2 abi.SectorNumber, arg3 types.TipSetKey) (*miner0.SectorLocation, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateSectorPartition", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(*miner.SectorLocation) + ret0, _ := ret[0].(*miner0.SectorLocation) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/api/v0api/v1_wrapper.go b/api/v0api/v1_wrapper.go index 769a280ab..d6de6f416 100644 --- a/api/v0api/v1_wrapper.go +++ b/api/v0api/v1_wrapper.go @@ -352,4 +352,8 @@ func (w *WrapperV1Full) ClientQueryAsk(ctx context.Context, p peer.ID, miner add return a.Response, nil } +func (w *WrapperV1Full) BeaconGetEntry(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) { + return w.StateGetBeaconEntry(ctx, epoch) +} + var _ FullNode = &WrapperV1Full{} diff --git a/blockstore/api.go b/blockstore/api.go index dc4c03452..090f53e5a 100644 --- a/blockstore/api.go +++ b/blockstore/api.go @@ -11,6 +11,7 @@ import ( type ChainIO interface { ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainHasObj(context.Context, cid.Cid) (bool, error) + ChainPutObj(context.Context, blocks.Block) error } type apiBlockstore struct { @@ -49,12 +50,18 @@ func (a *apiBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error) { return len(bb), nil } -func (a *apiBlockstore) Put(context.Context, blocks.Block) error { - return xerrors.New("not supported") +func (a *apiBlockstore) Put(ctx context.Context, block blocks.Block) error { + return a.api.ChainPutObj(ctx, block) } -func (a *apiBlockstore) PutMany(context.Context, []blocks.Block) error { - return xerrors.New("not supported") +func (a *apiBlockstore) PutMany(ctx context.Context, blocks []blocks.Block) error { + for _, block := range blocks { + err := a.api.ChainPutObj(ctx, block) + if err != nil { + return err + } + } + return nil } func (a *apiBlockstore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { diff --git a/build/actors/README.md b/build/actors/README.md new file mode 100644 index 000000000..981ad726a --- /dev/null +++ b/build/actors/README.md @@ -0,0 +1,26 @@ +# Bundles + +This directory includes the actors bundles for each release. Each actor bundle is a zstd compressed +tarfile containing one bundle per network type. These tarfiles are subsequently embedded in the +lotus binary. + +## Updating + +To update, run the `./pack.sh` script. For example, the following will pack the [builtin actors release](https://github.com/filecoin-project/builtin-actors/releases) `dev/20220602` into the `v8` tarfile. + +```bash +./pack.sh v8 dev/20220602 +``` + +This will: + +1. Download the actors bundles and pack them into the appropriate tarfile (`$VERSION.tar.zst`). +2. Run `make bundle-gen` in the top-level directory to regenerate the bundle metadata file for _all_ network versions (all `*.tar.zst` files in this directory). + +## Overriding + +To build a bundle, but specify a different release/tag for a specific network, append `$network=$alternative_release` on the command line. For example: + +```bash +./pack.sh v8 dev/20220602 mainnet=v8.0.0 calibrationnet=v8.0.0-rc.1 +``` diff --git a/build/actors/pack.sh b/build/actors/pack.sh new file mode 100755 index 000000000..c2060e67c --- /dev/null +++ b/build/actors/pack.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +NETWORKS=(devnet mainnet caterpillarnet butterflynet testing testing-fake-proofs calibrationnet) + +set -e + +if [[ $# -lt 2 ]]; then + echo "Usage: $0 VERSION RELEASE [NETWORK=RELEASE_OVERRIDE]..." >&2 + echo "expected at least two arguments, an actors version (e.g., v8), an actors release, and any number of release overrides." >&2 + exit 1 +fi + +VERSION="$1" # actors version +RELEASE="$2" # actors release name +RELEASE_OVERRIDES=("${@:3}") + +echo "Downloading bundles for actors version ${VERSION} release ${RELEASE}" +echo "With release overrides ${RELEASE_OVERRIDES[*]}" + +TARGET_FILE="$(pwd)/${VERSION}.tar.zst" +WORKDIR=$(mktemp -d -t "actor-bundles-${VERSION}.XXXXXXXXXX") +trap 'rm -rf -- "$WORKDIR"' EXIT + +encode_release() { + jq -rn --arg release "$1" '$release | @uri' +} + +pushd "${WORKDIR}" +for network in "${NETWORKS[@]}"; do + release="$RELEASE" + # Ideally, we'd use an associative array (map). But that's not supported on macos. + for override in "${RELEASE_OVERRIDES[@]}"; do + if [[ "${network}" = "${override%%=*}" ]]; then + release="${override#*=}" + break + fi + done + encoded_release="$(encode_release "$release")" + echo "Downloading $release for network $network." + wget "https://github.com/filecoin-project/builtin-actors/releases/download/${encoded_release}/builtin-actors-${network}"{.car,.sha256} +done + +echo "Checking the checksums..." + +sha256sum -c -- *.sha256 + +echo "Packing..." + +rm -f -- "$TARGET_FILE" +tar -cf "$TARGET_FILE" --use-compress-program "zstd -19" -- *.car +popd + +echo "Generating metadata..." + +make -C ../../ bundle-gen diff --git a/build/actors/v8.tar.zst b/build/actors/v8.tar.zst new file mode 100644 index 000000000..c4eb857b9 Binary files /dev/null and b/build/actors/v8.tar.zst differ diff --git a/build/bootstrap/butterflynet.pi b/build/bootstrap/butterflynet.pi index 68bd4f74f..919b71aa8 100644 --- a/build/bootstrap/butterflynet.pi +++ b/build/bootstrap/butterflynet.pi @@ -1,2 +1,2 @@ -/dns4/bootstrap-0.butterfly.fildev.network/tcp/1347/p2p/12D3KooWFHDtFx7CVTy4xoCDutVo1cScvSnQjDeaM8UzwVS1qwkh -/dns4/bootstrap-1.butterfly.fildev.network/tcp/1347/p2p/12D3KooWKt8cwpkiumkT8x32c3YFxsPRwhV5J8hCYPn9mhUmcAXt +/dns4/bootstrap-0.butterfly.fildev.network/tcp/1347/p2p/12D3KooWSUZhAY3eyoPUboJ1ZWe4dNPFWTr1EPoDjbTDSAN15uhY +/dns4/bootstrap-1.butterfly.fildev.network/tcp/1347/p2p/12D3KooWDfvNrSRVGWAGbn3sm9C8z98W2x25qCZjaXGHXmGiH24e diff --git a/build/bootstrap/interopnet.pi b/build/bootstrap/interopnet.pi index 923653d94..2e8ab67a9 100644 --- a/build/bootstrap/interopnet.pi +++ b/build/bootstrap/interopnet.pi @@ -1,2 +1,2 @@ -/dns4/bootstrap-0.interop.fildev.network/tcp/1347/p2p/12D3KooWLGPq9JL1xwL6gHok7HSNxtK1Q5kyfg4Hk69ifRPghn4i -/dns4/bootstrap-1.interop.fildev.network/tcp/1347/p2p/12D3KooWFYS1f31zafv8mqqYu8U3hEqYvaZ6avWzYU3BmZdpyH3h +/dns4/bootstrap-0.interop.fildev.network/tcp/1347/p2p/12D3KooWDY249nj6gxSiBTocNBnkbBBvnfPgkxq5SBUVrccjwRnr +/dns4/bootstrap-1.interop.fildev.network/tcp/1347/p2p/12D3KooWCwFsKt4NyoJQk7vjiACXL9LznBWANXKjCebKJ7MHh3h4 diff --git a/build/builtin_actors.go b/build/builtin_actors.go new file mode 100644 index 000000000..39f414c89 --- /dev/null +++ b/build/builtin_actors.go @@ -0,0 +1,263 @@ +package build + +import ( + "archive/tar" + "context" + "embed" + "fmt" + "io" + "os" + "path" + "sort" + "strconv" + "strings" + + "github.com/filecoin-project/lotus/blockstore" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + + "github.com/DataDog/zstd" + "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" + "github.com/ipld/go-car" + "golang.org/x/xerrors" +) + +//go:embed actors/*.tar.zst +var embeddedBuiltinActorReleases embed.FS + +func init() { + if BundleOverrides == nil { + BundleOverrides = make(map[actors.Version]string) + } + for _, av := range actors.Versions { + path := os.Getenv(fmt.Sprintf("LOTUS_BUILTIN_ACTORS_V%d_BUNDLE", av)) + if path == "" { + continue + } + BundleOverrides[actors.Version(av)] = path + } + if err := loadManifests(NetworkBundle); err != nil { + panic(err) + } +} + +// UseNetworkBundle switches to a different network bundle, by name. +func UseNetworkBundle(netw string) error { + if NetworkBundle == netw { + return nil + } + if err := loadManifests(netw); err != nil { + return err + } + NetworkBundle = netw + return nil +} + +func loadManifests(netw string) error { + overridden := make(map[actors.Version]struct{}) + var newMetadata []*BuiltinActorsMetadata + // First, prefer overrides. + for av, path := range BundleOverrides { + root, actorCids, err := readBundleManifestFromFile(path) + if err != nil { + return err + } + newMetadata = append(newMetadata, &BuiltinActorsMetadata{ + Network: netw, + Version: av, + ManifestCid: root, + Actors: actorCids, + }) + overridden[av] = struct{}{} + } + + // Then load embedded bundle metadata. + for _, meta := range EmbeddedBuiltinActorsMetadata { + if meta.Network != netw { + continue + } + if _, ok := overridden[meta.Version]; ok { + continue + } + newMetadata = append(newMetadata, meta) + } + + actors.ClearManifests() + + for _, meta := range newMetadata { + actors.RegisterManifest(meta.Version, meta.ManifestCid, meta.Actors) + } + + return nil +} + +type BuiltinActorsMetadata struct { + Network string + Version actors.Version + ManifestCid cid.Cid + Actors map[string]cid.Cid +} + +// ReadEmbeddedBuiltinActorsMetadata reads the metadata from the embedded built-in actor bundles. +// There should be no need to call this method as the result is cached in the +// `EmbeddedBuiltinActorsMetadata` variable on `make gen`. +func ReadEmbeddedBuiltinActorsMetadata() ([]*BuiltinActorsMetadata, error) { + files, err := embeddedBuiltinActorReleases.ReadDir("actors") + if err != nil { + return nil, xerrors.Errorf("failed to read embedded bundle directory: %s", err) + } + var bundles []*BuiltinActorsMetadata + for _, dirent := range files { + name := dirent.Name() + b, err := readEmbeddedBuiltinActorsMetadata(name) + if err != nil { + return nil, err + } + bundles = append(bundles, b...) + } + // Sort by network, then by bundle. + sort.Slice(bundles, func(i, j int) bool { + if bundles[i].Network == bundles[j].Network { + return bundles[i].Version < bundles[j].Version + } + return bundles[i].Network < bundles[j].Network + }) + return bundles, nil +} + +func readEmbeddedBuiltinActorsMetadata(bundle string) ([]*BuiltinActorsMetadata, error) { + const ( + archiveExt = ".tar.zst" + bundleExt = ".car" + bundlePrefix = "builtin-actors-" + ) + + if !strings.HasPrefix(bundle, "v") { + return nil, xerrors.Errorf("bundle bundle '%q' doesn't start with a 'v'", bundle) + } + if !strings.HasSuffix(bundle, archiveExt) { + return nil, xerrors.Errorf("bundle bundle '%q' doesn't end with '%s'", bundle, archiveExt) + } + version, err := strconv.ParseInt(bundle[1:len(bundle)-len(archiveExt)], 10, 0) + if err != nil { + return nil, xerrors.Errorf("failed to parse actors version from bundle '%q': %s", bundle, err) + } + fi, err := embeddedBuiltinActorReleases.Open(fmt.Sprintf("actors/%s", bundle)) + if err != nil { + return nil, err + } + defer fi.Close() //nolint + + uncompressed := zstd.NewReader(fi) + defer uncompressed.Close() //nolint + + var bundles []*BuiltinActorsMetadata + + tarReader := tar.NewReader(uncompressed) + for { + header, err := tarReader.Next() + switch err { + case io.EOF: + return bundles, nil + case nil: + default: + return nil, err + } + + // Read the network name from the bundle name. + name := path.Base(header.Name) + if !strings.HasSuffix(name, bundleExt) { + return nil, xerrors.Errorf("expected bundle to end with .car: %s", name) + } + if !strings.HasPrefix(name, bundlePrefix) { + return nil, xerrors.Errorf("expected bundle to end with .car: %s", name) + } + name = name[len(bundlePrefix) : len(name)-len(bundleExt)] + + // Load the bundle. + root, actorCids, err := readBundleManifest(tarReader) + if err != nil { + return nil, xerrors.Errorf("error loading builtin actors bundle: %w", err) + } + bundles = append(bundles, &BuiltinActorsMetadata{ + Network: name, + Version: actors.Version(version), + ManifestCid: root, + Actors: actorCids, + }) + } +} + +func readBundleManifestFromFile(path string) (cid.Cid, map[string]cid.Cid, error) { + fi, err := os.Open(path) + if err != nil { + return cid.Undef, nil, err + } + defer fi.Close() //nolint + + return readBundleManifest(fi) +} + +func readBundleManifest(r io.Reader) (cid.Cid, map[string]cid.Cid, error) { + // Load the bundle. + bs := blockstore.NewMemory() + hdr, err := car.LoadCar(context.Background(), bs, r) + if err != nil { + return cid.Undef, nil, xerrors.Errorf("error loading builtin actors bundle: %w", err) + } + + if len(hdr.Roots) != 1 { + return cid.Undef, nil, xerrors.Errorf("expected one root when loading actors bundle, got %d", len(hdr.Roots)) + } + root := hdr.Roots[0] + actorCids, err := actors.ReadManifest(context.Background(), adt.WrapStore(context.Background(), cbor.NewCborStore(bs)), root) + if err != nil { + return cid.Undef, nil, err + } + + // Make sure we have all the actors. + for name, c := range actorCids { + if has, err := bs.Has(context.Background(), c); err != nil { + return cid.Undef, nil, xerrors.Errorf("got an error when checking that the bundle has the actor %q: %w", name, err) + } else if !has { + return cid.Undef, nil, xerrors.Errorf("actor %q missing from bundle", name) + } + } + + return root, actorCids, nil +} + +// GetEmbeddedBuiltinActorsBundle returns the builtin-actors bundle for the given actors version. +func GetEmbeddedBuiltinActorsBundle(version actors.Version) ([]byte, bool) { + fi, err := embeddedBuiltinActorReleases.Open(fmt.Sprintf("actors/v%d.tar.zst", version)) + if err != nil { + return nil, false + } + defer fi.Close() //nolint + + uncompressed := zstd.NewReader(fi) + defer uncompressed.Close() //nolint + + tarReader := tar.NewReader(uncompressed) + targetFileName := fmt.Sprintf("builtin-actors-%s.car", NetworkBundle) + for { + header, err := tarReader.Next() + switch err { + case io.EOF: + return nil, false + case nil: + default: + panic(err) + } + if header.Name != targetFileName { + continue + } + + car, err := io.ReadAll(tarReader) + if err != nil { + panic(err) + } + return car, true + } +} diff --git a/build/builtin_actors_gen.go b/build/builtin_actors_gen.go new file mode 100644 index 000000000..f8d25aa3c --- /dev/null +++ b/build/builtin_actors_gen.go @@ -0,0 +1,128 @@ +// WARNING: This file has automatically been generated + +package build + +import ( + "github.com/ipfs/go-cid" +) + +var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMetadata{{ + Network: "butterflynet", + Version: 8, + ManifestCid: MustParseCid("bafy2bzacedvaarfyh6q3bk4dyzux46ednlace2ckxp5nbyn6mb3da2apqn6sk"), + Actors: map[string]cid.Cid{ + "account": MustParseCid("bafk2bzaceavzeu4gqte7o33vr4htiaapiwpfq6p26tgdkqla2baqhmiqswfso"), + "cron": MustParseCid("bafk2bzacech35onpqxep4yox36k7sr4mj4bch54s3i4b3yyaustrbo5xwfbfs"), + "init": MustParseCid("bafk2bzaceahxin3sf5f6ude5j6we4yeqlg66s5qe4tu7lwp26jcg7yp2ns6hi"), + "multisig": MustParseCid("bafk2bzacectfmzjtniypgl4whm42sws5aupihqgfikwsr7p5yoq3bmqaogldi"), + "paymentchannel": MustParseCid("bafk2bzacecbwu54ce5mjgp2pqxyj6kpn2vlgiu5wv2lj2byjiegxnn3infd5i"), + "reward": MustParseCid("bafk2bzacecskkbhe6c4ud5jt62wg4w7j7shj6xdwoyic74s5y6pgywxxvnw72"), + "storagemarket": MustParseCid("bafk2bzacebycxcwwm7hwhuhpasaskil2kxaqb7tins7azdvvm72rorlciuysi"), + "storageminer": MustParseCid("bafk2bzacecgx3etor5m6lahpmjdwqnryutqe6naiurfhgsju72rd4nqssutbg"), + "storagepower": MustParseCid("bafk2bzaceayvy6xyp5cwtngm457c5hssvihidppgq3o7gy3dlmhgor3yzujoc"), + "system": MustParseCid("bafk2bzacec6xctjxybp7r3kkhase56o6jsaiua7ure5ttu2xfuojt4jhlsoa6"), + "verifiedregistry": MustParseCid("bafk2bzacec2hcqlqcfacylfcrhhliwkisvh4y3adwt47xkf2gdvodwu6ccepc"), + }, +}, { + Network: "calibrationnet", + Version: 8, + ManifestCid: MustParseCid("bafy2bzacedrdn6z3z7xz7lx4wll3tlgktirhllzqxb766dxpaqp3ukxsjfsba"), + Actors: map[string]cid.Cid{ + "account": MustParseCid("bafk2bzacecruossn66xqbeutqx5r4k2kjzgd43frmwd4qkw6haez44ubvvpxo"), + "cron": MustParseCid("bafk2bzaceaxlezmclw5ugldhhtfgvn7yztux45scqik3ez4yhwiqhg5ssib44"), + "init": MustParseCid("bafk2bzaceadyfilb22bcvzvnpzbg2lyg6npmperyq6es2brvzjdh5rmywc4ry"), + "multisig": MustParseCid("bafk2bzacec66wmb4kohuzvuxsulhcgiwju7sqkldwfpmmgw7dbbwgm5l2574q"), + "paymentchannel": MustParseCid("bafk2bzaceblot4pemhfgwb3lceellwrpgxaqkpselzbpqu32maffpopdunlha"), + "reward": MustParseCid("bafk2bzaceayah37uvj7brl5no4gmvmqbmtndh5raywuts7h6tqbgbq2ge7dhu"), + "storagemarket": MustParseCid("bafk2bzacebotg5coqnglzsdrqxtkqk2eq4krxt6zvds3i3vb2yejgxhexl2n6"), + "storageminer": MustParseCid("bafk2bzacea6rabflc7kpwr6y4lzcqsnuahr4zblyq3rhzrrsfceeiw2lufrb4"), + "storagepower": MustParseCid("bafk2bzacecpwr4mynn55bg5hrlns3osvg7sty3rca6zlai3vl52vbbjk7ulfa"), + "system": MustParseCid("bafk2bzaceaqrkllksxv2jsfgjvmuewx5vbzrammw5mdscod6gkdr3ijih2q64"), + "verifiedregistry": MustParseCid("bafk2bzaceaihibfu625lbtzdp3tcftscshrmbgghgrc7kzqhxn4455pycpdkm"), + }, +}, { + Network: "caterpillarnet", + Version: 8, + ManifestCid: MustParseCid("bafy2bzacecsmunz6fzhg53276cixadn6ybhcnzkgbw3la5hf342tfxsdoet26"), + Actors: map[string]cid.Cid{ + "account": MustParseCid("bafk2bzaced6yatl4y2nmqmx2h3btk3np6oelyw2yt57elsb2nfmm33fadzt2g"), + "cron": MustParseCid("bafk2bzacebrujytq4u7g62jbz52gio5k2s6rhruty7nt4eqq7ygitzxuee5zi"), + "init": MustParseCid("bafk2bzacedajw5ptnwfdidv6m4rvd4c2m7dve4lhfbawygl5idkalcxbiiudu"), + "multisig": MustParseCid("bafk2bzaceb3kh5hjh6eebb5236xp7crn2owyyo7irap6sy4ns76uc7om6pxuy"), + "paymentchannel": MustParseCid("bafk2bzacedl5am53e4mtxpzligcycxvmkolfkhfiuavww2dq3ukgaqwowj7vw"), + "reward": MustParseCid("bafk2bzacecbswf242j43cymj3wh7nszawwlofv6z6z4qipb5d32hpxdhxywng"), + "storagemarket": MustParseCid("bafk2bzaceca5ersmg3zxf2cztgktq33bmfjuiqjcjlktwj52xyrpujbdsqvek"), + "storageminer": MustParseCid("bafk2bzacedg2fqaq5udfp3h6cxhywm27dgagxtselfgkyyyunqq362eaxpdm4"), + "storagepower": MustParseCid("bafk2bzaceb3dm2i2q323e6iozo3r6pyded645vvlpf537kga2a3hu5x7abgl4"), + "system": MustParseCid("bafk2bzacebu47th3xerlngqavlipb6cfu2utljkxxzgadc3totogto2tmx2jc"), + "verifiedregistry": MustParseCid("bafk2bzaceci3niq3rmbcmepgn27zvlgci6d5t4dvthx3pbmmx3wcu5elova6i"), + }, +}, { + Network: "devnet", + Version: 8, + ManifestCid: MustParseCid("bafy2bzacedq7tuibavyqxzkq4uybjj7ly22eu42mjkoehwn5d47xfunmtjm4k"), + Actors: map[string]cid.Cid{ + "account": MustParseCid("bafk2bzacea4tlgnp7m6tlldpz3termlwxlnyq24nwd4zdzv4r6nsjuaktuuzc"), + "cron": MustParseCid("bafk2bzacecgrlf3vg3mufwovddlbgclhpnpp3jftr46stssh3crd3pyljc37w"), + "init": MustParseCid("bafk2bzacedarbnovmucppbjkcwsxopludrj5ttmtm7mzfqsugmxdnqevqso7o"), + "multisig": MustParseCid("bafk2bzaced4gcxjwy6garxwfw6y5a2k4jewj4t5nzopjy4qwnimhjtnsgo3ss"), + "paymentchannel": MustParseCid("bafk2bzaceb3isfguytt6cs4xecyoonbhhekmngfbap2msggbwyde7zch3a6w4"), + "reward": MustParseCid("bafk2bzacedn3fkp27ys5dxn4pwqdq2atj2x6cyezxuekdorvjwi7zazirgvgy"), + "storagemarket": MustParseCid("bafk2bzacecw57fpkqesfhi5g3nr4csy4oy7oc42wmwjuis6l7ijniolo4rt2k"), + "storageminer": MustParseCid("bafk2bzacebze3elvppssc6v5457ukszzy6ndrg6xgaojfsqfbbtg3xfwo4rbs"), + "storagepower": MustParseCid("bafk2bzaceb45l6zhgc34n6clz7xnvd7ek55bhw46q25umuje34t6kroix6hh6"), + "system": MustParseCid("bafk2bzacecf7eta2stfd3cnuxzervd33imbvlaqq6b5tsho7pxmhifrybreru"), + "verifiedregistry": MustParseCid("bafk2bzaceaajgtglewgitshgdi2nzrvq7eihjtyqj5yiamesqun2hujl3xev2"), + }, +}, { + Network: "mainnet", + Version: 8, + ManifestCid: MustParseCid("bafy2bzacebogjbpiemi7npzxchgcjjki3tfxon4ims55obfyfleqntteljsea"), + Actors: map[string]cid.Cid{ + "account": MustParseCid("bafk2bzacedudbf7fc5va57t3tmo63snmt3en4iaidv4vo3qlyacbxaa6hlx6y"), + "cron": MustParseCid("bafk2bzacecqb3eolfurehny6yp7tgmapib4ocazo5ilkopjce2c7wc2bcec62"), + "init": MustParseCid("bafk2bzaceaipvjhoxmtofsnv3aj6gj5ida4afdrxa4ewku2hfipdlxpaektlw"), + "multisig": MustParseCid("bafk2bzacebhldfjuy4o5v7amrhp5p2gzv2qo5275jut4adnbyp56fxkwy5fag"), + "paymentchannel": MustParseCid("bafk2bzacebalad3f72wyk7qyilvfjijcwubdspytnyzlrhvn73254gqis44rq"), + "reward": MustParseCid("bafk2bzacecwzzxlgjiavnc3545cqqil3cmq4hgpvfp2crguxy2pl5ybusfsbe"), + "storagemarket": MustParseCid("bafk2bzacediohrxkp2fbsl4yj4jlupjdkgsiwqb4zuezvinhdo2j5hrxco62q"), + "storageminer": MustParseCid("bafk2bzacecgnynvd3tene3bvqoknuspit56canij5bpra6wl4mrq2mxxwriyu"), + "storagepower": MustParseCid("bafk2bzacebjvqva6ppvysn5xpmiqcdfelwbbcxmghx5ww6hr37cgred6dyrpm"), + "system": MustParseCid("bafk2bzacedwq5uppsw7vp55zpj7jdieizirmldceehu6wvombw3ixq2tcq57w"), + "verifiedregistry": MustParseCid("bafk2bzaceb3zbkjz3auizmoln2unmxep7dyfcmsre64vnqfhdyh7rkqfoxlw4"), + }, +}, { + Network: "testing", + Version: 8, + ManifestCid: MustParseCid("bafy2bzacedkjpqx27wgsvfxzuxfvixuxtbpt2y6yo6igcasez6gqiowron776"), + Actors: map[string]cid.Cid{ + "account": MustParseCid("bafk2bzacebmfbtdj5vruje5auacrhhprcjdd6uclhukb7je7t2f6ozfcgqlu2"), + "cron": MustParseCid("bafk2bzacea4gwsbeux7z4yxvpkxpco77iyxijoyqaoikofrxdewunwh3unjem"), + "init": MustParseCid("bafk2bzacecqk6zlwein7tzy7yrrhtj4pzavrkofgpyxvvw5ktr3w4x4ml4lis"), + "multisig": MustParseCid("bafk2bzacea5zp2g6ag5qfuro7zw6kyku2swxs57wjxncaaxbih5iqflqy4ghm"), + "paymentchannel": MustParseCid("bafk2bzaced47dbtbygmfwnyfsp5iihzhhdmnkpuyc5nlnfgc4mkkvlsgvj2do"), + "reward": MustParseCid("bafk2bzacecmcagk32pzdzfg7piobzqhlgla37x3g7jjzyndlz7mqdno2zulfi"), + "storagemarket": MustParseCid("bafk2bzaceballmgd7puoixfwm65f5shi3kzreqdisowtsoufbvduwytydqotw"), + "storageminer": MustParseCid("bafk2bzacebucngwdhxtod2gvv52adtdssafyg43znsoy4omtfkkqe2hbhvxeu"), + "storagepower": MustParseCid("bafk2bzaceakxw5wx3rtqoarrdbzhmxkufg2kx7n34xotzxzacvvbe5iqggmsa"), + "system": MustParseCid("bafk2bzaced6kjkbv7lrb2qwq5we2hqaxc6ztch5p52g27qtjy45zdemsk4b7m"), + "verifiedregistry": MustParseCid("bafk2bzacectzxvtoselhnzsair5nv6k5vokvegnht6z2lfee4p3xexo4kg4m6"), + }, +}, { + Network: "testing-fake-proofs", + Version: 8, + ManifestCid: MustParseCid("bafy2bzacecd3lb5v6tzjylnhnrhexslssyaozy6hogzgpkhztoe76exbrgrug"), + Actors: map[string]cid.Cid{ + "account": MustParseCid("bafk2bzacebmfbtdj5vruje5auacrhhprcjdd6uclhukb7je7t2f6ozfcgqlu2"), + "cron": MustParseCid("bafk2bzacea4gwsbeux7z4yxvpkxpco77iyxijoyqaoikofrxdewunwh3unjem"), + "init": MustParseCid("bafk2bzacebwkqd6e7gdphfzw2kdmbokdh2bly6fvzgfopxzy7quq4l67gmkks"), + "multisig": MustParseCid("bafk2bzacea5zp2g6ag5qfuro7zw6kyku2swxs57wjxncaaxbih5iqflqy4ghm"), + "paymentchannel": MustParseCid("bafk2bzaced47dbtbygmfwnyfsp5iihzhhdmnkpuyc5nlnfgc4mkkvlsgvj2do"), + "reward": MustParseCid("bafk2bzacecmcagk32pzdzfg7piobzqhlgla37x3g7jjzyndlz7mqdno2zulfi"), + "storagemarket": MustParseCid("bafk2bzacecxqgajcaednamgolc6wc3lzbjc6tz5alfrbwqez2y3c372vts6dg"), + "storageminer": MustParseCid("bafk2bzaceaqwxllfycpq6decpsnkqjdeycpysh5acubonjae7u3wciydlkvki"), + "storagepower": MustParseCid("bafk2bzaceddmeolsokbxgcr25cuf2skrobtmmoof3dmqfpcfp33lmw63oikvm"), + "system": MustParseCid("bafk2bzaced6kjkbv7lrb2qwq5we2hqaxc6ztch5p52g27qtjy45zdemsk4b7m"), + "verifiedregistry": MustParseCid("bafk2bzacectzxvtoselhnzsair5nv6k5vokvegnht6z2lfee4p3xexo4kg4m6"), + }, +}} diff --git a/build/builtin_actors_test.go b/build/builtin_actors_test.go new file mode 100644 index 000000000..389de5cbf --- /dev/null +++ b/build/builtin_actors_test.go @@ -0,0 +1,33 @@ +package build_test + +import ( + "testing" + + "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/stretchr/testify/require" +) + +// Test that the embedded metadata is correct. +func TestEmbeddedMetadata(t *testing.T) { + metadata, err := build.ReadEmbeddedBuiltinActorsMetadata() + require.NoError(t, err) + + require.Equal(t, metadata, build.EmbeddedBuiltinActorsMetadata) +} + +// Test that we're registering the manifest correctly. +func TestRegistration(t *testing.T) { + manifestCid, found := actors.GetManifest(actors.Version8) + require.True(t, found) + require.True(t, manifestCid.Defined()) + + for _, key := range actors.GetBuiltinActorsKeys() { + actorCid, found := actors.GetActorCodeID(actors.Version8, key) + require.True(t, found) + name, version, found := actors.GetActorMetaByCode(actorCid) + require.True(t, found) + require.Equal(t, actors.Version8, version) + require.Equal(t, key, name) + } +} diff --git a/build/genesis/butterflynet.car b/build/genesis/butterflynet.car index 6ef5243be..2a23ff147 100644 Binary files a/build/genesis/butterflynet.car and b/build/genesis/butterflynet.car differ diff --git a/build/genesis/interopnet.car b/build/genesis/interopnet.car index 2c7c2a498..4fe69551b 100644 Binary files a/build/genesis/interopnet.car and b/build/genesis/interopnet.car differ diff --git a/build/openrpc/full.json.gz b/build/openrpc/full.json.gz index d1e58b8fa..daa38a923 100644 Binary files a/build/openrpc/full.json.gz and b/build/openrpc/full.json.gz differ diff --git a/build/openrpc/miner.json.gz b/build/openrpc/miner.json.gz index 9aed6fad7..3a260231a 100644 Binary files a/build/openrpc/miner.json.gz and b/build/openrpc/miner.json.gz differ diff --git a/build/openrpc/worker.json.gz b/build/openrpc/worker.json.gz index 710db2123..adf31802b 100644 Binary files a/build/openrpc/worker.json.gz and b/build/openrpc/worker.json.gz differ diff --git a/build/params_2k.go b/build/params_2k.go index 60006cede..c5417a11e 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -11,13 +11,18 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" + + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" ) const BootstrappersFile = "" const GenesisFile = "" -const GenesisNetworkVersion = network.Version15 +var NetworkBundle = "devnet" +var BundleOverrides map[actors.Version]string + +const GenesisNetworkVersion = network.Version16 var UpgradeBreezeHeight = abi.ChainEpoch(-1) @@ -48,6 +53,7 @@ var UpgradeHyperdriveHeight = abi.ChainEpoch(-16) var UpgradeChocolateHeight = abi.ChainEpoch(-17) var UpgradeOhSnapHeight = abi.ChainEpoch(-18) +var UpgradeSkyrHeight = abi.ChainEpoch(-19) var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, @@ -99,6 +105,7 @@ func init() { UpgradeHyperdriveHeight = getUpgradeHeight("LOTUS_HYPERDRIVE_HEIGHT", UpgradeHyperdriveHeight) UpgradeChocolateHeight = getUpgradeHeight("LOTUS_CHOCOLATE_HEIGHT", UpgradeChocolateHeight) UpgradeOhSnapHeight = getUpgradeHeight("LOTUS_OHSNAP_HEIGHT", UpgradeOhSnapHeight) + UpgradeSkyrHeight = getUpgradeHeight("LOTUS_SKYR_HEIGHT", UpgradeSkyrHeight) BuildType |= Build2k diff --git a/build/params_butterfly.go b/build/params_butterfly.go index d74e17305..b5fa7c8a8 100644 --- a/build/params_butterfly.go +++ b/build/params_butterfly.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" "github.com/ipfs/go-cid" @@ -16,7 +17,10 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, } -const GenesisNetworkVersion = network.Version14 +const GenesisNetworkVersion = network.Version15 + +var NetworkBundle = "butterflynet" +var BundleOverrides map[actors.Version]string const BootstrappersFile = "butterflynet.pi" const GenesisFile = "butterflynet.car" @@ -42,7 +46,9 @@ const UpgradeTurboHeight = -15 const UpgradeHyperdriveHeight = -16 const UpgradeChocolateHeight = -17 -const UpgradeOhSnapHeight = 240 +const UpgradeOhSnapHeight = -18 + +const UpgradeSkyrHeight = abi.ChainEpoch(50) var SupportedProofTypes = []abi.RegisteredSealProof{ abi.RegisteredSealProof_StackedDrg512MiBV1, diff --git a/build/params_calibnet.go b/build/params_calibnet.go index 5ff8bd853..ef56d796c 100644 --- a/build/params_calibnet.go +++ b/build/params_calibnet.go @@ -7,6 +7,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" "github.com/ipfs/go-cid" @@ -18,6 +19,9 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ const GenesisNetworkVersion = network.Version0 +var NetworkBundle = "calibrationnet" +var BundleOverrides map[actors.Version]string + const BootstrappersFile = "calibnet.pi" const GenesisFile = "calibnet.car" @@ -57,6 +61,9 @@ const UpgradeChocolateHeight = 312746 // 2022-02-10T19:23:00Z const UpgradeOhSnapHeight = 682006 +// 2022-06-16T17:30:00Z +const UpgradeSkyrHeight = 1044660 + var SupportedProofTypes = []abi.RegisteredSealProof{ abi.RegisteredSealProof_StackedDrg32GiBV1, abi.RegisteredSealProof_StackedDrg64GiBV1, diff --git a/build/params_interop.go b/build/params_interop.go index ad051570c..bc5098f22 100644 --- a/build/params_interop.go +++ b/build/params_interop.go @@ -7,19 +7,22 @@ import ( "os" "strconv" - "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/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "github.com/ipfs/go-cid" ) +var NetworkBundle = "caterpillarnet" +var BundleOverrides map[actors.Version]string + const BootstrappersFile = "interopnet.pi" const GenesisFile = "interopnet.car" -const GenesisNetworkVersion = network.Version13 +const GenesisNetworkVersion = network.Version15 var UpgradeBreezeHeight = abi.ChainEpoch(-1) @@ -48,6 +51,7 @@ var UpgradeTurboHeight = abi.ChainEpoch(-15) var UpgradeHyperdriveHeight = abi.ChainEpoch(-16) var UpgradeChocolateHeight = abi.ChainEpoch(-17) var UpgradeOhSnapHeight = abi.ChainEpoch(-18) +var UpgradeSkyrHeight = abi.ChainEpoch(100) var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, @@ -98,6 +102,9 @@ func init() { UpgradeNorwegianHeight = getUpgradeHeight("LOTUS_NORWEGIAN_HEIGHT", UpgradeNorwegianHeight) UpgradeTurboHeight = getUpgradeHeight("LOTUS_ACTORSV4_HEIGHT", UpgradeTurboHeight) UpgradeHyperdriveHeight = getUpgradeHeight("LOTUS_HYPERDRIVE_HEIGHT", UpgradeHyperdriveHeight) + UpgradeChocolateHeight = getUpgradeHeight("LOTUS_CHOCOLATE_HEIGHT", UpgradeChocolateHeight) + UpgradeOhSnapHeight = getUpgradeHeight("LOTUS_OHSNAP_HEIGHT", UpgradeOhSnapHeight) + UpgradeSkyrHeight = getUpgradeHeight("LOTUS_SKYR_HEIGHT", UpgradeSkyrHeight) BuildType |= BuildInteropnet SetAddressNetwork(address.Testnet) diff --git a/build/params_mainnet.go b/build/params_mainnet.go index 72e25f2fb..6df302e1a 100644 --- a/build/params_mainnet.go +++ b/build/params_mainnet.go @@ -1,5 +1,5 @@ -//go:build !debug && !2k && !testground && !calibnet && !nerpanet && !butterflynet && !interopnet -// +build !debug,!2k,!testground,!calibnet,!nerpanet,!butterflynet,!interopnet +//go:build !debug && !2k && !testground && !calibnet && !butterflynet && !interopnet +// +build !debug,!2k,!testground,!calibnet,!butterflynet,!interopnet package build @@ -8,6 +8,7 @@ import ( "os" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -19,6 +20,11 @@ var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ UpgradeSmokeHeight: DrandMainnet, } +var NetworkBundle = "mainnet" + +// NOTE: DO NOT change this unless you REALLY know what you're doing. This is consensus critical. +var BundleOverrides map[actors.Version]string + const GenesisNetworkVersion = network.Version0 const BootstrappersFile = "mainnet.pi" @@ -68,7 +74,10 @@ const UpgradeHyperdriveHeight = 892800 const UpgradeChocolateHeight = 1231620 // 2022-03-01T15:00:00Z -var UpgradeOhSnapHeight = abi.ChainEpoch(1594680) +const UpgradeOhSnapHeight = 1594680 + +// 2022-07-06T14:00:00Z +var UpgradeSkyrHeight = abi.ChainEpoch(1960320) var SupportedProofTypes = []abi.RegisteredSealProof{ abi.RegisteredSealProof_StackedDrg32GiBV1, @@ -83,8 +92,8 @@ func init() { SetAddressNetwork(address.Mainnet) } - if os.Getenv("LOTUS_DISABLE_SNAPDEALS") == "1" { - UpgradeOhSnapHeight = math.MaxInt64 + if os.Getenv("LOTUS_DISABLE_SKYR") == "1" { + UpgradeSkyrHeight = math.MaxInt64 } Devnet = false diff --git a/build/params_nerpanet.go b/build/params_nerpanet.go deleted file mode 100644 index 4621a7271..000000000 --- a/build/params_nerpanet.go +++ /dev/null @@ -1,93 +0,0 @@ -//go:build nerpanet -// +build nerpanet - -package build - -import ( - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/chain/actors/policy" - "github.com/ipfs/go-cid" - - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" -) - -var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ - 0: DrandMainnet, -} - -const GenesisNetworkVersion = network.Version0 - -const BootstrappersFile = "nerpanet.pi" -const GenesisFile = "nerpanet.car" - -const UpgradeBreezeHeight = -1 -const BreezeGasTampingDuration = 0 - -const UpgradeSmokeHeight = -1 - -const UpgradeIgnitionHeight = -2 -const UpgradeRefuelHeight = -3 - -const UpgradeLiftoffHeight = -5 - -const UpgradeAssemblyHeight = 30 // critical: the network can bootstrap from v1 only -const UpgradeTapeHeight = 60 - -const UpgradeKumquatHeight = 90 - -const UpgradeCalicoHeight = 100 -const UpgradePersianHeight = UpgradeCalicoHeight + (builtin2.EpochsInHour * 1) - -const UpgradeClausHeight = 250 - -const UpgradeOrangeHeight = 300 - -const UpgradeTrustHeight = 600 -const UpgradeNorwegianHeight = 201000 -const UpgradeTurboHeight = 203000 -const UpgradeHyperdriveHeight = 379178 - -const UpgradeChocolateHeight = 999999999 - -var SupportedProofTypes = []abi.RegisteredSealProof{ - abi.RegisteredSealProof_StackedDrg512MiBV1, - abi.RegisteredSealProof_StackedDrg32GiBV1, - abi.RegisteredSealProof_StackedDrg64GiBV1, -} - -// Minimum block production power is set to 4 TiB -// Rationale is to discourage small-scale miners from trying to take over the network -// One needs to invest in ~2.3x the compute to break consensus, making it not worth it -// -// DOWNSIDE: the fake-seals need to be kept alive/protected, otherwise network will seize -// -var ConsensusMinerMinPower = abi.NewStoragePower(4 << 40) -var MinVerifiedDealSize = abi.NewStoragePower(1 << 20) - -// Lower the most time-consuming parts of PoRep -var PreCommitChallengeDelay = abi.ChainEpoch(10) - -func init() { - policy.SetSupportedProofTypes(SupportedProofTypes...) - policy.SetConsensusMinerMinPower(ConsensusMinerMinPower) - policy.SetMinVerifiedDealSize(MinVerifiedDealSize) - policy.SetPreCommitChallengeDelay(PreCommitChallengeDelay) - - // TODO - make this a variable - //miner.WPoStChallengeLookback = abi.ChainEpoch(2) - - Devnet = false - - BuildType = BuildNerpanet - -} - -const BlockDelaySecs = uint64(builtin2.EpochDurationSeconds) - -const PropagationDelaySecs = uint64(6) - -// BootstrapPeerThreshold is the minimum number peers we need to track for a sync worker to start -const BootstrapPeerThreshold = 4 - -var WhitelistedBlock = cid.Undef diff --git a/build/params_shared_vals.go b/build/params_shared_vals.go index 704c84639..d8d0a5382 100644 --- a/build/params_shared_vals.go +++ b/build/params_shared_vals.go @@ -34,7 +34,7 @@ const NewestNetworkVersion = network.Version{{.latestNetworkVersion}} /* inline-gen start */ -const NewestNetworkVersion = network.Version15 +const NewestNetworkVersion = network.Version16 /* inline-gen end */ diff --git a/build/params_testground.go b/build/params_testground.go index 46e90f494..3123a3bd0 100644 --- a/build/params_testground.go +++ b/build/params_testground.go @@ -17,6 +17,7 @@ import ( builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/policy" ) @@ -106,12 +107,15 @@ var ( UpgradeHyperdriveHeight abi.ChainEpoch = -15 UpgradeChocolateHeight abi.ChainEpoch = -16 UpgradeOhSnapHeight abi.ChainEpoch = -17 + UpgradeSkyrHeight abi.ChainEpoch = -18 DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, } GenesisNetworkVersion = network.Version0 + NetworkBundle = "devnet" + BundleOverrides map[actors.Version]string NewestNetworkVersion = network.Version15 ActorUpgradeNetworkVersion = network.Version15 diff --git a/build/version.go b/build/version.go index 9725d199e..e59313127 100644 --- a/build/version.go +++ b/build/version.go @@ -37,7 +37,7 @@ func BuildTypeString() string { } // BuildVersion is the local build version -const BuildVersion = "1.15.3" +const BuildVersion = "1.16.0" func UserVersion() string { if os.Getenv("LOTUS_VERSION_IGNORE_COMMIT") == "1" { diff --git a/chain/actors/agen/main.go b/chain/actors/agen/main.go index 9a3b8fd20..d07c039dd 100644 --- a/chain/actors/agen/main.go +++ b/chain/actors/agen/main.go @@ -3,6 +3,7 @@ package main import ( "bytes" "fmt" + "go/format" "io/ioutil" "os" "path/filepath" @@ -77,7 +78,12 @@ func generateAdapters() error { return err } - if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("%s.go", act)), b.Bytes(), 0666); err != nil { + fmted, err := format.Source(b.Bytes()) + if err != nil { + return err + } + + if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("%s.go", act)), fmted, 0666); err != nil { return err } } diff --git a/chain/actors/builtin/account/account.go b/chain/actors/builtin/account/account.go index 57ea510bb..04bdc3920 100644 --- a/chain/actors/builtin/account/account.go +++ b/chain/actors/builtin/account/account.go @@ -6,10 +6,8 @@ import ( "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/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" @@ -25,42 +23,26 @@ import ( 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/go-state-types/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 +var Methods = builtin8.MethodsAccount func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.AccountKey { + return nil, xerrors.Errorf("actor code is not account: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.AccountActorCodeID: @@ -85,6 +67,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -112,39 +95,13 @@ func MakeState(store adt.Store, av actors.Version, addr address.Address) (State, case actors.Version7: return make7(store, addr) + case actors.Version8: + return make8(store, addr) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.AccountActorCodeID, nil - - case actors.Version2: - return builtin2.AccountActorCodeID, nil - - case actors.Version3: - return builtin3.AccountActorCodeID, nil - - case actors.Version4: - return builtin4.AccountActorCodeID, nil - - case actors.Version5: - return builtin5.AccountActorCodeID, nil - - case actors.Version6: - return builtin6.AccountActorCodeID, nil - - case actors.Version7: - return builtin7.AccountActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/account/actor.go.template b/chain/actors/builtin/account/actor.go.template index 53962cc94..7aff20d42 100644 --- a/chain/actors/builtin/account/actor.go.template +++ b/chain/actors/builtin/account/actor.go.template @@ -6,32 +6,45 @@ import ( "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/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{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 +var Methods = builtin{{.latestVersion}}.MethodsAccount func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.AccountKey { + return nil, xerrors.Errorf("actor code is not account: %s", name) + } + + switch av { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.AccountActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.AccountActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -45,17 +58,6 @@ func MakeState(store adt.Store, av actors.Version, addr address.Address) (State, return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.AccountActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/account/state.go.template b/chain/actors/builtin/account/state.go.template index 5be262ece..93e7dc0db 100644 --- a/chain/actors/builtin/account/state.go.template +++ b/chain/actors/builtin/account/state.go.template @@ -6,7 +6,11 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" +{{if (le .v 7)}} account{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/account" +{{else}} + account{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}account" +{{end}} ) var _ State = (*state{{.v}})(nil) diff --git a/chain/actors/builtin/account/v8.go b/chain/actors/builtin/account/v8.go new file mode 100644 index 000000000..d8ef52c00 --- /dev/null +++ b/chain/actors/builtin/account/v8.go @@ -0,0 +1,40 @@ +package account + +import ( + "github.com/filecoin-project/go-address" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + account8 "github.com/filecoin-project/go-state-types/builtin/v8/account" +) + +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, addr address.Address) (State, error) { + out := state8{store: store} + out.State = account8.State{Address: addr} + return &out, nil +} + +type state8 struct { + account8.State + store adt.Store +} + +func (s *state8) PubkeyAddress() (address.Address, error) { + return s.Address, nil +} + +func (s *state8) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/builtin.go b/chain/actors/builtin/builtin.go index febbca479..d62fae462 100644 --- a/chain/actors/builtin/builtin.go +++ b/chain/actors/builtin/builtin.go @@ -1,133 +1,76 @@ package builtin import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/ipfs/go-cid" "golang.org/x/xerrors" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - smoothing2 "github.com/filecoin-project/specs-actors/v2/actors/util/smoothing" builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" - smoothing3 "github.com/filecoin-project/specs-actors/v3/actors/util/smoothing" builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" - smoothing4 "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing" builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - smoothing5 "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" - smoothing6 "github.com/filecoin-project/specs-actors/v6/actors/util/smoothing" 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" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/cbor" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/proof" - "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/chain/actors" - miner7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/miner" - proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" + miner8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" + smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing" ) -var SystemActorAddr = builtin7.SystemActorAddr -var BurntFundsActorAddr = builtin7.BurntFundsActorAddr -var CronActorAddr = builtin7.CronActorAddr +var SystemActorAddr = builtin.SystemActorAddr +var BurntFundsActorAddr = builtin.BurntFundsActorAddr +var CronActorAddr = builtin.CronActorAddr var SaftAddress = makeAddress("t0122") var ReserveAddress = makeAddress("t090") var RootVerifierAddress = makeAddress("t080") var ( - ExpectedLeadersPerEpoch = builtin7.ExpectedLeadersPerEpoch + ExpectedLeadersPerEpoch = builtin.ExpectedLeadersPerEpoch ) const ( - EpochDurationSeconds = builtin7.EpochDurationSeconds - EpochsInDay = builtin7.EpochsInDay - SecondsInDay = builtin7.SecondsInDay + EpochDurationSeconds = builtin.EpochDurationSeconds + EpochsInDay = builtin.EpochsInDay + SecondsInDay = builtin.SecondsInDay ) const ( - MethodSend = builtin7.MethodSend - MethodConstructor = builtin7.MethodConstructor + MethodSend = builtin.MethodSend + MethodConstructor = builtin.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 = proof7.SectorInfo -type ExtendedSectorInfo = proof7.ExtendedSectorInfo -type PoStProof = proof7.PoStProof -type FilterEstimate = smoothing0.FilterEstimate +type SectorInfo = proof.SectorInfo +type ExtendedSectorInfo = proof.ExtendedSectorInfo +type PoStProof = proof.PoStProof +type FilterEstimate = smoothingtypes.FilterEstimate func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower { - return miner7.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) -} - -func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate { - - return (FilterEstimate)(v0) //nolint:unconvert - -} - -func FromV2FilterEstimate(v2 smoothing2.FilterEstimate) FilterEstimate { - - return (FilterEstimate)(v2) - -} - -func FromV3FilterEstimate(v3 smoothing3.FilterEstimate) FilterEstimate { - - return (FilterEstimate)(v3) - -} - -func FromV4FilterEstimate(v4 smoothing4.FilterEstimate) FilterEstimate { - - return (FilterEstimate)(v4) - -} - -func FromV5FilterEstimate(v5 smoothing5.FilterEstimate) FilterEstimate { - - return (FilterEstimate)(v5) - -} - -func FromV6FilterEstimate(v6 smoothing6.FilterEstimate) FilterEstimate { - - return (FilterEstimate)(v6) - -} - -func FromV7FilterEstimate(v7 smoothing7.FilterEstimate) FilterEstimate { - - return (FilterEstimate)(v7) - -} - -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, xerrors.Errorf("unknown actor code %s", act.Code) - } - return loader(store, act.Head) + return miner8.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) } 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): @@ -151,12 +94,19 @@ func ActorNameByCode(c cid.Cid) string { case builtin7.IsBuiltinActor(c): return builtin7.ActorNameByCode(c) + case builtin8.IsBuiltinActor(c): + return builtin8.ActorNameByCode(c) + default: return "" } } func IsBuiltinActor(c cid.Cid) bool { + _, _, ok := actors.GetActorMetaByCode(c) + if ok { + return true + } if builtin0.IsBuiltinActor(c) { return true @@ -189,7 +139,44 @@ func IsBuiltinActor(c cid.Cid) bool { return false } +func GetAccountActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.AccountKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.AccountActorCodeID, nil + + case actors.Version2: + return builtin2.AccountActorCodeID, nil + + case actors.Version3: + return builtin3.AccountActorCodeID, nil + + case actors.Version4: + return builtin4.AccountActorCodeID, nil + + case actors.Version5: + return builtin5.AccountActorCodeID, nil + + case actors.Version6: + return builtin6.AccountActorCodeID, nil + + case actors.Version7: + return builtin7.AccountActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + func IsAccountActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == "account" + } if c == builtin0.AccountActorCodeID { return true @@ -222,7 +209,143 @@ func IsAccountActor(c cid.Cid) bool { return false } +func GetCronActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.CronKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.CronActorCodeID, nil + + case actors.Version2: + return builtin2.CronActorCodeID, nil + + case actors.Version3: + return builtin3.CronActorCodeID, nil + + case actors.Version4: + return builtin4.CronActorCodeID, nil + + case actors.Version5: + return builtin5.CronActorCodeID, nil + + case actors.Version6: + return builtin6.CronActorCodeID, nil + + case actors.Version7: + return builtin7.CronActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetInitActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.InitKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.InitActorCodeID, nil + + case actors.Version2: + return builtin2.InitActorCodeID, nil + + case actors.Version3: + return builtin3.InitActorCodeID, nil + + case actors.Version4: + return builtin4.InitActorCodeID, nil + + case actors.Version5: + return builtin5.InitActorCodeID, nil + + case actors.Version6: + return builtin6.InitActorCodeID, nil + + case actors.Version7: + return builtin7.InitActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetMarketActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.MarketKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.StorageMarketActorCodeID, nil + + case actors.Version2: + return builtin2.StorageMarketActorCodeID, nil + + case actors.Version3: + return builtin3.StorageMarketActorCodeID, nil + + case actors.Version4: + return builtin4.StorageMarketActorCodeID, nil + + case actors.Version5: + return builtin5.StorageMarketActorCodeID, nil + + case actors.Version6: + return builtin6.StorageMarketActorCodeID, nil + + case actors.Version7: + return builtin7.StorageMarketActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetMinerActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.MinerKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.StorageMinerActorCodeID, nil + + case actors.Version2: + return builtin2.StorageMinerActorCodeID, nil + + case actors.Version3: + return builtin3.StorageMinerActorCodeID, nil + + case actors.Version4: + return builtin4.StorageMinerActorCodeID, nil + + case actors.Version5: + return builtin5.StorageMinerActorCodeID, nil + + case actors.Version6: + return builtin6.StorageMinerActorCodeID, nil + + case actors.Version7: + return builtin7.StorageMinerActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + func IsStorageMinerActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == actors.MinerKey + } if c == builtin0.StorageMinerActorCodeID { return true @@ -255,7 +378,44 @@ func IsStorageMinerActor(c cid.Cid) bool { return false } +func GetMultisigActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.MultisigKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.MultisigActorCodeID, nil + + case actors.Version2: + return builtin2.MultisigActorCodeID, nil + + case actors.Version3: + return builtin3.MultisigActorCodeID, nil + + case actors.Version4: + return builtin4.MultisigActorCodeID, nil + + case actors.Version5: + return builtin5.MultisigActorCodeID, nil + + case actors.Version6: + return builtin6.MultisigActorCodeID, nil + + case actors.Version7: + return builtin7.MultisigActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + func IsMultisigActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == actors.MultisigKey + } if c == builtin0.MultisigActorCodeID { return true @@ -288,7 +448,44 @@ func IsMultisigActor(c cid.Cid) bool { return false } +func GetPaymentChannelActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.PaychKey); ok { + return c, nil + } + + 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, xerrors.Errorf("unknown actor version %d", av) +} + func IsPaymentChannelActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == "paymentchannel" + } if c == builtin0.PaymentChannelActorCodeID { return true @@ -321,6 +518,138 @@ func IsPaymentChannelActor(c cid.Cid) bool { return false } +func GetPowerActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.PowerKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.StoragePowerActorCodeID, nil + + case actors.Version2: + return builtin2.StoragePowerActorCodeID, nil + + case actors.Version3: + return builtin3.StoragePowerActorCodeID, nil + + case actors.Version4: + return builtin4.StoragePowerActorCodeID, nil + + case actors.Version5: + return builtin5.StoragePowerActorCodeID, nil + + case actors.Version6: + return builtin6.StoragePowerActorCodeID, nil + + case actors.Version7: + return builtin7.StoragePowerActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetRewardActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.RewardKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.RewardActorCodeID, nil + + case actors.Version2: + return builtin2.RewardActorCodeID, nil + + case actors.Version3: + return builtin3.RewardActorCodeID, nil + + case actors.Version4: + return builtin4.RewardActorCodeID, nil + + case actors.Version5: + return builtin5.RewardActorCodeID, nil + + case actors.Version6: + return builtin6.RewardActorCodeID, nil + + case actors.Version7: + return builtin7.RewardActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetSystemActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.SystemKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.SystemActorCodeID, nil + + case actors.Version2: + return builtin2.SystemActorCodeID, nil + + case actors.Version3: + return builtin3.SystemActorCodeID, nil + + case actors.Version4: + return builtin4.SystemActorCodeID, nil + + case actors.Version5: + return builtin5.SystemActorCodeID, nil + + case actors.Version6: + return builtin6.SystemActorCodeID, nil + + case actors.Version7: + return builtin7.SystemActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetVerifregActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.VerifregKey); ok { + return c, nil + } + + switch av { + + case actors.Version0: + return builtin0.VerifiedRegistryActorCodeID, nil + + case actors.Version2: + return builtin2.VerifiedRegistryActorCodeID, nil + + case actors.Version3: + return builtin3.VerifiedRegistryActorCodeID, nil + + case actors.Version4: + return builtin4.VerifiedRegistryActorCodeID, nil + + case actors.Version5: + return builtin5.VerifiedRegistryActorCodeID, nil + + case actors.Version6: + return builtin6.VerifiedRegistryActorCodeID, nil + + case actors.Version7: + return builtin7.VerifiedRegistryActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + 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 f5d5eb77b..ef4dcef39 100644 --- a/chain/actors/builtin/builtin.go.template +++ b/chain/actors/builtin/builtin.go.template @@ -1,140 +1,341 @@ package builtin import ( + "fmt" + "github.com/filecoin-project/go-address" "github.com/ipfs/go-cid" "golang.org/x/xerrors" - {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" - smoothing{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/util/smoothing" - {{end}} +{{range .versions}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" +{{end}} "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/cbor" + "github.com/filecoin-project/go-state-types/proof" + "github.com/filecoin-project/go-state-types/builtin" - "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/chain/actors" - miner{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/miner" - proof{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/runtime/proof" + miner{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin/v8/miner" + smoothingtypes "github.com/filecoin-project/go-state-types/builtin/v8/util/smoothing" ) -var SystemActorAddr = builtin{{.latestVersion}}.SystemActorAddr -var BurntFundsActorAddr = builtin{{.latestVersion}}.BurntFundsActorAddr -var CronActorAddr = builtin{{.latestVersion}}.CronActorAddr +var SystemActorAddr = builtin.SystemActorAddr +var BurntFundsActorAddr = builtin.BurntFundsActorAddr +var CronActorAddr = builtin.CronActorAddr var SaftAddress = makeAddress("t0122") var ReserveAddress = makeAddress("t090") var RootVerifierAddress = makeAddress("t080") var ( - ExpectedLeadersPerEpoch = builtin{{.latestVersion}}.ExpectedLeadersPerEpoch + ExpectedLeadersPerEpoch = builtin.ExpectedLeadersPerEpoch ) const ( - EpochDurationSeconds = builtin{{.latestVersion}}.EpochDurationSeconds - EpochsInDay = builtin{{.latestVersion}}.EpochsInDay - SecondsInDay = builtin{{.latestVersion}}.SecondsInDay + EpochDurationSeconds = builtin.EpochDurationSeconds + EpochsInDay = builtin.EpochsInDay + SecondsInDay = builtin.SecondsInDay ) const ( - MethodSend = builtin{{.latestVersion}}.MethodSend - MethodConstructor = builtin{{.latestVersion}}.MethodConstructor + MethodSend = builtin.MethodSend + MethodConstructor = builtin.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 +type SectorInfo = proof.SectorInfo +type ExtendedSectorInfo = proof.ExtendedSectorInfo +type PoStProof = proof.PoStProof +type FilterEstimate = smoothingtypes.FilterEstimate func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower { return miner{{.latestVersion}}.QAPowerForWeight(size, duration, dealWeight, verifiedWeight) } -{{range .versions}} - func FromV{{.}}FilterEstimate(v{{.}} smoothing{{.}}.FilterEstimate) FilterEstimate { - {{if (eq . 0)}} - return (FilterEstimate)(v{{.}}) //nolint:unconvert - {{else}} - return (FilterEstimate)(v{{.}}) - {{end}} - } -{{end}} - -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, xerrors.Errorf("unknown actor code %s", act.Code) - } - return loader(store, act.Head) -} - func ActorNameByCode(c cid.Cid) string { + if name, version, ok := actors.GetActorMetaByCode(c); ok { + return fmt.Sprintf("fil/%d/%s", version, name) + } + switch { - {{range .versions}} - case builtin{{.}}.IsBuiltinActor(c): - return builtin{{.}}.ActorNameByCode(c) - {{end}} + {{range .versions}} + case builtin{{.}}.IsBuiltinActor(c): + return builtin{{.}}.ActorNameByCode(c) + {{end}} default: return "" } } func IsBuiltinActor(c cid.Cid) bool { + _, _, ok := actors.GetActorMetaByCode(c) + if ok { + return true + } + {{range .versions}} - if builtin{{.}}.IsBuiltinActor(c) { - return true - } + {{if (le . 7)}} + if builtin{{.}}.IsBuiltinActor(c) { + return true + } + {{end}} {{end}} return false } +func GetAccountActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.AccountKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.AccountActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + func IsAccountActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == "account" + } + {{range .versions}} - if c == builtin{{.}}.AccountActorCodeID { - return true - } + {{if (le . 7)}} + if c == builtin{{.}}.AccountActorCodeID { + return true + } + {{end}} {{end}} return false } +func GetCronActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.CronKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.CronActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetInitActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.InitKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.InitActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetMarketActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.MarketKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.StorageMarketActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetMinerActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.MinerKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.StorageMinerActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + func IsStorageMinerActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == actors.MinerKey + } + {{range .versions}} - if c == builtin{{.}}.StorageMinerActorCodeID { - return true - } + {{if (le . 7)}} + if c == builtin{{.}}.StorageMinerActorCodeID { + return true + } + {{end}} {{end}} return false } +func GetMultisigActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.MultisigKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.MultisigActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + func IsMultisigActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == actors.MultisigKey + } + {{range .versions}} - if c == builtin{{.}}.MultisigActorCodeID { - return true - } + {{if (le . 7)}} + if c == builtin{{.}}.MultisigActorCodeID { + return true + } + {{end}} {{end}} return false } +func GetPaymentChannelActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.PaychKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.PaymentChannelActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + func IsPaymentChannelActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == "paymentchannel" + } + {{range .versions}} - if c == builtin{{.}}.PaymentChannelActorCodeID { - return true - } + {{if (le . 7)}} + if c == builtin{{.}}.PaymentChannelActorCodeID { + return true + } + {{end}} {{end}} return false } +func GetPowerActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.PowerKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.StoragePowerActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetRewardActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.RewardKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.RewardActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetSystemActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.SystemKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.SystemActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +func GetVerifregActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, actors.VerifregKey); ok { + return c, nil + } + + switch av { + {{range .versions}} + {{if (le . 7)}} + case actors.Version{{.}}: + return builtin{{.}}.VerifiedRegistryActorCodeID, nil + {{end}} + {{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + func makeAddress(addr string) address.Address { ret, err := address.NewFromString(addr) if err != nil { diff --git a/chain/actors/builtin/cron/actor.go.template b/chain/actors/builtin/cron/actor.go.template index d73808556..fb70f314a 100644 --- a/chain/actors/builtin/cron/actor.go.template +++ b/chain/actors/builtin/cron/actor.go.template @@ -4,12 +4,45 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" "golang.org/x/xerrors" - "github.com/ipfs/go-cid" + "github.com/filecoin-project/lotus/chain/types" + {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{end}} ) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.CronKey { + return nil, xerrors.Errorf("actor code is not cron: %s", name) + } + + switch av { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + + switch act.Code { +{{range .versions}} + {{if (le . 7)}} + case builtin{{.}}.CronActorCodeID: + return load{{.}}(store, act.Head) + {{end}} +{{end}} + } + + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + func MakeState(store adt.Store, av actors.Version) (State, error) { switch av { {{range .versions}} @@ -20,17 +53,6 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.CronActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - var ( Address = builtin{{.latestVersion}}.CronActorAddr Methods = builtin{{.latestVersion}}.MethodsCron diff --git a/chain/actors/builtin/cron/cron.go b/chain/actors/builtin/cron/cron.go index f27a14ac7..1a9c32c81 100644 --- a/chain/actors/builtin/cron/cron.go +++ b/chain/actors/builtin/cron/cron.go @@ -3,7 +3,7 @@ package cron import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/ipfs/go-cid" + "github.com/filecoin-project/lotus/chain/types" "golang.org/x/xerrors" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" @@ -19,8 +19,52 @@ import ( 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/go-state-types/builtin" ) +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.CronKey { + return nil, xerrors.Errorf("actor code is not cron: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + + switch act.Code { + + case builtin0.CronActorCodeID: + return load0(store, act.Head) + + case builtin2.CronActorCodeID: + return load2(store, act.Head) + + case builtin3.CronActorCodeID: + return load3(store, act.Head) + + case builtin4.CronActorCodeID: + return load4(store, act.Head) + + case builtin5.CronActorCodeID: + return load5(store, act.Head) + + case builtin6.CronActorCodeID: + return load6(store, act.Head) + + case builtin7.CronActorCodeID: + return load7(store, act.Head) + + } + + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + func MakeState(store adt.Store, av actors.Version) (State, error) { switch av { @@ -45,42 +89,16 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { case actors.Version7: return make7(store) + case actors.Version8: + return make8(store) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.CronActorCodeID, nil - - case actors.Version2: - return builtin2.CronActorCodeID, nil - - case actors.Version3: - return builtin3.CronActorCodeID, nil - - case actors.Version4: - return builtin4.CronActorCodeID, nil - - case actors.Version5: - return builtin5.CronActorCodeID, nil - - case actors.Version6: - return builtin6.CronActorCodeID, nil - - case actors.Version7: - return builtin7.CronActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - var ( - Address = builtin7.CronActorAddr - Methods = builtin7.MethodsCron + Address = builtin8.CronActorAddr + Methods = builtin8.MethodsCron ) type State interface { diff --git a/chain/actors/builtin/cron/state.go.template b/chain/actors/builtin/cron/state.go.template index 99a06d7f8..13cdc46c9 100644 --- a/chain/actors/builtin/cron/state.go.template +++ b/chain/actors/builtin/cron/state.go.template @@ -5,7 +5,11 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" +{{if (le .v 7)}} cron{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/cron" +{{else}} + cron{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}cron" +{{end}} ) var _ State = (*state{{.v}})(nil) diff --git a/chain/actors/builtin/cron/v8.go b/chain/actors/builtin/cron/v8.go new file mode 100644 index 000000000..00b22fcbf --- /dev/null +++ b/chain/actors/builtin/cron/v8.go @@ -0,0 +1,35 @@ +package cron + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + cron8 "github.com/filecoin-project/go-state-types/builtin/v8/cron" +) + +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 = *cron8.ConstructState(cron8.BuiltInEntries()) + return &out, nil +} + +type state8 struct { + cron8.State + store adt.Store +} + +func (s *state8) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/init/actor.go.template b/chain/actors/builtin/init/actor.go.template index f825eb9fa..e27c66fbb 100644 --- a/chain/actors/builtin/init/actor.go.template +++ b/chain/actors/builtin/init/actor.go.template @@ -10,33 +10,47 @@ import ( "github.com/ipfs/go-cid" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{end}} ) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} - var ( Address = builtin{{.latestVersion}}.InitActorAddr Methods = builtin{{.latestVersion}}.MethodsInit ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.InitKey { + return nil, xerrors.Errorf("actor code is not init: %s", name) + } + + switch 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, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -50,17 +64,6 @@ func MakeState(store adt.Store, av actors.Version, networkName string) (State, e return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.InitActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 737241ffe..9ba412cf1 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -10,7 +10,6 @@ import ( "github.com/ipfs/go-cid" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/modules/dtypes" @@ -27,45 +26,29 @@ import ( 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/go-state-types/builtin" ) -func init() { - - builtin.RegisterActorState(builtin0.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load0(store, root) - }) - - builtin.RegisterActorState(builtin2.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load2(store, root) - }) - - builtin.RegisterActorState(builtin3.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load3(store, root) - }) - - builtin.RegisterActorState(builtin4.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load4(store, root) - }) - - builtin.RegisterActorState(builtin5.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) - - builtin.RegisterActorState(builtin6.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) - - builtin.RegisterActorState(builtin7.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} - var ( - Address = builtin7.InitActorAddr - Methods = builtin7.MethodsInit + Address = builtin8.InitActorAddr + Methods = builtin8.MethodsInit ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.InitKey { + return nil, xerrors.Errorf("actor code is not init: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.InitActorCodeID: @@ -90,6 +73,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -117,39 +101,13 @@ func MakeState(store adt.Store, av actors.Version, networkName string) (State, e case actors.Version7: return make7(store, networkName) + case actors.Version8: + return make8(store, networkName) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.InitActorCodeID, nil - - case actors.Version2: - return builtin2.InitActorCodeID, nil - - case actors.Version3: - return builtin3.InitActorCodeID, nil - - case actors.Version4: - return builtin4.InitActorCodeID, nil - - case actors.Version5: - return builtin5.InitActorCodeID, nil - - case actors.Version6: - return builtin6.InitActorCodeID, nil - - case actors.Version7: - return builtin7.InitActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/init/state.go.template b/chain/actors/builtin/init/state.go.template index 482ad4df5..0e56f5da4 100644 --- a/chain/actors/builtin/init/state.go.template +++ b/chain/actors/builtin/init/state.go.template @@ -10,12 +10,17 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/node/modules/dtypes" -{{if (ge .v 3)}} - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" -{{end}} - +{{if (le .v 7)}} + {{if (ge .v 3)}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + {{end}} 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}} + 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) diff --git a/chain/actors/builtin/init/v8.go b/chain/actors/builtin/init/v8.go new file mode 100644 index 000000000..919819549 --- /dev/null +++ b/chain/actors/builtin/init/v8.go @@ -0,0 +1,113 @@ +package init + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/node/modules/dtypes" + + 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 xerrors.Errorf("failed to delete entry for address: %s; err: %w", addr, err) + } + } + amr, err := m.Root() + if err != nil { + return xerrors.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) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/market/actor.go.template b/chain/actors/builtin/market/actor.go.template index f0366e300..a96c62e43 100644 --- a/chain/actors/builtin/market/actor.go.template +++ b/chain/actors/builtin/market/actor.go.template @@ -1,6 +1,8 @@ package market import ( + "unicode/utf8" + "github.com/filecoin-project/go-state-types/network" "golang.org/x/xerrors" @@ -8,39 +10,52 @@ import ( "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" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{end}} "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -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 ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.MarketKey { + return nil, xerrors.Errorf("actor code is not market: %s", name) + } + + switch 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, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -54,17 +69,6 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.StorageMarketActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler BalancesChanged(State) (bool, error) @@ -96,14 +100,13 @@ 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 interface { DealIDs() ([]abi.DealID, error) @@ -126,30 +129,9 @@ func DecodePublishStorageDealsReturn(b []byte, nv network.Version) (PublishStora return nil, xerrors.Errorf("unknown actor version %d", av) } -type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams -type WithdrawBalanceParams = market0.WithdrawBalanceParams +type DealProposal = market{{.latestVersion}}.DealProposal -type ClientDealProposal = market0.ClientDealProposal - -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 @@ -176,7 +158,7 @@ type DealProposalChanges struct { type ProposalIDState struct { ID abi.DealID - Proposal DealProposal + Proposal market{{.latestVersion}}.DealProposal } func EmptyDealState() *DealState { @@ -188,7 +170,7 @@ func EmptyDealState() *DealState { } // returns the earned fees and pending fees for a given deal -func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, abi.TokenAmount) { +func GetDealFees(deal market{{.latestVersion}}.DealProposal, 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))) @@ -202,3 +184,11 @@ func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, ab return ef, big.Sub(tf, ef) } + +func labelFromGoString(s string) (market{{.latestVersion}}.DealLabel, error) { + if utf8.ValidString(s) { + return market{{.latestVersion}}.NewLabelFromString(s) + } else { + return market{{.latestVersion}}.NewLabelFromBytes([]byte(s)) + } +} diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index d74309c3c..b7e4897fb 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -1,6 +1,8 @@ package market import ( + "unicode/utf8" + "github.com/filecoin-project/go-state-types/network" "golang.org/x/xerrors" @@ -8,10 +10,9 @@ import ( "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" @@ -27,49 +28,32 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + builtin8 "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -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) - }) - - builtin.RegisterActorState(builtin6.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) - - builtin.RegisterActorState(builtin7.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} - var ( - Address = builtin7.StorageMarketActorAddr - Methods = builtin7.MethodsMarket + Address = builtin8.StorageMarketActorAddr + Methods = builtin8.MethodsMarket ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.MarketKey { + return nil, xerrors.Errorf("actor code is not market: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.StorageMarketActorCodeID: @@ -94,6 +78,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -121,39 +106,13 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { case actors.Version7: return make7(store) + case actors.Version8: + return make8(store) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.StorageMarketActorCodeID, nil - - case actors.Version2: - return builtin2.StorageMarketActorCodeID, nil - - case actors.Version3: - return builtin3.StorageMarketActorCodeID, nil - - case actors.Version4: - return builtin4.StorageMarketActorCodeID, nil - - case actors.Version5: - return builtin5.StorageMarketActorCodeID, nil - - case actors.Version6: - return builtin6.StorageMarketActorCodeID, nil - - case actors.Version7: - return builtin7.StorageMarketActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler BalancesChanged(State) (bool, error) @@ -185,15 +144,13 @@ 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 interface { DealIDs() ([]abi.DealID, error) // Note that this index is based on the batch of deals that were published, NOT the DealID @@ -229,34 +186,16 @@ func DecodePublishStorageDealsReturn(b []byte, nv network.Version) (PublishStora case actors.Version7: return decodePublishStorageDealsReturn7(b) + case actors.Version8: + return decodePublishStorageDealsReturn8(b) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams -type WithdrawBalanceParams = market0.WithdrawBalanceParams +type DealProposal = market8.DealProposal -type ClientDealProposal = market0.ClientDealProposal - -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 @@ -283,7 +222,7 @@ type DealProposalChanges struct { type ProposalIDState struct { ID abi.DealID - Proposal DealProposal + Proposal market8.DealProposal } func EmptyDealState() *DealState { @@ -295,7 +234,7 @@ func EmptyDealState() *DealState { } // returns the earned fees and pending fees for a given deal -func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, abi.TokenAmount) { +func GetDealFees(deal market8.DealProposal, 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))) @@ -309,3 +248,11 @@ func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, ab return ef, big.Sub(tf, ef) } + +func labelFromGoString(s string) (market8.DealLabel, error) { + if utf8.ValidString(s) { + return market8.NewLabelFromString(s) + } else { + return market8.NewLabelFromBytes([]byte(s)) + } +} diff --git a/chain/actors/builtin/market/state.go.template b/chain/actors/builtin/market/state.go.template index 091dbc2f7..1ed2fc4fc 100644 --- a/chain/actors/builtin/market/state.go.template +++ b/chain/actors/builtin/market/state.go.template @@ -17,8 +17,13 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" +{{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) @@ -195,7 +200,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 { @@ -211,14 +216,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) }) } @@ -227,18 +242,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}}) GetState() interface{} { return &s.State } diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index aa2ec4716..b57d2c724 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -199,14 +199,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) }) } @@ -215,7 +225,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 } @@ -223,8 +238,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) GetState() interface{} { diff --git a/chain/actors/builtin/market/v2.go b/chain/actors/builtin/market/v2.go index 42742936c..57ded97b2 100644 --- a/chain/actors/builtin/market/v2.go +++ b/chain/actors/builtin/market/v2.go @@ -199,14 +199,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) }) } @@ -215,7 +225,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 } @@ -223,8 +238,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) GetState() interface{} { diff --git a/chain/actors/builtin/market/v3.go b/chain/actors/builtin/market/v3.go index a37171a47..f85e55456 100644 --- a/chain/actors/builtin/market/v3.go +++ b/chain/actors/builtin/market/v3.go @@ -194,14 +194,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) }) } @@ -210,7 +220,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 } @@ -218,8 +233,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) GetState() interface{} { diff --git a/chain/actors/builtin/market/v4.go b/chain/actors/builtin/market/v4.go index b291ebe24..5789318fb 100644 --- a/chain/actors/builtin/market/v4.go +++ b/chain/actors/builtin/market/v4.go @@ -194,14 +194,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) }) } @@ -210,7 +220,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 } @@ -218,8 +233,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) GetState() interface{} { diff --git a/chain/actors/builtin/market/v5.go b/chain/actors/builtin/market/v5.go index e8e979ba8..6dbb724df 100644 --- a/chain/actors/builtin/market/v5.go +++ b/chain/actors/builtin/market/v5.go @@ -194,14 +194,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) }) } @@ -210,7 +220,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 } @@ -218,8 +233,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) GetState() interface{} { diff --git a/chain/actors/builtin/market/v6.go b/chain/actors/builtin/market/v6.go index 63aaba7d4..15c55998e 100644 --- a/chain/actors/builtin/market/v6.go +++ b/chain/actors/builtin/market/v6.go @@ -197,14 +197,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) }) } @@ -213,7 +223,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 } @@ -221,8 +236,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) GetState() interface{} { diff --git a/chain/actors/builtin/market/v7.go b/chain/actors/builtin/market/v7.go index 0d546d7ac..a3c2c7214 100644 --- a/chain/actors/builtin/market/v7.go +++ b/chain/actors/builtin/market/v7.go @@ -197,14 +197,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) }) } @@ -213,7 +223,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 } @@ -221,8 +236,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) GetState() interface{} { diff --git a/chain/actors/builtin/market/v8.go b/chain/actors/builtin/market/v8.go new file mode 100644 index 000000000..a306c44e9 --- /dev/null +++ b/chain/actors/builtin/market/v8.go @@ -0,0 +1,305 @@ +package market + +import ( + "bytes" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-bitfield" + rlepluslazy "github.com/filecoin-project/go-bitfield/rle" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" + + 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) TotalLocked() (abi.TokenAmount, error) { + fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral) + fml = types.BigAdd(fml, s.TotalClientStorageFee) + return fml, nil +} + +func (s *state8) BalancesChanged(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.EscrowTable.Equals(otherState8.State.EscrowTable) || !s.State.LockedTable.Equals(otherState8.State.LockedTable), nil +} + +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 +} + +func (s *state8) EscrowTable() (BalanceTable, error) { + bt, err := adt8.AsBalanceTable(s.store, s.State.EscrowTable) + if err != nil { + return nil, err + } + return &balanceTable8{bt}, nil +} + +func (s *state8) LockedTable() (BalanceTable, error) { + bt, err := adt8.AsBalanceTable(s.store, s.State.LockedTable) + if err != nil { + return nil, err + } + return &balanceTable8{bt}, nil +} + +func (s *state8) VerifyDealsForActivation( + minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, +) (weight, verifiedWeight abi.DealWeight, err error) { + w, vw, _, err := market8.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch) + return w, vw, err +} + +func (s *state8) NextID() (abi.DealID, error) { + return s.State.NextID, nil +} + +type balanceTable8 struct { + *adt8.BalanceTable +} + +func (bt *balanceTable8) ForEach(cb func(address.Address, abi.TokenAmount) error) error { + asMap := (*adt8.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 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) GetState() interface{} { + return &s.State +} + +var _ PublishStorageDealsReturn = (*publishStorageDealsReturn8)(nil) + +func decodePublishStorageDealsReturn8(b []byte) (PublishStorageDealsReturn, error) { + var retval market8.PublishStorageDealsReturn + if err := retval.UnmarshalCBOR(bytes.NewReader(b)); err != nil { + return nil, xerrors.Errorf("failed to unmarshal PublishStorageDealsReturn: %w", err) + } + + return &publishStorageDealsReturn8{retval}, nil +} + +type publishStorageDealsReturn8 struct { + market8.PublishStorageDealsReturn +} + +func (r *publishStorageDealsReturn8) IsDealValid(index uint64) (bool, int, error) { + + set, err := r.ValidDeals.IsSet(index) + if err != nil || !set { + return false, -1, err + } + maskBf, err := bitfield.NewFromIter(&rlepluslazy.RunSliceIterator{ + Runs: []rlepluslazy.Run{rlepluslazy.Run{Val: true, Len: index}}}) + if err != nil { + return false, -1, err + } + before, err := bitfield.IntersectBitField(maskBf, r.ValidDeals) + if err != nil { + return false, -1, err + } + outIdx, err := before.Count() + if err != nil { + return false, -1, err + } + return set, int(outIdx), nil + +} + +func (r *publishStorageDealsReturn8) DealIDs() ([]abi.DealID, error) { + return r.IDs, nil +} diff --git a/chain/actors/builtin/miner/actor.go.template b/chain/actors/builtin/miner/actor.go.template index 74c16be36..731af6255 100644 --- a/chain/actors/builtin/miner/actor.go.template +++ b/chain/actors/builtin/miner/actor.go.template @@ -4,62 +4,51 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" "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" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" + miner{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin{{import .latestVersion}}miner" - 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" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{end}} {{end}} ) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}} -} - -var Methods = builtin{{.latestVersion}}.MethodsMiner - -// Unchanged between v0, v2, v3, v4, and v5 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) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.MinerKey { + return nil, xerrors.Errorf("actor code is not miner: %s", name) + } + + switch av { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.StorageMinerActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.StorageMinerActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} -} + } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -73,17 +62,6 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.StorageMinerActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler @@ -98,8 +76,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) (*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) @@ -128,7 +106,7 @@ type State interface { sectors() (adt.Array, error) decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error) precommits() (adt.Map, error) - decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error) + decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (miner{{.latestVersion}}.SectorPreCommitOnChainInfo, error) GetState() interface{} } @@ -166,44 +144,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 -type ReplicaUpdate = miner7.ReplicaUpdate - -// 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 @@ -258,33 +199,9 @@ func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi } } -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 @@ -311,8 +228,8 @@ type SectorExtensions struct { } type PreCommitChanges struct { - Added []SectorPreCommitOnChainInfo - Removed []SectorPreCommitOnChainInfo + Added []miner{{.latestVersion}}.SectorPreCommitOnChainInfo + Removed []miner{{.latestVersion}}.SectorPreCommitOnChainInfo } type LockedFunds struct { diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index 7889d7a4d..44fa080a6 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -4,27 +4,19 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" "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/actors/builtin" "github.com/filecoin-project/lotus/chain/types" - 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" @@ -40,55 +32,20 @@ import ( 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) - }) - - builtin.RegisterActorState(builtin7.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) - -} - -var Methods = builtin7.MethodsMiner - -// Unchanged between v0, v2, v3, v4, and v5 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) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.MinerKey { + return nil, xerrors.Errorf("actor code is not miner: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.StorageMinerActorCodeID: @@ -113,6 +70,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -140,39 +98,13 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { case actors.Version7: return make7(store) + case actors.Version8: + return make8(store) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.StorageMinerActorCodeID, nil - - case actors.Version2: - return builtin2.StorageMinerActorCodeID, nil - - case actors.Version3: - return builtin3.StorageMinerActorCodeID, nil - - case actors.Version4: - return builtin4.StorageMinerActorCodeID, nil - - case actors.Version5: - return builtin5.StorageMinerActorCodeID, nil - - case actors.Version6: - return builtin6.StorageMinerActorCodeID, nil - - case actors.Version7: - return builtin7.StorageMinerActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler @@ -187,8 +119,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) @@ -217,7 +149,7 @@ type State interface { sectors() (adt.Array, error) decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error) precommits() (adt.Map, error) - decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error) + decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (miner8.SectorPreCommitOnChainInfo, error) GetState() interface{} } @@ -255,44 +187,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 -type ReplicaUpdate = miner7.ReplicaUpdate - -// 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 @@ -347,33 +242,9 @@ func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi } } -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 @@ -400,8 +271,8 @@ type SectorExtensions struct { } type PreCommitChanges struct { - Added []SectorPreCommitOnChainInfo - Removed []SectorPreCommitOnChainInfo + Added []miner8.SectorPreCommitOnChainInfo + Removed []miner8.SectorPreCommitOnChainInfo } type LockedFunds struct { diff --git a/chain/actors/builtin/miner/state.go.template b/chain/actors/builtin/miner/state.go.template index 775631961..53c4b446a 100644 --- a/chain/actors/builtin/miner/state.go.template +++ b/chain/actors/builtin/miner/state.go.template @@ -6,23 +6,28 @@ 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" "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/lotus/chain/actors/adt" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" -{{if (ge .v 3)}} - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" +{{if (le .v 7)}} + {{if (ge .v 3)}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + {{end}} + 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}} + 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}} - miner{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/miner" - adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" ) var _ State = (*state{{.v}})(nil) @@ -210,7 +215,7 @@ func (s *state{{.v}}) GetSectorExpiration(num abi.SectorNumber) (*SectorExpirati 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 @@ -221,7 +226,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 -}} @@ -389,10 +394,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 { @@ -404,10 +405,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, @@ -415,11 +415,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 } @@ -449,11 +444,11 @@ func (s *state{{.v}}) precommits() (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}}) 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 @@ -584,18 +579,14 @@ 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{} { diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 8bde8bf73..a6f11179c 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -6,16 +6,15 @@ 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/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" 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" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -197,7 +196,7 @@ func (s *state0) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e 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 @@ -208,7 +207,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 @@ -372,11 +371,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 @@ -387,10 +381,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, @@ -398,11 +391,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 } @@ -432,11 +420,11 @@ func (s *state0) precommits() (adt.Map, error) { return adt0.AsMap(s.store, s.PreCommittedSectors) } -func (s *state0) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +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 @@ -522,10 +510,14 @@ 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{} { diff --git a/chain/actors/builtin/miner/v2.go b/chain/actors/builtin/miner/v2.go index bbfdd403e..f54526bf7 100644 --- a/chain/actors/builtin/miner/v2.go +++ b/chain/actors/builtin/miner/v2.go @@ -4,16 +4,15 @@ import ( "bytes" "errors" - "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/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" 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" miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" @@ -195,7 +194,7 @@ func (s *state2) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e 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 @@ -206,7 +205,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 @@ -370,11 +369,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 @@ -385,10 +379,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, @@ -396,11 +389,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 } @@ -430,11 +418,11 @@ func (s *state2) precommits() (adt.Map, error) { return adt2.AsMap(s.store, s.PreCommittedSectors) } -func (s *state2) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +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 @@ -552,16 +540,14 @@ 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{} { diff --git a/chain/actors/builtin/miner/v3.go b/chain/actors/builtin/miner/v3.go index 68505918a..0c71d0d77 100644 --- a/chain/actors/builtin/miner/v3.go +++ b/chain/actors/builtin/miner/v3.go @@ -4,16 +4,15 @@ import ( "bytes" "errors" - "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/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" 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" builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" @@ -197,7 +196,7 @@ func (s *state3) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e 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 @@ -208,7 +207,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 @@ -372,20 +371,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, @@ -393,11 +386,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 } @@ -427,11 +415,11 @@ func (s *state3) precommits() (adt.Map, error) { return adt3.AsMap(s.store, s.PreCommittedSectors, builtin3.DefaultHamtBitwidth) } -func (s *state3) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +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 @@ -553,16 +541,14 @@ 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{} { diff --git a/chain/actors/builtin/miner/v4.go b/chain/actors/builtin/miner/v4.go index 5c40d4189..21f6d3feb 100644 --- a/chain/actors/builtin/miner/v4.go +++ b/chain/actors/builtin/miner/v4.go @@ -4,16 +4,15 @@ import ( "bytes" "errors" - "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/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" 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" builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" @@ -197,7 +196,7 @@ func (s *state4) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e 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 @@ -208,7 +207,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 @@ -372,20 +371,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, @@ -393,11 +386,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 } @@ -427,11 +415,11 @@ func (s *state4) precommits() (adt.Map, error) { return adt4.AsMap(s.store, s.PreCommittedSectors, builtin4.DefaultHamtBitwidth) } -func (s *state4) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +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 @@ -553,16 +541,14 @@ 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{} { diff --git a/chain/actors/builtin/miner/v5.go b/chain/actors/builtin/miner/v5.go index f717934f4..d5f81e175 100644 --- a/chain/actors/builtin/miner/v5.go +++ b/chain/actors/builtin/miner/v5.go @@ -4,16 +4,15 @@ import ( "bytes" "errors" - "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/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" 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" builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" @@ -197,7 +196,7 @@ func (s *state5) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e 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 @@ -208,7 +207,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 @@ -372,20 +371,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, @@ -393,11 +386,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 } @@ -427,11 +415,11 @@ func (s *state5) precommits() (adt.Map, error) { return adt5.AsMap(s.store, s.PreCommittedSectors, builtin5.DefaultHamtBitwidth) } -func (s *state5) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +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 @@ -553,16 +541,14 @@ 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{} { diff --git a/chain/actors/builtin/miner/v6.go b/chain/actors/builtin/miner/v6.go index 7a9dfb0df..36631aed4 100644 --- a/chain/actors/builtin/miner/v6.go +++ b/chain/actors/builtin/miner/v6.go @@ -4,16 +4,15 @@ import ( "bytes" "errors" - "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/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" 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" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" @@ -197,7 +196,7 @@ func (s *state6) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e 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 @@ -208,7 +207,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 @@ -372,20 +371,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, @@ -393,11 +386,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 } @@ -427,11 +415,11 @@ func (s *state6) precommits() (adt.Map, error) { return adt6.AsMap(s.store, s.PreCommittedSectors, builtin6.DefaultHamtBitwidth) } -func (s *state6) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +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 @@ -553,16 +541,14 @@ 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{} { diff --git a/chain/actors/builtin/miner/v7.go b/chain/actors/builtin/miner/v7.go index e1b2520e4..502620069 100644 --- a/chain/actors/builtin/miner/v7.go +++ b/chain/actors/builtin/miner/v7.go @@ -4,16 +4,15 @@ import ( "bytes" "errors" - "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/ipfs/go-cid" - "github.com/libp2p/go-libp2p-core/peer" 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" builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" @@ -196,7 +195,7 @@ func (s *state7) GetSectorExpiration(num abi.SectorNumber) (*SectorExpiration, e 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 @@ -207,7 +206,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 @@ -371,20 +370,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, @@ -392,11 +385,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 } @@ -426,11 +414,11 @@ func (s *state7) precommits() (adt.Map, error) { return adt7.AsMap(s.store, s.PreCommittedSectors, builtin7.DefaultHamtBitwidth) } -func (s *state7) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreCommitOnChainInfo, error) { +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 @@ -554,16 +542,14 @@ 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{} { diff --git a/chain/actors/builtin/miner/v8.go b/chain/actors/builtin/miner/v8.go new file mode 100644 index 000000000..370e149e7 --- /dev/null +++ b/chain/actors/builtin/miner/v8.go @@ -0,0 +1,556 @@ +package miner + +import ( + "bytes" + "errors" + + "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/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" + + 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) sectors() (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) precommits() (adt.Map, error) { + return adt8.AsMap(s.store, s.PreCommittedSectors, builtin8.DefaultHamtBitwidth) +} + +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 +} diff --git a/chain/actors/builtin/multisig/actor.go.template b/chain/actors/builtin/multisig/actor.go.template index b899815a6..bd6d4d77a 100644 --- a/chain/actors/builtin/multisig/actor.go.template +++ b/chain/actors/builtin/multisig/actor.go.template @@ -10,34 +10,46 @@ import ( "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" - msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - msig{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/multisig" + msig{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin{{import .latestVersion}}multisig" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{end}} "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -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 := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.MultisigKey { + return nil, xerrors.Errorf("actor code is not multisig: %s", name) + } + + switch 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, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -51,17 +63,6 @@ func MakeState(store adt.Store, av actors.Version, signers []address.Address, th return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.MultisigActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler @@ -80,7 +81,7 @@ type State interface { GetState() interface{} } -type Transaction = msig0.Transaction +type Transaction = msig{{.latestVersion}}.Transaction var Methods = builtin{{.latestVersion}}.MethodsMultisig diff --git a/chain/actors/builtin/multisig/message.go.template b/chain/actors/builtin/multisig/message.go.template index 6bff8983a..4db88826a 100644 --- a/chain/actors/builtin/multisig/message.go.template +++ b/chain/actors/builtin/multisig/message.go.template @@ -6,9 +6,17 @@ 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" - multisig{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/multisig" + {{if (le .v 7)}} + 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" + {{else}} + builtin{{.v}} "github.com/filecoin-project/go-state-types/builtin" + multisig{{.v}} "github.com/filecoin-project/go-state-types/builtin/v8/multisig" + init{{.v}} "github.com/filecoin-project/go-state-types/builtin/v8/init" + "github.com/filecoin-project/lotus/chain/actors/builtin" + {{end}} + "github.com/filecoin-project/lotus/chain/actors" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" @@ -54,11 +62,24 @@ func (m message{{.v}}) Create( 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, - } + {{if (le .v 7)}} + // 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, + } + {{else}} + code, err := builtin.GetMultisigActorCodeID(actors.Version{{.v}}) + if err != nil { + return nil, xerrors.Errorf("failed to get multisig code ID") + } + + // new actors are created by invoking 'exec' on the init actor with the constructor params + execParams := &init8.ExecParams{ + CodeCID: code, + ConstructorParams: enc, + } + {{end}} enc, actErr = actors.SerializeParams(execParams) if actErr != nil { diff --git a/chain/actors/builtin/multisig/message8.go b/chain/actors/builtin/multisig/message8.go new file mode 100644 index 000000000..bc560f50d --- /dev/null +++ b/chain/actors/builtin/multisig/message8.go @@ -0,0 +1,77 @@ +package multisig + +import ( + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + + builtin8 "github.com/filecoin-project/go-state-types/builtin" + init8 "github.com/filecoin-project/go-state-types/builtin/v8/init" + multisig8 "github.com/filecoin-project/go-state-types/builtin/v8/multisig" + "github.com/filecoin-project/lotus/chain/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/types" +) + +type message8 struct{ message0 } + +func (m message8) 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, xerrors.Errorf("cannot require signing of more addresses than provided for multisig") + } + + if threshold == 0 { + threshold = lenAddrs + } + + if m.from == address.Undef { + return nil, xerrors.Errorf("must provide source address") + } + + // Set up constructor parameters for multisig + msigParams := &multisig8.ConstructorParams{ + Signers: signers, + NumApprovalsThreshold: threshold, + UnlockDuration: unlockDuration, + StartEpoch: unlockStart, + } + + enc, actErr := actors.SerializeParams(msigParams) + if actErr != nil { + return nil, actErr + } + + code, err := builtin.GetMultisigActorCodeID(actors.Version8) + if err != nil { + return nil, xerrors.Errorf("failed to get multisig code ID") + } + + // new actors are created by invoking 'exec' on the init actor with the constructor params + execParams := &init8.ExecParams{ + CodeCID: code, + ConstructorParams: enc, + } + + enc, actErr = actors.SerializeParams(execParams) + if actErr != nil { + return nil, actErr + } + + return &types.Message{ + To: init_.Address, + From: m.from, + Method: builtin8.MethodsInit.Exec, + Params: enc, + Value: initialAmount, + }, nil +} diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go index f1b50475a..3985d4466 100644 --- a/chain/actors/builtin/multisig/multisig.go +++ b/chain/actors/builtin/multisig/multisig.go @@ -10,10 +10,8 @@ import ( "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" - msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - msig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig" + msig8 "github.com/filecoin-project/go-state-types/builtin/v8/multisig" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" @@ -29,44 +27,27 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + builtin8 "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -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) - }) - - builtin.RegisterActorState(builtin5.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) - - builtin.RegisterActorState(builtin6.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) - - 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) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.MultisigKey { + return nil, xerrors.Errorf("actor code is not multisig: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.MultisigActorCodeID: @@ -91,6 +72,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -118,39 +100,13 @@ func MakeState(store adt.Store, av actors.Version, signers []address.Address, th case actors.Version7: return make7(store, signers, threshold, startEpoch, unlockDuration, initialBalance) + case actors.Version8: + return make8(store, signers, threshold, startEpoch, unlockDuration, initialBalance) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.MultisigActorCodeID, nil - - case actors.Version2: - return builtin2.MultisigActorCodeID, nil - - case actors.Version3: - return builtin3.MultisigActorCodeID, nil - - case actors.Version4: - return builtin4.MultisigActorCodeID, nil - - case actors.Version5: - return builtin5.MultisigActorCodeID, nil - - case actors.Version6: - return builtin6.MultisigActorCodeID, nil - - case actors.Version7: - return builtin7.MultisigActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler @@ -169,9 +125,9 @@ type State interface { GetState() interface{} } -type Transaction = msig0.Transaction +type Transaction = msig8.Transaction -var Methods = builtin7.MethodsMultisig +var Methods = builtin8.MethodsMultisig func Message(version actors.Version, from address.Address) MessageBuilder { switch version { @@ -196,6 +152,9 @@ func Message(version actors.Version, from address.Address) MessageBuilder { case actors.Version7: return message7{message0{from}} + + case actors.Version8: + return message8{message0{from}} default: panic(fmt.Sprintf("unsupported actors version: %d", version)) } @@ -219,13 +178,13 @@ type MessageBuilder interface { } // this type is the same between v0 and v2 -type ProposalHashData = msig7.ProposalHashData -type ProposeReturn = msig7.ProposeReturn -type ProposeParams = msig7.ProposeParams -type ApproveReturn = msig7.ApproveReturn +type ProposalHashData = msig8.ProposalHashData +type ProposeReturn = msig8.ProposeReturn +type ProposeParams = msig8.ProposeParams +type ApproveReturn = msig8.ApproveReturn 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, xerrors.Errorf("proposer address must be an ID address, was %s", data.Requester) diff --git a/chain/actors/builtin/multisig/state.go.template b/chain/actors/builtin/multisig/state.go.template index 6c0130c09..e375becc3 100644 --- a/chain/actors/builtin/multisig/state.go.template +++ b/chain/actors/builtin/multisig/state.go.template @@ -4,7 +4,6 @@ import ( "bytes" "encoding/binary" - adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -14,10 +13,17 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" -{{if (ge .v 3)}} - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" +{{if (le .v 7)}} + {{if (ge .v 3)}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + {{end}} + msig{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/multisig" + adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" +{{else}} + msig{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}multisig" + adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt" + builtin{{.v}} "github.com/filecoin-project/go-state-types/builtin" {{end}} - msig{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/multisig" ) var _ State = (*state{{.v}})(nil) @@ -119,7 +125,7 @@ func (s *state{{.v}}) decodeTransaction(val *cbg.Deferred) (Transaction, error) if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return Transaction{}, err } - return tx, nil + return Transaction(tx), nil } func (s *state{{.v}}) GetState() interface{} { diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go index 973ac9209..ccd9a9e37 100644 --- a/chain/actors/builtin/multisig/v0.go +++ b/chain/actors/builtin/multisig/v0.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/binary" - adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -15,6 +13,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" ) var _ State = (*state0)(nil) @@ -109,7 +108,7 @@ func (s *state0) decodeTransaction(val *cbg.Deferred) (Transaction, error) { if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return Transaction{}, err } - return tx, nil + return Transaction(tx), nil } func (s *state0) GetState() interface{} { diff --git a/chain/actors/builtin/multisig/v2.go b/chain/actors/builtin/multisig/v2.go index 5b830e695..c3579b3e2 100644 --- a/chain/actors/builtin/multisig/v2.go +++ b/chain/actors/builtin/multisig/v2.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/binary" - adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -15,6 +13,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" msig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig" + adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt" ) var _ State = (*state2)(nil) @@ -109,7 +108,7 @@ func (s *state2) decodeTransaction(val *cbg.Deferred) (Transaction, error) { if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return Transaction{}, err } - return tx, nil + return Transaction(tx), nil } func (s *state2) GetState() interface{} { diff --git a/chain/actors/builtin/multisig/v3.go b/chain/actors/builtin/multisig/v3.go index c4a2791b7..80682808e 100644 --- a/chain/actors/builtin/multisig/v3.go +++ b/chain/actors/builtin/multisig/v3.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/binary" - adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -17,6 +15,7 @@ import ( builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" msig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig" + adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt" ) var _ State = (*state3)(nil) @@ -111,7 +110,7 @@ func (s *state3) decodeTransaction(val *cbg.Deferred) (Transaction, error) { if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return Transaction{}, err } - return tx, nil + return Transaction(tx), nil } func (s *state3) GetState() interface{} { diff --git a/chain/actors/builtin/multisig/v4.go b/chain/actors/builtin/multisig/v4.go index a35a890f8..f065f9f8c 100644 --- a/chain/actors/builtin/multisig/v4.go +++ b/chain/actors/builtin/multisig/v4.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/binary" - adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -17,6 +15,7 @@ import ( builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" msig4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig" + adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt" ) var _ State = (*state4)(nil) @@ -111,7 +110,7 @@ func (s *state4) decodeTransaction(val *cbg.Deferred) (Transaction, error) { if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return Transaction{}, err } - return tx, nil + return Transaction(tx), nil } func (s *state4) GetState() interface{} { diff --git a/chain/actors/builtin/multisig/v5.go b/chain/actors/builtin/multisig/v5.go index 4ad9aea94..783e3987f 100644 --- a/chain/actors/builtin/multisig/v5.go +++ b/chain/actors/builtin/multisig/v5.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/binary" - adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -17,6 +15,7 @@ import ( builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" msig5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig" + adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt" ) var _ State = (*state5)(nil) @@ -111,7 +110,7 @@ func (s *state5) decodeTransaction(val *cbg.Deferred) (Transaction, error) { if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return Transaction{}, err } - return tx, nil + return Transaction(tx), nil } func (s *state5) GetState() interface{} { diff --git a/chain/actors/builtin/multisig/v6.go b/chain/actors/builtin/multisig/v6.go index fa16494f8..71ea3c00c 100644 --- a/chain/actors/builtin/multisig/v6.go +++ b/chain/actors/builtin/multisig/v6.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/binary" - adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -17,6 +15,7 @@ import ( builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" msig6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/multisig" + adt6 "github.com/filecoin-project/specs-actors/v6/actors/util/adt" ) var _ State = (*state6)(nil) @@ -111,7 +110,7 @@ func (s *state6) decodeTransaction(val *cbg.Deferred) (Transaction, error) { if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return Transaction{}, err } - return tx, nil + return Transaction(tx), nil } func (s *state6) GetState() interface{} { diff --git a/chain/actors/builtin/multisig/v7.go b/chain/actors/builtin/multisig/v7.go index bbe41f3db..8ed1caacd 100644 --- a/chain/actors/builtin/multisig/v7.go +++ b/chain/actors/builtin/multisig/v7.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/binary" - adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -17,6 +15,7 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" msig7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/multisig" + adt7 "github.com/filecoin-project/specs-actors/v7/actors/util/adt" ) var _ State = (*state7)(nil) @@ -111,7 +110,7 @@ func (s *state7) decodeTransaction(val *cbg.Deferred) (Transaction, error) { if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil { return Transaction{}, err } - return tx, nil + return Transaction(tx), nil } func (s *state7) GetState() interface{} { diff --git a/chain/actors/builtin/multisig/v8.go b/chain/actors/builtin/multisig/v8.go new file mode 100644 index 000000000..5b76f662e --- /dev/null +++ b/chain/actors/builtin/multisig/v8.go @@ -0,0 +1,117 @@ +package multisig + +import ( + "bytes" + "encoding/binary" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + builtin8 "github.com/filecoin-project/go-state-types/builtin" + msig8 "github.com/filecoin-project/go-state-types/builtin/v8/multisig" + 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, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + out := state8{store: store} + out.State = msig8.State{} + out.State.Signers = signers + out.State.NumApprovalsThreshold = threshold + out.State.StartEpoch = startEpoch + out.State.UnlockDuration = unlockDuration + out.State.InitialBalance = initialBalance + + em, err := adt8.StoreEmptyMap(store, builtin8.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + + out.State.PendingTxns = em + + 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 xerrors.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) transactions() (adt.Map, error) { + return adt8.AsMap(s.store, s.PendingTxns, builtin8.DefaultHamtBitwidth) +} + +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 Transaction(tx), nil +} + +func (s *state8) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/paych/actor.go.template b/chain/actors/builtin/paych/actor.go.template index 7699e76b6..8730e6177 100644 --- a/chain/actors/builtin/paych/actor.go.template +++ b/chain/actors/builtin/paych/actor.go.template @@ -10,59 +10,50 @@ import ( "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" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{end}} {{end}} "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -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) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.PaychKey { + return nil, xerrors.Errorf("actor code is not paych: %s", name) + } + + switch av { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + switch act.Code { {{range .versions}} - case builtin{{.}}.PaymentChannelActorCodeID: - return load{{.}}(store, act.Head) + {{if (le . 7)}} + case builtin{{.}}.PaymentChannelActorCodeID: + return load{{.}}(store, act.Head) + {{end}} {{end}} } + return nil, xerrors.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, xerrors.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, xerrors.Errorf("unknown actor version %d", av) -} - // State is an abstract version of payment channel state that works across // versions type State interface { @@ -93,17 +84,14 @@ type LaneState interface { Nonce() (uint64, error) } -type SignedVoucher = paych0.SignedVoucher -type ModVerifyParams = paych0.ModVerifyParams - // DecodeSignedVoucher decodes base64 encoded signed voucher. -func DecodeSignedVoucher(s string) (*SignedVoucher, error) { +func DecodeSignedVoucher(s string) (*paychtypes.SignedVoucher, error) { data, err := base64.RawURLEncoding.DecodeString(s) if err != nil { return nil, err } - var sv SignedVoucher + var sv paychtypes.SignedVoucher if err := ipldcbor.DecodeInto(data, &sv); err != nil { return nil, err } @@ -111,8 +99,6 @@ func DecodeSignedVoucher(s string) (*SignedVoucher, error) { return &sv, nil } -var Methods = builtin{{.latestVersion}}.MethodsPaych - func Message(version actors.Version, from address.Address) MessageBuilder { switch version { {{range .versions}} @@ -126,7 +112,23 @@ func Message(version actors.Version, from address.Address) MessageBuilder { type MessageBuilder interface { Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) - Update(paych address.Address, voucher *SignedVoucher, secret []byte) (*types.Message, error) + Update(paych address.Address, voucher *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) Settle(paych address.Address) (*types.Message, error) Collect(paych address.Address) (*types.Message, error) } + +func toV0SignedVoucher(sv paychtypes.SignedVoucher) paych0.SignedVoucher { + return paych0.SignedVoucher{ + ChannelAddr: sv.ChannelAddr, + TimeLockMin: sv.TimeLockMin, + TimeLockMax: sv.TimeLockMax, + SecretPreimage: sv.SecretHash, + Extra: (*paych0.ModVerifyParams)(sv.Extra), + Lane: sv.Lane, + Nonce: sv.Nonce, + Amount: sv.Amount, + MinSettleHeight: sv.MinSettleHeight, + Merges: nil, + Signature: sv.Signature, + } +} \ No newline at end of file diff --git a/chain/actors/builtin/paych/message.go.template b/chain/actors/builtin/paych/message.go.template index 99f64cabb..9e92bf748 100644 --- a/chain/actors/builtin/paych/message.go.template +++ b/chain/actors/builtin/paych/message.go.template @@ -1,12 +1,24 @@ package paych import ( + {{if (ge .v 8)}} + "golang.org/x/xerrors" + {{end}} + "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" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + {{if (le .v 7)}} + 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" + {{else}} + builtin{{.v}} "github.com/filecoin-project/go-state-types/builtin" + paych{{.v}} "github.com/filecoin-project/go-state-types/builtin/v8/paych" + init{{.v}} "github.com/filecoin-project/go-state-types/builtin/v8/init" + {{end}} + "github.com/filecoin-project/lotus/chain/actors" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" @@ -16,12 +28,21 @@ import ( type message{{.v}} struct{ from address.Address } func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + {{if (le .v 7)}} + actorCodeID := builtin{{.v}}.PaymentChannelActorCodeID + {{else}} + actorCodeID, ok := actors.GetActorCodeID(actors.Version{{.v}}, "paymentchannel") + if !ok { + return nil, xerrors.Errorf("error getting actor paymentchannel code id for actor version %d", {{.v}}) + } + {{end}} + 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, + CodeCID: actorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -37,10 +58,10 @@ func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount) }, nil } -func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { +func (m message{{.v}}) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych{{.v}}.UpdateChannelStateParams{ - {{if (ge .v 7)}} - Sv: toV{{.v}}SignedVoucher(*sv), + {{if (le .v 6)}} + Sv: toV0SignedVoucher(*sv), {{else}} Sv: *sv, {{end}} diff --git a/chain/actors/builtin/paych/message0.go b/chain/actors/builtin/paych/message0.go index 7cba977e3..2daa0301b 100644 --- a/chain/actors/builtin/paych/message0.go +++ b/chain/actors/builtin/paych/message0.go @@ -4,6 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + 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" @@ -16,12 +18,15 @@ import ( type message0 struct{ from address.Address } func (m message0) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID := builtin0.PaymentChannelActorCodeID + 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, + CodeCID: actorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -37,10 +42,10 @@ func (m message0) Create(to address.Address, initialAmount abi.TokenAmount) (*ty }, nil } -func (m message0) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { +func (m message0) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych0.UpdateChannelStateParams{ - Sv: *sv, + Sv: toV0SignedVoucher(*sv), Secret: secret, }) diff --git a/chain/actors/builtin/paych/message2.go b/chain/actors/builtin/paych/message2.go index 60c7fe16e..925ad0ed9 100644 --- a/chain/actors/builtin/paych/message2.go +++ b/chain/actors/builtin/paych/message2.go @@ -4,6 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + 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" @@ -16,12 +18,15 @@ import ( type message2 struct{ from address.Address } func (m message2) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID := builtin2.PaymentChannelActorCodeID + 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, + CodeCID: actorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -37,10 +42,10 @@ func (m message2) Create(to address.Address, initialAmount abi.TokenAmount) (*ty }, nil } -func (m message2) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { +func (m message2) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych2.UpdateChannelStateParams{ - Sv: *sv, + Sv: toV0SignedVoucher(*sv), Secret: secret, }) diff --git a/chain/actors/builtin/paych/message3.go b/chain/actors/builtin/paych/message3.go index 04fb35b57..e8ae585fc 100644 --- a/chain/actors/builtin/paych/message3.go +++ b/chain/actors/builtin/paych/message3.go @@ -4,6 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + 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" @@ -16,12 +18,15 @@ import ( type message3 struct{ from address.Address } func (m message3) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID := builtin3.PaymentChannelActorCodeID + 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, + CodeCID: actorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -37,10 +42,10 @@ func (m message3) Create(to address.Address, initialAmount abi.TokenAmount) (*ty }, nil } -func (m message3) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { +func (m message3) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych3.UpdateChannelStateParams{ - Sv: *sv, + Sv: toV0SignedVoucher(*sv), Secret: secret, }) diff --git a/chain/actors/builtin/paych/message4.go b/chain/actors/builtin/paych/message4.go index 9f5e000d9..b32b0fa57 100644 --- a/chain/actors/builtin/paych/message4.go +++ b/chain/actors/builtin/paych/message4.go @@ -4,6 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + 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" @@ -16,12 +18,15 @@ import ( type message4 struct{ from address.Address } func (m message4) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID := builtin4.PaymentChannelActorCodeID + 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, + CodeCID: actorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -37,10 +42,10 @@ func (m message4) Create(to address.Address, initialAmount abi.TokenAmount) (*ty }, nil } -func (m message4) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { +func (m message4) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych4.UpdateChannelStateParams{ - Sv: *sv, + Sv: toV0SignedVoucher(*sv), Secret: secret, }) diff --git a/chain/actors/builtin/paych/message5.go b/chain/actors/builtin/paych/message5.go index 71e6b6799..897bebe7a 100644 --- a/chain/actors/builtin/paych/message5.go +++ b/chain/actors/builtin/paych/message5.go @@ -4,6 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + 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" @@ -16,12 +18,15 @@ import ( type message5 struct{ from address.Address } func (m message5) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID := builtin5.PaymentChannelActorCodeID + 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, + CodeCID: actorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -37,10 +42,10 @@ func (m message5) Create(to address.Address, initialAmount abi.TokenAmount) (*ty }, nil } -func (m message5) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { +func (m message5) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych5.UpdateChannelStateParams{ - Sv: *sv, + Sv: toV0SignedVoucher(*sv), Secret: secret, }) diff --git a/chain/actors/builtin/paych/message6.go b/chain/actors/builtin/paych/message6.go index 7f80bc4a6..11bd3a8a5 100644 --- a/chain/actors/builtin/paych/message6.go +++ b/chain/actors/builtin/paych/message6.go @@ -4,6 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + 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" @@ -16,12 +18,15 @@ import ( type message6 struct{ from address.Address } func (m message6) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID := builtin6.PaymentChannelActorCodeID + 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, + CodeCID: actorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -37,10 +42,10 @@ func (m message6) Create(to address.Address, initialAmount abi.TokenAmount) (*ty }, nil } -func (m message6) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { +func (m message6) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych6.UpdateChannelStateParams{ - Sv: *sv, + Sv: toV0SignedVoucher(*sv), Secret: secret, }) diff --git a/chain/actors/builtin/paych/message7.go b/chain/actors/builtin/paych/message7.go index e3ee0d77b..446e54ead 100644 --- a/chain/actors/builtin/paych/message7.go +++ b/chain/actors/builtin/paych/message7.go @@ -4,6 +4,8 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + 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" @@ -16,12 +18,15 @@ import ( type message7 struct{ from address.Address } func (m message7) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID := builtin7.PaymentChannelActorCodeID + 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, + CodeCID: actorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -37,10 +42,10 @@ func (m message7) Create(to address.Address, initialAmount abi.TokenAmount) (*ty }, nil } -func (m message7) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { +func (m message7) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych7.UpdateChannelStateParams{ - Sv: toV7SignedVoucher(*sv), + Sv: *sv, Secret: secret, }) diff --git a/chain/actors/builtin/paych/message8.go b/chain/actors/builtin/paych/message8.go new file mode 100644 index 000000000..189b20988 --- /dev/null +++ b/chain/actors/builtin/paych/message8.go @@ -0,0 +1,86 @@ +package paych + +import ( + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + + builtin8 "github.com/filecoin-project/go-state-types/builtin" + init8 "github.com/filecoin-project/go-state-types/builtin/v8/init" + paych8 "github.com/filecoin-project/go-state-types/builtin/v8/paych" + + "github.com/filecoin-project/lotus/chain/actors" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/types" +) + +type message8 struct{ from address.Address } + +func (m message8) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) { + + actorCodeID, ok := actors.GetActorCodeID(actors.Version8, "paymentchannel") + if !ok { + return nil, xerrors.Errorf("error getting actor paymentchannel code id for actor version %d", 8) + } + + params, aerr := actors.SerializeParams(&paych8.ConstructorParams{From: m.from, To: to}) + if aerr != nil { + return nil, aerr + } + enc, aerr := actors.SerializeParams(&init8.ExecParams{ + CodeCID: actorCodeID, + ConstructorParams: params, + }) + if aerr != nil { + return nil, aerr + } + + return &types.Message{ + To: init_.Address, + From: m.from, + Value: initialAmount, + Method: builtin8.MethodsInit.Exec, + Params: enc, + }, nil +} + +func (m message8) Update(paych address.Address, sv *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) { + params, aerr := actors.SerializeParams(&paych8.UpdateChannelStateParams{ + + Sv: *sv, + + Secret: secret, + }) + if aerr != nil { + return nil, aerr + } + + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin8.MethodsPaych.UpdateChannelState, + Params: params, + }, nil +} + +func (m message8) Settle(paych address.Address) (*types.Message, error) { + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin8.MethodsPaych.Settle, + }, nil +} + +func (m message8) Collect(paych address.Address) (*types.Message, error) { + return &types.Message{ + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), + Method: builtin8.MethodsPaych.Collect, + }, nil +} diff --git a/chain/actors/builtin/paych/paych.go b/chain/actors/builtin/paych/paych.go index f807b33ed..9dd373e8b 100644 --- a/chain/actors/builtin/paych/paych.go +++ b/chain/actors/builtin/paych/paych.go @@ -10,9 +10,9 @@ import ( "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" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" @@ -31,43 +31,24 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -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) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.PaychKey { + return nil, xerrors.Errorf("actor code is not paych: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.PaymentChannelActorCodeID: @@ -92,66 +73,10 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + 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) - - } - return nil, xerrors.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, xerrors.Errorf("unknown actor version %d", av) -} - // State is an abstract version of payment channel state that works across // versions type State interface { @@ -182,17 +107,14 @@ type LaneState interface { Nonce() (uint64, error) } -type SignedVoucher = paych0.SignedVoucher -type ModVerifyParams = paych0.ModVerifyParams - // DecodeSignedVoucher decodes base64 encoded signed voucher. -func DecodeSignedVoucher(s string) (*SignedVoucher, error) { +func DecodeSignedVoucher(s string) (*paychtypes.SignedVoucher, error) { data, err := base64.RawURLEncoding.DecodeString(s) if err != nil { return nil, err } - var sv SignedVoucher + var sv paychtypes.SignedVoucher if err := ipldcbor.DecodeInto(data, &sv); err != nil { return nil, err } @@ -200,8 +122,6 @@ func DecodeSignedVoucher(s string) (*SignedVoucher, error) { return &sv, nil } -var Methods = builtin7.MethodsPaych - func Message(version actors.Version, from address.Address) MessageBuilder { switch version { @@ -226,6 +146,9 @@ func Message(version actors.Version, from address.Address) MessageBuilder { case actors.Version7: return message7{from} + case actors.Version8: + return message8{from} + default: panic(fmt.Sprintf("unsupported actors version: %d", version)) } @@ -233,7 +156,23 @@ func Message(version actors.Version, from address.Address) MessageBuilder { type MessageBuilder interface { Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) - Update(paych address.Address, voucher *SignedVoucher, secret []byte) (*types.Message, error) + Update(paych address.Address, voucher *paychtypes.SignedVoucher, secret []byte) (*types.Message, error) Settle(paych address.Address) (*types.Message, error) Collect(paych address.Address) (*types.Message, error) } + +func toV0SignedVoucher(sv paychtypes.SignedVoucher) paych0.SignedVoucher { + return paych0.SignedVoucher{ + ChannelAddr: sv.ChannelAddr, + TimeLockMin: sv.TimeLockMin, + TimeLockMax: sv.TimeLockMax, + SecretPreimage: sv.SecretHash, + Extra: (*paych0.ModVerifyParams)(sv.Extra), + Lane: sv.Lane, + Nonce: sv.Nonce, + Amount: sv.Amount, + MinSettleHeight: sv.MinSettleHeight, + Merges: nil, + Signature: sv.Signature, + } +} diff --git a/chain/actors/builtin/paych/state.go.template b/chain/actors/builtin/paych/state.go.template index f11407202..c3954ce81 100644 --- a/chain/actors/builtin/paych/state.go.template +++ b/chain/actors/builtin/paych/state.go.template @@ -9,8 +9,13 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" +{{if (le .v 7)}} paych{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/paych" adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" +{{else}} + paych{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}paych" + adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt" +{{end}} ) var _ State = (*state{{.v}})(nil) @@ -112,21 +117,3 @@ func (ls *laneState{{.v}}) Redeemed() (big.Int, error) { 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}} \ No newline at end of file diff --git a/chain/actors/builtin/paych/v7.go b/chain/actors/builtin/paych/v7.go index 19c801c82..ce09ea2e4 100644 --- a/chain/actors/builtin/paych/v7.go +++ b/chain/actors/builtin/paych/v7.go @@ -112,19 +112,3 @@ func (ls *laneState7) Redeemed() (big.Int, error) { 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/paych/v8.go b/chain/actors/builtin/paych/v8.go new file mode 100644 index 000000000..7936b76e1 --- /dev/null +++ b/chain/actors/builtin/paych/v8.go @@ -0,0 +1,114 @@ +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/lotus/chain/actors/adt" + + paych8 "github.com/filecoin-project/go-state-types/builtin/v8/paych" + 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 = paych8.State{} + return &out, nil +} + +type state8 struct { + paych8.State + store adt.Store + lsAmt *adt8.Array +} + +// Channel owner, who has funded the actor +func (s *state8) From() (address.Address, error) { + return s.State.From, nil +} + +// Recipient of payouts from channel +func (s *state8) To() (address.Address, error) { + return s.State.To, nil +} + +// Height at which the channel can be `Collected` +func (s *state8) SettlingAt() (abi.ChainEpoch, error) { + return s.State.SettlingAt, nil +} + +// Amount successfully redeemed through the payment channel, paid out on `Collect()` +func (s *state8) ToSend() (abi.TokenAmount, error) { + return s.State.ToSend, nil +} + +func (s *state8) getOrLoadLsAmt() (*adt8.Array, error) { + if s.lsAmt != nil { + return s.lsAmt, nil + } + + // Get the lane state from the chain + lsamt, err := adt8.AsArray(s.store, s.State.LaneStates, paych8.LaneStatesAmtBitwidth) + if err != nil { + return nil, err + } + + s.lsAmt = lsamt + return lsamt, nil +} + +// Get total number of lanes +func (s *state8) LaneCount() (uint64, error) { + lsamt, err := s.getOrLoadLsAmt() + if err != nil { + return 0, err + } + return lsamt.Length(), nil +} + +func (s *state8) GetState() interface{} { + return &s.State +} + +// Iterate lane states +func (s *state8) 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 paych8.LaneState + return lsamt.ForEach(&ls, func(i int64) error { + return cb(uint64(i), &laneState8{ls}) + }) +} + +type laneState8 struct { + paych8.LaneState +} + +func (ls *laneState8) Redeemed() (big.Int, error) { + return ls.LaneState.Redeemed, nil +} + +func (ls *laneState8) Nonce() (uint64, error) { + return ls.LaneState.Nonce, nil +} diff --git a/chain/actors/builtin/power/actor.go.template b/chain/actors/builtin/power/actor.go.template index fe11fc160..af9190357 100644 --- a/chain/actors/builtin/power/actor.go.template +++ b/chain/actors/builtin/power/actor.go.template @@ -4,7 +4,6 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors" - "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -14,30 +13,46 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" + {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{end}} ) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} - var ( Address = builtin{{.latestVersion}}.StoragePowerActorAddr Methods = builtin{{.latestVersion}}.MethodsPower ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.PowerKey { + return nil, xerrors.Errorf("actor code is not power: %s", name) + } + + switch 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, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -51,17 +66,6 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.StoragePowerActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 9b73cdd60..1b79a623c 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -4,7 +4,6 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors" - "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -28,45 +27,29 @@ import ( 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/go-state-types/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) - }) - - 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) - }) - - builtin.RegisterActorState(builtin5.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) - - builtin.RegisterActorState(builtin6.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) - - builtin.RegisterActorState(builtin7.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} - var ( - Address = builtin7.StoragePowerActorAddr - Methods = builtin7.MethodsPower + Address = builtin8.StoragePowerActorAddr + Methods = builtin8.MethodsPower ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.PowerKey { + return nil, xerrors.Errorf("actor code is not power: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.StoragePowerActorCodeID: @@ -91,6 +74,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -118,39 +102,13 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { case actors.Version7: return make7(store) + case actors.Version8: + return make8(store) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.StoragePowerActorCodeID, nil - - case actors.Version2: - return builtin2.StoragePowerActorCodeID, nil - - case actors.Version3: - return builtin3.StoragePowerActorCodeID, nil - - case actors.Version4: - return builtin4.StoragePowerActorCodeID, nil - - case actors.Version5: - return builtin5.StoragePowerActorCodeID, nil - - case actors.Version6: - return builtin6.StoragePowerActorCodeID, nil - - case actors.Version7: - return builtin7.StoragePowerActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/power/state.go.template b/chain/actors/builtin/power/state.go.template index fcdc5c350..b53ba68c8 100644 --- a/chain/actors/builtin/power/state.go.template +++ b/chain/actors/builtin/power/state.go.template @@ -11,11 +11,17 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" -{{if (ge .v 3)}} - builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" -{{end}} +{{if (le .v 7)}} + {{if (ge .v 3)}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + {{end}} 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/go-state-types/builtin" + power{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}power" + adt{{.v}} "github.com/filecoin-project/go-state-types/builtin/v8/util/adt" +{{end}} ) var _ State = (*state{{.v}})(nil) @@ -100,7 +106,7 @@ func (s *state{{.v}}) MinerNominalPowerMeetsConsensusMinimum(a address.Address) } func (s *state{{.v}}) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV{{.v}}FilterEstimate({{if (le .v 1)}}*{{end}}s.State.ThisEpochQAPowerSmoothed), nil + return builtin.FilterEstimate({{if (le .v 1)}}*{{end}}s.State.ThisEpochQAPowerSmoothed), nil } func (s *state{{.v}}) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 465d16c5c..e114ac219 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -89,7 +89,7 @@ func (s *state0) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state0) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV0FilterEstimate(*s.State.ThisEpochQAPowerSmoothed), nil + return builtin.FilterEstimate(*s.State.ThisEpochQAPowerSmoothed), nil } func (s *state0) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/power/v2.go b/chain/actors/builtin/power/v2.go index 606534cef..405bad8ba 100644 --- a/chain/actors/builtin/power/v2.go +++ b/chain/actors/builtin/power/v2.go @@ -89,7 +89,7 @@ func (s *state2) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state2) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV2FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil + return builtin.FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil } func (s *state2) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/power/v3.go b/chain/actors/builtin/power/v3.go index 3dec3c63e..0ff06f617 100644 --- a/chain/actors/builtin/power/v3.go +++ b/chain/actors/builtin/power/v3.go @@ -86,7 +86,7 @@ func (s *state3) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state3) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV3FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil + return builtin.FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil } func (s *state3) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/power/v4.go b/chain/actors/builtin/power/v4.go index b73eedf5a..f121e3b2f 100644 --- a/chain/actors/builtin/power/v4.go +++ b/chain/actors/builtin/power/v4.go @@ -86,7 +86,7 @@ func (s *state4) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state4) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV4FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil + return builtin.FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil } func (s *state4) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/power/v5.go b/chain/actors/builtin/power/v5.go index 84b23a577..851522e50 100644 --- a/chain/actors/builtin/power/v5.go +++ b/chain/actors/builtin/power/v5.go @@ -86,7 +86,7 @@ func (s *state5) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state5) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV5FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil + return builtin.FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil } func (s *state5) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/power/v6.go b/chain/actors/builtin/power/v6.go index 4273c2c73..083b85f45 100644 --- a/chain/actors/builtin/power/v6.go +++ b/chain/actors/builtin/power/v6.go @@ -86,7 +86,7 @@ func (s *state6) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state6) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV6FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil + return builtin.FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil } func (s *state6) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/power/v7.go b/chain/actors/builtin/power/v7.go index af1761cb2..af626cf3a 100644 --- a/chain/actors/builtin/power/v7.go +++ b/chain/actors/builtin/power/v7.go @@ -86,7 +86,7 @@ func (s *state7) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool } func (s *state7) TotalPowerSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV7FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil + return builtin.FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil } func (s *state7) MinerCounts() (uint64, uint64, error) { diff --git a/chain/actors/builtin/power/v8.go b/chain/actors/builtin/power/v8.go new file mode 100644 index 000000000..177d3bc3d --- /dev/null +++ b/chain/actors/builtin/power/v8.go @@ -0,0 +1,186 @@ +package power + +import ( + "bytes" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin" + + builtin8 "github.com/filecoin-project/go-state-types/builtin" + power8 "github.com/filecoin-project/go-state-types/builtin/v8/power" + 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 := power8.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + 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.claims() + 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.FilterEstimate(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.claims() + 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.claims() + 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) SetTotalQualityAdjPower(p abi.StoragePower) error { + s.State.TotalQualityAdjPower = p + return nil +} + +func (s *state8) SetTotalRawBytePower(p abi.StoragePower) error { + s.State.TotalRawBytePower = p + return nil +} + +func (s *state8) SetThisEpochQualityAdjPower(p abi.StoragePower) error { + s.State.ThisEpochQualityAdjPower = p + return nil +} + +func (s *state8) SetThisEpochRawBytePower(p abi.StoragePower) error { + s.State.ThisEpochRawBytePower = p + return nil +} + +func (s *state8) GetState() interface{} { + return &s.State +} + +func (s *state8) claims() (adt.Map, error) { + return adt8.AsMap(s.store, s.Claims, builtin8.DefaultHamtBitwidth) +} + +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, + } +} diff --git a/chain/actors/builtin/reward/actor.go.template b/chain/actors/builtin/reward/actor.go.template index 89cdddaec..3e0e859a3 100644 --- a/chain/actors/builtin/reward/actor.go.template +++ b/chain/actors/builtin/reward/actor.go.template @@ -3,13 +3,16 @@ package reward import ( "github.com/filecoin-project/go-state-types/abi" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" - "github.com/ipfs/go-cid" "github.com/filecoin-project/lotus/chain/actors" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/cbor" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{end}} "github.com/filecoin-project/lotus/chain/actors/adt" @@ -17,25 +20,36 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) -func init() { -{{range .versions}} - builtin.RegisterActorState(builtin{{.}}.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load{{.}}(store, root) - }) -{{end}}} - var ( Address = builtin{{.latestVersion}}.RewardActorAddr Methods = builtin{{.latestVersion}}.MethodsReward ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.RewardKey { + return nil, xerrors.Errorf("actor code is not reward: %s", name) + } + + switch 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, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -49,17 +63,6 @@ func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.Storage return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.RewardActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index b6ee2f146..504c8a9ba 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -4,7 +4,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/actors" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" - "github.com/ipfs/go-cid" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/cbor" @@ -23,48 +22,32 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + builtin8 "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) -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) - }) - - 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) - }) - - builtin.RegisterActorState(builtin5.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load5(store, root) - }) - - builtin.RegisterActorState(builtin6.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load6(store, root) - }) - - builtin.RegisterActorState(builtin7.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) -} - var ( - Address = builtin7.RewardActorAddr - Methods = builtin7.MethodsReward + Address = builtin8.RewardActorAddr + Methods = builtin8.MethodsReward ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.RewardKey { + return nil, xerrors.Errorf("actor code is not reward: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.RewardActorCodeID: @@ -89,6 +72,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -116,39 +100,13 @@ func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.Storage case actors.Version7: return make7(store, currRealizedPower) + case actors.Version8: + return make8(store, currRealizedPower) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.RewardActorCodeID, nil - - case actors.Version2: - return builtin2.RewardActorCodeID, nil - - case actors.Version3: - return builtin3.RewardActorCodeID, nil - - case actors.Version4: - return builtin4.RewardActorCodeID, nil - - case actors.Version5: - return builtin5.RewardActorCodeID, nil - - case actors.Version6: - return builtin6.RewardActorCodeID, nil - - case actors.Version7: - return builtin7.RewardActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/reward/state.go.template b/chain/actors/builtin/reward/state.go.template index 2bc271cbb..dac3d82a4 100644 --- a/chain/actors/builtin/reward/state.go.template +++ b/chain/actors/builtin/reward/state.go.template @@ -7,9 +7,15 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" +{{if (le .v 7)}} miner{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/miner" reward{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/reward" smoothing{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/smoothing" +{{else}} + smoothing{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/smoothing" + miner{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}miner" + reward{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}reward" +{{end}} ) var _ State = (*state{{.v}})(nil) @@ -45,7 +51,7 @@ func (s *state{{.v}}) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate, }, nil {{else}} - return builtin.FromV0FilterEstimate(*s.State.ThisEpochRewardSmoothed), nil + return builtin.FilterEstimate(*s.State.ThisEpochRewardSmoothed), nil {{end}} } diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index cd098c151..646ab3a9a 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -40,7 +40,7 @@ func (s *state0) ThisEpochReward() (abi.TokenAmount, error) { func (s *state0) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) { - return builtin.FromV0FilterEstimate(*s.State.ThisEpochRewardSmoothed), nil + return builtin.FilterEstimate(*s.State.ThisEpochRewardSmoothed), nil } diff --git a/chain/actors/builtin/reward/v8.go b/chain/actors/builtin/reward/v8.go new file mode 100644 index 000000000..3d49063df --- /dev/null +++ b/chain/actors/builtin/reward/v8.go @@ -0,0 +1,98 @@ +package reward + +import ( + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin" + + miner8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" + reward8 "github.com/filecoin-project/go-state-types/builtin/v8/reward" + smoothing8 "github.com/filecoin-project/go-state-types/builtin/v8/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 +} + +func make8(store adt.Store, currRealizedPower abi.StoragePower) (State, error) { + out := state8{store: store} + out.State = *reward8.ConstructState(currRealizedPower) + 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) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/system/actor.go.template b/chain/actors/builtin/system/actor.go.template index 925319970..c5e1af3e4 100644 --- a/chain/actors/builtin/system/actor.go.template +++ b/chain/actors/builtin/system/actor.go.template @@ -3,11 +3,17 @@ package system import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors" - "golang.org/x/xerrors" + "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" + "golang.org/x/xerrors" + {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{end}} ) @@ -15,27 +21,45 @@ var ( Address = builtin{{.latestVersion}}.SystemActorAddr ) -func MakeState(store adt.Store, av actors.Version) (State, error) { +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.SystemKey { + return nil, xerrors.Errorf("actor code is not system: %s", name) + } + + switch av { + {{range .versions}} + {{if (ge . 8)}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + {{end}} + } + } + + switch act.Code { +{{range .versions}} + {{if (le . 7)}} + case builtin{{.}}.SystemActorCodeID: + return load{{.}}(store, act.Head) + {{end}} +{{end}} + } + + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +func MakeState(store adt.Store, av actors.Version, builtinActors cid.Cid) (State, error) { switch av { {{range .versions}} case actors.Version{{.}}: - return make{{.}}(store) + return make{{.}}(store{{if (ge . 8)}}, builtinActors{{end}}) {{end}} } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.SystemActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { GetState() interface{} + GetBuiltinActors() cid.Cid } diff --git a/chain/actors/builtin/system/state.go.template b/chain/actors/builtin/system/state.go.template index fa644f8c7..21b057ad5 100644 --- a/chain/actors/builtin/system/state.go.template +++ b/chain/actors/builtin/system/state.go.template @@ -5,7 +5,11 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" +{{if (le .v 7)}} system{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/system" +{{else}} + system{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}system" +{{end}} ) var _ State = (*state{{.v}})(nil) @@ -19,9 +23,11 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } -func make{{.v}}(store adt.Store) (State, error) { +func make{{.v}}(store adt.Store{{if (ge .v 8)}}, builtinActors cid.Cid{{end}}) (State, error) { out := state{{.v}}{store: store} - out.State = system{{.v}}.State{} + out.State = system{{.v}}.State{ + {{if (ge .v 8)}}BuiltinActors: builtinActors,{{end}} + } return &out, nil } @@ -32,4 +38,12 @@ type state{{.v}} struct { func (s *state{{.v}}) GetState() interface{} { return &s.State +} + +func (s *state{{.v}}) GetBuiltinActors() cid.Cid { +{{if (le .v 7)}} + return cid.Undef +{{else}} + return s.State.BuiltinActors +{{end}} } \ No newline at end of file diff --git a/chain/actors/builtin/system/system.go b/chain/actors/builtin/system/system.go index fb7515f35..64a0f3cba 100644 --- a/chain/actors/builtin/system/system.go +++ b/chain/actors/builtin/system/system.go @@ -3,7 +3,9 @@ package system import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" + "golang.org/x/xerrors" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" @@ -19,13 +21,57 @@ import ( 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/go-state-types/builtin" ) var ( - Address = builtin7.SystemActorAddr + Address = builtin8.SystemActorAddr ) -func MakeState(store adt.Store, av actors.Version) (State, error) { +func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.SystemKey { + return nil, xerrors.Errorf("actor code is not system: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + + switch act.Code { + + case builtin0.SystemActorCodeID: + return load0(store, act.Head) + + case builtin2.SystemActorCodeID: + return load2(store, act.Head) + + case builtin3.SystemActorCodeID: + return load3(store, act.Head) + + case builtin4.SystemActorCodeID: + return load4(store, act.Head) + + case builtin5.SystemActorCodeID: + return load5(store, act.Head) + + case builtin6.SystemActorCodeID: + return load6(store, act.Head) + + case builtin7.SystemActorCodeID: + return load7(store, act.Head) + + } + + return nil, xerrors.Errorf("unknown actor code %s", act.Code) +} + +func MakeState(store adt.Store, av actors.Version, builtinActors cid.Cid) (State, error) { switch av { case actors.Version0: @@ -49,39 +95,14 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { case actors.Version7: return make7(store) + case actors.Version8: + return make8(store, builtinActors) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.SystemActorCodeID, nil - - case actors.Version2: - return builtin2.SystemActorCodeID, nil - - case actors.Version3: - return builtin3.SystemActorCodeID, nil - - case actors.Version4: - return builtin4.SystemActorCodeID, nil - - case actors.Version5: - return builtin5.SystemActorCodeID, nil - - case actors.Version6: - return builtin6.SystemActorCodeID, nil - - case actors.Version7: - return builtin7.SystemActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - type State interface { GetState() interface{} + GetBuiltinActors() cid.Cid } diff --git a/chain/actors/builtin/system/v0.go b/chain/actors/builtin/system/v0.go index 64c6f53d3..a5aa8e8fa 100644 --- a/chain/actors/builtin/system/v0.go +++ b/chain/actors/builtin/system/v0.go @@ -33,3 +33,9 @@ type state0 struct { func (s *state0) GetState() interface{} { return &s.State } + +func (s *state0) GetBuiltinActors() cid.Cid { + + return cid.Undef + +} diff --git a/chain/actors/builtin/system/v2.go b/chain/actors/builtin/system/v2.go index eb540891c..aea9eff7b 100644 --- a/chain/actors/builtin/system/v2.go +++ b/chain/actors/builtin/system/v2.go @@ -33,3 +33,9 @@ type state2 struct { func (s *state2) GetState() interface{} { return &s.State } + +func (s *state2) GetBuiltinActors() cid.Cid { + + return cid.Undef + +} diff --git a/chain/actors/builtin/system/v3.go b/chain/actors/builtin/system/v3.go index 5b04e189e..fd5f0cd50 100644 --- a/chain/actors/builtin/system/v3.go +++ b/chain/actors/builtin/system/v3.go @@ -33,3 +33,9 @@ type state3 struct { func (s *state3) GetState() interface{} { return &s.State } + +func (s *state3) GetBuiltinActors() cid.Cid { + + return cid.Undef + +} diff --git a/chain/actors/builtin/system/v4.go b/chain/actors/builtin/system/v4.go index b6c924978..fbdec7e93 100644 --- a/chain/actors/builtin/system/v4.go +++ b/chain/actors/builtin/system/v4.go @@ -33,3 +33,9 @@ type state4 struct { func (s *state4) GetState() interface{} { return &s.State } + +func (s *state4) GetBuiltinActors() cid.Cid { + + return cid.Undef + +} diff --git a/chain/actors/builtin/system/v5.go b/chain/actors/builtin/system/v5.go index 77d2a8478..3d3c27a12 100644 --- a/chain/actors/builtin/system/v5.go +++ b/chain/actors/builtin/system/v5.go @@ -33,3 +33,9 @@ type state5 struct { func (s *state5) GetState() interface{} { return &s.State } + +func (s *state5) GetBuiltinActors() cid.Cid { + + return cid.Undef + +} diff --git a/chain/actors/builtin/system/v6.go b/chain/actors/builtin/system/v6.go index 689620afb..314308845 100644 --- a/chain/actors/builtin/system/v6.go +++ b/chain/actors/builtin/system/v6.go @@ -33,3 +33,9 @@ type state6 struct { func (s *state6) GetState() interface{} { return &s.State } + +func (s *state6) GetBuiltinActors() cid.Cid { + + return cid.Undef + +} diff --git a/chain/actors/builtin/system/v7.go b/chain/actors/builtin/system/v7.go index 813add5fb..3987db8dd 100644 --- a/chain/actors/builtin/system/v7.go +++ b/chain/actors/builtin/system/v7.go @@ -33,3 +33,9 @@ type state7 struct { func (s *state7) GetState() interface{} { return &s.State } + +func (s *state7) GetBuiltinActors() cid.Cid { + + return cid.Undef + +} diff --git a/chain/actors/builtin/system/v8.go b/chain/actors/builtin/system/v8.go new file mode 100644 index 000000000..a30d5fa30 --- /dev/null +++ b/chain/actors/builtin/system/v8.go @@ -0,0 +1,43 @@ +package system + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + system8 "github.com/filecoin-project/go-state-types/builtin/v8/system" +) + +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, builtinActors cid.Cid) (State, error) { + out := state8{store: store} + out.State = system8.State{ + BuiltinActors: builtinActors, + } + return &out, nil +} + +type state8 struct { + system8.State + store adt.Store +} + +func (s *state8) GetState() interface{} { + return &s.State +} + +func (s *state8) GetBuiltinActors() cid.Cid { + + return s.State.BuiltinActors + +} diff --git a/chain/actors/builtin/verifreg/actor.go.template b/chain/actors/builtin/verifreg/actor.go.template index adc156948..3df256004 100644 --- a/chain/actors/builtin/verifreg/actor.go.template +++ b/chain/actors/builtin/verifreg/actor.go.template @@ -1,7 +1,6 @@ package verifreg import ( - "github.com/ipfs/go-cid" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -9,36 +8,48 @@ import ( "github.com/filecoin-project/go-state-types/cbor" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{if (le . 7)}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + {{else}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + {{end}} {{end}} "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" - verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg" ) -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 Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.VerifregKey { + return nil, xerrors.Errorf("actor code is not verifreg: %s", name) + } + + switch 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, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -52,23 +63,6 @@ func MakeState(store adt.Store, av actors.Version, rootKeyAddress address.Addres return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { -{{range .versions}} - case actors.Version{{.}}: - return builtin{{.}}.VerifiedRegistryActorCodeID, nil -{{end}} - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - -type RemoveDataCapProposal = verifreg{{.latestVersion}}.RemoveDataCapProposal -type RemoveDataCapRequest = verifreg{{.latestVersion}}.RemoveDataCapRequest -type RemoveDataCapParams = verifreg{{.latestVersion}}.RemoveDataCapParams -type RmDcProposalID = verifreg{{.latestVersion}}.RmDcProposalID -const SignatureDomainSeparation_RemoveDataCap = verifreg{{.latestVersion}}.SignatureDomainSeparation_RemoveDataCap - type State interface { cbor.Marshaler diff --git a/chain/actors/builtin/verifreg/state.go.template b/chain/actors/builtin/verifreg/state.go.template index 4dfc11469..aaca86905 100644 --- a/chain/actors/builtin/verifreg/state.go.template +++ b/chain/actors/builtin/verifreg/state.go.template @@ -8,9 +8,17 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" -{{if (ge .v 3)}} builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" -{{end}} verifreg{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/verifreg" +{{if (le .v 7)}} + {{if (ge .v 3)}} + builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" + {{end}} + 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}} + verifreg{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}verifreg" + 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) diff --git a/chain/actors/builtin/verifreg/v3.go b/chain/actors/builtin/verifreg/v3.go index c71c69f92..b7ab18080 100644 --- a/chain/actors/builtin/verifreg/v3.go +++ b/chain/actors/builtin/verifreg/v3.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" 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" ) diff --git a/chain/actors/builtin/verifreg/v4.go b/chain/actors/builtin/verifreg/v4.go index d3adc5169..aee3fbdca 100644 --- a/chain/actors/builtin/verifreg/v4.go +++ b/chain/actors/builtin/verifreg/v4.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" 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" ) diff --git a/chain/actors/builtin/verifreg/v5.go b/chain/actors/builtin/verifreg/v5.go index 2af501af3..4a74e1ea8 100644 --- a/chain/actors/builtin/verifreg/v5.go +++ b/chain/actors/builtin/verifreg/v5.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" 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" ) diff --git a/chain/actors/builtin/verifreg/v6.go b/chain/actors/builtin/verifreg/v6.go index 454c9478f..a776f1149 100644 --- a/chain/actors/builtin/verifreg/v6.go +++ b/chain/actors/builtin/verifreg/v6.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" 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" ) diff --git a/chain/actors/builtin/verifreg/v7.go b/chain/actors/builtin/verifreg/v7.go index 3bcfa10bd..39d72a15d 100644 --- a/chain/actors/builtin/verifreg/v7.go +++ b/chain/actors/builtin/verifreg/v7.go @@ -9,6 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" 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" ) diff --git a/chain/actors/builtin/verifreg/v8.go b/chain/actors/builtin/verifreg/v8.go new file mode 100644 index 000000000..95fdf2e6d --- /dev/null +++ b/chain/actors/builtin/verifreg/v8.go @@ -0,0 +1,83 @@ +package verifreg + +import ( + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/abi" + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + + builtin8 "github.com/filecoin-project/go-state-types/builtin" + adt8 "github.com/filecoin-project/go-state-types/builtin/v8/util/adt" + verifreg8 "github.com/filecoin-project/go-state-types/builtin/v8/verifreg" +) + +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, rootKeyAddress address.Address) (State, error) { + out := state8{store: store} + + s, err := verifreg8.ConstructState(store, rootKeyAddress) + if err != nil { + return nil, err + } + + out.State = *s + + 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.verifiedClients, addr) +} + +func (s *state8) VerifierDataCap(addr address.Address) (bool, abi.StoragePower, error) { + return getDataCap(s.store, actors.Version8, s.verifiers, addr) +} + +func (s *state8) RemoveDataCapProposalID(verifier address.Address, client address.Address) (bool, uint64, error) { + return getRemoveDataCapProposalID(s.store, actors.Version8, s.removeDataCapProposalIDs, verifier, client) +} + +func (s *state8) ForEachVerifier(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, actors.Version8, s.verifiers, cb) +} + +func (s *state8) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error { + return forEachCap(s.store, actors.Version8, s.verifiedClients, cb) +} + +func (s *state8) verifiedClients() (adt.Map, error) { + return adt8.AsMap(s.store, s.VerifiedClients, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) verifiers() (adt.Map, error) { + return adt8.AsMap(s.store, s.Verifiers, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) removeDataCapProposalIDs() (adt.Map, error) { + return adt8.AsMap(s.store, s.RemoveDataCapProposalIDs, builtin8.DefaultHamtBitwidth) +} + +func (s *state8) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index cb26e324b..7c04bb733 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -1,7 +1,6 @@ package verifreg import ( - "github.com/ipfs/go-cid" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -23,51 +22,32 @@ import ( builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" + builtin8 "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" - verifreg7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/verifreg" ) -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) - }) - - builtin.RegisterActorState(builtin7.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { - return load7(store, root) - }) - -} - var ( - Address = builtin7.VerifiedRegistryActorAddr - Methods = builtin7.MethodsVerifiedRegistry + Address = builtin8.VerifiedRegistryActorAddr + Methods = builtin8.MethodsVerifiedRegistry ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != actors.VerifregKey { + return nil, xerrors.Errorf("actor code is not verifreg: %s", name) + } + + switch av { + + case actors.Version8: + return load8(store, act.Head) + + } + } + switch act.Code { case builtin0.VerifiedRegistryActorCodeID: @@ -92,6 +72,7 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return load7(store, act.Head) } + return nil, xerrors.Errorf("unknown actor code %s", act.Code) } @@ -119,46 +100,13 @@ func MakeState(store adt.Store, av actors.Version, rootKeyAddress address.Addres case actors.Version7: return make7(store, rootKeyAddress) + case actors.Version8: + return make8(store, rootKeyAddress) + } return nil, xerrors.Errorf("unknown actor version %d", av) } -func GetActorCodeID(av actors.Version) (cid.Cid, error) { - switch av { - - case actors.Version0: - return builtin0.VerifiedRegistryActorCodeID, nil - - case actors.Version2: - return builtin2.VerifiedRegistryActorCodeID, nil - - case actors.Version3: - return builtin3.VerifiedRegistryActorCodeID, nil - - case actors.Version4: - return builtin4.VerifiedRegistryActorCodeID, nil - - case actors.Version5: - return builtin5.VerifiedRegistryActorCodeID, nil - - case actors.Version6: - return builtin6.VerifiedRegistryActorCodeID, nil - - case actors.Version7: - return builtin7.VerifiedRegistryActorCodeID, nil - - } - - return cid.Undef, xerrors.Errorf("unknown actor version %d", av) -} - -type RemoveDataCapProposal = verifreg7.RemoveDataCapProposal -type RemoveDataCapRequest = verifreg7.RemoveDataCapRequest -type RemoveDataCapParams = verifreg7.RemoveDataCapParams -type RmDcProposalID = verifreg7.RmDcProposalID - -const SignatureDomainSeparation_RemoveDataCap = verifreg7.SignatureDomainSeparation_RemoveDataCap - type State interface { cbor.Marshaler diff --git a/chain/actors/manifest.go b/chain/actors/manifest.go new file mode 100644 index 000000000..452b763ea --- /dev/null +++ b/chain/actors/manifest.go @@ -0,0 +1,144 @@ +package actors + +import ( + "context" + "strings" + "sync" + + "github.com/filecoin-project/go-state-types/manifest" + + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/chain/actors/adt" + cid "github.com/ipfs/go-cid" + cbor "github.com/ipfs/go-ipld-cbor" +) + +var manifestCids map[Version]cid.Cid = make(map[Version]cid.Cid) +var manifests map[Version]map[string]cid.Cid = make(map[Version]map[string]cid.Cid) +var actorMeta map[cid.Cid]actorEntry = make(map[cid.Cid]actorEntry) + +const ( + AccountKey = "account" + CronKey = "cron" + InitKey = "init" + MarketKey = "storagemarket" + MinerKey = "storageminer" + MultisigKey = "multisig" + PaychKey = "paymentchannel" + PowerKey = "storagepower" + RewardKey = "reward" + SystemKey = "system" + VerifregKey = "verifiedregistry" +) + +func GetBuiltinActorsKeys() []string { + return []string{ + AccountKey, + CronKey, + InitKey, + MarketKey, + MinerKey, + MultisigKey, + PaychKey, + PowerKey, + RewardKey, + SystemKey, + VerifregKey, + } +} + +var ( + manifestMx sync.RWMutex +) + +type actorEntry struct { + name string + version Version +} + +// ClearManifest clears all known manifests. This is usually used in tests that need to switch networks. +func ClearManifests() { + manifestMx.Lock() + defer manifestMx.Unlock() + + manifestCids = make(map[Version]cid.Cid) + manifests = make(map[Version]map[string]cid.Cid) + actorMeta = make(map[cid.Cid]actorEntry) +} + +// RegisterManifest registers an actors manifest with lotus. +func RegisterManifest(av Version, manifestCid cid.Cid, entries map[string]cid.Cid) { + manifestMx.Lock() + defer manifestMx.Unlock() + + manifestCids[av] = manifestCid + manifests[av] = entries + + for name, c := range entries { + actorMeta[c] = actorEntry{name: name, version: av} + } +} + +// GetManifest gets a loaded manifest. +func GetManifest(av Version) (cid.Cid, bool) { + manifestMx.RLock() + defer manifestMx.RUnlock() + + c, ok := manifestCids[av] + return c, ok +} + +// ReadManifest reads a manifest from a blockstore. It does not "add" it. +func ReadManifest(ctx context.Context, store cbor.IpldStore, mfCid cid.Cid) (map[string]cid.Cid, error) { + adtStore := adt.WrapStore(ctx, store) + + var mf manifest.Manifest + if err := adtStore.Get(ctx, mfCid, &mf); err != nil { + return nil, xerrors.Errorf("error reading manifest (cid: %s): %w", mfCid, err) + } + + if err := mf.Load(ctx, adtStore); err != nil { + return nil, xerrors.Errorf("error loading manifest (cid: %s): %w", mfCid, err) + } + + actorKeys := GetBuiltinActorsKeys() // TODO: we should be able to enumerate manifests directly. + metadata := make(map[string]cid.Cid, len(actorKeys)) + for _, name := range actorKeys { + if c, ok := mf.Get(name); ok { + metadata[name] = c + } + } + + return metadata, nil +} + +// 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) { + manifestMx.RLock() + defer manifestMx.RUnlock() + + c, ok := manifests[av][name] + return c, ok +} + +func GetActorMetaByCode(c cid.Cid) (string, Version, bool) { + manifestMx.RLock() + defer manifestMx.RUnlock() + + entry, ok := actorMeta[c] + if !ok { + return "", -1, false + } + + return entry.name, entry.version, true +} + +func CanonicalName(name string) string { + idx := strings.LastIndex(name, "/") + if idx >= 0 { + return name[idx+1:] + } + + return name +} diff --git a/chain/actors/policy/policy.go b/chain/actors/policy/policy.go index f51da7aa7..f4f04f4a9 100644 --- a/chain/actors/policy/policy.go +++ b/chain/actors/policy/policy.go @@ -12,47 +12,59 @@ import ( 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" + power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" + 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" + builtin8 "github.com/filecoin-project/go-state-types/builtin" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" + miner8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" + verifreg8 "github.com/filecoin-project/go-state-types/builtin/v8/verifreg" + + paych8 "github.com/filecoin-project/go-state-types/builtin/v8/paych" ) const ( - ChainFinality = miner7.ChainFinality + ChainFinality = miner8.ChainFinality SealRandomnessLookback = ChainFinality - PaychSettleDelay = paych7.SettleDelay - MaxPreCommitRandomnessLookback = builtin7.EpochsInDay + SealRandomnessLookback + PaychSettleDelay = paych8.SettleDelay + MaxPreCommitRandomnessLookback = builtin8.EpochsInDay + SealRandomnessLookback ) // SetSupportedProofTypes sets supported proof types, across all actor versions. @@ -79,6 +91,8 @@ func SetSupportedProofTypes(types ...abi.RegisteredSealProof) { miner7.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + miner8.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + AddSupportedProofTypes(types...) } @@ -135,6 +149,15 @@ func AddSupportedProofTypes(types ...abi.RegisteredSealProof) { miner7.WindowPoStProofTypes[wpp] = struct{}{} + miner8.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} + wpp, err = t.RegisteredWindowPoStProof() + if err != nil { + // Fine to panic, this is a test-only method + panic(err) + } + + miner8.WindowPoStProofTypes[wpp] = struct{}{} + } } @@ -157,11 +180,13 @@ func SetPreCommitChallengeDelay(delay abi.ChainEpoch) { miner7.PreCommitChallengeDelay = delay + miner8.PreCommitChallengeDelay = delay + } // TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay. func GetPreCommitChallengeDelay() abi.ChainEpoch { - return miner7.PreCommitChallengeDelay + return miner8.PreCommitChallengeDelay } // SetConsensusMinerMinPower sets the minimum power of an individual miner must @@ -195,6 +220,10 @@ func SetConsensusMinerMinPower(p abi.StoragePower) { policy.ConsensusMinerMinPower = p } + for _, policy := range builtin8.PoStProofPolicies { + policy.ConsensusMinerMinPower = p + } + } // SetMinVerifiedDealSize sets the minimum size of a verified deal. This should @@ -215,6 +244,8 @@ func SetMinVerifiedDealSize(size abi.StoragePower) { verifreg7.MinVerifiedDealSize = size + verifreg8.MinVerifiedDealSize = size + } func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (abi.ChainEpoch, error) { @@ -248,6 +279,10 @@ func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) (a return miner7.MaxProveCommitDuration[t], nil + case actors.Version8: + + return miner8.MaxProveCommitDuration[t], nil + default: return 0, xerrors.Errorf("unsupported actors version") } @@ -288,6 +323,11 @@ func SetProviderCollateralSupplyTarget(num, denom big.Int) { Denominator: denom, } + market8.ProviderCollateralSupplyTarget = builtin8.BigFrac{ + Numerator: num, + Denominator: denom, + } + } func DealProviderCollateralBounds( @@ -336,13 +376,18 @@ func DealProviderCollateralBounds( min, max := market7.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) return min, max, nil + case actors.Version8: + + min, max := market8.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) + return min, max, nil + default: return big.Zero(), big.Zero(), xerrors.Errorf("unsupported actors version") } } func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) { - return market7.DealDurationBounds(pieceSize) + return market8.DealDurationBounds(pieceSize) } // Sets the challenge window and scales the proving period to match (such that @@ -390,6 +435,13 @@ func SetWPoStChallengeWindow(period abi.ChainEpoch) { // scale it if we're scaling the challenge period. miner7.WPoStDisputeWindow = period * 30 + miner8.WPoStChallengeWindow = period + miner8.WPoStProvingPeriod = period * abi.ChainEpoch(miner8.WPoStPeriodDeadlines) + + // by default, this is 2x finality which is 30 periods. + // scale it if we're scaling the challenge period. + miner8.WPoStDisputeWindow = period * 30 + } func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { @@ -402,15 +454,15 @@ func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { } func GetMaxSectorExpirationExtension() abi.ChainEpoch { - return miner7.MaxSectorExpirationExtension + return miner8.MaxSectorExpirationExtension } func GetMinSectorExpiration() abi.ChainEpoch { - return miner7.MinSectorExpiration + return miner8.MinSectorExpiration } func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, error) { - sectorsPerPart, err := builtin7.PoStProofWindowPoStPartitionSectors(p) + sectorsPerPart, err := builtin8.PoStProofWindowPoStPartitionSectors(p) if err != nil { return 0, err } @@ -423,8 +475,8 @@ func GetMaxPoStPartitions(nv network.Version, p abi.RegisteredPoStProof) (int, e 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 { + szs := make([]abi.SectorSize, 0, len(miner8.PreCommitSealProofTypesV8)) + for spt := range miner8.PreCommitSealProofTypesV8 { ss, err := spt.SectorSize() if err != nil { panic(err) @@ -449,7 +501,7 @@ func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) return builtin4.SealProofPoliciesV0[proof].SectorMaxLifetime } - return builtin7.SealProofPoliciesV11[proof].SectorMaxLifetime + return builtin8.SealProofPoliciesV11[proof].SectorMaxLifetime } func GetAddressedSectorsMax(nwVer network.Version) (int, error) { @@ -480,6 +532,9 @@ func GetAddressedSectorsMax(nwVer network.Version) (int, error) { case actors.Version7: return miner7.AddressedSectorsMax, nil + case actors.Version8: + return miner8.AddressedSectorsMax, nil + default: return 0, xerrors.Errorf("unsupported network version") } @@ -521,6 +576,10 @@ func GetDeclarationsMax(nwVer network.Version) (int, error) { return miner7.DeclarationsMax, nil + case actors.Version8: + + return miner8.DeclarationsMax, nil + default: return 0, xerrors.Errorf("unsupported network version") } @@ -561,6 +620,10 @@ func AggregateProveCommitNetworkFee(nwVer network.Version, aggregateSize int, ba return miner7.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil + case actors.Version8: + + return miner8.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil + default: return big.Zero(), xerrors.Errorf("unsupported network version") } @@ -601,6 +664,10 @@ func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, base return miner7.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil + case actors.Version8: + + return miner8.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil + default: return big.Zero(), xerrors.Errorf("unsupported network version") } diff --git a/chain/actors/policy/policy.go.template b/chain/actors/policy/policy.go.template index 64c1b7083..090e91165 100644 --- a/chain/actors/policy/policy.go.template +++ b/chain/actors/policy/policy.go.template @@ -11,14 +11,26 @@ import ( "github.com/filecoin-project/lotus/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}} + {{if (ge . 8)}} + builtin{{.}} "github.com/filecoin-project/go-state-types/builtin" + miner{{.}} "github.com/filecoin-project/go-state-types/builtin{{import .}}miner" + market{{.}} "github.com/filecoin-project/go-state-types/builtin{{import .}}market" + verifreg{{.}} "github.com/filecoin-project/go-state-types/builtin{{import .}}verifreg" + {{else}} + {{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}} {{end}} - paych{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/paych" + paych{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin{{import .latestVersion}}paych" + ) const ( diff --git a/chain/actors/version.go b/chain/actors/version.go index af51161c9..1a17a6972 100644 --- a/chain/actors/version.go +++ b/chain/actors/version.go @@ -20,9 +20,9 @@ const ({{range .actorVersions}} /* inline-gen start */ -var LatestVersion = 7 +var LatestVersion = 8 -var Versions = []int{0, 2, 3, 4, 5, 6, 7} +var Versions = []int{0, 2, 3, 4, 5, 6, 7, 8} const ( Version0 Version = 0 @@ -32,6 +32,7 @@ const ( Version5 Version = 5 Version6 Version = 6 Version7 Version = 7 + Version8 Version = 8 ) /* inline-gen end */ @@ -53,6 +54,8 @@ func VersionForNetwork(version network.Version) (Version, error) { return Version6, nil case network.Version15: return Version7, nil + case network.Version16: + return Version8, nil default: return -1, fmt.Errorf("unsupported network version %d", version) } diff --git a/chain/beacon/beacon.go b/chain/beacon/beacon.go index 220057282..9c795fc91 100644 --- a/chain/beacon/beacon.go +++ b/chain/beacon/beacon.go @@ -3,6 +3,8 @@ package beacon import ( "context" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/abi" logging "github.com/ipfs/go-log/v2" "golang.org/x/xerrors" @@ -42,10 +44,10 @@ type BeaconPoint struct { type RandomBeacon interface { Entry(context.Context, uint64) <-chan Response VerifyEntry(types.BeaconEntry, types.BeaconEntry) error - MaxBeaconRoundForEpoch(abi.ChainEpoch) uint64 + MaxBeaconRoundForEpoch(network.Version, abi.ChainEpoch) uint64 } -func ValidateBlockValues(bSchedule Schedule, h *types.BlockHeader, parentEpoch abi.ChainEpoch, +func ValidateBlockValues(bSchedule Schedule, nv network.Version, h *types.BlockHeader, parentEpoch abi.ChainEpoch, prevEntry types.BeaconEntry) error { { parentBeacon := bSchedule.BeaconForEpoch(parentEpoch) @@ -65,7 +67,7 @@ func ValidateBlockValues(bSchedule Schedule, h *types.BlockHeader, parentEpoch a // TODO: fork logic b := bSchedule.BeaconForEpoch(h.Height) - maxRound := b.MaxBeaconRoundForEpoch(h.Height) + maxRound := b.MaxBeaconRoundForEpoch(nv, h.Height) if maxRound == prevEntry.Round { if len(h.BeaconEntries) != 0 { return xerrors.Errorf("expected not to have any beacon entries in this block, got %d", len(h.BeaconEntries)) @@ -92,13 +94,13 @@ func ValidateBlockValues(bSchedule Schedule, h *types.BlockHeader, parentEpoch a return nil } -func BeaconEntriesForBlock(ctx context.Context, bSchedule Schedule, epoch abi.ChainEpoch, parentEpoch abi.ChainEpoch, prev types.BeaconEntry) ([]types.BeaconEntry, error) { +func BeaconEntriesForBlock(ctx context.Context, bSchedule Schedule, nv network.Version, epoch abi.ChainEpoch, parentEpoch abi.ChainEpoch, prev types.BeaconEntry) ([]types.BeaconEntry, error) { { parentBeacon := bSchedule.BeaconForEpoch(parentEpoch) currBeacon := bSchedule.BeaconForEpoch(epoch) if parentBeacon != currBeacon { // Fork logic - round := currBeacon.MaxBeaconRoundForEpoch(epoch) + round := currBeacon.MaxBeaconRoundForEpoch(nv, epoch) out := make([]types.BeaconEntry, 2) rch := currBeacon.Entry(ctx, round-1) res := <-rch @@ -120,7 +122,7 @@ func BeaconEntriesForBlock(ctx context.Context, bSchedule Schedule, epoch abi.Ch start := build.Clock.Now() - maxRound := beacon.MaxBeaconRoundForEpoch(epoch) + maxRound := beacon.MaxBeaconRoundForEpoch(nv, epoch) if maxRound == prev.Round { return nil, nil } diff --git a/chain/beacon/drand/drand.go b/chain/beacon/drand/drand.go index 118ab36e6..550fefab4 100644 --- a/chain/beacon/drand/drand.go +++ b/chain/beacon/drand/drand.go @@ -5,6 +5,8 @@ import ( "context" "time" + "github.com/filecoin-project/go-state-types/network" + dchain "github.com/drand/drand/chain" dclient "github.com/drand/drand/client" hclient "github.com/drand/drand/client/http" @@ -201,11 +203,32 @@ func (db *DrandBeacon) VerifyEntry(curr types.BeaconEntry, prev types.BeaconEntr return err } -func (db *DrandBeacon) MaxBeaconRoundForEpoch(filEpoch abi.ChainEpoch) uint64 { +func (db *DrandBeacon) MaxBeaconRoundForEpoch(nv network.Version, filEpoch abi.ChainEpoch) uint64 { // TODO: sometimes the genesis time for filecoin is zero and this goes negative latestTs := ((uint64(filEpoch) * db.filRoundTime) + db.filGenTime) - db.filRoundTime + + if nv <= network.Version15 { + return db.maxBeaconRoundV1(latestTs) + } + + return db.maxBeaconRoundV2(latestTs) +} + +func (db *DrandBeacon) maxBeaconRoundV1(latestTs uint64) uint64 { dround := (latestTs - db.drandGenTime) / uint64(db.interval.Seconds()) return dround } +func (db *DrandBeacon) maxBeaconRoundV2(latestTs uint64) uint64 { + if latestTs < db.drandGenTime { + return 1 + } + + fromGenesis := latestTs - db.drandGenTime + // we take the time from genesis divided by the periods in seconds, that + // gives us the number of periods since genesis. We also add +1 because + // round 1 starts at genesis time. + return fromGenesis/uint64(db.interval.Seconds()) + 1 +} + var _ beacon.RandomBeacon = (*DrandBeacon)(nil) diff --git a/chain/beacon/drand/drand_test.go b/chain/beacon/drand/drand_test.go index 44effd506..4990dfb01 100644 --- a/chain/beacon/drand/drand_test.go +++ b/chain/beacon/drand/drand_test.go @@ -6,6 +6,8 @@ import ( "os" "testing" + "github.com/filecoin-project/go-state-types/network" + dchain "github.com/drand/drand/chain" hclient "github.com/drand/drand/client/http" "github.com/stretchr/testify/assert" @@ -25,3 +27,12 @@ func TestPrintGroupInfo(t *testing.T) { err = chain.ToJSON(os.Stdout) assert.NoError(t, err) } + +func TestMaxBeaconRoundForEpoch(t *testing.T) { + todayTs := uint64(1652222222) + db, err := NewDrandBeacon(todayTs, build.BlockDelaySecs, nil, build.DrandConfigs[build.DrandDevnet]) + assert.NoError(t, err) + mbr15 := db.MaxBeaconRoundForEpoch(network.Version15, 100) + mbr16 := db.MaxBeaconRoundForEpoch(network.Version16, 100) + assert.Equal(t, mbr15+1, mbr16) +} diff --git a/chain/beacon/mock.go b/chain/beacon/mock.go index 2fc64b956..811698905 100644 --- a/chain/beacon/mock.go +++ b/chain/beacon/mock.go @@ -6,6 +6,8 @@ import ( "encoding/binary" "time" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/types" "github.com/minio/blake2b-simd" @@ -53,7 +55,7 @@ func (mb *mockBeacon) VerifyEntry(from types.BeaconEntry, to types.BeaconEntry) return nil } -func (mb *mockBeacon) MaxBeaconRoundForEpoch(epoch abi.ChainEpoch) uint64 { +func (mb *mockBeacon) MaxBeaconRoundForEpoch(nv network.Version, epoch abi.ChainEpoch) uint64 { // offset for better testing return uint64(epoch + 100) } diff --git a/chain/consensus/filcns/FVMLiftoff.txt b/chain/consensus/filcns/FVMLiftoff.txt new file mode 100644 index 000000000..4bff5c25b --- /dev/null +++ b/chain/consensus/filcns/FVMLiftoff.txt @@ -0,0 +1,57 @@ + . + + . ' ` . + . ' . + + . ' . ' | + . ' . ' | ++ . ' . + +| ` . . ' . ' . +| + . ' . + ++ | . ' . ' | + ` . | . ' . ' | ++ + . ' . + +| ` . . ' . ' +| + . ' ++ | . ' . + ` . | '. ` . + + ` . ` . + ` . ` . ` . --- --- + ` . ` . . + /\__\ ___ /\ \ + ` . + ' | /:/ _/_ /\ \ |::\ \ + ` . | | /:/ /\__\ \:\ \ |:|:\ \ + ` . | . + /:/ /:/ / \:\ \ __|:|\:\ \ + + ' /:/_/:/ / ___ \:\__\ /::::|_\:\__\ + \:\/:/ / /\ \ |:| | \:\~~\ \/__/ + \::/__/ \:\ \|:| | \:\ \ + \:\ \ \:\__|:|__| \:\ \ + \:\__\ \::::/__/ \:\__\ + \/__/ ~~~~ \/__/ + ___ ___ ___ ___ + /\__\ /\ \ /\__\ /\__\ + ___ /:/ _/_ ___ /::\ \ /:/ _/_ /:/ _/_ + /\__\ /:/ /\__\ /\__\ /:/\:\ \ /:/ /\__\ /:/ /\__\ + ___ ___ /:/__/ /:/ /:/ / /:/ / /:/ \:\ \ /:/ /:/ / /:/ /:/ / + /\ \ /\__\ /::\ \ /:/_/:/ / /:/__/ /:/__/ \:\__\ /:/_/:/ / /:/_/:/ / + \:\ \ /:/ / \/\:\ \__ \:\/:/ / /::\ \ \:\ \ /:/ / \:\/:/ / \:\/:/ / + \:\ /:/ / ~~\:\/\__\ \::/__/ /:/\:\ \ \:\ /:/ / \::/__/ \::/__/ . + + \:\/:/ / \::/ / \:\ \ \/__\:\ \ \:\/:/ / \:\ \ \:\ \ . ' ` . + \::/ / /:/ / \:\__\ \:\__\ \::/ / \:\__\ \:\__\ . ' . + + \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ \/__/ . ' . ' | + . ' . ' | + + . ' . + + | ` . . ' . ' . + | + . ' . + + + | . ' . ' | + ` . | . ' . ' | + + + . ' . + + | ` . . ' . ' + | + . ' + + | . ' . + ` . | '. ` . + + ` . ` . + ` . ` . ` . + ` . ` . . + + ` . + ' | + ` . | | + ` . | . + + + diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 9b2183a59..657b2dd5a 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -2,21 +2,8 @@ package filcns import ( "context" - "os" "sync/atomic" - "github.com/filecoin-project/lotus/chain/rand" - - "github.com/ipfs/go-cid" - cbg "github.com/whyrusleeping/cbor-gen" - "go.opencensus.io/stats" - "go.opencensus.io/trace" - "golang.org/x/xerrors" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" - blockadt "github.com/filecoin-project/specs-actors/actors/util/adt" - /* inline-gen template {{range .actorVersions}} exported{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/exported"{{end}} @@ -30,9 +17,22 @@ import ( exported5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/exported" exported6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/exported" exported7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/exported" + exported8 "github.com/filecoin-project/specs-actors/v8/actors/builtin/exported" /* inline-gen end */ + "github.com/filecoin-project/lotus/chain/rand" + + "github.com/ipfs/go-cid" + cbg "github.com/whyrusleeping/cbor-gen" + "go.opencensus.io/stats" + "go.opencensus.io/trace" + "golang.org/x/xerrors" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/big" + blockadt "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" @@ -49,20 +49,21 @@ import ( func NewActorRegistry() *vm.ActorRegistry { inv := vm.NewActorRegistry() - // TODO: define all these properties on the actors themselves, in specs-actors. /* inline-gen template {{range .actorVersions}} - inv.Register(vm.ActorsVersionPredicate(actors.Version{{.}}), exported{{.}}.BuiltinActors()...){{end}} + inv.Register(actors.Version{{.}}, vm.ActorsVersionPredicate(actors.Version{{.}}), exported{{.}}.BuiltinActors()...){{end}} + /* inline-gen start */ - inv.Register(vm.ActorsVersionPredicate(actors.Version0), exported0.BuiltinActors()...) - inv.Register(vm.ActorsVersionPredicate(actors.Version2), exported2.BuiltinActors()...) - inv.Register(vm.ActorsVersionPredicate(actors.Version3), exported3.BuiltinActors()...) - inv.Register(vm.ActorsVersionPredicate(actors.Version4), exported4.BuiltinActors()...) - inv.Register(vm.ActorsVersionPredicate(actors.Version5), exported5.BuiltinActors()...) - inv.Register(vm.ActorsVersionPredicate(actors.Version6), exported6.BuiltinActors()...) - inv.Register(vm.ActorsVersionPredicate(actors.Version7), exported7.BuiltinActors()...) + inv.Register(actors.Version0, vm.ActorsVersionPredicate(actors.Version0), exported0.BuiltinActors()...) + inv.Register(actors.Version2, vm.ActorsVersionPredicate(actors.Version2), exported2.BuiltinActors()...) + inv.Register(actors.Version3, vm.ActorsVersionPredicate(actors.Version3), exported3.BuiltinActors()...) + inv.Register(actors.Version4, vm.ActorsVersionPredicate(actors.Version4), exported4.BuiltinActors()...) + inv.Register(actors.Version5, vm.ActorsVersionPredicate(actors.Version5), exported5.BuiltinActors()...) + inv.Register(actors.Version6, vm.ActorsVersionPredicate(actors.Version6), exported6.BuiltinActors()...) + inv.Register(actors.Version7, vm.ActorsVersionPredicate(actors.Version7), exported7.BuiltinActors()...) + inv.Register(actors.Version8, vm.ActorsVersionPredicate(actors.Version8), exported8.BuiltinActors()...) /* inline-gen end */ @@ -109,19 +110,6 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts), } - if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" { - // This is needed so that the FVM does not have to duplicate the genesis vesting schedule, one - // of the components of the circ supply calc. - // This field is NOT needed by the LegacyVM, and also NOT needed by the FVM from v15 onwards. - filVested, err := sm.GetFilVested(ctx, e) - if err != nil { - return nil, err - } - - vmopt.FilVested = filVested - return vm.NewFVM(ctx, vmopt) - } - return sm.VMConstructor()(ctx, vmopt) } diff --git a/chain/consensus/filcns/filecoin.go b/chain/consensus/filcns/filecoin.go index 3aa85c7c5..be608cecc 100644 --- a/chain/consensus/filcns/filecoin.go +++ b/chain/consensus/filcns/filecoin.go @@ -264,7 +264,8 @@ func (filec *FilecoinEC) ValidateBlock(ctx context.Context, b *types.FullBlock) return nil } - if err := beacon.ValidateBlockValues(filec.beacon, h, baseTs.Height(), *prevBeacon); err != nil { + nv := filec.sm.GetNetworkVersion(ctx, h.Height) + if err := beacon.ValidateBlockValues(filec.beacon, nv, h, baseTs.Height(), *prevBeacon); err != nil { return xerrors.Errorf("failed to validate blocks random beacon values: %w", err) } return nil @@ -488,7 +489,7 @@ func (filec *FilecoinEC) checkBlockMessages(ctx context.Context, b *types.FullBl // Phase 2: (Partial) semantic validation: // the sender exists and is an account actor, and the nonces make sense var sender address.Address - if filec.sm.GetNetworkVersion(ctx, b.Header.Height) >= network.Version13 { + if nv >= network.Version13 { sender, err = st.LookupID(m.From) if err != nil { return xerrors.Errorf("failed to lookup sender %s: %w", m.From, err) diff --git a/chain/consensus/filcns/upgrades.go b/chain/consensus/filcns/upgrades.go index 116684b9f..33dbe638f 100644 --- a/chain/consensus/filcns/upgrades.go +++ b/chain/consensus/filcns/upgrades.go @@ -2,14 +2,13 @@ package filcns import ( "context" + "fmt" "runtime" "time" + _ "embed" + "github.com/docker/go-units" - - "github.com/filecoin-project/specs-actors/v6/actors/migration/nv14" - "github.com/filecoin-project/specs-actors/v7/actors/migration/nv15" - "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" @@ -17,8 +16,10 @@ import ( "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/manifest" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-state-types/rt" + gstStore "github.com/filecoin-project/go-state-types/store" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" @@ -31,18 +32,27 @@ import ( "github.com/filecoin-project/specs-actors/v3/actors/migration/nv10" "github.com/filecoin-project/specs-actors/v4/actors/migration/nv12" "github.com/filecoin-project/specs-actors/v5/actors/migration/nv13" + "github.com/filecoin-project/specs-actors/v6/actors/migration/nv14" + "github.com/filecoin-project/specs-actors/v7/actors/migration/nv15" + "github.com/filecoin-project/specs-actors/v8/actors/migration/nv16" "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" + "github.com/filecoin-project/lotus/chain/actors/builtin/system" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" + "github.com/filecoin-project/lotus/node/bundle" ) +//go:embed FVMLiftoff.txt +var fvmLiftoffBanner string + func DefaultUpgradeSchedule() stmgr.UpgradeSchedule { var us stmgr.UpgradeSchedule @@ -170,6 +180,17 @@ func DefaultUpgradeSchedule() stmgr.UpgradeSchedule { StopWithin: 5, }}, Expensive: true, + }, { + Height: build.UpgradeSkyrHeight, + Network: network.Version16, + Migration: UpgradeActorsV8, + PreMigrations: []stmgr.PreMigration{{ + PreMigration: PreUpgradeActorsV8, + StartWithin: 180, + DontStartWithin: 60, + StopWithin: 5, + }}, + Expensive: true, }, } @@ -1304,6 +1325,261 @@ func upgradeActorsV7Common( return newRoot, nil } +func UpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, cb stmgr.ExecMonitor, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) (cid.Cid, error) { + // Use all the CPUs except 3. + workerCount := runtime.NumCPU() - 3 + if workerCount <= 0 { + workerCount = 1 + } + + config := nv16.Config{ + MaxWorkers: uint(workerCount), + JobQueueSize: 1000, + ResultQueueSize: 100, + ProgressLogPeriod: 10 * time.Second, + } + + newRoot, err := upgradeActorsV8Common(ctx, sm, cache, root, epoch, ts, config) + if err != nil { + return cid.Undef, xerrors.Errorf("migrating actors v7 state: %w", err) + } + + fmt.Print(fvmLiftoffBanner) + + return newRoot, nil +} + +func PreUpgradeActorsV8(ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet) error { + // Use half the CPUs for pre-migration, but leave at least 3. + workerCount := runtime.NumCPU() + if workerCount <= 4 { + workerCount = 1 + } else { + workerCount /= 2 + } + + lbts, lbRoot, err := stmgr.GetLookbackTipSetForRound(ctx, sm, ts, epoch) + if err != nil { + return xerrors.Errorf("error getting lookback ts for premigration: %w", err) + } + + config := nv16.Config{MaxWorkers: uint(workerCount), + ProgressLogPeriod: time.Minute * 5} + + _, err = upgradeActorsV8Common(ctx, sm, cache, lbRoot, epoch, lbts, config) + return err +} + +func upgradeActorsV8Common( + ctx context.Context, sm *stmgr.StateManager, cache stmgr.MigrationCache, + root cid.Cid, epoch abi.ChainEpoch, ts *types.TipSet, + config nv16.Config, +) (cid.Cid, error) { + buf := blockstore.NewTieredBstore(sm.ChainStore().StateBlockstore(), blockstore.NewMemorySync()) + store := store.ActorStore(ctx, buf) + + // ensure that the manifest is loaded in the blockstore + if err := bundle.LoadBundles(ctx, buf, actors.Version8); err != nil { + return cid.Undef, xerrors.Errorf("failed to load manifest bundle: %w", err) + } + + // Load the state root. + var stateRoot types.StateRoot + if err := store.Get(ctx, root, &stateRoot); err != nil { + return cid.Undef, xerrors.Errorf("failed to decode state root: %w", err) + } + + if stateRoot.Version != types.StateTreeVersion4 { + return cid.Undef, xerrors.Errorf( + "expected state root version 4 for actors v8 upgrade, got %d", + stateRoot.Version, + ) + } + + manifest, ok := actors.GetManifest(actors.Version8) + if !ok { + return cid.Undef, xerrors.Errorf("no manifest CID for v8 upgrade") + } + + // Perform the migration + newHamtRoot, err := nv16.MigrateStateTree(ctx, store, manifest, stateRoot.Actors, epoch, config, migrationLogger{}, cache) + if err != nil { + return cid.Undef, xerrors.Errorf("upgrading to actors v8: %w", err) + } + + // Persist the result. + newRoot, err := store.Put(ctx, &types.StateRoot{ + Version: types.StateTreeVersion4, + Actors: newHamtRoot, + Info: stateRoot.Info, + }) + if err != nil { + return cid.Undef, xerrors.Errorf("failed to persist new state root: %w", err) + } + + // Persist the new tree. + + { + from := buf + to := buf.Read() + + if err := vm.Copy(ctx, from, to, newRoot); err != nil { + return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err) + } + } + + return newRoot, nil +} + +// Example upgrade function if upgrade requires only code changes +//func UpgradeActorsV9(ctx context.Context, sm *stmgr.StateManager, _ stmgr.MigrationCache, _ stmgr.ExecMonitor, root cid.Cid, _ abi.ChainEpoch, _ *types.TipSet) (cid.Cid, error) { +// buf := blockstore.NewTieredBstore(sm.ChainStore().StateBlockstore(), blockstore.NewMemorySync()) +// +// av := actors.Version9 +// // This may change for upgrade +// newStateTreeVersion := types.StateTreeVersion4 +// +// // ensure that the manifest is loaded in the blockstore +// if err := bundle.FetchAndLoadBundles(ctx, buf, map[actors.Version]build.Bundle{ +// av: build.BuiltinActorReleases[av], +// }); err != nil { +// return cid.Undef, xerrors.Errorf("failed to load manifest bundle: %w", err) +// } +// +// newActorsManifestCid, ok := actors.GetManifest(av) +// if !ok { +// return cid.Undef, xerrors.Errorf("no manifest CID for v8 upgrade") +// } +// +// bstore := sm.ChainStore().StateBlockstore() +// return LiteMigration(ctx, bstore, newActorsManifestCid, root, av, types.StateTreeVersion4, newStateTreeVersion) +//} + +func LiteMigration(ctx context.Context, bstore blockstore.Blockstore, newActorsManifestCid cid.Cid, root cid.Cid, av actors.Version, oldStateTreeVersion types.StateTreeVersion, newStateTreeVersion types.StateTreeVersion) (cid.Cid, error) { + buf := blockstore.NewTieredBstore(bstore, blockstore.NewMemorySync()) + store := store.ActorStore(ctx, buf) + adtStore := gstStore.WrapStore(ctx, store) + + // Load the state root. + var stateRoot types.StateRoot + if err := store.Get(ctx, root, &stateRoot); err != nil { + return cid.Undef, xerrors.Errorf("failed to decode state root: %w", err) + } + + if stateRoot.Version != oldStateTreeVersion { + return cid.Undef, xerrors.Errorf( + "expected state tree version %d for actors code upgrade, got %d", + oldStateTreeVersion, + stateRoot.Version, + ) + } + + st, err := state.LoadStateTree(store, root) + if err != nil { + return cid.Undef, xerrors.Errorf("failed to load state tree: %w", err) + } + + oldManifest, err := stmgr.GetManifest(ctx, st) + if err != nil { + return cid.Undef, xerrors.Errorf("error loading old actor manifest: %w", err) + } + oldManifestData := manifest.ManifestData{} + if err := store.Get(ctx, oldManifest.Data, &oldManifestData); err != nil { + return cid.Undef, xerrors.Errorf("error loading old manifest data: %w", err) + } + + // load new manifest + newManifest := manifest.Manifest{} + if err := store.Get(ctx, newActorsManifestCid, &newManifest); err != nil { + return cid.Undef, xerrors.Errorf("error loading new manifest: %w", err) + } + newManifestData := manifest.ManifestData{} + if err := store.Get(ctx, newManifest.Data, &newManifestData); err != nil { + return cid.Undef, xerrors.Errorf("error loading new manifest data: %w", err) + } + + if len(oldManifestData.Entries) != len(actors.GetBuiltinActorsKeys()) { + return cid.Undef, xerrors.Errorf("incomplete old manifest with %d code CIDs", len(oldManifestData.Entries)) + } + if len(newManifestData.Entries) != len(actors.GetBuiltinActorsKeys()) { + return cid.Undef, xerrors.Errorf("incomplete new manifest with %d code CIDs", len(newManifestData.Entries)) + } + + // Maps prior version code CIDs to migration functions. + migrations := make(map[cid.Cid]cid.Cid) + + for _, entry := range newManifestData.Entries { + oldCodeCid, ok := oldManifest.Get(entry.Name) + if !ok { + return cid.Undef, xerrors.Errorf("code cid for %s actor not found in old manifest", entry.Name) + } + migrations[oldCodeCid] = entry.Code + } + + startTime := time.Now() + + // Load output state tree + actorsOut, err := state.NewStateTree(adtStore, newStateTreeVersion) + if err != nil { + return cid.Undef, err + } + + // Insert migrated records in output state tree. + err = st.ForEach(func(addr address.Address, actorIn *types.Actor) error { + newCid, ok := migrations[actorIn.Code] + if !ok { + return xerrors.Errorf("new code cid not found in migrations for actor %s", addr) + } + var head cid.Cid + if addr == system.Address { + newSystemState, err := system.MakeState(store, av, newManifest.Data) + if err != nil { + return xerrors.Errorf("could not make system actor state: %w", err) + } + head, err = store.Put(ctx, newSystemState) + if err != nil { + return xerrors.Errorf("could not set system actor state head: %w", err) + } + } else { + head = actorIn.Head + } + newActor := types.Actor{ + Code: newCid, + Head: head, + Nonce: actorIn.Nonce, + Balance: actorIn.Balance, + } + err = actorsOut.SetActor(addr, &newActor) + if err != nil { + return xerrors.Errorf("could not set actor at address %s: %w", addr, err) + } + + return nil + }) + if err != nil { + return cid.Undef, xerrors.Errorf("failed update actor states: %w", err) + } + + elapsed := time.Since(startTime) + log.Infof("All done after %v. Flushing state tree root.", elapsed) + newRoot, err := actorsOut.Flush(ctx) + if err != nil { + return cid.Undef, xerrors.Errorf("failed to flush new actors: %w", err) + } + + // Persist the new tree. + { + from := buf + to := buf.Read() + + if err := vm.Copy(ctx, from, to, newRoot); err != nil { + return cid.Undef, xerrors.Errorf("copying migrated tree: %w", err) + } + } + + return newRoot, nil +} + type migrationLogger struct{} func (ml migrationLogger) Log(level rt.LogLevel, msg string, args ...interface{}) { diff --git a/chain/events/state/mock/api.go b/chain/events/state/mock/api.go index 7a73355a5..a66b65b3e 100644 --- a/chain/events/state/mock/api.go +++ b/chain/events/state/mock/api.go @@ -4,6 +4,8 @@ import ( "context" "sync" + blocks "github.com/ipfs/go-block-format" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/types" @@ -39,6 +41,10 @@ func (m *MockAPI) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error) { return blk.RawData(), nil } +func (m *MockAPI) ChainPutObj(ctx context.Context, block blocks.Block) error { + return m.bs.Put(ctx, block) +} + func (m *MockAPI) StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) { m.lk.Lock() defer m.lk.Unlock() diff --git a/chain/exchange/cbor_gen.go b/chain/exchange/cbor_gen.go index 7a8597fd0..9c7f68ab8 100644 --- a/chain/exchange/cbor_gen.go +++ b/chain/exchange/cbor_gen.go @@ -26,51 +26,57 @@ func (t *Request) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufRequest); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufRequest); err != nil { return err } - scratch := make([]byte, 9) - // t.Head ([]cid.Cid) (slice) if len(t.Head) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Head was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Head))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Head))); err != nil { return err } for _, v := range t.Head { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + if err := cbg.WriteCid(w, v); err != nil { return xerrors.Errorf("failed writing cid field t.Head: %w", err) } } // t.Length (uint64) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Length)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Length)); err != nil { return err } // t.Options (uint64) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Options)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Options)); err != nil { return err } return nil } -func (t *Request) UnmarshalCBOR(r io.Reader) error { +func (t *Request) UnmarshalCBOR(r io.Reader) (err error) { *t = Request{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -81,7 +87,7 @@ func (t *Request) UnmarshalCBOR(r io.Reader) error { // t.Head ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -100,7 +106,7 @@ func (t *Request) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("reading cid field t.Head failed: %w", err) } @@ -111,7 +117,7 @@ func (t *Request) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -125,7 +131,7 @@ func (t *Request) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -145,15 +151,16 @@ func (t *Response) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufResponse); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufResponse); err != nil { return err } - scratch := make([]byte, 9) - // t.Status (exchange.status) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Status)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Status)); err != nil { return err } @@ -162,7 +169,7 @@ func (t *Response) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.ErrorMessage was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.ErrorMessage))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.ErrorMessage))); err != nil { return err } if _, err := io.WriteString(w, string(t.ErrorMessage)); err != nil { @@ -174,27 +181,32 @@ func (t *Response) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Chain was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Chain))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Chain))); err != nil { return err } for _, v := range t.Chain { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } return nil } -func (t *Response) UnmarshalCBOR(r io.Reader) error { +func (t *Response) UnmarshalCBOR(r io.Reader) (err error) { *t = Response{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -207,7 +219,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -220,7 +232,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error { // t.ErrorMessage (string) (string) { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -229,7 +241,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error { } // t.Chain ([]*exchange.BSTipSet) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -249,7 +261,7 @@ func (t *Response) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v BSTipSet - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -266,22 +278,23 @@ func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufCompactedMessages); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufCompactedMessages); err != nil { return err } - scratch := make([]byte, 9) - // t.Bls ([]*types.Message) (slice) if len(t.Bls) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Bls was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Bls))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Bls))); err != nil { return err } for _, v := range t.Bls { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } @@ -291,7 +304,7 @@ func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.BlsIncludes was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BlsIncludes))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.BlsIncludes))); err != nil { return err } for _, v := range t.BlsIncludes { @@ -299,11 +312,11 @@ func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field v was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(v))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(v))); err != nil { return err } for _, v := range v { - if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil { + if err := cw.CborWriteHeader(cbg.MajUnsignedInt, uint64(v)); err != nil { return err } } @@ -314,11 +327,11 @@ func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Secpk was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Secpk))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Secpk))); err != nil { return err } for _, v := range t.Secpk { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } @@ -328,7 +341,7 @@ func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.SecpkIncludes was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.SecpkIncludes))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.SecpkIncludes))); err != nil { return err } for _, v := range t.SecpkIncludes { @@ -336,11 +349,11 @@ func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field v was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(v))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(v))); err != nil { return err } for _, v := range v { - if err := cbg.CborWriteHeader(w, cbg.MajUnsignedInt, uint64(v)); err != nil { + if err := cw.CborWriteHeader(cbg.MajUnsignedInt, uint64(v)); err != nil { return err } } @@ -348,16 +361,21 @@ func (t *CompactedMessages) MarshalCBOR(w io.Writer) error { return nil } -func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { +func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) (err error) { *t = CompactedMessages{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -368,7 +386,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { // t.Bls ([]*types.Message) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -388,7 +406,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v types.Message - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -397,7 +415,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { // t.BlsIncludes ([][]uint64) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -420,7 +438,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { var extra uint64 var err error - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -439,7 +457,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { for j := 0; j < int(extra); j++ { - maj, val, err := cbg.CborReadHeaderBuf(br, scratch) + maj, val, err := cr.ReadHeader() if err != nil { return xerrors.Errorf("failed to read uint64 for t.BlsIncludes[i] slice: %w", err) } @@ -456,7 +474,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { // t.Secpk ([]*types.SignedMessage) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -476,7 +494,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v types.SignedMessage - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -485,7 +503,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { // t.SecpkIncludes ([][]uint64) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -508,7 +526,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { var extra uint64 var err error - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -527,7 +545,7 @@ func (t *CompactedMessages) UnmarshalCBOR(r io.Reader) error { for j := 0; j < int(extra); j++ { - maj, val, err := cbg.CborReadHeaderBuf(br, scratch) + maj, val, err := cr.ReadHeader() if err != nil { return xerrors.Errorf("failed to read uint64 for t.SecpkIncludes[i] slice: %w", err) } @@ -552,43 +570,49 @@ func (t *BSTipSet) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufBSTipSet); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufBSTipSet); err != nil { return err } - scratch := make([]byte, 9) - // t.Blocks ([]*types.BlockHeader) (slice) if len(t.Blocks) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Blocks was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Blocks))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Blocks))); err != nil { return err } for _, v := range t.Blocks { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } // t.Messages (exchange.CompactedMessages) (struct) - if err := t.Messages.MarshalCBOR(w); err != nil { + if err := t.Messages.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { +func (t *BSTipSet) UnmarshalCBOR(r io.Reader) (err error) { *t = BSTipSet{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -599,7 +623,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { // t.Blocks ([]*types.BlockHeader) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -619,7 +643,7 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v types.BlockHeader - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -630,16 +654,16 @@ func (t *BSTipSet) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.Messages = new(CompactedMessages) - if err := t.Messages.UnmarshalCBOR(br); err != nil { + if err := t.Messages.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Messages pointer: %w", err) } } diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 4153830dc..cde414fec 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -29,8 +29,6 @@ import ( "github.com/ipld/go-car" "golang.org/x/xerrors" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" - "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" @@ -55,7 +53,7 @@ const msgsPerBlock = 20 //nolint:deadcode,varcheck var log = logging.Logger("gen") -var ValidWpostForTesting = []proof5.PoStProof{{ +var ValidWpostForTesting = []proof7.PoStProof{{ ProofBytes: []byte("valid proof"), }} @@ -492,7 +490,7 @@ func (cg *ChainGen) NextTipSetFromMinersWithMessagesAndNulls(base *types.TipSet, func (cg *ChainGen) makeBlock(parents *types.TipSet, m address.Address, vrfticket *types.Ticket, eticket *types.ElectionProof, bvals []types.BeaconEntry, height abi.ChainEpoch, - wpost []proof5.PoStProof, msgs []*types.SignedMessage) (*types.FullBlock, error) { + wpost []proof7.PoStProof, msgs []*types.SignedMessage) (*types.FullBlock, error) { var ts uint64 if cg.Timestamper != nil { @@ -620,7 +618,7 @@ func (mca mca) WalletSign(ctx context.Context, a address.Address, v []byte) (*cr type WinningPoStProver interface { GenerateCandidates(context.Context, abi.PoStRandomness, uint64) ([]uint64, error) - ComputeProof(context.Context, []proof7.ExtendedSectorInfo, abi.PoStRandomness, abi.ChainEpoch, network.Version) ([]proof5.PoStProof, error) + ComputeProof(context.Context, []proof7.ExtendedSectorInfo, abi.PoStRandomness, abi.ChainEpoch, network.Version) ([]proof7.PoStProof, error) } type wppProvider struct{} @@ -629,7 +627,7 @@ func (wpp *wppProvider) GenerateCandidates(ctx context.Context, _ abi.PoStRandom return []uint64{0}, nil } -func (wpp *wppProvider) ComputeProof(context.Context, []proof7.ExtendedSectorInfo, abi.PoStRandomness, abi.ChainEpoch, network.Version) ([]proof5.PoStProof, error) { +func (wpp *wppProvider) ComputeProof(context.Context, []proof7.ExtendedSectorInfo, abi.PoStRandomness, abi.ChainEpoch, network.Version) ([]proof7.PoStProof, error) { return ValidWpostForTesting, nil } @@ -680,11 +678,11 @@ type genFakeVerifier struct{} var _ ffiwrapper.Verifier = (*genFakeVerifier)(nil) -func (m genFakeVerifier) VerifySeal(svi proof5.SealVerifyInfo) (bool, error) { +func (m genFakeVerifier) VerifySeal(svi proof7.SealVerifyInfo) (bool, error) { return true, nil } -func (m genFakeVerifier) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) (bool, error) { +func (m genFakeVerifier) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) (bool, error) { panic("not supported") } diff --git a/chain/gen/genesis/f00_system.go b/chain/gen/genesis/f00_system.go index 4fde27107..527701f17 100644 --- a/chain/gen/genesis/f00_system.go +++ b/chain/gen/genesis/f00_system.go @@ -3,6 +3,16 @@ package genesis import ( "context" + "github.com/ipfs/go-cid" + + systemtypes "github.com/filecoin-project/go-state-types/builtin/v8/system" + + "github.com/filecoin-project/go-state-types/manifest" + + "github.com/filecoin-project/lotus/chain/actors/builtin" + + "golang.org/x/xerrors" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" @@ -17,17 +27,33 @@ import ( func SetupSystemActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { cst := cbor.NewCborStore(bs) - st, err := system.MakeState(adt.WrapStore(ctx, cst), av) + // TODO pass in built-in actors cid for V8 and later + st, err := system.MakeState(adt.WrapStore(ctx, cst), av, cid.Undef) if err != nil { return nil, err } + if av >= actors.Version8 { + mfCid, ok := actors.GetManifest(av) + if !ok { + return nil, xerrors.Errorf("missing manifest for actors version %d", av) + } + + mf := manifest.Manifest{} + if err := cst.Get(ctx, mfCid, &mf); err != nil { + return nil, xerrors.Errorf("loading manifest for actors version %d: %w", av, err) + } + + st8 := st.GetState().(*systemtypes.State) + st8.BuiltinActors = mf.Data + } + statecid, err := cst.Put(ctx, st.GetState()) if err != nil { return nil, err } - actcid, err := system.GetActorCodeID(av) + actcid, err := builtin.GetSystemActorCodeID(av) if err != nil { return nil, err } diff --git a/chain/gen/genesis/f01_init.go b/chain/gen/genesis/f01_init.go index 61ec91703..f1df7ae2a 100644 --- a/chain/gen/genesis/f01_init.go +++ b/chain/gen/genesis/f01_init.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" + "github.com/filecoin-project/lotus/chain/actors/builtin" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" "github.com/filecoin-project/lotus/chain/actors" @@ -176,7 +178,7 @@ func SetupInitActor(ctx context.Context, bs bstore.Blockstore, netname string, i return 0, nil, nil, err } - actcid, err := init_.GetActorCodeID(av) + actcid, err := builtin.GetInitActorCodeID(av) if err != nil { return 0, nil, nil, err } diff --git a/chain/gen/genesis/f02_reward.go b/chain/gen/genesis/f02_reward.go index c8f479722..e4d6aa32a 100644 --- a/chain/gen/genesis/f02_reward.go +++ b/chain/gen/genesis/f02_reward.go @@ -3,6 +3,8 @@ package genesis import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin/reward" @@ -28,7 +30,7 @@ func SetupRewardActor(ctx context.Context, bs bstore.Blockstore, qaPower big.Int return nil, err } - actcid, err := reward.GetActorCodeID(av) + actcid, err := builtin.GetRewardActorCodeID(av) if err != nil { return nil, err } diff --git a/chain/gen/genesis/f03_cron.go b/chain/gen/genesis/f03_cron.go index c9dd0d341..fad5e6fa6 100644 --- a/chain/gen/genesis/f03_cron.go +++ b/chain/gen/genesis/f03_cron.go @@ -3,6 +3,8 @@ package genesis import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" @@ -26,7 +28,7 @@ func SetupCronActor(ctx context.Context, bs bstore.Blockstore, av actors.Version return nil, err } - actcid, err := cron.GetActorCodeID(av) + actcid, err := builtin.GetCronActorCodeID(av) if err != nil { return nil, err } diff --git a/chain/gen/genesis/f04_power.go b/chain/gen/genesis/f04_power.go index b5e08cebe..35cd5f87b 100644 --- a/chain/gen/genesis/f04_power.go +++ b/chain/gen/genesis/f04_power.go @@ -3,6 +3,8 @@ package genesis import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors/builtin/power" @@ -28,7 +30,7 @@ func SetupStoragePowerActor(ctx context.Context, bs bstore.Blockstore, av actors return nil, err } - actcid, err := power.GetActorCodeID(av) + actcid, err := builtin.GetPowerActorCodeID(av) if err != nil { return nil, err } diff --git a/chain/gen/genesis/f05_market.go b/chain/gen/genesis/f05_market.go index ac32294c9..045842cde 100644 --- a/chain/gen/genesis/f05_market.go +++ b/chain/gen/genesis/f05_market.go @@ -3,6 +3,8 @@ package genesis import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" @@ -26,7 +28,7 @@ func SetupStorageMarketActor(ctx context.Context, bs bstore.Blockstore, av actor return nil, err } - actcid, err := market.GetActorCodeID(av) + actcid, err := builtin.GetMarketActorCodeID(av) if err != nil { return nil, err } diff --git a/chain/gen/genesis/f06_vreg.go b/chain/gen/genesis/f06_vreg.go index e61c951f5..d93b01a4f 100644 --- a/chain/gen/genesis/f06_vreg.go +++ b/chain/gen/genesis/f06_vreg.go @@ -3,6 +3,8 @@ package genesis import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" @@ -41,7 +43,7 @@ func SetupVerifiedRegistryActor(ctx context.Context, bs bstore.Blockstore, av ac return nil, err } - actcid, err := verifreg.GetActorCodeID(av) + actcid, err := builtin.GetVerifregActorCodeID(av) if err != nil { return nil, err } diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index a1d1d01b8..138437b78 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/filecoin-project/lotus/chain/consensus/filcns" + "github.com/filecoin-project/lotus/node/bundle" builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" @@ -155,6 +156,10 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, xerrors.Errorf("getting network version: %w", err) } + if err := bundle.LoadBundles(ctx, bs, av); err != nil { + return nil, nil, xerrors.Errorf("loading actors for genesis block: %w", err) + } + // Create system actor sysact, err := SetupSystemActor(ctx, bs, av) @@ -376,7 +381,7 @@ func MakeAccountActor(ctx context.Context, cst cbor.IpldStore, av actors.Version return nil, err } - actcid, err := account.GetActorCodeID(av) + actcid, err := builtin.GetAccountActorCodeID(av) if err != nil { return nil, err } @@ -458,7 +463,7 @@ func CreateMultisigAccount(ctx context.Context, cst cbor.IpldStore, state *state return err } - actcid, err := multisig.GetActorCodeID(av) + actcid, err := builtin.GetMultisigActorCodeID(av) if err != nil { return err } @@ -491,11 +496,10 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca Actors: filcns.NewActorRegistry(), Syscalls: mkFakedSigSyscalls(sys), CircSupplyCalc: csc, - FilVested: big.Zero(), NetworkVersion: nv, BaseFee: big.Zero(), } - vm, err := vm.NewLegacyVM(ctx, &vmopt) + vm, err := vm.NewVM(ctx, &vmopt) if err != nil { return cid.Undef, xerrors.Errorf("failed to create NewLegacyVM: %w", err) } diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index fd83a7640..542111a62 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -6,6 +6,17 @@ import ( "fmt" "math/rand" + "github.com/filecoin-project/lotus/chain/wallet" + + cborutil "github.com/filecoin-project/go-cbor-util" + + "github.com/filecoin-project/lotus/lib/sigs" + + smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing" + + "github.com/filecoin-project/lotus/chain/actors/builtin" + miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" + runtime7 "github.com/filecoin-project/specs-actors/v7/actors/runtime" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" @@ -23,7 +34,6 @@ import ( builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" @@ -32,9 +42,11 @@ import ( power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" reward4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" + builtintypes "github.com/filecoin-project/go-state-types/builtin" + markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/power" @@ -86,22 +98,25 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal return big.Zero(), nil } - vmopt := &vm.VMOpts{ - StateBase: sroot, - Epoch: 0, - Rand: &fakeRand{}, - Bstore: cs.StateBlockstore(), - Actors: filcns.NewActorRegistry(), - Syscalls: mkFakedSigSyscalls(sys), - CircSupplyCalc: csc, - NetworkVersion: nv, - BaseFee: big.Zero(), - FilVested: big.Zero(), + newVM := func(base cid.Cid) (vm.Interface, error) { + vmopt := &vm.VMOpts{ + StateBase: base, + Epoch: 0, + Rand: &fakeRand{}, + Bstore: cs.StateBlockstore(), + Actors: filcns.NewActorRegistry(), + Syscalls: mkFakedSigSyscalls(sys), + CircSupplyCalc: csc, + NetworkVersion: nv, + BaseFee: big.Zero(), + } + + return vm.NewVM(ctx, vmopt) } - vm, err := vm.NewLegacyVM(ctx, vmopt) + genesisVm, err := newVM(sroot) if err != nil { - return cid.Undef, xerrors.Errorf("failed to create NewLegacyVM: %w", err) + return cid.Undef, fmt.Errorf("creating vm: %w", err) } if len(miners) == 0 { @@ -116,7 +131,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal dealIDs []abi.DealID }, len(miners)) - maxPeriods := policy.GetMaxSectorExpirationExtension() / miner.WPoStProvingPeriod + maxPeriods := policy.GetMaxSectorExpirationExtension() / minertypes.WPoStProvingPeriod for i, m := range miners { // Create miner through power actor i := i @@ -136,7 +151,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal } params := mustEnc(constructorParams) - rval, err := doExecValue(ctx, vm, power.Address, m.Owner, m.PowerBalance, power.Methods.CreateMiner, params) + rval, err := doExecValue(ctx, genesisVm, power.Address, m.Owner, m.PowerBalance, power.Methods.CreateMiner, params) if err != nil { return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err) } @@ -152,12 +167,17 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal } minerInfos[i].maddr = ma.IDAddress - _, err = vm.Flush(ctx) + nh, err := genesisVm.Flush(ctx) if err != nil { return cid.Undef, xerrors.Errorf("flushing vm: %w", err) } - mact, err := vm.StateTree().GetActor(minerInfos[i].maddr) + nst, err := state.LoadStateTree(cst, nh) + if err != nil { + return cid.Undef, xerrors.Errorf("loading new state tree: %w", err) + } + + mact, err := nst.GetActor(minerInfos[i].maddr) if err != nil { return cid.Undef, xerrors.Errorf("getting newly created miner actor: %w", err) } @@ -179,7 +199,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal if m.MarketBalance.GreaterThan(big.Zero()) { params := mustEnc(&minerInfos[i].maddr) - _, err := doExecValue(ctx, vm, market.Address, m.Worker, m.MarketBalance, market.Methods.AddBalance, params) + _, err := doExecValue(ctx, genesisVm, market.Address, m.Worker, m.MarketBalance, market.Methods.AddBalance, params) if err != nil { return cid.Undef, xerrors.Errorf("failed to create genesis miner (add balance): %w", err) } @@ -188,10 +208,10 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal // Publish preseal deals { - publish := func(params *market.PublishStorageDealsParams) error { + publish := func(params *markettypes.PublishStorageDealsParams) error { fmt.Printf("publishing %d storage deals on miner %s with worker %s\n", len(params.Deals), params.Deals[0].Proposal.Provider, m.Worker) - ret, err := doExecValue(ctx, vm, market.Address, m.Worker, big.Zero(), builtin0.MethodsMarket.PublishStorageDeals, mustEnc(params)) + ret, err := doExecValue(ctx, genesisVm, market.Address, m.Worker, big.Zero(), builtin0.MethodsMarket.PublishStorageDeals, mustEnc(params)) if err != nil { return xerrors.Errorf("failed to create genesis miner (publish deals): %w", err) } @@ -213,21 +233,37 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal return nil } - params := &market.PublishStorageDealsParams{} + params := &markettypes.PublishStorageDealsParams{} for _, preseal := range m.Sectors { preseal.Deal.VerifiedDeal = true preseal.Deal.EndEpoch = minerInfos[i].presealExp - params.Deals = append(params.Deals, market.ClientDealProposal{ + p := markettypes.ClientDealProposal{ Proposal: preseal.Deal, - ClientSignature: crypto.Signature{Type: crypto.SigTypeBLS}, // TODO: do we want to sign these? Or do we want to fake signatures for genesis setup? - }) + ClientSignature: crypto.Signature{Type: crypto.SigTypeBLS}, + } + + if av >= actors.Version8 { + buf, err := cborutil.Dump(&preseal.Deal) + if err != nil { + return cid.Undef, fmt.Errorf("failed to marshal proposal: %w", err) + } + + sig, err := sigs.Sign(wallet.ActSigType(preseal.DealClientKey.Type), preseal.DealClientKey.PrivateKey, buf) + if err != nil { + return cid.Undef, fmt.Errorf("failed to sign proposal: %w", err) + } + + p.ClientSignature = *sig + } + + params.Deals = append(params.Deals, p) if len(params.Deals) == cbg.MaxLength { if err := publish(params); err != nil { return cid.Undef, err } - params = &market.PublishStorageDealsParams{} + params = &markettypes.PublishStorageDealsParams{} } } @@ -246,7 +282,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal for pi := range m.Sectors { rawPow = types.BigAdd(rawPow, types.NewInt(uint64(m.SectorSize))) - dweight, vdweight, err := dealWeight(ctx, vm, minerInfos[i].maddr, []abi.DealID{minerInfos[i].dealIDs[pi]}, 0, minerInfos[i].presealExp, av) + dweight, vdweight, err := dealWeight(ctx, genesisVm, minerInfos[i].maddr, []abi.DealID{minerInfos[i].dealIDs[pi]}, 0, minerInfos[i].presealExp, av) if err != nil { return cid.Undef, xerrors.Errorf("getting deal weight: %w", err) } @@ -257,12 +293,21 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal } } - _, err = vm.Flush(ctx) + nh, err := genesisVm.Flush(ctx) if err != nil { return cid.Undef, xerrors.Errorf("flushing vm: %w", err) } - pact, err := vm.StateTree().GetActor(power.Address) + if err != nil { + return cid.Undef, xerrors.Errorf("flushing vm: %w", err) + } + + nst, err := state.LoadStateTree(cst, nh) + if err != nil { + return cid.Undef, xerrors.Errorf("loading new state tree: %w", err) + } + + pact, err := nst.GetActor(power.Address) if err != nil { return cid.Undef, xerrors.Errorf("getting power actor: %w", err) } @@ -295,7 +340,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal pact.Head = pcid - if err = vm.StateTree().SetActor(power.Address, pact); err != nil { + if err = nst.SetActor(power.Address, pact); err != nil { return cid.Undef, xerrors.Errorf("setting power state: %w", err) } @@ -304,16 +349,26 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal return cid.Undef, xerrors.Errorf("setup reward actor: %w", err) } - if err = vm.StateTree().SetActor(reward.Address, rewact); err != nil { + if err = nst.SetActor(reward.Address, rewact); err != nil { return cid.Undef, xerrors.Errorf("set reward actor: %w", err) } + + nh, err = nst.Flush(ctx) + if err != nil { + return cid.Undef, xerrors.Errorf("flushing state tree: %w", err) + } + + genesisVm, err = newVM(nh) + if err != nil { + return cid.Undef, fmt.Errorf("creating new vm: %w", err) + } } for i, m := range miners { // Commit sectors { for pi, preseal := range m.Sectors { - params := &miner.SectorPreCommitInfo{ + params := &minertypes.SectorPreCommitInfo{ SealProof: preseal.ProofType, SectorNumber: preseal.SectorID, SealedCID: preseal.CommR, @@ -322,7 +377,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal Expiration: minerInfos[i].presealExp, // TODO: Allow setting externally! } - dweight, vdweight, err := dealWeight(ctx, vm, minerInfos[i].maddr, params.DealIDs, 0, minerInfos[i].presealExp, av) + dweight, vdweight, err := dealWeight(ctx, genesisVm, minerInfos[i].maddr, params.DealIDs, 0, minerInfos[i].presealExp, av) if err != nil { return cid.Undef, xerrors.Errorf("getting deal weight: %w", err) } @@ -331,12 +386,17 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal // we've added fake power for this sector above, remove it now - _, err = vm.Flush(ctx) + nh, err := genesisVm.Flush(ctx) if err != nil { return cid.Undef, xerrors.Errorf("flushing vm: %w", err) } - pact, err := vm.StateTree().GetActor(power.Address) + nst, err := state.LoadStateTree(cst, nh) + if err != nil { + return cid.Undef, xerrors.Errorf("loading new state tree: %w", err) + } + + pact, err := nst.GetActor(power.Address) if err != nil { return cid.Undef, xerrors.Errorf("getting power actor: %w", err) } @@ -366,35 +426,45 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal pact.Head = pcid - if err = vm.StateTree().SetActor(power.Address, pact); err != nil { + if err = nst.SetActor(power.Address, pact); err != nil { return cid.Undef, xerrors.Errorf("setting power state: %w", err) } - baselinePower, rewardSmoothed, err := currentEpochBlockReward(ctx, vm, minerInfos[i].maddr, av) + nh, err = nst.Flush(ctx) + if err != nil { + return cid.Undef, xerrors.Errorf("flushing state tree: %w", err) + } + + genesisVm, err = newVM(nh) + if err != nil { + return cid.Undef, fmt.Errorf("creating new vm: %w", err) + } + + baselinePower, rewardSmoothed, err := currentEpochBlockReward(ctx, genesisVm, minerInfos[i].maddr, av) if err != nil { return cid.Undef, xerrors.Errorf("getting current epoch reward: %w", err) } - tpow, err := currentTotalPower(ctx, vm, minerInfos[i].maddr) + tpow, err := currentTotalPower(ctx, genesisVm, minerInfos[i].maddr) if err != nil { return cid.Undef, xerrors.Errorf("getting current total power: %w", err) } - pcd := miner0.PreCommitDepositForPower(&rewardSmoothed, tpow.QualityAdjPowerSmoothed, sectorWeight) + pcd := miner0.PreCommitDepositForPower((*smoothing0.FilterEstimate)(&rewardSmoothed), tpow.QualityAdjPowerSmoothed, sectorWeight) pledge := miner0.InitialPledgeForPower( sectorWeight, baselinePower, tpow.PledgeCollateral, - &rewardSmoothed, + (*smoothing0.FilterEstimate)(&rewardSmoothed), tpow.QualityAdjPowerSmoothed, - circSupply(ctx, vm, minerInfos[i].maddr), + big.Zero(), ) pledge = big.Add(pcd, pledge) fmt.Println(types.FIL(pledge)) - _, err = doExecValue(ctx, vm, minerInfos[i].maddr, m.Worker, pledge, miner.Methods.PreCommitSector, mustEnc(params)) + _, err = doExecValue(ctx, genesisVm, minerInfos[i].maddr, m.Worker, pledge, builtintypes.MethodsMiner.PreCommitSector, mustEnc(params)) if err != nil { return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err) } @@ -417,7 +487,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal paramBytes = mustEnc(confirmParams) } - _, err = doExecValue(ctx, vm, minerInfos[i].maddr, power.Address, big.Zero(), miner.Methods.ConfirmSectorProofsValid, paramBytes) + _, err = doExecValue(ctx, genesisVm, minerInfos[i].maddr, power.Address, big.Zero(), builtintypes.MethodsMiner.ConfirmSectorProofsValid, paramBytes) if err != nil { return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err) } @@ -429,17 +499,22 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal QualityAdjustedDelta: sectorWeight, } - _, err = doExecValue(ctx, vm, power.Address, minerInfos[i].maddr, big.Zero(), power.Methods.UpdateClaimedPower, mustEnc(claimParams)) + _, err = doExecValue(ctx, genesisVm, power.Address, minerInfos[i].maddr, big.Zero(), power.Methods.UpdateClaimedPower, mustEnc(claimParams)) if err != nil { return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err) } - _, err = vm.Flush(ctx) + nh, err := genesisVm.Flush(ctx) if err != nil { return cid.Undef, xerrors.Errorf("flushing vm: %w", err) } - mact, err := vm.StateTree().GetActor(minerInfos[i].maddr) + nst, err := state.LoadStateTree(cst, nh) + if err != nil { + return cid.Undef, xerrors.Errorf("loading new state tree: %w", err) + } + + mact, err := nst.GetActor(minerInfos[i].maddr) if err != nil { return cid.Undef, xerrors.Errorf("getting miner actor: %w", err) } @@ -460,21 +535,36 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal mact.Head = mcid - if err = vm.StateTree().SetActor(minerInfos[i].maddr, mact); err != nil { + if err = nst.SetActor(minerInfos[i].maddr, mact); err != nil { return cid.Undef, xerrors.Errorf("setting miner state: %w", err) } + + nh, err = nst.Flush(ctx) + if err != nil { + return cid.Undef, xerrors.Errorf("flushing state tree: %w", err) + } + + genesisVm, err = newVM(nh) + if err != nil { + return cid.Undef, fmt.Errorf("creating new vm: %w", err) + } } } } } // Sanity-check total network power - _, err = vm.Flush(ctx) + nh, err := genesisVm.Flush(ctx) if err != nil { - return cid.Undef, xerrors.Errorf("flushing vm: %w", err) + return cid.Undef, fmt.Errorf("flushing vm: %w", err) } - pact, err := vm.StateTree().GetActor(power.Address) + nst, err := state.LoadStateTree(cst, nh) + if err != nil { + return cid.Undef, xerrors.Errorf("loading new state tree: %w", err) + } + + pact, err := nst.GetActor(power.Address) if err != nil { return cid.Undef, xerrors.Errorf("getting power actor: %w", err) } @@ -499,10 +589,11 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal // TODO: Should we re-ConstructState for the reward actor using rawPow as currRealizedPower here? - c, err := vm.Flush(ctx) + c, err := genesisVm.Flush(ctx) if err != nil { return cid.Undef, xerrors.Errorf("flushing vm: %w", err) } + return c, nil } @@ -521,7 +612,7 @@ func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, personalization cry return out, nil } -func currentTotalPower(ctx context.Context, vm *vm.LegacyVM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) { +func currentTotalPower(ctx context.Context, vm vm.Interface, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) { pwret, err := doExecValue(ctx, vm, power.Address, maddr, big.Zero(), builtin0.MethodsPower.CurrentTotalPower, nil) if err != nil { return nil, err @@ -534,7 +625,7 @@ func currentTotalPower(ctx context.Context, vm *vm.LegacyVM, maddr address.Addre return &pwr, nil } -func dealWeight(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) { +func dealWeight(ctx context.Context, vm vm.Interface, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) { // TODO: This hack should move to market actor wrapper if av <= actors.Version2 { params := &market0.VerifyDealsForActivationParams{ @@ -594,7 +685,7 @@ func dealWeight(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, dea return dealWeights.Sectors[0].DealWeight, dealWeights.Sectors[0].VerifiedDealWeight, nil } -func currentEpochBlockReward(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) { +func currentEpochBlockReward(ctx context.Context, vm vm.Interface, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) { rwret, err := doExecValue(ctx, vm, reward.Address, maddr, big.Zero(), reward.Methods.ThisEpochReward, nil) if err != nil { return big.Zero(), builtin.FilterEstimate{}, err @@ -609,7 +700,7 @@ func currentEpochBlockReward(ctx context.Context, vm *vm.LegacyVM, maddr address return big.Zero(), builtin.FilterEstimate{}, err } - return epochReward.ThisEpochBaselinePower, *epochReward.ThisEpochRewardSmoothed, nil + return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(*epochReward.ThisEpochRewardSmoothed), nil case actors.Version2: var epochReward reward2.ThisEpochRewardReturn @@ -628,13 +719,3 @@ func currentEpochBlockReward(ctx context.Context, vm *vm.LegacyVM, maddr address return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(epochReward.ThisEpochRewardSmoothed), nil } - -func circSupply(ctx context.Context, vmi *vm.LegacyVM, maddr address.Address) abi.TokenAmount { - unsafeVM := &vm.UnsafeVM{VM: vmi} - rt := unsafeVM.MakeRuntime(ctx, &types.Message{ - GasLimit: 1_000_000_000, - From: maddr, - }) - - return rt.TotalFilCircSupply() -} diff --git a/chain/gen/genesis/util.go b/chain/gen/genesis/util.go index 452bc835b..1f576c8a4 100644 --- a/chain/gen/genesis/util.go +++ b/chain/gen/genesis/util.go @@ -21,12 +21,7 @@ func mustEnc(i cbg.CBORMarshaler) []byte { return enc } -func doExecValue(ctx context.Context, vm *vm.LegacyVM, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) { - act, err := vm.StateTree().GetActor(from) - if err != nil { - return nil, xerrors.Errorf("doExec failed to get from actor (%s): %w", from, err) - } - +func doExecValue(ctx context.Context, vm vm.Interface, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) { ret, err := vm.ApplyImplicitMessage(ctx, &types.Message{ To: to, From: from, @@ -34,7 +29,7 @@ func doExecValue(ctx context.Context, vm *vm.LegacyVM, to, from address.Address, Params: params, GasLimit: 1_000_000_000_000_000, Value: value, - Nonce: act.Nonce, + Nonce: 0, }) if err != nil { return nil, xerrors.Errorf("doExec apply message failed: %w", err) diff --git a/chain/market/cbor_gen.go b/chain/market/cbor_gen.go index 1c13e9ddc..9c9ef1a94 100644 --- a/chain/market/cbor_gen.go +++ b/chain/market/cbor_gen.go @@ -25,30 +25,31 @@ func (t *FundedAddressState) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufFundedAddressState); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufFundedAddressState); err != nil { return err } - scratch := make([]byte, 9) - // t.Addr (address.Address) (struct) - if err := t.Addr.MarshalCBOR(w); err != nil { + if err := t.Addr.MarshalCBOR(cw); err != nil { return err } // t.AmtReserved (big.Int) (struct) - if err := t.AmtReserved.MarshalCBOR(w); err != nil { + if err := t.AmtReserved.MarshalCBOR(cw); err != nil { return err } // t.MsgCid (cid.Cid) (struct) if t.MsgCid == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.MsgCid); err != nil { + if err := cbg.WriteCid(cw, *t.MsgCid); err != nil { return xerrors.Errorf("failed to write cid field t.MsgCid: %w", err) } } @@ -56,16 +57,21 @@ func (t *FundedAddressState) MarshalCBOR(w io.Writer) error { return nil } -func (t *FundedAddressState) UnmarshalCBOR(r io.Reader) error { +func (t *FundedAddressState) UnmarshalCBOR(r io.Reader) (err error) { *t = FundedAddressState{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -78,7 +84,7 @@ func (t *FundedAddressState) UnmarshalCBOR(r io.Reader) error { { - if err := t.Addr.UnmarshalCBOR(br); err != nil { + if err := t.Addr.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Addr: %w", err) } @@ -87,7 +93,7 @@ func (t *FundedAddressState) UnmarshalCBOR(r io.Reader) error { { - if err := t.AmtReserved.UnmarshalCBOR(br); err != nil { + if err := t.AmtReserved.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.AmtReserved: %w", err) } @@ -96,16 +102,16 @@ func (t *FundedAddressState) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.MsgCid: %w", err) } diff --git a/chain/market/fundmanager.go b/chain/market/fundmanager.go index e934201d7..53afa1343 100644 --- a/chain/market/fundmanager.go +++ b/chain/market/fundmanager.go @@ -7,10 +7,11 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/market" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/impl/full" "github.com/filecoin-project/lotus/node/modules/dtypes" @@ -677,10 +678,10 @@ func (env *fundManagerEnvironment) AddFunds( } smsg, aerr := env.api.MpoolPushMessage(ctx, &types.Message{ - To: market.Address, + To: builtin.StorageMarketActorAddr, From: wallet, Value: amt, - Method: market.Methods.AddBalance, + Method: builtin.MethodsMarket.AddBalance, Params: params, }, nil) @@ -706,10 +707,10 @@ func (env *fundManagerEnvironment) WithdrawFunds( } smsg, aerr := env.api.MpoolPushMessage(ctx, &types.Message{ - To: market.Address, + To: builtin.StorageMarketActorAddr, From: wallet, Value: types.NewInt(0), - Method: market.Methods.WithdrawBalance, + Method: builtin.MethodsMarket.WithdrawBalance, Params: params, }, nil) diff --git a/chain/market/fundmanager_test.go b/chain/market/fundmanager_test.go index 8f2d5a2f9..4dcf3b66c 100644 --- a/chain/market/fundmanager_test.go +++ b/chain/market/fundmanager_test.go @@ -8,6 +8,8 @@ import ( "testing" "time" + markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/api" @@ -662,7 +664,7 @@ func checkWithdrawMessageFields(t *testing.T, msg *types.Message, from address.A require.Equal(t, market.Address, msg.To) require.Equal(t, abi.NewTokenAmount(0), msg.Value) - var params market.WithdrawBalanceParams + var params markettypes.WithdrawBalanceParams err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)) require.NoError(t, err) require.Equal(t, addr, params.ProviderOrClientAddress) @@ -742,7 +744,7 @@ func (mapi *mockFundManagerAPI) completeMsg(msgCid cid.Cid) { mapi.escrow[escrowAcct] = escrow log.Debugf("%s: escrow %d -> %d", escrowAcct, before, escrow) } else { - var params market.WithdrawBalanceParams + var params markettypes.WithdrawBalanceParams err := params.UnmarshalCBOR(bytes.NewReader(pmsg.msg.Message.Params)) if err != nil { panic(err) diff --git a/chain/rand/rand.go b/chain/rand/rand.go index 427648f2a..529ba6732 100644 --- a/chain/rand/rand.go +++ b/chain/rand/rand.go @@ -198,7 +198,9 @@ func (sr *stateRand) extractBeaconEntryForEpoch(ctx context.Context, filecoinEpo return nil, err } - round := sr.beacon.BeaconForEpoch(filecoinEpoch).MaxBeaconRoundForEpoch(filecoinEpoch) + nv := sr.networkVersionGetter(ctx, filecoinEpoch) + + round := sr.beacon.BeaconForEpoch(filecoinEpoch).MaxBeaconRoundForEpoch(nv, filecoinEpoch) for i := 0; i < 20; i++ { cbe := randTs.Blocks()[0].BeaconEntries diff --git a/chain/state/statetree.go b/chain/state/statetree.go index 9a518a622..7d6876c3c 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -159,7 +159,7 @@ func VersionForNetwork(ver network.Version) (types.StateTreeVersion, error) { /* inline-gen start */ - case network.Version13, network.Version14, network.Version15: + case network.Version13, network.Version14, network.Version15, network.Version16: /* inline-gen end */ return types.StateTreeVersion4, nil diff --git a/chain/stmgr/actors.go b/chain/stmgr/actors.go index 52773e1e4..bfa04827e 100644 --- a/chain/stmgr/actors.go +++ b/chain/stmgr/actors.go @@ -5,7 +5,7 @@ import ( "context" "os" - "github.com/filecoin-project/lotus/chain/rand" + "golang.org/x/xerrors" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" @@ -15,8 +15,7 @@ import ( "github.com/filecoin-project/go-state-types/network" cid "github.com/ipfs/go-cid" - "golang.org/x/xerrors" - + miner_types "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin/market" @@ -24,6 +23,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/beacon" + "github.com/filecoin-project/lotus/chain/rand" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" @@ -89,7 +89,7 @@ func GetPowerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr addres return mpow, tpow, minpow, nil } -func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (*miner.SectorPreCommitOnChainInfo, error) { +func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (*miner_types.SectorPreCommitOnChainInfo, error) { act, err := sm.LoadActor(ctx, maddr, ts) if err != nil { return nil, xerrors.Errorf("(get sset) failed to load miner actor: %w", err) @@ -316,7 +316,7 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule prev = &types.BeaconEntry{} } - entries, err := beacon.BeaconEntriesForBlock(ctx, bcs, round, ts.Height(), *prev) + entries, err := beacon.BeaconEntriesForBlock(ctx, bcs, sm.GetNetworkVersion(ctx, round), round, ts.Height(), *prev) if err != nil { return nil, err } diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index 888ca0254..7e011d99f 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -80,11 +80,6 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. return nil, fmt.Errorf("failed to handle fork: %w", err) } - filVested, err := sm.GetFilVested(ctx, vmHeight) - if err != nil { - return nil, err - } - vmopt := &vm.VMOpts{ StateBase: bstate, Epoch: vmHeight, @@ -95,7 +90,6 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. CircSupplyCalc: sm.GetVMCirculatingSupply, NetworkVersion: sm.GetNetworkVersion(ctx, pheight+1), BaseFee: types.NewInt(0), - FilVested: filVested, LookbackState: LookbackStateGetterForTipset(sm, ts), } @@ -218,11 +212,6 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri ) } - filVested, err := sm.GetFilVested(ctx, vmHeight) - if err != nil { - return nil, err - } - buffStore := blockstore.NewTieredBstore(sm.cs.StateBlockstore(), blockstore.NewMemorySync()) vmopt := &vm.VMOpts{ StateBase: stateCid, @@ -234,7 +223,6 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri CircSupplyCalc: sm.GetVMCirculatingSupply, NetworkVersion: sm.GetNetworkVersion(ctx, ts.Height()+1), BaseFee: ts.Blocks()[0].ParentBaseFee, - FilVested: filVested, LookbackState: LookbackStateGetterForTipset(sm, ts), } vmi, err := sm.newVM(ctx, vmopt) diff --git a/chain/stmgr/forks.go b/chain/stmgr/forks.go index 9aa3f7e53..048ea7372 100644 --- a/chain/stmgr/forks.go +++ b/chain/stmgr/forks.go @@ -8,9 +8,7 @@ import ( "sync" "time" - "github.com/filecoin-project/lotus/build" - - "github.com/filecoin-project/specs-actors/v7/actors/migration/nv15" + "github.com/filecoin-project/specs-actors/v8/actors/migration/nv16" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -19,6 +17,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" @@ -49,7 +48,8 @@ type MigrationCache interface { type MigrationFunc func( ctx context.Context, sm *StateManager, cache MigrationCache, - cb ExecMonitor, oldState cid.Cid, + cb ExecMonitor, + oldState cid.Cid, height abi.ChainEpoch, ts *types.TipSet, ) (newState cid.Cid, err error) @@ -214,7 +214,7 @@ func (sm *StateManager) hasExpensiveFork(height abi.ChainEpoch) bool { return ok } -func runPreMigration(ctx context.Context, sm *StateManager, fn PreMigrationFunc, cache *nv15.MemMigrationCache, ts *types.TipSet) { +func runPreMigration(ctx context.Context, sm *StateManager, fn PreMigrationFunc, cache *nv16.MemMigrationCache, ts *types.TipSet) { height := ts.Height() parent := ts.ParentState() diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index 9a22716ba..e36f57ceb 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -168,7 +168,7 @@ func TestForkHeightTriggers(t *testing.T) { } inv := filcns.NewActorRegistry() - inv.Register(nil, testActor{}) + inv.Register(actors.Version0, nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { nvm, err := vm.NewLegacyVM(ctx, vmopt) @@ -285,7 +285,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) { } inv := filcns.NewActorRegistry() - inv.Register(nil, testActor{}) + inv.Register(actors.Version0, nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { nvm, err := vm.NewLegacyVM(ctx, vmopt) @@ -506,7 +506,7 @@ func TestForkPreMigration(t *testing.T) { }() inv := filcns.NewActorRegistry() - inv.Register(nil, testActor{}) + inv.Register(actors.Version0, nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { nvm, err := vm.NewLegacyVM(ctx, vmopt) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 7b10cd805..9aaccfff3 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -5,8 +5,7 @@ import ( "sync" "github.com/filecoin-project/lotus/chain/actors/adt" - - "github.com/filecoin-project/specs-actors/v7/actors/migration/nv15" + "github.com/filecoin-project/specs-actors/v8/actors/migration/nv16" "github.com/filecoin-project/lotus/chain/rand" @@ -57,7 +56,7 @@ type versionSpec struct { type migration struct { upgrade MigrationFunc preMigrations []PreMigration - cache *nv15.MemMigrationCache + cache *nv16.MemMigrationCache } type Executor interface { @@ -125,7 +124,7 @@ func NewStateManager(cs *store.ChainStore, exec Executor, sys vm.SyscallBuilder, migration := &migration{ upgrade: upgrade.Migration, preMigrations: upgrade.PreMigrations, - cache: nv15.NewMemMigrationCache(), + cache: nv16.NewMemMigrationCache(), } stateMigrations[upgrade.Height] = migration } diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 49dd4700a..61eb5fcb0 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -5,18 +5,21 @@ import ( "fmt" "reflect" - "github.com/filecoin-project/lotus/chain/rand" - "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" + "github.com/filecoin-project/go-state-types/manifest" + gstStore "github.com/filecoin-project/go-state-types/store" + "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/lotus/api" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/actors/builtin/system" "github.com/filecoin-project/lotus/chain/actors/policy" + "github.com/filecoin-project/lotus/chain/rand" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" @@ -79,11 +82,6 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, // future. It's not guaranteed to be accurate... but that's fine. } - filVested, err := sm.GetFilVested(ctx, height) - if err != nil { - return cid.Undef, nil, err - } - r := rand.NewStateRand(sm.cs, ts.Cids(), sm.beacon, sm.GetNetworkVersion) vmopt := &vm.VMOpts{ StateBase: base, @@ -95,7 +93,6 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, CircSupplyCalc: sm.GetVMCirculatingSupply, NetworkVersion: sm.GetNetworkVersion(ctx, height), BaseFee: ts.Blocks()[0].ParentBaseFee, - FilVested: filVested, LookbackState: LookbackStateGetterForTipset(sm, ts), } vmi, err := sm.newVM(ctx, vmopt) @@ -217,3 +214,42 @@ func (sm *StateManager) ListAllActors(ctx context.Context, ts *types.TipSet) ([] return out, nil } + +func GetManifest(ctx context.Context, st *state.StateTree) (*manifest.Manifest, error) { + wrapStore := gstStore.WrapStore(ctx, st.Store) + + systemActor, err := st.GetActor(system.Address) + if err != nil { + return nil, fmt.Errorf("failed to get system actor: %w", err) + } + systemActorState, err := system.Load(wrapStore, systemActor) + if err != nil { + return nil, xerrors.Errorf("failed to load system actor state: %w", err) + } + actorsManifestCid := systemActorState.GetBuiltinActors() + + mf := manifest.Manifest{ + Version: 1, + Data: actorsManifestCid, + } + if err := mf.Load(ctx, wrapStore); err != nil { + return nil, xerrors.Errorf("failed to load actor manifest: %w", err) + } + manifestData := manifest.ManifestData{} + if err := st.Store.Get(ctx, mf.Data, &manifestData); err != nil { + return nil, xerrors.Errorf("failed to load manifest data: %w", err) + } + return &mf, nil +} + +func GetManifestEntries(ctx context.Context, st *state.StateTree) ([]manifest.ManifestEntry, error) { + mf, err := GetManifest(ctx, st) + if err != nil { + return nil, xerrors.Errorf("failed to get manifest: %w", err) + } + manifestData := manifest.ManifestData{} + if err := st.Store.Get(ctx, mf.Data, &manifestData); err != nil { + return nil, xerrors.Errorf("filed to load manifest data: %w", err) + } + return manifestData.Entries, nil +} diff --git a/chain/store/snapshot.go b/chain/store/snapshot.go index b9630bcbd..07d086e1f 100644 --- a/chain/store/snapshot.go +++ b/chain/store/snapshot.go @@ -8,6 +8,7 @@ import ( "github.com/ipfs/go-cid" "github.com/ipld/go-car" carutil "github.com/ipld/go-car/util" + mh "github.com/multiformats/go-multihash" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -142,7 +143,18 @@ func (cs *ChainStore) WalkSnapshot(ctx context.Context, ts *types.TipSet, inclRe for _, c := range out { if seen.Visit(c) { - if c.Prefix().Codec != cid.DagCBOR { + prefix := c.Prefix() + + // Don't include identity CIDs. + if prefix.MhType == mh.IDENTITY { + continue + } + + // We only include raw and dagcbor, for now. + // Raw for "code" CIDs. + switch prefix.Codec { + case cid.Raw, cid.DagCBOR: + default: continue } diff --git a/chain/sync_test.go b/chain/sync_test.go index 96ed1440e..d8c68b132 100644 --- a/chain/sync_test.go +++ b/chain/sync_test.go @@ -8,6 +8,8 @@ import ( "testing" "time" + prooftypes "github.com/filecoin-project/go-state-types/proof" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/stmgr" @@ -22,9 +24,6 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" - proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" - "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/policy" @@ -143,6 +142,14 @@ func prepSyncTestWithV5Height(t testing.TB, h int, v5height abi.ChainEpoch) *syn Network: network.Version14, Height: v5height + 10, Migration: filcns.UpgradeActorsV6, + }, { + Network: network.Version15, + Height: v5height + 15, + Migration: filcns.UpgradeActorsV7, + }, { + Network: network.Version16, + Height: v5height + 20, + Migration: filcns.UpgradeActorsV8, }} g, err := gen.NewGeneratorWithUpgradeSchedule(sched) @@ -551,8 +558,8 @@ func (wpp badWpp) GenerateCandidates(context.Context, abi.PoStRandomness, uint64 return []uint64{1}, nil } -func (wpp badWpp) ComputeProof(context.Context, []proof7.ExtendedSectorInfo, abi.PoStRandomness, abi.ChainEpoch, network.Version) ([]proof2.PoStProof, error) { - return []proof2.PoStProof{ +func (wpp badWpp) ComputeProof(context.Context, []prooftypes.ExtendedSectorInfo, abi.PoStRandomness, abi.ChainEpoch, network.Version) ([]prooftypes.PoStProof, error) { + return []prooftypes.PoStProof{ { PoStProof: abi.RegisteredPoStProof_StackedDrgWinning2KiBV1, ProofBytes: []byte("evil"), diff --git a/chain/types/blockheader.go b/chain/types/blockheader.go index d36ee9314..c28a17abb 100644 --- a/chain/types/blockheader.go +++ b/chain/types/blockheader.go @@ -4,7 +4,7 @@ import ( "bytes" "math/big" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" + "github.com/filecoin-project/go-state-types/proof" "github.com/minio/blake2b-simd" @@ -49,21 +49,21 @@ func NewBeaconEntry(round uint64, data []byte) BeaconEntry { type BlockHeader struct { Miner address.Address // 0 unique per block/miner - Ticket *Ticket // 1 unique per block/miner: should be a valid VRF - ElectionProof *ElectionProof // 2 unique per block/miner: should be a valid VRF - BeaconEntries []BeaconEntry // 3 identical for all blocks in same tipset - WinPoStProof []proof2.PoStProof // 4 unique per block/miner - Parents []cid.Cid // 5 identical for all blocks in same tipset - ParentWeight BigInt // 6 identical for all blocks in same tipset - Height abi.ChainEpoch // 7 identical for all blocks in same tipset - ParentStateRoot cid.Cid // 8 identical for all blocks in same tipset - ParentMessageReceipts cid.Cid // 9 identical for all blocks in same tipset - Messages cid.Cid // 10 unique per block - BLSAggregate *crypto.Signature // 11 unique per block: aggrregate of BLS messages from above - Timestamp uint64 // 12 identical for all blocks in same tipset / hard-tied to the value of Height above - BlockSig *crypto.Signature // 13 unique per block/miner: miner signature - ForkSignaling uint64 // 14 currently unused/undefined - ParentBaseFee abi.TokenAmount // 15 identical for all blocks in same tipset: the base fee after executing parent tipset + Ticket *Ticket // 1 unique per block/miner: should be a valid VRF + ElectionProof *ElectionProof // 2 unique per block/miner: should be a valid VRF + BeaconEntries []BeaconEntry // 3 identical for all blocks in same tipset + WinPoStProof []proof.PoStProof // 4 unique per block/miner + Parents []cid.Cid // 5 identical for all blocks in same tipset + ParentWeight BigInt // 6 identical for all blocks in same tipset + Height abi.ChainEpoch // 7 identical for all blocks in same tipset + ParentStateRoot cid.Cid // 8 identical for all blocks in same tipset + ParentMessageReceipts cid.Cid // 9 identical for all blocks in same tipset + Messages cid.Cid // 10 unique per block + BLSAggregate *crypto.Signature // 11 unique per block: aggrregate of BLS messages from above + Timestamp uint64 // 12 identical for all blocks in same tipset / hard-tied to the value of Height above + BlockSig *crypto.Signature // 13 unique per block/miner: miner signature + ForkSignaling uint64 // 14 currently unused/undefined + ParentBaseFee abi.TokenAmount // 15 identical for all blocks in same tipset: the base fee after executing parent tipset validated bool // internal, true if the signature has been validated } diff --git a/chain/types/blockheader_test.go b/chain/types/blockheader_test.go index e386277df..773cf27b2 100644 --- a/chain/types/blockheader_test.go +++ b/chain/types/blockheader_test.go @@ -8,7 +8,7 @@ import ( "reflect" "testing" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" + prooftypes "github.com/filecoin-project/go-state-types/proof" cid "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" @@ -85,7 +85,7 @@ func TestInteropBH(t *testing.T) { t.Fatal(err) } - posts := []proof2.PoStProof{ + posts := []prooftypes.PoStProof{ {PoStProof: abi.RegisteredPoStProof_StackedDrgWinning2KiBV1, ProofBytes: []byte{0x07}}, } diff --git a/chain/types/cbor_gen.go b/chain/types/cbor_gen.go index b54c18c07..79ff5d19c 100644 --- a/chain/types/cbor_gen.go +++ b/chain/types/cbor_gen.go @@ -11,7 +11,7 @@ import ( abi "github.com/filecoin-project/go-state-types/abi" crypto "github.com/filecoin-project/go-state-types/crypto" exitcode "github.com/filecoin-project/go-state-types/exitcode" - proof "github.com/filecoin-project/specs-actors/actors/runtime/proof" + proof "github.com/filecoin-project/go-state-types/proof" cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" @@ -29,24 +29,25 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufBlockHeader); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufBlockHeader); err != nil { return err } - scratch := make([]byte, 9) - // t.Miner (address.Address) (struct) - if err := t.Miner.MarshalCBOR(w); err != nil { + if err := t.Miner.MarshalCBOR(cw); err != nil { return err } // t.Ticket (types.Ticket) (struct) - if err := t.Ticket.MarshalCBOR(w); err != nil { + if err := t.Ticket.MarshalCBOR(cw); err != nil { return err } // t.ElectionProof (types.ElectionProof) (struct) - if err := t.ElectionProof.MarshalCBOR(w); err != nil { + if err := t.ElectionProof.MarshalCBOR(cw); err != nil { return err } @@ -55,11 +56,11 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.BeaconEntries was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BeaconEntries))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.BeaconEntries))); err != nil { return err } for _, v := range t.BeaconEntries { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } @@ -69,11 +70,11 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.WinPoStProof was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.WinPoStProof))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.WinPoStProof))); err != nil { return err } for _, v := range t.WinPoStProof { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } @@ -83,88 +84,93 @@ func (t *BlockHeader) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Parents was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Parents))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Parents))); err != nil { return err } for _, v := range t.Parents { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + if err := cbg.WriteCid(w, v); err != nil { return xerrors.Errorf("failed writing cid field t.Parents: %w", err) } } // t.ParentWeight (big.Int) (struct) - if err := t.ParentWeight.MarshalCBOR(w); err != nil { + if err := t.ParentWeight.MarshalCBOR(cw); err != nil { return err } // t.Height (abi.ChainEpoch) (int64) if t.Height >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Height)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Height)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Height-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Height-1)); err != nil { return err } } // t.ParentStateRoot (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.ParentStateRoot); err != nil { + if err := cbg.WriteCid(cw, t.ParentStateRoot); err != nil { return xerrors.Errorf("failed to write cid field t.ParentStateRoot: %w", err) } // t.ParentMessageReceipts (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.ParentMessageReceipts); err != nil { + if err := cbg.WriteCid(cw, t.ParentMessageReceipts); err != nil { return xerrors.Errorf("failed to write cid field t.ParentMessageReceipts: %w", err) } // t.Messages (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.Messages); err != nil { + if err := cbg.WriteCid(cw, t.Messages); err != nil { return xerrors.Errorf("failed to write cid field t.Messages: %w", err) } // t.BLSAggregate (crypto.Signature) (struct) - if err := t.BLSAggregate.MarshalCBOR(w); err != nil { + if err := t.BLSAggregate.MarshalCBOR(cw); err != nil { return err } // t.Timestamp (uint64) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Timestamp)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Timestamp)); err != nil { return err } // t.BlockSig (crypto.Signature) (struct) - if err := t.BlockSig.MarshalCBOR(w); err != nil { + if err := t.BlockSig.MarshalCBOR(cw); err != nil { return err } // t.ForkSignaling (uint64) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.ForkSignaling)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.ForkSignaling)); err != nil { return err } // t.ParentBaseFee (big.Int) (struct) - if err := t.ParentBaseFee.MarshalCBOR(w); err != nil { + if err := t.ParentBaseFee.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { +func (t *BlockHeader) UnmarshalCBOR(r io.Reader) (err error) { *t = BlockHeader{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -177,7 +183,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - if err := t.Miner.UnmarshalCBOR(br); err != nil { + if err := t.Miner.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Miner: %w", err) } @@ -186,16 +192,16 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.Ticket = new(Ticket) - if err := t.Ticket.UnmarshalCBOR(br); err != nil { + if err := t.Ticket.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Ticket pointer: %w", err) } } @@ -205,16 +211,16 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.ElectionProof = new(ElectionProof) - if err := t.ElectionProof.UnmarshalCBOR(br); err != nil { + if err := t.ElectionProof.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.ElectionProof pointer: %w", err) } } @@ -222,7 +228,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { } // t.BeaconEntries ([]types.BeaconEntry) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -242,7 +248,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v BeaconEntry - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -251,7 +257,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { // t.WinPoStProof ([]proof.PoStProof) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -271,7 +277,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v proof.PoStProof - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -280,7 +286,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { // t.Parents ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -299,7 +305,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("reading cid field t.Parents failed: %w", err) } @@ -310,14 +316,14 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - if err := t.ParentWeight.UnmarshalCBOR(br); err != nil { + if err := t.ParentWeight.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.ParentWeight: %w", err) } } // t.Height (abi.ChainEpoch) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -344,7 +350,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.ParentStateRoot: %w", err) } @@ -356,7 +362,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.ParentMessageReceipts: %w", err) } @@ -368,7 +374,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.Messages: %w", err) } @@ -380,16 +386,16 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.BLSAggregate = new(crypto.Signature) - if err := t.BLSAggregate.UnmarshalCBOR(br); err != nil { + if err := t.BLSAggregate.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.BLSAggregate pointer: %w", err) } } @@ -399,7 +405,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -413,16 +419,16 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.BlockSig = new(crypto.Signature) - if err := t.BlockSig.UnmarshalCBOR(br); err != nil { + if err := t.BlockSig.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.BlockSig pointer: %w", err) } } @@ -432,7 +438,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -446,7 +452,7 @@ func (t *BlockHeader) UnmarshalCBOR(r io.Reader) error { { - if err := t.ParentBaseFee.UnmarshalCBOR(br); err != nil { + if err := t.ParentBaseFee.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.ParentBaseFee: %w", err) } @@ -461,37 +467,43 @@ func (t *Ticket) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufTicket); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufTicket); err != nil { return err } - scratch := make([]byte, 9) - // t.VRFProof ([]uint8) (slice) if len(t.VRFProof) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.VRFProof was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.VRFProof))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.VRFProof))); err != nil { return err } - if _, err := w.Write(t.VRFProof[:]); err != nil { + if _, err := cw.Write(t.VRFProof[:]); err != nil { return err } return nil } -func (t *Ticket) UnmarshalCBOR(r io.Reader) error { +func (t *Ticket) UnmarshalCBOR(r io.Reader) (err error) { *t = Ticket{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -502,7 +514,7 @@ func (t *Ticket) UnmarshalCBOR(r io.Reader) error { // t.VRFProof ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -518,7 +530,7 @@ func (t *Ticket) UnmarshalCBOR(r io.Reader) error { t.VRFProof = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.VRFProof[:]); err != nil { + if _, err := io.ReadFull(cr, t.VRFProof[:]); err != nil { return err } return nil @@ -531,19 +543,20 @@ func (t *ElectionProof) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufElectionProof); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufElectionProof); err != nil { return err } - scratch := make([]byte, 9) - // t.WinCount (int64) (int64) if t.WinCount >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.WinCount)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.WinCount)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.WinCount-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.WinCount-1)); err != nil { return err } } @@ -553,26 +566,31 @@ func (t *ElectionProof) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.VRFProof was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.VRFProof))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.VRFProof))); err != nil { return err } - if _, err := w.Write(t.VRFProof[:]); err != nil { + if _, err := cw.Write(t.VRFProof[:]); err != nil { return err } return nil } -func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error { +func (t *ElectionProof) UnmarshalCBOR(r io.Reader) (err error) { *t = ElectionProof{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -583,7 +601,7 @@ func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error { // t.WinCount (int64) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -608,7 +626,7 @@ func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error { } // t.VRFProof ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -624,7 +642,7 @@ func (t *ElectionProof) UnmarshalCBOR(r io.Reader) error { t.VRFProof = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.VRFProof[:]); err != nil { + if _, err := io.ReadFull(cr, t.VRFProof[:]); err != nil { return err } return nil @@ -637,63 +655,64 @@ func (t *Message) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufMessage); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufMessage); err != nil { return err } - scratch := make([]byte, 9) - // t.Version (uint64) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Version)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Version)); err != nil { return err } // t.To (address.Address) (struct) - if err := t.To.MarshalCBOR(w); err != nil { + if err := t.To.MarshalCBOR(cw); err != nil { return err } // t.From (address.Address) (struct) - if err := t.From.MarshalCBOR(w); err != nil { + if err := t.From.MarshalCBOR(cw); err != nil { return err } // t.Nonce (uint64) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Nonce)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Nonce)); err != nil { return err } // t.Value (big.Int) (struct) - if err := t.Value.MarshalCBOR(w); err != nil { + if err := t.Value.MarshalCBOR(cw); err != nil { return err } // t.GasLimit (int64) (int64) if t.GasLimit >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.GasLimit)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.GasLimit)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.GasLimit-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.GasLimit-1)); err != nil { return err } } // t.GasFeeCap (big.Int) (struct) - if err := t.GasFeeCap.MarshalCBOR(w); err != nil { + if err := t.GasFeeCap.MarshalCBOR(cw); err != nil { return err } // t.GasPremium (big.Int) (struct) - if err := t.GasPremium.MarshalCBOR(w); err != nil { + if err := t.GasPremium.MarshalCBOR(cw); err != nil { return err } // t.Method (abi.MethodNum) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Method)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Method)); err != nil { return err } @@ -702,26 +721,31 @@ func (t *Message) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Params was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Params))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Params))); err != nil { return err } - if _, err := w.Write(t.Params[:]); err != nil { + if _, err := cw.Write(t.Params[:]); err != nil { return err } return nil } -func (t *Message) UnmarshalCBOR(r io.Reader) error { +func (t *Message) UnmarshalCBOR(r io.Reader) (err error) { *t = Message{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -734,7 +758,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -748,7 +772,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - if err := t.To.UnmarshalCBOR(br); err != nil { + if err := t.To.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.To: %w", err) } @@ -757,7 +781,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - if err := t.From.UnmarshalCBOR(br); err != nil { + if err := t.From.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.From: %w", err) } @@ -766,7 +790,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -780,14 +804,14 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - if err := t.Value.UnmarshalCBOR(br); err != nil { + if err := t.Value.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Value: %w", err) } } // t.GasLimit (int64) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -814,7 +838,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - if err := t.GasFeeCap.UnmarshalCBOR(br); err != nil { + if err := t.GasFeeCap.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.GasFeeCap: %w", err) } @@ -823,7 +847,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - if err := t.GasPremium.UnmarshalCBOR(br); err != nil { + if err := t.GasPremium.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.GasPremium: %w", err) } @@ -832,7 +856,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -844,7 +868,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { } // t.Params ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -860,7 +884,7 @@ func (t *Message) UnmarshalCBOR(r io.Reader) error { t.Params = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Params[:]); err != nil { + if _, err := io.ReadFull(cr, t.Params[:]); err != nil { return err } return nil @@ -873,32 +897,40 @@ func (t *SignedMessage) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufSignedMessage); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufSignedMessage); err != nil { return err } // t.Message (types.Message) (struct) - if err := t.Message.MarshalCBOR(w); err != nil { + if err := t.Message.MarshalCBOR(cw); err != nil { return err } // t.Signature (crypto.Signature) (struct) - if err := t.Signature.MarshalCBOR(w); err != nil { + if err := t.Signature.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error { +func (t *SignedMessage) UnmarshalCBOR(r io.Reader) (err error) { *t = SignedMessage{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -911,7 +943,7 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error { { - if err := t.Message.UnmarshalCBOR(br); err != nil { + if err := t.Message.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Message: %w", err) } @@ -920,7 +952,7 @@ func (t *SignedMessage) UnmarshalCBOR(r io.Reader) error { { - if err := t.Signature.UnmarshalCBOR(br); err != nil { + if err := t.Signature.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Signature: %w", err) } @@ -935,37 +967,43 @@ func (t *MsgMeta) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufMsgMeta); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufMsgMeta); err != nil { return err } - scratch := make([]byte, 9) - // t.BlsMessages (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.BlsMessages); err != nil { + if err := cbg.WriteCid(cw, t.BlsMessages); err != nil { return xerrors.Errorf("failed to write cid field t.BlsMessages: %w", err) } // t.SecpkMessages (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.SecpkMessages); err != nil { + if err := cbg.WriteCid(cw, t.SecpkMessages); err != nil { return xerrors.Errorf("failed to write cid field t.SecpkMessages: %w", err) } return nil } -func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error { +func (t *MsgMeta) UnmarshalCBOR(r io.Reader) (err error) { *t = MsgMeta{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -978,7 +1016,7 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.BlsMessages: %w", err) } @@ -990,7 +1028,7 @@ func (t *MsgMeta) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.SecpkMessages: %w", err) } @@ -1008,47 +1046,53 @@ func (t *Actor) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufActor); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufActor); err != nil { return err } - scratch := make([]byte, 9) - // t.Code (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.Code); err != nil { + if err := cbg.WriteCid(cw, t.Code); err != nil { return xerrors.Errorf("failed to write cid field t.Code: %w", err) } // t.Head (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.Head); err != nil { + if err := cbg.WriteCid(cw, t.Head); err != nil { return xerrors.Errorf("failed to write cid field t.Head: %w", err) } // t.Nonce (uint64) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Nonce)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Nonce)); err != nil { return err } // t.Balance (big.Int) (struct) - if err := t.Balance.MarshalCBOR(w); err != nil { + if err := t.Balance.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *Actor) UnmarshalCBOR(r io.Reader) error { +func (t *Actor) UnmarshalCBOR(r io.Reader) (err error) { *t = Actor{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -1061,7 +1105,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.Code: %w", err) } @@ -1073,7 +1117,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.Head: %w", err) } @@ -1085,7 +1129,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1099,7 +1143,7 @@ func (t *Actor) UnmarshalCBOR(r io.Reader) error { { - if err := t.Balance.UnmarshalCBOR(br); err != nil { + if err := t.Balance.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Balance: %w", err) } @@ -1114,19 +1158,20 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufMessageReceipt); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufMessageReceipt); err != nil { return err } - scratch := make([]byte, 9) - // t.ExitCode (exitcode.ExitCode) (int64) if t.ExitCode >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.ExitCode)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.ExitCode)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.ExitCode-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.ExitCode-1)); err != nil { return err } } @@ -1136,37 +1181,42 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Return was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Return))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Return))); err != nil { return err } - if _, err := w.Write(t.Return[:]); err != nil { + if _, err := cw.Write(t.Return[:]); err != nil { return err } // t.GasUsed (int64) (int64) if t.GasUsed >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.GasUsed)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.GasUsed)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.GasUsed-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.GasUsed-1)); err != nil { return err } } return nil } -func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { +func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) (err error) { *t = MessageReceipt{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -1177,7 +1227,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { // t.ExitCode (exitcode.ExitCode) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1202,7 +1252,7 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { } // t.Return ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1218,12 +1268,12 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error { t.Return = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Return[:]); err != nil { + if _, err := io.ReadFull(cr, t.Return[:]); err != nil { return err } // t.GasUsed (int64) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1256,14 +1306,15 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufBlockMsg); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufBlockMsg); err != nil { return err } - scratch := make([]byte, 9) - // t.Header (types.BlockHeader) (struct) - if err := t.Header.MarshalCBOR(w); err != nil { + if err := t.Header.MarshalCBOR(cw); err != nil { return err } @@ -1272,11 +1323,11 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.BlsMessages was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.BlsMessages))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.BlsMessages))); err != nil { return err } for _, v := range t.BlsMessages { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + if err := cbg.WriteCid(w, v); err != nil { return xerrors.Errorf("failed writing cid field t.BlsMessages: %w", err) } } @@ -1286,27 +1337,32 @@ func (t *BlockMsg) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.SecpkMessages was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.SecpkMessages))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.SecpkMessages))); err != nil { return err } for _, v := range t.SecpkMessages { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + if err := cbg.WriteCid(w, v); err != nil { return xerrors.Errorf("failed writing cid field t.SecpkMessages: %w", err) } } return nil } -func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { +func (t *BlockMsg) UnmarshalCBOR(r io.Reader) (err error) { *t = BlockMsg{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -1319,16 +1375,16 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.Header = new(BlockHeader) - if err := t.Header.UnmarshalCBOR(br); err != nil { + if err := t.Header.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Header pointer: %w", err) } } @@ -1336,7 +1392,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { } // t.BlsMessages ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1355,7 +1411,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("reading cid field t.BlsMessages failed: %w", err) } @@ -1364,7 +1420,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { // t.SecpkMessages ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1383,7 +1439,7 @@ func (t *BlockMsg) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("reading cid field t.SecpkMessages failed: %w", err) } @@ -1400,22 +1456,23 @@ func (t *ExpTipSet) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufExpTipSet); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufExpTipSet); err != nil { return err } - scratch := make([]byte, 9) - // t.Cids ([]cid.Cid) (slice) if len(t.Cids) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.Cids was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Cids))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Cids))); err != nil { return err } for _, v := range t.Cids { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + if err := cbg.WriteCid(w, v); err != nil { return xerrors.Errorf("failed writing cid field t.Cids: %w", err) } } @@ -1425,38 +1482,43 @@ func (t *ExpTipSet) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Blocks was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Blocks))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Blocks))); err != nil { return err } for _, v := range t.Blocks { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } // t.Height (abi.ChainEpoch) (int64) if t.Height >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Height)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Height)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Height-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Height-1)); err != nil { return err } } return nil } -func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { +func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) (err error) { *t = ExpTipSet{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -1467,7 +1529,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { // t.Cids ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1486,7 +1548,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("reading cid field t.Cids failed: %w", err) } @@ -1495,7 +1557,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { // t.Blocks ([]*types.BlockHeader) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1515,7 +1577,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v BlockHeader - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -1524,7 +1586,7 @@ func (t *ExpTipSet) UnmarshalCBOR(r io.Reader) error { // t.Height (abi.ChainEpoch) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1557,15 +1619,16 @@ func (t *BeaconEntry) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufBeaconEntry); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufBeaconEntry); err != nil { return err } - scratch := make([]byte, 9) - // t.Round (uint64) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Round)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Round)); err != nil { return err } @@ -1574,26 +1637,31 @@ func (t *BeaconEntry) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Data was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Data))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Data))); err != nil { return err } - if _, err := w.Write(t.Data[:]); err != nil { + if _, err := cw.Write(t.Data[:]); err != nil { return err } return nil } -func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error { +func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) (err error) { *t = BeaconEntry{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -1606,7 +1674,7 @@ func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1618,7 +1686,7 @@ func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error { } // t.Data ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1634,7 +1702,7 @@ func (t *BeaconEntry) UnmarshalCBOR(r io.Reader) error { t.Data = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Data[:]); err != nil { + if _, err := io.ReadFull(cr, t.Data[:]); err != nil { return err } return nil @@ -1647,43 +1715,49 @@ func (t *StateRoot) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufStateRoot); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufStateRoot); err != nil { return err } - scratch := make([]byte, 9) - // t.Version (types.StateTreeVersion) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Version)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Version)); err != nil { return err } // t.Actors (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.Actors); err != nil { + if err := cbg.WriteCid(cw, t.Actors); err != nil { return xerrors.Errorf("failed to write cid field t.Actors: %w", err) } // t.Info (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.Info); err != nil { + if err := cbg.WriteCid(cw, t.Info); err != nil { return xerrors.Errorf("failed to write cid field t.Info: %w", err) } return nil } -func (t *StateRoot) UnmarshalCBOR(r io.Reader) error { +func (t *StateRoot) UnmarshalCBOR(r io.Reader) (err error) { *t = StateRoot{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -1696,7 +1770,7 @@ func (t *StateRoot) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1710,7 +1784,7 @@ func (t *StateRoot) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.Actors: %w", err) } @@ -1722,7 +1796,7 @@ func (t *StateRoot) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.Info: %w", err) } @@ -1740,23 +1814,30 @@ func (t *StateInfo0) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufStateInfo0); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufStateInfo0); err != nil { return err } - return nil } -func (t *StateInfo0) UnmarshalCBOR(r io.Reader) error { +func (t *StateInfo0) UnmarshalCBOR(r io.Reader) (err error) { *t = StateInfo0{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } diff --git a/chain/vm/cbor_gen.go b/chain/vm/cbor_gen.go index 76d8e9d48..0e1677c95 100644 --- a/chain/vm/cbor_gen.go +++ b/chain/vm/cbor_gen.go @@ -26,19 +26,20 @@ func (t *FvmExecutionTrace) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufFvmExecutionTrace); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufFvmExecutionTrace); err != nil { return err } - scratch := make([]byte, 9) - // t.Msg (types.Message) (struct) - if err := t.Msg.MarshalCBOR(w); err != nil { + if err := t.Msg.MarshalCBOR(cw); err != nil { return err } // t.MsgRct (types.MessageReceipt) (struct) - if err := t.MsgRct.MarshalCBOR(w); err != nil { + if err := t.MsgRct.MarshalCBOR(cw); err != nil { return err } @@ -47,7 +48,7 @@ func (t *FvmExecutionTrace) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Error was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Error))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Error))); err != nil { return err } if _, err := io.WriteString(w, string(t.Error)); err != nil { @@ -59,27 +60,32 @@ func (t *FvmExecutionTrace) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Subcalls was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Subcalls))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Subcalls))); err != nil { return err } for _, v := range t.Subcalls { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } return nil } -func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) error { +func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) (err error) { *t = FvmExecutionTrace{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -92,16 +98,16 @@ func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.Msg = new(types.Message) - if err := t.Msg.UnmarshalCBOR(br); err != nil { + if err := t.Msg.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Msg pointer: %w", err) } } @@ -111,16 +117,16 @@ func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.MsgRct = new(types.MessageReceipt) - if err := t.MsgRct.UnmarshalCBOR(br); err != nil { + if err := t.MsgRct.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.MsgRct pointer: %w", err) } } @@ -129,7 +135,7 @@ func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) error { // t.Error (string) (string) { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -138,7 +144,7 @@ func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) error { } // t.Subcalls ([]vm.FvmExecutionTrace) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -158,7 +164,7 @@ func (t *FvmExecutionTrace) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v FvmExecutionTrace - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 2976b63d9..158d61c82 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -3,7 +3,8 @@ package vm import ( "bytes" "context" - "sync/atomic" + "fmt" + "os" "time" "github.com/ipfs/go-cid" @@ -12,10 +13,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/actors/policy" - "github.com/filecoin-project/go-state-types/network" - - "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/state" cbor "github.com/ipfs/go-ipld-cbor" @@ -31,6 +28,7 @@ import ( ffi "github.com/filecoin-project/filecoin-ffi" ffi_cgo "github.com/filecoin-project/filecoin-ffi/cgo" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" @@ -62,16 +60,18 @@ func (t *FvmExecutionTrace) ToExecutionTrace() types.ExecutionTrace { } ret := types.ExecutionTrace{ - Msg: t.Msg, - MsgRct: t.MsgRct, - Error: t.Error, - Duration: 0, - GasCharges: nil, - Subcalls: make([]types.ExecutionTrace, len(t.Subcalls)), + Msg: t.Msg, + MsgRct: t.MsgRct, + Error: t.Error, + Subcalls: nil, // Should be nil when there are no subcalls for backwards compatibility } - for i, v := range t.Subcalls { - ret.Subcalls[i] = v.ToExecutionTrace() + if len(t.Subcalls) > 0 { + ret.Subcalls = make([]types.ExecutionTrace, len(t.Subcalls)) + + for i, v := range t.Subcalls { + ret.Subcalls[i] = v.ToExecutionTrace() + } } return ret @@ -256,25 +256,25 @@ type FVM struct { } func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { - log.Info("using the FVM, this is experimental!") - circToReport := opts.FilVested - // For v14 (and earlier), we perform the FilVested portion of the calculation, and let the FVM dynamically do the rest - // v15 and after, the circ supply is always constant per epoch, so we calculate the base and report it at creation - if opts.NetworkVersion >= network.Version15 { - state, err := state.LoadStateTree(cbor.NewCborStore(opts.Bstore), opts.StateBase) - if err != nil { - return nil, err - } - - circToReport, err = opts.CircSupplyCalc(ctx, opts.Epoch, state) - if err != nil { - return nil, err - } + state, err := state.LoadStateTree(cbor.NewCborStore(opts.Bstore), opts.StateBase) + if err != nil { + return nil, err } - fvmOpts := ffi.FVMOpts{ - FVMVersion: 0, - Externs: &FvmExtern{Rand: opts.Rand, Blockstore: opts.Bstore, lbState: opts.LookbackState, base: opts.StateBase, epoch: opts.Epoch}, + circToReport, err := opts.CircSupplyCalc(ctx, opts.Epoch, state) + if err != nil { + return nil, err + } + + fvmopts := &ffi.FVMOpts{ + FVMVersion: 0, + Externs: &FvmExtern{ + Rand: opts.Rand, + Blockstore: opts.Bstore, + lbState: opts.LookbackState, + base: opts.StateBase, + epoch: opts.Epoch, + }, Epoch: opts.Epoch, BaseFee: opts.BaseFee, BaseCircSupply: circToReport, @@ -283,7 +283,21 @@ func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { Tracing: EnableDetailedTracing, } - fvm, err := ffi.CreateFVM(&fvmOpts) + if os.Getenv("LOTUS_USE_FVM_CUSTOM_BUNDLE") == "1" { + av, err := actors.VersionForNetwork(opts.NetworkVersion) + if err != nil { + return nil, xerrors.Errorf("mapping network version to actors version: %w", err) + } + + c, ok := actors.GetManifest(av) + if !ok { + return nil, xerrors.Errorf("no manifest for custom bundle (actors version %d)", av) + } + + fvmopts.Manifest = c + } + + fvm, err := ffi.CreateFVM(fvmopts) if err != nil { return nil, err @@ -296,8 +310,8 @@ func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) { start := build.Clock.Now() - defer atomic.AddUint64(&StatApplied, 1) - msgBytes, err := cmsg.VMMessage().Serialize() + vmMsg := cmsg.VMMessage() + msgBytes, err := vmMsg.Serialize() if err != nil { return nil, xerrors.Errorf("serializing msg: %w", err) } @@ -307,11 +321,11 @@ func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet return nil, xerrors.Errorf("applying msg: %w", err) } - var et FvmExecutionTrace - if len(ret.ExecTraceBytes) != 0 { - if err = et.UnmarshalCBOR(bytes.NewReader(ret.ExecTraceBytes)); err != nil { - return nil, xerrors.Errorf("failed to unmarshal exectrace: %w", err) - } + duration := time.Since(start) + receipt := types.MessageReceipt{ + Return: ret.Return, + ExitCode: exitcode.ExitCode(ret.ExitCode), + GasUsed: ret.GasUsed, } var aerr aerrors.ActorError @@ -323,32 +337,44 @@ func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet aerr = aerrors.New(exitcode.ExitCode(ret.ExitCode), amsg) } + var et types.ExecutionTrace + if len(ret.ExecTraceBytes) != 0 { + var fvmEt FvmExecutionTrace + if err = fvmEt.UnmarshalCBOR(bytes.NewReader(ret.ExecTraceBytes)); err != nil { + return nil, xerrors.Errorf("failed to unmarshal exectrace: %w", err) + } + et = fvmEt.ToExecutionTrace() + } + + // Set the top-level exectrace info from the message and receipt for backwards compatibility + et.Msg = vmMsg + et.MsgRct = &receipt + et.Duration = duration + if aerr != nil { + et.Error = aerr.Error() + } + return &ApplyRet{ - MessageReceipt: types.MessageReceipt{ - Return: ret.Return, - ExitCode: exitcode.ExitCode(ret.ExitCode), - GasUsed: ret.GasUsed, - }, + MessageReceipt: receipt, GasCosts: &GasOutputs{ - // TODO: do the other optional fields eventually - BaseFeeBurn: big.Zero(), - OverEstimationBurn: big.Zero(), + BaseFeeBurn: ret.BaseFeeBurn, + OverEstimationBurn: ret.OverEstimationBurn, MinerPenalty: ret.MinerPenalty, MinerTip: ret.MinerTip, - Refund: big.Zero(), - GasRefund: 0, - GasBurned: 0, + Refund: ret.Refund, + GasRefund: ret.GasRefund, + GasBurned: ret.GasBurned, }, ActorErr: aerr, - ExecutionTrace: et.ToExecutionTrace(), - Duration: time.Since(start), + ExecutionTrace: et, + Duration: duration, }, nil } func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (*ApplyRet, error) { start := build.Clock.Now() - defer atomic.AddUint64(&StatApplied, 1) - msgBytes, err := cmsg.VMMessage().Serialize() + vmMsg := cmsg.VMMessage() + msgBytes, err := vmMsg.Serialize() if err != nil { return nil, xerrors.Errorf("serializing msg: %w", err) } @@ -357,11 +383,11 @@ func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (* return nil, xerrors.Errorf("applying msg: %w", err) } - var et FvmExecutionTrace - if len(ret.ExecTraceBytes) != 0 { - if err = et.UnmarshalCBOR(bytes.NewReader(ret.ExecTraceBytes)); err != nil { - return nil, xerrors.Errorf("failed to unmarshal exectrace: %w", err) - } + duration := time.Since(start) + receipt := types.MessageReceipt{ + Return: ret.Return, + ExitCode: exitcode.ExitCode(ret.ExitCode), + GasUsed: ret.GasUsed, } var aerr aerrors.ActorError @@ -373,16 +399,34 @@ func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (* aerr = aerrors.New(exitcode.ExitCode(ret.ExitCode), amsg) } - return &ApplyRet{ - MessageReceipt: types.MessageReceipt{ - Return: ret.Return, - ExitCode: exitcode.ExitCode(ret.ExitCode), - GasUsed: ret.GasUsed, - }, + var et types.ExecutionTrace + if len(ret.ExecTraceBytes) != 0 { + var fvmEt FvmExecutionTrace + if err = fvmEt.UnmarshalCBOR(bytes.NewReader(ret.ExecTraceBytes)); err != nil { + return nil, xerrors.Errorf("failed to unmarshal exectrace: %w", err) + } + et = fvmEt.ToExecutionTrace() + } else { + et.Msg = vmMsg + et.MsgRct = &receipt + et.Duration = duration + if aerr != nil { + et.Error = aerr.Error() + } + } + + applyRet := &ApplyRet{ + MessageReceipt: receipt, ActorErr: aerr, - ExecutionTrace: et.ToExecutionTrace(), - Duration: time.Since(start), - }, nil + ExecutionTrace: et, + Duration: duration, + } + + if ret.ExitCode != 0 { + return applyRet, fmt.Errorf("implicit message failed with exit code: %d and error: %w", ret.ExitCode, applyRet.ActorErr) + } + + return applyRet, nil } func (vm *FVM) Flush(ctx context.Context) (cid.Cid, error) { diff --git a/chain/vm/invoker.go b/chain/vm/invoker.go index 8a7a4c8c9..01ff14480 100644 --- a/chain/vm/invoker.go +++ b/chain/vm/invoker.go @@ -89,22 +89,38 @@ func (ar *ActorRegistry) Invoke(codeCid cid.Cid, rt vmr.Runtime, method abi.Meth } -func (ar *ActorRegistry) Register(pred ActorPredicate, actors ...rtt.VMActor) { +func (ar *ActorRegistry) Register(av actors.Version, pred ActorPredicate, vmactors ...rtt.VMActor) { if pred == nil { pred = func(vmr.Runtime, rtt.VMActor) error { return nil } } - for _, a := range actors { + for _, a := range vmactors { // register in the `actors` map (for the invoker) code, err := ar.transform(a) if err != nil { panic(xerrors.Errorf("%s: %w", string(a.Code().Hash()), err)) } - ar.actors[a.Code()] = &actorInfo{ + + ai := &actorInfo{ methods: code, vmActor: a, predicate: pred, } + ac := a.Code() + ar.actors[ac] = ai + + // necessary to make stuff work + var realCode cid.Cid + if av >= actors.Version8 { + name := actors.CanonicalName(builtin.ActorNameByCode(ac)) + + var ok bool + realCode, ok = actors.GetActorCodeID(av, name) + if ok { + ar.actors[realCode] = ai + } + } + // register in the `Methods` map (used by statemanager utils) exports := a.Exports() methods := make(map[abi.MethodNum]MethodMeta, len(exports)) @@ -148,7 +164,11 @@ func (ar *ActorRegistry) Register(pred ActorPredicate, actors ...rtt.VMActor) { Ret: et.Out(0), } } - ar.Methods[a.Code()] = methods + if realCode.Defined() { + ar.Methods[realCode] = methods + } else { + ar.Methods[a.Code()] = methods + } } } diff --git a/chain/vm/mkactor.go b/chain/vm/mkactor.go index 5716b5006..acdbf9ad4 100644 --- a/chain/vm/mkactor.go +++ b/chain/vm/mkactor.go @@ -14,12 +14,6 @@ import ( "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" - /* inline-gen template - {{range .actorVersions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"{{end}} - - /* inline-gen start */ - 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" @@ -28,8 +22,6 @@ import ( builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" builtin7 "github.com/filecoin-project/specs-actors/v7/actors/builtin" - /* inline-gen end */ - "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/actors/builtin" @@ -113,12 +105,6 @@ func newAccountActor(ver actors.Version) *types.Actor { // TODO: ActorsUpgrade use a global actor registry? var code cid.Cid switch ver { - /* inline-gen template - {{range .actorVersions}} - case actors.Version{{.}}: - code = builtin{{.}}.AccountActorCodeID{{end}} - /* inline-gen start */ - case actors.Version0: code = builtin0.AccountActorCodeID case actors.Version2: @@ -133,7 +119,6 @@ func newAccountActor(ver actors.Version) *types.Actor { code = builtin6.AccountActorCodeID case actors.Version7: code = builtin7.AccountActorCodeID - /* inline-gen end */ default: panic("unsupported actors version") } diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index 858c69885..497d4f6d9 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -29,7 +29,9 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/aerrors" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" ) @@ -57,7 +59,7 @@ func (m *Message) ValueReceived() abi.TokenAmount { } // EnableDetailedTracing, if true, outputs gas tracing in execution traces. -var EnableDetailedTracing = os.Getenv("LOTUS_VM_ENABLE_GAS_TRACING_VERY_SLOW") == "1" +var EnableDetailedTracing = os.Getenv("LOTUS_VM_ENABLE_TRACING") == "1" type Runtime struct { rt7.Message @@ -365,6 +367,20 @@ func (rt *Runtime) ValidateImmediateCallerType(ts ...cid.Cid) { if t == callerCid { return } + + // this really only for genesis in tests; nv16 will be running on FVM anyway. + if nv := rt.NetworkVersion(); nv >= network.Version16 { + av, err := actors.VersionForNetwork(nv) + if err != nil { + panic(aerrors.Fatalf("failed to get actors version for network version %d", nv)) + } + + name := actors.CanonicalName(builtin.ActorNameByCode(t)) + ac, ok := actors.GetActorCodeID(av, name) + if ok && ac == callerCid { + return + } + } } rt.Abortf(exitcode.SysErrForbidden, "caller cid type %q was not one of %v", callerCid, ts) } diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index cd143279e..674a48070 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -7,8 +7,6 @@ import ( goruntime "runtime" "sync" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" - "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "github.com/minio/blake2b-simd" @@ -245,7 +243,7 @@ func (ss *syscallShim) workerKeyAtLookback(height abi.ChainEpoch) (address.Addre return ResolveToKeyAddr(ss.cstate, ss.cst, info.Worker) } -func (ss *syscallShim) VerifyPoSt(info proof5.WindowPoStVerifyInfo) error { +func (ss *syscallShim) VerifyPoSt(info proof7.WindowPoStVerifyInfo) error { ok, err := ss.verifier.VerifyWindowPoSt(context.TODO(), info) if err != nil { return err @@ -256,7 +254,7 @@ func (ss *syscallShim) VerifyPoSt(info proof5.WindowPoStVerifyInfo) error { return nil } -func (ss *syscallShim) VerifySeal(info proof5.SealVerifyInfo) error { +func (ss *syscallShim) VerifySeal(info proof7.SealVerifyInfo) error { //_, span := trace.StartSpan(ctx, "ValidatePoRep") //defer span.End() @@ -283,7 +281,7 @@ func (ss *syscallShim) VerifySeal(info proof5.SealVerifyInfo) error { return nil } -func (ss *syscallShim) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) error { +func (ss *syscallShim) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) error { ok, err := ss.verifier.VerifyAggregateSeals(aggregate) if err != nil { return xerrors.Errorf("failed to verify aggregated PoRep: %w", err) @@ -322,7 +320,7 @@ func (ss *syscallShim) VerifySignature(sig crypto.Signature, addr address.Addres var BatchSealVerifyParallelism = goruntime.NumCPU() -func (ss *syscallShim) BatchVerifySeals(inp map[address.Address][]proof5.SealVerifyInfo) (map[address.Address][]bool, error) { +func (ss *syscallShim) BatchVerifySeals(inp map[address.Address][]proof7.SealVerifyInfo) (map[address.Address][]bool, error) { out := make(map[address.Address][]bool) sema := make(chan struct{}, BatchSealVerifyParallelism) @@ -334,7 +332,7 @@ func (ss *syscallShim) BatchVerifySeals(inp map[address.Address][]proof5.SealVer for i, s := range seals { wg.Add(1) - go func(ma address.Address, ix int, svi proof5.SealVerifyInfo, res []bool) { + go func(ma address.Address, ix int, svi proof7.SealVerifyInfo, res []bool) { defer wg.Done() sema <- struct{}{} diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 06c615ac7..26d3a82b3 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -27,12 +27,12 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-state-types/network" + builtin_types "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/actors/builtin/account" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/reward" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/types" @@ -227,8 +227,6 @@ type VMOpts struct { Actors *ActorRegistry Syscalls SyscallBuilder CircSupplyCalc CircSupplyCalculator - // Amount of FIL vested from genesis actors. - FilVested abi.TokenAmount NetworkVersion network.Version BaseFee abi.TokenAmount LookbackState LookbackStateGetter @@ -625,7 +623,7 @@ func (vm *LegacyVM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *ty // Check to see if we should burn funds. We avoid burning on successful // window post. This won't catch _indirect_ window post calls, but this // is the best we can get for now. - if vm.blockHeight > build.UpgradeClausHeight && errcode == exitcode.Ok && msg.Method == miner.Methods.SubmitWindowedPoSt { + if vm.blockHeight > build.UpgradeClausHeight && errcode == exitcode.Ok && msg.Method == builtin_types.MethodsMiner.SubmitWindowedPoSt { // Ok, we've checked the _method_, but we still need to check // the target actor. It would be nice if we could just look at // the trace, but I'm not sure if that's safe? diff --git a/chain/vm/vmi.go b/chain/vm/vmi.go index 9ffd8d830..faef55074 100644 --- a/chain/vm/vmi.go +++ b/chain/vm/vmi.go @@ -4,6 +4,7 @@ import ( "context" "os" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" ) @@ -18,8 +19,15 @@ type Interface interface { Flush(ctx context.Context) (cid.Cid, error) } +var useFvmForMainnetV15 = os.Getenv("LOTUS_USE_FVM_TO_SYNC_MAINNET_V15") == "1" + func NewVM(ctx context.Context, opts *VMOpts) (Interface, error) { - if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" { + if opts.NetworkVersion >= network.Version16 { + return NewFVM(ctx, opts) + } + + // Remove after v16 upgrade, this is only to support testing and validation of the FVM + if useFvmForMainnetV15 && opts.NetworkVersion >= network.Version15 { return NewFVM(ctx, opts) } diff --git a/cli/client.go b/cli/client.go index 5df7664cf..6ad08a7e6 100644 --- a/cli/client.go +++ b/cli/client.go @@ -1654,7 +1654,7 @@ var clientQueryAskCmd = &cli.Command{ return xerrors.Errorf("failed to get peerID for miner: %w", err) } - if mi.PeerId == nil || *mi.PeerId == peer.ID("SETME") { + if mi.PeerId == nil || *mi.PeerId == ("SETME") { return fmt.Errorf("the miner hasn't initialized yet") } diff --git a/cli/filplus.go b/cli/filplus.go index b3a98d487..24657c6b5 100644 --- a/cli/filplus.go +++ b/cli/filplus.go @@ -6,7 +6,7 @@ import ( "encoding/hex" "fmt" - verifreg4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/verifreg" + verifregtypes "github.com/filecoin-project/go-state-types/builtin/v8/verifreg" "github.com/filecoin-project/go-state-types/big" @@ -96,7 +96,7 @@ var filplusVerifyClientCmd = &cli.Command{ } // TODO: This should be abstracted over actor versions - params, err := actors.SerializeParams(&verifreg4.AddVerifiedClientParams{Address: target, Allowance: allowance}) + params, err := actors.SerializeParams(&verifregtypes.AddVerifiedClientParams{Address: target, Allowance: allowance}) if err != nil { return err } @@ -361,14 +361,14 @@ var filplusSignRemoveDataCapProposal = &cli.Command{ } } - params := verifreg.RemoveDataCapProposal{ - RemovalProposalID: verifreg.RmDcProposalID{ProposalID: id}, + params := verifregtypes.RemoveDataCapProposal{ + RemovalProposalID: verifregtypes.RmDcProposalID{ProposalID: id}, DataCapAmount: allowanceToRemove, VerifiedClient: clientIdAddr, } paramBuf := new(bytes.Buffer) - paramBuf.WriteString(verifreg.SignatureDomainSeparation_RemoveDataCap) + paramBuf.WriteString(verifregtypes.SignatureDomainSeparation_RemoveDataCap) err = params.MarshalCBOR(paramBuf) if err != nil { return xerrors.Errorf("failed to marshall paramBuf: %w", err) diff --git a/cli/paych.go b/cli/paych.go index 92c1a13e3..7640eee01 100644 --- a/cli/paych.go +++ b/cli/paych.go @@ -10,13 +10,14 @@ import ( lapi "github.com/filecoin-project/lotus/api" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/lotus/paychmgr" "github.com/filecoin-project/go-address" "github.com/filecoin-project/lotus/build" "github.com/urfave/cli/v2" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + lpaych "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" ) @@ -416,7 +417,7 @@ var paychVoucherCheckCmd = &cli.Command{ return err } - sv, err := paych.DecodeSignedVoucher(cctx.Args().Get(1)) + sv, err := lpaych.DecodeSignedVoucher(cctx.Args().Get(1)) if err != nil { return err } @@ -452,7 +453,7 @@ var paychVoucherAddCmd = &cli.Command{ return err } - sv, err := paych.DecodeSignedVoucher(cctx.Args().Get(1)) + sv, err := lpaych.DecodeSignedVoucher(cctx.Args().Get(1)) if err != nil { return err } @@ -610,7 +611,7 @@ var paychVoucherSubmitCmd = &cli.Command{ return err } - sv, err := paych.DecodeSignedVoucher(cctx.Args().Get(1)) + sv, err := lpaych.DecodeSignedVoucher(cctx.Args().Get(1)) if err != nil { return err } diff --git a/cli/state.go b/cli/state.go index b1346d6cd..83df3fdde 100644 --- a/cli/state.go +++ b/cli/state.go @@ -15,8 +15,13 @@ import ( "sort" "strconv" "strings" + "text/tabwriter" "time" + "github.com/filecoin-project/go-state-types/network" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/chain/consensus/filcns" @@ -79,6 +84,7 @@ var StateCmd = &cli.Command{ StateExecTraceCmd, StateNtwkVersionCmd, StateMinerProvingDeadlineCmd, + StateSysActorCIDsCmd, }, } @@ -1875,3 +1881,62 @@ var StateNtwkVersionCmd = &cli.Command{ return nil }, } + +var StateSysActorCIDsCmd = &cli.Command{ + Name: "actor-cids", + Usage: "Returns the built-in actor bundle manifest ID & system actor cids", + Flags: []cli.Flag{ + &cli.UintFlag{ + Name: "network-version", + Usage: "specify network version", + Value: uint(build.NewestNetworkVersion), + }, + }, + Action: func(cctx *cli.Context) error { + if cctx.Args().Present() { + return ShowHelp(cctx, fmt.Errorf("doesn't expect any arguments")) + } + + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + + ctx := ReqContext(cctx) + + ts, err := LoadTipSet(ctx, cctx, api) + if err != nil { + return err + } + + nv, err := api.StateNetworkVersion(ctx, ts.Key()) + if err != nil { + return err + } + + if cctx.IsSet("network-version") { + nv = network.Version(cctx.Uint64("network-version")) + } + + fmt.Printf("Network Version: %d\n", nv) + + actorVersion, err := actors.VersionForNetwork(nv) + if err != nil { + return err + } + fmt.Printf("Actor Version: %d\n", actorVersion) + + tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) + _, _ = fmt.Fprintln(tw, "\nActor\tCID\t") + + actorsCids, err := api.StateActorCodeCIDs(ctx, nv) + if err != nil { + return err + } + for name, cid := range actorsCids { + _, _ = fmt.Fprintf(tw, "%v\t%v\n", name, cid) + } + return tw.Flush() + }, +} diff --git a/cmd/lotus-bench/caching_verifier.go b/cmd/lotus-bench/caching_verifier.go index 0fddf515d..8cb0f7211 100644 --- a/cmd/lotus-bench/caching_verifier.go +++ b/cmd/lotus-bench/caching_verifier.go @@ -5,11 +5,10 @@ import ( "context" "errors" - proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" - "github.com/filecoin-project/go-state-types/abi" + prooftypes "github.com/filecoin-project/go-state-types/proof" + "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" "github.com/ipfs/go-datastore" "github.com/minio/blake2b-simd" cbg "github.com/whyrusleeping/cbor-gen" @@ -80,17 +79,17 @@ func (cv cachingVerifier) withCache(execute func() (bool, error), param cbg.CBOR } } -func (cv *cachingVerifier) VerifySeal(svi proof2.SealVerifyInfo) (bool, error) { +func (cv *cachingVerifier) VerifySeal(svi prooftypes.SealVerifyInfo) (bool, error) { return cv.withCache(func() (bool, error) { return cv.backend.VerifySeal(svi) }, &svi) } -func (cv *cachingVerifier) VerifyWinningPoSt(ctx context.Context, info proof7.WinningPoStVerifyInfo) (bool, error) { +func (cv *cachingVerifier) VerifyWinningPoSt(ctx context.Context, info prooftypes.WinningPoStVerifyInfo) (bool, error) { return cv.backend.VerifyWinningPoSt(ctx, info) } -func (cv *cachingVerifier) VerifyWindowPoSt(ctx context.Context, info proof2.WindowPoStVerifyInfo) (bool, error) { +func (cv *cachingVerifier) VerifyWindowPoSt(ctx context.Context, info prooftypes.WindowPoStVerifyInfo) (bool, error) { return cv.withCache(func() (bool, error) { return cv.backend.VerifyWindowPoSt(ctx, info) }, &info) @@ -99,11 +98,11 @@ func (cv *cachingVerifier) GenerateWinningPoStSectorChallenge(ctx context.Contex return cv.backend.GenerateWinningPoStSectorChallenge(ctx, proofType, a, rnd, u) } -func (cv cachingVerifier) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) (bool, error) { +func (cv cachingVerifier) VerifyAggregateSeals(aggregate prooftypes.AggregateSealVerifyProofAndInfos) (bool, error) { return cv.backend.VerifyAggregateSeals(aggregate) } -func (cv cachingVerifier) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) { +func (cv cachingVerifier) VerifyReplicaUpdate(update prooftypes.ReplicaUpdateInfo) (bool, error) { return cv.backend.VerifyReplicaUpdate(update) } diff --git a/cmd/lotus-bench/main.go b/cmd/lotus-bench/main.go index c6fdd5e32..0c9d9956a 100644 --- a/cmd/lotus-bench/main.go +++ b/cmd/lotus-bench/main.go @@ -11,9 +11,7 @@ import ( "path/filepath" "time" - saproof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" - "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" - saproof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" + prooftypes "github.com/filecoin-project/go-state-types/proof" "github.com/docker/go-units" logging "github.com/ipfs/go-log/v2" @@ -262,8 +260,8 @@ var sealBenchCmd = &cli.Command{ sectorNumber := c.Int("num-sectors") var sealTimings []SealingResult - var extendedSealedSectors []saproof7.ExtendedSectorInfo - var sealedSectors []saproof7.SectorInfo + var extendedSealedSectors []prooftypes.ExtendedSectorInfo + var sealedSectors []prooftypes.SectorInfo if robench == "" { var err error @@ -277,7 +275,7 @@ var sealBenchCmd = &cli.Command{ return xerrors.Errorf("failed to run seals: %w", err) } for _, s := range extendedSealedSectors { - sealedSectors = append(sealedSectors, proof.SectorInfo{ + sealedSectors = append(sealedSectors, prooftypes.SectorInfo{ SealedCID: s.SealedCID, SectorNumber: s.SectorNumber, SealProof: s.SealProof, @@ -306,13 +304,13 @@ var sealBenchCmd = &cli.Command{ } for _, s := range genm.Sectors { - extendedSealedSectors = append(extendedSealedSectors, saproof7.ExtendedSectorInfo{ + extendedSealedSectors = append(extendedSealedSectors, prooftypes.ExtendedSectorInfo{ SealedCID: s.CommR, SectorNumber: s.SectorID, SealProof: s.ProofType, SectorKey: nil, }) - sealedSectors = append(sealedSectors, proof.SectorInfo{ + sealedSectors = append(sealedSectors, prooftypes.SectorInfo{ SealedCID: s.CommR, SectorNumber: s.SectorID, SealProof: s.ProofType, @@ -346,7 +344,7 @@ var sealBenchCmd = &cli.Command{ return err } - xcandidates := make([]saproof7.ExtendedSectorInfo, len(fcandidates)) + xcandidates := make([]prooftypes.ExtendedSectorInfo, len(fcandidates)) for i, fcandidate := range fcandidates { xcandidates[i] = extendedSealedSectors[fcandidate] } @@ -367,9 +365,9 @@ var sealBenchCmd = &cli.Command{ return err } - candidates := make([]saproof7.SectorInfo, len(xcandidates)) + candidates := make([]prooftypes.SectorInfo, len(xcandidates)) for i, xsi := range xcandidates { - candidates[i] = saproof7.SectorInfo{ + candidates[i] = prooftypes.SectorInfo{ SealedCID: xsi.SealedCID, SectorNumber: xsi.SectorNumber, SealProof: xsi.SealProof, @@ -378,7 +376,7 @@ var sealBenchCmd = &cli.Command{ winnningpost2 := time.Now() - pvi1 := saproof7.WinningPoStVerifyInfo{ + pvi1 := prooftypes.WinningPoStVerifyInfo{ Randomness: abi.PoStRandomness(challenge[:]), Proofs: proof1, ChallengedSectors: candidates, @@ -394,7 +392,7 @@ var sealBenchCmd = &cli.Command{ verifyWinningPost1 := time.Now() - pvi2 := saproof7.WinningPoStVerifyInfo{ + pvi2 := prooftypes.WinningPoStVerifyInfo{ Randomness: abi.PoStRandomness(challenge[:]), Proofs: proof2, ChallengedSectors: candidates, @@ -426,7 +424,7 @@ var sealBenchCmd = &cli.Command{ windowpost2 := time.Now() - wpvi1 := saproof2.WindowPoStVerifyInfo{ + wpvi1 := prooftypes.WindowPoStVerifyInfo{ Randomness: challenge[:], Proofs: wproof1, ChallengedSectors: sealedSectors, @@ -442,7 +440,7 @@ var sealBenchCmd = &cli.Command{ verifyWindowpost1 := time.Now() - wpvi2 := saproof2.WindowPoStVerifyInfo{ + wpvi2 := prooftypes.WindowPoStVerifyInfo{ Randomness: challenge[:], Proofs: wproof2, ChallengedSectors: sealedSectors, @@ -527,10 +525,10 @@ type ParCfg struct { Commit int } -func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par ParCfg, mid abi.ActorID, sectorSize abi.SectorSize, ticketPreimage []byte, saveC2inp string, skipc2, skipunseal bool) ([]SealingResult, []saproof7.ExtendedSectorInfo, error) { +func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par ParCfg, mid abi.ActorID, sectorSize abi.SectorSize, ticketPreimage []byte, saveC2inp string, skipc2, skipunseal bool) ([]SealingResult, []prooftypes.ExtendedSectorInfo, error) { var pieces []abi.PieceInfo sealTimings := make([]SealingResult, numSectors) - sealedSectors := make([]saproof7.ExtendedSectorInfo, numSectors) + sealedSectors := make([]prooftypes.ExtendedSectorInfo, numSectors) preCommit2Sema := make(chan struct{}, par.PreCommit2) commitSema := make(chan struct{}, par.Commit) @@ -604,7 +602,7 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par precommit2 := time.Now() <-preCommit2Sema - sealedSectors[i] = saproof7.ExtendedSectorInfo{ + sealedSectors[i] = prooftypes.ExtendedSectorInfo{ SealProof: sid.ProofType, SectorNumber: i, SealedCID: cids.Sealed, @@ -657,7 +655,7 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, par <-commitSema if !skipc2 { - svi := saproof2.SealVerifyInfo{ + svi := prooftypes.SealVerifyInfo{ SectorID: abi.SectorID{Miner: mid, Number: i}, SealedCID: cids.Sealed, SealProof: sid.ProofType, diff --git a/cmd/lotus-miner/actor.go b/cmd/lotus-miner/actor.go index 01440a09e..a6d047e37 100644 --- a/cmd/lotus-miner/actor.go +++ b/cmd/lotus-miner/actor.go @@ -6,6 +6,10 @@ import ( "os" "strings" + "github.com/filecoin-project/lotus/api" + + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/go-state-types/network" rlepluslazy "github.com/filecoin-project/go-bitfield/rle" @@ -22,13 +26,12 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/tablewriter" @@ -117,7 +120,7 @@ var actorSetAddrsCmd = &cli.Command{ return err } - params, err := actors.SerializeParams(&miner2.ChangeMultiaddrsParams{NewMultiaddrs: addrs}) + params, err := actors.SerializeParams(&miner.ChangeMultiaddrsParams{NewMultiaddrs: addrs}) if err != nil { return err } @@ -129,7 +132,7 @@ var actorSetAddrsCmd = &cli.Command{ From: minfo.Worker, Value: types.NewInt(0), GasLimit: gasLimit, - Method: miner.Methods.ChangeMultiaddrs, + Method: builtin.MethodsMiner.ChangeMultiaddrs, Params: params, }, nil) if err != nil { @@ -182,7 +185,7 @@ var actorSetPeeridCmd = &cli.Command{ return err } - params, err := actors.SerializeParams(&miner2.ChangePeerIDParams{NewID: abi.PeerID(pid)}) + params, err := actors.SerializeParams(&miner.ChangePeerIDParams{NewID: abi.PeerID(pid)}) if err != nil { return err } @@ -194,7 +197,7 @@ var actorSetPeeridCmd = &cli.Command{ From: minfo.Worker, Value: types.NewInt(0), GasLimit: gasLimit, - Method: miner.Methods.ChangePeerID, + Method: builtin.MethodsMiner.ChangePeerID, Params: params, }, nil) if err != nil { @@ -262,7 +265,7 @@ var actorWithdrawCmd = &cli.Command{ } } - params, err := actors.SerializeParams(&miner2.WithdrawBalanceParams{ + params, err := actors.SerializeParams(&miner.WithdrawBalanceParams{ AmountRequested: amount, // Default to attempting to withdraw all the extra funds in the miner actor }) if err != nil { @@ -273,7 +276,7 @@ var actorWithdrawCmd = &cli.Command{ To: maddr, From: mi.Owner, Value: types.NewInt(0), - Method: miner.Methods.WithdrawBalance, + Method: builtin.MethodsMiner.WithdrawBalance, Params: params, }, nil) if err != nil { @@ -368,7 +371,7 @@ var actorRepayDebtCmd = &cli.Command{ store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(api))) - mst, err := miner.Load(store, mact) + mst, err := lminer.Load(store, mact) if err != nil { return err } @@ -395,7 +398,7 @@ var actorRepayDebtCmd = &cli.Command{ return err } - if !mi.IsController(fromId) { + if !isController(mi, fromId) { return xerrors.Errorf("sender isn't a controller of miner: %s", fromId) } @@ -403,7 +406,7 @@ var actorRepayDebtCmd = &cli.Command{ To: maddr, From: fromId, Value: amount, - Method: miner.Methods.RepayDebt, + Method: builtin.MethodsMiner.RepayDebt, Params: nil, }, nil) if err != nil { @@ -682,7 +685,7 @@ var actorControlSet = &cli.Command{ return nil } - cwp := &miner2.ChangeWorkerAddressParams{ + cwp := &miner.ChangeWorkerAddressParams{ NewWorker: mi.Worker, NewControlAddrs: toSet, } @@ -695,7 +698,7 @@ var actorControlSet = &cli.Command{ smsg, err := api.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, - Method: miner.Methods.ChangeWorkerAddress, + Method: builtin.MethodsMiner.ChangeWorkerAddress, Value: big.Zero(), Params: sp, @@ -781,7 +784,7 @@ var actorSetOwnerCmd = &cli.Command{ smsg, err := api.MpoolPushMessage(ctx, &types.Message{ From: fromAddrId, To: maddr, - Method: miner.Methods.ChangeOwnerAddress, + Method: builtin.MethodsMiner.ChangeOwnerAddress, Value: big.Zero(), Params: sp, }, nil) @@ -874,7 +877,7 @@ var actorProposeChangeWorker = &cli.Command{ return nil } - cwp := &miner2.ChangeWorkerAddressParams{ + cwp := &miner.ChangeWorkerAddressParams{ NewWorker: newAddr, NewControlAddrs: mi.ControlAddresses, } @@ -887,7 +890,7 @@ var actorProposeChangeWorker = &cli.Command{ smsg, err := api.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, - Method: miner.Methods.ChangeWorkerAddress, + Method: builtin.MethodsMiner.ChangeWorkerAddress, Value: big.Zero(), Params: sp, }, nil) @@ -994,7 +997,7 @@ var actorConfirmChangeWorker = &cli.Command{ smsg, err := api.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, - Method: miner.Methods.ConfirmUpdateWorkerKey, + Method: builtin.MethodsMiner.ConfirmUpdateWorkerKey, Value: big.Zero(), }, nil) if err != nil { @@ -1081,7 +1084,7 @@ var actorCompactAllocatedCmd = &cli.Command{ store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(api))) - mst, err := miner.Load(store, mact) + mst, err := lminer.Load(store, mact) if err != nil { return err } @@ -1140,7 +1143,7 @@ var actorCompactAllocatedCmd = &cli.Command{ return err } - params := &miner2.CompactSectorNumbersParams{ + params := &miner.CompactSectorNumbersParams{ MaskSectorNumbers: maskBf, } @@ -1152,7 +1155,7 @@ var actorCompactAllocatedCmd = &cli.Command{ smsg, err := api.MpoolPushMessage(ctx, &types.Message{ From: mi.Worker, To: maddr, - Method: miner.Methods.CompactSectorNumbers, + Method: builtin.MethodsMiner.CompactSectorNumbers, Value: big.Zero(), Params: sp, }, nil) @@ -1177,3 +1180,17 @@ var actorCompactAllocatedCmd = &cli.Command{ return nil }, } + +func isController(mi api.MinerInfo, 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 +} diff --git a/cmd/lotus-miner/allinfo_test.go b/cmd/lotus-miner/allinfo_test.go index f64a4ab72..9a5359213 100644 --- a/cmd/lotus-miner/allinfo_test.go +++ b/cmd/lotus-miner/allinfo_test.go @@ -12,7 +12,6 @@ import ( "github.com/urfave/cli/v2" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/node/repo" ) @@ -25,12 +24,6 @@ func TestMinerAllInfo(t *testing.T) { kit.QuietMiningLogs() - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - client, miner, ens := kit.EnsembleMinimal(t) ens.InterconnectAll().BeginMining(time.Second) diff --git a/cmd/lotus-miner/init.go b/cmd/lotus-miner/init.go index 7d81026f2..b2c71e18c 100644 --- a/cmd/lotus-miner/init.go +++ b/cmd/lotus-miner/init.go @@ -13,6 +13,9 @@ import ( "path/filepath" "strconv" + "github.com/filecoin-project/go-state-types/builtin" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" + power6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/power" "github.com/docker/go-units" @@ -36,7 +39,6 @@ import ( "github.com/filecoin-project/lotus/extern/sector-storage/stores" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power" @@ -391,7 +393,7 @@ func migratePreSealMeta(ctx context.Context, api v1api.FullNode, metadata string return mds.Put(ctx, datastore.NewKey(modules.StorageCounterDSPrefix), buf[:size]) } -func findMarketDealID(ctx context.Context, api v1api.FullNode, deal market2.DealProposal) (abi.DealID, error) { +func findMarketDealID(ctx context.Context, api v1api.FullNode, deal market8.DealProposal) (abi.DealID, error) { // TODO: find a better way // (this is only used by genesis miners) @@ -599,7 +601,7 @@ func configureStorageMiner(ctx context.Context, api v1api.FullNode, addr address msg := &types.Message{ To: addr, From: mi.Worker, - Method: miner.Methods.ChangePeerID, + Method: builtin.MethodsMiner.ChangePeerID, Params: enc, Value: types.NewInt(0), GasPremium: gasPrice, diff --git a/cmd/lotus-miner/init_restore.go b/cmd/lotus-miner/init_restore.go index 1aaa7909a..e5f8174de 100644 --- a/cmd/lotus-miner/init_restore.go +++ b/cmd/lotus-miner/init_restore.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/v0api" "github.com/docker/go-units" @@ -22,7 +23,6 @@ import ( lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/extern/sector-storage/stores" @@ -74,7 +74,7 @@ var restoreCmd = &cli.Command{ repoPath := cctx.String(FlagMinerRepo) - if err := restore(ctx, cctx, repoPath, storageCfg, nil, func(api lapi.FullNode, maddr address.Address, peerid peer.ID, mi miner.MinerInfo) error { + if err := restore(ctx, cctx, repoPath, storageCfg, nil, func(api lapi.FullNode, maddr address.Address, peerid peer.ID, mi api.MinerInfo) error { log.Info("Checking proof parameters") if err := paramfetch.GetParams(ctx, build.ParametersJSON(), build.SrsJSON(), uint64(mi.SectorSize)); err != nil { @@ -96,7 +96,7 @@ var restoreCmd = &cli.Command{ }, } -func restore(ctx context.Context, cctx *cli.Context, targetPath string, strConfig *stores.StorageConfig, manageConfig func(*config.StorageMiner) error, after func(api lapi.FullNode, addr address.Address, peerid peer.ID, mi miner.MinerInfo) error) error { +func restore(ctx context.Context, cctx *cli.Context, targetPath string, strConfig *stores.StorageConfig, manageConfig func(*config.StorageMiner) error, after func(api lapi.FullNode, addr address.Address, peerid peer.ID, mi api.MinerInfo) error) error { if cctx.Args().Len() != 1 { return xerrors.Errorf("expected 1 argument") } diff --git a/cmd/lotus-miner/init_service.go b/cmd/lotus-miner/init_service.go index 6e874023e..d0d0e3fa9 100644 --- a/cmd/lotus-miner/init_service.go +++ b/cmd/lotus-miner/init_service.go @@ -6,9 +6,9 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/api" lapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/client" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" lcli "github.com/filecoin-project/lotus/cli" cliutil "github.com/filecoin-project/lotus/cli/util" "github.com/filecoin-project/lotus/extern/sector-storage/stores" @@ -99,7 +99,7 @@ var serviceCmd = &cli.Command{ } return nil - }, func(api lapi.FullNode, maddr address.Address, peerid peer.ID, mi miner.MinerInfo) error { + }, func(api lapi.FullNode, maddr address.Address, peerid peer.ID, mi api.MinerInfo) error { if es.Contains(MarketsService) { log.Info("Configuring miner actor") diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index 1aa964f7e..b1951cd9b 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -20,14 +20,15 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/network" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/tablewriter" @@ -58,6 +59,7 @@ var sectorsCmd = &cli.Command{ sectorsCapacityCollateralCmd, sectorsBatching, sectorsRefreshPieceMatchingCmd, + sectorsCompactPartitionsCmd, }, } @@ -181,14 +183,14 @@ var sectorsStatusCmd = &cli.Command{ } tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(fullApi), blockstore.NewMemory()) - mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact) + mas, err := lminer.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact) if err != nil { return err } errFound := errors.New("found") - if err := mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error { - return dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error { + if err := mas.ForEachDeadline(func(dlIdx uint64, dl lminer.Deadline) error { + return dl.ForEachPartition(func(partIdx uint64, part lminer.Partition) error { pas, err := part.AllSectors() if err != nil { return err @@ -684,7 +686,7 @@ type PseudoExtendSectorExpirationParams struct { Extensions []PseudoExpirationExtension } -func NewPseudoExtendParams(p *miner5.ExtendSectorExpirationParams) (*PseudoExtendSectorExpirationParams, error) { +func NewPseudoExtendParams(p *miner.ExtendSectorExpirationParams) (*PseudoExtendSectorExpirationParams, error) { res := PseudoExtendSectorExpirationParams{} for _, ext := range p.Extensions { scount, err := ext.Sectors.Count() @@ -857,22 +859,22 @@ var sectorsRenewCmd = &cli.Command{ } tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(fullApi), blockstore.NewMemory()) - mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact) + mas, err := lminer.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact) if err != nil { return err } - activeSectorsLocation := make(map[abi.SectorNumber]*miner.SectorLocation, len(activeSet)) + activeSectorsLocation := make(map[abi.SectorNumber]*lminer.SectorLocation, len(activeSet)) - if err := mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error { - return dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error { + if err := mas.ForEachDeadline(func(dlIdx uint64, dl lminer.Deadline) error { + return dl.ForEachPartition(func(partIdx uint64, part lminer.Partition) error { pas, err := part.ActiveSectors() if err != nil { return err } return pas.ForEach(func(i uint64) error { - activeSectorsLocation[abi.SectorNumber(i)] = &miner.SectorLocation{ + activeSectorsLocation[abi.SectorNumber(i)] = &lminer.SectorLocation{ Deadline: dlIdx, Partition: partIdx, } @@ -937,7 +939,7 @@ var sectorsRenewCmd = &cli.Command{ } } - extensions := map[miner.SectorLocation]map[abi.ChainEpoch][]uint64{} + extensions := map[lminer.SectorLocation]map[abi.ChainEpoch][]uint64{} withinTolerance := func(a, b abi.ChainEpoch) bool { diff := a - b @@ -996,9 +998,9 @@ var sectorsRenewCmd = &cli.Command{ } } - var params []miner5.ExtendSectorExpirationParams + var params []miner.ExtendSectorExpirationParams - p := miner5.ExtendSectorExpirationParams{} + p := miner.ExtendSectorExpirationParams{} scount := 0 for l, exts := range extensions { @@ -1014,11 +1016,11 @@ var sectorsRenewCmd = &cli.Command{ } if scount > addrSectors || len(p.Extensions) == declMax { params = append(params, p) - p = miner5.ExtendSectorExpirationParams{} + p = miner.ExtendSectorExpirationParams{} scount = len(numbers) } - p.Extensions = append(p.Extensions, miner5.ExpirationExtension{ + p.Extensions = append(p.Extensions, miner.ExpirationExtension{ Deadline: l.Deadline, Partition: l.Partition, Sectors: bitfield.NewFromSet(numbers), @@ -1080,7 +1082,7 @@ var sectorsRenewCmd = &cli.Command{ smsg, err := fullApi.MpoolPushMessage(ctx, &types.Message{ From: mi.Worker, To: maddr, - Method: miner.Methods.ExtendSectorExpiration, + Method: builtin.MethodsMiner.ExtendSectorExpiration, Value: big.Zero(), Params: sp, }, spec) @@ -1146,7 +1148,7 @@ var sectorsExtendCmd = &cli.Command{ return err } - var params []miner5.ExtendSectorExpirationParams + var params []miner.ExtendSectorExpirationParams if cctx.Bool("v1-sectors") { @@ -1160,7 +1162,7 @@ var sectorsExtendCmd = &cli.Command{ return err } - extensions := map[miner.SectorLocation]map[abi.ChainEpoch][]uint64{} + extensions := map[lminer.SectorLocation]map[abi.ChainEpoch][]uint64{} // are given durations within tolerance epochs withinTolerance := func(a, b abi.ChainEpoch) bool { @@ -1199,7 +1201,7 @@ var sectorsExtendCmd = &cli.Command{ } // Set the new expiration to 48 hours less than the theoretical maximum lifetime - newExp := ml - (miner5.WPoStProvingPeriod * 2) + si.Activation + newExp := ml - (miner.WPoStProvingPeriod * 2) + si.Activation if withinTolerance(si.Expiration, newExp) || si.Expiration >= newExp { continue } @@ -1234,7 +1236,7 @@ var sectorsExtendCmd = &cli.Command{ } } - p := miner5.ExtendSectorExpirationParams{} + p := miner.ExtendSectorExpirationParams{} scount := 0 for l, exts := range extensions { @@ -1250,11 +1252,11 @@ var sectorsExtendCmd = &cli.Command{ } if scount > addressedMax || len(p.Extensions) == declMax { params = append(params, p) - p = miner5.ExtendSectorExpirationParams{} + p = miner.ExtendSectorExpirationParams{} scount = len(numbers) } - p.Extensions = append(p.Extensions, miner5.ExpirationExtension{ + p.Extensions = append(p.Extensions, miner.ExpirationExtension{ Deadline: l.Deadline, Partition: l.Partition, Sectors: bitfield.NewFromSet(numbers), @@ -1272,7 +1274,7 @@ var sectorsExtendCmd = &cli.Command{ if !cctx.Args().Present() || !cctx.IsSet("new-expiration") { return xerrors.Errorf("must pass at least one sector number and new expiration") } - sectors := map[miner.SectorLocation][]uint64{} + sectors := map[lminer.SectorLocation][]uint64{} for i, s := range cctx.Args().Slice() { id, err := strconv.ParseUint(s, 10, 64) @@ -1292,11 +1294,11 @@ var sectorsExtendCmd = &cli.Command{ sectors[*p] = append(sectors[*p], id) } - p := miner5.ExtendSectorExpirationParams{} + p := miner.ExtendSectorExpirationParams{} for l, numbers := range sectors { // TODO: Dedup with above loop - p.Extensions = append(p.Extensions, miner5.ExpirationExtension{ + p.Extensions = append(p.Extensions, miner.ExpirationExtension{ Deadline: l.Deadline, Partition: l.Partition, Sectors: bitfield.NewFromSet(numbers), @@ -1326,7 +1328,7 @@ var sectorsExtendCmd = &cli.Command{ smsg, err := api.MpoolPushMessage(ctx, &types.Message{ From: mi.Worker, To: maddr, - Method: miner.Methods.ExtendSectorExpiration, + Method: builtin.MethodsMiner.ExtendSectorExpiration, Value: big.Zero(), Params: sp, @@ -1648,7 +1650,7 @@ var sectorsCapacityCollateralCmd = &cli.Command{ return err } - spt, err := miner.PreferredSealProofTypeFromWindowPoStType(nv, mi.WindowPoStProofType) + spt, err := lminer.PreferredSealProofTypeFromWindowPoStType(nv, mi.WindowPoStProofType) if err != nil { return err } @@ -1817,7 +1819,7 @@ var sectorsExpiredCmd = &cli.Command{ } tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(fullApi), blockstore.NewMemory()) - mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact) + mas, err := lminer.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact) if err != nil { return err } @@ -1833,8 +1835,8 @@ var sectorsExpiredCmd = &cli.Command{ return xerrors.Errorf("intersecting bitfields: %w", err) } - if err := mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error { - return dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error { + if err := mas.ForEachDeadline(func(dlIdx uint64, dl lminer.Deadline) error { + return dl.ForEachPartition(func(partIdx uint64, part lminer.Partition) error { live, err := part.LiveSectors() if err != nil { return err @@ -2088,3 +2090,106 @@ func yesno(b bool) string { } return color.RedString("NO") } + +// TODO simulate this call if --really-do-it is not used +var sectorsCompactPartitionsCmd = &cli.Command{ + Name: "compact-partitions", + Usage: "removes dead sectors from partitions and reduces the number of partitions used if possible", + Flags: []cli.Flag{ + &cli.Uint64Flag{ + Name: "deadline", + Usage: "the deadline to compact the partitions in", + Required: true, + }, + &cli.Int64SliceFlag{ + Name: "partitions", + Usage: "list of partitions to compact sectors in", + Required: true, + }, + &cli.BoolFlag{ + Name: "really-do-it", + Usage: "Actually send transaction performing the action", + Value: false, + }, + &cli.StringFlag{ + Name: "actor", + Usage: "Specify the address of the miner to run this command", + }, + }, + Action: func(cctx *cli.Context) error { + if !cctx.Bool("really-do-it") { + fmt.Println("Pass --really-do-it to actually execute this action") + return nil + } + + api, acloser, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer acloser() + + ctx := lcli.ReqContext(cctx) + + maddr, err := getActorAddress(ctx, cctx) + if err != nil { + return err + } + + minfo, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK) + if err != nil { + return err + } + + deadline := cctx.Uint64("deadline") + if deadline > miner.WPoStPeriodDeadlines { + return fmt.Errorf("deadline %d out of range", deadline) + } + + parts := cctx.Int64Slice("partitions") + if len(parts) <= 0 { + return fmt.Errorf("must include at least one partition to compact") + } + fmt.Printf("compacting %d paritions\n", len(parts)) + + partitions := bitfield.New() + for _, partition := range parts { + partitions.Set(uint64(partition)) + } + + params := miner.CompactPartitionsParams{ + Deadline: deadline, + Partitions: partitions, + } + + sp, err := actors.SerializeParams(¶ms) + if err != nil { + return xerrors.Errorf("serializing params: %w", err) + } + + smsg, err := api.MpoolPushMessage(ctx, &types.Message{ + From: minfo.Worker, + To: maddr, + Method: builtin.MethodsMiner.CompactPartitions, + Value: big.Zero(), + Params: sp, + }, nil) + if err != nil { + return xerrors.Errorf("mpool push: %w", err) + } + + fmt.Printf("Requested compact partitions in message %s\n", smsg.Cid()) + + wait, err := api.StateWaitMsg(ctx, smsg.Cid(), 0) + if err != nil { + return err + } + + // check it executed successfully + if wait.Receipt.ExitCode != 0 { + fmt.Println(cctx.App.Writer, "compact partitions failed!") + return err + } + + return nil + }, +} diff --git a/cmd/lotus-pcr/main.go b/cmd/lotus-pcr/main.go index 469f5ad8e..46ba49834 100644 --- a/cmd/lotus-pcr/main.go +++ b/cmd/lotus-pcr/main.go @@ -16,7 +16,11 @@ import ( "strings" "time" - "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/go-state-types/builtin" + + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + + lbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin" lcli "github.com/filecoin-project/lotus/cli" miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" @@ -635,9 +639,9 @@ type refunderNodeApi interface { ChainGetParentReceipts(ctx context.Context, blockCid cid.Cid) ([]*types.MessageReceipt, error) ChainGetTipSetByHeight(ctx context.Context, epoch abi.ChainEpoch, tsk types.TipSetKey) (*types.TipSet, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error) - StateMinerInitialPledgeCollateral(ctx context.Context, addr address.Address, precommitInfo miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) - StateSectorPreCommitInfo(ctx context.Context, addr address.Address, sector abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) + StateMinerInitialPledgeCollateral(ctx context.Context, addr address.Address, precommitInfo minertypes.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) + StateSectorPreCommitInfo(ctx context.Context, addr address.Address, sector abi.SectorNumber, tsk types.TipSetKey) (minertypes.SectorPreCommitOnChainInfo, error) StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) StateMinerSectors(ctx context.Context, addr address.Address, filter *bitfield.BitField, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) StateMinerFaults(ctx context.Context, addr address.Address, tsk types.TipSetKey) (bitfield.BitField, error) @@ -937,7 +941,7 @@ func (r *refunder) processTipsetStorageMinerActor(ctx context.Context, tipset *t } switch m.Method { - case miner.Methods.SubmitWindowedPoSt: + case builtin.MethodsMiner.SubmitWindowedPoSt: if !r.windowedPoStEnabled { return false, messageMethod, types.NewInt(0), nil } @@ -950,7 +954,7 @@ func (r *refunder) processTipsetStorageMinerActor(ctx context.Context, tipset *t } refundValue = types.BigMul(types.NewInt(uint64(recp.GasUsed)), tipset.Blocks()[0].ParentBaseFee) - case miner.Methods.ProveCommitSector: + case builtin.MethodsMiner.ProveCommitSector: if !r.proveCommitEnabled { return false, messageMethod, types.NewInt(0), nil } @@ -1011,7 +1015,7 @@ func (r *refunder) processTipsetStorageMinerActor(ctx context.Context, tipset *t if r.refundPercent > 0 { refundValue = types.BigMul(types.BigDiv(refundValue, types.NewInt(100)), types.NewInt(uint64(r.refundPercent))) } - case miner.Methods.PreCommitSector: + case builtin.MethodsMiner.PreCommitSector: if !r.preCommitEnabled { return false, messageMethod, types.NewInt(0), nil } @@ -1033,7 +1037,7 @@ func (r *refunder) processTipsetStorageMinerActor(ctx context.Context, tipset *t return false, messageMethod, types.NewInt(0), nil } - var precommitInfo miner.SectorPreCommitInfo + var precommitInfo minertypes.SectorPreCommitInfo if err := precommitInfo.UnmarshalCBOR(bytes.NewBuffer(m.Params)); err != nil { log.Warnw("failed to decode precommit params", "err", err, "method", messageMethod, "cid", msg.Cid, "miner", m.To) return false, messageMethod, types.NewInt(0), nil @@ -1098,7 +1102,7 @@ func (r *refunder) ProcessTipset(ctx context.Context, tipset *types.TipSet, refu processed, messageMethod, refundValue, err = r.processTipsetStorageMarketActor(ctx, tipset, msg, recps[i]) } - if builtin.IsStorageMinerActor(a.Code) { + if lbuiltin.IsStorageMinerActor(a.Code) { processed, messageMethod, refundValue, err = r.processTipsetStorageMinerActor(ctx, tipset, msg, recps[i]) } diff --git a/cmd/lotus-seed/genesis.go b/cmd/lotus-seed/genesis.go index 89feec33a..27bf25466 100644 --- a/cmd/lotus-seed/genesis.go +++ b/cmd/lotus-seed/genesis.go @@ -59,7 +59,7 @@ var genesisNewCmd = &cli.Command{ return xerrors.New("seed genesis new [genesis.json]") } out := genesis.Template{ - NetworkVersion: build.NewestNetworkVersion, + NetworkVersion: build.GenesisNetworkVersion, Accounts: []genesis.Actor{}, Miners: []genesis.Miner{}, VerifregRootKey: gen.DefaultVerifregRootkeyActor, @@ -577,6 +577,7 @@ var genesisCarCmd = &cli.Command{ jrnl := journal.NilJournal() bstor := blockstore.WrapIDStore(blockstore.NewMemorySync()) sbldr := vm.Syscalls(ffiwrapper.ProofVerifier) + _, err := testing.MakeGenesis(ofile, c.Args().First())(bstor, sbldr, jrnl)() return err }, diff --git a/cmd/lotus-seed/main.go b/cmd/lotus-seed/main.go index 317f2965f..ce8b87df9 100644 --- a/cmd/lotus-seed/main.go +++ b/cmd/lotus-seed/main.go @@ -97,7 +97,7 @@ var preSealCmd = &cli.Command{ &cli.UintFlag{ Name: "network-version", Usage: "specify network version", - Value: uint(build.NewestNetworkVersion), + Value: uint(build.GenesisNetworkVersion), }, }, Action: func(c *cli.Context) error { @@ -134,7 +134,7 @@ var preSealCmd = &cli.Command{ } sectorSize := abi.SectorSize(sectorSizeInt) - nv := build.NewestNetworkVersion + nv := build.GenesisNetworkVersion if c.IsSet("network-version") { nv = network.Version(c.Uint64("network-version")) } diff --git a/cmd/lotus-seed/seed/seed.go b/cmd/lotus-seed/seed/seed.go index 3fbe66556..55411713e 100644 --- a/cmd/lotus-seed/seed/seed.go +++ b/cmd/lotus-seed/seed/seed.go @@ -24,7 +24,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-storage/storage" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/wallet" @@ -252,12 +252,17 @@ func WriteGenesisMiner(maddr address.Address, sbroot string, gm *genesis.Miner, func createDeals(m *genesis.Miner, k *wallet.Key, maddr address.Address, ssize abi.SectorSize) error { for i, sector := range m.Sectors { - proposal := &market2.DealProposal{ + label, err := market8.NewLabelFromString(fmt.Sprintf("%d", i)) + if err != nil { + return xerrors.Errorf("error creating deal label: %w", err) + } + + proposal := &market8.DealProposal{ PieceCID: sector.CommD, PieceSize: abi.PaddedPieceSize(ssize), Client: k.Address, Provider: maddr, - Label: fmt.Sprintf("%d", i), + Label: label, StartEpoch: 0, EndEpoch: 9001, StoragePricePerEpoch: big.Zero(), @@ -265,6 +270,7 @@ func createDeals(m *genesis.Miner, k *wallet.Key, maddr address.Address, ssize a ClientCollateral: big.Zero(), } + sector.DealClientKey = k sector.Deal = *proposal } diff --git a/cmd/lotus-shed/actor.go b/cmd/lotus-shed/actor.go index 7ddc79b18..4a63a1ac5 100644 --- a/cmd/lotus-shed/actor.go +++ b/cmd/lotus-shed/actor.go @@ -5,6 +5,7 @@ import ( "fmt" "os" + "github.com/filecoin-project/go-state-types/builtin" "github.com/filecoin-project/go-state-types/network" "github.com/fatih/color" @@ -20,7 +21,6 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/tablewriter" @@ -119,7 +119,7 @@ var actorWithdrawCmd = &cli.Command{ To: maddr, From: mi.Owner, Value: types.NewInt(0), - Method: miner.Methods.WithdrawBalance, + Method: builtin.MethodsMiner.WithdrawBalance, Params: params, }, &api.MessageSendSpec{MaxFee: abi.TokenAmount(types.MustParseFIL("0.1"))}) if err != nil { @@ -253,7 +253,7 @@ var actorSetOwnerCmd = &cli.Command{ smsg, err := nodeAPI.MpoolPushMessage(ctx, &types.Message{ From: fromAddrId, To: maddr, - Method: miner.Methods.ChangeOwnerAddress, + Method: builtin.MethodsMiner.ChangeOwnerAddress, Value: big.Zero(), Params: sp, }, nil) @@ -513,7 +513,7 @@ var actorControlSet = &cli.Command{ smsg, err := nodeAPI.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, - Method: miner.Methods.ChangeWorkerAddress, + Method: builtin.MethodsMiner.ChangeWorkerAddress, Value: big.Zero(), Params: sp, @@ -621,7 +621,7 @@ var actorProposeChangeWorker = &cli.Command{ smsg, err := nodeAPI.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, - Method: miner.Methods.ChangeWorkerAddress, + Method: builtin.MethodsMiner.ChangeWorkerAddress, Value: big.Zero(), Params: sp, }, nil) @@ -743,7 +743,7 @@ var actorConfirmChangeWorker = &cli.Command{ smsg, err := nodeAPI.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, - Method: miner.Methods.ConfirmUpdateWorkerKey, + Method: builtin.MethodsMiner.ConfirmUpdateWorkerKey, Value: big.Zero(), }, nil) if err != nil { diff --git a/cmd/lotus-shed/cid.go b/cmd/lotus-shed/cid.go index 09f3d6e6f..f98206a56 100644 --- a/cmd/lotus-shed/cid.go +++ b/cmd/lotus-shed/cid.go @@ -4,6 +4,10 @@ import ( "encoding/base64" "encoding/hex" "fmt" + "os" + + "github.com/filecoin-project/lotus/blockstore" + "github.com/ipld/go-car" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -17,6 +21,7 @@ var cidCmd = &cli.Command{ Usage: "Cid command", Subcommands: cli.Commands{ cidIdCmd, + cidFromCarCmd, }, } @@ -83,3 +88,31 @@ var cidIdCmd = &cli.Command{ return nil }, } + +var cidFromCarCmd = &cli.Command{ + Name: "manifest-cid-from-car", + Usage: "Get the manifest CID from a car file", + ArgsUsage: "[path]", + Action: func(cctx *cli.Context) error { + ctx := cctx.Context + + cf := cctx.Args().Get(0) + f, err := os.OpenFile(cf, os.O_RDONLY, 0664) + if err != nil { + return xerrors.Errorf("opening the car file: %w", err) + } + + bs := blockstore.NewMemory() + + hdr, err := car.LoadCar(ctx, bs, f) + if err != nil { + return xerrors.Errorf("error loading car file: %w", err) + } + + manifestCid := hdr.Roots[0] + + fmt.Printf("Manifest CID: %s\n", manifestCid.String()) + + return nil + }, +} diff --git a/cmd/lotus-shed/deal-label.go b/cmd/lotus-shed/deal-label.go index 483415987..6c222a4b8 100644 --- a/cmd/lotus-shed/deal-label.go +++ b/cmd/lotus-shed/deal-label.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "unicode/utf8" "github.com/filecoin-project/lotus/chain/actors/builtin/market" @@ -99,7 +98,7 @@ var dealLabelCmd = &cli.Command{ var deals []abi.DealID if err = ps.ForEach(func(id abi.DealID, dp market.DealProposal) error { - if !utf8.Valid([]byte(dp.Label)) { + if dp.Label.IsBytes() { deals = append(deals, id) } diff --git a/cmd/lotus-shed/market.go b/cmd/lotus-shed/market.go index aaef4690e..4cd018628 100644 --- a/cmd/lotus-shed/market.go +++ b/cmd/lotus-shed/market.go @@ -6,6 +6,8 @@ import ( "os" "path" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" + levelds "github.com/ipfs/go-ds-leveldb" ldbopts "github.com/syndtr/goleveldb/leveldb/opt" @@ -82,7 +84,7 @@ var marketDealFeesCmd = &cli.Command{ for _, deal := range deals { if deal.Proposal.Provider == p { - e, p := deal.Proposal.GetDealFees(ht) + e, p := market.GetDealFees(deal.Proposal, ht) ef = big.Add(ef, e) pf = big.Add(pf, p) count++ @@ -103,7 +105,7 @@ var marketDealFeesCmd = &cli.Command{ return err } - ef, pf := deal.Proposal.GetDealFees(ht) + ef, pf := market.GetDealFees(deal.Proposal, ht) fmt.Println("Earned fees: ", ef) fmt.Println("Pending fees: ", pf) diff --git a/cmd/lotus-shed/mempool-stats.go b/cmd/lotus-shed/mempool-stats.go index 597ba0393..5a98f6965 100644 --- a/cmd/lotus-shed/mempool-stats.go +++ b/cmd/lotus-shed/mempool-stats.go @@ -6,6 +6,9 @@ import ( "sort" "time" + "github.com/filecoin-project/go-state-types/builtin" + lbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin" + "contrib.go.opencensus.io/exporter/prometheus" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" @@ -16,8 +19,6 @@ import ( "github.com/filecoin-project/go-address" lapi "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" ) @@ -122,7 +123,7 @@ var mpoolStatsCmd = &cli.Command{ return false, err } - ism := builtin.IsStorageMinerActor(act.Code) + ism := lbuiltin.IsStorageMinerActor(act.Code) mcache[addr] = ism return ism, nil } @@ -144,7 +145,7 @@ var mpoolStatsCmd = &cli.Command{ seen: time.Now(), } - if u.Message.Message.Method == miner.Methods.SubmitWindowedPoSt { + if u.Message.Message.Method == builtin.MethodsMiner.SubmitWindowedPoSt { miner, err := isMiner(u.Message.Message.To) if err != nil { diff --git a/cmd/lotus-shed/miner-multisig.go b/cmd/lotus-shed/miner-multisig.go index 712e45ee7..dd36a7a7d 100644 --- a/cmd/lotus-shed/miner-multisig.go +++ b/cmd/lotus-shed/miner-multisig.go @@ -5,6 +5,8 @@ import ( "fmt" "strconv" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/abi" miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" @@ -16,7 +18,6 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" "github.com/urfave/cli/v2" @@ -88,7 +89,7 @@ var mmProposeWithdrawBalance = &cli.Command{ return err } - pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(miner.Methods.WithdrawBalance), sp) + pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(builtin.MethodsMiner.WithdrawBalance), sp) if err != nil { return xerrors.Errorf("proposing message: %w", err) } @@ -167,7 +168,7 @@ var mmApproveWithdrawBalance = &cli.Command{ return err } - acid, err := api.MsigApproveTxnHash(ctx, multisigAddr, txid, proposer, minerAddr, big.Zero(), sender, uint64(miner.Methods.WithdrawBalance), sp) + acid, err := api.MsigApproveTxnHash(ctx, multisigAddr, txid, proposer, minerAddr, big.Zero(), sender, uint64(builtin.MethodsMiner.WithdrawBalance), sp) if err != nil { return xerrors.Errorf("approving message: %w", err) } @@ -248,7 +249,7 @@ var mmProposeChangeOwner = &cli.Command{ return xerrors.Errorf("serializing params: %w", err) } - pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(miner.Methods.ChangeOwnerAddress), sp) + pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(builtin.MethodsMiner.ChangeOwnerAddress), sp) if err != nil { return xerrors.Errorf("proposing message: %w", err) } @@ -338,7 +339,7 @@ var mmApproveChangeOwner = &cli.Command{ return xerrors.Errorf("serializing params: %w", err) } - acid, err := api.MsigApproveTxnHash(ctx, multisigAddr, txid, proposer, minerAddr, big.Zero(), sender, uint64(miner.Methods.ChangeOwnerAddress), sp) + acid, err := api.MsigApproveTxnHash(ctx, multisigAddr, txid, proposer, minerAddr, big.Zero(), sender, uint64(builtin.MethodsMiner.ChangeOwnerAddress), sp) if err != nil { return xerrors.Errorf("approving message: %w", err) } @@ -435,7 +436,7 @@ var mmProposeChangeWorker = &cli.Command{ return xerrors.Errorf("serializing params: %w", err) } - pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(miner.Methods.ChangeWorkerAddress), sp) + pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(builtin.MethodsMiner.ChangeWorkerAddress), sp) if err != nil { return xerrors.Errorf("proposing message: %w", err) } @@ -519,7 +520,7 @@ var mmConfirmChangeWorker = &cli.Command{ return xerrors.Errorf("worker key change cannot be confirmed until %d, current height is %d", mi.WorkerChangeEpoch, head.Height()) } - pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(miner.Methods.ConfirmUpdateWorkerKey), nil) + pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(builtin.MethodsMiner.ConfirmUpdateWorkerKey), nil) if err != nil { return xerrors.Errorf("proposing message: %w", err) } @@ -634,7 +635,7 @@ var mmProposeControlSet = &cli.Command{ return xerrors.Errorf("serializing params: %w", err) } - pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(miner.Methods.ChangeWorkerAddress), sp) + pcid, err := api.MsigPropose(ctx, multisigAddr, minerAddr, big.Zero(), sender, uint64(builtin.MethodsMiner.ChangeWorkerAddress), sp) if err != nil { return xerrors.Errorf("proposing message: %w", err) } diff --git a/cmd/lotus-shed/miner-peerid.go b/cmd/lotus-shed/miner-peerid.go index 3ccfb429b..5218bbe26 100644 --- a/cmd/lotus-shed/miner-peerid.go +++ b/cmd/lotus-shed/miner-peerid.go @@ -102,7 +102,7 @@ var minerPeeridCmd = &cli.Command{ return err } - if mi.PeerId != nil && *mi.PeerId == pid { + if mi.PeerId != nil && peer.ID(mi.PeerId) == pid { fmt.Println(addr) } } diff --git a/cmd/lotus-shed/miner.go b/cmd/lotus-shed/miner.go index c44b67d77..e961a4b30 100644 --- a/cmd/lotus-shed/miner.go +++ b/cmd/lotus-shed/miner.go @@ -9,15 +9,20 @@ import ( "path/filepath" "strings" - miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - - power6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/power" - - "github.com/docker/go-units" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" + "github.com/ipfs/go-cid" "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/big" + "github.com/filecoin-project/go-state-types/builtin" + miner8 "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-state-types/crypto" + power7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/power" + "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" + + "github.com/docker/go-units" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" @@ -37,6 +42,8 @@ var minerCmd = &cli.Command{ minerUnpackInfoCmd, minerCreateCmd, minerFaultsCmd, + sendInvalidWindowPoStCmd, + generateAndSendConsensusFaultCmd, }, } @@ -75,7 +82,7 @@ var minerFaultsCmd = &cli.Command{ return err } - faults, err := faultBf.All(miner2.SectorsMax) + faults, err := faultBf.All(abi.MaxSectorNumber) if err != nil { return err } @@ -216,7 +223,7 @@ var minerCreateCmd = &cli.Command{ return xerrors.Errorf("getting post proof type: %w", err) } - params, err := actors.SerializeParams(&power6.CreateMinerParams{ + params, err := actors.SerializeParams(&power7.CreateMinerParams{ Owner: owner, Worker: worker, WindowPoStProofType: spt, @@ -252,7 +259,7 @@ var minerCreateCmd = &cli.Command{ return xerrors.Errorf("create miner failed: exit code %d", mw.Receipt.ExitCode) } - var retval power6.CreateMinerReturn + var retval power7.CreateMinerReturn if err := retval.UnmarshalCBOR(bytes.NewReader(mw.Receipt.Return)); err != nil { return err } @@ -354,3 +361,226 @@ var minerUnpackInfoCmd = &cli.Command{ } }, } + +var sendInvalidWindowPoStCmd = &cli.Command{ + Name: "send-invalid-windowed-post", + Usage: "Sends an invalid windowed post for a specific deadline", + Description: `Note: This is meant for testing purposes and should NOT be used on mainnet or you will be slashed`, + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "really-do-it", + Usage: "Actually send transaction performing the action", + Value: false, + }, + &cli.Int64SliceFlag{ + Name: "partitions", + Usage: "list of partitions to submit invalid post for", + Required: true, + }, + &cli.StringFlag{ + Name: "actor", + Usage: "Specify the address of the miner to run this command", + }, + }, + Action: func(cctx *cli.Context) error { + if !cctx.Bool("really-do-it") { + return xerrors.Errorf("Pass --really-do-it to actually execute this action") + } + + api, acloser, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return xerrors.Errorf("getting api: %w", err) + } + defer acloser() + + ctx := lcli.ReqContext(cctx) + + maddr, err := address.NewFromString(cctx.String("actor")) + if err != nil { + return xerrors.Errorf("getting actor address: %w", err) + } + + minfo, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK) + if err != nil { + return xerrors.Errorf("getting mienr info: %w", err) + } + + deadline, err := api.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK) + if err != nil { + return xerrors.Errorf("getting deadline: %w", err) + } + + partitionIndices := cctx.Int64Slice("partitions") + if len(partitionIndices) <= 0 { + return fmt.Errorf("must include at least one partition to compact") + } + + chainHead, err := api.ChainHead(ctx) + if err != nil { + return xerrors.Errorf("getting chain head: %w", err) + } + + checkRand, err := api.StateGetRandomnessFromTickets(ctx, crypto.DomainSeparationTag_PoStChainCommit, deadline.Challenge, nil, chainHead.Key()) + if err != nil { + return xerrors.Errorf("getting randomness: %w", err) + } + + proofSize, err := minfo.WindowPoStProofType.ProofSize() + if err != nil { + return xerrors.Errorf("getting proof size: %w", err) + } + + var partitions []miner8.PoStPartition + + emptyProof := []proof.PoStProof{{ + PoStProof: minfo.WindowPoStProofType, + ProofBytes: make([]byte, proofSize)}} + + for _, partition := range partitionIndices { + newPartition := miner8.PoStPartition{ + Index: uint64(partition), + Skipped: bitfield.New(), + } + partitions = append(partitions, newPartition) + } + + params := miner8.SubmitWindowedPoStParams{ + Deadline: deadline.Index, + Partitions: partitions, + Proofs: emptyProof, + ChainCommitEpoch: deadline.Challenge, + ChainCommitRand: checkRand, + } + + sp, err := actors.SerializeParams(¶ms) + if err != nil { + return xerrors.Errorf("serializing params: %w", err) + } + + fmt.Printf("submitting bad PoST for %d paritions\n", len(partitionIndices)) + smsg, err := api.MpoolPushMessage(ctx, &types.Message{ + From: minfo.Worker, + To: maddr, + Method: builtin.MethodsMiner.SubmitWindowedPoSt, + Value: big.Zero(), + Params: sp, + }, nil) + if err != nil { + return xerrors.Errorf("mpool push: %w", err) + } + + fmt.Printf("Invalid PoST in message %s\n", smsg.Cid()) + + wait, err := api.StateWaitMsg(ctx, smsg.Cid(), 0) + if err != nil { + return err + } + + // check it executed successfully + if wait.Receipt.ExitCode != 0 { + fmt.Println(cctx.App.Writer, "Invalid PoST message failed!") + return err + } + + return nil + }, +} + +var generateAndSendConsensusFaultCmd = &cli.Command{ + Name: "generate-and-send-consensus-fault", + Usage: "Provided a block CID mined by the miner, will create another block at the same height, and send both block headers to generate a consensus fault.", + Description: `Note: This is meant for testing purposes and should NOT be used on mainnet or you will be slashed`, + Action: func(cctx *cli.Context) error { + if cctx.NArg() != 1 { + return xerrors.Errorf("expected 1 arg (blockCID)") + } + + blockCid, err := cid.Parse(cctx.Args().First()) + if err != nil { + return xerrors.Errorf("getting first arg: %w", err) + } + + api, acloser, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return xerrors.Errorf("getting chain head: %w", err) + } + defer acloser() + + ctx := lcli.ReqContext(cctx) + + blockHeader, err := api.ChainGetBlock(ctx, blockCid) + if err != nil { + return xerrors.Errorf("getting block header: %w", err) + } + + maddr := blockHeader.Miner + + minfo, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK) + if err != nil { + return xerrors.Errorf("getting miner info: %w", err) + } + + // We are changing one field in the block header, then resigning the new block. + // This gives two different blocks signed by the same miner at the same height which will result in a consensus fault. + blockHeaderCopy := *blockHeader + blockHeaderCopy.ForkSignaling = blockHeader.ForkSignaling + 1 + + signingBytes, err := blockHeaderCopy.SigningBytes() + if err != nil { + return xerrors.Errorf("getting bytes to sign second block: %w", err) + } + + sig, err := api.WalletSign(ctx, minfo.Worker, signingBytes) + if err != nil { + return xerrors.Errorf("signing second block: %w", err) + } + blockHeaderCopy.BlockSig = sig + + buf1 := new(bytes.Buffer) + err = blockHeader.MarshalCBOR(buf1) + if err != nil { + return xerrors.Errorf("marshalling block header 1: %w", err) + } + buf2 := new(bytes.Buffer) + err = blockHeaderCopy.MarshalCBOR(buf2) + if err != nil { + return xerrors.Errorf("marshalling block header 2: %w", err) + } + + params := miner8.ReportConsensusFaultParams{ + BlockHeader1: buf1.Bytes(), + BlockHeader2: buf2.Bytes(), + } + + sp, err := actors.SerializeParams(¶ms) + if err != nil { + return xerrors.Errorf("serializing params: %w", err) + } + + smsg, err := api.MpoolPushMessage(ctx, &types.Message{ + From: minfo.Worker, + To: maddr, + Method: builtin.MethodsMiner.ReportConsensusFault, + Value: big.Zero(), + Params: sp, + }, nil) + if err != nil { + return xerrors.Errorf("mpool push: %w", err) + } + + fmt.Printf("Consensus fault reported in message %s\n", smsg.Cid()) + + wait, err := api.StateWaitMsg(ctx, smsg.Cid(), 0) + if err != nil { + return err + } + + // check it executed successfully + if wait.Receipt.ExitCode != 0 { + fmt.Println(cctx.App.Writer, "Report consensus fault failed!") + return err + } + + return nil + }, +} diff --git a/cmd/lotus-shed/proofs.go b/cmd/lotus-shed/proofs.go index e75aeed14..13fdf008a 100644 --- a/cmd/lotus-shed/proofs.go +++ b/cmd/lotus-shed/proofs.go @@ -4,7 +4,7 @@ import ( "encoding/hex" "fmt" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" + prooftypes "github.com/filecoin-project/go-state-types/proof" "github.com/urfave/cli/v2" @@ -84,7 +84,7 @@ var verifySealProofCmd = &cli.Command{ snum := abi.SectorNumber(cctx.Uint64("sector-id")) - ok, err := ffi.VerifySeal(proof2.SealVerifyInfo{ + ok, err := ffi.VerifySeal(prooftypes.SealVerifyInfo{ SectorID: abi.SectorID{ Miner: abi.ActorID(mid), Number: snum, @@ -93,8 +93,8 @@ var verifySealProofCmd = &cli.Command{ SealProof: abi.RegisteredSealProof(cctx.Int64("proof-type")), Proof: proof, DealIDs: nil, - Randomness: abi.SealRandomness(ticket), - InteractiveRandomness: abi.InteractiveSealRandomness(proofRand), + Randomness: ticket, + InteractiveRandomness: proofRand, UnsealedCID: commd, }) if err != nil { diff --git a/cmd/lotus-shed/sectors.go b/cmd/lotus-shed/sectors.go index 4894a6eea..91fa67d32 100644 --- a/cmd/lotus-shed/sectors.go +++ b/cmd/lotus-shed/sectors.go @@ -21,6 +21,7 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/builtin" "github.com/ipfs/go-cid" "github.com/urfave/cli/v2" @@ -28,7 +29,6 @@ import ( "github.com/filecoin-project/lotus/api/v0api" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" lcli "github.com/filecoin-project/lotus/cli" "github.com/filecoin-project/lotus/lib/parmap" @@ -141,7 +141,7 @@ var terminateSectorCmd = &cli.Command{ smsg, err := nodeApi.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: maddr, - Method: miner.Methods.TerminateSectors, + Method: builtin.MethodsMiner.TerminateSectors, Value: big.Zero(), Params: sp, @@ -262,7 +262,7 @@ var terminateSectorPenaltyEstimationCmd = &cli.Command{ msg := &types.Message{ From: mi.Owner, To: maddr, - Method: miner.Methods.TerminateSectors, + Method: builtin.MethodsMiner.TerminateSectors, Value: big.Zero(), Params: sp, diff --git a/cmd/lotus-shed/shedgen/cbor_gen.go b/cmd/lotus-shed/shedgen/cbor_gen.go index 37ed95539..a04d52c8e 100644 --- a/cmd/lotus-shed/shedgen/cbor_gen.go +++ b/cmd/lotus-shed/shedgen/cbor_gen.go @@ -23,18 +23,19 @@ func (t *CarbNode) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{161}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{161}); err != nil { return err } - scratch := make([]byte, 9) - // t.Sub ([]cid.Cid) (slice) if len("Sub") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Sub\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Sub"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Sub"))); err != nil { return err } if _, err := io.WriteString(w, string("Sub")); err != nil { @@ -45,27 +46,32 @@ func (t *CarbNode) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Sub was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Sub))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Sub))); err != nil { return err } for _, v := range t.Sub { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + if err := cbg.WriteCid(w, v); err != nil { return xerrors.Errorf("failed writing cid field t.Sub: %w", err) } } return nil } -func (t *CarbNode) UnmarshalCBOR(r io.Reader) error { +func (t *CarbNode) UnmarshalCBOR(r io.Reader) (err error) { *t = CarbNode{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -80,7 +86,7 @@ func (t *CarbNode) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -92,7 +98,7 @@ func (t *CarbNode) UnmarshalCBOR(r io.Reader) error { // t.Sub ([]cid.Cid) (slice) case "Sub": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -111,7 +117,7 @@ func (t *CarbNode) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("reading cid field t.Sub failed: %w", err) } diff --git a/cmd/lotus-shed/terminations.go b/cmd/lotus-shed/terminations.go index 0691f35da..357e7809e 100644 --- a/cmd/lotus-shed/terminations.go +++ b/cmd/lotus-shed/terminations.go @@ -7,7 +7,8 @@ import ( "io" "strconv" - "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/go-state-types/builtin" + lbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/chain/types" @@ -111,7 +112,7 @@ var terminationsCmd = &cli.Command{ for _, v := range msgs { msg := v.VMMessage() - if msg.Method != miner.Methods.TerminateSectors { + if msg.Method != builtin.MethodsMiner.TerminateSectors { continue } @@ -125,7 +126,7 @@ var terminationsCmd = &cli.Command{ return err } - if !builtin.IsStorageMinerActor(minerAct.Code) { + if !lbuiltin.IsStorageMinerActor(minerAct.Code) { continue } @@ -167,8 +168,16 @@ var terminationsCmd = &cli.Command{ if err != nil { return err } + label, err := prop.Label.ToString() + if err != nil { + labelBs, err := prop.Label.ToBytes() + if err != nil { + return err + } + label = string(labelBs) + } if find { - fmt.Printf("%s, %d, %d, %s, %s, %s\n", msg.To, sector.SectorNumber, deal, prop.Client, prop.PieceCID, prop.Label) + fmt.Printf("%s, %d, %d, %s, %s, %s\n", msg.To, sector.SectorNumber, deal, prop.Client, prop.PieceCID, label) } } } diff --git a/cmd/lotus-shed/verifreg.go b/cmd/lotus-shed/verifreg.go index fb2598fda..ebd6df407 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -4,6 +4,8 @@ import ( "encoding/hex" "fmt" + verifregtypes "github.com/filecoin-project/go-state-types/builtin/v8/verifreg" + "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" "github.com/filecoin-project/go-state-types/crypto" @@ -193,7 +195,7 @@ var verifRegVerifyClientCmd = &cli.Command{ }, }, Action: func(cctx *cli.Context) error { - fmt.Println("DEPRECATED: This behavior is being moved to `lotus verifreg`") + fmt.Println("DEPRECATED: This behavior is being moved to `lotus filplus`") froms := cctx.String("from") if froms == "" { return fmt.Errorf("must specify from address with --from") @@ -262,7 +264,7 @@ var verifRegListVerifiersCmd = &cli.Command{ Usage: "list all verifiers", Hidden: true, Action: func(cctx *cli.Context) error { - fmt.Println("DEPRECATED: This behavior is being moved to `lotus verifreg`") + fmt.Println("DEPRECATED: This behavior is being moved to `lotus filplus`") api, closer, err := lcli.GetFullNodeAPI(cctx) if err != nil { return err @@ -294,7 +296,7 @@ var verifRegListClientsCmd = &cli.Command{ Usage: "list all verified clients", Hidden: true, Action: func(cctx *cli.Context) error { - fmt.Println("DEPRECATED: This behavior is being moved to `lotus verifreg`") + fmt.Println("DEPRECATED: This behavior is being moved to `lotus filplus`") api, closer, err := lcli.GetFullNodeAPI(cctx) if err != nil { return err @@ -326,7 +328,7 @@ var verifRegCheckClientCmd = &cli.Command{ Usage: "check verified client remaining bytes", Hidden: true, Action: func(cctx *cli.Context) error { - fmt.Println("DEPRECATED: This behavior is being moved to `lotus verifreg`") + fmt.Println("DEPRECATED: This behavior is being moved to `lotus filplus`") if !cctx.Args().Present() { return fmt.Errorf("must specify client address to check") } @@ -362,7 +364,7 @@ var verifRegCheckVerifierCmd = &cli.Command{ Usage: "check verifiers remaining bytes", Hidden: true, Action: func(cctx *cli.Context) error { - fmt.Println("DEPRECATED: This behavior is being moved to `lotus verifreg`") + fmt.Println("DEPRECATED: This behavior is being moved to `lotus filplus`") if !cctx.Args().Present() { return fmt.Errorf("must specify verifier address to check") } @@ -479,14 +481,14 @@ var verifRegRemoveVerifiedClientDataCapCmd = &cli.Command{ return xerrors.Errorf("couldn't unmarshal sig: %w", err) } - params, err := actors.SerializeParams(&verifreg.RemoveDataCapParams{ + params, err := actors.SerializeParams(&verifregtypes.RemoveDataCapParams{ VerifiedClientToRemove: client, DataCapAmountToRemove: allowanceToRemove, - VerifierRequest1: verifreg.RemoveDataCapRequest{ + VerifierRequest1: verifregtypes.RemoveDataCapRequest{ Verifier: verifier1Addr, VerifierSignature: sig1, }, - VerifierRequest2: verifreg.RemoveDataCapRequest{ + VerifierRequest2: verifregtypes.RemoveDataCapRequest{ Verifier: verifier2Addr, VerifierSignature: sig2, }, diff --git a/cmd/lotus-sim/info_commit.go b/cmd/lotus-sim/info_commit.go index 7a0daa332..d58106f33 100644 --- a/cmd/lotus-sim/info_commit.go +++ b/cmd/lotus-sim/info_commit.go @@ -6,12 +6,14 @@ import ( "os" "syscall" + "github.com/filecoin-project/go-state-types/builtin" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/ipfs/go-cid" "github.com/koalacxr/quantile" "github.com/urfave/cli/v2" "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/cmd/lotus-sim/simulation" @@ -85,8 +87,8 @@ var infoCommitGasSimCommand = &cli.Command{ if m.ExitCode != exitcode.Ok { continue } - if m.Method == miner.Methods.ProveCommitAggregate { - param := miner.ProveCommitAggregateParams{} + if m.Method == builtin.MethodsMiner.ProveCommitAggregate { + param := minertypes.ProveCommitAggregateParams{} err := param.UnmarshalCBOR(bytes.NewReader(m.Params)) if err != nil { log("failed to decode params: %+v", err) @@ -109,7 +111,7 @@ var infoCommitGasSimCommand = &cli.Command{ hist.Observe(float64(c)) } - if m.Method == miner.Methods.ProveCommitSector { + if m.Method == builtin.MethodsMiner.ProveCommitSector { gasSingle += uint64(m.GasUsed) proofsSingle++ qua.Add(1) diff --git a/cmd/lotus-sim/info_wdpost.go b/cmd/lotus-sim/info_wdpost.go index 719a133b1..37383c4fc 100644 --- a/cmd/lotus-sim/info_wdpost.go +++ b/cmd/lotus-sim/info_wdpost.go @@ -3,13 +3,13 @@ package main import ( "fmt" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/ipfs/go-cid" "github.com/urfave/cli/v2" "github.com/filecoin-project/go-state-types/exitcode" - "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/stmgr" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/cmd/lotus-sim/simulation" @@ -48,7 +48,7 @@ var infoWindowPostBandwidthSimCommand = &cli.Command{ if m.ExitCode != exitcode.Ok { continue } - if m.Method == miner.Methods.SubmitWindowedPoSt { + if m.Method == builtin.MethodsMiner.SubmitWindowedPoSt { postGas += m.GasUsed } } diff --git a/cmd/lotus-sim/simulation/mock/mock.go b/cmd/lotus-sim/simulation/mock/mock.go index b1d36ba48..5479cbec7 100644 --- a/cmd/lotus-sim/simulation/mock/mock.go +++ b/cmd/lotus-sim/simulation/mock/mock.go @@ -6,7 +6,7 @@ import ( "encoding/binary" "fmt" - proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" + prooftypes "github.com/filecoin-project/go-state-types/proof" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" @@ -14,7 +14,6 @@ import ( logging "github.com/ipfs/go-log/v2" miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" tutils "github.com/filecoin-project/specs-actors/v5/support/testing" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" @@ -36,7 +35,7 @@ type mockVerifier struct{} var Verifier ffiwrapper.Verifier = mockVerifier{} -func (mockVerifier) VerifySeal(proof proof5.SealVerifyInfo) (bool, error) { +func (mockVerifier) VerifySeal(proof prooftypes.SealVerifyInfo) (bool, error) { addr, err := address.NewIDAddress(uint64(proof.Miner)) if err != nil { return false, err @@ -52,7 +51,7 @@ func (mockVerifier) VerifySeal(proof proof5.SealVerifyInfo) (bool, error) { return false, nil } -func (mockVerifier) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) (bool, error) { +func (mockVerifier) VerifyAggregateSeals(aggregate prooftypes.AggregateSealVerifyProofAndInfos) (bool, error) { addr, err := address.NewIDAddress(uint64(aggregate.Miner)) if err != nil { return false, err @@ -74,14 +73,14 @@ func (mockVerifier) VerifyAggregateSeals(aggregate proof5.AggregateSealVerifyPro } // TODO: do the thing -func (mockVerifier) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) { +func (mockVerifier) VerifyReplicaUpdate(update prooftypes.ReplicaUpdateInfo) (bool, error) { return false, nil } -func (mockVerifier) VerifyWinningPoSt(ctx context.Context, info proof7.WinningPoStVerifyInfo) (bool, error) { +func (mockVerifier) VerifyWinningPoSt(ctx context.Context, info prooftypes.WinningPoStVerifyInfo) (bool, error) { panic("should not be called") } -func (mockVerifier) VerifyWindowPoSt(ctx context.Context, info proof5.WindowPoStVerifyInfo) (bool, error) { +func (mockVerifier) VerifyWindowPoSt(ctx context.Context, info prooftypes.WindowPoStVerifyInfo) (bool, error) { if len(info.Proofs) != 1 { return false, fmt.Errorf("expected exactly one proof") } diff --git a/cmd/lotus-sim/simulation/stages/commit_queue.go b/cmd/lotus-sim/simulation/stages/commit_queue.go index d625dedb6..1c689c32e 100644 --- a/cmd/lotus-sim/simulation/stages/commit_queue.go +++ b/cmd/lotus-sim/simulation/stages/commit_queue.go @@ -3,10 +3,11 @@ package stages import ( "sort" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" ) @@ -166,7 +167,7 @@ func (q *commitQueue) advanceEpoch(epoch abi.ChainEpoch) { } // enquueProveCommit enqueues prove-commit for the given pre-commit for the given miner. -func (q *commitQueue) enqueueProveCommit(addr address.Address, preCommitEpoch abi.ChainEpoch, info miner.SectorPreCommitInfo) error { +func (q *commitQueue) enqueueProveCommit(addr address.Address, preCommitEpoch abi.ChainEpoch, info minertypes.SectorPreCommitInfo) error { // Compute the epoch at which we can start trying to commit. preCommitDelay := policy.GetPreCommitChallengeDelay() minCommitEpoch := preCommitEpoch + preCommitDelay + 1 diff --git a/cmd/lotus-sim/simulation/stages/commit_queue_test.go b/cmd/lotus-sim/simulation/stages/commit_queue_test.go index 503228d38..589f8b201 100644 --- a/cmd/lotus-sim/simulation/stages/commit_queue_test.go +++ b/cmd/lotus-sim/simulation/stages/commit_queue_test.go @@ -4,12 +4,13 @@ package stages import ( "testing" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/stretchr/testify/require" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" ) @@ -19,31 +20,31 @@ func TestCommitQueue(t *testing.T) { addr1, err := address.NewIDAddress(1000) require.NoError(t, err) proofType := abi.RegisteredSealProof_StackedDrg64GiBV1_1 - require.NoError(t, q.enqueueProveCommit(addr1, 0, miner.SectorPreCommitInfo{ + require.NoError(t, q.enqueueProveCommit(addr1, 0, minertypes.SectorPreCommitInfo{ SealProof: proofType, SectorNumber: 0, })) - require.NoError(t, q.enqueueProveCommit(addr1, 0, miner.SectorPreCommitInfo{ + require.NoError(t, q.enqueueProveCommit(addr1, 0, minertypes.SectorPreCommitInfo{ SealProof: proofType, SectorNumber: 1, })) - require.NoError(t, q.enqueueProveCommit(addr1, 1, miner.SectorPreCommitInfo{ + require.NoError(t, q.enqueueProveCommit(addr1, 1, minertypes.SectorPreCommitInfo{ SealProof: proofType, SectorNumber: 2, })) - require.NoError(t, q.enqueueProveCommit(addr1, 1, miner.SectorPreCommitInfo{ + require.NoError(t, q.enqueueProveCommit(addr1, 1, minertypes.SectorPreCommitInfo{ SealProof: proofType, SectorNumber: 3, })) - require.NoError(t, q.enqueueProveCommit(addr1, 3, miner.SectorPreCommitInfo{ + require.NoError(t, q.enqueueProveCommit(addr1, 3, minertypes.SectorPreCommitInfo{ SealProof: proofType, SectorNumber: 4, })) - require.NoError(t, q.enqueueProveCommit(addr1, 4, miner.SectorPreCommitInfo{ + require.NoError(t, q.enqueueProveCommit(addr1, 4, minertypes.SectorPreCommitInfo{ SealProof: proofType, SectorNumber: 5, })) - require.NoError(t, q.enqueueProveCommit(addr1, 6, miner.SectorPreCommitInfo{ + require.NoError(t, q.enqueueProveCommit(addr1, 6, minertypes.SectorPreCommitInfo{ SealProof: proofType, SectorNumber: 6, })) diff --git a/cmd/lotus-sim/simulation/stages/interface.go b/cmd/lotus-sim/simulation/stages/interface.go index 0c40a9b23..2e3d54722 100644 --- a/cmd/lotus-sim/simulation/stages/interface.go +++ b/cmd/lotus-sim/simulation/stages/interface.go @@ -3,10 +3,11 @@ package stages import ( "context" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/cmd/lotus-sim/simulation/blockbuilder" ) @@ -23,5 +24,5 @@ type Funding interface { } type Committer interface { - EnqueueProveCommit(addr address.Address, preCommitEpoch abi.ChainEpoch, info miner.SectorPreCommitInfo) error + EnqueueProveCommit(addr address.Address, preCommitEpoch abi.ChainEpoch, info minertypes.SectorPreCommitInfo) error } diff --git a/cmd/lotus-sim/simulation/stages/precommit_stage.go b/cmd/lotus-sim/simulation/stages/precommit_stage.go index 5b9fed09e..dc5c16d0b 100644 --- a/cmd/lotus-sim/simulation/stages/precommit_stage.go +++ b/cmd/lotus-sim/simulation/stages/precommit_stage.go @@ -5,6 +5,9 @@ import ( "sort" "time" + "github.com/filecoin-project/go-state-types/builtin" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -176,9 +179,9 @@ func (stage *PreCommitStage) packMiner( } expiration := epoch + policy.GetMaxSectorExpirationExtension() - infos := make([]miner.SectorPreCommitInfo, len(sectorNos)) + infos := make([]minertypes.SectorPreCommitInfo, len(sectorNos)) for i, sno := range sectorNos { - infos[i] = miner.SectorPreCommitInfo{ + infos[i] = minertypes.SectorPreCommitInfo{ SealProof: sealType, SectorNumber: sno, SealedCID: mock.MockCommR(minerAddr, sno), @@ -196,7 +199,7 @@ func (stage *PreCommitStage) packMiner( if len(batch) > targetBatchSize { batch = batch[:targetBatchSize] } - params := miner5.PreCommitSectorBatchParams{ + params := minertypes.PreCommitSectorBatchParams{ Sectors: batch, } enc, err := actors.SerializeParams(¶ms) @@ -209,7 +212,7 @@ func (stage *PreCommitStage) packMiner( To: minerAddr, From: minerInfo.Worker, Value: abi.NewTokenAmount(0), - Method: miner.Methods.PreCommitSectorBatch, + Method: builtin.MethodsMiner.PreCommitSectorBatch, Params: enc, }); blockbuilder.IsOutOfGas(err) { // try again with a smaller batch. @@ -244,7 +247,7 @@ func (stage *PreCommitStage) packMiner( To: minerAddr, From: minerInfo.Worker, Value: abi.NewTokenAmount(0), - Method: miner.Methods.PreCommitSector, + Method: builtin.MethodsMiner.PreCommitSector, Params: enc, }); blockbuilder.IsOutOfGas(err) { return added, true, nil diff --git a/cmd/lotus-sim/simulation/stages/provecommit_stage.go b/cmd/lotus-sim/simulation/stages/provecommit_stage.go index 8b12fc68a..a6c14f3d0 100644 --- a/cmd/lotus-sim/simulation/stages/provecommit_stage.go +++ b/cmd/lotus-sim/simulation/stages/provecommit_stage.go @@ -4,6 +4,9 @@ import ( "context" "time" + "github.com/filecoin-project/go-state-types/builtin" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" @@ -48,7 +51,7 @@ func (*ProveCommitStage) Name() string { } func (stage *ProveCommitStage) EnqueueProveCommit( - minerAddr address.Address, preCommitEpoch abi.ChainEpoch, info miner.SectorPreCommitInfo, + minerAddr address.Address, preCommitEpoch abi.ChainEpoch, info minertypes.SectorPreCommitInfo, ) error { return stage.commitQueue.enqueueProveCommit(minerAddr, preCommitEpoch, info) } @@ -161,7 +164,7 @@ func (stage *ProveCommitStage) packProveCommitsMiner( From: info.Worker, To: minerAddr, Value: abi.NewTokenAmount(0), - Method: miner.Methods.ProveCommitAggregate, + Method: builtin.MethodsMiner.ProveCommitAggregate, Params: enc, }); err == nil { res.done += len(batch) @@ -237,7 +240,7 @@ func (stage *ProveCommitStage) packProveCommitsMiner( if err != nil { return res, err } - params := miner.ProveCommitSectorParams{ + params := minertypes.ProveCommitSectorParams{ SectorNumber: sno, Proof: proof, } @@ -249,7 +252,7 @@ func (stage *ProveCommitStage) packProveCommitsMiner( From: info.Worker, To: minerAddr, Value: abi.NewTokenAmount(0), - Method: miner.Methods.ProveCommitSector, + Method: builtin.MethodsMiner.ProveCommitSector, Params: enc, }); err == nil { res.unbatched++ @@ -293,7 +296,7 @@ func (stage *ProveCommitStage) loadMiner(ctx context.Context, bb *blockbuilder.B // Find all pending prove commits and group by proof type. Really, there should never // (except during upgrades be more than one type. var total, dropped int - err = minerState.ForEachPrecommittedSector(func(info miner.SectorPreCommitOnChainInfo) error { + err = minerState.ForEachPrecommittedSector(func(info minertypes.SectorPreCommitOnChainInfo) error { total++ msd, err := policy.GetMaxProveCommitDuration(av, info.Info.SealProof) if err != nil { diff --git a/cmd/lotus-sim/simulation/stages/windowpost_stage.go b/cmd/lotus-sim/simulation/stages/windowpost_stage.go index 68f8ea179..98490b9ca 100644 --- a/cmd/lotus-sim/simulation/stages/windowpost_stage.go +++ b/cmd/lotus-sim/simulation/stages/windowpost_stage.go @@ -5,13 +5,16 @@ import ( "math" "time" + prooftypes "github.com/filecoin-project/go-state-types/proof" + + "github.com/filecoin-project/go-state-types/builtin" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "golang.org/x/xerrors" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" - "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/aerrors" "github.com/filecoin-project/lotus/chain/actors/builtin/miner" @@ -129,8 +132,8 @@ func (stage *WindowPoStStage) queueMiner( } var ( - partitions []miner.PoStPartition - partitionGroups [][]miner.PoStPartition + partitions []minertypes.PoStPartition + partitionGroups [][]minertypes.PoStPartition ) // Only prove partitions with live sectors. err = dl.ForEachPartition(func(idx uint64, part miner.Partition) error { @@ -160,7 +163,7 @@ func (stage *WindowPoStStage) queueMiner( return err } if liveCount-faultyCount > 0 { - partitions = append(partitions, miner.PoStPartition{Index: idx}) + partitions = append(partitions, minertypes.PoStPartition{Index: idx}) } return nil }) @@ -177,10 +180,10 @@ func (stage *WindowPoStStage) queueMiner( return err } for _, group := range partitionGroups { - params := miner.SubmitWindowedPoStParams{ + params := minertypes.SubmitWindowedPoStParams{ Deadline: di.Index, Partitions: group, - Proofs: []proof5.PoStProof{{ + Proofs: []prooftypes.PoStProof{{ PoStProof: minerInfo.WindowPoStProofType, ProofBytes: proof, }}, @@ -194,7 +197,7 @@ func (stage *WindowPoStStage) queueMiner( msg := &types.Message{ To: addr, From: minerInfo.Worker, - Method: miner.Methods.SubmitWindowedPoSt, + Method: builtin.MethodsMiner.SubmitWindowedPoSt, Params: enc, Value: types.NewInt(0), } @@ -216,7 +219,7 @@ func (stage *WindowPoStStage) load(ctx context.Context, bb *blockbuilder.BlockBu }() // reset - stage.wpostPeriods = make([][]address.Address, miner.WPoStChallengeWindow) + stage.wpostPeriods = make([][]address.Address, minertypes.WPoStChallengeWindow) stage.pendingWposts = nil stage.nextWpostEpoch = bb.Height() + 1 @@ -259,7 +262,7 @@ func (stage *WindowPoStStage) load(ctx context.Context, bb *blockbuilder.BlockBu } dinfo = dinfo.NextNotElapsed() - ppOffset := int(dinfo.PeriodStart % miner.WPoStChallengeWindow) + ppOffset := int(dinfo.PeriodStart % minertypes.WPoStChallengeWindow) stage.wpostPeriods[ppOffset] = append(stage.wpostPeriods[ppOffset], minerAddr) return stage.queueMiner(ctx, bb, minerAddr, minerState, commitEpoch, commitRand) @@ -290,7 +293,7 @@ func (stage *WindowPoStStage) tick(ctx context.Context, bb *blockbuilder.BlockBu // Perform a bit of catch up. This lets us do things like skip blocks at upgrades then catch // up to make the simulation easier. for ; stage.nextWpostEpoch <= targetHeight; stage.nextWpostEpoch++ { - if stage.nextWpostEpoch+miner.WPoStChallengeWindow < targetHeight { + if stage.nextWpostEpoch+minertypes.WPoStChallengeWindow < targetHeight { bb.L().Warnw("skipping old window post", "deadline-open", stage.nextWpostEpoch) continue } @@ -300,7 +303,7 @@ func (stage *WindowPoStStage) tick(ctx context.Context, bb *blockbuilder.BlockBu return err } - for _, addr := range stage.wpostPeriods[int(stage.nextWpostEpoch%miner.WPoStChallengeWindow)] { + for _, addr := range stage.wpostPeriods[int(stage.nextWpostEpoch%minertypes.WPoStChallengeWindow)] { minerState, err := loadMiner(store, st, addr) if err != nil { return err diff --git a/conformance/chaos/cbor_gen.go b/conformance/chaos/cbor_gen.go index d0d1ad627..436849cdc 100644 --- a/conformance/chaos/cbor_gen.go +++ b/conformance/chaos/cbor_gen.go @@ -28,18 +28,19 @@ func (t *State) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufState); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufState); err != nil { return err } - scratch := make([]byte, 9) - // t.Value (string) (string) if len(t.Value) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Value was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Value))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Value))); err != nil { return err } if _, err := io.WriteString(w, string(t.Value)); err != nil { @@ -51,27 +52,32 @@ func (t *State) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Unmarshallable was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Unmarshallable))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Unmarshallable))); err != nil { return err } for _, v := range t.Unmarshallable { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } return nil } -func (t *State) UnmarshalCBOR(r io.Reader) error { +func (t *State) UnmarshalCBOR(r io.Reader) (err error) { *t = State{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -83,7 +89,7 @@ func (t *State) UnmarshalCBOR(r io.Reader) error { // t.Value (string) (string) { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -92,7 +98,7 @@ func (t *State) UnmarshalCBOR(r io.Reader) error { } // t.Unmarshallable ([]*chaos.UnmarshallableCBOR) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -112,7 +118,7 @@ func (t *State) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v UnmarshallableCBOR - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -129,19 +135,20 @@ func (t *CallerValidationArgs) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufCallerValidationArgs); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufCallerValidationArgs); err != nil { return err } - scratch := make([]byte, 9) - // t.Branch (chaos.CallerValidationBranch) (int64) if t.Branch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Branch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Branch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Branch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Branch-1)); err != nil { return err } } @@ -151,11 +158,11 @@ func (t *CallerValidationArgs) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Addrs was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Addrs))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Addrs))); err != nil { return err } for _, v := range t.Addrs { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } @@ -165,27 +172,32 @@ func (t *CallerValidationArgs) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Types was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Types))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Types))); err != nil { return err } for _, v := range t.Types { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + if err := cbg.WriteCid(w, v); err != nil { return xerrors.Errorf("failed writing cid field t.Types: %w", err) } } return nil } -func (t *CallerValidationArgs) UnmarshalCBOR(r io.Reader) error { +func (t *CallerValidationArgs) UnmarshalCBOR(r io.Reader) (err error) { *t = CallerValidationArgs{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -196,7 +208,7 @@ func (t *CallerValidationArgs) UnmarshalCBOR(r io.Reader) error { // t.Branch (chaos.CallerValidationBranch) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -221,7 +233,7 @@ func (t *CallerValidationArgs) UnmarshalCBOR(r io.Reader) error { } // t.Addrs ([]address.Address) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -241,7 +253,7 @@ func (t *CallerValidationArgs) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v address.Address - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -250,7 +262,7 @@ func (t *CallerValidationArgs) UnmarshalCBOR(r io.Reader) error { // t.Types ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -269,7 +281,7 @@ func (t *CallerValidationArgs) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("reading cid field t.Types failed: %w", err) } @@ -286,12 +298,13 @@ func (t *CreateActorArgs) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufCreateActorArgs); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufCreateActorArgs); err != nil { return err } - scratch := make([]byte, 9) - // t.UndefActorCID (bool) (bool) if err := cbg.WriteBool(w, t.UndefActorCID); err != nil { return err @@ -299,7 +312,7 @@ func (t *CreateActorArgs) MarshalCBOR(w io.Writer) error { // t.ActorCID (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.ActorCID); err != nil { + if err := cbg.WriteCid(cw, t.ActorCID); err != nil { return xerrors.Errorf("failed to write cid field t.ActorCID: %w", err) } @@ -309,22 +322,27 @@ func (t *CreateActorArgs) MarshalCBOR(w io.Writer) error { } // t.Address (address.Address) (struct) - if err := t.Address.MarshalCBOR(w); err != nil { + if err := t.Address.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *CreateActorArgs) UnmarshalCBOR(r io.Reader) error { +func (t *CreateActorArgs) UnmarshalCBOR(r io.Reader) (err error) { *t = CreateActorArgs{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -335,7 +353,7 @@ func (t *CreateActorArgs) UnmarshalCBOR(r io.Reader) error { // t.UndefActorCID (bool) (bool) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -354,7 +372,7 @@ func (t *CreateActorArgs) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.ActorCID: %w", err) } @@ -364,7 +382,7 @@ func (t *CreateActorArgs) UnmarshalCBOR(r io.Reader) error { } // t.UndefAddress (bool) (bool) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -383,7 +401,7 @@ func (t *CreateActorArgs) UnmarshalCBOR(r io.Reader) error { { - if err := t.Address.UnmarshalCBOR(br); err != nil { + if err := t.Address.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Address: %w", err) } @@ -398,12 +416,15 @@ func (t *ResolveAddressResponse) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufResolveAddressResponse); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufResolveAddressResponse); err != nil { return err } // t.Address (address.Address) (struct) - if err := t.Address.MarshalCBOR(w); err != nil { + if err := t.Address.MarshalCBOR(cw); err != nil { return err } @@ -414,16 +435,21 @@ func (t *ResolveAddressResponse) MarshalCBOR(w io.Writer) error { return nil } -func (t *ResolveAddressResponse) UnmarshalCBOR(r io.Reader) error { +func (t *ResolveAddressResponse) UnmarshalCBOR(r io.Reader) (err error) { *t = ResolveAddressResponse{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -436,14 +462,14 @@ func (t *ResolveAddressResponse) UnmarshalCBOR(r io.Reader) error { { - if err := t.Address.UnmarshalCBOR(br); err != nil { + if err := t.Address.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Address: %w", err) } } // t.Success (bool) (bool) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -468,25 +494,26 @@ func (t *SendArgs) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufSendArgs); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufSendArgs); err != nil { return err } - scratch := make([]byte, 9) - // t.To (address.Address) (struct) - if err := t.To.MarshalCBOR(w); err != nil { + if err := t.To.MarshalCBOR(cw); err != nil { return err } // t.Value (big.Int) (struct) - if err := t.Value.MarshalCBOR(w); err != nil { + if err := t.Value.MarshalCBOR(cw); err != nil { return err } // t.Method (abi.MethodNum) (uint64) - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Method)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Method)); err != nil { return err } @@ -495,26 +522,31 @@ func (t *SendArgs) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Params was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Params))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Params))); err != nil { return err } - if _, err := w.Write(t.Params[:]); err != nil { + if _, err := cw.Write(t.Params[:]); err != nil { return err } return nil } -func (t *SendArgs) UnmarshalCBOR(r io.Reader) error { +func (t *SendArgs) UnmarshalCBOR(r io.Reader) (err error) { *t = SendArgs{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -527,7 +559,7 @@ func (t *SendArgs) UnmarshalCBOR(r io.Reader) error { { - if err := t.To.UnmarshalCBOR(br); err != nil { + if err := t.To.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.To: %w", err) } @@ -536,7 +568,7 @@ func (t *SendArgs) UnmarshalCBOR(r io.Reader) error { { - if err := t.Value.UnmarshalCBOR(br); err != nil { + if err := t.Value.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Value: %w", err) } @@ -545,7 +577,7 @@ func (t *SendArgs) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -557,7 +589,7 @@ func (t *SendArgs) UnmarshalCBOR(r io.Reader) error { } // t.Params ([]uint8) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -573,7 +605,7 @@ func (t *SendArgs) UnmarshalCBOR(r io.Reader) error { t.Params = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Params[:]); err != nil { + if _, err := io.ReadFull(cr, t.Params[:]); err != nil { return err } return nil @@ -586,48 +618,54 @@ func (t *SendReturn) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufSendReturn); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufSendReturn); err != nil { return err } - scratch := make([]byte, 9) - // t.Return (builtin.CBORBytes) (slice) if len(t.Return) > cbg.ByteArrayMaxLen { return xerrors.Errorf("Byte array in field t.Return was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Return))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Return))); err != nil { return err } - if _, err := w.Write(t.Return[:]); err != nil { + if _, err := cw.Write(t.Return[:]); err != nil { return err } // t.Code (exitcode.ExitCode) (int64) if t.Code >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Code)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Code)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Code-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Code-1)); err != nil { return err } } return nil } -func (t *SendReturn) UnmarshalCBOR(r io.Reader) error { +func (t *SendReturn) UnmarshalCBOR(r io.Reader) (err error) { *t = SendReturn{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -638,7 +676,7 @@ func (t *SendReturn) UnmarshalCBOR(r io.Reader) error { // t.Return (builtin.CBORBytes) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -654,12 +692,12 @@ func (t *SendReturn) UnmarshalCBOR(r io.Reader) error { t.Return = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Return[:]); err != nil { + if _, err := io.ReadFull(cr, t.Return[:]); err != nil { return err } // t.Code (exitcode.ExitCode) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -692,18 +730,19 @@ func (t *MutateStateArgs) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufMutateStateArgs); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufMutateStateArgs); err != nil { return err } - scratch := make([]byte, 9) - // t.Value (string) (string) if len(t.Value) > cbg.MaxLength { return xerrors.Errorf("Value in field t.Value was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Value))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Value))); err != nil { return err } if _, err := io.WriteString(w, string(t.Value)); err != nil { @@ -712,27 +751,32 @@ func (t *MutateStateArgs) MarshalCBOR(w io.Writer) error { // t.Branch (chaos.MutateStateBranch) (int64) if t.Branch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Branch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Branch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Branch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Branch-1)); err != nil { return err } } return nil } -func (t *MutateStateArgs) UnmarshalCBOR(r io.Reader) error { +func (t *MutateStateArgs) UnmarshalCBOR(r io.Reader) (err error) { *t = MutateStateArgs{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -744,7 +788,7 @@ func (t *MutateStateArgs) UnmarshalCBOR(r io.Reader) error { // t.Value (string) (string) { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -753,7 +797,7 @@ func (t *MutateStateArgs) UnmarshalCBOR(r io.Reader) error { } // t.Branch (chaos.MutateStateBranch) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -786,19 +830,20 @@ func (t *AbortWithArgs) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufAbortWithArgs); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufAbortWithArgs); err != nil { return err } - scratch := make([]byte, 9) - // t.Code (exitcode.ExitCode) (int64) if t.Code >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Code)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Code)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.Code-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.Code-1)); err != nil { return err } } @@ -808,7 +853,7 @@ func (t *AbortWithArgs) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Message was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Message))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Message))); err != nil { return err } if _, err := io.WriteString(w, string(t.Message)); err != nil { @@ -822,16 +867,21 @@ func (t *AbortWithArgs) MarshalCBOR(w io.Writer) error { return nil } -func (t *AbortWithArgs) UnmarshalCBOR(r io.Reader) error { +func (t *AbortWithArgs) UnmarshalCBOR(r io.Reader) (err error) { *t = AbortWithArgs{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -842,7 +892,7 @@ func (t *AbortWithArgs) UnmarshalCBOR(r io.Reader) error { // t.Code (exitcode.ExitCode) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -868,7 +918,7 @@ func (t *AbortWithArgs) UnmarshalCBOR(r io.Reader) error { // t.Message (string) (string) { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -877,7 +927,7 @@ func (t *AbortWithArgs) UnmarshalCBOR(r io.Reader) error { } // t.Uncontrolled (bool) (bool) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -902,60 +952,66 @@ func (t *InspectRuntimeReturn) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufInspectRuntimeReturn); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufInspectRuntimeReturn); err != nil { return err } - scratch := make([]byte, 9) - // t.Caller (address.Address) (struct) - if err := t.Caller.MarshalCBOR(w); err != nil { + if err := t.Caller.MarshalCBOR(cw); err != nil { return err } // t.Receiver (address.Address) (struct) - if err := t.Receiver.MarshalCBOR(w); err != nil { + if err := t.Receiver.MarshalCBOR(cw); err != nil { return err } // t.ValueReceived (big.Int) (struct) - if err := t.ValueReceived.MarshalCBOR(w); err != nil { + if err := t.ValueReceived.MarshalCBOR(cw); err != nil { return err } // t.CurrEpoch (abi.ChainEpoch) (int64) if t.CurrEpoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.CurrEpoch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.CurrEpoch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.CurrEpoch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.CurrEpoch-1)); err != nil { return err } } // t.CurrentBalance (big.Int) (struct) - if err := t.CurrentBalance.MarshalCBOR(w); err != nil { + if err := t.CurrentBalance.MarshalCBOR(cw); err != nil { return err } // t.State (chaos.State) (struct) - if err := t.State.MarshalCBOR(w); err != nil { + if err := t.State.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *InspectRuntimeReturn) UnmarshalCBOR(r io.Reader) error { +func (t *InspectRuntimeReturn) UnmarshalCBOR(r io.Reader) (err error) { *t = InspectRuntimeReturn{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -968,7 +1024,7 @@ func (t *InspectRuntimeReturn) UnmarshalCBOR(r io.Reader) error { { - if err := t.Caller.UnmarshalCBOR(br); err != nil { + if err := t.Caller.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Caller: %w", err) } @@ -977,7 +1033,7 @@ func (t *InspectRuntimeReturn) UnmarshalCBOR(r io.Reader) error { { - if err := t.Receiver.UnmarshalCBOR(br); err != nil { + if err := t.Receiver.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Receiver: %w", err) } @@ -986,14 +1042,14 @@ func (t *InspectRuntimeReturn) UnmarshalCBOR(r io.Reader) error { { - if err := t.ValueReceived.UnmarshalCBOR(br); err != nil { + if err := t.ValueReceived.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.ValueReceived: %w", err) } } // t.CurrEpoch (abi.ChainEpoch) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1020,7 +1076,7 @@ func (t *InspectRuntimeReturn) UnmarshalCBOR(r io.Reader) error { { - if err := t.CurrentBalance.UnmarshalCBOR(br); err != nil { + if err := t.CurrentBalance.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.CurrentBalance: %w", err) } @@ -1029,7 +1085,7 @@ func (t *InspectRuntimeReturn) UnmarshalCBOR(r io.Reader) error { { - if err := t.State.UnmarshalCBOR(br); err != nil { + if err := t.State.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.State: %w", err) } diff --git a/conformance/driver.go b/conformance/driver.go index f6ca9f9db..54ee40d5b 100644 --- a/conformance/driver.go +++ b/conformance/driver.go @@ -8,6 +8,7 @@ import ( "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/blockstore" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/consensus/filcns" "github.com/filecoin-project/lotus/chain/state" "github.com/filecoin-project/lotus/chain/stmgr" @@ -235,7 +236,8 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP // register the chaos actor if required by the vector. if chaosOn, ok := d.selector["chaos_actor"]; ok && chaosOn == "true" { - invoker.Register(nil, chaos.Actor{}) + av, _ := actors.VersionForNetwork(params.NetworkVersion) + invoker.Register(av, nil, chaos.Actor{}) } lvm.SetInvoker(invoker) diff --git a/documentation/en/api-v0-methods-miner.md b/documentation/en/api-v0-methods-miner.md index 7642efbee..4f1fe275c 100644 --- a/documentation/en/api-v0-methods-miner.md +++ b/documentation/en/api-v0-methods-miner.md @@ -406,7 +406,7 @@ Inputs: ], "Bw==", 10101, - 15 + 16 ] ``` @@ -732,7 +732,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -1183,7 +1183,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -1325,7 +1325,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -1360,7 +1360,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -1481,7 +1481,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -2766,7 +2766,7 @@ Inputs: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -3134,7 +3134,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", diff --git a/documentation/en/api-v0-methods.md b/documentation/en/api-v0-methods.md index 6f3e5c8ee..652bf3c47 100644 --- a/documentation/en/api-v0-methods.md +++ b/documentation/en/api-v0-methods.md @@ -29,6 +29,7 @@ * [ChainHasObj](#ChainHasObj) * [ChainHead](#ChainHead) * [ChainNotify](#ChainNotify) + * [ChainPutObj](#ChainPutObj) * [ChainReadObj](#ChainReadObj) * [ChainSetHead](#ChainSetHead) * [ChainStatObj](#ChainStatObj) @@ -157,6 +158,7 @@ * [PaychVoucherSubmit](#PaychVoucherSubmit) * [State](#State) * [StateAccountKey](#StateAccountKey) + * [StateActorCodeCIDs](#StateActorCodeCIDs) * [StateAllMinerFaults](#StateAllMinerFaults) * [StateCall](#StateCall) * [StateChangedActors](#StateChangedActors) @@ -971,6 +973,21 @@ Response: ] ``` +### ChainPutObj +ChainPutObj puts and object into the blockstore + + +Perms: + +Inputs: +```json +[ + {} +] +``` + +Response: `{}` + ### ChainReadObj ChainReadObj reads ipld nodes referenced by the specified CID from chain blockstore and returns raw bytes. @@ -4274,7 +4291,7 @@ Response: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4351,7 +4368,7 @@ Inputs: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4392,7 +4409,7 @@ Inputs: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4433,7 +4450,7 @@ Inputs: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4480,7 +4497,7 @@ Response: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4524,7 +4541,7 @@ Response: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4561,7 +4578,7 @@ Inputs: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4623,6 +4640,21 @@ Inputs: Response: `"f01234"` +### StateActorCodeCIDs +StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version + + +Perms: read + +Inputs: +```json +[ + 16 +] +``` + +Response: `{}` + ### StateAllMinerFaults StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset @@ -5491,7 +5523,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -5569,7 +5601,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -5624,6 +5656,8 @@ Response: "InitialPledge": "0", "ExpectedDayReward": "0", "ExpectedStoragePledge": "0", + "ReplacedSectorAge": 10101, + "ReplacedDayReward": "0", "SectorKeyCID": null } ] @@ -6087,6 +6121,8 @@ Response: "InitialPledge": "0", "ExpectedDayReward": "0", "ExpectedStoragePledge": "0", + "ReplacedSectorAge": 10101, + "ReplacedDayReward": "0", "SectorKeyCID": null } ] @@ -6122,7 +6158,7 @@ Inputs: ] ``` -Response: `15` +Response: `16` ### StateReadState StateReadState returns the indicated actor's state. @@ -6508,6 +6544,8 @@ Response: "InitialPledge": "0", "ExpectedDayReward": "0", "ExpectedStoragePledge": "0", + "ReplacedSectorAge": 10101, + "ReplacedDayReward": "0", "SectorKeyCID": null } ``` diff --git a/documentation/en/api-v1-unstable-methods.md b/documentation/en/api-v1-unstable-methods.md index b08c87348..9d8938f81 100644 --- a/documentation/en/api-v1-unstable-methods.md +++ b/documentation/en/api-v1-unstable-methods.md @@ -8,8 +8,6 @@ * [Auth](#Auth) * [AuthNew](#AuthNew) * [AuthVerify](#AuthVerify) -* [Beacon](#Beacon) - * [BeaconGetEntry](#BeaconGetEntry) * [Chain](#Chain) * [ChainBlockstoreInfo](#ChainBlockstoreInfo) * [ChainCheckBlockstore](#ChainCheckBlockstore) @@ -30,6 +28,7 @@ * [ChainHasObj](#ChainHasObj) * [ChainHead](#ChainHead) * [ChainNotify](#ChainNotify) + * [ChainPutObj](#ChainPutObj) * [ChainReadObj](#ChainReadObj) * [ChainSetHead](#ChainSetHead) * [ChainStatObj](#ChainStatObj) @@ -166,6 +165,7 @@ * [PaychVoucherSubmit](#PaychVoucherSubmit) * [State](#State) * [StateAccountKey](#StateAccountKey) + * [StateActorCodeCIDs](#StateActorCodeCIDs) * [StateAllMinerFaults](#StateAllMinerFaults) * [StateCall](#StateCall) * [StateChangedActors](#StateChangedActors) @@ -175,6 +175,7 @@ * [StateDecodeParams](#StateDecodeParams) * [StateEncodeParams](#StateEncodeParams) * [StateGetActor](#StateGetActor) + * [StateGetBeaconEntry](#StateGetBeaconEntry) * [StateGetNetworkParams](#StateGetNetworkParams) * [StateGetRandomnessFromBeacon](#StateGetRandomnessFromBeacon) * [StateGetRandomnessFromTickets](#StateGetRandomnessFromTickets) @@ -342,33 +343,6 @@ Response: ] ``` -## Beacon -The Beacon method group contains methods for interacting with the random beacon (DRAND) - - -### BeaconGetEntry -BeaconGetEntry returns the beacon entry for the given filecoin epoch. If -the entry has not yet been produced, the call will block until the entry -becomes available - - -Perms: read - -Inputs: -```json -[ - 10101 -] -``` - -Response: -```json -{ - "Round": 42, - "Data": "Ynl0ZSBhcnJheQ==" -} -``` - ## Chain The Chain method group contains methods for interacting with the blockchain, but that do not require any form of state computation. @@ -987,6 +961,21 @@ Response: ] ``` +### ChainPutObj +ChainPutObj puts a given object into the block store + + +Perms: admin + +Inputs: +```json +[ + {} +] +``` + +Response: `{}` + ### ChainReadObj ChainReadObj reads ipld nodes referenced by the specified CID from chain blockstore and returns raw bytes. @@ -4712,7 +4701,7 @@ Response: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4789,7 +4778,7 @@ Inputs: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4830,7 +4819,7 @@ Inputs: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4871,7 +4860,7 @@ Inputs: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4918,7 +4907,7 @@ Response: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4962,7 +4951,7 @@ Response: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -4999,7 +4988,7 @@ Inputs: "ChannelAddr": "f01234", "TimeLockMin": 10101, "TimeLockMax": 10101, - "SecretPreimage": "Ynl0ZSBhcnJheQ==", + "SecretHash": "Ynl0ZSBhcnJheQ==", "Extra": { "Actor": "f01234", "Method": 1, @@ -5061,6 +5050,21 @@ Inputs: Response: `"f01234"` +### StateActorCodeCIDs +StateActorCodeCIDs returns the CIDs of all the builtin actors for the given network version + + +Perms: read + +Inputs: +```json +[ + 16 +] +``` + +Response: `{}` + ### StateAllMinerFaults StateAllMinerFaults returns all non-expired Faults that occur within lookback epochs of the given tipset @@ -5643,6 +5647,29 @@ Response: } ``` +### StateGetBeaconEntry +StateGetBeaconEntry returns the beacon entry for the given filecoin epoch. If +the entry has not yet been produced, the call will block until the entry +becomes available + + +Perms: read + +Inputs: +```json +[ + 10101 +] +``` + +Response: +```json +{ + "Round": 42, + "Data": "Ynl0ZSBhcnJheQ==" +} +``` + ### StateGetNetworkParams StateGetNetworkParams return current network params @@ -5931,7 +5958,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -6009,7 +6036,7 @@ Response: "VerifiedDeal": true, "Client": "f01234", "Provider": "f01234", - "Label": "string value", + "Label": "", "StartEpoch": 10101, "EndEpoch": 10101, "StoragePricePerEpoch": "0", @@ -6064,6 +6091,8 @@ Response: "InitialPledge": "0", "ExpectedDayReward": "0", "ExpectedStoragePledge": "0", + "ReplacedSectorAge": 10101, + "ReplacedDayReward": "0", "SectorKeyCID": null } ] @@ -6527,6 +6556,8 @@ Response: "InitialPledge": "0", "ExpectedDayReward": "0", "ExpectedStoragePledge": "0", + "ReplacedSectorAge": 10101, + "ReplacedDayReward": "0", "SectorKeyCID": null } ] @@ -6562,7 +6593,7 @@ Inputs: ] ``` -Response: `15` +Response: `16` ### StateReadState StateReadState returns the indicated actor's state. @@ -6905,6 +6936,8 @@ Response: "InitialPledge": "0", "ExpectedDayReward": "0", "ExpectedStoragePledge": "0", + "ReplacedSectorAge": 10101, + "ReplacedDayReward": "0", "SectorKeyCID": null } ``` diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index 1b609ab2e..726bf7561 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -7,7 +7,7 @@ USAGE: lotus-miner [global options] command [command options] [arguments...] VERSION: - 1.15.3 + 1.16.0 COMMANDS: init Initialize a lotus miner repo @@ -1665,6 +1665,7 @@ COMMANDS: get-cc-collateral Get the collateral required to pledge a committed capacity sector batching manage batch sector operations match-pending-pieces force a refreshed match of pending pieces to open sectors without manually waiting for more deals + compact-partitions removes dead sectors from partitions and reduces the number of partitions used if possible help, h Shows a list of commands or help for one command OPTIONS: @@ -2006,6 +2007,23 @@ OPTIONS: ``` +### lotus-miner sectors compact-partitions +``` +NAME: + lotus-miner sectors compact-partitions - removes dead sectors from partitions and reduces the number of partitions used if possible + +USAGE: + lotus-miner sectors compact-partitions [command options] [arguments...] + +OPTIONS: + --deadline value the deadline to compact the partitions in (default: 0) + --partitions value list of partitions to compact sectors in + --really-do-it Actually send transaction performing the action (default: false) + --actor value Specify the address of the miner to run this command + --help, -h show help (default: false) + +``` + ## lotus-miner proving ``` NAME: diff --git a/documentation/en/cli-lotus-worker.md b/documentation/en/cli-lotus-worker.md index 4e46b8ea8..d2f616655 100644 --- a/documentation/en/cli-lotus-worker.md +++ b/documentation/en/cli-lotus-worker.md @@ -7,7 +7,7 @@ USAGE: lotus-worker [global options] command [command options] [arguments...] VERSION: - 1.15.3 + 1.16.0 COMMANDS: run Start lotus worker diff --git a/documentation/en/cli-lotus.md b/documentation/en/cli-lotus.md index 5d0d58312..d1a16ce18 100644 --- a/documentation/en/cli-lotus.md +++ b/documentation/en/cli-lotus.md @@ -7,7 +7,7 @@ USAGE: lotus [global options] command [command options] [arguments...] VERSION: - 1.15.3 + 1.16.0 COMMANDS: daemon Start a lotus daemon process @@ -1749,6 +1749,7 @@ COMMANDS: exec-trace Get the execution trace of a given message network-version Returns the network version miner-proving-deadline Retrieve information about a given miner's proving deadline + actor-cids Returns the built-in actor bundle manifest ID & system actor cids help, h Shows a list of commands or help for one command OPTIONS: @@ -2066,6 +2067,20 @@ OPTIONS: ``` +### lotus state actor-cids +``` +NAME: + lotus state actor-cids - Returns the built-in actor bundle manifest ID & system actor cids + +USAGE: + lotus state actor-cids [command options] [arguments...] + +OPTIONS: + --network-version value specify network version (default: 16) + --help, -h show help (default: false) + +``` + ## lotus chain ``` NAME: 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/extern/sector-storage/cbor_gen.go b/extern/sector-storage/cbor_gen.go index 623d75b33..fd99576cc 100644 --- a/extern/sector-storage/cbor_gen.go +++ b/extern/sector-storage/cbor_gen.go @@ -24,25 +24,26 @@ func (t *Call) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{164}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{164}); err != nil { return err } - scratch := make([]byte, 9) - // t.ID (storiface.CallID) (struct) if len("ID") > cbg.MaxLength { return xerrors.Errorf("Value in field \"ID\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ID"))); err != nil { return err } if _, err := io.WriteString(w, string("ID")); err != nil { return err } - if err := t.ID.MarshalCBOR(w); err != nil { + if err := t.ID.MarshalCBOR(cw); err != nil { return err } @@ -51,7 +52,7 @@ func (t *Call) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"RetType\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("RetType"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("RetType"))); err != nil { return err } if _, err := io.WriteString(w, string("RetType")); err != nil { @@ -62,7 +63,7 @@ func (t *Call) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.RetType was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.RetType))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.RetType))); err != nil { return err } if _, err := io.WriteString(w, string(t.RetType)); err != nil { @@ -74,14 +75,14 @@ func (t *Call) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"State\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("State"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("State"))); err != nil { return err } if _, err := io.WriteString(w, string("State")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.State)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.State)); err != nil { return err } @@ -90,29 +91,34 @@ func (t *Call) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Result\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Result"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Result"))); err != nil { return err } if _, err := io.WriteString(w, string("Result")); err != nil { return err } - if err := t.Result.MarshalCBOR(w); err != nil { + if err := t.Result.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *Call) UnmarshalCBOR(r io.Reader) error { +func (t *Call) UnmarshalCBOR(r io.Reader) (err error) { *t = Call{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -127,7 +133,7 @@ func (t *Call) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -141,7 +147,7 @@ func (t *Call) UnmarshalCBOR(r io.Reader) error { { - if err := t.ID.UnmarshalCBOR(br); err != nil { + if err := t.ID.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.ID: %w", err) } @@ -150,7 +156,7 @@ func (t *Call) UnmarshalCBOR(r io.Reader) error { case "RetType": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -162,7 +168,7 @@ func (t *Call) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -177,16 +183,16 @@ func (t *Call) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.Result = new(ManyBytes) - if err := t.Result.UnmarshalCBOR(br); err != nil { + if err := t.Result.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Result pointer: %w", err) } } @@ -206,25 +212,26 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{166}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{166}); err != nil { return err } - scratch := make([]byte, 9) - // t.ID (sectorstorage.WorkID) (struct) if len("ID") > cbg.MaxLength { return xerrors.Errorf("Value in field \"ID\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ID"))); err != nil { return err } if _, err := io.WriteString(w, string("ID")); err != nil { return err } - if err := t.ID.MarshalCBOR(w); err != nil { + if err := t.ID.MarshalCBOR(cw); err != nil { return err } @@ -233,7 +240,7 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Status\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Status"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Status"))); err != nil { return err } if _, err := io.WriteString(w, string("Status")); err != nil { @@ -244,7 +251,7 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Status was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Status))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Status))); err != nil { return err } if _, err := io.WriteString(w, string(t.Status)); err != nil { @@ -256,14 +263,14 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"WorkerCall\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("WorkerCall"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("WorkerCall"))); err != nil { return err } if _, err := io.WriteString(w, string("WorkerCall")); err != nil { return err } - if err := t.WorkerCall.MarshalCBOR(w); err != nil { + if err := t.WorkerCall.MarshalCBOR(cw); err != nil { return err } @@ -272,7 +279,7 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"WorkError\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("WorkError"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("WorkError"))); err != nil { return err } if _, err := io.WriteString(w, string("WorkError")); err != nil { @@ -283,7 +290,7 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.WorkError was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.WorkError))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.WorkError))); err != nil { return err } if _, err := io.WriteString(w, string(t.WorkError)); err != nil { @@ -295,7 +302,7 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"WorkerHostname\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("WorkerHostname"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("WorkerHostname"))); err != nil { return err } if _, err := io.WriteString(w, string("WorkerHostname")); err != nil { @@ -306,7 +313,7 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.WorkerHostname was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.WorkerHostname))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.WorkerHostname))); err != nil { return err } if _, err := io.WriteString(w, string(t.WorkerHostname)); err != nil { @@ -318,7 +325,7 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"StartTime\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("StartTime"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("StartTime"))); err != nil { return err } if _, err := io.WriteString(w, string("StartTime")); err != nil { @@ -326,27 +333,32 @@ func (t *WorkState) MarshalCBOR(w io.Writer) error { } if t.StartTime >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.StartTime)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.StartTime)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.StartTime-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.StartTime-1)); err != nil { return err } } return nil } -func (t *WorkState) UnmarshalCBOR(r io.Reader) error { +func (t *WorkState) UnmarshalCBOR(r io.Reader) (err error) { *t = WorkState{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -361,7 +373,7 @@ func (t *WorkState) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -375,7 +387,7 @@ func (t *WorkState) UnmarshalCBOR(r io.Reader) error { { - if err := t.ID.UnmarshalCBOR(br); err != nil { + if err := t.ID.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.ID: %w", err) } @@ -384,7 +396,7 @@ func (t *WorkState) UnmarshalCBOR(r io.Reader) error { case "Status": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -396,7 +408,7 @@ func (t *WorkState) UnmarshalCBOR(r io.Reader) error { { - if err := t.WorkerCall.UnmarshalCBOR(br); err != nil { + if err := t.WorkerCall.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.WorkerCall: %w", err) } @@ -405,7 +417,7 @@ func (t *WorkState) UnmarshalCBOR(r io.Reader) error { case "WorkError": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -416,7 +428,7 @@ func (t *WorkState) UnmarshalCBOR(r io.Reader) error { case "WorkerHostname": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -426,7 +438,7 @@ func (t *WorkState) UnmarshalCBOR(r io.Reader) error { // t.StartTime (int64) (int64) case "StartTime": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -463,18 +475,19 @@ func (t *WorkID) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{162}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{162}); err != nil { return err } - scratch := make([]byte, 9) - // t.Method (sealtasks.TaskType) (string) if len("Method") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Method\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Method"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Method"))); err != nil { return err } if _, err := io.WriteString(w, string("Method")); err != nil { @@ -485,7 +498,7 @@ func (t *WorkID) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Method was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Method))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Method))); err != nil { return err } if _, err := io.WriteString(w, string(t.Method)); err != nil { @@ -497,7 +510,7 @@ func (t *WorkID) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Params\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Params"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Params"))); err != nil { return err } if _, err := io.WriteString(w, string("Params")); err != nil { @@ -508,7 +521,7 @@ func (t *WorkID) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Params was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Params))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Params))); err != nil { return err } if _, err := io.WriteString(w, string(t.Params)); err != nil { @@ -517,16 +530,21 @@ func (t *WorkID) MarshalCBOR(w io.Writer) error { return nil } -func (t *WorkID) UnmarshalCBOR(r io.Reader) error { +func (t *WorkID) UnmarshalCBOR(r io.Reader) (err error) { *t = WorkID{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -541,7 +559,7 @@ func (t *WorkID) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -554,7 +572,7 @@ func (t *WorkID) UnmarshalCBOR(r io.Reader) error { case "Method": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -565,7 +583,7 @@ func (t *WorkID) UnmarshalCBOR(r io.Reader) error { case "Params": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } diff --git a/extern/sector-storage/ffiwrapper/prover_cgo.go b/extern/sector-storage/ffiwrapper/prover_cgo.go index 1ca22083d..a41b11a27 100644 --- a/extern/sector-storage/ffiwrapper/prover_cgo.go +++ b/extern/sector-storage/ffiwrapper/prover_cgo.go @@ -5,7 +5,7 @@ package ffiwrapper import ( ffi "github.com/filecoin-project/filecoin-ffi" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" + "github.com/filecoin-project/go-state-types/proof" ) var ProofProver = proofProver{} @@ -14,6 +14,6 @@ var _ Prover = ProofProver type proofProver struct{} -func (v proofProver) AggregateSealProofs(aggregateInfo proof5.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) { +func (v proofProver) AggregateSealProofs(aggregateInfo proof.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) { return ffi.AggregateSealProofs(aggregateInfo, proofs) } diff --git a/extern/sector-storage/ffiwrapper/sealer_cgo.go b/extern/sector-storage/ffiwrapper/sealer_cgo.go index 400b67211..b0b4fdd2d 100644 --- a/extern/sector-storage/ffiwrapper/sealer_cgo.go +++ b/extern/sector-storage/ffiwrapper/sealer_cgo.go @@ -15,6 +15,8 @@ import ( "os" "runtime" + "github.com/filecoin-project/go-state-types/proof" + "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -25,7 +27,6 @@ import ( "github.com/filecoin-project/go-commp-utils/zerocomm" commcid "github.com/filecoin-project/go-fil-commcid" "github.com/filecoin-project/go-state-types/abi" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/extern/sector-storage/fr32" @@ -1093,21 +1094,21 @@ func GenerateUnsealedCID(proofType abi.RegisteredSealProof, pieces []abi.PieceIn return ffi.GenerateUnsealedCID(proofType, allPieces) } -func (sb *Sealer) GenerateWinningPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, vanillas [][]byte) ([]proof5.PoStProof, error) { +func (sb *Sealer) GenerateWinningPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, vanillas [][]byte) ([]proof.PoStProof, error) { return ffi.GenerateWinningPoStWithVanilla(proofType, minerID, randomness, vanillas) } -func (sb *Sealer) GenerateWindowPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte, partitionIdx int) (proof5.PoStProof, error) { +func (sb *Sealer) GenerateWindowPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte, partitionIdx int) (proof.PoStProof, error) { pp, err := ffi.GenerateSinglePartitionWindowPoStWithVanilla(proofType, minerID, randomness, proofs, uint(partitionIdx)) if err != nil { - return proof5.PoStProof{}, err + return proof.PoStProof{}, err } if pp == nil { // should be impossible, but just in case do not panic - return proof5.PoStProof{}, xerrors.New("postproof was nil") + return proof.PoStProof{}, xerrors.New("postproof was nil") } - return proof5.PoStProof{ + return proof.PoStProof{ PoStProof: pp.PoStProof, ProofBytes: pp.ProofBytes, }, nil diff --git a/extern/sector-storage/ffiwrapper/sealer_test.go b/extern/sector-storage/ffiwrapper/sealer_test.go index 97102e50e..b182eff76 100644 --- a/extern/sector-storage/ffiwrapper/sealer_test.go +++ b/extern/sector-storage/ffiwrapper/sealer_test.go @@ -15,11 +15,9 @@ import ( "testing" "time" - commpffi "github.com/filecoin-project/go-commp-utils/ffiwrapper" + prooftypes "github.com/filecoin-project/go-state-types/proof" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" - proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" + commpffi "github.com/filecoin-project/go-commp-utils/ffiwrapper" "github.com/ipfs/go-cid" @@ -32,7 +30,7 @@ import ( "github.com/filecoin-project/specs-storage/storage" ffi "github.com/filecoin-project/filecoin-ffi" - "github.com/filecoin-project/filecoin-ffi/generated" + "github.com/filecoin-project/filecoin-ffi/cgo" "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper/basicfs" @@ -106,7 +104,7 @@ func (s *seal) commit(t *testing.T, sb *Sealer, done func()) storage.Proof { return nil } - ok, err := ProofVerifier.VerifySeal(proof2.SealVerifyInfo{ + ok, err := ProofVerifier.VerifySeal(prooftypes.SealVerifyInfo{ SectorID: s.ref.ID, SealedCID: s.cids.Sealed, SealProof: s.ref.ProofType, @@ -188,9 +186,9 @@ func (s *seal) unseal(t *testing.T, sb *Sealer, sp *basicfs.Provider, si storage func post(t *testing.T, sealer *Sealer, skipped []abi.SectorID, seals ...seal) { randomness := abi.PoStRandomness{0, 9, 2, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 45, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 7} - xsis := make([]proof7.ExtendedSectorInfo, len(seals)) + xsis := make([]prooftypes.ExtendedSectorInfo, len(seals)) for i, s := range seals { - xsis[i] = proof7.ExtendedSectorInfo{ + xsis[i] = prooftypes.ExtendedSectorInfo{ SealProof: s.ref.ProofType, SectorNumber: s.ref.ID.Number, SealedCID: s.cids.Sealed, @@ -208,16 +206,16 @@ func post(t *testing.T, sealer *Sealer, skipped []abi.SectorID, seals ...seal) { t.Fatalf("%+v", err) } - sis := make([]proof7.SectorInfo, len(seals)) + sis := make([]prooftypes.SectorInfo, len(seals)) for i, xsi := range xsis { - sis[i] = proof7.SectorInfo{ + sis[i] = prooftypes.SectorInfo{ SealProof: xsi.SealProof, SectorNumber: xsi.SectorNumber, SealedCID: xsi.SealedCID, } } - ok, err := ProofVerifier.VerifyWindowPoSt(context.TODO(), proof7.WindowPoStVerifyInfo{ + ok, err := ProofVerifier.VerifyWindowPoSt(context.TODO(), prooftypes.WindowPoStVerifyInfo{ Randomness: randomness, Proofs: proofs, ChallengedSectors: sis, @@ -525,12 +523,12 @@ func TestSealAndVerifyAggregate(t *testing.T) { } }) - avi := proof5.AggregateSealVerifyProofAndInfos{ + avi := prooftypes.AggregateSealVerifyProofAndInfos{ Miner: miner, SealProof: sealProofType, AggregateProof: policy.GetDefaultAggregationProof(), Proof: nil, - Infos: make([]proof5.AggregateSealVerifyInfo, numAgg), + Infos: make([]prooftypes.AggregateSealVerifyInfo, numAgg), } toAggregate := make([][]byte, numAgg) @@ -544,7 +542,7 @@ func TestSealAndVerifyAggregate(t *testing.T) { s.precommit(t, sb, si, func() {}) toAggregate[i] = s.commit(t, sb, func() {}) - avi.Infos[i] = proof5.AggregateSealVerifyInfo{ + avi.Infos[i] = prooftypes.AggregateSealVerifyInfo{ Number: abi.SectorNumber(i + 1), Randomness: s.ticket, InteractiveRandomness: seed, @@ -883,14 +881,8 @@ func setupLogger(t *testing.T) *bytes.Buffer { runtime.KeepAlive(w) }() - resp := generated.FilInitLogFd(int32(w.Fd())) - resp.Deref() - - defer generated.FilDestroyInitLogFdResponse(resp) - - if resp.StatusCode != generated.FCPResponseStatusFCPNoError { - t.Fatal(generated.RawString(resp.ErrorMsg).Copy()) - } + err = cgo.InitLogFd(int32(w.Fd())) + require.NoError(t, err) return &bb } diff --git a/extern/sector-storage/ffiwrapper/types.go b/extern/sector-storage/ffiwrapper/types.go index b8d9e90f1..3c39a831e 100644 --- a/extern/sector-storage/ffiwrapper/types.go +++ b/extern/sector-storage/ffiwrapper/types.go @@ -4,7 +4,7 @@ import ( "context" "io" - "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" + "github.com/filecoin-project/go-state-types/proof" "github.com/ipfs/go-cid" diff --git a/extern/sector-storage/ffiwrapper/verifier_cgo.go b/extern/sector-storage/ffiwrapper/verifier_cgo.go index 6adda05c9..3f689e62e 100644 --- a/extern/sector-storage/ffiwrapper/verifier_cgo.go +++ b/extern/sector-storage/ffiwrapper/verifier_cgo.go @@ -11,7 +11,6 @@ import ( ffi "github.com/filecoin-project/filecoin-ffi" "github.com/filecoin-project/go-state-types/abi" - ffiproof "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" "github.com/filecoin-project/specs-storage/storage" @@ -114,7 +113,7 @@ func (sb *Sealer) pubExtendedSectorToPriv(ctx context.Context, mid abi.ActorID, return ffi.SortedPrivateSectorInfo{}, nil, nil, xerrors.Errorf("acquiring registered PoSt proof from sector info %+v: %w", s, err) } - ffiInfo := ffiproof.SectorInfo{ + ffiInfo := proof.SectorInfo{ SealProof: s.SealProof, SectorNumber: s.SectorNumber, SealedCID: s.SealedCID, diff --git a/extern/sector-storage/manager_test.go b/extern/sector-storage/manager_test.go index 9c844292e..e8cba2fa5 100644 --- a/extern/sector-storage/manager_test.go +++ b/extern/sector-storage/manager_test.go @@ -16,6 +16,9 @@ import ( "testing" "time" + ffi "github.com/filecoin-project/filecoin-ffi" + "github.com/filecoin-project/go-state-types/proof" + "github.com/google/uuid" "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" @@ -317,6 +320,147 @@ func TestSnapDeals(t *testing.T) { } +func TestSnarkPackV2(t *testing.T) { + logging.SetAllLoggers(logging.LevelWarn) + ctx := context.Background() + m, lstor, stor, idx, cleanup := newTestMgr(ctx, t, datastore.NewMapDatastore()) + defer cleanup() + + localTasks := []sealtasks.TaskType{ + sealtasks.TTAddPiece, sealtasks.TTPreCommit1, sealtasks.TTPreCommit2, sealtasks.TTCommit1, sealtasks.TTCommit2, sealtasks.TTFinalize, + sealtasks.TTFetch, sealtasks.TTReplicaUpdate, sealtasks.TTProveReplicaUpdate1, sealtasks.TTProveReplicaUpdate2, sealtasks.TTUnseal, + sealtasks.TTRegenSectorKey, + } + wds := datastore.NewMapDatastore() + + w := NewLocalWorker(WorkerConfig{TaskTypes: localTasks}, stor, lstor, idx, m, statestore.New(wds)) + err := m.AddWorker(ctx, w) + require.NoError(t, err) + + proofType := abi.RegisteredSealProof_StackedDrg2KiBV1 + ptStr := os.Getenv("LOTUS_TEST_SNAP_DEALS_PROOF_TYPE") + switch ptStr { + case "2k": + case "8M": + proofType = abi.RegisteredSealProof_StackedDrg8MiBV1 + case "512M": + proofType = abi.RegisteredSealProof_StackedDrg512MiBV1 + case "32G": + proofType = abi.RegisteredSealProof_StackedDrg32GiBV1 + case "64G": + proofType = abi.RegisteredSealProof_StackedDrg64GiBV1 + default: + log.Warn("Unspecified proof type, make sure to set LOTUS_TEST_SNAP_DEALS_PROOF_TYPE to '2k', '8M', '512M', '32G' or '64G'") + log.Warn("Continuing test with 2k sectors") + } + + mid := abi.ActorID(1000) + + sid1 := storage.SectorRef{ + ID: abi.SectorID{Miner: mid, Number: 1}, + ProofType: proofType, + } + + sid2 := storage.SectorRef{ + ID: abi.SectorID{Miner: mid, Number: 2}, + ProofType: proofType, + } + + ss, err := proofType.SectorSize() + require.NoError(t, err) + + unpaddedSectorSize := abi.PaddedPieceSize(ss).Unpadded() + + // Pack sector with no pieces + p1, err := m.AddPiece(ctx, sid1, nil, unpaddedSectorSize, NewNullReader(unpaddedSectorSize)) + require.NoError(t, err) + ccPieces1 := []abi.PieceInfo{p1} + + p2, err := m.AddPiece(ctx, sid2, nil, unpaddedSectorSize, NewNullReader(unpaddedSectorSize)) + require.NoError(t, err) + ccPieces2 := []abi.PieceInfo{p2} + + // Precommit and Seal 2 CC sectors + fmt.Printf("PC1\n") + + ticket1 := abi.SealRandomness{9, 9, 9, 9, 9, 9, 9, 9} + ticket2 := abi.SealRandomness{1, 9, 8, 9, 1, 9, 8, 9} + interactiveRandomness1 := abi.InteractiveSealRandomness{1, 9, 2, 1, 2, 5, 3, 0} + interactiveRandomness2 := abi.InteractiveSealRandomness{1, 5, 2, 2, 1, 5, 2, 2} + + pc1Out1, err := m.SealPreCommit1(ctx, sid1, ticket1, ccPieces1) + require.NoError(t, err) + pc1Out2, err := m.SealPreCommit1(ctx, sid2, ticket2, ccPieces2) + require.NoError(t, err) + + fmt.Printf("PC2\n") + + pc2Out1, err := m.SealPreCommit2(ctx, sid1, pc1Out1) + require.NoError(t, err) + pc2Out2, err := m.SealPreCommit2(ctx, sid2, pc1Out2) + require.NoError(t, err) + + // Commit the sector + + fmt.Printf("C1\n") + + c1Out1, err := m.SealCommit1(ctx, sid1, ticket1, interactiveRandomness1, ccPieces1, pc2Out1) + require.NoError(t, err) + c1Out2, err := m.SealCommit1(ctx, sid2, ticket2, interactiveRandomness2, ccPieces2, pc2Out2) + require.NoError(t, err) + + fmt.Printf("C2\n") + + c2Out1, err := m.SealCommit2(ctx, sid1, c1Out1) + require.NoError(t, err) + c2Out2, err := m.SealCommit2(ctx, sid2, c1Out2) + require.NoError(t, err) + + fmt.Println("Aggregate") + agg, err := ffi.AggregateSealProofs(proof.AggregateSealVerifyProofAndInfos{ + Miner: mid, + SealProof: proofType, + AggregateProof: abi.RegisteredAggregationProof_SnarkPackV2, + Infos: []proof.AggregateSealVerifyInfo{{ + Number: sid1.ID.Number, + Randomness: ticket1, + InteractiveRandomness: interactiveRandomness1, + SealedCID: pc2Out1.Sealed, + UnsealedCID: pc2Out1.Unsealed, + }, { + Number: sid2.ID.Number, + Randomness: ticket2, + InteractiveRandomness: interactiveRandomness2, + SealedCID: pc2Out2.Sealed, + UnsealedCID: pc2Out2.Unsealed, + }}, + }, [][]byte{c2Out1, c2Out2}) + require.NoError(t, err) + + fmt.Println("Verifying aggregate") + ret, err := ffi.VerifyAggregateSeals(proof.AggregateSealVerifyProofAndInfos{ + Miner: mid, + SealProof: proofType, + AggregateProof: abi.RegisteredAggregationProof_SnarkPackV2, + Proof: agg, + Infos: []proof.AggregateSealVerifyInfo{{ + Number: sid1.ID.Number, + Randomness: ticket1, + InteractiveRandomness: interactiveRandomness1, + SealedCID: pc2Out1.Sealed, + UnsealedCID: pc2Out1.Unsealed, + }, { + Number: sid2.ID.Number, + Randomness: ticket2, + InteractiveRandomness: interactiveRandomness2, + SealedCID: pc2Out2.Sealed, + UnsealedCID: pc2Out2.Unsealed, + }}, + }) + require.NoError(t, err) + require.True(t, ret, "proof should be good") +} + func TestRedoPC1(t *testing.T) { logging.SetAllLoggers(logging.LevelDebug) diff --git a/extern/sector-storage/mock/mock.go b/extern/sector-storage/mock/mock.go index ecb06da0b..e50780d1c 100644 --- a/extern/sector-storage/mock/mock.go +++ b/extern/sector-storage/mock/mock.go @@ -10,7 +10,7 @@ import ( "math/rand" "sync" - "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" + prooftypes "github.com/filecoin-project/go-state-types/proof" "github.com/filecoin-project/dagstore/mount" ffiwrapper2 "github.com/filecoin-project/go-commp-utils/ffiwrapper" @@ -37,7 +37,7 @@ type SectorMgr struct { } type mockVerifProver struct { - aggregates map[string]proof.AggregateSealVerifyProofAndInfos // used for logging bad verifies + aggregates map[string]prooftypes.AggregateSealVerifyProofAndInfos // used for logging bad verifies } func NewMockSectorMgr(genesisSectors []abi.SectorID) *SectorMgr { @@ -338,13 +338,13 @@ func AddOpFinish(ctx context.Context) (context.Context, func()) { } } -func (mgr *SectorMgr) GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, xSectorInfo []proof.ExtendedSectorInfo, randomness abi.PoStRandomness) ([]proof.PoStProof, error) { +func (mgr *SectorMgr) GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, xSectorInfo []prooftypes.ExtendedSectorInfo, randomness abi.PoStRandomness) ([]prooftypes.PoStProof, error) { mgr.lk.Lock() defer mgr.lk.Unlock() - sectorInfo := make([]proof.SectorInfo, len(xSectorInfo)) + sectorInfo := make([]prooftypes.SectorInfo, len(xSectorInfo)) for i, xssi := range xSectorInfo { - sectorInfo[i] = proof.SectorInfo{ + sectorInfo[i] = prooftypes.SectorInfo{ SealProof: xssi.SealProof, SectorNumber: xssi.SectorNumber, SealedCID: xssi.SealedCID, @@ -354,7 +354,7 @@ func (mgr *SectorMgr) GenerateWinningPoSt(ctx context.Context, minerID abi.Actor return generateFakePoSt(sectorInfo, abi.RegisteredSealProof.RegisteredWinningPoStProof, randomness), nil } -func (mgr *SectorMgr) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, xSectorInfo []proof.ExtendedSectorInfo, randomness abi.PoStRandomness) ([]proof.PoStProof, []abi.SectorID, error) { +func (mgr *SectorMgr) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, xSectorInfo []prooftypes.ExtendedSectorInfo, randomness abi.PoStRandomness) ([]prooftypes.PoStProof, []abi.SectorID, error) { mgr.lk.Lock() defer mgr.lk.Unlock() @@ -362,7 +362,7 @@ func (mgr *SectorMgr) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorI return nil, nil, xerrors.Errorf("failed to post (mock)") } - si := make([]proof.ExtendedSectorInfo, 0, len(xSectorInfo)) + si := make([]prooftypes.ExtendedSectorInfo, 0, len(xSectorInfo)) var skipped []abi.SectorID @@ -388,9 +388,9 @@ func (mgr *SectorMgr) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorI return nil, skipped, err } - sectorInfo := make([]proof.SectorInfo, len(si)) + sectorInfo := make([]prooftypes.SectorInfo, len(si)) for i, xssi := range si { - sectorInfo[i] = proof.SectorInfo{ + sectorInfo[i] = prooftypes.SectorInfo{ SealProof: xssi.SealProof, SectorNumber: xssi.SectorNumber, SealedCID: xssi.SealedCID, @@ -400,7 +400,7 @@ func (mgr *SectorMgr) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorI return generateFakePoSt(sectorInfo, abi.RegisteredSealProof.RegisteredWindowPoStProof, randomness), skipped, nil } -func generateFakePoStProof(sectorInfo []proof.SectorInfo, randomness abi.PoStRandomness) []byte { +func generateFakePoStProof(sectorInfo []prooftypes.SectorInfo, randomness abi.PoStRandomness) []byte { randomness[31] &= 0x3f hasher := sha256.New() @@ -415,13 +415,13 @@ func generateFakePoStProof(sectorInfo []proof.SectorInfo, randomness abi.PoStRan } -func generateFakePoSt(sectorInfo []proof.SectorInfo, rpt func(abi.RegisteredSealProof) (abi.RegisteredPoStProof, error), randomness abi.PoStRandomness) []proof.PoStProof { +func generateFakePoSt(sectorInfo []prooftypes.SectorInfo, rpt func(abi.RegisteredSealProof) (abi.RegisteredPoStProof, error), randomness abi.PoStRandomness) []prooftypes.PoStProof { wp, err := rpt(sectorInfo[0].SealProof) if err != nil { panic(err) } - return []proof.PoStProof{ + return []prooftypes.PoStProof{ { PoStProof: wp, ProofBytes: generateFakePoStProof(sectorInfo, randomness), @@ -429,11 +429,11 @@ func generateFakePoSt(sectorInfo []proof.SectorInfo, rpt func(abi.RegisteredSeal } } -func (mgr *SectorMgr) GenerateWinningPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte) ([]proof.PoStProof, error) { +func (mgr *SectorMgr) GenerateWinningPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte) ([]prooftypes.PoStProof, error) { panic("implement me") } -func (mgr *SectorMgr) GenerateWindowPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte, partitionIdx int) (proof.PoStProof, error) { +func (mgr *SectorMgr) GenerateWindowPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte, partitionIdx int) (prooftypes.PoStProof, error) { panic("implement me") } @@ -609,7 +609,7 @@ func (mgr *SectorMgr) ReturnFinalizeReplicaUpdate(ctx context.Context, callID st panic("not supported") } -func (m mockVerifProver) VerifySeal(svi proof.SealVerifyInfo) (bool, error) { +func (m mockVerifProver) VerifySeal(svi prooftypes.SealVerifyInfo) (bool, error) { plen, err := svi.SealProof.ProofSize() if err != nil { return false, err @@ -630,7 +630,7 @@ func (m mockVerifProver) VerifySeal(svi proof.SealVerifyInfo) (bool, error) { return true, nil } -func (m mockVerifProver) VerifyAggregateSeals(aggregate proof.AggregateSealVerifyProofAndInfos) (bool, error) { +func (m mockVerifProver) VerifyAggregateSeals(aggregate prooftypes.AggregateSealVerifyProofAndInfos) (bool, error) { out := make([]byte, m.aggLen(len(aggregate.Infos))) for pi, svi := range aggregate.Infos { for i := 0; i < 32; i++ { @@ -656,11 +656,11 @@ func (m mockVerifProver) VerifyAggregateSeals(aggregate proof.AggregateSealVerif return ok, nil } -func (m mockVerifProver) VerifyReplicaUpdate(update proof.ReplicaUpdateInfo) (bool, error) { +func (m mockVerifProver) VerifyReplicaUpdate(update prooftypes.ReplicaUpdateInfo) (bool, error) { return true, nil } -func (m mockVerifProver) AggregateSealProofs(aggregateInfo proof.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) { +func (m mockVerifProver) AggregateSealProofs(aggregateInfo prooftypes.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) { out := make([]byte, m.aggLen(len(aggregateInfo.Infos))) // todo: figure out more real length for pi, proof := range proofs { for i := range proof[:32] { @@ -702,12 +702,12 @@ func (m mockVerifProver) aggLen(nproofs int) int { } } -func (m mockVerifProver) VerifyWinningPoSt(ctx context.Context, info proof.WinningPoStVerifyInfo) (bool, error) { +func (m mockVerifProver) VerifyWinningPoSt(ctx context.Context, info prooftypes.WinningPoStVerifyInfo) (bool, error) { info.Randomness[31] &= 0x3f return true, nil } -func (m mockVerifProver) VerifyWindowPoSt(ctx context.Context, info proof.WindowPoStVerifyInfo) (bool, error) { +func (m mockVerifProver) VerifyWindowPoSt(ctx context.Context, info prooftypes.WindowPoStVerifyInfo) (bool, error) { if len(info.Proofs) != 1 { return false, xerrors.Errorf("expected 1 proof entry") } @@ -730,7 +730,7 @@ func (m mockVerifProver) GenerateWinningPoStSectorChallenge(ctx context.Context, } var MockVerifier = mockVerifProver{ - aggregates: map[string]proof.AggregateSealVerifyProofAndInfos{}, + aggregates: map[string]prooftypes.AggregateSealVerifyProofAndInfos{}, } var MockProver = MockVerifier diff --git a/extern/sector-storage/sched_test.go b/extern/sector-storage/sched_test.go index 77e674793..816fb2c06 100644 --- a/extern/sector-storage/sched_test.go +++ b/extern/sector-storage/sched_test.go @@ -11,13 +11,14 @@ import ( "testing" "time" + prooftypes "github.com/filecoin-project/go-state-types/proof" + "github.com/google/uuid" "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" @@ -144,7 +145,7 @@ func (s *schedTestWorker) ReadPiece(ctx context.Context, writer io.Writer, id st panic("implement me") } -func (s *schedTestWorker) GenerateWinningPoSt(ctx context.Context, ppt abi.RegisteredPoStProof, mid abi.ActorID, sectors []storiface.PostSectorChallenge, randomness abi.PoStRandomness) ([]proof.PoStProof, error) { +func (s *schedTestWorker) GenerateWinningPoSt(ctx context.Context, ppt abi.RegisteredPoStProof, mid abi.ActorID, sectors []storiface.PostSectorChallenge, randomness abi.PoStRandomness) ([]prooftypes.PoStProof, error) { panic("implement me") } diff --git a/extern/sector-storage/stores/local.go b/extern/sector-storage/stores/local.go index 4efddca38..1bdd1f08b 100644 --- a/extern/sector-storage/stores/local.go +++ b/extern/sector-storage/stores/local.go @@ -11,11 +11,12 @@ import ( "sync" "time" + "github.com/filecoin-project/go-state-types/proof" + "golang.org/x/xerrors" ffi "github.com/filecoin-project/filecoin-ffi" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" diff --git a/extern/sector-storage/storiface/cbor_gen.go b/extern/sector-storage/storiface/cbor_gen.go index 44b5ae9ee..5b4623175 100644 --- a/extern/sector-storage/storiface/cbor_gen.go +++ b/extern/sector-storage/storiface/cbor_gen.go @@ -23,25 +23,26 @@ func (t *CallID) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{162}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{162}); err != nil { return err } - scratch := make([]byte, 9) - // t.Sector (abi.SectorID) (struct) if len("Sector") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Sector\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Sector"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Sector"))); err != nil { return err } if _, err := io.WriteString(w, string("Sector")); err != nil { return err } - if err := t.Sector.MarshalCBOR(w); err != nil { + if err := t.Sector.MarshalCBOR(cw); err != nil { return err } @@ -50,7 +51,7 @@ func (t *CallID) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"ID\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ID"))); err != nil { return err } if _, err := io.WriteString(w, string("ID")); err != nil { @@ -61,26 +62,31 @@ func (t *CallID) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.ID was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.ID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.ID))); err != nil { return err } - if _, err := w.Write(t.ID[:]); err != nil { + if _, err := cw.Write(t.ID[:]); err != nil { return err } return nil } -func (t *CallID) UnmarshalCBOR(r io.Reader) error { +func (t *CallID) UnmarshalCBOR(r io.Reader) (err error) { *t = CallID{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -95,7 +101,7 @@ func (t *CallID) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -109,7 +115,7 @@ func (t *CallID) UnmarshalCBOR(r io.Reader) error { { - if err := t.Sector.UnmarshalCBOR(br); err != nil { + if err := t.Sector.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Sector: %w", err) } @@ -117,7 +123,7 @@ func (t *CallID) UnmarshalCBOR(r io.Reader) error { // t.ID (uuid.UUID) (array) case "ID": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -135,7 +141,7 @@ func (t *CallID) UnmarshalCBOR(r io.Reader) error { t.ID = [16]uint8{} - if _, err := io.ReadFull(br, t.ID[:]); err != nil { + if _, err := io.ReadFull(cr, t.ID[:]); err != nil { return err } diff --git a/extern/sector-storage/storiface/worker.go b/extern/sector-storage/storiface/worker.go index 5b4fabf02..41a27a905 100644 --- a/extern/sector-storage/storiface/worker.go +++ b/extern/sector-storage/storiface/worker.go @@ -6,11 +6,12 @@ import ( "fmt" "time" + "github.com/filecoin-project/go-state-types/proof" + "github.com/google/uuid" "github.com/ipfs/go-cid" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" diff --git a/extern/sector-storage/teststorage_test.go b/extern/sector-storage/teststorage_test.go index 0c15fbf7b..b687e37a2 100644 --- a/extern/sector-storage/teststorage_test.go +++ b/extern/sector-storage/teststorage_test.go @@ -31,7 +31,7 @@ func (t *testExec) GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, panic("implement me") } -func (t *testExec) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []proof.ExtendedSectorInfo, randomness abi.PoStRandomness) (proof []proof.PoStProof, skipped []abi.SectorID, err error) { +func (t *testExec) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []proof.ExtendedSectorInfo, randomness abi.PoStRandomness) (miner []proof.PoStProof, skipped []abi.SectorID, err error) { panic("implement me") } diff --git a/extern/sector-storage/worker_local.go b/extern/sector-storage/worker_local.go index 9a14e42b5..6a01cbf0b 100644 --- a/extern/sector-storage/worker_local.go +++ b/extern/sector-storage/worker_local.go @@ -11,6 +11,8 @@ import ( "sync/atomic" "time" + "github.com/filecoin-project/go-state-types/proof" + "github.com/elastic/go-sysinfo" "github.com/google/uuid" "github.com/hashicorp/go-multierror" @@ -20,7 +22,6 @@ import ( ffi "github.com/filecoin-project/filecoin-ffi" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-statestore" - "github.com/filecoin-project/specs-actors/actors/runtime/proof" "github.com/filecoin-project/specs-storage/storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" diff --git a/extern/storage-sealing/cbor_gen.go b/extern/storage-sealing/cbor_gen.go index c1e2b08fa..8b66619e3 100644 --- a/extern/storage-sealing/cbor_gen.go +++ b/extern/storage-sealing/cbor_gen.go @@ -9,8 +9,8 @@ import ( "sort" abi "github.com/filecoin-project/go-state-types/abi" + miner "github.com/filecoin-project/go-state-types/builtin/v8/miner" api "github.com/filecoin-project/lotus/api" - miner "github.com/filecoin-project/specs-actors/actors/builtin/miner" cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" @@ -26,25 +26,26 @@ func (t *Piece) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{162}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{162}); err != nil { return err } - scratch := make([]byte, 9) - // t.Piece (abi.PieceInfo) (struct) if len("Piece") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Piece\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Piece"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Piece"))); err != nil { return err } if _, err := io.WriteString(w, string("Piece")); err != nil { return err } - if err := t.Piece.MarshalCBOR(w); err != nil { + if err := t.Piece.MarshalCBOR(cw); err != nil { return err } @@ -53,29 +54,34 @@ func (t *Piece) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"DealInfo\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("DealInfo"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("DealInfo"))); err != nil { return err } if _, err := io.WriteString(w, string("DealInfo")); err != nil { return err } - if err := t.DealInfo.MarshalCBOR(w); err != nil { + if err := t.DealInfo.MarshalCBOR(cw); err != nil { return err } return nil } -func (t *Piece) UnmarshalCBOR(r io.Reader) error { +func (t *Piece) UnmarshalCBOR(r io.Reader) (err error) { *t = Piece{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -90,7 +96,7 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -104,7 +110,7 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error { { - if err := t.Piece.UnmarshalCBOR(br); err != nil { + if err := t.Piece.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Piece: %w", err) } @@ -114,16 +120,16 @@ func (t *Piece) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.DealInfo = new(api.PieceDealInfo) - if err := t.DealInfo.UnmarshalCBOR(br); err != nil { + if err := t.DealInfo.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.DealInfo pointer: %w", err) } } @@ -143,18 +149,19 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{184, 32}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{184, 32}); err != nil { return err } - scratch := make([]byte, 9) - // t.State (sealing.SectorState) (string) if len("State") > cbg.MaxLength { return xerrors.Errorf("Value in field \"State\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("State"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("State"))); err != nil { return err } if _, err := io.WriteString(w, string("State")); err != nil { @@ -165,7 +172,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.State was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.State))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.State))); err != nil { return err } if _, err := io.WriteString(w, string(t.State)); err != nil { @@ -177,14 +184,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"SectorNumber\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SectorNumber"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("SectorNumber"))); err != nil { return err } if _, err := io.WriteString(w, string("SectorNumber")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorNumber)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.SectorNumber)); err != nil { return err } @@ -193,7 +200,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"SectorType\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SectorType"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("SectorType"))); err != nil { return err } if _, err := io.WriteString(w, string("SectorType")); err != nil { @@ -201,11 +208,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.SectorType >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SectorType)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.SectorType)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.SectorType-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.SectorType-1)); err != nil { return err } } @@ -215,7 +222,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"CreationTime\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CreationTime"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("CreationTime"))); err != nil { return err } if _, err := io.WriteString(w, string("CreationTime")); err != nil { @@ -223,11 +230,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.CreationTime >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.CreationTime)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.CreationTime)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.CreationTime-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.CreationTime-1)); err != nil { return err } } @@ -237,7 +244,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Pieces\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Pieces"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Pieces"))); err != nil { return err } if _, err := io.WriteString(w, string("Pieces")); err != nil { @@ -248,11 +255,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Pieces was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Pieces))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Pieces))); err != nil { return err } for _, v := range t.Pieces { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } @@ -262,7 +269,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"TicketValue\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TicketValue"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("TicketValue"))); err != nil { return err } if _, err := io.WriteString(w, string("TicketValue")); err != nil { @@ -273,11 +280,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.TicketValue was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.TicketValue))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.TicketValue))); err != nil { return err } - if _, err := w.Write(t.TicketValue[:]); err != nil { + if _, err := cw.Write(t.TicketValue[:]); err != nil { return err } @@ -286,7 +293,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"TicketEpoch\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TicketEpoch"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("TicketEpoch"))); err != nil { return err } if _, err := io.WriteString(w, string("TicketEpoch")); err != nil { @@ -294,11 +301,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.TicketEpoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TicketEpoch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.TicketEpoch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TicketEpoch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.TicketEpoch-1)); err != nil { return err } } @@ -308,7 +315,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"PreCommit1Out\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommit1Out"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PreCommit1Out"))); err != nil { return err } if _, err := io.WriteString(w, string("PreCommit1Out")); err != nil { @@ -319,11 +326,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.PreCommit1Out was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.PreCommit1Out))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.PreCommit1Out))); err != nil { return err } - if _, err := w.Write(t.PreCommit1Out[:]); err != nil { + if _, err := cw.Write(t.PreCommit1Out[:]); err != nil { return err } @@ -332,7 +339,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"CommD\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CommD"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("CommD"))); err != nil { return err } if _, err := io.WriteString(w, string("CommD")); err != nil { @@ -340,11 +347,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.CommD == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.CommD); err != nil { + if err := cbg.WriteCid(cw, *t.CommD); err != nil { return xerrors.Errorf("failed to write cid field t.CommD: %w", err) } } @@ -354,7 +361,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"CommR\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CommR"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("CommR"))); err != nil { return err } if _, err := io.WriteString(w, string("CommR")); err != nil { @@ -362,11 +369,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.CommR == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.CommR); err != nil { + if err := cbg.WriteCid(cw, *t.CommR); err != nil { return xerrors.Errorf("failed to write cid field t.CommR: %w", err) } } @@ -376,7 +383,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Proof\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Proof"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Proof"))); err != nil { return err } if _, err := io.WriteString(w, string("Proof")); err != nil { @@ -387,11 +394,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Proof was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Proof))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Proof))); err != nil { return err } - if _, err := w.Write(t.Proof[:]); err != nil { + if _, err := cw.Write(t.Proof[:]); err != nil { return err } @@ -400,14 +407,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"PreCommitInfo\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitInfo"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PreCommitInfo"))); err != nil { return err } if _, err := io.WriteString(w, string("PreCommitInfo")); err != nil { return err } - if err := t.PreCommitInfo.MarshalCBOR(w); err != nil { + if err := t.PreCommitInfo.MarshalCBOR(cw); err != nil { return err } @@ -416,14 +423,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"PreCommitDeposit\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitDeposit"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PreCommitDeposit"))); err != nil { return err } if _, err := io.WriteString(w, string("PreCommitDeposit")); err != nil { return err } - if err := t.PreCommitDeposit.MarshalCBOR(w); err != nil { + if err := t.PreCommitDeposit.MarshalCBOR(cw); err != nil { return err } @@ -432,7 +439,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"PreCommitMessage\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitMessage"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PreCommitMessage"))); err != nil { return err } if _, err := io.WriteString(w, string("PreCommitMessage")); err != nil { @@ -440,11 +447,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.PreCommitMessage == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.PreCommitMessage); err != nil { + if err := cbg.WriteCid(cw, *t.PreCommitMessage); err != nil { return xerrors.Errorf("failed to write cid field t.PreCommitMessage: %w", err) } } @@ -454,7 +461,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"PreCommitTipSet\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommitTipSet"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PreCommitTipSet"))); err != nil { return err } if _, err := io.WriteString(w, string("PreCommitTipSet")); err != nil { @@ -465,11 +472,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.PreCommitTipSet was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.PreCommitTipSet))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.PreCommitTipSet))); err != nil { return err } - if _, err := w.Write(t.PreCommitTipSet[:]); err != nil { + if _, err := cw.Write(t.PreCommitTipSet[:]); err != nil { return err } @@ -478,14 +485,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"PreCommit2Fails\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PreCommit2Fails"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PreCommit2Fails"))); err != nil { return err } if _, err := io.WriteString(w, string("PreCommit2Fails")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.PreCommit2Fails)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.PreCommit2Fails)); err != nil { return err } @@ -494,7 +501,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"SeedValue\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SeedValue"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("SeedValue"))); err != nil { return err } if _, err := io.WriteString(w, string("SeedValue")); err != nil { @@ -505,11 +512,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.SeedValue was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.SeedValue))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.SeedValue))); err != nil { return err } - if _, err := w.Write(t.SeedValue[:]); err != nil { + if _, err := cw.Write(t.SeedValue[:]); err != nil { return err } @@ -518,7 +525,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"SeedEpoch\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("SeedEpoch"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("SeedEpoch"))); err != nil { return err } if _, err := io.WriteString(w, string("SeedEpoch")); err != nil { @@ -526,11 +533,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.SeedEpoch >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.SeedEpoch)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.SeedEpoch)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.SeedEpoch-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.SeedEpoch-1)); err != nil { return err } } @@ -540,7 +547,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"CommitMessage\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CommitMessage"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("CommitMessage"))); err != nil { return err } if _, err := io.WriteString(w, string("CommitMessage")); err != nil { @@ -548,11 +555,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.CommitMessage == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.CommitMessage); err != nil { + if err := cbg.WriteCid(cw, *t.CommitMessage); err != nil { return xerrors.Errorf("failed to write cid field t.CommitMessage: %w", err) } } @@ -562,14 +569,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"InvalidProofs\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("InvalidProofs"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("InvalidProofs"))); err != nil { return err } if _, err := io.WriteString(w, string("InvalidProofs")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.InvalidProofs)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.InvalidProofs)); err != nil { return err } @@ -578,7 +585,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"CCUpdate\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CCUpdate"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("CCUpdate"))); err != nil { return err } if _, err := io.WriteString(w, string("CCUpdate")); err != nil { @@ -594,7 +601,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"CCPieces\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CCPieces"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("CCPieces"))); err != nil { return err } if _, err := io.WriteString(w, string("CCPieces")); err != nil { @@ -605,11 +612,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.CCPieces was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.CCPieces))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.CCPieces))); err != nil { return err } for _, v := range t.CCPieces { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } @@ -619,7 +626,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"UpdateSealed\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("UpdateSealed"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("UpdateSealed"))); err != nil { return err } if _, err := io.WriteString(w, string("UpdateSealed")); err != nil { @@ -627,11 +634,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.UpdateSealed == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.UpdateSealed); err != nil { + if err := cbg.WriteCid(cw, *t.UpdateSealed); err != nil { return xerrors.Errorf("failed to write cid field t.UpdateSealed: %w", err) } } @@ -641,7 +648,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"UpdateUnsealed\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("UpdateUnsealed"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("UpdateUnsealed"))); err != nil { return err } if _, err := io.WriteString(w, string("UpdateUnsealed")); err != nil { @@ -649,11 +656,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.UpdateUnsealed == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.UpdateUnsealed); err != nil { + if err := cbg.WriteCid(cw, *t.UpdateUnsealed); err != nil { return xerrors.Errorf("failed to write cid field t.UpdateUnsealed: %w", err) } } @@ -663,7 +670,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"ReplicaUpdateProof\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ReplicaUpdateProof"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ReplicaUpdateProof"))); err != nil { return err } if _, err := io.WriteString(w, string("ReplicaUpdateProof")); err != nil { @@ -674,11 +681,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.ReplicaUpdateProof was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.ReplicaUpdateProof))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.ReplicaUpdateProof))); err != nil { return err } - if _, err := w.Write(t.ReplicaUpdateProof[:]); err != nil { + if _, err := cw.Write(t.ReplicaUpdateProof[:]); err != nil { return err } @@ -687,7 +694,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"ReplicaUpdateMessage\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ReplicaUpdateMessage"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ReplicaUpdateMessage"))); err != nil { return err } if _, err := io.WriteString(w, string("ReplicaUpdateMessage")); err != nil { @@ -695,11 +702,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.ReplicaUpdateMessage == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.ReplicaUpdateMessage); err != nil { + if err := cbg.WriteCid(cw, *t.ReplicaUpdateMessage); err != nil { return xerrors.Errorf("failed to write cid field t.ReplicaUpdateMessage: %w", err) } } @@ -709,7 +716,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"FaultReportMsg\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("FaultReportMsg"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("FaultReportMsg"))); err != nil { return err } if _, err := io.WriteString(w, string("FaultReportMsg")); err != nil { @@ -717,11 +724,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.FaultReportMsg == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.FaultReportMsg); err != nil { + if err := cbg.WriteCid(cw, *t.FaultReportMsg); err != nil { return xerrors.Errorf("failed to write cid field t.FaultReportMsg: %w", err) } } @@ -731,7 +738,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Return\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Return"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Return"))); err != nil { return err } if _, err := io.WriteString(w, string("Return")); err != nil { @@ -742,7 +749,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Return was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Return))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Return))); err != nil { return err } if _, err := io.WriteString(w, string(t.Return)); err != nil { @@ -754,7 +761,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"TerminateMessage\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TerminateMessage"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("TerminateMessage"))); err != nil { return err } if _, err := io.WriteString(w, string("TerminateMessage")); err != nil { @@ -762,11 +769,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.TerminateMessage == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.TerminateMessage); err != nil { + if err := cbg.WriteCid(cw, *t.TerminateMessage); err != nil { return xerrors.Errorf("failed to write cid field t.TerminateMessage: %w", err) } } @@ -776,7 +783,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"TerminatedAt\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("TerminatedAt"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("TerminatedAt"))); err != nil { return err } if _, err := io.WriteString(w, string("TerminatedAt")); err != nil { @@ -784,11 +791,11 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } if t.TerminatedAt >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TerminatedAt)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.TerminatedAt)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TerminatedAt-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.TerminatedAt-1)); err != nil { return err } } @@ -798,7 +805,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"LastErr\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("LastErr"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("LastErr"))); err != nil { return err } if _, err := io.WriteString(w, string("LastErr")); err != nil { @@ -809,7 +816,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.LastErr was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.LastErr))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.LastErr))); err != nil { return err } if _, err := io.WriteString(w, string(t.LastErr)); err != nil { @@ -821,7 +828,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Log\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Log"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Log"))); err != nil { return err } if _, err := io.WriteString(w, string("Log")); err != nil { @@ -832,27 +839,32 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Log was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Log))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Log))); err != nil { return err } for _, v := range t.Log { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } return nil } -func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { +func (t *SectorInfo) UnmarshalCBOR(r io.Reader) (err error) { *t = SectorInfo{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -867,7 +879,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -880,7 +892,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { case "State": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -892,7 +904,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -905,7 +917,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.SectorType (abi.RegisteredSealProof) (int64) case "SectorType": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -931,7 +943,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.CreationTime (int64) (int64) case "CreationTime": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -957,7 +969,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.Pieces ([]sealing.Piece) (slice) case "Pieces": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -977,7 +989,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v Piece - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -987,7 +999,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.TicketValue (abi.SealRandomness) (slice) case "TicketValue": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1003,13 +1015,13 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { t.TicketValue = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.TicketValue[:]); err != nil { + if _, err := io.ReadFull(cr, t.TicketValue[:]); err != nil { return err } // t.TicketEpoch (abi.ChainEpoch) (int64) case "TicketEpoch": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1035,7 +1047,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.PreCommit1Out (storage.PreCommit1Out) (slice) case "PreCommit1Out": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1051,7 +1063,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { t.PreCommit1Out = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.PreCommit1Out[:]); err != nil { + if _, err := io.ReadFull(cr, t.PreCommit1Out[:]); err != nil { return err } // t.CommD (cid.Cid) (struct) @@ -1059,16 +1071,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.CommD: %w", err) } @@ -1082,16 +1094,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.CommR: %w", err) } @@ -1103,7 +1115,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.Proof ([]uint8) (slice) case "Proof": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1119,7 +1131,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { t.Proof = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Proof[:]); err != nil { + if _, err := io.ReadFull(cr, t.Proof[:]); err != nil { return err } // t.PreCommitInfo (miner.SectorPreCommitInfo) (struct) @@ -1127,16 +1139,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.PreCommitInfo = new(miner.SectorPreCommitInfo) - if err := t.PreCommitInfo.UnmarshalCBOR(br); err != nil { + if err := t.PreCommitInfo.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.PreCommitInfo pointer: %w", err) } } @@ -1147,7 +1159,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.PreCommitDeposit.UnmarshalCBOR(br); err != nil { + if err := t.PreCommitDeposit.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.PreCommitDeposit: %w", err) } @@ -1157,16 +1169,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.PreCommitMessage: %w", err) } @@ -1178,7 +1190,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.PreCommitTipSet (sealing.TipSetToken) (slice) case "PreCommitTipSet": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1194,7 +1206,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { t.PreCommitTipSet = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.PreCommitTipSet[:]); err != nil { + if _, err := io.ReadFull(cr, t.PreCommitTipSet[:]); err != nil { return err } // t.PreCommit2Fails (uint64) (uint64) @@ -1202,7 +1214,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1215,7 +1227,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.SeedValue (abi.InteractiveSealRandomness) (slice) case "SeedValue": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1231,13 +1243,13 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { t.SeedValue = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.SeedValue[:]); err != nil { + if _, err := io.ReadFull(cr, t.SeedValue[:]); err != nil { return err } // t.SeedEpoch (abi.ChainEpoch) (int64) case "SeedEpoch": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1265,16 +1277,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.CommitMessage: %w", err) } @@ -1288,7 +1300,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1301,7 +1313,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.CCUpdate (bool) (bool) case "CCUpdate": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1319,7 +1331,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.CCPieces ([]sealing.Piece) (slice) case "CCPieces": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1339,7 +1351,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v Piece - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -1351,16 +1363,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.UpdateSealed: %w", err) } @@ -1374,16 +1386,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.UpdateUnsealed: %w", err) } @@ -1395,7 +1407,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.ReplicaUpdateProof (storage.ReplicaUpdateProof) (slice) case "ReplicaUpdateProof": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1411,7 +1423,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { t.ReplicaUpdateProof = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.ReplicaUpdateProof[:]); err != nil { + if _, err := io.ReadFull(cr, t.ReplicaUpdateProof[:]); err != nil { return err } // t.ReplicaUpdateMessage (cid.Cid) (struct) @@ -1419,16 +1431,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.ReplicaUpdateMessage: %w", err) } @@ -1442,16 +1454,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.FaultReportMsg: %w", err) } @@ -1464,7 +1476,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { case "Return": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -1476,16 +1488,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.TerminateMessage: %w", err) } @@ -1497,7 +1509,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.TerminatedAt (abi.ChainEpoch) (int64) case "TerminatedAt": { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -1524,7 +1536,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { case "LastErr": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -1534,7 +1546,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { // t.Log ([]sealing.Log) (slice) case "Log": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1554,7 +1566,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v Log - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -1574,25 +1586,26 @@ func (t *Log) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{164}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{164}); err != nil { return err } - scratch := make([]byte, 9) - // t.Timestamp (uint64) (uint64) if len("Timestamp") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Timestamp\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Timestamp"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Timestamp"))); err != nil { return err } if _, err := io.WriteString(w, string("Timestamp")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Timestamp)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Timestamp)); err != nil { return err } @@ -1601,7 +1614,7 @@ func (t *Log) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Trace\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Trace"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Trace"))); err != nil { return err } if _, err := io.WriteString(w, string("Trace")); err != nil { @@ -1612,7 +1625,7 @@ func (t *Log) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Trace was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Trace))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Trace))); err != nil { return err } if _, err := io.WriteString(w, string(t.Trace)); err != nil { @@ -1624,7 +1637,7 @@ func (t *Log) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Message\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Message"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Message"))); err != nil { return err } if _, err := io.WriteString(w, string("Message")); err != nil { @@ -1635,7 +1648,7 @@ func (t *Log) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Message was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Message))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Message))); err != nil { return err } if _, err := io.WriteString(w, string(t.Message)); err != nil { @@ -1647,7 +1660,7 @@ func (t *Log) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Kind\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Kind"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Kind"))); err != nil { return err } if _, err := io.WriteString(w, string("Kind")); err != nil { @@ -1658,7 +1671,7 @@ func (t *Log) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Kind was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Kind))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Kind))); err != nil { return err } if _, err := io.WriteString(w, string(t.Kind)); err != nil { @@ -1667,16 +1680,21 @@ func (t *Log) MarshalCBOR(w io.Writer) error { return nil } -func (t *Log) UnmarshalCBOR(r io.Reader) error { +func (t *Log) UnmarshalCBOR(r io.Reader) (err error) { *t = Log{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -1691,7 +1709,7 @@ func (t *Log) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -1705,7 +1723,7 @@ func (t *Log) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -1719,7 +1737,7 @@ func (t *Log) UnmarshalCBOR(r io.Reader) error { case "Trace": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -1730,7 +1748,7 @@ func (t *Log) UnmarshalCBOR(r io.Reader) error { case "Message": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -1741,7 +1759,7 @@ func (t *Log) UnmarshalCBOR(r io.Reader) error { case "Kind": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } diff --git a/extern/storage-sealing/checks.go b/extern/storage-sealing/checks.go index dc045ded2..4aa00c34e 100644 --- a/extern/storage-sealing/checks.go +++ b/extern/storage-sealing/checks.go @@ -4,9 +4,9 @@ import ( "bytes" "context" - "github.com/filecoin-project/lotus/chain/actors/policy" + prooftypes "github.com/filecoin-project/go-state-types/proof" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" + "github.com/filecoin-project/lotus/chain/actors/policy" "golang.org/x/xerrors" @@ -177,7 +177,7 @@ func (m *Sealing) checkCommit(ctx context.Context, si SectorInfo, proof []byte, log.Warn("on-chain sealed CID doesn't match!") } - ok, err := m.verif.VerifySeal(proof2.SealVerifyInfo{ + ok, err := m.verif.VerifySeal(prooftypes.SealVerifyInfo{ SectorID: m.minerSectorID(si.SectorNumber), SealedCID: pci.Info.SealedCID, SealProof: pci.Info.SealProof, diff --git a/extern/storage-sealing/commit_batch.go b/extern/storage-sealing/commit_batch.go index 1c55b6700..f2a665293 100644 --- a/extern/storage-sealing/commit_batch.go +++ b/extern/storage-sealing/commit_batch.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "github.com/filecoin-project/go-state-types/proof" + "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -14,14 +16,12 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/go-state-types/network" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" - "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" @@ -29,8 +29,6 @@ import ( "github.com/filecoin-project/lotus/node/config" ) -const arp = abi.RegisteredAggregationProof_SnarkPackV1 - var aggFeeNum = big.NewInt(110) var aggFeeDen = big.NewInt(100) @@ -38,7 +36,7 @@ var aggFeeDen = big.NewInt(100) type CommitBatcherApi interface { SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error) - StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error) + StateMinerInfo(context.Context, address.Address, TipSetToken) (api.MinerInfo, error) ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error) ChainBaseFee(context.Context, TipSetToken) (abi.TokenAmount, error) @@ -50,7 +48,7 @@ type CommitBatcherApi interface { type AggregateInput struct { Spt abi.RegisteredSealProof - Info proof5.AggregateSealVerifyInfo + Info proof.AggregateSealVerifyInfo Proof []byte } @@ -206,13 +204,22 @@ func (b *CommitBatcher) maybeStartBatch(notif bool) ([]sealiface.CommitBatchRes, var res []sealiface.CommitBatchRes - individual := (total < cfg.MinCommitBatch) || (total < miner5.MinAggregatedSectors) + tok, h, err := b.api.ChainHead(b.mctx) + if err != nil { + return nil, err + } + + blackedOut := func() bool { + const nv16BlackoutWindow = abi.ChainEpoch(20) // a magik number + if h <= build.UpgradeSkyrHeight && build.UpgradeSkyrHeight-h < nv16BlackoutWindow { + return true + } + return false + } + + individual := (total < cfg.MinCommitBatch) || (total < miner.MinAggregatedSectors) || blackedOut() if !individual && !cfg.AggregateAboveBaseFee.Equals(big.Zero()) { - tok, _, err := b.api.ChainHead(b.mctx) - if err != nil { - return nil, err - } bf, err := b.api.ChainBaseFee(b.mctx, tok) if err != nil { @@ -269,12 +276,12 @@ func (b *CommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.CommitBa FailedSectors: map[abi.SectorNumber]string{}, } - params := miner5.ProveCommitAggregateParams{ + params := miner.ProveCommitAggregateParams{ SectorNumbers: bitfield.New(), } proofs := make([][]byte, 0, total) - infos := make([]proof5.AggregateSealVerifyInfo, 0, total) + infos := make([]proof.AggregateSealVerifyInfo, 0, total) collateral := big.Zero() for id, p := range b.todo { @@ -314,7 +321,18 @@ func (b *CommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.CommitBa return []sealiface.CommitBatchRes{res}, xerrors.Errorf("getting miner id: %w", err) } - params.AggregateProof, err = b.prover.AggregateSealProofs(proof5.AggregateSealVerifyProofAndInfos{ + nv, err := b.api.StateNetworkVersion(b.mctx, tok) + if err != nil { + log.Errorf("getting network version: %s", err) + return []sealiface.CommitBatchRes{res}, xerrors.Errorf("getting network version: %s", err) + } + + arp, err := b.aggregateProofType(nv) + if err != nil { + return []sealiface.CommitBatchRes{res}, xerrors.Errorf("getting aggregate proof type: %w", err) + } + + params.AggregateProof, err = b.prover.AggregateSealProofs(proof.AggregateSealVerifyProofAndInfos{ Miner: abi.ActorID(mid), SealProof: b.todo[infos[0].Number].Spt, AggregateProof: arp, @@ -341,12 +359,6 @@ func (b *CommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.CommitBa return []sealiface.CommitBatchRes{res}, xerrors.Errorf("couldn't get base fee: %w", err) } - nv, err := b.api.StateNetworkVersion(b.mctx, tok) - if err != nil { - log.Errorf("getting network version: %s", err) - return []sealiface.CommitBatchRes{res}, xerrors.Errorf("getting network version: %s", err) - } - aggFeeRaw, err := policy.AggregateProveCommitNetworkFee(nv, len(infos), bf) if err != nil { log.Errorf("getting aggregate commit network fee: %s", err) @@ -368,7 +380,7 @@ func (b *CommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.CommitBa return []sealiface.CommitBatchRes{res}, xerrors.Errorf("no good address found: %w", err) } - mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, miner.Methods.ProveCommitAggregate, needFunds, maxFee, enc.Bytes()) + mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, builtin.MethodsMiner.ProveCommitAggregate, needFunds, maxFee, enc.Bytes()) if err != nil { return []sealiface.CommitBatchRes{res}, xerrors.Errorf("sending message failed: %w", err) } @@ -427,7 +439,7 @@ func (b *CommitBatcher) processIndividually(cfg sealiface.Config) ([]sealiface.C return res, nil } -func (b *CommitBatcher) processSingle(cfg sealiface.Config, mi miner.MinerInfo, avail *abi.TokenAmount, sn abi.SectorNumber, info AggregateInput, tok TipSetToken) (cid.Cid, error) { +func (b *CommitBatcher) processSingle(cfg sealiface.Config, mi api.MinerInfo, avail *abi.TokenAmount, sn abi.SectorNumber, info AggregateInput, tok TipSetToken) (cid.Cid, error) { enc := new(bytes.Buffer) params := &miner.ProveCommitSectorParams{ SectorNumber: sn, @@ -463,7 +475,7 @@ func (b *CommitBatcher) processSingle(cfg sealiface.Config, mi miner.MinerInfo, return cid.Undef, xerrors.Errorf("no good address to send commit message from: %w", err) } - mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, miner.Methods.ProveCommitSector, collateral, big.Int(b.feeCfg.MaxCommitGasFee), enc.Bytes()) + mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, builtin.MethodsMiner.ProveCommitSector, collateral, big.Int(b.feeCfg.MaxCommitGasFee), enc.Bytes()) if err != nil { return cid.Undef, xerrors.Errorf("pushing message to mpool: %w", err) } @@ -625,3 +637,9 @@ func (b *CommitBatcher) getSectorCollateral(sn abi.SectorNumber, tok TipSetToken return collateral, nil } +func (b *CommitBatcher) aggregateProofType(nv network.Version) (abi.RegisteredAggregationProof, error) { + if nv < network.Version16 { + return abi.RegisteredAggregationProof_SnarkPackV1, nil + } + return abi.RegisteredAggregationProof_SnarkPackV2, nil +} diff --git a/extern/storage-sealing/commit_batch_test.go b/extern/storage-sealing/commit_batch_test.go index 3bda6d3fd..17988ed92 100644 --- a/extern/storage-sealing/commit_batch_test.go +++ b/extern/storage-sealing/commit_batch_test.go @@ -9,6 +9,10 @@ import ( "testing" "time" + prooftypes "github.com/filecoin-project/go-state-types/proof" + + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" @@ -16,16 +20,13 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" - "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" "github.com/filecoin-project/lotus/extern/storage-sealing/mocks" "github.com/filecoin-project/lotus/extern/storage-sealing/sealiface" + miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" ) func TestCommitBatcher(t *testing.T) { @@ -35,7 +36,7 @@ func TestCommitBatcher(t *testing.T) { ctx := context.Background() - as := func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { + as := func(ctx context.Context, mi api.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { return t0123, big.Zero(), nil } @@ -107,14 +108,14 @@ func TestCommitBatcher(t *testing.T) { s.EXPECT().ChainHead(gomock.Any()).Return(nil, abi.ChainEpoch(1), nil) s.EXPECT().StateNetworkVersion(gomock.Any(), gomock.Any()).Return(network.Version13, nil) - s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&miner.SectorPreCommitOnChainInfo{ + s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&minertypes.SectorPreCommitOnChainInfo{ PreCommitDeposit: big.Zero(), }, nil) go func() { defer done.Unlock() pcres, pcerr = pcb.AddCommit(ctx, si, sealing.AggregateInput{ - Info: proof5.AggregateSealVerifyInfo{ + Info: prooftypes.AggregateSealVerifyInfo{ Number: sn, }, }) @@ -152,7 +153,7 @@ func TestCommitBatcher(t *testing.T) { //stm: @CHAIN_STATE_MINER_INFO_001, @CHAIN_STATE_NETWORK_VERSION_001, @CHAIN_STATE_MINER_GET_COLLATERAL_001 expectSend := func(expect []abi.SectorNumber, aboveBalancer, failOnePCI bool) action { return func(t *testing.T, s *mocks.MockCommitBatcherApi, pcb *sealing.CommitBatcher) promise { - s.EXPECT().StateMinerInfo(gomock.Any(), gomock.Any(), gomock.Any()).Return(miner.MinerInfo{Owner: t0123, Worker: t0123}, nil) + s.EXPECT().StateMinerInfo(gomock.Any(), gomock.Any(), gomock.Any()).Return(api.MinerInfo{Owner: t0123, Worker: t0123}, nil) ti := len(expect) batch := false @@ -166,8 +167,8 @@ func TestCommitBatcher(t *testing.T) { basefee = types.NanoFil } + s.EXPECT().ChainHead(gomock.Any()).Return(nil, abi.ChainEpoch(1), nil) if batch { - s.EXPECT().ChainHead(gomock.Any()).Return(nil, abi.ChainEpoch(1), nil) s.EXPECT().ChainBaseFee(gomock.Any(), gomock.Any()).Return(basefee, nil) } @@ -186,7 +187,7 @@ func TestCommitBatcher(t *testing.T) { ti-- } } - s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&miner.SectorPreCommitOnChainInfo{ + s.EXPECT().StateSectorPreCommitInfo(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(&minertypes.SectorPreCommitOnChainInfo{ PreCommitDeposit: big.Zero(), }, nil).Times(pciC) s.EXPECT().StateMinerInitialPledgeCollateral(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(big.Zero(), nil).Times(pciC) @@ -380,7 +381,7 @@ func TestCommitBatcher(t *testing.T) { type fakeProver struct{} -func (f fakeProver) AggregateSealProofs(aggregateInfo proof5.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) { +func (f fakeProver) AggregateSealProofs(aggregateInfo prooftypes.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) { return []byte("Trust me, I'm a proof"), nil } diff --git a/extern/storage-sealing/currentdealinfo.go b/extern/storage-sealing/currentdealinfo.go index 06c24163b..542792696 100644 --- a/extern/storage-sealing/currentdealinfo.go +++ b/extern/storage-sealing/currentdealinfo.go @@ -5,15 +5,16 @@ import ( "context" "fmt" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" + "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/types" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" "github.com/ipfs/go-cid" "golang.org/x/xerrors" ) @@ -121,7 +122,7 @@ func (mgr *CurrentDealInfoManager) dealIDFromPublishDealsMsg(ctx context.Context return dealID, nil, xerrors.Errorf("getting publish deal message %s: %w", publishCid, err) } - var pubDealsParams market2.PublishStorageDealsParams + var pubDealsParams market8.PublishStorageDealsParams if err := pubDealsParams.UnmarshalCBOR(bytes.NewReader(pubmsg.Params)); err != nil { return dealID, nil, xerrors.Errorf("unmarshalling publish deal message params for message %s: %w", publishCid, err) } @@ -130,7 +131,7 @@ func (mgr *CurrentDealInfoManager) dealIDFromPublishDealsMsg(ctx context.Context // index of the target deal proposal dealIdx := -1 for i, paramDeal := range pubDealsParams.Deals { - eq, err := mgr.CheckDealEquality(ctx, tok, *proposal, market.DealProposal(paramDeal.Proposal)) + eq, err := mgr.CheckDealEquality(ctx, tok, *proposal, paramDeal.Proposal) if err != nil { return dealID, nil, xerrors.Errorf("comparing publish deal message %s proposal to deal proposal: %w", publishCid, err) } @@ -180,7 +181,7 @@ func (mgr *CurrentDealInfoManager) CheckDealEquality(ctx context.Context, tok Ti return p1.PieceCID.Equals(p2.PieceCID) && p1.PieceSize == p2.PieceSize && p1.VerifiedDeal == p2.VerifiedDeal && - p1.Label == p2.Label && + p1.Label.Equals(p2.Label) && p1.StartEpoch == p2.StartEpoch && p1.EndEpoch == p2.EndEpoch && p1.StoragePricePerEpoch.Equals(p2.StoragePricePerEpoch) && diff --git a/extern/storage-sealing/currentdealinfo_test.go b/extern/storage-sealing/currentdealinfo_test.go index 31d538190..5f889467a 100644 --- a/extern/storage-sealing/currentdealinfo_test.go +++ b/extern/storage-sealing/currentdealinfo_test.go @@ -9,10 +9,12 @@ import ( "time" "github.com/filecoin-project/go-bitfield" + + markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/filecoin-project/go-state-types/network" market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" - market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market" "golang.org/x/net/context" "golang.org/x/xerrors" @@ -25,7 +27,6 @@ import ( "github.com/filecoin-project/lotus/chain/actors/builtin/market" evtmock "github.com/filecoin-project/lotus/chain/events/state/mock" "github.com/filecoin-project/lotus/chain/types" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" tutils "github.com/filecoin-project/specs-actors/v2/support/testing" "github.com/ipfs/go-cid" "github.com/stretchr/testify/require" @@ -34,6 +35,15 @@ import ( var errNotFound = errors.New("could not find") func TestGetCurrentDealInfo(t *testing.T) { + success, err := markettypes.NewLabelFromString("success") + require.NoError(t, err) + + other, err := markettypes.NewLabelFromString("other") + require.NoError(t, err) + + another, err := markettypes.NewLabelFromString("another") + require.NoError(t, err) + ctx := context.Background() dummyCid, _ := cid.Parse("bafkqaaa") dummyCid2, _ := cid.Parse("bafkqaab") @@ -49,7 +59,7 @@ func TestGetCurrentDealInfo(t *testing.T) { StoragePricePerEpoch: abi.NewTokenAmount(1), ProviderCollateral: abi.NewTokenAmount(1), ClientCollateral: abi.NewTokenAmount(1), - Label: "success", + Label: success, } otherProposal := market.DealProposal{ PieceCID: dummyCid2, @@ -59,7 +69,7 @@ func TestGetCurrentDealInfo(t *testing.T) { StoragePricePerEpoch: abi.NewTokenAmount(1), ProviderCollateral: abi.NewTokenAmount(1), ClientCollateral: abi.NewTokenAmount(1), - Label: "other", + Label: other, } anotherProposal := market.DealProposal{ PieceCID: dummyCid2, @@ -69,7 +79,7 @@ func TestGetCurrentDealInfo(t *testing.T) { StoragePricePerEpoch: abi.NewTokenAmount(1), ProviderCollateral: abi.NewTokenAmount(1), ClientCollateral: abi.NewTokenAmount(1), - Label: "another", + Label: another, } successDeal := &api.MarketDeal{ Proposal: proposal, @@ -328,11 +338,11 @@ func (mapi *CurrentDealInfoMockAPI) ChainGetMessage(ctx context.Context, c cid.C return keys[i].DealID < keys[j].DealID }) - var deals []market2.ClientDealProposal + var deals []markettypes.ClientDealProposal for _, k := range keys { dl := mapi.MarketDeals[k] - deals = append(deals, market2.ClientDealProposal{ - Proposal: market2.DealProposal(dl.Proposal), + deals = append(deals, markettypes.ClientDealProposal{ + Proposal: dl.Proposal, ClientSignature: crypto.Signature{ Data: []byte("foo bar cat dog"), Type: crypto.SigTypeBLS, @@ -341,7 +351,7 @@ func (mapi *CurrentDealInfoMockAPI) ChainGetMessage(ctx context.Context, c cid.C } buf := new(bytes.Buffer) - params := market2.PublishStorageDealsParams{Deals: deals} + params := markettypes.PublishStorageDealsParams{Deals: deals} err := params.MarshalCBOR(buf) if err != nil { panic(err) @@ -393,7 +403,7 @@ func makePublishDealsReturnBytesOldVersion(t *testing.T, dealIDs []abi.DealID) [ func makePublishDealsReturn(t *testing.T, dealIDs []abi.DealID, validIdxs []uint64) []byte { buf := new(bytes.Buffer) - dealsReturn := market7.PublishStorageDealsReturn{ + dealsReturn := markettypes.PublishStorageDealsReturn{ IDs: dealIDs, ValidDeals: bitfield.NewFromSet(validIdxs), } diff --git a/extern/storage-sealing/fsm_events.go b/extern/storage-sealing/fsm_events.go index 66497473f..621b90aaf 100644 --- a/extern/storage-sealing/fsm_events.go +++ b/extern/storage-sealing/fsm_events.go @@ -10,7 +10,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/specs-storage/storage" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" ) type mutator interface { diff --git a/extern/storage-sealing/mocks/api.go b/extern/storage-sealing/mocks/api.go index efe89ff0b..cd1b66d34 100644 --- a/extern/storage-sealing/mocks/api.go +++ b/extern/storage-sealing/mocks/api.go @@ -12,15 +12,14 @@ import ( bitfield "github.com/filecoin-project/go-bitfield" abi "github.com/filecoin-project/go-state-types/abi" big "github.com/filecoin-project/go-state-types/big" + market "github.com/filecoin-project/go-state-types/builtin/v8/market" + miner "github.com/filecoin-project/go-state-types/builtin/v8/miner" crypto "github.com/filecoin-project/go-state-types/crypto" dline "github.com/filecoin-project/go-state-types/dline" network "github.com/filecoin-project/go-state-types/network" api "github.com/filecoin-project/lotus/api" - market "github.com/filecoin-project/lotus/chain/actors/builtin/market" - miner "github.com/filecoin-project/lotus/chain/actors/builtin/miner" types "github.com/filecoin-project/lotus/chain/types" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" gomock "github.com/golang/mock/gomock" cid "github.com/ipfs/go-cid" ) @@ -245,10 +244,10 @@ func (mr *MockSealingAPIMockRecorder) StateMinerAvailableBalance(arg0, arg1, arg } // StateMinerInfo mocks base method. -func (m *MockSealingAPI) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (miner.MinerInfo, error) { +func (m *MockSealingAPI) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (api.MinerInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInfo", arg0, arg1, arg2) - ret0, _ := ret[0].(miner.MinerInfo) + ret0, _ := ret[0].(api.MinerInfo) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -260,7 +259,7 @@ func (mr *MockSealingAPIMockRecorder) StateMinerInfo(arg0, arg1, arg2 interface{ } // StateMinerInitialPledgeCollateral mocks base method. -func (m *MockSealingAPI) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner0.SectorPreCommitInfo, arg3 sealing.TipSetToken) (big.Int, error) { +func (m *MockSealingAPI) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner.SectorPreCommitInfo, arg3 sealing.TipSetToken) (big.Int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInitialPledgeCollateral", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(big.Int) @@ -290,7 +289,7 @@ func (mr *MockSealingAPIMockRecorder) StateMinerPartitions(arg0, arg1, arg2, arg } // StateMinerPreCommitDepositForPower mocks base method. -func (m *MockSealingAPI) StateMinerPreCommitDepositForPower(arg0 context.Context, arg1 address.Address, arg2 miner0.SectorPreCommitInfo, arg3 sealing.TipSetToken) (big.Int, error) { +func (m *MockSealingAPI) StateMinerPreCommitDepositForPower(arg0 context.Context, arg1 address.Address, arg2 miner.SectorPreCommitInfo, arg3 sealing.TipSetToken) (big.Int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerPreCommitDepositForPower", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(big.Int) diff --git a/extern/storage-sealing/mocks/mock_commit_batcher.go b/extern/storage-sealing/mocks/mock_commit_batcher.go index 061121899..7285f7ea5 100644 --- a/extern/storage-sealing/mocks/mock_commit_batcher.go +++ b/extern/storage-sealing/mocks/mock_commit_batcher.go @@ -11,10 +11,10 @@ import ( address "github.com/filecoin-project/go-address" abi "github.com/filecoin-project/go-state-types/abi" big "github.com/filecoin-project/go-state-types/big" + miner "github.com/filecoin-project/go-state-types/builtin/v8/miner" network "github.com/filecoin-project/go-state-types/network" - miner "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + api "github.com/filecoin-project/lotus/api" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" gomock "github.com/golang/mock/gomock" cid "github.com/ipfs/go-cid" ) @@ -104,10 +104,10 @@ func (mr *MockCommitBatcherApiMockRecorder) StateMinerAvailableBalance(arg0, arg } // StateMinerInfo mocks base method. -func (m *MockCommitBatcherApi) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (miner.MinerInfo, error) { +func (m *MockCommitBatcherApi) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (api.MinerInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInfo", arg0, arg1, arg2) - ret0, _ := ret[0].(miner.MinerInfo) + ret0, _ := ret[0].(api.MinerInfo) ret1, _ := ret[1].(error) return ret0, ret1 } @@ -119,7 +119,7 @@ func (mr *MockCommitBatcherApiMockRecorder) StateMinerInfo(arg0, arg1, arg2 inte } // StateMinerInitialPledgeCollateral mocks base method. -func (m *MockCommitBatcherApi) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner0.SectorPreCommitInfo, arg3 sealing.TipSetToken) (big.Int, error) { +func (m *MockCommitBatcherApi) StateMinerInitialPledgeCollateral(arg0 context.Context, arg1 address.Address, arg2 miner.SectorPreCommitInfo, arg3 sealing.TipSetToken) (big.Int, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInitialPledgeCollateral", arg0, arg1, arg2, arg3) ret0, _ := ret[0].(big.Int) diff --git a/extern/storage-sealing/mocks/mock_precommit_batcher.go b/extern/storage-sealing/mocks/mock_precommit_batcher.go index fe7424d35..914fcd56d 100644 --- a/extern/storage-sealing/mocks/mock_precommit_batcher.go +++ b/extern/storage-sealing/mocks/mock_precommit_batcher.go @@ -12,7 +12,7 @@ import ( abi "github.com/filecoin-project/go-state-types/abi" big "github.com/filecoin-project/go-state-types/big" network "github.com/filecoin-project/go-state-types/network" - miner "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + api "github.com/filecoin-project/lotus/api" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" gomock "github.com/golang/mock/gomock" cid "github.com/ipfs/go-cid" @@ -103,10 +103,10 @@ func (mr *MockPreCommitBatcherApiMockRecorder) StateMinerAvailableBalance(arg0, } // StateMinerInfo mocks base method. -func (m *MockPreCommitBatcherApi) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (miner.MinerInfo, error) { +func (m *MockPreCommitBatcherApi) StateMinerInfo(arg0 context.Context, arg1 address.Address, arg2 sealing.TipSetToken) (api.MinerInfo, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "StateMinerInfo", arg0, arg1, arg2) - ret0, _ := ret[0].(miner.MinerInfo) + ret0, _ := ret[0].(api.MinerInfo) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/extern/storage-sealing/precommit_batch.go b/extern/storage-sealing/precommit_batch.go index 2a8168a4a..02cce8c38 100644 --- a/extern/storage-sealing/precommit_batch.go +++ b/extern/storage-sealing/precommit_batch.go @@ -15,12 +15,12 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/storage-sealing/sealiface" @@ -31,7 +31,7 @@ import ( type PreCommitBatcherApi interface { SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error) - StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error) + StateMinerInfo(context.Context, address.Address, TipSetToken) (api.MinerInfo, error) StateMinerAvailableBalance(context.Context, address.Address, TipSetToken) (big.Int, error) ChainHead(ctx context.Context) (TipSetToken, abi.ChainEpoch, error) ChainBaseFee(context.Context, TipSetToken) (abi.TokenAmount, error) @@ -40,7 +40,7 @@ type PreCommitBatcherApi interface { type preCommitEntry struct { deposit abi.TokenAmount - pci *miner0.SectorPreCommitInfo + pci *miner.SectorPreCommitInfo } type PreCommitBatcher struct { @@ -281,7 +281,7 @@ func (b *PreCommitBatcher) processIndividually(cfg sealiface.Config) ([]sealifac return res, nil } -func (b *PreCommitBatcher) processSingle(cfg sealiface.Config, mi miner.MinerInfo, avail *abi.TokenAmount, params *preCommitEntry) (cid.Cid, error) { +func (b *PreCommitBatcher) processSingle(cfg sealiface.Config, mi api.MinerInfo, avail *abi.TokenAmount, params *preCommitEntry) (cid.Cid, error) { enc := new(bytes.Buffer) if err := params.pci.MarshalCBOR(enc); err != nil { @@ -309,7 +309,7 @@ func (b *PreCommitBatcher) processSingle(cfg sealiface.Config, mi miner.MinerInf return cid.Undef, xerrors.Errorf("no good address to send precommit message from: %w", err) } - mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, miner.Methods.PreCommitSector, deposit, big.Int(b.feeCfg.MaxPreCommitGasFee), enc.Bytes()) + mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, builtin.MethodsMiner.PreCommitSector, deposit, big.Int(b.feeCfg.MaxPreCommitGasFee), enc.Bytes()) if err != nil { return cid.Undef, xerrors.Errorf("pushing message to mpool: %w", err) } @@ -318,7 +318,7 @@ func (b *PreCommitBatcher) processSingle(cfg sealiface.Config, mi miner.MinerInf } func (b *PreCommitBatcher) processBatch(cfg sealiface.Config, tok TipSetToken, bf abi.TokenAmount, nv network.Version) ([]sealiface.PreCommitBatchRes, error) { - params := miner5.PreCommitSectorBatchParams{} + params := miner.PreCommitSectorBatchParams{} deposit := big.Zero() var res sealiface.PreCommitBatchRes @@ -366,7 +366,7 @@ func (b *PreCommitBatcher) processBatch(cfg sealiface.Config, tok TipSetToken, b return []sealiface.PreCommitBatchRes{res}, xerrors.Errorf("no good address found: %w", err) } - mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, miner.Methods.PreCommitSectorBatch, needFunds, maxFee, enc.Bytes()) + mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, builtin.MethodsMiner.PreCommitSectorBatch, needFunds, maxFee, enc.Bytes()) if err != nil { return []sealiface.PreCommitBatchRes{res}, xerrors.Errorf("sending message failed: %w", err) } @@ -379,7 +379,7 @@ func (b *PreCommitBatcher) processBatch(cfg sealiface.Config, tok TipSetToken, b } // register PreCommit, wait for batch message, return message CID -func (b *PreCommitBatcher) AddPreCommit(ctx context.Context, s SectorInfo, deposit abi.TokenAmount, in *miner0.SectorPreCommitInfo) (res sealiface.PreCommitBatchRes, err error) { +func (b *PreCommitBatcher) AddPreCommit(ctx context.Context, s SectorInfo, deposit abi.TokenAmount, in *miner.SectorPreCommitInfo) (res sealiface.PreCommitBatchRes, err error) { _, curEpoch, err := b.api.ChainHead(b.mctx) if err != nil { log.Errorf("getting chain head: %s", err) diff --git a/extern/storage-sealing/precommit_batch_test.go b/extern/storage-sealing/precommit_batch_test.go index a90645a05..e2cea330e 100644 --- a/extern/storage-sealing/precommit_batch_test.go +++ b/extern/storage-sealing/precommit_batch_test.go @@ -9,6 +9,8 @@ import ( "testing" "time" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + miner6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner" "github.com/filecoin-project/go-state-types/network" @@ -21,13 +23,11 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" "github.com/filecoin-project/lotus/extern/storage-sealing/mocks" "github.com/filecoin-project/lotus/extern/storage-sealing/sealiface" "github.com/filecoin-project/lotus/node/config" - miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner" ) var fc = config.MinerFeeConfig{ @@ -45,7 +45,7 @@ func TestPrecommitBatcher(t *testing.T) { ctx := context.Background() - as := func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { + as := func(ctx context.Context, mi api.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { return t0123, big.Zero(), nil } @@ -116,7 +116,7 @@ func TestPrecommitBatcher(t *testing.T) { go func() { defer done.Unlock() - pcres, pcerr = pcb.AddPreCommit(ctx, si, big.Zero(), &miner0.SectorPreCommitInfo{ + pcres, pcerr = pcb.AddPreCommit(ctx, si, big.Zero(), &minertypes.SectorPreCommitInfo{ SectorNumber: si.SectorNumber, SealedCID: fakePieceCid(t), DealIDs: nil, @@ -160,7 +160,7 @@ func TestPrecommitBatcher(t *testing.T) { s.EXPECT().ChainBaseFee(gomock.Any(), gomock.Any()).Return(big.NewInt(10001), nil) s.EXPECT().StateNetworkVersion(gomock.Any(), gomock.Any()).Return(network.Version14, nil) - s.EXPECT().StateMinerInfo(gomock.Any(), gomock.Any(), gomock.Any()).Return(miner.MinerInfo{Owner: t0123, Worker: t0123}, nil) + s.EXPECT().StateMinerInfo(gomock.Any(), gomock.Any(), gomock.Any()).Return(api.MinerInfo{Owner: t0123, Worker: t0123}, nil) s.EXPECT().SendMsg(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), funMatcher(func(i interface{}) bool { b := i.([]byte) var params miner6.PreCommitSectorBatchParams @@ -181,7 +181,7 @@ func TestPrecommitBatcher(t *testing.T) { s.EXPECT().ChainBaseFee(gomock.Any(), gomock.Any()).Return(big.NewInt(9999), nil) s.EXPECT().StateNetworkVersion(gomock.Any(), gomock.Any()).Return(network.Version14, nil) - s.EXPECT().StateMinerInfo(gomock.Any(), gomock.Any(), gomock.Any()).Return(miner.MinerInfo{Owner: t0123, Worker: t0123}, nil) + s.EXPECT().StateMinerInfo(gomock.Any(), gomock.Any(), gomock.Any()).Return(api.MinerInfo{Owner: t0123, Worker: t0123}, nil) for _, number := range expect { numClone := number s.EXPECT().SendMsg(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), funMatcher(func(i interface{}) bool { diff --git a/extern/storage-sealing/precommit_policy.go b/extern/storage-sealing/precommit_policy.go index 398956f01..b215e5844 100644 --- a/extern/storage-sealing/precommit_policy.go +++ b/extern/storage-sealing/precommit_policy.go @@ -6,9 +6,9 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" ) diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index cacd5b3c4..509e267c4 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -6,6 +6,8 @@ import ( "sync" "time" + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/ipfs/go-cid" @@ -23,9 +25,9 @@ import ( "github.com/filecoin-project/go-statemachine" "github.com/filecoin-project/specs-storage/storage" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin/market" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" @@ -62,7 +64,7 @@ type SealingAPI interface { StateMinerWorkerAddress(ctx context.Context, maddr address.Address, tok TipSetToken) (address.Address, error) StateMinerPreCommitDepositForPower(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) StateMinerInitialPledgeCollateral(context.Context, address.Address, miner.SectorPreCommitInfo, TipSetToken) (big.Int, error) - StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error) + StateMinerInfo(context.Context, address.Address, TipSetToken) (api.MinerInfo, error) StateMinerAvailableBalance(context.Context, address.Address, TipSetToken) (big.Int, error) StateMinerSectorAllocated(context.Context, address.Address, abi.SectorNumber, TipSetToken) (bool, error) StateMinerActiveSectors(context.Context, address.Address, TipSetToken) (bitfield.BitField, error) @@ -82,7 +84,7 @@ type SealingAPI interface { type SectorStateNotifee func(before, after SectorInfo) -type AddrSel func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) +type AddrSel func(ctx context.Context, mi api.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) type Sealing struct { Api SealingAPI @@ -269,7 +271,7 @@ func (m *Sealing) currentSealProof(ctx context.Context) (abi.RegisteredSealProof return 0, err } - return miner.PreferredSealProofTypeFromWindowPoStType(ver, mi.WindowPoStProofType) + return lminer.PreferredSealProofTypeFromWindowPoStType(ver, mi.WindowPoStProofType) } func (m *Sealing) minerSector(spt abi.RegisteredSealProof, num abi.SectorNumber) storage.SectorRef { diff --git a/extern/storage-sealing/states_failed.go b/extern/storage-sealing/states_failed.go index 2a6d50ccf..c94752552 100644 --- a/extern/storage-sealing/states_failed.go +++ b/extern/storage-sealing/states_failed.go @@ -8,8 +8,8 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/chain/actors/builtin/market" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/exitcode" @@ -455,7 +455,7 @@ func (m *Sealing) handleRecoverDealIDsOrFailWith(ctx statemachine.Context, secto var dp *market.DealProposal if p.DealInfo.DealProposal != nil { - mdp := market.DealProposal(*p.DealInfo.DealProposal) + mdp := *p.DealInfo.DealProposal dp = &mdp } res, err := m.DealInfo.GetCurrentDealInfo(ctx.Context(), tok, dp, *p.DealInfo.PublishCid) diff --git a/extern/storage-sealing/states_replica_update.go b/extern/storage-sealing/states_replica_update.go index ff6302599..186997553 100644 --- a/extern/storage-sealing/states_replica_update.go +++ b/extern/storage-sealing/states_replica_update.go @@ -7,10 +7,11 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/go-state-types/exitcode" statemachine "github.com/filecoin-project/go-statemachine" api "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" "golang.org/x/xerrors" ) @@ -168,7 +169,7 @@ func (m *Sealing) handleSubmitReplicaUpdate(ctx statemachine.Context, sector Sec log.Errorf("no good address to send replica update message from: %+v", err) return ctx.Send(SectorSubmitReplicaUpdateFailed{}) } - mcid, err := m.Api.SendMsg(ctx.Context(), from, m.maddr, miner.Methods.ProveReplicaUpdates, collateral, big.Int(m.feeCfg.MaxCommitGasFee), enc.Bytes()) + mcid, err := m.Api.SendMsg(ctx.Context(), from, m.maddr, builtin.MethodsMiner.ProveReplicaUpdates, collateral, big.Int(m.feeCfg.MaxCommitGasFee), enc.Bytes()) if err != nil { log.Errorf("handleSubmitReplicaUpdate: error sending message: %+v", err) return ctx.Send(SectorSubmitReplicaUpdateFailed{}) diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index 1b2556943..052ff846d 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -4,6 +4,8 @@ import ( "bytes" "context" + "github.com/filecoin-project/go-state-types/proof" + "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -14,12 +16,12 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-statemachine" - "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof" "github.com/filecoin-project/specs-storage/storage" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" ) @@ -28,7 +30,7 @@ var MaxTicketAge = policy.MaxPreCommitRandomnessLookback func (m *Sealing) handlePacking(ctx statemachine.Context, sector SectorInfo) error { m.inputLk.Lock() - // make sure we not accepting deals into this sector + // make sure we are not accepting deals into this sector for _, c := range m.assignedPieces[m.minerSectorID(sector.SectorNumber)] { pp := m.pendingPieces[c] delete(m.pendingPieces, c) @@ -409,7 +411,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf } log.Infof("submitting precommit for sector %d (deposit: %s): ", sector.SectorNumber, deposit) - mcid, err := m.Api.SendMsg(ctx.Context(), from, m.maddr, miner.Methods.PreCommitSector, deposit, big.Int(m.feeCfg.MaxPreCommitGasFee), enc.Bytes()) + mcid, err := m.Api.SendMsg(ctx.Context(), from, m.maddr, builtin.MethodsMiner.PreCommitSector, deposit, big.Int(m.feeCfg.MaxPreCommitGasFee), enc.Bytes()) if err != nil { return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)}) } @@ -669,7 +671,7 @@ func (m *Sealing) handleSubmitCommit(ctx statemachine.Context, sector SectorInfo } // TODO: check seed / ticket / deals are up to date - mcid, err := m.Api.SendMsg(ctx.Context(), from, m.maddr, miner.Methods.ProveCommitSector, collateral, big.Int(m.feeCfg.MaxCommitGasFee), enc.Bytes()) + mcid, err := m.Api.SendMsg(ctx.Context(), from, m.maddr, builtin.MethodsMiner.ProveCommitSector, collateral, big.Int(m.feeCfg.MaxCommitGasFee), enc.Bytes()) if err != nil { return ctx.Send(SectorCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)}) } diff --git a/extern/storage-sealing/terminate_batch.go b/extern/storage-sealing/terminate_batch.go index 13fa281c3..ec772680b 100644 --- a/extern/storage-sealing/terminate_batch.go +++ b/extern/storage-sealing/terminate_batch.go @@ -14,18 +14,18 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/go-state-types/dline" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/node/config" ) type TerminateBatcherApi interface { StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok TipSetToken) (*SectorLocation, error) SendMsg(ctx context.Context, from, to address.Address, method abi.MethodNum, value, maxFee abi.TokenAmount, params []byte) (cid.Cid, error) - StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error) + StateMinerInfo(context.Context, address.Address, TipSetToken) (api.MinerInfo, error) StateMinerProvingDeadline(context.Context, address.Address, TipSetToken) (*dline.Info, error) StateMinerPartitions(ctx context.Context, m address.Address, dlIdx uint64, tok TipSetToken) ([]api.Partition, error) } @@ -119,7 +119,7 @@ func (b *TerminateBatcher) processBatch(notif, after bool) (*cid.Cid, error) { b.lk.Lock() defer b.lk.Unlock() - params := miner2.TerminateSectorsParams{} + params := miner.TerminateSectorsParams{} var total uint64 for loc, sectors := range b.todo { @@ -178,7 +178,7 @@ func (b *TerminateBatcher) processBatch(notif, after bool) (*cid.Cid, error) { total += n - params.Terminations = append(params.Terminations, miner2.TerminationDeclaration{ + params.Terminations = append(params.Terminations, miner.TerminationDeclaration{ Deadline: loc.Deadline, Partition: loc.Partition, Sectors: toTerminate, @@ -220,7 +220,7 @@ func (b *TerminateBatcher) processBatch(notif, after bool) (*cid.Cid, error) { return nil, xerrors.Errorf("no good address found: %w", err) } - mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, miner.Methods.TerminateSectors, big.Zero(), big.Int(b.feeCfg.MaxTerminateGasFee), enc.Bytes()) + mcid, err := b.api.SendMsg(b.mctx, from, b.maddr, builtin.MethodsMiner.TerminateSectors, big.Zero(), big.Int(b.feeCfg.MaxTerminateGasFee), enc.Bytes()) if err != nil { return nil, xerrors.Errorf("sending message failed: %w", err) } diff --git a/extern/storage-sealing/types.go b/extern/storage-sealing/types.go index d30d98f03..f03843f5b 100644 --- a/extern/storage-sealing/types.go +++ b/extern/storage-sealing/types.go @@ -11,8 +11,8 @@ import ( "github.com/filecoin-project/go-state-types/exitcode" "github.com/filecoin-project/specs-storage/storage" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/storage-sealing/sealiface" ) diff --git a/extern/storage-sealing/types_test.go b/extern/storage-sealing/types_test.go index 68e2b1111..ae8569717 100644 --- a/extern/storage-sealing/types_test.go +++ b/extern/storage-sealing/types_test.go @@ -4,6 +4,8 @@ import ( "bytes" "testing" + markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/ipfs/go-cid" "gotest.tools/assert" @@ -11,7 +13,6 @@ import ( cborutil "github.com/filecoin-project/go-cbor-util" "github.com/filecoin-project/go-state-types/abi" api "github.com/filecoin-project/lotus/api" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" tutils "github.com/filecoin-project/specs-actors/v2/support/testing" ) @@ -29,7 +30,7 @@ func TestSectorInfoSerialization(t *testing.T) { StartEpoch: 0, EndEpoch: 100, }, - DealProposal: &market2.DealProposal{ + DealProposal: &markettypes.DealProposal{ PieceCID: dummyCid, PieceSize: 5, Client: tutils.NewActorAddr(t, "client"), diff --git a/gateway/node.go b/gateway/node.go index 87a8551b1..aa292065c 100644 --- a/gateway/node.go +++ b/gateway/node.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -46,6 +47,7 @@ type TargetAPI interface { ChainNotify(context.Context) (<-chan []*api.HeadChange, error) ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error) + ChainPutObj(context.Context, blocks.Block) error ChainGetGenesis(context.Context) (*types.TipSet, error) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) MpoolPushUntrusted(ctx context.Context, sm *types.SignedMessage) (cid.Cid, error) @@ -67,7 +69,7 @@ type TargetAPI interface { StateMinerPower(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) StateMinerFaults(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (bitfield.BitField, error) - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error) StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) StateMinerProvingDeadline(context.Context, address.Address, types.TipSetKey) (*dline.Info, error) @@ -251,6 +253,10 @@ func (gw *Node) ChainReadObj(ctx context.Context, c cid.Cid) ([]byte, error) { return gw.target.ChainReadObj(ctx, c) } +func (gw *Node) ChainPutObj(context.Context, blocks.Block) error { + return xerrors.New("not supported") +} + func (gw *Node) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, tsk types.TipSetKey) (*types.Message, error) { if err := gw.checkTipsetKey(ctx, tsk); err != nil { return nil, err @@ -414,9 +420,9 @@ func (gw *Node) StateMinerRecoveries(ctx context.Context, m address.Address, tsk return gw.target.StateMinerRecoveries(ctx, m, tsk) } -func (gw *Node) StateMinerInfo(ctx context.Context, m address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) { +func (gw *Node) StateMinerInfo(ctx context.Context, m address.Address, tsk types.TipSetKey) (api.MinerInfo, error) { if err := gw.checkTipsetKey(ctx, tsk); err != nil { - return miner.MinerInfo{}, err + return api.MinerInfo{}, err } return gw.target.StateMinerInfo(ctx, m, tsk) } diff --git a/gateway/node_test.go b/gateway/node_test.go index 4705f9bd5..aebd8ba14 100644 --- a/gateway/node_test.go +++ b/gateway/node_test.go @@ -16,7 +16,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types/mock" ) @@ -143,7 +142,7 @@ func (m *mockGatewayDepsAPI) StateMarketStorageDeal(ctx context.Context, dealId panic("implement me") } -func (m *mockGatewayDepsAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) { +func (m *mockGatewayDepsAPI) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error) { panic("implement me") } diff --git a/gen/bundle/bundle.go b/gen/bundle/bundle.go new file mode 100644 index 000000000..c7655157e --- /dev/null +++ b/gen/bundle/bundle.go @@ -0,0 +1,50 @@ +package main + +import ( + "os" + "text/template" + + "github.com/filecoin-project/lotus/build" +) + +var tmpl *template.Template = template.Must(template.New("actor-metadata").Parse(` +// WARNING: This file has automatically been generated + +package build + +import ( + "github.com/ipfs/go-cid" +) + +var EmbeddedBuiltinActorsMetadata []*BuiltinActorsMetadata = []*BuiltinActorsMetadata{ +{{- range . }} { + Network: {{printf "%q" .Network}}, + Version: {{.Version}}, + ManifestCid: MustParseCid({{printf "%q" .ManifestCid}}), + Actors: map[string]cid.Cid { + {{- range $name, $cid := .Actors }} + {{printf "%q" $name}}: MustParseCid({{printf "%q" $cid}}), + {{- end }} + }, +}, +{{- end -}} +} +`)) + +func main() { + metadata, err := build.ReadEmbeddedBuiltinActorsMetadata() + if err != nil { + panic(err) + } + + fi, err := os.Create("./build/builtin_actors_gen.go") + if err != nil { + panic(err) + } + defer fi.Close() //nolint + + err = tmpl.Execute(fi, metadata) + if err != nil { + panic(err) + } +} diff --git a/gen/inlinegen-data.json b/gen/inlinegen-data.json index ef97db651..8b8081ac4 100644 --- a/gen/inlinegen-data.json +++ b/gen/inlinegen-data.json @@ -1,7 +1,7 @@ { - "actorVersions": [0, 2, 3, 4, 5, 6, 7], - "latestActorsVersion": 7, + "actorVersions": [0, 2, 3, 4, 5, 6, 7, 8], + "latestActorsVersion": 8, - "networkVersions": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], - "latestNetworkVersion": 15 + "networkVersions": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], + "latestNetworkVersion": 16 } diff --git a/genesis/types.go b/genesis/types.go index d4c04113a..1a4bbec41 100644 --- a/genesis/types.go +++ b/genesis/types.go @@ -3,14 +3,14 @@ package genesis import ( "encoding/json" - "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/filecoin-project/go-state-types/network" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" - - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" ) type ActorType string @@ -21,11 +21,12 @@ const ( ) type PreSeal struct { - CommR cid.Cid - CommD cid.Cid - SectorID abi.SectorNumber - Deal market2.DealProposal - ProofType abi.RegisteredSealProof + CommR cid.Cid + CommD cid.Cid + SectorID abi.SectorNumber + Deal market8.DealProposal + DealClientKey *wallet.Key + ProofType abi.RegisteredSealProof } type Miner struct { diff --git a/go.mod b/go.mod index 69c745d7e..63ea020ef 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ retract v1.14.0 // Accidentally force-pushed tag, use v1.14.1+ instead. require ( contrib.go.opencensus.io/exporter/prometheus v0.4.0 github.com/BurntSushi/toml v0.4.1 + github.com/DataDog/zstd v1.4.1 github.com/GeertJohan/go.rice v1.0.2 github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee github.com/Kubuxu/imtui v0.0.0-20210401140320-41663d68d0fa @@ -36,25 +37,26 @@ require ( github.com/filecoin-project/go-data-transfer v1.15.1 github.com/filecoin-project/go-fil-commcid v0.1.0 github.com/filecoin-project/go-fil-commp-hashhash v0.1.0 - github.com/filecoin-project/go-fil-markets v1.20.1 + github.com/filecoin-project/go-fil-markets v1.20.1-v16-2 github.com/filecoin-project/go-jsonrpc v0.1.5 - github.com/filecoin-project/go-legs v0.3.7 + github.com/filecoin-project/go-legs v0.3.10 github.com/filecoin-project/go-padreader v0.0.1 github.com/filecoin-project/go-paramfetch v0.0.4 - github.com/filecoin-project/go-state-types v0.1.3 + github.com/filecoin-project/go-state-types v0.1.10 github.com/filecoin-project/go-statemachine v1.0.2 github.com/filecoin-project/go-statestore v0.2.0 github.com/filecoin-project/go-storedcounter v0.1.0 github.com/filecoin-project/index-provider v0.5.0 github.com/filecoin-project/pubsub v1.0.0 - github.com/filecoin-project/specs-actors v0.9.14 + 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-storage v0.2.4 + 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/filecoin-project/specs-actors/v8 v8.0.0 + github.com/filecoin-project/specs-storage v0.4.1 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.1 github.com/gdamore/tcell/v2 v2.2.0 @@ -109,7 +111,7 @@ require ( github.com/koalacxr/quantile v0.0.1 github.com/libp2p/go-buffer-pool v0.0.2 github.com/libp2p/go-eventbus v0.2.1 - github.com/libp2p/go-libp2p v0.19.3 + github.com/libp2p/go-libp2p v0.19.4 github.com/libp2p/go-libp2p-connmgr v0.3.1 github.com/libp2p/go-libp2p-core v0.15.1 github.com/libp2p/go-libp2p-discovery v0.6.0 @@ -145,7 +147,7 @@ require ( github.com/syndtr/goleveldb v1.0.0 github.com/urfave/cli/v2 v2.3.0 github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba - github.com/whyrusleeping/cbor-gen v0.0.0-20220302191723-37c43cae8e14 + github.com/whyrusleeping/cbor-gen v0.0.0-20220323183124-98fa8256a799 github.com/whyrusleeping/ledger-filecoin-go v0.9.1-0.20201010031517-c3dcc1bddce4 github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 github.com/xorcare/golden v0.6.1-0.20191112154924-b87f686d7542 @@ -168,7 +170,6 @@ require ( ) require ( - github.com/DataDog/zstd v1.4.1 // indirect github.com/GeertJohan/go.incremental v1.0.0 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect @@ -276,7 +277,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 @@ -310,7 +311,6 @@ require ( github.com/prometheus/common v0.33.0 // indirect github.com/prometheus/procfs v0.7.3 // indirect github.com/prometheus/statsd_exporter v0.21.0 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/rivo/uniseg v0.1.0 // indirect github.com/rs/cors v1.7.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect @@ -319,7 +319,6 @@ require ( github.com/sirupsen/logrus v1.8.1 // indirect github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/tj/go-spin v1.1.0 // indirect github.com/uber/jaeger-client-go v2.25.0+incompatible // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.0.1 // indirect @@ -327,8 +326,6 @@ require ( github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // 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 @@ -350,11 +347,6 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect lukechampine.com/blake3 v1.1.7 // 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 github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi diff --git a/go.sum b/go.sum index 2bd042698..cb712ade9 100644 --- a/go.sum +++ b/go.sum @@ -343,8 +343,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= @@ -355,8 +355,9 @@ github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0/go.mod h1:bxmzgT8tmeVQA1/gvBw 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= @@ -367,11 +368,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= @@ -385,27 +389,33 @@ github.com/filecoin-project/index-provider v0.5.0/go.mod h1:KHVrP2vU3YuScb+fawOb 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 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= @@ -1086,8 +1096,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= @@ -1251,6 +1262,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= @@ -1344,6 +1356,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= @@ -1446,8 +1459,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= @@ -1807,8 +1821,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 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= @@ -1922,8 +1934,6 @@ github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= 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/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= @@ -1980,10 +1990,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= @@ -2004,10 +2014,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= @@ -2169,7 +2175,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= @@ -2492,7 +2497,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= @@ -2677,20 +2681,6 @@ howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCU lukechampine.com/blake3 v1.1.6/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0= lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= -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/itests/deadlines_test.go b/itests/deadlines_test.go index f0abdb556..2b6d94143 100644 --- a/itests/deadlines_test.go +++ b/itests/deadlines_test.go @@ -7,6 +7,9 @@ import ( "testing" "time" + "github.com/filecoin-project/go-state-types/builtin" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" @@ -238,7 +241,7 @@ func TestDeadlineToggling(t *testing.T) { cr, err := cid.Parse("bagboea4b5abcatlxechwbp7kjpjguna6r6q7ejrhe6mdp3lf34pmswn27pkkiekz") require.NoError(t, err) - params := &miner.SectorPreCommitInfo{ + params := &minertypes.SectorPreCommitInfo{ Expiration: 2880 * 300, SectorNumber: 22, SealProof: kit.TestSpt, @@ -254,7 +257,7 @@ func TestDeadlineToggling(t *testing.T) { To: maddrE, From: defaultFrom, Value: types.FromFil(1), - Method: miner.Methods.PreCommitSector, + Method: builtin.MethodsMiner.PreCommitSector, Params: enc.Bytes(), }, nil) require.NoError(t, err) @@ -335,7 +338,7 @@ func TestDeadlineToggling(t *testing.T) { smsg, err := client.MpoolPushMessage(ctx, &types.Message{ From: defaultFrom, To: maddrD, - Method: miner.Methods.TerminateSectors, + Method: builtin.MethodsMiner.TerminateSectors, Value: big.Zero(), Params: sp, diff --git a/itests/deals_512mb_test.go b/itests/deals_512mb_test.go index 967e33da4..8c3aea655 100644 --- a/itests/deals_512mb_test.go +++ b/itests/deals_512mb_test.go @@ -22,8 +22,6 @@ func TestStorageDealMissingBlock(t *testing.T) { //stm: @CLIENT_STORAGE_DEALS_LIST_IMPORTS_001 ctx := context.Background() - // enable 512MiB proofs so we can conduct larger transfers. - kit.EnableLargeSectors(t) kit.QuietMiningLogs() client, miner, ens := kit.EnsembleMinimal(t, diff --git a/itests/deals_anycid_test.go b/itests/deals_anycid_test.go index 8e061af29..03317596b 100644 --- a/itests/deals_anycid_test.go +++ b/itests/deals_anycid_test.go @@ -18,7 +18,6 @@ import ( "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/itests/kit" "github.com/filecoin-project/lotus/node" "github.com/filecoin-project/lotus/node/modules" @@ -31,14 +30,7 @@ func TestDealRetrieveByAnyCid(t *testing.T) { } ctx := context.Background() - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - // Allow 8MB sectors - policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg8MiBV1) kit.QuietMiningLogs() // For these tests where the block time is artificially short, just use diff --git a/itests/deals_concurrent_test.go b/itests/deals_concurrent_test.go index 015cf03a1..3248a1d20 100644 --- a/itests/deals_concurrent_test.go +++ b/itests/deals_concurrent_test.go @@ -16,7 +16,6 @@ import ( provider "github.com/filecoin-project/index-provider" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/itests/kit" "github.com/filecoin-project/lotus/node" "github.com/filecoin-project/lotus/node/modules" @@ -39,12 +38,6 @@ func TestDealWithMarketAndMinerNode(t *testing.T) { kit.QuietMiningLogs() - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - // For these tests where the block time is artificially short, just use // a deal start epoch that is guaranteed to be far enough in the future // so that the deal starts sealing in time @@ -91,12 +84,6 @@ func TestDealCyclesConcurrent(t *testing.T) { t.Skip("skipping test in short mode") } - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - kit.QuietMiningLogs() // For these tests where the block time is artificially short, just use @@ -142,12 +129,6 @@ func TestSimultanenousTransferLimit(t *testing.T) { kit.QuietMiningLogs() - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - // For these tests where the block time is artificially short, just use // a deal start epoch that is guaranteed to be far enough in the future // so that the deal starts sealing in time diff --git a/itests/deals_invalid_utf8_label_test.go b/itests/deals_invalid_utf8_label_test.go new file mode 100644 index 000000000..7a4e79150 --- /dev/null +++ b/itests/deals_invalid_utf8_label_test.go @@ -0,0 +1,78 @@ +package itests + +import ( + "context" + "encoding/hex" + "testing" + "time" + + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/itests/kit" + "github.com/stretchr/testify/require" +) + +// The following function will generate and print out the hex encoding of PublishStorageDealsParams with a dealLabel with invalid utf8 encoding. +// This is not possible with our current code structure, so this was run with a modified NewLabelFromString() function in go-state-types +// The result is recorded in the function below for submission. +//func generateInvalidDealProposal(t *testing.T) { +// ctx := context.Background() +// +// kit.QuietMiningLogs() +// +// client16, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.GenesisNetworkVersion(network.Version16)) +// ens.InterconnectAll().BeginMining(10 * time.Millisecond) +// +// dealLabel, err := market.NewLabelFromString(string([]byte{0xde, 0xad, 0xbe, 0xef})) +// require.NoError(t, err) +// +// dummyCid, err := cid.Parse("bafkqaaa") +// require.NoError(t, err) +// +// proposal := market.DealProposal{ +// PieceCID: dummyCid, +// Client: client16.DefaultKey.Address, +// Provider: client16.DefaultKey.Address, +// Label: dealLabel, +// } +// +// proposalBytes := new(bytes.Buffer) +// err = proposal.MarshalCBOR(proposalBytes) +// require.NoError(t, err) +// +// signature, err := client16.WalletSign(ctx, client16.DefaultKey.Address, proposalBytes.Bytes()) +// require.NoError(t, err) +// +// params, err := actors.SerializeParams(&market.PublishStorageDealsParams{ +// Deals: []market.ClientDealProposal{{ +// Proposal: proposal, +// ClientSignature: *signature, +// }}, +// }) +// require.NoError(t, err) +// +// fmt.Println(hex.EncodeToString(params)) +//} + +func TestSubmitInvalidDealLabel(t *testing.T) { + ctx := context.Background() + + kit.QuietMiningLogs() + + client16, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.GenesisNetworkVersion(network.Version16)) + ens.InterconnectAll().BeginMining(10 * time.Millisecond) + + // This hex string is generated by using the commented function above. + serializedParams, err := hex.DecodeString("8181828bd82a45000155000000f458310394345a1393a5665772ae97456fdc00cf8f537960eeb3838c297da0d60546252d98469cc68b56eb45081e5c959c8cf4fa58310394345a1393a5665772ae97456fdc00cf8f537960eeb3838c297da0d60546252d98469cc68b56eb45081e5c959c8cf4fa64deadbeef00004040405861029927585cf250656cb3ddf337aed516e6393829389e52c45a4fbbe297b8ad3b7a008b3675a5b5c4df43657ff53bcb6c670b4bd83911867ba90b2b14da856a0ecb36782a7d87232272e3b9cd98dd959b2851602fea30c414a4dc1ea12057d31f81") + require.NoError(t, err) + + _, err = client16.MpoolPushMessage(ctx, &types.Message{ + To: builtin.StorageMarketActorAddr, + From: client16.DefaultKey.Address, + Value: types.NewInt(0), + Method: builtin.MethodsMarket.PublishStorageDeals, + Params: serializedParams, + }, nil) + require.Contains(t, err.Error(), "Serialization error for Cbor protocol: InvalidUtf8") +} diff --git a/itests/deals_max_staging_deals_test.go b/itests/deals_max_staging_deals_test.go index 6a4234e02..fd18c4de0 100644 --- a/itests/deals_max_staging_deals_test.go +++ b/itests/deals_max_staging_deals_test.go @@ -22,8 +22,6 @@ func TestMaxStagingDeals(t *testing.T) { //stm: @CLIENT_STORAGE_DEALS_LIST_IMPORTS_001 ctx := context.Background() - // enable 512MiB proofs so we can conduct larger transfers. - kit.EnableLargeSectors(t) kit.QuietMiningLogs() client, miner, ens := kit.EnsembleMinimal(t, diff --git a/itests/deals_padding_test.go b/itests/deals_padding_test.go index c79b6a7db..2b0dd0d17 100644 --- a/itests/deals_padding_test.go +++ b/itests/deals_padding_test.go @@ -9,7 +9,6 @@ import ( commcid "github.com/filecoin-project/go-fil-commcid" commp "github.com/filecoin-project/go-fil-commp-hashhash" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/itests/kit" "github.com/stretchr/testify/require" ) @@ -26,7 +25,6 @@ func TestDealPadding(t *testing.T) { var blockTime = 250 * time.Millisecond startEpoch := abi.ChainEpoch(2 << 12) - policy.SetPreCommitChallengeDelay(2) client, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.WithAllSubsystems()) // no mock proofs. ens.InterconnectAll().BeginMining(blockTime) diff --git a/itests/deals_partial_retrieval_dm-level_test.go b/itests/deals_partial_retrieval_dm-level_test.go index 4b1a5b0e3..aa92cf731 100644 --- a/itests/deals_partial_retrieval_dm-level_test.go +++ b/itests/deals_partial_retrieval_dm-level_test.go @@ -13,7 +13,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/api" api0 "github.com/filecoin-project/lotus/api/v0api" - "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/itests/kit" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" @@ -46,7 +45,6 @@ func TestDMLevelPartialRetrieval(t *testing.T) { //stm: @CLIENT_RETRIEVAL_RETRIEVE_001, @CLIENT_RETRIEVAL_FIND_001 ctx := context.Background() - policy.SetPreCommitChallengeDelay(2) kit.QuietMiningLogs() client, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.MockProofs()) dh := kit.NewDealHarness(t, client, miner, miner) diff --git a/itests/deals_partial_retrieval_test.go b/itests/deals_partial_retrieval_test.go index abc5cf411..e1be43637 100644 --- a/itests/deals_partial_retrieval_test.go +++ b/itests/deals_partial_retrieval_test.go @@ -16,7 +16,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/itests/kit" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" @@ -48,8 +47,6 @@ func TestPartialRetrieval(t *testing.T) { //stm: @CLIENT_RETRIEVAL_RETRIEVE_001 ctx := context.Background() - policy.SetPreCommitChallengeDelay(2) - kit.EnableLargeSectors(t) kit.QuietMiningLogs() client, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.MockProofs(), kit.SectorSize(512<<20)) dh := kit.NewDealHarness(t, client, miner, miner) diff --git a/itests/deals_retry_deal_no_funds_test.go b/itests/deals_retry_deal_no_funds_test.go index a14a0d085..cf52d6f55 100644 --- a/itests/deals_retry_deal_no_funds_test.go +++ b/itests/deals_retry_deal_no_funds_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/lotus/itests/kit" @@ -35,14 +34,7 @@ func TestDealsRetryLackOfFunds(t *testing.T) { //stm: @CHAIN_INCOMING_HANDLE_INCOMING_BLOCKS_001, @CHAIN_INCOMING_VALIDATE_BLOCK_PUBSUB_001, @CHAIN_INCOMING_VALIDATE_MESSAGE_PUBSUB_001 //stm: @CLIENT_STORAGE_DEALS_LIST_IMPORTS_001 ctx := context.Background() - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - - policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg8MiBV1) kit.QuietMiningLogs() // Allow 8MB sectors @@ -119,14 +111,6 @@ func TestDealsRetryLackOfFunds_blockInPublishDeal(t *testing.T) { //stm: @CHAIN_SYNCER_NEW_PEER_HEAD_001, @CHAIN_SYNCER_VALIDATE_MESSAGE_META_001, @CHAIN_SYNCER_STOP_001 //stm: @CLIENT_STORAGE_DEALS_LIST_IMPORTS_001 ctx := context.Background() - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - - policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg8MiBV1) kit.QuietMiningLogs() // Allow 8MB sectors @@ -200,14 +184,6 @@ func TestDealsRetryLackOfFunds_belowLimit(t *testing.T) { //stm: @CHAIN_SYNCER_NEW_PEER_HEAD_001, @CHAIN_SYNCER_VALIDATE_MESSAGE_META_001, @CHAIN_SYNCER_STOP_001 //stm: @CLIENT_STORAGE_DEALS_LIST_IMPORTS_001 ctx := context.Background() - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - - policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg8MiBV1) kit.QuietMiningLogs() // Allow 8MB sectors @@ -261,7 +237,7 @@ func TestDealsRetryLackOfFunds_belowLimit(t *testing.T) { dp.EpochPrice = abi.NewTokenAmount(62500000) // minimum asking price. deal := dh.StartDeal(ctx, dp) - err = dh.ExpectDealFailure(ctx, deal, "actor balance less than needed") + err = dh.ExpectDealFailure(ctx, deal, "Actor balance less than needed") if err != nil { t.Fatal(err) } diff --git a/itests/deals_test.go b/itests/deals_test.go index fb8e6e4f3..9810d417a 100644 --- a/itests/deals_test.go +++ b/itests/deals_test.go @@ -5,7 +5,6 @@ import ( "testing" "time" - "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/itests/kit" ) @@ -22,12 +21,6 @@ func TestDealsWithSealingAndRPC(t *testing.T) { kit.QuietMiningLogs() - oldDelay := policy.GetPreCommitChallengeDelay() - policy.SetPreCommitChallengeDelay(5) - t.Cleanup(func() { - policy.SetPreCommitChallengeDelay(oldDelay) - }) - client, miner, ens := kit.EnsembleMinimal(t, kit.ThroughRPC(), kit.WithAllSubsystems()) // no mock proofs. ens.InterconnectAll().BeginMining(250 * time.Millisecond) dh := kit.NewDealHarness(t, client, miner, miner) diff --git a/itests/kit/blockminer.go b/itests/kit/blockminer.go index 03f5d6e34..aa1658dfe 100644 --- a/itests/kit/blockminer.go +++ b/itests/kit/blockminer.go @@ -9,11 +9,13 @@ import ( "testing" "time" + "github.com/filecoin-project/go-state-types/builtin" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/lotus/api" - aminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/miner" "github.com/stretchr/testify/require" @@ -72,10 +74,10 @@ func (p *partitionTracker) recordIfPost(t *testing.T, bm *BlockMiner, msg *types if !(msg.To == bm.miner.ActorAddr) { return } - if msg.Method != aminer.Methods.SubmitWindowedPoSt { + if msg.Method != builtin.MethodsMiner.SubmitWindowedPoSt { return } - params := aminer.SubmitWindowedPoStParams{} + params := minertypes.SubmitWindowedPoStParams{} require.NoError(t, params.UnmarshalCBOR(bytes.NewReader(msg.Params))) for _, part := range params.Partitions { p.posted.Set(part.Index) diff --git a/itests/kit/control.go b/itests/kit/control.go index 73ac39b7a..e1954c56c 100644 --- a/itests/kit/control.go +++ b/itests/kit/control.go @@ -3,6 +3,8 @@ package kit import ( "context" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/stretchr/testify/require" addr "github.com/filecoin-project/go-address" @@ -10,7 +12,6 @@ import ( miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" ) @@ -31,7 +32,7 @@ func (tm *TestMiner) SetControlAddresses(addrs ...addr.Address) { smsg, err := tm.FullNode.MpoolPushMessage(ctx, &types.Message{ From: mi.Owner, To: tm.ActorAddr, - Method: miner.Methods.ChangeWorkerAddress, + Method: builtin.MethodsMiner.ChangeWorkerAddress, Value: big.Zero(), Params: sp, diff --git a/itests/kit/ensemble.go b/itests/kit/ensemble.go index 8b0128f46..8e0a3ef6c 100644 --- a/itests/kit/ensemble.go +++ b/itests/kit/ensemble.go @@ -12,6 +12,8 @@ import ( "testing" "time" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore/namespace" libp2pcrypto "github.com/libp2p/go-libp2p-core/crypto" @@ -26,8 +28,6 @@ import ( "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/go-statestore" "github.com/filecoin-project/go-storedcounter" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - power2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/power" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/v1api" @@ -59,6 +59,8 @@ import ( testing2 "github.com/filecoin-project/lotus/node/modules/testing" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage/mockstorage" + miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" + power3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/power" ) func init() { @@ -158,6 +160,14 @@ func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble { }) } + // Ensure we're using the right actors. This really shouldn't be some global thing, but it's + // the best we can do for now. + if n.options.mockProofs { + require.NoError(t, build.UseNetworkBundle("testing-fake-proofs")) + } else { + require.NoError(t, build.UseNetworkBundle("testing")) + } + return n } @@ -406,19 +416,14 @@ func (n *Ensemble) Start() *Ensemble { // this is a miner created after genesis, so it won't have a preseal. // we need to create it on chain. - // we get the proof type for the requested sector size, for - // the current network version. - nv, err := m.FullNode.FullNode.StateNetworkVersion(ctx, types.EmptyTSK) + proofType, err := miner.WindowPoStProofTypeFromSectorSize(m.options.sectorSize) require.NoError(n.t, err) - proofType, err := miner.SealProofTypeFromSectorSize(m.options.sectorSize, nv) - require.NoError(n.t, err) - - params, aerr := actors.SerializeParams(&power2.CreateMinerParams{ - Owner: m.OwnerKey.Address, - Worker: m.OwnerKey.Address, - SealProofType: proofType, - Peer: abi.PeerID(m.Libp2p.PeerID), + params, aerr := actors.SerializeParams(&power3.CreateMinerParams{ + Owner: m.OwnerKey.Address, + Worker: m.OwnerKey.Address, + WindowPoStProofType: proofType, + Peer: abi.PeerID(m.Libp2p.PeerID), }) require.NoError(n.t, aerr) @@ -437,7 +442,7 @@ func (n *Ensemble) Start() *Ensemble { require.NoError(n.t, err) require.Equal(n.t, exitcode.Ok, mw.Receipt.ExitCode) - var retval power2.CreateMinerReturn + var retval power3.CreateMinerReturn err = retval.UnmarshalCBOR(bytes.NewReader(mw.Receipt.Return)) require.NoError(n.t, err, "failed to create miner") @@ -449,7 +454,7 @@ func (n *Ensemble) Start() *Ensemble { msg := &types.Message{ To: m.options.mainMiner.ActorAddr, From: m.options.mainMiner.OwnerKey.Address, - Method: miner.Methods.ChangePeerID, + Method: builtin.MethodsMiner.ChangePeerID, Params: params, Value: types.NewInt(0), } @@ -560,7 +565,7 @@ func (n *Ensemble) Start() *Ensemble { msg := &types.Message{ From: m.OwnerKey.Address, To: m.ActorAddr, - Method: miner.Methods.ChangePeerID, + Method: builtin.MethodsMiner.ChangePeerID, Params: enc, Value: types.NewInt(0), } diff --git a/itests/kit/ensemble_opts_nv.go b/itests/kit/ensemble_opts_nv.go index 45ed51443..b51b82bd5 100644 --- a/itests/kit/ensemble_opts_nv.go +++ b/itests/kit/ensemble_opts_nv.go @@ -49,12 +49,12 @@ func LatestActorsAt(upgradeHeight abi.ChainEpoch) EnsembleOpt { }) /* inline-gen start */ return UpgradeSchedule(stmgr.Upgrade{ - Network: network.Version14, + Network: network.Version15, Height: -1, }, stmgr.Upgrade{ - Network: network.Version15, + Network: network.Version16, Height: upgradeHeight, - Migration: filcns.UpgradeActorsV7, + Migration: filcns.UpgradeActorsV8, }) /* inline-gen end */ } diff --git a/itests/kit/init.go b/itests/kit/init.go index c455cf8c6..33a9ace7d 100644 --- a/itests/kit/init.go +++ b/itests/kit/init.go @@ -15,10 +15,27 @@ import ( func init() { _ = logging.SetLogLevel("*", "INFO") + // These values mimic the values set in the builtin-actors when configured to use the "testing" network. Specifically: + // - All proof types. + // - 2k minimum power. + // - "small" verified deals. + // - short precommit + // + // See: + // - https://github.com/filecoin-project/builtin-actors/blob/0502c0722225ee58d1e6641431b4f9356cb2d18e/actors/runtime/src/runtime/policy.rs#L235 + // - https://github.com/filecoin-project/builtin-actors/blob/0502c0722225ee58d1e6641431b4f9356cb2d18e/actors/runtime/build.rs#L17-L45 policy.SetProviderCollateralSupplyTarget(big.Zero(), big.NewInt(1)) policy.SetConsensusMinerMinPower(abi.NewStoragePower(2048)) - policy.SetSupportedProofTypes(abi.RegisteredSealProof_StackedDrg2KiBV1) policy.SetMinVerifiedDealSize(abi.NewStoragePower(256)) + policy.SetPreCommitChallengeDelay(10) + policy.SetSupportedProofTypes( + abi.RegisteredSealProof_StackedDrg2KiBV1, + abi.RegisteredSealProof_StackedDrg8MiBV1, + abi.RegisteredSealProof_StackedDrg512MiBV1, + abi.RegisteredSealProof_StackedDrg32GiBV1, + abi.RegisteredSealProof_StackedDrg64GiBV1, + ) + policy.SetProviderCollateralSupplyTarget(big.NewInt(0), big.NewInt(100)) build.InsecurePoStValidation = true diff --git a/itests/kit/sectors.go b/itests/kit/sectors.go deleted file mode 100644 index d9c52b9ca..000000000 --- a/itests/kit/sectors.go +++ /dev/null @@ -1,23 +0,0 @@ -package kit - -import ( - "testing" - - "github.com/filecoin-project/go-state-types/abi" - - "github.com/filecoin-project/lotus/chain/actors/policy" -) - -// EnableLargeSectors enables 512MiB sectors. This is useful in combination with -// mock proofs, for testing larger transfers. -func EnableLargeSectors(t *testing.T) { - policy.SetSupportedProofTypes( - abi.RegisteredSealProof_StackedDrg2KiBV1, - abi.RegisteredSealProof_StackedDrg512MiBV1, // <== here - ) - t.Cleanup(func() { // reset when done. - policy.SetSupportedProofTypes( - abi.RegisteredSealProof_StackedDrg2KiBV1, - ) - }) -} diff --git a/itests/lite_migration_test.go b/itests/lite_migration_test.go new file mode 100644 index 000000000..8701dac4e --- /dev/null +++ b/itests/lite_migration_test.go @@ -0,0 +1,120 @@ +package itests + +import ( + "context" + "fmt" + "testing" + "time" + + "github.com/ipfs/go-cid" + mh "github.com/multiformats/go-multihash" + "github.com/stretchr/testify/require" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/manifest" + "github.com/filecoin-project/go-state-types/network" + gstStore "github.com/filecoin-project/go-state-types/store" + "github.com/filecoin-project/specs-actors/v8/actors/util/adt" + + "github.com/filecoin-project/lotus/blockstore" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/consensus/filcns" + "github.com/filecoin-project/lotus/chain/state" + "github.com/filecoin-project/lotus/chain/stmgr" + "github.com/filecoin-project/lotus/chain/types" + "github.com/filecoin-project/lotus/itests/kit" +) + +func TestLiteMigration(t *testing.T) { + ctx := context.Background() + + kit.QuietMiningLogs() + + client16, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.GenesisNetworkVersion(network.Version16)) + ens.InterconnectAll().BeginMining(10 * time.Millisecond) + + client16.WaitTillChain(ctx, func(set *types.TipSet) bool { + return set.Height() > 100 + }) + + bs := blockstore.NewAPIBlockstore(client16) + ctxStore := gstStore.WrapBlockStore(ctx, bs) + + ts, err := client16.ChainHead(ctx) + require.NoError(t, err) + + stateRoot := ts.ParentState() + oldStateTree, err := state.LoadStateTree(ctxStore, stateRoot) + require.NoError(t, err) + + oldManifest, err := stmgr.GetManifest(ctx, oldStateTree) + require.NoError(t, err) + newManifestCid := makeTestManifest(t, ctxStore) + // Use the Cid we generated to get the new manifest instead of loading it from the state tree, because that would not test that we have the correct manifest in the state + var newManifest manifest.Manifest + err = ctxStore.Get(ctx, newManifestCid, &newManifest) + require.NoError(t, err) + err = newManifest.Load(ctx, ctxStore) + require.NoError(t, err) + newManifestData := manifest.ManifestData{} + err = ctxStore.Get(ctx, newManifest.Data, &newManifestData) + require.NoError(t, err) + + newStateRoot, err := filcns.LiteMigration(ctx, bs, newManifestCid, stateRoot, actors.Version8, types.StateTreeVersion4, types.StateTreeVersion4) + require.NoError(t, err) + + newStateTree, err := state.LoadStateTree(ctxStore, newStateRoot) + require.NoError(t, err) + + migrations := make(map[cid.Cid]cid.Cid) + for _, entry := range newManifestData.Entries { + oldCodeCid, ok := oldManifest.Get(entry.Name) + require.True(t, ok) + migrations[oldCodeCid] = entry.Code + } + + err = newStateTree.ForEach(func(addr address.Address, newActorState *types.Actor) error { + oldActor, err := oldStateTree.GetActor(addr) + require.NoError(t, err) + newCodeCid, ok := migrations[oldActor.Code] + require.True(t, ok) + require.Equal(t, newCodeCid, newActorState.Code) + return nil + }) + require.NoError(t, err) +} + +func makeTestManifest(t *testing.T, ctxStore adt.Store) cid.Cid { + builder := cid.V1Builder{Codec: cid.Raw, MhType: mh.IDENTITY} + + manifestData := manifest.ManifestData{} + for _, name := range []string{"system", "init", "cron", "account", "storagepower", "storageminer", "storagemarket", "paymentchannel", "multisig", "reward", "verifiedregistry"} { + codeCid, err := builder.Sum([]byte(fmt.Sprintf("fil/8/%s", name))) + if err != nil { + t.Fatal(err) + } + + manifestData.Entries = append(manifestData.Entries, + manifest.ManifestEntry{ + Name: name, + Code: codeCid, + }) + } + + manifestDataCid, err := ctxStore.Put(ctxStore.Context(), &manifestData) + if err != nil { + t.Fatal(err) + } + + mf := manifest.Manifest{ + Version: 1, + Data: manifestDataCid, + } + + manifestCid, err := ctxStore.Put(ctxStore.Context(), &mf) + if err != nil { + t.Fatal(err) + } + + return manifestCid +} diff --git a/itests/paych_api_test.go b/itests/paych_api_test.go index 19e181064..cf63f3de3 100644 --- a/itests/paych_api_test.go +++ b/itests/paych_api_test.go @@ -6,6 +6,8 @@ import ( "testing" "time" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/itests/kit" @@ -171,7 +173,7 @@ func TestPaymentChannelsAPI(t *testing.T) { require.EqualValues(t, excessAmt, vouchRes.Shortfall, "Expected voucher shortfall of %d, got %d", excessAmt, vouchRes.Shortfall) // Add a voucher whose value would exceed the channel balance - vouch := &paych.SignedVoucher{ChannelAddr: channel, Amount: excessAmt, Lane: 4, Nonce: 1} + vouch := &paychtypes.SignedVoucher{ChannelAddr: channel, Amount: excessAmt, Lane: 4, Nonce: 1} vb, err := vouch.SigningBytes() require.NoError(t, err) diff --git a/itests/wdpost_dispute_test.go b/itests/wdpost_dispute_test.go index fe723a814..b1df48053 100644 --- a/itests/wdpost_dispute_test.go +++ b/itests/wdpost_dispute_test.go @@ -8,15 +8,18 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" + prooftypes "github.com/filecoin-project/go-state-types/proof" + + "github.com/filecoin-project/go-state-types/builtin" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - minerActor "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/itests/kit" - proof3 "github.com/filecoin-project/specs-actors/v3/actors/runtime/proof" "github.com/stretchr/testify/require" ) @@ -140,7 +143,7 @@ func TestWindowPostDispute(t *testing.T) { // OBJECTION! The good miner files a DISPUTE!!!! { - params := &minerActor.DisputeWindowedPoStParams{ + params := &minertypes.DisputeWindowedPoStParams{ Deadline: evilSectorLoc.Deadline, PoStIndex: 0, } @@ -150,7 +153,7 @@ func TestWindowPostDispute(t *testing.T) { msg := &types.Message{ To: evilMinerAddr, - Method: minerActor.Methods.DisputeWindowedPoSt, + Method: builtin.MethodsMiner.DisputeWindowedPoSt, Params: enc, Value: types.NewInt(0), From: defaultFrom, @@ -182,8 +185,8 @@ func TestWindowPostDispute(t *testing.T) { minerInfo, err := client.StateMinerInfo(ctx, evilMinerAddr, types.EmptyTSK) require.NoError(t, err) - params := &minerActor.DeclareFaultsRecoveredParams{ - Recoveries: []minerActor.RecoveryDeclaration{{ + params := &minertypes.DeclareFaultsRecoveredParams{ + Recoveries: []minertypes.RecoveryDeclaration{{ Deadline: evilSectorLoc.Deadline, Partition: evilSectorLoc.Partition, Sectors: bitfield.NewFromSet([]uint64{uint64(evilSectorNo)}), @@ -195,7 +198,7 @@ func TestWindowPostDispute(t *testing.T) { msg := &types.Message{ To: evilMinerAddr, - Method: minerActor.Methods.DeclareFaultsRecovered, + Method: builtin.MethodsMiner.DeclareFaultsRecovered, Params: enc, Value: types.FromFil(30), // repay debt. From: minerInfo.Owner, @@ -223,7 +226,8 @@ func TestWindowPostDispute(t *testing.T) { // Now try to be evil again err = submitBadProof(ctx, client, evilMiner.OwnerKey.Address, evilMinerAddr, di, evilSectorLoc.Deadline, evilSectorLoc.Partition) require.Error(t, err) - require.Contains(t, err.Error(), "message execution failed: exit 16, reason: window post failed: invalid PoSt") + require.Contains(t, err.Error(), "invalid post was submitted") + require.Contains(t, err.Error(), "(RetCode=16)") // It didn't work because we're recovering. } @@ -310,7 +314,7 @@ waitForProof: // Try to object to the proof. This should fail. { - params := &minerActor.DisputeWindowedPoStParams{ + params := &minertypes.DisputeWindowedPoStParams{ Deadline: targetDeadline, PoStIndex: 0, } @@ -320,14 +324,15 @@ waitForProof: msg := &types.Message{ To: maddr, - Method: minerActor.Methods.DisputeWindowedPoSt, + Method: builtin.MethodsMiner.DisputeWindowedPoSt, Params: enc, Value: types.NewInt(0), From: defaultFrom, } _, err := client.MpoolPushMessage(ctx, msg, nil) require.Error(t, err) - require.Contains(t, err.Error(), "failed to dispute valid post (RetCode=16)") + require.Contains(t, err.Error(), "failed to dispute valid post") + require.Contains(t, err.Error(), "(RetCode=16)") } } @@ -356,12 +361,12 @@ func submitBadProof( if err != nil { return err } - params := &minerActor.SubmitWindowedPoStParams{ + params := &minertypes.SubmitWindowedPoStParams{ ChainCommitEpoch: commEpoch, ChainCommitRand: commRand, Deadline: dlIdx, - Partitions: []minerActor.PoStPartition{{Index: partIdx}}, - Proofs: []proof3.PoStProof{{ + Partitions: []minertypes.PoStPartition{{Index: partIdx}}, + Proofs: []prooftypes.PoStProof{{ PoStProof: minerInfo.WindowPoStProofType, ProofBytes: []byte("I'm soooo very evil."), }}, @@ -374,7 +379,7 @@ func submitBadProof( msg := &types.Message{ To: maddr, - Method: minerActor.Methods.SubmitWindowedPoSt, + Method: builtin.MethodsMiner.SubmitWindowedPoSt, Params: enc, Value: types.NewInt(0), From: owner, diff --git a/lotuspond/front/src/chain/methodgen.go b/lotuspond/front/src/chain/methodgen.go index 057ec7d01..da174bfaa 100644 --- a/lotuspond/front/src/chain/methodgen.go +++ b/lotuspond/front/src/chain/methodgen.go @@ -5,10 +5,9 @@ import ( "io/ioutil" "os" - "github.com/multiformats/go-multihash" - "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/consensus/filcns" ) @@ -46,12 +45,7 @@ func main() { out := map[string][]string{} for c, methods := range filcns.NewActorRegistry().Methods { - cmh, err := multihash.Decode(c.Hash()) - if err != nil { - panic(err) - } - - name := string(cmh.Digest) + name := builtin.ActorNameByCode(c) remaining := len(methods) // iterate over actor methods in order. diff --git a/lotuspond/front/src/chain/methods.json b/lotuspond/front/src/chain/methods.json index 15c04ca28..938105528 100644 --- a/lotuspond/front/src/chain/methods.json +++ b/lotuspond/front/src/chain/methods.json @@ -730,5 +730,113 @@ "UseBytes", "RestoreBytes", "RemoveVerifiedClientDataCap" + ], + "fil/8/account": [ + "Send", + "Constructor", + "PubkeyAddress" + ], + "fil/8/cron": [ + "Send", + "Constructor", + "EpochTick" + ], + "fil/8/init": [ + "Send", + "Constructor", + "Exec" + ], + "fil/8/multisig": [ + "Send", + "Constructor", + "Propose", + "Approve", + "Cancel", + "AddSigner", + "RemoveSigner", + "SwapSigner", + "ChangeNumApprovalsThreshold", + "LockBalance" + ], + "fil/8/paymentchannel": [ + "Send", + "Constructor", + "UpdateChannelState", + "Settle", + "Collect" + ], + "fil/8/reward": [ + "Send", + "Constructor", + "AwardBlockReward", + "ThisEpochReward", + "UpdateNetworkKPI" + ], + "fil/8/storagemarket": [ + "Send", + "Constructor", + "AddBalance", + "WithdrawBalance", + "PublishStorageDeals", + "VerifyDealsForActivation", + "ActivateDeals", + "OnMinerSectorsTerminate", + "ComputeDataCommitment", + "CronTick" + ], + "fil/8/storageminer": [ + "Send", + "Constructor", + "ControlAddresses", + "ChangeWorkerAddress", + "ChangePeerID", + "SubmitWindowedPoSt", + "PreCommitSector", + "ProveCommitSector", + "ExtendSectorExpiration", + "TerminateSectors", + "DeclareFaults", + "DeclareFaultsRecovered", + "OnDeferredCronEvent", + "CheckSectorProven", + "ApplyRewards", + "ReportConsensusFault", + "WithdrawBalance", + "ConfirmSectorProofsValid", + "ChangeMultiaddrs", + "CompactPartitions", + "CompactSectorNumbers", + "ConfirmUpdateWorkerKey", + "RepayDebt", + "ChangeOwnerAddress", + "DisputeWindowedPoSt", + "PreCommitSectorBatch", + "ProveCommitAggregate", + "ProveReplicaUpdates" + ], + "fil/8/storagepower": [ + "Send", + "Constructor", + "CreateMiner", + "UpdateClaimedPower", + "EnrollCronEvent", + "CronTick", + "UpdatePledgeTotal", + "SubmitPoRepForBulkVerify", + "CurrentTotalPower" + ], + "fil/8/system": [ + "Send", + "Constructor" + ], + "fil/8/verifiedregistry": [ + "Send", + "Constructor", + "AddVerifier", + "RemoveVerifier", + "AddVerifiedClient", + "UseBytes", + "RestoreBytes", + "RemoveVerifiedClientDataCap" ] } \ No newline at end of file diff --git a/markets/dagstore/miner_api_test.go b/markets/dagstore/miner_api_test.go index 637600bfc..f39bcb8de 100644 --- a/markets/dagstore/miner_api_test.go +++ b/markets/dagstore/miner_api_test.go @@ -10,6 +10,8 @@ import ( "testing" "time" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" ds_sync "github.com/ipfs/go-datastore/sync" @@ -18,13 +20,11 @@ import ( "github.com/filecoin-project/dagstore/mount" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" - "github.com/filecoin-project/go-fil-markets/piecestore" piecestoreimpl "github.com/filecoin-project/go-fil-markets/piecestore/impl" "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/shared" + "github.com/filecoin-project/go-state-types/abi" ) const unsealedSectorID = abi.SectorNumber(1) @@ -242,7 +242,7 @@ func (m *mockRPN) GetMinerWorkerAddress(ctx context.Context, miner address.Addre panic("implement me") } -func (m *mockRPN) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount, tok shared.TipSetToken) (abi.TokenAmount, error) { +func (m *mockRPN) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paychtypes.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount, tok shared.TipSetToken) (abi.TokenAmount, error) { panic("implement me") } diff --git a/markets/dagstore/wrapper_migration_test.go b/markets/dagstore/wrapper_migration_test.go index 6c04f6929..be723704e 100644 --- a/markets/dagstore/wrapper_migration_test.go +++ b/markets/dagstore/wrapper_migration_test.go @@ -6,6 +6,8 @@ import ( "io" "testing" + markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market" + mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/stretchr/testify/require" @@ -20,8 +22,6 @@ import ( "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/lotus/node/config" - - "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" ) func TestShardRegistration(t *testing.T) { @@ -63,8 +63,8 @@ func TestShardRegistration(t *testing.T) { //stm: @MARKET_DAGSTORE_MIGRATE_DEALS_001 State: storagemarket.StorageDealSealing, SectorNumber: unsealedSector1, - ClientDealProposal: market.ClientDealProposal{ - Proposal: market.DealProposal{ + ClientDealProposal: markettypes.ClientDealProposal{ + Proposal: markettypes.DealProposal{ PieceCID: pieceCidUnsealed, }, }, @@ -72,8 +72,8 @@ func TestShardRegistration(t *testing.T) { // Should be registered with lazy registration (because sector is sealed) State: storagemarket.StorageDealSealing, SectorNumber: sealedSector, - ClientDealProposal: market.ClientDealProposal{ - Proposal: market.DealProposal{ + ClientDealProposal: markettypes.ClientDealProposal{ + Proposal: markettypes.DealProposal{ PieceCID: pieceCidSealed, }, }, @@ -82,8 +82,8 @@ func TestShardRegistration(t *testing.T) { //stm: @MARKET_DAGSTORE_MIGRATE_DEALS_003 State: storagemarket.StorageDealError, SectorNumber: unsealedSector2, - ClientDealProposal: market.ClientDealProposal{ - Proposal: market.DealProposal{ + ClientDealProposal: markettypes.ClientDealProposal{ + Proposal: markettypes.DealProposal{ PieceCID: pieceCidUnsealed2, }, }, @@ -91,8 +91,8 @@ func TestShardRegistration(t *testing.T) { // Should be ignored because deal is not yet sealing State: storagemarket.StorageDealFundsReserved, SectorNumber: unsealedSector3, - ClientDealProposal: market.ClientDealProposal{ - Proposal: market.DealProposal{ + ClientDealProposal: markettypes.ClientDealProposal{ + Proposal: markettypes.DealProposal{ PieceCID: pieceCidUnsealed3, }, }, diff --git a/markets/retrievaladapter/client.go b/markets/retrievaladapter/client.go index 74f02570b..e08d78c38 100644 --- a/markets/retrievaladapter/client.go +++ b/markets/retrievaladapter/client.go @@ -10,8 +10,8 @@ import ( "github.com/ipfs/go-cid" "github.com/multiformats/go-multiaddr" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/impl/full" payapi "github.com/filecoin-project/lotus/node/impl/paych" @@ -63,7 +63,7 @@ func (rcn *retrievalClientNode) AllocateLane(ctx context.Context, paymentChannel // CreatePaymentVoucher creates a new payment voucher in the given lane for a // given payment channel so that all the payment vouchers in the lane add up // to the given amount (so the payment voucher will be for the difference) -func (rcn *retrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount abi.TokenAmount, lane uint64, tok shared.TipSetToken) (*paych.SignedVoucher, error) { +func (rcn *retrievalClientNode) CreatePaymentVoucher(ctx context.Context, paymentChannel address.Address, amount abi.TokenAmount, lane uint64, tok shared.TipSetToken) (*paychtypes.SignedVoucher, error) { // TODO: respect the provided TipSetToken (a serialized TipSetKey) when // querying the chain voucher, err := rcn.payAPI.PaychVoucherCreate(ctx, paymentChannel, amount, lane) diff --git a/markets/retrievaladapter/provider.go b/markets/retrievaladapter/provider.go index 470c1cfc7..31d0acc36 100644 --- a/markets/retrievaladapter/provider.go +++ b/markets/retrievaladapter/provider.go @@ -12,8 +12,8 @@ import ( "github.com/filecoin-project/go-fil-markets/retrievalmarket" "github.com/filecoin-project/go-fil-markets/shared" "github.com/filecoin-project/go-state-types/abi" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/lotus/api/v1api" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" logging "github.com/ipfs/go-log/v2" ) @@ -42,7 +42,7 @@ func (rpn *retrievalProviderNode) GetMinerWorkerAddress(ctx context.Context, min return mi.Worker, err } -func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paych.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount, tok shared.TipSetToken) (abi.TokenAmount, error) { +func (rpn *retrievalProviderNode) SavePaymentVoucher(ctx context.Context, paymentChannel address.Address, voucher *paychtypes.SignedVoucher, proof []byte, expectedAmount abi.TokenAmount, tok shared.TipSetToken) (abi.TokenAmount, error) { // TODO: respect the provided TipSetToken (a serialized TipSetKey) when // querying the chain added, err := rpn.full.PaychVoucherAdd(ctx, paymentChannel, voucher, proof, expectedAmount) diff --git a/markets/storageadapter/api.go b/markets/storageadapter/api.go index c49a96f88..4316174bc 100644 --- a/markets/storageadapter/api.go +++ b/markets/storageadapter/api.go @@ -3,6 +3,7 @@ package storageadapter import ( "context" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" "golang.org/x/xerrors" @@ -20,6 +21,7 @@ type apiWrapper struct { StateGetActor(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*types.Actor, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainHasObj(context.Context, cid.Cid) (bool, error) + ChainPutObj(context.Context, blocks.Block) error } } diff --git a/markets/storageadapter/client.go b/markets/storageadapter/client.go index 198e83a1a..bddd5b4f7 100644 --- a/markets/storageadapter/client.go +++ b/markets/storageadapter/client.go @@ -6,7 +6,7 @@ import ( "bytes" "context" - market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" builtin6 "github.com/filecoin-project/specs-actors/v6/actors/builtin" "github.com/ipfs/go-cid" @@ -184,7 +184,7 @@ func (c *ClientNodeAdapter) ValidatePublishedDeal(ctx context.Context, deal stor return 0, xerrors.Errorf("deal publish message called incorrect method (method=%s)", pubmsg.Method) } - var params marketactor.PublishStorageDealsParams + var params market8.PublishStorageDealsParams if err := params.UnmarshalCBOR(bytes.NewReader(pubmsg.Params)); err != nil { return 0, err } @@ -269,13 +269,13 @@ func (c *ClientNodeAdapter) DealProviderCollateralBounds(ctx context.Context, si } // TODO: Remove dealID parameter, change publishCid to be cid.Cid (instead of pointer) -func (c *ClientNodeAdapter) OnDealSectorPreCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, proposal market0.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorPreCommittedCallback) error { - return c.scMgr.OnDealSectorPreCommitted(ctx, provider, marketactor.DealProposal(proposal), *publishCid, cb) +func (c *ClientNodeAdapter) OnDealSectorPreCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, proposal market8.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorPreCommittedCallback) error { + return c.scMgr.OnDealSectorPreCommitted(ctx, provider, proposal, *publishCid, cb) } // TODO: Remove dealID parameter, change publishCid to be cid.Cid (instead of pointer) -func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, sectorNumber abi.SectorNumber, proposal market0.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorCommittedCallback) error { - return c.scMgr.OnDealSectorCommitted(ctx, provider, sectorNumber, marketactor.DealProposal(proposal), *publishCid, cb) +func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, sectorNumber abi.SectorNumber, proposal market8.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorCommittedCallback) error { + return c.scMgr.OnDealSectorCommitted(ctx, provider, sectorNumber, proposal, *publishCid, cb) } // TODO: Replace dealID parameter with DealProposal @@ -368,7 +368,7 @@ func (c *ClientNodeAdapter) OnDealExpiredOrSlashed(ctx context.Context, dealID a return nil } -func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal market0.DealProposal) (*marketactor.ClientDealProposal, error) { +func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal market8.DealProposal) (*market8.ClientDealProposal, error) { // TODO: output spec signed proposal buf, err := cborutil.Dump(&proposal) if err != nil { @@ -387,7 +387,7 @@ func (c *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Add return nil, err } - return &marketactor.ClientDealProposal{ + return &market8.ClientDealProposal{ Proposal: proposal, ClientSignature: *sig, }, nil diff --git a/markets/storageadapter/dealpublisher.go b/markets/storageadapter/dealpublisher.go index 65a57d7ce..6e6d37bd4 100644 --- a/markets/storageadapter/dealpublisher.go +++ b/markets/storageadapter/dealpublisher.go @@ -15,14 +15,12 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/exitcode" - market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/market" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/market" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/storage" @@ -31,7 +29,7 @@ import ( type dealPublisherAPI interface { ChainHead(context.Context) (*types.TipSet, error) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) WalletBalance(context.Context, address.Address) (types.BigInt, error) WalletHas(context.Context, address.Address) (bool, error) @@ -69,7 +67,7 @@ type DealPublisher struct { // A deal that is queued to be published type pendingDeal struct { ctx context.Context - deal market2.ClientDealProposal + deal market.ClientDealProposal Result chan publishResult } @@ -79,7 +77,7 @@ type publishResult struct { err error } -func newPendingDeal(ctx context.Context, deal market2.ClientDealProposal) *pendingDeal { +func newPendingDeal(ctx context.Context, deal market.ClientDealProposal) *pendingDeal { return &pendingDeal{ ctx: ctx, deal: deal, @@ -151,7 +149,7 @@ func (p *DealPublisher) PendingDeals() api.PendingDealInfo { } } - pending := make([]market2.ClientDealProposal, len(deals)) + pending := make([]market.ClientDealProposal, len(deals)) for i, deal := range deals { pending[i] = deal.deal } @@ -173,7 +171,7 @@ func (p *DealPublisher) ForcePublishPendingDeals() { p.publishAllDeals() } -func (p *DealPublisher) Publish(ctx context.Context, deal market2.ClientDealProposal) (cid.Cid, error) { +func (p *DealPublisher) Publish(ctx context.Context, deal market.ClientDealProposal) (cid.Cid, error) { pdeal := newPendingDeal(ctx, deal) // Add the deal to the queue @@ -297,7 +295,7 @@ func (p *DealPublisher) publishReady(ready []*pendingDeal) { // Validate each deal to make sure it can be published validated := make([]*pendingDeal, 0, len(ready)) - deals := make([]market2.ClientDealProposal, 0, len(ready)) + deals := make([]market.ClientDealProposal, 0, len(ready)) for _, pd := range ready { // Validate the deal if err := p.validateDeal(pd.deal); err != nil { @@ -321,7 +319,7 @@ func (p *DealPublisher) publishReady(ready []*pendingDeal) { // validateDeal checks that the deal proposal start epoch hasn't already // elapsed -func (p *DealPublisher) validateDeal(deal market2.ClientDealProposal) error { +func (p *DealPublisher) validateDeal(deal market.ClientDealProposal) error { start := time.Now() pcid, err := deal.Proposal.Cid() @@ -344,8 +342,8 @@ func (p *DealPublisher) validateDeal(deal market2.ClientDealProposal) error { return xerrors.Errorf("getting provider info: %w", err) } - params, err := actors.SerializeParams(&market2.PublishStorageDealsParams{ - Deals: []market0.ClientDealProposal{deal}, + params, err := actors.SerializeParams(&market.PublishStorageDealsParams{ + Deals: []market.ClientDealProposal{deal}, }) if err != nil { return xerrors.Errorf("serializing PublishStorageDeals params failed: %w", err) @@ -357,10 +355,10 @@ func (p *DealPublisher) validateDeal(deal market2.ClientDealProposal) error { } res, err := p.api.StateCall(p.ctx, &types.Message{ - To: market.Address, + To: builtin.StorageMarketActorAddr, From: addr, Value: types.NewInt(0), - Method: market.Methods.PublishStorageDeals, + Method: builtin.MethodsMarket.PublishStorageDeals, Params: params, }, head.Key()) if err != nil { @@ -377,7 +375,7 @@ func (p *DealPublisher) validateDeal(deal market2.ClientDealProposal) error { } // Sends the publish message -func (p *DealPublisher) publishDealProposals(deals []market2.ClientDealProposal) (cid.Cid, error) { +func (p *DealPublisher) publishDealProposals(deals []market.ClientDealProposal) (cid.Cid, error) { if len(deals) == 0 { return cid.Undef, nil } @@ -400,7 +398,7 @@ func (p *DealPublisher) publishDealProposals(deals []market2.ClientDealProposal) return cid.Undef, err } - params, err := actors.SerializeParams(&market2.PublishStorageDealsParams{ + params, err := actors.SerializeParams(&market.PublishStorageDealsParams{ Deals: deals, }) @@ -414,10 +412,10 @@ func (p *DealPublisher) publishDealProposals(deals []market2.ClientDealProposal) } smsg, err := p.api.MpoolPushMessage(p.ctx, &types.Message{ - To: market.Address, + To: builtin.StorageMarketActorAddr, From: addr, Value: types.NewInt(0), - Method: market.Methods.PublishStorageDeals, + Method: builtin.MethodsMarket.PublishStorageDeals, Params: params, }, p.publishSpec) @@ -427,7 +425,7 @@ func (p *DealPublisher) publishDealProposals(deals []market2.ClientDealProposal) return smsg.Cid(), nil } -func pieceCids(deals []market2.ClientDealProposal) string { +func pieceCids(deals []market.ClientDealProposal) string { cids := make([]string, 0, len(deals)) for _, dl := range deals { cids = append(cids, dl.Proposal.PieceCID.String()) diff --git a/markets/storageadapter/dealpublisher_test.go b/markets/storageadapter/dealpublisher_test.go index a0ee0ae06..c0251b2c8 100644 --- a/markets/storageadapter/dealpublisher_test.go +++ b/markets/storageadapter/dealpublisher_test.go @@ -7,6 +7,8 @@ import ( "testing" "time" + markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/ipfs/go-cid" "github.com/raulk/clock" "golang.org/x/xerrors" @@ -17,15 +19,12 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/exitcode" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" tutils "github.com/filecoin-project/specs-actors/v2/support/testing" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin/market" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" - market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" ) func TestDealPublisher(t *testing.T) { @@ -120,7 +119,7 @@ func TestDealPublisher(t *testing.T) { }, &api.MessageSendSpec{MaxFee: abi.NewTokenAmount(1)}) // Keep a record of the deals that were submitted to be published - var dealsToPublish []market.ClientDealProposal + var dealsToPublish []markettypes.ClientDealProposal // Publish deals within publish period for i := 0; i < tc.dealCountWithinPublishPeriod; i++ { @@ -203,7 +202,7 @@ func TestForcePublish(t *testing.T) { }, &api.MessageSendSpec{MaxFee: abi.NewTokenAmount(1)}) // Queue three deals for publishing, one with a cancelled context - var dealsToPublish []market.ClientDealProposal + var dealsToPublish []markettypes.ClientDealProposal // 1. Regular deal deal := publishDeal(t, dp, 0, false, false) dealsToPublish = append(dealsToPublish, deal) @@ -235,7 +234,7 @@ func TestForcePublish(t *testing.T) { checkPublishedDeals(t, dpapi, dealsToPublish, []int{2}) } -func publishDeal(t *testing.T, dp *DealPublisher, invalid int, ctxCancelled bool, expired bool) market.ClientDealProposal { +func publishDeal(t *testing.T, dp *DealPublisher, invalid int, ctxCancelled bool, expired bool) markettypes.ClientDealProposal { ctx, cancel := context.WithCancel(context.Background()) t.Cleanup(cancel) @@ -249,8 +248,8 @@ func publishDeal(t *testing.T, dp *DealPublisher, invalid int, ctxCancelled bool if expired { startEpoch = abi.ChainEpoch(5) } - deal := market.ClientDealProposal{ - Proposal: market0.DealProposal{ + deal := markettypes.ClientDealProposal{ + Proposal: markettypes.DealProposal{ PieceCID: generateCids(1)[0], Client: getClientActor(t), Provider: getProviderActor(t), @@ -282,9 +281,9 @@ func publishDeal(t *testing.T, dp *DealPublisher, invalid int, ctxCancelled bool return deal } -func checkPublishedDeals(t *testing.T, dpapi *dpAPI, dealsToPublish []market.ClientDealProposal, expectedDealsPerMsg []int) { +func checkPublishedDeals(t *testing.T, dpapi *dpAPI, dealsToPublish []markettypes.ClientDealProposal, expectedDealsPerMsg []int) { // For each message that was expected to be sent - var publishedDeals []market.ClientDealProposal + var publishedDeals []markettypes.ClientDealProposal for _, expectedDealsInMsg := range expectedDealsPerMsg { // Should have called StateMinerInfo with the provider address stateMinerInfoAddr := <-dpapi.stateMinerInfoCalls @@ -297,7 +296,7 @@ func checkPublishedDeals(t *testing.T, dpapi *dpAPI, dealsToPublish []market.Cli require.Equal(t, market.Methods.PublishStorageDeals, msg.Method) // Check that the expected number of deals was included in the message - var params market2.PublishStorageDealsParams + var params markettypes.PublishStorageDealsParams err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)) require.NoError(t, err) require.Len(t, params.Deals, expectedDealsInMsg) @@ -313,7 +312,7 @@ func checkPublishedDeals(t *testing.T, dpapi *dpAPI, dealsToPublish []market.Cli require.True(t, matchPieceCids(publishedDeals, dealsToPublish)) } -func matchPieceCids(sent []market.ClientDealProposal, exp []market.ClientDealProposal) bool { +func matchPieceCids(sent []markettypes.ClientDealProposal, exp []markettypes.ClientDealProposal) bool { cidsA := dealPieceCids(sent) cidsB := dealPieceCids(exp) @@ -335,7 +334,7 @@ func matchPieceCids(sent []market.ClientDealProposal, exp []market.ClientDealPro return true } -func dealPieceCids(deals []market2.ClientDealProposal) []cid.Cid { +func dealPieceCids(deals []markettypes.ClientDealProposal) []cid.Cid { cids := make([]cid.Cid, 0, len(deals)) for _, dl := range deals { cids = append(cids, dl.Proposal.PieceCID) @@ -374,9 +373,9 @@ func (d *dpAPI) ChainHead(ctx context.Context) (*types.TipSet, error) { }}) } -func (d *dpAPI) StateMinerInfo(ctx context.Context, address address.Address, key types.TipSetKey) (miner.MinerInfo, error) { +func (d *dpAPI) StateMinerInfo(ctx context.Context, address address.Address, key types.TipSetKey) (api.MinerInfo, error) { d.stateMinerInfoCalls <- address - return miner.MinerInfo{Worker: d.worker}, nil + return api.MinerInfo{Worker: d.worker}, nil } func (d *dpAPI) MpoolPushMessage(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec) (*types.SignedMessage, error) { @@ -401,7 +400,7 @@ func (d *dpAPI) StateLookupID(ctx context.Context, a address.Address, key types. } func (d *dpAPI) StateCall(ctx context.Context, message *types.Message, key types.TipSetKey) (*api.InvocResult, error) { - var p market2.PublishStorageDealsParams + var p markettypes.PublishStorageDealsParams if err := p.UnmarshalCBOR(bytes.NewReader(message.Params)); err != nil { return nil, xerrors.Errorf("unmarshal market params: %w", err) } diff --git a/markets/storageadapter/ondealsectorcommitted.go b/markets/storageadapter/ondealsectorcommitted.go index 94eaadef4..88457b70c 100644 --- a/markets/storageadapter/ondealsectorcommitted.go +++ b/markets/storageadapter/ondealsectorcommitted.go @@ -5,6 +5,8 @@ import ( "context" "sync" + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/go-bitfield" sealing "github.com/filecoin-project/lotus/extern/storage-sealing" "github.com/ipfs/go-cid" @@ -13,11 +15,11 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-fil-markets/storagemarket" "github.com/filecoin-project/go-state-types/abi" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/builtin/market" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/types" ) @@ -31,7 +33,7 @@ type dealInfoAPI interface { } type diffPreCommitsAPI interface { - diffPreCommits(ctx context.Context, actor address.Address, pre, cur types.TipSetKey) (*miner.PreCommitChanges, error) + diffPreCommits(ctx context.Context, actor address.Address, pre, cur types.TipSetKey) (*lminer.PreCommitChanges, error) } type SectorCommittedManager struct { @@ -111,7 +113,7 @@ func (mgr *SectorCommittedManager) OnDealSectorPreCommitted(ctx context.Context, // Watch for a pre-commit message to the provider. matchEvent := func(msg *types.Message) (bool, error) { - matched := msg.To == provider && (msg.Method == miner.Methods.PreCommitSector || msg.Method == miner.Methods.PreCommitSectorBatch || msg.Method == miner.Methods.ProveReplicaUpdates) + matched := msg.To == provider && (msg.Method == builtin.MethodsMiner.PreCommitSector || msg.Method == builtin.MethodsMiner.PreCommitSectorBatch || msg.Method == builtin.MethodsMiner.ProveReplicaUpdates) return matched, nil } @@ -147,7 +149,7 @@ func (mgr *SectorCommittedManager) OnDealSectorPreCommitted(ctx context.Context, } // If this is a replica update method that succeeded the deal is active - if msg.Method == miner.Methods.ProveReplicaUpdates { + if msg.Method == builtin.MethodsMiner.ProveReplicaUpdates { sn, err := dealSectorInReplicaUpdateSuccess(msg, rec, res) if err != nil { return false, err @@ -318,7 +320,7 @@ func dealSectorInReplicaUpdateSuccess(msg *types.Message, rec *types.MessageRece // dealSectorInPreCommitMsg tries to find a sector containing the specified deal func dealSectorInPreCommitMsg(msg *types.Message, res sealing.CurrentDealInfo) (*abi.SectorNumber, error) { switch msg.Method { - case miner.Methods.PreCommitSector: + case builtin.MethodsMiner.PreCommitSector: var params miner.SectorPreCommitInfo if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil { return nil, xerrors.Errorf("unmarshal pre commit: %w", err) @@ -331,8 +333,8 @@ func dealSectorInPreCommitMsg(msg *types.Message, res sealing.CurrentDealInfo) ( return ¶ms.SectorNumber, nil } } - case miner.Methods.PreCommitSectorBatch: - var params miner5.PreCommitSectorBatchParams + case builtin.MethodsMiner.PreCommitSectorBatch: + var params miner.PreCommitSectorBatchParams if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil { return nil, xerrors.Errorf("unmarshal pre commit: %w", err) } @@ -356,7 +358,7 @@ func dealSectorInPreCommitMsg(msg *types.Message, res sealing.CurrentDealInfo) ( // sectorInCommitMsg checks if the provided message commits specified sector func sectorInCommitMsg(msg *types.Message, sectorNumber abi.SectorNumber) (bool, error) { switch msg.Method { - case miner.Methods.ProveCommitSector: + case builtin.MethodsMiner.ProveCommitSector: var params miner.ProveCommitSectorParams if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil { return false, xerrors.Errorf("failed to unmarshal prove commit sector params: %w", err) @@ -364,8 +366,8 @@ func sectorInCommitMsg(msg *types.Message, sectorNumber abi.SectorNumber) (bool, return params.SectorNumber == sectorNumber, nil - case miner.Methods.ProveCommitAggregate: - var params miner5.ProveCommitAggregateParams + case builtin.MethodsMiner.ProveCommitAggregate: + var params miner.ProveCommitAggregateParams if err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)); err != nil { return false, xerrors.Errorf("failed to unmarshal prove commit sector params: %w", err) } diff --git a/markets/storageadapter/ondealsectorcommitted_test.go b/markets/storageadapter/ondealsectorcommitted_test.go index b11bf03a5..8b420bdd3 100644 --- a/markets/storageadapter/ondealsectorcommitted_test.go +++ b/markets/storageadapter/ondealsectorcommitted_test.go @@ -10,6 +10,10 @@ import ( "testing" "time" + "github.com/filecoin-project/go-state-types/builtin" + markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + sealing "github.com/filecoin-project/lotus/extern/storage-sealing" "golang.org/x/xerrors" @@ -31,6 +35,9 @@ import ( ) func TestOnDealSectorPreCommitted(t *testing.T) { + label, err := markettypes.NewLabelFromString("success") + require.NoError(t, err) + provider := address.TestAddress ctx := context.Background() publishCid := generateCids(1)[0] @@ -46,7 +53,7 @@ func TestOnDealSectorPreCommitted(t *testing.T) { StoragePricePerEpoch: abi.NewTokenAmount(1), ProviderCollateral: abi.NewTokenAmount(1), ClientCollateral: abi.NewTokenAmount(1), - Label: "success", + Label: label, } unfinishedDeal := &api.MarketDeal{ Proposal: proposal, @@ -91,7 +98,7 @@ func TestOnDealSectorPreCommitted(t *testing.T) { }, matchStates: []matchState{ { - msg: makeMessage(t, provider, miner.Methods.PreCommitSector, &miner.SectorPreCommitInfo{ + msg: makeMessage(t, provider, builtin.MethodsMiner.PreCommitSector, &minertypes.SectorPreCommitInfo{ SectorNumber: sectorNumber, SealedCID: sealedCid, DealIDs: []abi.DealID{dealID}, @@ -109,7 +116,7 @@ func TestOnDealSectorPreCommitted(t *testing.T) { }, matchStates: []matchState{ { - msg: makeMessage(t, provider, miner.Methods.PreCommitSector, &miner.SectorPreCommitInfo{ + msg: makeMessage(t, provider, builtin.MethodsMiner.PreCommitSector, &minertypes.SectorPreCommitInfo{ SectorNumber: sectorNumber, SealedCID: sealedCid, DealIDs: []abi.DealID{dealID}, @@ -126,8 +133,8 @@ func TestOnDealSectorPreCommitted(t *testing.T) { MarketDeal: unfinishedDeal, }, preCommitDiff: &miner.PreCommitChanges{ - Added: []miner.SectorPreCommitOnChainInfo{{ - Info: miner.SectorPreCommitInfo{ + Added: []minertypes.SectorPreCommitOnChainInfo{{ + Info: minertypes.SectorPreCommitInfo{ SectorNumber: sectorNumber, DealIDs: []abi.DealID{dealID}, }, @@ -167,7 +174,7 @@ func TestOnDealSectorPreCommitted(t *testing.T) { currentDealInfoErr2: errors.New("something went wrong"), matchStates: []matchState{ { - msg: makeMessage(t, provider, miner.Methods.PreCommitSector, &miner.SectorPreCommitInfo{ + msg: makeMessage(t, provider, builtin.MethodsMiner.PreCommitSector, &minertypes.SectorPreCommitInfo{ SectorNumber: sectorNumber, SealedCID: sealedCid, DealIDs: []abi.DealID{dealID}, @@ -252,6 +259,9 @@ func TestOnDealSectorPreCommitted(t *testing.T) { } func TestOnDealSectorCommitted(t *testing.T) { + label, err := markettypes.NewLabelFromString("success") + require.NoError(t, err) + provider := address.TestAddress publishCid := generateCids(1)[0] pieceCid := generateCids(1)[0] @@ -265,7 +275,7 @@ func TestOnDealSectorCommitted(t *testing.T) { StoragePricePerEpoch: abi.NewTokenAmount(1), ProviderCollateral: abi.NewTokenAmount(1), ClientCollateral: abi.NewTokenAmount(1), - Label: "success", + Label: label, } unfinishedDeal := &api.MarketDeal{ Proposal: proposal, @@ -312,7 +322,7 @@ func TestOnDealSectorCommitted(t *testing.T) { }, matchStates: []matchState{ { - msg: makeMessage(t, provider, miner.Methods.ProveCommitSector, &miner.ProveCommitSectorParams{ + msg: makeMessage(t, provider, builtin.MethodsMiner.ProveCommitSector, &minertypes.ProveCommitSectorParams{ SectorNumber: sectorNumber, }), }, @@ -330,7 +340,7 @@ func TestOnDealSectorCommitted(t *testing.T) { }, matchStates: []matchState{ { - msg: makeMessage(t, provider, miner.Methods.ProveCommitSector, &miner.ProveCommitSectorParams{ + msg: makeMessage(t, provider, builtin.MethodsMiner.ProveCommitSector, &minertypes.ProveCommitSectorParams{ SectorNumber: sectorNumber, }), // Exit-code 1 means the prove-commit was unsuccessful @@ -367,7 +377,7 @@ func TestOnDealSectorCommitted(t *testing.T) { currentDealInfoErr2: errors.New("something went wrong"), matchStates: []matchState{ { - msg: makeMessage(t, provider, miner.Methods.ProveCommitSector, &miner.ProveCommitSectorParams{ + msg: makeMessage(t, provider, builtin.MethodsMiner.ProveCommitSector, &minertypes.ProveCommitSectorParams{ SectorNumber: sectorNumber, }), }, @@ -395,7 +405,7 @@ func TestOnDealSectorCommitted(t *testing.T) { }, matchStates: []matchState{ { - msg: makeMessage(t, provider, miner.Methods.ProveCommitSector, &miner.ProveCommitSectorParams{ + msg: makeMessage(t, provider, builtin.MethodsMiner.ProveCommitSector, &minertypes.ProveCommitSectorParams{ SectorNumber: sectorNumber, }), }, diff --git a/markets/storageadapter/provider.go b/markets/storageadapter/provider.go index 0828db271..ef8b8b76d 100644 --- a/markets/storageadapter/provider.go +++ b/markets/storageadapter/provider.go @@ -6,6 +6,8 @@ import ( "context" "time" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/ipfs/go-cid" logging "github.com/ipfs/go-log/v2" "go.uber.org/fx" @@ -17,7 +19,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/exitcode" - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/v1api" @@ -284,13 +285,13 @@ func (n *ProviderNodeAdapter) DealProviderCollateralBounds(ctx context.Context, } // TODO: Remove dealID parameter, change publishCid to be cid.Cid (instead of pointer) -func (n *ProviderNodeAdapter) OnDealSectorPreCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, proposal market2.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorPreCommittedCallback) error { - return n.scMgr.OnDealSectorPreCommitted(ctx, provider, market.DealProposal(proposal), *publishCid, cb) +func (n *ProviderNodeAdapter) OnDealSectorPreCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, proposal market8.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorPreCommittedCallback) error { + return n.scMgr.OnDealSectorPreCommitted(ctx, provider, proposal, *publishCid, cb) } // TODO: Remove dealID parameter, change publishCid to be cid.Cid (instead of pointer) -func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, sectorNumber abi.SectorNumber, proposal market2.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorCommittedCallback) error { - return n.scMgr.OnDealSectorCommitted(ctx, provider, sectorNumber, market.DealProposal(proposal), *publishCid, cb) +func (n *ProviderNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, sectorNumber abi.SectorNumber, proposal market8.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorCommittedCallback) error { + return n.scMgr.OnDealSectorCommitted(ctx, provider, sectorNumber, proposal, *publishCid, cb) } func (n *ProviderNodeAdapter) GetChainHead(ctx context.Context) (shared.TipSetToken, abi.ChainEpoch, error) { @@ -310,7 +311,7 @@ func (n *ProviderNodeAdapter) WaitForMessage(ctx context.Context, mcid cid.Cid, return cb(receipt.Receipt.ExitCode, receipt.Receipt.Return, receipt.Message, nil) } -func (n *ProviderNodeAdapter) WaitForPublishDeals(ctx context.Context, publishCid cid.Cid, proposal market2.DealProposal) (*storagemarket.PublishDealsWaitResult, error) { +func (n *ProviderNodeAdapter) WaitForPublishDeals(ctx context.Context, publishCid cid.Cid, proposal market8.DealProposal) (*storagemarket.PublishDealsWaitResult, error) { // Wait for deal to be published (plus additional time for confidence) receipt, err := n.StateWaitMsg(ctx, publishCid, 2*build.MessageConfidence, api.LookbackNoLimit, true) if err != nil { @@ -327,7 +328,7 @@ func (n *ProviderNodeAdapter) WaitForPublishDeals(ctx context.Context, publishCi return nil, xerrors.Errorf("WaitForPublishDeals failed to get chain head: %w", err) } - res, err := n.scMgr.dealInfo.GetCurrentDealInfo(ctx, head.Key().Bytes(), (*market.DealProposal)(&proposal), publishCid) + res, err := n.scMgr.dealInfo.GetCurrentDealInfo(ctx, head.Key().Bytes(), &proposal, publishCid) if err != nil { return nil, xerrors.Errorf("WaitForPublishDeals getting deal info errored: %w", err) } diff --git a/miner/miner.go b/miner/miner.go index 976e9ca6f..6fbf159bf 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -10,12 +10,12 @@ import ( "sync" "time" + "github.com/filecoin-project/go-state-types/proof" + lrand "github.com/filecoin-project/lotus/chain/rand" "github.com/filecoin-project/lotus/api/v1api" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" - "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/gen/slashfilter" @@ -260,7 +260,7 @@ minerLoop: } // just wait for the beacon entry to become available before we select our final mining base - _, err = m.api.BeaconGetEntry(ctx, prebase.TipSet.Height()+prebase.NullRounds+1) + _, err = m.api.StateGetBeaconEntry(ctx, prebase.TipSet.Height()+prebase.NullRounds+1) if err != nil { log.Errorf("failed getting beacon entry: %s", err) if !m.niceSleep(time.Second) { @@ -611,7 +611,7 @@ func (m *Miner) computeTicket(ctx context.Context, brand *types.BeaconEntry, bas } func (m *Miner) createBlock(base *MiningBase, addr address.Address, ticket *types.Ticket, - eproof *types.ElectionProof, bvals []types.BeaconEntry, wpostProof []proof2.PoStProof, msgs []*types.SignedMessage) (*types.BlockMsg, error) { + eproof *types.ElectionProof, bvals []types.BeaconEntry, wpostProof []proof.PoStProof, msgs []*types.SignedMessage) (*types.BlockMsg, error) { uts := base.TipSet.MinTimestamp() + build.BlockDelaySecs*(uint64(base.NullRounds)+1) nheight := base.TipSet.Height() + base.NullRounds + 1 diff --git a/node/builder_chain.go b/node/builder_chain.go index 226ecac68..d2c116b96 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -50,7 +50,7 @@ var ChainNode = Options( // Consensus settings Override(new(dtypes.DrandSchedule), modules.BuiltinDrandConfig), - Override(new(stmgr.UpgradeSchedule), filcns.DefaultUpgradeSchedule()), + Override(new(stmgr.UpgradeSchedule), modules.UpgradeSchedule), Override(new(dtypes.NetworkName), modules.NetworkName), Override(new(modules.Genesis), modules.ErrorGenesis), Override(new(dtypes.AfterGenesisSet), modules.SetGenesis), diff --git a/node/bundle/bundle.go b/node/bundle/bundle.go new file mode 100644 index 000000000..b08ff691c --- /dev/null +++ b/node/bundle/bundle.go @@ -0,0 +1,87 @@ +package bundle + +import ( + "bytes" + "context" + "io" + "os" + + "github.com/ipld/go-car" + + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/blockstore" + "github.com/filecoin-project/lotus/build" + "github.com/filecoin-project/lotus/chain/actors" + + cid "github.com/ipfs/go-cid" +) + +func LoadBundleFromFile(ctx context.Context, bs blockstore.Blockstore, path string) (cid.Cid, error) { + f, err := os.Open(path) + if err != nil { + return cid.Undef, xerrors.Errorf("error opening bundle %q for builtin-actors: %w", path, err) + } + defer f.Close() //nolint + + return LoadBundle(ctx, bs, f) +} + +func LoadBundle(ctx context.Context, bs blockstore.Blockstore, r io.Reader) (cid.Cid, error) { + hdr, err := car.LoadCar(ctx, bs, r) + if err != nil { + return cid.Undef, xerrors.Errorf("error loading builtin actors bundle: %w", err) + } + + if len(hdr.Roots) != 1 { + return cid.Undef, xerrors.Errorf("expected one root when loading actors bundle, got %d", len(hdr.Roots)) + } + return hdr.Roots[0], nil +} + +// LoadBundles loads the bundles for the specified actor versions into the passed blockstore, if and +// only if the bundle's manifest is not already present in the blockstore. +func LoadBundles(ctx context.Context, bs blockstore.Blockstore, versions ...actors.Version) error { + for _, av := range versions { + // No bundles before version 8. + if av < actors.Version8 { + continue + } + + manifestCid, ok := actors.GetManifest(av) + if !ok { + // All manifests are registered on start, so this must succeed. + return xerrors.Errorf("unknown actor version v%d", av) + } + + if haveManifest, err := bs.Has(ctx, manifestCid); err != nil { + return xerrors.Errorf("blockstore error when loading manifest %s: %w", manifestCid, err) + } else if haveManifest { + // We already have the manifest, and therefore everything under it. + continue + } + + var ( + root cid.Cid + err error + ) + if path, ok := build.BundleOverrides[av]; ok { + root, err = LoadBundleFromFile(ctx, bs, path) + } else if embedded, ok := build.GetEmbeddedBuiltinActorsBundle(av); ok { + root, err = LoadBundle(ctx, bs, bytes.NewReader(embedded)) + } else { + err = xerrors.Errorf("bundle for actors version v%d not found", av) + } + + if err != nil { + return err + } + + if root != manifestCid { + return xerrors.Errorf("expected manifest for actors version %d does not match actual: %s != %s", av, manifestCid, root) + } + + } + + return nil +} diff --git a/node/hello/cbor_gen.go b/node/hello/cbor_gen.go index 145a19728..68c82e2bb 100644 --- a/node/hello/cbor_gen.go +++ b/node/hello/cbor_gen.go @@ -26,61 +26,67 @@ func (t *HelloMessage) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufHelloMessage); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufHelloMessage); err != nil { return err } - scratch := make([]byte, 9) - // t.HeaviestTipSet ([]cid.Cid) (slice) if len(t.HeaviestTipSet) > cbg.MaxLength { return xerrors.Errorf("Slice value in field t.HeaviestTipSet was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.HeaviestTipSet))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.HeaviestTipSet))); err != nil { return err } for _, v := range t.HeaviestTipSet { - if err := cbg.WriteCidBuf(scratch, w, v); err != nil { + if err := cbg.WriteCid(w, v); err != nil { return xerrors.Errorf("failed writing cid field t.HeaviestTipSet: %w", err) } } // t.HeaviestTipSetHeight (abi.ChainEpoch) (int64) if t.HeaviestTipSetHeight >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.HeaviestTipSetHeight)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.HeaviestTipSetHeight)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.HeaviestTipSetHeight-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.HeaviestTipSetHeight-1)); err != nil { return err } } // t.HeaviestTipSetWeight (big.Int) (struct) - if err := t.HeaviestTipSetWeight.MarshalCBOR(w); err != nil { + if err := t.HeaviestTipSetWeight.MarshalCBOR(cw); err != nil { return err } // t.GenesisHash (cid.Cid) (struct) - if err := cbg.WriteCidBuf(scratch, w, t.GenesisHash); err != nil { + if err := cbg.WriteCid(cw, t.GenesisHash); err != nil { return xerrors.Errorf("failed to write cid field t.GenesisHash: %w", err) } return nil } -func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { +func (t *HelloMessage) UnmarshalCBOR(r io.Reader) (err error) { *t = HelloMessage{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -91,7 +97,7 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { // t.HeaviestTipSet ([]cid.Cid) (slice) - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -110,7 +116,7 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("reading cid field t.HeaviestTipSet failed: %w", err) } @@ -119,7 +125,7 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { // t.HeaviestTipSetHeight (abi.ChainEpoch) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -146,7 +152,7 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { { - if err := t.HeaviestTipSetWeight.UnmarshalCBOR(br); err != nil { + if err := t.HeaviestTipSetWeight.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.HeaviestTipSetWeight: %w", err) } @@ -155,7 +161,7 @@ func (t *HelloMessage) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.GenesisHash: %w", err) } @@ -173,46 +179,52 @@ func (t *LatencyMessage) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write(lengthBufLatencyMessage); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write(lengthBufLatencyMessage); err != nil { return err } - scratch := make([]byte, 9) - // t.TArrival (int64) (int64) if t.TArrival >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TArrival)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.TArrival)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TArrival-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.TArrival-1)); err != nil { return err } } // t.TSent (int64) (int64) if t.TSent >= 0 { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.TSent)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.TSent)); err != nil { return err } } else { - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajNegativeInt, uint64(-t.TSent-1)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajNegativeInt, uint64(-t.TSent-1)); err != nil { return err } } return nil } -func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error { +func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) (err error) { *t = LatencyMessage{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajArray { return fmt.Errorf("cbor input should be of type array") } @@ -223,7 +235,7 @@ func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error { // t.TArrival (int64) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err @@ -248,7 +260,7 @@ func (t *LatencyMessage) UnmarshalCBOR(r io.Reader) error { } // t.TSent (int64) (int64) { - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() var extraI int64 if err != nil { return err diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 5b4791cfa..83806ee80 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -12,6 +12,8 @@ import ( "strings" "time" + market8 "github.com/filecoin-project/go-state-types/builtin/v8/market" + bstore "github.com/ipfs/go-ipfs-blockstore" format "github.com/ipfs/go-ipld-format" unixfile "github.com/ipfs/go-unixfs/file" @@ -60,7 +62,6 @@ import ( "github.com/filecoin-project/lotus/markets/storageadapter" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/v3/actors/builtin/market" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/node/repo/imports" @@ -233,12 +234,17 @@ func (a *API) dealStarter(ctx context.Context, params *api.StartDealParams, isSt // stateless flow from here to the end // - dealProposal := &market.DealProposal{ + label, err := market8.NewLabelFromString(params.Data.Root.Encode(multibase.MustNewEncoder('u'))) + if err != nil { + return nil, xerrors.Errorf("failed to encode label: %w", err) + } + + dealProposal := &market8.DealProposal{ PieceCID: *params.Data.PieceCid, PieceSize: params.Data.PieceSize.Padded(), Client: walletKey, Provider: params.Miner, - Label: params.Data.Root.Encode(multibase.MustNewEncoder('u')), + Label: label, StartEpoch: dealStart, EndEpoch: calcDealExpiration(params.MinBlocksDuration, md, dealStart), StoragePricePerEpoch: big.Zero(), @@ -265,7 +271,7 @@ func (a *API) dealStarter(ctx context.Context, params *api.StartDealParams, isSt return nil, xerrors.Errorf("failed to sign proposal : %w", err) } - dealProposalSigned := &market.ClientDealProposal{ + dealProposalSigned := &market8.ClientDealProposal{ Proposal: *dealProposal, ClientSignature: *dealProposalSig, } diff --git a/node/impl/full.go b/node/impl/full.go index a6f61c305..b66e647a1 100644 --- a/node/impl/full.go +++ b/node/impl/full.go @@ -35,7 +35,6 @@ type FullNodeAPI struct { full.MsigAPI full.WalletAPI full.SyncAPI - full.BeaconAPI DS dtypes.MetadataDS NetworkName dtypes.NetworkName diff --git a/node/impl/full/beacon.go b/node/impl/full/beacon.go deleted file mode 100644 index bc7232c27..000000000 --- a/node/impl/full/beacon.go +++ /dev/null @@ -1,36 +0,0 @@ -package full - -import ( - "context" - "fmt" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/beacon" - "github.com/filecoin-project/lotus/chain/types" - "go.uber.org/fx" -) - -type BeaconAPI struct { - fx.In - - Beacon beacon.Schedule -} - -func (a *BeaconAPI) BeaconGetEntry(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) { - b := a.Beacon.BeaconForEpoch(epoch) - rr := b.MaxBeaconRoundForEpoch(epoch) - e := b.Entry(ctx, rr) - - select { - case be, ok := <-e: - if !ok { - return nil, fmt.Errorf("beacon get returned no value") - } - if be.Err != nil { - return nil, be.Err - } - return &be.Entry, nil - case <-ctx.Done(): - return nil, ctx.Err() - } -} diff --git a/node/impl/full/chain.go b/node/impl/full/chain.go index 61be82bc9..97bf260a4 100644 --- a/node/impl/full/chain.go +++ b/node/impl/full/chain.go @@ -15,6 +15,7 @@ import ( "go.uber.org/fx" "golang.org/x/xerrors" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-blockservice" "github.com/ipfs/go-cid" offline "github.com/ipfs/go-ipfs-exchange-offline" @@ -261,6 +262,10 @@ func (m *ChainModule) ChainReadObj(ctx context.Context, obj cid.Cid) ([]byte, er return blk.RawData(), nil } +func (a *ChainAPI) ChainPutObj(ctx context.Context, obj blocks.Block) error { + return a.ExposedBlockstore.Put(ctx, obj) +} + func (a *ChainAPI) ChainDeleteObj(ctx context.Context, obj cid.Cid) error { return a.ExposedBlockstore.DeleteBlock(ctx, obj) } diff --git a/node/impl/full/gas.go b/node/impl/full/gas.go index dd1e8d5ea..624296254 100644 --- a/node/impl/full/gas.go +++ b/node/impl/full/gas.go @@ -6,8 +6,9 @@ import ( "math/rand" "sort" - "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + lbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin" + + "github.com/filecoin-project/go-state-types/builtin" lru "github.com/hashicorp/golang-lru" "go.uber.org/fx" @@ -295,31 +296,62 @@ func gasEstimateGasLimit( return -1, xerrors.Errorf("message execution failed: exit %s, reason: %s", res.MsgRct.ExitCode, res.Error) } + ret := res.MsgRct.GasUsed + + transitionalMulti := 1.0 + // Overestimate gas around the upgrade + if ts.Height() <= build.UpgradeSkyrHeight && (build.UpgradeSkyrHeight-ts.Height() <= 20) { + transitionalMulti = 2.0 + + func() { + st, err := smgr.ParentState(ts) + if err != nil { + return + } + act, err := st.GetActor(msg.To) + if err != nil { + return + } + + if lbuiltin.IsStorageMinerActor(act.Code) { + switch msgIn.Method { + case 5: + transitionalMulti = 3.954 + case 6: + transitionalMulti = 4.095 + case 7: + // skip, stay at 2.0 + //transitionalMulti = 1.289 + case 11: + transitionalMulti = 17.8758 + case 16: + transitionalMulti = 2.1704 + case 25: + transitionalMulti = 3.1177 + case 26: + transitionalMulti = 2.3322 + default: + } + } + + // skip storage market, 80th percentie for everything ~1.9, leave it at 2.0 + }() + } + ret = (ret * int64(transitionalMulti*1024)) >> 10 + // Special case for PaymentChannel collect, which is deleting actor + // We ignore errors in this special case since they CAN occur, + // and we just want to detect existing payment channel actors st, err := smgr.ParentState(ts) - if err != nil { - _ = err - // somewhat ignore it as it can happen and we just want to detect - // an existing PaymentChannel actor - return res.MsgRct.GasUsed, nil - } - act, err := st.GetActor(msg.To) - if err != nil { - _ = err - // somewhat ignore it as it can happen and we just want to detect - // an existing PaymentChannel actor - return res.MsgRct.GasUsed, nil + if err == nil { + act, err := st.GetActor(msg.To) + if err == nil && lbuiltin.IsPaymentChannelActor(act.Code) && msgIn.Method == builtin.MethodsPaych.Collect { + // add the refunded gas for DestroyActor back into the gas used + ret += 76e3 + } } - if !builtin.IsPaymentChannelActor(act.Code) { - return res.MsgRct.GasUsed, nil - } - if msgIn.Method != paych.Methods.Collect { - return res.MsgRct.GasUsed, nil - } - - // return GasUsed without the refund for DestoryActor - return res.MsgRct.GasUsed + 76e3, nil + return ret, nil } func (m *GasModule) GasEstimateMessageGas(ctx context.Context, msg *types.Message, spec *api.MessageSendSpec, _ types.TipSetKey) (*types.Message, error) { diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 648b3e76e..bc264712c 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -4,12 +4,17 @@ import ( "bytes" "context" "encoding/json" + "fmt" "strconv" + "github.com/filecoin-project/lotus/chain/actors" + + "github.com/libp2p/go-libp2p-core/peer" + "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/cbor" - cid "github.com/ipfs/go-cid" + "github.com/ipfs/go-cid" "go.uber.org/fx" "golang.org/x/xerrors" @@ -22,6 +27,7 @@ import ( "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/actors/builtin/market" @@ -53,7 +59,7 @@ type StateModuleAPI interface { StateLookupID(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (api.MarketBalance, error) StateMarketStorageDeal(ctx context.Context, dealId abi.DealID, tsk types.TipSetKey) (*api.MarketDeal, error) - StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) + StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error) StateMinerProvingDeadline(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*dline.Info, error) StateMinerPower(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) StateNetworkVersion(ctx context.Context, key types.TipSetKey) (network.Version, error) @@ -132,27 +138,52 @@ func (a *StateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Ad return mas.LoadSectors(&activeSectors) } -func (m *StateModule) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (miner.MinerInfo, error) { +func (m *StateModule) StateMinerInfo(ctx context.Context, actor address.Address, tsk types.TipSetKey) (api.MinerInfo, error) { ts, err := m.Chain.GetTipSetFromKey(ctx, tsk) if err != nil { - return miner.MinerInfo{}, xerrors.Errorf("failed to load tipset: %w", err) + return api.MinerInfo{}, xerrors.Errorf("failed to load tipset: %w", err) } act, err := m.StateManager.LoadActor(ctx, actor, ts) if err != nil { - return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor: %w", err) + return api.MinerInfo{}, xerrors.Errorf("failed to load miner actor: %w", err) } mas, err := miner.Load(m.StateManager.ChainStore().ActorStore(ctx), act) if err != nil { - return miner.MinerInfo{}, xerrors.Errorf("failed to load miner actor state: %w", err) + return api.MinerInfo{}, xerrors.Errorf("failed to load miner actor state: %w", err) } info, err := mas.Info() if err != nil { - return miner.MinerInfo{}, err + return api.MinerInfo{}, err } - return info, nil + + var pid *peer.ID + if peerID, err := peer.IDFromBytes(info.PeerId); err == nil { + pid = &peerID + } + + ret := api.MinerInfo{ + Owner: info.Owner, + Worker: info.Worker, + ControlAddresses: info.ControlAddresses, + NewWorker: address.Undef, + WorkerChangeEpoch: -1, + PeerId: pid, + Multiaddrs: info.Multiaddrs, + WindowPoStProofType: info.WindowPoStProofType, + SectorSize: info.SectorSize, + WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, + ConsensusFaultElapsed: info.ConsensusFaultElapsed, + } + + if info.PendingWorkerKey != nil { + ret.NewWorker = info.PendingWorkerKey.NewWorker + ret.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt + } + + return ret, nil } func (a *StateAPI) StateMinerDeadlines(ctx context.Context, m address.Address, tsk types.TipSetKey) ([]api.Deadline, error) { @@ -680,8 +711,8 @@ func (a *StateAPI) StateMarketParticipants(ctx context.Context, tsk types.TipSet return out, nil } -func (a *StateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]api.MarketDeal, error) { - out := map[string]api.MarketDeal{} +func (a *StateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]*api.MarketDeal, error) { + out := map[string]*api.MarketDeal{} ts, err := a.Chain.GetTipSetFromKey(ctx, tsk) if err != nil { @@ -710,7 +741,7 @@ func (a *StateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (m } else if !found { s = market.EmptyDealState() } - out[strconv.FormatInt(int64(dealID), 10)] = api.MarketDeal{ + out[strconv.FormatInt(int64(dealID), 10)] = &api.MarketDeal{ Proposal: d, State: *s, } @@ -786,17 +817,17 @@ func (a *StateAPI) StateMinerSectorCount(ctx context.Context, addr address.Addre return api.MinerSectors{Live: liveCount, Active: activeCount, Faulty: faultyCount}, nil } -func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) { +func (a *StateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (minertypes.SectorPreCommitOnChainInfo, error) { ts, err := a.Chain.GetTipSetFromKey(ctx, tsk) if err != nil { - return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) + return minertypes.SectorPreCommitOnChainInfo{}, xerrors.Errorf("loading tipset %s: %w", tsk, err) } pci, err := stmgr.PreCommitInfo(ctx, a.StateManager, maddr, n, ts) if err != nil { - return miner.SectorPreCommitOnChainInfo{}, err + return minertypes.SectorPreCommitOnChainInfo{}, err } else if pci == nil { - return miner.SectorPreCommitOnChainInfo{}, xerrors.Errorf("precommit info is not exists") + return minertypes.SectorPreCommitOnChainInfo{}, xerrors.Errorf("precommit info is not exists") } return *pci, err @@ -1062,7 +1093,7 @@ func (m *StateModule) MsigGetPending(ctx context.Context, addr address.Address, var initialPledgeNum = types.NewInt(110) var initialPledgeDen = types.NewInt(100) -func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) { +func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr address.Address, pci minertypes.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) { ts, err := a.Chain.GetTipSetFromKey(ctx, tsk) if err != nil { return types.EmptyInt, xerrors.Errorf("loading tipset %s: %w", tsk, err) @@ -1122,7 +1153,7 @@ func (a *StateAPI) StateMinerPreCommitDepositForPower(ctx context.Context, maddr return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil } -func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) { +func (a *StateAPI) StateMinerInitialPledgeCollateral(ctx context.Context, maddr address.Address, pci minertypes.SectorPreCommitInfo, tsk types.TipSetKey) (types.BigInt, error) { // TODO: this repeats a lot of the previous function. Fix that. ts, err := a.Chain.GetTipSetFromKey(ctx, tsk) if err != nil { @@ -1431,6 +1462,33 @@ func (m *StateModule) StateNetworkVersion(ctx context.Context, tsk types.TipSetK return m.StateManager.GetNetworkVersion(ctx, ts.Height()), nil } +func (a *StateAPI) StateActorCodeCIDs(ctx context.Context, nv network.Version) (map[string]cid.Cid, error) { + actorVersion, err := actors.VersionForNetwork(nv) + if err != nil { + return nil, xerrors.Errorf("invalid network version") + } + + cids := make(map[string]cid.Cid) + + manifestCid, ok := actors.GetManifest(actorVersion) + if !ok { + return nil, xerrors.Errorf("cannot get manifest CID") + } + + cids["_manifest"] = manifestCid + + var actorKeys = actors.GetBuiltinActorsKeys() + for _, name := range actorKeys { + actorCID, ok := actors.GetActorCodeID(actorVersion, name) + if !ok { + return nil, xerrors.Errorf("didn't find actor %v code id for actor version %d", name, + actorVersion) + } + cids[name] = actorCID + } + return cids, nil +} + func (a *StateAPI) StateGetRandomnessFromTickets(ctx context.Context, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte, tsk types.TipSetKey) (abi.Randomness, error) { return a.StateManager.GetRandomnessFromTickets(ctx, personalization, randEpoch, entropy, tsk) } @@ -1440,6 +1498,25 @@ func (a *StateAPI) StateGetRandomnessFromBeacon(ctx context.Context, personaliza } +func (a *StateAPI) StateGetBeaconEntry(ctx context.Context, epoch abi.ChainEpoch) (*types.BeaconEntry, error) { + b := a.Beacon.BeaconForEpoch(epoch) + rr := b.MaxBeaconRoundForEpoch(a.StateManager.GetNetworkVersion(ctx, epoch), epoch) + e := b.Entry(ctx, rr) + + select { + case be, ok := <-e: + if !ok { + return nil, fmt.Errorf("beacon get returned no value") + } + if be.Err != nil { + return nil, be.Err + } + return &be.Entry, nil + case <-ctx.Done(): + return nil, ctx.Err() + } +} + func (a *StateAPI) StateGetNetworkParams(ctx context.Context) (*api.NetworkParams, error) { networkName, err := a.StateNetworkName(ctx) if err != nil { diff --git a/node/impl/paych/paych.go b/node/impl/paych/paych.go index d338c6032..04ffbfe6a 100644 --- a/node/impl/paych/paych.go +++ b/node/impl/paych/paych.go @@ -10,8 +10,8 @@ import ( "github.com/filecoin-project/go-address" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/paychmgr" ) @@ -83,10 +83,10 @@ func (a *PaychAPI) PaychNewPayment(ctx context.Context, from, to address.Address return nil, err } - svs := make([]*paych.SignedVoucher, len(vouchers)) + svs := make([]*paychtypes.SignedVoucher, len(vouchers)) for i, v := range vouchers { - sv, err := a.PaychMgr.CreateVoucher(ctx, ch.Channel, paych.SignedVoucher{ + sv, err := a.PaychMgr.CreateVoucher(ctx, ch.Channel, paychtypes.SignedVoucher{ Amount: v.Amount, Lane: lane, @@ -135,15 +135,15 @@ func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid. return a.PaychMgr.Collect(ctx, addr) } -func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error { +func (a *PaychAPI) PaychVoucherCheckValid(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher) error { return a.PaychMgr.CheckVoucherValid(ctx, ch, sv) } -func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (a *PaychAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, secret []byte, proof []byte) (bool, error) { return a.PaychMgr.CheckVoucherSpendable(ctx, ch, sv, secret, proof) } -func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { return a.PaychMgr.AddVoucherInbound(ctx, ch, sv, proof, minDelta) } @@ -155,16 +155,16 @@ func (a *PaychAPI) PaychVoucherAdd(ctx context.Context, ch address.Address, sv * // If there are insufficient funds in the channel to create the voucher, // returns a nil voucher and the shortfall. func (a *PaychAPI) PaychVoucherCreate(ctx context.Context, pch address.Address, amt types.BigInt, lane uint64) (*api.VoucherCreateResult, error) { - return a.PaychMgr.CreateVoucher(ctx, pch, paych.SignedVoucher{Amount: amt, Lane: lane}) + return a.PaychMgr.CreateVoucher(ctx, pch, paychtypes.SignedVoucher{Amount: amt, Lane: lane}) } -func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error) { +func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paychtypes.SignedVoucher, error) { vi, err := a.PaychMgr.ListVouchers(ctx, pch) if err != nil { return nil, err } - out := make([]*paych.SignedVoucher, len(vi)) + out := make([]*paychtypes.SignedVoucher, len(vi)) for k, v := range vi { out[k] = v.Voucher } @@ -172,6 +172,6 @@ func (a *PaychAPI) PaychVoucherList(ctx context.Context, pch address.Address) ([ return out, nil } -func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { +func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { return a.PaychMgr.SubmitVoucher(ctx, ch, sv, secret, proof) } diff --git a/node/impl/storminer.go b/node/impl/storminer.go index f34761d89..76c7fe010 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -11,12 +11,13 @@ import ( "strconv" "time" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + "github.com/filecoin-project/dagstore" "github.com/filecoin-project/dagstore/shard" "github.com/filecoin-project/go-jsonrpc/auth" "github.com/filecoin-project/lotus/chain/actors/builtin" - lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/gen" "github.com/google/uuid" @@ -410,7 +411,7 @@ func (sm *StorageMinerAPI) SectorMatchPendingPiecesToOpenSectors(ctx context.Con return sm.Miner.SectorMatchPendingPiecesToOpenSectors(ctx) } -func (sm *StorageMinerAPI) ComputeWindowPoSt(ctx context.Context, dlIdx uint64, tsk types.TipSetKey) ([]lminer.SubmitWindowedPoStParams, error) { +func (sm *StorageMinerAPI) ComputeWindowPoSt(ctx context.Context, dlIdx uint64, tsk types.TipSetKey) ([]minertypes.SubmitWindowedPoStParams, error) { var ts *types.TipSet var err error if tsk == types.EmptyTSK { @@ -458,7 +459,7 @@ func (sm *StorageMinerAPI) MarketImportDealData(ctx context.Context, propCid cid return sm.StorageProvider.ImportDataForDeal(ctx, propCid, fi) } -func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, error) { +func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]*api.MarketDeal, error) { ts, err := sm.Full.ChainHead(ctx) if err != nil { return nil, err @@ -469,7 +470,7 @@ func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, err return nil, err } - var out []api.MarketDeal + var out []*api.MarketDeal for _, deal := range allDeals { if deal.Proposal.Provider == sm.Miner.Address() { @@ -480,7 +481,7 @@ func (sm *StorageMinerAPI) listDeals(ctx context.Context) ([]api.MarketDeal, err return out, nil } -func (sm *StorageMinerAPI) MarketListDeals(ctx context.Context) ([]api.MarketDeal, error) { +func (sm *StorageMinerAPI) MarketListDeals(ctx context.Context) ([]*api.MarketDeal, error) { return sm.listDeals(ctx) } @@ -1076,7 +1077,7 @@ func (sm *StorageMinerAPI) DagstoreLookupPieces(ctx context.Context, cid cid.Cid return ret, nil } -func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]api.MarketDeal, error) { +func (sm *StorageMinerAPI) DealsList(ctx context.Context) ([]*api.MarketDeal, error) { return sm.listDeals(ctx) } diff --git a/node/modules/blockstore.go b/node/modules/blockstore.go index 2486b9744..7a01c4dcc 100644 --- a/node/modules/blockstore.go +++ b/node/modules/blockstore.go @@ -37,6 +37,10 @@ func UniversalBlockstore(lc fx.Lifecycle, mctx helpers.MetricsCtx, r repo.Locked return bs, err } +func MemoryBlockstore() dtypes.UniversalBlockstore { + return blockstore.NewMemory() +} + func DiscardColdBlockstore(lc fx.Lifecycle, bs dtypes.UniversalBlockstore) (dtypes.ColdBlockstore, error) { return blockstore.NewDiscardStore(bs), nil } diff --git a/node/modules/chain.go b/node/modules/chain.go index ff957c9ad..a01feddb2 100644 --- a/node/modules/chain.go +++ b/node/modules/chain.go @@ -18,6 +18,7 @@ import ( "github.com/filecoin-project/lotus/chain" "github.com/filecoin-project/lotus/chain/beacon" "github.com/filecoin-project/lotus/chain/consensus" + "github.com/filecoin-project/lotus/chain/consensus/filcns" "github.com/filecoin-project/lotus/chain/exchange" "github.com/filecoin-project/lotus/chain/gen/slashfilter" "github.com/filecoin-project/lotus/chain/messagepool" @@ -176,3 +177,7 @@ func NewSyncer(params SyncerParams) (*chain.Syncer, error) { func NewSlashFilter(ds dtypes.MetadataDS) *slashfilter.SlashFilter { return slashfilter.New(ds) } + +func UpgradeSchedule() stmgr.UpgradeSchedule { + return filcns.DefaultUpgradeSchedule() +} diff --git a/node/modules/lp2p/rcmgr.go b/node/modules/lp2p/rcmgr.go index 13d97418a..b82169393 100644 --- a/node/modules/lp2p/rcmgr.go +++ b/node/modules/lp2p/rcmgr.go @@ -27,9 +27,10 @@ import ( func ResourceManager(connMgrHi uint) func(lc fx.Lifecycle, repo repo.LockedRepo) (network.ResourceManager, error) { return func(lc fx.Lifecycle, repo repo.LockedRepo) (network.ResourceManager, error) { + isFullNode := repo.RepoType().Type() == "FullNode" envvar := os.Getenv("LOTUS_RCMGR") - if envvar == "0" { - // this is enabled by default; specify LOTUS_RCMGR=0 to disable + if (isFullNode && envvar == "0") || // only set NullResourceManager if envvar is explicitly "0" + (!isFullNode && envvar != "1") { // set NullResourceManager *unless* envvar is explicitly "1" log.Info("libp2p resource manager is disabled") return network.NullResourceManager, nil } diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index 9688a518b..25c3e269e 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -417,6 +417,10 @@ type fsLockedRepo struct { configLk sync.Mutex } +func (fsr *fsLockedRepo) RepoType() RepoType { + return fsr.repoType +} + func (fsr *fsLockedRepo) Readonly() bool { return fsr.readonly } diff --git a/node/repo/interface.go b/node/repo/interface.go index b169ee5cc..904511634 100644 --- a/node/repo/interface.go +++ b/node/repo/interface.go @@ -52,6 +52,9 @@ type LockedRepo interface { // Close closes repo and removes lock. Close() error + // returns the type of this repo + RepoType() RepoType + // Returns datastore defined in this repo. // The supplied context must only be used to initialize the datastore. // The implementation should not retain the context for usage throughout diff --git a/node/repo/memrepo.go b/node/repo/memrepo.go index baff37d55..1b2e59c66 100644 --- a/node/repo/memrepo.go +++ b/node/repo/memrepo.go @@ -55,6 +55,10 @@ type lockedMemRepo struct { token *byte } +func (lmem *lockedMemRepo) RepoType() RepoType { + return lmem.t +} + func (lmem *lockedMemRepo) GetStorage() (stores.StorageConfig, error) { if err := lmem.checkToken(); err != nil { return stores.StorageConfig{}, err diff --git a/paychmgr/cbor_gen.go b/paychmgr/cbor_gen.go index 428c09a9e..450d526d8 100644 --- a/paychmgr/cbor_gen.go +++ b/paychmgr/cbor_gen.go @@ -9,7 +9,7 @@ import ( "sort" address "github.com/filecoin-project/go-address" - paych "github.com/filecoin-project/specs-actors/actors/builtin/paych" + paych "github.com/filecoin-project/go-state-types/builtin/v8/paych" cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" @@ -25,25 +25,26 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{163}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{163}); err != nil { return err } - scratch := make([]byte, 9) - // t.Voucher (paych.SignedVoucher) (struct) if len("Voucher") > cbg.MaxLength { return xerrors.Errorf("Value in field \"Voucher\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Voucher"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Voucher"))); err != nil { return err } if _, err := io.WriteString(w, string("Voucher")); err != nil { return err } - if err := t.Voucher.MarshalCBOR(w); err != nil { + if err := t.Voucher.MarshalCBOR(cw); err != nil { return err } @@ -52,7 +53,7 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Proof\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Proof"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Proof"))); err != nil { return err } if _, err := io.WriteString(w, string("Proof")); err != nil { @@ -63,11 +64,11 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Byte array in field t.Proof was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajByteString, uint64(len(t.Proof))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajByteString, uint64(len(t.Proof))); err != nil { return err } - if _, err := w.Write(t.Proof[:]); err != nil { + if _, err := cw.Write(t.Proof[:]); err != nil { return err } @@ -76,7 +77,7 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Submitted\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Submitted"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Submitted"))); err != nil { return err } if _, err := io.WriteString(w, string("Submitted")); err != nil { @@ -89,16 +90,21 @@ func (t *VoucherInfo) MarshalCBOR(w io.Writer) error { return nil } -func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error { +func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) (err error) { *t = VoucherInfo{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -113,7 +119,7 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -127,16 +133,16 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.Voucher = new(paych.SignedVoucher) - if err := t.Voucher.UnmarshalCBOR(br); err != nil { + if err := t.Voucher.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Voucher pointer: %w", err) } } @@ -145,7 +151,7 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error { // t.Proof ([]uint8) (slice) case "Proof": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -161,13 +167,13 @@ func (t *VoucherInfo) UnmarshalCBOR(r io.Reader) error { t.Proof = make([]uint8, extra) } - if _, err := io.ReadFull(br, t.Proof[:]); err != nil { + if _, err := io.ReadFull(cr, t.Proof[:]); err != nil { return err } // t.Submitted (bool) (bool) case "Submitted": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -196,18 +202,19 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{174}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{174}); err != nil { return err } - scratch := make([]byte, 9) - // t.ChannelID (string) (string) if len("ChannelID") > cbg.MaxLength { return xerrors.Errorf("Value in field \"ChannelID\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ChannelID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ChannelID"))); err != nil { return err } if _, err := io.WriteString(w, string("ChannelID")); err != nil { @@ -218,7 +225,7 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.ChannelID was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.ChannelID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.ChannelID))); err != nil { return err } if _, err := io.WriteString(w, string(t.ChannelID)); err != nil { @@ -230,14 +237,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Channel\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Channel"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Channel"))); err != nil { return err } if _, err := io.WriteString(w, string("Channel")); err != nil { return err } - if err := t.Channel.MarshalCBOR(w); err != nil { + if err := t.Channel.MarshalCBOR(cw); err != nil { return err } @@ -246,14 +253,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Control\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Control"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Control"))); err != nil { return err } if _, err := io.WriteString(w, string("Control")); err != nil { return err } - if err := t.Control.MarshalCBOR(w); err != nil { + if err := t.Control.MarshalCBOR(cw); err != nil { return err } @@ -262,14 +269,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Target\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Target"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Target"))); err != nil { return err } if _, err := io.WriteString(w, string("Target")); err != nil { return err } - if err := t.Target.MarshalCBOR(w); err != nil { + if err := t.Target.MarshalCBOR(cw); err != nil { return err } @@ -278,14 +285,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Direction\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Direction"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Direction"))); err != nil { return err } if _, err := io.WriteString(w, string("Direction")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.Direction)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.Direction)); err != nil { return err } @@ -294,7 +301,7 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Vouchers\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Vouchers"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Vouchers"))); err != nil { return err } if _, err := io.WriteString(w, string("Vouchers")); err != nil { @@ -305,11 +312,11 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Slice value in field t.Vouchers was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajArray, uint64(len(t.Vouchers))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajArray, uint64(len(t.Vouchers))); err != nil { return err } for _, v := range t.Vouchers { - if err := v.MarshalCBOR(w); err != nil { + if err := v.MarshalCBOR(cw); err != nil { return err } } @@ -319,14 +326,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"NextLane\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("NextLane"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("NextLane"))); err != nil { return err } if _, err := io.WriteString(w, string("NextLane")); err != nil { return err } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajUnsignedInt, uint64(t.NextLane)); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajUnsignedInt, uint64(t.NextLane)); err != nil { return err } @@ -335,14 +342,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Amount\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Amount"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Amount"))); err != nil { return err } if _, err := io.WriteString(w, string("Amount")); err != nil { return err } - if err := t.Amount.MarshalCBOR(w); err != nil { + if err := t.Amount.MarshalCBOR(cw); err != nil { return err } @@ -351,14 +358,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"AvailableAmount\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("AvailableAmount"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("AvailableAmount"))); err != nil { return err } if _, err := io.WriteString(w, string("AvailableAmount")); err != nil { return err } - if err := t.AvailableAmount.MarshalCBOR(w); err != nil { + if err := t.AvailableAmount.MarshalCBOR(cw); err != nil { return err } @@ -367,14 +374,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"PendingAvailableAmount\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PendingAvailableAmount"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PendingAvailableAmount"))); err != nil { return err } if _, err := io.WriteString(w, string("PendingAvailableAmount")); err != nil { return err } - if err := t.PendingAvailableAmount.MarshalCBOR(w); err != nil { + if err := t.PendingAvailableAmount.MarshalCBOR(cw); err != nil { return err } @@ -383,14 +390,14 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"PendingAmount\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("PendingAmount"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("PendingAmount"))); err != nil { return err } if _, err := io.WriteString(w, string("PendingAmount")); err != nil { return err } - if err := t.PendingAmount.MarshalCBOR(w); err != nil { + if err := t.PendingAmount.MarshalCBOR(cw); err != nil { return err } @@ -399,7 +406,7 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"CreateMsg\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("CreateMsg"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("CreateMsg"))); err != nil { return err } if _, err := io.WriteString(w, string("CreateMsg")); err != nil { @@ -407,11 +414,11 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { } if t.CreateMsg == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.CreateMsg); err != nil { + if err := cbg.WriteCid(cw, *t.CreateMsg); err != nil { return xerrors.Errorf("failed to write cid field t.CreateMsg: %w", err) } } @@ -421,7 +428,7 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"AddFundsMsg\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("AddFundsMsg"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("AddFundsMsg"))); err != nil { return err } if _, err := io.WriteString(w, string("AddFundsMsg")); err != nil { @@ -429,11 +436,11 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { } if t.AddFundsMsg == nil { - if _, err := w.Write(cbg.CborNull); err != nil { + if _, err := cw.Write(cbg.CborNull); err != nil { return err } } else { - if err := cbg.WriteCidBuf(scratch, w, *t.AddFundsMsg); err != nil { + if err := cbg.WriteCid(cw, *t.AddFundsMsg); err != nil { return xerrors.Errorf("failed to write cid field t.AddFundsMsg: %w", err) } } @@ -443,7 +450,7 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Settling\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Settling"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Settling"))); err != nil { return err } if _, err := io.WriteString(w, string("Settling")); err != nil { @@ -456,16 +463,21 @@ func (t *ChannelInfo) MarshalCBOR(w io.Writer) error { return nil } -func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { +func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) (err error) { *t = ChannelInfo{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -480,7 +492,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -493,7 +505,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { case "ChannelID": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -505,16 +517,16 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } t.Channel = new(address.Address) - if err := t.Channel.UnmarshalCBOR(br); err != nil { + if err := t.Channel.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Channel pointer: %w", err) } } @@ -525,7 +537,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.Control.UnmarshalCBOR(br); err != nil { + if err := t.Control.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Control: %w", err) } @@ -535,7 +547,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.Target.UnmarshalCBOR(br); err != nil { + if err := t.Target.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Target: %w", err) } @@ -545,7 +557,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -558,7 +570,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { // t.Vouchers ([]*paychmgr.VoucherInfo) (slice) case "Vouchers": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -578,7 +590,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { for i := 0; i < int(extra); i++ { var v VoucherInfo - if err := v.UnmarshalCBOR(br); err != nil { + if err := v.UnmarshalCBOR(cr); err != nil { return err } @@ -590,7 +602,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -605,7 +617,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.Amount.UnmarshalCBOR(br); err != nil { + if err := t.Amount.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.Amount: %w", err) } @@ -615,7 +627,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.AvailableAmount.UnmarshalCBOR(br); err != nil { + if err := t.AvailableAmount.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.AvailableAmount: %w", err) } @@ -625,7 +637,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.PendingAvailableAmount.UnmarshalCBOR(br); err != nil { + if err := t.PendingAvailableAmount.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.PendingAvailableAmount: %w", err) } @@ -635,7 +647,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - if err := t.PendingAmount.UnmarshalCBOR(br); err != nil { + if err := t.PendingAmount.UnmarshalCBOR(cr); err != nil { return xerrors.Errorf("unmarshaling t.PendingAmount: %w", err) } @@ -645,16 +657,16 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.CreateMsg: %w", err) } @@ -668,16 +680,16 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { { - b, err := br.ReadByte() + b, err := cr.ReadByte() if err != nil { return err } if b != cbg.CborNull[0] { - if err := br.UnreadByte(); err != nil { + if err := cr.UnreadByte(); err != nil { return err } - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.AddFundsMsg: %w", err) } @@ -689,7 +701,7 @@ func (t *ChannelInfo) UnmarshalCBOR(r io.Reader) error { // t.Settling (bool) (bool) case "Settling": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -718,18 +730,19 @@ func (t *MsgInfo) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{164}); err != nil { + + cw := cbg.NewCborWriter(w) + + if _, err := cw.Write([]byte{164}); err != nil { return err } - scratch := make([]byte, 9) - // t.ChannelID (string) (string) if len("ChannelID") > cbg.MaxLength { return xerrors.Errorf("Value in field \"ChannelID\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("ChannelID"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("ChannelID"))); err != nil { return err } if _, err := io.WriteString(w, string("ChannelID")); err != nil { @@ -740,7 +753,7 @@ func (t *MsgInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.ChannelID was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.ChannelID))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.ChannelID))); err != nil { return err } if _, err := io.WriteString(w, string(t.ChannelID)); err != nil { @@ -752,14 +765,14 @@ func (t *MsgInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"MsgCid\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("MsgCid"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("MsgCid"))); err != nil { return err } if _, err := io.WriteString(w, string("MsgCid")); err != nil { return err } - if err := cbg.WriteCidBuf(scratch, w, t.MsgCid); err != nil { + if err := cbg.WriteCid(cw, t.MsgCid); err != nil { return xerrors.Errorf("failed to write cid field t.MsgCid: %w", err) } @@ -768,7 +781,7 @@ func (t *MsgInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Received\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Received"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Received"))); err != nil { return err } if _, err := io.WriteString(w, string("Received")); err != nil { @@ -784,7 +797,7 @@ func (t *MsgInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field \"Err\" was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len("Err"))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len("Err"))); err != nil { return err } if _, err := io.WriteString(w, string("Err")); err != nil { @@ -795,7 +808,7 @@ func (t *MsgInfo) MarshalCBOR(w io.Writer) error { return xerrors.Errorf("Value in field t.Err was too long") } - if err := cbg.WriteMajorTypeHeaderBuf(scratch, w, cbg.MajTextString, uint64(len(t.Err))); err != nil { + if err := cw.WriteMajorTypeHeader(cbg.MajTextString, uint64(len(t.Err))); err != nil { return err } if _, err := io.WriteString(w, string(t.Err)); err != nil { @@ -804,16 +817,21 @@ func (t *MsgInfo) MarshalCBOR(w io.Writer) error { return nil } -func (t *MsgInfo) UnmarshalCBOR(r io.Reader) error { +func (t *MsgInfo) UnmarshalCBOR(r io.Reader) (err error) { *t = MsgInfo{} - br := cbg.GetPeeker(r) - scratch := make([]byte, 8) + cr := cbg.NewCborReader(r) - maj, extra, err := cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err := cr.ReadHeader() if err != nil { return err } + defer func() { + if err == io.EOF { + err = io.ErrUnexpectedEOF + } + }() + if maj != cbg.MajMap { return fmt.Errorf("cbor input should be of type map") } @@ -828,7 +846,7 @@ func (t *MsgInfo) UnmarshalCBOR(r io.Reader) error { for i := uint64(0); i < n; i++ { { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -841,7 +859,7 @@ func (t *MsgInfo) UnmarshalCBOR(r io.Reader) error { case "ChannelID": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } @@ -853,7 +871,7 @@ func (t *MsgInfo) UnmarshalCBOR(r io.Reader) error { { - c, err := cbg.ReadCid(br) + c, err := cbg.ReadCid(cr) if err != nil { return xerrors.Errorf("failed to read cid field t.MsgCid: %w", err) } @@ -864,7 +882,7 @@ func (t *MsgInfo) UnmarshalCBOR(r io.Reader) error { // t.Received (bool) (bool) case "Received": - maj, extra, err = cbg.CborReadHeaderBuf(br, scratch) + maj, extra, err = cr.ReadHeader() if err != nil { return err } @@ -883,7 +901,7 @@ func (t *MsgInfo) UnmarshalCBOR(r io.Reader) error { case "Err": { - sval, err := cbg.ReadStringBuf(br, scratch) + sval, err := cbg.ReadString(cr) if err != nil { return err } diff --git a/paychmgr/manager.go b/paychmgr/manager.go index ea77c67ef..0fb3a399c 100644 --- a/paychmgr/manager.go +++ b/paychmgr/manager.go @@ -5,6 +5,8 @@ import ( "errors" "sync" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" @@ -206,7 +208,7 @@ func (pm *Manager) GetChannelInfo(ctx context.Context, addr address.Address) (*C return ca.getChannelInfo(ctx, addr) } -func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, voucher paych.SignedVoucher) (*api.VoucherCreateResult, error) { +func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, voucher paychtypes.SignedVoucher) (*api.VoucherCreateResult, error) { ca, err := pm.accessorByAddress(ctx, ch) if err != nil { return nil, err @@ -218,7 +220,7 @@ func (pm *Manager) CreateVoucher(ctx context.Context, ch address.Address, vouche // CheckVoucherValid checks if the given voucher is valid (is or could become spendable at some point). // If the channel is not in the store, fetches the channel from state (and checks that // the channel To address is owned by the wallet). -func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) error { +func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher) error { // Get an accessor for the channel, creating it from state if necessary ca, err := pm.inboundChannelAccessor(ctx, ch) if err != nil { @@ -230,7 +232,7 @@ func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv } // CheckVoucherSpendable checks if the given voucher is currently spendable -func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, secret []byte, proof []byte) (bool, error) { if len(proof) > 0 { return false, errProofNotSupported } @@ -244,7 +246,7 @@ func (pm *Manager) CheckVoucherSpendable(ctx context.Context, ch address.Address // AddVoucherOutbound adds a voucher for an outbound channel. // Returns an error if the channel is not already in the store. -func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { if len(proof) > 0 { return types.NewInt(0), errProofNotSupported } @@ -258,7 +260,7 @@ func (pm *Manager) AddVoucherOutbound(ctx context.Context, ch address.Address, s // AddVoucherInbound adds a voucher for an inbound channel. // If the channel is not in the store, fetches the channel from state (and checks that // the channel To address is owned by the wallet). -func (pm *Manager) AddVoucherInbound(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { +func (pm *Manager) AddVoucherInbound(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, proof []byte, minDelta types.BigInt) (types.BigInt, error) { if len(proof) > 0 { return types.NewInt(0), errProofNotSupported } @@ -331,7 +333,7 @@ func (pm *Manager) trackInboundChannel(ctx context.Context, ch address.Address) } // TODO: secret vs proof doesn't make sense, there is only one, not two -func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { +func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paychtypes.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) { if len(proof) > 0 { return cid.Undef, errProofNotSupported } diff --git a/paychmgr/paych.go b/paychmgr/paych.go index 5fdb4d884..e0ea00d62 100644 --- a/paychmgr/paych.go +++ b/paychmgr/paych.go @@ -4,16 +4,18 @@ import ( "context" "fmt" + lpaych "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + "github.com/ipfs/go-cid" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" cborutil "github.com/filecoin-project/go-cbor-util" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/sigs" ) @@ -82,7 +84,7 @@ func newChannelAccessor(pm *Manager, from address.Address, to address.Address) * } } -func (ca *channelAccessor) messageBuilder(ctx context.Context, from address.Address) (paych.MessageBuilder, error) { +func (ca *channelAccessor) messageBuilder(ctx context.Context, from address.Address) (lpaych.MessageBuilder, error) { nwVersion, err := ca.api.StateNetworkVersion(ctx, types.EmptyTSK) if err != nil { return nil, err @@ -92,7 +94,7 @@ func (ca *channelAccessor) messageBuilder(ctx context.Context, from address.Addr if err != nil { return nil, err } - return paych.Message(av, from), nil + return lpaych.Message(av, from), nil } func (ca *channelAccessor) getChannelInfo(ctx context.Context, addr address.Address) (*ChannelInfo, error) { @@ -172,14 +174,14 @@ func (ca *channelAccessor) nextNonceForLane(ci *ChannelInfo, lane uint64) uint64 return maxnonce + 1 } -func (ca *channelAccessor) checkVoucherValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) (map[uint64]paych.LaneState, error) { +func (ca *channelAccessor) checkVoucherValid(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) (map[uint64]lpaych.LaneState, error) { ca.lk.Lock() defer ca.lk.Unlock() return ca.checkVoucherValidUnlocked(ctx, ch, sv) } -func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) (map[uint64]paych.LaneState, error) { +func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch address.Address, sv *paych.SignedVoucher) (map[uint64]lpaych.LaneState, error) { if sv.ChannelAddr != ch { return nil, xerrors.Errorf("voucher ChannelAddr doesn't match channel address, got %s, expected %s", sv.ChannelAddr, ch) } @@ -194,7 +196,7 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add if sv.TimeLockMin != 0 { return nil, xerrors.Errorf("voucher is Min Time Locked") } - if len(sv.SecretPreimage) != 0 { + if len(sv.SecretHash) != 0 { return nil, xerrors.Errorf("voucher is Hash Locked") } @@ -479,7 +481,7 @@ func (ca *channelAccessor) listVouchers(ctx context.Context, ch address.Address) // laneState gets the LaneStates from chain, then applies all vouchers in // the data store over the chain state -func (ca *channelAccessor) laneState(ctx context.Context, state paych.State, ch address.Address) (map[uint64]paych.LaneState, error) { +func (ca *channelAccessor) laneState(ctx context.Context, state lpaych.State, ch address.Address) (map[uint64]lpaych.LaneState, error) { // TODO: we probably want to call UpdateChannelState with all vouchers to be fully correct // (but technically dont't need to) @@ -491,8 +493,8 @@ func (ca *channelAccessor) laneState(ctx context.Context, state paych.State, ch // 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. - laneStates := make(map[uint64]paych.LaneState, laneCount) - err = state.ForEachLaneState(func(idx uint64, ls paych.LaneState) error { + laneStates := make(map[uint64]lpaych.LaneState, laneCount) + err = state.ForEachLaneState(func(idx uint64, ls lpaych.LaneState) error { laneStates[idx] = ls return nil }) @@ -535,7 +537,7 @@ func (ca *channelAccessor) laneState(ctx context.Context, state paych.State, ch } // Get the total redeemed amount across all lanes, after applying the voucher -func (ca *channelAccessor) totalRedeemedWithVoucher(laneStates map[uint64]paych.LaneState, sv *paych.SignedVoucher) (big.Int, error) { +func (ca *channelAccessor) totalRedeemedWithVoucher(laneStates map[uint64]lpaych.LaneState, sv *paych.SignedVoucher) (big.Int, error) { // TODO: merges if len(sv.Merges) != 0 { return big.Int{}, xerrors.Errorf("dont currently support paych lane merges") diff --git a/paychmgr/paych_test.go b/paychmgr/paych_test.go index 7f767510b..cec74d10b 100644 --- a/paychmgr/paych_test.go +++ b/paychmgr/paych_test.go @@ -6,6 +6,8 @@ import ( "context" "testing" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" ds_sync "github.com/ipfs/go-datastore/sync" @@ -16,7 +18,6 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/specs-actors/v2/actors/builtin" - paych2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/paych" tutils "github.com/filecoin-project/specs-actors/v2/support/testing" "github.com/filecoin-project/lotus/api" @@ -242,7 +243,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 1 voucherLane1Amt := big.NewInt(5) - voucher := paych.SignedVoucher{ + voucher := paychtypes.SignedVoucher{ Lane: 1, Amount: voucherLane1Amt, } @@ -258,7 +259,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 1 again, with a higher amount voucherLane1Amt = big.NewInt(8) - voucher = paych.SignedVoucher{ + voucher = paychtypes.SignedVoucher{ Lane: 1, Amount: voucherLane1Amt, } @@ -273,7 +274,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 2 that covers all the remaining funds // in the channel voucherLane2Amt := big.Sub(s.amt, voucherLane1Amt) - voucher = paych.SignedVoucher{ + voucher = paychtypes.SignedVoucher{ Lane: 2, Amount: voucherLane2Amt, } @@ -287,7 +288,7 @@ func TestCreateVoucher(t *testing.T) { // Create a voucher in lane 2 that exceeds the remaining funds in the // channel voucherLane2Amt = big.Add(voucherLane2Amt, big.NewInt(1)) - voucher = paych.SignedVoucher{ + voucher = paychtypes.SignedVoucher{ Lane: 2, Amount: voucherLane2Amt, } @@ -637,7 +638,7 @@ func TestCheckSpendable(t *testing.T) { // Check that the secret was passed through correctly lastCall := s.mock.getLastCall() - var p paych2.UpdateChannelStateParams + var p paychtypes.UpdateChannelStateParams err = p.UnmarshalCBOR(bytes.NewReader(lastCall.Params)) require.NoError(t, err) require.Equal(t, secret, p.Secret) @@ -691,7 +692,7 @@ func TestSubmitVoucher(t *testing.T) { // Check that the secret was passed through correctly msg := s.mock.pushedMessages(submitCid) - var p paych2.UpdateChannelStateParams + var p paychtypes.UpdateChannelStateParams err = p.UnmarshalCBOR(bytes.NewReader(msg.Message.Params)) require.NoError(t, err) @@ -703,7 +704,7 @@ func TestSubmitVoucher(t *testing.T) { require.NoError(t, err) msg = s.mock.pushedMessages(submitCid) - var p3 paych2.UpdateChannelStateParams + var p3 paychtypes.UpdateChannelStateParams err = p3.UnmarshalCBOR(bytes.NewReader(msg.Message.Params)) require.NoError(t, err) @@ -789,8 +790,8 @@ func testGenerateKeyPair(t *testing.T) ([]byte, []byte) { return priv, pub } -func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paych2.SignedVoucher { - sv := &paych2.SignedVoucher{ +func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paychtypes.SignedVoucher { + sv := &paychtypes.SignedVoucher{ ChannelAddr: ch, Lane: voucherLane, Nonce: nonce, @@ -805,13 +806,13 @@ func createTestVoucher(t *testing.T, ch address.Address, voucherLane uint64, non return sv } -func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paych2.SignedVoucher { //nolint:deadcode - sv := &paych2.SignedVoucher{ +func createTestVoucherWithExtra(t *testing.T, ch address.Address, voucherLane uint64, nonce uint64, voucherAmount big.Int, key []byte) *paychtypes.SignedVoucher { //nolint:deadcode + sv := &paychtypes.SignedVoucher{ ChannelAddr: ch, Lane: voucherLane, Nonce: nonce, Amount: voucherAmount, - Extra: &paych2.ModVerifyParams{ + Extra: &paychtypes.ModVerifyParams{ Actor: tutils.NewActorAddr(t, "act"), }, } @@ -829,13 +830,13 @@ type mockBestSpendableAPI struct { mgr *Manager } -func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address.Address) ([]*paych2.SignedVoucher, error) { +func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address.Address) ([]*paychtypes.SignedVoucher, error) { vi, err := m.mgr.ListVouchers(ctx, ch) if err != nil { return nil, err } - out := make([]*paych2.SignedVoucher, len(vi)) + out := make([]*paychtypes.SignedVoucher, len(vi)) for k, v := range vi { out[k] = v.Voucher } @@ -843,7 +844,7 @@ func (m *mockBestSpendableAPI) PaychVoucherList(ctx context.Context, ch address. return out, nil } -func (m *mockBestSpendableAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, voucher *paych2.SignedVoucher, secret []byte, proof []byte) (bool, error) { +func (m *mockBestSpendableAPI) PaychVoucherCheckSpendable(ctx context.Context, ch address.Address, voucher *paychtypes.SignedVoucher, secret []byte, proof []byte) (bool, error) { return m.mgr.CheckVoucherSpendable(ctx, ch, voucher, secret, proof) } diff --git a/paychmgr/paychvoucherfunds_test.go b/paychmgr/paychvoucherfunds_test.go index dc894a04f..f44f75e4c 100644 --- a/paychmgr/paychvoucherfunds_test.go +++ b/paychmgr/paychvoucherfunds_test.go @@ -4,6 +4,8 @@ import ( "context" "testing" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" + "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/ipfs/go-cid" @@ -68,7 +70,7 @@ func TestPaychAddVoucherAfterAddFunds(t *testing.T) { require.NoError(t, err) // Create a voucher with a value equal to the channel balance - voucher := paych.SignedVoucher{Amount: createAmt, Lane: 1} + voucher := paychtypes.SignedVoucher{Amount: createAmt, Lane: 1} res, err := mgr.CreateVoucher(ctx, ch, voucher) require.NoError(t, err) require.NotNil(t, res.Voucher) @@ -76,7 +78,7 @@ func TestPaychAddVoucherAfterAddFunds(t *testing.T) { // Create a voucher in a different lane with an amount that exceeds the // channel balance excessAmt := types.NewInt(5) - voucher = paych.SignedVoucher{Amount: excessAmt, Lane: 2} + voucher = paychtypes.SignedVoucher{Amount: excessAmt, Lane: 2} res, err = mgr.CreateVoucher(ctx, ch, voucher) require.NoError(t, err) require.Nil(t, res.Voucher) diff --git a/paychmgr/settler/settler.go b/paychmgr/settler/settler.go index 38fcc3b92..0984b207f 100644 --- a/paychmgr/settler/settler.go +++ b/paychmgr/settler/settler.go @@ -13,10 +13,11 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/builtin" + paychtypes "github.com/filecoin-project/go-state-types/builtin/v8/paych" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/impl/full" @@ -38,9 +39,9 @@ type API struct { type settlerAPI interface { PaychList(context.Context) ([]address.Address, error) PaychStatus(context.Context, address.Address) (*api.PaychStatus, error) - PaychVoucherCheckSpendable(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (bool, error) - PaychVoucherList(context.Context, address.Address) ([]*paych.SignedVoucher, error) - PaychVoucherSubmit(context.Context, address.Address, *paych.SignedVoucher, []byte, []byte) (cid.Cid, error) + PaychVoucherCheckSpendable(context.Context, address.Address, *paychtypes.SignedVoucher, []byte, []byte) (bool, error) + PaychVoucherList(context.Context, address.Address) ([]*paychtypes.SignedVoucher, error) + PaychVoucherSubmit(context.Context, address.Address, *paychtypes.SignedVoucher, []byte, []byte) (cid.Cid, error) StateWaitMsg(ctx context.Context, cid cid.Cid, confidence uint64, limit abi.ChainEpoch, allowReplaced bool) (*api.MsgLookup, error) } @@ -94,7 +95,7 @@ func (pcs *paymentChannelSettler) messageHandler(msg *types.Message, rec *types. if err != nil { return true, err } - go func(voucher *paych.SignedVoucher, submitMessageCID cid.Cid) { + go func(voucher *paychtypes.SignedVoucher, submitMessageCID cid.Cid) { defer wg.Done() msgLookup, err := pcs.api.StateWaitMsg(pcs.ctx, submitMessageCID, build.MessageConfidence, api.LookbackNoLimit, true) if err != nil { @@ -116,7 +117,7 @@ func (pcs *paymentChannelSettler) revertHandler(ctx context.Context, ts *types.T func (pcs *paymentChannelSettler) matcher(msg *types.Message) (matched bool, err error) { // Check if this is a settle payment channel message - if msg.Method != paych.Methods.Settle { + if msg.Method != builtin.MethodsPaych.Settle { return false, nil } // Check if this payment channel is of concern to this node (i.e. tracked in payment channel store), diff --git a/paychmgr/store.go b/paychmgr/store.go index f3c67e565..671537afe 100644 --- a/paychmgr/store.go +++ b/paychmgr/store.go @@ -19,7 +19,7 @@ import ( "github.com/filecoin-project/go-address" cborrpc "github.com/filecoin-project/go-cbor-util" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" ) var ErrChannelNotTracked = errors.New("channel not tracked") diff --git a/paychmgr/util.go b/paychmgr/util.go index 8e5dd4fab..2e9965ff2 100644 --- a/paychmgr/util.go +++ b/paychmgr/util.go @@ -5,7 +5,7 @@ import ( "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lotus/chain/actors/builtin/paych" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" ) type BestSpendableAPI interface { diff --git a/storage/adapter_storage_miner.go b/storage/adapter_storage_miner.go index d976d9aa2..4acf86f95 100644 --- a/storage/adapter_storage_miner.go +++ b/storage/adapter_storage_miner.go @@ -19,6 +19,7 @@ import ( market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" market5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/market" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" @@ -49,7 +50,7 @@ func (s SealingAPIAdapter) StateMinerSectorSize(ctx context.Context, maddr addre return mi.SectorSize, nil } -func (s SealingAPIAdapter) StateMinerPreCommitDepositForPower(ctx context.Context, a address.Address, pci miner.SectorPreCommitInfo, tok sealing.TipSetToken) (big.Int, error) { +func (s SealingAPIAdapter) StateMinerPreCommitDepositForPower(ctx context.Context, a address.Address, pci minertypes.SectorPreCommitInfo, tok sealing.TipSetToken) (big.Int, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return big.Zero(), xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) @@ -58,7 +59,7 @@ func (s SealingAPIAdapter) StateMinerPreCommitDepositForPower(ctx context.Contex return s.delegate.StateMinerPreCommitDepositForPower(ctx, a, pci, tsk) } -func (s SealingAPIAdapter) StateMinerInitialPledgeCollateral(ctx context.Context, a address.Address, pci miner.SectorPreCommitInfo, tok sealing.TipSetToken) (big.Int, error) { +func (s SealingAPIAdapter) StateMinerInitialPledgeCollateral(ctx context.Context, a address.Address, pci minertypes.SectorPreCommitInfo, tok sealing.TipSetToken) (big.Int, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return big.Zero(), xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) @@ -67,10 +68,10 @@ func (s SealingAPIAdapter) StateMinerInitialPledgeCollateral(ctx context.Context return s.delegate.StateMinerInitialPledgeCollateral(ctx, a, pci, tsk) } -func (s SealingAPIAdapter) StateMinerInfo(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) (miner.MinerInfo, error) { +func (s SealingAPIAdapter) StateMinerInfo(ctx context.Context, maddr address.Address, tok sealing.TipSetToken) (api.MinerInfo, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { - return miner.MinerInfo{}, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) + return api.MinerInfo{}, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) } // TODO: update storage-fsm to just StateMinerInfo @@ -240,7 +241,7 @@ func (s SealingAPIAdapter) StateComputeDataCommitment(ctx context.Context, maddr return cid.Cid(cr.CommDs[0]), nil } -func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok sealing.TipSetToken) (*miner.SectorPreCommitOnChainInfo, error) { +func (s SealingAPIAdapter) StateSectorPreCommitInfo(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok sealing.TipSetToken) (*minertypes.SectorPreCommitOnChainInfo, error) { tsk, err := types.TipSetKeyFromBytes(tok) if err != nil { return nil, xerrors.Errorf("failed to unmarshal TipSetToken to TipSetKey: %w", err) diff --git a/storage/addresses.go b/storage/addresses.go index f8f06ed98..2c9b381cd 100644 --- a/storage/addresses.go +++ b/storage/addresses.go @@ -8,7 +8,6 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/api" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" ) @@ -24,7 +23,7 @@ type AddressSelector struct { api.AddressConfig } -func (as *AddressSelector) AddressFor(ctx context.Context, a addrSelectApi, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { +func (as *AddressSelector) AddressFor(ctx context.Context, a addrSelectApi, mi api.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { if as == nil { // should only happen in some tests log.Warnw("smart address selection disabled, using worker address") @@ -82,7 +81,7 @@ func (as *AddressSelector) AddressFor(ctx context.Context, a addrSelectApi, mi m return pickAddress(ctx, a, mi, goodFunds, minFunds, addrs) } -func pickAddress(ctx context.Context, a addrSelectApi, mi miner.MinerInfo, goodFunds, minFunds abi.TokenAmount, addrs []address.Address) (address.Address, abi.TokenAmount, error) { +func pickAddress(ctx context.Context, a addrSelectApi, mi api.MinerInfo, goodFunds, minFunds abi.TokenAmount, addrs []address.Address) (address.Address, abi.TokenAmount, error) { leastBad := mi.Worker bestAvail := minFunds diff --git a/storage/miner.go b/storage/miner.go index c52b786ee..80f06581f 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -6,6 +6,7 @@ import ( "time" "github.com/filecoin-project/go-bitfield" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" logging "github.com/ipfs/go-log/v2" @@ -22,11 +23,13 @@ import ( sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/v1api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + lminer "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/events" "github.com/filecoin-project/lotus/chain/gen" "github.com/filecoin-project/lotus/chain/types" @@ -83,8 +86,8 @@ type fullNodeFilteredAPI interface { StateMinerSectors(context.Context, address.Address, *bitfield.BitField, types.TipSetKey) ([]*miner.SectorOnChainInfo, error) StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) - StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*miner.SectorLocation, error) - StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) + StateSectorPartition(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tok types.TipSetKey) (*lminer.SectorLocation, error) + StateMinerInfo(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error) StateMinerAvailableBalance(ctx context.Context, maddr address.Address, tok types.TipSetKey) (types.BigInt, error) StateMinerActiveSectors(context.Context, address.Address, types.TipSetKey) ([]*miner.SectorOnChainInfo, error) StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) ([]api.Deadline, error) @@ -120,6 +123,7 @@ type fullNodeFilteredAPI interface { ChainGetPath(ctx context.Context, from, to types.TipSetKey) ([]*api.HeadChange, error) ChainReadObj(context.Context, cid.Cid) ([]byte, error) ChainHasObj(context.Context, cid.Cid) (bool, error) + ChainPutObj(context.Context, blocks.Block) error ChainGetTipSet(ctx context.Context, key types.TipSetKey) (*types.TipSet, error) WalletSign(context.Context, address.Address, []byte) (*crypto.Signature, error) @@ -189,7 +193,7 @@ func (m *Miner) Run(ctx context.Context) error { pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, cfg, provingBuffer) // address selector. - as := func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { + as := func(ctx context.Context, mi api.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { return m.addrSel.AddressFor(ctx, m.api, mi, use, goodFunds, minFunds) } diff --git a/storage/mockstorage/preseal.go b/storage/mockstorage/preseal.go index 66a2a5054..4e5b2306c 100644 --- a/storage/mockstorage/preseal.go +++ b/storage/mockstorage/preseal.go @@ -3,14 +3,15 @@ package mockstorage import ( "fmt" + markettypes "github.com/filecoin-project/go-state-types/builtin/v8/market" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-commp-utils/zerocomm" commcid "github.com/filecoin-project/go-fil-commcid" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/extern/sector-storage/mock" - - market2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/market" + "golang.org/x/xerrors" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/wallet" @@ -39,6 +40,11 @@ func PreSeal(spt abi.RegisteredSealProof, maddr address.Address, sectors int) (* } for i := range genm.Sectors { + label, err := markettypes.NewLabelFromString(fmt.Sprintf("%d", i)) + if err != nil { + return nil, nil, xerrors.Errorf("failed to create label: %w", err) + } + preseal := &genesis.PreSeal{} preseal.ProofType = spt @@ -47,18 +53,19 @@ func PreSeal(spt abi.RegisteredSealProof, maddr address.Address, sectors int) (* r := mock.CommDR(d) preseal.CommR, _ = commcid.ReplicaCommitmentV1ToCID(r[:]) preseal.SectorID = abi.SectorNumber(i + 1) - preseal.Deal = market2.DealProposal{ + preseal.Deal = markettypes.DealProposal{ PieceCID: preseal.CommD, PieceSize: abi.PaddedPieceSize(ssize), Client: k.Address, Provider: maddr, - Label: fmt.Sprintf("%d", i), + Label: label, StartEpoch: 1, EndEpoch: 10000, StoragePricePerEpoch: big.Zero(), ProviderCollateral: big.Zero(), ClientCollateral: big.Zero(), } + preseal.DealClientKey = k genm.Sectors[i] = preseal } diff --git a/storage/wdpost_changehandler.go b/storage/wdpost_changehandler.go index 9540182b5..ce39eb37d 100644 --- a/storage/wdpost_changehandler.go +++ b/storage/wdpost_changehandler.go @@ -7,8 +7,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/lotus/chain/types" ) diff --git a/storage/wdpost_changehandler_test.go b/storage/wdpost_changehandler_test.go index 00b1e94cc..a1f08c200 100644 --- a/storage/wdpost_changehandler_test.go +++ b/storage/wdpost_changehandler_test.go @@ -8,6 +8,8 @@ import ( "testing" "time" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" + tutils "github.com/filecoin-project/specs-actors/support/testing" "github.com/filecoin-project/go-state-types/crypto" @@ -18,7 +20,6 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/dline" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" ) @@ -29,7 +30,7 @@ func init() { } type proveRes struct { - posts []miner.SubmitWindowedPoStParams + posts []minertypes.SubmitWindowedPoStParams err error } @@ -85,10 +86,10 @@ func (m *mockAPI) setDeadline(di *dline.Info) { } func (m *mockAPI) getDeadline(currentEpoch abi.ChainEpoch) *dline.Info { - close := miner.WPoStChallengeWindow - 1 + close := minertypes.WPoStChallengeWindow - 1 dlIdx := uint64(0) for close < currentEpoch { - close += miner.WPoStChallengeWindow + close += minertypes.WPoStChallengeWindow dlIdx++ } return NewDeadlineInfo(0, dlIdx, currentEpoch) @@ -161,7 +162,7 @@ func (m *mockAPI) startSubmitPoST( ctx context.Context, ts *types.TipSet, deadline *dline.Info, - posts []miner.SubmitWindowedPoStParams, + posts []minertypes.SubmitWindowedPoStParams, completeSubmitPoST CompleteSubmitPoSTCb, ) context.CancelFunc { ctx, cancel := context.WithCancel(ctx) @@ -225,7 +226,7 @@ func TestChangeHandlerBasic(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(di)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -291,7 +292,7 @@ func TestChangeHandlerFromProvingToSubmittingNoHeadChange(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(di)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -346,7 +347,7 @@ func TestChangeHandlerFromProvingEmptyProofsToComplete(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(di)) // Send a response to the call to generate proofs with an empty proofs array - posts := []miner.SubmitWindowedPoStParams{} + posts := []minertypes.SubmitWindowedPoStParams{} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -368,7 +369,7 @@ func TestChangeHandlerDontStartUntilProvingPeriod(t *testing.T) { s := makeScaffolding(t) mock := s.mock - periodStart := miner.WPoStProvingPeriod + periodStart := minertypes.WPoStProvingPeriod dlIdx := uint64(1) currentEpoch := abi.ChainEpoch(10) di := NewDeadlineInfo(periodStart, dlIdx, currentEpoch) @@ -390,7 +391,7 @@ func TestChangeHandlerDontStartUntilProvingPeriod(t *testing.T) { } // Advance the head to the next proving period's first epoch - currentEpoch = periodStart + miner.WPoStChallengeWindow + currentEpoch = periodStart + minertypes.WPoStChallengeWindow di = NewDeadlineInfo(periodStart, dlIdx, currentEpoch) mock.setDeadline(di) go triggerHeadAdvance(t, s, currentEpoch) @@ -431,7 +432,7 @@ func TestChangeHandlerStartProvingNextDeadline(t *testing.T) { require.Equal(t, postStatusProving, s.mock.getPostStatus(di)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -466,7 +467,7 @@ func TestChangeHandlerProvingRounds(t *testing.T) { s.ch.start() completeProofIndex := abi.ChainEpoch(10) - for currentEpoch := abi.ChainEpoch(1); currentEpoch < miner.WPoStChallengeWindow*5; currentEpoch++ { + for currentEpoch := abi.ChainEpoch(1); currentEpoch < minertypes.WPoStChallengeWindow*5; currentEpoch++ { // Trigger a head change di := mock.getDeadline(currentEpoch) go triggerHeadAdvance(t, s, currentEpoch+ChallengeConfidence) @@ -507,7 +508,7 @@ func TestChangeHandlerProvingRounds(t *testing.T) { if currentEpoch == completeProofEpoch { // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -562,7 +563,7 @@ func TestChangeHandlerProvingErrorRecovery(t *testing.T) { require.Equal(t, postStatusProving, s.mock.getPostStatus(di)) // Send a success response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -597,7 +598,7 @@ func TestChangeHandlerSubmitErrorRecovery(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(di)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -665,7 +666,7 @@ func TestChangeHandlerProveExpiry(t *testing.T) { require.Equal(t, postStatusProving, s.mock.getPostStatus(di)) // Move to a height that expires the current proof - currentEpoch = miner.WPoStChallengeWindow + currentEpoch = minertypes.WPoStChallengeWindow di = mock.getDeadline(currentEpoch) go triggerHeadAdvance(t, s, currentEpoch) @@ -676,7 +677,7 @@ func TestChangeHandlerProveExpiry(t *testing.T) { require.True(t, mock.wasAbortCalled()) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -709,7 +710,7 @@ func TestChangeHandlerSubmitExpiry(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(di)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -726,7 +727,7 @@ func TestChangeHandlerSubmitExpiry(t *testing.T) { require.Equal(t, SubmitStateSubmitting, s.submitState(di)) // Move to a height that expires the submit - currentEpoch = miner.WPoStChallengeWindow + currentEpoch = minertypes.WPoStChallengeWindow di = mock.getDeadline(currentEpoch) go triggerHeadAdvance(t, s, currentEpoch) @@ -763,7 +764,7 @@ func TestChangeHandlerProveRevert(t *testing.T) { s.ch.start() // Trigger a head change - currentEpoch := miner.WPoStChallengeWindow + currentEpoch := minertypes.WPoStChallengeWindow go triggerHeadAdvance(t, s, currentEpoch) // Should start proving @@ -780,7 +781,7 @@ func TestChangeHandlerProveRevert(t *testing.T) { require.Equal(t, postStatusProving, s.mock.getPostStatus(di)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -806,7 +807,7 @@ func TestChangeHandlerSubmittingRevert(t *testing.T) { s.ch.start() // Trigger a head change - currentEpoch := miner.WPoStChallengeWindow + currentEpoch := minertypes.WPoStChallengeWindow go triggerHeadAdvance(t, s, currentEpoch) // Submitter doesn't have anything to do yet @@ -815,7 +816,7 @@ func TestChangeHandlerSubmittingRevert(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(di)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -881,7 +882,7 @@ func TestChangeHandlerSubmitCompleteRevert(t *testing.T) { s.ch.start() // Trigger a head change - currentEpoch := miner.WPoStChallengeWindow + currentEpoch := minertypes.WPoStChallengeWindow go triggerHeadAdvance(t, s, currentEpoch) // Submitter doesn't have anything to do yet @@ -890,7 +891,7 @@ func TestChangeHandlerSubmitCompleteRevert(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(di)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: di.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: di.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -946,7 +947,7 @@ func TestChangeHandlerSubmitRevertTwoEpochs(t *testing.T) { s.ch.start() // Trigger a head change - currentEpoch := miner.WPoStChallengeWindow + currentEpoch := minertypes.WPoStChallengeWindow go triggerHeadAdvance(t, s, currentEpoch) // Submitter doesn't have anything to do yet @@ -955,7 +956,7 @@ func TestChangeHandlerSubmitRevertTwoEpochs(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(diE1)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: diE1.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: diE1.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -981,7 +982,7 @@ func TestChangeHandlerSubmitRevertTwoEpochs(t *testing.T) { // Should start proving epoch 2 // Send a response to the call to generate proofs - postsE2 := []miner.SubmitWindowedPoStParams{{Deadline: diE2.Index}} + postsE2 := []minertypes.SubmitWindowedPoStParams{{Deadline: diE2.Index}} mock.proveResult <- &proveRes{posts: postsE2} // Should move to proving complete for epoch 2 @@ -1051,7 +1052,7 @@ func TestChangeHandlerSubmitRevertAdvanceLess(t *testing.T) { s.ch.start() // Trigger a head change - currentEpoch := miner.WPoStChallengeWindow + currentEpoch := minertypes.WPoStChallengeWindow go triggerHeadAdvance(t, s, currentEpoch) // Submitter doesn't have anything to do yet @@ -1060,7 +1061,7 @@ func TestChangeHandlerSubmitRevertAdvanceLess(t *testing.T) { require.Equal(t, SubmitStateStart, s.submitState(diE1)) // Send a response to the call to generate proofs - posts := []miner.SubmitWindowedPoStParams{{Deadline: diE1.Index}} + posts := []minertypes.SubmitWindowedPoStParams{{Deadline: diE1.Index}} mock.proveResult <- &proveRes{posts: posts} // Should move to proving complete @@ -1086,7 +1087,7 @@ func TestChangeHandlerSubmitRevertAdvanceLess(t *testing.T) { // Should start proving epoch 2 // Send a response to the call to generate proofs - postsE2 := []miner.SubmitWindowedPoStParams{{Deadline: diE2.Index}} + postsE2 := []minertypes.SubmitWindowedPoStParams{{Deadline: diE2.Index}} mock.proveResult <- &proveRes{posts: postsE2} // Should move to proving complete for epoch 2 diff --git a/storage/wdpost_journal.go b/storage/wdpost_journal.go index 48eb2f2b1..53519588f 100644 --- a/storage/wdpost_journal.go +++ b/storage/wdpost_journal.go @@ -2,9 +2,8 @@ package storage import ( "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/go-state-types/dline" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" - "github.com/ipfs/go-cid" ) diff --git a/storage/wdpost_nextdl_test.go b/storage/wdpost_nextdl_test.go index 31e8b7d6d..5de546a17 100644 --- a/storage/wdpost_nextdl_test.go +++ b/storage/wdpost_nextdl_test.go @@ -7,7 +7,8 @@ import ( "github.com/stretchr/testify/require" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" ) func TestNextDeadline(t *testing.T) { @@ -22,14 +23,14 @@ func TestNextDeadline(t *testing.T) { require.EqualValues(t, 0, di.Open) require.EqualValues(t, 60, di.Close) - for i := 1; i < 1+int(miner.WPoStPeriodDeadlines)*2; i++ { + for i := 1; i < 1+int(minertypes.WPoStPeriodDeadlines)*2; i++ { //stm: @WDPOST_NEXT_DEADLINE_001 di = nextDeadline(di) - deadlineIdx = i % int(miner.WPoStPeriodDeadlines) - expPeriodStart := int(miner.WPoStProvingPeriod) * (i / int(miner.WPoStPeriodDeadlines)) - expOpen := expPeriodStart + deadlineIdx*int(miner.WPoStChallengeWindow) - expClose := expOpen + int(miner.WPoStChallengeWindow) - expChallenge := expOpen - int(miner.WPoStChallengeLookback) + deadlineIdx = i % int(minertypes.WPoStPeriodDeadlines) + expPeriodStart := int(minertypes.WPoStProvingPeriod) * (i / int(minertypes.WPoStPeriodDeadlines)) + expOpen := expPeriodStart + deadlineIdx*int(minertypes.WPoStChallengeWindow) + expClose := expOpen + int(minertypes.WPoStChallengeWindow) + expChallenge := expOpen - int(minertypes.WPoStChallengeLookback) //fmt.Printf("%d: %d@%d %d-%d (%d)\n", i, expPeriodStart, deadlineIdx, expOpen, expClose, expChallenge) require.EqualValues(t, deadlineIdx, di.Index) require.EqualValues(t, expPeriodStart, di.PeriodStart) diff --git a/storage/wdpost_run.go b/storage/wdpost_run.go index c0c36b8c4..916c5a905 100644 --- a/storage/wdpost_run.go +++ b/storage/wdpost_run.go @@ -5,6 +5,8 @@ import ( "context" "time" + "github.com/filecoin-project/go-state-types/proof" + "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/specs-storage/storage" @@ -19,13 +21,13 @@ import ( "go.opencensus.io/trace" "golang.org/x/xerrors" - "github.com/filecoin-project/specs-actors/v3/actors/runtime/proof" proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" + "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/go-state-types/builtin/v8/miner" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/actors" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/messagepool" "github.com/filecoin-project/lotus/chain/types" @@ -323,7 +325,7 @@ func (s *WindowPoStScheduler) declareRecoveries(ctx context.Context, dlIdx uint6 msg := &types.Message{ To: s.actor, - Method: miner.Methods.DeclareFaultsRecovered, + Method: builtin.MethodsMiner.DeclareFaultsRecovered, Params: enc, Value: types.NewInt(0), } @@ -421,7 +423,7 @@ func (s *WindowPoStScheduler) declareFaults(ctx context.Context, dlIdx uint64, p msg := &types.Message{ To: s.actor, - Method: miner.Methods.DeclareFaults, + Method: builtin.MethodsMiner.DeclareFaults, Params: enc, Value: types.NewInt(0), // TODO: Is there a fee? } @@ -854,7 +856,7 @@ func (s *WindowPoStScheduler) submitPoStMessage(ctx context.Context, proof *mine msg := &types.Message{ To: s.actor, - Method: miner.Methods.SubmitWindowedPoSt, + Method: builtin.MethodsMiner.SubmitWindowedPoSt, Params: enc, Value: types.NewInt(0), } diff --git a/storage/wdpost_run_test.go b/storage/wdpost_run_test.go index cd61f15b7..6efb3e547 100644 --- a/storage/wdpost_run_test.go +++ b/storage/wdpost_run_test.go @@ -6,6 +6,12 @@ import ( "context" "testing" + prooftypes "github.com/filecoin-project/go-state-types/proof" + + "github.com/filecoin-project/lotus/chain/actors" + lbuiltin "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/stretchr/testify/require" "golang.org/x/xerrors" @@ -15,14 +21,9 @@ import ( "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/specs-storage/storage" - builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" - miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner" - proof2 "github.com/filecoin-project/specs-actors/v2/actors/runtime/proof" + "github.com/filecoin-project/go-state-types/builtin" + minertypes "github.com/filecoin-project/go-state-types/builtin/v8/miner" tutils "github.com/filecoin-project/specs-actors/v2/support/testing" - builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin" - miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" - "github.com/filecoin-project/specs-actors/v6/actors/runtime/proof" - proof7 "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" @@ -32,7 +33,6 @@ import ( "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/actors/policy" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/extern/sector-storage/storiface" @@ -51,8 +51,8 @@ func newMockStorageMinerAPI() *mockStorageMinerAPI { } } -func (m *mockStorageMinerAPI) StateMinerInfo(ctx context.Context, a address.Address, key types.TipSetKey) (miner.MinerInfo, error) { - return miner.MinerInfo{ +func (m *mockStorageMinerAPI) StateMinerInfo(ctx context.Context, a address.Address, key types.TipSetKey) (api.MinerInfo, error) { + return api.MinerInfo{ Worker: tutils.NewIDAddr(nil, 101), Owner: tutils.NewIDAddr(nil, 101), }, nil @@ -78,13 +78,13 @@ func (m *mockStorageMinerAPI) StateMinerPartitions(ctx context.Context, a addres return m.partitions, nil } -func (m *mockStorageMinerAPI) StateMinerSectors(ctx context.Context, address address.Address, snos *bitfield.BitField, key types.TipSetKey) ([]*miner.SectorOnChainInfo, error) { - var sis []*miner.SectorOnChainInfo +func (m *mockStorageMinerAPI) StateMinerSectors(ctx context.Context, address address.Address, snos *bitfield.BitField, key types.TipSetKey) ([]*minertypes.SectorOnChainInfo, error) { + var sis []*minertypes.SectorOnChainInfo if snos == nil { panic("unsupported") } _ = snos.ForEach(func(i uint64) error { - sis = append(sis, &miner.SectorOnChainInfo{ + sis = append(sis, &minertypes.SectorOnChainInfo{ SectorNumber: abi.SectorNumber(i), }) return nil @@ -118,20 +118,20 @@ func (m *mockStorageMinerAPI) GasEstimateFeeCap(context.Context, *types.Message, type mockProver struct { } -func (m *mockProver) GenerateWinningPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte) ([]proof.PoStProof, error) { +func (m *mockProver) GenerateWinningPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte) ([]prooftypes.PoStProof, error) { panic("implement me") } -func (m *mockProver) GenerateWindowPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte, partitionIdx int) (proof.PoStProof, error) { +func (m *mockProver) GenerateWindowPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte, partitionIdx int) (prooftypes.PoStProof, error) { panic("implement me") } -func (m *mockProver) GenerateWinningPoSt(context.Context, abi.ActorID, []proof7.ExtendedSectorInfo, abi.PoStRandomness) ([]proof2.PoStProof, error) { +func (m *mockProver) GenerateWinningPoSt(context.Context, abi.ActorID, []prooftypes.ExtendedSectorInfo, abi.PoStRandomness) ([]prooftypes.PoStProof, error) { panic("implement me") } -func (m *mockProver) GenerateWindowPoSt(ctx context.Context, aid abi.ActorID, sis []proof7.ExtendedSectorInfo, pr abi.PoStRandomness) ([]proof2.PoStProof, []abi.SectorID, error) { - return []proof2.PoStProof{ +func (m *mockProver) GenerateWindowPoSt(ctx context.Context, aid abi.ActorID, sis []prooftypes.ExtendedSectorInfo, pr abi.PoStRandomness) ([]prooftypes.PoStProof, []abi.SectorID, error) { + return []prooftypes.PoStProof{ { PoStProof: abi.RegisteredPoStProof_StackedDrgWindow2KiBV1, ProofBytes: []byte("post-proof"), @@ -142,11 +142,11 @@ func (m *mockProver) GenerateWindowPoSt(ctx context.Context, aid abi.ActorID, si type mockVerif struct { } -func (m mockVerif) VerifyWinningPoSt(ctx context.Context, info proof7.WinningPoStVerifyInfo) (bool, error) { +func (m mockVerif) VerifyWinningPoSt(ctx context.Context, info prooftypes.WinningPoStVerifyInfo) (bool, error) { panic("implement me") } -func (m mockVerif) VerifyWindowPoSt(ctx context.Context, info proof2.WindowPoStVerifyInfo) (bool, error) { +func (m mockVerif) VerifyWindowPoSt(ctx context.Context, info prooftypes.WindowPoStVerifyInfo) (bool, error) { if len(info.Proofs) != 1 { return false, xerrors.Errorf("expected 1 proof entry") } @@ -159,15 +159,15 @@ func (m mockVerif) VerifyWindowPoSt(ctx context.Context, info proof2.WindowPoStV return true, nil } -func (m mockVerif) VerifyAggregateSeals(aggregate proof7.AggregateSealVerifyProofAndInfos) (bool, error) { +func (m mockVerif) VerifyAggregateSeals(aggregate prooftypes.AggregateSealVerifyProofAndInfos) (bool, error) { panic("implement me") } -func (m mockVerif) VerifyReplicaUpdate(update proof7.ReplicaUpdateInfo) (bool, error) { +func (m mockVerif) VerifyReplicaUpdate(update prooftypes.ReplicaUpdateInfo) (bool, error) { panic("implement me") } -func (m mockVerif) VerifySeal(proof2.SealVerifyInfo) (bool, error) { +func (m mockVerif) VerifySeal(prooftypes.SealVerifyInfo) (bool, error) { panic("implement me") } @@ -199,7 +199,7 @@ func TestWDPostDoPost(t *testing.T) { mockStgMinerAPI := newMockStorageMinerAPI() // Get the number of sectors allowed in a partition for this proof type - sectorsPerPartition, err := builtin5.PoStProofWindowPoStPartitionSectors(proofType) + sectorsPerPartition, err := builtin.PoStProofWindowPoStPartitionSectors(proofType) require.NoError(t, err) // Work out the number of partitions that can be included in a message // without exceeding the message sector limit @@ -207,8 +207,8 @@ func TestWDPostDoPost(t *testing.T) { //stm: @BLOCKCHAIN_POLICY_GET_MAX_POST_PARTITIONS_001 partitionsPerMsg, err := policy.GetMaxPoStPartitions(network.Version13, proofType) require.NoError(t, err) - if partitionsPerMsg > miner5.AddressedPartitionsMax { - partitionsPerMsg = miner5.AddressedPartitionsMax + if partitionsPerMsg > minertypes.AddressedPartitionsMax { + partitionsPerMsg = minertypes.AddressedPartitionsMax } // Enough partitions to fill expectedMsgCount-1 messages @@ -245,23 +245,23 @@ func TestWDPostDoPost(t *testing.T) { } di := &dline.Info{ - WPoStPeriodDeadlines: miner5.WPoStPeriodDeadlines, - WPoStProvingPeriod: miner5.WPoStProvingPeriod, - WPoStChallengeWindow: miner5.WPoStChallengeWindow, - WPoStChallengeLookback: miner5.WPoStChallengeLookback, - FaultDeclarationCutoff: miner5.FaultDeclarationCutoff, + WPoStPeriodDeadlines: minertypes.WPoStPeriodDeadlines, + WPoStProvingPeriod: minertypes.WPoStProvingPeriod, + WPoStChallengeWindow: minertypes.WPoStChallengeWindow, + WPoStChallengeLookback: minertypes.WPoStChallengeLookback, + FaultDeclarationCutoff: minertypes.FaultDeclarationCutoff, } ts := mockTipSet(t) - scheduler.startGeneratePoST(ctx, ts, di, func(posts []miner.SubmitWindowedPoStParams, err error) { + scheduler.startGeneratePoST(ctx, ts, di, func(posts []minertypes.SubmitWindowedPoStParams, err error) { scheduler.startSubmitPoST(ctx, ts, di, posts, func(err error) {}) }) // Read the window PoST messages for i := 0; i < expectedMsgCount; i++ { msg := <-mockStgMinerAPI.pushedMessages - require.Equal(t, miner.Methods.SubmitWindowedPoSt, msg.Method) - var params miner.SubmitWindowedPoStParams + require.Equal(t, builtin.MethodsMiner.SubmitWindowedPoSt, msg.Method) + var params minertypes.SubmitWindowedPoStParams err := params.UnmarshalCBOR(bytes.NewReader(msg.Params)) require.NoError(t, err) @@ -305,11 +305,11 @@ func (m *mockStorageMinerAPI) StateMinerDeadlines(ctx context.Context, maddr add panic("implement me") } -func (m *mockStorageMinerAPI) StateSectorPreCommitInfo(ctx context.Context, address address.Address, number abi.SectorNumber, key types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) { +func (m *mockStorageMinerAPI) StateSectorPreCommitInfo(ctx context.Context, address address.Address, number abi.SectorNumber, key types.TipSetKey) (minertypes.SectorPreCommitOnChainInfo, error) { panic("implement me") } -func (m *mockStorageMinerAPI) StateSectorGetInfo(ctx context.Context, address address.Address, number abi.SectorNumber, key types.TipSetKey) (*miner.SectorOnChainInfo, error) { +func (m *mockStorageMinerAPI) StateSectorGetInfo(ctx context.Context, address address.Address, number abi.SectorNumber, key types.TipSetKey) (*minertypes.SectorOnChainInfo, error) { panic("implement me") } @@ -326,19 +326,19 @@ func (m *mockStorageMinerAPI) StateMinerProvingDeadline(ctx context.Context, add Close: 0, Challenge: 0, FaultCutoff: 0, - WPoStPeriodDeadlines: miner2.WPoStPeriodDeadlines, - WPoStProvingPeriod: miner2.WPoStProvingPeriod, - WPoStChallengeWindow: miner2.WPoStChallengeWindow, - WPoStChallengeLookback: miner2.WPoStChallengeLookback, - FaultDeclarationCutoff: miner2.FaultDeclarationCutoff, + WPoStPeriodDeadlines: minertypes.WPoStPeriodDeadlines, + WPoStProvingPeriod: minertypes.WPoStProvingPeriod, + WPoStChallengeWindow: minertypes.WPoStChallengeWindow, + WPoStChallengeLookback: minertypes.WPoStChallengeLookback, + FaultDeclarationCutoff: minertypes.FaultDeclarationCutoff, }, nil } -func (m *mockStorageMinerAPI) StateMinerPreCommitDepositForPower(ctx context.Context, address address.Address, info miner.SectorPreCommitInfo, key types.TipSetKey) (types.BigInt, error) { +func (m *mockStorageMinerAPI) StateMinerPreCommitDepositForPower(ctx context.Context, address address.Address, info minertypes.SectorPreCommitInfo, key types.TipSetKey) (types.BigInt, error) { panic("implement me") } -func (m *mockStorageMinerAPI) StateMinerInitialPledgeCollateral(ctx context.Context, address address.Address, info miner.SectorPreCommitInfo, key types.TipSetKey) (types.BigInt, error) { +func (m *mockStorageMinerAPI) StateMinerInitialPledgeCollateral(ctx context.Context, address address.Address, info minertypes.SectorPreCommitInfo, key types.TipSetKey) (types.BigInt, error) { panic("implement me") } @@ -347,8 +347,12 @@ func (m *mockStorageMinerAPI) StateSearchMsg(ctx context.Context, from types.Tip } func (m *mockStorageMinerAPI) StateGetActor(ctx context.Context, actor address.Address, ts types.TipSetKey) (*types.Actor, error) { + code, err := lbuiltin.GetMinerActorCodeID(actors.Version7) + if err != nil { + return nil, err + } return &types.Actor{ - Code: builtin2.StorageMinerActorCodeID, + Code: code, }, nil } diff --git a/testplans/lotus-soup/go.mod b/testplans/lotus-soup/go.mod index 65cd77f42..fb039cf76 100644 --- a/testplans/lotus-soup/go.mod +++ b/testplans/lotus-soup/go.mod @@ -9,12 +9,12 @@ require ( github.com/drand/drand v1.3.0 github.com/filecoin-project/go-address v0.0.6 github.com/filecoin-project/go-data-transfer v1.15.1 - github.com/filecoin-project/go-fil-markets v1.20.1 + github.com/filecoin-project/go-fil-markets v1.20.1-v16-2 github.com/filecoin-project/go-jsonrpc v0.1.5 - github.com/filecoin-project/go-state-types v0.1.3 + github.com/filecoin-project/go-state-types v0.1.10 github.com/filecoin-project/go-storedcounter v0.1.0 github.com/filecoin-project/lotus v0.0.0-00010101000000-000000000000 - github.com/filecoin-project/specs-actors v0.9.14 + github.com/filecoin-project/specs-actors v0.9.15 github.com/google/uuid v1.3.0 github.com/gorilla/mux v1.8.0 github.com/hashicorp/go-multierror v1.1.1 @@ -27,7 +27,7 @@ require ( github.com/ipfs/go-unixfs v0.3.1 github.com/ipld/go-car v0.3.3 github.com/kpacha/opencensus-influxdb v0.0.0-20181102202715-663e2683a27c - github.com/libp2p/go-libp2p v0.19.0 + github.com/libp2p/go-libp2p v0.19.4 github.com/libp2p/go-libp2p-core v0.15.1 github.com/libp2p/go-libp2p-pubsub-tracer v0.0.0-20200626141350-e730b32bf1e6 github.com/multiformats/go-multiaddr v0.5.0 @@ -94,7 +94,7 @@ require ( 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-hamt-ipld/v3 v3.1.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-paramfetch v0.0.4 // indirect github.com/filecoin-project/go-statemachine v1.0.2 // indirect @@ -102,12 +102,13 @@ require ( github.com/filecoin-project/index-provider v0.5.0 // indirect github.com/filecoin-project/pubsub v1.0.0 // indirect github.com/filecoin-project/specs-actors/v2 v2.3.6 // indirect - github.com/filecoin-project/specs-actors/v3 v3.1.1 // indirect - github.com/filecoin-project/specs-actors/v4 v4.0.1 // indirect - github.com/filecoin-project/specs-actors/v5 v5.0.4 // indirect - github.com/filecoin-project/specs-actors/v6 v6.0.1 // indirect - github.com/filecoin-project/specs-actors/v7 v7.0.0 // indirect - github.com/filecoin-project/specs-storage v0.2.3-0.20220426183226-1a0a63c5990f // indirect + github.com/filecoin-project/specs-actors/v3 v3.1.2 // indirect + github.com/filecoin-project/specs-actors/v4 v4.0.2 // indirect + github.com/filecoin-project/specs-actors/v5 v5.0.6 // indirect + github.com/filecoin-project/specs-actors/v6 v6.0.2 // indirect + github.com/filecoin-project/specs-actors/v7 v7.0.1 // indirect + github.com/filecoin-project/specs-actors/v8 v8.0.0 // 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 @@ -214,7 +215,7 @@ require ( github.com/libp2p/go-libp2p-noise v0.4.0 // indirect github.com/libp2p/go-libp2p-peerstore v0.6.0 // indirect github.com/libp2p/go-libp2p-pnet v0.2.0 // indirect - github.com/libp2p/go-libp2p-pubsub v0.6.1 // indirect + github.com/libp2p/go-libp2p-pubsub v0.7.0 // indirect github.com/libp2p/go-libp2p-quic-transport v0.17.0 // indirect github.com/libp2p/go-libp2p-record v0.1.3 // indirect github.com/libp2p/go-libp2p-resource-manager v0.2.1 // indirect @@ -235,8 +236,8 @@ 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/lucas-clemente/quic-go v0.27.0 // 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 github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect @@ -284,7 +285,6 @@ require ( github.com/raulk/clock v1.1.0 // indirect github.com/raulk/go-watchdog v1.2.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect - github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/rivo/uniseg v0.1.0 // indirect github.com/rs/cors v1.7.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect @@ -296,7 +296,6 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/stretchr/testify v1.7.1 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect - github.com/tj/go-spin v1.1.0 // indirect github.com/uber/jaeger-client-go v2.28.0+incompatible // indirect github.com/uber/jaeger-lib v2.4.1+incompatible // indirect github.com/urfave/cli/v2 v2.3.0 // indirect @@ -306,14 +305,12 @@ require ( github.com/weaveworks/promrus v1.2.0 // indirect github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba // indirect github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 // indirect - github.com/whyrusleeping/cbor-gen v0.0.0-20220302191723-37c43cae8e14 // indirect + github.com/whyrusleeping/cbor-gen v0.0.0-20220323183124-98fa8256a799 // indirect github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect 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.dedis.ch/fixbuf v1.0.3 // indirect @@ -345,11 +342,6 @@ require ( gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect lukechampine.com/blake3 v1.1.7 // 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 ) // This will work in all build modes: docker:go, exec:go, and local go build. diff --git a/testplans/lotus-soup/go.sum b/testplans/lotus-soup/go.sum index 75ffd2a15..dfd59514c 100644 --- a/testplans/lotus-soup/go.sum +++ b/testplans/lotus-soup/go.sum @@ -434,8 +434,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= @@ -446,8 +446,9 @@ github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0/go.mod h1:bxmzgT8tmeVQA1/gvBw 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= @@ -458,11 +459,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= @@ -476,27 +480,33 @@ github.com/filecoin-project/index-provider v0.5.0/go.mod h1:KHVrP2vU3YuScb+fawOb 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.3-0.20220426183226-1a0a63c5990f h1:+suJFu4RJt7aZRXvE+Innrpacap+Z8N87y6a1Cgkuqc= -github.com/filecoin-project/specs-storage v0.2.3-0.20220426183226-1a0a63c5990f/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= @@ -1327,8 +1337,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.0 h1:zosskMbaobL7UDCVLEe1m5CGs1TaFNFoN/M5XLiKg0U= -github.com/libp2p/go-libp2p v0.19.0/go.mod h1:Ki9jJXLO2YqrTIFxofV7Twyd3INWPT97+r8hGt7XPjI= +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= @@ -1490,8 +1501,9 @@ github.com/libp2p/go-libp2p-protocol v0.1.0/go.mod h1:KQPHpAabB57XQxGrXCNvbL6UEX github.com/libp2p/go-libp2p-pubsub v0.1.1/go.mod h1:ZwlKzRSe1eGvSIdU5bD7+8RZN/Uzw0t1Bp9R1znpR/Q= github.com/libp2p/go-libp2p-pubsub v0.3.2/go.mod h1:Uss7/Cfz872KggNb+doCVPHeCDmXB7z500m/R8DaAUk= github.com/libp2p/go-libp2p-pubsub v0.6.0/go.mod h1:nJv87QM2cU0w45KPR1rZicq+FmFIOD16zmT+ep1nOmg= -github.com/libp2p/go-libp2p-pubsub v0.6.1 h1:wycbV+f4rreCoVY61Do6g/BUk0RIrbNRcYVbn+QkjGk= github.com/libp2p/go-libp2p-pubsub v0.6.1/go.mod h1:nJv87QM2cU0w45KPR1rZicq+FmFIOD16zmT+ep1nOmg= +github.com/libp2p/go-libp2p-pubsub v0.7.0 h1:Fd9198JVc3pCsKuzd37TclzM0QcHA+uDyoiG2pvT7s4= +github.com/libp2p/go-libp2p-pubsub v0.7.0/go.mod h1:EuyBJFtF8qF67IEA98biwK8Xnw5MNJpJ/Z+8iWCMFwc= github.com/libp2p/go-libp2p-pubsub-router v0.5.0/go.mod h1:TRJKskSem3C0aSb3CmRgPwq6IleVFzds6hS09fmZbGM= github.com/libp2p/go-libp2p-pubsub-tracer v0.0.0-20200626141350-e730b32bf1e6 h1:2lH7rMlvDPSvXeOR+g7FE6aqiEwxtpxWKQL8uigk5fQ= github.com/libp2p/go-libp2p-pubsub-tracer v0.0.0-20200626141350-e730b32bf1e6/go.mod h1:8ZodgKS4qRLayfw9FDKDd9DX4C16/GMofDxSldG8QPI= @@ -1503,6 +1515,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= @@ -1598,6 +1611,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= @@ -1700,8 +1714,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= @@ -1712,8 +1727,9 @@ github.com/lucas-clemente/quic-go v0.21.2/go.mod h1:vF5M1XqhBAHgbjKcJOXY3JZz3GP0 github.com/lucas-clemente/quic-go v0.23.0/go.mod h1:paZuzjXCE5mj6sikVLMvqXk8lJV2AsqtJ6bDhjEfxx0= github.com/lucas-clemente/quic-go v0.24.0/go.mod h1:paZuzjXCE5mj6sikVLMvqXk8lJV2AsqtJ6bDhjEfxx0= github.com/lucas-clemente/quic-go v0.25.0/go.mod h1:YtzP8bxRVCBlO77yRanE264+fY/T2U9ZlW1AaHOsMOg= -github.com/lucas-clemente/quic-go v0.27.0 h1:v6WY87q9zD4dKASbG8hy/LpzAVNzEQzw8sEIeloJsc4= github.com/lucas-clemente/quic-go v0.27.0/go.mod h1:AzgQoPda7N+3IqMMMkywBKggIFo2KT6pfnlrQ2QieeI= +github.com/lucas-clemente/quic-go v0.27.1 h1:sOw+4kFSVrdWOYmUjufQ9GBVPqZ+tu+jMtXxXNmRJyk= +github.com/lucas-clemente/quic-go v0.27.1/go.mod h1:AzgQoPda7N+3IqMMMkywBKggIFo2KT6pfnlrQ2QieeI= github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac= github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lufia/iostat v1.1.0/go.mod h1:rEPNA0xXgjHQjuI5Cy05sLlS2oRcSlWHRLrvh/AQ+Pg= @@ -2105,8 +2121,6 @@ github.com/raulk/go-watchdog v1.2.0/go.mod h1:lzSbAl5sh4rtI8tYHU01BWIDzgzqaQLj6R github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 h1:MkV+77GLUNo5oJ0jf870itWm3D0Sjh7+Za9gazKc5LQ= github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0/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/retailnext/hllpp v1.0.1-0.20180308014038-101a6d2f8b52/go.mod h1:RDpi1RftBQPUCDRw6SmxeaREsAaRKnOclghuzp/WRzc= github.com/rivo/uniseg v0.1.0 h1:+2KBaVoUmb9XzDsrx/Ct0W/EYOSFf/nWTauy++DprtY= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= @@ -2241,8 +2255,6 @@ github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0 github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tinylib/msgp v1.1.0/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= -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/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= @@ -2306,10 +2318,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= @@ -2334,10 +2346,6 @@ github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7V github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= 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/xlab/treeprint v0.0.0-20180616005107-d6fb6747feb6/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= 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= @@ -2512,7 +2520,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= @@ -2877,7 +2884,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-20200721032237-77f530d86f9a/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= @@ -3085,20 +3091,6 @@ k8s.io/utils v0.0.0-20200414100711-2df71ebbae66/go.mod h1:jPW/WVKK9YHAvNhRxK0md/ lukechampine.com/blake3 v1.1.6/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= lukechampine.com/blake3 v1.1.7 h1:GgRMhmdsuK8+ii6UZFDL8Nb+VyMwadAgcJyfYHxG6n0= lukechampine.com/blake3 v1.1.7/go.mod h1:tkKEOtDkNtklkXtLNEOGNq5tcV90tJiA1vAA12R78LA= -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/testplans/lotus-soup/paych/stress.go b/testplans/lotus-soup/paych/stress.go index 4f107bf5b..6b91d7277 100644 --- a/testplans/lotus-soup/paych/stress.go +++ b/testplans/lotus-soup/paych/stress.go @@ -6,11 +6,12 @@ import ( "os" "time" + "github.com/filecoin-project/go-state-types/builtin/v8/paych" + "github.com/ipfs/go-cid" "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/specs-actors/actors/builtin/paych" "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big"