From 77145372395544e24fe4431f16e69e38503c77f2 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 14 May 2021 21:11:23 -0400 Subject: [PATCH] Allow starting networks from arbitrary actor versions --- build/openrpc/full.json.gz | Bin 23308 -> 23305 bytes build/params_2k.go | 20 +- build/params_shared_vals.go | 2 +- chain/actors/adt/temp | 0 chain/actors/aerrors/temp | 0 chain/actors/agen/main.go | 72 ++-- chain/actors/agen/temp | 0 chain/actors/builtin/account/account.go | 41 +++ .../actors/builtin/account/actor.go.template | 23 ++ .../actors/builtin/account/state.go.template | 10 + chain/actors/builtin/account/temp | 0 chain/actors/builtin/account/v0.go | 10 + chain/actors/builtin/account/v2.go | 10 + chain/actors/builtin/account/v3.go | 10 + chain/actors/builtin/account/v4.go | 10 + chain/actors/builtin/builtin.go.template | 94 ++--- chain/actors/builtin/cron/actor.go.template | 34 +- chain/actors/builtin/cron/cron.go | 54 +++ chain/actors/builtin/cron/state.go.template | 35 ++ chain/actors/builtin/cron/temp | 0 chain/actors/builtin/cron/v0.go | 35 ++ chain/actors/builtin/cron/v2.go | 35 ++ chain/actors/builtin/cron/v3.go | 35 ++ chain/actors/builtin/cron/v4.go | 35 ++ chain/actors/builtin/init/actor.go.template | 31 +- chain/actors/builtin/init/diff.go | 4 +- chain/actors/builtin/init/init.go | 49 ++- chain/actors/builtin/init/state.go.template | 38 +- chain/actors/builtin/init/temp | 0 chain/actors/builtin/init/v0.go | 31 +- chain/actors/builtin/init/v2.go | 31 +- chain/actors/builtin/init/v3.go | 31 +- chain/actors/builtin/init/v4.go | 31 +- chain/actors/builtin/market/actor.go.template | 80 +++-- chain/actors/builtin/market/market.go | 42 ++- chain/actors/builtin/market/state.go.template | 29 ++ chain/actors/builtin/market/temp | 0 chain/actors/builtin/market/v0.go | 22 ++ chain/actors/builtin/market/v2.go | 22 ++ chain/actors/builtin/market/v3.go | 17 + chain/actors/builtin/market/v4.go | 17 + chain/actors/builtin/miner/actor.go.template | 86 +++-- chain/actors/builtin/miner/miner.go | 46 +++ chain/actors/builtin/miner/state.go.template | 101 ++++-- chain/actors/builtin/miner/temp | 0 chain/actors/builtin/miner/v0.go | 21 ++ chain/actors/builtin/miner/v2.go | 51 +++ chain/actors/builtin/miner/v3.go | 51 +++ chain/actors/builtin/miner/v4.go | 51 +++ .../actors/builtin/multisig/actor.go.template | 24 +- .../builtin/multisig/message.go.template | 36 +- chain/actors/builtin/multisig/multisig.go | 40 +++ .../actors/builtin/multisig/state.go.template | 30 ++ chain/actors/builtin/multisig/temp | 0 chain/actors/builtin/multisig/v0.go | 23 ++ chain/actors/builtin/multisig/v2.go | 23 ++ chain/actors/builtin/multisig/v3.go | 23 ++ chain/actors/builtin/multisig/v4.go | 23 ++ chain/actors/builtin/paych/actor.go.template | 23 ++ .../actors/builtin/paych/message.go.template | 28 +- chain/actors/builtin/paych/mock/mock.go | 4 + chain/actors/builtin/paych/mock/temp | 0 chain/actors/builtin/paych/paych.go | 41 +++ chain/actors/builtin/paych/state.go.template | 10 + chain/actors/builtin/paych/temp | 0 chain/actors/builtin/paych/v0.go | 10 + chain/actors/builtin/paych/v2.go | 10 + chain/actors/builtin/paych/v3.go | 10 + chain/actors/builtin/paych/v4.go | 10 + chain/actors/builtin/power/actor.go.template | 31 +- chain/actors/builtin/power/power.go | 47 +++ chain/actors/builtin/power/state.go.template | 60 +++- chain/actors/builtin/power/temp | 0 chain/actors/builtin/power/v0.go | 42 +++ chain/actors/builtin/power/v2.go | 42 +++ chain/actors/builtin/power/v3.go | 37 ++ chain/actors/builtin/power/v4.go | 37 ++ chain/actors/builtin/reward/actor.go.template | 23 ++ chain/actors/builtin/reward/reward.go | 41 +++ chain/actors/builtin/reward/state.go.template | 10 + chain/actors/builtin/reward/temp | 0 chain/actors/builtin/reward/v0.go | 10 + chain/actors/builtin/reward/v2.go | 10 + chain/actors/builtin/reward/v3.go | 10 + chain/actors/builtin/reward/v4.go | 10 + chain/actors/builtin/system/actor.go.template | 41 +++ chain/actors/builtin/system/state.go.template | 35 ++ chain/actors/builtin/system/system.go | 63 ++++ chain/actors/builtin/system/temp | 0 chain/actors/builtin/system/v0.go | 35 ++ chain/actors/builtin/system/v2.go | 35 ++ chain/actors/builtin/system/v3.go | 35 ++ chain/actors/builtin/system/v4.go | 35 ++ chain/actors/builtin/temp | 0 .../actors/builtin/verifreg/actor.go.template | 24 ++ .../actors/builtin/verifreg/state.go.template | 26 +- chain/actors/builtin/verifreg/temp | 0 chain/actors/builtin/verifreg/v0.go | 17 + chain/actors/builtin/verifreg/v2.go | 17 + chain/actors/builtin/verifreg/v3.go | 17 + chain/actors/builtin/verifreg/v4.go | 17 + chain/actors/builtin/verifreg/verifreg.go | 41 +++ chain/actors/policy/policy.go.template | 164 ++++----- chain/actors/policy/temp | 0 chain/actors/temp | 0 chain/actors/version.go | 4 + chain/gen/gen.go | 3 + chain/gen/genesis/f00_system.go | 21 +- chain/gen/genesis/f01_init.go | 40 ++- chain/gen/genesis/f02_reward.go | 33 +- chain/gen/genesis/f03_cron.go | 34 +- chain/gen/genesis/f04_power.go | 31 +- chain/gen/genesis/f05_market.go | 30 +- chain/gen/genesis/f06_vreg.go | 25 +- chain/gen/genesis/genesis.go | 242 +++++++------ chain/gen/genesis/miners.go | 335 ++++++++++++++---- chain/gen/genesis/util.go | 29 -- chain/state/statetree.go | 17 +- chain/state/statetree_test.go | 48 ++- chain/vm/vm.go | 35 +- cmd/lotus-seed/genesis.go | 51 +++ cmd/lotus-seed/main.go | 7 +- documentation/en/api-v0-methods.md | 2 +- documentation/en/api-v1-unstable-methods.md | 2 +- genesis/types.go | 7 +- node/test/builder.go | 4 + 126 files changed, 3174 insertions(+), 653 deletions(-) create mode 100644 chain/actors/adt/temp create mode 100644 chain/actors/aerrors/temp create mode 100644 chain/actors/agen/temp create mode 100644 chain/actors/builtin/account/temp create mode 100644 chain/actors/builtin/cron/state.go.template create mode 100644 chain/actors/builtin/cron/temp create mode 100644 chain/actors/builtin/cron/v0.go create mode 100644 chain/actors/builtin/cron/v2.go create mode 100644 chain/actors/builtin/cron/v3.go create mode 100644 chain/actors/builtin/cron/v4.go create mode 100644 chain/actors/builtin/init/temp create mode 100644 chain/actors/builtin/market/temp create mode 100644 chain/actors/builtin/miner/temp create mode 100644 chain/actors/builtin/multisig/temp create mode 100644 chain/actors/builtin/paych/mock/temp create mode 100644 chain/actors/builtin/paych/temp create mode 100644 chain/actors/builtin/power/temp create mode 100644 chain/actors/builtin/reward/temp create mode 100644 chain/actors/builtin/system/actor.go.template create mode 100644 chain/actors/builtin/system/state.go.template create mode 100644 chain/actors/builtin/system/system.go create mode 100644 chain/actors/builtin/system/temp create mode 100644 chain/actors/builtin/system/v0.go create mode 100644 chain/actors/builtin/system/v2.go create mode 100644 chain/actors/builtin/system/v3.go create mode 100644 chain/actors/builtin/system/v4.go create mode 100644 chain/actors/builtin/temp create mode 100644 chain/actors/builtin/verifreg/temp create mode 100644 chain/actors/policy/temp create mode 100644 chain/actors/temp diff --git a/build/openrpc/full.json.gz b/build/openrpc/full.json.gz index 4d9fb5284d1c6ed52d84f50d11610f338e15b4bf..394f1998be7c464c835d2474d93a843971cb659d 100644 GIT binary patch delta 4808 zcmV;(5;yIPwgHK@0k958e@6HFt}99*UNu>dP67Kmk5MP$kXB#N|8CFZHxhOXE#Iw$ zCNnKQ6FMikiic(IQbd+zo~oSdh*t|Axop3d^#z4@Hu}jVCxywm$9!1gy$X|~tZkOP zbWE-D<(c8P6jz#4sp++O-1p2jcAD%^>Waj)E0LCUEs>j|&>r#Ee-4N*Df1D%V&17b z0G6cLbY?}DWmy!de|VNa3^>Ol=p)Q|JRx+1h(Onvr>aP8YZ?U1yDWzT(U@-Sf?m+0 zA;RW2x`e4@`k~HH==YUf3hTZ-*@x*>781d^15&^-e2<5z(=`-U;D&I2gH0kWdcpG z@W!gRe5{zE`8@f|!$ANMx>kwN1w%l29GUzvaDzP&OifpRf5pJnUHIIGzzuk@0AEl0 z6n*-7cCP(4bPE;ZA{@bAF%D#BY3>KPPY#H`c0s=pG1fY9!c9v9CdM;kkQ2)yG9nZQ z>3}A9DwhOsgfPFLJoY@`d>9A8G#zL<(S3A1Cf-<8k}HM+atR0{pT&a!Uh)vAulD6$ z^|r&gl@eoFe~}D_5J~EJaC9h_ekz6V518x3uUzeh3z`+538zpALvZ~sw04j5Mre9{znd6O_U6@Nr0$j`md zH^qQr2lki5)y9HkKq|sm-7re=$HjT@~+l- z{xutGT`l36-8NUojauxdjB!~m?^o+I7YQ5eH1Sm*n6bNz2$l|2Re!}C^lGJ@%)zJ* z$0nJnwx=M)hV8VQMJU(0+Z6S+&h1fwE!#)G)F88My&N80JT#gk#*P>-lNcLGyX7f< z+(i7*nNynF%Fh5t-dK{AP8OB4dIzJ5@*>9rvZkC!RWOD=3b)aKu|Nf><)dT9F5}S3 z+>#$j-gR6y*#|BF_T_j8S&nmJI7%72Z4b@>ab6^Mxw9VDW5 z@}M-{wOcc&Okytb29@%Z)Y?bg4;%#S+C*^k|HzCCva+HEYp861(Yr_4 zCuSPBpsHzx6uohV8fU0+h8kz6S;pm5rRDT z%F58SYzvFwxqsbt{kq^Gcv@+p3EtB7^0G)-zxUDH%IFeR>|=VPW4>U~SP4{Q?ou%BBtd6o-v6WkhU{kmanDt~Su$6{qdF6MuW-5H? z@Ss>2RI8onOaulch=8o~RP$rG;5PTox$e#_yZT&~F@H;KIjgko^qfqx0Hp756imA@ zWmDBE;-%^I>4k@Q({#a2FX0CemG`z=@C(z#Z8M9u!69Y`*NRn`YK2QLsZ+3u6)`V; z#u_>`b!i*~h|tVWIEkJnn<05GXRX#t-H2s@wH(u$;Hh#U9st6g7e`otY*)p(mW}g1 ziaAuXa(^Tk8i7bFUQo#1DK6-Eoa1p%h{rVrtym~z#n0-bFZrA>OHTnalk6oQ`66Mp z<@_)CXa&mKuqup!dNC8aK|QMoL{WG?6J4UW-s=)8%7yQ!ZNi1`Snco~4;eVVZMye7 zn`>wR=$JNg+u-q-d2RI!`LVUaj%h_SB-H0=T7QvW(@fmjXjMdyPde$E17S}SgeAwa z8G+?W*}$)2&bmUHy7uYlTI6tRm3{4zag5FNrW@GR*%Z5TjeJA5z&R>YKz36<%nr33 zBgt1Ts3OugcDe}1RUB7&++1bek+nMoFz`9I!MorxmJ~UaC=!z#8p-KCYk7}xRYxa^n6UX zq@?ndaur4qge(%;VN>}%$5fCBAR@;x#D5+j!F0enjy&csF|~9 z0VK^`(5$5=sc>;@u!SCc_HdMS;1wk-R)77L7Jfyk<7ShOTS5^|VMMryrl*XVjky4U zoN25@Soc|~*@7CDJDrEe=Mh6Qntud?C*@Jn(=QxFjHy_g4kzD7l=l+pUv<{7q7-7Q z$(g}y`)CQsDY|#e6m>vLk;6$2C#^6UbU0}_RB*e=K>rOB(K(`rsa!|*ve+G)C?-_w zY%e#AN7j9dAReYt=MWxiCLpW52z`l&d^PVtS6A>E)d(1{K?EPz>h^YH-OB8K(K5 zBm$n`NHTvcg(5#mnPfr`_J0#4kxro$0p^S@Plw|$)QaV4F%8VlZTi?k$x=w!@W}E9 zZ@#KC%qPbzWQ3M8+*p$cRo&XWq|>R*BN0iP7DPf7RRn=2B!WxA;H59Y@1qG|nkI0Q zbb`@e1cEDw{qFk%x#gmbvM4-M+)I4Jufnuj^!nu-8H@PEM13bV=o-|Z{)XO=xy*SePPi>zy%5OCt>TDxEma25|HMC?oc-i=aa_3Plt3yqmonNNIV0aJ>NHba$MS%2hViUxpU$(sd3T)jdV zQMeAK$csQ3IUAfDFgo-I1(1WI04(b7+bfup2oqG++_pN*3Lp3h0{ba6VzL zOp#gyJbzDmyLOd|otp4?bMtM3#qKMe;OKHM2)ddF@(olf4d)8nGcD9h+xdbhjH3}K zlYo(_J?xF4k0$t1?s+0m$T%m1K*c{$szbrFr!Yrh1XqN`JeU?u{|jpspW5EqT5qsA z>GfJ{V=cw3dccwoPRhVYeN*mBTSsl$=RG9&4J&jyH_}+ z-tXoFoU3RxolbqR3Hw{d1I7Xyn^dX&W_nO8p4-XSV^E&>h1(A%fi2;h79bWO%7kcSh?owi~l)vg*X!*0|x+;q%}g)5_MWWtrN3n#ZDuT=|+dvUmM5lh;&TQxd@ zWT^w_;7ydTY|R=PrMa0F=WzmE5c%pK9e;_@>`djG+jS>CcnbgIq?YX(HHF?L?`}dC zwU<}&mFf zH#_fCf5f~-^-z>!$kRU4PUbHihn+^5|7fxR-_w=n_+1(T+EpG&`2P)_c zMk#+ybkJT9`|3@OA)2e6sxn6^v5bjmvg`xo7>Wx9c#mYDQ73Uscvm7It5)kDzW?ZS z;!T51XI&OS0pWtHh&VZY11!Y5P?8Lm6-&d+e&Y(e@BrsvA+*o{5u_UG}Y&v0$r|GB;nP%VIE=`l5^<76bq zwst}Ht}qEyC`l>9sgduZLBRWngBNbT+PU1w{rOVms*Nt_SsW^+IAjr`@qYv&;^82v zzJXrmYj2{LX#e<3BFJouEZJ~nCfklmOP;q(JFR0SOFFA>8Z{|rsam+>kb&!s6*gCpD-1^Je=63iDaq&(6RWJ;W^_8lFndcXz02=Fc(`V>+R2drIcsrXRD|mg(a0r0YEzz3JM1iP?Xxt0kNL_ION# zVX{Cs>rU@%p_aj2pTKeM_cD-Uc}4yHs7Y>V91U_bs3Q%^-yqEI{gnmgk2RF;c3lc( z4O)|{1&g_Y&a_eo+4b^t)pM6SnWuk4o2ilBjmo?iaH8hcu~JR+93MR9YmZTkt|16s znhQo|+)G32cOK5wDWz}mq}3&hHJcG4GHjpzFkiX7dQPSLDQQ|-IR~X(=TrPNo;p_cI_ja&nKd8C$b4>J)UuasPryME2USOR0i_QzuRZPRX(6GzDlk^J{2Snq}9^~ iHs;oFN6osE7n$w^^y?lB*hc(20bC~KQ# zFCA0se0gU0Eyb1QRBC!{9``-7jh!Ytl)54@?MkF&T}$MqD6~iXf3*YROUisiub6kL z4uBK~pZ5ChKf2>J+f9#04zAtKN<=BX-D+nNRe^DfKbKs2UXyPy~J zXo#@+jV@s-nSQ7<6#9K-m%_SlPxfJYm4${Zraod6d1Fjy|ANXMCLqSlN7p1sE~Oz% z^^72nr`mhUpv$DKe{0O?FG9Cx21Hryh-6J1%5xYI$*fE{!coB3CHN=~^{~k>8B*E} z8e#r2f-oXp(iEdF)%dewa_9pv^9??Fi3pV~sk|;6jQ5xPH1JVw;nzO#(E%~vPMJUx zEWEKQE*~pqXg*Iq^KcMAgsxR$bioi%9!DmB4BTK(1XI)1e_t_hbr(MOA#ej;EWp>( zK1H9to}FvI4c$V;xClq^SBwMMS(^Jn?vn%JuU*h@M2xjgoN&|9fQj+U805sVh>Qru zK{}ubp2{Tw93jjvD33i4I3LDAFii)VPIMn#kBK){mE?+{fLsE?$Y=2&fR{W3>Z^UZ zSH10UZl%One^w;JAw-gT9vmIYrJqV6`~&7X@hexm;euwxI2lna0ZShZVquyI0>s1^ zBE3!^AmVxfW%tiGiz5$y^??gQl_sozK`B$|^EJxpBM{!&b0;O;GSFy5XNDrr7keuC zZLuwRWF)Bo4)TOz#32~I)MW;8Q+TEg17Ib=Od?Xu7#ARjjK4E-zpK2`8jpU!{FqFLP&a=+VE!K9 z0EgMjf0GC%B%YWDpA?tu?QZmYCx#gG{!N4R|D5fQJ^J5c_}72^mjt<0cZUaq(1+1g zv_-Z(#^G9wr+oD4=JF=|Ye+Y*hu+^ildH|~gk6g3fq!#}Z??IDfuH#3)KiP|?uH1B zK-c@dQ^m@v2k-&&uPQ3^+ke!L1IASYpELztf8IKz9jWQr#~j`R?CWvKCtt20ddCIP z3G#C<^i46KSUC`6kIqRl`KK_9Y0|Qa9-+TNN8Wg+*b`y&Ji;2tyDeeACEiI~S5CBk z7$?@Eo%QrTy@AF!8fCHA&*FiELFRYM2HRdZkK35A%s?svcb9j}Jq#j0mA0|hiz87M ze}Sr|y^-DE^evBjVKF?nyRKgsJOocGEi}Pf+Fo83DeLz>np+uNqKbV?Z*Jr3lVGzw*j-BECsgG@GP(V z&elwYFC88f3xjI46P<~`f1m^rkaeDFek>Q<=Ds=C-MM8~pUX04sV!%fww<1nNfvPZ=T1C7xoj$$r5O10;xalSQ0HX5Vb_;%Cnz(Id(Ka~5?BH6l3RA6c=_Pdv zRU2`Dp zX@aoiST-ZDTqzs)Rm@peNK@B79bJnYZmqJfJu;55x!!aGyE>aWA5(wqqpu$^}(K`o>Nd;kb(9Dvz71%saAnXqf4)+#!YG1}MM67lD!=EL3Nisiw|y*74lKsG1*5|OACf3 zRRXv%Q?YA^?6^?%I4ok~Rn;se_{IVw4`)}MG)qao=7Od!8zewP@uo=KTA>U9711=g z!jv{7@F0MsxeJ=L^duE7jt#cZgU=q0vJSkWgvIKw-_pXbD0SRy@^MQj!YPah7t!>T zF|#oje;|-EjkO5tK1(%QP{VSk^YHjQVrWK_VDO|oN_zT*qlhsTYt!N6`-t*hBK@n* z8dj7-Y&AJEm~9^|0XaqYj+vqkXen|y$>F3GCW8(qEr$wjHyP-^VIn$5^e~m{=w24P zV-v-MikCqtiK))-V@kaPiOlw~-(F(MRh}a;Jx9;<^3D~5ifuM1hI0iq zf4Jm`4AXp25&=(eB$+>!LXn@OOfn$|`-zfBr%;Ljb4Hh^!*LjD#qzY624?3reQcp* zDWq(8WchD1Zg1{3J!6jkv(wE@( z(F8C}6Szq_!RRjn!4*XE{9Gb@ji+cBf3XQ7!Z}>shX(a?9F%<#&BGjVO+|npc;M%9 zr_LlirQRnTb>`cq?p(G#_atTwH6KG$uHpnf47liS>0Ob2)1Xf{iw6@T_9cJse@3aY`gQQ+g~rUP%qKpwfGNdBo1sdsEb=f#13=bU1nlcO zTq>DRKE>lX@hwtnkq^?=*Em^ z2uU|Mwb1BKnaPK?3@nj9a1UYnOH81}pfeWHao`!l={EQoYGngaJD_6T-i&9Ma_gJX zMN-?XdIf`PH~0z$+@*o8Ar4Z&@WeSlhU4z;NLC%P9HOu}G(`;9e~p|M8n6g)C5!G) z1$0ezIG?arrbsOUo+rIsyGq4QO?bSy`L@Ag_mxg?bh#GU)E5c$POpB)fg|&)L zZEtO@H&~tYdM&oGf0kl-$~V=l&`C?8nAX{!DmU0bh2tPTP8^W6AqwFUCeG&MY)+5n zz;D#uE1XjAcXI;HRkWH;r@q*P{Vn4GV}XrLs?>fnJt!8>?d0n*C{O&t?FW;{UIvn>E(rZ#W1*?Bf7auf4^%e^A@<7VvZQ%vdGJ=!lAW z=XSP>`XgH?S+FY)%rj$9E?n(RLTx3s=P_VE4bnAUD*s-&8@p9!C%-l|L@0gfuAG*R zS&hL{@6AIP;y4g>;SKCgTd|R9SB;ioH)rj>Kqort;10x)UEfg@1BV%XW>L zLT{6IHzAAK%PaZH_Q=OLWc&tGo2dFTeazeNx?q78hY`8L0?;L>JIA>*umCN7@F$?S z3UyvH*=rl8nR63eI^Zhix0-e-r&YN^wDVlZH@2t|f49ao@ksdCs~Yu$J{})&SIG4d z+lDx@R7T{Rop-7~VqT+qD9SP9X`g8)^OugpPNU3!G+BV}>B@8bE)45c;lQ<^4D-n=Y ztMw1xe}8m3@utD1vo4FEfN;T8M4X(y0T$waRXecs6{UHqDlvZ-N|EYEKk?}JZso(2 z+lx6qr5z+5_V#?;sC@Vg*By7~XSi;*ApHi@b7gky#-4Qh^LW!|xHj(pTwe#M7QnLf zm>Se^GLmCkyP$hlm;@@6q?F;*$am2o;C;lwe+xHX?Obl;{(Px&)kYWeEDjY@9I^<} zcmfgeaFA5rKri#PH_=P9e|#npWVS_?Y`8L$ZAYag&s(OQ*0GW$oz*vunv}CtE!^?Q zW(_P;VOVH&-g(Umn=8l_1|#)973{B^>-BpOW(!)fcY_*5Pb#s1Lp4m4se*gJc(dJ;)!|iNyT#R?dn^*Y6+@BMOJ2* z9g{IjEPuU!+GaRYU)}ZwQtrDuR5kNw8Hq8S(6&7#b8pj+S!~O6@p#hp9*y2~ZNJ3q zzt+`~&3=14rok{-pqq84ceYT=;I2>LIQM%Q$g#Ylet*;?w=|9hIU3ZF2IX%M=J)=} z0`tcjN_V?1g|Y^%$<>0zTtR1Ase|l#dAjPk%YU8B)1l4ONbg2v-U~QUbL&{CCVGw! z9`m)wC`Q*11TW16BQx%$q4hft=jxQww|LU(lEs?M2oV{!Pk)%N++IDW(*2Y)Ev=k` z(ysF1hgK{xIk2T7p0ZbD@`f`dFJ2kGvF#8&=_AO s*C!yKiU-o_X#*Q`YdEE!^D0{wxmDR`fBf_R0ssL2{{xC7k>8sH07~LgPyhe` diff --git a/build/params_2k.go b/build/params_2k.go index 32b010c32..3dd68c9c6 100644 --- a/build/params_2k.go +++ b/build/params_2k.go @@ -24,20 +24,20 @@ var UpgradeIgnitionHeight = abi.ChainEpoch(-2) var UpgradeRefuelHeight = abi.ChainEpoch(-3) var UpgradeTapeHeight = abi.ChainEpoch(-4) -var UpgradeActorsV2Height = abi.ChainEpoch(10) -var UpgradeLiftoffHeight = abi.ChainEpoch(-5) +var UpgradeActorsV2Height = abi.ChainEpoch(-5) +var UpgradeLiftoffHeight = abi.ChainEpoch(-6) -var UpgradeKumquatHeight = abi.ChainEpoch(15) -var UpgradeCalicoHeight = abi.ChainEpoch(20) -var UpgradePersianHeight = abi.ChainEpoch(25) -var UpgradeOrangeHeight = abi.ChainEpoch(27) -var UpgradeClausHeight = abi.ChainEpoch(30) +var UpgradeKumquatHeight = abi.ChainEpoch(-7) +var UpgradeCalicoHeight = abi.ChainEpoch(-8) +var UpgradePersianHeight = abi.ChainEpoch(-9) +var UpgradeOrangeHeight = abi.ChainEpoch(-10) +var UpgradeClausHeight = abi.ChainEpoch(-11) -var UpgradeActorsV3Height = abi.ChainEpoch(35) +var UpgradeActorsV3Height = abi.ChainEpoch(-12) -var UpgradeNorwegianHeight = abi.ChainEpoch(40) +var UpgradeNorwegianHeight = abi.ChainEpoch(-13) -var UpgradeActorsV4Height = abi.ChainEpoch(45) +var UpgradeActorsV4Height = abi.ChainEpoch(-14) var DrandSchedule = map[abi.ChainEpoch]DrandEnum{ 0: DrandMainnet, diff --git a/build/params_shared_vals.go b/build/params_shared_vals.go index 92bbc5db9..6b98b6a9c 100644 --- a/build/params_shared_vals.go +++ b/build/params_shared_vals.go @@ -25,7 +25,7 @@ const UnixfsLinksPerLevel = 1024 // Consensus / Network const AllowableClockDriftSecs = uint64(1) -const NewestNetworkVersion = network.Version11 +const NewestNetworkVersion = network.Version12 const ActorUpgradeNetworkVersion = network.Version4 // Epochs diff --git a/chain/actors/adt/temp b/chain/actors/adt/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/aerrors/temp b/chain/actors/aerrors/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/agen/main.go b/chain/actors/agen/main.go index 7269d9ae5..9a3b8fd20 100644 --- a/chain/actors/agen/main.go +++ b/chain/actors/agen/main.go @@ -6,33 +6,26 @@ import ( "io/ioutil" "os" "path/filepath" + "strconv" "text/template" + lotusactors "github.com/filecoin-project/lotus/chain/actors" + "golang.org/x/xerrors" ) -var latestVersion = 4 - -var versions = []int{0, 2, 3, latestVersion} - -var versionImports = map[int]string{ - 0: "/", - 2: "/v2/", - 3: "/v3/", - latestVersion: "/v4/", -} - var actors = map[string][]int{ - "account": versions, - "cron": versions, - "init": versions, - "market": versions, - "miner": versions, - "multisig": versions, - "paych": versions, - "power": versions, - "reward": versions, - "verifreg": versions, + "account": lotusactors.Versions, + "cron": lotusactors.Versions, + "init": lotusactors.Versions, + "market": lotusactors.Versions, + "miner": lotusactors.Versions, + "multisig": lotusactors.Versions, + "paych": lotusactors.Versions, + "power": lotusactors.Versions, + "system": lotusactors.Versions, + "reward": lotusactors.Versions, + "verifreg": lotusactors.Versions, } func main() { @@ -71,14 +64,14 @@ func generateAdapters() error { } tpl := template.Must(template.New("").Funcs(template.FuncMap{ - "import": func(v int) string { return versionImports[v] }, + "import": func(v int) string { return getVersionImports()[v] }, }).Parse(string(af))) var b bytes.Buffer err = tpl.Execute(&b, map[string]interface{}{ "versions": versions, - "latestVersion": latestVersion, + "latestVersion": lotusactors.LatestVersion, }) if err != nil { return err @@ -103,14 +96,14 @@ func generateState(actDir string) error { return xerrors.Errorf("loading state adapter template: %w", err) } - for _, version := range versions { + for _, version := range lotusactors.Versions { tpl := template.Must(template.New("").Funcs(template.FuncMap{}).Parse(string(af))) var b bytes.Buffer err := tpl.Execute(&b, map[string]interface{}{ "v": version, - "import": versionImports[version], + "import": getVersionImports()[version], }) if err != nil { return err @@ -134,14 +127,14 @@ func generateMessages(actDir string) error { return xerrors.Errorf("loading message adapter template: %w", err) } - for _, version := range versions { + for _, version := range lotusactors.Versions { tpl := template.Must(template.New("").Funcs(template.FuncMap{}).Parse(string(af))) var b bytes.Buffer err := tpl.Execute(&b, map[string]interface{}{ "v": version, - "import": versionImports[version], + "import": getVersionImports()[version], }) if err != nil { return err @@ -167,13 +160,13 @@ func generatePolicy(policyPath string) error { } tpl := template.Must(template.New("").Funcs(template.FuncMap{ - "import": func(v int) string { return versionImports[v] }, + "import": func(v int) string { return getVersionImports()[v] }, }).Parse(string(pf))) var b bytes.Buffer err = tpl.Execute(&b, map[string]interface{}{ - "versions": versions, - "latestVersion": latestVersion, + "versions": lotusactors.Versions, + "latestVersion": lotusactors.LatestVersion, }) if err != nil { return err @@ -198,13 +191,13 @@ func generateBuiltin(builtinPath string) error { } tpl := template.Must(template.New("").Funcs(template.FuncMap{ - "import": func(v int) string { return versionImports[v] }, + "import": func(v int) string { return getVersionImports()[v] }, }).Parse(string(bf))) var b bytes.Buffer err = tpl.Execute(&b, map[string]interface{}{ - "versions": versions, - "latestVersion": latestVersion, + "versions": lotusactors.Versions, + "latestVersion": lotusactors.LatestVersion, }) if err != nil { return err @@ -216,3 +209,16 @@ func generateBuiltin(builtinPath string) error { return nil } + +func getVersionImports() map[int]string { + versionImports := make(map[int]string, lotusactors.LatestVersion) + for _, v := range lotusactors.Versions { + if v == 0 { + versionImports[v] = "/" + } else { + versionImports[v] = "/v" + strconv.Itoa(v) + "/" + } + } + + return versionImports +} diff --git a/chain/actors/agen/temp b/chain/actors/agen/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/account/account.go b/chain/actors/builtin/account/account.go index 8242e300d..97811d08a 100644 --- a/chain/actors/builtin/account/account.go +++ b/chain/actors/builtin/account/account.go @@ -1,6 +1,7 @@ package account import ( + "github.com/filecoin-project/lotus/chain/actors" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -60,8 +61,48 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, addr address.Address) (State, error) { + switch av { + + case actors.Version0: + return make0(store, addr) + + case actors.Version2: + return make2(store, addr) + + case actors.Version3: + return make3(store, addr) + + case actors.Version4: + return make4(store, addr) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.AccountActorCodeID, nil + + case actors.Version2: + return builtin2.AccountActorCodeID, nil + + case actors.Version3: + return builtin3.AccountActorCodeID, nil + + case actors.Version4: + return builtin4.AccountActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler PubkeyAddress() (address.Address, error) + GetState() interface{} } diff --git a/chain/actors/builtin/account/actor.go.template b/chain/actors/builtin/account/actor.go.template index f75af3dfb..53962cc94 100644 --- a/chain/actors/builtin/account/actor.go.template +++ b/chain/actors/builtin/account/actor.go.template @@ -1,6 +1,7 @@ package account import ( + "github.com/filecoin-project/lotus/chain/actors" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -34,8 +35,30 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, addr address.Address) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store, addr) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.AccountActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler PubkeyAddress() (address.Address, error) + GetState() interface{} } diff --git a/chain/actors/builtin/account/state.go.template b/chain/actors/builtin/account/state.go.template index 65d874c80..5be262ece 100644 --- a/chain/actors/builtin/account/state.go.template +++ b/chain/actors/builtin/account/state.go.template @@ -20,6 +20,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store, addr address.Address) (State, error) { + out := state{{.v}}{store: store} + out.State = account{{.v}}.State{Address:addr} + return &out, nil +} + type state{{.v}} struct { account{{.v}}.State store adt.Store @@ -28,3 +34,7 @@ type state{{.v}} struct { func (s *state{{.v}}) PubkeyAddress() (address.Address, error) { return s.Address, nil } + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/account/temp b/chain/actors/builtin/account/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/account/v0.go b/chain/actors/builtin/account/v0.go index 67c555c5d..bdfca2fd7 100644 --- a/chain/actors/builtin/account/v0.go +++ b/chain/actors/builtin/account/v0.go @@ -20,6 +20,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store, addr address.Address) (State, error) { + out := state0{store: store} + out.State = account0.State{Address: addr} + return &out, nil +} + type state0 struct { account0.State store adt.Store @@ -28,3 +34,7 @@ type state0 struct { func (s *state0) PubkeyAddress() (address.Address, error) { return s.Address, nil } + +func (s *state0) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/account/v2.go b/chain/actors/builtin/account/v2.go index 2664631bc..66618e06a 100644 --- a/chain/actors/builtin/account/v2.go +++ b/chain/actors/builtin/account/v2.go @@ -20,6 +20,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store, addr address.Address) (State, error) { + out := state2{store: store} + out.State = account2.State{Address: addr} + return &out, nil +} + type state2 struct { account2.State store adt.Store @@ -28,3 +34,7 @@ type state2 struct { func (s *state2) PubkeyAddress() (address.Address, error) { return s.Address, nil } + +func (s *state2) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/account/v3.go b/chain/actors/builtin/account/v3.go index 16b489a3e..dbe100a4f 100644 --- a/chain/actors/builtin/account/v3.go +++ b/chain/actors/builtin/account/v3.go @@ -20,6 +20,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store, addr address.Address) (State, error) { + out := state3{store: store} + out.State = account3.State{Address: addr} + return &out, nil +} + type state3 struct { account3.State store adt.Store @@ -28,3 +34,7 @@ type state3 struct { func (s *state3) PubkeyAddress() (address.Address, error) { return s.Address, nil } + +func (s *state3) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/account/v4.go b/chain/actors/builtin/account/v4.go index 1a24007d8..53f71dcc5 100644 --- a/chain/actors/builtin/account/v4.go +++ b/chain/actors/builtin/account/v4.go @@ -20,6 +20,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store, addr address.Address) (State, error) { + out := state4{store: store} + out.State = account4.State{Address: addr} + return &out, nil +} + type state4 struct { account4.State store adt.Store @@ -28,3 +34,7 @@ type state4 struct { func (s *state4) PubkeyAddress() (address.Address, error) { return s.Address, nil } + +func (s *state4) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/builtin.go.template b/chain/actors/builtin/builtin.go.template index 9b89b13f5..6eac2627e 100644 --- a/chain/actors/builtin/builtin.go.template +++ b/chain/actors/builtin/builtin.go.template @@ -6,9 +6,9 @@ import ( "golang.org/x/xerrors" {{range .versions}} - builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" - smoothing{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/util/smoothing" - {{end}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" + smoothing{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/util/smoothing" + {{end}} "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" @@ -17,7 +17,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" miner{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/miner" - proof{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/runtime/proof" + proof{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/runtime/proof" ) var SystemActorAddr = builtin{{.latestVersion}}.SystemActorAddr @@ -33,12 +33,12 @@ var ( const ( EpochDurationSeconds = builtin{{.latestVersion}}.EpochDurationSeconds - EpochsInDay = builtin{{.latestVersion}}.EpochsInDay - SecondsInDay = builtin{{.latestVersion}}.SecondsInDay + EpochsInDay = builtin{{.latestVersion}}.EpochsInDay + SecondsInDay = builtin{{.latestVersion}}.SecondsInDay ) const ( - MethodSend = builtin{{.latestVersion}}.MethodSend + MethodSend = builtin{{.latestVersion}}.MethodSend MethodConstructor = builtin{{.latestVersion}}.MethodConstructor ) @@ -53,13 +53,13 @@ func QAPowerForWeight(size abi.SectorSize, duration abi.ChainEpoch, dealWeight, } {{range .versions}} - func FromV{{.}}FilterEstimate(v{{.}} smoothing{{.}}.FilterEstimate) FilterEstimate { + func FromV{{.}}FilterEstimate(v{{.}} smoothing{{.}}.FilterEstimate) FilterEstimate { {{if (eq . 0)}} - return (FilterEstimate)(v{{.}}) //nolint:unconvert - {{else}} - return (FilterEstimate)(v{{.}}) - {{end}} - } + return (FilterEstimate)(v{{.}}) //nolint:unconvert + {{else}} + return (FilterEstimate)(v{{.}}) + {{end}} + } {{end}} type ActorStateLoader func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) @@ -80,58 +80,58 @@ func Load(store adt.Store, act *types.Actor) (cbor.Marshaler, error) { func ActorNameByCode(c cid.Cid) string { switch { - {{range .versions}} - case builtin{{.}}.IsBuiltinActor(c): - return builtin{{.}}.ActorNameByCode(c) - {{end}} + {{range .versions}} + case builtin{{.}}.IsBuiltinActor(c): + return builtin{{.}}.ActorNameByCode(c) + {{end}} default: return "" } } func IsBuiltinActor(c cid.Cid) bool { - {{range .versions}} - if builtin{{.}}.IsBuiltinActor(c) { - return true - } - {{end}} - return false + {{range .versions}} + if builtin{{.}}.IsBuiltinActor(c) { + return true + } + {{end}} + return false } func IsAccountActor(c cid.Cid) bool { - {{range .versions}} - if c == builtin{{.}}.AccountActorCodeID { - return true - } - {{end}} - return false + {{range .versions}} + if c == builtin{{.}}.AccountActorCodeID { + return true + } + {{end}} + return false } func IsStorageMinerActor(c cid.Cid) bool { - {{range .versions}} - if c == builtin{{.}}.StorageMinerActorCodeID { - return true - } - {{end}} - return false + {{range .versions}} + if c == builtin{{.}}.StorageMinerActorCodeID { + return true + } + {{end}} + return false } func IsMultisigActor(c cid.Cid) bool { - {{range .versions}} - if c == builtin{{.}}.MultisigActorCodeID { - return true - } - {{end}} - return false + {{range .versions}} + if c == builtin{{.}}.MultisigActorCodeID { + return true + } + {{end}} + return false } func IsPaymentChannelActor(c cid.Cid) bool { - {{range .versions}} - if c == builtin{{.}}.PaymentChannelActorCodeID { - return true - } - {{end}} - return false + {{range .versions}} + if c == builtin{{.}}.PaymentChannelActorCodeID { + return true + } + {{end}} + return false } func makeAddress(addr string) address.Address { diff --git a/chain/actors/builtin/cron/actor.go.template b/chain/actors/builtin/cron/actor.go.template index 6b7449617..d73808556 100644 --- a/chain/actors/builtin/cron/actor.go.template +++ b/chain/actors/builtin/cron/actor.go.template @@ -1,10 +1,42 @@ package cron import ( - builtin{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "golang.org/x/xerrors" + "github.com/ipfs/go-cid" +{{range .versions}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" +{{end}} ) +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.CronActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + var ( Address = builtin{{.latestVersion}}.CronActorAddr Methods = builtin{{.latestVersion}}.MethodsCron ) + + +type State interface { + GetState() interface{} +} diff --git a/chain/actors/builtin/cron/cron.go b/chain/actors/builtin/cron/cron.go index 52a9fab07..62fa413a8 100644 --- a/chain/actors/builtin/cron/cron.go +++ b/chain/actors/builtin/cron/cron.go @@ -1,10 +1,64 @@ package cron import ( + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/ipfs/go-cid" + "golang.org/x/xerrors" + + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" ) +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { + + case actors.Version0: + return make0(store) + + case actors.Version2: + return make2(store) + + case actors.Version3: + return make3(store) + + case actors.Version4: + return make4(store) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.CronActorCodeID, nil + + case actors.Version2: + return builtin2.CronActorCodeID, nil + + case actors.Version3: + return builtin3.CronActorCodeID, nil + + case actors.Version4: + return builtin4.CronActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + var ( Address = builtin4.CronActorAddr Methods = builtin4.MethodsCron ) + +type State interface { + GetState() interface{} +} diff --git a/chain/actors/builtin/cron/state.go.template b/chain/actors/builtin/cron/state.go.template new file mode 100644 index 000000000..99a06d7f8 --- /dev/null +++ b/chain/actors/builtin/cron/state.go.template @@ -0,0 +1,35 @@ +package cron + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + cron{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/cron" +) + +var _ State = (*state{{.v}})(nil) + +func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { + out := state{{.v}}{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make{{.v}}(store adt.Store) (State, error) { + out := state{{.v}}{store: store} + out.State = *cron{{.v}}.ConstructState(cron{{.v}}.BuiltInEntries()) + return &out, nil +} + +type state{{.v}} struct { + cron{{.v}}.State + store adt.Store +} + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/cron/temp b/chain/actors/builtin/cron/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/cron/v0.go b/chain/actors/builtin/cron/v0.go new file mode 100644 index 000000000..6147b858c --- /dev/null +++ b/chain/actors/builtin/cron/v0.go @@ -0,0 +1,35 @@ +package cron + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + cron0 "github.com/filecoin-project/specs-actors/actors/builtin/cron" +) + +var _ State = (*state0)(nil) + +func load0(store adt.Store, root cid.Cid) (State, error) { + out := state0{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make0(store adt.Store) (State, error) { + out := state0{store: store} + out.State = *cron0.ConstructState(cron0.BuiltInEntries()) + return &out, nil +} + +type state0 struct { + cron0.State + store adt.Store +} + +func (s *state0) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/cron/v2.go b/chain/actors/builtin/cron/v2.go new file mode 100644 index 000000000..51ca179d9 --- /dev/null +++ b/chain/actors/builtin/cron/v2.go @@ -0,0 +1,35 @@ +package cron + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + cron2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/cron" +) + +var _ State = (*state2)(nil) + +func load2(store adt.Store, root cid.Cid) (State, error) { + out := state2{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make2(store adt.Store) (State, error) { + out := state2{store: store} + out.State = *cron2.ConstructState(cron2.BuiltInEntries()) + return &out, nil +} + +type state2 struct { + cron2.State + store adt.Store +} + +func (s *state2) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/cron/v3.go b/chain/actors/builtin/cron/v3.go new file mode 100644 index 000000000..ff74d511d --- /dev/null +++ b/chain/actors/builtin/cron/v3.go @@ -0,0 +1,35 @@ +package cron + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + cron3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/cron" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make3(store adt.Store) (State, error) { + out := state3{store: store} + out.State = *cron3.ConstructState(cron3.BuiltInEntries()) + return &out, nil +} + +type state3 struct { + cron3.State + store adt.Store +} + +func (s *state3) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/cron/v4.go b/chain/actors/builtin/cron/v4.go new file mode 100644 index 000000000..1cff8cc28 --- /dev/null +++ b/chain/actors/builtin/cron/v4.go @@ -0,0 +1,35 @@ +package cron + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + cron4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/cron" +) + +var _ State = (*state4)(nil) + +func load4(store adt.Store, root cid.Cid) (State, error) { + out := state4{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make4(store adt.Store) (State, error) { + out := state4{store: store} + out.State = *cron4.ConstructState(cron4.BuiltInEntries()) + return &out, nil +} + +type state4 struct { + cron4.State + store adt.Store +} + +func (s *state4) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/init/actor.go.template b/chain/actors/builtin/init/actor.go.template index 5b700cec8..f825eb9fa 100644 --- a/chain/actors/builtin/init/actor.go.template +++ b/chain/actors/builtin/init/actor.go.template @@ -1,6 +1,7 @@ package init import ( + "github.com/filecoin-project/lotus/chain/actors" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -39,6 +40,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, networkName string) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store, networkName) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.InitActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -56,5 +78,12 @@ type State interface { // Sets the network's name. This should only be used on upgrade/fork. SetNetworkName(name string) error - addressMap() (adt.Map, error) + // Sets the next ID for the init actor. This should only be used for testing. + SetNextID(id abi.ActorID) error + + // Sets the address map for the init actor. This should only be used for testing. + SetAddressMap(mcid cid.Cid) error + + AddressMap() (adt.Map, error) + GetState() interface{} } diff --git a/chain/actors/builtin/init/diff.go b/chain/actors/builtin/init/diff.go index 593171322..5eb8f3c75 100644 --- a/chain/actors/builtin/init/diff.go +++ b/chain/actors/builtin/init/diff.go @@ -11,12 +11,12 @@ import ( ) func DiffAddressMap(pre, cur State) (*AddressMapChanges, error) { - prem, err := pre.addressMap() + prem, err := pre.AddressMap() if err != nil { return nil, err } - curm, err := cur.addressMap() + curm, err := cur.AddressMap() if err != nil { return nil, err } diff --git a/chain/actors/builtin/init/init.go b/chain/actors/builtin/init/init.go index 730d21fd8..2091252ce 100644 --- a/chain/actors/builtin/init/init.go +++ b/chain/actors/builtin/init/init.go @@ -1,6 +1,7 @@ package init import ( + "github.com/filecoin-project/lotus/chain/actors" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -65,6 +66,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, networkName string) (State, error) { + switch av { + + case actors.Version0: + return make0(store, networkName) + + case actors.Version2: + return make2(store, networkName) + + case actors.Version3: + return make3(store, networkName) + + case actors.Version4: + return make4(store, networkName) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.InitActorCodeID, nil + + case actors.Version2: + return builtin2.InitActorCodeID, nil + + case actors.Version3: + return builtin3.InitActorCodeID, nil + + case actors.Version4: + return builtin4.InitActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -82,5 +122,12 @@ type State interface { // Sets the network's name. This should only be used on upgrade/fork. SetNetworkName(name string) error - addressMap() (adt.Map, error) + // Sets the next ID for the init actor. This should only be used for testing. + SetNextID(id abi.ActorID) error + + // Sets the address map for the init actor. This should only be used for testing. + SetAddressMap(mcid cid.Cid) error + + AddressMap() (adt.Map, error) + GetState() interface{} } diff --git a/chain/actors/builtin/init/state.go.template b/chain/actors/builtin/init/state.go.template index 95f052bda..482ad4df5 100644 --- a/chain/actors/builtin/init/state.go.template +++ b/chain/actors/builtin/init/state.go.template @@ -29,6 +29,26 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store, networkName string) (State, error) { + out := state{{.v}}{store: store} + {{if (le .v 2)}} + mr, err := adt{{.v}}.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *init{{.v}}.ConstructState(mr, networkName) + {{else}} + s, err := init{{.v}}.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + {{end}} + return &out, nil +} + type state{{.v}} struct { init{{.v}}.State store adt.Store @@ -66,6 +86,11 @@ func (s *state{{.v}}) SetNetworkName(name string) error { return nil } +func (s *state{{.v}}) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) { m, err := adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) if err != nil { @@ -84,6 +109,15 @@ func (s *state{{.v}}) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state{{.v}}) addressMap() (adt.Map, error) { - return adt{{.v}}.AsMap(s.store, s.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) +func (s *state{{.v}}) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil } + +func (s *state{{.v}}) AddressMap() (adt.Map, error) { + return adt{{.v}}.AsMap(s.store, s.State.AddressMap{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) +} + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/init/temp b/chain/actors/builtin/init/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/init/v0.go b/chain/actors/builtin/init/v0.go index c019705b1..ddd2dab94 100644 --- a/chain/actors/builtin/init/v0.go +++ b/chain/actors/builtin/init/v0.go @@ -25,6 +25,19 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store, networkName string) (State, error) { + out := state0{store: store} + + mr, err := adt0.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *init0.ConstructState(mr, networkName) + + return &out, nil +} + type state0 struct { init0.State store adt.Store @@ -62,6 +75,11 @@ func (s *state0) SetNetworkName(name string) error { return nil } +func (s *state0) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state0) Remove(addrs ...address.Address) (err error) { m, err := adt0.AsMap(s.store, s.State.AddressMap) if err != nil { @@ -80,6 +98,15 @@ func (s *state0) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state0) addressMap() (adt.Map, error) { - return adt0.AsMap(s.store, s.AddressMap) +func (s *state0) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state0) AddressMap() (adt.Map, error) { + return adt0.AsMap(s.store, s.State.AddressMap) +} + +func (s *state0) GetState() interface{} { + return &s.State } diff --git a/chain/actors/builtin/init/v2.go b/chain/actors/builtin/init/v2.go index 420243be4..72e2d56a5 100644 --- a/chain/actors/builtin/init/v2.go +++ b/chain/actors/builtin/init/v2.go @@ -25,6 +25,19 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store, networkName string) (State, error) { + out := state2{store: store} + + mr, err := adt2.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *init2.ConstructState(mr, networkName) + + return &out, nil +} + type state2 struct { init2.State store adt.Store @@ -62,6 +75,11 @@ func (s *state2) SetNetworkName(name string) error { return nil } +func (s *state2) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state2) Remove(addrs ...address.Address) (err error) { m, err := adt2.AsMap(s.store, s.State.AddressMap) if err != nil { @@ -80,6 +98,15 @@ func (s *state2) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state2) addressMap() (adt.Map, error) { - return adt2.AsMap(s.store, s.AddressMap) +func (s *state2) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state2) AddressMap() (adt.Map, error) { + return adt2.AsMap(s.store, s.State.AddressMap) +} + +func (s *state2) GetState() interface{} { + return &s.State } diff --git a/chain/actors/builtin/init/v3.go b/chain/actors/builtin/init/v3.go index eaa54dfd4..4609c94a3 100644 --- a/chain/actors/builtin/init/v3.go +++ b/chain/actors/builtin/init/v3.go @@ -27,6 +27,19 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store, networkName string) (State, error) { + out := state3{store: store} + + s, err := init3.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state3 struct { init3.State store adt.Store @@ -64,6 +77,11 @@ func (s *state3) SetNetworkName(name string) error { return nil } +func (s *state3) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state3) Remove(addrs ...address.Address) (err error) { m, err := adt3.AsMap(s.store, s.State.AddressMap, builtin3.DefaultHamtBitwidth) if err != nil { @@ -82,6 +100,15 @@ func (s *state3) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state3) addressMap() (adt.Map, error) { - return adt3.AsMap(s.store, s.AddressMap, builtin3.DefaultHamtBitwidth) +func (s *state3) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state3) AddressMap() (adt.Map, error) { + return adt3.AsMap(s.store, s.State.AddressMap, builtin3.DefaultHamtBitwidth) +} + +func (s *state3) GetState() interface{} { + return &s.State } diff --git a/chain/actors/builtin/init/v4.go b/chain/actors/builtin/init/v4.go index 38749eed5..dc56d1f19 100644 --- a/chain/actors/builtin/init/v4.go +++ b/chain/actors/builtin/init/v4.go @@ -27,6 +27,19 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store, networkName string) (State, error) { + out := state4{store: store} + + s, err := init4.ConstructState(store, networkName) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state4 struct { init4.State store adt.Store @@ -64,6 +77,11 @@ func (s *state4) SetNetworkName(name string) error { return nil } +func (s *state4) SetNextID(id abi.ActorID) error { + s.State.NextID = id + return nil +} + func (s *state4) Remove(addrs ...address.Address) (err error) { m, err := adt4.AsMap(s.store, s.State.AddressMap, builtin4.DefaultHamtBitwidth) if err != nil { @@ -82,6 +100,15 @@ func (s *state4) Remove(addrs ...address.Address) (err error) { return nil } -func (s *state4) addressMap() (adt.Map, error) { - return adt4.AsMap(s.store, s.AddressMap, builtin4.DefaultHamtBitwidth) +func (s *state4) SetAddressMap(mcid cid.Cid) error { + s.State.AddressMap = mcid + return nil +} + +func (s *state4) AddressMap() (adt.Map, error) { + return adt4.AsMap(s.store, s.State.AddressMap, builtin4.DefaultHamtBitwidth) +} + +func (s *state4) GetState() interface{} { + return &s.State } diff --git a/chain/actors/builtin/market/actor.go.template b/chain/actors/builtin/market/actor.go.template index 39cfe1be7..5b67695e1 100644 --- a/chain/actors/builtin/market/actor.go.template +++ b/chain/actors/builtin/market/actor.go.template @@ -16,6 +16,7 @@ import ( {{end}} "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" ) @@ -42,6 +43,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.StorageMarketActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler BalancesChanged(State) (bool, error) @@ -56,6 +78,7 @@ type State interface { minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, ) (weight, verifiedWeight abi.DealWeight, err error) NextID() (abi.DealID, error) + GetState() interface{} } type BalanceTable interface { @@ -81,7 +104,6 @@ type DealProposals interface { type PublishStorageDealsParams = market0.PublishStorageDealsParams type PublishStorageDealsReturn = market0.PublishStorageDealsReturn -type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams type WithdrawBalanceParams = market0.WithdrawBalanceParams type ClientDealProposal = market0.ClientDealProposal @@ -89,71 +111,71 @@ type ClientDealProposal = market0.ClientDealProposal type DealState struct { SectorStartEpoch abi.ChainEpoch // -1 if not yet included in proven sector LastUpdatedEpoch abi.ChainEpoch // -1 if deal state never updated - SlashEpoch abi.ChainEpoch // -1 if deal never slashed + SlashEpoch abi.ChainEpoch // -1 if deal never slashed } type DealProposal struct { - PieceCID cid.Cid - PieceSize abi.PaddedPieceSize - VerifiedDeal bool - Client address.Address - Provider address.Address - Label string - StartEpoch abi.ChainEpoch - EndEpoch abi.ChainEpoch + PieceCID cid.Cid + PieceSize abi.PaddedPieceSize + VerifiedDeal bool + Client address.Address + Provider address.Address + Label string + StartEpoch abi.ChainEpoch + EndEpoch abi.ChainEpoch StoragePricePerEpoch abi.TokenAmount - ProviderCollateral abi.TokenAmount - ClientCollateral abi.TokenAmount + ProviderCollateral abi.TokenAmount + ClientCollateral abi.TokenAmount } type DealStateChanges struct { - Added []DealIDState + Added []DealIDState Modified []DealStateChange - Removed []DealIDState + Removed []DealIDState } type DealIDState struct { - ID abi.DealID + ID abi.DealID Deal DealState } // DealStateChange is a change in deal state from -> to type DealStateChange struct { - ID abi.DealID + ID abi.DealID From *DealState - To *DealState + To *DealState } type DealProposalChanges struct { - Added []ProposalIDState + Added []ProposalIDState Removed []ProposalIDState } type ProposalIDState struct { - ID abi.DealID + ID abi.DealID Proposal DealProposal } func EmptyDealState() *DealState { return &DealState{ SectorStartEpoch: -1, - SlashEpoch: -1, + SlashEpoch: -1, LastUpdatedEpoch: -1, } } // returns the earned fees and pending fees for a given deal func (deal DealProposal) GetDealFees(height abi.ChainEpoch) (abi.TokenAmount, abi.TokenAmount) { - tf := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(deal.EndEpoch-deal.StartEpoch))) + tf := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(deal.EndEpoch-deal.StartEpoch))) - ef := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(height-deal.StartEpoch))) - if ef.LessThan(big.Zero()) { - ef = big.Zero() - } + ef := big.Mul(deal.StoragePricePerEpoch, big.NewInt(int64(height-deal.StartEpoch))) + if ef.LessThan(big.Zero()) { + ef = big.Zero() + } - if ef.GreaterThan(tf) { - ef = tf - } + if ef.GreaterThan(tf) { + ef = tf + } - return ef, big.Sub(tf, ef) + return ef, big.Sub(tf, ef) } diff --git a/chain/actors/builtin/market/market.go b/chain/actors/builtin/market/market.go index adf7ce33d..ffc826658 100644 --- a/chain/actors/builtin/market/market.go +++ b/chain/actors/builtin/market/market.go @@ -20,6 +20,7 @@ import ( builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" @@ -68,6 +69,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { + + case actors.Version0: + return make0(store) + + case actors.Version2: + return make2(store) + + case actors.Version3: + return make3(store) + + case actors.Version4: + return make4(store) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.StorageMarketActorCodeID, nil + + case actors.Version2: + return builtin2.StorageMarketActorCodeID, nil + + case actors.Version3: + return builtin3.StorageMarketActorCodeID, nil + + case actors.Version4: + return builtin4.StorageMarketActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler BalancesChanged(State) (bool, error) @@ -82,6 +122,7 @@ type State interface { minerAddr address.Address, deals []abi.DealID, currEpoch, sectorExpiry abi.ChainEpoch, ) (weight, verifiedWeight abi.DealWeight, err error) NextID() (abi.DealID, error) + GetState() interface{} } type BalanceTable interface { @@ -107,7 +148,6 @@ type DealProposals interface { type PublishStorageDealsParams = market0.PublishStorageDealsParams type PublishStorageDealsReturn = market0.PublishStorageDealsReturn -type VerifyDealsForActivationParams = market0.VerifyDealsForActivationParams type WithdrawBalanceParams = market0.WithdrawBalanceParams type ClientDealProposal = market0.ClientDealProposal diff --git a/chain/actors/builtin/market/state.go.template b/chain/actors/builtin/market/state.go.template index a55743ce5..965c8d41f 100644 --- a/chain/actors/builtin/market/state.go.template +++ b/chain/actors/builtin/market/state.go.template @@ -26,6 +26,31 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store) (State, error) { + out := state{{.v}}{store: store} + {{if (le .v 2)}} + ea, err := adt{{.v}}.MakeEmptyArray(store).Root() + if err != nil { + return nil, err + } + + em, err := adt{{.v}}.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *market{{.v}}.ConstructState(ea, em, em) + {{else}} + s, err := market{{.v}}.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + {{end}} + return &out, nil +} + type state{{.v}} struct { market{{.v}}.State store adt.Store @@ -207,3 +232,7 @@ func (s *dealProposals{{.v}}) array() adt.Array { func fromV{{.v}}DealProposal(v{{.v}} market{{.v}}.DealProposal) DealProposal { return (DealProposal)(v{{.v}}) } + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/market/temp b/chain/actors/builtin/market/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/market/v0.go b/chain/actors/builtin/market/v0.go index 175c0a2ea..b3093b54b 100644 --- a/chain/actors/builtin/market/v0.go +++ b/chain/actors/builtin/market/v0.go @@ -26,6 +26,24 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store) (State, error) { + out := state0{store: store} + + ea, err := adt0.MakeEmptyArray(store).Root() + if err != nil { + return nil, err + } + + em, err := adt0.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *market0.ConstructState(ea, em, em) + + return &out, nil +} + type state0 struct { market0.State store adt.Store @@ -207,3 +225,7 @@ func (s *dealProposals0) array() adt.Array { func fromV0DealProposal(v0 market0.DealProposal) DealProposal { return (DealProposal)(v0) } + +func (s *state0) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/market/v2.go b/chain/actors/builtin/market/v2.go index dafae8feb..fdedcce85 100644 --- a/chain/actors/builtin/market/v2.go +++ b/chain/actors/builtin/market/v2.go @@ -26,6 +26,24 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store) (State, error) { + out := state2{store: store} + + ea, err := adt2.MakeEmptyArray(store).Root() + if err != nil { + return nil, err + } + + em, err := adt2.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *market2.ConstructState(ea, em, em) + + return &out, nil +} + type state2 struct { market2.State store adt.Store @@ -207,3 +225,7 @@ func (s *dealProposals2) array() adt.Array { func fromV2DealProposal(v2 market2.DealProposal) DealProposal { return (DealProposal)(v2) } + +func (s *state2) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/market/v3.go b/chain/actors/builtin/market/v3.go index dec8d6e25..53d266443 100644 --- a/chain/actors/builtin/market/v3.go +++ b/chain/actors/builtin/market/v3.go @@ -26,6 +26,19 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store) (State, error) { + out := state3{store: store} + + s, err := market3.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state3 struct { market3.State store adt.Store @@ -207,3 +220,7 @@ func (s *dealProposals3) array() adt.Array { func fromV3DealProposal(v3 market3.DealProposal) DealProposal { return (DealProposal)(v3) } + +func (s *state3) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/market/v4.go b/chain/actors/builtin/market/v4.go index 22514395c..30aa26920 100644 --- a/chain/actors/builtin/market/v4.go +++ b/chain/actors/builtin/market/v4.go @@ -26,6 +26,19 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store) (State, error) { + out := state4{store: store} + + s, err := market4.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state4 struct { market4.State store adt.Store @@ -207,3 +220,7 @@ func (s *dealProposals4) array() adt.Array { func fromV4DealProposal(v4 market4.DealProposal) DealProposal { return (DealProposal)(v4) } + +func (s *state4) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/miner/actor.go.template b/chain/actors/builtin/miner/actor.go.template index 4b3d8db5e..c7755ef71 100644 --- a/chain/actors/builtin/miner/actor.go.template +++ b/chain/actors/builtin/miner/actor.go.template @@ -3,6 +3,7 @@ package miner import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" @@ -60,6 +61,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.StorageMinerActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -79,6 +101,11 @@ type State interface { NumLiveSectors() (uint64, error) IsAllocated(abi.SectorNumber) (bool, error) + // Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors + GetProvingPeriodStart() (abi.ChainEpoch, error) + // Testing only + EraseAllUnproven() error + LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error NumDeadlines() (uint64, error) @@ -95,6 +122,7 @@ type State interface { decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error) precommits() (adt.Map, error) decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error) + GetState() interface{} } type Deadline interface { @@ -115,26 +143,26 @@ type Partition interface { } type SectorOnChainInfo struct { - SectorNumber abi.SectorNumber - SealProof abi.RegisteredSealProof - SealedCID cid.Cid - DealIDs []abi.DealID - Activation abi.ChainEpoch - Expiration abi.ChainEpoch - DealWeight abi.DealWeight - VerifiedDealWeight abi.DealWeight - InitialPledge abi.TokenAmount - ExpectedDayReward abi.TokenAmount + SectorNumber abi.SectorNumber + SealProof abi.RegisteredSealProof + SealedCID cid.Cid + DealIDs []abi.DealID + Activation abi.ChainEpoch + Expiration abi.ChainEpoch + DealWeight abi.DealWeight + VerifiedDealWeight abi.DealWeight + InitialPledge abi.TokenAmount + ExpectedDayReward abi.TokenAmount ExpectedStoragePledge abi.TokenAmount } type SectorPreCommitInfo = miner0.SectorPreCommitInfo type SectorPreCommitOnChainInfo struct { - Info SectorPreCommitInfo + Info SectorPreCommitInfo PreCommitDeposit abi.TokenAmount - PreCommitEpoch abi.ChainEpoch - DealWeight abi.DealWeight + PreCommitEpoch abi.ChainEpoch + DealWeight abi.DealWeight VerifiedDealWeight abi.DealWeight } @@ -203,17 +231,17 @@ func WinningPoStProofTypeFromWindowPoStProofType(nver network.Version, proof abi } type MinerInfo struct { - Owner address.Address // Must be an ID-address. - Worker address.Address // Must be an ID-address. - NewWorker address.Address // Must be an ID-address. - ControlAddresses []address.Address // Must be an ID-addresses. - WorkerChangeEpoch abi.ChainEpoch - PeerId *peer.ID - Multiaddrs []abi.Multiaddrs - WindowPoStProofType abi.RegisteredPoStProof - SectorSize abi.SectorSize + Owner address.Address // Must be an ID-address. + Worker address.Address // Must be an ID-address. + NewWorker address.Address // Must be an ID-address. + ControlAddresses []address.Address // Must be an ID-addresses. + WorkerChangeEpoch abi.ChainEpoch + PeerId *peer.ID + Multiaddrs []abi.Multiaddrs + WindowPoStProofType abi.RegisteredPoStProof + SectorSize abi.SectorSize WindowPoStPartitionSectors uint64 - ConsensusFaultElapsed abi.ChainEpoch + ConsensusFaultElapsed abi.ChainEpoch } func (mi MinerInfo) IsController(addr address.Address) bool { @@ -244,25 +272,25 @@ type SectorLocation struct { } type SectorChanges struct { - Added []SectorOnChainInfo + Added []SectorOnChainInfo Extended []SectorExtensions - Removed []SectorOnChainInfo + Removed []SectorOnChainInfo } type SectorExtensions struct { From SectorOnChainInfo - To SectorOnChainInfo + To SectorOnChainInfo } type PreCommitChanges struct { - Added []SectorPreCommitOnChainInfo + Added []SectorPreCommitOnChainInfo Removed []SectorPreCommitOnChainInfo } type LockedFunds struct { - VestingFunds abi.TokenAmount + VestingFunds abi.TokenAmount InitialPledgeRequirement abi.TokenAmount - PreCommitDeposits abi.TokenAmount + PreCommitDeposits abi.TokenAmount } func (lf LockedFunds) TotalLockedFunds() abi.TokenAmount { diff --git a/chain/actors/builtin/miner/miner.go b/chain/actors/builtin/miner/miner.go index a426e063b..d9b872e3f 100644 --- a/chain/actors/builtin/miner/miner.go +++ b/chain/actors/builtin/miner/miner.go @@ -3,6 +3,7 @@ package miner import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/chain/actors" "github.com/ipfs/go-cid" "github.com/libp2p/go-libp2p-core/peer" cbg "github.com/whyrusleeping/cbor-gen" @@ -86,6 +87,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { + + case actors.Version0: + return make0(store) + + case actors.Version2: + return make2(store) + + case actors.Version3: + return make3(store) + + case actors.Version4: + return make4(store) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.StorageMinerActorCodeID, nil + + case actors.Version2: + return builtin2.StorageMinerActorCodeID, nil + + case actors.Version3: + return builtin3.StorageMinerActorCodeID, nil + + case actors.Version4: + return builtin4.StorageMinerActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -105,6 +145,11 @@ type State interface { NumLiveSectors() (uint64, error) IsAllocated(abi.SectorNumber) (bool, error) + // Note that ProvingPeriodStart is deprecated and will be renamed / removed in a future version of actors + GetProvingPeriodStart() (abi.ChainEpoch, error) + // Testing only + EraseAllUnproven() error + LoadDeadline(idx uint64) (Deadline, error) ForEachDeadline(cb func(idx uint64, dl Deadline) error) error NumDeadlines() (uint64, error) @@ -121,6 +166,7 @@ type State interface { decodeSectorOnChainInfo(*cbg.Deferred) (SectorOnChainInfo, error) precommits() (adt.Map, error) decodeSectorPreCommitOnChainInfo(*cbg.Deferred) (SectorPreCommitOnChainInfo, error) + GetState() interface{} } type Deadline interface { diff --git a/chain/actors/builtin/miner/state.go.template b/chain/actors/builtin/miner/state.go.template index 0769eea10..270510a8c 100644 --- a/chain/actors/builtin/miner/state.go.template +++ b/chain/actors/builtin/miner/state.go.template @@ -35,6 +35,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store) (State, error) { + out := state{{.v}}{store: store} + out.State = miner{{.v}}.State{} + return &out, nil +} + type state{{.v}} struct { miner{{.v}}.State store adt.Store @@ -68,9 +74,9 @@ func (s *state{{.v}}) VestedFunds(epoch abi.ChainEpoch) (abi.TokenAmount, error) func (s *state{{.v}}) LockedFunds() (LockedFunds, error) { return LockedFunds{ - VestingFunds: s.State.LockedFunds, + VestingFunds: s.State.LockedFunds, InitialPledgeRequirement: s.State.InitialPledge{{if (le .v 1)}}Requirement{{end}}, - PreCommitDeposits: s.State.PreCommitDeposits, + PreCommitDeposits: s.State.PreCommitDeposits, }, nil } @@ -245,6 +251,10 @@ func (s *state{{.v}}) IsAllocated(num abi.SectorNumber) (bool, error) { return allocatedSectors.IsSet(uint64(num)) } +func (s *state{{.v}}) GetProvingPeriodStart() (abi.ChainEpoch, error) { + return s.State.ProvingPeriodStart, nil +} + func (s *state{{.v}}) LoadDeadline(idx uint64) (Deadline, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { @@ -307,19 +317,19 @@ func (s *state{{.v}}) Info() (MinerInfo, error) { } {{end}} mi := MinerInfo{ - Owner: info.Owner, - Worker: info.Worker, + Owner: info.Owner, + Worker: info.Worker, ControlAddresses: info.ControlAddresses, - NewWorker: address.Undef, + NewWorker: address.Undef, WorkerChangeEpoch: -1, - PeerId: pid, - Multiaddrs: info.Multiaddrs, - WindowPoStProofType: {{if (ge .v 3)}}info.WindowPoStProofType{{else}}wpp{{end}}, - SectorSize: info.SectorSize, + PeerId: pid, + Multiaddrs: info.Multiaddrs, + WindowPoStProofType: {{if (ge .v 3)}}info.WindowPoStProofType{{else}}wpp{{end}}, + SectorSize: info.SectorSize, WindowPoStPartitionSectors: info.WindowPoStPartitionSectors, - ConsensusFaultElapsed: {{if (ge .v 2)}}info.ConsensusFaultElapsed{{else}}-1{{end}}, + ConsensusFaultElapsed: {{if (ge .v 2)}}info.ConsensusFaultElapsed{{else}}-1{{end}}, } if info.PendingWorkerKey != nil { @@ -366,6 +376,45 @@ func (s *state{{.v}}) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (Secto return fromV{{.v}}SectorPreCommitOnChainInfo(sp), nil } +func (s *state{{.v}}) EraseAllUnproven() error { + {{if (ge .v 2)}} + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + + err = dls.ForEach(s.store, func(dindx uint64, dl *miner{{.v}}.Deadline) error { + ps, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + + var part miner{{.v}}.Partition + err = ps.ForEach(&part, func(pindx int64) error { + _ = part.ActivateUnproven() + err = ps.Set(uint64(pindx), &part) + return nil + }) + + if err != nil { + return err + } + + dl.Partitions, err = ps.Root() + if err != nil { + return err + } + + return dls.UpdateDeadline(s.store, dindx, dl) + }) + + return s.State.SaveDeadlines(s.store, dls) + {{else}} + // field doesn't exist until v2 + {{end}} + return nil +} + func (d *deadline{{.v}}) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) if err != nil { @@ -428,16 +477,16 @@ func (p *partition{{.v}}) RecoveringSectors() (bitfield.BitField, error) { func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorOnChainInfo { {{if (ge .v 2)}} return SectorOnChainInfo{ - SectorNumber: v{{.v}}.SectorNumber, - SealProof: v{{.v}}.SealProof, - SealedCID: v{{.v}}.SealedCID, - DealIDs: v{{.v}}.DealIDs, - Activation: v{{.v}}.Activation, - Expiration: v{{.v}}.Expiration, - DealWeight: v{{.v}}.DealWeight, - VerifiedDealWeight: v{{.v}}.VerifiedDealWeight, - InitialPledge: v{{.v}}.InitialPledge, - ExpectedDayReward: v{{.v}}.ExpectedDayReward, + SectorNumber: v{{.v}}.SectorNumber, + SealProof: v{{.v}}.SealProof, + SealedCID: v{{.v}}.SealedCID, + DealIDs: v{{.v}}.DealIDs, + Activation: v{{.v}}.Activation, + Expiration: v{{.v}}.Expiration, + DealWeight: v{{.v}}.DealWeight, + VerifiedDealWeight: v{{.v}}.VerifiedDealWeight, + InitialPledge: v{{.v}}.InitialPledge, + ExpectedDayReward: v{{.v}}.ExpectedDayReward, ExpectedStoragePledge: v{{.v}}.ExpectedStoragePledge, } {{else}} @@ -448,13 +497,17 @@ func fromV{{.v}}SectorOnChainInfo(v{{.v}} miner{{.v}}.SectorOnChainInfo) SectorO func fromV{{.v}}SectorPreCommitOnChainInfo(v{{.v}} miner{{.v}}.SectorPreCommitOnChainInfo) SectorPreCommitOnChainInfo { {{if (ge .v 2)}} return SectorPreCommitOnChainInfo{ - Info: (SectorPreCommitInfo)(v{{.v}}.Info), - PreCommitDeposit: v{{.v}}.PreCommitDeposit, - PreCommitEpoch: v{{.v}}.PreCommitEpoch, - DealWeight: v{{.v}}.DealWeight, + Info: (SectorPreCommitInfo)(v{{.v}}.Info), + PreCommitDeposit: v{{.v}}.PreCommitDeposit, + PreCommitEpoch: v{{.v}}.PreCommitEpoch, + DealWeight: v{{.v}}.DealWeight, VerifiedDealWeight: v{{.v}}.VerifiedDealWeight, } {{else}} return (SectorPreCommitOnChainInfo)(v0) {{end}} } + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/miner/temp b/chain/actors/builtin/miner/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/miner/v0.go b/chain/actors/builtin/miner/v0.go index 2dc8ae23e..344be1993 100644 --- a/chain/actors/builtin/miner/v0.go +++ b/chain/actors/builtin/miner/v0.go @@ -32,6 +32,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store) (State, error) { + out := state0{store: store} + out.State = miner0.State{} + return &out, nil +} + type state0 struct { miner0.State store adt.Store @@ -242,6 +248,10 @@ func (s *state0) IsAllocated(num abi.SectorNumber) (bool, error) { return allocatedSectors.IsSet(uint64(num)) } +func (s *state0) GetProvingPeriodStart() (abi.ChainEpoch, error) { + return s.State.ProvingPeriodStart, nil +} + func (s *state0) LoadDeadline(idx uint64) (Deadline, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { @@ -363,6 +373,13 @@ func (s *state0) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC return fromV0SectorPreCommitOnChainInfo(sp), nil } +func (s *state0) EraseAllUnproven() error { + + // field doesn't exist until v2 + + return nil +} + func (d *deadline0) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) if err != nil { @@ -426,3 +443,7 @@ func fromV0SectorPreCommitOnChainInfo(v0 miner0.SectorPreCommitOnChainInfo) Sect return (SectorPreCommitOnChainInfo)(v0) } + +func (s *state0) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/miner/v2.go b/chain/actors/builtin/miner/v2.go index 7564dd8b8..3e76d0b69 100644 --- a/chain/actors/builtin/miner/v2.go +++ b/chain/actors/builtin/miner/v2.go @@ -30,6 +30,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store) (State, error) { + out := state2{store: store} + out.State = miner2.State{} + return &out, nil +} + type state2 struct { miner2.State store adt.Store @@ -240,6 +246,10 @@ func (s *state2) IsAllocated(num abi.SectorNumber) (bool, error) { return allocatedSectors.IsSet(uint64(num)) } +func (s *state2) GetProvingPeriodStart() (abi.ChainEpoch, error) { + return s.State.ProvingPeriodStart, nil +} + func (s *state2) LoadDeadline(idx uint64) (Deadline, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { @@ -361,6 +371,43 @@ func (s *state2) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC return fromV2SectorPreCommitOnChainInfo(sp), nil } +func (s *state2) EraseAllUnproven() error { + + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + + err = dls.ForEach(s.store, func(dindx uint64, dl *miner2.Deadline) error { + ps, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + + var part miner2.Partition + err = ps.ForEach(&part, func(pindx int64) error { + _ = part.ActivateUnproven() + err = ps.Set(uint64(pindx), &part) + return nil + }) + + if err != nil { + return err + } + + dl.Partitions, err = ps.Root() + if err != nil { + return err + } + + return dls.UpdateDeadline(s.store, dindx, dl) + }) + + return s.State.SaveDeadlines(s.store, dls) + + return nil +} + func (d *deadline2) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) if err != nil { @@ -442,3 +489,7 @@ func fromV2SectorPreCommitOnChainInfo(v2 miner2.SectorPreCommitOnChainInfo) Sect } } + +func (s *state2) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/miner/v3.go b/chain/actors/builtin/miner/v3.go index 72a080f73..72986233d 100644 --- a/chain/actors/builtin/miner/v3.go +++ b/chain/actors/builtin/miner/v3.go @@ -32,6 +32,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store) (State, error) { + out := state3{store: store} + out.State = miner3.State{} + return &out, nil +} + type state3 struct { miner3.State store adt.Store @@ -242,6 +248,10 @@ func (s *state3) IsAllocated(num abi.SectorNumber) (bool, error) { return allocatedSectors.IsSet(uint64(num)) } +func (s *state3) GetProvingPeriodStart() (abi.ChainEpoch, error) { + return s.State.ProvingPeriodStart, nil +} + func (s *state3) LoadDeadline(idx uint64) (Deadline, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { @@ -358,6 +368,43 @@ func (s *state3) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC return fromV3SectorPreCommitOnChainInfo(sp), nil } +func (s *state3) EraseAllUnproven() error { + + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + + err = dls.ForEach(s.store, func(dindx uint64, dl *miner3.Deadline) error { + ps, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + + var part miner3.Partition + err = ps.ForEach(&part, func(pindx int64) error { + _ = part.ActivateUnproven() + err = ps.Set(uint64(pindx), &part) + return nil + }) + + if err != nil { + return err + } + + dl.Partitions, err = ps.Root() + if err != nil { + return err + } + + return dls.UpdateDeadline(s.store, dindx, dl) + }) + + return s.State.SaveDeadlines(s.store, dls) + + return nil +} + func (d *deadline3) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) if err != nil { @@ -443,3 +490,7 @@ func fromV3SectorPreCommitOnChainInfo(v3 miner3.SectorPreCommitOnChainInfo) Sect } } + +func (s *state3) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/miner/v4.go b/chain/actors/builtin/miner/v4.go index 698bdf2f5..96ed21f04 100644 --- a/chain/actors/builtin/miner/v4.go +++ b/chain/actors/builtin/miner/v4.go @@ -32,6 +32,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store) (State, error) { + out := state4{store: store} + out.State = miner4.State{} + return &out, nil +} + type state4 struct { miner4.State store adt.Store @@ -242,6 +248,10 @@ func (s *state4) IsAllocated(num abi.SectorNumber) (bool, error) { return allocatedSectors.IsSet(uint64(num)) } +func (s *state4) GetProvingPeriodStart() (abi.ChainEpoch, error) { + return s.State.ProvingPeriodStart, nil +} + func (s *state4) LoadDeadline(idx uint64) (Deadline, error) { dls, err := s.State.LoadDeadlines(s.store) if err != nil { @@ -358,6 +368,43 @@ func (s *state4) decodeSectorPreCommitOnChainInfo(val *cbg.Deferred) (SectorPreC return fromV4SectorPreCommitOnChainInfo(sp), nil } +func (s *state4) EraseAllUnproven() error { + + dls, err := s.State.LoadDeadlines(s.store) + if err != nil { + return err + } + + err = dls.ForEach(s.store, func(dindx uint64, dl *miner4.Deadline) error { + ps, err := dl.PartitionsArray(s.store) + if err != nil { + return err + } + + var part miner4.Partition + err = ps.ForEach(&part, func(pindx int64) error { + _ = part.ActivateUnproven() + err = ps.Set(uint64(pindx), &part) + return nil + }) + + if err != nil { + return err + } + + dl.Partitions, err = ps.Root() + if err != nil { + return err + } + + return dls.UpdateDeadline(s.store, dindx, dl) + }) + + return s.State.SaveDeadlines(s.store, dls) + + return nil +} + func (d *deadline4) LoadPartition(idx uint64) (Partition, error) { p, err := d.Deadline.LoadPartition(d.store, idx) if err != nil { @@ -443,3 +490,7 @@ func fromV4SectorPreCommitOnChainInfo(v4 miner4.SectorPreCommitOnChainInfo) Sect } } + +func (s *state4) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/multisig/actor.go.template b/chain/actors/builtin/multisig/actor.go.template index 19d99dcb7..3af270c60 100644 --- a/chain/actors/builtin/multisig/actor.go.template +++ b/chain/actors/builtin/multisig/actor.go.template @@ -40,6 +40,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store, signers, threshold, startEpoch, unlockDuration, initialBalance) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.MultisigActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -55,6 +76,7 @@ type State interface { transactions() (adt.Map, error) decodeTransaction(val *cbg.Deferred) (Transaction, error) + GetState() interface{} } type Transaction = msig{{.latestVersion}}.Transaction @@ -66,7 +88,7 @@ func Message(version actors.Version, from address.Address) MessageBuilder { {{range .versions}} case actors.Version{{.}}: return message{{.}}{{"{"}}{{if (ge . 2)}}message0{from}{{else}}from{{end}}} -{{end}} default: +{{end}} default: panic(fmt.Sprintf("unsupported actors version: %d", version)) } } diff --git a/chain/actors/builtin/multisig/message.go.template b/chain/actors/builtin/multisig/message.go.template index 6bff8983a..917e6944b 100644 --- a/chain/actors/builtin/multisig/message.go.template +++ b/chain/actors/builtin/multisig/message.go.template @@ -43,10 +43,10 @@ func (m message{{.v}}) Create( {{end}} // Set up constructor parameters for multisig msigParams := &multisig{{.v}}.ConstructorParams{ - Signers: signers, + Signers: signers, NumApprovalsThreshold: threshold, - UnlockDuration: unlockDuration,{{if (ge .v 2)}} - StartEpoch: unlockStart,{{end}} + UnlockDuration: unlockDuration,{{if (ge .v 2)}} + StartEpoch: unlockStart,{{end}} } enc, actErr := actors.SerializeParams(msigParams) @@ -56,7 +56,7 @@ func (m message{{.v}}) Create( // new actors are created by invoking 'exec' on the init actor with the constructor params execParams := &init{{.v}}.ExecParams{ - CodeCID: builtin{{.v}}.MultisigActorCodeID, + CodeCID: builtin{{.v}}.MultisigActorCodeID, ConstructorParams: enc, } @@ -66,11 +66,11 @@ func (m message{{.v}}) Create( } return &types.Message{ - To: init_.Address, - From: m.from, + To: init_.Address, + From: m.from, Method: builtin{{.v}}.MethodsInit.Exec, Params: enc, - Value: initialAmount, + Value: initialAmount, }, nil } @@ -96,8 +96,8 @@ func (m message0) Propose(msig, to address.Address, amt abi.TokenAmount, } enc, actErr := actors.SerializeParams(&multisig0.ProposeParams{ - To: to, - Value: amt, + To: to, + Value: amt, Method: method, Params: params, }) @@ -106,9 +106,9 @@ func (m message0) Propose(msig, to address.Address, amt abi.TokenAmount, } return &types.Message{ - To: msig, - From: m.from, - Value: abi.NewTokenAmount(0), + To: msig, + From: m.from, + Value: abi.NewTokenAmount(0), Method: builtin0.MethodsMultisig.Propose, Params: enc, }, nil @@ -121,9 +121,9 @@ func (m message0) Approve(msig address.Address, txID uint64, hashData *ProposalH } return &types.Message{ - To: msig, - From: m.from, - Value: types.NewInt(0), + To: msig, + From: m.from, + Value: types.NewInt(0), Method: builtin0.MethodsMultisig.Approve, Params: enc, }, nil @@ -136,9 +136,9 @@ func (m message0) Cancel(msig address.Address, txID uint64, hashData *ProposalHa } return &types.Message{ - To: msig, - From: m.from, - Value: types.NewInt(0), + To: msig, + From: m.from, + Value: types.NewInt(0), Method: builtin0.MethodsMultisig.Cancel, Params: enc, }, nil diff --git a/chain/actors/builtin/multisig/multisig.go b/chain/actors/builtin/multisig/multisig.go index d8f6fabae..fd773f398 100644 --- a/chain/actors/builtin/multisig/multisig.go +++ b/chain/actors/builtin/multisig/multisig.go @@ -66,6 +66,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + switch av { + + case actors.Version0: + return make0(store, signers, threshold, startEpoch, unlockDuration, initialBalance) + + case actors.Version2: + return make2(store, signers, threshold, startEpoch, unlockDuration, initialBalance) + + case actors.Version3: + return make3(store, signers, threshold, startEpoch, unlockDuration, initialBalance) + + case actors.Version4: + return make4(store, signers, threshold, startEpoch, unlockDuration, initialBalance) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.MultisigActorCodeID, nil + + case actors.Version2: + return builtin2.MultisigActorCodeID, nil + + case actors.Version3: + return builtin3.MultisigActorCodeID, nil + + case actors.Version4: + return builtin4.MultisigActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -81,6 +120,7 @@ type State interface { transactions() (adt.Map, error) decodeTransaction(val *cbg.Deferred) (Transaction, error) + GetState() interface{} } type Transaction = msig4.Transaction diff --git a/chain/actors/builtin/multisig/state.go.template b/chain/actors/builtin/multisig/state.go.template index 2316aadba..067415533 100644 --- a/chain/actors/builtin/multisig/state.go.template +++ b/chain/actors/builtin/multisig/state.go.template @@ -31,6 +31,32 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + out := state{{.v}}{store: store} + out.State = msig{{.v}}.State{} + out.State.Signers = signers + out.State.NumApprovalsThreshold = threshold + out.State.StartEpoch = startEpoch + out.State.UnlockDuration = unlockDuration + out.State.InitialBalance = initialBalance + {{if (le .v 2)}} + em, err := adt{{.v}}.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State.PendingTxns = em + {{else}} + em, err := adt{{.v}}.StoreEmptyMap(store, builtin{{.v}}.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + + out.State.PendingTxns = em + {{end}} + return &out, nil +} + type state{{.v}} struct { msig{{.v}}.State store adt.Store @@ -95,3 +121,7 @@ func (s *state{{.v}}) decodeTransaction(val *cbg.Deferred) (Transaction, error) } return tx, nil } + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/multisig/temp b/chain/actors/builtin/multisig/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/multisig/v0.go b/chain/actors/builtin/multisig/v0.go index 20c1557b0..973ac9209 100644 --- a/chain/actors/builtin/multisig/v0.go +++ b/chain/actors/builtin/multisig/v0.go @@ -28,6 +28,25 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + out := state0{store: store} + out.State = msig0.State{} + out.State.Signers = signers + out.State.NumApprovalsThreshold = threshold + out.State.StartEpoch = startEpoch + out.State.UnlockDuration = unlockDuration + out.State.InitialBalance = initialBalance + + em, err := adt0.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State.PendingTxns = em + + return &out, nil +} + type state0 struct { msig0.State store adt.Store @@ -92,3 +111,7 @@ func (s *state0) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state0) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/multisig/v2.go b/chain/actors/builtin/multisig/v2.go index ef317f903..5b830e695 100644 --- a/chain/actors/builtin/multisig/v2.go +++ b/chain/actors/builtin/multisig/v2.go @@ -28,6 +28,25 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + out := state2{store: store} + out.State = msig2.State{} + out.State.Signers = signers + out.State.NumApprovalsThreshold = threshold + out.State.StartEpoch = startEpoch + out.State.UnlockDuration = unlockDuration + out.State.InitialBalance = initialBalance + + em, err := adt2.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State.PendingTxns = em + + return &out, nil +} + type state2 struct { msig2.State store adt.Store @@ -92,3 +111,7 @@ func (s *state2) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state2) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/multisig/v3.go b/chain/actors/builtin/multisig/v3.go index 8834e4553..c4a2791b7 100644 --- a/chain/actors/builtin/multisig/v3.go +++ b/chain/actors/builtin/multisig/v3.go @@ -30,6 +30,25 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + out := state3{store: store} + out.State = msig3.State{} + out.State.Signers = signers + out.State.NumApprovalsThreshold = threshold + out.State.StartEpoch = startEpoch + out.State.UnlockDuration = unlockDuration + out.State.InitialBalance = initialBalance + + em, err := adt3.StoreEmptyMap(store, builtin3.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + + out.State.PendingTxns = em + + return &out, nil +} + type state3 struct { msig3.State store adt.Store @@ -94,3 +113,7 @@ func (s *state3) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state3) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/multisig/v4.go b/chain/actors/builtin/multisig/v4.go index 9f9dc7573..a35a890f8 100644 --- a/chain/actors/builtin/multisig/v4.go +++ b/chain/actors/builtin/multisig/v4.go @@ -30,6 +30,25 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store, signers []address.Address, threshold uint64, startEpoch abi.ChainEpoch, unlockDuration abi.ChainEpoch, initialBalance abi.TokenAmount) (State, error) { + out := state4{store: store} + out.State = msig4.State{} + out.State.Signers = signers + out.State.NumApprovalsThreshold = threshold + out.State.StartEpoch = startEpoch + out.State.UnlockDuration = unlockDuration + out.State.InitialBalance = initialBalance + + em, err := adt4.StoreEmptyMap(store, builtin4.DefaultHamtBitwidth) + if err != nil { + return nil, err + } + + out.State.PendingTxns = em + + return &out, nil +} + type state4 struct { msig4.State store adt.Store @@ -94,3 +113,7 @@ func (s *state4) decodeTransaction(val *cbg.Deferred) (Transaction, error) { } return tx, nil } + +func (s *state4) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/paych/actor.go.template b/chain/actors/builtin/paych/actor.go.template index 3f68a5cfa..7699e76b6 100644 --- a/chain/actors/builtin/paych/actor.go.template +++ b/chain/actors/builtin/paych/actor.go.template @@ -42,6 +42,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.PaymentChannelActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + // State is an abstract version of payment channel state that works across // versions type State interface { @@ -62,6 +83,8 @@ type State interface { // Iterate lane states ForEachLaneState(cb func(idx uint64, dl LaneState) error) error + + GetState() interface{} } // LaneState is an abstract copy of the state of a single lane diff --git a/chain/actors/builtin/paych/message.go.template b/chain/actors/builtin/paych/message.go.template index 4a5ea2331..cb111d910 100644 --- a/chain/actors/builtin/paych/message.go.template +++ b/chain/actors/builtin/paych/message.go.template @@ -21,7 +21,7 @@ func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount) return nil, aerr } enc, aerr := actors.SerializeParams(&init{{.v}}.ExecParams{ - CodeCID: builtin{{.v}}.PaymentChannelActorCodeID, + CodeCID: builtin{{.v}}.PaymentChannelActorCodeID, ConstructorParams: params, }) if aerr != nil { @@ -29,9 +29,9 @@ func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount) } return &types.Message{ - To: init_.Address, - From: m.from, - Value: initialAmount, + To: init_.Address, + From: m.from, + Value: initialAmount, Method: builtin{{.v}}.MethodsInit.Exec, Params: enc, }, nil @@ -39,7 +39,7 @@ func (m message{{.v}}) Create(to address.Address, initialAmount abi.TokenAmount) func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret []byte) (*types.Message, error) { params, aerr := actors.SerializeParams(&paych{{.v}}.UpdateChannelStateParams{ - Sv: *sv, + Sv: *sv, Secret: secret, }) if aerr != nil { @@ -47,9 +47,9 @@ func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret [ } return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), Method: builtin{{.v}}.MethodsPaych.UpdateChannelState, Params: params, }, nil @@ -57,18 +57,18 @@ func (m message{{.v}}) Update(paych address.Address, sv *SignedVoucher, secret [ func (m message{{.v}}) Settle(paych address.Address) (*types.Message, error) { return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), Method: builtin{{.v}}.MethodsPaych.Settle, }, nil } func (m message{{.v}}) Collect(paych address.Address) (*types.Message, error) { return &types.Message{ - To: paych, - From: m.from, - Value: abi.NewTokenAmount(0), + To: paych, + From: m.from, + Value: abi.NewTokenAmount(0), Method: builtin{{.v}}.MethodsPaych.Collect, }, nil } diff --git a/chain/actors/builtin/paych/mock/mock.go b/chain/actors/builtin/paych/mock/mock.go index 3b82511ff..1ecfa1130 100644 --- a/chain/actors/builtin/paych/mock/mock.go +++ b/chain/actors/builtin/paych/mock/mock.go @@ -17,6 +17,10 @@ type mockState struct { lanes map[uint64]paych.LaneState } +func (ms *mockState) GetState() interface{} { + panic("implement me") +} + type mockLaneState struct { redeemed big.Int nonce uint64 diff --git a/chain/actors/builtin/paych/mock/temp b/chain/actors/builtin/paych/mock/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/paych/paych.go b/chain/actors/builtin/paych/paych.go index 30e4408d8..63638cda1 100644 --- a/chain/actors/builtin/paych/paych.go +++ b/chain/actors/builtin/paych/paych.go @@ -68,6 +68,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { + + case actors.Version0: + return make0(store) + + case actors.Version2: + return make2(store) + + case actors.Version3: + return make3(store) + + case actors.Version4: + return make4(store) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.PaymentChannelActorCodeID, nil + + case actors.Version2: + return builtin2.PaymentChannelActorCodeID, nil + + case actors.Version3: + return builtin3.PaymentChannelActorCodeID, nil + + case actors.Version4: + return builtin4.PaymentChannelActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + // State is an abstract version of payment channel state that works across // versions type State interface { @@ -88,6 +127,8 @@ type State interface { // Iterate lane states ForEachLaneState(cb func(idx uint64, dl LaneState) error) error + + GetState() interface{} } // LaneState is an abstract copy of the state of a single lane diff --git a/chain/actors/builtin/paych/state.go.template b/chain/actors/builtin/paych/state.go.template index b4b575a3e..3e41f5be5 100644 --- a/chain/actors/builtin/paych/state.go.template +++ b/chain/actors/builtin/paych/state.go.template @@ -24,6 +24,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store) (State, error) { + out := state{{.v}}{store: store} + out.State = paych{{.v}}.State{} + return &out, nil +} + type state{{.v}} struct { paych{{.v}}.State store adt.Store @@ -74,6 +80,10 @@ func (s *state{{.v}}) LaneCount() (uint64, error) { return lsamt.Length(), nil } +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} + // Iterate lane states func (s *state{{.v}}) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { // Get the lane state from the chain diff --git a/chain/actors/builtin/paych/temp b/chain/actors/builtin/paych/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/paych/v0.go b/chain/actors/builtin/paych/v0.go index 8e0e3434e..e9bc30e3d 100644 --- a/chain/actors/builtin/paych/v0.go +++ b/chain/actors/builtin/paych/v0.go @@ -24,6 +24,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store) (State, error) { + out := state0{store: store} + out.State = paych0.State{} + return &out, nil +} + type state0 struct { paych0.State store adt.Store @@ -74,6 +80,10 @@ func (s *state0) LaneCount() (uint64, error) { return lsamt.Length(), nil } +func (s *state0) GetState() interface{} { + return &s.State +} + // Iterate lane states func (s *state0) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { // Get the lane state from the chain diff --git a/chain/actors/builtin/paych/v2.go b/chain/actors/builtin/paych/v2.go index fbf4b9fde..400305e2f 100644 --- a/chain/actors/builtin/paych/v2.go +++ b/chain/actors/builtin/paych/v2.go @@ -24,6 +24,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store) (State, error) { + out := state2{store: store} + out.State = paych2.State{} + return &out, nil +} + type state2 struct { paych2.State store adt.Store @@ -74,6 +80,10 @@ func (s *state2) LaneCount() (uint64, error) { return lsamt.Length(), nil } +func (s *state2) GetState() interface{} { + return &s.State +} + // Iterate lane states func (s *state2) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { // Get the lane state from the chain diff --git a/chain/actors/builtin/paych/v3.go b/chain/actors/builtin/paych/v3.go index 14bb4cb61..1d7c2f94b 100644 --- a/chain/actors/builtin/paych/v3.go +++ b/chain/actors/builtin/paych/v3.go @@ -24,6 +24,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store) (State, error) { + out := state3{store: store} + out.State = paych3.State{} + return &out, nil +} + type state3 struct { paych3.State store adt.Store @@ -74,6 +80,10 @@ func (s *state3) LaneCount() (uint64, error) { return lsamt.Length(), nil } +func (s *state3) GetState() interface{} { + return &s.State +} + // Iterate lane states func (s *state3) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { // Get the lane state from the chain diff --git a/chain/actors/builtin/paych/v4.go b/chain/actors/builtin/paych/v4.go index cf37eea5c..b7d1e52a5 100644 --- a/chain/actors/builtin/paych/v4.go +++ b/chain/actors/builtin/paych/v4.go @@ -24,6 +24,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store) (State, error) { + out := state4{store: store} + out.State = paych4.State{} + return &out, nil +} + type state4 struct { paych4.State store adt.Store @@ -74,6 +80,10 @@ func (s *state4) LaneCount() (uint64, error) { return lsamt.Length(), nil } +func (s *state4) GetState() interface{} { + return &s.State +} + // Iterate lane states func (s *state4) ForEachLaneState(cb func(idx uint64, dl LaneState) error) error { // Get the lane state from the chain diff --git a/chain/actors/builtin/power/actor.go.template b/chain/actors/builtin/power/actor.go.template index 82f791e58..7ff3d0387 100644 --- a/chain/actors/builtin/power/actor.go.template +++ b/chain/actors/builtin/power/actor.go.template @@ -3,6 +3,7 @@ package power import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -40,6 +41,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.StoragePowerActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -47,6 +69,7 @@ type State interface { TotalPower() (Claim, error) TotalCommitted() (Claim, error) TotalPowerSmoothed() (builtin.FilterEstimate, error) + GetState() interface{} // MinerCounts returns the number of miners. Participating is the number // with power above the minimum miner threshold. @@ -57,6 +80,12 @@ type State interface { ForEachClaim(func(miner address.Address, claim Claim) error) error ClaimsChanged(State) (bool, error) + // Testing or genesis setup only + SetTotalQualityAdjPower(abi.StoragePower) error + SetTotalRawBytePower(abi.StoragePower) error + SetThisEpochQualityAdjPower(abi.StoragePower) error + SetThisEpochRawBytePower(abi.StoragePower) error + // Diff helpers. Used by Diff* functions internally. claims() (adt.Map, error) decodeClaim(*cbg.Deferred) (Claim, error) @@ -72,7 +101,7 @@ type Claim struct { func AddClaims(a Claim, b Claim) Claim { return Claim{ - RawBytePower: big.Add(a.RawBytePower, b.RawBytePower), + RawBytePower: big.Add(a.RawBytePower, b.RawBytePower), QualityAdjPower: big.Add(a.QualityAdjPower, b.QualityAdjPower), } } diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index bf530a21a..69ed6cf89 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -3,6 +3,7 @@ package power import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/actors" "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -66,6 +67,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { + + case actors.Version0: + return make0(store) + + case actors.Version2: + return make2(store) + + case actors.Version3: + return make3(store) + + case actors.Version4: + return make4(store) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.StoragePowerActorCodeID, nil + + case actors.Version2: + return builtin2.StoragePowerActorCodeID, nil + + case actors.Version3: + return builtin3.StoragePowerActorCodeID, nil + + case actors.Version4: + return builtin4.StoragePowerActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -73,6 +113,7 @@ type State interface { TotalPower() (Claim, error) TotalCommitted() (Claim, error) TotalPowerSmoothed() (builtin.FilterEstimate, error) + GetState() interface{} // MinerCounts returns the number of miners. Participating is the number // with power above the minimum miner threshold. @@ -83,6 +124,12 @@ type State interface { ForEachClaim(func(miner address.Address, claim Claim) error) error ClaimsChanged(State) (bool, error) + // Testing or genesis setup only + SetTotalQualityAdjPower(abi.StoragePower) error + SetTotalRawBytePower(abi.StoragePower) error + SetThisEpochQualityAdjPower(abi.StoragePower) error + SetThisEpochRawBytePower(abi.StoragePower) error + // Diff helpers. Used by Diff* functions internally. claims() (adt.Map, error) decodeClaim(*cbg.Deferred) (Claim, error) diff --git a/chain/actors/builtin/power/state.go.template b/chain/actors/builtin/power/state.go.template index 4cb904a1d..d0abba3fa 100644 --- a/chain/actors/builtin/power/state.go.template +++ b/chain/actors/builtin/power/state.go.template @@ -29,6 +29,32 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store) (State, error) { + out := state{{.v}}{store: store} + {{if (le .v 2)}} + em, err := adt{{.v}}.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + emm, err := adt{{.v}}.MakeEmptyMultimap(store).Root() + if err != nil { + return nil, err + } + + out.State = *power{{.v}}.ConstructState(em, emm) + {{else}} + s, err := power{{.v}}.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + {{end}} + + return &out, nil +} + type state{{.v}} struct { power{{.v}}.State store adt.Store @@ -40,7 +66,7 @@ func (s *state{{.v}}) TotalLocked() (abi.TokenAmount, error) { func (s *state{{.v}}) TotalPower() (Claim, error) { return Claim{ - RawBytePower: s.TotalRawBytePower, + RawBytePower: s.TotalRawBytePower, QualityAdjPower: s.TotalQualityAdjPower, }, nil } @@ -48,7 +74,7 @@ func (s *state{{.v}}) TotalPower() (Claim, error) { // Committed power to the network. Includes miners below the minimum threshold. func (s *state{{.v}}) TotalCommitted() (Claim, error) { return Claim{ - RawBytePower: s.TotalBytesCommitted, + RawBytePower: s.TotalBytesCommitted, QualityAdjPower: s.TotalQABytesCommitted, }, nil } @@ -64,7 +90,7 @@ func (s *state{{.v}}) MinerPower(addr address.Address) (Claim, bool, error) { return Claim{}, false, err } return Claim{ - RawBytePower: claim.RawBytePower, + RawBytePower: claim.RawBytePower, QualityAdjPower: claim.QualityAdjPower, }, ok, nil } @@ -116,7 +142,7 @@ func (s *state{{.v}}) ForEachClaim(cb func(miner address.Address, claim Claim) e return err } return cb(a, Claim{ - RawBytePower: claim.RawBytePower, + RawBytePower: claim.RawBytePower, QualityAdjPower: claim.QualityAdjPower, }) }) @@ -131,6 +157,30 @@ func (s *state{{.v}}) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other{{.v}}.State.Claims), nil } +func (s *state{{.v}}) SetTotalQualityAdjPower(p abi.StoragePower) error { + s.State.TotalQualityAdjPower = p + return nil +} + +func (s *state{{.v}}) SetTotalRawBytePower(p abi.StoragePower) error { + s.State.TotalRawBytePower = p + return nil +} + +func (s *state{{.v}}) SetThisEpochQualityAdjPower(p abi.StoragePower) error { + s.State.ThisEpochQualityAdjPower = p + return nil +} + +func (s *state{{.v}}) SetThisEpochRawBytePower(p abi.StoragePower) error { + s.State.ThisEpochRawBytePower = p + return nil +} + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} + func (s *state{{.v}}) claims() (adt.Map, error) { return adt{{.v}}.AsMap(s.store, s.Claims{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) } @@ -145,7 +195,7 @@ func (s *state{{.v}}) decodeClaim(val *cbg.Deferred) (Claim, error) { func fromV{{.v}}Claim(v{{.v}} power{{.v}}.Claim) Claim { return Claim{ - RawBytePower: v{{.v}}.RawBytePower, + RawBytePower: v{{.v}}.RawBytePower, QualityAdjPower: v{{.v}}.QualityAdjPower, } } diff --git a/chain/actors/builtin/power/temp b/chain/actors/builtin/power/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 91fad8c57..465d16c5c 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -26,6 +26,24 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store) (State, error) { + out := state0{store: store} + + em, err := adt0.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + emm, err := adt0.MakeEmptyMultimap(store).Root() + if err != nil { + return nil, err + } + + out.State = *power0.ConstructState(em, emm) + + return &out, nil +} + type state0 struct { power0.State store adt.Store @@ -128,6 +146,30 @@ func (s *state0) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other0.State.Claims), nil } +func (s *state0) SetTotalQualityAdjPower(p abi.StoragePower) error { + s.State.TotalQualityAdjPower = p + return nil +} + +func (s *state0) SetTotalRawBytePower(p abi.StoragePower) error { + s.State.TotalRawBytePower = p + return nil +} + +func (s *state0) SetThisEpochQualityAdjPower(p abi.StoragePower) error { + s.State.ThisEpochQualityAdjPower = p + return nil +} + +func (s *state0) SetThisEpochRawBytePower(p abi.StoragePower) error { + s.State.ThisEpochRawBytePower = p + return nil +} + +func (s *state0) GetState() interface{} { + return &s.State +} + func (s *state0) claims() (adt.Map, error) { return adt0.AsMap(s.store, s.Claims) } diff --git a/chain/actors/builtin/power/v2.go b/chain/actors/builtin/power/v2.go index 313160a78..606534cef 100644 --- a/chain/actors/builtin/power/v2.go +++ b/chain/actors/builtin/power/v2.go @@ -26,6 +26,24 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store) (State, error) { + out := state2{store: store} + + em, err := adt2.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + emm, err := adt2.MakeEmptyMultimap(store).Root() + if err != nil { + return nil, err + } + + out.State = *power2.ConstructState(em, emm) + + return &out, nil +} + type state2 struct { power2.State store adt.Store @@ -128,6 +146,30 @@ func (s *state2) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other2.State.Claims), nil } +func (s *state2) SetTotalQualityAdjPower(p abi.StoragePower) error { + s.State.TotalQualityAdjPower = p + return nil +} + +func (s *state2) SetTotalRawBytePower(p abi.StoragePower) error { + s.State.TotalRawBytePower = p + return nil +} + +func (s *state2) SetThisEpochQualityAdjPower(p abi.StoragePower) error { + s.State.ThisEpochQualityAdjPower = p + return nil +} + +func (s *state2) SetThisEpochRawBytePower(p abi.StoragePower) error { + s.State.ThisEpochRawBytePower = p + return nil +} + +func (s *state2) GetState() interface{} { + return &s.State +} + func (s *state2) claims() (adt.Map, error) { return adt2.AsMap(s.store, s.Claims) } diff --git a/chain/actors/builtin/power/v3.go b/chain/actors/builtin/power/v3.go index 2ef1e2808..3dec3c63e 100644 --- a/chain/actors/builtin/power/v3.go +++ b/chain/actors/builtin/power/v3.go @@ -28,6 +28,19 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store) (State, error) { + out := state3{store: store} + + s, err := power3.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state3 struct { power3.State store adt.Store @@ -130,6 +143,30 @@ func (s *state3) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other3.State.Claims), nil } +func (s *state3) SetTotalQualityAdjPower(p abi.StoragePower) error { + s.State.TotalQualityAdjPower = p + return nil +} + +func (s *state3) SetTotalRawBytePower(p abi.StoragePower) error { + s.State.TotalRawBytePower = p + return nil +} + +func (s *state3) SetThisEpochQualityAdjPower(p abi.StoragePower) error { + s.State.ThisEpochQualityAdjPower = p + return nil +} + +func (s *state3) SetThisEpochRawBytePower(p abi.StoragePower) error { + s.State.ThisEpochRawBytePower = p + return nil +} + +func (s *state3) GetState() interface{} { + return &s.State +} + func (s *state3) claims() (adt.Map, error) { return adt3.AsMap(s.store, s.Claims, builtin3.DefaultHamtBitwidth) } diff --git a/chain/actors/builtin/power/v4.go b/chain/actors/builtin/power/v4.go index 686550456..b73eedf5a 100644 --- a/chain/actors/builtin/power/v4.go +++ b/chain/actors/builtin/power/v4.go @@ -28,6 +28,19 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store) (State, error) { + out := state4{store: store} + + s, err := power4.ConstructState(store) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state4 struct { power4.State store adt.Store @@ -130,6 +143,30 @@ func (s *state4) ClaimsChanged(other State) (bool, error) { return !s.State.Claims.Equals(other4.State.Claims), nil } +func (s *state4) SetTotalQualityAdjPower(p abi.StoragePower) error { + s.State.TotalQualityAdjPower = p + return nil +} + +func (s *state4) SetTotalRawBytePower(p abi.StoragePower) error { + s.State.TotalRawBytePower = p + return nil +} + +func (s *state4) SetThisEpochQualityAdjPower(p abi.StoragePower) error { + s.State.ThisEpochQualityAdjPower = p + return nil +} + +func (s *state4) SetThisEpochRawBytePower(p abi.StoragePower) error { + s.State.ThisEpochRawBytePower = p + return nil +} + +func (s *state4) GetState() interface{} { + return &s.State +} + func (s *state4) claims() (adt.Map, error) { return adt4.AsMap(s.store, s.Claims, builtin4.DefaultHamtBitwidth) } diff --git a/chain/actors/builtin/reward/actor.go.template b/chain/actors/builtin/reward/actor.go.template index 81437d26f..89cdddaec 100644 --- a/chain/actors/builtin/reward/actor.go.template +++ b/chain/actors/builtin/reward/actor.go.template @@ -4,6 +4,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/ipfs/go-cid" + "github.com/filecoin-project/lotus/chain/actors" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/cbor" @@ -38,6 +39,27 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.StoragePower) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store, currRealizedPower) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.RewardActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -55,6 +77,7 @@ type State interface { InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error) PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error) + GetState() interface{} } type AwardBlockRewardParams = reward0.AwardBlockRewardParams diff --git a/chain/actors/builtin/reward/reward.go b/chain/actors/builtin/reward/reward.go index 1037cf741..c325cc7b6 100644 --- a/chain/actors/builtin/reward/reward.go +++ b/chain/actors/builtin/reward/reward.go @@ -2,6 +2,7 @@ package reward import ( "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/lotus/chain/actors" reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -64,6 +65,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.StoragePower) (State, error) { + switch av { + + case actors.Version0: + return make0(store, currRealizedPower) + + case actors.Version2: + return make2(store, currRealizedPower) + + case actors.Version3: + return make3(store, currRealizedPower) + + case actors.Version4: + return make4(store, currRealizedPower) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.RewardActorCodeID, nil + + case actors.Version2: + return builtin2.RewardActorCodeID, nil + + case actors.Version3: + return builtin3.RewardActorCodeID, nil + + case actors.Version4: + return builtin4.RewardActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -81,6 +121,7 @@ type State interface { InitialPledgeForPower(abi.StoragePower, abi.TokenAmount, *builtin.FilterEstimate, abi.TokenAmount) (abi.TokenAmount, error) PreCommitDepositForPower(builtin.FilterEstimate, abi.StoragePower) (abi.TokenAmount, error) + GetState() interface{} } type AwardBlockRewardParams = reward0.AwardBlockRewardParams diff --git a/chain/actors/builtin/reward/state.go.template b/chain/actors/builtin/reward/state.go.template index 1758d1413..67bfd5c85 100644 --- a/chain/actors/builtin/reward/state.go.template +++ b/chain/actors/builtin/reward/state.go.template @@ -23,6 +23,12 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store, currRealizedPower abi.StoragePower) (State, error) { + out := state{{.v}}{store: store} + out.State = *reward{{.v}}.ConstructState(currRealizedPower) + return &out, nil +} + type state{{.v}} struct { reward{{.v}}.State store adt.Store @@ -101,3 +107,7 @@ func (s *state{{.v}}) PreCommitDepositForPower(networkQAPower builtin.FilterEsti }, sectorWeight), nil } + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/reward/temp b/chain/actors/builtin/reward/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/reward/v0.go b/chain/actors/builtin/reward/v0.go index fe053cc16..cd098c151 100644 --- a/chain/actors/builtin/reward/v0.go +++ b/chain/actors/builtin/reward/v0.go @@ -23,6 +23,12 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store, currRealizedPower abi.StoragePower) (State, error) { + out := state0{store: store} + out.State = *reward0.ConstructState(currRealizedPower) + return &out, nil +} + type state0 struct { reward0.State store adt.Store @@ -83,3 +89,7 @@ func (s *state0) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state0) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/reward/v2.go b/chain/actors/builtin/reward/v2.go index 90621e467..08e9a7bc3 100644 --- a/chain/actors/builtin/reward/v2.go +++ b/chain/actors/builtin/reward/v2.go @@ -23,6 +23,12 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store, currRealizedPower abi.StoragePower) (State, error) { + out := state2{store: store} + out.State = *reward2.ConstructState(currRealizedPower) + return &out, nil +} + type state2 struct { reward2.State store adt.Store @@ -86,3 +92,7 @@ func (s *state2) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state2) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/reward/v3.go b/chain/actors/builtin/reward/v3.go index 926cc085b..fd9fa56e2 100644 --- a/chain/actors/builtin/reward/v3.go +++ b/chain/actors/builtin/reward/v3.go @@ -23,6 +23,12 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store, currRealizedPower abi.StoragePower) (State, error) { + out := state3{store: store} + out.State = *reward3.ConstructState(currRealizedPower) + return &out, nil +} + type state3 struct { reward3.State store adt.Store @@ -86,3 +92,7 @@ func (s *state3) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state3) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/reward/v4.go b/chain/actors/builtin/reward/v4.go index f034b0018..310ca04e8 100644 --- a/chain/actors/builtin/reward/v4.go +++ b/chain/actors/builtin/reward/v4.go @@ -23,6 +23,12 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store, currRealizedPower abi.StoragePower) (State, error) { + out := state4{store: store} + out.State = *reward4.ConstructState(currRealizedPower) + return &out, nil +} + type state4 struct { reward4.State store adt.Store @@ -86,3 +92,7 @@ func (s *state4) PreCommitDepositForPower(networkQAPower builtin.FilterEstimate, }, sectorWeight), nil } + +func (s *state4) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/system/actor.go.template b/chain/actors/builtin/system/actor.go.template new file mode 100644 index 000000000..925319970 --- /dev/null +++ b/chain/actors/builtin/system/actor.go.template @@ -0,0 +1,41 @@ +package system + +import ( + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors" + "golang.org/x/xerrors" + "github.com/ipfs/go-cid" + +{{range .versions}} + builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" +{{end}} +) + +var ( + Address = builtin{{.latestVersion}}.SystemActorAddr +) + +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.SystemActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +type State interface { + GetState() interface{} +} diff --git a/chain/actors/builtin/system/state.go.template b/chain/actors/builtin/system/state.go.template new file mode 100644 index 000000000..fa644f8c7 --- /dev/null +++ b/chain/actors/builtin/system/state.go.template @@ -0,0 +1,35 @@ +package system + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + system{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/system" +) + +var _ State = (*state{{.v}})(nil) + +func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { + out := state{{.v}}{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make{{.v}}(store adt.Store) (State, error) { + out := state{{.v}}{store: store} + out.State = system{{.v}}.State{} + return &out, nil +} + +type state{{.v}} struct { + system{{.v}}.State + store adt.Store +} + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/system/system.go b/chain/actors/builtin/system/system.go new file mode 100644 index 000000000..b4ced850f --- /dev/null +++ b/chain/actors/builtin/system/system.go @@ -0,0 +1,63 @@ +package system + +import ( + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/ipfs/go-cid" + "golang.org/x/xerrors" + + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + + builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" + + builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin" + + builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" +) + +var ( + Address = builtin4.SystemActorAddr +) + +func MakeState(store adt.Store, av actors.Version) (State, error) { + switch av { + + case actors.Version0: + return make0(store) + + case actors.Version2: + return make2(store) + + case actors.Version3: + return make3(store) + + case actors.Version4: + return make4(store) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.SystemActorCodeID, nil + + case actors.Version2: + return builtin2.SystemActorCodeID, nil + + case actors.Version3: + return builtin3.SystemActorCodeID, nil + + case actors.Version4: + return builtin4.SystemActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + +type State interface { + GetState() interface{} +} diff --git a/chain/actors/builtin/system/temp b/chain/actors/builtin/system/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/system/v0.go b/chain/actors/builtin/system/v0.go new file mode 100644 index 000000000..64c6f53d3 --- /dev/null +++ b/chain/actors/builtin/system/v0.go @@ -0,0 +1,35 @@ +package system + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + system0 "github.com/filecoin-project/specs-actors/actors/builtin/system" +) + +var _ State = (*state0)(nil) + +func load0(store adt.Store, root cid.Cid) (State, error) { + out := state0{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make0(store adt.Store) (State, error) { + out := state0{store: store} + out.State = system0.State{} + return &out, nil +} + +type state0 struct { + system0.State + store adt.Store +} + +func (s *state0) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/system/v2.go b/chain/actors/builtin/system/v2.go new file mode 100644 index 000000000..eb540891c --- /dev/null +++ b/chain/actors/builtin/system/v2.go @@ -0,0 +1,35 @@ +package system + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + system2 "github.com/filecoin-project/specs-actors/v2/actors/builtin/system" +) + +var _ State = (*state2)(nil) + +func load2(store adt.Store, root cid.Cid) (State, error) { + out := state2{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make2(store adt.Store) (State, error) { + out := state2{store: store} + out.State = system2.State{} + return &out, nil +} + +type state2 struct { + system2.State + store adt.Store +} + +func (s *state2) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/system/v3.go b/chain/actors/builtin/system/v3.go new file mode 100644 index 000000000..5b04e189e --- /dev/null +++ b/chain/actors/builtin/system/v3.go @@ -0,0 +1,35 @@ +package system + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + system3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/system" +) + +var _ State = (*state3)(nil) + +func load3(store adt.Store, root cid.Cid) (State, error) { + out := state3{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make3(store adt.Store) (State, error) { + out := state3{store: store} + out.State = system3.State{} + return &out, nil +} + +type state3 struct { + system3.State + store adt.Store +} + +func (s *state3) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/system/v4.go b/chain/actors/builtin/system/v4.go new file mode 100644 index 000000000..b6c924978 --- /dev/null +++ b/chain/actors/builtin/system/v4.go @@ -0,0 +1,35 @@ +package system + +import ( + "github.com/ipfs/go-cid" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + system4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/system" +) + +var _ State = (*state4)(nil) + +func load4(store adt.Store, root cid.Cid) (State, error) { + out := state4{store: store} + err := store.Get(store.Context(), root, &out) + if err != nil { + return nil, err + } + return &out, nil +} + +func make4(store adt.Store) (State, error) { + out := state4{store: store} + out.State = system4.State{} + return &out, nil +} + +type state4 struct { + system4.State + store adt.Store +} + +func (s *state4) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/temp b/chain/actors/builtin/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/verifreg/actor.go.template b/chain/actors/builtin/verifreg/actor.go.template index 22e809ccf..9ea8e155a 100644 --- a/chain/actors/builtin/verifreg/actor.go.template +++ b/chain/actors/builtin/verifreg/actor.go.template @@ -14,6 +14,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/types" ) @@ -40,6 +41,28 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, rootKeyAddress address.Address) (State, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return make{{.}}(store, rootKeyAddress) +{{end}} +} + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { +{{range .versions}} + case actors.Version{{.}}: + return builtin{{.}}.VerifiedRegistryActorCodeID, nil +{{end}} + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + + type State interface { cbor.Marshaler @@ -48,4 +71,5 @@ type State interface { VerifierDataCap(address.Address) (bool, abi.StoragePower, error) ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error + GetState() interface{} } diff --git a/chain/actors/builtin/verifreg/state.go.template b/chain/actors/builtin/verifreg/state.go.template index 244d20932..96bebe25f 100644 --- a/chain/actors/builtin/verifreg/state.go.template +++ b/chain/actors/builtin/verifreg/state.go.template @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors/adt" {{if (ge .v 3)}} builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin" -{{end}} verifreg{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/verifreg" +{{end}} verifreg{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/verifreg" adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt" ) @@ -24,6 +24,26 @@ func load{{.v}}(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make{{.v}}(store adt.Store, rootKeyAddress address.Address) (State, error) { + out := state{{.v}}{store: store} + {{if (le .v 2)}} + em, err := adt{{.v}}.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *verifreg{{.v}}.ConstructState(em, rootKeyAddress) + {{else}} + s, err := verifreg{{.v}}.ConstructState(store, rootKeyAddress) + if err != nil { + return nil, err + } + + out.State = *s + {{end}} + return &out, nil +} + type state{{.v}} struct { verifreg{{.v}}.State store adt.Store @@ -56,3 +76,7 @@ func (s *state{{.v}}) verifiedClients() (adt.Map, error) { func (s *state{{.v}}) verifiers() (adt.Map, error) { return adt{{.v}}.AsMap(s.store, s.Verifiers{{if (ge .v 3)}}, builtin{{.v}}.DefaultHamtBitwidth{{end}}) } + +func (s *state{{.v}}) GetState() interface{} { + return &s.State +} \ No newline at end of file diff --git a/chain/actors/builtin/verifreg/temp b/chain/actors/builtin/verifreg/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/builtin/verifreg/v0.go b/chain/actors/builtin/verifreg/v0.go index 0dc4696f4..e70b0e3c9 100644 --- a/chain/actors/builtin/verifreg/v0.go +++ b/chain/actors/builtin/verifreg/v0.go @@ -23,6 +23,19 @@ func load0(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make0(store adt.Store, rootKeyAddress address.Address) (State, error) { + out := state0{store: store} + + em, err := adt0.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *verifreg0.ConstructState(em, rootKeyAddress) + + return &out, nil +} + type state0 struct { verifreg0.State store adt.Store @@ -55,3 +68,7 @@ func (s *state0) verifiedClients() (adt.Map, error) { func (s *state0) verifiers() (adt.Map, error) { return adt0.AsMap(s.store, s.Verifiers) } + +func (s *state0) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/verifreg/v2.go b/chain/actors/builtin/verifreg/v2.go index a5ef84532..0bcbe0212 100644 --- a/chain/actors/builtin/verifreg/v2.go +++ b/chain/actors/builtin/verifreg/v2.go @@ -23,6 +23,19 @@ func load2(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make2(store adt.Store, rootKeyAddress address.Address) (State, error) { + out := state2{store: store} + + em, err := adt2.MakeEmptyMap(store).Root() + if err != nil { + return nil, err + } + + out.State = *verifreg2.ConstructState(em, rootKeyAddress) + + return &out, nil +} + type state2 struct { verifreg2.State store adt.Store @@ -55,3 +68,7 @@ func (s *state2) verifiedClients() (adt.Map, error) { func (s *state2) verifiers() (adt.Map, error) { return adt2.AsMap(s.store, s.Verifiers) } + +func (s *state2) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/verifreg/v3.go b/chain/actors/builtin/verifreg/v3.go index fb0c46d0c..32003ca3a 100644 --- a/chain/actors/builtin/verifreg/v3.go +++ b/chain/actors/builtin/verifreg/v3.go @@ -24,6 +24,19 @@ func load3(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make3(store adt.Store, rootKeyAddress address.Address) (State, error) { + out := state3{store: store} + + s, err := verifreg3.ConstructState(store, rootKeyAddress) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state3 struct { verifreg3.State store adt.Store @@ -56,3 +69,7 @@ func (s *state3) verifiedClients() (adt.Map, error) { func (s *state3) verifiers() (adt.Map, error) { return adt3.AsMap(s.store, s.Verifiers, builtin3.DefaultHamtBitwidth) } + +func (s *state3) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/verifreg/v4.go b/chain/actors/builtin/verifreg/v4.go index 2419ef758..b752e747b 100644 --- a/chain/actors/builtin/verifreg/v4.go +++ b/chain/actors/builtin/verifreg/v4.go @@ -24,6 +24,19 @@ func load4(store adt.Store, root cid.Cid) (State, error) { return &out, nil } +func make4(store adt.Store, rootKeyAddress address.Address) (State, error) { + out := state4{store: store} + + s, err := verifreg4.ConstructState(store, rootKeyAddress) + if err != nil { + return nil, err + } + + out.State = *s + + return &out, nil +} + type state4 struct { verifreg4.State store adt.Store @@ -56,3 +69,7 @@ func (s *state4) verifiedClients() (adt.Map, error) { func (s *state4) verifiers() (adt.Map, error) { return adt4.AsMap(s.store, s.Verifiers, builtin4.DefaultHamtBitwidth) } + +func (s *state4) GetState() interface{} { + return &s.State +} diff --git a/chain/actors/builtin/verifreg/verifreg.go b/chain/actors/builtin/verifreg/verifreg.go index 32f50a4ae..618907554 100644 --- a/chain/actors/builtin/verifreg/verifreg.go +++ b/chain/actors/builtin/verifreg/verifreg.go @@ -17,6 +17,7 @@ import ( builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/chain/types" @@ -66,6 +67,45 @@ func Load(store adt.Store, act *types.Actor) (State, error) { return nil, xerrors.Errorf("unknown actor code %s", act.Code) } +func MakeState(store adt.Store, av actors.Version, rootKeyAddress address.Address) (State, error) { + switch av { + + case actors.Version0: + return make0(store, rootKeyAddress) + + case actors.Version2: + return make2(store, rootKeyAddress) + + case actors.Version3: + return make3(store, rootKeyAddress) + + case actors.Version4: + return make4(store, rootKeyAddress) + + } + return nil, xerrors.Errorf("unknown actor version %d", av) +} + +func GetActorCodeID(av actors.Version) (cid.Cid, error) { + switch av { + + case actors.Version0: + return builtin0.VerifiedRegistryActorCodeID, nil + + case actors.Version2: + return builtin2.VerifiedRegistryActorCodeID, nil + + case actors.Version3: + return builtin3.VerifiedRegistryActorCodeID, nil + + case actors.Version4: + return builtin4.VerifiedRegistryActorCodeID, nil + + } + + return cid.Undef, xerrors.Errorf("unknown actor version %d", av) +} + type State interface { cbor.Marshaler @@ -74,4 +114,5 @@ type State interface { VerifierDataCap(address.Address) (bool, abi.StoragePower, error) ForEachVerifier(func(addr address.Address, dcap abi.StoragePower) error) error ForEachClient(func(addr address.Address, dcap abi.StoragePower) error) error + GetState() interface{} } diff --git a/chain/actors/policy/policy.go.template b/chain/actors/policy/policy.go.template index d395d7132..a1a47852b 100644 --- a/chain/actors/policy/policy.go.template +++ b/chain/actors/policy/policy.go.template @@ -8,20 +8,20 @@ import ( "github.com/filecoin-project/lotus/chain/actors" {{range .versions}} - {{if (ge . 2)}} builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" {{end}} + {{if (ge . 2)}} builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin" {{end}} market{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/market" miner{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/miner" verifreg{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/verifreg" {{if (eq . 0)}} power{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin/power" {{end}} - {{end}} + {{end}} - paych{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/paych" + paych{{.latestVersion}} "github.com/filecoin-project/specs-actors{{import .latestVersion}}actors/builtin/paych" ) const ( - ChainFinality = miner{{.latestVersion}}.ChainFinality - SealRandomnessLookback = ChainFinality - PaychSettleDelay = paych{{.latestVersion}}.SettleDelay + ChainFinality = miner{{.latestVersion}}.ChainFinality + SealRandomnessLookback = ChainFinality + PaychSettleDelay = paych{{.latestVersion}}.SettleDelay MaxPreCommitRandomnessLookback = builtin{{.latestVersion}}.EpochsInDay + SealRandomnessLookback ) @@ -29,13 +29,13 @@ const ( // This should only be used for testing. func SetSupportedProofTypes(types ...abi.RegisteredSealProof) { {{range .versions}} - {{if (eq . 0)}} - miner{{.}}.SupportedProofTypes = make(map[abi.RegisteredSealProof]struct{}, len(types)) - {{else}} - miner{{.}}.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - miner{{.}}.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) - miner{{.}}.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) - {{end}} + {{if (eq . 0)}} + miner{{.}}.SupportedProofTypes = make(map[abi.RegisteredSealProof]struct{}, len(types)) + {{else}} + miner{{.}}.PreCommitSealProofTypesV0 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + miner{{.}}.PreCommitSealProofTypesV7 = make(map[abi.RegisteredSealProof]struct{}, len(types)*2) + miner{{.}}.PreCommitSealProofTypesV8 = make(map[abi.RegisteredSealProof]struct{}, len(types)) + {{end}} {{end}} AddSupportedProofTypes(types...) @@ -51,15 +51,15 @@ func AddSupportedProofTypes(types ...abi.RegisteredSealProof) { // Set for all miner versions. {{range .versions}} - {{if (eq . 0)}} - miner{{.}}.SupportedProofTypes[t] = struct{}{} - {{else}} - miner{{.}}.PreCommitSealProofTypesV0[t] = struct{}{} - miner{{.}}.PreCommitSealProofTypesV7[t] = struct{}{} - miner{{.}}.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - miner{{.}}.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} - {{end}} - {{end}} + {{if (eq . 0)}} + miner{{.}}.SupportedProofTypes[t] = struct{}{} + {{else}} + miner{{.}}.PreCommitSealProofTypesV0[t] = struct{}{} + miner{{.}}.PreCommitSealProofTypesV7[t] = struct{}{} + miner{{.}}.PreCommitSealProofTypesV7[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} + miner{{.}}.PreCommitSealProofTypesV8[t+abi.RegisteredSealProof_StackedDrg2KiBV1_1] = struct{}{} + {{end}} + {{end}} } } @@ -67,9 +67,9 @@ func AddSupportedProofTypes(types ...abi.RegisteredSealProof) { // actors versions. Use for testing. func SetPreCommitChallengeDelay(delay abi.ChainEpoch) { // Set for all miner versions. - {{range .versions}} - miner{{.}}.PreCommitChallengeDelay = delay - {{end}} + {{range .versions}} + miner{{.}}.PreCommitChallengeDelay = delay + {{end}} } // TODO: this function shouldn't really exist. Instead, the API should expose the precommit delay. @@ -81,42 +81,42 @@ func GetPreCommitChallengeDelay() abi.ChainEpoch { // meet for leader election, across all actor versions. This should only be used // for testing. func SetConsensusMinerMinPower(p abi.StoragePower) { - {{range .versions}} - {{if (eq . 0)}} - power{{.}}.ConsensusMinerMinPower = p - {{else if (eq . 2)}} - for _, policy := range builtin{{.}}.SealProofPolicies { - policy.ConsensusMinerMinPower = p - } - {{else}} - for _, policy := range builtin{{.}}.PoStProofPolicies { - policy.ConsensusMinerMinPower = p - } - {{end}} - {{end}} + {{range .versions}} + {{if (eq . 0)}} + power{{.}}.ConsensusMinerMinPower = p + {{else if (eq . 2)}} + for _, policy := range builtin{{.}}.SealProofPolicies { + policy.ConsensusMinerMinPower = p + } + {{else}} + for _, policy := range builtin{{.}}.PoStProofPolicies { + policy.ConsensusMinerMinPower = p + } + {{end}} + {{end}} } // SetMinVerifiedDealSize sets the minimum size of a verified deal. This should // only be used for testing. func SetMinVerifiedDealSize(size abi.StoragePower) { - {{range .versions}} - verifreg{{.}}.MinVerifiedDealSize = size - {{end}} + {{range .versions}} + verifreg{{.}}.MinVerifiedDealSize = size + {{end}} } func GetMaxProveCommitDuration(ver actors.Version, t abi.RegisteredSealProof) abi.ChainEpoch { switch ver { {{range .versions}} - case actors.Version{{.}}: - {{if (eq . 0)}} - return miner{{.}}.MaxSealDuration[t] - {{else}} - return miner{{.}}.MaxProveCommitDuration[t] - {{end}} - {{end}} - default: - panic("unsupported actors version") - } + case actors.Version{{.}}: + {{if (eq . 0)}} + return miner{{.}}.MaxSealDuration[t] + {{else}} + return miner{{.}}.MaxProveCommitDuration[t] + {{end}} + {{end}} + default: + panic("unsupported actors version") + } } func DealProviderCollateralBounds( @@ -125,14 +125,14 @@ func DealProviderCollateralBounds( circulatingFil abi.TokenAmount, nwVer network.Version, ) (min, max abi.TokenAmount) { switch actors.VersionForNetwork(nwVer) { - {{range .versions}} - case actors.Version{{.}}: - {{if (eq . 0)}} - return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer) - {{else}} - return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) - {{end}} - {{end}} + {{range .versions}} + case actors.Version{{.}}: + {{if (eq . 0)}} + return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil, nwVer) + {{else}} + return market{{.}}.DealProviderCollateralBounds(size, verified, rawBytePower, qaPower, baselinePower, circulatingFil) + {{end}} + {{end}} default: panic("unsupported actors version") } @@ -145,15 +145,15 @@ func DealDurationBounds(pieceSize abi.PaddedPieceSize) (min, max abi.ChainEpoch) // Sets the challenge window and scales the proving period to match (such that // there are always 48 challenge windows in a proving period). func SetWPoStChallengeWindow(period abi.ChainEpoch) { - {{range .versions}} - miner{{.}}.WPoStChallengeWindow = period - miner{{.}}.WPoStProvingPeriod = period * abi.ChainEpoch(miner{{.}}.WPoStPeriodDeadlines) - {{if (ge . 3)}} - // by default, this is 2x finality which is 30 periods. - // scale it if we're scaling the challenge period. - miner{{.}}.WPoStDisputeWindow = period * 30 - {{end}} - {{end}} + {{range .versions}} + miner{{.}}.WPoStChallengeWindow = period + miner{{.}}.WPoStProvingPeriod = period * abi.ChainEpoch(miner{{.}}.WPoStPeriodDeadlines) + {{if (ge . 3)}} + // by default, this is 2x finality which is 30 periods. + // scale it if we're scaling the challenge period. + miner{{.}}.WPoStDisputeWindow = period * 30 + {{end}} + {{end}} } func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { @@ -161,7 +161,7 @@ func GetWinningPoStSectorSetLookback(nwVer network.Version) abi.ChainEpoch { return 10 } - // NOTE: if this ever changes, adjust it in a (*Miner).mineOne() logline as well + // NOTE: if this ever changes, adjust it in a (*Miner).mineOne() logline as well return ChainFinality } @@ -207,10 +207,10 @@ func GetSectorMaxLifetime(proof abi.RegisteredSealProof, nwVer network.Version) func GetAddressedSectorsMax(nwVer network.Version) int { switch actors.VersionForNetwork(nwVer) { - {{range .versions}} - case actors.Version{{.}}: - return miner{{.}}.AddressedSectorsMax - {{end}} + {{range .versions}} + case actors.Version{{.}}: + return miner{{.}}.AddressedSectorsMax + {{end}} default: panic("unsupported network version") } @@ -218,15 +218,15 @@ func GetAddressedSectorsMax(nwVer network.Version) int { func GetDeclarationsMax(nwVer network.Version) int { switch actors.VersionForNetwork(nwVer) { - {{range .versions}} - case actors.Version{{.}}: - {{if (eq . 0)}} - // TODO: Should we instead panic here since the concept doesn't exist yet? - return miner{{.}}.AddressedPartitionsMax - {{else}} - return miner{{.}}.DeclarationsMax - {{end}} - {{end}} + {{range .versions}} + case actors.Version{{.}}: + {{if (eq . 0)}} + // TODO: Should we instead panic here since the concept doesn't exist yet? + return miner{{.}}.AddressedPartitionsMax + {{else}} + return miner{{.}}.DeclarationsMax + {{end}} + {{end}} default: panic("unsupported network version") } diff --git a/chain/actors/policy/temp b/chain/actors/policy/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/temp b/chain/actors/temp new file mode 100644 index 000000000..e69de29bb diff --git a/chain/actors/version.go b/chain/actors/version.go index bd7b708bd..a8b4c62b2 100644 --- a/chain/actors/version.go +++ b/chain/actors/version.go @@ -8,6 +8,10 @@ import ( type Version int +var LatestVersion = 4 + +var Versions = []int{0, 2, 3, LatestVersion} + const ( Version0 Version = 0 Version2 Version = 2 diff --git a/chain/gen/gen.go b/chain/gen/gen.go index d06c755fa..5c33ac4d7 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -9,6 +9,8 @@ import ( "sync/atomic" "time" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" @@ -197,6 +199,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) { sys := vm.Syscalls(&genFakeVerifier{}) tpl := genesis.Template{ + NetworkVersion: network.Version0, Accounts: []genesis.Actor{ { Type: genesis.TAccount, diff --git a/chain/gen/genesis/f00_system.go b/chain/gen/genesis/f00_system.go index 015dfac4a..d1dd203b6 100644 --- a/chain/gen/genesis/f00_system.go +++ b/chain/gen/genesis/f00_system.go @@ -3,27 +3,36 @@ package genesis import ( "context" - "github.com/filecoin-project/specs-actors/actors/builtin/system" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/system" - "github.com/filecoin-project/specs-actors/actors/builtin" cbor "github.com/ipfs/go-ipld-cbor" bstore "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/types" ) -func SetupSystemActor(bs bstore.Blockstore) (*types.Actor, error) { - var st system.State +func SetupSystemActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { cst := cbor.NewCborStore(bs) + st, err := system.MakeState(adt.WrapStore(ctx, cst), av) + if err != nil { + return nil, err + } - statecid, err := cst.Put(context.TODO(), &st) + statecid, err := cst.Put(ctx, st.GetState()) + if err != nil { + return nil, err + } + + actcid, err := system.GetActorCodeID(av) if err != nil { return nil, err } act := &types.Actor{ - Code: builtin.SystemActorCodeID, + Code: actcid, Head: statecid, } diff --git a/chain/gen/genesis/f01_init.go b/chain/gen/genesis/f01_init.go index 718eb4480..88d409221 100644 --- a/chain/gen/genesis/f01_init.go +++ b/chain/gen/genesis/f01_init.go @@ -5,13 +5,15 @@ import ( "encoding/json" "fmt" + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/specs-actors/actors/builtin" "github.com/filecoin-project/specs-actors/actors/util/adt" - init_ "github.com/filecoin-project/specs-actors/actors/builtin/init" cbor "github.com/ipfs/go-ipld-cbor" cbg "github.com/whyrusleeping/cbor-gen" "golang.org/x/xerrors" @@ -21,17 +23,25 @@ import ( "github.com/filecoin-project/lotus/genesis" ) -func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesis.Actor, rootVerifier genesis.Actor, remainder genesis.Actor) (int64, *types.Actor, map[address.Address]address.Address, error) { +func SetupInitActor(ctx context.Context, bs bstore.Blockstore, netname string, initialActors []genesis.Actor, rootVerifier genesis.Actor, remainder genesis.Actor, av actors.Version) (int64, *types.Actor, map[address.Address]address.Address, error) { if len(initialActors) > MaxAccounts { return 0, nil, nil, xerrors.New("too many initial actors") } - var ias init_.State - ias.NextID = MinerStart - ias.NetworkName = netname + cst := cbor.NewCborStore(bs) + ist, err := init_.MakeState(adt.WrapStore(ctx, cst), av, netname) + if err != nil { + return 0, nil, nil, err + } - store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs)) - amap := adt.MakeEmptyMap(store) + if err = ist.SetNextID(MinerStart); err != nil { + return 0, nil, nil, err + } + + amap, err := ist.AddressMap() + if err != nil { + return 0, nil, nil, err + } keyToId := map[address.Address]address.Address{} counter := int64(AccountStart) @@ -155,15 +165,23 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi if err != nil { return 0, nil, nil, err } - ias.AddressMap = amapaddr - statecid, err := store.Put(store.Context(), &ias) + if err = ist.SetAddressMap(amapaddr); err != nil { + return 0, nil, nil, err + } + + statecid, err := cst.Put(ctx, ist.GetState()) + if err != nil { + return 0, nil, nil, err + } + + actcid, err := init_.GetActorCodeID(av) if err != nil { return 0, nil, nil, err } act := &types.Actor{ - Code: builtin.InitActorCodeID, + Code: actcid, Head: statecid, } diff --git a/chain/gen/genesis/f02_reward.go b/chain/gen/genesis/f02_reward.go index e218da6fe..c8f479722 100644 --- a/chain/gen/genesis/f02_reward.go +++ b/chain/gen/genesis/f02_reward.go @@ -3,10 +3,12 @@ package genesis import ( "context" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" + "github.com/filecoin-project/go-state-types/big" - "github.com/filecoin-project/specs-actors/actors/builtin" - reward0 "github.com/filecoin-project/specs-actors/actors/builtin/reward" cbor "github.com/ipfs/go-ipld-cbor" bstore "github.com/filecoin-project/lotus/blockstore" @@ -14,19 +16,28 @@ import ( "github.com/filecoin-project/lotus/chain/types" ) -func SetupRewardActor(bs bstore.Blockstore, qaPower big.Int) (*types.Actor, error) { +func SetupRewardActor(ctx context.Context, bs bstore.Blockstore, qaPower big.Int, av actors.Version) (*types.Actor, error) { cst := cbor.NewCborStore(bs) - - st := reward0.ConstructState(qaPower) - - hcid, err := cst.Put(context.TODO(), st) + rst, err := reward.MakeState(adt.WrapStore(ctx, cst), av, qaPower) if err != nil { return nil, err } - return &types.Actor{ - Code: builtin.RewardActorCodeID, + statecid, err := cst.Put(ctx, rst.GetState()) + if err != nil { + return nil, err + } + + actcid, err := reward.GetActorCodeID(av) + if err != nil { + return nil, err + } + + act := &types.Actor{ + Code: actcid, Balance: types.BigInt{Int: build.InitialRewardBalance}, - Head: hcid, - }, nil + Head: statecid, + } + + return act, nil } diff --git a/chain/gen/genesis/f03_cron.go b/chain/gen/genesis/f03_cron.go index dd43a59a4..c6fd2422a 100644 --- a/chain/gen/genesis/f03_cron.go +++ b/chain/gen/genesis/f03_cron.go @@ -3,27 +3,37 @@ package genesis import ( "context" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/cron" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/cron" + cbor "github.com/ipfs/go-ipld-cbor" bstore "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/types" ) -func SetupCronActor(bs bstore.Blockstore) (*types.Actor, error) { +func SetupCronActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { cst := cbor.NewCborStore(bs) - cas := cron.ConstructState(cron.BuiltInEntries()) - - stcid, err := cst.Put(context.TODO(), cas) + st, err := cron.MakeState(adt.WrapStore(ctx, cbor.NewCborStore(bs)), av) if err != nil { return nil, err } - return &types.Actor{ - Code: builtin.CronActorCodeID, - Head: stcid, - Nonce: 0, - Balance: types.NewInt(0), - }, nil + statecid, err := cst.Put(ctx, st.GetState()) + if err != nil { + return nil, err + } + + actcid, err := cron.GetActorCodeID(av) + if err != nil { + return nil, err + } + + act := &types.Actor{ + Code: actcid, + Head: statecid, + } + + return act, nil } diff --git a/chain/gen/genesis/f04_power.go b/chain/gen/genesis/f04_power.go index ed349c18b..6fe4d75c0 100644 --- a/chain/gen/genesis/f04_power.go +++ b/chain/gen/genesis/f04_power.go @@ -3,44 +3,39 @@ package genesis import ( "context" - "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/filecoin-project/lotus/chain/actors/builtin/power" + + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/specs-actors/actors/util/adt" - power0 "github.com/filecoin-project/specs-actors/actors/builtin/power" cbor "github.com/ipfs/go-ipld-cbor" bstore "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/types" ) -func SetupStoragePowerActor(bs bstore.Blockstore) (*types.Actor, error) { - store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs)) - emptyMap, err := adt.MakeEmptyMap(store).Root() +func SetupStoragePowerActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { + + cst := cbor.NewCborStore(bs) + pst, err := power.MakeState(adt.WrapStore(ctx, cbor.NewCborStore(bs)), av) if err != nil { return nil, err } - multiMap, err := adt.AsMultimap(store, emptyMap) + statecid, err := cst.Put(ctx, pst.GetState()) if err != nil { return nil, err } - emptyMultiMap, err := multiMap.Root() + actcid, err := power.GetActorCodeID(av) if err != nil { return nil, err } - sms := power0.ConstructState(emptyMap, emptyMultiMap) - - stcid, err := store.Put(store.Context(), sms) - if err != nil { - return nil, err + act := &types.Actor{ + Code: actcid, + Head: statecid, } - return &types.Actor{ - Code: builtin.StoragePowerActorCodeID, - Head: stcid, - Nonce: 0, - Balance: types.NewInt(0), - }, nil + return act, nil } diff --git a/chain/gen/genesis/f05_market.go b/chain/gen/genesis/f05_market.go index f7ac26f43..5c39ef38f 100644 --- a/chain/gen/genesis/f05_market.go +++ b/chain/gen/genesis/f05_market.go @@ -3,38 +3,36 @@ package genesis import ( "context" - "github.com/filecoin-project/specs-actors/actors/builtin" - "github.com/filecoin-project/specs-actors/actors/builtin/market" - "github.com/filecoin-project/specs-actors/actors/util/adt" + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/market" + cbor "github.com/ipfs/go-ipld-cbor" bstore "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/types" ) -func SetupStorageMarketActor(bs bstore.Blockstore) (*types.Actor, error) { - store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs)) - - a, err := adt.MakeEmptyArray(store).Root() - if err != nil { - return nil, err - } - h, err := adt.MakeEmptyMap(store).Root() +func SetupStorageMarketActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { + cst := cbor.NewCborStore(bs) + mst, err := market.MakeState(adt.WrapStore(ctx, cbor.NewCborStore(bs)), av) if err != nil { return nil, err } - sms := market.ConstructState(a, h, h) + statecid, err := cst.Put(ctx, mst.GetState()) + if err != nil { + return nil, err + } - stcid, err := store.Put(store.Context(), sms) + actcid, err := market.GetActorCodeID(av) if err != nil { return nil, err } act := &types.Actor{ - Code: builtin.StorageMarketActorCodeID, - Head: stcid, - Balance: types.NewInt(0), + Code: actcid, + Head: statecid, } return act, nil diff --git a/chain/gen/genesis/f06_vreg.go b/chain/gen/genesis/f06_vreg.go index 1ba8abede..d8f5ee2a0 100644 --- a/chain/gen/genesis/f06_vreg.go +++ b/chain/gen/genesis/f06_vreg.go @@ -3,11 +3,13 @@ package genesis import ( "context" + "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" + + "github.com/filecoin-project/lotus/chain/actors" + "github.com/filecoin-project/go-address" cbor "github.com/ipfs/go-ipld-cbor" - "github.com/filecoin-project/specs-actors/actors/builtin" - verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" "github.com/filecoin-project/specs-actors/actors/util/adt" bstore "github.com/filecoin-project/lotus/blockstore" @@ -26,25 +28,26 @@ func init() { RootVerifierID = idk } -func SetupVerifiedRegistryActor(bs bstore.Blockstore) (*types.Actor, error) { - store := adt.WrapStore(context.TODO(), cbor.NewCborStore(bs)) - - h, err := adt.MakeEmptyMap(store).Root() +func SetupVerifiedRegistryActor(ctx context.Context, bs bstore.Blockstore, av actors.Version) (*types.Actor, error) { + cst := cbor.NewCborStore(bs) + vst, err := verifreg.MakeState(adt.WrapStore(ctx, cbor.NewCborStore(bs)), av, RootVerifierID) if err != nil { return nil, err } - sms := verifreg0.ConstructState(h, RootVerifierID) + statecid, err := cst.Put(ctx, vst.GetState()) + if err != nil { + return nil, err + } - stcid, err := store.Put(store.Context(), sms) + actcid, err := verifreg.GetActorCodeID(av) if err != nil { return nil, err } act := &types.Actor{ - Code: builtin.VerifiedRegistryActorCodeID, - Head: stcid, - Balance: types.NewInt(0), + Code: actcid, + Head: statecid, } return act, nil diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index 4b86db550..94badbbfb 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -6,6 +6,32 @@ import ( "encoding/json" "fmt" + builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" + verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" + adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" + + "github.com/filecoin-project/go-state-types/network" + + "github.com/filecoin-project/lotus/chain/actors/builtin/multisig" + + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/account" + + "github.com/filecoin-project/lotus/chain/actors" + + "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" + + "github.com/filecoin-project/lotus/chain/actors/builtin/market" + + "github.com/filecoin-project/lotus/chain/actors/builtin/power" + + "github.com/filecoin-project/lotus/chain/actors/builtin/cron" + + init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" + "github.com/filecoin-project/lotus/chain/actors/builtin/reward" + + "github.com/filecoin-project/lotus/chain/actors/builtin/system" + "github.com/filecoin-project/lotus/chain/actors/builtin" "github.com/filecoin-project/lotus/journal" @@ -21,11 +47,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" - builtin0 "github.com/filecoin-project/specs-actors/actors/builtin" - account0 "github.com/filecoin-project/specs-actors/actors/builtin/account" - multisig0 "github.com/filecoin-project/specs-actors/actors/builtin/multisig" - verifreg0 "github.com/filecoin-project/specs-actors/actors/builtin/verifreg" - adt0 "github.com/filecoin-project/specs-actors/actors/util/adt" bstore "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/build" @@ -118,94 +139,92 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, xerrors.Errorf("putting empty object: %w", err) } - state, err := state.NewStateTree(cst, types.StateTreeVersion0) + sv, err := state.VersionForNetwork(template.NetworkVersion) + if err != nil { + return nil, nil, xerrors.Errorf("getting state tree version: %w", err) + } + + state, err := state.NewStateTree(cst, sv) if err != nil { return nil, nil, xerrors.Errorf("making new state tree: %w", err) } + av := actors.VersionForNetwork(template.NetworkVersion) + // Create system actor - sysact, err := SetupSystemActor(bs) + sysact, err := SetupSystemActor(ctx, bs, av) if err != nil { - return nil, nil, xerrors.Errorf("setup init actor: %w", err) + return nil, nil, xerrors.Errorf("setup system actor: %w", err) } - if err := state.SetActor(builtin0.SystemActorAddr, sysact); err != nil { - return nil, nil, xerrors.Errorf("set init actor: %w", err) + if err := state.SetActor(system.Address, sysact); err != nil { + return nil, nil, xerrors.Errorf("set system actor: %w", err) } // Create init actor - idStart, initact, keyIDs, err := SetupInitActor(bs, template.NetworkName, template.Accounts, template.VerifregRootKey, template.RemainderAccount) + idStart, initact, keyIDs, err := SetupInitActor(ctx, bs, template.NetworkName, template.Accounts, template.VerifregRootKey, template.RemainderAccount, av) if err != nil { return nil, nil, xerrors.Errorf("setup init actor: %w", err) } - if err := state.SetActor(builtin0.InitActorAddr, initact); err != nil { + if err := state.SetActor(init_.Address, initact); err != nil { return nil, nil, xerrors.Errorf("set init actor: %w", err) } // Setup reward - // RewardActor's state is overrwritten by SetupStorageMiners - rewact, err := SetupRewardActor(bs, big.Zero()) + // RewardActor's state is overwritten by SetupStorageMiners, but needs to exist for miner creation messages + rewact, err := SetupRewardActor(ctx, bs, big.Zero(), av) if err != nil { - return nil, nil, xerrors.Errorf("setup init actor: %w", err) + return nil, nil, xerrors.Errorf("setup reward actor: %w", err) } - err = state.SetActor(builtin0.RewardActorAddr, rewact) + err = state.SetActor(reward.Address, rewact) if err != nil { - return nil, nil, xerrors.Errorf("set network account actor: %w", err) + return nil, nil, xerrors.Errorf("set reward actor: %w", err) } // Setup cron - cronact, err := SetupCronActor(bs) + cronact, err := SetupCronActor(ctx, bs, av) if err != nil { return nil, nil, xerrors.Errorf("setup cron actor: %w", err) } - if err := state.SetActor(builtin0.CronActorAddr, cronact); err != nil { + if err := state.SetActor(cron.Address, cronact); err != nil { return nil, nil, xerrors.Errorf("set cron actor: %w", err) } // Create empty power actor - spact, err := SetupStoragePowerActor(bs) + spact, err := SetupStoragePowerActor(ctx, bs, av) if err != nil { - return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) + return nil, nil, xerrors.Errorf("setup storage power actor: %w", err) } - if err := state.SetActor(builtin0.StoragePowerActorAddr, spact); err != nil { - return nil, nil, xerrors.Errorf("set storage market actor: %w", err) + if err := state.SetActor(power.Address, spact); err != nil { + return nil, nil, xerrors.Errorf("set storage power actor: %w", err) } // Create empty market actor - marketact, err := SetupStorageMarketActor(bs) + marketact, err := SetupStorageMarketActor(ctx, bs, av) if err != nil { return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) } - if err := state.SetActor(builtin0.StorageMarketActorAddr, marketact); err != nil { - return nil, nil, xerrors.Errorf("set market actor: %w", err) + if err := state.SetActor(market.Address, marketact); err != nil { + return nil, nil, xerrors.Errorf("set storage market actor: %w", err) } // Create verified registry - verifact, err := SetupVerifiedRegistryActor(bs) + verifact, err := SetupVerifiedRegistryActor(ctx, bs, av) if err != nil { - return nil, nil, xerrors.Errorf("setup storage market actor: %w", err) + return nil, nil, xerrors.Errorf("setup verified registry market actor: %w", err) } - if err := state.SetActor(builtin0.VerifiedRegistryActorAddr, verifact); err != nil { - return nil, nil, xerrors.Errorf("set market actor: %w", err) + if err := state.SetActor(verifreg.Address, verifact); err != nil { + return nil, nil, xerrors.Errorf("set verified registry actor: %w", err) } - burntRoot, err := cst.Put(ctx, &account0.State{ - Address: builtin0.BurntFundsActorAddr, - }) + bact, err := makeAccountActor(ctx, cst, av, builtin.BurntFundsActorAddr, big.Zero()) if err != nil { - return nil, nil, xerrors.Errorf("failed to setup burnt funds actor state: %w", err) + return nil, nil, xerrors.Errorf("setup burnt funds actor state: %w", err) } - - // Setup burnt-funds - err = state.SetActor(builtin0.BurntFundsActorAddr, &types.Actor{ - Code: builtin0.AccountActorCodeID, - Balance: types.NewInt(0), - Head: burntRoot, - }) - if err != nil { - return nil, nil, xerrors.Errorf("set burnt funds account actor: %w", err) + if err := state.SetActor(builtin.BurntFundsActorAddr, bact); err != nil { + return nil, nil, xerrors.Errorf("set burnt funds actor: %w", err) } // Create accounts @@ -213,7 +232,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge switch info.Type { case genesis.TAccount: - if err := createAccountActor(ctx, cst, state, info, keyIDs); err != nil { + if err := createAccountActor(ctx, cst, state, info, keyIDs, av); err != nil { return nil, nil, xerrors.Errorf("failed to create account actor: %w", err) } @@ -225,7 +244,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge } idStart++ - if err := createMultisigAccount(ctx, bs, cst, state, ida, info, keyIDs); err != nil { + if err := createMultisigAccount(ctx, cst, state, ida, info, keyIDs, av); err != nil { return nil, nil, err } default: @@ -240,26 +259,21 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err := json.Unmarshal(template.VerifregRootKey.Meta, &ainfo); err != nil { return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) } - st, err := cst.Put(ctx, &account0.State{Address: ainfo.Owner}) - if err != nil { - return nil, nil, err - } _, ok := keyIDs[ainfo.Owner] if ok { return nil, nil, fmt.Errorf("rootkey account has already been declared, cannot be assigned 80: %s", ainfo.Owner) } - err = state.SetActor(builtin.RootVerifierAddress, &types.Actor{ - Code: builtin0.AccountActorCodeID, - Balance: template.VerifregRootKey.Balance, - Head: st, - }) + vact, err := makeAccountActor(ctx, cst, av, ainfo.Owner, template.VerifregRootKey.Balance) if err != nil { - return nil, nil, xerrors.Errorf("setting verifreg rootkey account: %w", err) + return nil, nil, xerrors.Errorf("setup verifreg rootkey account state: %w", err) + } + if err = state.SetActor(builtin.RootVerifierAddress, vact); err != nil { + return nil, nil, xerrors.Errorf("set verifreg rootkey account actor: %w", err) } case genesis.TMultisig: - if err = createMultisigAccount(ctx, bs, cst, state, builtin.RootVerifierAddress, template.VerifregRootKey, keyIDs); err != nil { + if err = createMultisigAccount(ctx, cst, state, builtin.RootVerifierAddress, template.VerifregRootKey, keyIDs, av); err != nil { return nil, nil, xerrors.Errorf("failed to set up verified registry signer: %w", err) } default: @@ -288,18 +302,13 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, err } - verifierState, err := cst.Put(ctx, &account0.State{Address: verifierAd}) + verifierAct, err := makeAccountActor(ctx, cst, av, verifierAd, big.Zero()) if err != nil { - return nil, nil, err + return nil, nil, xerrors.Errorf("setup first verifier state: %w", err) } - err = state.SetActor(verifierId, &types.Actor{ - Code: builtin0.AccountActorCodeID, - Balance: types.NewInt(0), - Head: verifierState, - }) - if err != nil { - return nil, nil, xerrors.Errorf("setting account from actmap: %w", err) + if err = state.SetActor(verifierId, verifierAct); err != nil { + return nil, nil, xerrors.Errorf("set first verifier actor: %w", err) } totalFilAllocated := big.Zero() @@ -337,13 +346,13 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge } keyIDs[ainfo.Owner] = builtin.ReserveAddress - err = createAccountActor(ctx, cst, state, template.RemainderAccount, keyIDs) + err = createAccountActor(ctx, cst, state, template.RemainderAccount, keyIDs, av) if err != nil { return nil, nil, xerrors.Errorf("creating remainder acct: %w", err) } case genesis.TMultisig: - if err = createMultisigAccount(ctx, bs, cst, state, builtin.ReserveAddress, template.RemainderAccount, keyIDs); err != nil { + if err = createMultisigAccount(ctx, cst, state, builtin.ReserveAddress, template.RemainderAccount, keyIDs, av); err != nil { return nil, nil, xerrors.Errorf("failed to set up remainder: %w", err) } default: @@ -353,12 +362,38 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return state, keyIDs, nil } -func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.StateTree, info genesis.Actor, keyIDs map[address.Address]address.Address) error { +func makeAccountActor(ctx context.Context, cst cbor.IpldStore, av actors.Version, addr address.Address, bal types.BigInt) (*types.Actor, error) { + ast, err := account.MakeState(adt.WrapStore(ctx, cst), av, addr) + if err != nil { + return nil, err + } + + statecid, err := cst.Put(ctx, ast.GetState()) + if err != nil { + return nil, err + } + + actcid, err := account.GetActorCodeID(av) + if err != nil { + return nil, err + } + + act := &types.Actor{ + Code: actcid, + Head: statecid, + Balance: bal, + } + + return act, nil +} + +func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.StateTree, info genesis.Actor, keyIDs map[address.Address]address.Address, av actors.Version) error { var ainfo genesis.AccountMeta if err := json.Unmarshal(info.Meta, &ainfo); err != nil { return xerrors.Errorf("unmarshaling account meta: %w", err) } - st, err := cst.Put(ctx, &account0.State{Address: ainfo.Owner}) + + aa, err := makeAccountActor(ctx, cst, av, ainfo.Owner, info.Balance) if err != nil { return err } @@ -368,18 +403,14 @@ func createAccountActor(ctx context.Context, cst cbor.IpldStore, state *state.St return fmt.Errorf("no registered ID for account actor: %s", ainfo.Owner) } - err = state.SetActor(ida, &types.Actor{ - Code: builtin0.AccountActorCodeID, - Balance: info.Balance, - Head: st, - }) + err = state.SetActor(ida, aa) if err != nil { return xerrors.Errorf("setting account from actmap: %w", err) } return nil } -func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore, state *state.StateTree, ida address.Address, info genesis.Actor, keyIDs map[address.Address]address.Address) error { +func createMultisigAccount(ctx context.Context, cst cbor.IpldStore, state *state.StateTree, ida address.Address, info genesis.Actor, keyIDs map[address.Address]address.Address, av actors.Version) error { if info.Type != genesis.TMultisig { return fmt.Errorf("can only call createMultisigAccount with multisig Actor info") } @@ -387,10 +418,6 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I if err := json.Unmarshal(info.Meta, &ainfo); err != nil { return xerrors.Errorf("unmarshaling account meta: %w", err) } - pending, err := adt0.MakeEmptyMap(adt0.WrapStore(ctx, cst)).Root() - if err != nil { - return xerrors.Errorf("failed to create empty map: %v", err) - } var signers []address.Address @@ -407,44 +434,45 @@ func createMultisigAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.I continue } - st, err := cst.Put(ctx, &account0.State{Address: e}) + aa, err := makeAccountActor(ctx, cst, av, e, big.Zero()) if err != nil { return err } - err = state.SetActor(idAddress, &types.Actor{ - Code: builtin0.AccountActorCodeID, - Balance: types.NewInt(0), - Head: st, - }) - if err != nil { + + if err = state.SetActor(idAddress, aa); err != nil { return xerrors.Errorf("setting account from actmap: %w", err) } signers = append(signers, idAddress) } - st, err := cst.Put(ctx, &multisig0.State{ - Signers: signers, - NumApprovalsThreshold: uint64(ainfo.Threshold), - StartEpoch: abi.ChainEpoch(ainfo.VestingStart), - UnlockDuration: abi.ChainEpoch(ainfo.VestingDuration), - PendingTxns: pending, - InitialBalance: info.Balance, - }) + mst, err := multisig.MakeState(adt.WrapStore(ctx, cst), av, signers, uint64(ainfo.Threshold), abi.ChainEpoch(ainfo.VestingStart), abi.ChainEpoch(ainfo.VestingDuration), info.Balance) if err != nil { return err } + + statecid, err := cst.Put(ctx, mst.GetState()) + if err != nil { + return err + } + + actcid, err := multisig.GetActorCodeID(av) + if err != nil { + return err + } + err = state.SetActor(ida, &types.Actor{ - Code: builtin0.MultisigActorCodeID, + Code: actcid, Balance: info.Balance, - Head: st, + Head: statecid, }) if err != nil { return xerrors.Errorf("setting account from actmap: %w", err) } + return nil } -func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot cid.Cid, template genesis.Template, keyIDs map[address.Address]address.Address) (cid.Cid, error) { +func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot cid.Cid, template genesis.Template, keyIDs map[address.Address]address.Address, nv network.Version) (cid.Cid, error) { verifNeeds := make(map[address.Address]abi.PaddedPieceSize) var sum abi.PaddedPieceSize @@ -455,8 +483,10 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci Bstore: cs.StateBlockstore(), Syscalls: mkFakedSigSyscalls(cs.VMSys()), CircSupplyCalc: nil, - NtwkVersion: genesisNetworkVersion, - BaseFee: types.NewInt(0), + NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version { + return nv + }, + BaseFee: types.NewInt(0), } vm, err := vm.NewVM(ctx, &vmopt) if err != nil { @@ -485,7 +515,8 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci return cid.Undef, err } - _, err = doExecValue(ctx, vm, builtin0.VerifiedRegistryActorAddr, verifregRoot, types.NewInt(0), builtin0.MethodsVerifiedRegistry.AddVerifier, mustEnc(&verifreg0.AddVerifierParams{ + // Note: This is brittle, if the methodNum / param changes, it could break things + _, err = doExecValue(ctx, vm, verifreg.Address, verifregRoot, types.NewInt(0), builtin0.MethodsVerifiedRegistry.AddVerifier, mustEnc(&verifreg0.AddVerifierParams{ Address: verifier, Allowance: abi.NewStoragePower(int64(sum)), // eh, close enough @@ -496,7 +527,8 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci } for c, amt := range verifNeeds { - _, err := doExecValue(ctx, vm, builtin0.VerifiedRegistryActorAddr, verifier, types.NewInt(0), builtin0.MethodsVerifiedRegistry.AddVerifiedClient, mustEnc(&verifreg0.AddVerifiedClientParams{ + // Note: This is brittle, if the methodNum / param changes, it could break things + _, err := doExecValue(ctx, vm, verifreg.Address, verifier, types.NewInt(0), builtin0.MethodsVerifiedRegistry.AddVerifiedClient, mustEnc(&verifreg0.AddVerifiedClientParams{ Address: c, Allowance: abi.NewStoragePower(int64(amt)), })) @@ -531,17 +563,17 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto cs := store.NewChainStore(bs, bs, datastore.NewMapDatastore(), sys, j) // Verify PreSealed Data - stateroot, err = VerifyPreSealedData(ctx, cs, stateroot, template, keyIDs) + stateroot, err = VerifyPreSealedData(ctx, cs, stateroot, template, keyIDs, template.NetworkVersion) if err != nil { return nil, xerrors.Errorf("failed to verify presealed data: %w", err) } - stateroot, err = SetupStorageMiners(ctx, cs, stateroot, template.Miners) + stateroot, err = SetupStorageMiners(ctx, cs, stateroot, template.Miners, template.NetworkVersion) if err != nil { return nil, xerrors.Errorf("setup miners failed: %w", err) } - store := adt0.WrapStore(ctx, cbor.NewCborStore(bs)) + store := adt.WrapStore(ctx, cbor.NewCborStore(bs)) emptyroot, err := adt0.MakeEmptyArray(store).Root() if err != nil { return nil, xerrors.Errorf("amt build failed: %w", err) @@ -590,7 +622,7 @@ func MakeGenesisBlock(ctx context.Context, j journal.Journal, bs bstore.Blocksto } b := &types.BlockHeader{ - Miner: builtin0.SystemActorAddr, + Miner: system.Address, Ticket: genesisticket, Parents: []cid.Cid{filecoinGenesisCid}, Height: 0, diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 297543886..17349b270 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -6,6 +6,22 @@ import ( "fmt" "math/rand" + power4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/power" + + reward4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/reward" + + market4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/market" + + "github.com/filecoin-project/lotus/chain/actors" + + "github.com/filecoin-project/lotus/chain/actors/builtin" + + "github.com/filecoin-project/lotus/chain/actors/policy" + + "github.com/filecoin-project/lotus/chain/actors/adt" + + "github.com/filecoin-project/go-state-types/network" + market0 "github.com/filecoin-project/specs-actors/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/power" @@ -61,7 +77,12 @@ func mkFakedSigSyscalls(base vm.SyscallBuilder) vm.SyscallBuilder { } } -func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, miners []genesis.Miner) (cid.Cid, error) { +// Note: Much of this is brittle, if the methodNum / param / return changes, it will break things +func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid, miners []genesis.Miner, nv network.Version) (cid.Cid, error) { + + cst := cbor.NewCborStore(cs.StateBlockstore()) + av := actors.VersionForNetwork(nv) + csc := func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) { return big.Zero(), nil } @@ -73,8 +94,10 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid Bstore: cs.StateBlockstore(), Syscalls: mkFakedSigSyscalls(cs.VMSys()), CircSupplyCalc: csc, - NtwkVersion: genesisNetworkVersion, - BaseFee: types.NewInt(0), + NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version { + return nv + }, + BaseFee: types.NewInt(0), } vm, err := vm.NewVM(ctx, vmopt) @@ -94,12 +117,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid dealIDs []abi.DealID }, len(miners)) + maxPeriods := policy.GetMaxSectorExpirationExtension() / miner.WPoStProvingPeriod for i, m := range miners { // Create miner through power actor i := i m := m - spt, err := miner.SealProofTypeFromSectorSize(m.SectorSize, GenesisNetworkVersion) + spt, err := miner.SealProofTypeFromSectorSize(m.SectorSize, nv) if err != nil { return cid.Undef, err } @@ -113,7 +137,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } params := mustEnc(constructorParams) - rval, err := doExecValue(ctx, vm, power.Address, m.Owner, m.PowerBalance, builtin0.MethodsPower.CreateMiner, params) + rval, err := doExecValue(ctx, vm, power.Address, m.Owner, m.PowerBalance, power.Methods.CreateMiner, params) if err != nil { return cid.Undef, xerrors.Errorf("failed to create genesis miner: %w", err) } @@ -129,23 +153,34 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid } minerInfos[i].maddr = ma.IDAddress - // TODO: ActorUpgrade - err = vm.MutateState(ctx, minerInfos[i].maddr, func(cst cbor.IpldStore, st *miner0.State) error { - maxPeriods := miner0.MaxSectorExpirationExtension / miner0.WPoStProvingPeriod - minerInfos[i].presealExp = (maxPeriods-1)*miner0.WPoStProvingPeriod + st.ProvingPeriodStart - 1 - - return nil - }) + _, err = vm.Flush(ctx) if err != nil { - return cid.Undef, xerrors.Errorf("mutating state: %w", err) + return cid.Undef, xerrors.Errorf("flushing vm: %w", err) } + + mact, err := vm.StateTree().GetActor(minerInfos[i].maddr) + if err != nil { + return cid.Undef, xerrors.Errorf("getting newly created miner actor: %w", err) + } + + mst, err := miner.Load(adt.WrapStore(ctx, cst), mact) + if err != nil { + return cid.Undef, xerrors.Errorf("getting newly created miner state: %w", err) + } + + pps, err := mst.GetProvingPeriodStart() + if err != nil { + return cid.Undef, xerrors.Errorf("getting newly created miner proving period start: %w", err) + } + + minerInfos[i].presealExp = (maxPeriods-1)*miner0.WPoStProvingPeriod + pps - 1 } // Add market funds if m.MarketBalance.GreaterThan(big.Zero()) { params := mustEnc(&minerInfos[i].maddr) - _, err := doExecValue(ctx, vm, market.Address, m.Worker, m.MarketBalance, builtin0.MethodsMarket.AddBalance, params) + _, err := doExecValue(ctx, vm, market.Address, m.Worker, m.MarketBalance, market.Methods.AddBalance, params) if err != nil { return cid.Undef, xerrors.Errorf("failed to create genesis miner (add balance): %w", err) } @@ -203,35 +238,66 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid for pi := range m.Sectors { rawPow = types.BigAdd(rawPow, types.NewInt(uint64(m.SectorSize))) - dweight, err := dealWeight(ctx, vm, minerInfos[i].maddr, []abi.DealID{minerInfos[i].dealIDs[pi]}, 0, minerInfos[i].presealExp) + dweight, vdweight, err := dealWeight(ctx, vm, minerInfos[i].maddr, []abi.DealID{minerInfos[i].dealIDs[pi]}, 0, minerInfos[i].presealExp, av) if err != nil { return cid.Undef, xerrors.Errorf("getting deal weight: %w", err) } - sectorWeight := miner0.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) + sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight, vdweight) qaPow = types.BigAdd(qaPow, sectorWeight) } } - err = vm.MutateState(ctx, power.Address, func(cst cbor.IpldStore, st *power0.State) error { - st.TotalQualityAdjPower = qaPow - st.TotalRawBytePower = rawPow - - st.ThisEpochQualityAdjPower = qaPow - st.ThisEpochRawBytePower = rawPow - return nil - }) + _, err = vm.Flush(ctx) if err != nil { - return cid.Undef, xerrors.Errorf("mutating state: %w", err) + return cid.Undef, xerrors.Errorf("flushing vm: %w", err) } - err = vm.MutateState(ctx, reward.Address, func(sct cbor.IpldStore, st *reward0.State) error { - *st = *reward0.ConstructState(qaPow) - return nil - }) + pact, err := vm.StateTree().GetActor(power.Address) if err != nil { - return cid.Undef, xerrors.Errorf("mutating state: %w", err) + return cid.Undef, xerrors.Errorf("getting power actor: %w", err) + } + + pst, err := power.Load(adt.WrapStore(ctx, cst), pact) + if err != nil { + return cid.Undef, xerrors.Errorf("getting power state: %w", err) + } + + if err = pst.SetTotalQualityAdjPower(qaPow); err != nil { + return cid.Undef, xerrors.Errorf("setting TotalQualityAdjPower in power state: %w", err) + } + + if err = pst.SetTotalRawBytePower(rawPow); err != nil { + return cid.Undef, xerrors.Errorf("setting TotalRawBytePower in power state: %w", err) + } + + if err = pst.SetThisEpochQualityAdjPower(qaPow); err != nil { + return cid.Undef, xerrors.Errorf("setting ThisEpochQualityAdjPower in power state: %w", err) + } + + if err = pst.SetThisEpochRawBytePower(rawPow); err != nil { + return cid.Undef, xerrors.Errorf("setting ThisEpochRawBytePower in power state: %w", err) + } + + pcid, err := cst.Put(ctx, pst.GetState()) + if err != nil { + return cid.Undef, xerrors.Errorf("putting power state: %w", err) + } + + pact.Head = pcid + + if err = vm.StateTree().SetActor(power.Address, pact); err != nil { + return cid.Undef, xerrors.Errorf("setting power state: %w", err) + } + + rewact, err := SetupRewardActor(ctx, cs.StateBlockstore(), big.Zero(), actors.VersionForNetwork(nv)) + if err != nil { + return cid.Undef, xerrors.Errorf("setup reward actor: %w", err) + } + + if err = vm.StateTree().SetActor(reward.Address, rewact); err != nil { + return cid.Undef, xerrors.Errorf("set reward actor: %w", err) } } @@ -248,24 +314,55 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid Expiration: minerInfos[i].presealExp, // TODO: Allow setting externally! } - dweight, err := dealWeight(ctx, vm, minerInfos[i].maddr, params.DealIDs, 0, minerInfos[i].presealExp) + dweight, vdweight, err := dealWeight(ctx, vm, minerInfos[i].maddr, params.DealIDs, 0, minerInfos[i].presealExp, av) if err != nil { return cid.Undef, xerrors.Errorf("getting deal weight: %w", err) } - sectorWeight := miner0.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight.DealWeight, dweight.VerifiedDealWeight) + sectorWeight := builtin.QAPowerForWeight(m.SectorSize, minerInfos[i].presealExp, dweight, vdweight) // we've added fake power for this sector above, remove it now - err = vm.MutateState(ctx, power.Address, func(cst cbor.IpldStore, st *power0.State) error { - st.TotalQualityAdjPower = types.BigSub(st.TotalQualityAdjPower, sectorWeight) //nolint:scopelint - st.TotalRawBytePower = types.BigSub(st.TotalRawBytePower, types.NewInt(uint64(m.SectorSize))) - return nil - }) + + _, err = vm.Flush(ctx) if err != nil { - return cid.Undef, xerrors.Errorf("removing fake power: %w", err) + return cid.Undef, xerrors.Errorf("flushing vm: %w", err) } - epochReward, err := currentEpochBlockReward(ctx, vm, minerInfos[i].maddr) + pact, err := vm.StateTree().GetActor(power.Address) + if err != nil { + return cid.Undef, xerrors.Errorf("getting power actor: %w", err) + } + + pst, err := power.Load(adt.WrapStore(ctx, cst), pact) + if err != nil { + return cid.Undef, xerrors.Errorf("getting power state: %w", err) + } + + pc, err := pst.TotalPower() + if err != nil { + return cid.Undef, xerrors.Errorf("getting total power: %w", err) + } + + if err = pst.SetTotalRawBytePower(types.BigSub(pc.RawBytePower, types.NewInt(uint64(m.SectorSize)))); err != nil { + return cid.Undef, xerrors.Errorf("setting TotalRawBytePower in power state: %w", err) + } + + if err = pst.SetTotalQualityAdjPower(types.BigSub(pc.QualityAdjPower, sectorWeight)); err != nil { + return cid.Undef, xerrors.Errorf("setting TotalQualityAdjPower in power state: %w", err) + } + + pcid, err := cst.Put(ctx, pst.GetState()) + if err != nil { + return cid.Undef, xerrors.Errorf("putting power state: %w", err) + } + + pact.Head = pcid + + if err = vm.StateTree().SetActor(power.Address, pact); err != nil { + return cid.Undef, xerrors.Errorf("setting power state: %w", err) + } + + baselinePower, rewardSmoothed, err := currentEpochBlockReward(ctx, vm, minerInfos[i].maddr, av) if err != nil { return cid.Undef, xerrors.Errorf("getting current epoch reward: %w", err) } @@ -275,13 +372,13 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return cid.Undef, xerrors.Errorf("getting current total power: %w", err) } - pcd := miner0.PreCommitDepositForPower(epochReward.ThisEpochRewardSmoothed, tpow.QualityAdjPowerSmoothed, sectorWeight) + pcd := miner0.PreCommitDepositForPower(&rewardSmoothed, tpow.QualityAdjPowerSmoothed, sectorWeight) pledge := miner0.InitialPledgeForPower( sectorWeight, - epochReward.ThisEpochBaselinePower, + baselinePower, tpow.PledgeCollateral, - epochReward.ThisEpochRewardSmoothed, + &rewardSmoothed, tpow.QualityAdjPowerSmoothed, circSupply(ctx, vm, minerInfos[i].maddr), ) @@ -289,7 +386,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid pledge = big.Add(pcd, pledge) fmt.Println(types.FIL(pledge)) - _, err = doExecValue(ctx, vm, minerInfos[i].maddr, m.Worker, pledge, builtin0.MethodsMiner.PreCommitSector, mustEnc(params)) + _, err = doExecValue(ctx, vm, minerInfos[i].maddr, m.Worker, pledge, miner.Methods.PreCommitSector, mustEnc(params)) if err != nil { return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err) } @@ -299,28 +396,84 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid Sectors: []abi.SectorNumber{preseal.SectorID}, } - _, err = doExecValue(ctx, vm, minerInfos[i].maddr, power.Address, big.Zero(), builtin0.MethodsMiner.ConfirmSectorProofsValid, mustEnc(confirmParams)) + _, err = doExecValue(ctx, vm, minerInfos[i].maddr, power.Address, big.Zero(), miner.Methods.ConfirmSectorProofsValid, mustEnc(confirmParams)) if err != nil { return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err) } + + if av > actors.Version2 { + // post v2, we need to explicitly Claim this power since ConfirmSectorProofsValid doesn't do it anymore + claimParams := &power4.UpdateClaimedPowerParams{ + RawByteDelta: types.NewInt(uint64(m.SectorSize)), + QualityAdjustedDelta: sectorWeight, + } + + _, err = doExecValue(ctx, vm, power.Address, minerInfos[i].maddr, big.Zero(), power.Methods.UpdateClaimedPower, mustEnc(claimParams)) + if err != nil { + return cid.Undef, xerrors.Errorf("failed to confirm presealed sectors: %w", err) + } + + _, err = vm.Flush(ctx) + if err != nil { + return cid.Undef, xerrors.Errorf("flushing vm: %w", err) + } + + mact, err := vm.StateTree().GetActor(minerInfos[i].maddr) + if err != nil { + return cid.Undef, xerrors.Errorf("getting miner actor: %w", err) + } + + mst, err := miner.Load(adt.WrapStore(ctx, cst), mact) + if err != nil { + return cid.Undef, xerrors.Errorf("getting miner state: %w", err) + } + + if err = mst.EraseAllUnproven(); err != nil { + return cid.Undef, xerrors.Errorf("failed to erase unproven sectors: %w", err) + } + + mcid, err := cst.Put(ctx, mst.GetState()) + if err != nil { + return cid.Undef, xerrors.Errorf("putting miner state: %w", err) + } + + mact.Head = mcid + + if err = vm.StateTree().SetActor(minerInfos[i].maddr, mact); err != nil { + return cid.Undef, xerrors.Errorf("setting miner state: %w", err) + } + } } } } // Sanity-check total network power - err = vm.MutateState(ctx, power.Address, func(cst cbor.IpldStore, st *power0.State) error { - if !st.TotalRawBytePower.Equals(rawPow) { - return xerrors.Errorf("st.TotalRawBytePower doesn't match previously calculated rawPow") - } - - if !st.TotalQualityAdjPower.Equals(qaPow) { - return xerrors.Errorf("st.TotalQualityAdjPower doesn't match previously calculated qaPow") - } - - return nil - }) + _, err = vm.Flush(ctx) if err != nil { - return cid.Undef, xerrors.Errorf("mutating state: %w", err) + return cid.Undef, xerrors.Errorf("flushing vm: %w", err) + } + + pact, err := vm.StateTree().GetActor(power.Address) + if err != nil { + return cid.Undef, xerrors.Errorf("getting power actor: %w", err) + } + + pst, err := power.Load(adt.WrapStore(ctx, cst), pact) + if err != nil { + return cid.Undef, xerrors.Errorf("getting power state: %w", err) + } + + pc, err := pst.TotalPower() + if err != nil { + return cid.Undef, xerrors.Errorf("getting total power: %w", err) + } + + if !pc.RawBytePower.Equals(rawPow) { + return cid.Undef, xerrors.Errorf("TotalRawBytePower (%s) doesn't match previously calculated rawPow (%s)", pc.RawBytePower, rawPow) + } + + if !pc.QualityAdjPower.Equals(qaPow) { + return cid.Undef, xerrors.Errorf("QualityAdjPower (%s) doesn't match previously calculated qaPow (%s)", pc.QualityAdjPower, qaPow) } // TODO: Should we re-ConstructState for the reward actor using rawPow as currRealizedPower here? @@ -360,43 +513,79 @@ func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (* return &pwr, nil } -func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch) (market0.VerifyDealsForActivationReturn, error) { - params := &market.VerifyDealsForActivationParams{ - DealIDs: dealIDs, - SectorStart: sectorStart, - SectorExpiry: sectorExpiry, - } +func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) { + // TODO: This hack should move to market actor wrapper + if av <= actors.Version2 { + params := &market0.VerifyDealsForActivationParams{ + DealIDs: dealIDs, + SectorStart: sectorStart, + SectorExpiry: sectorExpiry, + } - var dealWeights market0.VerifyDealsForActivationReturn + var dealWeights market0.VerifyDealsForActivationReturn + ret, err := doExecValue(ctx, vm, + market.Address, + maddr, + abi.NewTokenAmount(0), + builtin0.MethodsMarket.VerifyDealsForActivation, + mustEnc(params), + ) + if err != nil { + return big.Zero(), big.Zero(), err + } + if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret)); err != nil { + return big.Zero(), big.Zero(), err + } + + return dealWeights.DealWeight, dealWeights.VerifiedDealWeight, nil + } + params := &market4.VerifyDealsForActivationParams{Sectors: []market4.SectorDeals{{ + SectorExpiry: sectorExpiry, + DealIDs: dealIDs, + }}} + + var dealWeights market4.VerifyDealsForActivationReturn ret, err := doExecValue(ctx, vm, market.Address, maddr, abi.NewTokenAmount(0), - builtin0.MethodsMarket.VerifyDealsForActivation, + market.Methods.VerifyDealsForActivation, mustEnc(params), ) if err != nil { - return market0.VerifyDealsForActivationReturn{}, err + return big.Zero(), big.Zero(), err } if err := dealWeights.UnmarshalCBOR(bytes.NewReader(ret)); err != nil { - return market0.VerifyDealsForActivationReturn{}, err + return big.Zero(), big.Zero(), err } - return dealWeights, nil + return dealWeights.Sectors[0].DealWeight, dealWeights.Sectors[0].VerifiedDealWeight, nil } -func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address) (*reward0.ThisEpochRewardReturn, error) { - rwret, err := doExecValue(ctx, vm, reward.Address, maddr, big.Zero(), builtin0.MethodsReward.ThisEpochReward, nil) +func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) { + rwret, err := doExecValue(ctx, vm, reward.Address, maddr, big.Zero(), reward.Methods.ThisEpochReward, nil) if err != nil { - return nil, err + return big.Zero(), builtin.FilterEstimate{}, err } - var epochReward reward0.ThisEpochRewardReturn + // TODO: This hack should move to reward actor wrapper + if av <= actors.Version2 { + var epochReward reward0.ThisEpochRewardReturn + + if err := epochReward.UnmarshalCBOR(bytes.NewReader(rwret)); err != nil { + return big.Zero(), builtin.FilterEstimate{}, err + } + + return epochReward.ThisEpochBaselinePower, *epochReward.ThisEpochRewardSmoothed, nil + } + + var epochReward reward4.ThisEpochRewardReturn + if err := epochReward.UnmarshalCBOR(bytes.NewReader(rwret)); err != nil { - return nil, err + return big.Zero(), builtin.FilterEstimate{}, err } - return &epochReward, nil + return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(epochReward.ThisEpochRewardSmoothed), nil } func circSupply(ctx context.Context, vmi *vm.VM, maddr address.Address) abi.TokenAmount { diff --git a/chain/gen/genesis/util.go b/chain/gen/genesis/util.go index 54cc30cc1..67a4e9579 100644 --- a/chain/gen/genesis/util.go +++ b/chain/gen/genesis/util.go @@ -3,9 +3,6 @@ package genesis import ( "context" - "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" cbg "github.com/whyrusleeping/cbor-gen" @@ -49,29 +46,3 @@ func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value return ret.Return, nil } - -// TODO: Get from build -// TODO: make a list/schedule of these. -var GenesisNetworkVersion = func() network.Version { - // returns the version _before_ the first upgrade. - if build.UpgradeBreezeHeight >= 0 { - return network.Version0 - } - if build.UpgradeSmokeHeight >= 0 { - return network.Version1 - } - if build.UpgradeIgnitionHeight >= 0 { - return network.Version2 - } - if build.UpgradeActorsV2Height >= 0 { - return network.Version3 - } - if build.UpgradeLiftoffHeight >= 0 { - return network.Version3 - } - return build.ActorUpgradeNetworkVersion - 1 // genesis requires actors v0. -}() - -func genesisNetworkVersion(context.Context, abi.ChainEpoch) network.Version { // TODO: Get from build/ - return GenesisNetworkVersion // TODO: Get from build/ -} // TODO: Get from build/ diff --git a/chain/state/statetree.go b/chain/state/statetree.go index 2a7b436b8..a31ec2396 100644 --- a/chain/state/statetree.go +++ b/chain/state/statetree.go @@ -14,7 +14,6 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/network" - "github.com/filecoin-project/lotus/chain/actors" init_ "github.com/filecoin-project/lotus/chain/actors/builtin/init" cbg "github.com/whyrusleeping/cbor-gen" @@ -142,11 +141,19 @@ func (ss *stateSnaps) deleteActor(addr address.Address) { // VersionForNetwork returns the state tree version for the given network // version. -func VersionForNetwork(ver network.Version) types.StateTreeVersion { - if actors.VersionForNetwork(ver) == actors.Version0 { - return types.StateTreeVersion0 +func VersionForNetwork(ver network.Version) (types.StateTreeVersion, error) { + switch ver { + case network.Version0, network.Version1, network.Version2, network.Version3: + return types.StateTreeVersion0, nil + case network.Version4, network.Version5, network.Version6, network.Version7, network.Version8, network.Version9: + return types.StateTreeVersion1, nil + case network.Version10, network.Version11: + return types.StateTreeVersion2, nil + case network.Version12: + return types.StateTreeVersion3, nil + default: + panic(fmt.Sprintf("unsupported network version %d", ver)) } - return types.StateTreeVersion1 } func NewStateTree(cst cbor.IpldStore, ver types.StateTreeVersion) (*StateTree, error) { diff --git a/chain/state/statetree_test.go b/chain/state/statetree_test.go index 91674337b..9177af312 100644 --- a/chain/state/statetree_test.go +++ b/chain/state/statetree_test.go @@ -5,11 +5,12 @@ import ( "fmt" "testing" + "github.com/filecoin-project/go-state-types/network" + "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" address "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/network" builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin" "github.com/filecoin-project/lotus/build" @@ -45,7 +46,12 @@ func BenchmarkStateTreeSet(b *testing.B) { func BenchmarkStateTreeSetFlush(b *testing.B) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst, VersionForNetwork(build.NewestNetworkVersion)) + sv, err := VersionForNetwork(build.NewestNetworkVersion) + if err != nil { + b.Fatal(err) + } + + st, err := NewStateTree(cst, sv) if err != nil { b.Fatal(err) } @@ -75,7 +81,12 @@ func BenchmarkStateTreeSetFlush(b *testing.B) { func TestResolveCache(t *testing.T) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst, VersionForNetwork(build.NewestNetworkVersion)) + sv, err := VersionForNetwork(build.NewestNetworkVersion) + if err != nil { + t.Fatal(err) + } + + st, err := NewStateTree(cst, sv) if err != nil { t.Fatal(err) } @@ -172,7 +183,12 @@ func TestResolveCache(t *testing.T) { func BenchmarkStateTree10kGetActor(b *testing.B) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst, VersionForNetwork(build.NewestNetworkVersion)) + sv, err := VersionForNetwork(build.NewestNetworkVersion) + if err != nil { + b.Fatal(err) + } + + st, err := NewStateTree(cst, sv) if err != nil { b.Fatal(err) } @@ -214,7 +230,12 @@ func BenchmarkStateTree10kGetActor(b *testing.B) { func TestSetCache(t *testing.T) { cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst, VersionForNetwork(build.NewestNetworkVersion)) + sv, err := VersionForNetwork(build.NewestNetworkVersion) + if err != nil { + t.Fatal(err) + } + + st, err := NewStateTree(cst, sv) if err != nil { t.Fatal(err) } @@ -251,7 +272,13 @@ func TestSetCache(t *testing.T) { func TestSnapshots(t *testing.T) { ctx := context.Background() cst := cbor.NewMemCborStore() - st, err := NewStateTree(cst, VersionForNetwork(build.NewestNetworkVersion)) + + sv, err := VersionForNetwork(build.NewestNetworkVersion) + if err != nil { + t.Fatal(err) + } + + st, err := NewStateTree(cst, sv) if err != nil { t.Fatal(err) } @@ -334,8 +361,15 @@ func assertNotHas(t *testing.T, st *StateTree, addr address.Address) { func TestStateTreeConsistency(t *testing.T) { cst := cbor.NewMemCborStore() + // TODO: ActorUpgrade: this test tests pre actors v2 - st, err := NewStateTree(cst, VersionForNetwork(network.Version3)) + + sv, err := VersionForNetwork(network.Version3) + if err != nil { + t.Fatal(err) + } + + st, err := NewStateTree(cst, sv) if err != nil { t.Fatal(err) } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index afc74e744..f488c7864 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "reflect" "sync/atomic" "time" @@ -203,7 +202,8 @@ type ( ) type VM struct { - cstate *state.StateTree + cstate *state.StateTree + // TODO: Is base actually used? Can we delete it? base cid.Cid cst *cbor.BasicIpldStore buf *blockstore.BufferedBlockstore @@ -662,37 +662,6 @@ func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) { return root, nil } -// MutateState usage: MutateState(ctx, idAddr, func(cst cbor.IpldStore, st *ActorStateType) error {...}) -func (vm *VM) MutateState(ctx context.Context, addr address.Address, fn interface{}) error { - act, err := vm.cstate.GetActor(addr) - if err != nil { - return xerrors.Errorf("actor not found: %w", err) - } - - st := reflect.New(reflect.TypeOf(fn).In(1).Elem()) - if err := vm.cst.Get(ctx, act.Head, st.Interface()); err != nil { - return xerrors.Errorf("read actor head: %w", err) - } - - out := reflect.ValueOf(fn).Call([]reflect.Value{reflect.ValueOf(vm.cst), st}) - if !out[0].IsNil() && out[0].Interface().(error) != nil { - return out[0].Interface().(error) - } - - head, err := vm.cst.Put(ctx, st.Interface()) - if err != nil { - return xerrors.Errorf("put new actor head: %w", err) - } - - act.Head = head - - if err := vm.cstate.SetActor(addr, act); err != nil { - return xerrors.Errorf("set actor: %w", err) - } - - return nil -} - func linksForObj(blk block.Block, cb func(cid.Cid)) error { switch blk.Cid().Prefix().Codec { case cid.DagCBOR: diff --git a/cmd/lotus-seed/genesis.go b/cmd/lotus-seed/genesis.go index d5f1d5ad6..87493c58a 100644 --- a/cmd/lotus-seed/genesis.go +++ b/cmd/lotus-seed/genesis.go @@ -9,6 +9,8 @@ import ( "strconv" "strings" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" @@ -39,6 +41,7 @@ var genesisCmd = &cli.Command{ genesisAddMsigsCmd, genesisSetVRKCmd, genesisSetRemainderCmd, + genesisSetActorVersionCmd, genesisCarCmd, }, } @@ -56,6 +59,7 @@ var genesisNewCmd = &cli.Command{ return xerrors.New("seed genesis new [genesis.json]") } out := genesis.Template{ + NetworkVersion: network.Version0, Accounts: []genesis.Actor{}, Miners: []genesis.Miner{}, VerifregRootKey: gen.DefaultVerifregRootkeyActor, @@ -503,6 +507,53 @@ var genesisSetRemainderCmd = &cli.Command{ }, } +var genesisSetActorVersionCmd = &cli.Command{ + Name: "set-network-version", + Usage: "Set the version that this network will start from", + ArgsUsage: " ", + Action: func(cctx *cli.Context) error { + if cctx.Args().Len() != 2 { + return fmt.Errorf("must specify genesis file and network version (e.g. '0'") + } + + genf, err := homedir.Expand(cctx.Args().First()) + if err != nil { + return err + } + + var template genesis.Template + b, err := ioutil.ReadFile(genf) + if err != nil { + return xerrors.Errorf("read genesis template: %w", err) + } + + if err := json.Unmarshal(b, &template); err != nil { + return xerrors.Errorf("unmarshal genesis template: %w", err) + } + + nv, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64) + if err != nil { + return xerrors.Errorf("parsing network version: %w", err) + } + + if nv > uint64(build.NewestNetworkVersion) { + return xerrors.Errorf("invalid network version: %d", nv) + } + + template.NetworkVersion = network.Version(nv) + + b, err = json.MarshalIndent(&template, "", " ") + if err != nil { + return err + } + + if err := ioutil.WriteFile(genf, b, 0644); err != nil { + return err + } + return nil + }, +} + var genesisCarCmd = &cli.Command{ Name: "car", Description: "write genesis car file", diff --git a/cmd/lotus-seed/main.go b/cmd/lotus-seed/main.go index c4e62b419..c92397125 100644 --- a/cmd/lotus-seed/main.go +++ b/cmd/lotus-seed/main.go @@ -94,6 +94,11 @@ var preSealCmd = &cli.Command{ Name: "fake-sectors", Value: false, }, + &cli.IntFlag{ + Name: "network-version", + Value: 0, + Usage: "specify network version", + }, }, Action: func(c *cli.Context) error { sdir := c.String("sector-dir") @@ -129,7 +134,7 @@ var preSealCmd = &cli.Command{ } sectorSize := abi.SectorSize(sectorSizeInt) - spt, err := miner.SealProofTypeFromSectorSize(sectorSize, network.Version0) + spt, err := miner.SealProofTypeFromSectorSize(sectorSize, network.Version(c.Uint64("network-version"))) if err != nil { return err } diff --git a/documentation/en/api-v0-methods.md b/documentation/en/api-v0-methods.md index 0372c0dab..a8b760f8a 100644 --- a/documentation/en/api-v0-methods.md +++ b/documentation/en/api-v0-methods.md @@ -4551,7 +4551,7 @@ Inputs: ] ``` -Response: `11` +Response: `12` ### StateReadState StateReadState returns the indicated actor's state. diff --git a/documentation/en/api-v1-unstable-methods.md b/documentation/en/api-v1-unstable-methods.md index bf282745a..be326b3e8 100644 --- a/documentation/en/api-v1-unstable-methods.md +++ b/documentation/en/api-v1-unstable-methods.md @@ -4772,7 +4772,7 @@ Inputs: ] ``` -Response: `11` +Response: `12` ### StateReadState StateReadState returns the indicated actor's state. diff --git a/genesis/types.go b/genesis/types.go index db8d32a3b..d4c04113a 100644 --- a/genesis/types.go +++ b/genesis/types.go @@ -3,6 +3,8 @@ package genesis import ( "encoding/json" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/ipfs/go-cid" @@ -75,8 +77,9 @@ type Actor struct { } type Template struct { - Accounts []Actor - Miners []Miner + NetworkVersion network.Version + Accounts []Actor + Miners []Miner NetworkName string Timestamp uint64 `json:",omitempty"` diff --git a/node/test/builder.go b/node/test/builder.go index 7e26966a8..bd180ee41 100644 --- a/node/test/builder.go +++ b/node/test/builder.go @@ -12,6 +12,8 @@ import ( "testing" "time" + "github.com/filecoin-project/go-state-types/network" + "github.com/gorilla/mux" "golang.org/x/xerrors" @@ -277,6 +279,7 @@ func mockBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []test. genms = append(genms, *genm) } templ := &genesis.Template{ + NetworkVersion: network.Version0, Accounts: genaccs, Miners: genms, NetworkName: "test", @@ -440,6 +443,7 @@ func mockSbBuilderOpts(t *testing.T, fullOpts []test.FullNodeOpts, storage []tes genms = append(genms, *genm) } templ := &genesis.Template{ + NetworkVersion: network.Version0, Accounts: genaccs, Miners: genms, NetworkName: "test",