Skip to content

Commit

Permalink
feat(cosmic-swingset): inboundQueue limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman authored and mergify[bot] committed Oct 5, 2022
1 parent a132187 commit 1b2d08f
Show file tree
Hide file tree
Showing 10 changed files with 525 additions and 74 deletions.
22 changes: 22 additions & 0 deletions golang/cosmos/proto/agoric/swingset/swingset.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ message Params {
repeated PowerFlagFee power_flag_fees = 4 [
(gogoproto.nullable) = false
];

// Maximum sizes for queues.
// These values are used by SwingSet to compute how many messages should be
// accepted in a block.
//
// There is no required order to this list of entries, but all the chain
// nodes must all serialize and deserialize the existing order without
// permuting it.
repeated QueueSize queue_max = 5 [
(gogoproto.nullable) = false
];
}

// Map element of a string key to a Nat bean count.
Expand Down Expand Up @@ -98,6 +109,17 @@ message PowerFlagFee {
];
}

// Map element of a string key to a size.
message QueueSize {
option (gogoproto.equal) = true;

// What the size is for.
string key = 1;

// The actual size value.
int32 size = 2;
}

// Egress is the format for a swingset egress.
message Egress {
option (gogoproto.equal) = false;
Expand Down
17 changes: 15 additions & 2 deletions golang/cosmos/x/swingset/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package swingset
import (
// "fmt"
// "os"
"encoding/json"
"time"

"github.com/cosmos/cosmos-sdk/telemetry"
Expand All @@ -22,6 +23,10 @@ type beginBlockAction struct {
Params types.Params `json:"params"`
}

type beginBlockResult struct {
QueueAllowed []types.QueueSize `json:"queue_allowed"`
}

type endBlockAction struct {
Type string `json:"type"`
BlockHeight int64 `json:"blockHeight"`
Expand All @@ -45,9 +50,17 @@ func BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock, keeper Keeper) erro
ChainID: ctx.ChainID(),
Params: keeper.GetParams(ctx),
}
_, err := keeper.BlockingSend(ctx, action)

out, err := keeper.BlockingSend(ctx, action)
// fmt.Fprintf(os.Stderr, "BEGIN_BLOCK Returned from SwingSet: %s, %v\n", out, err)

if out != "" {
var result beginBlockResult
err := json.Unmarshal([]byte(out), &result)
if err != nil {
panic(err)
}
}

return err
}

Expand Down
8 changes: 8 additions & 0 deletions golang/cosmos/x/swingset/types/default-params.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
BeansPerMinFeeDebit = "minFeeDebit"
BeansPerVatCreation = "vatCreation"
BeansPerXsnapComputron = "xsnapComputron"

QueueInbound = "inbound"
)

var (
Expand Down Expand Up @@ -59,4 +61,10 @@ var (
DefaultPowerFlagFees = []PowerFlagFee{
NewPowerFlagFee("SMART_WALLET", sdk.NewCoins(sdk.NewInt64Coin("ubld", 10_000_000))),
}

DefaultInboundQueueMax = int32(1_000)

DefaultQueueMax = []QueueSize{
NewQueueSize(QueueInbound, DefaultInboundQueueMax),
}
)
21 changes: 21 additions & 0 deletions golang/cosmos/x/swingset/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (
ParamStoreKeyBootstrapVatConfig = []byte("bootstrap_vat_config")
ParamStoreKeyFeeUnitPrice = []byte("fee_unit_price")
ParamStoreKeyPowerFlagFees = []byte("power_flag_fees")
ParamStoreKeyQueueMax = []byte("queue_max")
)

func NewStringBeans(key string, beans sdk.Uint) StringBeans {
Expand All @@ -31,6 +32,13 @@ func NewPowerFlagFee(powerFlag string, fee sdk.Coins) PowerFlagFee {
}
}

func NewQueueSize(key string, sz int32) QueueSize {
return QueueSize{
Key: key,
Size_: sz,
}
}

// ParamKeyTable returns the parameter key table.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
Expand All @@ -43,6 +51,7 @@ func DefaultParams() Params {
BootstrapVatConfig: DefaultBootstrapVatConfig,
FeeUnitPrice: DefaultFeeUnitPrice,
PowerFlagFees: DefaultPowerFlagFees,
QueueMax: DefaultQueueMax,
}
}

Expand All @@ -58,6 +67,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
paramtypes.NewParamSetPair(ParamStoreKeyFeeUnitPrice, &p.FeeUnitPrice, validateFeeUnitPrice),
paramtypes.NewParamSetPair(ParamStoreKeyBootstrapVatConfig, &p.BootstrapVatConfig, validateBootstrapVatConfig),
paramtypes.NewParamSetPair(ParamStoreKeyPowerFlagFees, &p.PowerFlagFees, validatePowerFlagFees),
paramtypes.NewParamSetPair(ParamStoreKeyQueueMax, &p.QueueMax, validateQueueMax),
}
}

Expand All @@ -75,6 +85,9 @@ func (p Params) ValidateBasic() error {
if err := validatePowerFlagFees(p.PowerFlagFees); err != nil {
return err
}
if err := validateQueueMax(p.QueueMax); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -142,3 +155,11 @@ func validatePowerFlagFees(i interface{}) error {

return nil
}

func validateQueueMax(i interface{}) error {
_, ok := i.([]QueueSize)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}

0 comments on commit 1b2d08f

Please sign in to comment.