Skip to content
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
18 changes: 0 additions & 18 deletions aclmapping/utils/identifier_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package utils

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
)

const (
Expand All @@ -24,18 +21,3 @@ func GetIdentifierTemplatePerModule(module string, identifier string) string {
func GetPrefixedIdentifierTemplatePerModule(module string, identifier string, prefix string) string {
return fmt.Sprintf("%s/%s/%s", module, prefix, identifier)
}

func GetOracleReadAccessOpsForValAndFeeder(feederAddr sdk.Address, valAddr sdk.Address) []sdkacltypes.AccessOperation {
return []sdkacltypes.AccessOperation{
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_ORACLE,
IdentifierTemplate: feederAddr.String(),
},
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_ORACLE,
IdentifierTemplate: valAddr.String(),
},
}
}
4 changes: 2 additions & 2 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk
anteDecorators := []sdk.AnteFullDecorator{
sdk.DefaultWrappedAnteDecorator(ante.NewSetUpContextDecorator(antedecorators.GetGasMeterSetter(*options.AccessControlKeeper))), // outermost AnteDecorator. SetUpContext must be called first
// TODO: have dex antehandler separate, and then call the individual antehandlers FROM the gasless antehandler decorator wrapper
sdk.DefaultWrappedAnteDecorator(antedecorators.NewGaslessDecorator([]sdk.AnteDecorator{}, *options.OracleKeeper, *options.NitroKeeper)),
antedecorators.NewGaslessDecorator([]sdk.AnteDecorator{}, *options.OracleKeeper, *options.NitroKeeper),
sdk.DefaultWrappedAnteDecorator(wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit)), // after setup context to enforce limits early
sdk.DefaultWrappedAnteDecorator(ante.NewRejectExtensionOptionsDecorator()),
sdk.DefaultWrappedAnteDecorator(oracle.NewSpammingPreventionDecorator(*options.OracleKeeper)),
oracle.NewSpammingPreventionDecorator(*options.OracleKeeper),
sdk.DefaultWrappedAnteDecorator(ante.NewValidateBasicDecorator()),
sdk.DefaultWrappedAnteDecorator(ante.NewTxTimeoutHeightDecorator()),
sdk.DefaultWrappedAnteDecorator(ante.NewValidateMemoDecorator(options.AccountKeeper)),
Expand Down
28 changes: 23 additions & 5 deletions app/antedecorators/gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
dextypes "github.com/sei-protocol/sei-chain/x/dex/types"
nitrokeeper "github.com/sei-protocol/sei-chain/x/nitro/keeper"
nitrotypes "github.com/sei-protocol/sei-chain/x/nitro/types"
Expand Down Expand Up @@ -52,12 +52,30 @@ func (gd GaslessDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sdk
// Error checking will be handled in AnteHandler
switch m := msg.(type) {
case *oracletypes.MsgAggregateExchangeRateVote:
feederAddr, _ := sdk.AccAddressFromBech32(m.Feeder)
valAddr, _ := sdk.ValAddressFromBech32(m.Validator)
deps = append(deps, aclutils.GetOracleReadAccessOpsForValAndFeeder(feederAddr, valAddr)...)
// TODO: add tx gasless deps for nitro for nitrokeeper read
// TODO: we also need to add READs for Validator + bonded check
deps = append(deps, []sdkacltypes.AccessOperation{
// validate feeder
// read feeder delegation for val addr - READ
{
ResourceType: sdkacltypes.ResourceType_KV_ORACLE_FEEDERS,
AccessType: sdkacltypes.AccessType_READ,
IdentifierTemplate: string(oracletypes.GetFeederDelegationKey(valAddr)),
},
// read validator from staking - READ
{
ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR,
AccessType: sdkacltypes.AccessType_READ,
IdentifierTemplate: string(stakingtypes.GetValidatorKey(valAddr)),
},
// check exchange rate vote exists - READ
{
ResourceType: sdkacltypes.ResourceType_KV_ORACLE_AGGREGATE_VOTES,
AccessType: sdkacltypes.AccessType_READ,
IdentifierTemplate: string(oracletypes.GetAggregateExchangeRateVoteKey(valAddr)),
},
}...)
default:
// TODO: add tx gasless deps for nitro for nitrokeeper read
continue
}
}
Expand Down
26 changes: 22 additions & 4 deletions x/oracle/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/sei-protocol/sei-chain/x/oracle/keeper"
"github.com/sei-protocol/sei-chain/x/oracle/types"
)
Expand Down Expand Up @@ -53,10 +53,28 @@ func (spd SpammingPreventionDecorator) AnteDeps(txDeps []sdkacltypes.AccessOpera
// Error checking will be handled in AnteHandler
switch m := msg.(type) {
case *types.MsgAggregateExchangeRateVote:
feederAddr, _ := sdk.AccAddressFromBech32(m.Feeder)
valAddr, _ := sdk.ValAddressFromBech32(m.Validator)
deps = append(deps, aclutils.GetOracleReadAccessOpsForValAndFeeder(feederAddr, valAddr)...)
// TODO: we also need to add READs for Validator + bonded check
deps = append(deps, []sdkacltypes.AccessOperation{
// validate feeder
// read feeder delegation for val addr - READ
{
ResourceType: sdkacltypes.ResourceType_KV_ORACLE_FEEDERS,
AccessType: sdkacltypes.AccessType_READ,
IdentifierTemplate: string(types.GetFeederDelegationKey(valAddr)),
},
// read validator from staking - READ
{
ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR,
AccessType: sdkacltypes.AccessType_READ,
IdentifierTemplate: string(stakingtypes.GetValidatorKey(valAddr)),
},
// check exchange rate vote exists - READ
{
ResourceType: sdkacltypes.ResourceType_KV_ORACLE_AGGREGATE_VOTES,
AccessType: sdkacltypes.AccessType_READ,
IdentifierTemplate: string(types.GetAggregateExchangeRateVoteKey(valAddr)),
},
}...)
default:
continue
}
Expand Down