Skip to content

Commit

Permalink
hopfully fix most of the things
Browse files Browse the repository at this point in the history
- there are still some bugs in lotus that prevent lily from running correctly
  • Loading branch information
frrist committed Jan 19, 2023
1 parent db81191 commit c48824d
Show file tree
Hide file tree
Showing 21 changed files with 1,815 additions and 34 deletions.
1 change: 1 addition & 0 deletions chain/actors/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
Version8 Version = 8
Version9 Version = 9
Version10 Version = 10
Version11 Version = 11
)
const (
AccountKey = "account"
Expand Down
14 changes: 11 additions & 3 deletions chain/actors/builtin/datacap/datacap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
actorstypes "github.com/filecoin-project/go-state-types/actors"
builtin10 "github.com/filecoin-project/go-state-types/builtin"
builtin11 "github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/ipfs/go-cid"

Expand All @@ -17,8 +17,8 @@ import (
)

var (
Address = builtin10.DatacapActorAddr
Methods = builtin10.MethodsDatacap
Address = builtin11.DatacapActorAddr
Methods = builtin11.MethodsDatacap
)

func Load(store adt.Store, act *types.Actor) (State, error) {
Expand All @@ -35,6 +35,9 @@ func Load(store adt.Store, act *types.Actor) (State, error) {
case actorstypes.Version10:
return load10(store, act.Head)

case actorstypes.Version11:
return load11(store, act.Head)

}
}

Expand All @@ -50,6 +53,9 @@ func MakeState(store adt.Store, av actorstypes.Version, governor address.Address
case actorstypes.Version10:
return make10(store, governor, bitwidth)

case actorstypes.Version11:
return make11(store, governor, bitwidth)

default:
return nil, xerrors.Errorf("datacap actor only valid for actors v9 and above, got %d", av)
}
Expand All @@ -76,12 +82,14 @@ func AllCodes() []cid.Cid {
return []cid.Cid{
(&state9{}).Code(),
(&state10{}).Code(),
(&state11{}).Code(),
}
}

func VersionCodes() map[actors.Version]cid.Cid {
return map[actors.Version]cid.Cid{
actors.Version9: (&state9{}).Code(),
actors.Version10: (&state10{}).Code(),
actors.Version11: (&state11{}).Code(),
}
}
92 changes: 92 additions & 0 deletions chain/actors/builtin/datacap/v11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package datacap

import (
"crypto/sha256"
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-cid"

"github.com/filecoin-project/lily/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt"

datacap11 "github.com/filecoin-project/go-state-types/builtin/v11/datacap"
adt11 "github.com/filecoin-project/go-state-types/builtin/v11/util/adt"
)

var _ State = (*state11)(nil)

func load11(store adt.Store, root cid.Cid) (State, error) {
out := state11{store: store}
err := store.Get(store.Context(), root, &out)
if err != nil {
return nil, err
}
return &out, nil
}

func make11(store adt.Store, governor address.Address, bitwidth uint64) (State, error) {
out := state11{store: store}
s, err := datacap11.ConstructState(store, governor, bitwidth)
if err != nil {
return nil, err
}

out.State = *s

return &out, nil
}

type state11 struct {
datacap11.State
store adt.Store
}

func (s *state11) Governor() (address.Address, error) {
return s.State.Governor, nil
}

func (s *state11) GetState() interface{} {
return &s.State
}

func (s *state11) ForEachClient(cb func(addr address.Address, dcap abi.StoragePower) error) error {
return forEachClient(s.store, actors.Version11, s.VerifiedClients, cb)
}

func (s *state11) VerifiedClients() (adt.Map, error) {
return adt11.AsMap(s.store, s.Token.Balances, int(s.Token.HamtBitWidth))
}

func (s *state11) VerifiedClientDataCap(addr address.Address) (bool, abi.StoragePower, error) {
return getDataCap(s.store, actors.Version11, s.VerifiedClients, addr)
}

func (s *state11) VerifiedClientsMapBitWidth() int {
return int(s.Token.HamtBitWidth)
}

func (s *state11) VerifiedClientsMapHashFunction() func(input []byte) []byte {
return func(input []byte) []byte {
res := sha256.Sum256(input)
return res[:]
}
}

func (s *state11) ActorKey() string {
return actors.DatacapKey
}

func (s *state11) ActorVersion() actors.Version {
return actors.Version11
}

func (s *state11) Code() cid.Cid {
code, ok := actors.GetActorCodeID(s.ActorVersion(), s.ActorKey())
if !ok {
panic(fmt.Errorf("didn't find actor %v code id for actor version %d", s.ActorKey(), s.ActorVersion()))
}

return code
}
14 changes: 11 additions & 3 deletions chain/actors/builtin/init/init.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

151 changes: 151 additions & 0 deletions chain/actors/builtin/init/v11.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions chain/actors/builtin/market/market.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c48824d

Please sign in to comment.