Merge pull request #6580 from filecoin-project/release/v1.10.0
Release/v1.10.0
This commit is contained in:
commit
764fa9dae6
@ -428,6 +428,40 @@ jobs:
|
|||||||
- "~/.rustup"
|
- "~/.rustup"
|
||||||
- "~/.cargo"
|
- "~/.cargo"
|
||||||
|
|
||||||
|
build-appimage:
|
||||||
|
machine:
|
||||||
|
image: ubuntu-2004:202104-01
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- attach_workspace:
|
||||||
|
at: "."
|
||||||
|
- run:
|
||||||
|
name: install appimage-builder
|
||||||
|
command: |
|
||||||
|
# docs: https://appimage-builder.readthedocs.io/en/latest/intro/install.html
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y python3-pip python3-setuptools patchelf desktop-file-utils libgdk-pixbuf2.0-dev fakeroot strace
|
||||||
|
sudo curl -Lo /usr/local/bin/appimagetool https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage
|
||||||
|
sudo chmod +x /usr/local/bin/appimagetool
|
||||||
|
sudo pip3 install appimage-builder
|
||||||
|
- run:
|
||||||
|
name: install lotus dependencies
|
||||||
|
command: sudo apt install ocl-icd-opencl-dev libhwloc-dev
|
||||||
|
- run:
|
||||||
|
name: build appimage
|
||||||
|
command: |
|
||||||
|
sed -i "s/version: latest/version: ${CIRCLE_TAG:-latest}/" AppImageBuilder.yml
|
||||||
|
make appimage
|
||||||
|
- run:
|
||||||
|
name: prepare workspace
|
||||||
|
command: |
|
||||||
|
mkdir appimage
|
||||||
|
mv Lotus-latest-x86_64.AppImage appimage
|
||||||
|
- persist_to_workspace:
|
||||||
|
root: "."
|
||||||
|
paths:
|
||||||
|
- appimage
|
||||||
|
|
||||||
gofmt:
|
gofmt:
|
||||||
executor: golang
|
executor: golang
|
||||||
steps:
|
steps:
|
||||||
@ -802,10 +836,9 @@ workflows:
|
|||||||
tags:
|
tags:
|
||||||
only:
|
only:
|
||||||
- /^v\d+\.\d+\.\d+(-rc\d+)?$/
|
- /^v\d+\.\d+\.\d+(-rc\d+)?$/
|
||||||
- publish:
|
- build-appimage:
|
||||||
requires:
|
requires:
|
||||||
- build-all
|
- test-short
|
||||||
- build-macos
|
|
||||||
filters:
|
filters:
|
||||||
branches:
|
branches:
|
||||||
ignore:
|
ignore:
|
||||||
@ -813,6 +846,19 @@ workflows:
|
|||||||
tags:
|
tags:
|
||||||
only:
|
only:
|
||||||
- /^v\d+\.\d+\.\d+(-rc\d+)?$/
|
- /^v\d+\.\d+\.\d+(-rc\d+)?$/
|
||||||
|
- publish:
|
||||||
|
requires:
|
||||||
|
- build-all
|
||||||
|
- build-macos
|
||||||
|
- build-appimage
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
ignore:
|
||||||
|
- /.*/
|
||||||
|
tags:
|
||||||
|
only:
|
||||||
|
- /^v\d+\.\d+\.\d+(-rc\d+)?$/
|
||||||
|
|
||||||
- build-and-push-image:
|
- build-and-push-image:
|
||||||
dockerfile: Dockerfile.lotus
|
dockerfile: Dockerfile.lotus
|
||||||
path: .
|
path: .
|
||||||
|
1
AppDir/usr/share/icons/icon.svg
Normal file
1
AppDir/usr/share/icons/icon.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0" y="0" viewBox="0 0 127 127" xml:space="preserve" enable-background="new 0 0 127 127"><style type="text/css">.st0{fill:#00d2d6}.st1{fill:#fff}</style><g><path class="st0" d="M63.5,127C28.5,127.1-0.2,98.4,0,63.2C0.2,28.3,28.6-0.2,63.9,0c34.8,0.2,63.3,28.7,63.1,64 C126.7,98.7,98.5,127.1,63.5,127z M71.4,57.6c5.5,0.8,11,1.5,16.5,2.3c0.5-1.7,0.9-3.1,1.3-4.7c-5.7-0.8-11.2-1.7-17.1-2.5 c2-7,3.7-13.7,5.8-20.2c0.7-2.2,2.3-4.2,3.9-5.9c2.1-2.2,5-1.7,6.8,0.7c0.7,1,1.4,2.1,2.3,2.9c1.1,1.1,2.8,1.6,4,0.6 c0.8-0.7,0.7-2.4,0.8-3.6c0-0.5-0.6-1.1-1-1.6c-2-2.3-4.7-3.1-7.5-3.2c-6.3-0.3-10.9,3-14.5,7.8c-3.5,4.8-5.1,10.5-6.8,16.2 c-0.5,1.6-0.9,3.3-1.4,5.1c-6.2-0.9-12.1-1.7-18.2-2.6c-0.2,1.6-0.4,3.2-0.6,4.8c6,0.9,11.8,1.8,17.8,2.7c-0.8,3.4-1.5,6.5-2.3,9.7 c-5.8-0.8-11.4-1.6-17-2.4c-0.2,1.8-0.4,3.2-0.6,4.8c5.6,0.9,11,1.7,16.5,2.5c0,0.6,0.1,1,0,1.3c-1.7,7.4-3.4,14.8-5.3,22.2 c-0.9,3.5-2.4,6.9-5.3,9.3c-2.4,2-5,1.7-6.8-0.8c-0.8-1.1-1.5-2.5-2.6-3.3c-0.8-0.6-2.5-0.9-3.1-0.5c-0.9,0.7-1.5,2.2-1.4,3.3 c0.1,1,1,2.2,1.9,2.8c3,2.3,6.5,2.6,10,1.9c5.9-1.2,10.1-4.9,12.7-10.1c2-4.1,3.6-8.5,5-12.9c1.3-4,2.2-8,3.3-12.2 c5.8,0.8,11.5,1.7,17.3,2.5c0.5-1.7,0.9-3.2,1.4-4.8c-6.1-0.9-11.9-1.7-17.7-2.6C70.1,64,70.7,60.9,71.4,57.6z"/><path class="st1" d="M71.4,57.6c-0.7,3.3-1.3,6.4-2,9.8c5.9,0.9,11.7,1.7,17.7,2.6c-0.5,1.6-0.9,3.1-1.4,4.8 c-5.8-0.8-11.5-1.7-17.3-2.5c-1.1,4.2-2,8.3-3.3,12.2c-1.4,4.4-3,8.7-5,12.9c-2.6,5.2-6.8,8.9-12.7,10.1c-3.5,0.7-7,0.4-10-1.9 c-0.9-0.7-1.8-1.8-1.9-2.8c-0.1-1.1,0.5-2.7,1.4-3.3c0.6-0.5,2.3-0.1,3.1,0.5c1.1,0.8,1.8,2.1,2.6,3.3c1.8,2.5,4.4,2.9,6.8,0.8 c2.9-2.5,4.4-5.8,5.3-9.3c1.9-7.3,3.6-14.8,5.3-22.2c0.1-0.3,0-0.7,0-1.3c-5.4-0.8-10.8-1.7-16.5-2.5c0.2-1.6,0.4-3,0.6-4.8 c5.6,0.8,11.1,1.6,17,2.4c0.8-3.2,1.5-6.4,2.3-9.7c-6-0.9-11.7-1.8-17.8-2.7c0.2-1.6,0.4-3.2,0.6-4.8c6.1,0.9,12,1.7,18.2,2.6 c0.5-1.8,0.9-3.5,1.4-5.1c1.7-5.6,3.2-11.3,6.8-16.2c3.6-4.9,8.1-8.1,14.5-7.8c2.8,0.1,5.5,0.9,7.5,3.2c0.4,0.5,1,1.1,1,1.6 c-0.1,1.2,0,2.9-0.8,3.6c-1.1,1.1-2.8,0.5-4-0.6c-0.9-0.9-1.6-1.9-2.3-2.9c-1.8-2.4-4.7-2.9-6.8-0.7c-1.6,1.7-3.2,3.7-3.9,5.9 C75.7,39.4,74,46,72,53c5.9,0.9,11.4,1.7,17.1,2.5c-0.5,1.6-0.9,3.1-1.3,4.7C82.3,59.1,76.9,58.3,71.4,57.6z"/></g></svg>
|
After Width: | Height: | Size: 2.2 KiB |
73
AppImageBuilder.yml
Normal file
73
AppImageBuilder.yml
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
version: 1
|
||||||
|
AppDir:
|
||||||
|
path: ./AppDir
|
||||||
|
app_info:
|
||||||
|
id: io.filecoin.lotus
|
||||||
|
name: Lotus
|
||||||
|
icon: icon
|
||||||
|
version: latest
|
||||||
|
exec: usr/bin/lotus
|
||||||
|
exec_args: $@
|
||||||
|
apt:
|
||||||
|
arch: amd64
|
||||||
|
allow_unauthenticated: true
|
||||||
|
sources:
|
||||||
|
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal main restricted
|
||||||
|
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted
|
||||||
|
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal universe
|
||||||
|
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates universe
|
||||||
|
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal multiverse
|
||||||
|
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-updates multiverse
|
||||||
|
- sourceline: deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted
|
||||||
|
universe multiverse
|
||||||
|
- sourceline: deb http://security.ubuntu.com/ubuntu focal-security main restricted
|
||||||
|
- sourceline: deb http://security.ubuntu.com/ubuntu focal-security universe
|
||||||
|
- sourceline: deb http://security.ubuntu.com/ubuntu focal-security multiverse
|
||||||
|
- sourceline: deb https://cli-assets.heroku.com/apt ./
|
||||||
|
- sourceline: deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu focal main
|
||||||
|
- sourceline: deb http://ppa.launchpad.net/git-core/ppa/ubuntu focal main
|
||||||
|
- sourceline: deb http://archive.canonical.com/ubuntu focal partner
|
||||||
|
include:
|
||||||
|
- ocl-icd-libopencl1
|
||||||
|
- libhwloc15
|
||||||
|
exclude: []
|
||||||
|
files:
|
||||||
|
include:
|
||||||
|
- /usr/lib/x86_64-linux-gnu/libgcc_s.so.1
|
||||||
|
- /usr/lib/x86_64-linux-gnu/libpthread-2.31.so
|
||||||
|
- /usr/lib/x86_64-linux-gnu/libm-2.31.so
|
||||||
|
- /usr/lib/x86_64-linux-gnu/libdl-2.31.so
|
||||||
|
- /usr/lib/x86_64-linux-gnu/libc-2.31.so
|
||||||
|
- /usr/lib/x86_64-linux-gnu/libudev.so.1.6.17
|
||||||
|
exclude:
|
||||||
|
- usr/share/man
|
||||||
|
- usr/share/doc/*/README.*
|
||||||
|
- usr/share/doc/*/changelog.*
|
||||||
|
- usr/share/doc/*/NEWS.*
|
||||||
|
- usr/share/doc/*/TODO.*
|
||||||
|
test:
|
||||||
|
fedora:
|
||||||
|
image: appimagecrafters/tests-env:fedora-30
|
||||||
|
command: ./AppRun
|
||||||
|
use_host_x: true
|
||||||
|
debian:
|
||||||
|
image: appimagecrafters/tests-env:debian-stable
|
||||||
|
command: ./AppRun
|
||||||
|
use_host_x: true
|
||||||
|
arch:
|
||||||
|
image: appimagecrafters/tests-env:archlinux-latest
|
||||||
|
command: ./AppRun
|
||||||
|
use_host_x: true
|
||||||
|
centos:
|
||||||
|
image: appimagecrafters/tests-env:centos-7
|
||||||
|
command: ./AppRun
|
||||||
|
use_host_x: true
|
||||||
|
ubuntu:
|
||||||
|
image: appimagecrafters/tests-env:ubuntu-xenial
|
||||||
|
command: ./AppRun
|
||||||
|
use_host_x: true
|
||||||
|
AppImage:
|
||||||
|
arch: x86_64
|
||||||
|
update-information: guess
|
||||||
|
sign-key: None
|
||||||
|
|
137
CHANGELOG.md
137
CHANGELOG.md
@ -1,5 +1,142 @@
|
|||||||
# Lotus changelog
|
# Lotus changelog
|
||||||
|
|
||||||
|
# 1.10.0 / 2021-06-23
|
||||||
|
|
||||||
|
This is a mandatory release of Lotus that introduces Filecoin network v13, codenamed the HyperDrive upgrade. The
|
||||||
|
Filecoin mainnet will upgrade, which is epoch 892800, on 2021-06-30T22:00:00Z. The network upgrade introduces the
|
||||||
|
following FIPs:
|
||||||
|
|
||||||
|
- [FIP-0008](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0008.md): Add miner batched sector pre-commit method
|
||||||
|
- [FIP-0011](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0011.md): Remove reward auction from reporting consensus faults
|
||||||
|
- [FIP-0012](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0012.md): DataCap Top up for FIL+ Client Addresses
|
||||||
|
- [FIP-0013](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0013.md): Add ProveCommitSectorAggregated method to reduce on-chain congestion
|
||||||
|
- [FIP-0015](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0015.md): Revert FIP-0009(Exempt Window PoSts from BaseFee burn)
|
||||||
|
|
||||||
|
Note that this release is built on top of Lotus v1.9.0. Enterprising users can use the `master` branch of Lotus to get the latest functionality, including all changes in this release candidate.
|
||||||
|
|
||||||
|
## Proof batching and aggregation
|
||||||
|
|
||||||
|
FIPs [0008](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0008.md) and [0013](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0013.md) combine to allow for a significant increase in the rate of onboarding storage on the Filecoin network. This aims to lead to more useful data being stored on the network, reduced network congestion, and lower network base fee.
|
||||||
|
|
||||||
|
**Check out the documentation [here](https://docs.filecoin.io/mine/lotus/miner-configuration/#precommitsectorsbatch) for details on the new Lotus miner sealing config options, [here](https://docs.filecoin.io/mine/lotus/miner-configuration/#fees-section) for fee config options, and explanations of the new features.**
|
||||||
|
|
||||||
|
Note:
|
||||||
|
- We recommend to keep `PreCommitSectorsBatch` as 1.
|
||||||
|
- We recommend miners to set `PreCommitBatchWait` lower than 30 hours.
|
||||||
|
- We recommend miners to set a longer `CommitBatchSlack` and `PreCommitBatchSlack` to prevent message failures
|
||||||
|
due to expirations.
|
||||||
|
|
||||||
|
### Projected state tree growth
|
||||||
|
|
||||||
|
In order to validate the Hyperdrive changes, we wrote a simulation to seal as many sectors as quickly as possible, assuming the same number and mix of 32GiB and 64GiB miners as the current network.
|
||||||
|
|
||||||
|
Given these assumptions:
|
||||||
|
|
||||||
|
- We'd expect a network storage growth rate of around 530PiB per day. 😳 🎉 🥳 😅
|
||||||
|
- We'd expect network bandwidth dedicated to `SubmitWindowedPoSt` to grow by about 0.02% per day.
|
||||||
|
- We'd expect the [state-tree](https://spec.filecoin.io/#section-systems.filecoin_vm.state_tree) (and therefore [snapshot](https://docs.filecoin.io/get-started/lotus/chain/#lightweight-snapshot)) size to grow by 1.16GiB per day.
|
||||||
|
- Nearly all of the state-tree growth is expected to come from new sector metadata.
|
||||||
|
- We'd expect the daily lotus datastore growth rate to increase by about 10-15% (from current ~21GiB/day).
|
||||||
|
- Most "growth" of the lotus datastore is due to "churn", historical data that's no longer referenced by the latest state-tree.
|
||||||
|
|
||||||
|
### Future improvements
|
||||||
|
|
||||||
|
Various Lotus improvements are planned moving forward to mitigate the effects of the growing state tree size. The primary improvement is the [Lotus splitstore](https://github.com/filecoin-project/lotus/discussions/5788), which will soon be enabled by default. The feature allows for [online garbage collection](https://github.com/filecoin-project/lotus/issues/6577) for nodes that do not seek to maintain full chain and state history, thus eliminating the need for users to delete their datastores and sync from snapshots.
|
||||||
|
|
||||||
|
Other improvements including better compressed snapshots, faster pre-migrations, and improved chain exports are in the roadmap.
|
||||||
|
|
||||||
|
## WindowPost base fee burn
|
||||||
|
|
||||||
|
Included in the HyperDrive upgrade is [FIP-0015](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0015.md) which eliminates the special-case gas treatment of `SubmitWindowedPoSt` messages that was introduced in [FIP-0009](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0009.md). Although `SubmitWindowedPoSt` messages will be relatively cheap, thanks to the introduction of optimistic acceptance of these proofs in [FIP-0010](https://github.com/filecoin-project/FIPs/blob/master/FIPS/fip-0010.md), storage providers should pay attention to their `MaxWindowPoStGasFee` config option: too low and PoSts may not land on chain; too high and they may cost an exorbitant amount!
|
||||||
|
|
||||||
|
## Changelog
|
||||||
|
|
||||||
|
### New Features
|
||||||
|
|
||||||
|
- Implement FIP-0015 ([filecoin-project/lotus#6361](https://github.com/filecoin-project/lotus/pull/6361))
|
||||||
|
- Integrate FIP0013 and FIP0008 ([filecoin-project/lotus#6235](https://github.com/filecoin-project/lotus/pull/6235))
|
||||||
|
- [Configuration docs and cli examples](https://docs.filecoin.io/mine/lotus/miner-configuration/#precommitsectorsbatch)
|
||||||
|
- [cli docs](https://github.com/filecoin-project/lotus/blob/master/documentation/en/cli-lotus-miner.md#lotus-miner-sectors-batching)
|
||||||
|
- Introduce gas prices for aggregate verifications ([filecoin-project/lotus#6347](https://github.com/filecoin-project/lotus/pull/6347))
|
||||||
|
- Introduce v5 actors ([filecoin-project/lotus#6195](https://github.com/filecoin-project/lotus/pull/6195))
|
||||||
|
- Robustify commit batcher ([filecoin-project/lotus#6367](https://github.com/filecoin-project/lotus/pull/6367))
|
||||||
|
- Always flush when timer goes off ([filecoin-project/lotus#6563](https://github.com/filecoin-project/lotus/pull/6563))
|
||||||
|
- Update default fees for aggregates ([filecoin-project/lotus#6548](https://github.com/filecoin-project/lotus/pull/6548))
|
||||||
|
- sealing: Early finalization option ([filecoin-project/lotus#6452](https://github.com/filecoin-project/lotus/pull/6452))
|
||||||
|
- `./lotus-miner/config.toml/[Sealing.FinalizeEarly]`: default to false. Enable if you want to FinalizeSector before commiting
|
||||||
|
- Add filplus utils to CLI ([filecoin-project/lotus#6351](https://github.com/filecoin-project/lotus/pull/6351))
|
||||||
|
- cli doc can be found [here](https://github.com/filecoin-project/lotus/blob/master/documentation/en/cli-lotus.md#lotus-filplus)
|
||||||
|
- Add miner-side MaxDealStartDelay config ([filecoin-project/lotus#6576](https://github.com/filecoin-project/lotus/pull/6576))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
- chainstore: Don't take heaviestLk with backlogged reorgCh ([filecoin-project/lotus#6526](https://github.com/filecoin-project/lotus/pull/6526))
|
||||||
|
- Backport #6041 - storagefsm: Fix batch deal packing behavior ([filecoin-project/lotus#6519](https://github.com/filecoin-project/lotus/pull/6519))
|
||||||
|
- backport: pick the correct partitions-per-post limit ([filecoin-project/lotus#6503](https://github.com/filecoin-project/lotus/pull/6503))
|
||||||
|
- failed sectors should be added into res correctly ([filecoin-project/lotus#6472](https://github.com/filecoin-project/lotus/pull/6472))
|
||||||
|
- sealing: Fix restartSectors race ([filecoin-project/lotus#6491](https://github.com/filecoin-project/lotus/pull/6491))
|
||||||
|
- Fund miners with the aggregate fee when ProveCommitting ([filecoin-project/lotus#6428](https://github.com/filecoin-project/lotus/pull/6428))
|
||||||
|
- Commit and Precommit batcher cannot share a getSectorDeadline method ([filecoin-project/lotus#6416](https://github.com/filecoin-project/lotus/pull/6416))
|
||||||
|
- Fix supported proof type manipulations for v5 actors ([filecoin-project/lotus#6366](https://github.com/filecoin-project/lotus/pull/6366))
|
||||||
|
- events: Fix handling of multiple matched events per epoch ([filecoin-project/lotus#6362](https://github.com/filecoin-project/lotus/pull/6362))
|
||||||
|
- Fix randomness fetching around null blocks ([filecoin-project/lotus#6240](https://github.com/filecoin-project/lotus/pull/6240))
|
||||||
|
|
||||||
|
### Improvements
|
||||||
|
- Appimage v1.10.0 rc3 ([filecoin-project/lotus#6492](https://github.com/filecoin-project/lotus/pull/6492))
|
||||||
|
- Expand on Drand change testing ([filecoin-project/lotus#6500](https://github.com/filecoin-project/lotus/pull/6500))
|
||||||
|
- Backport Fix logging around mineOne ([filecoin-project/lotus#6499](https://github.com/filecoin-project/lotus/pull/6499))
|
||||||
|
- mpool: Add more metrics ([filecoin-project/lotus#6453](https://github.com/filecoin-project/lotus/pull/6453))
|
||||||
|
- Merge backported PRs into v1.10 release branch ([filecoin-project/lotus#6436](https://github.com/filecoin-project/lotus/pull/6436))
|
||||||
|
- Fix tests ([filecoin-project/lotus#6371](https://github.com/filecoin-project/lotus/pull/6371))
|
||||||
|
- Extend the default deal start epoch delay ([filecoin-project/lotus#6350](https://github.com/filecoin-project/lotus/pull/6350))
|
||||||
|
- sealing: Wire up context to batchers ([filecoin-project/lotus#6497](https://github.com/filecoin-project/lotus/pull/6497))
|
||||||
|
- Improve address resolution for messages ([filecoin-project/lotus#6364](https://github.com/filecoin-project/lotus/pull/6364))
|
||||||
|
|
||||||
|
### Dependency Updates
|
||||||
|
- Proofs v8.0.2 ([filecoin-project/lotus#6524](https://github.com/filecoin-project/lotus/pull/6524))
|
||||||
|
- Update to fixed Bellperson ([filecoin-project/lotus#6480](https://github.com/filecoin-project/lotus/pull/6480))
|
||||||
|
- Update to go-praamfetch with fslocks ([filecoin-project/lotus#6473](https://github.com/filecoin-project/lotus/pull/6473))
|
||||||
|
- Update ffi with fixed multicore sdr support ([filecoin-project/lotus#6471](https://github.com/filecoin-project/lotus/pull/6471))
|
||||||
|
- github.com/filecoin-project/go-paramfetch (v0.0.2-0.20200701152213-3e0f0afdc261 -> v0.0.2-0.20210614165157-25a6c7769498)
|
||||||
|
- github.com/filecoin-project/specs-actors/v5 (v5.0.0-20210512015452-4fe3889fff57 -> v5.0.0)
|
||||||
|
- github.com/filecoin-project/go-hamt-ipld/v3 (v3.0.1 -> v3.1.0)
|
||||||
|
- github.com/ipfs/go-log/v2 (v2.1.2-0.20200626104915-0016c0b4b3e4 -> v2.1.3)
|
||||||
|
- github.com/filecoin-project/go-amt-ipld/v3 (v3.0.0 -> v3.1.0)
|
||||||
|
|
||||||
|
### Network Version v13 HyperDrive Upgrade
|
||||||
|
- Set HyperDrive upgrade epoch ([filecoin-project/lotus#6565](https://github.com/filecoin-project/lotus/pull/6565))
|
||||||
|
- version bump to lotus v1.10.0-rc6 ([filecoin-project/lotus#6529](https://github.com/filecoin-project/lotus/pull/6529))
|
||||||
|
- Upgrade epochs for calibration reset ([filecoin-project/lotus#6528](https://github.com/filecoin-project/lotus/pull/6528))
|
||||||
|
- Lotus version 1.10.0-rc5 ([filecoin-project/lotus#6504](https://github.com/filecoin-project/lotus/pull/6504))
|
||||||
|
- Merge releases into v1.10 release ([filecoin-project/lotus#6494](https://github.com/filecoin-project/lotus/pull/6494))
|
||||||
|
- update lotus to v1.10.0-rc3 ([filecoin-project/lotus#6481](https://github.com/filecoin-project/lotus/pull/6481))
|
||||||
|
- updated configuration comments for docs
|
||||||
|
- Lotus version 1.10.0-rc2 ([filecoin-project/lotus#6443](https://github.com/filecoin-project/lotus/pull/6443))
|
||||||
|
- Set ntwk v13 HyperDrive Calibration upgrade epoch ([filecoin-project/lotus#6442](https://github.com/filecoin-project/lotus/pull/6442))
|
||||||
|
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
💙Thank you to all the contributors!
|
||||||
|
|
||||||
|
| Contributor | Commits | Lines ± | Files Changed |
|
||||||
|
|--------------------|---------|-------------|---------------|
|
||||||
|
| @magik6k | 81 | +9606/-1536 | 361 |
|
||||||
|
| @arajasek | 41 | +6543/-679 | 189 |
|
||||||
|
| @ZenGround0 | 11 | +4074/-727 | 110 |
|
||||||
|
| @anorth | 10 | +2035/-1177 | 55 |
|
||||||
|
| @iand | 1 | +779/-12 | 5 |
|
||||||
|
| @frrist | 2 | +722/-6 | 6 |
|
||||||
|
| @Stebalien | 6 | +368/-24 | 15 |
|
||||||
|
| @jennijuju | 11 | +204/-111 | 19 |
|
||||||
|
| @vyzo | 6 | +155/-66 | 13 |
|
||||||
|
| @coryschwartz | 10 | +171/-27 | 14 |
|
||||||
|
| @Kubuxu | 4 | +177/-13 | 7 |
|
||||||
|
| @ribasushi | 4 | +65/-42 | 5 |
|
||||||
|
| @travisperson | 2 | +11/-11 | 4 |
|
||||||
|
| @kirk-baird | 1 | +1/-5 | 1 |
|
||||||
|
| @wangchao | 2 | +3/-2 | 2 |
|
||||||
|
|
||||||
|
|
||||||
# 1.9.0 / 2021-05-17
|
# 1.9.0 / 2021-05-17
|
||||||
|
|
||||||
|
23
Makefile
23
Makefile
@ -42,7 +42,7 @@ BUILD_DEPS+=build/.filecoin-install
|
|||||||
CLEAN+=build/.filecoin-install
|
CLEAN+=build/.filecoin-install
|
||||||
|
|
||||||
ffi-version-check:
|
ffi-version-check:
|
||||||
@[[ "$$(awk '/const Version/{print $$5}' extern/filecoin-ffi/version.go)" -eq 2 ]] || (echo "FFI version mismatch, update submodules"; exit 1)
|
@[[ "$$(awk '/const Version/{print $$5}' extern/filecoin-ffi/version.go)" -eq 3 ]] || (echo "FFI version mismatch, update submodules"; exit 1)
|
||||||
BUILD_DEPS+=ffi-version-check
|
BUILD_DEPS+=ffi-version-check
|
||||||
|
|
||||||
.PHONY: ffi-version-check
|
.PHONY: ffi-version-check
|
||||||
@ -333,17 +333,32 @@ type-gen: api-gen
|
|||||||
method-gen: api-gen
|
method-gen: api-gen
|
||||||
(cd ./lotuspond/front/src/chain && go run ./methodgen.go)
|
(cd ./lotuspond/front/src/chain && go run ./methodgen.go)
|
||||||
|
|
||||||
|
actors-gen:
|
||||||
|
go run ./chain/actors/agen
|
||||||
|
go fmt ./...
|
||||||
|
|
||||||
api-gen:
|
api-gen:
|
||||||
go run ./gen/api
|
go run ./gen/api
|
||||||
goimports -w api
|
goimports -w api
|
||||||
goimports -w api
|
goimports -w api
|
||||||
.PHONY: api-gen
|
.PHONY: api-gen
|
||||||
|
|
||||||
|
appimage: $(BUILD_DEPS)
|
||||||
|
rm -rf appimage-builder-cache || true
|
||||||
|
rm AppDir/io.filecoin.lotus.desktop || true
|
||||||
|
rm AppDir/icon.svg || true
|
||||||
|
rm Appdir/AppRun || true
|
||||||
|
mkdir -p AppDir/usr/bin
|
||||||
|
rm -rf lotus
|
||||||
|
go run github.com/GeertJohan/go.rice/rice embed-go -i ./build
|
||||||
|
go build $(GOFLAGS) -o lotus ./cmd/lotus
|
||||||
|
cp ./lotus AppDir/usr/bin/
|
||||||
|
appimage-builder
|
||||||
docsgen: docsgen-md docsgen-openrpc
|
docsgen: docsgen-md docsgen-openrpc
|
||||||
|
|
||||||
docsgen-md-bin: api-gen
|
docsgen-md-bin: api-gen actors-gen
|
||||||
go build $(GOFLAGS) -o docgen-md ./api/docgen/cmd
|
go build $(GOFLAGS) -o docgen-md ./api/docgen/cmd
|
||||||
docsgen-openrpc-bin: api-gen
|
docsgen-openrpc-bin: api-gen actors-gen
|
||||||
go build $(GOFLAGS) -o docgen-openrpc ./api/docgen-openrpc/cmd
|
go build $(GOFLAGS) -o docgen-openrpc ./api/docgen-openrpc/cmd
|
||||||
|
|
||||||
docsgen-md: docsgen-md-full docsgen-md-storage docsgen-md-worker
|
docsgen-md: docsgen-md-full docsgen-md-storage docsgen-md-worker
|
||||||
@ -367,7 +382,7 @@ docsgen-openrpc-worker: docsgen-openrpc-bin
|
|||||||
|
|
||||||
.PHONY: docsgen docsgen-md-bin docsgen-openrpc-bin
|
.PHONY: docsgen docsgen-md-bin docsgen-openrpc-bin
|
||||||
|
|
||||||
gen: type-gen method-gen docsgen api-gen
|
gen: actors-gen type-gen method-gen docsgen api-gen
|
||||||
.PHONY: gen
|
.PHONY: gen
|
||||||
|
|
||||||
print-%:
|
print-%:
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/extern/sector-storage/fsutil"
|
"github.com/filecoin-project/lotus/extern/sector-storage/fsutil"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
||||||
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MODIFYING THE API INTERFACE
|
// MODIFYING THE API INTERFACE
|
||||||
@ -91,6 +92,16 @@ type StorageMiner interface {
|
|||||||
// SectorTerminatePending returns a list of pending sector terminations to be sent in the next batch message
|
// SectorTerminatePending returns a list of pending sector terminations to be sent in the next batch message
|
||||||
SectorTerminatePending(ctx context.Context) ([]abi.SectorID, error) //perm:admin
|
SectorTerminatePending(ctx context.Context) ([]abi.SectorID, error) //perm:admin
|
||||||
SectorMarkForUpgrade(ctx context.Context, id abi.SectorNumber) error //perm:admin
|
SectorMarkForUpgrade(ctx context.Context, id abi.SectorNumber) error //perm:admin
|
||||||
|
// SectorPreCommitFlush immediately sends a PreCommit message with sectors batched for PreCommit.
|
||||||
|
// Returns null if message wasn't sent
|
||||||
|
SectorPreCommitFlush(ctx context.Context) ([]sealiface.PreCommitBatchRes, error) //perm:admin
|
||||||
|
// SectorPreCommitPending returns a list of pending PreCommit sectors to be sent in the next batch message
|
||||||
|
SectorPreCommitPending(ctx context.Context) ([]abi.SectorID, error) //perm:admin
|
||||||
|
// SectorCommitFlush immediately sends a Commit message with sectors aggregated for Commit.
|
||||||
|
// Returns null if message wasn't sent
|
||||||
|
SectorCommitFlush(ctx context.Context) ([]sealiface.CommitBatchRes, error) //perm:admin
|
||||||
|
// SectorCommitPending returns a list of pending Commit sectors to be sent in the next aggregate message
|
||||||
|
SectorCommitPending(ctx context.Context) ([]abi.SectorID, error) //perm:admin
|
||||||
|
|
||||||
// WorkerConnect tells the node to connect to workers RPC
|
// WorkerConnect tells the node to connect to workers RPC
|
||||||
WorkerConnect(context.Context, string) error //perm:admin retry:true
|
WorkerConnect(context.Context, string) error //perm:admin retry:true
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
||||||
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
||||||
marketevents "github.com/filecoin-project/lotus/markets/loggers"
|
marketevents "github.com/filecoin-project/lotus/markets/loggers"
|
||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
"github.com/filecoin-project/specs-storage/storage"
|
"github.com/filecoin-project/specs-storage/storage"
|
||||||
@ -649,12 +650,20 @@ type StorageMinerStruct struct {
|
|||||||
|
|
||||||
SealingSchedDiag func(p0 context.Context, p1 bool) (interface{}, error) `perm:"admin"`
|
SealingSchedDiag func(p0 context.Context, p1 bool) (interface{}, error) `perm:"admin"`
|
||||||
|
|
||||||
|
SectorCommitFlush func(p0 context.Context) ([]sealiface.CommitBatchRes, error) `perm:"admin"`
|
||||||
|
|
||||||
|
SectorCommitPending func(p0 context.Context) ([]abi.SectorID, error) `perm:"admin"`
|
||||||
|
|
||||||
SectorGetExpectedSealDuration func(p0 context.Context) (time.Duration, error) `perm:"read"`
|
SectorGetExpectedSealDuration func(p0 context.Context) (time.Duration, error) `perm:"read"`
|
||||||
|
|
||||||
SectorGetSealDelay func(p0 context.Context) (time.Duration, error) `perm:"read"`
|
SectorGetSealDelay func(p0 context.Context) (time.Duration, error) `perm:"read"`
|
||||||
|
|
||||||
SectorMarkForUpgrade func(p0 context.Context, p1 abi.SectorNumber) error `perm:"admin"`
|
SectorMarkForUpgrade func(p0 context.Context, p1 abi.SectorNumber) error `perm:"admin"`
|
||||||
|
|
||||||
|
SectorPreCommitFlush func(p0 context.Context) ([]sealiface.PreCommitBatchRes, error) `perm:"admin"`
|
||||||
|
|
||||||
|
SectorPreCommitPending func(p0 context.Context) ([]abi.SectorID, error) `perm:"admin"`
|
||||||
|
|
||||||
SectorRemove func(p0 context.Context, p1 abi.SectorNumber) error `perm:"admin"`
|
SectorRemove func(p0 context.Context, p1 abi.SectorNumber) error `perm:"admin"`
|
||||||
|
|
||||||
SectorSetExpectedSealDuration func(p0 context.Context, p1 time.Duration) error `perm:"write"`
|
SectorSetExpectedSealDuration func(p0 context.Context, p1 time.Duration) error `perm:"write"`
|
||||||
@ -3067,6 +3076,22 @@ func (s *StorageMinerStub) SealingSchedDiag(p0 context.Context, p1 bool) (interf
|
|||||||
return nil, xerrors.New("method not supported")
|
return nil, xerrors.New("method not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StorageMinerStruct) SectorCommitFlush(p0 context.Context) ([]sealiface.CommitBatchRes, error) {
|
||||||
|
return s.Internal.SectorCommitFlush(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StorageMinerStub) SectorCommitFlush(p0 context.Context) ([]sealiface.CommitBatchRes, error) {
|
||||||
|
return *new([]sealiface.CommitBatchRes), xerrors.New("method not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StorageMinerStruct) SectorCommitPending(p0 context.Context) ([]abi.SectorID, error) {
|
||||||
|
return s.Internal.SectorCommitPending(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StorageMinerStub) SectorCommitPending(p0 context.Context) ([]abi.SectorID, error) {
|
||||||
|
return *new([]abi.SectorID), xerrors.New("method not supported")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StorageMinerStruct) SectorGetExpectedSealDuration(p0 context.Context) (time.Duration, error) {
|
func (s *StorageMinerStruct) SectorGetExpectedSealDuration(p0 context.Context) (time.Duration, error) {
|
||||||
return s.Internal.SectorGetExpectedSealDuration(p0)
|
return s.Internal.SectorGetExpectedSealDuration(p0)
|
||||||
}
|
}
|
||||||
@ -3091,6 +3116,22 @@ func (s *StorageMinerStub) SectorMarkForUpgrade(p0 context.Context, p1 abi.Secto
|
|||||||
return xerrors.New("method not supported")
|
return xerrors.New("method not supported")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StorageMinerStruct) SectorPreCommitFlush(p0 context.Context) ([]sealiface.PreCommitBatchRes, error) {
|
||||||
|
return s.Internal.SectorPreCommitFlush(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StorageMinerStub) SectorPreCommitFlush(p0 context.Context) ([]sealiface.PreCommitBatchRes, error) {
|
||||||
|
return *new([]sealiface.PreCommitBatchRes), xerrors.New("method not supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StorageMinerStruct) SectorPreCommitPending(p0 context.Context) ([]abi.SectorID, error) {
|
||||||
|
return s.Internal.SectorPreCommitPending(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StorageMinerStub) SectorPreCommitPending(p0 context.Context) ([]abi.SectorID, error) {
|
||||||
|
return *new([]abi.SectorID), xerrors.New("method not supported")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *StorageMinerStruct) SectorRemove(p0 context.Context, p1 abi.SectorNumber) error {
|
func (s *StorageMinerStruct) SectorRemove(p0 context.Context, p1 abi.SectorNumber) error {
|
||||||
return s.Internal.SectorRemove(p0, p1)
|
return s.Internal.SectorRemove(p0, p1)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func TestCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|||||||
|
|
||||||
func testCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration, upgradeHeight abi.ChainEpoch) {
|
func testCCUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration, upgradeHeight abi.ChainEpoch) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV4At(upgradeHeight)}, OneMiner)
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(upgradeHeight)}, OneMiner)
|
||||||
client := n[0].FullNode.(*impl.FullNodeAPI)
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
miner := sn[0]
|
miner := sn[0]
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ func TestDeadlineToggling(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV4At(upgradeH)}, OneMiner)
|
n, sn := b(t, []FullNodeOpts{FullNodeWithV4ActorsAt(upgradeH)}, OneMiner)
|
||||||
|
|
||||||
client := n[0].FullNode.(*impl.FullNodeAPI)
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
minerA := sn[0]
|
minerA := sn[0]
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"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/api"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/market"
|
||||||
@ -51,7 +53,7 @@ func TestDoubleDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, sta
|
|||||||
}
|
}
|
||||||
|
|
||||||
func MakeDeal(t *testing.T, ctx context.Context, rseed int, client api.FullNode, miner TestStorageNode, carExport, fastRet bool, startEpoch abi.ChainEpoch) {
|
func MakeDeal(t *testing.T, ctx context.Context, rseed int, client api.FullNode, miner TestStorageNode, carExport, fastRet bool, startEpoch abi.ChainEpoch) {
|
||||||
res, data, err := CreateClientFile(ctx, client, rseed)
|
res, data, err := CreateClientFile(ctx, client, rseed, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -63,7 +65,7 @@ func MakeDeal(t *testing.T, ctx context.Context, rseed int, client api.FullNode,
|
|||||||
|
|
||||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
waitDealSealed(t, ctx, miner, client, deal, false)
|
waitDealSealed(t, ctx, miner, client, deal, false, false, nil)
|
||||||
|
|
||||||
// Retrieval
|
// Retrieval
|
||||||
info, err := client.ClientGetDealInfo(ctx, *deal)
|
info, err := client.ClientGetDealInfo(ctx, *deal)
|
||||||
@ -72,8 +74,11 @@ func MakeDeal(t *testing.T, ctx context.Context, rseed int, client api.FullNode,
|
|||||||
testRetrieval(t, ctx, client, fcid, &info.PieceCID, carExport, data)
|
testRetrieval(t, ctx, client, fcid, &info.PieceCID, carExport, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateClientFile(ctx context.Context, client api.FullNode, rseed int) (*api.ImportRes, []byte, error) {
|
func CreateClientFile(ctx context.Context, client api.FullNode, rseed, size int) (*api.ImportRes, []byte, error) {
|
||||||
data := make([]byte, 1600)
|
if size == 0 {
|
||||||
|
size = 1600
|
||||||
|
}
|
||||||
|
data := make([]byte, size)
|
||||||
rand.New(rand.NewSource(int64(rseed))).Read(data)
|
rand.New(rand.NewSource(int64(rseed))).Read(data)
|
||||||
|
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "test-make-deal-")
|
dir, err := ioutil.TempDir(os.TempDir(), "test-make-deal-")
|
||||||
@ -119,7 +124,7 @@ func TestPublishDealsBatching(t *testing.T, b APIBuilder, blocktime time.Duratio
|
|||||||
|
|
||||||
// Starts a deal and waits until it's published
|
// Starts a deal and waits until it's published
|
||||||
runDealTillPublish := func(rseed int) {
|
runDealTillPublish := func(rseed int) {
|
||||||
res, _, err := CreateClientFile(s.ctx, s.client, rseed)
|
res, _, err := CreateClientFile(s.ctx, s.client, rseed, 0)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
upds, err := client.ClientGetDealUpdates(s.ctx)
|
upds, err := client.ClientGetDealUpdates(s.ctx)
|
||||||
@ -186,8 +191,10 @@ func TestPublishDealsBatching(t *testing.T, b APIBuilder, blocktime time.Duratio
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBatchDealInput(t *testing.T, b APIBuilder, blocktime time.Duration, startEpoch abi.ChainEpoch) {
|
func TestBatchDealInput(t *testing.T, b APIBuilder, blocktime time.Duration, startEpoch abi.ChainEpoch) {
|
||||||
|
run := func(piece, deals, expectSectors int) func(t *testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
publishPeriod := 10 * time.Second
|
publishPeriod := 10 * time.Second
|
||||||
maxDealsPerMsg := uint64(4)
|
maxDealsPerMsg := uint64(deals)
|
||||||
|
|
||||||
// Set max deals per publish deals message to maxDealsPerMsg
|
// Set max deals per publish deals message to maxDealsPerMsg
|
||||||
minerDef := []StorageMiner{{
|
minerDef := []StorageMiner{{
|
||||||
@ -202,10 +209,11 @@ func TestBatchDealInput(t *testing.T, b APIBuilder, blocktime time.Duration, sta
|
|||||||
node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) {
|
node.Override(new(dtypes.GetSealingConfigFunc), func() (dtypes.GetSealingConfigFunc, error) {
|
||||||
return func() (sealiface.Config, error) {
|
return func() (sealiface.Config, error) {
|
||||||
return sealiface.Config{
|
return sealiface.Config{
|
||||||
MaxWaitDealsSectors: 1,
|
MaxWaitDealsSectors: 2,
|
||||||
MaxSealingSectors: 1,
|
MaxSealingSectors: 1,
|
||||||
MaxSealingSectorsForDeals: 2,
|
MaxSealingSectorsForDeals: 3,
|
||||||
AlwaysKeepUnsealedCopy: true,
|
AlwaysKeepUnsealedCopy: true,
|
||||||
|
WaitDealsDelay: time.Hour,
|
||||||
}, nil
|
}, nil
|
||||||
}, nil
|
}, nil
|
||||||
}),
|
}),
|
||||||
@ -220,18 +228,43 @@ func TestBatchDealInput(t *testing.T, b APIBuilder, blocktime time.Duration, sta
|
|||||||
s := connectAndStartMining(t, b, blocktime, client, miner)
|
s := connectAndStartMining(t, b, blocktime, client, miner)
|
||||||
defer s.blockMiner.Stop()
|
defer s.blockMiner.Stop()
|
||||||
|
|
||||||
|
err := miner.MarketSetAsk(s.ctx, big.Zero(), big.Zero(), 200, 128, 32<<30)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
checkNoPadding := func() {
|
||||||
|
sl, err := sn[0].SectorsList(s.ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
sort.Slice(sl, func(i, j int) bool {
|
||||||
|
return sl[i] < sl[j]
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, snum := range sl {
|
||||||
|
si, err := sn[0].SectorsStatus(s.ctx, snum, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// fmt.Printf("S %d: %+v %s\n", snum, si.Deals, si.State)
|
||||||
|
|
||||||
|
for _, deal := range si.Deals {
|
||||||
|
if deal == 0 {
|
||||||
|
fmt.Printf("sector %d had a padding piece!\n", snum)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Starts a deal and waits until it's published
|
// Starts a deal and waits until it's published
|
||||||
runDealTillSeal := func(rseed int) {
|
runDealTillSeal := func(rseed int) {
|
||||||
res, _, err := CreateClientFile(s.ctx, s.client, rseed)
|
res, _, err := CreateClientFile(s.ctx, s.client, rseed, piece)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dc := startDeal(t, s.ctx, s.miner, s.client, res.Root, false, startEpoch)
|
dc := startDeal(t, s.ctx, s.miner, s.client, res.Root, false, startEpoch)
|
||||||
waitDealSealed(t, s.ctx, s.miner, s.client, dc, false)
|
waitDealSealed(t, s.ctx, s.miner, s.client, dc, false, true, checkNoPadding)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run maxDealsPerMsg+1 deals in parallel
|
// Run maxDealsPerMsg deals in parallel
|
||||||
done := make(chan struct{}, maxDealsPerMsg+1)
|
done := make(chan struct{}, maxDealsPerMsg)
|
||||||
for rseed := 1; rseed <= int(maxDealsPerMsg+1); rseed++ {
|
for rseed := 0; rseed < int(maxDealsPerMsg); rseed++ {
|
||||||
rseed := rseed
|
rseed := rseed
|
||||||
go func() {
|
go func() {
|
||||||
runDealTillSeal(rseed)
|
runDealTillSeal(rseed)
|
||||||
@ -244,10 +277,23 @@ func TestBatchDealInput(t *testing.T, b APIBuilder, blocktime time.Duration, sta
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkNoPadding()
|
||||||
|
|
||||||
sl, err := sn[0].SectorsList(s.ctx)
|
sl, err := sn[0].SectorsList(s.ctx)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.GreaterOrEqual(t, len(sl), 4)
|
require.Equal(t, len(sl), expectSectors)
|
||||||
require.LessOrEqual(t, len(sl), 5)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("4-p1600B", run(1600, 4, 4))
|
||||||
|
t.Run("4-p513B", run(513, 4, 2))
|
||||||
|
if !testing.Short() {
|
||||||
|
t.Run("32-p257B", run(257, 32, 8))
|
||||||
|
t.Run("32-p10B", run(10, 32, 2))
|
||||||
|
|
||||||
|
// fixme: this appears to break data-transfer / markets in some really creative ways
|
||||||
|
//t.Run("128-p10B", run(10, 128, 8))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFastRetrievalDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, startEpoch abi.ChainEpoch) {
|
func TestFastRetrievalDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration, startEpoch abi.ChainEpoch) {
|
||||||
@ -303,12 +349,12 @@ func TestSecondDealRetrieval(t *testing.T, b APIBuilder, blocktime time.Duration
|
|||||||
|
|
||||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
waitDealSealed(t, s.ctx, s.miner, s.client, deal1, true)
|
waitDealSealed(t, s.ctx, s.miner, s.client, deal1, true, false, nil)
|
||||||
|
|
||||||
deal2 := startDeal(t, s.ctx, s.miner, s.client, fcid2, true, 0)
|
deal2 := startDeal(t, s.ctx, s.miner, s.client, fcid2, true, 0)
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
waitDealSealed(t, s.ctx, s.miner, s.client, deal2, false)
|
waitDealSealed(t, s.ctx, s.miner, s.client, deal2, false, false, nil)
|
||||||
|
|
||||||
// Retrieval
|
// Retrieval
|
||||||
info, err := s.client.ClientGetDealInfo(s.ctx, *deal2)
|
info, err := s.client.ClientGetDealInfo(s.ctx, *deal2)
|
||||||
@ -364,7 +410,7 @@ func startDeal(t *testing.T, ctx context.Context, miner TestStorageNode, client
|
|||||||
return deal
|
return deal
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitDealSealed(t *testing.T, ctx context.Context, miner TestStorageNode, client api.FullNode, deal *cid.Cid, noseal bool) {
|
func waitDealSealed(t *testing.T, ctx context.Context, miner TestStorageNode, client api.FullNode, deal *cid.Cid, noseal, noSealStart bool, cb func()) {
|
||||||
loop:
|
loop:
|
||||||
for {
|
for {
|
||||||
di, err := client.ClientGetDealInfo(ctx, *deal)
|
di, err := client.ClientGetDealInfo(ctx, *deal)
|
||||||
@ -376,7 +422,9 @@ loop:
|
|||||||
if noseal {
|
if noseal {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if !noSealStart {
|
||||||
startSealingWaiting(t, ctx, miner)
|
startSealingWaiting(t, ctx, miner)
|
||||||
|
}
|
||||||
case storagemarket.StorageDealProposalRejected:
|
case storagemarket.StorageDealProposalRejected:
|
||||||
t.Fatal("deal rejected")
|
t.Fatal("deal rejected")
|
||||||
case storagemarket.StorageDealFailing:
|
case storagemarket.StorageDealFailing:
|
||||||
@ -387,8 +435,25 @@ loop:
|
|||||||
fmt.Println("COMPLETE", di)
|
fmt.Println("COMPLETE", di)
|
||||||
break loop
|
break loop
|
||||||
}
|
}
|
||||||
fmt.Println("Deal state: ", storagemarket.DealStates[di.State])
|
|
||||||
|
mds, err := miner.MarketListIncompleteDeals(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var minerState storagemarket.StorageDealStatus
|
||||||
|
for _, md := range mds {
|
||||||
|
if md.DealID == di.DealID {
|
||||||
|
minerState = md.State
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Deal %d state: client:%s provider:%s\n", di.DealID, storagemarket.DealStates[di.State], storagemarket.DealStates[minerState])
|
||||||
time.Sleep(time.Second / 2)
|
time.Sleep(time.Second / 2)
|
||||||
|
if cb != nil {
|
||||||
|
cb()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,11 +495,13 @@ func startSealingWaiting(t *testing.T, ctx context.Context, miner TestStorageNod
|
|||||||
si, err := miner.SectorsStatus(ctx, snum, false)
|
si, err := miner.SectorsStatus(ctx, snum, false)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Logf("Sector state: %s", si.State)
|
t.Logf("Sector %d state: %s", snum, si.State)
|
||||||
if si.State == api.SectorState(sealing.WaitDeals) {
|
if si.State == api.SectorState(sealing.WaitDeals) {
|
||||||
require.NoError(t, miner.SectorStartSealing(ctx, snum))
|
require.NoError(t, miner.SectorStartSealing(ctx, snum))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flushSealingBatches(t, ctx, miner)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testRetrieval(t *testing.T, ctx context.Context, client api.FullNode, fcid cid.Cid, piece *cid.Cid, carExport bool, data []byte) {
|
func testRetrieval(t *testing.T, ctx context.Context, client api.FullNode, fcid cid.Cid, piece *cid.Cid, carExport bool, data []byte) {
|
||||||
|
@ -194,7 +194,7 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo
|
|||||||
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
// TODO: this sleep is only necessary because deals don't immediately get logged in the dealstore, we should fix this
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
waitDealSealed(t, ctx, provider, client, deal, false)
|
waitDealSealed(t, ctx, provider, client, deal, false, false, nil)
|
||||||
|
|
||||||
<-minedTwo
|
<-minedTwo
|
||||||
|
|
||||||
@ -206,7 +206,7 @@ func TestDealMining(t *testing.T, b APIBuilder, blocktime time.Duration, carExpo
|
|||||||
func (ts *testSuite) testNonGenesisMiner(t *testing.T) {
|
func (ts *testSuite) testNonGenesisMiner(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
n, sn := ts.makeNodes(t, []FullNodeOpts{
|
n, sn := ts.makeNodes(t, []FullNodeOpts{
|
||||||
FullNodeWithActorsV4At(-1),
|
FullNodeWithLatestActorsAt(-1),
|
||||||
}, []StorageMiner{
|
}, []StorageMiner{
|
||||||
{Full: 0, Preseal: PresealGenesis},
|
{Full: 0, Preseal: PresealGenesis},
|
||||||
})
|
})
|
||||||
|
389
api/test/pledge.go
Normal file
389
api/test/pledge.go
Normal file
@ -0,0 +1,389 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||||
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
||||||
|
bminer "github.com/filecoin-project/lotus/miner"
|
||||||
|
"github.com/filecoin-project/lotus/node"
|
||||||
|
"github.com/filecoin-project/lotus/node/impl"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSDRUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
n, sn := b(t, []FullNodeOpts{FullNodeWithSDRAt(500, 1000)}, OneMiner)
|
||||||
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
|
miner := sn[0]
|
||||||
|
|
||||||
|
addrinfo, err := client.NetAddrsListen(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
|
pledge := make(chan struct{})
|
||||||
|
mine := int64(1)
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
round := 0
|
||||||
|
for atomic.LoadInt64(&mine) != 0 {
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
||||||
|
|
||||||
|
}}); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3 sealing rounds: before, during after.
|
||||||
|
if round >= 3 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
head, err := client.ChainHead(ctx)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
// rounds happen every 100 blocks, with a 50 block offset.
|
||||||
|
if head.Height() >= abi.ChainEpoch(round*500+50) {
|
||||||
|
round++
|
||||||
|
pledge <- struct{}{}
|
||||||
|
|
||||||
|
ver, err := client.StateNetworkVersion(ctx, head.Key())
|
||||||
|
assert.NoError(t, err)
|
||||||
|
switch round {
|
||||||
|
case 1:
|
||||||
|
assert.Equal(t, network.Version6, ver)
|
||||||
|
case 2:
|
||||||
|
assert.Equal(t, network.Version7, ver)
|
||||||
|
case 3:
|
||||||
|
assert.Equal(t, network.Version8, ver)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// before.
|
||||||
|
pledgeSectors(t, ctx, miner, 9, 0, pledge)
|
||||||
|
|
||||||
|
s, err := miner.SectorsList(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
sort.Slice(s, func(i, j int) bool {
|
||||||
|
return s[i] < s[j]
|
||||||
|
})
|
||||||
|
|
||||||
|
for i, id := range s {
|
||||||
|
info, err := miner.SectorsStatus(ctx, id, true)
|
||||||
|
require.NoError(t, err)
|
||||||
|
expectProof := abi.RegisteredSealProof_StackedDrg2KiBV1
|
||||||
|
if i >= 3 {
|
||||||
|
// after
|
||||||
|
expectProof = abi.RegisteredSealProof_StackedDrg2KiBV1_1
|
||||||
|
}
|
||||||
|
assert.Equal(t, expectProof, info.SealProof, "sector %d, id %d", i, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic.StoreInt64(&mine, 0)
|
||||||
|
<-done
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPledgeBatching(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(-1)}, OneMiner)
|
||||||
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
|
miner := sn[0]
|
||||||
|
|
||||||
|
addrinfo, err := client.NetAddrsListen(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
|
mine := int64(1)
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
for atomic.LoadInt64(&mine) != 0 {
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
||||||
|
|
||||||
|
}}); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
h, err := client.ChainHead(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if h.Height() > 10 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toCheck := startPledge(t, ctx, miner, nSectors, 0, nil)
|
||||||
|
|
||||||
|
for len(toCheck) > 0 {
|
||||||
|
states := map[api.SectorState]int{}
|
||||||
|
|
||||||
|
for n := range toCheck {
|
||||||
|
st, err := miner.SectorsStatus(ctx, n, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
states[st.State]++
|
||||||
|
if st.State == api.SectorState(sealing.Proving) {
|
||||||
|
delete(toCheck, n)
|
||||||
|
}
|
||||||
|
if strings.Contains(string(st.State), "Fail") {
|
||||||
|
t.Fatal("sector in a failed state", st.State)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if states[api.SectorState(sealing.SubmitPreCommitBatch)] == nSectors ||
|
||||||
|
(states[api.SectorState(sealing.SubmitPreCommitBatch)] > 0 && states[api.SectorState(sealing.PreCommit1)] == 0 && states[api.SectorState(sealing.PreCommit2)] == 0) {
|
||||||
|
pcb, err := miner.SectorPreCommitFlush(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if pcb != nil {
|
||||||
|
fmt.Printf("PRECOMMIT BATCH: %+v\n", pcb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if states[api.SectorState(sealing.SubmitCommitAggregate)] == nSectors ||
|
||||||
|
(states[api.SectorState(sealing.SubmitCommitAggregate)] > 0 && states[api.SectorState(sealing.WaitSeed)] == 0 && states[api.SectorState(sealing.Committing)] == 0) {
|
||||||
|
cb, err := miner.SectorCommitFlush(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if cb != nil {
|
||||||
|
fmt.Printf("COMMIT BATCH: %+v\n", cb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(100 * time.Millisecond)
|
||||||
|
fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states)
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic.StoreInt64(&mine, 0)
|
||||||
|
<-done
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPledgeBeforeNv13(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
n, sn := b(t, []FullNodeOpts{
|
||||||
|
{
|
||||||
|
Opts: func(nodes []TestNode) node.Option {
|
||||||
|
return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{
|
||||||
|
Network: network.Version9,
|
||||||
|
Height: 1,
|
||||||
|
Migration: stmgr.UpgradeActorsV2,
|
||||||
|
}, {
|
||||||
|
Network: network.Version10,
|
||||||
|
Height: 2,
|
||||||
|
Migration: stmgr.UpgradeActorsV3,
|
||||||
|
}, {
|
||||||
|
Network: network.Version12,
|
||||||
|
Height: 3,
|
||||||
|
Migration: stmgr.UpgradeActorsV4,
|
||||||
|
}, {
|
||||||
|
Network: network.Version13,
|
||||||
|
Height: 1000000000,
|
||||||
|
Migration: stmgr.UpgradeActorsV5,
|
||||||
|
}})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, OneMiner)
|
||||||
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
|
miner := sn[0]
|
||||||
|
|
||||||
|
addrinfo, err := client.NetAddrsListen(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
|
mine := int64(1)
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
for atomic.LoadInt64(&mine) != 0 {
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
||||||
|
|
||||||
|
}}); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for {
|
||||||
|
h, err := client.ChainHead(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if h.Height() > 10 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toCheck := startPledge(t, ctx, miner, nSectors, 0, nil)
|
||||||
|
|
||||||
|
for len(toCheck) > 0 {
|
||||||
|
states := map[api.SectorState]int{}
|
||||||
|
|
||||||
|
for n := range toCheck {
|
||||||
|
st, err := miner.SectorsStatus(ctx, n, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
states[st.State]++
|
||||||
|
if st.State == api.SectorState(sealing.Proving) {
|
||||||
|
delete(toCheck, n)
|
||||||
|
}
|
||||||
|
if strings.Contains(string(st.State), "Fail") {
|
||||||
|
t.Fatal("sector in a failed state", st.State)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(100 * time.Millisecond)
|
||||||
|
fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states)
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic.StoreInt64(&mine, 0)
|
||||||
|
<-done
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
n, sn := b(t, OneFull, OneMiner)
|
||||||
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
|
miner := sn[0]
|
||||||
|
|
||||||
|
addrinfo, err := client.NetAddrsListen(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
|
mine := int64(1)
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
for atomic.LoadInt64(&mine) != 0 {
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
||||||
|
|
||||||
|
}}); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
pledgeSectors(t, ctx, miner, nSectors, 0, nil)
|
||||||
|
|
||||||
|
atomic.StoreInt64(&mine, 0)
|
||||||
|
<-done
|
||||||
|
}
|
||||||
|
|
||||||
|
func flushSealingBatches(t *testing.T, ctx context.Context, miner TestStorageNode) {
|
||||||
|
pcb, err := miner.SectorPreCommitFlush(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if pcb != nil {
|
||||||
|
fmt.Printf("PRECOMMIT BATCH: %+v\n", pcb)
|
||||||
|
}
|
||||||
|
|
||||||
|
cb, err := miner.SectorCommitFlush(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if cb != nil {
|
||||||
|
fmt.Printf("COMMIT BATCH: %+v\n", cb)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func startPledge(t *testing.T, ctx context.Context, miner TestStorageNode, n, existing int, blockNotif <-chan struct{}) map[abi.SectorNumber]struct{} {
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
if i%3 == 0 && blockNotif != nil {
|
||||||
|
<-blockNotif
|
||||||
|
log.Errorf("WAIT")
|
||||||
|
}
|
||||||
|
log.Errorf("PLEDGING %d", i)
|
||||||
|
_, err := miner.PledgeSector(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
s, err := miner.SectorsList(ctx) // Note - the test builder doesn't import genesis sectors into FSM
|
||||||
|
require.NoError(t, err)
|
||||||
|
fmt.Printf("Sectors: %d\n", len(s))
|
||||||
|
if len(s) >= n+existing {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("All sectors is fsm\n")
|
||||||
|
|
||||||
|
s, err := miner.SectorsList(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
toCheck := map[abi.SectorNumber]struct{}{}
|
||||||
|
for _, number := range s {
|
||||||
|
toCheck[number] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return toCheck
|
||||||
|
}
|
||||||
|
|
||||||
|
func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n, existing int, blockNotif <-chan struct{}) {
|
||||||
|
toCheck := startPledge(t, ctx, miner, n, existing, blockNotif)
|
||||||
|
|
||||||
|
for len(toCheck) > 0 {
|
||||||
|
flushSealingBatches(t, ctx, miner)
|
||||||
|
|
||||||
|
states := map[api.SectorState]int{}
|
||||||
|
for n := range toCheck {
|
||||||
|
st, err := miner.SectorsStatus(ctx, n, false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
states[st.State]++
|
||||||
|
if st.State == api.SectorState(sealing.Proving) {
|
||||||
|
delete(toCheck, n)
|
||||||
|
}
|
||||||
|
if strings.Contains(string(st.State), "Fail") {
|
||||||
|
t.Fatal("sector in a failed state", st.State)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(100 * time.Millisecond)
|
||||||
|
fmt.Printf("WaitSeal: %d %+v\n", len(toCheck), states)
|
||||||
|
}
|
||||||
|
}
|
@ -121,9 +121,10 @@ var OneMiner = []StorageMiner{{Full: 0, Preseal: PresealGenesis}}
|
|||||||
var OneFull = DefaultFullOpts(1)
|
var OneFull = DefaultFullOpts(1)
|
||||||
var TwoFull = DefaultFullOpts(2)
|
var TwoFull = DefaultFullOpts(2)
|
||||||
|
|
||||||
var FullNodeWithActorsV4At = func(upgradeHeight abi.ChainEpoch) FullNodeOpts {
|
var FullNodeWithLatestActorsAt = func(upgradeHeight abi.ChainEpoch) FullNodeOpts {
|
||||||
if upgradeHeight == -1 {
|
if upgradeHeight == -1 {
|
||||||
upgradeHeight = 3
|
// Attention: Update this when introducing new actor versions or your tests will be sad
|
||||||
|
upgradeHeight = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
return FullNodeOpts{
|
return FullNodeOpts{
|
||||||
@ -139,8 +140,12 @@ var FullNodeWithActorsV4At = func(upgradeHeight abi.ChainEpoch) FullNodeOpts {
|
|||||||
Migration: stmgr.UpgradeActorsV3,
|
Migration: stmgr.UpgradeActorsV3,
|
||||||
}, {
|
}, {
|
||||||
Network: network.Version12,
|
Network: network.Version12,
|
||||||
Height: upgradeHeight,
|
Height: 3,
|
||||||
Migration: stmgr.UpgradeActorsV4,
|
Migration: stmgr.UpgradeActorsV4,
|
||||||
|
}, {
|
||||||
|
Network: network.Version13,
|
||||||
|
Height: upgradeHeight,
|
||||||
|
Migration: stmgr.UpgradeActorsV5,
|
||||||
}})
|
}})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -165,6 +170,31 @@ var FullNodeWithSDRAt = func(calico, persian abi.ChainEpoch) FullNodeOpts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var FullNodeWithV4ActorsAt = func(upgradeHeight abi.ChainEpoch) FullNodeOpts {
|
||||||
|
if upgradeHeight == -1 {
|
||||||
|
upgradeHeight = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
return FullNodeOpts{
|
||||||
|
Opts: func(nodes []TestNode) node.Option {
|
||||||
|
return node.Override(new(stmgr.UpgradeSchedule), stmgr.UpgradeSchedule{{
|
||||||
|
// prepare for upgrade.
|
||||||
|
Network: network.Version9,
|
||||||
|
Height: 1,
|
||||||
|
Migration: stmgr.UpgradeActorsV2,
|
||||||
|
}, {
|
||||||
|
Network: network.Version10,
|
||||||
|
Height: 2,
|
||||||
|
Migration: stmgr.UpgradeActorsV3,
|
||||||
|
}, {
|
||||||
|
Network: network.Version12,
|
||||||
|
Height: upgradeHeight,
|
||||||
|
Migration: stmgr.UpgradeActorsV4,
|
||||||
|
}})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var MineNext = miner.MineReq{
|
var MineNext = miner.MineReq{
|
||||||
InjectNulls: 0,
|
InjectNulls: 0,
|
||||||
Done: func(bool, abi.ChainEpoch, error) {},
|
Done: func(bool, abi.ChainEpoch, error) {},
|
||||||
|
@ -3,14 +3,11 @@ package test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
|
||||||
"sync/atomic"
|
|
||||||
|
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
@ -18,7 +15,6 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
"github.com/filecoin-project/go-state-types/dline"
|
"github.com/filecoin-project/go-state-types/dline"
|
||||||
"github.com/filecoin-project/go-state-types/network"
|
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
"github.com/filecoin-project/lotus/extern/sector-storage/mock"
|
||||||
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
||||||
proof3 "github.com/filecoin-project/specs-actors/v3/actors/runtime/proof"
|
proof3 "github.com/filecoin-project/specs-actors/v3/actors/runtime/proof"
|
||||||
@ -29,181 +25,9 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
minerActor "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
minerActor "github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
bminer "github.com/filecoin-project/lotus/miner"
|
|
||||||
"github.com/filecoin-project/lotus/node/impl"
|
"github.com/filecoin-project/lotus/node/impl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSDRUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
n, sn := b(t, []FullNodeOpts{FullNodeWithSDRAt(500, 1000)}, OneMiner)
|
|
||||||
client := n[0].FullNode.(*impl.FullNodeAPI)
|
|
||||||
miner := sn[0]
|
|
||||||
|
|
||||||
addrinfo, err := client.NetAddrsListen(ctx)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
build.Clock.Sleep(time.Second)
|
|
||||||
|
|
||||||
pledge := make(chan struct{})
|
|
||||||
mine := int64(1)
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
defer close(done)
|
|
||||||
round := 0
|
|
||||||
for atomic.LoadInt64(&mine) != 0 {
|
|
||||||
build.Clock.Sleep(blocktime)
|
|
||||||
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
|
||||||
|
|
||||||
}}); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3 sealing rounds: before, during after.
|
|
||||||
if round >= 3 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
head, err := client.ChainHead(ctx)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// rounds happen every 100 blocks, with a 50 block offset.
|
|
||||||
if head.Height() >= abi.ChainEpoch(round*500+50) {
|
|
||||||
round++
|
|
||||||
pledge <- struct{}{}
|
|
||||||
|
|
||||||
ver, err := client.StateNetworkVersion(ctx, head.Key())
|
|
||||||
assert.NoError(t, err)
|
|
||||||
switch round {
|
|
||||||
case 1:
|
|
||||||
assert.Equal(t, network.Version6, ver)
|
|
||||||
case 2:
|
|
||||||
assert.Equal(t, network.Version7, ver)
|
|
||||||
case 3:
|
|
||||||
assert.Equal(t, network.Version8, ver)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// before.
|
|
||||||
pledgeSectors(t, ctx, miner, 9, 0, pledge)
|
|
||||||
|
|
||||||
s, err := miner.SectorsList(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
sort.Slice(s, func(i, j int) bool {
|
|
||||||
return s[i] < s[j]
|
|
||||||
})
|
|
||||||
|
|
||||||
for i, id := range s {
|
|
||||||
info, err := miner.SectorsStatus(ctx, id, true)
|
|
||||||
require.NoError(t, err)
|
|
||||||
expectProof := abi.RegisteredSealProof_StackedDrg2KiBV1
|
|
||||||
if i >= 3 {
|
|
||||||
// after
|
|
||||||
expectProof = abi.RegisteredSealProof_StackedDrg2KiBV1_1
|
|
||||||
}
|
|
||||||
assert.Equal(t, expectProof, info.SealProof, "sector %d, id %d", i, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
atomic.StoreInt64(&mine, 0)
|
|
||||||
<-done
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
n, sn := b(t, OneFull, OneMiner)
|
|
||||||
client := n[0].FullNode.(*impl.FullNodeAPI)
|
|
||||||
miner := sn[0]
|
|
||||||
|
|
||||||
addrinfo, err := client.NetAddrsListen(ctx)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
build.Clock.Sleep(time.Second)
|
|
||||||
|
|
||||||
mine := int64(1)
|
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
|
||||||
defer close(done)
|
|
||||||
for atomic.LoadInt64(&mine) != 0 {
|
|
||||||
build.Clock.Sleep(blocktime)
|
|
||||||
if err := sn[0].MineOne(ctx, bminer.MineReq{Done: func(bool, abi.ChainEpoch, error) {
|
|
||||||
|
|
||||||
}}); err != nil {
|
|
||||||
t.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
pledgeSectors(t, ctx, miner, nSectors, 0, nil)
|
|
||||||
|
|
||||||
atomic.StoreInt64(&mine, 0)
|
|
||||||
<-done
|
|
||||||
}
|
|
||||||
|
|
||||||
func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n, existing int, blockNotif <-chan struct{}) {
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
if i%3 == 0 && blockNotif != nil {
|
|
||||||
<-blockNotif
|
|
||||||
log.Errorf("WAIT")
|
|
||||||
}
|
|
||||||
log.Errorf("PLEDGING %d", i)
|
|
||||||
_, err := miner.PledgeSector(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
s, err := miner.SectorsList(ctx) // Note - the test builder doesn't import genesis sectors into FSM
|
|
||||||
require.NoError(t, err)
|
|
||||||
fmt.Printf("Sectors: %d\n", len(s))
|
|
||||||
if len(s) >= n+existing {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
build.Clock.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("All sectors is fsm\n")
|
|
||||||
|
|
||||||
s, err := miner.SectorsList(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
toCheck := map[abi.SectorNumber]struct{}{}
|
|
||||||
for _, number := range s {
|
|
||||||
toCheck[number] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
for len(toCheck) > 0 {
|
|
||||||
for n := range toCheck {
|
|
||||||
st, err := miner.SectorsStatus(ctx, n, false)
|
|
||||||
require.NoError(t, err)
|
|
||||||
if st.State == api.SectorState(sealing.Proving) {
|
|
||||||
delete(toCheck, n)
|
|
||||||
}
|
|
||||||
if strings.Contains(string(st.State), "Fail") {
|
|
||||||
t.Fatal("sector in a failed state", st.State)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
build.Clock.Sleep(100 * time.Millisecond)
|
|
||||||
fmt.Printf("WaitSeal: %d\n", len(s))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
|
func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
|
||||||
for _, height := range []abi.ChainEpoch{
|
for _, height := range []abi.ChainEpoch{
|
||||||
-1, // before
|
-1, // before
|
||||||
@ -223,7 +47,7 @@ func testWindowPostUpgrade(t *testing.T, b APIBuilder, blocktime time.Duration,
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV4At(upgradeHeight)}, OneMiner)
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(upgradeHeight)}, OneMiner)
|
||||||
|
|
||||||
client := n[0].FullNode.(*impl.FullNodeAPI)
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
miner := sn[0]
|
miner := sn[0]
|
||||||
@ -442,7 +266,7 @@ func TestTerminate(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
|||||||
|
|
||||||
nSectors := uint64(2)
|
nSectors := uint64(2)
|
||||||
|
|
||||||
n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV4At(-1)}, []StorageMiner{{Full: 0, Preseal: int(nSectors)}})
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(-1)}, []StorageMiner{{Full: 0, Preseal: int(nSectors)}})
|
||||||
|
|
||||||
client := n[0].FullNode.(*impl.FullNodeAPI)
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
miner := sn[0]
|
miner := sn[0]
|
||||||
@ -617,7 +441,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
///
|
///
|
||||||
// Then we're going to manually submit bad proofs.
|
// Then we're going to manually submit bad proofs.
|
||||||
n, sn := b(t, []FullNodeOpts{
|
n, sn := b(t, []FullNodeOpts{
|
||||||
FullNodeWithActorsV4At(-1),
|
FullNodeWithV4ActorsAt(-1),
|
||||||
}, []StorageMiner{
|
}, []StorageMiner{
|
||||||
{Full: 0, Preseal: PresealGenesis},
|
{Full: 0, Preseal: PresealGenesis},
|
||||||
{Full: 0},
|
{Full: 0},
|
||||||
@ -719,7 +543,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
for {
|
for {
|
||||||
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if di.Index == evilSectorLoc.Deadline {
|
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.PeriodStart > 1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
build.Clock.Sleep(blocktime)
|
build.Clock.Sleep(blocktime)
|
||||||
@ -816,7 +640,7 @@ func TestWindowPostDispute(t *testing.T, b APIBuilder, blocktime time.Duration)
|
|||||||
for {
|
for {
|
||||||
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
di, err = client.StateMinerProvingDeadline(ctx, evilMinerAddr, types.EmptyTSK)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if di.Index == evilSectorLoc.Deadline {
|
if di.Index == evilSectorLoc.Deadline && di.CurrentEpoch-di.PeriodStart > 1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
build.Clock.Sleep(blocktime)
|
build.Clock.Sleep(blocktime)
|
||||||
@ -900,7 +724,7 @@ func TestWindowPostDisputeFails(t *testing.T, b APIBuilder, blocktime time.Durat
|
|||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
n, sn := b(t, []FullNodeOpts{FullNodeWithActorsV4At(-1)}, OneMiner)
|
n, sn := b(t, []FullNodeOpts{FullNodeWithV4ActorsAt(-1)}, OneMiner)
|
||||||
|
|
||||||
client := n[0].FullNode.(*impl.FullNodeAPI)
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
miner := sn[0]
|
miner := sn[0]
|
||||||
@ -1024,3 +848,155 @@ waitForProof:
|
|||||||
require.Contains(t, err.Error(), "failed to dispute valid post (RetCode=16)")
|
require.Contains(t, err.Error(), "failed to dispute valid post (RetCode=16)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWindowPostBaseFeeNoBurn(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
och := build.UpgradeClausHeight
|
||||||
|
build.UpgradeClausHeight = 10
|
||||||
|
n, sn := b(t, DefaultFullOpts(1), OneMiner)
|
||||||
|
|
||||||
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
|
miner := sn[0]
|
||||||
|
|
||||||
|
{
|
||||||
|
addrinfo, err := client.NetAddrsListen(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
maddr, err := miner.ActorAddress(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
mi, err := client.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
for ctx.Err() == nil {
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
if err := miner.MineOne(ctx, MineNext); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
// context was canceled, ignore the error.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
defer func() {
|
||||||
|
cancel()
|
||||||
|
<-done
|
||||||
|
}()
|
||||||
|
|
||||||
|
pledgeSectors(t, ctx, miner, 10, 0, nil)
|
||||||
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
en := wact.Nonce
|
||||||
|
|
||||||
|
// wait for a new message to be sent from worker address, it will be a PoSt
|
||||||
|
|
||||||
|
waitForProof:
|
||||||
|
for {
|
||||||
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if wact.Nonce > en {
|
||||||
|
break waitForProof
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
}
|
||||||
|
|
||||||
|
slm, err := client.StateListMessages(ctx, &api.MessageMatch{To: maddr}, types.EmptyTSK, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pmr, err := client.StateReplay(ctx, types.EmptyTSK, slm[0])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, pmr.GasCost.BaseFeeBurn, big.Zero())
|
||||||
|
|
||||||
|
build.UpgradeClausHeight = och
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWindowPostBaseFeeBurn(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
n, sn := b(t, []FullNodeOpts{FullNodeWithLatestActorsAt(-1)}, OneMiner)
|
||||||
|
|
||||||
|
client := n[0].FullNode.(*impl.FullNodeAPI)
|
||||||
|
miner := sn[0]
|
||||||
|
|
||||||
|
{
|
||||||
|
addrinfo, err := client.NetAddrsListen(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := miner.NetConnect(ctx, addrinfo); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
maddr, err := miner.ActorAddress(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
mi, err := client.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
build.Clock.Sleep(time.Second)
|
||||||
|
|
||||||
|
done := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
defer close(done)
|
||||||
|
for ctx.Err() == nil {
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
if err := miner.MineOne(ctx, MineNext); err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
// context was canceled, ignore the error.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
defer func() {
|
||||||
|
cancel()
|
||||||
|
<-done
|
||||||
|
}()
|
||||||
|
|
||||||
|
pledgeSectors(t, ctx, miner, 10, 0, nil)
|
||||||
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
en := wact.Nonce
|
||||||
|
|
||||||
|
// wait for a new message to be sent from worker address, it will be a PoSt
|
||||||
|
|
||||||
|
waitForProof:
|
||||||
|
for {
|
||||||
|
wact, err := client.StateGetActor(ctx, mi.Worker, types.EmptyTSK)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if wact.Nonce > en {
|
||||||
|
break waitForProof
|
||||||
|
}
|
||||||
|
|
||||||
|
build.Clock.Sleep(blocktime)
|
||||||
|
}
|
||||||
|
|
||||||
|
slm, err := client.StateListMessages(ctx, &api.MessageMatch{To: maddr}, types.EmptyTSK, 0)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pmr, err := client.StateReplay(ctx, types.EmptyTSK, slm[0])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.NotEqual(t, pmr.GasCost.BaseFeeBurn, big.Zero())
|
||||||
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/dns4/bootstrap-0.calibration.fildev.network/tcp/1347/p2p/12D3KooWRLZAseMo9h7fRD6ojn6YYDXHsBSavX5YmjBZ9ngtAEec
|
/dns4/bootstrap-0.calibration.fildev.network/tcp/1347/p2p/12D3KooWJkikQQkxS58spo76BYzFt4fotaT5NpV2zngvrqm4u5ow
|
||||||
/dns4/bootstrap-1.calibration.fildev.network/tcp/1347/p2p/12D3KooWJFtDXgZEQMEkjJPSrbfdvh2xfjVKrXeNFG1t8ioJXAzv
|
/dns4/bootstrap-1.calibration.fildev.network/tcp/1347/p2p/12D3KooWLce5FDHR4EX4CrYavphA5xS3uDsX6aoowXh5tzDUxJav
|
||||||
/dns4/bootstrap-2.calibration.fildev.network/tcp/1347/p2p/12D3KooWP1uB9Lo7yCA3S17TD4Y5wStP5Nk7Vqh53m8GsFjkyujD
|
/dns4/bootstrap-2.calibration.fildev.network/tcp/1347/p2p/12D3KooWA9hFfQG9GjP6bHeuQQbMD3FDtZLdW1NayxKXUT26PQZu
|
||||||
/dns4/bootstrap-3.calibration.fildev.network/tcp/1347/p2p/12D3KooWLrPM4WPK1YRGPCUwndWcDX8GCYgms3DiuofUmxwvhMCn
|
/dns4/bootstrap-3.calibration.fildev.network/tcp/1347/p2p/12D3KooWMHDi3LVTFG8Szqogt7RkNXvonbQYqSazxBx41A5aeuVz
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -5,3 +5,7 @@ import rice "github.com/GeertJohan/go.rice"
|
|||||||
func ParametersJSON() []byte {
|
func ParametersJSON() []byte {
|
||||||
return rice.MustFindBox("proof-params").MustBytes("parameters.json")
|
return rice.MustFindBox("proof-params").MustBytes("parameters.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SrsJSON() []byte {
|
||||||
|
return rice.MustFindBox("proof-params").MustBytes("srs-inner-product.json")
|
||||||
|
}
|
||||||
|
@ -24,20 +24,22 @@ var UpgradeIgnitionHeight = abi.ChainEpoch(-2)
|
|||||||
var UpgradeRefuelHeight = abi.ChainEpoch(-3)
|
var UpgradeRefuelHeight = abi.ChainEpoch(-3)
|
||||||
var UpgradeTapeHeight = abi.ChainEpoch(-4)
|
var UpgradeTapeHeight = abi.ChainEpoch(-4)
|
||||||
|
|
||||||
var UpgradeActorsV2Height = abi.ChainEpoch(10)
|
var UpgradeAssemblyHeight = abi.ChainEpoch(5)
|
||||||
var UpgradeLiftoffHeight = abi.ChainEpoch(-5)
|
var UpgradeLiftoffHeight = abi.ChainEpoch(-5)
|
||||||
|
|
||||||
var UpgradeKumquatHeight = abi.ChainEpoch(15)
|
var UpgradeKumquatHeight = abi.ChainEpoch(6)
|
||||||
var UpgradeCalicoHeight = abi.ChainEpoch(20)
|
var UpgradeCalicoHeight = abi.ChainEpoch(7)
|
||||||
var UpgradePersianHeight = abi.ChainEpoch(25)
|
var UpgradePersianHeight = abi.ChainEpoch(8)
|
||||||
var UpgradeOrangeHeight = abi.ChainEpoch(27)
|
var UpgradeOrangeHeight = abi.ChainEpoch(9)
|
||||||
var UpgradeClausHeight = abi.ChainEpoch(30)
|
var UpgradeClausHeight = abi.ChainEpoch(10)
|
||||||
|
|
||||||
var UpgradeActorsV3Height = abi.ChainEpoch(35)
|
var UpgradeTrustHeight = abi.ChainEpoch(11)
|
||||||
|
|
||||||
var UpgradeNorwegianHeight = abi.ChainEpoch(40)
|
var UpgradeNorwegianHeight = abi.ChainEpoch(12)
|
||||||
|
|
||||||
var UpgradeActorsV4Height = abi.ChainEpoch(45)
|
var UpgradeTurboHeight = abi.ChainEpoch(13)
|
||||||
|
|
||||||
|
var UpgradeHyperdriveHeight = abi.ChainEpoch(14)
|
||||||
|
|
||||||
var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
var DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
||||||
0: DrandMainnet,
|
0: DrandMainnet,
|
||||||
@ -68,16 +70,17 @@ func init() {
|
|||||||
UpgradeIgnitionHeight = getUpgradeHeight("LOTUS_IGNITION_HEIGHT", UpgradeIgnitionHeight)
|
UpgradeIgnitionHeight = getUpgradeHeight("LOTUS_IGNITION_HEIGHT", UpgradeIgnitionHeight)
|
||||||
UpgradeRefuelHeight = getUpgradeHeight("LOTUS_REFUEL_HEIGHT", UpgradeRefuelHeight)
|
UpgradeRefuelHeight = getUpgradeHeight("LOTUS_REFUEL_HEIGHT", UpgradeRefuelHeight)
|
||||||
UpgradeTapeHeight = getUpgradeHeight("LOTUS_TAPE_HEIGHT", UpgradeTapeHeight)
|
UpgradeTapeHeight = getUpgradeHeight("LOTUS_TAPE_HEIGHT", UpgradeTapeHeight)
|
||||||
UpgradeActorsV2Height = getUpgradeHeight("LOTUS_ACTORSV2_HEIGHT", UpgradeActorsV2Height)
|
UpgradeAssemblyHeight = getUpgradeHeight("LOTUS_ACTORSV2_HEIGHT", UpgradeAssemblyHeight)
|
||||||
UpgradeLiftoffHeight = getUpgradeHeight("LOTUS_LIFTOFF_HEIGHT", UpgradeLiftoffHeight)
|
UpgradeLiftoffHeight = getUpgradeHeight("LOTUS_LIFTOFF_HEIGHT", UpgradeLiftoffHeight)
|
||||||
UpgradeKumquatHeight = getUpgradeHeight("LOTUS_KUMQUAT_HEIGHT", UpgradeKumquatHeight)
|
UpgradeKumquatHeight = getUpgradeHeight("LOTUS_KUMQUAT_HEIGHT", UpgradeKumquatHeight)
|
||||||
UpgradeCalicoHeight = getUpgradeHeight("LOTUS_CALICO_HEIGHT", UpgradeCalicoHeight)
|
UpgradeCalicoHeight = getUpgradeHeight("LOTUS_CALICO_HEIGHT", UpgradeCalicoHeight)
|
||||||
UpgradePersianHeight = getUpgradeHeight("LOTUS_PERSIAN_HEIGHT", UpgradePersianHeight)
|
UpgradePersianHeight = getUpgradeHeight("LOTUS_PERSIAN_HEIGHT", UpgradePersianHeight)
|
||||||
UpgradeOrangeHeight = getUpgradeHeight("LOTUS_ORANGE_HEIGHT", UpgradeOrangeHeight)
|
UpgradeOrangeHeight = getUpgradeHeight("LOTUS_ORANGE_HEIGHT", UpgradeOrangeHeight)
|
||||||
UpgradeClausHeight = getUpgradeHeight("LOTUS_CLAUS_HEIGHT", UpgradeClausHeight)
|
UpgradeClausHeight = getUpgradeHeight("LOTUS_CLAUS_HEIGHT", UpgradeClausHeight)
|
||||||
UpgradeActorsV3Height = getUpgradeHeight("LOTUS_ACTORSV3_HEIGHT", UpgradeActorsV3Height)
|
UpgradeTrustHeight = getUpgradeHeight("LOTUS_ACTORSV3_HEIGHT", UpgradeTrustHeight)
|
||||||
UpgradeNorwegianHeight = getUpgradeHeight("LOTUS_NORWEGIAN_HEIGHT", UpgradeNorwegianHeight)
|
UpgradeNorwegianHeight = getUpgradeHeight("LOTUS_NORWEGIAN_HEIGHT", UpgradeNorwegianHeight)
|
||||||
UpgradeActorsV4Height = getUpgradeHeight("LOTUS_ACTORSV4_HEIGHT", UpgradeActorsV4Height)
|
UpgradeTurboHeight = getUpgradeHeight("LOTUS_ACTORSV4_HEIGHT", UpgradeTurboHeight)
|
||||||
|
UpgradeHyperdriveHeight = getUpgradeHeight("LOTUS_HYPERDRIVE_HEIGHT", UpgradeHyperdriveHeight)
|
||||||
|
|
||||||
BuildType |= Build2k
|
BuildType |= Build2k
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ const UpgradeSmokeHeight = -2
|
|||||||
const UpgradeIgnitionHeight = -3
|
const UpgradeIgnitionHeight = -3
|
||||||
const UpgradeRefuelHeight = -4
|
const UpgradeRefuelHeight = -4
|
||||||
|
|
||||||
var UpgradeActorsV2Height = abi.ChainEpoch(30)
|
var UpgradeAssemblyHeight = abi.ChainEpoch(30)
|
||||||
|
|
||||||
const UpgradeTapeHeight = 60
|
const UpgradeTapeHeight = 60
|
||||||
const UpgradeLiftoffHeight = -5
|
const UpgradeLiftoffHeight = -5
|
||||||
@ -32,9 +32,10 @@ const UpgradeCalicoHeight = 120
|
|||||||
const UpgradePersianHeight = 150
|
const UpgradePersianHeight = 150
|
||||||
const UpgradeClausHeight = 180
|
const UpgradeClausHeight = 180
|
||||||
const UpgradeOrangeHeight = 210
|
const UpgradeOrangeHeight = 210
|
||||||
const UpgradeActorsV3Height = 240
|
const UpgradeTrustHeight = 240
|
||||||
const UpgradeNorwegianHeight = UpgradeActorsV3Height + (builtin2.EpochsInHour * 12)
|
const UpgradeNorwegianHeight = UpgradeTrustHeight + (builtin2.EpochsInHour * 12)
|
||||||
const UpgradeActorsV4Height = 8922
|
const UpgradeTurboHeight = 8922
|
||||||
|
const UpgradeHyperdriveHeight = 9999999
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
policy.SetConsensusMinerMinPower(abi.NewStoragePower(2 << 30))
|
policy.SetConsensusMinerMinPower(abi.NewStoragePower(2 << 30))
|
||||||
|
@ -25,7 +25,7 @@ const UpgradeSmokeHeight = -2
|
|||||||
const UpgradeIgnitionHeight = -3
|
const UpgradeIgnitionHeight = -3
|
||||||
const UpgradeRefuelHeight = -4
|
const UpgradeRefuelHeight = -4
|
||||||
|
|
||||||
var UpgradeActorsV2Height = abi.ChainEpoch(30)
|
var UpgradeAssemblyHeight = abi.ChainEpoch(30)
|
||||||
|
|
||||||
const UpgradeTapeHeight = 60
|
const UpgradeTapeHeight = 60
|
||||||
|
|
||||||
@ -33,17 +33,20 @@ const UpgradeLiftoffHeight = -5
|
|||||||
|
|
||||||
const UpgradeKumquatHeight = 90
|
const UpgradeKumquatHeight = 90
|
||||||
|
|
||||||
const UpgradeCalicoHeight = 100
|
const UpgradeCalicoHeight = 120
|
||||||
const UpgradePersianHeight = UpgradeCalicoHeight + (builtin2.EpochsInHour * 1)
|
const UpgradePersianHeight = UpgradeCalicoHeight + (builtin2.EpochsInHour * 1)
|
||||||
|
|
||||||
const UpgradeClausHeight = 250
|
const UpgradeClausHeight = 270
|
||||||
|
|
||||||
const UpgradeOrangeHeight = 300
|
const UpgradeOrangeHeight = 300
|
||||||
|
|
||||||
const UpgradeActorsV3Height = 600
|
const UpgradeTrustHeight = 330
|
||||||
const UpgradeNorwegianHeight = 114000
|
|
||||||
|
|
||||||
const UpgradeActorsV4Height = 193789
|
const UpgradeNorwegianHeight = 360
|
||||||
|
|
||||||
|
const UpgradeTurboHeight = 390
|
||||||
|
|
||||||
|
const UpgradeHyperdriveHeight = 420
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
policy.SetConsensusMinerMinPower(abi.NewStoragePower(32 << 30))
|
policy.SetConsensusMinerMinPower(abi.NewStoragePower(32 << 30))
|
||||||
|
@ -34,7 +34,7 @@ const UpgradeSmokeHeight = 51000
|
|||||||
const UpgradeIgnitionHeight = 94000
|
const UpgradeIgnitionHeight = 94000
|
||||||
const UpgradeRefuelHeight = 130800
|
const UpgradeRefuelHeight = 130800
|
||||||
|
|
||||||
const UpgradeActorsV2Height = 138720
|
const UpgradeAssemblyHeight = 138720
|
||||||
|
|
||||||
const UpgradeTapeHeight = 140760
|
const UpgradeTapeHeight = 140760
|
||||||
|
|
||||||
@ -51,16 +51,19 @@ const UpgradePersianHeight = UpgradeCalicoHeight + (builtin2.EpochsInHour * 60)
|
|||||||
const UpgradeOrangeHeight = 336458
|
const UpgradeOrangeHeight = 336458
|
||||||
|
|
||||||
// 2020-12-22T02:00:00Z
|
// 2020-12-22T02:00:00Z
|
||||||
const UpgradeClausHeight = 343200
|
var UpgradeClausHeight = abi.ChainEpoch(343200)
|
||||||
|
|
||||||
// 2021-03-04T00:00:30Z
|
// 2021-03-04T00:00:30Z
|
||||||
var UpgradeActorsV3Height = abi.ChainEpoch(550321)
|
const UpgradeTrustHeight = 550321
|
||||||
|
|
||||||
// 2021-04-12T22:00:00Z
|
// 2021-04-12T22:00:00Z
|
||||||
const UpgradeNorwegianHeight = 665280
|
const UpgradeNorwegianHeight = 665280
|
||||||
|
|
||||||
// 2021-04-29T06:00:00Z
|
// 2021-04-29T06:00:00Z
|
||||||
var UpgradeActorsV4Height = abi.ChainEpoch(712320)
|
const UpgradeTurboHeight = 712320
|
||||||
|
|
||||||
|
// 2021-06-30T22:00:00Z
|
||||||
|
var UpgradeHyperdriveHeight = abi.ChainEpoch(892800)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
policy.SetConsensusMinerMinPower(abi.NewStoragePower(10 << 40))
|
policy.SetConsensusMinerMinPower(abi.NewStoragePower(10 << 40))
|
||||||
@ -69,12 +72,8 @@ func init() {
|
|||||||
SetAddressNetwork(address.Mainnet)
|
SetAddressNetwork(address.Mainnet)
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.Getenv("LOTUS_DISABLE_V3_ACTOR_MIGRATION") == "1" {
|
if os.Getenv("LOTUS_DISABLE_HYPERDRIVE") == "1" {
|
||||||
UpgradeActorsV3Height = math.MaxInt64
|
UpgradeHyperdriveHeight = math.MaxInt64
|
||||||
}
|
|
||||||
|
|
||||||
if os.Getenv("LOTUS_DISABLE_V4_ACTOR_MIGRATION") == "1" {
|
|
||||||
UpgradeActorsV4Height = math.MaxInt64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Devnet = false
|
Devnet = false
|
||||||
|
@ -27,7 +27,7 @@ const UpgradeRefuelHeight = -3
|
|||||||
|
|
||||||
const UpgradeLiftoffHeight = -5
|
const UpgradeLiftoffHeight = -5
|
||||||
|
|
||||||
const UpgradeActorsV2Height = 30 // critical: the network can bootstrap from v1 only
|
const UpgradeAssemblyHeight = 30 // critical: the network can bootstrap from v1 only
|
||||||
const UpgradeTapeHeight = 60
|
const UpgradeTapeHeight = 60
|
||||||
|
|
||||||
const UpgradeKumquatHeight = 90
|
const UpgradeKumquatHeight = 90
|
||||||
@ -39,9 +39,10 @@ const UpgradeClausHeight = 250
|
|||||||
|
|
||||||
const UpgradeOrangeHeight = 300
|
const UpgradeOrangeHeight = 300
|
||||||
|
|
||||||
const UpgradeActorsV3Height = 600
|
const UpgradeTrustHeight = 600
|
||||||
const UpgradeNorwegianHeight = 201000
|
const UpgradeNorwegianHeight = 201000
|
||||||
const UpgradeActorsV4Height = 203000
|
const UpgradeTurboHeight = 203000
|
||||||
|
const UpgradeHyperdriveHeight = 999999999
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Minimum block production power is set to 4 TiB
|
// Minimum block production power is set to 4 TiB
|
||||||
|
@ -25,7 +25,7 @@ const UnixfsLinksPerLevel = 1024
|
|||||||
// Consensus / Network
|
// Consensus / Network
|
||||||
|
|
||||||
const AllowableClockDriftSecs = uint64(1)
|
const AllowableClockDriftSecs = uint64(1)
|
||||||
const NewestNetworkVersion = network.Version11
|
const NewestNetworkVersion = network.Version13
|
||||||
const ActorUpgradeNetworkVersion = network.Version4
|
const ActorUpgradeNetworkVersion = network.Version4
|
||||||
|
|
||||||
// Epochs
|
// Epochs
|
||||||
|
@ -86,16 +86,17 @@ var (
|
|||||||
UpgradeIgnitionHeight abi.ChainEpoch = -2
|
UpgradeIgnitionHeight abi.ChainEpoch = -2
|
||||||
UpgradeRefuelHeight abi.ChainEpoch = -3
|
UpgradeRefuelHeight abi.ChainEpoch = -3
|
||||||
UpgradeTapeHeight abi.ChainEpoch = -4
|
UpgradeTapeHeight abi.ChainEpoch = -4
|
||||||
UpgradeActorsV2Height abi.ChainEpoch = 10
|
UpgradeAssemblyHeight abi.ChainEpoch = 10
|
||||||
UpgradeLiftoffHeight abi.ChainEpoch = -5
|
UpgradeLiftoffHeight abi.ChainEpoch = -5
|
||||||
UpgradeKumquatHeight abi.ChainEpoch = -6
|
UpgradeKumquatHeight abi.ChainEpoch = -6
|
||||||
UpgradeCalicoHeight abi.ChainEpoch = -7
|
UpgradeCalicoHeight abi.ChainEpoch = -7
|
||||||
UpgradePersianHeight abi.ChainEpoch = -8
|
UpgradePersianHeight abi.ChainEpoch = -8
|
||||||
UpgradeOrangeHeight abi.ChainEpoch = -9
|
UpgradeOrangeHeight abi.ChainEpoch = -9
|
||||||
UpgradeClausHeight abi.ChainEpoch = -10
|
UpgradeClausHeight abi.ChainEpoch = -10
|
||||||
UpgradeActorsV3Height abi.ChainEpoch = -11
|
UpgradeTrustHeight abi.ChainEpoch = -11
|
||||||
UpgradeNorwegianHeight abi.ChainEpoch = -12
|
UpgradeNorwegianHeight abi.ChainEpoch = -12
|
||||||
UpgradeActorsV4Height abi.ChainEpoch = -13
|
UpgradeTurboHeight abi.ChainEpoch = -13
|
||||||
|
UpgradeHyperdriveHeight abi.ChainEpoch = -13
|
||||||
|
|
||||||
DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
DrandSchedule = map[abi.ChainEpoch]DrandEnum{
|
||||||
0: DrandMainnet,
|
0: DrandMainnet,
|
||||||
|
7
build/proof-params/srs-inner-product.json
Normal file
7
build/proof-params/srs-inner-product.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"v28-fil-inner-product-v1.srs": {
|
||||||
|
"cid": "Qmdq44DjcQnFfU3PJcdX7J49GCqcUYszr1TxMbHtAkvQ3g",
|
||||||
|
"digest": "ae20310138f5ba81451d723f858e3797",
|
||||||
|
"sector_size": 0
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,7 @@ func buildType() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildVersion is the local build version, set by build system
|
// BuildVersion is the local build version, set by build system
|
||||||
const BuildVersion = "1.9.0"
|
const BuildVersion = "1.10.0"
|
||||||
|
|
||||||
func UserVersion() string {
|
func UserVersion() string {
|
||||||
return BuildVersion + buildType() + CurrentCommit
|
return BuildVersion + buildType() + CurrentCommit
|
||||||
|
219
chain/actors/agen/main.go
Normal file
219
chain/actors/agen/main.go
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
)
|
||||||
|
|
||||||
|
var latestVersion = 5
|
||||||
|
|
||||||
|
var versions = []int{0, 2, 3, 4, latestVersion}
|
||||||
|
|
||||||
|
var versionImports = map[int]string{
|
||||||
|
0: "/",
|
||||||
|
2: "/v2/",
|
||||||
|
3: "/v3/",
|
||||||
|
4: "/v4/",
|
||||||
|
latestVersion: "/v5/",
|
||||||
|
}
|
||||||
|
|
||||||
|
var actors = map[string][]int{
|
||||||
|
"account": versions,
|
||||||
|
"cron": versions,
|
||||||
|
"init": versions,
|
||||||
|
"market": versions,
|
||||||
|
"miner": versions,
|
||||||
|
"multisig": versions,
|
||||||
|
"paych": versions,
|
||||||
|
"power": versions,
|
||||||
|
"reward": versions,
|
||||||
|
"verifreg": versions,
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if err := generateAdapters(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := generatePolicy("chain/actors/policy/policy.go"); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := generateBuiltin("chain/actors/builtin/builtin.go"); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateAdapters() error {
|
||||||
|
for act, versions := range actors {
|
||||||
|
actDir := filepath.Join("chain/actors/builtin", act)
|
||||||
|
|
||||||
|
if err := generateState(actDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := generateMessages(actDir); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
af, err := ioutil.ReadFile(filepath.Join(actDir, "actor.go.template"))
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("loading actor template: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tpl := template.Must(template.New("").Funcs(template.FuncMap{
|
||||||
|
"import": func(v int) string { return versionImports[v] },
|
||||||
|
}).Parse(string(af)))
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
|
||||||
|
err = tpl.Execute(&b, map[string]interface{}{
|
||||||
|
"versions": versions,
|
||||||
|
"latestVersion": latestVersion,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("%s.go", act)), b.Bytes(), 0666); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateState(actDir string) error {
|
||||||
|
af, err := ioutil.ReadFile(filepath.Join(actDir, "state.go.template"))
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil // skip
|
||||||
|
}
|
||||||
|
|
||||||
|
return xerrors.Errorf("loading state adapter template: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, version := range versions {
|
||||||
|
tpl := template.Must(template.New("").Funcs(template.FuncMap{}).Parse(string(af)))
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
|
||||||
|
err := tpl.Execute(&b, map[string]interface{}{
|
||||||
|
"v": version,
|
||||||
|
"import": versionImports[version],
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("v%d.go", version)), b.Bytes(), 0666); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateMessages(actDir string) error {
|
||||||
|
af, err := ioutil.ReadFile(filepath.Join(actDir, "message.go.template"))
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil // skip
|
||||||
|
}
|
||||||
|
|
||||||
|
return xerrors.Errorf("loading message adapter template: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, version := range versions {
|
||||||
|
tpl := template.Must(template.New("").Funcs(template.FuncMap{}).Parse(string(af)))
|
||||||
|
|
||||||
|
var b bytes.Buffer
|
||||||
|
|
||||||
|
err := tpl.Execute(&b, map[string]interface{}{
|
||||||
|
"v": version,
|
||||||
|
"import": versionImports[version],
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("message%d.go", version)), b.Bytes(), 0666); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func generatePolicy(policyPath string) error {
|
||||||
|
|
||||||
|
pf, err := ioutil.ReadFile(policyPath + ".template")
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil // skip
|
||||||
|
}
|
||||||
|
|
||||||
|
return xerrors.Errorf("loading policy template file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tpl := template.Must(template.New("").Funcs(template.FuncMap{
|
||||||
|
"import": func(v int) string { return versionImports[v] },
|
||||||
|
}).Parse(string(pf)))
|
||||||
|
var b bytes.Buffer
|
||||||
|
|
||||||
|
err = tpl.Execute(&b, map[string]interface{}{
|
||||||
|
"versions": versions,
|
||||||
|
"latestVersion": latestVersion,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(policyPath, b.Bytes(), 0666); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func generateBuiltin(builtinPath string) error {
|
||||||
|
|
||||||
|
bf, err := ioutil.ReadFile(builtinPath + ".template")
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return nil // skip
|
||||||
|
}
|
||||||
|
|
||||||
|
return xerrors.Errorf("loading builtin template file: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tpl := template.Must(template.New("").Funcs(template.FuncMap{
|
||||||
|
"import": func(v int) string { return versionImports[v] },
|
||||||
|
}).Parse(string(bf)))
|
||||||
|
var b bytes.Buffer
|
||||||
|
|
||||||
|
err = tpl.Execute(&b, map[string]interface{}{
|
||||||
|
"versions": versions,
|
||||||
|
"latestVersion": latestVersion,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(builtinPath, b.Bytes(), 0666); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -12,38 +12,59 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin0.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin0.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load0(store, root)
|
return load0(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin2.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin2.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load2(store, root)
|
return load2(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin3.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin3.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load3(store, root)
|
return load3(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin4.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin4.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load4(store, root)
|
return load4(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builtin.RegisterActorState(builtin5.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load5(store, root)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var Methods = builtin4.MethodsAccount
|
var Methods = builtin4.MethodsAccount
|
||||||
|
|
||||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
switch act.Code {
|
switch act.Code {
|
||||||
|
|
||||||
case builtin0.AccountActorCodeID:
|
case builtin0.AccountActorCodeID:
|
||||||
return load0(store, act.Head)
|
return load0(store, act.Head)
|
||||||
|
|
||||||
case builtin2.AccountActorCodeID:
|
case builtin2.AccountActorCodeID:
|
||||||
return load2(store, act.Head)
|
return load2(store, act.Head)
|
||||||
|
|
||||||
case builtin3.AccountActorCodeID:
|
case builtin3.AccountActorCodeID:
|
||||||
return load3(store, act.Head)
|
return load3(store, act.Head)
|
||||||
|
|
||||||
case builtin4.AccountActorCodeID:
|
case builtin4.AccountActorCodeID:
|
||||||
return load4(store, act.Head)
|
return load4(store, act.Head)
|
||||||
|
|
||||||
|
case builtin5.AccountActorCodeID:
|
||||||
|
return load5(store, act.Head)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
}
|
}
|
||||||
|
41
chain/actors/builtin/account/actor.go.template
Normal file
41
chain/actors/builtin/account/actor.go.template
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
{{end}}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
{{range .versions}}
|
||||||
|
builtin.RegisterActorState(builtin{{.}}.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load{{.}}(store, root)
|
||||||
|
})
|
||||||
|
{{end}}}
|
||||||
|
|
||||||
|
var Methods = builtin4.MethodsAccount
|
||||||
|
|
||||||
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.AccountActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
|
||||||
|
PubkeyAddress() (address.Address, error)
|
||||||
|
}
|
30
chain/actors/builtin/account/state.go.template
Normal file
30
chain/actors/builtin/account/state.go.template
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
|
account{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/account"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state{{.v}})(nil)
|
||||||
|
|
||||||
|
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state{{.v}}{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state{{.v}} struct {
|
||||||
|
account{{.v}}.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) PubkeyAddress() (address.Address, error) {
|
||||||
|
return s.Address, nil
|
||||||
|
}
|
30
chain/actors/builtin/account/v5.go
Normal file
30
chain/actors/builtin/account/v5.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
|
account5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/account"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state5)(nil)
|
||||||
|
|
||||||
|
func load5(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state5{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state5 struct {
|
||||||
|
account5.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) PubkeyAddress() (address.Address, error) {
|
||||||
|
return s.Address, nil
|
||||||
|
}
|
@ -6,9 +6,19 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
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"
|
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"
|
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"
|
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"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/filecoin-project/go-state-types/cbor"
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
@ -16,62 +26,70 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
smoothing0 "github.com/filecoin-project/specs-actors/actors/util/smoothing"
|
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
||||||
smoothing2 "github.com/filecoin-project/specs-actors/v2/actors/util/smoothing"
|
proof5 "github.com/filecoin-project/specs-actors/v5/actors/runtime/proof"
|
||||||
smoothing3 "github.com/filecoin-project/specs-actors/v3/actors/util/smoothing"
|
|
||||||
smoothing4 "github.com/filecoin-project/specs-actors/v4/actors/util/smoothing"
|
|
||||||
|
|
||||||
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
||||||
proof0 "github.com/filecoin-project/specs-actors/actors/runtime/proof"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var SystemActorAddr = builtin0.SystemActorAddr
|
var SystemActorAddr = builtin5.SystemActorAddr
|
||||||
var BurntFundsActorAddr = builtin0.BurntFundsActorAddr
|
var BurntFundsActorAddr = builtin5.BurntFundsActorAddr
|
||||||
var CronActorAddr = builtin0.CronActorAddr
|
var CronActorAddr = builtin5.CronActorAddr
|
||||||
var SaftAddress = makeAddress("t0122")
|
var SaftAddress = makeAddress("t0122")
|
||||||
var ReserveAddress = makeAddress("t090")
|
var ReserveAddress = makeAddress("t090")
|
||||||
var RootVerifierAddress = makeAddress("t080")
|
var RootVerifierAddress = makeAddress("t080")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ExpectedLeadersPerEpoch = builtin0.ExpectedLeadersPerEpoch
|
ExpectedLeadersPerEpoch = builtin5.ExpectedLeadersPerEpoch
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EpochDurationSeconds = builtin0.EpochDurationSeconds
|
EpochDurationSeconds = builtin5.EpochDurationSeconds
|
||||||
EpochsInDay = builtin0.EpochsInDay
|
EpochsInDay = builtin5.EpochsInDay
|
||||||
SecondsInDay = builtin0.SecondsInDay
|
SecondsInDay = builtin5.SecondsInDay
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MethodSend = builtin4.MethodSend
|
MethodSend = builtin5.MethodSend
|
||||||
MethodConstructor = builtin4.MethodConstructor
|
MethodConstructor = builtin5.MethodConstructor
|
||||||
)
|
)
|
||||||
|
|
||||||
// These are all just type aliases across actor versions 0, 2, & 3. In the future, that might change
|
// These are all just type aliases across actor versions. In the future, that might change
|
||||||
// and we might need to do something fancier.
|
// and we might need to do something fancier.
|
||||||
type SectorInfo = proof0.SectorInfo
|
type SectorInfo = proof5.SectorInfo
|
||||||
type PoStProof = proof0.PoStProof
|
type PoStProof = proof5.PoStProof
|
||||||
type FilterEstimate = smoothing0.FilterEstimate
|
type FilterEstimate = smoothing0.FilterEstimate
|
||||||
|
|
||||||
func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate {
|
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
|
||||||
return (FilterEstimate)(v0) //nolint:unconvert
|
return miner5.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Doesn't change between actors v0, v2, and v3.
|
func FromV0FilterEstimate(v0 smoothing0.FilterEstimate) FilterEstimate {
|
||||||
func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, verifiedWeight abi.DealWeight) abi.StoragePower {
|
|
||||||
return miner0.QAPowerForWeight(size, duration, dealWeight, verifiedWeight)
|
return (FilterEstimate)(v0) //nolint:unconvert
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromV2FilterEstimate(v2 smoothing2.FilterEstimate) FilterEstimate {
|
func FromV2FilterEstimate(v2 smoothing2.FilterEstimate) FilterEstimate {
|
||||||
|
|
||||||
return (FilterEstimate)(v2)
|
return (FilterEstimate)(v2)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromV3FilterEstimate(v3 smoothing3.FilterEstimate) FilterEstimate {
|
func FromV3FilterEstimate(v3 smoothing3.FilterEstimate) FilterEstimate {
|
||||||
|
|
||||||
return (FilterEstimate)(v3)
|
return (FilterEstimate)(v3)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromV4FilterEstimate(v4 smoothing4.FilterEstimate) FilterEstimate {
|
func FromV4FilterEstimate(v4 smoothing4.FilterEstimate) FilterEstimate {
|
||||||
|
|
||||||
return (FilterEstimate)(v4)
|
return (FilterEstimate)(v4)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func FromV5FilterEstimate(v5 smoothing5.FilterEstimate) FilterEstimate {
|
||||||
|
|
||||||
|
return (FilterEstimate)(v5)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error)
|
type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error)
|
||||||
@ -92,52 +110,150 @@ func Load(store adt.Store, act *types.Actor) (cbor.Marshaler, error) {
|
|||||||
|
|
||||||
func ActorNameByCode(c cid.Cid) string {
|
func ActorNameByCode(c cid.Cid) string {
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
case builtin0.IsBuiltinActor(c):
|
case builtin0.IsBuiltinActor(c):
|
||||||
return builtin0.ActorNameByCode(c)
|
return builtin0.ActorNameByCode(c)
|
||||||
|
|
||||||
case builtin2.IsBuiltinActor(c):
|
case builtin2.IsBuiltinActor(c):
|
||||||
return builtin2.ActorNameByCode(c)
|
return builtin2.ActorNameByCode(c)
|
||||||
|
|
||||||
case builtin3.IsBuiltinActor(c):
|
case builtin3.IsBuiltinActor(c):
|
||||||
return builtin3.ActorNameByCode(c)
|
return builtin3.ActorNameByCode(c)
|
||||||
|
|
||||||
case builtin4.IsBuiltinActor(c):
|
case builtin4.IsBuiltinActor(c):
|
||||||
return builtin4.ActorNameByCode(c)
|
return builtin4.ActorNameByCode(c)
|
||||||
|
|
||||||
|
case builtin5.IsBuiltinActor(c):
|
||||||
|
return builtin5.ActorNameByCode(c)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return "<unknown>"
|
return "<unknown>"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsBuiltinActor(c cid.Cid) bool {
|
func IsBuiltinActor(c cid.Cid) bool {
|
||||||
return builtin0.IsBuiltinActor(c) ||
|
|
||||||
builtin2.IsBuiltinActor(c) ||
|
if builtin0.IsBuiltinActor(c) {
|
||||||
builtin3.IsBuiltinActor(c) ||
|
return true
|
||||||
builtin4.IsBuiltinActor(c)
|
}
|
||||||
|
|
||||||
|
if builtin2.IsBuiltinActor(c) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if builtin3.IsBuiltinActor(c) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if builtin4.IsBuiltinActor(c) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if builtin5.IsBuiltinActor(c) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsAccountActor(c cid.Cid) bool {
|
func IsAccountActor(c cid.Cid) bool {
|
||||||
return c == builtin0.AccountActorCodeID ||
|
|
||||||
c == builtin2.AccountActorCodeID ||
|
if c == builtin0.AccountActorCodeID {
|
||||||
c == builtin3.AccountActorCodeID ||
|
return true
|
||||||
c == builtin4.AccountActorCodeID
|
}
|
||||||
|
|
||||||
|
if c == builtin2.AccountActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin3.AccountActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin4.AccountActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin5.AccountActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsStorageMinerActor(c cid.Cid) bool {
|
func IsStorageMinerActor(c cid.Cid) bool {
|
||||||
return c == builtin0.StorageMinerActorCodeID ||
|
|
||||||
c == builtin2.StorageMinerActorCodeID ||
|
if c == builtin0.StorageMinerActorCodeID {
|
||||||
c == builtin3.StorageMinerActorCodeID ||
|
return true
|
||||||
c == builtin4.StorageMinerActorCodeID
|
}
|
||||||
|
|
||||||
|
if c == builtin2.StorageMinerActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin3.StorageMinerActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin4.StorageMinerActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin5.StorageMinerActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsMultisigActor(c cid.Cid) bool {
|
func IsMultisigActor(c cid.Cid) bool {
|
||||||
return c == builtin0.MultisigActorCodeID ||
|
|
||||||
c == builtin2.MultisigActorCodeID ||
|
if c == builtin0.MultisigActorCodeID {
|
||||||
c == builtin3.MultisigActorCodeID ||
|
return true
|
||||||
c == builtin4.MultisigActorCodeID
|
}
|
||||||
|
|
||||||
|
if c == builtin2.MultisigActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin3.MultisigActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin4.MultisigActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin5.MultisigActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPaymentChannelActor(c cid.Cid) bool {
|
func IsPaymentChannelActor(c cid.Cid) bool {
|
||||||
return c == builtin0.PaymentChannelActorCodeID ||
|
|
||||||
c == builtin2.PaymentChannelActorCodeID ||
|
if c == builtin0.PaymentChannelActorCodeID {
|
||||||
c == builtin3.PaymentChannelActorCodeID ||
|
return true
|
||||||
c == builtin4.PaymentChannelActorCodeID
|
}
|
||||||
|
|
||||||
|
if c == builtin2.PaymentChannelActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin3.PaymentChannelActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin4.PaymentChannelActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if c == builtin5.PaymentChannelActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeAddress(addr string) address.Address {
|
func makeAddress(addr string) address.Address {
|
||||||
|
144
chain/actors/builtin/builtin.go.template
Normal file
144
chain/actors/builtin/builtin.go.template
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
package builtin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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}}
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var SystemActorAddr = builtin{{.latestVersion}}.SystemActorAddr
|
||||||
|
var BurntFundsActorAddr = builtin{{.latestVersion}}.BurntFundsActorAddr
|
||||||
|
var CronActorAddr = builtin{{.latestVersion}}.CronActorAddr
|
||||||
|
var SaftAddress = makeAddress("t0122")
|
||||||
|
var ReserveAddress = makeAddress("t090")
|
||||||
|
var RootVerifierAddress = makeAddress("t080")
|
||||||
|
|
||||||
|
var (
|
||||||
|
ExpectedLeadersPerEpoch = builtin{{.latestVersion}}.ExpectedLeadersPerEpoch
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
EpochDurationSeconds = builtin{{.latestVersion}}.EpochDurationSeconds
|
||||||
|
EpochsInDay = builtin{{.latestVersion}}.EpochsInDay
|
||||||
|
SecondsInDay = builtin{{.latestVersion}}.SecondsInDay
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
MethodSend = builtin{{.latestVersion}}.MethodSend
|
||||||
|
MethodConstructor = builtin{{.latestVersion}}.MethodConstructor
|
||||||
|
)
|
||||||
|
|
||||||
|
// These are all just type aliases across actor versions. In the future, that might change
|
||||||
|
// and we might need to do something fancier.
|
||||||
|
type SectorInfo = proof{{.latestVersion}}.SectorInfo
|
||||||
|
type PoStProof = proof{{.latestVersion}}.PoStProof
|
||||||
|
type FilterEstimate = smoothing0.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 {
|
||||||
|
switch {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.IsBuiltinActor(c):
|
||||||
|
return builtin{{.}}.ActorNameByCode(c)
|
||||||
|
{{end}}
|
||||||
|
default:
|
||||||
|
return "<unknown>"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsBuiltinActor(c cid.Cid) bool {
|
||||||
|
{{range .versions}}
|
||||||
|
if builtin{{.}}.IsBuiltinActor(c) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsAccountActor(c cid.Cid) bool {
|
||||||
|
{{range .versions}}
|
||||||
|
if c == builtin{{.}}.AccountActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsStorageMinerActor(c cid.Cid) bool {
|
||||||
|
{{range .versions}}
|
||||||
|
if c == builtin{{.}}.StorageMinerActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsMultisigActor(c cid.Cid) bool {
|
||||||
|
{{range .versions}}
|
||||||
|
if c == builtin{{.}}.MultisigActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsPaymentChannelActor(c cid.Cid) bool {
|
||||||
|
{{range .versions}}
|
||||||
|
if c == builtin{{.}}.PaymentChannelActorCodeID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeAddress(addr string) address.Address {
|
||||||
|
ret, err := address.NewFromString(addr)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
|
}
|
10
chain/actors/builtin/cron/actor.go.template
Normal file
10
chain/actors/builtin/cron/actor.go.template
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package cron
|
||||||
|
|
||||||
|
import (
|
||||||
|
builtin{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Address = builtin{{.latestVersion}}.CronActorAddr
|
||||||
|
Methods = builtin{{.latestVersion}}.MethodsCron
|
||||||
|
)
|
@ -1,10 +1,10 @@
|
|||||||
package cron
|
package cron
|
||||||
|
|
||||||
import (
|
import (
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Address = builtin4.CronActorAddr
|
Address = builtin5.CronActorAddr
|
||||||
Methods = builtin4.MethodsCron
|
Methods = builtin5.MethodsCron
|
||||||
)
|
)
|
||||||
|
60
chain/actors/builtin/init/actor.go.template
Normal file
60
chain/actors/builtin/init/actor.go.template
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
package init
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/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"
|
||||||
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
|
{{range .versions}}
|
||||||
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
||||||
|
{{end}}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
{{range .versions}}
|
||||||
|
builtin.RegisterActorState(builtin{{.}}.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load{{.}}(store, root)
|
||||||
|
})
|
||||||
|
{{end}}}
|
||||||
|
|
||||||
|
var (
|
||||||
|
Address = builtin{{.latestVersion}}.InitActorAddr
|
||||||
|
Methods = builtin{{.latestVersion}}.MethodsInit
|
||||||
|
)
|
||||||
|
|
||||||
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.InitActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
|
||||||
|
ResolveAddress(address address.Address) (address.Address, bool, error)
|
||||||
|
MapAddressToNewID(address address.Address) (address.Address, error)
|
||||||
|
NetworkName() (dtypes.NetworkName, error)
|
||||||
|
|
||||||
|
ForEachActor(func(id abi.ActorID, address address.Address) error) error
|
||||||
|
|
||||||
|
// Remove exists to support tooling that manipulates state for testing.
|
||||||
|
// It should not be used in production code, as init actor entries are
|
||||||
|
// immutable.
|
||||||
|
Remove(addrs ...address.Address) error
|
||||||
|
|
||||||
|
// Sets the network's name. This should only be used on upgrade/fork.
|
||||||
|
SetNetworkName(name string) error
|
||||||
|
|
||||||
|
addressMap() (adt.Map, error)
|
||||||
|
}
|
@ -14,41 +14,62 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin0.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin0.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load0(store, root)
|
return load0(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin2.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin2.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load2(store, root)
|
return load2(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin3.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin3.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load3(store, root)
|
return load3(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin4.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin4.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load4(store, root)
|
return load4(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builtin.RegisterActorState(builtin5.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load5(store, root)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Address = builtin4.InitActorAddr
|
Address = builtin5.InitActorAddr
|
||||||
Methods = builtin4.MethodsInit
|
Methods = builtin5.MethodsInit
|
||||||
)
|
)
|
||||||
|
|
||||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
switch act.Code {
|
switch act.Code {
|
||||||
|
|
||||||
case builtin0.InitActorCodeID:
|
case builtin0.InitActorCodeID:
|
||||||
return load0(store, act.Head)
|
return load0(store, act.Head)
|
||||||
|
|
||||||
case builtin2.InitActorCodeID:
|
case builtin2.InitActorCodeID:
|
||||||
return load2(store, act.Head)
|
return load2(store, act.Head)
|
||||||
|
|
||||||
case builtin3.InitActorCodeID:
|
case builtin3.InitActorCodeID:
|
||||||
return load3(store, act.Head)
|
return load3(store, act.Head)
|
||||||
|
|
||||||
case builtin4.InitActorCodeID:
|
case builtin4.InitActorCodeID:
|
||||||
return load4(store, act.Head)
|
return load4(store, act.Head)
|
||||||
|
|
||||||
|
case builtin5.InitActorCodeID:
|
||||||
|
return load5(store, act.Head)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
}
|
}
|
||||||
|
89
chain/actors/builtin/init/state.go.template
Normal file
89
chain/actors/builtin/init/state.go.template
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
{{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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state{{.v}})(nil)
|
||||||
|
|
||||||
|
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state{{.v}}{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state{{.v}} struct {
|
||||||
|
init{{.v}}.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) ResolveAddress(address address.Address) (address.Address, bool, error) {
|
||||||
|
return s.State.ResolveAddress(s.store, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) MapAddressToNewID(address address.Address) (address.Address, error) {
|
||||||
|
return s.State.MapAddressToNewID(s.store, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error {
|
||||||
|
addrs, err := adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
|
||||||
|
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 *state{{.v}}) NetworkName() (dtypes.NetworkName, error) {
|
||||||
|
return dtypes.NetworkName(s.State.NetworkName), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) SetNetworkName(name string) error {
|
||||||
|
s.State.NetworkName = name
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) {
|
||||||
|
m, err := adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
|
||||||
|
if err != nil {
|
||||||
|
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 *state{{.v}}) addressMap() (adt.Map, error) {
|
||||||
|
return adt{{.v}}.AsMap(s.store, s.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
|
||||||
|
}
|
@ -3,7 +3,6 @@ package init
|
|||||||
import (
|
import (
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
@ -11,6 +10,8 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
|
|
||||||
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init"
|
init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init"
|
||||||
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
|
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,6 @@ package init
|
|||||||
import (
|
import (
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
@ -11,6 +10,8 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
|
|
||||||
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
init4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/init"
|
init4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/init"
|
||||||
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
|
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
|
||||||
)
|
)
|
||||||
|
87
chain/actors/builtin/init/v5.go
Normal file
87
chain/actors/builtin/init/v5.go
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
|
||||||
|
init5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/init"
|
||||||
|
adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state5)(nil)
|
||||||
|
|
||||||
|
func load5(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state5{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state5 struct {
|
||||||
|
init5.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) ResolveAddress(address address.Address) (address.Address, bool, error) {
|
||||||
|
return s.State.ResolveAddress(s.store, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) MapAddressToNewID(address address.Address) (address.Address, error) {
|
||||||
|
return s.State.MapAddressToNewID(s.store, address)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) ForEachActor(cb func(id abi.ActorID, address address.Address) error) error {
|
||||||
|
addrs, err := adt5.AsMap(s.store, s.State.AddressMap, builtin5.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 *state5) NetworkName() (dtypes.NetworkName, error) {
|
||||||
|
return dtypes.NetworkName(s.State.NetworkName), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) SetNetworkName(name string) error {
|
||||||
|
s.State.NetworkName = name
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) Remove(addrs ...address.Address) (err error) {
|
||||||
|
m, err := adt5.AsMap(s.store, s.State.AddressMap, builtin5.DefaultHamtBitwidth)
|
||||||
|
if err != nil {
|
||||||
|
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 *state5) addressMap() (adt.Map, error) {
|
||||||
|
return adt5.AsMap(s.store, s.AddressMap, builtin5.DefaultHamtBitwidth)
|
||||||
|
}
|
142
chain/actors/builtin/market/actor.go.template
Normal file
142
chain/actors/builtin/market/actor.go.template
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
package market
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
|
|
||||||
|
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||||
|
{{range .versions}}
|
||||||
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
"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{{.}}.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) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.StorageMarketActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
BalancesChanged(State) (bool, error)
|
||||||
|
EscrowTable() (BalanceTable, error)
|
||||||
|
LockedTable() (BalanceTable, error)
|
||||||
|
TotalLocked() (abi.TokenAmount, error)
|
||||||
|
StatesChanged(State) (bool, error)
|
||||||
|
States() (DealStates, error)
|
||||||
|
ProposalsChanged(State) (bool, error)
|
||||||
|
Proposals() (DealProposals, error)
|
||||||
|
VerifyDealsForActivation(
|
||||||
|
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
|
||||||
|
) (weight, verifiedWeight abi.DealWeight, err error)
|
||||||
|
NextID() (abi.DealID, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type BalanceTable interface {
|
||||||
|
ForEach(cb func(address.Address, abi.TokenAmount) error) error
|
||||||
|
Get(key address.Address) (abi.TokenAmount, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DealStates interface {
|
||||||
|
ForEach(cb func(id abi.DealID, ds DealState) error) error
|
||||||
|
Get(id abi.DealID) (*DealState, bool, error)
|
||||||
|
|
||||||
|
array() adt.Array
|
||||||
|
decode(*cbg.Deferred) (*DealState, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DealProposals interface {
|
||||||
|
ForEach(cb func(id abi.DealID, dp DealProposal) error) error
|
||||||
|
Get(id abi.DealID) (*DealProposal, bool, error)
|
||||||
|
|
||||||
|
array() adt.Array
|
||||||
|
decode(*cbg.Deferred) (*DealProposal, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type PublishStorageDealsParams = market0.PublishStorageDealsParams
|
||||||
|
type PublishStorageDealsReturn = market0.PublishStorageDealsReturn
|
||||||
|
type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams
|
||||||
|
type WithdrawBalanceParams = market0.WithdrawBalanceParams
|
||||||
|
|
||||||
|
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 DealStateChanges struct {
|
||||||
|
Added []DealIDState
|
||||||
|
Modified []DealStateChange
|
||||||
|
Removed []DealIDState
|
||||||
|
}
|
||||||
|
|
||||||
|
type DealIDState struct {
|
||||||
|
ID abi.DealID
|
||||||
|
Deal DealState
|
||||||
|
}
|
||||||
|
|
||||||
|
// DealStateChange is a change in deal state from -> to
|
||||||
|
type DealStateChange struct {
|
||||||
|
ID abi.DealID
|
||||||
|
From *DealState
|
||||||
|
To *DealState
|
||||||
|
}
|
||||||
|
|
||||||
|
type DealProposalChanges struct {
|
||||||
|
Added []ProposalIDState
|
||||||
|
Removed []ProposalIDState
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProposalIDState struct {
|
||||||
|
ID abi.DealID
|
||||||
|
Proposal DealProposal
|
||||||
|
}
|
||||||
|
|
||||||
|
func EmptyDealState() *DealState {
|
||||||
|
return &DealState{
|
||||||
|
SectorStartEpoch: -1,
|
||||||
|
SlashEpoch: -1,
|
||||||
|
LastUpdatedEpoch: -1,
|
||||||
|
}
|
||||||
|
}
|
@ -9,47 +9,69 @@ import (
|
|||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
|
||||||
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
|
||||||
|
|
||||||
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin0.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin0.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load0(store, root)
|
return load0(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin2.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin2.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load2(store, root)
|
return load2(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin3.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin3.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load3(store, root)
|
return load3(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin4.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin4.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load4(store, root)
|
return load4(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builtin.RegisterActorState(builtin5.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load5(store, root)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Address = builtin4.StorageMarketActorAddr
|
Address = builtin5.StorageMarketActorAddr
|
||||||
Methods = builtin4.MethodsMarket
|
Methods = builtin5.MethodsMarket
|
||||||
)
|
)
|
||||||
|
|
||||||
func Load(store adt.Store, act *types.Actor) (st State, err error) {
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
switch act.Code {
|
switch act.Code {
|
||||||
|
|
||||||
case builtin0.StorageMarketActorCodeID:
|
case builtin0.StorageMarketActorCodeID:
|
||||||
return load0(store, act.Head)
|
return load0(store, act.Head)
|
||||||
|
|
||||||
case builtin2.StorageMarketActorCodeID:
|
case builtin2.StorageMarketActorCodeID:
|
||||||
return load2(store, act.Head)
|
return load2(store, act.Head)
|
||||||
|
|
||||||
case builtin3.StorageMarketActorCodeID:
|
case builtin3.StorageMarketActorCodeID:
|
||||||
return load3(store, act.Head)
|
return load3(store, act.Head)
|
||||||
|
|
||||||
case builtin4.StorageMarketActorCodeID:
|
case builtin4.StorageMarketActorCodeID:
|
||||||
return load4(store, act.Head)
|
return load4(store, act.Head)
|
||||||
|
|
||||||
|
case builtin5.StorageMarketActorCodeID:
|
||||||
|
return load5(store, act.Head)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
}
|
}
|
||||||
|
209
chain/actors/builtin/market/state.go.template
Normal file
209
chain/actors/builtin/market/state.go.template
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
|
market{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/market"
|
||||||
|
adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state{{.v}})(nil)
|
||||||
|
|
||||||
|
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state{{.v}}{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state{{.v}} struct {
|
||||||
|
market{{.v}}.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) TotalLocked() (abi.TokenAmount, error) {
|
||||||
|
fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral)
|
||||||
|
fml = types.BigAdd(fml, s.TotalClientStorageFee)
|
||||||
|
return fml, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) BalancesChanged(otherState State) (bool, error) {
|
||||||
|
otherState{{.v}}, ok := otherState.(*state{{.v}})
|
||||||
|
if !ok {
|
||||||
|
// there's no way to compare different versions of the state, so let's
|
||||||
|
// just say that means the state of balances has changed
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.EscrowTable.Equals(otherState{{.v}}.State.EscrowTable) || !s.State.LockedTable.Equals(otherState{{.v}}.State.LockedTable), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) StatesChanged(otherState State) (bool, error) {
|
||||||
|
otherState{{.v}}, ok := otherState.(*state{{.v}})
|
||||||
|
if !ok {
|
||||||
|
// there's no way to compare different versions of the state, so let's
|
||||||
|
// just say that means the state of balances has changed
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.States.Equals(otherState{{.v}}.State.States), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) States() (DealStates, error) {
|
||||||
|
stateArray, err := adt{{.v}}.AsArray(s.store, s.State.States{{if (ge .v 3)}}, market{{.v}}.StatesAmtBitwidth{{end}})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &dealStates{{.v}}{stateArray}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) ProposalsChanged(otherState State) (bool, error) {
|
||||||
|
otherState{{.v}}, ok := otherState.(*state{{.v}})
|
||||||
|
if !ok {
|
||||||
|
// there's no way to compare different versions of the state, so let's
|
||||||
|
// just say that means the state of balances has changed
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.Proposals.Equals(otherState{{.v}}.State.Proposals), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) Proposals() (DealProposals, error) {
|
||||||
|
proposalArray, err := adt{{.v}}.AsArray(s.store, s.State.Proposals{{if (ge .v 3)}}, market{{.v}}.ProposalsAmtBitwidth{{end}})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &dealProposals{{.v}}{proposalArray}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) EscrowTable() (BalanceTable, error) {
|
||||||
|
bt, err := adt{{.v}}.AsBalanceTable(s.store, s.State.EscrowTable)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &balanceTable{{.v}}{bt}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) LockedTable() (BalanceTable, error) {
|
||||||
|
bt, err := adt{{.v}}.AsBalanceTable(s.store, s.State.LockedTable)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &balanceTable{{.v}}{bt}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) VerifyDealsForActivation(
|
||||||
|
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
|
||||||
|
) (weight, verifiedWeight abi.DealWeight, err error) {
|
||||||
|
w, vw{{if (ge .v 2)}}, _{{end}}, err := market{{.v}}.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch)
|
||||||
|
return w, vw, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) NextID() (abi.DealID, error) {
|
||||||
|
return s.State.NextID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type balanceTable{{.v}} struct {
|
||||||
|
*adt{{.v}}.BalanceTable
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bt *balanceTable{{.v}}) ForEach(cb func(address.Address, abi.TokenAmount) error) error {
|
||||||
|
asMap := (*adt{{.v}}.Map)(bt.BalanceTable)
|
||||||
|
var ta abi.TokenAmount
|
||||||
|
return asMap.ForEach(&ta, func(key string) error {
|
||||||
|
a, err := address.NewFromBytes([]byte(key))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return cb(a, ta)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type dealStates{{.v}} struct {
|
||||||
|
adt.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealStates{{.v}}) Get(dealID abi.DealID) (*DealState, bool, error) {
|
||||||
|
var deal{{.v}} market{{.v}}.DealState
|
||||||
|
found, err := s.Array.Get(uint64(dealID), &deal{{.v}})
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return nil, false, nil
|
||||||
|
}
|
||||||
|
deal := fromV{{.v}}DealState(deal{{.v}})
|
||||||
|
return &deal, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealStates{{.v}}) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
||||||
|
var ds{{.v}} market{{.v}}.DealState
|
||||||
|
return s.Array.ForEach(&ds{{.v}}, func(idx int64) error {
|
||||||
|
return cb(abi.DealID(idx), fromV{{.v}}DealState(ds{{.v}}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealStates{{.v}}) decode(val *cbg.Deferred) (*DealState, error) {
|
||||||
|
var ds{{.v}} market{{.v}}.DealState
|
||||||
|
if err := ds{{.v}}.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ds := fromV{{.v}}DealState(ds{{.v}})
|
||||||
|
return &ds, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealStates{{.v}}) array() adt.Array {
|
||||||
|
return s.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV{{.v}}DealState(v{{.v}} market{{.v}}.DealState) DealState {
|
||||||
|
return (DealState)(v{{.v}})
|
||||||
|
}
|
||||||
|
|
||||||
|
type dealProposals{{.v}} struct {
|
||||||
|
adt.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealProposals{{.v}}) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
||||||
|
var proposal{{.v}} market{{.v}}.DealProposal
|
||||||
|
found, err := s.Array.Get(uint64(dealID), &proposal{{.v}})
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return nil, false, nil
|
||||||
|
}
|
||||||
|
proposal := fromV{{.v}}DealProposal(proposal{{.v}})
|
||||||
|
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}}))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealProposals{{.v}}) decode(val *cbg.Deferred) (*DealProposal, error) {
|
||||||
|
var dp{{.v}} market{{.v}}.DealProposal
|
||||||
|
if err := dp{{.v}}.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dp := fromV{{.v}}DealProposal(dp{{.v}})
|
||||||
|
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}})
|
||||||
|
}
|
@ -102,7 +102,8 @@ func (s *state0) LockedTable() (BalanceTable, error) {
|
|||||||
func (s *state0) VerifyDealsForActivation(
|
func (s *state0) VerifyDealsForActivation(
|
||||||
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
|
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
|
||||||
) (weight, verifiedWeight abi.DealWeight, err error) {
|
) (weight, verifiedWeight abi.DealWeight, err error) {
|
||||||
return market0.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch)
|
w, vw, err := market0.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch)
|
||||||
|
return w, vw, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) NextID() (abi.DealID, error) {
|
func (s *state0) NextID() (abi.DealID, error) {
|
||||||
|
@ -144,18 +144,18 @@ func (s *dealStates2) Get(dealID abi.DealID) (*DealState, bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealStates2) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
func (s *dealStates2) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
||||||
var ds1 market2.DealState
|
var ds2 market2.DealState
|
||||||
return s.Array.ForEach(&ds1, func(idx int64) error {
|
return s.Array.ForEach(&ds2, func(idx int64) error {
|
||||||
return cb(abi.DealID(idx), fromV2DealState(ds1))
|
return cb(abi.DealID(idx), fromV2DealState(ds2))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealStates2) decode(val *cbg.Deferred) (*DealState, error) {
|
func (s *dealStates2) decode(val *cbg.Deferred) (*DealState, error) {
|
||||||
var ds1 market2.DealState
|
var ds2 market2.DealState
|
||||||
if err := ds1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
if err := ds2.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ds := fromV2DealState(ds1)
|
ds := fromV2DealState(ds2)
|
||||||
return &ds, nil
|
return &ds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,8 +163,8 @@ func (s *dealStates2) array() adt.Array {
|
|||||||
return s.Array
|
return s.Array
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromV2DealState(v1 market2.DealState) DealState {
|
func fromV2DealState(v2 market2.DealState) DealState {
|
||||||
return (DealState)(v1)
|
return (DealState)(v2)
|
||||||
}
|
}
|
||||||
|
|
||||||
type dealProposals2 struct {
|
type dealProposals2 struct {
|
||||||
@ -185,18 +185,18 @@ func (s *dealProposals2) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealProposals2) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
|
func (s *dealProposals2) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
|
||||||
var dp1 market2.DealProposal
|
var dp2 market2.DealProposal
|
||||||
return s.Array.ForEach(&dp1, func(idx int64) error {
|
return s.Array.ForEach(&dp2, func(idx int64) error {
|
||||||
return cb(abi.DealID(idx), fromV2DealProposal(dp1))
|
return cb(abi.DealID(idx), fromV2DealProposal(dp2))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealProposals2) decode(val *cbg.Deferred) (*DealProposal, error) {
|
func (s *dealProposals2) decode(val *cbg.Deferred) (*DealProposal, error) {
|
||||||
var dp1 market2.DealProposal
|
var dp2 market2.DealProposal
|
||||||
if err := dp1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
if err := dp2.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dp := fromV2DealProposal(dp1)
|
dp := fromV2DealProposal(dp2)
|
||||||
return &dp, nil
|
return &dp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +204,6 @@ func (s *dealProposals2) array() adt.Array {
|
|||||||
return s.Array
|
return s.Array
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromV2DealProposal(v1 market2.DealProposal) DealProposal {
|
func fromV2DealProposal(v2 market2.DealProposal) DealProposal {
|
||||||
return (DealProposal)(v1)
|
return (DealProposal)(v2)
|
||||||
}
|
}
|
||||||
|
@ -38,23 +38,23 @@ func (s *state3) TotalLocked() (abi.TokenAmount, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) BalancesChanged(otherState State) (bool, error) {
|
func (s *state3) BalancesChanged(otherState State) (bool, error) {
|
||||||
otherState2, ok := otherState.(*state3)
|
otherState3, ok := otherState.(*state3)
|
||||||
if !ok {
|
if !ok {
|
||||||
// there's no way to compare different versions of the state, so let's
|
// there's no way to compare different versions of the state, so let's
|
||||||
// just say that means the state of balances has changed
|
// just say that means the state of balances has changed
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.EscrowTable.Equals(otherState2.State.EscrowTable) || !s.State.LockedTable.Equals(otherState2.State.LockedTable), nil
|
return !s.State.EscrowTable.Equals(otherState3.State.EscrowTable) || !s.State.LockedTable.Equals(otherState3.State.LockedTable), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) StatesChanged(otherState State) (bool, error) {
|
func (s *state3) StatesChanged(otherState State) (bool, error) {
|
||||||
otherState2, ok := otherState.(*state3)
|
otherState3, ok := otherState.(*state3)
|
||||||
if !ok {
|
if !ok {
|
||||||
// there's no way to compare different versions of the state, so let's
|
// there's no way to compare different versions of the state, so let's
|
||||||
// just say that means the state of balances has changed
|
// just say that means the state of balances has changed
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.States.Equals(otherState2.State.States), nil
|
return !s.State.States.Equals(otherState3.State.States), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) States() (DealStates, error) {
|
func (s *state3) States() (DealStates, error) {
|
||||||
@ -66,13 +66,13 @@ func (s *state3) States() (DealStates, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) ProposalsChanged(otherState State) (bool, error) {
|
func (s *state3) ProposalsChanged(otherState State) (bool, error) {
|
||||||
otherState2, ok := otherState.(*state3)
|
otherState3, ok := otherState.(*state3)
|
||||||
if !ok {
|
if !ok {
|
||||||
// there's no way to compare different versions of the state, so let's
|
// there's no way to compare different versions of the state, so let's
|
||||||
// just say that means the state of balances has changed
|
// just say that means the state of balances has changed
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.Proposals.Equals(otherState2.State.Proposals), nil
|
return !s.State.Proposals.Equals(otherState3.State.Proposals), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) Proposals() (DealProposals, error) {
|
func (s *state3) Proposals() (DealProposals, error) {
|
||||||
@ -131,31 +131,31 @@ type dealStates3 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealStates3) Get(dealID abi.DealID) (*DealState, bool, error) {
|
func (s *dealStates3) Get(dealID abi.DealID) (*DealState, bool, error) {
|
||||||
var deal2 market3.DealState
|
var deal3 market3.DealState
|
||||||
found, err := s.Array.Get(uint64(dealID), &deal2)
|
found, err := s.Array.Get(uint64(dealID), &deal3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
deal := fromV3DealState(deal2)
|
deal := fromV3DealState(deal3)
|
||||||
return &deal, true, nil
|
return &deal, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealStates3) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
func (s *dealStates3) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
||||||
var ds1 market3.DealState
|
var ds3 market3.DealState
|
||||||
return s.Array.ForEach(&ds1, func(idx int64) error {
|
return s.Array.ForEach(&ds3, func(idx int64) error {
|
||||||
return cb(abi.DealID(idx), fromV3DealState(ds1))
|
return cb(abi.DealID(idx), fromV3DealState(ds3))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealStates3) decode(val *cbg.Deferred) (*DealState, error) {
|
func (s *dealStates3) decode(val *cbg.Deferred) (*DealState, error) {
|
||||||
var ds1 market3.DealState
|
var ds3 market3.DealState
|
||||||
if err := ds1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
if err := ds3.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ds := fromV3DealState(ds1)
|
ds := fromV3DealState(ds3)
|
||||||
return &ds, nil
|
return &ds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,8 +163,8 @@ func (s *dealStates3) array() adt.Array {
|
|||||||
return s.Array
|
return s.Array
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromV3DealState(v1 market3.DealState) DealState {
|
func fromV3DealState(v3 market3.DealState) DealState {
|
||||||
return (DealState)(v1)
|
return (DealState)(v3)
|
||||||
}
|
}
|
||||||
|
|
||||||
type dealProposals3 struct {
|
type dealProposals3 struct {
|
||||||
@ -172,31 +172,31 @@ type dealProposals3 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealProposals3) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
func (s *dealProposals3) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
||||||
var proposal2 market3.DealProposal
|
var proposal3 market3.DealProposal
|
||||||
found, err := s.Array.Get(uint64(dealID), &proposal2)
|
found, err := s.Array.Get(uint64(dealID), &proposal3)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
proposal := fromV3DealProposal(proposal2)
|
proposal := fromV3DealProposal(proposal3)
|
||||||
return &proposal, true, nil
|
return &proposal, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealProposals3) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
|
func (s *dealProposals3) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
|
||||||
var dp1 market3.DealProposal
|
var dp3 market3.DealProposal
|
||||||
return s.Array.ForEach(&dp1, func(idx int64) error {
|
return s.Array.ForEach(&dp3, func(idx int64) error {
|
||||||
return cb(abi.DealID(idx), fromV3DealProposal(dp1))
|
return cb(abi.DealID(idx), fromV3DealProposal(dp3))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealProposals3) decode(val *cbg.Deferred) (*DealProposal, error) {
|
func (s *dealProposals3) decode(val *cbg.Deferred) (*DealProposal, error) {
|
||||||
var dp1 market3.DealProposal
|
var dp3 market3.DealProposal
|
||||||
if err := dp1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
if err := dp3.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dp := fromV3DealProposal(dp1)
|
dp := fromV3DealProposal(dp3)
|
||||||
return &dp, nil
|
return &dp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +204,6 @@ func (s *dealProposals3) array() adt.Array {
|
|||||||
return s.Array
|
return s.Array
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromV3DealProposal(v1 market3.DealProposal) DealProposal {
|
func fromV3DealProposal(v3 market3.DealProposal) DealProposal {
|
||||||
return (DealProposal)(v1)
|
return (DealProposal)(v3)
|
||||||
}
|
}
|
||||||
|
@ -38,23 +38,23 @@ func (s *state4) TotalLocked() (abi.TokenAmount, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) BalancesChanged(otherState State) (bool, error) {
|
func (s *state4) BalancesChanged(otherState State) (bool, error) {
|
||||||
otherState2, ok := otherState.(*state4)
|
otherState4, ok := otherState.(*state4)
|
||||||
if !ok {
|
if !ok {
|
||||||
// there's no way to compare different versions of the state, so let's
|
// there's no way to compare different versions of the state, so let's
|
||||||
// just say that means the state of balances has changed
|
// just say that means the state of balances has changed
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.EscrowTable.Equals(otherState2.State.EscrowTable) || !s.State.LockedTable.Equals(otherState2.State.LockedTable), nil
|
return !s.State.EscrowTable.Equals(otherState4.State.EscrowTable) || !s.State.LockedTable.Equals(otherState4.State.LockedTable), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) StatesChanged(otherState State) (bool, error) {
|
func (s *state4) StatesChanged(otherState State) (bool, error) {
|
||||||
otherState2, ok := otherState.(*state4)
|
otherState4, ok := otherState.(*state4)
|
||||||
if !ok {
|
if !ok {
|
||||||
// there's no way to compare different versions of the state, so let's
|
// there's no way to compare different versions of the state, so let's
|
||||||
// just say that means the state of balances has changed
|
// just say that means the state of balances has changed
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.States.Equals(otherState2.State.States), nil
|
return !s.State.States.Equals(otherState4.State.States), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) States() (DealStates, error) {
|
func (s *state4) States() (DealStates, error) {
|
||||||
@ -66,13 +66,13 @@ func (s *state4) States() (DealStates, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) ProposalsChanged(otherState State) (bool, error) {
|
func (s *state4) ProposalsChanged(otherState State) (bool, error) {
|
||||||
otherState2, ok := otherState.(*state4)
|
otherState4, ok := otherState.(*state4)
|
||||||
if !ok {
|
if !ok {
|
||||||
// there's no way to compare different versions of the state, so let's
|
// there's no way to compare different versions of the state, so let's
|
||||||
// just say that means the state of balances has changed
|
// just say that means the state of balances has changed
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.Proposals.Equals(otherState2.State.Proposals), nil
|
return !s.State.Proposals.Equals(otherState4.State.Proposals), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) Proposals() (DealProposals, error) {
|
func (s *state4) Proposals() (DealProposals, error) {
|
||||||
@ -131,31 +131,31 @@ type dealStates4 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealStates4) Get(dealID abi.DealID) (*DealState, bool, error) {
|
func (s *dealStates4) Get(dealID abi.DealID) (*DealState, bool, error) {
|
||||||
var deal2 market4.DealState
|
var deal4 market4.DealState
|
||||||
found, err := s.Array.Get(uint64(dealID), &deal2)
|
found, err := s.Array.Get(uint64(dealID), &deal4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
deal := fromV4DealState(deal2)
|
deal := fromV4DealState(deal4)
|
||||||
return &deal, true, nil
|
return &deal, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealStates4) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
func (s *dealStates4) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
||||||
var ds1 market4.DealState
|
var ds4 market4.DealState
|
||||||
return s.Array.ForEach(&ds1, func(idx int64) error {
|
return s.Array.ForEach(&ds4, func(idx int64) error {
|
||||||
return cb(abi.DealID(idx), fromV4DealState(ds1))
|
return cb(abi.DealID(idx), fromV4DealState(ds4))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealStates4) decode(val *cbg.Deferred) (*DealState, error) {
|
func (s *dealStates4) decode(val *cbg.Deferred) (*DealState, error) {
|
||||||
var ds1 market4.DealState
|
var ds4 market4.DealState
|
||||||
if err := ds1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
if err := ds4.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ds := fromV4DealState(ds1)
|
ds := fromV4DealState(ds4)
|
||||||
return &ds, nil
|
return &ds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,31 +172,31 @@ type dealProposals4 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealProposals4) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
func (s *dealProposals4) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
||||||
var proposal2 market4.DealProposal
|
var proposal4 market4.DealProposal
|
||||||
found, err := s.Array.Get(uint64(dealID), &proposal2)
|
found, err := s.Array.Get(uint64(dealID), &proposal4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
proposal := fromV4DealProposal(proposal2)
|
proposal := fromV4DealProposal(proposal4)
|
||||||
return &proposal, true, nil
|
return &proposal, true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealProposals4) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
|
func (s *dealProposals4) ForEach(cb func(dealID abi.DealID, dp DealProposal) error) error {
|
||||||
var dp1 market4.DealProposal
|
var dp4 market4.DealProposal
|
||||||
return s.Array.ForEach(&dp1, func(idx int64) error {
|
return s.Array.ForEach(&dp4, func(idx int64) error {
|
||||||
return cb(abi.DealID(idx), fromV4DealProposal(dp1))
|
return cb(abi.DealID(idx), fromV4DealProposal(dp4))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *dealProposals4) decode(val *cbg.Deferred) (*DealProposal, error) {
|
func (s *dealProposals4) decode(val *cbg.Deferred) (*DealProposal, error) {
|
||||||
var dp1 market4.DealProposal
|
var dp4 market4.DealProposal
|
||||||
if err := dp1.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
if err := dp4.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dp := fromV4DealProposal(dp1)
|
dp := fromV4DealProposal(dp4)
|
||||||
return &dp, nil
|
return &dp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
209
chain/actors/builtin/market/v5.go
Normal file
209
chain/actors/builtin/market/v5.go
Normal file
@ -0,0 +1,209 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
|
market5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/market"
|
||||||
|
adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state5)(nil)
|
||||||
|
|
||||||
|
func load5(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state5{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state5 struct {
|
||||||
|
market5.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) TotalLocked() (abi.TokenAmount, error) {
|
||||||
|
fml := types.BigAdd(s.TotalClientLockedCollateral, s.TotalProviderLockedCollateral)
|
||||||
|
fml = types.BigAdd(fml, s.TotalClientStorageFee)
|
||||||
|
return fml, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) BalancesChanged(otherState State) (bool, error) {
|
||||||
|
otherState5, ok := otherState.(*state5)
|
||||||
|
if !ok {
|
||||||
|
// there's no way to compare different versions of the state, so let's
|
||||||
|
// just say that means the state of balances has changed
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.EscrowTable.Equals(otherState5.State.EscrowTable) || !s.State.LockedTable.Equals(otherState5.State.LockedTable), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) StatesChanged(otherState State) (bool, error) {
|
||||||
|
otherState5, ok := otherState.(*state5)
|
||||||
|
if !ok {
|
||||||
|
// there's no way to compare different versions of the state, so let's
|
||||||
|
// just say that means the state of balances has changed
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.States.Equals(otherState5.State.States), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) States() (DealStates, error) {
|
||||||
|
stateArray, err := adt5.AsArray(s.store, s.State.States, market5.StatesAmtBitwidth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &dealStates5{stateArray}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) ProposalsChanged(otherState State) (bool, error) {
|
||||||
|
otherState5, ok := otherState.(*state5)
|
||||||
|
if !ok {
|
||||||
|
// there's no way to compare different versions of the state, so let's
|
||||||
|
// just say that means the state of balances has changed
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.Proposals.Equals(otherState5.State.Proposals), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) Proposals() (DealProposals, error) {
|
||||||
|
proposalArray, err := adt5.AsArray(s.store, s.State.Proposals, market5.ProposalsAmtBitwidth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &dealProposals5{proposalArray}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) EscrowTable() (BalanceTable, error) {
|
||||||
|
bt, err := adt5.AsBalanceTable(s.store, s.State.EscrowTable)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &balanceTable5{bt}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) LockedTable() (BalanceTable, error) {
|
||||||
|
bt, err := adt5.AsBalanceTable(s.store, s.State.LockedTable)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &balanceTable5{bt}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) VerifyDealsForActivation(
|
||||||
|
minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch,
|
||||||
|
) (weight, verifiedWeight abi.DealWeight, err error) {
|
||||||
|
w, vw, _, err := market5.ValidateDealsForActivation(&s.State, s.store, deals, minerAddr, sectorExpiry, currEpoch)
|
||||||
|
return w, vw, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) NextID() (abi.DealID, error) {
|
||||||
|
return s.State.NextID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type balanceTable5 struct {
|
||||||
|
*adt5.BalanceTable
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bt *balanceTable5) ForEach(cb func(address.Address, abi.TokenAmount) error) error {
|
||||||
|
asMap := (*adt5.Map)(bt.BalanceTable)
|
||||||
|
var ta abi.TokenAmount
|
||||||
|
return asMap.ForEach(&ta, func(key string) error {
|
||||||
|
a, err := address.NewFromBytes([]byte(key))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return cb(a, ta)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type dealStates5 struct {
|
||||||
|
adt.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealStates5) Get(dealID abi.DealID) (*DealState, bool, error) {
|
||||||
|
var deal5 market5.DealState
|
||||||
|
found, err := s.Array.Get(uint64(dealID), &deal5)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return nil, false, nil
|
||||||
|
}
|
||||||
|
deal := fromV5DealState(deal5)
|
||||||
|
return &deal, true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealStates5) ForEach(cb func(dealID abi.DealID, ds DealState) error) error {
|
||||||
|
var ds5 market5.DealState
|
||||||
|
return s.Array.ForEach(&ds5, func(idx int64) error {
|
||||||
|
return cb(abi.DealID(idx), fromV5DealState(ds5))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealStates5) decode(val *cbg.Deferred) (*DealState, error) {
|
||||||
|
var ds5 market5.DealState
|
||||||
|
if err := ds5.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ds := fromV5DealState(ds5)
|
||||||
|
return &ds, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealStates5) array() adt.Array {
|
||||||
|
return s.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV5DealState(v5 market5.DealState) DealState {
|
||||||
|
return (DealState)(v5)
|
||||||
|
}
|
||||||
|
|
||||||
|
type dealProposals5 struct {
|
||||||
|
adt.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealProposals5) Get(dealID abi.DealID) (*DealProposal, bool, error) {
|
||||||
|
var proposal5 market5.DealProposal
|
||||||
|
found, err := s.Array.Get(uint64(dealID), &proposal5)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false, err
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return nil, false, nil
|
||||||
|
}
|
||||||
|
proposal := fromV5DealProposal(proposal5)
|
||||||
|
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))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealProposals5) decode(val *cbg.Deferred) (*DealProposal, error) {
|
||||||
|
var dp5 market5.DealProposal
|
||||||
|
if err := dp5.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dp := fromV5DealProposal(dp5)
|
||||||
|
return &dp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *dealProposals5) array() adt.Array {
|
||||||
|
return s.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV5DealProposal(v5 market5.DealProposal) DealProposal {
|
||||||
|
return (DealProposal)(v5)
|
||||||
|
}
|
270
chain/actors/builtin/miner/actor.go.template
Normal file
270
chain/actors/builtin/miner/actor.go.template
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
package miner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
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/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"
|
||||||
|
{{range .versions}}
|
||||||
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
||||||
|
{{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, and v4 actors
|
||||||
|
var WPoStProvingPeriod = miner0.WPoStProvingPeriod
|
||||||
|
var WPoStPeriodDeadlines = miner0.WPoStPeriodDeadlines
|
||||||
|
var WPoStChallengeWindow = miner0.WPoStChallengeWindow
|
||||||
|
var WPoStChallengeLookback = miner0.WPoStChallengeLookback
|
||||||
|
var FaultDeclarationCutoff = miner0.FaultDeclarationCutoff
|
||||||
|
|
||||||
|
const MinSectorExpiration = miner0.MinSectorExpiration
|
||||||
|
|
||||||
|
// Not used / checked in v0
|
||||||
|
// TODO: Abstract over network versions
|
||||||
|
var DeclarationsMax = miner2.DeclarationsMax
|
||||||
|
var AddressedSectorsMax = miner2.AddressedSectorsMax
|
||||||
|
|
||||||
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.StorageMinerActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
|
||||||
|
// Total available balance to spend.
|
||||||
|
AvailableBalance(abi.TokenAmount) (abi.TokenAmount, error)
|
||||||
|
// Funds that will vest by the given epoch.
|
||||||
|
VestedFunds(abi.ChainEpoch) (abi.TokenAmount, error)
|
||||||
|
// Funds locked for various reasons.
|
||||||
|
LockedFunds() (LockedFunds, error)
|
||||||
|
FeeDebt() (abi.TokenAmount, error)
|
||||||
|
|
||||||
|
GetSector(abi.SectorNumber) (*SectorOnChainInfo, error)
|
||||||
|
FindSector(abi.SectorNumber) (*SectorLocation, error)
|
||||||
|
GetSectorExpiration(abi.SectorNumber) (*SectorExpiration, error)
|
||||||
|
GetPrecommittedSector(abi.SectorNumber) (*SectorPreCommitOnChainInfo, error)
|
||||||
|
LoadSectors(sectorNos *bitfield.BitField) ([]*SectorOnChainInfo, error)
|
||||||
|
NumLiveSectors() (uint64, error)
|
||||||
|
IsAllocated(abi.SectorNumber) (bool, error)
|
||||||
|
|
||||||
|
LoadDeadline(idx uint64) (Deadline, error)
|
||||||
|
ForEachDeadline(cb func(idx uint64, dl Deadline) error) error
|
||||||
|
NumDeadlines() (uint64, error)
|
||||||
|
DeadlinesChanged(State) (bool, error)
|
||||||
|
|
||||||
|
Info() (MinerInfo, error)
|
||||||
|
MinerInfoChanged(State) (bool, error)
|
||||||
|
|
||||||
|
DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error)
|
||||||
|
DeadlineCronActive() (bool, error)
|
||||||
|
|
||||||
|
// Diff helpers. Used by Diff* functions internally.
|
||||||
|
sectors() (adt.Array, error)
|
||||||
|
decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error)
|
||||||
|
precommits() (adt.Map, error)
|
||||||
|
decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Deadline interface {
|
||||||
|
LoadPartition(idx uint64) (Partition, error)
|
||||||
|
ForEachPartition(cb func(idx uint64, part Partition) error) error
|
||||||
|
PartitionsPoSted() (bitfield.BitField, error)
|
||||||
|
|
||||||
|
PartitionsChanged(Deadline) (bool, error)
|
||||||
|
DisputableProofCount() (uint64, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Partition interface {
|
||||||
|
AllSectors() (bitfield.BitField, error)
|
||||||
|
FaultySectors() (bitfield.BitField, error)
|
||||||
|
RecoveringSectors() (bitfield.BitField, error)
|
||||||
|
LiveSectors() (bitfield.BitField, error)
|
||||||
|
ActiveSectors() (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
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectorPreCommitInfo = miner0.SectorPreCommitInfo
|
||||||
|
|
||||||
|
type SectorPreCommitOnChainInfo struct {
|
||||||
|
Info SectorPreCommitInfo
|
||||||
|
PreCommitDeposit abi.TokenAmount
|
||||||
|
PreCommitEpoch abi.ChainEpoch
|
||||||
|
DealWeight abi.DealWeight
|
||||||
|
VerifiedDealWeight abi.DealWeight
|
||||||
|
}
|
||||||
|
|
||||||
|
type PoStPartition = miner0.PoStPartition
|
||||||
|
type RecoveryDeclaration = miner0.RecoveryDeclaration
|
||||||
|
type FaultDeclaration = miner0.FaultDeclaration
|
||||||
|
|
||||||
|
// Params
|
||||||
|
type DeclareFaultsParams = miner0.DeclareFaultsParams
|
||||||
|
type DeclareFaultsRecoveredParams = miner0.DeclareFaultsRecoveredParams
|
||||||
|
type SubmitWindowedPoStParams = miner0.SubmitWindowedPoStParams
|
||||||
|
type ProveCommitSectorParams = miner0.ProveCommitSectorParams
|
||||||
|
type DisputeWindowedPoStParams = miner3.DisputeWindowedPoStParams
|
||||||
|
|
||||||
|
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
|
||||||
|
// ones in network version 8.
|
||||||
|
if nver < network.Version7 {
|
||||||
|
switch proof {
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg2KiBV1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg8MiBV1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg512MiBV1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg32GiBV1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg64GiBV1, nil
|
||||||
|
default:
|
||||||
|
return -1, xerrors.Errorf("unrecognized window post type: %d", proof)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch proof {
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg2KiBV1_1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg8MiBV1_1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg512MiBV1_1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg32GiBV1_1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1:
|
||||||
|
return abi.RegisteredSealProof_StackedDrg64GiBV1_1, nil
|
||||||
|
default:
|
||||||
|
return -1, xerrors.Errorf("unrecognized window post type: %d", proof)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi.RegisteredPoStProof) (abi.RegisteredPoStProof, error) {
|
||||||
|
switch proof {
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow2KiBV1:
|
||||||
|
return abi.RegisteredPoStProof_StackedDrgWinning2KiBV1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow8MiBV1:
|
||||||
|
return abi.RegisteredPoStProof_StackedDrgWinning8MiBV1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow512MiBV1:
|
||||||
|
return abi.RegisteredPoStProof_StackedDrgWinning512MiBV1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow32GiBV1:
|
||||||
|
return abi.RegisteredPoStProof_StackedDrgWinning32GiBV1, nil
|
||||||
|
case abi.RegisteredPoStProof_StackedDrgWindow64GiBV1:
|
||||||
|
return abi.RegisteredPoStProof_StackedDrgWinning64GiBV1, nil
|
||||||
|
default:
|
||||||
|
return -1, xerrors.Errorf("unknown proof type %d", proof)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MinerInfo struct {
|
||||||
|
Owner address.Address // Must be an ID-address.
|
||||||
|
Worker address.Address // Must be an ID-address.
|
||||||
|
NewWorker address.Address // Must be an ID-address.
|
||||||
|
ControlAddresses []address.Address // Must be an ID-addresses.
|
||||||
|
WorkerChangeEpoch abi.ChainEpoch
|
||||||
|
PeerId *peer.ID
|
||||||
|
Multiaddrs []abi.Multiaddrs
|
||||||
|
WindowPoStProofType abi.RegisteredPoStProof
|
||||||
|
SectorSize abi.SectorSize
|
||||||
|
WindowPoStPartitionSectors uint64
|
||||||
|
ConsensusFaultElapsed abi.ChainEpoch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mi MinerInfo) IsController(addr address.Address) bool {
|
||||||
|
if addr == mi.Owner || addr == mi.Worker {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ca := range mi.ControlAddresses {
|
||||||
|
if addr == ca {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectorExpiration struct {
|
||||||
|
OnTime abi.ChainEpoch
|
||||||
|
|
||||||
|
// non-zero if sector is faulty, epoch at which it will be permanently
|
||||||
|
// removed if it doesn't recover
|
||||||
|
Early abi.ChainEpoch
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectorLocation struct {
|
||||||
|
Deadline uint64
|
||||||
|
Partition uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectorChanges struct {
|
||||||
|
Added []SectorOnChainInfo
|
||||||
|
Extended []SectorExtensions
|
||||||
|
Removed []SectorOnChainInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type SectorExtensions struct {
|
||||||
|
From SectorOnChainInfo
|
||||||
|
To SectorOnChainInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type PreCommitChanges struct {
|
||||||
|
Added []SectorPreCommitOnChainInfo
|
||||||
|
Removed []SectorPreCommitOnChainInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type LockedFunds struct {
|
||||||
|
VestingFunds abi.TokenAmount
|
||||||
|
InitialPledgeRequirement abi.TokenAmount
|
||||||
|
PreCommitDeposits abi.TokenAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lf LockedFunds) TotalLockedFunds() abi.TokenAmount {
|
||||||
|
return big.Add(lf.VestingFunds, big.Add(lf.InitialPledgeRequirement, lf.PreCommitDeposits))
|
||||||
|
}
|
@ -18,31 +18,46 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
|
||||||
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
miner0 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
||||||
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
|
miner2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/miner"
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
|
||||||
miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner"
|
miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner"
|
||||||
|
|
||||||
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
|
|
||||||
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin0.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin0.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load0(store, root)
|
return load0(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin2.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin2.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load2(store, root)
|
return load2(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin3.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin3.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load3(store, root)
|
return load3(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin4.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin4.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load4(store, root)
|
return load4(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builtin.RegisterActorState(builtin5.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load5(store, root)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Methods = builtin4.MethodsMiner
|
var Methods = builtin5.MethodsMiner
|
||||||
|
|
||||||
// Unchanged between v0, v2, v3, and v4 actors
|
// Unchanged between v0, v2, v3, and v4 actors
|
||||||
var WPoStProvingPeriod = miner0.WPoStProvingPeriod
|
var WPoStProvingPeriod = miner0.WPoStProvingPeriod
|
||||||
@ -58,16 +73,24 @@ const MinSectorExpiration = miner0.MinSectorExpiration
|
|||||||
var DeclarationsMax = miner2.DeclarationsMax
|
var DeclarationsMax = miner2.DeclarationsMax
|
||||||
var AddressedSectorsMax = miner2.AddressedSectorsMax
|
var AddressedSectorsMax = miner2.AddressedSectorsMax
|
||||||
|
|
||||||
func Load(store adt.Store, act *types.Actor) (st State, err error) {
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
switch act.Code {
|
switch act.Code {
|
||||||
|
|
||||||
case builtin0.StorageMinerActorCodeID:
|
case builtin0.StorageMinerActorCodeID:
|
||||||
return load0(store, act.Head)
|
return load0(store, act.Head)
|
||||||
|
|
||||||
case builtin2.StorageMinerActorCodeID:
|
case builtin2.StorageMinerActorCodeID:
|
||||||
return load2(store, act.Head)
|
return load2(store, act.Head)
|
||||||
|
|
||||||
case builtin3.StorageMinerActorCodeID:
|
case builtin3.StorageMinerActorCodeID:
|
||||||
return load3(store, act.Head)
|
return load3(store, act.Head)
|
||||||
|
|
||||||
case builtin4.StorageMinerActorCodeID:
|
case builtin4.StorageMinerActorCodeID:
|
||||||
return load4(store, act.Head)
|
return load4(store, act.Head)
|
||||||
|
|
||||||
|
case builtin5.StorageMinerActorCodeID:
|
||||||
|
return load5(store, act.Head)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
}
|
}
|
||||||
|
460
chain/actors/builtin/miner/state.go.template
Normal file
460
chain/actors/builtin/miner/state.go.template
Normal file
@ -0,0 +1,460 @@
|
|||||||
|
package miner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
{{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"
|
||||||
|
"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"
|
||||||
|
|
||||||
|
{{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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state{{.v}})(nil)
|
||||||
|
|
||||||
|
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state{{.v}}{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state{{.v}} struct {
|
||||||
|
miner{{.v}}.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
type deadline{{.v}} struct {
|
||||||
|
miner{{.v}}.Deadline
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
type partition{{.v}} struct {
|
||||||
|
miner{{.v}}.Partition
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) 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{{if (ge .v 2)}}, err{{end}} = s.GetAvailableBalance(bal)
|
||||||
|
return available, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||||
|
return s.CheckVestedFunds(s.store, epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) LockedFunds() (LockedFunds, error) {
|
||||||
|
return LockedFunds{
|
||||||
|
VestingFunds: s.State.LockedFunds,
|
||||||
|
InitialPledgeRequirement: s.State.InitialPledge{{if (le .v 1)}}Requirement{{end}},
|
||||||
|
PreCommitDeposits: s.State.PreCommitDeposits,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) FeeDebt() (abi.TokenAmount, error) {
|
||||||
|
return {{if (ge .v 2)}}s.State.FeeDebt{{else}}big.Zero(){{end}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) InitialPledge() (abi.TokenAmount, error) {
|
||||||
|
return s.State.InitialPledge{{if (le .v 1)}}Requirement{{end}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) PreCommitDeposits() (abi.TokenAmount, error) {
|
||||||
|
return s.State.PreCommitDeposits, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
|
||||||
|
info, ok, err := s.State.GetSector(s.store, num)
|
||||||
|
if !ok || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := fromV{{.v}}SectorOnChainInfo(*info)
|
||||||
|
return &ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) 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 *state{{.v}}) 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 *miner{{.v}}.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 *state{{.v}}) 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 either expire on-time (can be
|
||||||
|
// learned from the sector info), or in the next quantized expiration
|
||||||
|
// epoch (i.e., the first element in the partition's expiration queue.
|
||||||
|
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||||
|
// of the expiration queue.
|
||||||
|
stopErr := errors.New("stop")
|
||||||
|
out := SectorExpiration{}
|
||||||
|
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner{{.v}}.Deadline) error {
|
||||||
|
partitions, err := dl.PartitionsArray(s.store)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
quant := s.State.QuantSpecForDeadline(dlIdx)
|
||||||
|
var part miner{{.v}}.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 := miner{{.v}}.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant{{if (ge .v 3)}}, miner{{.v}}.PartitionExpirationAmtBitwidth{{end}})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var exp miner{{.v}}.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 *state{{.v}}) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) {
|
||||||
|
info, ok, err := s.State.GetPrecommittedSector(s.store, num)
|
||||||
|
if !ok || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := fromV{{.v}}SectorPreCommitOnChainInfo(*info)
|
||||||
|
|
||||||
|
return &ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
|
||||||
|
sectors, err := miner{{.v}}.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 info{{.v}} miner{{.v}}.SectorOnChainInfo
|
||||||
|
if err := sectors.ForEach(&info{{.v}}, func(_ int64) error {
|
||||||
|
info := fromV{{.v}}SectorOnChainInfo(info{{.v}})
|
||||||
|
infos = append(infos, &info)
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return infos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, load selected.
|
||||||
|
infos{{.v}}, err := sectors.Load(*snos)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
infos := make([]*SectorOnChainInfo, len(infos{{.v}}))
|
||||||
|
for i, info{{.v}} := range infos{{.v}} {
|
||||||
|
info := fromV{{.v}}SectorOnChainInfo(*info{{.v}})
|
||||||
|
infos[i] = &info
|
||||||
|
}
|
||||||
|
return infos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) IsAllocated(num abi.SectorNumber) (bool, error) {
|
||||||
|
var allocatedSectors bitfield.BitField
|
||||||
|
if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return allocatedSectors.IsSet(uint64(num))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) 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 &deadline{{.v}}{*dl, s.store}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) 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 *miner{{.v}}.Deadline) error {
|
||||||
|
return cb(i, &deadline{{.v}}{*dl, s.store})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) NumDeadlines() (uint64, error) {
|
||||||
|
return miner{{.v}}.WPoStPeriodDeadlines, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) DeadlinesChanged(other State) (bool, error) {
|
||||||
|
other{{.v}}, ok := other.(*state{{.v}})
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return !s.State.Deadlines.Equals(other{{.v}}.Deadlines), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) MinerInfoChanged(other State) (bool, error) {
|
||||||
|
other0, ok := other.(*state{{.v}})
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.Info.Equals(other0.State.Info), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) Info() (MinerInfo, error) {
|
||||||
|
info, err := s.State.GetInfo(s.store)
|
||||||
|
if err != nil {
|
||||||
|
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 {
|
||||||
|
return MinerInfo{}, err
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
mi := MinerInfo{
|
||||||
|
Owner: info.Owner,
|
||||||
|
Worker: info.Worker,
|
||||||
|
ControlAddresses: info.ControlAddresses,
|
||||||
|
|
||||||
|
NewWorker: address.Undef,
|
||||||
|
WorkerChangeEpoch: -1,
|
||||||
|
|
||||||
|
PeerId: pid,
|
||||||
|
Multiaddrs: info.Multiaddrs,
|
||||||
|
WindowPoStProofType: {{if (ge .v 3)}}info.WindowPoStProofType{{else}}wpp{{end}},
|
||||||
|
SectorSize: info.SectorSize,
|
||||||
|
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) {
|
||||||
|
return s.State.{{if (ge .v 4)}}Recorded{{end}}DeadlineInfo(epoch), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) DeadlineCronActive() (bool, error) {
|
||||||
|
return {{if (ge .v 4)}}s.State.DeadlineCronActive{{else}}true{{end}}, nil{{if (lt .v 4)}} // always active in this version{{end}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) sectors() (adt.Array, error) {
|
||||||
|
return adt{{.v}}.AsArray(s.store, s.Sectors{{if (ge .v 3)}}, miner{{.v}}.SectorsAmtBitwidth{{end}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) {
|
||||||
|
var si miner{{.v}}.SectorOnChainInfo
|
||||||
|
err := si.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
||||||
|
if err != nil {
|
||||||
|
return SectorOnChainInfo{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fromV{{.v}}SectorOnChainInfo(si), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
var sp miner{{.v}}.SectorPreCommitOnChainInfo
|
||||||
|
err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
||||||
|
if err != nil {
|
||||||
|
return SectorPreCommitOnChainInfo{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fromV{{.v}}SectorPreCommitOnChainInfo(sp), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline{{.v}}) LoadPartition(idx uint64) (Partition, error) {
|
||||||
|
p, err := d.Deadline.LoadPartition(d.store, idx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &partition{{.v}}{*p, d.store}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline{{.v}}) ForEachPartition(cb func(uint64, Partition) error) error {
|
||||||
|
ps, err := d.Deadline.PartitionsArray(d.store)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var part miner{{.v}}.Partition
|
||||||
|
return ps.ForEach(&part, func(i int64) error {
|
||||||
|
return cb(uint64(i), &partition{{.v}}{part, d.store})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline{{.v}}) PartitionsChanged(other Deadline) (bool, error) {
|
||||||
|
other{{.v}}, ok := other.(*deadline{{.v}})
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return !d.Deadline.Partitions.Equals(other{{.v}}.Deadline.Partitions), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline{{.v}}) PartitionsPoSted() (bitfield.BitField, error) {
|
||||||
|
return d.Deadline.{{if (ge .v 3)}}PartitionsPoSted{{else}}PostSubmissions{{end}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline{{.v}}) DisputableProofCount() (uint64, error) {
|
||||||
|
{{if (ge .v 3)}}
|
||||||
|
ops, err := d.OptimisticProofsSnapshotArray(d.store)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ops.Length(), nil
|
||||||
|
{{else}}
|
||||||
|
// field doesn't exist until v3
|
||||||
|
return 0, nil
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *partition{{.v}}) AllSectors() (bitfield.BitField, error) {
|
||||||
|
return p.Partition.Sectors, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *partition{{.v}}) FaultySectors() (bitfield.BitField, error) {
|
||||||
|
return p.Partition.Faults, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *partition{{.v}}) RecoveringSectors() (bitfield.BitField, error) {
|
||||||
|
return p.Partition.Recoveries, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorOnChainInfo {
|
||||||
|
{{if (ge .v 2)}}
|
||||||
|
return SectorOnChainInfo{
|
||||||
|
SectorNumber: v{{.v}}.SectorNumber,
|
||||||
|
SealProof: v{{.v}}.SealProof,
|
||||||
|
SealedCID: v{{.v}}.SealedCID,
|
||||||
|
DealIDs: v{{.v}}.DealIDs,
|
||||||
|
Activation: v{{.v}}.Activation,
|
||||||
|
Expiration: v{{.v}}.Expiration,
|
||||||
|
DealWeight: v{{.v}}.DealWeight,
|
||||||
|
VerifiedDealWeight: v{{.v}}.VerifiedDealWeight,
|
||||||
|
InitialPledge: v{{.v}}.InitialPledge,
|
||||||
|
ExpectedDayReward: v{{.v}}.ExpectedDayReward,
|
||||||
|
ExpectedStoragePledge: v{{.v}}.ExpectedStoragePledge,
|
||||||
|
}
|
||||||
|
{{else}}
|
||||||
|
return (SectorOnChainInfo)(v0)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV{{.v}}SectorPreCommitOnChainInfo(v{{.v}} miner{{.v}}.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||||
|
{{if (ge .v 2)}}
|
||||||
|
return SectorPreCommitOnChainInfo{
|
||||||
|
Info: (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}}
|
||||||
|
}
|
@ -196,6 +196,7 @@ func (s *state0) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOn
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret := fromV0SectorPreCommitOnChainInfo(*info)
|
ret := fromV0SectorPreCommitOnChainInfo(*info)
|
||||||
|
|
||||||
return &ret, nil
|
return &ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,8 +397,10 @@ func (d *deadline0) PartitionsPoSted() (bitfield.BitField, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *deadline0) DisputableProofCount() (uint64, error) {
|
func (d *deadline0) DisputableProofCount() (uint64, error) {
|
||||||
|
|
||||||
// field doesn't exist until v3
|
// field doesn't exist until v3
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *partition0) AllSectors() (bitfield.BitField, error) {
|
func (p *partition0) AllSectors() (bitfield.BitField, error) {
|
||||||
@ -413,9 +416,13 @@ func (p *partition0) RecoveringSectors() (bitfield.BitField, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fromV0SectorOnChainInfo(v0 miner0.SectorOnChainInfo) SectorOnChainInfo {
|
func fromV0SectorOnChainInfo(v0 miner0.SectorOnChainInfo) SectorOnChainInfo {
|
||||||
|
|
||||||
return (SectorOnChainInfo)(v0)
|
return (SectorOnChainInfo)(v0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||||
|
|
||||||
return (SectorPreCommitOnChainInfo)(v0)
|
return (SectorPreCommitOnChainInfo)(v0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -395,8 +395,10 @@ func (d *deadline2) PartitionsPoSted() (bitfield.BitField, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *deadline2) DisputableProofCount() (uint64, error) {
|
func (d *deadline2) DisputableProofCount() (uint64, error) {
|
||||||
|
|
||||||
// field doesn't exist until v3
|
// field doesn't exist until v3
|
||||||
return 0, nil
|
return 0, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *partition2) AllSectors() (bitfield.BitField, error) {
|
func (p *partition2) AllSectors() (bitfield.BitField, error) {
|
||||||
@ -412,6 +414,7 @@ func (p *partition2) RecoveringSectors() (bitfield.BitField, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fromV2SectorOnChainInfo(v2 miner2.SectorOnChainInfo) SectorOnChainInfo {
|
func fromV2SectorOnChainInfo(v2 miner2.SectorOnChainInfo) SectorOnChainInfo {
|
||||||
|
|
||||||
return SectorOnChainInfo{
|
return SectorOnChainInfo{
|
||||||
SectorNumber: v2.SectorNumber,
|
SectorNumber: v2.SectorNumber,
|
||||||
SealProof: v2.SealProof,
|
SealProof: v2.SealProof,
|
||||||
@ -425,9 +428,11 @@ func fromV2SectorOnChainInfo(v2 miner2.SectorOnChainInfo) SectorOnChainInfo {
|
|||||||
ExpectedDayReward: v2.ExpectedDayReward,
|
ExpectedDayReward: v2.ExpectedDayReward,
|
||||||
ExpectedStoragePledge: v2.ExpectedStoragePledge,
|
ExpectedStoragePledge: v2.ExpectedStoragePledge,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromV2SectorPreCommitOnChainInfo(v2 miner2.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
func fromV2SectorPreCommitOnChainInfo(v2 miner2.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||||
|
|
||||||
return SectorPreCommitOnChainInfo{
|
return SectorPreCommitOnChainInfo{
|
||||||
Info: (SectorPreCommitInfo)(v2.Info),
|
Info: (SectorPreCommitInfo)(v2.Info),
|
||||||
PreCommitDeposit: v2.PreCommitDeposit,
|
PreCommitDeposit: v2.PreCommitDeposit,
|
||||||
@ -435,4 +440,5 @@ func fromV2SectorPreCommitOnChainInfo(v2 miner2.SectorPreCommitOnChainInfo) Sect
|
|||||||
DealWeight: v2.DealWeight,
|
DealWeight: v2.DealWeight,
|
||||||
VerifiedDealWeight: v2.VerifiedDealWeight,
|
VerifiedDealWeight: v2.VerifiedDealWeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner"
|
miner3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/miner"
|
||||||
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
|
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
|
||||||
)
|
)
|
||||||
@ -208,9 +209,9 @@ func (s *state3) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, err
|
|||||||
// If no sector numbers are specified, load all.
|
// If no sector numbers are specified, load all.
|
||||||
if snos == nil {
|
if snos == nil {
|
||||||
infos := make([]*SectorOnChainInfo, 0, sectors.Length())
|
infos := make([]*SectorOnChainInfo, 0, sectors.Length())
|
||||||
var info2 miner3.SectorOnChainInfo
|
var info3 miner3.SectorOnChainInfo
|
||||||
if err := sectors.ForEach(&info2, func(_ int64) error {
|
if err := sectors.ForEach(&info3, func(_ int64) error {
|
||||||
info := fromV3SectorOnChainInfo(info2)
|
info := fromV3SectorOnChainInfo(info3)
|
||||||
infos = append(infos, &info)
|
infos = append(infos, &info)
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -220,13 +221,13 @@ func (s *state3) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, load selected.
|
// Otherwise, load selected.
|
||||||
infos2, err := sectors.Load(*snos)
|
infos3, err := sectors.Load(*snos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
infos := make([]*SectorOnChainInfo, len(infos2))
|
infos := make([]*SectorOnChainInfo, len(infos3))
|
||||||
for i, info2 := range infos2 {
|
for i, info3 := range infos3 {
|
||||||
info := fromV3SectorOnChainInfo(*info2)
|
info := fromV3SectorOnChainInfo(*info3)
|
||||||
infos[i] = &info
|
infos[i] = &info
|
||||||
}
|
}
|
||||||
return infos, nil
|
return infos, nil
|
||||||
@ -268,13 +269,13 @@ func (s *state3) NumDeadlines() (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) DeadlinesChanged(other State) (bool, error) {
|
func (s *state3) DeadlinesChanged(other State) (bool, error) {
|
||||||
other2, ok := other.(*state3)
|
other3, ok := other.(*state3)
|
||||||
if !ok {
|
if !ok {
|
||||||
// treat an upgrade as a change, always
|
// treat an upgrade as a change, always
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return !s.State.Deadlines.Equals(other2.Deadlines), nil
|
return !s.State.Deadlines.Equals(other3.Deadlines), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) MinerInfoChanged(other State) (bool, error) {
|
func (s *state3) MinerInfoChanged(other State) (bool, error) {
|
||||||
@ -377,13 +378,13 @@ func (d *deadline3) ForEachPartition(cb func(uint64, Partition) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *deadline3) PartitionsChanged(other Deadline) (bool, error) {
|
func (d *deadline3) PartitionsChanged(other Deadline) (bool, error) {
|
||||||
other2, ok := other.(*deadline3)
|
other3, ok := other.(*deadline3)
|
||||||
if !ok {
|
if !ok {
|
||||||
// treat an upgrade as a change, always
|
// treat an upgrade as a change, always
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return !d.Deadline.Partitions.Equals(other2.Deadline.Partitions), nil
|
return !d.Deadline.Partitions.Equals(other3.Deadline.Partitions), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *deadline3) PartitionsPoSted() (bitfield.BitField, error) {
|
func (d *deadline3) PartitionsPoSted() (bitfield.BitField, error) {
|
||||||
@ -391,12 +392,14 @@ func (d *deadline3) PartitionsPoSted() (bitfield.BitField, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *deadline3) DisputableProofCount() (uint64, error) {
|
func (d *deadline3) DisputableProofCount() (uint64, error) {
|
||||||
|
|
||||||
ops, err := d.OptimisticProofsSnapshotArray(d.store)
|
ops, err := d.OptimisticProofsSnapshotArray(d.store)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ops.Length(), nil
|
return ops.Length(), nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *partition3) AllSectors() (bitfield.BitField, error) {
|
func (p *partition3) AllSectors() (bitfield.BitField, error) {
|
||||||
@ -412,6 +415,7 @@ func (p *partition3) RecoveringSectors() (bitfield.BitField, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fromV3SectorOnChainInfo(v3 miner3.SectorOnChainInfo) SectorOnChainInfo {
|
func fromV3SectorOnChainInfo(v3 miner3.SectorOnChainInfo) SectorOnChainInfo {
|
||||||
|
|
||||||
return SectorOnChainInfo{
|
return SectorOnChainInfo{
|
||||||
SectorNumber: v3.SectorNumber,
|
SectorNumber: v3.SectorNumber,
|
||||||
SealProof: v3.SealProof,
|
SealProof: v3.SealProof,
|
||||||
@ -425,9 +429,11 @@ func fromV3SectorOnChainInfo(v3 miner3.SectorOnChainInfo) SectorOnChainInfo {
|
|||||||
ExpectedDayReward: v3.ExpectedDayReward,
|
ExpectedDayReward: v3.ExpectedDayReward,
|
||||||
ExpectedStoragePledge: v3.ExpectedStoragePledge,
|
ExpectedStoragePledge: v3.ExpectedStoragePledge,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||||
|
|
||||||
return SectorPreCommitOnChainInfo{
|
return SectorPreCommitOnChainInfo{
|
||||||
Info: (SectorPreCommitInfo)(v3.Info),
|
Info: (SectorPreCommitInfo)(v3.Info),
|
||||||
PreCommitDeposit: v3.PreCommitDeposit,
|
PreCommitDeposit: v3.PreCommitDeposit,
|
||||||
@ -435,4 +441,5 @@ func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) Sect
|
|||||||
DealWeight: v3.DealWeight,
|
DealWeight: v3.DealWeight,
|
||||||
VerifiedDealWeight: v3.VerifiedDealWeight,
|
VerifiedDealWeight: v3.VerifiedDealWeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner"
|
miner4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/miner"
|
||||||
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
|
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
|
||||||
)
|
)
|
||||||
@ -208,9 +209,9 @@ func (s *state4) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, err
|
|||||||
// If no sector numbers are specified, load all.
|
// If no sector numbers are specified, load all.
|
||||||
if snos == nil {
|
if snos == nil {
|
||||||
infos := make([]*SectorOnChainInfo, 0, sectors.Length())
|
infos := make([]*SectorOnChainInfo, 0, sectors.Length())
|
||||||
var info2 miner4.SectorOnChainInfo
|
var info4 miner4.SectorOnChainInfo
|
||||||
if err := sectors.ForEach(&info2, func(_ int64) error {
|
if err := sectors.ForEach(&info4, func(_ int64) error {
|
||||||
info := fromV4SectorOnChainInfo(info2)
|
info := fromV4SectorOnChainInfo(info4)
|
||||||
infos = append(infos, &info)
|
infos = append(infos, &info)
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@ -220,13 +221,13 @@ func (s *state4) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, load selected.
|
// Otherwise, load selected.
|
||||||
infos2, err := sectors.Load(*snos)
|
infos4, err := sectors.Load(*snos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
infos := make([]*SectorOnChainInfo, len(infos2))
|
infos := make([]*SectorOnChainInfo, len(infos4))
|
||||||
for i, info2 := range infos2 {
|
for i, info4 := range infos4 {
|
||||||
info := fromV4SectorOnChainInfo(*info2)
|
info := fromV4SectorOnChainInfo(*info4)
|
||||||
infos[i] = &info
|
infos[i] = &info
|
||||||
}
|
}
|
||||||
return infos, nil
|
return infos, nil
|
||||||
@ -268,13 +269,13 @@ func (s *state4) NumDeadlines() (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) DeadlinesChanged(other State) (bool, error) {
|
func (s *state4) DeadlinesChanged(other State) (bool, error) {
|
||||||
other2, ok := other.(*state4)
|
other4, ok := other.(*state4)
|
||||||
if !ok {
|
if !ok {
|
||||||
// treat an upgrade as a change, always
|
// treat an upgrade as a change, always
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return !s.State.Deadlines.Equals(other2.Deadlines), nil
|
return !s.State.Deadlines.Equals(other4.Deadlines), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) MinerInfoChanged(other State) (bool, error) {
|
func (s *state4) MinerInfoChanged(other State) (bool, error) {
|
||||||
@ -377,13 +378,13 @@ func (d *deadline4) ForEachPartition(cb func(uint64, Partition) error) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *deadline4) PartitionsChanged(other Deadline) (bool, error) {
|
func (d *deadline4) PartitionsChanged(other Deadline) (bool, error) {
|
||||||
other2, ok := other.(*deadline4)
|
other4, ok := other.(*deadline4)
|
||||||
if !ok {
|
if !ok {
|
||||||
// treat an upgrade as a change, always
|
// treat an upgrade as a change, always
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return !d.Deadline.Partitions.Equals(other2.Deadline.Partitions), nil
|
return !d.Deadline.Partitions.Equals(other4.Deadline.Partitions), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *deadline4) PartitionsPoSted() (bitfield.BitField, error) {
|
func (d *deadline4) PartitionsPoSted() (bitfield.BitField, error) {
|
||||||
@ -391,12 +392,14 @@ func (d *deadline4) PartitionsPoSted() (bitfield.BitField, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *deadline4) DisputableProofCount() (uint64, error) {
|
func (d *deadline4) DisputableProofCount() (uint64, error) {
|
||||||
|
|
||||||
ops, err := d.OptimisticProofsSnapshotArray(d.store)
|
ops, err := d.OptimisticProofsSnapshotArray(d.store)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ops.Length(), nil
|
return ops.Length(), nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *partition4) AllSectors() (bitfield.BitField, error) {
|
func (p *partition4) AllSectors() (bitfield.BitField, error) {
|
||||||
@ -412,6 +415,7 @@ func (p *partition4) RecoveringSectors() (bitfield.BitField, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fromV4SectorOnChainInfo(v4 miner4.SectorOnChainInfo) SectorOnChainInfo {
|
func fromV4SectorOnChainInfo(v4 miner4.SectorOnChainInfo) SectorOnChainInfo {
|
||||||
|
|
||||||
return SectorOnChainInfo{
|
return SectorOnChainInfo{
|
||||||
SectorNumber: v4.SectorNumber,
|
SectorNumber: v4.SectorNumber,
|
||||||
SealProof: v4.SealProof,
|
SealProof: v4.SealProof,
|
||||||
@ -425,9 +429,11 @@ func fromV4SectorOnChainInfo(v4 miner4.SectorOnChainInfo) SectorOnChainInfo {
|
|||||||
ExpectedDayReward: v4.ExpectedDayReward,
|
ExpectedDayReward: v4.ExpectedDayReward,
|
||||||
ExpectedStoragePledge: v4.ExpectedStoragePledge,
|
ExpectedStoragePledge: v4.ExpectedStoragePledge,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromV4SectorPreCommitOnChainInfo(v4 miner4.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
func fromV4SectorPreCommitOnChainInfo(v4 miner4.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||||
|
|
||||||
return SectorPreCommitOnChainInfo{
|
return SectorPreCommitOnChainInfo{
|
||||||
Info: (SectorPreCommitInfo)(v4.Info),
|
Info: (SectorPreCommitInfo)(v4.Info),
|
||||||
PreCommitDeposit: v4.PreCommitDeposit,
|
PreCommitDeposit: v4.PreCommitDeposit,
|
||||||
@ -435,4 +441,5 @@ func fromV4SectorPreCommitOnChainInfo(v4 miner4.SectorPreCommitOnChainInfo) Sect
|
|||||||
DealWeight: v4.DealWeight,
|
DealWeight: v4.DealWeight,
|
||||||
VerifiedDealWeight: v4.VerifiedDealWeight,
|
VerifiedDealWeight: v4.VerifiedDealWeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
445
chain/actors/builtin/miner/v5.go
Normal file
445
chain/actors/builtin/miner/v5.go
Normal file
@ -0,0 +1,445 @@
|
|||||||
|
package miner
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"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/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"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
|
||||||
|
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
||||||
|
adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state5)(nil)
|
||||||
|
|
||||||
|
func load5(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state5{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state5 struct {
|
||||||
|
miner5.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
type deadline5 struct {
|
||||||
|
miner5.Deadline
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
type partition5 struct {
|
||||||
|
miner5.Partition
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) 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 *state5) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||||
|
return s.CheckVestedFunds(s.store, epoch)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) LockedFunds() (LockedFunds, error) {
|
||||||
|
return LockedFunds{
|
||||||
|
VestingFunds: s.State.LockedFunds,
|
||||||
|
InitialPledgeRequirement: s.State.InitialPledge,
|
||||||
|
PreCommitDeposits: s.State.PreCommitDeposits,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) FeeDebt() (abi.TokenAmount, error) {
|
||||||
|
return s.State.FeeDebt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) InitialPledge() (abi.TokenAmount, error) {
|
||||||
|
return s.State.InitialPledge, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) PreCommitDeposits() (abi.TokenAmount, error) {
|
||||||
|
return s.State.PreCommitDeposits, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) GetSector(num abi.SectorNumber) (*SectorOnChainInfo, error) {
|
||||||
|
info, ok, err := s.State.GetSector(s.store, num)
|
||||||
|
if !ok || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := fromV5SectorOnChainInfo(*info)
|
||||||
|
return &ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) 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 *state5) 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 *miner5.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 *state5) 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 either expire on-time (can be
|
||||||
|
// learned from the sector info), or in the next quantized expiration
|
||||||
|
// epoch (i.e., the first element in the partition's expiration queue.
|
||||||
|
// 2. If it's faulty, it will expire early within the first 14 entries
|
||||||
|
// of the expiration queue.
|
||||||
|
stopErr := errors.New("stop")
|
||||||
|
out := SectorExpiration{}
|
||||||
|
err = dls.ForEach(s.store, func(dlIdx uint64, dl *miner5.Deadline) error {
|
||||||
|
partitions, err := dl.PartitionsArray(s.store)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
quant := s.State.QuantSpecForDeadline(dlIdx)
|
||||||
|
var part miner5.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 := miner5.LoadExpirationQueue(s.store, part.ExpirationsEpochs, quant, miner5.PartitionExpirationAmtBitwidth)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var exp miner5.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 *state5) GetPrecommittedSector(num abi.SectorNumber) (*SectorPreCommitOnChainInfo, error) {
|
||||||
|
info, ok, err := s.State.GetPrecommittedSector(s.store, num)
|
||||||
|
if !ok || err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := fromV5SectorPreCommitOnChainInfo(*info)
|
||||||
|
|
||||||
|
return &ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) LoadSectors(snos *bitfield.BitField) ([]*SectorOnChainInfo, error) {
|
||||||
|
sectors, err := miner5.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 info5 miner5.SectorOnChainInfo
|
||||||
|
if err := sectors.ForEach(&info5, func(_ int64) error {
|
||||||
|
info := fromV5SectorOnChainInfo(info5)
|
||||||
|
infos = append(infos, &info)
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return infos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, load selected.
|
||||||
|
infos5, err := sectors.Load(*snos)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
infos := make([]*SectorOnChainInfo, len(infos5))
|
||||||
|
for i, info5 := range infos5 {
|
||||||
|
info := fromV5SectorOnChainInfo(*info5)
|
||||||
|
infos[i] = &info
|
||||||
|
}
|
||||||
|
return infos, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) IsAllocated(num abi.SectorNumber) (bool, error) {
|
||||||
|
var allocatedSectors bitfield.BitField
|
||||||
|
if err := s.store.Get(s.store.Context(), s.State.AllocatedSectors, &allocatedSectors); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return allocatedSectors.IsSet(uint64(num))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) 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 &deadline5{*dl, s.store}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) 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 *miner5.Deadline) error {
|
||||||
|
return cb(i, &deadline5{*dl, s.store})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) NumDeadlines() (uint64, error) {
|
||||||
|
return miner5.WPoStPeriodDeadlines, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) DeadlinesChanged(other State) (bool, error) {
|
||||||
|
other5, ok := other.(*state5)
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return !s.State.Deadlines.Equals(other5.Deadlines), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) MinerInfoChanged(other State) (bool, error) {
|
||||||
|
other0, ok := other.(*state5)
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.Info.Equals(other0.State.Info), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) Info() (MinerInfo, error) {
|
||||||
|
info, err := s.State.GetInfo(s.store)
|
||||||
|
if err != nil {
|
||||||
|
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,
|
||||||
|
|
||||||
|
PeerId: pid,
|
||||||
|
Multiaddrs: info.Multiaddrs,
|
||||||
|
WindowPoStProofType: info.WindowPoStProofType,
|
||||||
|
SectorSize: info.SectorSize,
|
||||||
|
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
|
||||||
|
ConsensusFaultElapsed: info.ConsensusFaultElapsed,
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.PendingWorkerKey != nil {
|
||||||
|
mi.NewWorker = info.PendingWorkerKey.NewWorker
|
||||||
|
mi.WorkerChangeEpoch = info.PendingWorkerKey.EffectiveAt
|
||||||
|
}
|
||||||
|
|
||||||
|
return mi, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) DeadlineInfo(epoch abi.ChainEpoch) (*dline.Info, error) {
|
||||||
|
return s.State.RecordedDeadlineInfo(epoch), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) DeadlineCronActive() (bool, error) {
|
||||||
|
return s.State.DeadlineCronActive, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) sectors() (adt.Array, error) {
|
||||||
|
return adt5.AsArray(s.store, s.Sectors, miner5.SectorsAmtBitwidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) decodeSectorOnChainInfo(val *cbg.Deferred) (SectorOnChainInfo, error) {
|
||||||
|
var si miner5.SectorOnChainInfo
|
||||||
|
err := si.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
||||||
|
if err != nil {
|
||||||
|
return SectorOnChainInfo{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fromV5SectorOnChainInfo(si), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
var sp miner5.SectorPreCommitOnChainInfo
|
||||||
|
err := sp.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
||||||
|
if err != nil {
|
||||||
|
return SectorPreCommitOnChainInfo{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return fromV5SectorPreCommitOnChainInfo(sp), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline5) LoadPartition(idx uint64) (Partition, error) {
|
||||||
|
p, err := d.Deadline.LoadPartition(d.store, idx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &partition5{*p, d.store}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline5) ForEachPartition(cb func(uint64, Partition) error) error {
|
||||||
|
ps, err := d.Deadline.PartitionsArray(d.store)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var part miner5.Partition
|
||||||
|
return ps.ForEach(&part, func(i int64) error {
|
||||||
|
return cb(uint64(i), &partition5{part, d.store})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline5) PartitionsChanged(other Deadline) (bool, error) {
|
||||||
|
other5, ok := other.(*deadline5)
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return !d.Deadline.Partitions.Equals(other5.Deadline.Partitions), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline5) PartitionsPoSted() (bitfield.BitField, error) {
|
||||||
|
return d.Deadline.PartitionsPoSted, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *deadline5) DisputableProofCount() (uint64, error) {
|
||||||
|
|
||||||
|
ops, err := d.OptimisticProofsSnapshotArray(d.store)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return ops.Length(), nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *partition5) AllSectors() (bitfield.BitField, error) {
|
||||||
|
return p.Partition.Sectors, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *partition5) FaultySectors() (bitfield.BitField, error) {
|
||||||
|
return p.Partition.Faults, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *partition5) RecoveringSectors() (bitfield.BitField, error) {
|
||||||
|
return p.Partition.Recoveries, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV5SectorOnChainInfo(v5 miner5.SectorOnChainInfo) SectorOnChainInfo {
|
||||||
|
|
||||||
|
return SectorOnChainInfo{
|
||||||
|
SectorNumber: v5.SectorNumber,
|
||||||
|
SealProof: v5.SealProof,
|
||||||
|
SealedCID: v5.SealedCID,
|
||||||
|
DealIDs: v5.DealIDs,
|
||||||
|
Activation: v5.Activation,
|
||||||
|
Expiration: v5.Expiration,
|
||||||
|
DealWeight: v5.DealWeight,
|
||||||
|
VerifiedDealWeight: v5.VerifiedDealWeight,
|
||||||
|
InitialPledge: v5.InitialPledge,
|
||||||
|
ExpectedDayReward: v5.ExpectedDayReward,
|
||||||
|
ExpectedStoragePledge: v5.ExpectedStoragePledge,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV5SectorPreCommitOnChainInfo(v5 miner5.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo {
|
||||||
|
|
||||||
|
return SectorPreCommitOnChainInfo{
|
||||||
|
Info: (SectorPreCommitInfo)(v5.Info),
|
||||||
|
PreCommitDeposit: v5.PreCommitDeposit,
|
||||||
|
PreCommitEpoch: v5.PreCommitEpoch,
|
||||||
|
DealWeight: v5.DealWeight,
|
||||||
|
VerifiedDealWeight: v5.VerifiedDealWeight,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
118
chain/actors/builtin/multisig/actor.go.template
Normal file
118
chain/actors/builtin/multisig/actor.go.template
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
package multisig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/minio/blake2b-simd"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/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"
|
||||||
|
{{range .versions}}
|
||||||
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
||||||
|
{{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) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.MultisigActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
|
||||||
|
LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error)
|
||||||
|
StartEpoch() (abi.ChainEpoch, error)
|
||||||
|
UnlockDuration() (abi.ChainEpoch, error)
|
||||||
|
InitialBalance() (abi.TokenAmount, error)
|
||||||
|
Threshold() (uint64, error)
|
||||||
|
Signers() ([]address.Address, error)
|
||||||
|
|
||||||
|
ForEachPendingTxn(func(id int64, txn Transaction) error) error
|
||||||
|
PendingTxnChanged(State) (bool, error)
|
||||||
|
|
||||||
|
transactions() (adt.Map, error)
|
||||||
|
decodeTransaction(val *cbg.Deferred) (Transaction, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Transaction = msig0.Transaction
|
||||||
|
|
||||||
|
var Methods = builtin{{.latestVersion}}.MethodsMultisig
|
||||||
|
|
||||||
|
func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||||
|
switch version {
|
||||||
|
{{range .versions}}
|
||||||
|
case actors.Version{{.}}:
|
||||||
|
return message{{.}}{{"{"}}{{if (ge . 2)}}message0{from}{{else}}from{{end}}}
|
||||||
|
{{end}} default:
|
||||||
|
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MessageBuilder interface {
|
||||||
|
// Create a new multisig with the specified parameters.
|
||||||
|
Create(signers []address.Address, threshold uint64,
|
||||||
|
vestingStart, vestingDuration abi.ChainEpoch,
|
||||||
|
initialAmount abi.TokenAmount) (*types.Message, error)
|
||||||
|
|
||||||
|
// Propose a transaction to the given multisig.
|
||||||
|
Propose(msig, target address.Address, amt abi.TokenAmount,
|
||||||
|
method abi.MethodNum, params []byte) (*types.Message, error)
|
||||||
|
|
||||||
|
// Approve a multisig transaction. The "hash" is optional.
|
||||||
|
Approve(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error)
|
||||||
|
|
||||||
|
// Cancel a multisig transaction. The "hash" is optional.
|
||||||
|
Cancel(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// this type is the same between v0 and v2
|
||||||
|
type ProposalHashData = msig{{.latestVersion}}.ProposalHashData
|
||||||
|
type ProposeReturn = msig{{.latestVersion}}.ProposeReturn
|
||||||
|
type ProposeParams = msig{{.latestVersion}}.ProposeParams
|
||||||
|
|
||||||
|
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
||||||
|
params := msig{{.latestVersion}}.TxnIDParams{ID: msig{{.latestVersion}}.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)
|
||||||
|
}
|
||||||
|
if data.Value.Sign() == -1 {
|
||||||
|
return nil, xerrors.Errorf("proposal value must be non-negative, was %s", data.Value)
|
||||||
|
}
|
||||||
|
if data.To == address.Undef {
|
||||||
|
return nil, xerrors.Errorf("proposed destination address must be set")
|
||||||
|
}
|
||||||
|
pser, err := data.Serialize()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
hash := blake2b.Sum256(pser)
|
||||||
|
params.ProposalHash = hash[:]
|
||||||
|
}
|
||||||
|
|
||||||
|
return actors.SerializeParams(¶ms)
|
||||||
|
}
|
@ -1,79 +0,0 @@
|
|||||||
package multisig
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/minio/blake2b-simd"
|
|
||||||
"golang.org/x/xerrors"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
|
||||||
multisig4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Methods = builtin4.MethodsMultisig
|
|
||||||
|
|
||||||
func Message(version actors.Version, from address.Address) MessageBuilder {
|
|
||||||
switch version {
|
|
||||||
case actors.Version0:
|
|
||||||
return message0{from}
|
|
||||||
case actors.Version2:
|
|
||||||
return message2{message0{from}}
|
|
||||||
case actors.Version3:
|
|
||||||
return message3{message0{from}}
|
|
||||||
case actors.Version4:
|
|
||||||
return message4{message0{from}}
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type MessageBuilder interface {
|
|
||||||
// Create a new multisig with the specified parameters.
|
|
||||||
Create(signers []address.Address, threshold uint64,
|
|
||||||
vestingStart, vestingDuration abi.ChainEpoch,
|
|
||||||
initialAmount abi.TokenAmount) (*types.Message, error)
|
|
||||||
|
|
||||||
// Propose a transaction to the given multisig.
|
|
||||||
Propose(msig, target address.Address, amt abi.TokenAmount,
|
|
||||||
method abi.MethodNum, params []byte) (*types.Message, error)
|
|
||||||
|
|
||||||
// Approve a multisig transaction. The "hash" is optional.
|
|
||||||
Approve(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error)
|
|
||||||
|
|
||||||
// Cancel a multisig transaction. The "hash" is optional.
|
|
||||||
Cancel(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// this type is the same between v0 and v2
|
|
||||||
type ProposalHashData = multisig4.ProposalHashData
|
|
||||||
type ProposeReturn = multisig4.ProposeReturn
|
|
||||||
type ProposeParams = multisig4.ProposeParams
|
|
||||||
|
|
||||||
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
|
||||||
params := multisig4.TxnIDParams{ID: multisig4.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)
|
|
||||||
}
|
|
||||||
if data.Value.Sign() == -1 {
|
|
||||||
return nil, xerrors.Errorf("proposal value must be non-negative, was %s", data.Value)
|
|
||||||
}
|
|
||||||
if data.To == address.Undef {
|
|
||||||
return nil, xerrors.Errorf("proposed destination address must be set")
|
|
||||||
}
|
|
||||||
pser, err := data.Serialize()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
hash := blake2b.Sum256(pser)
|
|
||||||
params.ProposalHash = hash[:]
|
|
||||||
}
|
|
||||||
|
|
||||||
return actors.SerializeParams(¶ms)
|
|
||||||
}
|
|
146
chain/actors/builtin/multisig/message.go.template
Normal file
146
chain/actors/builtin/multisig/message.go.template
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
package multisig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
|
builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin"
|
||||||
|
init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init"
|
||||||
|
multisig{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/multisig"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
|
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type message{{.v}} struct{ {{if (ge .v 2)}}message0{{else}}from address.Address{{end}} }
|
||||||
|
|
||||||
|
func (m message{{.v}}) Create(
|
||||||
|
signers []address.Address, threshold uint64,
|
||||||
|
unlockStart, unlockDuration abi.ChainEpoch,
|
||||||
|
initialAmount abi.TokenAmount,
|
||||||
|
) (*types.Message, error) {
|
||||||
|
|
||||||
|
lenAddrs := uint64(len(signers))
|
||||||
|
|
||||||
|
if lenAddrs < threshold {
|
||||||
|
return nil, 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")
|
||||||
|
}
|
||||||
|
{{if (le .v 1)}}
|
||||||
|
if unlockStart != 0 {
|
||||||
|
return nil, xerrors.Errorf("actors v0 does not support a non-zero vesting start time")
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
// Set up constructor parameters for multisig
|
||||||
|
msigParams := &multisig{{.v}}.ConstructorParams{
|
||||||
|
Signers: signers,
|
||||||
|
NumApprovalsThreshold: threshold,
|
||||||
|
UnlockDuration: unlockDuration,{{if (ge .v 2)}}
|
||||||
|
StartEpoch: unlockStart,{{end}}
|
||||||
|
}
|
||||||
|
|
||||||
|
enc, actErr := actors.SerializeParams(msigParams)
|
||||||
|
if actErr != nil {
|
||||||
|
return nil, actErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// new actors are created by invoking 'exec' on the init actor with the constructor params
|
||||||
|
execParams := &init{{.v}}.ExecParams{
|
||||||
|
CodeCID: builtin{{.v}}.MultisigActorCodeID,
|
||||||
|
ConstructorParams: enc,
|
||||||
|
}
|
||||||
|
|
||||||
|
enc, actErr = actors.SerializeParams(execParams)
|
||||||
|
if actErr != nil {
|
||||||
|
return nil, actErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: init_.Address,
|
||||||
|
From: m.from,
|
||||||
|
Method: builtin{{.v}}.MethodsInit.Exec,
|
||||||
|
Params: enc,
|
||||||
|
Value: initialAmount,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
{{if (le .v 1)}}
|
||||||
|
|
||||||
|
func (m message0) Propose(msig, to address.Address, amt abi.TokenAmount,
|
||||||
|
method abi.MethodNum, params []byte) (*types.Message, error) {
|
||||||
|
|
||||||
|
if msig == address.Undef {
|
||||||
|
return nil, xerrors.Errorf("must provide a multisig address for proposal")
|
||||||
|
}
|
||||||
|
|
||||||
|
if to == address.Undef {
|
||||||
|
return nil, xerrors.Errorf("must provide a target address for proposal")
|
||||||
|
}
|
||||||
|
|
||||||
|
if amt.Sign() == -1 {
|
||||||
|
return nil, xerrors.Errorf("must provide a non-negative amount for proposed send")
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.from == address.Undef {
|
||||||
|
return nil, xerrors.Errorf("must provide source address")
|
||||||
|
}
|
||||||
|
|
||||||
|
enc, actErr := actors.SerializeParams(&multisig0.ProposeParams{
|
||||||
|
To: to,
|
||||||
|
Value: amt,
|
||||||
|
Method: method,
|
||||||
|
Params: params,
|
||||||
|
})
|
||||||
|
if actErr != nil {
|
||||||
|
return nil, xerrors.Errorf("failed to serialize parameters: %w", actErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: msig,
|
||||||
|
From: m.from,
|
||||||
|
Value: abi.NewTokenAmount(0),
|
||||||
|
Method: builtin0.MethodsMultisig.Propose,
|
||||||
|
Params: enc,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m message0) Approve(msig address.Address, txID uint64, hashData *ProposalHashData) (*types.Message, error) {
|
||||||
|
enc, err := txnParams(txID, hashData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: msig,
|
||||||
|
From: m.from,
|
||||||
|
Value: types.NewInt(0),
|
||||||
|
Method: builtin0.MethodsMultisig.Approve,
|
||||||
|
Params: enc,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m message0) Cancel(msig address.Address, txID uint64, hashData *ProposalHashData) (*types.Message, error) {
|
||||||
|
enc, err := txnParams(txID, hashData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: msig,
|
||||||
|
From: m.from,
|
||||||
|
Value: types.NewInt(0),
|
||||||
|
Method: builtin0.MethodsMultisig.Cancel,
|
||||||
|
Params: enc,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
{{end}}
|
71
chain/actors/builtin/multisig/message5.go
Normal file
71
chain/actors/builtin/multisig/message5.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package multisig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
init5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/init"
|
||||||
|
multisig5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
|
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type message5 struct{ message0 }
|
||||||
|
|
||||||
|
func (m message5) Create(
|
||||||
|
signers []address.Address, threshold uint64,
|
||||||
|
unlockStart, unlockDuration abi.ChainEpoch,
|
||||||
|
initialAmount abi.TokenAmount,
|
||||||
|
) (*types.Message, error) {
|
||||||
|
|
||||||
|
lenAddrs := uint64(len(signers))
|
||||||
|
|
||||||
|
if lenAddrs < threshold {
|
||||||
|
return nil, 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 := &multisig5.ConstructorParams{
|
||||||
|
Signers: signers,
|
||||||
|
NumApprovalsThreshold: threshold,
|
||||||
|
UnlockDuration: unlockDuration,
|
||||||
|
StartEpoch: unlockStart,
|
||||||
|
}
|
||||||
|
|
||||||
|
enc, actErr := actors.SerializeParams(msigParams)
|
||||||
|
if actErr != nil {
|
||||||
|
return nil, actErr
|
||||||
|
}
|
||||||
|
|
||||||
|
// new actors are created by invoking 'exec' on the init actor with the constructor params
|
||||||
|
execParams := &init5.ExecParams{
|
||||||
|
CodeCID: builtin5.MultisigActorCodeID,
|
||||||
|
ConstructorParams: enc,
|
||||||
|
}
|
||||||
|
|
||||||
|
enc, actErr = actors.SerializeParams(execParams)
|
||||||
|
if actErr != nil {
|
||||||
|
return nil, actErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: init_.Address,
|
||||||
|
From: m.from,
|
||||||
|
Method: builtin5.MethodsInit.Exec,
|
||||||
|
Params: enc,
|
||||||
|
Value: initialAmount,
|
||||||
|
}, nil
|
||||||
|
}
|
165
chain/actors/builtin/multisig/multisig.go
Normal file
165
chain/actors/builtin/multisig/multisig.go
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
package multisig
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/minio/blake2b-simd"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
|
||||||
|
msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||||
|
msig5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig"
|
||||||
|
|
||||||
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
|
|
||||||
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
|
||||||
|
"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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
|
switch act.Code {
|
||||||
|
|
||||||
|
case builtin0.MultisigActorCodeID:
|
||||||
|
return load0(store, act.Head)
|
||||||
|
|
||||||
|
case builtin2.MultisigActorCodeID:
|
||||||
|
return load2(store, act.Head)
|
||||||
|
|
||||||
|
case builtin3.MultisigActorCodeID:
|
||||||
|
return load3(store, act.Head)
|
||||||
|
|
||||||
|
case builtin4.MultisigActorCodeID:
|
||||||
|
return load4(store, act.Head)
|
||||||
|
|
||||||
|
case builtin5.MultisigActorCodeID:
|
||||||
|
return load5(store, act.Head)
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
|
||||||
|
LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error)
|
||||||
|
StartEpoch() (abi.ChainEpoch, error)
|
||||||
|
UnlockDuration() (abi.ChainEpoch, error)
|
||||||
|
InitialBalance() (abi.TokenAmount, error)
|
||||||
|
Threshold() (uint64, error)
|
||||||
|
Signers() ([]address.Address, error)
|
||||||
|
|
||||||
|
ForEachPendingTxn(func(id int64, txn Transaction) error) error
|
||||||
|
PendingTxnChanged(State) (bool, error)
|
||||||
|
|
||||||
|
transactions() (adt.Map, error)
|
||||||
|
decodeTransaction(val *cbg.Deferred) (Transaction, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Transaction = msig0.Transaction
|
||||||
|
|
||||||
|
var Methods = builtin5.MethodsMultisig
|
||||||
|
|
||||||
|
func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||||
|
switch version {
|
||||||
|
|
||||||
|
case actors.Version0:
|
||||||
|
return message0{from}
|
||||||
|
|
||||||
|
case actors.Version2:
|
||||||
|
return message2{message0{from}}
|
||||||
|
|
||||||
|
case actors.Version3:
|
||||||
|
return message3{message0{from}}
|
||||||
|
|
||||||
|
case actors.Version4:
|
||||||
|
return message4{message0{from}}
|
||||||
|
|
||||||
|
case actors.Version5:
|
||||||
|
return message5{message0{from}}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MessageBuilder interface {
|
||||||
|
// Create a new multisig with the specified parameters.
|
||||||
|
Create(signers []address.Address, threshold uint64,
|
||||||
|
vestingStart, vestingDuration abi.ChainEpoch,
|
||||||
|
initialAmount abi.TokenAmount) (*types.Message, error)
|
||||||
|
|
||||||
|
// Propose a transaction to the given multisig.
|
||||||
|
Propose(msig, target address.Address, amt abi.TokenAmount,
|
||||||
|
method abi.MethodNum, params []byte) (*types.Message, error)
|
||||||
|
|
||||||
|
// Approve a multisig transaction. The "hash" is optional.
|
||||||
|
Approve(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error)
|
||||||
|
|
||||||
|
// Cancel a multisig transaction. The "hash" is optional.
|
||||||
|
Cancel(msig address.Address, txID uint64, hash *ProposalHashData) (*types.Message, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// this type is the same between v0 and v2
|
||||||
|
type ProposalHashData = msig5.ProposalHashData
|
||||||
|
type ProposeReturn = msig5.ProposeReturn
|
||||||
|
type ProposeParams = msig5.ProposeParams
|
||||||
|
|
||||||
|
func txnParams(id uint64, data *ProposalHashData) ([]byte, error) {
|
||||||
|
params := msig5.TxnIDParams{ID: msig5.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)
|
||||||
|
}
|
||||||
|
if data.Value.Sign() == -1 {
|
||||||
|
return nil, xerrors.Errorf("proposal value must be non-negative, was %s", data.Value)
|
||||||
|
}
|
||||||
|
if data.To == address.Undef {
|
||||||
|
return nil, xerrors.Errorf("proposed destination address must be set")
|
||||||
|
}
|
||||||
|
pser, err := data.Serialize()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
hash := blake2b.Sum256(pser)
|
||||||
|
params.ProposalHash = hash[:]
|
||||||
|
}
|
||||||
|
|
||||||
|
return actors.SerializeParams(¶ms)
|
||||||
|
}
|
@ -1,69 +0,0 @@
|
|||||||
package multisig
|
|
||||||
|
|
||||||
import (
|
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
|
||||||
"golang.org/x/xerrors"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
|
||||||
"github.com/filecoin-project/go-state-types/cbor"
|
|
||||||
"github.com/ipfs/go-cid"
|
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
|
||||||
msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
|
||||||
|
|
||||||
"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)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
|
||||||
switch act.Code {
|
|
||||||
case builtin0.MultisigActorCodeID:
|
|
||||||
return load0(store, act.Head)
|
|
||||||
case builtin2.MultisigActorCodeID:
|
|
||||||
return load2(store, act.Head)
|
|
||||||
case builtin3.MultisigActorCodeID:
|
|
||||||
return load3(store, act.Head)
|
|
||||||
case builtin4.MultisigActorCodeID:
|
|
||||||
return load4(store, act.Head)
|
|
||||||
}
|
|
||||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
|
||||||
}
|
|
||||||
|
|
||||||
type State interface {
|
|
||||||
cbor.Marshaler
|
|
||||||
|
|
||||||
LockedBalance(epoch abi.ChainEpoch) (abi.TokenAmount, error)
|
|
||||||
StartEpoch() (abi.ChainEpoch, error)
|
|
||||||
UnlockDuration() (abi.ChainEpoch, error)
|
|
||||||
InitialBalance() (abi.TokenAmount, error)
|
|
||||||
Threshold() (uint64, error)
|
|
||||||
Signers() ([]address.Address, error)
|
|
||||||
|
|
||||||
ForEachPendingTxn(func(id int64, txn Transaction) error) error
|
|
||||||
PendingTxnChanged(State) (bool, error)
|
|
||||||
|
|
||||||
transactions() (adt.Map, error)
|
|
||||||
decodeTransaction(val *cbg.Deferred) (Transaction, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Transaction = msig0.Transaction
|
|
97
chain/actors/builtin/multisig/state.go.template
Normal file
97
chain/actors/builtin/multisig/state.go.template
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
package multisig
|
||||||
|
|
||||||
|
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"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
|
{{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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state{{.v}})(nil)
|
||||||
|
|
||||||
|
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state{{.v}}{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state{{.v}} struct {
|
||||||
|
msig{{.v}}.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||||
|
return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) StartEpoch() (abi.ChainEpoch, error) {
|
||||||
|
return s.State.StartEpoch, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) UnlockDuration() (abi.ChainEpoch, error) {
|
||||||
|
return s.State.UnlockDuration, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) InitialBalance() (abi.TokenAmount, error) {
|
||||||
|
return s.State.InitialBalance, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) Threshold() (uint64, error) {
|
||||||
|
return s.State.NumApprovalsThreshold, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) Signers() ([]address.Address, error) {
|
||||||
|
return s.State.Signers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error {
|
||||||
|
arr, err := adt{{.v}}.AsMap(s.store, s.State.PendingTxns{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var out msig{{.v}}.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 *state{{.v}}) PendingTxnChanged(other State) (bool, error) {
|
||||||
|
other{{.v}}, ok := other.(*state{{.v}})
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.PendingTxns.Equals(other{{.v}}.PendingTxns), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) transactions() (adt.Map, error) {
|
||||||
|
return adt{{.v}}.AsMap(s.store, s.PendingTxns{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
|
||||||
|
var tx msig{{.v}}.Transaction
|
||||||
|
if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
|
return Transaction{}, err
|
||||||
|
}
|
||||||
|
return tx, nil
|
||||||
|
}
|
@ -4,6 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
|
||||||
|
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -13,8 +15,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
msig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
||||||
multisig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
|
|
||||||
adt0 "github.com/filecoin-project/specs-actors/actors/util/adt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ State = (*state0)(nil)
|
var _ State = (*state0)(nil)
|
||||||
@ -86,7 +86,7 @@ func (s *state0) transactions() (adt.Map, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
|
func (s *state0) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
|
||||||
var tx multisig0.Transaction
|
var tx msig0.Transaction
|
||||||
if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
return Transaction{}, err
|
return Transaction{}, err
|
||||||
}
|
}
|
@ -4,6 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
|
||||||
|
adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -13,7 +15,6 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
msig2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/multisig"
|
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)
|
var _ State = (*state2)(nil)
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
msig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig"
|
msig3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/multisig"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -74,12 +75,12 @@ func (s *state3) ForEachPendingTxn(cb func(id int64, txn Transaction) error) err
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) PendingTxnChanged(other State) (bool, error) {
|
func (s *state3) PendingTxnChanged(other State) (bool, error) {
|
||||||
other2, ok := other.(*state3)
|
other3, ok := other.(*state3)
|
||||||
if !ok {
|
if !ok {
|
||||||
// treat an upgrade as a change, always
|
// treat an upgrade as a change, always
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.PendingTxns.Equals(other2.PendingTxns), nil
|
return !s.State.PendingTxns.Equals(other3.PendingTxns), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) transactions() (adt.Map, error) {
|
func (s *state3) transactions() (adt.Map, error) {
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
msig4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig"
|
msig4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/multisig"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -69,17 +70,17 @@ func (s *state4) ForEachPendingTxn(cb func(id int64, txn Transaction) error) err
|
|||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
return xerrors.Errorf("invalid pending transaction key: %v", key)
|
return xerrors.Errorf("invalid pending transaction key: %v", key)
|
||||||
}
|
}
|
||||||
return cb(txid, (Transaction)(out))
|
return cb(txid, (Transaction)(out)) //nolint:unconvert
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) PendingTxnChanged(other State) (bool, error) {
|
func (s *state4) PendingTxnChanged(other State) (bool, error) {
|
||||||
other2, ok := other.(*state4)
|
other4, ok := other.(*state4)
|
||||||
if !ok {
|
if !ok {
|
||||||
// treat an upgrade as a change, always
|
// treat an upgrade as a change, always
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.PendingTxns.Equals(other2.PendingTxns), nil
|
return !s.State.PendingTxns.Equals(other4.PendingTxns), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) transactions() (adt.Map, error) {
|
func (s *state4) transactions() (adt.Map, error) {
|
96
chain/actors/builtin/multisig/v5.go
Normal file
96
chain/actors/builtin/multisig/v5.go
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
package multisig
|
||||||
|
|
||||||
|
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"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
|
||||||
|
msig5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/multisig"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state5)(nil)
|
||||||
|
|
||||||
|
func load5(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state5{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state5 struct {
|
||||||
|
msig5.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) LockedBalance(currEpoch abi.ChainEpoch) (abi.TokenAmount, error) {
|
||||||
|
return s.State.AmountLocked(currEpoch - s.State.StartEpoch), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) StartEpoch() (abi.ChainEpoch, error) {
|
||||||
|
return s.State.StartEpoch, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) UnlockDuration() (abi.ChainEpoch, error) {
|
||||||
|
return s.State.UnlockDuration, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) InitialBalance() (abi.TokenAmount, error) {
|
||||||
|
return s.State.InitialBalance, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) Threshold() (uint64, error) {
|
||||||
|
return s.State.NumApprovalsThreshold, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) Signers() ([]address.Address, error) {
|
||||||
|
return s.State.Signers, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) ForEachPendingTxn(cb func(id int64, txn Transaction) error) error {
|
||||||
|
arr, err := adt5.AsMap(s.store, s.State.PendingTxns, builtin5.DefaultHamtBitwidth)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var out msig5.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 *state5) PendingTxnChanged(other State) (bool, error) {
|
||||||
|
other5, ok := other.(*state5)
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.PendingTxns.Equals(other5.PendingTxns), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) transactions() (adt.Map, error) {
|
||||||
|
return adt5.AsMap(s.store, s.PendingTxns, builtin5.DefaultHamtBitwidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) decodeTransaction(val *cbg.Deferred) (Transaction, error) {
|
||||||
|
var tx msig5.Transaction
|
||||||
|
if err := tx.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
|
return Transaction{}, err
|
||||||
|
}
|
||||||
|
return tx, nil
|
||||||
|
}
|
109
chain/actors/builtin/paych/actor.go.template
Normal file
109
chain/actors/builtin/paych/actor.go.template
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package paych
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
big "github.com/filecoin-project/go-state-types/big"
|
||||||
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
ipldcbor "github.com/ipfs/go-ipld-cbor"
|
||||||
|
|
||||||
|
paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
||||||
|
{{range .versions}}
|
||||||
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/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) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.PaymentChannelActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
// State is an abstract version of payment channel state that works across
|
||||||
|
// versions
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
// Channel owner, who has funded the actor
|
||||||
|
From() (address.Address, error)
|
||||||
|
// Recipient of payouts from channel
|
||||||
|
To() (address.Address, error)
|
||||||
|
|
||||||
|
// Height at which the channel can be `Collected`
|
||||||
|
SettlingAt() (abi.ChainEpoch, error)
|
||||||
|
|
||||||
|
// Amount successfully redeemed through the payment channel, paid out on `Collect()`
|
||||||
|
ToSend() (abi.TokenAmount, error)
|
||||||
|
|
||||||
|
// Get total number of lanes
|
||||||
|
LaneCount() (uint64, error)
|
||||||
|
|
||||||
|
// Iterate lane states
|
||||||
|
ForEachLaneState(cb func(idx uint64, dl LaneState) error) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// LaneState is an abstract copy of the state of a single lane
|
||||||
|
type LaneState interface {
|
||||||
|
Redeemed() (big.Int, error)
|
||||||
|
Nonce() (uint64, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type SignedVoucher = paych0.SignedVoucher
|
||||||
|
type ModVerifyParams = paych0.ModVerifyParams
|
||||||
|
|
||||||
|
// DecodeSignedVoucher decodes base64 encoded signed voucher.
|
||||||
|
func DecodeSignedVoucher(s string) (*SignedVoucher, error) {
|
||||||
|
data, err := base64.RawURLEncoding.DecodeString(s)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var sv SignedVoucher
|
||||||
|
if err := ipldcbor.DecodeInto(data, &sv); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &sv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var Methods = builtin{{.latestVersion}}.MethodsPaych
|
||||||
|
|
||||||
|
func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||||
|
switch version {
|
||||||
|
{{range .versions}}
|
||||||
|
case actors.Version{{.}}:
|
||||||
|
return message{{.}}{from}
|
||||||
|
{{end}}
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MessageBuilder interface {
|
||||||
|
Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error)
|
||||||
|
Update(paych address.Address, voucher *SignedVoucher, secret []byte) (*types.Message, error)
|
||||||
|
Settle(paych address.Address) (*types.Message, error)
|
||||||
|
Collect(paych address.Address) (*types.Message, error)
|
||||||
|
}
|
@ -1,36 +0,0 @@
|
|||||||
package paych
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
|
||||||
"github.com/filecoin-project/go-state-types/abi"
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Methods = builtin4.MethodsPaych
|
|
||||||
|
|
||||||
func Message(version actors.Version, from address.Address) MessageBuilder {
|
|
||||||
switch version {
|
|
||||||
case actors.Version0:
|
|
||||||
return message0{from}
|
|
||||||
case actors.Version2:
|
|
||||||
return message2{from}
|
|
||||||
case actors.Version3:
|
|
||||||
return message3{from}
|
|
||||||
case actors.Version4:
|
|
||||||
return message4{from}
|
|
||||||
default:
|
|
||||||
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type MessageBuilder interface {
|
|
||||||
Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error)
|
|
||||||
Update(paych address.Address, voucher *SignedVoucher, secret []byte) (*types.Message, error)
|
|
||||||
Settle(paych address.Address) (*types.Message, error)
|
|
||||||
Collect(paych address.Address) (*types.Message, error)
|
|
||||||
}
|
|
74
chain/actors/builtin/paych/message.go.template
Normal file
74
chain/actors/builtin/paych/message.go.template
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package paych
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
|
builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin"
|
||||||
|
init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init"
|
||||||
|
paych{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/paych"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
|
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type message{{.v}} struct{ from address.Address }
|
||||||
|
|
||||||
|
func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
|
||||||
|
params, aerr := actors.SerializeParams(&paych{{.v}}.ConstructorParams{From: m.from, To: to})
|
||||||
|
if aerr != nil {
|
||||||
|
return nil, aerr
|
||||||
|
}
|
||||||
|
enc, aerr := actors.SerializeParams(&init{{.v}}.ExecParams{
|
||||||
|
CodeCID: builtin{{.v}}.PaymentChannelActorCodeID,
|
||||||
|
ConstructorParams: params,
|
||||||
|
})
|
||||||
|
if aerr != nil {
|
||||||
|
return nil, aerr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: init_.Address,
|
||||||
|
From: m.from,
|
||||||
|
Value: initialAmount,
|
||||||
|
Method: builtin{{.v}}.MethodsInit.Exec,
|
||||||
|
Params: enc,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) {
|
||||||
|
params, aerr := actors.SerializeParams(&paych{{.v}}.UpdateChannelStateParams{
|
||||||
|
Sv: *sv,
|
||||||
|
Secret: secret,
|
||||||
|
})
|
||||||
|
if aerr != nil {
|
||||||
|
return nil, aerr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: paych,
|
||||||
|
From: m.from,
|
||||||
|
Value: abi.NewTokenAmount(0),
|
||||||
|
Method: builtin{{.v}}.MethodsPaych.UpdateChannelState,
|
||||||
|
Params: params,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m message{{.v}}) Settle(paych address.Address) (*types.Message, error) {
|
||||||
|
return &types.Message{
|
||||||
|
To: paych,
|
||||||
|
From: m.from,
|
||||||
|
Value: abi.NewTokenAmount(0),
|
||||||
|
Method: builtin{{.v}}.MethodsPaych.Settle,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m message{{.v}}) Collect(paych address.Address) (*types.Message, error) {
|
||||||
|
return &types.Message{
|
||||||
|
To: paych,
|
||||||
|
From: m.from,
|
||||||
|
Value: abi.NewTokenAmount(0),
|
||||||
|
Method: builtin{{.v}}.MethodsPaych.Collect,
|
||||||
|
}, nil
|
||||||
|
}
|
74
chain/actors/builtin/paych/message5.go
Normal file
74
chain/actors/builtin/paych/message5.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package paych
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
init5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/init"
|
||||||
|
paych5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
|
init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init"
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type message5 struct{ from address.Address }
|
||||||
|
|
||||||
|
func (m message5) Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error) {
|
||||||
|
params, aerr := actors.SerializeParams(&paych5.ConstructorParams{From: m.from, To: to})
|
||||||
|
if aerr != nil {
|
||||||
|
return nil, aerr
|
||||||
|
}
|
||||||
|
enc, aerr := actors.SerializeParams(&init5.ExecParams{
|
||||||
|
CodeCID: builtin5.PaymentChannelActorCodeID,
|
||||||
|
ConstructorParams: params,
|
||||||
|
})
|
||||||
|
if aerr != nil {
|
||||||
|
return nil, aerr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: init_.Address,
|
||||||
|
From: m.from,
|
||||||
|
Value: initialAmount,
|
||||||
|
Method: builtin5.MethodsInit.Exec,
|
||||||
|
Params: enc,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m message5) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) {
|
||||||
|
params, aerr := actors.SerializeParams(&paych5.UpdateChannelStateParams{
|
||||||
|
Sv: *sv,
|
||||||
|
Secret: secret,
|
||||||
|
})
|
||||||
|
if aerr != nil {
|
||||||
|
return nil, aerr
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.Message{
|
||||||
|
To: paych,
|
||||||
|
From: m.from,
|
||||||
|
Value: abi.NewTokenAmount(0),
|
||||||
|
Method: builtin5.MethodsPaych.UpdateChannelState,
|
||||||
|
Params: params,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m message5) Settle(paych address.Address) (*types.Message, error) {
|
||||||
|
return &types.Message{
|
||||||
|
To: paych,
|
||||||
|
From: m.from,
|
||||||
|
Value: abi.NewTokenAmount(0),
|
||||||
|
Method: builtin5.MethodsPaych.Settle,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m message5) Collect(paych address.Address) (*types.Message, error) {
|
||||||
|
return &types.Message{
|
||||||
|
To: paych,
|
||||||
|
From: m.from,
|
||||||
|
Value: abi.NewTokenAmount(0),
|
||||||
|
Method: builtin5.MethodsPaych.Collect,
|
||||||
|
}, nil
|
||||||
|
}
|
@ -2,6 +2,7 @@ package paych
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -12,43 +13,66 @@ import (
|
|||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
ipldcbor "github.com/ipfs/go-ipld-cbor"
|
ipldcbor "github.com/ipfs/go-ipld-cbor"
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
|
||||||
paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
paych0 "github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
||||||
|
|
||||||
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin0.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin0.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load0(store, root)
|
return load0(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin2.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin2.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load2(store, root)
|
return load2(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin3.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin3.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load3(store, root)
|
return load3(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin4.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin4.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load4(store, root)
|
return load4(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builtin.RegisterActorState(builtin5.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load5(store, root)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load returns an abstract copy of payment channel state, irregardless of actor version
|
// Load returns an abstract copy of payment channel state, irregardless of actor version
|
||||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
switch act.Code {
|
switch act.Code {
|
||||||
|
|
||||||
case builtin0.PaymentChannelActorCodeID:
|
case builtin0.PaymentChannelActorCodeID:
|
||||||
return load0(store, act.Head)
|
return load0(store, act.Head)
|
||||||
|
|
||||||
case builtin2.PaymentChannelActorCodeID:
|
case builtin2.PaymentChannelActorCodeID:
|
||||||
return load2(store, act.Head)
|
return load2(store, act.Head)
|
||||||
|
|
||||||
case builtin3.PaymentChannelActorCodeID:
|
case builtin3.PaymentChannelActorCodeID:
|
||||||
return load3(store, act.Head)
|
return load3(store, act.Head)
|
||||||
|
|
||||||
case builtin4.PaymentChannelActorCodeID:
|
case builtin4.PaymentChannelActorCodeID:
|
||||||
return load4(store, act.Head)
|
return load4(store, act.Head)
|
||||||
|
|
||||||
|
case builtin5.PaymentChannelActorCodeID:
|
||||||
|
return load5(store, act.Head)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
}
|
}
|
||||||
@ -98,3 +122,35 @@ func DecodeSignedVoucher(s string) (*SignedVoucher, error) {
|
|||||||
|
|
||||||
return &sv, nil
|
return &sv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Methods = builtin5.MethodsPaych
|
||||||
|
|
||||||
|
func Message(version actors.Version, from address.Address) MessageBuilder {
|
||||||
|
switch version {
|
||||||
|
|
||||||
|
case actors.Version0:
|
||||||
|
return message0{from}
|
||||||
|
|
||||||
|
case actors.Version2:
|
||||||
|
return message2{from}
|
||||||
|
|
||||||
|
case actors.Version3:
|
||||||
|
return message3{from}
|
||||||
|
|
||||||
|
case actors.Version4:
|
||||||
|
return message4{from}
|
||||||
|
|
||||||
|
case actors.Version5:
|
||||||
|
return message5{from}
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("unsupported actors version: %d", version))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type MessageBuilder interface {
|
||||||
|
Create(to address.Address, initialAmount abi.TokenAmount) (*types.Message, error)
|
||||||
|
Update(paych address.Address, voucher *SignedVoucher, secret []byte) (*types.Message, error)
|
||||||
|
Settle(paych address.Address) (*types.Message, error)
|
||||||
|
Collect(paych address.Address) (*types.Message, error)
|
||||||
|
}
|
104
chain/actors/builtin/paych/state.go.template
Normal file
104
chain/actors/builtin/paych/state.go.template
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
paych{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/paych"
|
||||||
|
adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state{{.v}})(nil)
|
||||||
|
|
||||||
|
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state{{.v}}{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state{{.v}} struct {
|
||||||
|
paych{{.v}}.State
|
||||||
|
store adt.Store
|
||||||
|
lsAmt *adt{{.v}}.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
// Channel owner, who has funded the actor
|
||||||
|
func (s *state{{.v}}) From() (address.Address, error) {
|
||||||
|
return s.State.From, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recipient of payouts from channel
|
||||||
|
func (s *state{{.v}}) To() (address.Address, error) {
|
||||||
|
return s.State.To, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Height at which the channel can be `Collected`
|
||||||
|
func (s *state{{.v}}) SettlingAt() (abi.ChainEpoch, error) {
|
||||||
|
return s.State.SettlingAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Amount successfully redeemed through the payment channel, paid out on `Collect()`
|
||||||
|
func (s *state{{.v}}) ToSend() (abi.TokenAmount, error) {
|
||||||
|
return s.State.ToSend, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) getOrLoadLsAmt() (*adt{{.v}}.Array, error) {
|
||||||
|
if s.lsAmt != nil {
|
||||||
|
return s.lsAmt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the lane state from the chain
|
||||||
|
lsamt, err := adt{{.v}}.AsArray(s.store, s.State.LaneStates{{if (ge .v 3)}}, paych{{.v}}.LaneStatesAmtBitwidth{{end}})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.lsAmt = lsamt
|
||||||
|
return lsamt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get total number of lanes
|
||||||
|
func (s *state{{.v}}) LaneCount() (uint64, error) {
|
||||||
|
lsamt, err := s.getOrLoadLsAmt()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return lsamt.Length(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate lane states
|
||||||
|
func (s *state{{.v}}) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
|
||||||
|
// Get the lane state from the chain
|
||||||
|
lsamt, err := s.getOrLoadLsAmt()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: we use a map instead of an array to store laneStates because the
|
||||||
|
// client sets the lane ID (the index) and potentially they could use a
|
||||||
|
// very large index.
|
||||||
|
var ls paych{{.v}}.LaneState
|
||||||
|
return lsamt.ForEach(&ls, func(i int64) error {
|
||||||
|
return cb(uint64(i), &laneState{{.v}}{ls})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type laneState{{.v}} struct {
|
||||||
|
paych{{.v}}.LaneState
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ls *laneState{{.v}}) Redeemed() (big.Int, error) {
|
||||||
|
return ls.LaneState.Redeemed, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ls *laneState{{.v}}) Nonce() (uint64, error) {
|
||||||
|
return ls.LaneState.Nonce, nil
|
||||||
|
}
|
104
chain/actors/builtin/paych/v5.go
Normal file
104
chain/actors/builtin/paych/v5.go
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
paych5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/paych"
|
||||||
|
adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state5)(nil)
|
||||||
|
|
||||||
|
func load5(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state5{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state5 struct {
|
||||||
|
paych5.State
|
||||||
|
store adt.Store
|
||||||
|
lsAmt *adt5.Array
|
||||||
|
}
|
||||||
|
|
||||||
|
// Channel owner, who has funded the actor
|
||||||
|
func (s *state5) From() (address.Address, error) {
|
||||||
|
return s.State.From, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recipient of payouts from channel
|
||||||
|
func (s *state5) To() (address.Address, error) {
|
||||||
|
return s.State.To, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Height at which the channel can be `Collected`
|
||||||
|
func (s *state5) SettlingAt() (abi.ChainEpoch, error) {
|
||||||
|
return s.State.SettlingAt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Amount successfully redeemed through the payment channel, paid out on `Collect()`
|
||||||
|
func (s *state5) ToSend() (abi.TokenAmount, error) {
|
||||||
|
return s.State.ToSend, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) getOrLoadLsAmt() (*adt5.Array, error) {
|
||||||
|
if s.lsAmt != nil {
|
||||||
|
return s.lsAmt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the lane state from the chain
|
||||||
|
lsamt, err := adt5.AsArray(s.store, s.State.LaneStates, paych5.LaneStatesAmtBitwidth)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.lsAmt = lsamt
|
||||||
|
return lsamt, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get total number of lanes
|
||||||
|
func (s *state5) LaneCount() (uint64, error) {
|
||||||
|
lsamt, err := s.getOrLoadLsAmt()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return lsamt.Length(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate lane states
|
||||||
|
func (s *state5) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error {
|
||||||
|
// Get the lane state from the chain
|
||||||
|
lsamt, err := s.getOrLoadLsAmt()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: we use a map instead of an array to store laneStates because the
|
||||||
|
// client sets the lane ID (the index) and potentially they could use a
|
||||||
|
// very large index.
|
||||||
|
var ls paych5.LaneState
|
||||||
|
return lsamt.ForEach(&ls, func(i int64) error {
|
||||||
|
return cb(uint64(i), &laneState5{ls})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type laneState5 struct {
|
||||||
|
paych5.LaneState
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ls *laneState5) Redeemed() (big.Int, error) {
|
||||||
|
return ls.LaneState.Redeemed, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ls *laneState5) Nonce() (uint64, error) {
|
||||||
|
return ls.LaneState.Nonce, nil
|
||||||
|
}
|
78
chain/actors/builtin/power/actor.go.template
Normal file
78
chain/actors/builtin/power/actor.go.template
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
package power
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/big"
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
{{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) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.StoragePowerActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
|
||||||
|
TotalLocked() (abi.TokenAmount, error)
|
||||||
|
TotalPower() (Claim, error)
|
||||||
|
TotalCommitted() (Claim, error)
|
||||||
|
TotalPowerSmoothed() (builtin.FilterEstimate, error)
|
||||||
|
|
||||||
|
// MinerCounts returns the number of miners. Participating is the number
|
||||||
|
// with power above the minimum miner threshold.
|
||||||
|
MinerCounts() (participating, total uint64, err error)
|
||||||
|
MinerPower(address.Address) (Claim, bool, error)
|
||||||
|
MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error)
|
||||||
|
ListAllMiners() ([]address.Address, error)
|
||||||
|
ForEachClaim(func(miner address.Address, claim Claim) error) error
|
||||||
|
ClaimsChanged(State) (bool, error)
|
||||||
|
|
||||||
|
// Diff helpers. Used by Diff* functions internally.
|
||||||
|
claims() (adt.Map, error)
|
||||||
|
decodeClaim(*cbg.Deferred) (Claim, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type Claim struct {
|
||||||
|
// Sum of raw byte power for a miner's sectors.
|
||||||
|
RawBytePower abi.StoragePower
|
||||||
|
|
||||||
|
// Sum of quality adjusted power for a miner's sectors.
|
||||||
|
QualityAdjPower abi.StoragePower
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddClaims(a Claim, b Claim) Claim {
|
||||||
|
return Claim{
|
||||||
|
RawBytePower: big.Add(a.RawBytePower, b.RawBytePower),
|
||||||
|
QualityAdjPower: big.Add(a.QualityAdjPower, b.QualityAdjPower),
|
||||||
|
}
|
||||||
|
}
|
@ -15,41 +15,62 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin0.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin0.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load0(store, root)
|
return load0(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin2.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin2.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load2(store, root)
|
return load2(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin3.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin3.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load3(store, root)
|
return load3(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin4.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin4.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load4(store, root)
|
return load4(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builtin.RegisterActorState(builtin5.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load5(store, root)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Address = builtin4.StoragePowerActorAddr
|
Address = builtin5.StoragePowerActorAddr
|
||||||
Methods = builtin4.MethodsPower
|
Methods = builtin5.MethodsPower
|
||||||
)
|
)
|
||||||
|
|
||||||
func Load(store adt.Store, act *types.Actor) (st State, err error) {
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
switch act.Code {
|
switch act.Code {
|
||||||
|
|
||||||
case builtin0.StoragePowerActorCodeID:
|
case builtin0.StoragePowerActorCodeID:
|
||||||
return load0(store, act.Head)
|
return load0(store, act.Head)
|
||||||
|
|
||||||
case builtin2.StoragePowerActorCodeID:
|
case builtin2.StoragePowerActorCodeID:
|
||||||
return load2(store, act.Head)
|
return load2(store, act.Head)
|
||||||
|
|
||||||
case builtin3.StoragePowerActorCodeID:
|
case builtin3.StoragePowerActorCodeID:
|
||||||
return load3(store, act.Head)
|
return load3(store, act.Head)
|
||||||
|
|
||||||
case builtin4.StoragePowerActorCodeID:
|
case builtin4.StoragePowerActorCodeID:
|
||||||
return load4(store, act.Head)
|
return load4(store, act.Head)
|
||||||
|
|
||||||
|
case builtin5.StoragePowerActorCodeID:
|
||||||
|
return load5(store, act.Head)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
}
|
}
|
||||||
|
151
chain/actors/builtin/power/state.go.template
Normal file
151
chain/actors/builtin/power/state.go.template
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
{{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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state{{.v}})(nil)
|
||||||
|
|
||||||
|
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state{{.v}}{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state{{.v}} struct {
|
||||||
|
power{{.v}}.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) TotalLocked() (abi.TokenAmount, error) {
|
||||||
|
return s.TotalPledgeCollateral, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) 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 *state{{.v}}) TotalCommitted() (Claim, error) {
|
||||||
|
return Claim{
|
||||||
|
RawBytePower: s.TotalBytesCommitted,
|
||||||
|
QualityAdjPower: s.TotalQABytesCommitted,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||||
|
claims, err := s.claims()
|
||||||
|
if err != nil {
|
||||||
|
return Claim{}, false, err
|
||||||
|
}
|
||||||
|
var claim power{{.v}}.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 *state{{.v}}) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) {
|
||||||
|
return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) TotalPowerSmoothed() (builtin.FilterEstimate, error) {
|
||||||
|
return builtin.FromV{{.v}}FilterEstimate({{if (le .v 1)}}*{{end}}s.State.ThisEpochQAPowerSmoothed), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) MinerCounts() (uint64, uint64, error) {
|
||||||
|
return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) 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 *state{{.v}}) ForEachClaim(cb func(miner address.Address, claim Claim) error) error {
|
||||||
|
claims, err := s.claims()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var claim power{{.v}}.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 *state{{.v}}) ClaimsChanged(other State) (bool, error) {
|
||||||
|
other{{.v}}, ok := other.(*state{{.v}})
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.Claims.Equals(other{{.v}}.State.Claims), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) claims() (adt.Map, error) {
|
||||||
|
return adt{{.v}}.AsMap(s.store, s.Claims{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) decodeClaim(val *cbg.Deferred) (Claim, error) {
|
||||||
|
var ci power{{.v}}.Claim
|
||||||
|
if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
|
return Claim{}, err
|
||||||
|
}
|
||||||
|
return fromV{{.v}}Claim(ci), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV{{.v}}Claim(v{{.v}} power{{.v}}.Claim) Claim {
|
||||||
|
return Claim{
|
||||||
|
RawBytePower: v{{.v}}.RawBytePower,
|
||||||
|
QualityAdjPower: v{{.v}}.QualityAdjPower,
|
||||||
|
}
|
||||||
|
}
|
@ -51,7 +51,7 @@ func (s *state0) TotalCommitted() (Claim, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) MinerPower(addr address.Address) (Claim, bool, error) {
|
func (s *state0) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||||
claims, err := adt0.AsMap(s.store, s.Claims)
|
claims, err := s.claims()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Claim{}, false, err
|
return Claim{}, false, err
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func (s *state0) MinerCounts() (uint64, uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) ListAllMiners() ([]address.Address, error) {
|
func (s *state0) ListAllMiners() ([]address.Address, error) {
|
||||||
claims, err := adt0.AsMap(s.store, s.Claims)
|
claims, err := s.claims()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ func (s *state0) ListAllMiners() ([]address.Address, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) ForEachClaim(cb func(miner address.Address, claim Claim) error) error {
|
func (s *state0) ForEachClaim(cb func(miner address.Address, claim Claim) error) error {
|
||||||
claims, err := adt0.AsMap(s.store, s.Claims)
|
claims, err := s.claims()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -141,5 +141,8 @@ func (s *state0) decodeClaim(val *cbg.Deferred) (Claim, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fromV0Claim(v0 power0.Claim) Claim {
|
func fromV0Claim(v0 power0.Claim) Claim {
|
||||||
return (Claim)(v0)
|
return Claim{
|
||||||
|
RawBytePower: v0.RawBytePower,
|
||||||
|
QualityAdjPower: v0.QualityAdjPower,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (s *state2) TotalCommitted() (Claim, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state2) MinerPower(addr address.Address) (Claim, bool, error) {
|
func (s *state2) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||||
claims, err := adt2.AsMap(s.store, s.Claims)
|
claims, err := s.claims()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Claim{}, false, err
|
return Claim{}, false, err
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ func (s *state2) MinerCounts() (uint64, uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state2) ListAllMiners() ([]address.Address, error) {
|
func (s *state2) ListAllMiners() ([]address.Address, error) {
|
||||||
claims, err := adt2.AsMap(s.store, s.Claims)
|
claims, err := s.claims()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ func (s *state2) ListAllMiners() ([]address.Address, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state2) ForEachClaim(cb func(miner address.Address, claim Claim) error) error {
|
func (s *state2) ForEachClaim(cb func(miner address.Address, claim Claim) error) error {
|
||||||
claims, err := adt2.AsMap(s.store, s.Claims)
|
claims, err := s.claims()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
power3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/power"
|
power3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/power"
|
||||||
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
|
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
|
||||||
)
|
)
|
||||||
@ -121,12 +122,12 @@ func (s *state3) ForEachClaim(cb func(miner address.Address, claim Claim) error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) ClaimsChanged(other State) (bool, error) {
|
func (s *state3) ClaimsChanged(other State) (bool, error) {
|
||||||
other2, ok := other.(*state3)
|
other3, ok := other.(*state3)
|
||||||
if !ok {
|
if !ok {
|
||||||
// treat an upgrade as a change, always
|
// treat an upgrade as a change, always
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.Claims.Equals(other2.State.Claims), nil
|
return !s.State.Claims.Equals(other3.State.Claims), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) claims() (adt.Map, error) {
|
func (s *state3) claims() (adt.Map, error) {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power"
|
power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power"
|
||||||
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
|
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
|
||||||
)
|
)
|
||||||
@ -121,12 +122,12 @@ func (s *state4) ForEachClaim(cb func(miner address.Address, claim Claim) error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) ClaimsChanged(other State) (bool, error) {
|
func (s *state4) ClaimsChanged(other State) (bool, error) {
|
||||||
other2, ok := other.(*state4)
|
other4, ok := other.(*state4)
|
||||||
if !ok {
|
if !ok {
|
||||||
// treat an upgrade as a change, always
|
// treat an upgrade as a change, always
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
return !s.State.Claims.Equals(other2.State.Claims), nil
|
return !s.State.Claims.Equals(other4.State.Claims), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) claims() (adt.Map, error) {
|
func (s *state4) claims() (adt.Map, error) {
|
||||||
|
150
chain/actors/builtin/power/v5.go
Normal file
150
chain/actors/builtin/power/v5.go
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
|
||||||
|
power5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/power"
|
||||||
|
adt5 "github.com/filecoin-project/specs-actors/v5/actors/util/adt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state5)(nil)
|
||||||
|
|
||||||
|
func load5(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state5{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state5 struct {
|
||||||
|
power5.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) TotalLocked() (abi.TokenAmount, error) {
|
||||||
|
return s.TotalPledgeCollateral, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) 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 *state5) TotalCommitted() (Claim, error) {
|
||||||
|
return Claim{
|
||||||
|
RawBytePower: s.TotalBytesCommitted,
|
||||||
|
QualityAdjPower: s.TotalQABytesCommitted,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) MinerPower(addr address.Address) (Claim, bool, error) {
|
||||||
|
claims, err := s.claims()
|
||||||
|
if err != nil {
|
||||||
|
return Claim{}, false, err
|
||||||
|
}
|
||||||
|
var claim power5.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 *state5) MinerNominalPowerMeetsConsensusMinimum(a address.Address) (bool, error) {
|
||||||
|
return s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) TotalPowerSmoothed() (builtin.FilterEstimate, error) {
|
||||||
|
return builtin.FromV5FilterEstimate(s.State.ThisEpochQAPowerSmoothed), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) MinerCounts() (uint64, uint64, error) {
|
||||||
|
return uint64(s.State.MinerAboveMinPowerCount), uint64(s.State.MinerCount), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) 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 *state5) ForEachClaim(cb func(miner address.Address, claim Claim) error) error {
|
||||||
|
claims, err := s.claims()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var claim power5.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 *state5) ClaimsChanged(other State) (bool, error) {
|
||||||
|
other5, ok := other.(*state5)
|
||||||
|
if !ok {
|
||||||
|
// treat an upgrade as a change, always
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
return !s.State.Claims.Equals(other5.State.Claims), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) claims() (adt.Map, error) {
|
||||||
|
return adt5.AsMap(s.store, s.Claims, builtin5.DefaultHamtBitwidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) decodeClaim(val *cbg.Deferred) (Claim, error) {
|
||||||
|
var ci power5.Claim
|
||||||
|
if err := ci.UnmarshalCBOR(bytes.NewReader(val.Raw)); err != nil {
|
||||||
|
return Claim{}, err
|
||||||
|
}
|
||||||
|
return fromV5Claim(ci), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func fromV5Claim(v5 power5.Claim) Claim {
|
||||||
|
return Claim{
|
||||||
|
RawBytePower: v5.RawBytePower,
|
||||||
|
QualityAdjPower: v5.QualityAdjPower,
|
||||||
|
}
|
||||||
|
}
|
60
chain/actors/builtin/reward/actor.go.template
Normal file
60
chain/actors/builtin/reward/actor.go.template
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
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"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
|
{{range .versions}}
|
||||||
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
"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{{.}}.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) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.RewardActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
|
||||||
|
ThisEpochBaselinePower() (abi.StoragePower, error)
|
||||||
|
ThisEpochReward() (abi.StoragePower, error)
|
||||||
|
ThisEpochRewardSmoothed() (builtin.FilterEstimate, error)
|
||||||
|
|
||||||
|
EffectiveBaselinePower() (abi.StoragePower, error)
|
||||||
|
EffectiveNetworkTime() (abi.ChainEpoch, error)
|
||||||
|
|
||||||
|
TotalStoragePowerReward() (abi.TokenAmount, error)
|
||||||
|
|
||||||
|
CumsumBaseline() (abi.StoragePower, error)
|
||||||
|
CumsumRealized() (abi.StoragePower, error)
|
||||||
|
|
||||||
|
InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error)
|
||||||
|
PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AwardBlockRewardParams = reward0.AwardBlockRewardParams
|
@ -7,46 +7,68 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-state-types/cbor"
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
|
|
||||||
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
|
||||||
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
||||||
|
|
||||||
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
|
||||||
|
|
||||||
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
|
||||||
|
|
||||||
|
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin0.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin0.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load0(store, root)
|
return load0(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin2.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin2.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load2(store, root)
|
return load2(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin3.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin3.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load3(store, root)
|
return load3(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
builtin.RegisterActorState(builtin4.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
builtin.RegisterActorState(builtin4.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
return load4(store, root)
|
return load4(store, root)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builtin.RegisterActorState(builtin5.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
|
||||||
|
return load5(store, root)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Address = builtin4.RewardActorAddr
|
Address = builtin5.RewardActorAddr
|
||||||
Methods = builtin4.MethodsReward
|
Methods = builtin5.MethodsReward
|
||||||
)
|
)
|
||||||
|
|
||||||
func Load(store adt.Store, act *types.Actor) (st State, err error) {
|
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||||
switch act.Code {
|
switch act.Code {
|
||||||
|
|
||||||
case builtin0.RewardActorCodeID:
|
case builtin0.RewardActorCodeID:
|
||||||
return load0(store, act.Head)
|
return load0(store, act.Head)
|
||||||
|
|
||||||
case builtin2.RewardActorCodeID:
|
case builtin2.RewardActorCodeID:
|
||||||
return load2(store, act.Head)
|
return load2(store, act.Head)
|
||||||
|
|
||||||
case builtin3.RewardActorCodeID:
|
case builtin3.RewardActorCodeID:
|
||||||
return load3(store, act.Head)
|
return load3(store, act.Head)
|
||||||
|
|
||||||
case builtin4.RewardActorCodeID:
|
case builtin4.RewardActorCodeID:
|
||||||
return load4(store, act.Head)
|
return load4(store, act.Head)
|
||||||
|
|
||||||
|
case builtin5.RewardActorCodeID:
|
||||||
|
return load5(store, act.Head)
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
}
|
}
|
||||||
|
103
chain/actors/builtin/reward/state.go.template
Normal file
103
chain/actors/builtin/reward/state.go.template
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state{{.v}})(nil)
|
||||||
|
|
||||||
|
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state{{.v}}{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state{{.v}} struct {
|
||||||
|
reward{{.v}}.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) ThisEpochReward() (abi.TokenAmount, error) {
|
||||||
|
return s.State.ThisEpochReward, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||||
|
{{if (ge .v 2)}}
|
||||||
|
return builtin.FilterEstimate{
|
||||||
|
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
||||||
|
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
||||||
|
}, nil
|
||||||
|
{{else}}
|
||||||
|
return builtin.FromV0FilterEstimate(*s.State.ThisEpochRewardSmoothed), nil
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||||
|
return s.State.ThisEpochBaselinePower, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) TotalStoragePowerReward() (abi.TokenAmount, error) {
|
||||||
|
return s.State.{{if (ge .v 2)}}TotalStoragePowerReward{{else}}TotalMined{{end}}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) EffectiveBaselinePower() (abi.StoragePower, error) {
|
||||||
|
return s.State.EffectiveBaselinePower, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) EffectiveNetworkTime() (abi.ChainEpoch, error) {
|
||||||
|
return s.State.EffectiveNetworkTime, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) CumsumBaseline() (reward{{.v}}.Spacetime, error) {
|
||||||
|
return s.State.CumsumBaseline, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state{{.v}}) CumsumRealized() (reward{{.v}}.Spacetime, error) {
|
||||||
|
return s.State.CumsumRealized, nil
|
||||||
|
}
|
||||||
|
{{if (ge .v 2)}}
|
||||||
|
func (s *state{{.v}}) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) {
|
||||||
|
return miner{{.v}}.InitialPledgeForPower(
|
||||||
|
qaPower,
|
||||||
|
s.State.ThisEpochBaselinePower,
|
||||||
|
s.State.ThisEpochRewardSmoothed,
|
||||||
|
smoothing{{.v}}.FilterEstimate{
|
||||||
|
PositionEstimate: networkQAPower.PositionEstimate,
|
||||||
|
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||||
|
},
|
||||||
|
circSupply,
|
||||||
|
), nil
|
||||||
|
}
|
||||||
|
{{else}}
|
||||||
|
func (s *state0) InitialPledgeForPower(sectorWeight abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) {
|
||||||
|
return miner0.InitialPledgeForPower(
|
||||||
|
sectorWeight,
|
||||||
|
s.State.ThisEpochBaselinePower,
|
||||||
|
networkTotalPledge,
|
||||||
|
s.State.ThisEpochRewardSmoothed,
|
||||||
|
&smoothing0.FilterEstimate{
|
||||||
|
PositionEstimate: networkQAPower.PositionEstimate,
|
||||||
|
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||||
|
},
|
||||||
|
circSupply), nil
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
func (s *state{{.v}}) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) {
|
||||||
|
return miner{{.v}}.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed,
|
||||||
|
{{if (le .v 0)}}&{{end}}smoothing{{.v}}.FilterEstimate{
|
||||||
|
PositionEstimate: networkQAPower.PositionEstimate,
|
||||||
|
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||||
|
},
|
||||||
|
sectorWeight), nil
|
||||||
|
}
|
@ -28,12 +28,14 @@ type state0 struct {
|
|||||||
store adt.Store
|
store adt.Store
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) ThisEpochReward() (abi.StoragePower, error) {
|
func (s *state0) ThisEpochReward() (abi.TokenAmount, error) {
|
||||||
return s.State.ThisEpochReward, nil
|
return s.State.ThisEpochReward, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
func (s *state0) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||||
|
|
||||||
return builtin.FromV0FilterEstimate(*s.State.ThisEpochRewardSmoothed), nil
|
return builtin.FromV0FilterEstimate(*s.State.ThisEpochRewardSmoothed), nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
func (s *state0) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||||
@ -52,11 +54,11 @@ func (s *state0) EffectiveNetworkTime() (abi.ChainEpoch, error) {
|
|||||||
return s.State.EffectiveNetworkTime, nil
|
return s.State.EffectiveNetworkTime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) CumsumBaseline() (abi.StoragePower, error) {
|
func (s *state0) CumsumBaseline() (reward0.Spacetime, error) {
|
||||||
return s.State.CumsumBaseline, nil
|
return s.State.CumsumBaseline, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state0) CumsumRealized() (abi.StoragePower, error) {
|
func (s *state0) CumsumRealized() (reward0.Spacetime, error) {
|
||||||
return s.State.CumsumRealized, nil
|
return s.State.CumsumRealized, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,10 +33,12 @@ func (s *state2) ThisEpochReward() (abi.TokenAmount, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state2) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
func (s *state2) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||||
|
|
||||||
return builtin.FilterEstimate{
|
return builtin.FilterEstimate{
|
||||||
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
||||||
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state2) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
func (s *state2) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||||
|
@ -33,10 +33,12 @@ func (s *state3) ThisEpochReward() (abi.TokenAmount, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
func (s *state3) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||||
|
|
||||||
return builtin.FilterEstimate{
|
return builtin.FilterEstimate{
|
||||||
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
||||||
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state3) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
func (s *state3) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||||
|
@ -33,10 +33,12 @@ func (s *state4) ThisEpochReward() (abi.TokenAmount, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
func (s *state4) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||||
|
|
||||||
return builtin.FilterEstimate{
|
return builtin.FilterEstimate{
|
||||||
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
||||||
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *state4) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
func (s *state4) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||||
|
88
chain/actors/builtin/reward/v5.go
Normal file
88
chain/actors/builtin/reward/v5.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
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"
|
||||||
|
|
||||||
|
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
|
||||||
|
reward5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/reward"
|
||||||
|
smoothing5 "github.com/filecoin-project/specs-actors/v5/actors/util/smoothing"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ State = (*state5)(nil)
|
||||||
|
|
||||||
|
func load5(store adt.Store, root cid.Cid) (State, error) {
|
||||||
|
out := state5{store: store}
|
||||||
|
err := store.Get(store.Context(), root, &out)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type state5 struct {
|
||||||
|
reward5.State
|
||||||
|
store adt.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) ThisEpochReward() (abi.TokenAmount, error) {
|
||||||
|
return s.State.ThisEpochReward, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) ThisEpochRewardSmoothed() (builtin.FilterEstimate, error) {
|
||||||
|
|
||||||
|
return builtin.FilterEstimate{
|
||||||
|
PositionEstimate: s.State.ThisEpochRewardSmoothed.PositionEstimate,
|
||||||
|
VelocityEstimate: s.State.ThisEpochRewardSmoothed.VelocityEstimate,
|
||||||
|
}, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) ThisEpochBaselinePower() (abi.StoragePower, error) {
|
||||||
|
return s.State.ThisEpochBaselinePower, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) TotalStoragePowerReward() (abi.TokenAmount, error) {
|
||||||
|
return s.State.TotalStoragePowerReward, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) EffectiveBaselinePower() (abi.StoragePower, error) {
|
||||||
|
return s.State.EffectiveBaselinePower, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) EffectiveNetworkTime() (abi.ChainEpoch, error) {
|
||||||
|
return s.State.EffectiveNetworkTime, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) CumsumBaseline() (reward5.Spacetime, error) {
|
||||||
|
return s.State.CumsumBaseline, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) CumsumRealized() (reward5.Spacetime, error) {
|
||||||
|
return s.State.CumsumRealized, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) InitialPledgeForPower(qaPower abi.StoragePower, networkTotalPledge abi.TokenAmount, networkQAPower *builtin.FilterEstimate, circSupply abi.TokenAmount) (abi.TokenAmount, error) {
|
||||||
|
return miner5.InitialPledgeForPower(
|
||||||
|
qaPower,
|
||||||
|
s.State.ThisEpochBaselinePower,
|
||||||
|
s.State.ThisEpochRewardSmoothed,
|
||||||
|
smoothing5.FilterEstimate{
|
||||||
|
PositionEstimate: networkQAPower.PositionEstimate,
|
||||||
|
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||||
|
},
|
||||||
|
circSupply,
|
||||||
|
), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *state5) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, sectorWeight abi.StoragePower) (abi.TokenAmount, error) {
|
||||||
|
return miner5.PreCommitDepositForPower(s.State.ThisEpochRewardSmoothed,
|
||||||
|
smoothing5.FilterEstimate{
|
||||||
|
PositionEstimate: networkQAPower.PositionEstimate,
|
||||||
|
VelocityEstimate: networkQAPower.VelocityEstimate,
|
||||||
|
},
|
||||||
|
sectorWeight), nil
|
||||||
|
}
|
51
chain/actors/builtin/verifreg/actor.go.template
Normal file
51
chain/actors/builtin/verifreg/actor.go.template
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package verifreg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/ipfs/go-cid"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/cbor"
|
||||||
|
{{range .versions}}
|
||||||
|
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
"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{{.}}.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) {
|
||||||
|
switch act.Code {
|
||||||
|
{{range .versions}}
|
||||||
|
case builtin{{.}}.VerifiedRegistryActorCodeID:
|
||||||
|
return load{{.}}(store, act.Head)
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
type State interface {
|
||||||
|
cbor.Marshaler
|
||||||
|
|
||||||
|
RootKey() (address.Address, error)
|
||||||
|
VerifiedClientDataCap(address.Address) (bool, abi.StoragePower, error)
|
||||||
|
VerifierDataCap(address.Address) (bool, abi.StoragePower, error)
|
||||||
|
ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error
|
||||||
|
ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user