Skip to content

Commit

Permalink
fix from comments
Browse files Browse the repository at this point in the history
  • Loading branch information
colmazia committed Oct 4, 2023
1 parent ceae46d commit f503e97
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
22 changes: 12 additions & 10 deletions x/oracle/keeper/owasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ func ConvertToOwasmGas(cosmos uint64) uint64 {

// GetSpanSize return maximum value between MaxReportDataSize and MaxCallDataSize
func (k Keeper) GetSpanSize(ctx sdk.Context) uint64 {
if k.GetParams(ctx).MaxReportDataSize > k.GetParams(ctx).MaxCalldataSize {
return k.GetParams(ctx).MaxReportDataSize
params := k.GetParams(ctx)
if params.MaxReportDataSize > params.MaxCalldataSize {
return params.MaxReportDataSize
}
return k.GetParams(ctx).MaxCalldataSize
return params.MaxCalldataSize
}

// GetRandomValidators returns a pseudorandom subset of active validators. Each validator has
Expand Down Expand Up @@ -71,12 +72,13 @@ func (k Keeper) PrepareRequest(
}

askCount := r.GetAskCount()
if askCount > k.GetParams(ctx).MaxAskCount {
return 0, types.WrapMaxError(types.ErrInvalidAskCount, int(askCount), int(k.GetParams(ctx).MaxAskCount))
params := k.GetParams(ctx)
if askCount > params.MaxAskCount {
return 0, types.WrapMaxError(types.ErrInvalidAskCount, int(askCount), int(params.MaxAskCount))
}

// Consume gas for data requests.
ctx.GasMeter().ConsumeGas(askCount*k.GetParams(ctx).PerValidatorRequestGas, "PER_VALIDATOR_REQUEST_FEE")
ctx.GasMeter().ConsumeGas(askCount*params.PerValidatorRequestGas, "PER_VALIDATOR_REQUEST_FEE")

// Get a random validator set to perform this request.
validators, err := k.GetRandomValidators(ctx, int(askCount), k.GetRequestCount(ctx)+1)
Expand All @@ -93,8 +95,8 @@ func (k Keeper) PrepareRequest(
// Create an execution environment and call Owasm prepare function.
env := types.NewPrepareEnv(
req,
int64(k.GetParams(ctx).MaxCalldataSize),
int64(k.GetParams(ctx).MaxRawRequestCount),
int64(params.MaxCalldataSize),
int64(params.MaxRawRequestCount),
int64(k.GetSpanSize(ctx)),
)
script, err := k.GetOracleScript(ctx, req.OracleScriptID)
Expand All @@ -103,7 +105,7 @@ func (k Keeper) PrepareRequest(
}

// Consume fee and execute owasm code
ctx.GasMeter().ConsumeGas(k.GetParams(ctx).BaseOwasmGas, "BASE_OWASM_FEE")
ctx.GasMeter().ConsumeGas(params.BaseOwasmGas, "BASE_OWASM_FEE")
ctx.GasMeter().ConsumeGas(r.GetPrepareGas(), "OWASM_PREPARE_FEE")
code := k.GetFile(script.Filename)
output, err := k.owasmVM.Prepare(code, ConvertToOwasmGas(r.GetPrepareGas()), env)
Expand Down Expand Up @@ -142,7 +144,7 @@ func (k Keeper) PrepareRequest(
ctx.EventManager().EmitEvent(event)

// Subtract execute fee
ctx.GasMeter().ConsumeGas(k.GetParams(ctx).BaseOwasmGas, "BASE_OWASM_FEE")
ctx.GasMeter().ConsumeGas(params.BaseOwasmGas, "BASE_OWASM_FEE")
ctx.GasMeter().ConsumeGas(r.GetExecuteGas(), "OWASM_EXECUTE_FEE")

// Emit an event for each of the raw data requests.
Expand Down
3 changes: 0 additions & 3 deletions x/oracle/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
)

// AccountKeeper defines the expected account keeper.
Expand Down Expand Up @@ -47,8 +46,6 @@ type DistrKeeper interface {

// ChannelKeeper defines the expected IBC channel keeper
type ChannelKeeper interface {
GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel ibcchanneltypes.Channel, found bool)
GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool)
SendPacket(
ctx sdk.Context,
chanCap *capabilitytypes.Capability,
Expand Down

0 comments on commit f503e97

Please sign in to comment.