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

Limit prepare execute gas #107

Merged
merged 4 commits into from
Jun 14, 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
6 changes: 5 additions & 1 deletion x/oracle/keeper/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/bandprotocol/chain/x/oracle/types"
)

const (
packetExpireTime = int64(10 * time.Minute)
)

// HasResult checks if the result of this request ID exists in the storage.
func (k Keeper) HasResult(ctx sdk.Context, id types.RequestID) bool {
return ctx.KVStore(k.storeKey).Has(types.ResultStoreKey(id))
Expand Down Expand Up @@ -129,7 +133,7 @@ func (k Keeper) SaveResult(
destinationPort,
destinationChannel,
clienttypes.NewHeight(0, 0),
uint64(ctx.BlockTime().UnixNano()+int64(10*time.Minute)), // TODO: Find what time out will be used on response packet
uint64(ctx.BlockTime().UnixNano()+packetExpireTime),
)

if err := k.channelKeeper.SendPacket(ctx, channelCap, packet); err != nil {
Expand Down
5 changes: 5 additions & 0 deletions x/oracle/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
TypeMsgActivate = "activate"
TypeMsgAddReporter = "add_reporter"
TypeMsgRemoveReporter = "remove_reporter"

maximumOwasmGas = 20000000 // The half of block gas limit
)

var (
Expand Down Expand Up @@ -88,6 +90,9 @@ func (msg MsgRequestData) ValidateBasic() error {
if msg.ExecuteGas <= 0 {
return sdkerrors.Wrapf(ErrInvalidOwasmGas, "invalid execute gas: %d", msg.ExecuteGas)
}
if msg.PrepareGas+msg.ExecuteGas > maximumOwasmGas {
return sdkerrors.Wrapf(ErrInvalidOwasmGas, "sum of prepare gas and execute gas (%d) exceed %d", msg.PrepareGas+msg.ExecuteGas, maximumOwasmGas)
}
if !msg.FeeLimit.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.FeeLimit.String())
}
Expand Down