Skip to content

Commit

Permalink
Cleanup actor adapter templates
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Apr 30, 2021
1 parent 7336a78 commit 1cda986
Show file tree
Hide file tree
Showing 39 changed files with 315 additions and 66 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ type-gen: api-gen
method-gen: api-gen
(cd ./lotuspond/front/src/chain && go run ./methodgen.go)

actors-gen:
go run ./chain/actors/agen
go fmt ./...

api-gen:
go run ./gen/api
goimports -w api
Expand All @@ -341,9 +345,9 @@ api-gen:

docsgen: docsgen-md docsgen-openrpc

docsgen-md-bin: api-gen
docsgen-md-bin: api-gen actors-gen
go build $(GOFLAGS) -o docgen-md ./api/docgen/cmd
docsgen-openrpc-bin: api-gen
docsgen-openrpc-bin: api-gen actors-gen
go build $(GOFLAGS) -o docgen-openrpc ./api/docgen-openrpc/cmd

docsgen-md: docsgen-md-full docsgen-md-storage docsgen-md-worker
Expand All @@ -367,7 +371,7 @@ docsgen-openrpc-worker: docsgen-openrpc-bin

.PHONY: docsgen docsgen-md-bin docsgen-openrpc-bin

gen: type-gen method-gen docsgen api-gen
gen: actors-gen type-gen method-gen docsgen api-gen
@echo ">>> IF YOU'VE MODIFIED THE CLI, REMEMBER TO ALSO MAKE docsgen-cli"
.PHONY: gen

Expand Down
12 changes: 12 additions & 0 deletions chain/actors/builtin/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ import (
"github.com/filecoin-project/lotus/chain/types"

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 init() {

builtin.RegisterActorState(builtin0.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load0(store, root)
})

builtin.RegisterActorState(builtin2.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load2(store, root)
})

builtin.RegisterActorState(builtin3.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load3(store, root)
})

builtin.RegisterActorState(builtin4.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load4(store, root)
})
Expand All @@ -36,14 +43,19 @@ var Methods = builtin4.MethodsAccount

func Load(store adt.Store, act *types.Actor) (State, error) {
switch act.Code {

case builtin0.AccountActorCodeID:
return load0(store, act.Head)

case builtin2.AccountActorCodeID:
return load2(store, act.Head)

case builtin3.AccountActorCodeID:
return load3(store, act.Head)

case builtin4.AccountActorCodeID:
return load4(store, act.Head)

}
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
Expand Down
12 changes: 8 additions & 4 deletions chain/actors/builtin/account/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/types"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"{{end}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}
)

func init() {
{{range .versions}} builtin.RegisterActorState(builtin{{.}}.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
{{range .versions}}
builtin.RegisterActorState(builtin{{.}}.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load{{.}}(store, root)
})
{{end}}}
Expand All @@ -24,9 +26,11 @@ var Methods = builtin4.MethodsAccount

func Load(store adt.Store, act *types.Actor) (State, error) {
switch act.Code {
{{range .versions}} case builtin{{.}}.AccountActorCodeID:
{{range .versions}}
case builtin{{.}}.AccountActorCodeID:
return load{{.}}(store, act.Head)
{{end}} }
{{end}}
}
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}

Expand Down
12 changes: 8 additions & 4 deletions chain/actors/builtin/init/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import (
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/dtypes"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"{{end}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}
)

func init() {
{{range .versions}} builtin.RegisterActorState(builtin{{.}}.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
{{range .versions}}
builtin.RegisterActorState(builtin{{.}}.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load{{.}}(store, root)
})
{{end}}}
Expand All @@ -29,9 +31,11 @@ var (

func Load(store adt.Store, act *types.Actor) (State, error) {
switch act.Code {
{{range .versions}} case builtin{{.}}.InitActorCodeID:
{{range .versions}}
case builtin{{.}}.InitActorCodeID:
return load{{.}}(store, act.Head)
{{end}} }
{{end}}
}
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}

Expand Down
12 changes: 12 additions & 0 deletions chain/actors/builtin/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,28 @@ import (
"github.com/filecoin-project/lotus/node/modules/dtypes"

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 init() {

builtin.RegisterActorState(builtin0.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load0(store, root)
})

builtin.RegisterActorState(builtin2.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load2(store, root)
})

builtin.RegisterActorState(builtin3.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load3(store, root)
})

builtin.RegisterActorState(builtin4.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load4(store, root)
})
Expand All @@ -41,14 +48,19 @@ var (

func Load(store adt.Store, act *types.Actor) (State, error) {
switch act.Code {

case builtin0.InitActorCodeID:
return load0(store, act.Head)

case builtin2.InitActorCodeID:
return load2(store, act.Head)

case builtin3.InitActorCodeID:
return load3(store, act.Head)

case builtin4.InitActorCodeID:
return load4(store, act.Head)

}
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
Expand Down
7 changes: 5 additions & 2 deletions chain/actors/builtin/init/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package init
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
{{if (ge .v 3)}} builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin"
{{end}} "github.com/ipfs/go-cid"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/node/modules/dtypes"

{{if (ge .v 3)}}
builtin{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin"
{{end}}

init{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/builtin/init"
adt{{.v}} "github.com/filecoin-project/specs-actors{{.import}}actors/util/adt"
)
Expand Down
3 changes: 2 additions & 1 deletion chain/actors/builtin/init/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package init
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/node/modules/dtypes"

builtin3 "github.com/filecoin-project/specs-actors/v3/actors/builtin"

init3 "github.com/filecoin-project/specs-actors/v3/actors/builtin/init"
adt3 "github.com/filecoin-project/specs-actors/v3/actors/util/adt"
)
Expand Down
3 changes: 2 additions & 1 deletion chain/actors/builtin/init/v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package init
import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"
"golang.org/x/xerrors"

"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/node/modules/dtypes"

builtin4 "github.com/filecoin-project/specs-actors/v4/actors/builtin"

init4 "github.com/filecoin-project/specs-actors/v4/actors/builtin/init"
adt4 "github.com/filecoin-project/specs-actors/v4/actors/util/adt"
)
Expand Down
29 changes: 25 additions & 4 deletions chain/actors/builtin/market/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"

market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"
{{range .versions}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"{{end}}
builtin{{.}} "github.com/filecoin-project/specs-actors{{import .}}actors/builtin"
{{end}}

"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin"
"github.com/filecoin-project/lotus/chain/types"
)

func init() {
{{range .versions}} builtin.RegisterActorState(builtin{{.}}.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
{{range .versions}}
builtin.RegisterActorState(builtin{{.}}.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load{{.}}(store, root)
})
{{end}}}
Expand All @@ -31,9 +34,11 @@ var (

func Load(store adt.Store, act *types.Actor) (State, error) {
switch act.Code {
{{range .versions}} case builtin{{.}}.StorageMarketActorCodeID:
{{range .versions}}
case builtin{{.}}.StorageMarketActorCodeID:
return load{{.}}(store, act.Head)
{{end}} }
{{end}}
}
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}

Expand Down Expand Up @@ -136,3 +141,19 @@ func EmptyDealState() *DealState {
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)))

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
}

return ef, big.Sub(tf, ef)
}
14 changes: 13 additions & 1 deletion chain/actors/builtin/market/market.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
package market

import (
"github.com/filecoin-project/go-state-types/big"
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/ipfs/go-cid"
cbg "github.com/whyrusleeping/cbor-gen"

market0 "github.com/filecoin-project/specs-actors/actors/builtin/market"

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"

"github.com/filecoin-project/lotus/chain/actors/adt"
Expand All @@ -23,15 +26,19 @@ import (
)

func init() {

builtin.RegisterActorState(builtin0.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load0(store, root)
})

builtin.RegisterActorState(builtin2.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load2(store, root)
})

builtin.RegisterActorState(builtin3.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load3(store, root)
})

builtin.RegisterActorState(builtin4.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) {
return load4(store, root)
})
Expand All @@ -44,14 +51,19 @@ var (

func Load(store adt.Store, act *types.Actor) (State, error) {
switch act.Code {

case builtin0.StorageMarketActorCodeID:
return load0(store, act.Head)

case builtin2.StorageMarketActorCodeID:
return load2(store, act.Head)

case builtin3.StorageMarketActorCodeID:
return load3(store, act.Head)

case builtin4.StorageMarketActorCodeID:
return load4(store, act.Head)

}
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
}
Expand Down
Loading

0 comments on commit 1cda986

Please sign in to comment.