-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cosmos Gas Multiplier Params (#1565)
* Cosmos Gas Multiplier Params * Update ante dep decorators to remove unnecessary dep * bump sei-cosmos * Bump sei-wasmd * Update sei-cosmos to v0.2.83 --------- Co-authored-by: Uday Patil <[email protected]>
- Loading branch information
Showing
6 changed files
with
42 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,24 @@ | ||
package antedecorators | ||
|
||
import ( | ||
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" | ||
"github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" | ||
aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" | ||
acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" | ||
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" | ||
) | ||
|
||
const ( | ||
GasMultiplierNumerator uint64 = 1 | ||
DefaultGasMultiplierDenominator uint64 = 1 | ||
WasmCorrectDependencyDiscountDenominator uint64 = 2 | ||
) | ||
|
||
func GetGasMeterSetter(aclkeeper aclkeeper.Keeper) func(bool, sdk.Context, uint64, sdk.Tx) sdk.Context { | ||
func GetGasMeterSetter(pk paramskeeper.Keeper) func(bool, sdk.Context, uint64, sdk.Tx) sdk.Context { | ||
return func(simulate bool, ctx sdk.Context, gasLimit uint64, tx sdk.Tx) sdk.Context { | ||
if simulate || ctx.BlockHeight() == 0 { | ||
if ctx.BlockHeight() == 0 { | ||
return ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) | ||
} | ||
|
||
denominator := uint64(1) | ||
updatedGasDenominator := false | ||
for _, msg := range tx.GetMsgs() { | ||
candidateDenominator := getMessageMultiplierDenominator(ctx, msg, aclkeeper) | ||
if !updatedGasDenominator || candidateDenominator < denominator { | ||
updatedGasDenominator = true | ||
denominator = candidateDenominator | ||
} | ||
} | ||
return ctx.WithGasMeter(types.NewMultiplierGasMeter(gasLimit, DefaultGasMultiplierDenominator, denominator)) | ||
} | ||
} | ||
cosmosGasParams := pk.GetCosmosGasParams(ctx) | ||
|
||
func getMessageMultiplierDenominator(ctx sdk.Context, msg sdk.Msg, aclKeeper aclkeeper.Keeper) uint64 { | ||
// TODO: reason through whether it's reasonable to require non-* identifier for all operations | ||
// under the context of inter-contract changes | ||
// only give gas discount if none of the dependency (except COMMIT) has id "*" | ||
if wasmExecuteMsg, ok := msg.(*wasmtypes.MsgExecuteContract); ok { | ||
msgInfo, err := acltypes.NewExecuteMessageInfo(wasmExecuteMsg.Msg) | ||
if err != nil { | ||
return DefaultGasMultiplierDenominator | ||
} | ||
if messageContainsNoWildcardDependencies( | ||
ctx, | ||
aclKeeper, | ||
wasmExecuteMsg.Contract, | ||
msgInfo, | ||
wasmExecuteMsg.Sender, | ||
) { | ||
return WasmCorrectDependencyDiscountDenominator | ||
// In simulation, still use multiplier but with infinite gas limit | ||
if simulate { | ||
return ctx.WithGasMeter(types.NewInfiniteMultiplierGasMeter(cosmosGasParams.CosmosGasMultiplierNumerator, cosmosGasParams.CosmosGasMultiplierDenominator)) | ||
} | ||
} | ||
return DefaultGasMultiplierDenominator | ||
} | ||
|
||
// TODO: add tracing to measure latency | ||
func messageContainsNoWildcardDependencies( | ||
ctx sdk.Context, | ||
aclKeeper aclkeeper.Keeper, | ||
contractAddrStr string, | ||
msgInfo *acltypes.WasmMessageInfo, | ||
sender string, | ||
) bool { | ||
addr, err := sdk.AccAddressFromBech32(contractAddrStr) | ||
if err != nil { | ||
return false | ||
} | ||
accessOps, err := aclKeeper.GetWasmDependencyAccessOps(ctx, addr, sender, msgInfo, make(aclkeeper.ContractReferenceLookupMap)) | ||
if err != nil { | ||
return false | ||
return ctx.WithGasMeter(types.NewMultiplierGasMeter(gasLimit, cosmosGasParams.CosmosGasMultiplierNumerator, cosmosGasParams.CosmosGasMultiplierDenominator)) | ||
} | ||
for _, op := range accessOps { | ||
if op.AccessType != sdkacltypes.AccessType_COMMIT && op.IdentifierTemplate == "*" { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.