Skip to content

Commit

Permalink
feat(cosmos): add some x/swingset fee charging params
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 2, 2021
1 parent 41ca6dc commit 53e43bb
Show file tree
Hide file tree
Showing 4 changed files with 389 additions and 41 deletions.
19 changes: 19 additions & 0 deletions golang/cosmos/proto/agoric/swingset/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];

string fee_denom = 3;

string fee_per_message = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string fee_per_message_byte = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string fee_per_message_slot = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string fee_per_inbound_tx = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

message Storage {
Expand Down
59 changes: 50 additions & 9 deletions golang/cosmos/x/swingset/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ import (
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

var (
// This is how many computrons we allow before starting a new block.
// Some analysis (#3459) suggests this leads to about 2/3rds utilization,
// based on 5 sec voting time and up to 10 sec of computation.
DefaultMaxComputronsPerBlock = sdk.NewInt(8000000)
// observed: 0.385 sec
DefaultEstimatedComputronsPerVatCreation = sdk.NewInt(300000)
)

// Parameter keys
var (
ParamStoreKeyMaxComputronsPerBlock = []byte("max_computrons_per_block")
ParamStoreKeyEstimatedComputronsPerVatCreation = []byte("estimated_computrons_per_vat_creation")
ParamStoreKeyFeeDenom = []byte("fee_denom")
ParamStoreKeyFeePerInboundTx = []byte("fee_per_inbound_tx")
ParamStoreKeyFeePerMessage = []byte("fee_per_message")
ParamStoreKeyFeePerMessageByte = []byte("fee_per_message_byte")
ParamStoreKeyFeePerMessageSlot = []byte("fee_per_message_slot")
)

// ParamKeyTable returns the parameter key table.
Expand All @@ -34,6 +30,11 @@ func DefaultParams() Params {
return Params{
MaxComputronsPerBlock: DefaultMaxComputronsPerBlock,
EstimatedComputronsPerVatCreation: DefaultEstimatedComputronsPerVatCreation,
FeeDenom: DefaultFeeDenom,
FeePerInboundTx: DefaultFeePerInboundTx,
FeePerMessage: DefaultFeePerMessage,
FeePerMessageByte: DefaultFeePerMessageByte,
FeePerMessageSlot: DefaultFeePerMessageSlot,
}
}

Expand All @@ -47,6 +48,11 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyMaxComputronsPerBlock, &p.MaxComputronsPerBlock, validateMaxComputronsPerBlock),
paramtypes.NewParamSetPair(ParamStoreKeyEstimatedComputronsPerVatCreation, &p.EstimatedComputronsPerVatCreation, validateEstimatedComputronsPerVatCreation),
paramtypes.NewParamSetPair(ParamStoreKeyFeeDenom, &p.FeeDenom, validateFeeDenom),
paramtypes.NewParamSetPair(ParamStoreKeyFeePerInboundTx, &p.FeePerInboundTx, validateFeePerInboundTx),
paramtypes.NewParamSetPair(ParamStoreKeyFeePerMessage, &p.FeePerMessage, validateFeePerMessage),
paramtypes.NewParamSetPair(ParamStoreKeyFeePerMessageByte, &p.FeePerMessageByte, validateFeePerMessageByte),
paramtypes.NewParamSetPair(ParamStoreKeyFeePerMessageSlot, &p.FeePerMessageSlot, validateFeePerMessageSlot),
}
}

Expand Down Expand Up @@ -84,3 +90,38 @@ func validateEstimatedComputronsPerVatCreation(i interface{}) error {

return nil
}

func validateFeeDenom(i interface{}) error {
v, ok := i.(string)
if !ok {
return fmt.Errorf("invalid fee denom parameter type: %T", i)
}

if err := sdk.ValidateDenom(v); err != nil {
return fmt.Errorf("invalid fee denom %s: %w", v, err)
}

return nil
}

func makeFeeValidator(description string) func(interface{}) error {
return func(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid %s parameter type: %T", description, i)
}

if v.IsNegative() {
return fmt.Errorf("%s amount must not be negative: %s", description, v)
}

return nil
}
}

var (
validateFeePerInboundTx = makeFeeValidator("fee per inbound tx")
validateFeePerMessage = makeFeeValidator("fee per message")
validateFeePerMessageByte = makeFeeValidator("fee per message byte")
validateFeePerMessageSlot = makeFeeValidator("fee per message slot")
)
27 changes: 27 additions & 0 deletions golang/cosmos/x/swingset/types/sim-params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// This should roughly match the values in
// `agoric-sdk/packages/cosmic-swingset/src/sim-params.js`.
//
// Nothing bad happens if they diverge, but it makes for a better simulation
// experience if they don't.
var (
// This is how many computrons we allow before starting a new block.
// Some analysis (#3459) suggests this leads to about 2/3rds utilization,
// based on 5 sec voting time and up to 10 sec of computation.
DefaultMaxComputronsPerBlock = sdk.NewInt(8000000)
// observed: 0.385 sec
DefaultEstimatedComputronsPerVatCreation = sdk.NewInt(300000)

// These fee defaults are denominated in urun.
DefaultFeeDenom = "urun"

DefaultFeePerInboundTx = sdk.MustNewDecFromStr("100")
DefaultFeePerMessage = sdk.MustNewDecFromStr("10")
DefaultFeePerMessageSlot = sdk.MustNewDecFromStr("1")
DefaultFeePerMessageByte = sdk.MustNewDecFromStr("0.02")
)

0 comments on commit 53e43bb

Please sign in to comment.