Compare commits

..
211 Commits
Author SHA1 Message Date
Travis Person 06670f4cae New interop network info 2020-06-02 00:29:49 +00:00
Łukasz Magiera c6b6c2990c Merge pull request #1888 from filecoin-project/feat/build-typ-version
Include build type in version
2020-06-01 21:18:30 +02:00
Łukasz Magiera a49dc90386 Fix version test 2020-06-01 21:11:37 +02:00
Łukasz Magiera 64f4e80446 Include build type in version 2020-06-01 20:49:39 +02:00
Łukasz Magiera e67253b6a8 Merge pull request #1887 from filecoin-project/feat/improve-datastore
fsrepo: Use LevelDB for metadata datastore
2020-06-01 20:21:15 +02:00
Łukasz Magiera c73326e96d fsrepo: Use LevelDB for metadata datastore 2020-06-01 20:13:07 +02:00
Łukasz Magiera 7003960fdd Merge remote-tracking branch 'origin/master' into next 2020-06-01 18:52:06 +02:00
Łukasz Magiera 0acc2a2a63 Merge pull request #1880 from filecoin-project/asr/minerfaults
Add an API method to list all faults occuring in a certain range
2020-06-01 18:47:09 +02:00
Łukasz Magiera 596f78f9e6 Merge pull request #1885 from filecoin-project/bugs/sector-size-usage-in-scripts
update scripts and docs to use human-readable sector size
2020-06-01 18:45:20 +02:00
Łukasz Magiera 17f1eec81f Merge pull request #1886 from filecoin-project/feat/1829-repo-already-locked
error message to tell user why repo is already locked
2020-06-01 18:43:05 +02:00
Łukasz Magiera f0d44ea396 Merge pull request #1884 from filecoin-project/feat/fountain-maddr-link
fountain/miner: Add a link to docs about creating owner address
2020-06-01 18:41:57 +02:00
Łukasz Magiera ad4712b593 Merge pull request #1873 from filecoin-project/feat/better-post-faults
wdpost: Better fault handling
2020-06-01 18:39:00 +02:00
laser 92b8d9ad17 tell user why repo is already locked
Fixes #1829
2020-06-01 09:37:10 -07:00
laser 12ff9fd76b update scripts and docs to use human-readable sector size
Commit #fa863595 modified various CLI commands to accept a 
human-readable sector size. We should update docs and scripts, too.
2020-06-01 09:20:44 -07:00
Łukasz Magiera e26cf4e003 fountain/miner: Add a link to docs about creating owner address 2020-06-01 17:49:15 +02:00
Łukasz Magiera b753cd4503 Run window post test on circle 2020-06-01 15:06:10 +02:00
Łukasz Magiera ee29a92021 Add a test for Window Post 2020-06-01 14:49:48 +02:00
Łukasz Magiera c3916e3a7f Merge pull request #1875 from filecoin-project/feat/check-verifreg-cmds
add commands to check individual balances for verifiers and clients
2020-06-01 13:00:08 +02:00
Aayush Rajasekaran ec0baefc48 Add an API method to list all faults occuring in a certain range 2020-05-31 00:57:52 -04:00
Jeromy 2a3d79f055 add commands to check individual balances for verifiers and clients 2020-05-29 14:47:17 -07:00
Whyrusleeping 1c01799a4b Merge pull request #1855 from filecoin-project/feat/systemd-usage
Add systemd documention to table of contents
2020-05-29 14:07:09 -07:00
WhyrusleepingandJakub Sztandera 4ef330ba8b Update scripts/lotus-daemon.service
Co-authored-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-29 14:02:07 -07:00
Łukasz Magiera cd2bf04a6b wdpost: Better fault handling 2020-05-29 21:36:11 +02:00
Łukasz Magiera f7a71f4be7 Merge pull request #1837 from filecoin-project/feat/secstor-unseal
Update sector-storage with ReadPiece impl
2020-05-29 20:36:40 +02:00
Łukasz Magiera e5c24ff32b Update sector-storage with ReadPiece impl 2020-05-29 19:53:35 +02:00
Whyrusleeping f87054bde4 Merge pull request #1858 from hayeah/fix-miner-stale-tipset
Fix block production timing to avoid mining old tipset
2020-05-29 10:41:25 -07:00
Łukasz Magiera e954cc0d67 Merge pull request #1872 from filecoin-project/asr/docs
Fix broken link
2020-05-29 18:44:00 +02:00
Aayush Rajasekaran 43c887f2b6 Fix broken link 2020-05-29 12:35:21 -04:00
Aayush Rajasekaran 1cf9b9a67f Merge pull request #1861 from filecoin-project/asr/printmoney
Correctly handle transfers with sender = receiver
2020-05-29 12:27:56 -04:00
Aayush Rajasekaran 7dd25c3ac5 Correctly handle transfers with sender = receiver 2020-05-29 12:15:41 -04:00
Jakub Sztandera 241c3fa673 Merge pull request #1869 from filecoin-project/feat/drand-pubsub
Add pubsub support to drand beacon
2020-05-29 18:06:38 +02:00
Łukasz Magiera 785eeb1eee Merge pull request #1850 from filecoin-project/chore/lint
Cleanup many lint warnings
2020-05-29 18:06:06 +02:00
Jakub Sztandera 30d82ba962 Explicity Watch for randomness
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-29 17:55:24 +02:00
Jakub Sztandera 002d021eb7 Enable HashMsgId
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-29 17:55:24 +02:00
Jakub Sztandera 71eb41b9aa Add pubsub support to drand beacon
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-29 17:55:17 +02:00
Łukasz Magiera f06369166e Merge pull request #1868 from filecoin-project/feat/pond-regen-methods
pond: rerun method-gen
2020-05-29 15:14:20 +02:00
Łukasz Magiera 5129fed7c8 pond: rerun method-gen 2020-05-29 14:36:56 +02:00
Łukasz Magiera f06794ae84 Merge pull request #1856 from filecoin-project/deps/specs-actors-batch-porep
update specs actors to version with batch porep verification
2020-05-29 14:13:04 +02:00
Howard Yeh 1cabecedee Fix block production timing to avoid mining old tipset 2020-05-29 18:13:58 +08:00
Whyrusleeping f17c32c593 Merge pull request #1749 from filecoin-project/feat/shed-verifreg
add some commands for interacting with verified registry actor to lot…
2020-05-28 17:41:28 -07:00
Whyrusleeping b59f88324c Merge pull request #1865 from filecoin-project/fix/missing-err-check-stored-ask
Add missing err check in storage ask initialization
2020-05-28 17:17:50 -07:00
hannahhoward 0c4db8cf6b fix(storageminer): add missing err check
Missing an err check in storage miner initialization in the stored ask
2020-05-28 17:05:17 -07:00
Jeromy 9c020e54b5 Add more verifreg commands to list verifiers and clients 2020-05-28 17:01:01 -07:00
Jeromy 9811375d18 add some commands for interacting with verified registry actor to lotus-shed 2020-05-28 17:01:00 -07:00
Whyrusleeping 2632621f7e Merge pull request #1862 from filecoin-project/mod-tidy/master
Mod-tidy on master
2020-05-28 14:52:00 -07:00
Jakub Sztandera d742efe165 Mod-tidy on master
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-28 23:50:29 +02:00
Jakub Sztandera 492ffac913 Merge pull request #1853 from shepf/master
update struct.go github url
2020-05-28 23:50:05 +02:00
Mike Greenberg 4acf0c7ec0 install service files in suitable path; tweak lotus svc restarting 2020-05-28 16:26:07 -04:00
Aayush Rajasekaran fa69adf45c update chain-validation 2020-05-28 13:21:12 -07:00
Aayush Rajasekaran fa04da2995 Update specs-actors and storage-fsm 2020-05-28 13:19:36 -07:00
Jeromy e2a554c2e6 update specs actors to version with batch porep verification 2020-05-28 13:19:18 -07:00
Jeromy 91da81c8bc mod tidy 2020-05-28 13:17:55 -07:00
Jeromy 7bd18290db Merge branch 'master' into next 2020-05-28 13:16:47 -07:00
Jeromy 8e55c91cd2 check neq zero exit code 2020-05-28 22:11:49 +02:00
Mike Greenberg 514339e855 update systemd services; include make directives and docs for use 2020-05-28 22:11:49 +02:00
frrist 9f8ecb0ac4 update chain-validation
- has new syscalls
2020-05-28 22:11:49 +02:00
frrist be1bbe88b0 update chain-val syscalls interface 2020-05-28 22:11:49 +02:00
Łukasz Magiera f1ccbe496a cli: Trim spaces from token file 2020-05-28 22:11:49 +02:00
vyzo 495554e565 gomod: update go-libp2p-pubsub@v0.3.1 2020-05-28 22:11:49 +02:00
Ignacio Hagopian 17c378c18a fix
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-28 22:11:49 +02:00
Ignacio Hagopian 6e63ea6cce revert file
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-28 22:11:49 +02:00
Ignacio Hagopian 10753f14d0 retrieve: make fileref optional
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-28 22:11:49 +02:00
Ignacio Hagopian 0af7cd1448 allow using ipfs for retrieval
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-28 22:11:49 +02:00
Ignacio Hagopian de3edc2ec7 remote ipfs support & automatic env
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-28 22:11:49 +02:00
Whyrusleeping d0eb4278ae Merge pull request #1860 from filecoin-project/fix/recovery-exit-code-check
check neq zero exit code
2020-05-28 12:59:29 -07:00
Jeromy b807bdbea0 check neq zero exit code 2020-05-28 08:45:34 -07:00
Mike Greenberg 386b818d16 add systemd documention to table of contents 2020-05-27 19:28:31 -04:00
Jakub Sztandera 8639409f74 go mod tidy
,
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-28 01:16:01 +02:00
Jakub Sztandera b372881e91 Fix more lint warnings
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-28 01:15:19 +02:00
Whyrusleeping fc351d08b0 Merge pull request #1849 from filecoin-project/feat/remove-drand-on-miner
Remove drand on miner side, MinerGetBaseInfo provides the same info
2020-05-27 16:06:08 -07:00
shepf eb325e6814 update struct.go github url 2020-05-28 07:05:53 +08:00
Jakub Sztandera 7232e5481c Use origin/next for linting
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-28 00:49:52 +02:00
Jakub Sztandera f26a336afb Use git.base_revision
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-28 00:45:17 +02:00
Whyrusleeping 70e690dac0 Merge pull request #1852 from filecoin-project/feat/systemd-usage
Update systemd usage and docs
2020-05-27 15:23:45 -07:00
Mike Greenberg 78e0c96f22 update systemd services; include make directives and docs for use 2020-05-27 17:17:18 -04:00
Jakub Sztandera d6615b6286 Cleanup many lint warnings
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-27 22:53:20 +02:00
Jakub Sztandera 4604b60fb1 Remove drand on miner side, MinerGetBaseInfo provides the same info
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-27 20:24:26 +02:00
Whyrusleeping 75041b96e4 Merge pull request #1815 from filecoin-project/frrist/new-chainval-syscalls
update chain-val syscalls interface
2020-05-27 11:00:16 -07:00
Whyrusleeping 8544bda14a Merge pull request #1846 from filecoin-project/feat/trim-token-file
cli: Trim spaces from token file
2020-05-27 10:58:09 -07:00
Whyrusleeping 745fba7d1f Merge pull request #1841 from filecoin-project/gomod/update-pubsub
Update go-libp2p-pubsub to v0.3.1
2020-05-27 10:50:19 -07:00
Łukasz Magiera 6986204657 Merge pull request #1848 from filecoin-project/feat/new-drand-client
Update go-log, reduce drand entry log level, add TAG env for dev scripts
2020-05-27 16:22:13 +02:00
Jakub Sztandera 3f9cde28fc Update go-log, reduce drand entry log level, add TAG env for dev scripts
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-27 16:19:21 +02:00
Jakub Sztandera aa682a377d Partially fix pond spawn
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-27 16:19:21 +02:00
Łukasz Magiera af1d54501f Merge pull request #1843 from jsign/jsign/2stackedprs
Allow remote IPFS node support & IPFS for data retrieval & automatic env wiring
2020-05-27 14:59:18 +02:00
Ignacio Hagopian 009cd92010 fix
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-27 09:50:32 -03:00
Łukasz Magiera 6386107b80 Merge pull request #1819 from filecoin-project/feat/new-drand-client
Switch to new drand client
2020-05-27 14:35:01 +02:00
Jakub Sztandera 218b2b82c1 Update drand chain info
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-27 14:09:04 +02:00
Jakub Sztandera b06b0147a9 Switch to new drand client
This is a preview of a change to new drand client.

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-27 13:52:33 +02:00
Łukasz Magiera b74e8f5922 Merge pull request #1847 from waynewyang/Deadline-Index
fix: add deadline index for wdpost
2020-05-27 11:40:31 +02:00
waynewyang 94a7ef1c10 add deadline index for wdpost 2020-05-27 17:01:48 +08:00
Łukasz Magiera 02afd7d71f cli: Trim spaces from token file 2020-05-27 10:13:06 +02:00
Ignacio Hagopian a10690359c revert file
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-26 15:35:20 -03:00
Łukasz Magiera fa4ff89dca Set devnet params 2020-05-26 19:58:09 +02:00
Ignacio Hagopian bcd84cbe9d retrieve: make fileref optional
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-26 14:52:52 -03:00
Ignacio Hagopian 61daaa774b allow using ipfs for retrieval
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-26 14:52:52 -03:00
Ignacio Hagopian d5346f8326 remote ipfs support & automatic env
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
2020-05-26 14:52:51 -03:00
frrist 8ce6921b18 update chain-validation
- has new syscalls
2020-05-26 10:51:19 -07:00
frrist c8f28103f3 update chain-val syscalls interface 2020-05-26 10:49:39 -07:00
vyzo 3cd3785385 gomod: update go-libp2p-pubsub@v0.3.1 2020-05-26 20:47:00 +03:00
Łukasz Magiera 9089aadbbf Merge pull request #1821 from filecoin-project/deps/update-ffi
update to latest ffi
2020-05-26 19:34:02 +02:00
Łukasz Magiera 02ca1937f8 mod tidy 2020-05-26 19:07:21 +02:00
Łukasz Magiera 6897110fe5 Merge pull request #1838 from waynewyang/wdpost-input-correct
Fix:the input sectors of wpost  must match with the minerActor
2020-05-26 15:00:58 +02:00
waynewyang b799af3e9a Fix:the input sectors of wpost must match with the minerActor 2020-05-26 17:58:20 +08:00
Łukasz Magiera 9641d93615 Merge pull request #1836 from waynewyang/Wdpost-Gaslimit
Set largest gaslimit for wdpost
2020-05-26 08:53:59 +02:00
waynewyang da6768c94d Set largest gaslimit for wdpost 2020-05-26 11:43:17 +08:00
Lucas Molas 54a8b88d6c Merge pull request #1832 from filecoin-project/fix/disable-relay
Unconditionally disable relay
2020-05-25 10:38:48 -03:00
vyzo ba6217cc2c go mod tidy 2020-05-25 13:46:53 +03:00
vyzo 314da26da3 unconditionally disable relay 2020-05-25 13:39:50 +03:00
Jeromy 646800b8a8 update to latest ffi 2020-05-22 09:26:14 -07:00
Lucas Molas 92d58ab191 Merge pull request #1820 from filecoin-project/fix/sink-message-topic-deliveries
sink message topic deliveries
2020-05-22 11:33:43 -03:00
vyzo 5531f27798 sink the FirstMessageDeliveries boost for the messages topic 2020-05-22 17:25:56 +03:00
vyzo cc98117df2 log block validation time 2020-05-22 17:21:37 +03:00
Whyrusleeping ffd340086e Merge pull request #1817 from filecoin-project/feat/sort-miners-by-deal-count
Add command to sort miners by deal counts
2020-05-21 16:06:44 -07:00
Jeromy 805686be2e Add command to sort miners by deal counts 2020-05-21 15:52:20 -07:00
Whyrusleeping 0d3f602d58 Merge pull request #1804 from filecoin-project/feat/seal-verify-shed
put a command for verifying seals into the shed
2020-05-21 10:07:19 -07:00
Whyrusleeping 83436842c5 Merge pull request #1802 from filecoin-project/feat/gfm-v0.2.7
Use latest go-fil-markets
2020-05-21 10:05:54 -07:00
Whyrusleeping bafb922ff7 Merge pull request #1811 from filecoin-project/feat/update-pubsub
Update pubsub and libp2p
2020-05-21 09:51:00 -07:00
Jeromy 6e024d9994 parse ticket and seal randomness flags 2020-05-21 08:26:32 -07:00
vyzo d597c3fb0d increase OpportunisticGraftThreshold to 5 2020-05-21 14:38:11 +03:00
vyzo 24cebb8b2f gomod: update go-libp2p@v0.9.2 2020-05-21 12:13:14 +03:00
vyzo 0cc8446a79 configure Dout=0 for bootstrappers, turn off Mesh Failure Penalty for messages as well 2020-05-21 12:11:22 +03:00
vyzo 3e383d909a gomod: update go-libp2p-pubsub@v0.3.0 2020-05-21 12:08:13 +03:00
hannahhoward 3264a9faad feat(deps): update to latest go-fil-markets
update to go-fil-markets v0.2.7 with latest changes, modify constructors as needed to accomodate new
DS Prefix customization
2020-05-20 16:01:03 -07:00
hannahhoward c52b75d59e fix(deps): update to new 0.2.7 2020-05-20 16:00:03 -07:00
shannonwells 652c257763 passing w/ new namespace wraps 2020-05-20 15:58:59 -07:00
shannonwells 060f23d748 mod tidy 2020-05-20 15:56:58 -07:00
shannonwells e68ab286f6 upgrade lotus to go-fil-markets v0.2.5 2020-05-20 15:56:58 -07:00
Jeromy 92e5cc5ad7 add args usage 2020-05-20 15:28:19 -07:00
Łukasz Magiera 6831ca9e03 Merge pull request #1808 from filecoin-project/feat/extract-jsonrpc-auth
Extract auth utils to go-jsonrpc
2020-05-20 22:22:53 +02:00
Łukasz Magiera f7325a69c1 Extract auth utils to go-jsonrpc 2020-05-20 20:37:45 +02:00
Łukasz Magiera bb78292faf Merge pull request #1807 from filecoin-project/feat/extract-jsonrpc
Extract lib/jsonrpc to go-jsonrpc
2020-05-20 19:58:50 +02:00
Łukasz Magiera eeca031525 extract lib/jsonrpc to go-jsonrpc 2020-05-20 19:49:09 +02:00
Jeromy f82e0e61e1 put a command for verifying seals into the shed 2020-05-20 10:10:35 -07:00
Łukasz Magiera 75e47db520 Merge pull request #1771 from filecoin-project/feat/post-recover
post: Handle Recovering sectors
2020-05-20 19:08:09 +02:00
Łukasz Magiera 3da1a0d8cc post: Declare recoveries for the next deadline 2020-05-20 19:07:31 +02:00
Travis Person a293bd798f init map 2020-05-20 18:41:22 +02:00
Łukasz Magiera ae60001dcc post: Handle Recovering sectors 2020-05-20 18:41:20 +02:00
Łukasz Magiera cea7c41023 Merge pull request #1761 from dtynn/fix/dtynn/use_abs_path_for_client_filestore
use abs path to construct FileManager
2020-05-20 12:49:53 +02:00
Łukasz Magiera 0fe7a0b2e3 Merge pull request #1764 from filecoin-project/feat/has-cache-bs
add blockstore 'Has' caching
2020-05-20 12:48:50 +02:00
Łukasz Magiera 267368d56c Merge pull request #1767 from filecoin-project/feat/html-trace-improvements
add tipset key and height to html trace output
2020-05-20 12:48:05 +02:00
Łukasz Magiera f5451ad455 Merge pull request #1795 from shannon-6block/master
Pset represents the proving sectors, and Sset repensents all sectors
2020-05-20 12:46:22 +02:00
Łukasz Magiera 555537c528 Merge pull request #1791 from filecoin-project/feat/api-gen-2
improving the autogenerated api docs
2020-05-20 12:40:49 +02:00
shannon cc5875c6bd Pset represents the proving sectors, and Sset repensents all sectors 2020-05-20 12:12:13 +08:00
Jeromy c54d050cb7 slightly better methodgroup parsing, and more group docs 2020-05-19 09:49:47 -07:00
Jeromy cb88237305 improving the autogenerated api docs 2020-05-19 08:48:58 -07:00
Whyrusleeping cc44167f2c Merge pull request #1564 from filecoin-project/feat/api-doc-gen
working on api documentation autogeneration
2020-05-18 19:24:31 -07:00
Whyrusleeping 78c656e4c1 Merge pull request #1788 from filecoin-project/asr/issuetemplate
Create an issue template for mining issues
2020-05-18 17:27:55 -07:00
Jeromy 607bcc401c very basic api documentation autogeneration 2020-05-18 17:20:54 -07:00
Whyrusleeping 7fd481ea6f Merge pull request #1766 from filecoin-project/feat/chain-get-decoders
Feat/chain get decoders
2020-05-18 16:06:41 -07:00
Whyrusleeping 9c91daf19a Merge pull request #1787 from filecoin-project/fix/dont-mine-below-min
having power below the minimum means not having power
2020-05-18 16:05:06 -07:00
Aayush Rajasekaran c1ef9d1731 Create an issue template for mining issues 2020-05-18 18:31:53 -04:00
Jeromy eaf69b160c having power below the minimum means not having power 2020-05-18 14:51:42 -07:00
Łukasz Magiera 269286e587 Merge pull request #1785 from filecoin-project/frrist/chain-val-update
update chain-validation
2020-05-18 23:49:11 +02:00
Łukasz Magiera f99c5416ce Merge pull request #1786 from filecoin-project/asr/clideal
Prevent client list-deals from crashing
2020-05-18 23:48:33 +02:00
Aayush Rajasekaran 8f6c3c2cc7 prevent client list-deals from crashing 2020-05-18 17:44:00 -04:00
frrist a2e25897e9 go mod tidy 2020-05-18 14:35:47 -07:00
frrist fc9e046ca7 update chain-validation 2020-05-18 12:50:36 -07:00
Travis Person 5730d46179 Merge pull request #1728 from filecoin-project/frrist/vm-transfer-exitcodes
return correct exit codes from vm transfer
2020-05-18 19:28:48 +00:00
frrist 9165f14693 feedback: fatal errors in vm.transfer 2020-05-18 12:00:52 -07:00
frrist 9305eca97c don't ignore transfer error in delete actor 2020-05-18 12:00:52 -07:00
frrist 0c2e4e2d4f return correct exitcodes from vm transfer 2020-05-18 12:00:52 -07:00
Łukasz Magiera 59725b3af3 Merge pull request #1784 from filecoin-project/feat/update-serialization-vectors
update serialization vectors
2020-05-18 20:34:44 +02:00
Whyrusleeping a0ab3483ed Merge pull request #1770 from filecoin-project/asr/test
Add an interop test for block header serialisation
2020-05-18 11:28:06 -07:00
Jeromy e6f3b79b23 update serialization vectors 2020-05-18 11:02:34 -07:00
Whyrusleeping 1ed6183344 Merge pull request #1782 from filecoin-project/fix/no-metrics-drand
Change drand to one without metrics
2020-05-18 10:24:15 -07:00
Jakub Sztandera 29b1ac964b mod tidy
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-18 19:09:19 +02:00
Jakub Sztandera 8d637c515a Change drand to one without metrics
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
2020-05-18 19:00:30 +02:00
Aayush Rajasekaran 5220a61fc5 Add an interop test for block header serialisation 2020-05-16 17:27:04 -04:00
Jeromy d9502693f0 add tipset key and height to html trace output 2020-05-16 12:53:51 -07:00
Whyrusleeping 9a0d0511c7 Merge pull request #1765 from filecoin-project/fix/miner-info-div-zero
avoid dividing by zero if pset is empty
2020-05-16 12:48:53 -07:00
Jeromy 72eb32ae3c add additional chain get decoders 2020-05-16 12:41:04 -07:00
Jeromy cf9e576028 avoid dividing by zero if pset is empty 2020-05-16 11:35:24 -07:00
Jeromy 9804bd3c4c add blockstore 'Has' caching 2020-05-16 11:31:14 -07:00
dtynn 30e2642f4d use abs path to construct FileManager 2020-05-16 09:36:38 +08:00
Whyrusleeping 54b3eafd6d Merge pull request #1758 from filecoin-project/fix/lotus-bench-secp
register secp signatures for lotus bench usage
2020-05-15 13:05:27 -07:00
Jeromy f6589407c1 register secp signatures for lotus bench usage 2020-05-15 13:01:45 -07:00
Łukasz Magiera 5c73602d24 Merge pull request #1757 from filecoin-project/feat/faster-mpool-add
cache signatures, and dont check them in a lock
2020-05-15 20:27:31 +02:00
Whyrusleeping 70657e35ba Merge pull request #1708 from filecoin-project/feat/block-validator
Improved pubsub block validator
2020-05-15 11:26:26 -07:00
Łukasz Magiera 908053015b Merge pull request #1753 from filecoin-project/feat/less-res-comm2
Update sector-storage with relaxed commit2 resource numbers
2020-05-15 20:17:41 +02:00
Whyrusleeping 8bae22ef61 Merge pull request #1746 from filecoin-project/bug/circleci-mac
install jq in /usr/local/bin
2020-05-15 11:17:12 -07:00
Łukasz Magiera 1012a64110 Merge pull request #1756 from filecoin-project/feat/ffi-88555ec98
Update FFI
2020-05-15 20:16:27 +02:00
Łukasz Magiera 9eb2399539 Merge pull request #1754 from filecoin-project/fix/initial-pledge
state: Calculate slightly larger initial pledge
2020-05-15 20:15:36 +02:00
Łukasz Magiera d539be4875 Merge pull request #1741 from filecoin-project/fix/json-out-chan-closing
properly select channel ID to close for handleOutChans
2020-05-15 20:10:10 +02:00
Jeromy 13fc3f2f54 remove stress test (not really a real test) 2020-05-15 11:00:13 -07:00
Jeromy 33ec4d332b cache signatures, and dont check them in a lock 2020-05-15 10:56:38 -07:00
Whyrusleeping d6bb0500df Merge pull request #1752 from filecoin-project/fix/mpool-slowness
miner: Optimize SelectMessages
2020-05-15 10:48:06 -07:00
Łukasz Magiera b90666b293 miner: optimize SelectMessages 2020-05-15 19:30:31 +02:00
Łukasz Magiera 173a72f374 Merge pull request #1755 from filecoin-project/fix/cw-tkt-crash
chainwatch: Don't crash with nil ticket
2020-05-15 19:17:45 +02:00
Łukasz Magiera 0ae0e89ddd Update FFI 2020-05-15 19:16:06 +02:00
Łukasz Magiera c4d01c04a4 chainwatch: don't crash with nil ticket 2020-05-15 19:06:52 +02:00
Łukasz Magiera 0b56ca3c21 Merge pull request #1751 from filecoin-project/fix/turnoff-block-mesh-penalty
Turn off Mesh Delivery Failure penalty
2020-05-15 19:02:46 +02:00
Łukasz Magiera 022348f426 state: Calculate slightly larger initial pledge 2020-05-15 16:53:35 +02:00
Łukasz Magiera ad108d6051 Update sector-storage with relaxed commit2 resource numbers 2020-05-15 16:00:14 +02:00
vyzo dbe2a1e2cd turn off Mesh Delivery Failure penalty 2020-05-15 12:50:20 +03:00
Aayush Rajasekaran f86a2ced06 Merge pull request #1747 from filecoin-project/asr/docs
Fix 3 typos
2020-05-14 18:34:59 -04:00
Aayush Rajasekaran f7a45f6c12 Fix 3 typos 2020-05-14 18:27:47 -04:00
ognots 658f78d75f install jq in /usr/local/bin
/home/ognots/.bin not in path, causing macos test to fail
2020-05-14 17:32:05 -04:00
Aayush Rajasekaran e9eaee6ef8 Merge pull request #1745 from filecoin-project/asr/docs
Docs finishing touches
2020-05-14 17:08:33 -04:00
Aayush Rajasekaran 505e30c7b2 Docs finishing touches 2020-05-14 16:27:20 -04:00
Jeromy edae6a3ae8 fix the problem 2020-05-14 12:05:01 -07:00
Jeromy 987571dd8c add test to demonstrate failure 2020-05-14 11:48:58 -07:00
vyzo 81bc159b3e cache successful block signature validation 2020-05-14 20:48:40 +03:00
vyzo 50e05ae1ba use sigs.CheckBlockSignature 2020-05-14 20:48:40 +03:00
vyzo 432c69c616 update message validator to provide rejection signal 2020-05-14 20:48:40 +03:00
vyzo e714294273 initialize map 2020-05-14 20:48:19 +03:00
vyzo c3a144bcb6 flesh out signature validation logic 2020-05-14 20:48:19 +03:00
vyzo dd86a289ce cache miner worker keys 2020-05-14 20:48:19 +03:00
vyzo 6e0dac06f4 utility to retrieve miner worker key from the chain 2020-05-14 20:48:19 +03:00
vyzo 5bd0e92068 remove source flagging from bogus CID blocks
it's ineffective.
2020-05-14 20:48:19 +03:00
vyzo b032d3524b configure behaviour penalty for gsv1.1 2020-05-14 20:48:19 +03:00
vyzo 6933df918a gomod: update go-libp2p-pubsub@master 2020-05-14 20:45:25 +03:00
166 changed files with 3448 additions and 3878 deletions
+14 -6
View File
@@ -134,6 +134,9 @@ jobs:
type: string
default: "./..."
description: Import paths of packages to be tested.
winpost-test:
type: string
default: "0"
test-suite-name:
type: string
default: unit
@@ -171,6 +174,7 @@ jobs:
environment:
GOTESTSUM_JUNITFILE: /tmp/test-reports/<< parameters.test-suite-name >>/junit.xml
GOTESTSUM_FORMAT: << parameters.gotestsum-format >>
LOTUS_TEST_WINDOW_POST: << parameters.winpost-test >>
command: |
mkdir -p /tmp/test-reports/<< parameters.test-suite-name >>
gotestsum -- \
@@ -199,6 +203,8 @@ jobs:
test-short:
<<: *test
test-window-post:
<<: *test
build-macos:
description: build darwin lotus binary
@@ -225,9 +231,8 @@ jobs:
- run:
name: Install jq
command: |
mkdir $HOME/.bin
curl --location https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 --output $HOME/.bin/jq
chmod +x $HOME/.bin/jq
curl --location https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 --output /usr/local/bin/jq
chmod +x /usr/local/bin/jq
- restore_cache:
name: restore go mod and cargo cache
key: v3-go-deps-{{ arch }}-{{ checksum "~/go/src/github.com/filecoin-project/lotus/go.sum" }}
@@ -332,11 +337,14 @@ workflows:
ci:
jobs:
- lint-changes:
args: "--new-from-rev origin/master"
- test:
codecov-upload: true
args: "--new-from-rev origin/next"
- mod-tidy-check
- gofmt
- test:
codecov-upload: true
- test-window-post:
go-test-flags: "-run=TestWindowedPost"
winpost-test: "1"
- test-short:
go-test-flags: "--timeout 10m --short"
filters:
+34
View File
@@ -0,0 +1,34 @@
---
name: Sealing Issues
about: Create a report for help with sealing (commit) failures.
title: ''
labels: 'sealing'
assignees: ''
---
Please provide all the information requested here to help us troubleshoot "commit failed" issues.
If the information requested is missing, we will probably have to just ask you to provide it anyway,
before we can help debug.
**Describe the problem**
A brief description of the problem you encountered while proving (sealing) a sector.
Including what commands you ran, and a description of your setup, is very helpful.
**Sectors list**
The output of `./lotus-storage-miner sectors list`.
**Sectors status**
The output of `./lotus-storage-miner sectors status --log <sectorId>` for the failed sector(s).
**Lotus storage miner logs**
Please go through the logs of your storage miner, and include screenshots of any error-like messages you find.
**Version**
The output of `./lotus --version`.
+11 -1
View File
@@ -22,13 +22,23 @@ issues:
- "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this"
- "Potential file inclusion via variable"
- "should have( a package)? comment"
- "Error return value of `logging.SetLogLevel` is not checked"
exclude-use-default: false
exclude-rules:
- path: lotuspond
linters:
- errcheck
- path: node/modules/lp2p
linters:
- golint
- path: ".*_test.go"
- path: build/params_.*\.go
linters:
- golint
- path: .*_test.go
linters:
- gosec
+15 -2
View File
@@ -17,7 +17,7 @@ MODULES:=
CLEAN:=
BINS:=
ldflags=-X=github.com/filecoin-project/lotus/build.CurrentCommit='+git$(subst -,.,$(shell git describe --always --match=NeVeRmAtCh --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null))'
ldflags=-X=github.com/filecoin-project/lotus/build.CurrentCommit=+git.$(subst -,.,$(shell git describe --always --match=NeVeRmAtCh --dirty 2>/dev/null || git rev-parse --short HEAD 2>/dev/null))
ifneq ($(strip $(LDFLAGS)),)
ldflags+=-extldflags=$(LDFLAGS)
endif
@@ -103,6 +103,19 @@ install:
install -C ./lotus-storage-miner /usr/local/bin/lotus-storage-miner
install -C ./lotus-seal-worker /usr/local/bin/lotus-seal-worker
install-services: install
mkdir -p /usr/local/lib/systemd/system
install -C -m 0644 ./scripts/lotus-daemon.service /usr/local/lib/systemd/system/lotus-daemon.service
install -C -m 0644 ./scripts/lotus-miner.service /usr/local/lib/systemd/system/lotus-miner.service
systemctl daemon-reload
@echo
@echo "lotus and lotus-miner services installed. Don't forget to 'systemctl enable lotus|lotus-miner' for it to be enabled on startup."
clean-services:
rm -f /usr/local/lib/systemd/system/lotus-daemon.service
rm -f /usr/local/lib/systemd/system/lotus-miner.service
systemctl daemon-reload
# TOOLS
lotus-seed: $(BUILD_DEPS)
@@ -119,7 +132,7 @@ benchmarks:
@curl -X POST 'http://benchmark.kittyhawk.wtf/benchmark' -d '@bench.json' -u "${benchmark_http_cred}"
.PHONY: benchmarks
pond: build
pond: 2k
go build -o pond ./lotuspond
(cd lotuspond/front && npm i && CI=false npm run build)
.PHONY: pond
+6 -5
View File
@@ -4,17 +4,18 @@ import (
"context"
"fmt"
"github.com/filecoin-project/lotus/build"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
)
type Permission = string
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/lotus/build"
)
type Common interface {
// Auth
AuthVerify(ctx context.Context, token string) ([]Permission, error)
AuthNew(ctx context.Context, perms []Permission) ([]byte, error)
AuthVerify(ctx context.Context, token string) ([]auth.Permission, error)
AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error)
// network
+46 -9
View File
@@ -28,13 +28,18 @@ type FullNode interface {
// TODO: TipSetKeys
// chain
// MethodGroup: Chain
// The Chain method group contains methods for interacting with the
// blockchain, but that do not require any form of state computation
// ChainNotify returns channel with chain head updates
// First message is guaranteed to be of len == 1, and type == 'current'
ChainNotify(context.Context) (<-chan []*HeadChange, error)
// ChainHead returns the current head of the chain
ChainHead(context.Context) (*types.TipSet, error)
// ChainGetRandomness is used to sample the chain for randomness
ChainGetRandomness(ctx context.Context, tsk types.TipSetKey, personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)
// ChainGetBlock returns the block specified by the given CID
ChainGetBlock(context.Context, cid.Cid) (*types.BlockHeader, error)
ChainGetTipSet(context.Context, types.TipSetKey) (*types.TipSet, error)
ChainGetBlockMessages(context.Context, cid.Cid) (*BlockMessages, error)
@@ -52,14 +57,23 @@ type FullNode interface {
ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*HeadChange, error)
ChainExport(context.Context, types.TipSetKey) (<-chan []byte, error)
// syncer
// MethodGroup: Sync
// The Sync method group contains methods for interacting with and
// observing the lotus sync service
// SyncState returns the current status of the lotus sync system
SyncState(context.Context) (*SyncState, error)
// SyncSubmitBlock can be used to submit a newly created block to the
// network through this node
SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) error
SyncIncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error)
SyncMarkBad(ctx context.Context, bcid cid.Cid) error
SyncCheckBad(ctx context.Context, bcid cid.Cid) (string, error)
// messages
// MethodGroup: Mpool
// The Mpool methods are for interacting with the message pool. The message pool
// manages all incoming and outgoing 'messages' going over the network.
MpoolPending(context.Context, types.TipSetKey) ([]*types.SignedMessage, error)
MpoolPush(context.Context, *types.SignedMessage) (cid.Cid, error)
MpoolPushMessage(context.Context, *types.Message) (*types.SignedMessage, error) // get nonce, sign, push
@@ -67,16 +81,14 @@ type FullNode interface {
MpoolSub(context.Context) (<-chan MpoolUpdate, error)
MpoolEstimateGasPrice(context.Context, uint64, address.Address, int64, types.TipSetKey) (types.BigInt, error)
// FullNodeStruct
// miner
// MethodGroup: Miner
MinerGetBaseInfo(context.Context, address.Address, abi.ChainEpoch, types.TipSetKey) (*MiningBaseInfo, error)
MinerCreateBlock(context.Context, *BlockTemplate) (*types.BlockMsg, error)
// // UX ?
// wallet
// MethodGroup: Wallet
WalletNew(context.Context, crypto.SigType) (address.Address, error)
WalletHas(context.Context, address.Address) (bool, error)
@@ -92,14 +104,20 @@ type FullNode interface {
// Other
// MethodGroup: Client
// The Client methods all have to do with interacting with the storage and
// retrieval markets as a client
// ClientImport imports file under the specified path into filestore
ClientImport(ctx context.Context, ref FileRef) (cid.Cid, error)
// ClientStartDeal proposes a deal with a miner
ClientStartDeal(ctx context.Context, params *StartDealParams) (*cid.Cid, error)
// ClientGetDeal info returns the latest information about a given deal
ClientGetDealInfo(context.Context, cid.Cid) (*DealInfo, error)
ClientListDeals(ctx context.Context) ([]DealInfo, error)
ClientHasLocal(ctx context.Context, root cid.Cid) (bool, error)
ClientFindData(ctx context.Context, root cid.Cid) ([]QueryOffer, error)
ClientRetrieve(ctx context.Context, order RetrievalOrder, ref FileRef) error
ClientRetrieve(ctx context.Context, order RetrievalOrder, ref *FileRef) error
ClientQueryAsk(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error)
ClientCalcCommP(ctx context.Context, inpath string, miner address.Address) (*CommPRet, error)
ClientGenCar(ctx context.Context, ref FileRef, outpath string) error
@@ -112,6 +130,9 @@ type FullNode interface {
//ClientListAsks() []Ask
// MethodGroup: State
// The State methods are used to query, inspect, and interact with chain state
// if tipset is nil, we'll use heaviest
StateCall(context.Context, *types.Message, types.TipSetKey) (*InvocResult, error)
StateReplay(context.Context, types.TipSetKey, cid.Cid) (*InvocResult, error)
@@ -126,10 +147,14 @@ type FullNode interface {
StateMinerPower(context.Context, address.Address, types.TipSetKey) (*MinerPower, error)
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error)
StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error)
StateMinerFaults(context.Context, address.Address, types.TipSetKey) ([]abi.SectorNumber, error)
StateMinerFaults(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error)
// Returns all non-expired Faults that occur within lookback epochs of the given tipset
StateAllMinerFaults(ctx context.Context, lookback abi.ChainEpoch, ts types.TipSetKey) ([]*Fault, error)
StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error)
StateMinerInitialPledgeCollateral(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (types.BigInt, error)
StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error)
StateSectorPreCommitInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error)
StateSectorGetInfo(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error)
StatePledgeCollateral(context.Context, types.TipSetKey) (types.BigInt, error)
StateWaitMsg(context.Context, cid.Cid) (*MsgLookup, error)
StateSearchMsg(context.Context, cid.Cid) (*MsgLookup, error)
@@ -146,6 +171,10 @@ type FullNode interface {
StateMinerSectorCount(context.Context, address.Address, types.TipSetKey) (MinerSectors, error)
StateCompute(context.Context, abi.ChainEpoch, []*types.Message, types.TipSetKey) (*ComputeStateOutput, error)
// MethodGroup: Msig
// The Msig methods are used to interact with multisig wallets on the
// filecoin network
MsigGetAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error)
MsigCreate(context.Context, int64, []address.Address, types.BigInt, address.Address, types.BigInt) (cid.Cid, error)
MsigPropose(context.Context, address.Address, address.Address, types.BigInt, address.Address, uint64, []byte) (cid.Cid, error)
@@ -155,6 +184,9 @@ type FullNode interface {
MarketEnsureAvailable(context.Context, address.Address, address.Address, types.BigInt) (cid.Cid, error)
// MarketFreeBalance
// MethodGroup: Paych
// The Paych methods are for interacting with and managing payment channels
PaychGet(ctx context.Context, from, to address.Address, ensureFunds types.BigInt) (*ChannelInfo, error)
PaychList(context.Context) ([]address.Address, error)
PaychStatus(context.Context, address.Address) (*PaychStatus, error)
@@ -424,3 +456,8 @@ const (
MsigApprove MsigProposeResponse = iota
MsigCancel
)
type Fault struct {
Miner address.Address
Epoch abi.ChainEpoch
}
+1 -2
View File
@@ -8,11 +8,10 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/sector-storage/stores"
"github.com/filecoin-project/sector-storage/storiface"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/lotus/chain/types"
)
// StorageMiner is a low-level interface to the Filecoin network storage miner node
+9 -2
View File
@@ -2,6 +2,9 @@ package api
import (
"context"
"io"
"github.com/ipfs/go-cid"
"github.com/filecoin-project/sector-storage/sealtasks"
"github.com/filecoin-project/sector-storage/stores"
@@ -12,7 +15,7 @@ import (
"github.com/filecoin-project/lotus/build"
)
type WorkerApi interface {
type WorkerAPI interface {
Version(context.Context) (build.Version, error)
// TODO: Info() (name, ...) ?
@@ -21,7 +24,11 @@ type WorkerApi interface {
Info(context.Context) (storiface.WorkerInfo, error)
storage.Sealer
Fetch(context.Context, abi.SectorID, stores.SectorFileType, bool) error
UnsealPiece(context.Context, abi.SectorID, storiface.UnpaddedByteIndex, abi.UnpaddedPieceSize, abi.SealRandomness, cid.Cid) error
ReadPiece(context.Context, io.Writer, abi.SectorID, storiface.UnpaddedByteIndex, abi.UnpaddedPieceSize) error
Fetch(context.Context, abi.SectorID, stores.SectorFileType, bool, stores.AcquireMode) error
Closing(context.Context) (<-chan struct{}, error)
}
+13 -86
View File
@@ -1,111 +1,38 @@
package apistruct
import (
"context"
"reflect"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/lotus/api"
)
type permKey int
var permCtxKey permKey
const (
// When changing these, update docs/API.md too
PermRead api.Permission = "read" // default
PermWrite api.Permission = "write"
PermSign api.Permission = "sign" // Use wallet keys for signing
PermAdmin api.Permission = "admin" // Manage permissions
PermRead auth.Permission = "read" // default
PermWrite auth.Permission = "write"
PermSign auth.Permission = "sign" // Use wallet keys for signing
PermAdmin auth.Permission = "admin" // Manage permissions
)
var AllPermissions = []api.Permission{PermRead, PermWrite, PermSign, PermAdmin}
var defaultPerms = []api.Permission{PermRead}
func WithPerm(ctx context.Context, perms []api.Permission) context.Context {
return context.WithValue(ctx, permCtxKey, perms)
}
var AllPermissions = []auth.Permission{PermRead, PermWrite, PermSign, PermAdmin}
var DefaultPerms = []auth.Permission{PermRead}
func PermissionedStorMinerAPI(a api.StorageMiner) api.StorageMiner {
var out StorageMinerStruct
permissionedAny(a, &out.Internal)
permissionedAny(a, &out.CommonStruct.Internal)
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.Internal)
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.CommonStruct.Internal)
return &out
}
func PermissionedFullAPI(a api.FullNode) api.FullNode {
var out FullNodeStruct
permissionedAny(a, &out.Internal)
permissionedAny(a, &out.CommonStruct.Internal)
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.Internal)
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.CommonStruct.Internal)
return &out
}
func PermissionedWorkerAPI(a api.WorkerApi) api.WorkerApi {
func PermissionedWorkerAPI(a api.WorkerAPI) api.WorkerAPI {
var out WorkerStruct
permissionedAny(a, &out.Internal)
auth.PermissionedProxy(AllPermissions, DefaultPerms, a, &out.Internal)
return &out
}
func HasPerm(ctx context.Context, perm api.Permission) bool {
callerPerms, ok := ctx.Value(permCtxKey).([]api.Permission)
if !ok {
callerPerms = defaultPerms
}
for _, callerPerm := range callerPerms {
if callerPerm == perm {
return true
}
}
return false
}
func permissionedAny(in interface{}, out interface{}) {
rint := reflect.ValueOf(out).Elem()
ra := reflect.ValueOf(in)
for f := 0; f < rint.NumField(); f++ {
field := rint.Type().Field(f)
requiredPerm := api.Permission(field.Tag.Get("perm"))
if requiredPerm == "" {
panic("missing 'perm' tag on " + field.Name) // ok
}
// Validate perm tag
ok := false
for _, perm := range AllPermissions {
if requiredPerm == perm {
ok = true
break
}
}
if !ok {
panic("unknown 'perm' tag on " + field.Name) // ok
}
fn := ra.MethodByName(field.Name)
rint.Field(f).Set(reflect.MakeFunc(field.Type, func(args []reflect.Value) (results []reflect.Value) {
ctx := args[0].Interface().(context.Context)
if HasPerm(ctx, requiredPerm) {
return fn.Call(args)
}
err := xerrors.Errorf("missing permission to invoke '%s' (need '%s')", field.Name, requiredPerm)
rerr := reflect.ValueOf(&err).Elem()
if field.Type.NumOut() == 2 {
return []reflect.Value{
reflect.Zero(field.Type.Out(0)),
rerr,
}
} else {
return []reflect.Value{rerr}
}
}))
}
}
+56 -27
View File
@@ -2,6 +2,7 @@ package apistruct
import (
"context"
"io"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/network"
@@ -9,6 +10,8 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storagemarket"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/sector-storage/sealtasks"
"github.com/filecoin-project/sector-storage/stores"
"github.com/filecoin-project/sector-storage/storiface"
@@ -30,8 +33,8 @@ var _ = AllPermissions
type CommonStruct struct {
Internal struct {
AuthVerify func(ctx context.Context, token string) ([]api.Permission, error) `perm:"read"`
AuthNew func(ctx context.Context, perms []api.Permission) ([]byte, error) `perm:"admin"`
AuthVerify func(ctx context.Context, token string) ([]auth.Permission, error) `perm:"read"`
AuthNew func(ctx context.Context, perms []auth.Permission) ([]byte, error) `perm:"admin"`
NetConnectedness func(context.Context, peer.ID) (network.Connectedness, error) `perm:"read"`
NetPeers func(context.Context) ([]peer.AddrInfo, error) `perm:"read"`
@@ -108,7 +111,7 @@ type FullNodeStruct struct {
ClientStartDeal func(ctx context.Context, params *api.StartDealParams) (*cid.Cid, error) `perm:"admin"`
ClientGetDealInfo func(context.Context, cid.Cid) (*api.DealInfo, error) `perm:"read"`
ClientListDeals func(ctx context.Context) ([]api.DealInfo, error) `perm:"write"`
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref api.FileRef) error `perm:"admin"`
ClientRetrieve func(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) error `perm:"admin"`
ClientQueryAsk func(ctx context.Context, p peer.ID, miner address.Address) (*storagemarket.SignedStorageAsk, error) `perm:"read"`
ClientCalcCommP func(ctx context.Context, inpath string, miner address.Address) (*api.CommPRet, error) `perm:"read"`
ClientGenCar func(ctx context.Context, ref api.FileRef, outpath string) error `perm:"write"`
@@ -120,10 +123,13 @@ type FullNodeStruct struct {
StateMinerPower func(context.Context, address.Address, types.TipSetKey) (*api.MinerPower, error) `perm:"read"`
StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) `perm:"read"`
StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error) `perm:"read"`
StateMinerFaults func(context.Context, address.Address, types.TipSetKey) ([]abi.SectorNumber, error) `perm:"read"`
StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error) `perm:"read"`
StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"`
StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error) `perm:"read"`
StateMinerInitialPledgeCollateral func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (types.BigInt, error) `perm:"read"`
StateMinerAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"`
StateSectorPreCommitInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (miner.SectorPreCommitOnChainInfo, error) `perm:"read"`
StateSectorGetInfo func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (*miner.SectorOnChainInfo, error) `perm:"read"`
StateCall func(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) `perm:"read"`
StateReplay func(context.Context, types.TipSetKey, cid.Cid) (*api.InvocResult, error) `perm:"read"`
StateGetActor func(context.Context, address.Address, types.TipSetKey) (*types.Actor, error) `perm:"read"`
@@ -197,16 +203,16 @@ type StorageMinerStruct struct {
WorkerConnect func(context.Context, string) error `perm:"admin"` // TODO: worker perm
WorkerStats func(context.Context) (map[uint64]storiface.WorkerStats, error) `perm:"admin"`
StorageList func(context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"`
StorageLocal func(context.Context) (map[stores.ID]string, error) `perm:"admin"`
StorageStat func(context.Context, stores.ID) (stores.FsStat, error) `perm:"admin"`
StorageAttach func(context.Context, stores.StorageInfo, stores.FsStat) error `perm:"admin"`
StorageDeclareSector func(context.Context, stores.ID, abi.SectorID, stores.SectorFileType) error `perm:"admin"`
StorageDropSector func(context.Context, stores.ID, abi.SectorID, stores.SectorFileType) error `perm:"admin"`
StorageFindSector func(context.Context, abi.SectorID, stores.SectorFileType, bool) ([]stores.StorageInfo, error) `perm:"admin"`
StorageInfo func(context.Context, stores.ID) (stores.StorageInfo, error) `perm:"admin"`
StorageBestAlloc func(ctx context.Context, allocate stores.SectorFileType, spt abi.RegisteredProof, sealing bool) ([]stores.StorageInfo, error) `perm:"admin"`
StorageReportHealth func(ctx context.Context, id stores.ID, report stores.HealthReport) error `perm:"admin"`
StorageList func(context.Context) (map[stores.ID][]stores.Decl, error) `perm:"admin"`
StorageLocal func(context.Context) (map[stores.ID]string, error) `perm:"admin"`
StorageStat func(context.Context, stores.ID) (stores.FsStat, error) `perm:"admin"`
StorageAttach func(context.Context, stores.StorageInfo, stores.FsStat) error `perm:"admin"`
StorageDeclareSector func(context.Context, stores.ID, abi.SectorID, stores.SectorFileType, bool) error `perm:"admin"`
StorageDropSector func(context.Context, stores.ID, abi.SectorID, stores.SectorFileType) error `perm:"admin"`
StorageFindSector func(context.Context, abi.SectorID, stores.SectorFileType, bool) ([]stores.SectorStorageInfo, error) `perm:"admin"`
StorageInfo func(context.Context, stores.ID) (stores.StorageInfo, error) `perm:"admin"`
StorageBestAlloc func(ctx context.Context, allocate stores.SectorFileType, spt abi.RegisteredProof, sealing stores.PathType) ([]stores.StorageInfo, error) `perm:"admin"`
StorageReportHealth func(ctx context.Context, id stores.ID, report stores.HealthReport) error `perm:"admin"`
DealsImportData func(ctx context.Context, dealPropCid cid.Cid, file string) error `perm:"write"`
DealsList func(ctx context.Context) ([]storagemarket.StorageDeal, error) `perm:"read"`
@@ -231,7 +237,10 @@ type WorkerStruct struct {
SealCommit2 func(context.Context, abi.SectorID, storage.Commit1Out) (storage.Proof, error) `perm:"admin"`
FinalizeSector func(context.Context, abi.SectorID) error `perm:"admin"`
Fetch func(context.Context, abi.SectorID, stores.SectorFileType, bool) error `perm:"admin"`
UnsealPiece func(context.Context, abi.SectorID, storiface.UnpaddedByteIndex, abi.UnpaddedPieceSize, abi.SealRandomness, cid.Cid) error `perm:"admin"`
ReadPiece func(context.Context, io.Writer, abi.SectorID, storiface.UnpaddedByteIndex, abi.UnpaddedPieceSize) error `perm:"admin"`
Fetch func(context.Context, abi.SectorID, stores.SectorFileType, bool, stores.AcquireMode) error `perm:"admin"`
Closing func(context.Context) (<-chan struct{}, error) `perm:"admin"`
}
@@ -239,11 +248,11 @@ type WorkerStruct struct {
// CommonStruct
func (c *CommonStruct) AuthVerify(ctx context.Context, token string) ([]api.Permission, error) {
func (c *CommonStruct) AuthVerify(ctx context.Context, token string) ([]auth.Permission, error) {
return c.Internal.AuthVerify(ctx, token)
}
func (c *CommonStruct) AuthNew(ctx context.Context, perms []api.Permission) ([]byte, error) {
func (c *CommonStruct) AuthNew(ctx context.Context, perms []auth.Permission) ([]byte, error) {
return c.Internal.AuthNew(ctx, perms)
}
@@ -318,7 +327,7 @@ func (c *FullNodeStruct) ClientListDeals(ctx context.Context) ([]api.DealInfo, e
return c.Internal.ClientListDeals(ctx)
}
func (c *FullNodeStruct) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, ref api.FileRef) error {
func (c *FullNodeStruct) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, ref *api.FileRef) error {
return c.Internal.ClientRetrieve(ctx, order, ref)
}
@@ -533,10 +542,18 @@ func (c *FullNodeStruct) StateMinerDeadlines(ctx context.Context, m address.Addr
return c.Internal.StateMinerDeadlines(ctx, m, tsk)
}
func (c *FullNodeStruct) StateMinerFaults(ctx context.Context, actor address.Address, tsk types.TipSetKey) ([]abi.SectorNumber, error) {
func (c *FullNodeStruct) StateMinerFaults(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*abi.BitField, error) {
return c.Internal.StateMinerFaults(ctx, actor, tsk)
}
func (c *FullNodeStruct) StateAllMinerFaults(ctx context.Context, cutoff abi.ChainEpoch, endTsk types.TipSetKey) ([]*api.Fault, error) {
return c.Internal.StateAllMinerFaults(ctx, cutoff, endTsk)
}
func (c *FullNodeStruct) StateMinerRecoveries(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*abi.BitField, error) {
return c.Internal.StateMinerRecoveries(ctx, actor, tsk)
}
func (c *FullNodeStruct) StateMinerInitialPledgeCollateral(ctx context.Context, maddr address.Address, snum abi.SectorNumber, tsk types.TipSetKey) (types.BigInt, error) {
return c.Internal.StateMinerInitialPledgeCollateral(ctx, maddr, snum, tsk)
}
@@ -549,6 +566,10 @@ func (c *FullNodeStruct) StateSectorPreCommitInfo(ctx context.Context, maddr add
return c.Internal.StateSectorPreCommitInfo(ctx, maddr, n, tsk)
}
func (c *FullNodeStruct) StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*miner.SectorOnChainInfo, error) {
return c.Internal.StateSectorGetInfo(ctx, maddr, n, tsk)
}
func (c *FullNodeStruct) StateCall(ctx context.Context, msg *types.Message, tsk types.TipSetKey) (*api.InvocResult, error) {
return c.Internal.StateCall(ctx, msg, tsk)
}
@@ -745,15 +766,15 @@ func (c *StorageMinerStruct) StorageAttach(ctx context.Context, si stores.Storag
return c.Internal.StorageAttach(ctx, si, st)
}
func (c *StorageMinerStruct) StorageDeclareSector(ctx context.Context, storageId stores.ID, s abi.SectorID, ft stores.SectorFileType) error {
return c.Internal.StorageDeclareSector(ctx, storageId, s, ft)
func (c *StorageMinerStruct) StorageDeclareSector(ctx context.Context, storageId stores.ID, s abi.SectorID, ft stores.SectorFileType, primary bool) error {
return c.Internal.StorageDeclareSector(ctx, storageId, s, ft, primary)
}
func (c *StorageMinerStruct) StorageDropSector(ctx context.Context, storageId stores.ID, s abi.SectorID, ft stores.SectorFileType) error {
return c.Internal.StorageDropSector(ctx, storageId, s, ft)
}
func (c *StorageMinerStruct) StorageFindSector(ctx context.Context, si abi.SectorID, types stores.SectorFileType, allowFetch bool) ([]stores.StorageInfo, error) {
func (c *StorageMinerStruct) StorageFindSector(ctx context.Context, si abi.SectorID, types stores.SectorFileType, allowFetch bool) ([]stores.SectorStorageInfo, error) {
return c.Internal.StorageFindSector(ctx, si, types, allowFetch)
}
@@ -773,8 +794,8 @@ func (c *StorageMinerStruct) StorageInfo(ctx context.Context, id stores.ID) (sto
return c.Internal.StorageInfo(ctx, id)
}
func (c *StorageMinerStruct) StorageBestAlloc(ctx context.Context, allocate stores.SectorFileType, spt abi.RegisteredProof, sealing bool) ([]stores.StorageInfo, error) {
return c.Internal.StorageBestAlloc(ctx, allocate, spt, sealing)
func (c *StorageMinerStruct) StorageBestAlloc(ctx context.Context, allocate stores.SectorFileType, spt abi.RegisteredProof, pt stores.PathType) ([]stores.StorageInfo, error) {
return c.Internal.StorageBestAlloc(ctx, allocate, spt, pt)
}
func (c *StorageMinerStruct) StorageReportHealth(ctx context.Context, id stores.ID, report stores.HealthReport) error {
@@ -847,8 +868,16 @@ func (w *WorkerStruct) FinalizeSector(ctx context.Context, sector abi.SectorID)
return w.Internal.FinalizeSector(ctx, sector)
}
func (w *WorkerStruct) Fetch(ctx context.Context, id abi.SectorID, fileType stores.SectorFileType, b bool) error {
return w.Internal.Fetch(ctx, id, fileType, b)
func (w *WorkerStruct) UnsealPiece(ctx context.Context, id abi.SectorID, index storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize, randomness abi.SealRandomness, c cid.Cid) error {
return w.Internal.UnsealPiece(ctx, id, index, size, randomness, c)
}
func (w *WorkerStruct) ReadPiece(ctx context.Context, writer io.Writer, id abi.SectorID, index storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) error {
return w.Internal.ReadPiece(ctx, writer, id, index, size)
}
func (w *WorkerStruct) Fetch(ctx context.Context, id abi.SectorID, fileType stores.SectorFileType, b bool, am stores.AcquireMode) error {
return w.Internal.Fetch(ctx, id, fileType, b, am)
}
func (w *WorkerStruct) Closing(ctx context.Context) (<-chan struct{}, error) {
@@ -858,4 +887,4 @@ func (w *WorkerStruct) Closing(ctx context.Context) (<-chan struct{}, error) {
var _ api.Common = &CommonStruct{}
var _ api.FullNode = &FullNodeStruct{}
var _ api.StorageMiner = &StorageMinerStruct{}
var _ api.WorkerApi = &WorkerStruct{}
var _ api.WorkerAPI = &WorkerStruct{}
+4 -3
View File
@@ -1,11 +1,12 @@
package client
import (
"github.com/filecoin-project/lotus/api/apistruct"
"net/http"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/lib/jsonrpc"
"github.com/filecoin-project/lotus/api/apistruct"
)
// NewCommonRPC creates a new http jsonrpc client.
@@ -47,7 +48,7 @@ func NewStorageMinerRPC(addr string, requestHeader http.Header) (api.StorageMine
return &res, closer, err
}
func NewWorkerRPC(addr string, requestHeader http.Header) (api.WorkerApi, jsonrpc.ClientCloser, error) {
func NewWorkerRPC(addr string, requestHeader http.Header) (api.WorkerAPI, jsonrpc.ClientCloser, error) {
var res apistruct.WorkerStruct
closer, err := jsonrpc.NewMergeClient(addr, "Filecoin",
[]interface{}{
+339
View File
@@ -0,0 +1,339 @@
package main
import (
"encoding/json"
"fmt"
"go/ast"
"go/parser"
"go/token"
"reflect"
"sort"
"strings"
"time"
"unicode"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-bitfield"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-filestore"
"github.com/libp2p/go-libp2p-core/network"
peer "github.com/libp2p/go-libp2p-peer"
"github.com/multiformats/go-multiaddr"
)
var ExampleValues = map[reflect.Type]interface{}{
reflect.TypeOf(auth.Permission("")): auth.Permission("write"),
reflect.TypeOf(""): "string value",
reflect.TypeOf(uint64(42)): uint64(42),
reflect.TypeOf(byte(7)): byte(7),
reflect.TypeOf([]byte{}): []byte("byte array"),
}
func addExample(v interface{}) {
ExampleValues[reflect.TypeOf(v)] = v
}
func init() {
c, err := cid.Decode("bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4")
if err != nil {
panic(err)
}
ExampleValues[reflect.TypeOf(c)] = c
c2, err := cid.Decode("bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve")
if err != nil {
panic(err)
}
tsk := types.NewTipSetKey(c, c2)
ExampleValues[reflect.TypeOf(tsk)] = tsk
addr, err := address.NewIDAddress(1234)
if err != nil {
panic(err)
}
ExampleValues[reflect.TypeOf(addr)] = addr
pid, err := peer.IDB58Decode("12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf")
if err != nil {
panic(err)
}
addExample(pid)
addExample(bitfield.NewFromSet([]uint64{5}))
addExample(abi.RegisteredProof_StackedDRG32GiBPoSt)
addExample(abi.ChainEpoch(10101))
addExample(crypto.SigTypeBLS)
addExample(int64(9))
addExample(abi.MethodNum(1))
addExample(exitcode.ExitCode(0))
addExample(crypto.DomainSeparationTag_ElectionProofProduction)
addExample(true)
addExample(abi.UnpaddedPieceSize(1024))
addExample(abi.UnpaddedPieceSize(1024).Padded())
addExample(abi.DealID(5432))
addExample(filestore.StatusFileChanged)
addExample(abi.SectorNumber(9))
addExample(abi.SectorSize(32 * 1024 * 1024 * 1024))
addExample(api.MpoolChange(0))
addExample(network.Connected)
addExample(dtypes.NetworkName("lotus"))
addExample(api.SyncStateStage(1))
addExample(build.APIVersion)
addExample(api.PCHInbound)
addExample(time.Minute)
addExample(&types.ExecutionResult{
Msg: exampleValue(reflect.TypeOf(&types.Message{})).(*types.Message),
MsgRct: exampleValue(reflect.TypeOf(&types.MessageReceipt{})).(*types.MessageReceipt),
})
addExample(map[string]types.Actor{
"t01236": exampleValue(reflect.TypeOf(types.Actor{})).(types.Actor),
})
addExample(map[string]api.MarketDeal{
"t026363": exampleValue(reflect.TypeOf(api.MarketDeal{})).(api.MarketDeal),
})
addExample(map[string]api.MarketBalance{
"t026363": exampleValue(reflect.TypeOf(api.MarketBalance{})).(api.MarketBalance),
})
maddr, err := multiaddr.NewMultiaddr("/ip4/52.36.61.156/tcp/1347/p2p/12D3KooWFETiESTf1v4PGUvtnxMAcEFMzLZbJGg4tjWfGEimYior")
if err != nil {
panic(err)
}
// because reflect.TypeOf(maddr) returns the concrete type...
ExampleValues[reflect.TypeOf(struct{ A multiaddr.Multiaddr }{}).Field(0).Type] = maddr
}
func exampleValue(t reflect.Type) interface{} {
v, ok := ExampleValues[t]
if ok {
return v
}
switch t.Kind() {
case reflect.Slice:
out := reflect.New(t).Elem()
reflect.Append(out, reflect.ValueOf(exampleValue(t.Elem())))
return out.Interface()
case reflect.Chan:
return exampleValue(t.Elem())
case reflect.Struct:
es := exampleStruct(t)
v := reflect.ValueOf(es).Elem().Interface()
ExampleValues[t] = v
return v
case reflect.Array:
out := reflect.New(t).Elem()
for i := 0; i < t.Len(); i++ {
out.Index(i).Set(reflect.ValueOf(exampleValue(t.Elem())))
}
return out.Interface()
case reflect.Ptr:
if t.Elem().Kind() == reflect.Struct {
es := exampleStruct(t.Elem())
//ExampleValues[t] = es
return es
}
case reflect.Interface:
return struct{}{}
}
panic(fmt.Sprintf("No example value for type: %s", t))
}
func exampleStruct(t reflect.Type) interface{} {
ns := reflect.New(t)
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
if strings.Title(f.Name) == f.Name {
ns.Elem().Field(i).Set(reflect.ValueOf(exampleValue(f.Type)))
}
}
return ns.Interface()
}
type Visitor struct {
Methods map[string]ast.Node
}
func (v *Visitor) Visit(node ast.Node) ast.Visitor {
st, ok := node.(*ast.TypeSpec)
if !ok {
return v
}
if st.Name.Name != "FullNode" {
return nil
}
iface := st.Type.(*ast.InterfaceType)
for _, m := range iface.Methods.List {
if len(m.Names) > 0 {
v.Methods[m.Names[0].Name] = m
}
}
return v
}
const noComment = "There are not yet any comments for this method."
func parseApiASTInfo() (map[string]string, map[string]string) {
fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, "./api", nil, parser.AllErrors|parser.ParseComments)
if err != nil {
fmt.Println("parse error: ", err)
}
ap := pkgs["api"]
f := ap.Files["api/api_full.go"]
cmap := ast.NewCommentMap(fset, f, f.Comments)
v := &Visitor{make(map[string]ast.Node)}
ast.Walk(v, pkgs["api"])
groupDocs := make(map[string]string)
out := make(map[string]string)
for mn, node := range v.Methods {
cs := cmap.Filter(node).Comments()
if len(cs) == 0 {
out[mn] = noComment
} else {
for _, c := range cs {
if strings.HasPrefix(c.Text(), "MethodGroup:") {
parts := strings.Split(c.Text(), "\n")
groupName := strings.TrimSpace(parts[0][12:])
comment := strings.Join(parts[1:], "\n")
groupDocs[groupName] = comment
break
}
}
last := cs[len(cs)-1].Text()
if !strings.HasPrefix(last, "MethodGroup:") {
out[mn] = last
} else {
out[mn] = noComment
}
}
}
return out, groupDocs
}
type MethodGroup struct {
GroupName string
Header string
Methods []*Method
}
type Method struct {
Comment string
Name string
InputExample string
ResponseExample string
}
func methodGroupFromName(mn string) string {
i := strings.IndexFunc(mn[1:], func(r rune) bool {
return unicode.IsUpper(r)
})
if i < 0 {
return ""
}
return mn[:i+1]
}
func main() {
comments, groupComments := parseApiASTInfo()
groups := make(map[string]*MethodGroup)
var api struct{ api.FullNode }
t := reflect.TypeOf(api)
for i := 0; i < t.NumMethod(); i++ {
m := t.Method(i)
groupName := methodGroupFromName(m.Name)
g, ok := groups[groupName]
if !ok {
g = new(MethodGroup)
g.Header = groupComments[groupName]
g.GroupName = groupName
groups[groupName] = g
}
var args []interface{}
ft := m.Func.Type()
for j := 2; j < ft.NumIn(); j++ {
inp := ft.In(j)
args = append(args, exampleValue(inp))
}
v, err := json.Marshal(args)
if err != nil {
panic(err)
}
outv := exampleValue(ft.Out(0))
ov, err := json.Marshal(outv)
if err != nil {
panic(err)
}
g.Methods = append(g.Methods, &Method{
Name: m.Name,
Comment: comments[m.Name],
InputExample: string(v),
ResponseExample: string(ov),
})
}
var groupslice []*MethodGroup
for _, g := range groups {
groupslice = append(groupslice, g)
}
sort.Slice(groupslice, func(i, j int) bool {
return groupslice[i].GroupName < groupslice[j].GroupName
})
for _, g := range groupslice {
g := g
fmt.Printf("## %s\n", g.GroupName)
fmt.Printf("%s\n\n", g.Header)
sort.Slice(g.Methods, func(i, j int) bool {
return g.Methods[i].Name < g.Methods[j].Name
})
for _, m := range g.Methods {
fmt.Printf("### %s\n", m.Name)
fmt.Printf("%s\n\n", m.Comment)
fmt.Printf("Inputs: `%s`\n\n", m.InputExample)
fmt.Printf("Response: `%s`\n\n", m.ResponseExample)
}
}
}
+2 -2
View File
@@ -193,14 +193,14 @@ func testRetrieval(t *testing.T, ctx context.Context, err error, client *impl.Fu
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(rpath)
defer os.RemoveAll(rpath) //nolint:errcheck
caddr, err := client.WalletDefaultAddress(ctx)
if err != nil {
t.Fatal(err)
}
ref := api.FileRef{
ref := &api.FileRef{
Path: filepath.Join(rpath, "ret"),
IsCAR: carExport,
}
+6 -4
View File
@@ -4,9 +4,11 @@ import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/stretchr/testify/assert"
)
type TestNode struct {
@@ -21,6 +23,8 @@ type TestStorageNode struct {
var PresealGenesis = -1
const GenesisPreseals = 2
type StorageMiner struct {
Full int
Preseal int
@@ -60,9 +64,7 @@ func (ts *testSuite) testVersion(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if v.Version != build.BuildVersion {
t.Error("Version didn't work properly")
}
require.Equal(t, v.Version, build.BuildVersion)
}
func (ts *testSuite) testID(t *testing.T) {
+169
View File
@@ -0,0 +1,169 @@
package test
import (
"context"
"fmt"
"github.com/filecoin-project/lotus/api"
"os"
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/specs-actors/actors/abi"
miner2 "github.com/filecoin-project/specs-actors/actors/builtin/miner"
sealing "github.com/filecoin-project/storage-fsm"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/impl"
)
func TestPledgeSector(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
os.Setenv("BELLMAN_NO_GPU", "1")
ctx := context.Background()
n, sn := b(t, 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)
}
time.Sleep(time.Second)
mine := true
done := make(chan struct{})
go func() {
defer close(done)
for mine {
time.Sleep(blocktime)
if err := sn[0].MineOne(ctx, func(bool) {}); err != nil {
t.Error(err)
}
}
}()
pledgeSectors(t, ctx, miner, nSectors)
mine = false
<-done
}
func pledgeSectors(t *testing.T, ctx context.Context, miner TestStorageNode, n int) {
for i := 0; i < n; 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 {
break
}
time.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)
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)
}
}
time.Sleep(100 * time.Millisecond)
fmt.Printf("WaitSeal: %d\n", len(s))
}
}
func TestWindowPost(t *testing.T, b APIBuilder, blocktime time.Duration, nSectors int) {
os.Setenv("BELLMAN_NO_GPU", "1")
ctx := context.Background()
n, sn := b(t, 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)
}
time.Sleep(time.Second)
mine := true
done := make(chan struct{})
go func() {
defer close(done)
for mine {
time.Sleep(blocktime)
if err := sn[0].MineOne(ctx, func(bool) {}); err != nil {
t.Error(err)
}
}
}()
pledgeSectors(t, ctx, miner, nSectors)
maddr, err := miner.ActorAddress(ctx)
require.NoError(t, err)
di, err := client.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
require.NoError(t, err)
fmt.Printf("Running one proving periods\n")
for {
head, err := client.ChainHead(ctx)
require.NoError(t, err)
if head.Height() > di.PeriodStart+(miner2.WPoStProvingPeriod)+2 {
break
}
if head.Height()%100 == 0 {
fmt.Printf("@%d\n", head.Height())
}
time.Sleep(blocktime)
}
p, err := client.StateMinerPower(ctx, maddr, types.EmptyTSK)
require.NoError(t, err)
ssz, err := miner.ActorSectorSize(ctx, maddr)
require.NoError(t, err)
require.Equal(t, p.MinerPower, p.TotalPower)
require.Equal(t, p.MinerPower.RawBytePower, types.NewInt(uint64(ssz)*uint64(nSectors+GenesisPreseals)))
// TODO: Inject faults here
mine = false
<-done
}
+1
View File
@@ -7,6 +7,7 @@ import (
)
// TODO: check if this exists anywhere else
type MultiaddrSlice []ma.Multiaddr
func (m *MultiaddrSlice) UnmarshalJSON(raw []byte) (err error) {
+6 -12
View File
@@ -1,12 +1,6 @@
/dns4/bootstrap-0-sin.fil-test.net/tcp/1347/p2p/12D3KooWKNF7vNFEhnvB45E9mw2B5z6t419W3ziZPLdUDVnLLKGs
/ip4/86.109.15.57/tcp/1347/p2p/12D3KooWKNF7vNFEhnvB45E9mw2B5z6t419W3ziZPLdUDVnLLKGs
/dns4/bootstrap-0-dfw.fil-test.net/tcp/1347/p2p/12D3KooWECJTm7RUPyGfNbRwm6y2fK4wA7EB8rDJtWsq5AKi7iDr
/ip4/139.178.84.45/tcp/1347/p2p/12D3KooWECJTm7RUPyGfNbRwm6y2fK4wA7EB8rDJtWsq5AKi7iDr
/dns4/bootstrap-0-fra.fil-test.net/tcp/1347/p2p/12D3KooWC7MD6m7iNCuDsYtNr7xVtazihyVUizBbhmhEiyMAm9ym
/ip4/136.144.49.17/tcp/1347/p2p/12D3KooWC7MD6m7iNCuDsYtNr7xVtazihyVUizBbhmhEiyMAm9ym
/dns4/bootstrap-1-sin.fil-test.net/tcp/1347/p2p/12D3KooWD8eYqsKcEMFax6EbWN3rjA7qFsxCez2rmN8dWqkzgNaN
/ip4/86.109.15.55/tcp/1347/p2p/12D3KooWD8eYqsKcEMFax6EbWN3rjA7qFsxCez2rmN8dWqkzgNaN
/dns4/bootstrap-1-dfw.fil-test.net/tcp/1347/p2p/12D3KooWLB3RR8frLAmaK4ntHC2dwrAjyGzQgyUzWxAum1FxyyqD
/ip4/139.178.84.41/tcp/1347/p2p/12D3KooWLB3RR8frLAmaK4ntHC2dwrAjyGzQgyUzWxAum1FxyyqD
/dns4/bootstrap-1-fra.fil-test.net/tcp/1347/p2p/12D3KooWGPDJAw3HW4uVU3JEQBfFaZ1kdpg4HvvwRMVpUYbzhsLQ
/ip4/136.144.49.131/tcp/1347/p2p/12D3KooWGPDJAw3HW4uVU3JEQBfFaZ1kdpg4HvvwRMVpUYbzhsLQ
/dns4/t01000.miner.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWNMVRk3KkMANV67A4zPxB83FtvLouwsYGitEofY1ympJs
/ip4/34.217.110.132/tcp/1347/p2p/12D3KooWNMVRk3KkMANV67A4zPxB83FtvLouwsYGitEofY1ympJs
/dns4/peer0.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWM1ufVLkBAyyf8Jn5DMdmW5gA7upSvCUatoneHp6yUEtd
/ip4/54.187.182.170/tcp/1347/p2p/12D3KooWM1ufVLkBAyyf8Jn5DMdmW5gA7upSvCUatoneHp6yUEtd
/dns4/peer1.interopnet.kittyhawk.wtf/tcp/1347/p2p/12D3KooWLxMPSbs7XEPhyUiSo6RpTTRAkRiD1bp6uKYxyZx4QSZR
/ip4/52.24.84.39/tcp/1347/p2p/12D3KooWLxMPSbs7XEPhyUiSo6RpTTRAkRiD1bp6uKYxyZx4QSZR
Binary file not shown.
+1 -1
View File
@@ -2,6 +2,6 @@ package build
import rice "github.com/GeertJohan/go.rice"
func ParametersJson() []byte {
func ParametersJSON() []byte {
return rice.MustFindBox("proof-params").MustBytes("parameters.json")
}
+2
View File
@@ -16,6 +16,8 @@ func init() {
abi.RegisteredProof_StackedDRG2KiBSeal: {},
}
verifreg.MinVerifiedDealSize = big.NewInt(256)
BuildType |= Build2k
}
// Seconds
+1
View File
@@ -4,6 +4,7 @@ package build
func init() {
InsecurePoStValidation = true
BuildType |= BuildDebug
}
// NOTE: Also includes settings from params_2k
+6 -7
View File
@@ -109,16 +109,15 @@ const BadBlockCacheSize = 1 << 15
// 10 block reorg.
const BlsSignatureCacheSize = 40000
// Size of signature verification cache
// 32k keeps the cache around 10MB in size, max
const VerifSigCacheSize = 32000
// ///////
// Limits
// TODO: If this is gonna stay, it should move to specs-actors
const BlockMessageLimit = 512
const BlockGasLimit = 100_000_000
const BlockGasLimit = 100_000_000_000
var DrandCoeffs = []string{
"82c279cce744450e68de98ee08f9698a01dd38f8e3be3c53f2b840fb9d09ad62a0b6b87981e179e1b14bc9a2d284c985",
"82d51308ad346c686f81b8094551597d7b963295cbf313401a93df9baf52d5ae98a87745bee70839a4d6e65c342bd15b",
"94eebfd53f4ba6a3b8304236400a12e73885e5a781509a5c8d41d2e8b476923d8ea6052649b3c17282f596217f96c5de",
"8dc4231e42b4edf39e86ef1579401692480647918275da767d3e558c520d6375ad953530610fd27daf110187877a65d0",
}
var DrandChain = `{"public_key":"922a2e93828ff83345bae533f5172669a26c02dc76d6bf59c80892e12ab1455c229211886f35bb56af6d5bea981024df","period":25,"genesis_time":1590445175,"hash":"138a324aa6540f93d0dad002aa89454b1bec2b6e948682cde6bd4db40f4b7c9b"}`
+4 -3
View File
@@ -12,10 +12,11 @@ import (
)
func init() {
power.ConsensusMinerMinPower = big.NewInt(1024 << 30)
power.ConsensusMinerMinPower = big.NewInt(1024 << 20)
miner.SupportedProofTypes = map[abi.RegisteredProof]struct{}{
abi.RegisteredProof_StackedDRG32GiBSeal: {},
abi.RegisteredProof_StackedDRG64GiBSeal: {},
abi.RegisteredProof_StackedDRG512MiBSeal: {},
abi.RegisteredProof_StackedDRG32GiBSeal: {},
abi.RegisteredProof_StackedDRG64GiBSeal: {},
}
}
+25 -2
View File
@@ -3,11 +3,33 @@ package build
import "fmt"
var CurrentCommit string
var BuildType int
const (
BuildDefault = 0
Build2k = 0x1
BuildDebug = 0x3
)
func buildType() string {
switch BuildType {
case BuildDefault:
return ""
case BuildDebug:
return "+debug"
case Build2k:
return "+2k"
default:
return "+huh?"
}
}
// BuildVersion is the local build version, set by build system
const BuildVersion = "0.3.0"
const BuildVersion = "0.4.0"
var UserVersion = BuildVersion + CurrentCommit
func UserVersion() string {
return BuildVersion + buildType() + CurrentCommit
}
type Version uint32
@@ -33,6 +55,7 @@ func (ve Version) EqMajorMinor(v2 Version) bool {
// APIVersion is a semver version of the rpc api exposed
var APIVersion Version = newVer(0, 3, 0)
//nolint:varcheck
const (
majorMask = 0xff0000
minorMask = 0xffff00
+1
View File
@@ -50,6 +50,7 @@ func Newf(retCode exitcode.ExitCode, format string, args ...interface{}) ActorEr
}
// todo: bit hacky
func NewfSkip(skip int, retCode exitcode.ExitCode, format string, args ...interface{}) ActorError {
if retCode == 0 {
return &actorError{
+74 -116
View File
@@ -1,45 +1,45 @@
package drand
import (
"bytes"
"context"
"math/rand"
"sync"
"time"
dchain "github.com/drand/drand/chain"
dclient "github.com/drand/drand/client"
gclient "github.com/drand/drand/cmd/relay-gossip/client"
dlog "github.com/drand/drand/log"
"github.com/drand/kyber"
kzap "github.com/go-kit/kit/log/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/xerrors"
logging "github.com/ipfs/go-log"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/beacon"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/specs-actors/actors/abi"
"golang.org/x/xerrors"
logging "github.com/ipfs/go-log"
dbeacon "github.com/drand/drand/beacon"
"github.com/drand/drand/core"
dkey "github.com/drand/drand/key"
dnet "github.com/drand/drand/net"
dproto "github.com/drand/drand/protobuf/drand"
)
var log = logging.Logger("drand")
var drandServers = []string{
"nicolas.drand.fil-test.net:443",
"philipp.drand.fil-test.net:443",
"mathilde.drand.fil-test.net:443",
"ludovic.drand.fil-test.net:443",
"gabbi.drand.fil-test.net:443",
"linus.drand.fil-test.net:443",
"jeff.drand.fil-test.net:443",
"https://pl-eu.testnet.drand.sh",
"https://pl-us.testnet.drand.sh",
"https://pl-sin.testnet.drand.sh",
}
var drandPubKey *dkey.DistPublic
var drandChain *dchain.Info
func init() {
drandPubKey = new(dkey.DistPublic)
err := drandPubKey.FromTOML(&dkey.DistPublicTOML{Coefficients: build.DrandCoeffs})
var err error
drandChain, err = dchain.InfoFromJSON(bytes.NewReader([]byte(build.DrandChain)))
if err != nil {
panic(err)
panic("could not unmarshal chain info: " + err.Error())
}
}
@@ -57,13 +57,9 @@ func (dp *drandPeer) IsTLS() bool {
}
type DrandBeacon struct {
client dnet.Client
client dclient.Client
peers []dnet.Peer
peersIndex int
peersIndexMtx sync.Mutex
pubkey *dkey.DistPublic
pubkey kyber.Point
// seconds
interval time.Duration
@@ -76,120 +72,83 @@ type DrandBeacon struct {
localCache map[uint64]types.BeaconEntry
}
func NewDrandBeacon(genesisTs, interval uint64) (*DrandBeacon, error) {
func NewDrandBeacon(genesisTs, interval uint64, ps *pubsub.PubSub) (*DrandBeacon, error) {
if genesisTs == 0 {
panic("what are you doing this cant be zero")
}
dlogger := dlog.NewKitLoggerFrom(kzap.NewZapSugarLogger(
log.SugaredLogger.Desugar(), zapcore.InfoLevel))
opts := []dclient.Option{
dclient.WithChainInfo(drandChain),
dclient.WithHTTPEndpoints(drandServers),
dclient.WithCacheSize(1024),
dclient.WithLogger(dlogger),
}
if ps != nil {
opts = append(opts, gclient.WithPubsub(ps))
} else {
log.Info("drand beacon without pubsub")
}
client, err := dclient.New(opts...)
if err != nil {
return nil, xerrors.Errorf("creating drand client")
}
go func() {
// Explicitly Watch until that is fixed in drand
ch := client.Watch(context.Background())
for range ch {
}
log.Error("dranch Watch bork")
}()
db := &DrandBeacon{
client: dnet.NewGrpcClient(),
client: client,
localCache: make(map[uint64]types.BeaconEntry),
}
for _, ds := range drandServers {
db.peers = append(db.peers, &drandPeer{addr: ds, tls: true})
}
db.peersIndex = rand.Intn(len(db.peers))
groupResp, err := db.client.Group(context.TODO(), db.peers[db.peersIndex], &dproto.GroupRequest{})
if err != nil {
return nil, xerrors.Errorf("failed to get group response from beacon peer: %w", err)
}
kgroup, err := core.ProtoToGroup(groupResp)
if err != nil {
return nil, xerrors.Errorf("failed to parse group response: %w", err)
}
// TODO: verify these values are what we expect them to be
if !kgroup.PublicKey.Equal(drandPubKey) {
return nil, xerrors.Errorf("public key does not match")
}
// fmt.Printf("Drand Pubkey:\n%#v\n", kgroup.PublicKey.TOML()) // use to print public key
db.pubkey = drandPubKey
db.interval = kgroup.Period
db.drandGenTime = uint64(kgroup.GenesisTime)
db.pubkey = drandChain.PublicKey
db.interval = drandChain.Period
db.drandGenTime = uint64(drandChain.GenesisTime)
db.filRoundTime = interval
db.filGenTime = genesisTs
// TODO: the stream currently gives you back *all* values since drand genesis.
// Having the stream in the background is merely an optimization, so not a big deal to disable it for now
// go db.handleStreamingUpdates()
return db, nil
}
func (db *DrandBeacon) rotatePeersIndex() {
db.peersIndexMtx.Lock()
nval := rand.Intn(len(db.peers))
db.peersIndex = nval
db.peersIndexMtx.Unlock()
log.Warnf("rotated to drand peer %d, %q", nval, db.peers[nval].Address())
}
func (db *DrandBeacon) getPeerIndex() int {
db.peersIndexMtx.Lock()
defer db.peersIndexMtx.Unlock()
return db.peersIndex
}
func (db *DrandBeacon) handleStreamingUpdates() {
for {
p := db.peers[db.getPeerIndex()]
ch, err := db.client.PublicRandStream(context.Background(), p, &dproto.PublicRandRequest{})
if err != nil {
log.Warnf("failed to get public rand stream to peer %q: %s", p.Address(), err)
log.Warnf("trying again in 10 seconds")
db.rotatePeersIndex()
time.Sleep(time.Second * 10)
continue
}
for e := range ch {
db.cacheValue(types.BeaconEntry{
Round: e.Round,
Data: e.Signature,
})
}
log.Warnf("drand beacon stream to peer %q broke, reconnecting in 10 seconds", p.Address())
db.rotatePeersIndex()
time.Sleep(time.Second * 10)
}
}
func (db *DrandBeacon) Entry(ctx context.Context, round uint64) <-chan beacon.Response {
// check cache, it it if there, otherwise query the endpoint
cres := db.getCachedValue(round)
if cres != nil {
out := make(chan beacon.Response, 1)
out <- beacon.Response{Entry: *cres}
close(out)
return out
}
out := make(chan beacon.Response, 1)
if round != 0 {
be := db.getCachedValue(round)
if be != nil {
out <- beacon.Response{Entry: *be}
close(out)
return out
}
}
go func() {
p := db.peers[db.getPeerIndex()]
resp, err := db.client.PublicRand(ctx, p, &dproto.PublicRandRequest{Round: round})
start := time.Now()
log.Infow("start fetching randomness", "round", round)
resp, err := db.client.Get(ctx, round)
var br beacon.Response
if err != nil {
db.rotatePeersIndex()
br.Err = xerrors.Errorf("drand peer %q failed publicRand request: %w", p.Address(), err)
br.Err = xerrors.Errorf("drand failed Get request: %w", err)
} else {
br.Entry.Round = resp.GetRound()
br.Entry.Data = resp.GetSignature()
br.Entry.Round = resp.Round()
br.Entry.Data = resp.Signature()
}
log.Infow("done fetching randomness", "round", round, "took", time.Since(start))
out <- br
close(out)
}()
return out
}
func (db *DrandBeacon) cacheValue(e types.BeaconEntry) {
db.cacheLk.Lock()
defer db.cacheLk.Unlock()
@@ -211,13 +170,12 @@ func (db *DrandBeacon) VerifyEntry(curr types.BeaconEntry, prev types.BeaconEntr
// TODO handle genesis better
return nil
}
b := &dbeacon.Beacon{
b := &dchain.Beacon{
PreviousSig: prev.Data,
Round: curr.Round,
Signature: curr.Data,
}
//log.Warnw("VerifyEntry", "beacon", b)
err := dbeacon.VerifyBeacon(db.pubkey.Key(), b)
err := dchain.VerifyBeacon(db.pubkey, b)
if err == nil {
db.cacheValue(curr)
}
+15 -7
View File
@@ -1,14 +1,22 @@
package drand
import (
"fmt"
"os"
"testing"
dchain "github.com/drand/drand/chain"
dclient "github.com/drand/drand/client"
"github.com/stretchr/testify/assert"
)
func TestPrintDrandPubkey(t *testing.T) {
bc, err := NewDrandBeacon(1, 1)
if err != nil {
t.Fatal(err)
}
fmt.Printf("Drand Pubkey:\n%#v\n", bc.pubkey.TOML())
func TestPrintGroupInfo(t *testing.T) {
c, err := dclient.NewHTTPClient(drandServers[0], nil, nil)
assert.NoError(t, err)
cg := c.(interface {
FetchChainInfo(groupHash []byte) (*dchain.Info, error)
})
chain, err := cg.FetchChainInfo(nil)
assert.NoError(t, err)
err = chain.ToJSON(os.Stdout)
assert.NoError(t, err)
}
+2 -2
View File
@@ -91,7 +91,7 @@ func (bss *BlockSyncService) HandleStream(s inet.Stream) {
ctx, span := trace.StartSpan(context.Background(), "blocksync.HandleStream")
defer span.End()
defer s.Close()
defer s.Close() //nolint:errcheck
var req BlockSyncRequest
if err := cborutil.ReadCborRPC(bufio.NewReader(s), &req); err != nil {
@@ -107,7 +107,7 @@ func (bss *BlockSyncService) HandleStream(s inet.Stream) {
}
writeDeadline := 60 * time.Second
s.SetDeadline(time.Now().Add(writeDeadline))
_ = s.SetDeadline(time.Now().Add(writeDeadline))
if err := cborutil.WriteCborRPC(s, resp); err != nil {
log.Warnw("failed to write back response for handle stream", "err", err, "peer", s.Conn().RemotePeer())
return
+3 -3
View File
@@ -283,14 +283,14 @@ func (bs *BlockSync) fetchBlocksBlockSync(ctx context.Context, p peer.ID, req *B
bs.RemovePeer(p)
return nil, xerrors.Errorf("failed to open stream to peer: %w", err)
}
s.SetWriteDeadline(time.Now().Add(5 * time.Second))
_ = s.SetWriteDeadline(time.Now().Add(5 * time.Second))
if err := cborutil.WriteCborRPC(s, req); err != nil {
s.SetWriteDeadline(time.Time{})
_ = s.SetWriteDeadline(time.Time{})
bs.syncPeers.logFailure(p, time.Since(start))
return nil, err
}
s.SetWriteDeadline(time.Time{})
_ = s.SetWriteDeadline(time.Time{})
var res BlockSyncResponse
r := incrt.New(s, 50<<10, 5*time.Second)
+2 -2
View File
@@ -67,7 +67,7 @@ func NewEvents(ctx context.Context, api eventApi) *Events {
heightEvents: heightEvents{
tsc: tsc,
ctx: ctx,
gcConfidence: abi.ChainEpoch(gcConfidence),
gcConfidence: gcConfidence,
heightTriggers: map[uint64]*heightHandler{},
htTriggerHeights: map[abi.ChainEpoch][]uint64{},
@@ -166,7 +166,7 @@ func (e *Events) listenHeadChangesOnce(ctx context.Context) error {
}
// sync with fake chainstore (for tests)
if fcs, ok := e.api.(interface{notifDone()}); ok {
if fcs, ok := e.api.(interface{ notifDone() }); ok {
fcs.notifDone()
}
}
+1 -1
View File
@@ -671,7 +671,7 @@ func TestCalled(t *testing.T) {
0: n2msg,
})
require.Equal(t, true, applied) // msg from H=7, which had reverted execution
require.Equal(t, true, applied) // msg from H=7, which had reverted execution
require.Equal(t, false, reverted)
require.Equal(t, abi.ChainEpoch(10), appliedH)
applied = false
+5 -1
View File
@@ -104,7 +104,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
return nil, xerrors.Errorf("failed to get metadata datastore: %w", err)
}
bds, err := lr.Datastore("/blocks")
bds, err := lr.Datastore("/chain")
if err != nil {
return nil, xerrors.Errorf("failed to get blocks datastore: %w", err)
}
@@ -219,6 +219,10 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
miners := []address.Address{maddr1, maddr2}
beac := beacon.NewMockBeacon(time.Second)
//beac, err := drand.NewDrandBeacon(tpl.Timestamp, build.BlockDelay)
//if err != nil {
//return nil, xerrors.Errorf("creating drand beacon: %w", err)
//}
gen := &ChainGen{
bs: bs,
+3
View File
@@ -58,6 +58,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
for i, m := range miners {
// Create miner through power actor
i := i
m := m
spt, err := ffiwrapper.SealProofTypeFromSectorSize(m.SectorSize)
if err != nil {
@@ -154,6 +156,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid
// Commit sectors
for pi, preseal := range m.Sectors {
preseal := preseal
// TODO: Maybe check seal (Can just be snark inputs, doesn't go into the genesis file)
// check deals, get dealWeight
+49 -7
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"errors"
"fmt"
"math"
"sort"
"sync"
@@ -87,6 +88,8 @@ type MessagePool struct {
localMsgs datastore.Datastore
netName dtypes.NetworkName
sigValCache *lru.TwoQueueCache
}
type msgSet struct {
@@ -180,6 +183,8 @@ func (mpp *mpoolProvider) LoadTipSet(tsk types.TipSetKey) (*types.TipSet, error)
func New(api Provider, ds dtypes.MetadataDS, netName dtypes.NetworkName) (*MessagePool, error) {
cache, _ := lru.New2Q(build.BlsSignatureCacheSize)
verifcache, _ := lru.New2Q(build.VerifSigCacheSize)
mp := &MessagePool{
closer: make(chan struct{}),
repubTk: time.NewTicker(build.BlockDelay * 10 * time.Second),
@@ -188,6 +193,7 @@ func New(api Provider, ds dtypes.MetadataDS, netName dtypes.NetworkName) (*Messa
minGasPrice: types.NewInt(0),
maxTxPoolSize: 5000,
blsSigCache: cache,
sigValCache: verifcache,
changes: lps.New(50),
localMsgs: namespace.Wrap(ds, datastore.NewKey(localMsgsDs)),
api: api,
@@ -313,12 +319,6 @@ func (mp *MessagePool) Push(m *types.SignedMessage) (cid.Cid, error) {
}
func (mp *MessagePool) Add(m *types.SignedMessage) error {
mp.curTsLk.Lock()
defer mp.curTsLk.Unlock()
return mp.addTs(m, mp.curTs)
}
func (mp *MessagePool) addTs(m *types.SignedMessage, curTs *types.TipSet) error {
// big messages are bad, anti DOS
if m.Size() > 32*1024 {
return xerrors.Errorf("mpool message too large (%dB): %w", m.Size(), ErrMessageTooBig)
@@ -332,11 +332,53 @@ func (mp *MessagePool) addTs(m *types.SignedMessage, curTs *types.TipSet) error
return ErrMessageValueTooHigh
}
if err := sigs.Verify(&m.Signature, m.Message.From, m.Message.Cid().Bytes()); err != nil {
if err := mp.VerifyMsgSig(m); err != nil {
log.Warnf("mpooladd signature verification failed: %s", err)
return err
}
mp.curTsLk.Lock()
defer mp.curTsLk.Unlock()
return mp.addTs(m, mp.curTs)
}
func sigCacheKey(m *types.SignedMessage) (string, error) {
switch m.Signature.Type {
case crypto.SigTypeBLS:
if len(m.Signature.Data) < 90 {
return "", fmt.Errorf("bls signature too short")
}
return string(m.Cid().Bytes()) + string(m.Signature.Data[64:]), nil
case crypto.SigTypeSecp256k1:
return string(m.Cid().Bytes()), nil
default:
return "", xerrors.Errorf("unrecognized signature type: %d", m.Signature.Type)
}
}
func (mp *MessagePool) VerifyMsgSig(m *types.SignedMessage) error {
sck, err := sigCacheKey(m)
if err != nil {
return err
}
_, ok := mp.sigValCache.Get(sck)
if ok {
// already validated, great
return nil
}
if err := sigs.Verify(&m.Signature, m.Message.From, m.Message.Cid().Bytes()); err != nil {
return err
}
mp.sigValCache.Add(sck, struct{}{})
return nil
}
func (mp *MessagePool) addTs(m *types.SignedMessage, curTs *types.TipSet) error {
snonce, err := mp.getStateNonce(m.Message.From, curTs)
if err != nil {
return xerrors.Errorf("failed to look up actor state nonce: %s: %w", err, ErrBroadcastAnyway)
+4 -1
View File
@@ -255,12 +255,15 @@ func TestStateTreeConsistency(t *testing.T) {
}
for i, a := range addrs {
st.SetActor(a, &types.Actor{
err := st.SetActor(a, &types.Actor{
Code: randomCid,
Head: randomCid,
Balance: types.NewInt(uint64(10000 + i)),
Nonce: uint64(1000 - i),
})
if err != nil {
t.Fatalf("while setting actor: %+v", err)
}
}
root, err := st.Flush(context.TODO())
+2 -2
View File
@@ -382,8 +382,8 @@ func (sm *StateManager) LoadActorState(ctx context.Context, a address.Address, o
cst := cbor.NewCborStore(sm.cs.Blockstore())
if err := cst.Get(ctx, act.Head, out); err != nil {
var r cbg.Deferred
cst.Get(ctx, act.Head, &r)
fmt.Printf("badhead %x\n", r.Raw)
_ = cst.Get(ctx, act.Head, &r)
log.Errorw("bad actor head", "error", err, "raw", r.Raw, "address", a)
return nil, err
}
+28 -10
View File
@@ -138,6 +138,24 @@ func PreCommitInfo(ctx context.Context, sm *StateManager, maddr address.Address,
return *i, nil
}
func MinerSectorInfo(ctx context.Context, sm *StateManager, maddr address.Address, sid abi.SectorNumber, ts *types.TipSet) (*miner.SectorOnChainInfo, error) {
var mas miner.State
_, err := sm.LoadActorState(ctx, maddr, &mas, ts)
if err != nil {
return nil, xerrors.Errorf("(get sset) failed to load miner actor state: %w", err)
}
sectorInfo, ok, err := mas.GetSector(sm.cs.Store(ctx), sid)
if err != nil {
return nil, err
}
if !ok {
return nil, xerrors.New("sector not found")
}
return sectorInfo, nil
}
func GetMinerSectorSet(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address, filter *abi.BitField, filterOut bool) ([]*api.ChainSectorInfo, error) {
var mas miner.State
_, err := sm.LoadActorState(ctx, maddr, &mas, ts)
@@ -248,24 +266,24 @@ func GetMinerDeadlines(ctx context.Context, sm *StateManager, ts *types.TipSet,
return mas.LoadDeadlines(sm.cs.Store(ctx))
}
func GetMinerFaults(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]abi.SectorNumber, error) {
func GetMinerFaults(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (*abi.BitField, error) {
var mas miner.State
_, err := sm.LoadActorState(ctx, maddr, &mas, ts)
if err != nil {
return nil, xerrors.Errorf("(get ssize) failed to load miner actor state: %w", err)
return nil, xerrors.Errorf("(get faults) failed to load miner actor state: %w", err)
}
faults, err := mas.Faults.All(miner.SectorsMax)
return mas.Faults, nil
}
func GetMinerRecoveries(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (*abi.BitField, error) {
var mas miner.State
_, err := sm.LoadActorState(ctx, maddr, &mas, ts)
if err != nil {
return nil, xerrors.Errorf("reading fault bit set: %w", err)
return nil, xerrors.Errorf("(get recoveries) failed to load miner actor state: %w", err)
}
out := make([]abi.SectorNumber, len(faults))
for i, fault := range faults {
out[i] = abi.SectorNumber(fault)
}
return out, nil
return mas.Recoveries, nil
}
func GetStorageDeal(ctx context.Context, sm *StateManager, dealId abi.DealID, ts *types.TipSet) (*api.MarketDeal, error) {
+8 -2
View File
@@ -895,11 +895,17 @@ func DrawRandomness(rbase []byte, pers crypto.DomainSeparationTag, round abi.Cha
return nil, xerrors.Errorf("deriving randomness: %w", err)
}
VRFDigest := blake2b.Sum256(rbase)
h.Write(VRFDigest[:])
_, err := h.Write(VRFDigest[:])
if err != nil {
return nil, xerrors.Errorf("hashing VRFDigest: %w", err)
}
if err := binary.Write(h, binary.BigEndian, round); err != nil {
return nil, xerrors.Errorf("deriving randomness: %w", err)
}
h.Write(entropy)
_, err = h.Write(entropy)
if err != nil {
return nil, xerrors.Errorf("hashing entropy: %w", err)
}
return h.Sum(nil), nil
}
+1 -1
View File
@@ -55,7 +55,7 @@ func BenchmarkGetRandomness(b *testing.B) {
b.Fatal(err)
}
bds, err := lr.Datastore("/blocks")
bds, err := lr.Datastore("/chain")
if err != nil {
b.Fatal(err)
}
+196 -15
View File
@@ -1,30 +1,45 @@
package sub
import (
"bytes"
"context"
"fmt"
"sync"
"time"
"golang.org/x/xerrors"
address "github.com/filecoin-project/go-address"
amt "github.com/filecoin-project/go-amt-ipld/v2"
miner "github.com/filecoin-project/specs-actors/actors/builtin/miner"
lru "github.com/hashicorp/golang-lru"
"github.com/ipfs/go-cid"
dstore "github.com/ipfs/go-datastore"
bstore "github.com/ipfs/go-ipfs-blockstore"
cbor "github.com/ipfs/go-ipld-cbor"
logging "github.com/ipfs/go-log/v2"
connmgr "github.com/libp2p/go-libp2p-core/connmgr"
"github.com/libp2p/go-libp2p-core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub"
cbg "github.com/whyrusleeping/cbor-gen"
"go.opencensus.io/stats"
"go.opencensus.io/tag"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain"
"github.com/filecoin-project/lotus/chain/messagepool"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/bufbstore"
"github.com/filecoin-project/lotus/lib/sigs"
"github.com/filecoin-project/lotus/metrics"
)
var log = logging.Logger("sub")
func HandleIncomingBlocks(ctx context.Context, bsub *pubsub.Subscription, s *chain.Syncer, cmgr connmgr.ConnManager, bv *BlockValidator) {
func HandleIncomingBlocks(ctx context.Context, bsub *pubsub.Subscription, s *chain.Syncer, cmgr connmgr.ConnManager) {
for {
msg, err := bsub.Next(ctx)
if err != nil {
@@ -52,15 +67,13 @@ func HandleIncomingBlocks(ctx context.Context, bsub *pubsub.Subscription, s *cha
log.Debug("about to fetch messages for block from pubsub")
bmsgs, err := s.Bsync.FetchMessagesByCids(context.TODO(), blk.BlsMessages)
if err != nil {
log.Errorf("failed to fetch all bls messages for block received over pubusb: %s; flagging source %s", err, src)
bv.flagPeer(src)
log.Errorf("failed to fetch all bls messages for block received over pubusb: %s; source: %s", err, src)
return
}
smsgs, err := s.Bsync.FetchSignedMessagesByCids(context.TODO(), blk.SecpkMessages)
if err != nil {
log.Errorf("failed to fetch all secpk messages for block received over pubusb: %s; flagging source %s", err, src)
bv.flagPeer(src)
log.Errorf("failed to fetch all secpk messages for block received over pubusb: %s; source: %s", err, src)
return
}
@@ -89,15 +102,25 @@ type BlockValidator struct {
recvBlocks *blockReceiptCache
blacklist func(peer.ID)
// necessary for block validation
chain *store.ChainStore
stmgr *stmgr.StateManager
mx sync.Mutex
keycache map[string]address.Address
}
func NewBlockValidator(blacklist func(peer.ID)) *BlockValidator {
func NewBlockValidator(chain *store.ChainStore, stmgr *stmgr.StateManager, blacklist func(peer.ID)) *BlockValidator {
p, _ := lru.New2Q(4096)
return &BlockValidator{
peers: p,
killThresh: 10,
blacklist: blacklist,
recvBlocks: newBlockReceiptCache(),
chain: chain,
stmgr: stmgr,
keycache: make(map[string]address.Address),
}
}
@@ -120,35 +143,191 @@ func (bv *BlockValidator) flagPeer(p peer.ID) {
}
func (bv *BlockValidator) Validate(ctx context.Context, pid peer.ID, msg *pubsub.Message) pubsub.ValidationResult {
// track validation time
begin := time.Now()
defer func() {
end := time.Now()
log.Infof("block validation time: %s", end.Sub(begin))
}()
stats.Record(ctx, metrics.BlockReceived.M(1))
recordFailure := func(what string) {
ctx, _ = tag.New(ctx, tag.Insert(metrics.FailureType, what))
stats.Record(ctx, metrics.BlockValidationFailure.M(1))
bv.flagPeer(pid)
}
// make sure the block can be decoded
blk, err := types.DecodeBlockMsg(msg.GetData())
if err != nil {
log.Error("got invalid block over pubsub: ", err)
ctx, _ = tag.New(ctx, tag.Insert(metrics.FailureType, "invalid"))
stats.Record(ctx, metrics.BlockValidationFailure.M(1))
bv.flagPeer(pid)
recordFailure("invalid")
return pubsub.ValidationReject
}
// check the message limit constraints
if len(blk.BlsMessages)+len(blk.SecpkMessages) > build.BlockMessageLimit {
log.Warnf("received block with too many messages over pubsub")
ctx, _ = tag.New(ctx, tag.Insert(metrics.FailureType, "too_many_messages"))
stats.Record(ctx, metrics.BlockValidationFailure.M(1))
bv.flagPeer(pid)
recordFailure("too_many_messages")
return pubsub.ValidationReject
}
// make sure we have a signature
if blk.Header.BlockSig == nil {
log.Warnf("received block without a signature over pubsub")
recordFailure("missing_signature")
return pubsub.ValidationReject
}
// validate the block meta: the Message CID in the header must match the included messages
err = bv.validateMsgMeta(ctx, blk)
if err != nil {
log.Warnf("error validating message metadata: %s", err)
recordFailure("invalid_block_meta")
return pubsub.ValidationReject
}
// we want to ensure that it is a block from a known miner; we reject blocks from unknown miners
// to prevent spam attacks.
// the logic works as follows: we lookup the miner in the chain for its key.
// if we can find it then it's a known miner and we can validate the signature.
// if we can't find it, we check whether we are (near) synced in the chain.
// if we are not synced we cannot validate the block and we must ignore it.
// if we are synced and the miner is unknown, then the block is rejcected.
key, err := bv.getMinerWorkerKey(ctx, blk)
if err != nil {
if bv.isChainNearSynced() {
log.Warnf("received block message from unknown miner over pubsub; rejecting message")
recordFailure("unknown_miner")
return pubsub.ValidationReject
} else {
log.Warnf("cannot validate block message; unknown miner in unsynced chain")
return pubsub.ValidationIgnore
}
}
err = sigs.CheckBlockSignature(blk.Header, ctx, key)
if err != nil {
log.Errorf("block signature verification failed: %s", err)
recordFailure("signature_verification_failed")
return pubsub.ValidationReject
}
// it's a good block! make sure we've only seen it once
if bv.recvBlocks.add(blk.Header.Cid()) > 0 {
// TODO: once these changes propagate to the network, we can consider
// dropping peers who send us the same block multiple times
return pubsub.ValidationIgnore
}
// all good, accept the block
msg.ValidatorData = blk
stats.Record(ctx, metrics.BlockValidationSuccess.M(1))
return pubsub.ValidationAccept
}
func (bv *BlockValidator) isChainNearSynced() bool {
ts := bv.chain.GetHeaviestTipSet()
timestamp := ts.MinTimestamp()
now := time.Now().UnixNano()
cutoff := uint64(now) - uint64(6*time.Hour)
return timestamp > cutoff
}
func (bv *BlockValidator) validateMsgMeta(ctx context.Context, msg *types.BlockMsg) error {
var bcids, scids []cbg.CBORMarshaler
for _, m := range msg.BlsMessages {
c := cbg.CborCid(m)
bcids = append(bcids, &c)
}
for _, m := range msg.SecpkMessages {
c := cbg.CborCid(m)
scids = append(scids, &c)
}
// TODO there has to be a simpler way to do this without the blockstore dance
bs := cbor.NewCborStore(bstore.NewBlockstore(dstore.NewMapDatastore()))
bmroot, err := amt.FromArray(ctx, bs, bcids)
if err != nil {
return err
}
smroot, err := amt.FromArray(ctx, bs, scids)
if err != nil {
return err
}
mrcid, err := bs.Put(ctx, &types.MsgMeta{
BlsMessages: bmroot,
SecpkMessages: smroot,
})
if err != nil {
return err
}
if msg.Header.Messages != mrcid {
return fmt.Errorf("messages didn't match root cid in header")
}
return nil
}
func (bv *BlockValidator) getMinerWorkerKey(ctx context.Context, msg *types.BlockMsg) (address.Address, error) {
addr := msg.Header.Miner
bv.mx.Lock()
key, ok := bv.keycache[addr.String()]
bv.mx.Unlock()
if ok {
return key, nil
}
// TODO I have a feeling all this can be simplified by cleverer DI to use the API
ts := bv.chain.GetHeaviestTipSet()
st, _, err := bv.stmgr.TipSetState(ctx, ts)
if err != nil {
return address.Undef, err
}
buf := bufbstore.NewBufferedBstore(bv.chain.Blockstore())
cst := cbor.NewCborStore(buf)
state, err := state.LoadStateTree(cst, st)
if err != nil {
return address.Undef, err
}
act, err := state.GetActor(addr)
if err != nil {
return address.Undef, err
}
blk, err := bv.chain.Blockstore().Get(act.Head)
if err != nil {
return address.Undef, err
}
aso := blk.RawData()
var mst miner.State
err = mst.UnmarshalCBOR(bytes.NewReader(aso))
if err != nil {
return address.Undef, err
}
worker := mst.Info.Worker
key, err = bv.stmgr.ResolveToKeyAddress(ctx, worker, ts)
if err != nil {
return address.Undef, err
}
bv.mx.Lock()
bv.keycache[addr.String()] = key
bv.mx.Unlock()
return key, nil
}
type blockReceiptCache struct {
blocks *lru.TwoQueueCache
}
@@ -197,10 +376,12 @@ func (mv *MessageValidator) Validate(ctx context.Context, pid peer.ID, msg *pubs
tag.Insert(metrics.FailureType, "add"),
)
stats.Record(ctx, metrics.MessageValidationFailure.M(1))
if xerrors.Is(err, messagepool.ErrBroadcastAnyway) {
return pubsub.ValidationAccept
switch {
case xerrors.Is(err, messagepool.ErrBroadcastAnyway):
return pubsub.ValidationIgnore
default:
return pubsub.ValidationReject
}
return pubsub.ValidationIgnore
}
stats.Record(ctx, metrics.MessageValidationSuccess.M(1))
return pubsub.ValidationAccept
+2 -2
View File
@@ -417,7 +417,7 @@ func TestSyncBadTimestamp(t *testing.T) {
a1 := tu.mineOnBlock(base, 0, nil, false, true)
tu.g.Timestamper = nil
tu.g.ResyncBankerNonce(a1.TipSet())
require.NoError(t, tu.g.ResyncBankerNonce(a1.TipSet()))
fmt.Println("After mine bad block!")
tu.printHeads()
@@ -479,7 +479,7 @@ func TestSyncFork(t *testing.T) {
a := tu.mineOnBlock(a1, p1, []int{0}, true, false)
a = tu.mineOnBlock(a, p1, []int{0}, true, false)
tu.g.ResyncBankerNonce(a1.TipSet())
require.NoError(t, tu.g.ResyncBankerNonce(a1.TipSet()))
// chain B will now be heaviest
b := tu.mineOnBlock(base, p2, []int{1}, true, false)
b = tu.mineOnBlock(b, p2, []int{1}, true, false)
+11
View File
@@ -69,6 +69,9 @@ type BlockHeader struct {
BlockSig *crypto.Signature // 13
ForkSignaling uint64 // 14
// internal
validated bool // true if the signature has been validated
}
func (b *BlockHeader) ToStorageBlock() (block.Block, error) {
@@ -124,6 +127,14 @@ func (blk *BlockHeader) SigningBytes() ([]byte, error) {
return blkcopy.Serialize()
}
func (blk *BlockHeader) SetValidated() {
blk.validated = true
}
func (blk *BlockHeader) IsValidated() bool {
return blk.validated
}
type MsgMeta struct {
BlsMessages cid.Cid
SecpkMessages cid.Cid
+61 -2
View File
@@ -2,13 +2,16 @@ package types
import (
"bytes"
"encoding/hex"
"fmt"
"reflect"
"testing"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/crypto"
cid "github.com/ipfs/go-cid"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
)
func testBlockHeader(t testing.TB) *BlockHeader {
@@ -63,6 +66,62 @@ func TestBlockHeaderSerialization(t *testing.T) {
}
}
func TestInteropBH(t *testing.T) {
newAddr, err := address.NewSecp256k1Address([]byte("address0"))
if err != nil {
t.Fatal(err)
}
mcid, err := cid.Parse("bafy2bzaceaxyj7xq27gc2747adjcirpxx52tt7owqx6z6kckun7tqivvoym4y")
if err != nil {
t.Fatal(err)
}
posts := []abi.PoStProof{
{abi.RegisteredProof_StackedDRG2KiBWinningPoSt, []byte{0x07}},
}
bh := &BlockHeader{
Miner: newAddr,
Ticket: &Ticket{[]byte{0x01, 0x02, 0x03}},
ElectionProof: &ElectionProof{[]byte{0x0a, 0x0b}},
BeaconEntries: []BeaconEntry{
{
Round: 5,
Data: []byte{0x0c},
//prevRound: 0,
},
},
Height: 2,
Messages: mcid,
ParentMessageReceipts: mcid,
Parents: []cid.Cid{mcid},
ParentWeight: NewInt(1000),
ForkSignaling: 3,
ParentStateRoot: mcid,
Timestamp: 1,
WinPoStProof: posts,
BlockSig: &crypto.Signature{
Type: crypto.SigTypeBLS,
Data: []byte{0x3},
},
BLSAggregate: &crypto.Signature{},
}
bhsb, err := bh.SigningBytes()
if err != nil {
t.Fatal(err)
}
// acquired from go-filecoin
gfc := "8f5501d04cb15021bf6bd003073d79e2238d4e61f1ad22814301020381420a0b818205410c818209410781d82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619cc430003e802d82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619ccd82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619ccd82a5827000171a0e402202f84fef0d7cc2d7f9f00d22445f7bf7539fdd685fd9f284aa37f3822b57619cc410001f603"
if gfc != hex.EncodeToString(bhsb) {
t.Fatal("not equal!")
}
}
func BenchmarkBlockHeaderMarshal(b *testing.B) {
bh := testBlockHeader(b)
+6 -5
View File
@@ -9,10 +9,10 @@ import (
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/crypto"
"github.com/filecoin-project/specs-actors/actors/puppet"
"github.com/filecoin-project/specs-actors/actors/runtime"
"github.com/ipfs/go-cid"
vtypes "github.com/filecoin-project/chain-validation/chain/types"
vdrivers "github.com/filecoin-project/chain-validation/drivers"
vstate "github.com/filecoin-project/chain-validation/state"
"github.com/filecoin-project/lotus/chain/stmgr"
@@ -24,12 +24,13 @@ import (
// Applier applies messages to state trees and storage.
type Applier struct {
stateWrapper *StateWrapper
syscalls runtime.Syscalls
}
var _ vstate.Applier = &Applier{}
func NewApplier(sw *StateWrapper) *Applier {
return &Applier{sw}
func NewApplier(sw *StateWrapper, syscalls runtime.Syscalls) *Applier {
return &Applier{sw, syscalls}
}
func (a *Applier) ApplyMessage(epoch abi.ChainEpoch, message *vtypes.Message) (vtypes.ApplyMessageResult, error) {
@@ -65,7 +66,7 @@ func (a *Applier) ApplySignedMessage(epoch abi.ChainEpoch, msg *vtypes.SignedMes
}
func (a *Applier) ApplyTipSetMessages(epoch abi.ChainEpoch, blocks []vtypes.BlockMessagesInfo, rnd vstate.RandomnessSource) (vtypes.ApplyTipSetResult, error) {
cs := store.NewChainStore(a.stateWrapper.bs, a.stateWrapper.ds, vdrivers.NewChainValidationSyscalls())
cs := store.NewChainStore(a.stateWrapper.bs, a.stateWrapper.ds, a.syscalls)
sm := stmgr.NewStateManager(cs)
var bms []stmgr.BlockMessages
@@ -134,7 +135,7 @@ func (a *Applier) applyMessage(epoch abi.ChainEpoch, lm types.ChainMsg) (vtypes.
ctx := context.TODO()
base := a.stateWrapper.Root()
lotusVM, err := vm.NewVM(base, epoch, &vmRand{}, a.stateWrapper.bs, vdrivers.NewChainValidationSyscalls())
lotusVM, err := vm.NewVM(base, epoch, &vmRand{}, a.stateWrapper.bs, a.syscalls)
// need to modify the VM invoker to add the puppet actor
chainValInvoker := vm.NewInvoker()
chainValInvoker.Register(puppet.PuppetActorCodeID, puppet.Actor{}, puppet.State{})
+3 -16
View File
@@ -1,11 +1,9 @@
package validation
import (
"context"
"github.com/filecoin-project/specs-actors/actors/runtime"
vstate "github.com/filecoin-project/chain-validation/state"
"github.com/filecoin-project/specs-actors/actors/abi"
acrypto "github.com/filecoin-project/specs-actors/actors/crypto"
)
type Factories struct {
@@ -18,26 +16,15 @@ func NewFactories() *Factories {
return &Factories{}
}
func (f *Factories) NewStateAndApplier() (vstate.VMWrapper, vstate.Applier) {
func (f *Factories) NewStateAndApplier(syscalls runtime.Syscalls) (vstate.VMWrapper, vstate.Applier) {
st := NewState()
return st, NewApplier(st)
return st, NewApplier(st, syscalls)
}
func (f *Factories) NewKeyManager() vstate.KeyManager {
return newKeyManager()
}
type fakeRandSrc struct {
}
func (r fakeRandSrc) Randomness(_ context.Context, _ acrypto.DomainSeparationTag, _ abi.ChainEpoch, _ []byte) (abi.Randomness, error) {
return abi.Randomness("sausages"), nil
}
func (f *Factories) NewRandomnessSource() vstate.RandomnessSource {
return &fakeRandSrc{}
}
func (f *Factories) NewValidationConfig() vstate.ValidationConfig {
trackGas := true
checkExit := true
+7 -2
View File
@@ -7,6 +7,7 @@ import (
"os"
"github.com/filecoin-project/go-address"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/gen"
"github.com/filecoin-project/lotus/chain/types"
@@ -173,14 +174,18 @@ func WriteJsonToFile(fname string, obj interface{}) error {
if err != nil {
return err
}
defer fi.Close()
defer fi.Close() //nolint:errcheck
out, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return err
}
fi.Write(out)
_, err = fi.Write(out)
if err != nil {
return xerrors.Errorf("writing json: %w", err)
}
return nil
}
+40 -1
View File
@@ -1,11 +1,15 @@
package vectors
import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/filecoin-project/lotus/chain/types"
)
func LoadVector(t *testing.T, f string, out interface{}) {
@@ -42,5 +46,40 @@ func TestBlockHeaderVectors(t *testing.T) {
}
func TestMessageSigningVectors(t *testing.T) {
// TODO:
var msvs []MessageSigningVector
LoadVector(t, "message_signing.json", &msvs)
for i, msv := range msvs {
smsg := &types.SignedMessage{
Message: *msv.Unsigned,
Signature: *msv.Signature,
}
if smsg.Cid().String() != msv.Cid {
t.Fatalf("cid of message in vector %d mismatches", i)
}
// TODO: check signature
}
}
func TestUnsignedMessageVectors(t *testing.T) {
var msvs []UnsignedMessageVector
LoadVector(t, "unsigned_messages.json", &msvs)
for i, msv := range msvs {
b, err := msv.Message.Serialize()
if err != nil {
t.Fatal(err)
}
dec, err := hex.DecodeString(msv.HexCbor)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(b, dec) {
t.Fatalf("serialization vector %d mismatches bytes", i)
}
}
}
+6
View File
@@ -3,6 +3,7 @@ package vm
import (
"fmt"
"github.com/filecoin-project/go-address"
addr "github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/crypto"
@@ -143,3 +144,8 @@ func (ps pricedSyscalls) VerifyConsensusFault(h1 []byte, h2 []byte, extra []byte
ps.chargeGas(ps.pl.OnVerifyConsensusFault())
return ps.under.VerifyConsensusFault(h1, h2, extra)
}
func (ps pricedSyscalls) BatchVerifySeals(inp map[address.Address][]abi.SealVerifyInfo) (map[address.Address][]bool, error) {
ps.chargeGas(0) // TODO: this is only called by the cron actor. Should we even charge gas?
return ps.under.BatchVerifySeals(inp)
}
+10 -5
View File
@@ -5,6 +5,7 @@ import (
"context"
"encoding/binary"
"fmt"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/abi/big"
@@ -182,7 +183,7 @@ func (rs *Runtime) ValidateImmediateCallerAcceptAny() {
func (rs *Runtime) CurrentBalance() abi.TokenAmount {
b, err := rs.GetBalance(rs.Message().Receiver())
if err != nil {
rs.Abortf(exitcode.ExitCode(err.RetCode()), "get current balance: %v", err)
rs.Abortf(err.RetCode(), "get current balance: %v", err)
}
return b
}
@@ -271,7 +272,9 @@ func (rt *Runtime) DeleteActor(addr address.Address) {
panic(aerrors.Fatalf("failed to get actor: %s", err))
}
if !act.Balance.IsZero() {
rt.vm.transfer(rt.Message().Receiver(), builtin.BurntFundsActorAddr, act.Balance)
if err := rt.vm.transfer(rt.Message().Receiver(), builtin.BurntFundsActorAddr, act.Balance); err != nil {
panic(aerrors.Fatalf("failed to transfer balance to burnt funds actor: %s", err))
}
}
if err := rt.state.DeleteActor(rt.Message().Receiver()); err != nil {
@@ -352,13 +355,13 @@ func (rs *Runtime) Send(to address.Address, method abi.MethodNum, m vmr.CBORMars
params = buf.Bytes()
}
ret, err := rs.internalSend(rs.Message().Receiver(), to, method, types.BigInt(value), params)
ret, err := rs.internalSend(rs.Message().Receiver(), to, method, value, params)
if err != nil {
if err.IsFatal() {
panic(err)
}
log.Warnf("vmctx send failed: to: %s, method: %d: ret: %d, err: %s", to, method, ret, err)
return nil, exitcode.ExitCode(err.RetCode())
return nil, err.RetCode()
}
return &dumbWrapperType{ret}, 0
}
@@ -397,7 +400,7 @@ func (rt *Runtime) internalSend(from, to address.Address, method abi.MethodNum,
}
mr := types.MessageReceipt{
ExitCode: exitcode.ExitCode(aerrors.RetCode(errSend)),
ExitCode: aerrors.RetCode(errSend),
Return: ret,
GasUsed: 0,
}
@@ -429,6 +432,7 @@ type shimStateHandle struct {
func (ssh *shimStateHandle) Create(obj vmr.CBORMarshaler) {
c := ssh.rs.Put(obj)
// TODO: handle error below
ssh.rs.stateCommit(EmptyObjectCid, c)
}
@@ -458,6 +462,7 @@ func (ssh *shimStateHandle) Transaction(obj vmr.CBORer, f func() interface{}) in
c := ssh.rs.Put(obj)
// TODO: handle error below
ssh.rs.stateCommit(baseState, c)
return out
+29 -2
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"sync"
"github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
@@ -225,10 +226,10 @@ func (ss *syscallShim) VerifySeal(info abi.SealVerifyInfo) error {
}
ticket := []byte(info.Randomness)
proof := []byte(info.OnChain.Proof)
proof := info.Proof
seed := []byte(info.InteractiveRandomness)
log.Debugf("Verif r:%x; d:%x; m:%s; t:%x; s:%x; N:%d; p:%x", info.OnChain.SealedCID, info.UnsealedCID, miner, ticket, seed, info.SectorID.Number, proof)
log.Debugf("Verif r:%x; d:%x; m:%s; t:%x; s:%x; N:%d; p:%x", info.SealedCID, info.UnsealedCID, miner, ticket, seed, info.SectorID.Number, proof)
//func(ctx context.Context, maddr address.Address, ssize abi.SectorSize, commD, commR, ticket, proof, seed []byte, sectorID abi.SectorNumber)
ok, err := ss.verifier.VerifySeal(info)
@@ -252,3 +253,29 @@ func (ss *syscallShim) VerifySignature(sig crypto.Signature, addr address.Addres
return sigs.Verify(&sig, kaddr, input)
}
func (ss *syscallShim) BatchVerifySeals(inp map[address.Address][]abi.SealVerifyInfo) (map[address.Address][]bool, error) {
out := make(map[address.Address][]bool)
var wg sync.WaitGroup
for addr, seals := range inp {
results := make([]bool, len(seals))
out[addr] = results
for i, s := range seals {
wg.Add(1)
go func(ma address.Address, ix int, svi abi.SealVerifyInfo, res []bool) {
defer wg.Done()
if err := ss.VerifySeal(svi); err != nil {
log.Warnw("seal verify in batch failed", "miner", ma, "index", ix, "err", err)
res[ix] = false
} else {
res[ix] = true
}
}(addr, i, s, results)
}
}
wg.Wait()
return out, nil
}
+2
View File
@@ -41,6 +41,7 @@ func init() {
func TestChainValidationMessageSuite(t *testing.T) {
f := factory.NewFactories()
for _, testCase := range suites.MessageTestCases() {
testCase := testCase
if TestSuiteSkipper.Skip(testCase) {
continue
}
@@ -53,6 +54,7 @@ func TestChainValidationMessageSuite(t *testing.T) {
func TestChainValidationTipSetSuite(t *testing.T) {
f := factory.NewFactories()
for _, testCase := range suites.TipSetTestCases() {
testCase := testCase
if TestSuiteSkipper.Skip(testCase) {
continue
}
+28 -14
View File
@@ -210,7 +210,7 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
if types.BigCmp(msg.Value, types.NewInt(0)) != 0 {
if err := vm.transfer(msg.From, msg.To, msg.Value); err != nil {
return nil, aerrors.Absorb(err, 1, "failed to transfer funds"), nil
return nil, aerrors.Wrap(err, "failed to transfer funds"), nil
}
}
@@ -246,7 +246,7 @@ func (vm *VM) ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*Ap
ret, actorErr, rt := vm.send(ctx, msg, nil, 0)
return &ApplyRet{
MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.ExitCode(aerrors.RetCode(actorErr)),
ExitCode: aerrors.RetCode(actorErr),
Return: ret,
GasUsed: 0,
},
@@ -415,7 +415,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
return &ApplyRet{
MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.ExitCode(errcode),
ExitCode: errcode,
Return: ret,
GasUsed: gasUsed,
},
@@ -602,36 +602,50 @@ func (vm *VM) incrementNonce(addr address.Address) error {
})
}
func (vm *VM) transfer(from, to address.Address, amt types.BigInt) error {
func (vm *VM) transfer(from, to address.Address, amt types.BigInt) aerrors.ActorError {
if from == to {
return nil
}
fromId, err := vm.cstate.LookupID(from)
if err != nil {
return aerrors.Fatalf("transfer failed when resolving sender address: %s", err)
}
toId, err := vm.cstate.LookupID(to)
if err != nil {
return aerrors.Fatalf("transfer failed when resolving receiver address: %s", err)
}
if fromId == toId {
return nil
}
if amt.LessThan(types.NewInt(0)) {
return xerrors.Errorf("attempted to transfer negative value")
return aerrors.Newf(exitcode.SysErrForbidden, "attempted to transfer negative value: %s", amt)
}
f, err := vm.cstate.GetActor(from)
f, err := vm.cstate.GetActor(fromId)
if err != nil {
return xerrors.Errorf("transfer failed when retrieving sender actor")
return aerrors.Fatalf("transfer failed when retrieving sender actor: %s", err)
}
t, err := vm.cstate.GetActor(to)
t, err := vm.cstate.GetActor(toId)
if err != nil {
return xerrors.Errorf("transfer failed when retrieving receiver actor")
return aerrors.Fatalf("transfer failed when retrieving receiver actor: %s", err)
}
if err := deductFunds(f, amt); err != nil {
return err
return aerrors.Newf(exitcode.SysErrInsufficientFunds, "transfer failed when deducting funds: %s", err)
}
depositFunds(t, amt)
if err := vm.cstate.SetActor(from, f); err != nil {
return err
if err := vm.cstate.SetActor(fromId, f); err != nil {
return aerrors.Fatalf("transfer failed when setting receiver actor: %s", err)
}
if err := vm.cstate.SetActor(to, t); err != nil {
return err
if err := vm.cstate.SetActor(toId, t); err != nil {
return aerrors.Fatalf("transfer failed when setting sender actor: %s", err)
}
return nil
+2 -2
View File
@@ -12,8 +12,8 @@ import (
"github.com/filecoin-project/go-address"
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
_ "github.com/filecoin-project/lotus/lib/sigs/bls" // enable bls signatures
_ "github.com/filecoin-project/lotus/lib/sigs/secp" // enable secp signatures
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/sigs"
+4 -2
View File
@@ -6,6 +6,8 @@ import (
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/lotus/api/apistruct"
"github.com/filecoin-project/lotus/node/repo"
)
@@ -45,7 +47,7 @@ var authCreateAdminToken = &cli.Command{
perm := cctx.String("perm")
idx := 0
for i, p := range apistruct.AllPermissions {
if perm == p {
if auth.Permission(perm) == p {
idx = i + 1
}
}
@@ -93,7 +95,7 @@ var authApiInfoToken = &cli.Command{
perm := cctx.String("perm")
idx := 0
for i, p := range apistruct.AllPermissions {
if perm == p {
if auth.Permission(perm) == p {
idx = i + 1
}
}
+13 -1
View File
@@ -18,6 +18,7 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/account"
"github.com/filecoin-project/specs-actors/actors/builtin/market"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
"github.com/filecoin-project/specs-actors/actors/builtin/power"
"github.com/filecoin-project/specs-actors/actors/util/adt"
@@ -521,6 +522,12 @@ var chainGetCmd = &cli.Command{
cbu = new(power.CronEvent)
case "account-state":
cbu = new(account.State)
case "miner-state":
cbu = new(miner.State)
case "power-state":
cbu = new(power.State)
case "market-state":
cbu = new(market.State)
default:
return fmt.Errorf("unknown type: %q", t)
}
@@ -797,7 +804,12 @@ var chainExportCmd = &cli.Command{
if err != nil {
return err
}
defer fi.Close()
defer func() {
err := fi.Close()
if err != nil {
fmt.Printf("error closing output file: %+v", err)
}
}()
ts, err := LoadTipSet(ctx, cctx, api)
if err != nil {
+21 -10
View File
@@ -384,7 +384,7 @@ var clientRetrieveCmd = &cli.Command{
return nil
}
ref := lapi.FileRef{
ref := &lapi.FileRef{
Path: cctx.Args().Get(1),
IsCAR: cctx.Bool("car"),
}
@@ -501,16 +501,27 @@ var clientListDeals = &cli.Command{
}
var deals []deal
for idx := range localDeals {
onChain, err := api.StateMarketStorageDeal(ctx, localDeals[idx].DealID, head.Key())
if err != nil {
return err
}
for _, v := range localDeals {
if v.DealID == 0 {
deals = append(deals, deal{
LocalDeal: v,
OnChainDealState: market.DealState{
SectorStartEpoch: -1,
LastUpdatedEpoch: -1,
SlashEpoch: -1,
},
})
} else {
onChain, err := api.StateMarketStorageDeal(ctx, v.DealID, head.Key())
if err != nil {
return err
}
deals = append(deals, deal{
LocalDeal: localDeals[idx],
OnChainDealState: onChain.State,
})
deals = append(deals, deal{
LocalDeal: v,
OnChainDealState: onChain.State,
})
}
}
w := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
+2 -1
View File
@@ -16,9 +16,10 @@ import (
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/client"
"github.com/filecoin-project/lotus/lib/jsonrpc"
"github.com/filecoin-project/lotus/node/repo"
)
+4 -1
View File
@@ -206,7 +206,10 @@ var msigInspectCmd = &cli.Command{
tx := pending[txid]
fmt.Fprintf(w, "%d\t%s\t%s\t%s\t%d\t%x\n", txid, state(tx), tx.To, types.FIL(tx.Value), tx.Method, tx.Params)
}
w.Flush()
if err := w.Flush(); err != nil {
return xerrors.Errorf("flushing output: %+v", err)
}
}
return nil
+1 -1
View File
@@ -24,7 +24,7 @@ var fetchParamCmd = &cli.Command{
return err
}
sectorSize := uint64(sectorSizeInt)
err = paramfetch.GetParams(build.ParametersJson(), sectorSize)
err = paramfetch.GetParams(build.ParametersJSON(), sectorSize)
if err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
}
+1 -1
View File
@@ -370,7 +370,7 @@ var paychVoucherSubmitCmd = &cli.Command{
return fmt.Errorf("message execution failed (exit code %d)", mwait.Receipt.ExitCode)
}
fmt.Println("channel updated succesfully")
fmt.Println("channel updated successfully")
return nil
},
+48 -3
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"sort"
"strconv"
"strings"
"time"
@@ -493,6 +494,12 @@ var stateGetDealSetCmd = &cli.Command{
var stateListMinersCmd = &cli.Command{
Name: "list-miners",
Usage: "list all miners in the network",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "sort-by",
Usage: "criteria to sort miners by (none, num-deals)",
},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetFullNodeAPI(cctx)
if err != nil {
@@ -512,6 +519,26 @@ var stateListMinersCmd = &cli.Command{
return err
}
switch cctx.String("sort-by") {
case "num-deals":
ndm, err := getDealsCounts(ctx, api)
if err != nil {
return err
}
sort.Slice(miners, func(i, j int) bool {
return ndm[miners[i]] > ndm[miners[j]]
})
for i := 0; i < 50 && i < len(miners); i++ {
fmt.Printf("%s %d\n", miners[i], ndm[miners[i]])
}
return nil
default:
return fmt.Errorf("unrecognized sorting order")
case "", "none":
}
for _, m := range miners {
fmt.Println(m.String())
}
@@ -520,6 +547,22 @@ var stateListMinersCmd = &cli.Command{
},
}
func getDealsCounts(ctx context.Context, lapi api.FullNode) (map[address.Address]int, error) {
allDeals, err := lapi.StateMarketDeals(ctx, types.EmptyTSK)
if err != nil {
return nil, err
}
out := make(map[address.Address]int)
for _, d := range allDeals {
if d.State.SectorStartEpoch != -1 {
out[d.Proposal.Provider]++
}
}
return out, nil
}
var stateListActorsCmd = &cli.Command{
Name: "list-actors",
Usage: "list all actors in the network",
@@ -892,7 +935,7 @@ var stateComputeStateCmd = &cli.Command{
return c.Code, nil
}
return computeStateHtml(stout, getCode)
return computeStateHtml(ts, stout, getCode)
}
fmt.Println("computed state cid: ", stout.Root)
@@ -921,7 +964,7 @@ func codeStr(c cid.Cid) string {
return string(cmh.Digest)
}
func computeStateHtml(o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error {
func computeStateHtml(ts *types.TipSet, o *api.ComputeStateOutput, getCode func(addr address.Address) (cid.Cid, error)) error {
fmt.Printf(`<html>
<head>
<style>
@@ -947,8 +990,10 @@ func computeStateHtml(o *api.ComputeStateOutput, getCode func(addr address.Addre
</style>
</head>
<body>
<div>Tipset: <b>%s</b></div>
<div>Height: %d</div>
<div>State CID: <b>%s</b></div>
<div>Calls</div>`, o.Root)
<div>Calls</div>`, ts.Key(), ts.Height(), o.Root)
for _, ir := range o.Trace {
toCode, err := getCode(ir.Msg.To)
+3 -1
View File
@@ -23,7 +23,9 @@ var versionCmd = &cli.Command{
if err != nil {
return err
}
fmt.Println(v)
fmt.Println("Daemon: ", v)
fmt.Print("Local: ")
cli.VersionPrinter(cctx)
return nil
},
+1 -2
View File
@@ -53,8 +53,7 @@ var runCmd = &cli.Command{
defer closer()
ctx := lcli.ReqContext(cctx)
sendSmallFundsTxs(ctx, api, addr, 5)
return nil
return sendSmallFundsTxs(ctx, api, addr, 5)
},
}
+18 -4
View File
@@ -15,6 +15,8 @@ import (
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
"github.com/filecoin-project/sector-storage/ffiwrapper"
"github.com/filecoin-project/specs-actors/actors/abi"
"golang.org/x/xerrors"
@@ -53,7 +55,7 @@ var importBenchCmd = &cli.Command{
if err != nil {
return err
}
defer cfi.Close()
defer cfi.Close() //nolint:errcheck // read only file
tdir, err := ioutil.TempDir("", "lotus-import-bench")
if err != nil {
@@ -65,6 +67,11 @@ var importBenchCmd = &cli.Command{
return err
}
bs := blockstore.NewBlockstore(bds)
cbs, err := blockstore.CachedBlockstore(context.TODO(), bs, blockstore.DefaultCacheOpts())
if err != nil {
return err
}
bs = cbs
ds := datastore.NewMapDatastore()
cs := store.NewChainStore(bs, ds, vm.Syscalls(ffiwrapper.ProofVerifier))
stm := stmgr.NewStateManager(cs)
@@ -73,7 +80,7 @@ var importBenchCmd = &cli.Command{
if err != nil {
return err
}
defer prof.Close()
defer prof.Close() //nolint:errcheck
if err := pprof.StartCPUProfile(prof); err != nil {
return err
@@ -111,7 +118,14 @@ var importBenchCmd = &cli.Command{
cur := tschain[i]
log.Infof("computing state (height: %d, ts=%s)", cur.Height(), cur.Cids())
if cur.ParentState() != lastState {
return xerrors.Errorf("tipset chain had state mismatch at height %d", cur.Height())
lastTrace := out[len(out)-1].Trace
d, err := json.MarshalIndent(lastTrace, "", " ")
if err != nil {
panic(err)
}
fmt.Println("TRACE")
fmt.Println(string(d))
return xerrors.Errorf("tipset chain had state mismatch at height %d (%s != %s)", cur.Height(), cur.ParentState(), lastState)
}
start := time.Now()
st, trace, err := stm.ExecutionTrace(context.TODO(), cur)
@@ -132,7 +146,7 @@ var importBenchCmd = &cli.Command{
if err != nil {
return err
}
defer ibj.Close()
defer ibj.Close() //nolint:errcheck
if err := json.NewEncoder(ibj).Encode(out); err != nil {
return err
+21 -22
View File
@@ -78,7 +78,7 @@ func main() {
app := &cli.App{
Name: "lotus-bench",
Usage: "Benchmark performance of lotus on your hardware",
Version: build.UserVersion,
Version: build.UserVersion(),
Commands: []*cli.Command{
proveCmd,
sealBenchCmd,
@@ -141,7 +141,10 @@ var sealBenchCmd = &cli.Command{
},
Action: func(c *cli.Context) error {
if c.Bool("no-gpu") {
os.Setenv("BELLMAN_NO_GPU", "1")
err := os.Setenv("BELLMAN_NO_GPU", "1")
if err != nil {
return xerrors.Errorf("setting no-gpu flag: %w", err)
}
}
robench := c.String("benchmark-existing-sectorbuilder")
@@ -154,7 +157,10 @@ var sealBenchCmd = &cli.Command{
return err
}
os.MkdirAll(sdir, 0775)
err = os.MkdirAll(sdir, 0775) //nolint:gosec
if err != nil {
return xerrors.Errorf("creating sectorbuilder dir: %w", err)
}
tsdir, err := ioutil.TempDir(sdir, "bench")
if err != nil {
@@ -209,7 +215,7 @@ var sealBenchCmd = &cli.Command{
// Only fetch parameters if actually needed
if !c.Bool("skip-commit2") {
if err := paramfetch.GetParams(build.ParametersJson(), uint64(sectorSize)); err != nil {
if err := paramfetch.GetParams(build.ParametersJSON(), uint64(sectorSize)); err != nil {
return xerrors.Errorf("getting params: %w", err)
}
}
@@ -527,16 +533,11 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, mid
if !skipc2 {
svi := abi.SealVerifyInfo{
SectorID: abi.SectorID{Miner: mid, Number: i},
OnChain: abi.OnChainSealVerifyInfo{
SealedCID: cids.Sealed,
InteractiveEpoch: seed.Epoch,
RegisteredProof: sb.SealProofType(),
Proof: proof,
DealIDs: nil,
SectorNumber: i,
SealRandEpoch: 0,
},
SectorID: abi.SectorID{Miner: mid, Number: i},
SealedCID: cids.Sealed,
RegisteredProof: sb.SealProofType(),
Proof: proof,
DealIDs: nil,
Randomness: ticket,
InteractiveRandomness: seed.Value,
UnsealedCID: cids.Unsealed,
@@ -567,15 +568,10 @@ func runSeals(sb *ffiwrapper.Sealer, sbfs *basicfs.Provider, numSectors int, mid
}
}
// TODO: RM unsealed sector first
rc, err := sb.ReadPieceFromSealedSector(context.TODO(), abi.SectorID{Miner: mid, Number: 1}, 0, abi.UnpaddedPieceSize(sectorSize), ticket, cids.Unsealed)
err := sb.UnsealPiece(context.TODO(), abi.SectorID{Miner: mid, Number: 1}, 0, abi.UnpaddedPieceSize(sectorSize), ticket, cids.Unsealed)
if err != nil {
return nil, nil, err
}
if err := rc.Close(); err != nil {
return nil, nil, err
}
}
unseal := time.Now()
@@ -604,7 +600,10 @@ var proveCmd = &cli.Command{
},
Action: func(c *cli.Context) error {
if c.Bool("no-gpu") {
os.Setenv("BELLMAN_NO_GPU", "1")
err := os.Setenv("BELLMAN_NO_GPU", "1")
if err != nil {
return xerrors.Errorf("setting no-gpu flag: %w", err)
}
}
if !c.Args().Present() {
@@ -621,7 +620,7 @@ var proveCmd = &cli.Command{
return xerrors.Errorf("unmarshalling input file: %w", err)
}
if err := paramfetch.GetParams(build.ParametersJson(), c2in.SectorSize); err != nil {
if err := paramfetch.GetParams(build.ParametersJSON(), c2in.SectorSize); err != nil {
return xerrors.Errorf("getting params: %w", err)
}
+2 -2
View File
@@ -29,7 +29,7 @@ func main() {
app := &cli.App{
Name: "lotus-chainwatch",
Usage: "Devnet token distribution utility",
Version: build.UserVersion,
Version: build.UserVersion(),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
@@ -86,7 +86,7 @@ var runCmd = &cli.Command{
if err != nil {
return err
}
defer st.close()
defer st.close() //nolint:errcheck
runSyncer(ctx, api, st, maxBatch)
+8
View File
@@ -653,6 +653,14 @@ create temp table b (like blocks excluding constraints) on commit drop;
eprof = bh.ElectionProof.VRFProof
}
if bh.Ticket == nil {
log.Warnf("got a block with nil ticket")
bh.Ticket = &types.Ticket{
VRFProof: []byte{},
}
}
if _, err := stmt2.Exec(
bh.Cid().String(),
bh.ParentWeight.String(),
+9 -6
View File
@@ -20,6 +20,7 @@ import (
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
parmap "github.com/filecoin-project/lotus/lib/parmap"
)
func runSyncer(ctx context.Context, api api.FullNode, st *storage, maxBatch int) {
@@ -138,7 +139,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
log.Infof("Syncing %d blocks", len(toSync))
paDone := 0
par(50, maparr(toSync), func(bh *types.BlockHeader) {
parmap.Par(50, parmap.MapArr(toSync), func(bh *types.BlockHeader) {
paDone++
if paDone%100 == 0 {
log.Infof("pa: %d %d%%", paDone, (paDone*100)/len(toSync))
@@ -152,7 +153,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
return
}
par(50, aadrs, func(addr address.Address) {
parmap.Par(50, aadrs, func(addr address.Address) {
act, err := api.StateGetActor(ctx, addr, ts.Key())
if err != nil {
log.Error(err)
@@ -198,6 +199,8 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
}
for a, act := range changes {
act := act
addr, err := address.NewFromString(a)
if err != nil {
log.Error(err)
@@ -239,7 +242,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
addresses[message.From] = address.Undef
}
par(50, kmaparr(addresses), func(addr address.Address) {
parmap.Par(50, parmap.KMapArr(addresses), func(addr address.Address) {
raddr, err := api.StateLookupID(ctx, addr, types.EmptyTSK)
if err != nil {
log.Warn(err)
@@ -268,7 +271,7 @@ func syncHead(ctx context.Context, api api.FullNode, st *storage, ts *types.TipS
}
}
par(50, kvmaparr(miners), func(it func() (minerKey, *minerInfo)) {
parmap.Par(50, parmap.KVMapArr(miners), func(it func() (minerKey, *minerInfo)) {
k, info := it()
pow, err := api.StateMinerPower(ctx, k.addr, types.EmptyTSK)
@@ -386,7 +389,7 @@ func fetchMessages(ctx context.Context, api api.FullNode, toSync map[cid.Cid]*ty
messages := map[cid.Cid]*types.Message{}
inclusions := map[cid.Cid][]cid.Cid{} // block -> msgs
par(50, maparr(toSync), func(header *types.BlockHeader) {
parmap.Par(50, parmap.MapArr(toSync), func(header *types.BlockHeader) {
msgs, err := api.ChainGetBlockMessages(ctx, header.Cid())
if err != nil {
log.Error(err)
@@ -423,7 +426,7 @@ func fetchParentReceipts(ctx context.Context, api api.FullNode, toSync map[cid.C
var lk sync.Mutex
out := map[mrec]*types.MessageReceipt{}
par(50, maparr(toSync), func(header *types.BlockHeader) {
parmap.Par(50, parmap.MapArr(toSync), func(header *types.BlockHeader) {
recs, err := api.ChainGetParentReceipts(ctx, header.Cid())
if err != nil {
log.Error(err)
+4 -4
View File
@@ -46,7 +46,7 @@ func main() {
app := &cli.App{
Name: "lotus-fountain",
Usage: "Devnet token distribution utility",
Version: build.UserVersion,
Version: build.UserVersion(),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "repo",
@@ -157,7 +157,7 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
to, err := address.NewFromString(r.FormValue("address"))
if err != nil {
w.WriteHeader(400)
w.Write([]byte(err.Error()))
_, _ = w.Write([]byte(err.Error()))
return
}
@@ -204,11 +204,11 @@ func (h *handler) send(w http.ResponseWriter, r *http.Request) {
})
if err != nil {
w.WriteHeader(400)
w.Write([]byte(err.Error()))
_, _ = w.Write([]byte(err.Error()))
return
}
w.Write([]byte(smsg.Cid().String()))
_, _ = w.Write([]byte(smsg.Cid().String()))
}
func (h *handler) mkminer(w http.ResponseWriter, r *http.Request) {
+5 -2
View File
@@ -12,8 +12,8 @@
</div>
<div class="Index-node" id="formnd">
<form id="f" action='/mkminer' method='POST'>
<span>Enter destination address:</span>
<input type='text' name='address' style="width: 300px">
<span>Enter owner/worker address:</span>
<input type='text' name='address' style="width: 300px" placeholder="t3...">
<select name="sectorSize">
<option selected value="34359738368">32GiB sectors</option>
<option value="68719476736">64GiB sectors</option>
@@ -27,6 +27,9 @@
<div class="Index-node">
<span>When creating storage miner, DO NOT REFRESH THE PAGE, wait for it to load. This can take more than 5min.</span>
</div>
<div class="Index-node">
<span>If you don't have an owner/worker address, you can create it by following <a target="_blank" href="https://docs.lotu.sh/en+mining#get-started-22083">these instructions</a>.</span>
</div>
</div>
<div class="Index-footer">
<div>
+8 -6
View File
@@ -8,14 +8,16 @@ import (
"syscall"
"time"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/lib/jsonrpc"
cid "github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log"
"gopkg.in/urfave/cli.v2"
)
type CidWindow [][]cid.Cid
@@ -34,7 +36,7 @@ func main() {
app := &cli.App{
Name: "lotus-health",
Usage: "Tools for monitoring lotus daemon health",
Version: build.UserVersion,
Version: build.UserVersion(),
Commands: local,
Flags: []cli.Flag{
&cli.StringFlag{
@@ -77,7 +79,7 @@ var watchHeadCmd = &cli.Command{
&cli.IntFlag{
Name: "api-retries",
Value: 8,
Usage: "number of API retry attemps",
Usage: "number of API retry attempts",
},
},
Action: func(c *cli.Context) error {
+8 -6
View File
@@ -15,6 +15,8 @@ import (
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-jsonrpc/auth"
paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/sector-storage/ffiwrapper"
@@ -22,11 +24,9 @@ import (
"github.com/filecoin-project/lotus/api/apistruct"
"github.com/filecoin-project/lotus/build"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/lib/auth"
"github.com/filecoin-project/lotus/lib/jsonrpc"
"github.com/filecoin-project/lotus/lib/lotuslog"
"github.com/filecoin-project/lotus/node/repo"
"github.com/filecoin-project/sector-storage"
sectorstorage "github.com/filecoin-project/sector-storage"
"github.com/filecoin-project/sector-storage/sealtasks"
"github.com/filecoin-project/sector-storage/stores"
)
@@ -47,7 +47,7 @@ func main() {
app := &cli.App{
Name: "lotus-seal-worker",
Usage: "Remote storage miner worker",
Version: build.UserVersion,
Version: build.UserVersion(),
Flags: []cli.Flag{
&cli.StringFlag{
Name: FlagStorageRepo,
@@ -107,7 +107,9 @@ var runCmd = &cli.Command{
},
Action: func(cctx *cli.Context) error {
if !cctx.Bool("enable-gpu-proving") {
os.Setenv("BELLMAN_NO_GPU", "true")
if err := os.Setenv("BELLMAN_NO_GPU", "true"); err != nil {
return xerrors.Errorf("could not set no-gpu env: %+v", err)
}
}
if cctx.String("address") == "" {
@@ -146,7 +148,7 @@ var runCmd = &cli.Command{
}
if cctx.Bool("commit") {
if err := paramfetch.GetParams(build.ParametersJson(), uint64(ssize)); err != nil {
if err := paramfetch.GetParams(build.ParametersJSON(), uint64(ssize)); err != nil {
return xerrors.Errorf("get params: %w", err)
}
}
+1 -2
View File
@@ -39,7 +39,7 @@ func main() {
app := &cli.App{
Name: "lotus-seed",
Usage: "Seal sectors for genesis miner",
Version: build.UserVersion,
Version: build.UserVersion(),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "sector-dir",
@@ -145,7 +145,6 @@ var aggregateManifestsCmd = &cli.Command{
if err != nil {
return err
}
defer fi.Close()
var val map[string]genesis.Miner
if err := json.NewDecoder(fi).Decode(&val); err != nil {
return err
+2 -2
View File
@@ -6,7 +6,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/minio/blake2b-simd"
"io/ioutil"
"os"
"path/filepath"
@@ -15,6 +14,7 @@ import (
logging "github.com/ipfs/go-log/v2"
ic "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/minio/blake2b-simd"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
@@ -48,7 +48,7 @@ func PreSeal(maddr address.Address, pt abi.RegisteredProof, offset abi.SectorNum
SealProofType: spt,
}
if err := os.MkdirAll(sbroot, 0775); err != nil {
if err := os.MkdirAll(sbroot, 0775); err != nil { //nolint:gosec
return nil, nil, err
}
+2 -2
View File
@@ -34,7 +34,7 @@ var importCarCmd = &cli.Command{
if err != nil {
return err
}
defer lr.Close()
defer lr.Close() //nolint:errcheck
cf := cctx.Args().Get(0)
f, err := os.OpenFile(cf, os.O_RDONLY, 0664)
@@ -42,7 +42,7 @@ var importCarCmd = &cli.Command{
return xerrors.Errorf("opening the car file: %w", err)
}
ds, err := lr.Datastore("/blocks")
ds, err := lr.Datastore("/chain")
if err != nil {
return err
}
+2
View File
@@ -26,6 +26,8 @@ func main() {
importCarCmd,
commpToCidCmd,
fetchParamCmd,
proofsCmd,
verifRegCmd,
}
app := &cli.App{
+1 -1
View File
@@ -24,7 +24,7 @@ var fetchParamCmd = &cli.Command{
return err
}
sectorSize := uint64(sectorSizeInt)
err = paramfetch.GetParams(build.ParametersJson(), sectorSize)
err = paramfetch.GetParams(build.ParametersJSON(), sectorSize)
if err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
}
+108
View File
@@ -0,0 +1,108 @@
package main
import (
"encoding/hex"
"fmt"
"gopkg.in/urfave/cli.v2"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
)
var proofsCmd = &cli.Command{
Name: "proofs",
Subcommands: []*cli.Command{
verifySealProofCmd,
},
}
var verifySealProofCmd = &cli.Command{
Name: "verify-seal",
ArgsUsage: "<commr> <commd> <proof>",
Description: "Verify a seal proof with manual inputs",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "ticket",
},
&cli.StringFlag{
Name: "proof-rand",
},
&cli.StringFlag{
Name: "miner",
},
&cli.Uint64Flag{
Name: "sector-id",
},
&cli.Int64Flag{
Name: "proof-type",
},
},
Action: func(cctx *cli.Context) error {
if cctx.Args().Len() != 3 {
return fmt.Errorf("must specify commR, commD, and proof to verify")
}
commr, err := cid.Decode(cctx.Args().Get(0))
if err != nil {
return err
}
commd, err := cid.Decode(cctx.Args().Get(1))
if err != nil {
return err
}
proof, err := hex.DecodeString(cctx.Args().Get(2))
if err != nil {
return fmt.Errorf("failed to decode hex proof input: %w", err)
}
maddr, err := address.NewFromString(cctx.String("miner"))
if err != nil {
return err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return err
}
ticket, err := hex.DecodeString(cctx.String("ticket"))
if err != nil {
return err
}
proofRand, err := hex.DecodeString(cctx.String("proof-rand"))
if err != nil {
return err
}
snum := abi.SectorNumber(cctx.Uint64("sector-id"))
ok, err := ffi.VerifySeal(abi.SealVerifyInfo{
SectorID: abi.SectorID{
Miner: abi.ActorID(mid),
Number: snum,
},
SealedCID: commr,
RegisteredProof: abi.RegisteredProof(cctx.Int64("proof-type")),
Proof: proof,
DealIDs: nil,
Randomness: abi.SealRandomness(ticket),
InteractiveRandomness: abi.InteractiveSealRandomness(proofRand),
UnsealedCID: commd,
})
if err != nil {
return err
}
if !ok {
return fmt.Errorf("invalid proof")
}
fmt.Println("proof valid!")
return nil
},
}
+377
View File
@@ -0,0 +1,377 @@
package main
import (
"bytes"
"fmt"
"github.com/filecoin-project/go-address"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/api/apibstore"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
"github.com/ipfs/go-hamt-ipld"
cbor "github.com/ipfs/go-ipld-cbor"
cbg "github.com/whyrusleeping/cbor-gen"
)
var verifRegCmd = &cli.Command{
Name: "verifreg",
Usage: "Interact with the verified registry actor",
Flags: []cli.Flag{},
Subcommands: []*cli.Command{
verifRegAddVerifierCmd,
verifRegVerifyClientCmd,
verifRegListVerifiersCmd,
verifRegListClientsCmd,
verifRegCheckClientCmd,
verifRegCheckVerifierCmd,
},
}
var verifRegAddVerifierCmd = &cli.Command{
Name: "add-verifier",
Usage: "make a given account a verifier",
Action: func(cctx *cli.Context) error {
fromk, err := address.NewFromString("t3qfoulel6fy6gn3hjmbhpdpf6fs5aqjb5fkurhtwvgssizq4jey5nw4ptq5up6h7jk7frdvvobv52qzmgjinq")
if err != nil {
return err
}
if cctx.Args().Len() != 2 {
return fmt.Errorf("must specify two arguments: address and allowance")
}
target, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
allowance, err := types.BigFromString(cctx.Args().Get(1))
if err != nil {
return err
}
params, err := actors.SerializeParams(&verifreg.AddVerifierParams{Address: target, Allowance: allowance})
if err != nil {
return err
}
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
msg := &types.Message{
To: builtin.VerifiedRegistryActorAddr,
From: fromk,
Method: builtin.MethodsVerifiedRegistry.AddVerifier,
GasPrice: types.NewInt(1),
GasLimit: 300000,
Params: params,
}
smsg, err := api.MpoolPushMessage(ctx, msg)
if err != nil {
return err
}
fmt.Printf("message sent, now waiting on cid: %s\n", smsg.Cid())
mwait, err := api.StateWaitMsg(ctx, smsg.Cid())
if err != nil {
return err
}
if mwait.Receipt.ExitCode != 0 {
return fmt.Errorf("failed to add verifier: %d", mwait.Receipt.ExitCode)
}
return nil
},
}
var verifRegVerifyClientCmd = &cli.Command{
Name: "verify-client",
Usage: "make a given account a verified client",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "from",
Usage: "specify your verifier address to send the message from",
},
},
Action: func(cctx *cli.Context) error {
froms := cctx.String("from")
if froms == "" {
return fmt.Errorf("must specify from address with --from")
}
fromk, err := address.NewFromString(froms)
if err != nil {
return err
}
if cctx.Args().Len() != 2 {
return fmt.Errorf("must specify two arguments: address and allowance")
}
target, err := address.NewFromString(cctx.Args().Get(0))
if err != nil {
return err
}
allowance, err := types.BigFromString(cctx.Args().Get(1))
if err != nil {
return err
}
params, err := actors.SerializeParams(&verifreg.AddVerifiedClientParams{Address: target, Allowance: allowance})
if err != nil {
return err
}
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
msg := &types.Message{
To: builtin.VerifiedRegistryActorAddr,
From: fromk,
Method: builtin.MethodsVerifiedRegistry.AddVerifiedClient,
GasPrice: types.NewInt(1),
GasLimit: 300000,
Params: params,
}
smsg, err := api.MpoolPushMessage(ctx, msg)
if err != nil {
return err
}
fmt.Printf("message sent, now waiting on cid: %s\n", smsg.Cid())
mwait, err := api.StateWaitMsg(ctx, smsg.Cid())
if err != nil {
return err
}
if mwait.Receipt.ExitCode != 0 {
return fmt.Errorf("failed to add verified client: %d", mwait.Receipt.ExitCode)
}
return nil
},
}
var verifRegListVerifiersCmd = &cli.Command{
Name: "list-verifiers",
Usage: "list all verifiers",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK)
if err != nil {
return err
}
apibs := apibstore.NewAPIBlockstore(api)
cst := cbor.NewCborStore(apibs)
var st verifreg.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return err
}
vh, err := hamt.LoadNode(ctx, cst, st.Verifiers)
if err != nil {
return err
}
if err := vh.ForEach(ctx, func(k string, val interface{}) error {
addr, err := address.NewFromBytes([]byte(k))
if err != nil {
return err
}
var dcap verifreg.DataCap
if err := dcap.UnmarshalCBOR(bytes.NewReader(val.(*cbg.Deferred).Raw)); err != nil {
return err
}
fmt.Printf("%s: %s\n", addr, dcap)
return nil
}); err != nil {
return err
}
return nil
},
}
var verifRegListClientsCmd = &cli.Command{
Name: "list-clients",
Usage: "list all verified clients",
Action: func(cctx *cli.Context) error {
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK)
if err != nil {
return err
}
apibs := apibstore.NewAPIBlockstore(api)
cst := cbor.NewCborStore(apibs)
var st verifreg.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return err
}
vh, err := hamt.LoadNode(ctx, cst, st.VerifiedClients)
if err != nil {
return err
}
if err := vh.ForEach(ctx, func(k string, val interface{}) error {
addr, err := address.NewFromBytes([]byte(k))
if err != nil {
return err
}
var dcap verifreg.DataCap
if err := dcap.UnmarshalCBOR(bytes.NewReader(val.(*cbg.Deferred).Raw)); err != nil {
return err
}
fmt.Printf("%s: %s\n", addr, dcap)
return nil
}); err != nil {
return err
}
return nil
},
}
var verifRegCheckClientCmd = &cli.Command{
Name: "check-client",
Usage: "check verified client remaining bytes",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return fmt.Errorf("must specify client address to check")
}
caddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK)
if err != nil {
return err
}
apibs := apibstore.NewAPIBlockstore(api)
cst := cbor.NewCborStore(apibs)
var st verifreg.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return err
}
vh, err := hamt.LoadNode(ctx, cst, st.VerifiedClients)
if err != nil {
return err
}
var dcap verifreg.DataCap
if err := vh.Find(ctx, string(caddr.Bytes()), &dcap); err != nil {
return err
}
fmt.Println(dcap)
return nil
},
}
var verifRegCheckVerifierCmd = &cli.Command{
Name: "check-verifier",
Usage: "check verifiers remaining bytes",
Action: func(cctx *cli.Context) error {
if !cctx.Args().Present() {
return fmt.Errorf("must specify verifier address to check")
}
vaddr, err := address.NewFromString(cctx.Args().First())
if err != nil {
return err
}
api, closer, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK)
if err != nil {
return err
}
apibs := apibstore.NewAPIBlockstore(api)
cst := cbor.NewCborStore(apibs)
var st verifreg.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return err
}
vh, err := hamt.LoadNode(ctx, cst, st.Verifiers)
if err != nil {
return err
}
var dcap verifreg.DataCap
if err := vh.Find(ctx, string(vaddr.Bytes()), &dcap); err != nil {
return err
}
fmt.Println(dcap)
return nil
},
}
+13 -4
View File
@@ -98,14 +98,23 @@ var infoCmd = &cli.Command{
return err
}
nfaults, err := faults.Count()
if err != nil {
return xerrors.Errorf("counting faults: %w", err)
}
fmt.Printf("\tCommitted: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Sset), types.NewInt(uint64(mi.SectorSize)))))
if len(faults) == 0 {
if nfaults == 0 {
fmt.Printf("\tProving: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Pset), types.NewInt(uint64(mi.SectorSize)))))
} else {
var faultyPercentage float64
if secCounts.Sset != 0 {
faultyPercentage = float64(10000*nfaults/secCounts.Sset) / 100.
}
fmt.Printf("\tProving: %s (%s Faulty, %.2f%%)\n",
types.SizeStr(types.BigMul(types.NewInt(secCounts.Pset-uint64(len(faults))), types.NewInt(uint64(mi.SectorSize)))),
types.SizeStr(types.BigMul(types.NewInt(uint64(len(faults))), types.NewInt(uint64(mi.SectorSize)))),
float64(10000*uint64(len(faults))/secCounts.Pset)/100.)
types.SizeStr(types.BigMul(types.NewInt(secCounts.Pset), types.NewInt(uint64(mi.SectorSize)))),
types.SizeStr(types.BigMul(types.NewInt(nfaults), types.NewInt(uint64(mi.SectorSize)))),
faultyPercentage)
}
fmt.Println()
+5 -16
View File
@@ -37,7 +37,6 @@ import (
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/beacon/drand"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/genesis"
@@ -127,7 +126,7 @@ var initCmd = &cli.Command{
}
log.Info("Checking proof parameters")
if err := paramfetch.GetParams(build.ParametersJson(), uint64(ssize)); err != nil {
if err := paramfetch.GetParams(build.ParametersJSON(), uint64(ssize)); err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
}
@@ -362,7 +361,7 @@ func migratePreSealMeta(ctx context.Context, api lapi.FullNode, metadata string,
buf := make([]byte, binary.MaxVarintLen64)
size := binary.PutUvarint(buf, uint64(maxSectorID+1))
return mds.Put(datastore.NewKey("/storage/nextid"), buf[:size])
return mds.Put(datastore.NewKey(modules.StorageCounterDSPrefix), buf[:size])
}
func findMarketDealID(ctx context.Context, api lapi.FullNode, deal market.DealProposal) (abi.DealID, error) {
@@ -389,7 +388,7 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode,
if err != nil {
return err
}
defer lr.Close()
defer lr.Close() //nolint:errcheck
log.Info("Initializing libp2p identity")
@@ -437,7 +436,7 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode,
smgr, err := sectorstorage.New(ctx, lr, stores.NewIndex(), &ffiwrapper.Config{
SealProofType: spt,
}, sectorstorage.SealerConfig{true, true, true}, nil, sa)
}, sectorstorage.SealerConfig{true, true, true, true}, nil, sa)
if err != nil {
return err
}
@@ -446,17 +445,7 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api lapi.FullNode,
return err
}
gen, err := api.ChainGetGenesis(ctx)
if err != nil {
return err
}
beacon, err := drand.NewDrandBeacon(gen.Blocks()[0].Timestamp, build.BlockDelay)
if err != nil {
return err
}
m := miner.NewMiner(api, epp, beacon, a)
m := miner.NewMiner(api, epp, a)
{
if err := m.Start(ctx); err != nil {
return xerrors.Errorf("failed to start up genesis miner: %w", err)
+1 -1
View File
@@ -57,7 +57,7 @@ func main() {
app := &cli.App{
Name: "lotus-storage-miner",
Usage: "Filecoin decentralized storage network storage miner",
Version: build.UserVersion,
Version: build.UserVersion(),
EnableShellCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
+3 -2
View File
@@ -14,12 +14,13 @@ import (
"golang.org/x/xerrors"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/apistruct"
"github.com/filecoin-project/lotus/build"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/lib/auth"
"github.com/filecoin-project/lotus/lib/jsonrpc"
"github.com/filecoin-project/lotus/lib/ulimit"
"github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/impl"
+1 -1
View File
@@ -249,7 +249,7 @@ var storageListCmd = &cli.Command{
type storedSector struct {
id stores.ID
store stores.StorageInfo
store stores.SectorStorageInfo
unsealed, sealed, cache bool
}
+3 -3
View File
@@ -134,7 +134,7 @@ var DaemonCmd = &cli.Command{
return xerrors.Errorf("repo init error: %w", err)
}
if err := paramfetch.GetParams(build.ParametersJson(), 0); err != nil {
if err := paramfetch.GetParams(build.ParametersJSON(), 0); err != nil {
return xerrors.Errorf("fetching proof parameters: %w", err)
}
@@ -269,9 +269,9 @@ func ImportChain(r repo.Repo, fname string) error {
if err != nil {
return err
}
defer lr.Close()
defer lr.Close() //nolint:errcheck
ds, err := lr.Datastore("/blocks")
ds, err := lr.Datastore("/chain")
if err != nil {
return err
}
+1 -3
View File
@@ -17,8 +17,6 @@ import (
var AdvanceBlockCmd *cli.Command
func main() {
os.Setenv("BELLMAN_NO_GPU", "1")
lotuslog.SetupLogLevels()
local := []*cli.Command{
@@ -54,7 +52,7 @@ func main() {
app := &cli.App{
Name: "lotus",
Usage: "Filecoin decentralized storage network client",
Version: build.UserVersion,
Version: build.UserVersion(),
EnableShellCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
+11 -11
View File
@@ -9,14 +9,6 @@ import (
"os/signal"
"syscall"
"github.com/filecoin-project/lotus/api/apistruct"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/lib/auth"
"github.com/filecoin-project/lotus/lib/jsonrpc"
"github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/impl"
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"github.com/multiformats/go-multiaddr"
@@ -24,6 +16,14 @@ import (
"golang.org/x/xerrors"
"contrib.go.opencensus.io/exporter/prometheus"
"github.com/filecoin-project/go-jsonrpc"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/apistruct"
"github.com/filecoin-project/lotus/node"
"github.com/filecoin-project/lotus/node/impl"
)
var log = logging.Logger("main")
@@ -83,16 +83,16 @@ func handleImport(a *impl.FullNodeAPI) func(w http.ResponseWriter, r *http.Reque
w.WriteHeader(404)
return
}
if !apistruct.HasPerm(r.Context(), apistruct.PermWrite) {
if !auth.HasPerm(r.Context(), nil, apistruct.PermWrite) {
w.WriteHeader(401)
json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
_ = json.NewEncoder(w).Encode(struct{ Error string }{"unauthorized: missing write permission"})
return
}
c, err := a.ClientImportLocal(r.Context(), r.Body)
if err != nil {
w.WriteHeader(500)
json.NewEncoder(w).Encode(struct{ Error string }{err.Error()})
_ = json.NewEncoder(w).Encode(struct{ Error string }{err.Error()})
return
}
w.WriteHeader(200)
+7 -1
View File
@@ -56,6 +56,12 @@
"github": "en/join-testnet.md",
"value": null
},
{
"title": "Use Lotus with systemd",
"slug": "en+install-system-services",
"github": "en/install-system-services.md",
"value": null
},
{
"title": "Setup Troubleshooting",
"slug": "en+setup-troubleshooting",
@@ -137,7 +143,7 @@
"value": null,
"posts": [
{
"title": "API Scripting Support",
"title": "Remote API Support",
"slug": "en+api-scripting-support",
"github": "en/api-scripting-support.md",
"value": null
+4 -12
View File
@@ -1,21 +1,13 @@
# API Scripting Support
# Remote API Support
You may want to delegate the work **Lotus Storage Miner** or **Lotus Node** perform to other machines. Here is how to setup the necessary authorization and environment variables.
## Generate a JWT
To generate a JWT for your environment variables, use this command:
```sh
lotus auth create-token --perm admin
lotus-storage-miner auth create-token --perm admin
```
You may want to delegate the work **Lotus Storage Miner** or **Lotus Node** performs to other machines.
Here is how to setup the necessary authorization and environment variables.
## Environment variables
Environmental variables are variables that are defined for the current shell and are inherited by any child shells or processes. Environmental variables are used to pass information into processes that are spawned from the shell.
Using the JWT you generated, you can assign it and the **multiaddr** to the appropriate environment variable.
Using the [JWT you generated](https://lotu.sh/en+api#how-do-i-generate-a-token-18865), you can assign it and the **multiaddr** to the appropriate environment variable.
```sh
# Lotus Node
+2 -2
View File
@@ -2,7 +2,7 @@
Here is an early overview of how to make API calls.
Implementation details for the **JSON-RPC** package are [here](https://github.com/filecoin-project/lotus/tree/master/lib/jsonrpc).
Implementation details for the **JSON-RPC** package are [here](https://github.com/filecoin-project/go-jsonrpc).
## Overview: How do you modify the config.toml to change the API endpoint?
@@ -77,7 +77,7 @@ lotus-storage-miner auth create-token --perm admin
## What authorization level should I use?
When viewing [api/struct.go](https://github.com/filecoin-project/lotus/blob/master/api/struct.go), you will encounter these types:
When viewing [api/apistruct/struct.go](https://github.com/filecoin-project/lotus/blob/master/api/apistruct/struct.go), you will encounter these types:
- `read` - Read node state, no private data.
- `write` - Write to local store / chain, and `read` permissions.
@@ -0,0 +1,29 @@
# Use Lotus with systemd
Lotus is capable of running as a systemd service daemon. You can find installable service files for systemd in the [lotus repo scripts directory](https://github.com/filecoin-project/lotus/tree/master/scripts) as files with `.service` extension. In order to install these service files, you can copy these `.service` files to the default systemd service path.
## Installing via `make`
NOTE: Before using lotus and lotus-miner as systemd services, don't forget to `sudo make install` to ensure the binaries are accessible by the root user.
If your host uses the default systemd service path, it can be installed with `sudo make install-services`:
```sh
$ sudo make install-services
```
## Interacting with service logs
Logs from the services can be reviewed using `journalctl`.
### Follow logs from a specific service unit
```sh
$ sudo journalctl -u lotus-daemon -f
```
### View logs in reverse order
```sh
$ sudo journalctl -u lotus-miner -r
```
+1 -1
View File
@@ -55,7 +55,7 @@ Here is an example of the response:
t1aswwvjsae63tcrniz6x5ykvsuotlgkvlulnqpsi
```
- Visit the [faucet](https://facuet.testnet.filecoin.io) to add funds.
- Visit the [faucet](https://faucet.testnet.filecoin.io) to add funds.
- Paste the address you created.
- Press the send button.
+2 -2
View File
@@ -14,7 +14,7 @@ Download the 2048 byte parameters:
Pre-seal some sectors:
```sh
./lotus-seed pre-seal --sector-size 2048 --num-sectors 2
./lotus-seed pre-seal --sector-size 2KiB --num-sectors 2
```
Create the genesis block and start up the first node:
@@ -34,7 +34,7 @@ Then, in another console, import the genesis miner key:
Set up the genesis miner:
```sh
./lotus-storage-miner init --genesis-miner --actor=t01000 --sector-size=2048 --pre-sealed-sectors=~/.genesis-sectors --pre-sealed-metadata=~/.genesis-sectors/pre-seal-t01000.json --nosync
./lotus-storage-miner init --genesis-miner --actor=t01000 --sector-size=2KiB --pre-sealed-sectors=~/.genesis-sectors --pre-sealed-metadata=~/.genesis-sectors/pre-seal-t01000.json --nosync
```
Now, finally, start up the miner:
+1 -1
View File
@@ -51,7 +51,7 @@ If you suspect that your GPU is not being used, first make sure it is properly c
First, to watch GPU utilization run `nvtop` in one terminal, then in a separate terminal, run:
```sh
lotus-bench --sector-size=2048
lotus-bench --sector-size=2KiB
```
This process uses a fair amount of GPU, and generally takes ~4 minutes to complete. If you do not see any activity in nvtop from lotus during the entire process, it is likely something is misconfigured with your GPU.
+1 -1
View File
@@ -28,7 +28,7 @@ lotus wallet new bls
With your wallet address:
- Visit the [faucet](https://facuet.testnet.filecoin.io)
- Visit the [faucet](https://faucet.testnet.filecoin.io)
- Click "Create Miner"
- DO NOT REFRESH THE PAGE. THIS OPERATION CAN TAKE SOME TIME.
+3 -1
View File
@@ -2,7 +2,9 @@
Lotus supports making deals with data stored in IPFS, without having to re-import it into lotus.
To enable this integration, open up `~/.lotus/config.toml` (Or if you manually set `LOTUS_PATH`, look under that directory) and look for the Client field, and set `UseIpfs` to `true`.
To enable this integration, you need to have an IPFS daemon running in the background.
Then, open up `~/.lotus/config.toml` (or if you manually set `LOTUS_PATH`, look under that directory)
and look for the Client field, and set `UseIpfs` to `true`.
```toml
[Client]
-154
View File
@@ -1,154 +0,0 @@
package bitvector
import (
"errors"
"log"
)
var (
// ErrOutOfRange - the index passed is out of range for the BitVector
ErrOutOfRange = errors.New("index out of range")
)
// BitNumbering indicates the ordering of bits, either
// least-significant bit in position 0, or most-significant bit
// in position 0.
//
// It it used in 3 ways with BitVector:
// 1. Ordering of bits within the Buf []byte structure
// 2. What order to add bits when using Extend()
// 3. What order to read bits when using Take()
//
// https://en.wikipedia.org/wiki/Bit_numbering
type BitNumbering int
const (
// LSB0 - bit ordering starts with the low-order bit
LSB0 BitNumbering = iota
// MSB0 - bit ordering starts with the high-order bit
MSB0
)
// BitVector is used to manipulate ordered collections of bits
type BitVector struct {
Buf []byte
// BytePacking is the bit ordering within bytes
BytePacking BitNumbering
// Len is the logical number of bits in the vector.
// The last byte in Buf may have undefined bits if Len is not a multiple of 8
Len uint
}
// NewBitVector constructs a new BitVector from a slice of bytes.
//
// The bytePacking parameter is required to know how to interpret the bit ordering within the bytes.
func NewBitVector(buf []byte, bytePacking BitNumbering) *BitVector {
return &BitVector{
BytePacking: bytePacking,
Buf: buf,
Len: uint(len(buf) * 8),
}
}
// Push adds a single bit to the BitVector.
//
// Although it takes a byte, only the low-order bit is used, so just use 0 or 1.
func (v *BitVector) Push(val byte) {
if v.Len%8 == 0 {
v.Buf = append(v.Buf, 0)
}
lastIdx := v.Len / 8
switch v.BytePacking {
case LSB0:
v.Buf[lastIdx] |= (val & 1) << (v.Len % 8)
default:
v.Buf[lastIdx] |= (val & 1) << (7 - (v.Len % 8))
}
v.Len++
}
// Get returns a single bit as a byte -- either 0 or 1
func (v *BitVector) Get(idx uint) (byte, error) {
if idx >= v.Len {
return 0, ErrOutOfRange
}
blockIdx := idx / 8
switch v.BytePacking {
case LSB0:
return v.Buf[blockIdx] >> (idx % 8) & 1, nil
default:
return v.Buf[blockIdx] >> (7 - idx%8) & 1, nil
}
}
// Extend adds up to 8 bits to the receiver
//
// Given a byte b == 0b11010101
// v.Extend(b, 4, LSB0) would add < 1, 0, 1, 0 >
// v.Extend(b, 4, MSB0) would add < 1, 1, 0, 1 >
//
// Panics if count is out of range
func (v *BitVector) Extend(val byte, count uint, order BitNumbering) {
if count > 8 {
log.Panicf("invalid count")
}
for i := uint(0); i < count; i++ {
switch order {
case LSB0:
v.Push((val >> i) & 1)
default:
v.Push((val >> (7 - i)) & 1)
}
}
}
// Take reads up to 8 bits at the given index.
//
// Given a BitVector < 1, 1, 0, 1, 0, 1, 0, 1 >
// v.Take(0, 4, LSB0) would return 0b00001011
// v.Take(0, 4, MSB0) would return 0b11010000
//
// Panics if count is out of range
func (v *BitVector) Take(index uint, count uint, order BitNumbering) (out byte) {
if count > 8 {
log.Panicf("invalid count")
}
for i := uint(0); i < count; i++ {
val, _ := v.Get(index + i)
switch order {
case LSB0:
out |= val << i
default:
out |= val << (7 - i)
}
}
return
}
// Iterator returns a function, which when invoked, returns the number
// of bits requested, and increments an internal cursor.
//
// When the end of the BitVector is reached, it returns zeroes indefinitely
//
// Panics if count is out of range
func (v *BitVector) Iterator(order BitNumbering) func(uint) byte {
cursor := uint(0)
return func(count uint) (out byte) {
if count > 8 {
log.Panicf("invalid count")
}
out = v.Take(cursor, count, order)
cursor += count
return
}
}
-136
View File
@@ -1,136 +0,0 @@
package bitvector_test
import (
"testing"
"github.com/stretchr/testify/assert"
bitvector "github.com/filecoin-project/lotus/extern/rleplus/internal"
)
func TestBitVector(t *testing.T) {
t.Run("zero value", func(t *testing.T) {
var v bitvector.BitVector
assert.Equal(t, bitvector.LSB0, v.BytePacking)
})
t.Run("Push", func(t *testing.T) {
// MSB0 bit numbering
v := bitvector.BitVector{BytePacking: bitvector.MSB0}
v.Push(1)
v.Push(0)
v.Push(1)
v.Push(1)
assert.Equal(t, byte(176), v.Buf[0])
// LSB0 bit numbering
v = bitvector.BitVector{BytePacking: bitvector.LSB0}
v.Push(1)
v.Push(0)
v.Push(1)
v.Push(1)
assert.Equal(t, byte(13), v.Buf[0])
})
t.Run("Get", func(t *testing.T) {
bits := []byte{1, 0, 1, 1, 0, 0, 1, 0}
for _, numbering := range []bitvector.BitNumbering{bitvector.MSB0, bitvector.LSB0} {
v := bitvector.BitVector{BytePacking: numbering}
for _, bit := range bits {
v.Push(bit)
}
for idx, expected := range bits {
actual, _ := v.Get(uint(idx))
assert.Equal(t, expected, actual)
}
}
})
t.Run("Extend", func(t *testing.T) {
val := byte(171) // 0b10101011
var v bitvector.BitVector
// MSB0 bit numbering
v = bitvector.BitVector{}
v.Extend(val, 4, bitvector.MSB0)
assertBitVector(t, []byte{1, 0, 1, 0}, v)
v.Extend(val, 5, bitvector.MSB0)
assertBitVector(t, []byte{1, 0, 1, 0, 1, 0, 1, 0, 1}, v)
// LSB0 bit numbering
v = bitvector.BitVector{}
v.Extend(val, 4, bitvector.LSB0)
assertBitVector(t, []byte{1, 1, 0, 1}, v)
v.Extend(val, 5, bitvector.LSB0)
assertBitVector(t, []byte{1, 1, 0, 1, 1, 1, 0, 1, 0}, v)
})
t.Run("invalid counts to Take/Extend/Iterator cause panics", func(t *testing.T) {
v := bitvector.BitVector{BytePacking: bitvector.LSB0}
assert.Panics(t, func() { v.Extend(0xff, 9, bitvector.LSB0) })
assert.Panics(t, func() { v.Take(0, 9, bitvector.LSB0) })
next := v.Iterator(bitvector.LSB0)
assert.Panics(t, func() { next(9) })
})
t.Run("Take", func(t *testing.T) {
var v bitvector.BitVector
bits := []byte{1, 0, 1, 0, 1, 0, 1, 1}
for _, bit := range bits {
v.Push(bit)
}
assert.Equal(t, byte(176), v.Take(4, 4, bitvector.MSB0))
assert.Equal(t, byte(13), v.Take(4, 4, bitvector.LSB0))
})
t.Run("Iterator", func(t *testing.T) {
var buf []byte
// make a bitvector of 256 sample bits
for i := 0; i < 32; i++ {
buf = append(buf, 128+32)
}
v := bitvector.NewBitVector(buf, bitvector.LSB0)
next := v.Iterator(bitvector.LSB0)
// compare to Get()
for i := uint(0); i < v.Len; i++ {
expected, _ := v.Get(i)
assert.Equal(t, expected, next(1))
}
// out of range should return zero
assert.Equal(t, byte(0), next(1))
assert.Equal(t, byte(0), next(8))
// compare to Take()
next = v.Iterator(bitvector.LSB0)
assert.Equal(t, next(5), v.Take(0, 5, bitvector.LSB0))
assert.Equal(t, next(8), v.Take(5, 8, bitvector.LSB0))
})
}
// Note: When using this helper assertion, expectedBits should *only* be 0s and 1s.
func assertBitVector(t *testing.T, expectedBits []byte, actual bitvector.BitVector) {
assert.Equal(t, uint(len(expectedBits)), actual.Len)
for idx, bit := range expectedBits {
actualBit, err := actual.Get(uint(idx))
assert.NoError(t, err)
assert.Equal(t, bit, actualBit)
}
}
-204
View File
@@ -1,204 +0,0 @@
package rleplus
import (
"encoding/binary"
"errors"
"fmt"
"sort"
bitvector "github.com/filecoin-project/lotus/extern/rleplus/internal"
)
// Version is the 2 lowest bits of this constant
const Version = 0
var (
// ErrRunLengthTooLarge - data implies a run-length which isn't supported
ErrRunLengthTooLarge = fmt.Errorf("run length too large for RLE+ version %d", Version)
// ErrDecode - invalid encoding for this version
ErrDecode = fmt.Errorf("invalid encoding for RLE+ version %d", Version)
// ErrWrongVersion - wrong version of RLE+
ErrWrongVersion = errors.New("invalid RLE+ version")
)
// Encode returns the RLE+ representation of the provided integers.
// Also returned is the number of bits required by this encoding,
// which is not necessarily on a byte boundary.
//
// The RLE+ spec is here: https://github.com/filecoin-project/specs/blob/master/data-structures.md#rle-bitset-encoding
// and is described by the BNF Grammar:
//
// <encoding> ::= <header> <blocks>
// <header> ::= <version> <bit>
// <version> ::= "00"
// <blocks> ::= <block> <blocks> | ""
// <block> ::= <block_single> | <block_short> | <block_long>
// <block_single> ::= "1"
// <block_short> ::= "01" <bit> <bit> <bit> <bit>
// <block_long> ::= "00" <unsigned_varint>
// <bit> ::= "0" | "1"
//
// Filecoin specific:
// The encoding is returned as a []byte, each byte packed starting with the low-order bit (LSB0)
func Encode(ints []uint64) ([]byte, uint, error) {
v := bitvector.BitVector{BytePacking: bitvector.LSB0}
firstBit, runs := RunLengths(ints)
// Add version header
v.Extend(Version, 2, bitvector.LSB0)
v.Push(firstBit)
for _, run := range runs {
switch {
case run == 1:
v.Push(1)
case run < 16:
v.Push(0)
v.Push(1)
v.Extend(byte(run), 4, bitvector.LSB0)
case run >= 16:
v.Push(0)
v.Push(0)
// 10 bytes needed to encode MaxUint64
buf := make([]byte, 10)
numBytes := binary.PutUvarint(buf, run)
for i := 0; i < numBytes; i++ {
v.Extend(buf[i], 8, bitvector.LSB0)
}
default:
return nil, 0, ErrRunLengthTooLarge
}
}
return v.Buf, v.Len, nil
}
// Decode returns integers represented by the given RLE+ encoding
//
// The length of the encoding is not specified. It is inferred by
// reading zeroes from the (possibly depleted) BitVector, by virtue
// of the behavior of BitVector.Take() returning 0 when the end of
// the BitVector has been reached. This has the downside of not
// being able to detect corrupt encodings.
//
// The passed []byte should be packed in LSB0 bit numbering
func Decode(buf []byte) (ints []uint64, err error) {
if len(buf) == 0 {
return
}
v := bitvector.NewBitVector(buf, bitvector.LSB0)
take := v.Iterator(bitvector.LSB0)
// Read version and check
// Version check
ver := take(2)
if ver != Version {
return nil, ErrWrongVersion
}
curIdx := uint64(0)
curBit := take(1)
var runLength int
done := false
for done == false {
y := take(1)
switch y {
case 1:
runLength = 1
case 0:
val := take(1)
if val == 1 {
// short block
runLength = int(take(4))
} else {
// long block
var buf []byte
for {
b := take(8)
buf = append(buf, b)
if b&0x80 == 0 {
break
}
// 10 bytes is required to store math.MaxUint64 in a uvarint
if len(buf) > 10 {
return nil, ErrDecode
}
}
x, _ := binary.Uvarint(buf)
if x == 0 {
done = true
}
runLength = int(x)
}
}
if curBit == 1 {
for j := 0; j < runLength; j++ {
ints = append(ints, curIdx+uint64(j))
}
}
curIdx += uint64(runLength)
curBit = 1 - curBit
}
return
}
// RunLengths transforms integers into its bit-set-run-length representation.
//
// A set of unsigned integers { 0, 2, 4, 5, 6 } can be thought of as
// indices into a bitset { 1, 0, 1, 0, 1, 1, 1 } where bitset[index] == 1.
//
// The bit set run lengths of this set would then be { 1, 1, 1, 1, 3 },
// representing lengths of runs alternating between 1 and 0, starting
// with a first bit of 1.
//
// Duplicated numbers are ignored.
//
// This is a helper function for Encode()
func RunLengths(ints []uint64) (firstBit byte, runs []uint64) {
if len(ints) == 0 {
return
}
// Sort our incoming numbers
sort.Slice(ints, func(i, j int) bool { return ints[i] < ints[j] })
prev := ints[0]
// Initialize our return value
if prev == 0 {
firstBit = 1
}
if firstBit == 0 {
// first run of zeroes
runs = append(runs, prev)
}
runs = append(runs, 1)
for _, cur := range ints[1:] {
delta := cur - prev
switch {
case delta == 1:
runs[len(runs)-1]++
case delta > 1:
// add run of zeroes if there is a gap
runs = append(runs, delta-1)
runs = append(runs, 1)
default:
// repeated number?
}
prev = cur
}
return
}

Some files were not shown because too many files have changed in this diff Show More