Skip to content

Commit e337d7f

Browse files
committed
upgrade spec-actor v5
1 parent c419a0e commit e337d7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+7109
-494
lines changed

api/api_full.go

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type FullNode interface {
3636
// ChainTipSetWeight computes weight for the specified tipset.
3737
ChainTipSetWeight(context.Context, types.TipSetKey) (types.BigInt, error)
3838

39-
4039
// MethodGroup: Beacon
4140
// The Beacon method group contains methods for interacting with the random beacon (DRAND)
4241

api/apistruct/struct.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ type MinerStruct struct {
171171
CommonStruct
172172

173173
Internal struct {
174-
UpdateAddress func(context.Context, int64, int64) ([]dtypes.MinerInfo, error) `perm:"write"`
174+
UpdateAddress func(context.Context, int64, int64) ([]dtypes.MinerInfo, error) `perm:"write"`
175175
ListAddress func(context.Context) ([]dtypes.MinerInfo, error) `perm:"read"`
176176
StatesForMining func(context.Context, []address.Address) ([]dtypes.MinerState, error) `perm:"read"`
177177
CountWinners func(context.Context, []address.Address, abi.ChainEpoch, abi.ChainEpoch) ([]dtypes.CountWinners, error) `perm:"write"`

build/parameters.go

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ import rice "github.com/GeertJohan/go.rice"
55
func ParametersJSON() []byte {
66
return rice.MustFindBox("proof-params").MustBytes("parameters.json")
77
}
8+
9+
func SrsJSON() []byte {
10+
return rice.MustFindBox("proof-params").MustBytes("srs-inner-product.json")
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"v28-fil-inner-product-v1.srs": {
3+
"cid": "Qmdq44DjcQnFfU3PJcdX7J49GCqcUYszr1TxMbHtAkvQ3g",
4+
"digest": "ae20310138f5ba81451d723f858e3797",
5+
"sector_size": 0
6+
}
7+
}

chain/actors/adt/diff_adt_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (t *TestDiffArray) Remove(key uint64, val *typegen.Deferred) error {
295295

296296
func newContextStore() Store {
297297
ctx := context.Background()
298-
bs := bstore.NewTemporarySync()
298+
bs := bstore.NewMemorySync()
299299
store := cbornode.NewCborStore(bs)
300300
return WrapStore(ctx, store)
301301
}

chain/actors/agen/main.go

+219
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"io/ioutil"
7+
"os"
8+
"path/filepath"
9+
"text/template"
10+
11+
"golang.org/x/xerrors"
12+
)
13+
14+
var latestVersion = 5
15+
16+
var versions = []int{0, 2, 3, 4, latestVersion}
17+
18+
var versionImports = map[int]string{
19+
0: "/",
20+
2: "/v2/",
21+
3: "/v3/",
22+
4: "/v4/",
23+
latestVersion: "/v5/",
24+
}
25+
26+
var actors = map[string][]int{
27+
"account": versions,
28+
"cron": versions,
29+
"init": versions,
30+
"market": versions,
31+
"miner": versions,
32+
"multisig": versions,
33+
"paych": versions,
34+
"power": versions,
35+
"reward": versions,
36+
"verifreg": versions,
37+
}
38+
39+
func main() {
40+
if err := generateAdapters(); err != nil {
41+
fmt.Println(err)
42+
return
43+
}
44+
45+
if err := generatePolicy("chain/actors/policy/policy.go"); err != nil {
46+
fmt.Println(err)
47+
return
48+
}
49+
50+
if err := generateBuiltin("chain/actors/builtin/builtin.go"); err != nil {
51+
fmt.Println(err)
52+
return
53+
}
54+
}
55+
56+
func generateAdapters() error {
57+
for act, versions := range actors {
58+
actDir := filepath.Join("chain/actors/builtin", act)
59+
60+
if err := generateState(actDir); err != nil {
61+
return err
62+
}
63+
64+
if err := generateMessages(actDir); err != nil {
65+
return err
66+
}
67+
68+
{
69+
af, err := ioutil.ReadFile(filepath.Join(actDir, "actor.go.template"))
70+
if err != nil {
71+
return xerrors.Errorf("loading actor template: %w", err)
72+
}
73+
74+
tpl := template.Must(template.New("").Funcs(template.FuncMap{
75+
"import": func(v int) string { return versionImports[v] },
76+
}).Parse(string(af)))
77+
78+
var b bytes.Buffer
79+
80+
err = tpl.Execute(&b, map[string]interface{}{
81+
"versions": versions,
82+
"latestVersion": latestVersion,
83+
})
84+
if err != nil {
85+
return err
86+
}
87+
88+
if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("%s.go", act)), b.Bytes(), 0666); err != nil {
89+
return err
90+
}
91+
}
92+
}
93+
94+
return nil
95+
}
96+
97+
func generateState(actDir string) error {
98+
af, err := ioutil.ReadFile(filepath.Join(actDir, "state.go.template"))
99+
if err != nil {
100+
if os.IsNotExist(err) {
101+
return nil // skip
102+
}
103+
104+
return xerrors.Errorf("loading state adapter template: %w", err)
105+
}
106+
107+
for _, version := range versions {
108+
tpl := template.Must(template.New("").Funcs(template.FuncMap{}).Parse(string(af)))
109+
110+
var b bytes.Buffer
111+
112+
err := tpl.Execute(&b, map[string]interface{}{
113+
"v": version,
114+
"import": versionImports[version],
115+
})
116+
if err != nil {
117+
return err
118+
}
119+
120+
if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("v%d.go", version)), b.Bytes(), 0666); err != nil {
121+
return err
122+
}
123+
}
124+
125+
return nil
126+
}
127+
128+
func generateMessages(actDir string) error {
129+
af, err := ioutil.ReadFile(filepath.Join(actDir, "message.go.template"))
130+
if err != nil {
131+
if os.IsNotExist(err) {
132+
return nil // skip
133+
}
134+
135+
return xerrors.Errorf("loading message adapter template: %w", err)
136+
}
137+
138+
for _, version := range versions {
139+
tpl := template.Must(template.New("").Funcs(template.FuncMap{}).Parse(string(af)))
140+
141+
var b bytes.Buffer
142+
143+
err := tpl.Execute(&b, map[string]interface{}{
144+
"v": version,
145+
"import": versionImports[version],
146+
})
147+
if err != nil {
148+
return err
149+
}
150+
151+
if err := ioutil.WriteFile(filepath.Join(actDir, fmt.Sprintf("message%d.go", version)), b.Bytes(), 0666); err != nil {
152+
return err
153+
}
154+
}
155+
156+
return nil
157+
}
158+
159+
func generatePolicy(policyPath string) error {
160+
161+
pf, err := ioutil.ReadFile(policyPath + ".template")
162+
if err != nil {
163+
if os.IsNotExist(err) {
164+
return nil // skip
165+
}
166+
167+
return xerrors.Errorf("loading policy template file: %w", err)
168+
}
169+
170+
tpl := template.Must(template.New("").Funcs(template.FuncMap{
171+
"import": func(v int) string { return versionImports[v] },
172+
}).Parse(string(pf)))
173+
var b bytes.Buffer
174+
175+
err = tpl.Execute(&b, map[string]interface{}{
176+
"versions": versions,
177+
"latestVersion": latestVersion,
178+
})
179+
if err != nil {
180+
return err
181+
}
182+
183+
if err := ioutil.WriteFile(policyPath, b.Bytes(), 0666); err != nil {
184+
return err
185+
}
186+
187+
return nil
188+
}
189+
190+
func generateBuiltin(builtinPath string) error {
191+
192+
bf, err := ioutil.ReadFile(builtinPath + ".template")
193+
if err != nil {
194+
if os.IsNotExist(err) {
195+
return nil // skip
196+
}
197+
198+
return xerrors.Errorf("loading builtin template file: %w", err)
199+
}
200+
201+
tpl := template.Must(template.New("").Funcs(template.FuncMap{
202+
"import": func(v int) string { return versionImports[v] },
203+
}).Parse(string(bf)))
204+
var b bytes.Buffer
205+
206+
err = tpl.Execute(&b, map[string]interface{}{
207+
"versions": versions,
208+
"latestVersion": latestVersion,
209+
})
210+
if err != nil {
211+
return err
212+
}
213+
214+
if err := ioutil.WriteFile(builtinPath, b.Bytes(), 0666); err != nil {
215+
return err
216+
}
217+
218+
return nil
219+
}

chain/actors/builtin/account/account.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,59 @@ import (
1212
"github.com/filecoin-project/venus-miner/chain/types"
1313

1414
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
15+
1516
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
17+
1618
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
19+
20+
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
21+
22+
builtin5 "github.com/filecoin-project/specs-actors/v5/actors/builtin"
1723
)
1824

1925
func init() {
26+
2027
builtin.RegisterActorState(builtin0.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
2128
return load0(store, root)
2229
})
30+
2331
builtin.RegisterActorState(builtin2.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
2432
return load2(store, root)
2533
})
34+
2635
builtin.RegisterActorState(builtin3.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
2736
return load3(store, root)
2837
})
38+
39+
builtin.RegisterActorState(builtin4.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
40+
return load4(store, root)
41+
})
42+
43+
builtin.RegisterActorState(builtin5.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
44+
return load5(store, root)
45+
})
2946
}
3047

31-
var Methods = builtin3.MethodsAccount
48+
var Methods = builtin4.MethodsAccount
3249

3350
func Load(store adt.Store, act *types.Actor) (State, error) {
3451
switch act.Code {
52+
3553
case builtin0.AccountActorCodeID:
3654
return load0(store, act.Head)
55+
3756
case builtin2.AccountActorCodeID:
3857
return load2(store, act.Head)
58+
3959
case builtin3.AccountActorCodeID:
4060
return load3(store, act.Head)
61+
62+
case builtin4.AccountActorCodeID:
63+
return load4(store, act.Head)
64+
65+
case builtin5.AccountActorCodeID:
66+
return load5(store, act.Head)
67+
4168
}
4269
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
4370
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package account
2+
3+
import (
4+
"golang.org/x/xerrors"
5+
6+
"github.com/filecoin-project/go-address"
7+
"github.com/filecoin-project/go-state-types/cbor"
8+
"github.com/ipfs/go-cid"
9+
10+
"github.com/filecoin-project/venus-miner/chain/actors/adt"
11+
"github.com/filecoin-project/venus-miner/chain/actors/builtin"
12+
"github.com/filecoin-project/venus-miner/chain/types"
13+
{{range .versions}}
14+
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
15+
{{end}}
16+
)
17+
18+
func init() {
19+
{{range .versions}}
20+
builtin.RegisterActorState(builtin{{.}}.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
21+
return load{{.}}(store, root)
22+
})
23+
{{end}}}
24+
25+
var Methods = builtin4.MethodsAccount
26+
27+
func Load(store adt.Store, act *types.Actor) (State, error) {
28+
switch act.Code {
29+
{{range .versions}}
30+
case builtin{{.}}.AccountActorCodeID:
31+
return load{{.}}(store, act.Head)
32+
{{end}}
33+
}
34+
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
35+
}
36+
37+
type State interface {
38+
cbor.Marshaler
39+
40+
PubkeyAddress() (address.Address, error)
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package account
2+
3+
import (
4+
"github.com/filecoin-project/go-address"
5+
"github.com/ipfs/go-cid"
6+
7+
"github.com/filecoin-project/venus-miner/chain/actors/adt"
8+
9+
account{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/account"
10+
)
11+
12+
var _ State = (*state{{.v}})(nil)
13+
14+
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
15+
out := state{{.v}}{store: store}
16+
err := store.Get(store.Context(), root, &out)
17+
if err != nil {
18+
return nil, err
19+
}
20+
return &out, nil
21+
}
22+
23+
type state{{.v}} struct {
24+
account{{.v}}.State
25+
store adt.Store
26+
}
27+
28+
func (s *state{{.v}}) PubkeyAddress() (address.Address, error) {
29+
return s.Address, nil
30+
}

0 commit comments

Comments
 (0)