Skip to content

Commit

Permalink
feat(cosmos): set swingset.params.bootstrap_vat_config at genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jan 12, 2022
1 parent f599585 commit 63e6e67
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 41 deletions.
16 changes: 9 additions & 7 deletions golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,13 +659,14 @@ func NewAgoricApp(
}

type cosmosInitAction struct {
Type string `json:"type"`
ChainID string `json:"chainID"`
StoragePort int `json:"storagePort"`
SupplyCoins sdk.Coins `json:"supplyCoins"`
VibcPort int `json:"vibcPort"`
VbankPort int `json:"vbankPort"`
LienPort int `json:"lienPort"`
Type string `json:"type"`
ChainID string `json:"chainID"`
Params swingset.Params `json:"params"`
StoragePort int `json:"storagePort"`
SupplyCoins sdk.Coins `json:"supplyCoins"`
VibcPort int `json:"vibcPort"`
VbankPort int `json:"vbankPort"`
LienPort int `json:"lienPort"`
}

// Name returns the name of the App
Expand All @@ -681,6 +682,7 @@ func (app *GaiaApp) MustInitController(ctx sdk.Context) {
action := &cosmosInitAction{
Type: "AG_COSMOS_INIT",
ChainID: ctx.ChainID(),
Params: app.SwingSetKeeper.GetParams(ctx),
StoragePort: vm.GetPort("storage"),
SupplyCoins: sdk.NewCoins(app.BankKeeper.GetSupply(ctx, "urun")),
VibcPort: app.vibcPort,
Expand Down
8 changes: 5 additions & 3 deletions golang/cosmos/proto/agoric/swingset/swingset.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ message Params {
// These values are used by SwingSet to normalize named per-resource charges
// (maybe rent) in a single Nat usage unit, the "bean".
//
// The structure and interpretation of this map and the units therein is
// entirely determined by the JS-level code.
//
// 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.
Expand All @@ -35,6 +32,11 @@ message Params {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];

// The SwingSet bootstrap vat configuration file. Not usefully modifiable
// via governance as it is only referenced by the chain's initial
// construction.
string bootstrap_vat_config = 3;
}

// Map element of a string key to a Nat bean count.
Expand Down
1 change: 1 addition & 0 deletions golang/cosmos/x/swingset/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ type (
Egress = types.Egress
MsgDeliverInbound = types.MsgDeliverInbound
MsgProvision = types.MsgProvision
Params = types.Params
Storage = types.Storage
)
2 changes: 2 additions & 0 deletions golang/cosmos/x/swingset/types/default-params.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ var (
NewStringBeans(BeansPerVatCreation, DefaultBeansPerVatCreation),
NewStringBeans(BeansPerXsnapComputron, DefaultBeansPerXsnapComputron),
}

DefaultBootstrapVatConfig = "@agoric/vats/decentral-config.json"
)
1 change: 1 addition & 0 deletions golang/cosmos/x/swingset/types/genesis.pb.go

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

27 changes: 23 additions & 4 deletions golang/cosmos/x/swingset/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (

// Parameter keys
var (
ParamStoreKeyBeansPerUnit = []byte("beans_per_unit")
ParamStoreKeyFeeUnitPrice = []byte("fee_unit_price")
ParamStoreKeyBeansPerUnit = []byte("beans_per_unit")
ParamStoreKeyBootstrapVatConfig = []byte("bootstrap_vat_config")
ParamStoreKeyFeeUnitPrice = []byte("fee_unit_price")
)

func NewStringBeans(key string, beans sdk.Uint) StringBeans {
Expand All @@ -30,8 +31,9 @@ func ParamKeyTable() paramtypes.KeyTable {
// DefaultParams returns default swingset parameters
func DefaultParams() Params {
return Params{
BeansPerUnit: DefaultBeansPerUnit,
FeeUnitPrice: DefaultFeeUnitPrice,
BeansPerUnit: DefaultBeansPerUnit,
BootstrapVatConfig: DefaultBootstrapVatConfig,
FeeUnitPrice: DefaultFeeUnitPrice,
}
}

Expand All @@ -45,6 +47,7 @@ func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyBeansPerUnit, &p.BeansPerUnit, validateBeansPerUnit),
paramtypes.NewParamSetPair(ParamStoreKeyFeeUnitPrice, &p.FeeUnitPrice, validateFeeUnitPrice),
paramtypes.NewParamSetPair(ParamStoreKeyBootstrapVatConfig, &p.BootstrapVatConfig, validateBootstrapVatConfig),
}
}

Expand All @@ -56,6 +59,9 @@ func (p Params) ValidateBasic() error {
if err := validateFeeUnitPrice(p.FeeUnitPrice); err != nil {
return err
}
if err := validateBootstrapVatConfig(p.BootstrapVatConfig); err != nil {
return err
}

return nil
}
Expand Down Expand Up @@ -92,3 +98,16 @@ func validateFeeUnitPrice(i interface{}) error {

return nil
}

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

if v == "" {
return fmt.Errorf("bootstrap vat config must not be empty")
}

return nil
}
110 changes: 83 additions & 27 deletions golang/cosmos/x/swingset/types/swingset.pb.go

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

0 comments on commit 63e6e67

Please sign in to comment.