-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: actors: Integrate datacap actor into lotus (#9348)
* Integrate datacap actor * Implement datacap actor in chain/builtin
- Loading branch information
1 parent
7e6a2df
commit 495135e
Showing
13 changed files
with
247 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package datacap | ||
|
||
import ( | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
actorstypes "github.com/filecoin-project/go-state-types/actors" | ||
builtin{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin" | ||
"github.com/filecoin-project/go-state-types/cbor" | ||
|
||
"github.com/filecoin-project/lotus/chain/actors" | ||
"github.com/filecoin-project/lotus/chain/actors/adt" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
) | ||
|
||
var ( | ||
Address = builtin9.DatacapActorAddr | ||
Methods = builtin9.MethodsDatacap | ||
) | ||
|
||
func Load(store adt.Store, act *types.Actor) (State, error) { | ||
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { | ||
if name != actors.DatacapKey { | ||
return nil, xerrors.Errorf("actor code is not datacap: %s", name) | ||
} | ||
|
||
switch av { | ||
{{range .versions}} | ||
case actorstypes.Version{{.}}: | ||
return load{{.}}(store, act.Head) | ||
{{end}} | ||
} | ||
} | ||
|
||
return nil, xerrors.Errorf("unknown actor code %s", act.Code) | ||
} | ||
|
||
func MakeState(store adt.Store, av actorstypes.Version, governor address.Address, bitwidth uint64) (State, error) { | ||
switch av { | ||
{{range .versions}} | ||
case actorstypes.Version{{.}}: | ||
return make{{.}}(store, governor, bitwidth) | ||
|
||
default: return nil, xerrors.Errorf("datacap actor only valid for actors v9 and above, got %d", av) | ||
{{end}} | ||
} | ||
} | ||
|
||
type State interface { | ||
cbor.Marshaler | ||
|
||
Governor() (address.Address, error) | ||
GetState() interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package datacap | ||
|
||
import ( | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/go-address" | ||
actorstypes "github.com/filecoin-project/go-state-types/actors" | ||
builtin9 "github.com/filecoin-project/go-state-types/builtin" | ||
"github.com/filecoin-project/go-state-types/cbor" | ||
|
||
"github.com/filecoin-project/lotus/chain/actors" | ||
"github.com/filecoin-project/lotus/chain/actors/adt" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
) | ||
|
||
var ( | ||
Address = builtin9.DatacapActorAddr | ||
Methods = builtin9.MethodsDatacap | ||
) | ||
|
||
func Load(store adt.Store, act *types.Actor) (State, error) { | ||
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { | ||
if name != actors.DatacapKey { | ||
return nil, xerrors.Errorf("actor code is not datacap: %s", name) | ||
} | ||
|
||
switch av { | ||
|
||
case actorstypes.Version9: | ||
return load9(store, act.Head) | ||
|
||
} | ||
} | ||
|
||
return nil, xerrors.Errorf("unknown actor code %s", act.Code) | ||
} | ||
|
||
func MakeState(store adt.Store, av actorstypes.Version, governor address.Address, bitwidth uint64) (State, error) { | ||
switch av { | ||
|
||
case actorstypes.Version9: | ||
return make9(store, governor, bitwidth) | ||
|
||
default: | ||
return nil, xerrors.Errorf("datacap actor only valid for actors v9 and above, got %d", av) | ||
|
||
} | ||
} | ||
|
||
type State interface { | ||
cbor.Marshaler | ||
|
||
Governor() (address.Address, error) | ||
GetState() interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package datacap | ||
|
||
import ( | ||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/ipfs/go-cid" | ||
|
||
"github.com/filecoin-project/lotus/chain/actors" | ||
"github.com/filecoin-project/lotus/chain/actors/adt" | ||
|
||
datacap{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}datacap" | ||
adt{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}util/adt" | ||
builtin{{.v}} "github.com/filecoin-project/go-state-types/builtin" | ||
) | ||
|
||
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, governor address.Address, bitwidth uint64) (State, error) { | ||
out := state{{.v}}{store: store} | ||
s, err := datacap{{.v}}.ConstructState(store, governor, bitwidth) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
out.State = *s | ||
|
||
return &out, nil | ||
} | ||
|
||
type state{{.v}} struct { | ||
datacap{{.v}}.State | ||
store adt.Store | ||
} | ||
|
||
func (s *state{{.v}}) Governor() (address.Address, error) { | ||
return s.State.Governor, nil | ||
} | ||
|
||
func (s *state{{.v}}) GetState() interface{} { | ||
return &s.State | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package datacap | ||
|
||
import ( | ||
"github.com/ipfs/go-cid" | ||
|
||
"github.com/filecoin-project/go-address" | ||
datacap9 "github.com/filecoin-project/go-state-types/builtin/v9/datacap" | ||
|
||
"github.com/filecoin-project/lotus/chain/actors/adt" | ||
) | ||
|
||
var _ State = (*state9)(nil) | ||
|
||
func load9(store adt.Store, root cid.Cid) (State, error) { | ||
out := state9{store: store} | ||
err := store.Get(store.Context(), root, &out) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &out, nil | ||
} | ||
|
||
func make9(store adt.Store, governor address.Address, bitwidth uint64) (State, error) { | ||
out := state9{store: store} | ||
s, err := datacap9.ConstructState(store, governor, bitwidth) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
out.State = *s | ||
|
||
return &out, nil | ||
} | ||
|
||
type state9 struct { | ||
datacap9.State | ||
store adt.Store | ||
} | ||
|
||
func (s *state9) Governor() (address.Address, error) { | ||
return s.State.Governor, nil | ||
} | ||
|
||
func (s *state9) GetState() interface{} { | ||
return &s.State | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.