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

Beans per unit nondeterminism #4137

Merged
merged 2 commits into from
Dec 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
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 [
JimLarson marked this conversation as resolved.
Show resolved Hide resolved
(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),
}
)
Loading