Skip to content

Commit

Permalink
fix(cosmos): make a repeated array of entries for beans_per_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Dec 1, 2021
1 parent a1065c0 commit fa96b9a
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 237 deletions.
17 changes: 12 additions & 5 deletions golang/cosmos/proto/agoric/swingset/swingset.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ message Params {
//
// The structure and interpretation of this map and the units therein is
// entirely determined by the JS-level code.
map<string, Beans> beans_per_unit = 1 [
//
// 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 StringBeans beans_per_unit = 1 [
(gogoproto.nullable) = false
];

Expand All @@ -33,12 +37,15 @@ message Params {
];
}

// Beans are a Nat unit that is used to ascribe accounting value to other
// SwingSet-level units.
message Beans {
// Map element of a string key to a Nat bean count.
message StringBeans {
option (gogoproto.equal) = true;

string whole = 1 [
// What the beans are for.
string key = 1;

// The actual bean value.
string beans = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Uint",
(gogoproto.nullable) = false
];
Expand Down
15 changes: 8 additions & 7 deletions golang/cosmos/x/swingset/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ var (
ParamStoreKeyFeeUnitPrice = []byte("fee_unit_price")
)

func NewBeans(u sdk.Uint) Beans {
return Beans{
Whole: u,
func NewStringBeans(key string, beans sdk.Uint) StringBeans {
return StringBeans{
Key: key,
Beans: beans,
}
}

Expand Down Expand Up @@ -60,14 +61,14 @@ func (p Params) ValidateBasic() error {
}

func validateBeansPerUnit(i interface{}) error {
v, ok := i.(map[string]Beans)
v, ok := i.([]StringBeans)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}

for unit := range v {
if unit == "" {
return fmt.Errorf("unit must not be empty")
for _, sb := range v {
if sb.Key == "" {
return fmt.Errorf("key must not be empty")
}
}

Expand Down
18 changes: 9 additions & 9 deletions golang/cosmos/x/swingset/types/sim-params.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ var (
DefaultBeansPerMessageByte = DefaultBeansPerFeeUnit.Quo(sdk.NewUint(50000000)) // $0.0000002
DefaultBeansPerMinFeeDebit = DefaultBeansPerFeeUnit.Quo(sdk.NewUint(4)) // $0.25

DefaultBeansPerUnit = map[string]Beans{
BeansPerBlockComputeLimit: NewBeans(DefaultBeansPerBlockComputeLimit),
BeansPerFeeUnit: NewBeans(DefaultBeansPerFeeUnit),
BeansPerInboundTx: NewBeans(DefaultBeansPerInboundTx),
BeansPerMessage: NewBeans(DefaultBeansPerMessage),
BeansPerMessageByte: NewBeans(DefaultBeansPerMessageByte),
BeansPerMinFeeDebit: NewBeans(DefaultBeansPerMinFeeDebit),
BeansPerVatCreation: NewBeans(DefaultBeansPerVatCreation),
BeansPerXsnapComputron: NewBeans(DefaultBeansPerXsnapComputron),
DefaultBeansPerUnit = []StringBeans{
NewStringBeans(BeansPerBlockComputeLimit, DefaultBeansPerBlockComputeLimit),
NewStringBeans(BeansPerFeeUnit, DefaultBeansPerFeeUnit),
NewStringBeans(BeansPerInboundTx, DefaultBeansPerInboundTx),
NewStringBeans(BeansPerMessage, DefaultBeansPerMessage),
NewStringBeans(BeansPerMessageByte, DefaultBeansPerMessageByte),
NewStringBeans(BeansPerMinFeeDebit, DefaultBeansPerMinFeeDebit),
NewStringBeans(BeansPerVatCreation, DefaultBeansPerVatCreation),
NewStringBeans(BeansPerXsnapComputron, DefaultBeansPerXsnapComputron),
}
)

0 comments on commit fa96b9a

Please sign in to comment.