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
22 changes: 21 additions & 1 deletion aclmapping/utils/identifier_templates.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package util

import "fmt"
import (
"fmt"

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

const (
ACCOUNT = "acc"
Expand All @@ -16,3 +21,18 @@ 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,
IdentifierTemplate: GetIdentifierTemplatePerModule("oracle", feederAddr.String()),
},
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV,
IdentifierTemplate: GetIdentifierTemplatePerModule("oracle", valAddr.String()),
},
}
}
10 changes: 5 additions & 5 deletions app/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func (app *App) CheckTx(ctx context.Context, req *abci.RequestCheckTx) (*abci.Re

func (app *App) DeliverTx(ctx sdk.Context, req abci.RequestDeliverTx) abci.ResponseDeliverTx {
defer metrics.MeasureDeliverTxDuration(time.Now())
// tracectx, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "DeliverTx")
// oldCtx := app.tracingInfo.TracerContext
// app.tracingInfo.TracerContext = tracectx
// defer span.End()
// defer func() { app.tracingInfo.TracerContext = oldCtx }()
tracectx, span := (*app.tracingInfo.Tracer).Start(app.tracingInfo.TracerContext, "DeliverTx")
oldCtx := app.tracingInfo.TracerContext
app.tracingInfo.TracerContext = tracectx
defer span.End()
defer func() { app.tracingInfo.TracerContext = oldCtx }()
return app.BaseApp.DeliverTx(ctx, req)
}

Expand Down
4 changes: 2 additions & 2 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk
sdk.DefaultWrappedAnteDecorator(ante.NewValidateBasicDecorator()),
sdk.DefaultWrappedAnteDecorator(ante.NewTxTimeoutHeightDecorator()),
sdk.DefaultWrappedAnteDecorator(ante.NewValidateMemoDecorator(options.AccountKeeper)),
sdk.CustomDepWrappedAnteDecorator(ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), depdecorators.SignerDepDecorator{ReadOnly: true}),
sdk.DefaultWrappedAnteDecorator(ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker)),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker),
// PriorityDecorator must be called after DeductFeeDecorator which sets tx priority based on tx fees
sdk.DefaultWrappedAnteDecorator(antedecorators.NewPriorityDecorator()),
// SetPubKeyDecorator must be called before all signature verification decorators
Expand Down
27 changes: 27 additions & 0 deletions app/antedecorators/gasless.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils"
dextypes "github.com/sei-protocol/sei-chain/x/dex/types"
oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper"
oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types"
Expand Down Expand Up @@ -38,6 +40,31 @@ func (gd GaslessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
return next(ctx.WithGasMeter(gaslessMeter), tx, simulate)
}

func (gd GaslessDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sdk.Tx, next sdk.AnteDepGenerator) (newTxDeps []sdkacltypes.AccessOperation, err error) {
deps := []sdkacltypes.AccessOperation{}
for _, msg := range tx.GetMsgs() {
// Error checking will be handled in AnteHandler
switch m := msg.(type) {
case *oracletypes.MsgAggregateExchangeRatePrevote:
feederAddr, _ := sdk.AccAddressFromBech32(m.Feeder)
valAddr, _ := sdk.ValAddressFromBech32(m.Validator)
deps = append(deps, aclutils.GetOracleReadAccessOpsForValAndFeeder(feederAddr, valAddr)...)
case *oracletypes.MsgAggregateExchangeRateVote:
feederAddr, _ := sdk.AccAddressFromBech32(m.Feeder)
valAddr, _ := sdk.ValAddressFromBech32(m.Validator)
deps = append(deps, aclutils.GetOracleReadAccessOpsForValAndFeeder(feederAddr, valAddr)...)
case *oracletypes.MsgAggregateExchangeRateCombinedVote:
feederAddr, _ := sdk.AccAddressFromBech32(m.Feeder)
valAddr, _ := sdk.ValAddressFromBech32(m.Validator)
deps = append(deps, aclutils.GetOracleReadAccessOpsForValAndFeeder(feederAddr, valAddr)...)
default:
continue
}
}

return next(append(txDeps, deps...), tx)
}

func isTxGasless(tx sdk.Tx, ctx sdk.Context, oracleKeeper oraclekeeper.Keeper) bool {
if len(tx.GetMsgs()) == 0 {
// empty TX shouldn't be gasless
Expand Down
11 changes: 9 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ func New(
app.BankKeeper.(bankkeeper.BaseKeeper).WithMintCoinsRestriction(tokenfactorytypes.NewTokenFactoryDenomMintCoinsRestriction()),
app.DistrKeeper,
)

customDependencyGenerators := aclmapping.NewCustomDependencyGenerator()
aclOpts = append(aclOpts, aclkeeper.WithDependencyGeneratorMappings(customDependencyGenerators.GetCustomDependencyGenerators()))
app.AccessControlKeeper = aclkeeper.NewKeeper(
Expand Down Expand Up @@ -1001,6 +1002,7 @@ func (app *App) ProcessTxConcurrent(
ctx = ctx.WithTxCompletionChannels(getChannelsFromSignalMapping(txCompletionSignalingMap))

// Deliver the transaction and store the result in the channel

resultChan <- ChannelResult{txIndex, app.DeliverTxWithResult(ctx, txBytes)}
metrics.IncrTxProcessTypeCounter(metrics.CONCURRENT)
}
Expand Down Expand Up @@ -1061,7 +1063,7 @@ func (app *App) ProcessBlockConcurrent(

func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequest, lastCommit abci.CommitInfo) ([]abci.Event, []*abci.ExecTxResult, abci.ResponseEndBlock, error) {
goCtx := app.decorateContextWithDexMemState(ctx.Context())
ctx = ctx.WithContext(goCtx)
ctx = ctx.WithContext(goCtx).WithContextMemCache(sdk.NewContextMemCache())

events := []abci.Event{}
beginBlockReq := abci.RequestBeginBlock{
Expand Down Expand Up @@ -1101,6 +1103,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
// app.batchVerifier.VerifyTxs(ctx, typedTxs)

dependencyDag, err := app.AccessControlKeeper.BuildDependencyDag(ctx, app.txDecoder, app.GetAnteDepGenerator(), txs)

var txResults []*abci.ExecTxResult

switch err {
Expand All @@ -1113,7 +1116,6 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
processBlockCtx, processBlockCache := app.CacheContext(ctx)
txResults = app.ProcessBlockConcurrent(processBlockCtx, txs, dependencyDag.CompletionSignalingMap, dependencyDag.BlockingSignalsMap)
// Write the results back to the concurrent contexts
ctx.Logger().Info("ProcessBlock:Writing processBlockCtx")
processBlockCache.Write()
case acltypes.ErrGovMsgInBlock:
ctx.Logger().Info(fmt.Sprintf("Gov msg found while building DAG, processing synchronously: %s", err))
Expand All @@ -1125,9 +1127,14 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ
metrics.IncrDagBuildErrorCounter(metrics.FailedToBuild)
}

// Finalize all Bank Module Transfers here so that events are included
lazyWriteEvents := app.BankKeeper.WriteDeferredDepositsToModuleAccounts(ctx)
events = append(events, lazyWriteEvents...)

endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{
Height: req.GetHeight(),
})

events = append(events, endBlockResp.Events...)

return events, txResults, endBlockResp, nil
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ require (
github.com/lib/pq v1.10.6 // indirect
github.com/libp2p/go-buffer-pool v0.0.2 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand Down Expand Up @@ -122,7 +122,7 @@ require (
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
Expand All @@ -131,7 +131,7 @@ require (
)

replace (
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.153
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.175
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.1.59
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,9 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
Expand Down Expand Up @@ -1097,8 +1098,8 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo=
github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sei-protocol/sei-cosmos v0.1.153 h1:6jDUjEicctFtcwZ+NjiNSGe1owFRlLGcam5bR+PFT64=
github.com/sei-protocol/sei-cosmos v0.1.153/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0=
github.com/sei-protocol/sei-cosmos v0.1.175 h1:JFeAe8NeUvAnt4423O51HLzePN2WTmLHWv8iXeWZTA0=
github.com/sei-protocol/sei-cosmos v0.1.175/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0=
github.com/sei-protocol/sei-tendermint v0.1.59 h1:POGL60PumMQHF4EzAHzvkGfDnodQJLHpl65LuiwSO/Y=
github.com/sei-protocol/sei-tendermint v0.1.59/go.mod h1:Olwbjyagrpoxj5DAUhHxMTWDVEfQ3FYdpypaJ3+6Hs8=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
Expand Down Expand Up @@ -1631,8 +1632,8 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
3 changes: 3 additions & 0 deletions loadtest/scripts/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,20 @@ def get_metrics():
for height in all_heights:
block_info_list.append(get_block_info(height))
# Skip first and last block since it may have high deviation if we start it at the end of the block

skip_edge_blocks = block_info_list[1:-1]
total_duration = skip_edge_blocks[-1]["timestamp"] - skip_edge_blocks[0]["timestamp"]
average_block_time = total_duration.total_seconds() / (len(skip_edge_blocks) - 1)
total_txs_num = sum([block["number_of_txs"] for block in skip_edge_blocks])
average_txs_num = total_txs_num / len(skip_edge_blocks)

return {
"Summary (excl. edge block)": {
"average_block_time": average_block_time,
"average_throughput_per_block": average_txs_num,
"average_throughput_per_sec": average_txs_num / average_block_time,
"number_of_full_blocks": len(skip_edge_blocks),
"full_blocks": all_heights[1:-1],
"total_txs_num": total_txs_num,
},
"Detail (incl. edge blocks)": {
Expand Down
1 change: 1 addition & 0 deletions loadtest/scripts/populate_genesis_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def add_genesis_account(account_name, lock, local=False):
subprocess.check_call(
[add_account_cmd],
shell=True,
timeout=20,
)
success = True
except subprocess.CalledProcessError as e:
Expand Down
29 changes: 28 additions & 1 deletion x/oracle/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"sync"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
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"
"github.com/sei-protocol/sei-chain/x/oracle/keeper"
"github.com/sei-protocol/sei-chain/x/oracle/types"
)
Expand Down Expand Up @@ -47,6 +49,31 @@ func (spd SpammingPreventionDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, si
return next(ctx, tx, simulate)
}

func (spd SpammingPreventionDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sdk.Tx, next sdk.AnteDepGenerator) (newTxDeps []sdkacltypes.AccessOperation, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are these AnteDeps functions going to look similar across all antes (i.e. oracle, gasless)? If so, maybe it'll make sense to have this somewhere centralized. If not, ffti

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tony did that in his PR - I'm going to remove my changes and rebase on his

deps := []sdkacltypes.AccessOperation{}
for _, msg := range tx.GetMsgs() {
// Error checking will be handled in AnteHandler
switch m := msg.(type) {
case *types.MsgAggregateExchangeRatePrevote:
feederAddr, _ := sdk.AccAddressFromBech32(m.Feeder)
valAddr, _ := sdk.ValAddressFromBech32(m.Validator)
deps = append(deps, aclutils.GetOracleReadAccessOpsForValAndFeeder(feederAddr, valAddr)...)
case *types.MsgAggregateExchangeRateVote:
feederAddr, _ := sdk.AccAddressFromBech32(m.Feeder)
valAddr, _ := sdk.ValAddressFromBech32(m.Validator)
deps = append(deps, aclutils.GetOracleReadAccessOpsForValAndFeeder(feederAddr, valAddr)...)
case *types.MsgAggregateExchangeRateCombinedVote:
feederAddr, _ := sdk.AccAddressFromBech32(m.Feeder)
valAddr, _ := sdk.ValAddressFromBech32(m.Validator)
deps = append(deps, aclutils.GetOracleReadAccessOpsForValAndFeeder(feederAddr, valAddr)...)
default:
continue
}
}

return next(append(txDeps, deps...), tx)
}

// CheckOracleSpamming check whether the msgs are spamming purpose or not
func (spd SpammingPreventionDecorator) CheckOracleSpamming(ctx sdk.Context, msgs []sdk.Msg) error {
spd.mu.Lock()
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func WeightedOperations(
}

// SimulateMsgAggregateExchangeRatePrevote generates a MsgAggregateExchangeRatePrevote with random values.
//nolint: funlen
// nolint: funlen
func SimulateMsgAggregateExchangeRatePrevote(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down Expand Up @@ -146,7 +146,7 @@ func SimulateMsgAggregateExchangeRatePrevote(ak types.AccountKeeper, bk types.Ba
}

// SimulateMsgAggregateExchangeRateVote generates a MsgAggregateExchangeRateVote with random values.
//nolint: funlen
// nolint: funlen
func SimulateMsgAggregateExchangeRateVote(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down Expand Up @@ -213,7 +213,7 @@ func SimulateMsgAggregateExchangeRateVote(ak types.AccountKeeper, bk types.BankK
}

// SimulateMsgDelegateFeedConsent generates a MsgDelegateFeedConsent with random values.
//nolint: funlen
// nolint: funlen
func SimulateMsgDelegateFeedConsent(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
Expand Down