Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precommit batch balancer support/config #7410

Merged
merged 5 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions chain/actors/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ func GetDeclarationsMax(nwVer network.Version) (int, error) {
}
}

func AggregateNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
func AggregateProveCommitNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
v, err := actors.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
Expand Down Expand Up @@ -503,7 +503,43 @@ func AggregateNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.T

case actors.Version6:

return miner6.AggregateNetworkFee(aggregateSize, baseFee), nil
return miner6.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil

default:
return big.Zero(), xerrors.Errorf("unsupported network version")
}
}

func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
v, err := actors.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
}
switch v {

case actors.Version0:

return big.Zero(), nil

case actors.Version2:

return big.Zero(), nil

case actors.Version3:

return big.Zero(), nil

case actors.Version4:

return big.Zero(), nil

case actors.Version5:

return big.Zero(), nil

case actors.Version6:

return miner6.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil

default:
return big.Zero(), xerrors.Errorf("unsupported network version")
Expand Down
27 changes: 24 additions & 3 deletions chain/actors/policy/policy.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,39 @@ func GetDeclarationsMax(nwVer network.Version) (int, error) {
}
}

func AggregateNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
func AggregateProveCommitNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
v, err := actors.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
}
switch v {
{{range .versions}}
case actors.Version{{.}}:
{{if (le . 4)}}
{{if (ge . 6)}}
return miner{{.}}.AggregateProveCommitNetworkFee(aggregateSize, baseFee), nil
{{else if (eq . 5)}}
return miner{{.}}.AggregateNetworkFee(aggregateSize, baseFee), nil
{{else}}
return big.Zero(), nil
{{end}}
{{end}}
default:
return big.Zero(), xerrors.Errorf("unsupported network version")
}
}

func AggregatePreCommitNetworkFee(nwVer network.Version, aggregateSize int, baseFee abi.TokenAmount) (abi.TokenAmount, error) {
v, err := actors.VersionForNetwork(nwVer)
if err != nil {
return big.Zero(), err
}
switch v {
{{range .versions}}
case actors.Version{{.}}:
{{if (ge . 6)}}
return miner{{.}}.AggregatePreCommitNetworkFee(aggregateSize, baseFee), nil
{{else}}
return miner{{.}}.AggregateNetworkFee(aggregateSize, baseFee), nil
return big.Zero(), nil
{{end}}
{{end}}
default:
Expand Down
1 change: 0 additions & 1 deletion chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
if err != nil {
return xerrors.Errorf("failed to create genesis miner (publish deals): %w", err)
}

retval, err := market.DecodePublishStorageDealsReturn(ret, nv)
if err != nil {
return xerrors.Errorf("failed to create genesis miner (decoding published deals): %w", err)
Expand Down
49 changes: 44 additions & 5 deletions cmd/lotus-shed/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ import (
"os"
"strings"

miner6 "github.com/filecoin-project/specs-actors/v6/actors/builtin/miner"

"github.com/urfave/cli/v2"
"golang.org/x/xerrors"

"github.com/filecoin-project/lotus/chain/types"
miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner"
)

var mathCmd = &cli.Command{
Name: "math",
Usage: "utility commands around doing math on a list of numbers",
Subcommands: []*cli.Command{
mathSumCmd,
mathAggFeesCmd,
mathPreCommitAggFeesCmd,
mathProveCommitAggFeesCmd,
},
}

Expand Down Expand Up @@ -105,8 +107,8 @@ var mathSumCmd = &cli.Command{
},
}

var mathAggFeesCmd = &cli.Command{
Name: "agg-fees",
var mathProveCommitAggFeesCmd = &cli.Command{
Name: "agg-fees-commit",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "size",
Expand All @@ -117,6 +119,43 @@ var mathAggFeesCmd = &cli.Command{
Usage: "baseFee aFIL",
Required: true,
},
&cli.StringFlag{
Name: "base-fee",
Usage: "baseFee aFIL",
Required: true,
},
},
Action: func(cctx *cli.Context) error {
as := cctx.Int("size")

bf, err := types.BigFromString(cctx.String("base-fee"))
if err != nil {
return xerrors.Errorf("parsing basefee: %w", err)
}

fmt.Println(types.FIL(miner6.AggregateProveCommitNetworkFee(as, bf)))

return nil
},
}

var mathPreCommitAggFeesCmd = &cli.Command{
Name: "agg-fees-precommit",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "size",
Required: true,
},
&cli.StringFlag{
Name: "base-fee",
Usage: "baseFee aFIL",
Required: true,
},
&cli.StringFlag{
Name: "base-fee",
Usage: "baseFee aFIL",
Required: true,
},
},
Action: func(cctx *cli.Context) error {
as := cctx.Int("size")
Expand All @@ -126,7 +165,7 @@ var mathAggFeesCmd = &cli.Command{
return xerrors.Errorf("parsing basefee: %w", err)
}

fmt.Println(types.FIL(miner5.AggregateNetworkFee(as, bf)))
fmt.Println(types.FIL(miner6.AggregatePreCommitNetworkFee(as, bf)))

return nil
},
Expand Down
7 changes: 4 additions & 3 deletions extern/storage-sealing/commit_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,12 @@ func (b *CommitBatcher) processBatch(cfg sealiface.Config) ([]sealiface.CommitBa
return []sealiface.CommitBatchRes{res}, xerrors.Errorf("getting network version: %s", err)
}

aggFeeRaw, err := policy.AggregateNetworkFee(nv, len(infos), bf)
aggFeeRaw, err := policy.AggregateProveCommitNetworkFee(nv, len(infos), bf)
if err != nil {
log.Errorf("getting aggregate network fee: %s", err)
return []sealiface.CommitBatchRes{res}, xerrors.Errorf("getting aggregate network fee: %s", err)
log.Errorf("getting aggregate commit network fee: %s", err)
return []sealiface.CommitBatchRes{res}, xerrors.Errorf("getting aggregate commit network fee: %s", err)
}

aggFee := big.Div(big.Mul(aggFeeRaw, aggFeeNum), aggFeeDen)

needFunds := big.Add(collateral, aggFee)
Expand Down
3 changes: 2 additions & 1 deletion extern/storage-sealing/commit_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func TestCommitBatcher(t *testing.T) {
CommitBatchWait: 24 * time.Hour,
CommitBatchSlack: 1 * time.Hour,

AggregateAboveBaseFee: types.BigMul(types.PicoFil, types.NewInt(150)), // 0.15 nFIL
AggregateAboveBaseFee: types.BigMul(types.PicoFil, types.NewInt(150)), // 0.15 nFIL
BatchPreCommitAboveBaseFee: types.BigMul(types.PicoFil, types.NewInt(150)), // 0.15 nFIL

TerminateBatchMin: 1,
TerminateBatchMax: 100,
Expand Down
31 changes: 31 additions & 0 deletions extern/storage-sealing/mocks/mock_precommit_batcher.go

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

Loading