From 8d83c713a5b97a0670e4109df9eceb2c86de1619 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 01/41] Revert "Update Antehandler resource depedencies (#354)" This reverts commit 6c672fbd0179769138f488c3797c5ee5a8a41be4. --- app/ante_test.go | 209 -------------------- app/antedecorators/depdecorators/signers.go | 5 +- app/apptesting/test_suite.go | 3 +- go.mod | 2 +- go.sum | 4 +- 5 files changed, 7 insertions(+), 216 deletions(-) delete mode 100644 app/ante_test.go diff --git a/app/ante_test.go b/app/ante_test.go deleted file mode 100644 index ef2b364e4c..0000000000 --- a/app/ante_test.go +++ /dev/null @@ -1,209 +0,0 @@ -package app_test - -import ( - "context" - "testing" - - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/tx" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/simapp" - "github.com/cosmos/cosmos-sdk/testutil/testdata" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - "github.com/cosmos/cosmos-sdk/types/tx/signing" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - - "github.com/cosmos/cosmos-sdk/x/auth/ante" - xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils" - app "github.com/sei-protocol/sei-chain/app" - "github.com/sei-protocol/sei-chain/app/apptesting" - "github.com/sei-protocol/sei-chain/utils/tracing" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - "go.opentelemetry.io/otel" -) - -// AnteTestSuite is a test suite to be used with ante handler tests. -type AnteTestSuite struct { - apptesting.KeeperTestHelper - - anteHandler sdk.AnteHandler - anteDepGenerator sdk.AnteDepGenerator - clientCtx client.Context - txBuilder client.TxBuilder - testAcc sdk.AccAddress - testAccPriv cryptotypes.PrivKey -} - -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(AnteTestSuite)) -} - -// SetupTest setups a new test, with new app, context, and anteHandler. -func (suite *AnteTestSuite) SetupTest(isCheckTx bool) { - suite.Setup() - - // keys and addresses - suite.testAccPriv, _, suite.testAcc = testdata.KeyTestPubAddr() - initalBalance := sdk.Coins{sdk.NewInt64Coin("atom", 100000000000)} - suite.FundAcc(suite.testAcc, initalBalance) - - suite.Ctx = suite.Ctx.WithBlockHeight(1) - - msgValidator := sdkacltypes.NewMsgValidator(aclutils.StoreKeyToResourceTypePrefixMap) - suite.Ctx = suite.Ctx.WithMsgValidator(msgValidator) - - // Set up TxConfig. - encodingConfig := simapp.MakeTestEncodingConfig() - // We're using TestMsg encoding in some tests, so register it here. - encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil) - testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry) - - suite.clientCtx = client.Context{}. - WithTxConfig(encodingConfig.TxConfig) - - wasmConfig := wasmtypes.DefaultWasmConfig() - defaultTracer, _ := tracing.DefaultTracerProvider() - otel.SetTracerProvider(defaultTracer) - tr := defaultTracer.Tracer("component-main") - - antehandler, anteDepGenerator, err := app.NewAnteHandlerAndDepGenerator( - app.HandlerOptions{ - HandlerOptions: ante.HandlerOptions{ - AccountKeeper: suite.App.AccountKeeper, - BankKeeper: suite.App.BankKeeper, - FeegrantKeeper: suite.App.FeeGrantKeeper, - SignModeHandler: suite.clientCtx.TxConfig.SignModeHandler(), - SigGasConsumer: ante.DefaultSigVerificationGasConsumer, - // BatchVerifier: app.batchVerifier, - }, - IBCKeeper: suite.App.IBCKeeper, - WasmConfig: &wasmConfig, - OracleKeeper: &suite.App.OracleKeeper, - DexKeeper: &suite.App.DexKeeper, - NitroKeeper: &suite.App.NitroKeeper, - AccessControlKeeper: &suite.App.AccessControlKeeper, - TracingInfo: &tracing.Info{ - Tracer: &tr, - TracerContext: context.Background(), - }, - }, - ) - - suite.Require().NoError(err) - suite.anteHandler = antehandler - suite.anteDepGenerator = anteDepGenerator -} - -func (suite *AnteTestSuite) AnteHandlerValidateAccessOp(acessOps []sdkacltypes.AccessOperation) error { - for _, accessOp := range acessOps { - err := acltypes.ValidateAccessOp(accessOp) - if err != nil { - return err - } - } - return nil -} - -// CreateTestTx is a helper function to create a tx given multiple inputs. -func (suite *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) { - // First round: we gather all the signer infos. We use the "set empty - // signature" hack to do that. - var sigsV2 []signing.SignatureV2 - for i, priv := range privs { - sigV2 := signing.SignatureV2{ - PubKey: priv.PubKey(), - Data: &signing.SingleSignatureData{ - SignMode: suite.clientCtx.TxConfig.SignModeHandler().DefaultMode(), - Signature: nil, - }, - Sequence: accSeqs[i], - } - - sigsV2 = append(sigsV2, sigV2) - } - err := suite.txBuilder.SetSignatures(sigsV2...) - if err != nil { - return nil, err - } - - // Second round: all signer infos are set, so each signer can sign. - sigsV2 = []signing.SignatureV2{} - for i, priv := range privs { - signerData := xauthsigning.SignerData{ - ChainID: chainID, - AccountNumber: accNums[i], - Sequence: accSeqs[i], - } - sigV2, err := tx.SignWithPrivKey( - suite.clientCtx.TxConfig.SignModeHandler().DefaultMode(), signerData, - suite.txBuilder, priv, suite.clientCtx.TxConfig, accSeqs[i]) - if err != nil { - return nil, err - } - - sigsV2 = append(sigsV2, sigV2) - } - err = suite.txBuilder.SetSignatures(sigsV2...) - if err != nil { - return nil, err - } - - return suite.txBuilder.GetTx(), nil -} - -func (suite *AnteTestSuite) TestValidateDepedencies() { - suite.SetupTest(true) // setup - suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder() - - // msg and signatures - msg := testdata.NewTestMsg(suite.testAcc) - feeAmount := testdata.NewTestFeeAmount() - gasLimit := testdata.NewTestGasLimit() - suite.Require().NoError(suite.txBuilder.SetMsgs(msg)) - suite.txBuilder.SetFeeAmount(feeAmount) - suite.txBuilder.SetGasLimit(gasLimit) - - privs, accNums, accSeqs := []cryptotypes.PrivKey{}, []uint64{}, []uint64{} - invalidTx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.Ctx.ChainID()) - suite.Require().NoError(err) - - _, err = suite.anteHandler(suite.Ctx, invalidTx, false) - - suite.Require().NotNil(err, "Did not error on invalid tx") - - privs, accNums, accSeqs = []cryptotypes.PrivKey{suite.testAccPriv}, []uint64{8}, []uint64{0} - - handlerCtx, cms := aclutils.CacheTxContext(suite.Ctx) - validTx, err := suite.CreateTestTx(privs, accNums, accSeqs, suite.Ctx.ChainID()) - - suite.Require().NoError(err) - depdenencies, _ := suite.anteDepGenerator([]sdkacltypes.AccessOperation{}, validTx) - _, err = suite.anteHandler(handlerCtx, validTx, false) - suite.Require().Nil(err, "ValidateBasicDecorator returned error on valid tx. err: %v", err) - err = suite.AnteHandlerValidateAccessOp(depdenencies) - - require.NoError(suite.T(), err) - - missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - suite.Require().Empty(missing) - - // test decorator skips on recheck - suite.Ctx = suite.Ctx.WithIsReCheckTx(true) - - // decorator should skip processing invalidTx on recheck and thus return nil-error - handlerCtx, cms = aclutils.CacheTxContext(suite.Ctx) - depdenencies, _ = suite.anteDepGenerator([]sdkacltypes.AccessOperation{}, invalidTx) - _, err = suite.anteHandler(handlerCtx, invalidTx, false) - missing = handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - - err = suite.AnteHandlerValidateAccessOp(depdenencies) - require.NoError(suite.T(), err) - - suite.Require().Empty(missing) - - suite.Require().Nil(err, "ValidateBasicDecorator ran on ReCheck") -} diff --git a/app/antedecorators/depdecorators/signers.go b/app/antedecorators/depdecorators/signers.go index 9d8043c3b8..f123e8dca5 100644 --- a/app/antedecorators/depdecorators/signers.go +++ b/app/antedecorators/depdecorators/signers.go @@ -6,6 +6,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + utils "github.com/sei-protocol/sei-chain/aclmapping/utils" ) type SignerDepDecorator struct { @@ -26,8 +27,8 @@ func (d SignerDepDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sd for _, signer := range sigTx.GetSigners() { txDeps = append(txDeps, sdkacltypes.AccessOperation{ AccessType: accessType, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(signer)), + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetPrefixedIdentifierTemplatePerModule(utils.ACCOUNT, signer.String(), string(authtypes.AddressStoreKeyPrefix)), }) } return next(txDeps, tx) diff --git a/app/apptesting/test_suite.go b/app/apptesting/test_suite.go index 01c71943d3..860d6192c3 100644 --- a/app/apptesting/test_suite.go +++ b/app/apptesting/test_suite.go @@ -143,8 +143,7 @@ func (s *KeeperTestHelper) BuildTx( txBuilder client.TxBuilder, msgs []sdk.Msg, sigV2 signing.SignatureV2, - memo string, - txFee sdk.Coins, + memo string, txFee sdk.Coins, gasLimit uint64, ) authsigning.Tx { err := txBuilder.SetMsgs(msgs[0]) diff --git a/go.mod b/go.mod index 8e1dadb5e3..193c90e1c0 100644 --- a/go.mod +++ b/go.mod @@ -133,7 +133,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.249 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.246 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 diff --git a/go.sum b/go.sum index fea46d9317..0db4cedab9 100644 --- a/go.sum +++ b/go.sum @@ -1101,8 +1101,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.249 h1:beHuyOOGxDewo1G7l067OPO56BKyfVi1boDiuS8jNfw= -github.com/sei-protocol/sei-cosmos v0.1.249/go.mod h1:KPV8lFdD2Ki/M2wZTpfX3LCcuMAZnmcUzYJycjbmOYM= +github.com/sei-protocol/sei-cosmos v0.1.246 h1:qX6ycebWYECnh9DIP9xqCFHVgJ8U4yHuR+asr/vuOVE= +github.com/sei-protocol/sei-cosmos v0.1.246/go.mod h1:KPV8lFdD2Ki/M2wZTpfX3LCcuMAZnmcUzYJycjbmOYM= 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= From 252698bef16c8d5c3e9548943c62b1a70c202eaa Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 02/41] Revert "update staking validation identifier (#353)" This reverts commit 8a17c26d80e7bfdeee29a6e3482c6cae97e16f3b. --- aclmapping/staking/mappings.go | 541 ++++------------------- aclmapping/staking/mappings_test.go | 349 +++------------ aclmapping/tokenfactory/mappings.go | 2 +- aclmapping/tokenfactory/mappings_test.go | 2 +- aclmapping/utils/resource_type.go | 32 +- app/app.go | 1 - go.mod | 2 +- go.sum | 4 +- store/testutils.go | 2 +- 9 files changed, 133 insertions(+), 802 deletions(-) diff --git a/aclmapping/staking/mappings.go b/aclmapping/staking/mappings.go index 70a280f1c8..ed3eb9fc8c 100644 --- a/aclmapping/staking/mappings.go +++ b/aclmapping/staking/mappings.go @@ -7,10 +7,8 @@ import ( 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" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + utils "github.com/sei-protocol/sei-chain/aclmapping/utils" ) var ErrorInvalidMsgType = fmt.Errorf("invalid message received for staking module") @@ -34,168 +32,64 @@ func MsgDelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, ms return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType } - bondedModuleAdr := keeper.AccountKeeper.GetModuleAddress(stakingtypes.BondedPoolName) - notBondedModuleAdr := keeper.AccountKeeper.GetModuleAddress(stakingtypes.NotBondedPoolName) - - delegateAddr, _ := sdk.AccAddressFromBech32(msgDelegate.DelegatorAddress) - validatorAddr, _ := sdk.ValAddressFromBech32(msgDelegate.ValidatorAddress) - - validator, _ := keeper.StakingKeeper.GetValidator(ctx, validatorAddr) - // validatorCons, _ := validator.GetConsAddr() - // validatorAddrCons := string(stakingtypes.GetValidatorByConsAddrKey(validatorCons)) - // validatorOperatorAddr := validator.GetOperator().String() - - delegationKey := string(stakingtypes.GetDelegationKey(delegateAddr, validatorAddr)) - validatorKey := string(stakingtypes.GetValidatorKey(validatorAddr)) - delegatorBalanceKey := string(banktypes.CreateAccountBalancesPrefixFromBech32(msgDelegate.DelegatorAddress)) - validatorBalanceKey := string(banktypes.CreateAccountBalancesPrefixFromBech32(msgDelegate.ValidatorAddress)) - // validatorOperatorBalanceKey := string(banktypes.CreateAccountBalancesPrefixFromBech32(validatorOperatorAddr)) - accessOperations := []sdkacltypes.AccessOperation{ - // Treat Delegations and Undelegations to have the same ACL since they are highly coupled, no point in finer granularization - - // Get delegation/redelegations and error checking + // Checks if the delegator exists + // Checks if there is a delegation object that already exists for (delegatorAddr, validatorAddr) { AccessType: sdkacltypes.AccessType_READ, ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, - IdentifierTemplate: delegationKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.DelegatorAddress+msgDelegate.ValidatorAddress), }, - // Update/delete delegation and update redelegation + // Store new delegator for (delegator, validator) { AccessType: sdkacltypes.AccessType_WRITE, ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, - IdentifierTemplate: delegationKey, - }, - - // Check Unbonding - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER, - IdentifierTemplate: string(stakingtypes.GetValidatorsByPowerIndexKey(validator, keeper.StakingKeeper.PowerReduction(ctx))), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER, - IdentifierTemplate: string(stakingtypes.GetValidatorsByPowerIndexKey(validator, keeper.StakingKeeper.PowerReduction(ctx))), - }, - - // Before Unbond Distribution Hook - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO, - IdentifierTemplate: string(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO, - IdentifierTemplate: string(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorCurrentRewardsKey(validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorCurrentRewardsKey(validatorAddr)), - }, - - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_OUTSTANDING_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorOutstandingRewardsKey(validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_OUTSTANDING_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorOutstandingRewardsKey(validatorAddr)), + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.DelegatorAddress+msgDelegate.ValidatorAddress), }, + // delegate coins from account validator account { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_FEE_POOL, - IdentifierTemplate: string(distributiontypes.FeePoolKey), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_FEE_POOL, - IdentifierTemplate: string(distributiontypes.FeePoolKey), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.DelegatorAddress), }, - { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorHistoricalRewardsPrefix(validatorAddr)), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.ValidatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorHistoricalRewardsPrefix(validatorAddr)), - }, - - // Gets Module Account information - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(bondedModuleAdr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(notBondedModuleAdr)), - }, - - // Get Delegator Acc Info - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(delegateAddr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(delegateAddr)), - }, - - // Update the delegator and validator account balances - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: delegatorBalanceKey, - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: delegatorBalanceKey, - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: validatorBalanceKey, - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: validatorBalanceKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.ValidatorAddress), }, // Checks if the validators exchange rate is valid { AccessType: sdkacltypes.AccessType_READ, ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, - IdentifierTemplate: validatorKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.ValidatorAddress), }, // Update validator shares and power index { AccessType: sdkacltypes.AccessType_WRITE, ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, - IdentifierTemplate: validatorKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.ValidatorAddress), }, // Last Operation should always be a commit - *acltypes.CommitAccessOp(), + { + ResourceType: sdkacltypes.ResourceType_ANY, + AccessType: sdkacltypes.AccessType_COMMIT, + IdentifierTemplate: utils.DefaultIDTemplate, + }, } + return accessOperations, nil } @@ -204,20 +98,6 @@ func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, if !ok { return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType } - bondedModuleAdr := keeper.AccountKeeper.GetModuleAddress(stakingtypes.BondedPoolName) - notBondedModuleAdr := keeper.AccountKeeper.GetModuleAddress(stakingtypes.NotBondedPoolName) - - delegateAddr, _ := sdk.AccAddressFromBech32(msgUndelegate.DelegatorAddress) - validatorAddr, _ := sdk.ValAddressFromBech32(msgUndelegate.ValidatorAddress) - - validator, _ := keeper.StakingKeeper.GetValidator(ctx, validatorAddr) - validatorCons, _ := validator.GetConsAddr() - validatorAddrCons := string(stakingtypes.GetValidatorByConsAddrKey(validatorCons)) - - delegationKey := string(stakingtypes.GetDelegationKey(delegateAddr, validatorAddr)) - validatorKey := string(stakingtypes.GetValidatorKey(validatorAddr)) - delegatorBalanceKey := string(banktypes.CreateAccountBalancesPrefixFromBech32(msgUndelegate.DelegatorAddress)) - validatorBalanceKey := string(banktypes.CreateAccountBalancesPrefixFromBech32(msgUndelegate.ValidatorAddress)) accessOperations := []sdkacltypes.AccessOperation{ // Treat Delegations and Undelegations to have the same ACL since they are highly coupled, no point in finer granularization @@ -226,180 +106,56 @@ func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, { AccessType: sdkacltypes.AccessType_READ, ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, - IdentifierTemplate: delegationKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.DelegatorAddress+msgUndelegate.ValidatorAddress), }, // Update/delete delegation and update redelegation { AccessType: sdkacltypes.AccessType_WRITE, ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, - IdentifierTemplate: delegationKey, - }, - - // Check Unbonding - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_UNBONDING_DELEGATION, - IdentifierTemplate: string(stakingtypes.GetUBDKey(delegateAddr, validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_UNBONDING_DELEGATION, - IdentifierTemplate: string(stakingtypes.GetUBDKey(delegateAddr, validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_UNBONDING_DELEGATION_VAL, - IdentifierTemplate: string(stakingtypes.GetUBDsByValIndexKey(validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_UNBONDING_DELEGATION_VAL, - IdentifierTemplate: string(stakingtypes.GetUBDsByValIndexKey(validatorAddr)), - }, - - // Testing - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_UNBONDING_DELEGATION, - IdentifierTemplate: delegationKey, - }, - - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_UNBONDING, - IdentifierTemplate: string(stakingtypes.UnbondingQueueKey), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_UNBONDING, - IdentifierTemplate: string(stakingtypes.UnbondingQueueKey), - }, - - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_CON_ADDR, - IdentifierTemplate: validatorAddrCons, - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_CON_ADDR, - IdentifierTemplate: string(stakingtypes.GetUBDsByValIndexKey(validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER, - IdentifierTemplate: string(stakingtypes.GetValidatorsByPowerIndexKey(validator, keeper.StakingKeeper.PowerReduction(ctx))), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER, - IdentifierTemplate: string(stakingtypes.GetValidatorsByPowerIndexKey(validator, keeper.StakingKeeper.PowerReduction(ctx))), - }, - - // Before Unbond Distribution Hook - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO, - IdentifierTemplate: string(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorCurrentRewardsKey(validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorCurrentRewardsKey(validatorAddr)), - }, - - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_OUTSTANDING_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorOutstandingRewardsKey(validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_OUTSTANDING_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorOutstandingRewardsKey(validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_FEE_POOL, - IdentifierTemplate: string(distributiontypes.FeePoolKey), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_FEE_POOL, - IdentifierTemplate: string(distributiontypes.FeePoolKey), - }, - - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorHistoricalRewardsPrefix(validatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorHistoricalRewardsPrefix(validatorAddr)), - }, - - // Gets Module Account information - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(bondedModuleAdr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(notBondedModuleAdr)), - }, - - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO, - IdentifierTemplate: string(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)), + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.DelegatorAddress+msgUndelegate.ValidatorAddress), }, // Update the delegator and validator account balances { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: delegatorBalanceKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: delegatorBalanceKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: validatorBalanceKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.ValidatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: validatorBalanceKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.ValidatorAddress), }, // Checks if the validators exchange rate is valid { AccessType: sdkacltypes.AccessType_READ, ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, - IdentifierTemplate: validatorKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.ValidatorAddress), }, // Update validator shares and power index { AccessType: sdkacltypes.AccessType_WRITE, ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, - IdentifierTemplate: validatorKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.ValidatorAddress), }, // Last Operation should always be a commit - *acltypes.CommitAccessOp(), + { + ResourceType: sdkacltypes.ResourceType_ANY, + AccessType: sdkacltypes.AccessType_COMMIT, + IdentifierTemplate: utils.DefaultIDTemplate, + }, } return accessOperations, nil @@ -410,244 +166,95 @@ func MsgBeginRedelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Cont if !ok { return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType } - bondedModuleAdr := keeper.AccountKeeper.GetModuleAddress(stakingtypes.BondedPoolName) - notBondedModuleAdr := keeper.AccountKeeper.GetModuleAddress(stakingtypes.NotBondedPoolName) - - delegateAddr, _ := sdk.AccAddressFromBech32(msgBeingRedelegate.DelegatorAddress) - srcValidatorAddr, _ := sdk.ValAddressFromBech32(msgBeingRedelegate.ValidatorSrcAddress) - dstValidatorAddr, _ := sdk.ValAddressFromBech32(msgBeingRedelegate.ValidatorDstAddress) - - srcValidator, _ := keeper.StakingKeeper.GetValidator(ctx, srcValidatorAddr) - dstValidator, _ := keeper.StakingKeeper.GetValidator(ctx, dstValidatorAddr) - - srcDelegationKey := string(stakingtypes.GetDelegationKey(delegateAddr, srcValidatorAddr)) - dstDelegationKey := string(stakingtypes.GetDelegationKey(delegateAddr, dstValidatorAddr)) - - srcValidatorKey := string(stakingtypes.GetValidatorKey(srcValidatorAddr)) - dstValidatorKey := string(stakingtypes.GetValidatorKey(dstValidatorAddr)) - - dstValidatorBalanceKey := string(banktypes.CreateAccountBalancesPrefixFromBech32(msgBeingRedelegate.ValidatorDstAddress)) accessOperations := []sdkacltypes.AccessOperation{ - // Treat Delegations and Undelegations to have the same ACL since they are highly coupled, no point in finer granularization + // Treat Delegations and Redelegations to have the same ACL since they are highly coupled, no point in finer granularization - // Get delegation/redelegations and error checking + // Get src delegation to verify it has sufficient funds to undelegate + // Get dest delegation to see if it already exists { AccessType: sdkacltypes.AccessType_READ, ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, - IdentifierTemplate: srcDelegationKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_READ, ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, - IdentifierTemplate: dstDelegationKey, - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_REDELEGATION, - IdentifierTemplate: string(stakingtypes.GetREDsKey(delegateAddr)), + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorDstAddress), }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_REDELEGATION, - IdentifierTemplate: string(stakingtypes.GetREDsKey(delegateAddr)), - }, - - // Update/delete delegation and update redelegation + // Update/delete src and destination delegation after tokens have been unbonded { AccessType: sdkacltypes.AccessType_WRITE, ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, - IdentifierTemplate: dstDelegationKey, - }, - - // Check Unbonding - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER, - IdentifierTemplate: string(stakingtypes.GetValidatorsByPowerIndexKey(srcValidator, keeper.StakingKeeper.PowerReduction(ctx))), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER, - IdentifierTemplate: string(stakingtypes.GetValidatorsByPowerIndexKey(srcValidator, keeper.StakingKeeper.PowerReduction(ctx))), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER, - IdentifierTemplate: string(stakingtypes.GetValidatorsByPowerIndexKey(dstValidator, keeper.StakingKeeper.PowerReduction(ctx))), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER, - IdentifierTemplate: string(stakingtypes.GetValidatorsByPowerIndexKey(dstValidator, keeper.StakingKeeper.PowerReduction(ctx))), - }, - - // Before Unbond Distribution Hook - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO, - IdentifierTemplate: string(distributiontypes.GetDelegatorStartingInfoKey(srcValidatorAddr, delegateAddr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO, - IdentifierTemplate: string(distributiontypes.GetDelegatorStartingInfoKey(dstValidatorAddr, delegateAddr)), - }, - - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorCurrentRewardsKey(srcValidatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorCurrentRewardsKey(srcValidatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorCurrentRewardsKey(dstValidatorAddr)), + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorCurrentRewardsKey(dstValidatorAddr)), - }, - - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_OUTSTANDING_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorOutstandingRewardsKey(srcValidatorAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_OUTSTANDING_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorOutstandingRewardsKey(srcValidatorAddr)), - }, - - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_FEE_POOL, - IdentifierTemplate: string(distributiontypes.FeePoolKey), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_FEE_POOL, - IdentifierTemplate: string(distributiontypes.FeePoolKey), + ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorDstAddress), }, + // Update the delegator, src validator and dest validator account balances { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorHistoricalRewardsPrefix(srcValidatorAddr)), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorHistoricalRewardsPrefix(srcValidatorAddr)), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorHistoricalRewardsPrefix(dstValidatorAddr)), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS, - IdentifierTemplate: string(distributiontypes.GetValidatorHistoricalRewardsPrefix(dstValidatorAddr)), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorSrcAddress), }, - { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_REDELEGATION_QUEUE, - IdentifierTemplate: string(stakingtypes.RedelegationQueueKey), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorDstAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_REDELEGATION_QUEUE, - IdentifierTemplate: string(stakingtypes.RedelegationQueueKey), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorDstAddress), }, - // Gets Module Account information + // Update validators staking shares and power index { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(bondedModuleAdr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(notBondedModuleAdr)), - }, - - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO, - IdentifierTemplate: string(distributiontypes.GetDelegatorStartingInfoKey(srcValidatorAddr, delegateAddr)), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO, - IdentifierTemplate: string(distributiontypes.GetDelegatorStartingInfoKey(dstValidatorAddr, delegateAddr)), - }, - - // Update the delegator and validator account balances - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: dstValidatorBalanceKey, + ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: dstValidatorBalanceKey, - }, - - // Checks if the validators exchange rate is valid - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_REDELEGATION_VAL_SRC, - IdentifierTemplate: string(stakingtypes.GetREDByValSrcIndexKey( - delegateAddr, - srcValidatorAddr, - dstValidatorAddr, - )), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_REDELEGATION_VAL_DST, - IdentifierTemplate: string(stakingtypes.GetREDByValDstIndexKey( - delegateAddr, - srcValidatorAddr, - dstValidatorAddr, - )), - }, - - // Checks if the validators exchange rate is valid - { - AccessType: sdkacltypes.AccessType_READ, ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, - IdentifierTemplate: srcValidatorKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_READ, ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, - IdentifierTemplate: dstValidatorKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorDstAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, - IdentifierTemplate: srcValidatorKey, - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, - IdentifierTemplate: dstValidatorKey, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorDstAddress), }, // Last Operation should always be a commit - *acltypes.CommitAccessOp(), + { + ResourceType: sdkacltypes.ResourceType_ANY, + AccessType: sdkacltypes.AccessType_COMMIT, + IdentifierTemplate: utils.DefaultIDTemplate, + }, } + return accessOperations, nil } diff --git a/aclmapping/staking/mappings_test.go b/aclmapping/staking/mappings_test.go index e1f9f64e74..09efb9dbe9 100644 --- a/aclmapping/staking/mappings_test.go +++ b/aclmapping/staking/mappings_test.go @@ -1,283 +1,18 @@ -package aclstakingmapping_test +package aclstakingmapping import ( - "fmt" "testing" "time" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - "github.com/cosmos/cosmos-sdk/x/staking/keeper" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/cosmos/cosmos-sdk/x/staking/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - stakingacl "github.com/sei-protocol/sei-chain/aclmapping/staking" - aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils" - "github.com/sei-protocol/sei-chain/app/apptesting" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/sei-protocol/sei-chain/app" + oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" ) -type KeeperTestSuite struct { - apptesting.KeeperTestHelper - - queryClient stakingtypes.QueryClient - msgServer stakingtypes.MsgServer - // defaultDenom is on the suite, as it depends on the creator test address. - defaultDenom string - defaultExchangeRate string - initalBalance sdk.Coins - - validator sdk.ValAddress - newValidator sdk.ValAddress - delegateMsg *types.MsgDelegate - undelegateMsg *types.MsgUndelegate - redelegateMsg *types.MsgBeginRedelegate -} - -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) -} - -// Runs before each test case -func (suite *KeeperTestSuite) SetupTest() { - suite.Setup() -} - -// Explicitly only run once during setup -func (suite *KeeperTestSuite) PrepareTest() { - suite.defaultDenom = "usei" - suite.defaultExchangeRate = fmt.Sprintf("%dusei", sdk.NewDec(1700)) - - suite.initalBalance = sdk.Coins{sdk.NewInt64Coin(suite.defaultDenom, 100000000000)} - suite.initalBalance = sdk.Coins{sdk.NewInt64Coin("stake", 100000000000)} - suite.FundAcc(suite.TestAccs[0], suite.initalBalance) - - suite.queryClient = stakingtypes.NewQueryClient(suite.QueryHelper) - suite.msgServer = stakingkeeper.NewMsgServerImpl(suite.App.StakingKeeper) - - msgValidator := sdkacltypes.NewMsgValidator(aclutils.StoreKeyToResourceTypePrefixMap) - suite.Ctx = suite.Ctx.WithMsgValidator(msgValidator) - - suite.Ctx = suite.Ctx.WithBlockHeight(10) - suite.Ctx = suite.Ctx.WithBlockTime(time.Unix(333, 0)) - suite.validator = suite.SetupValidator(stakingtypes.Bonded) - suite.newValidator = suite.SetupValidator(stakingtypes.Unbonded) - - notBondedPool := suite.App.StakingKeeper.GetNotBondedPool(suite.Ctx) - suite.App.AccountKeeper.SetModuleAccount(suite.Ctx, notBondedPool) - - validator, _ := suite.App.StakingKeeper.GetValidator(suite.Ctx, suite.validator) - suite.App.StakingKeeper.SetValidatorByConsAddr(suite.Ctx, validator) - - newValidator, _ := suite.App.StakingKeeper.GetValidator(suite.Ctx, suite.newValidator) - suite.App.StakingKeeper.SetValidatorByConsAddr(suite.Ctx, newValidator) - - valTokens := suite.App.StakingKeeper.TokensFromConsensusPower(suite.Ctx, 10) - validator, issuedShares := validator.AddTokensFromDel(valTokens) - validator = keeper.TestingUpdateValidator(suite.App.StakingKeeper, suite.Ctx, validator, true) - - newValTokens := suite.App.StakingKeeper.TokensFromConsensusPower(suite.Ctx, 10) - newValidator, newIssuedShares := newValidator.AddTokensFromDel(newValTokens) - newValidator = keeper.TestingUpdateValidator(suite.App.StakingKeeper, suite.Ctx, validator, true) - - val0AccAddr := sdk.AccAddress(suite.validator) - val1AccAddr := sdk.AccAddress(suite.newValidator) - - val0selfDelegation := types.NewDelegation(val0AccAddr, suite.validator, issuedShares) - val1SelfDelegation := types.NewDelegation(val1AccAddr, suite.validator, newIssuedShares) - - suite.App.StakingKeeper.SetDelegation(suite.Ctx, val0selfDelegation) - suite.App.StakingKeeper.SetDelegation(suite.Ctx, val1SelfDelegation) - - bondedPool := suite.App.StakingKeeper.GetBondedPool(suite.Ctx) - suite.App.AccountKeeper.SetModuleAccount(suite.Ctx, bondedPool) - - suite.delegateMsg = &stakingtypes.MsgDelegate{ - Amount: sdk.NewInt64Coin("stake", 10), - ValidatorAddress: suite.validator.String(), - DelegatorAddress: suite.TestAccs[0].String(), - } - suite.undelegateMsg = &stakingtypes.MsgUndelegate{ - Amount: sdk.NewInt64Coin("stake", 10), - ValidatorAddress: suite.validator.String(), - DelegatorAddress: suite.TestAccs[0].String(), - } - suite.redelegateMsg = &stakingtypes.MsgBeginRedelegate{ - Amount: sdk.NewInt64Coin("stake", 10), - ValidatorSrcAddress: suite.validator.String(), - ValidatorDstAddress: suite.newValidator.String(), - DelegatorAddress: suite.TestAccs[0].String(), - } - - _, err := suite.msgServer.Delegate( - sdk.WrapSDKContext(suite.Ctx), - suite.delegateMsg, - ) - if err != nil { - panic(err) - } -} - - -func (suite *KeeperTestSuite) TestMsgUndelegateDependencies() { - suite.PrepareTest() - tests := []struct { - name string - expectedError error - msg *stakingtypes.MsgUndelegate - dynamicDep bool - }{ - { - name: "default vote", - msg: suite.undelegateMsg, - expectedError: nil, - dynamicDep: true, - }, - { - name: "dont check synchronous", - msg: suite.undelegateMsg, - expectedError: nil, - dynamicDep: false, - }, - } - for _, tc := range tests { - suite.Run(fmt.Sprintf("Test Case: %s", tc.name), func() { - - handlerCtx, cms := aclutils.CacheTxContext(suite.Ctx) - _, err := suite.msgServer.Undelegate( - sdk.WrapSDKContext(handlerCtx), - tc.msg, - ) - depdenencies , _ := stakingacl.MsgUndelegateDependencyGenerator( - suite.App.AccessControlKeeper, - handlerCtx, - tc.msg, - ) - - if !tc.dynamicDep { - depdenencies = sdkacltypes.SynchronousAccessOps() - } - - if tc.expectedError != nil { - suite.Require().EqualError(err, tc.expectedError.Error()) - } else { - suite.Require().NoError(err) - } - - missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - suite.Require().Empty(missing) - }) - } -} - -func (suite *KeeperTestSuite) TestMsgRedelegateDependencies() { - suite.PrepareTest() - tests := []struct { - name string - expectedError error - msg *stakingtypes.MsgBeginRedelegate - dynamicDep bool - }{ - { - name: "default vote", - msg: suite.redelegateMsg, - expectedError: nil, - dynamicDep: true, - }, - // { - // name: "dont check synchronous", - // msg: suite.redelegateMsg, - // expectedError: nil, - // dynamicDep: false, - // }, - } - for _, tc := range tests { - suite.Run(fmt.Sprintf("Test Case: %s", tc.name), func() { - - handlerCtx, cms := aclutils.CacheTxContext(suite.Ctx) - _, err := suite.msgServer.BeginRedelegate( - sdk.WrapSDKContext(handlerCtx), - tc.msg, - ) - depdenencies , _ := stakingacl.MsgBeginRedelegateDependencyGenerator( - suite.App.AccessControlKeeper, - handlerCtx, - tc.msg, - ) - - if !tc.dynamicDep { - depdenencies = sdkacltypes.SynchronousAccessOps() - } - - if tc.expectedError != nil { - suite.Require().EqualError(err, tc.expectedError.Error()) - } else { - suite.Require().NoError(err) - } - - missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - suite.Require().Empty(missing) - }) - } -} - - -func (suite *KeeperTestSuite) TestMsgDelegateDependencies() { - suite.PrepareTest() - tests := []struct { - name string - expectedError error - msg *stakingtypes.MsgDelegate - dynamicDep bool - }{ - { - name: "default vote", - msg: suite.delegateMsg, - expectedError: nil, - dynamicDep: true, - }, - { - name: "dont check synchronous", - msg: suite.delegateMsg, - expectedError: nil, - dynamicDep: false, - }, - } - for _, tc := range tests { - suite.Run(fmt.Sprintf("Test Case: %s", tc.name), func() { - handlerCtx, cms := aclutils.CacheTxContext(suite.Ctx) - _, err := suite.msgServer.Delegate( - sdk.WrapSDKContext(handlerCtx), - tc.msg, - ) - depdenencies , _ := stakingacl.MsgDelegateDependencyGenerator( - suite.App.AccessControlKeeper, - handlerCtx, - tc.msg, - ) - - if !tc.dynamicDep { - depdenencies = sdkacltypes.SynchronousAccessOps() - } - - if tc.expectedError != nil { - suite.Require().EqualError(err, tc.expectedError.Error()) - } else { - suite.Require().NoError(err) - } - - missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - suite.Require().Empty(missing) - }) - } -} - func TestGeneratorInvalidMessageTypes(t *testing.T) { tm := time.Now().UTC() valPub := secp256k1.GenPrivKey().PubKey() @@ -294,49 +29,65 @@ func TestGeneratorInvalidMessageTypes(t *testing.T) { Validator: "validator", } - _, err := stakingacl.MsgUndelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &oracleVote) + _, err := MsgDelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &oracleVote) require.Error(t, err) - _, err = stakingacl.MsgUndelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingDelegate) + _, err = MsgUndelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingDelegate) require.Error(t, err) - _, err = stakingacl.MsgUndelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingDelegate) + _, err = MsgBeginRedelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingDelegate) require.Error(t, err) } -func (suite *KeeperTestSuite) TestMsgDelegateGenerator() { - suite.PrepareTest() - stakingDelegate := suite.delegateMsg +func TestMsgDelegateGenerator(t *testing.T) { + tm := time.Now().UTC() + valPub := secp256k1.GenPrivKey().PubKey() + testWrapper := app.NewTestWrapper(t, tm, valPub) + + stakingDelegate := stakingtypes.MsgDelegate{ + DelegatorAddress: "delegator", + ValidatorAddress: "validator", + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, + } - accessOps, err := stakingacl.MsgDelegateDependencyGenerator( - suite.App.AccessControlKeeper, - suite.Ctx, - stakingDelegate, - ) - require.NoError(suite.T(), err) + accessOps, err := MsgDelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingDelegate) + require.NoError(t, err) err = acltypes.ValidateAccessOps(accessOps) - require.NoError(suite.T(), err) + require.NoError(t, err) } -func (suite *KeeperTestSuite) TestMsgUndelegateGenerator() { - suite.PrepareTest() - accessOps, err := stakingacl.MsgUndelegateDependencyGenerator( - suite.App.AccessControlKeeper, - suite.Ctx, - suite.undelegateMsg, - ) - require.NoError(suite.T(), err) +func TestMsgUndelegateGenerator(t *testing.T) { + tm := time.Now().UTC() + valPub := secp256k1.GenPrivKey().PubKey() + + testWrapper := app.NewTestWrapper(t, tm, valPub) + + stakingUndelegate := stakingtypes.MsgUndelegate{ + DelegatorAddress: "delegator", + ValidatorAddress: "validator", + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, + } + + accessOps, err := MsgUndelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingUndelegate) + require.NoError(t, err) err = acltypes.ValidateAccessOps(accessOps) - require.NoError(suite.T(), err) + require.NoError(t, err) } -func (suite *KeeperTestSuite) TestMsgBeginRedelegateGenerator() { - suite.PrepareTest() - accessOps, err := stakingacl.MsgBeginRedelegateDependencyGenerator( - suite.App.AccessControlKeeper, - suite.Ctx, - suite.redelegateMsg, - ) - require.NoError(suite.T(), err) +func TestMsgBeginRedelegateGenerator(t *testing.T) { + tm := time.Now().UTC() + valPub := secp256k1.GenPrivKey().PubKey() + + testWrapper := app.NewTestWrapper(t, tm, valPub) + + stakingBeginRedelegate := stakingtypes.MsgBeginRedelegate{ + DelegatorAddress: "delegator", + ValidatorSrcAddress: "src_validator", + ValidatorDstAddress: "dst_validator", + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, + } + + accessOps, err := MsgBeginRedelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingBeginRedelegate) + require.NoError(t, err) err = acltypes.ValidateAccessOps(accessOps) - require.NoError(suite.T(), err) + require.NoError(t, err) } diff --git a/aclmapping/tokenfactory/mappings.go b/aclmapping/tokenfactory/mappings.go index 1a48909742..752e6f3155 100644 --- a/aclmapping/tokenfactory/mappings.go +++ b/aclmapping/tokenfactory/mappings.go @@ -152,7 +152,7 @@ func TokenFactoryBurnDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Contex // Gets Module Account Balance { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, + ResourceType: sdkacltypes.ResourceType_KV_AUTH, IdentifierTemplate: string(authtypes.AddressStoreKey(moduleAdr)), }, diff --git a/aclmapping/tokenfactory/mappings_test.go b/aclmapping/tokenfactory/mappings_test.go index 70792a373d..8edfaf6af0 100644 --- a/aclmapping/tokenfactory/mappings_test.go +++ b/aclmapping/tokenfactory/mappings_test.go @@ -212,7 +212,7 @@ func TestGeneratorInvalidMessageTypes(t *testing.T) { require.Error(t, err) } -func TestMsgBeginBurnDepedencyGenerator(t *testing.T) { +func TestMsgBeginBankSendGenerator(t *testing.T) { priv1 := secp256k1.GenPrivKey() addr1 := sdk.AccAddress(priv1.PubKey().Address()) diff --git a/aclmapping/utils/resource_type.go b/aclmapping/utils/resource_type.go index cb0fe3f2cd..5da04b0717 100644 --- a/aclmapping/utils/resource_type.go +++ b/aclmapping/utils/resource_type.go @@ -4,7 +4,6 @@ import ( aclsdktypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" dextypes "github.com/sei-protocol/sei-chain/x/dex/types" epochtypes "github.com/sei-protocol/sei-chain/x/epoch/types" @@ -32,18 +31,6 @@ var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMa aclsdktypes.ResourceType_KV_AUTH: aclsdktypes.EmptyPrefix, aclsdktypes.ResourceType_KV_AUTH_ADDRESS_STORE: authtypes.AddressStoreKeyPrefix, }, - distributiontypes.StoreKey: { - aclsdktypes.ResourceType_KV_DISTRIBUTION: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_KV_DISTRIBUTION_FEE_POOL: distributiontypes.FeePoolKey, - aclsdktypes.ResourceType_KV_DISTRIBUTION_PROPOSER_KEY: distributiontypes.ProposerKey, - aclsdktypes.ResourceType_KV_DISTRIBUTION_OUTSTANDING_REWARDS: distributiontypes.ValidatorOutstandingRewardsPrefix, - aclsdktypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_WITHDRAW_ADDR: distributiontypes.DelegatorWithdrawAddrPrefix, - aclsdktypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO: distributiontypes.DelegatorStartingInfoPrefix, - aclsdktypes.ResourceType_KV_DISTRIBUTION_VAL_HISTORICAL_REWARDS: distributiontypes.ValidatorHistoricalRewardsPrefix, - aclsdktypes.ResourceType_KV_DISTRIBUTION_VAL_CURRENT_REWARDS: distributiontypes.ValidatorCurrentRewardsPrefix, - aclsdktypes.ResourceType_KV_DISTRIBUTION_VAL_ACCUM_COMMISSION: distributiontypes.ValidatorAccumulatedCommissionPrefix, - aclsdktypes.ResourceType_KV_DISTRIBUTION_SLASH_EVENT: distributiontypes.ValidatorSlashEventPrefix, - }, oracletypes.StoreKey: { aclsdktypes.ResourceType_KV_ORACLE: aclsdktypes.EmptyPrefix, aclsdktypes.ResourceType_KV_ORACLE_VOTE_TARGETS: oracletypes.VoteTargetKey, @@ -51,22 +38,9 @@ var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMa aclsdktypes.ResourceType_KV_ORACLE_FEEDERS: oracletypes.FeederDelegationKey, }, stakingtypes.StoreKey: { - aclsdktypes.ResourceType_KV_STAKING: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_KV_STAKING_VALIDATION_POWER: stakingtypes.LastValidatorPowerKey, - aclsdktypes.ResourceType_KV_STAKING_TOTAL_POWER: stakingtypes.LastTotalPowerKey, - aclsdktypes.ResourceType_KV_STAKING_VALIDATOR: stakingtypes.ValidatorsKey, - aclsdktypes.ResourceType_KV_STAKING_VALIDATORS_CON_ADDR: stakingtypes.ValidatorsByConsAddrKey, - aclsdktypes.ResourceType_KV_STAKING_VALIDATORS_BY_POWER: stakingtypes.ValidatorsByPowerIndexKey, - aclsdktypes.ResourceType_KV_STAKING_DELEGATION: stakingtypes.DelegationKey, - aclsdktypes.ResourceType_KV_STAKING_UNBONDING_DELEGATION: stakingtypes.UnbondingDelegationKey, - aclsdktypes.ResourceType_KV_STAKING_UNBONDING_DELEGATION_VAL: stakingtypes.UnbondingDelegationByValIndexKey, - aclsdktypes.ResourceType_KV_STAKING_REDELEGATION: stakingtypes.RedelegationKey, - aclsdktypes.ResourceType_KV_STAKING_REDELEGATION_VAL_SRC: stakingtypes.RedelegationByValSrcIndexKey, - aclsdktypes.ResourceType_KV_STAKING_REDELEGATION_VAL_DST: stakingtypes.RedelegationByValDstIndexKey, - aclsdktypes.ResourceType_KV_STAKING_UNBONDING: stakingtypes.UnbondingQueueKey, - aclsdktypes.ResourceType_KV_STAKING_REDELEGATION_QUEUE: stakingtypes.RedelegationQueueKey, - aclsdktypes.ResourceType_KV_STAKING_VALIDATOR_QUEUE: stakingtypes.ValidatorQueueKey, - aclsdktypes.ResourceType_KV_STAKING_HISTORICAL_INFO: stakingtypes.HistoricalInfoKey, + aclsdktypes.ResourceType_KV_STAKING: aclsdktypes.EmptyPrefix, + aclsdktypes.ResourceType_KV_STAKING_DELEGATION: stakingtypes.DelegationKey, + aclsdktypes.ResourceType_KV_STAKING_VALIDATOR: stakingtypes.ValidatorsKey, }, tokenfactorytypes.StoreKey: { aclsdktypes.ResourceType_KV_TOKENFACTORY: aclsdktypes.EmptyPrefix, diff --git a/app/app.go b/app/app.go index 4611f1702e..1aa001451b 100644 --- a/app/app.go +++ b/app/app.go @@ -525,7 +525,6 @@ func New( app.keys[acltypes.StoreKey], app.GetSubspace(acltypes.ModuleName), app.AccountKeeper, - app.StakingKeeper, aclOpts..., ) // The last arguments can contain custom message handlers, and custom query handlers, diff --git a/go.mod b/go.mod index 193c90e1c0..d2a7f14794 100644 --- a/go.mod +++ b/go.mod @@ -133,7 +133,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.246 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.245 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 diff --git a/go.sum b/go.sum index 0db4cedab9..0af27f1059 100644 --- a/go.sum +++ b/go.sum @@ -1101,8 +1101,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.246 h1:qX6ycebWYECnh9DIP9xqCFHVgJ8U4yHuR+asr/vuOVE= -github.com/sei-protocol/sei-cosmos v0.1.246/go.mod h1:KPV8lFdD2Ki/M2wZTpfX3LCcuMAZnmcUzYJycjbmOYM= +github.com/sei-protocol/sei-cosmos v0.1.245 h1:mOPiwp1ThCapVCVH8mrmXU7ugngLWsiWAftaZ5Ga63U= +github.com/sei-protocol/sei-cosmos v0.1.245/go.mod h1:KPV8lFdD2Ki/M2wZTpfX3LCcuMAZnmcUzYJycjbmOYM= 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= diff --git a/store/testutils.go b/store/testutils.go index 86b0aa59bb..2a3efaac33 100644 --- a/store/testutils.go +++ b/store/testutils.go @@ -11,7 +11,7 @@ import ( func NewTestKVStore() types.KVStore { mem := dbadapter.Store{DB: dbm.NewMemDB()} - return cachekv.NewStore(mem, storetypes.NewKVStoreKey("test")) + return cachekv.NewStore(mem, storetypes.NewKVStoreKey("testStoreKey")) } func NewTestCacheMultiStore(stores map[types.StoreKey]types.CacheWrapper) types.CacheMultiStore { From 526aa980e6cd53ea098c78ef1bb767599dacb118 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 03/41] Revert "Update Oracle Parallel Tx Resource Identifiers (#351)" This reverts commit c9229ab72bb4e8addb657069ddab12f048ed2056. --- aclmapping/oracle/mappings.go | 18 ++--- aclmapping/oracle/mappings_test.go | 119 +---------------------------- aclmapping/utils/test_utils.go | 9 --- x/oracle/simulation/operations.go | 4 +- 4 files changed, 14 insertions(+), 136 deletions(-) delete mode 100644 aclmapping/utils/test_utils.go diff --git a/aclmapping/oracle/mappings.go b/aclmapping/oracle/mappings.go index 778bc5bf6b..84517eee09 100644 --- a/aclmapping/oracle/mappings.go +++ b/aclmapping/oracle/mappings.go @@ -7,7 +7,6 @@ import ( 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" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" utils "github.com/sei-protocol/sei-chain/aclmapping/utils" oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" ) @@ -29,7 +28,6 @@ func MsgVoteDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sd if !ok { return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType } - valAddr, _ := sdk.ValAddressFromBech32(msgVote.Validator) accessOperations := []sdkacltypes.AccessOperation{ // validate feeder @@ -37,7 +35,7 @@ func MsgVoteDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sd { ResourceType: sdkacltypes.ResourceType_KV_ORACLE_FEEDERS, AccessType: sdkacltypes.AccessType_READ, - IdentifierTemplate: string(oracletypes.GetFeederDelegationKey(valAddr)), + IdentifierTemplate: msgVote.Validator, }, // read validator from staking - READ // validator is bonded check - READ @@ -45,9 +43,8 @@ func MsgVoteDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sd { ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, AccessType: sdkacltypes.AccessType_READ, - IdentifierTemplate: string(stakingtypes.GetValidatorKey(valAddr)), + IdentifierTemplate: msgVote.Validator, }, - // get vote target (for all exchange rate tuples) -> blanket read on that prefix - READ { ResourceType: sdkacltypes.ResourceType_KV_ORACLE_VOTE_TARGETS, @@ -58,12 +55,15 @@ func MsgVoteDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sd // set exchange rate vote - WRITE { ResourceType: sdkacltypes.ResourceType_KV_ORACLE_AGGREGATE_VOTES, - AccessType: sdkacltypes.AccessType_WRITE, - IdentifierTemplate: string(oracletypes.GetAggregateExchangeRateVoteKey(valAddr)), + AccessType: sdkacltypes.AccessType_READ, + IdentifierTemplate: msgVote.Validator, }, - // Last Operation should always be a commit - *acltypes.CommitAccessOp(), + { + ResourceType: sdkacltypes.ResourceType_ANY, + AccessType: sdkacltypes.AccessType_COMMIT, + IdentifierTemplate: utils.DefaultIDTemplate, + }, } return accessOperations, nil } diff --git a/aclmapping/oracle/mappings_test.go b/aclmapping/oracle/mappings_test.go index 0e3246475c..0e7a6d29de 100644 --- a/aclmapping/oracle/mappings_test.go +++ b/aclmapping/oracle/mappings_test.go @@ -1,129 +1,16 @@ -package acloraclemapping_test +package acloraclemapping import ( - "fmt" "testing" "time" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - oracleacl "github.com/sei-protocol/sei-chain/aclmapping/oracle" - aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils" - utils "github.com/sei-protocol/sei-chain/aclmapping/utils" - "github.com/sei-protocol/sei-chain/app/apptesting" - oraclekeeper "github.com/sei-protocol/sei-chain/x/oracle/keeper" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/sei-protocol/sei-chain/app" + oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" ) -type KeeperTestSuite struct { - apptesting.KeeperTestHelper - - queryClient oracletypes.QueryClient - msgServer oracletypes.MsgServer - // defaultDenom is on the suite, as it depends on the creator test address. - defaultDenom string - defaultExchangeRate string - initalBalance sdk.Coins - - validator sdk.ValAddress -} - -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) -} - -// Runs before each test case -func (suite *KeeperTestSuite) SetupTest() { - suite.Setup() -} - -// Explicitly only run once during setup -func (suite *KeeperTestSuite) PrepareTest() { - suite.defaultDenom = "usei" - suite.defaultExchangeRate = fmt.Sprintf("%dusei", sdk.NewDec(1700)) - - suite.initalBalance = sdk.Coins{sdk.NewInt64Coin(suite.defaultDenom, 100000000000)} - suite.FundAcc(suite.TestAccs[0], suite.initalBalance) - - suite.queryClient = oracletypes.NewQueryClient(suite.QueryHelper) - suite.msgServer = oraclekeeper.NewMsgServerImpl(suite.App.OracleKeeper) - - // testInput := oraclekeeper.CreateTestInput(suite.T()) - // suite.Ctx = testInput.Ctx - - msgValidator := sdkacltypes.NewMsgValidator(aclutils.StoreKeyToResourceTypePrefixMap) - suite.Ctx = suite.Ctx.WithMsgValidator(msgValidator) - suite.Ctx = suite.Ctx.WithBlockHeight(1) - suite.validator = suite.SetupValidator(stakingtypes.Bonded) - - suite.App.OracleKeeper.SetFeederDelegation(suite.Ctx, suite.validator, suite.TestAccs[0]) - suite.App.OracleKeeper.SetVoteTarget(suite.Ctx, suite.defaultDenom) -} - -func (suite *KeeperTestSuite) TestMsgBurnDependencies() { - suite.PrepareTest() - tests := []struct { - name string - expectedError error - msg *oracletypes.MsgAggregateExchangeRateVote - dynamicDep bool - }{ - { - name: "default vote", - msg: &oracletypes.MsgAggregateExchangeRateVote{ - ExchangeRates: suite.defaultExchangeRate, - Feeder: suite.TestAccs[0].String(), - Validator: suite.validator.String(), - }, - expectedError: nil, - dynamicDep: true, - }, - { - name: "dont check synchronous", - msg: &oracletypes.MsgAggregateExchangeRateVote{ - ExchangeRates: suite.defaultExchangeRate, - Feeder: suite.TestAccs[0].String(), - Validator: suite.validator.String(), - }, - expectedError: nil, - dynamicDep: false, - }, - } - for _, tc := range tests { - suite.Run(fmt.Sprintf("Test Case: %s", tc.name), func() { - handlerCtx, cms := utils.CacheTxContext(suite.Ctx) - _, err := suite.msgServer.AggregateExchangeRateVote( - sdk.WrapSDKContext(handlerCtx), - tc.msg, - ) - depdenencies , _ := oracleacl.MsgVoteDependencyGenerator( - suite.App.AccessControlKeeper, - handlerCtx, - tc.msg, - ) - - if !tc.dynamicDep { - depdenencies = sdkacltypes.SynchronousAccessOps() - } - - if tc.expectedError != nil { - suite.Require().EqualError(err, tc.expectedError.Error()) - } else { - suite.Require().NoError(err) - } - - missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - suite.Require().Empty(missing) - }) - } -} func TestMsgVoteDependencyGenerator(t *testing.T) { tm := time.Now().UTC() valPub := secp256k1.GenPrivKey().PubKey() @@ -136,7 +23,7 @@ func TestMsgVoteDependencyGenerator(t *testing.T) { Validator: "validator", } - accessOps, err := oracleacl.MsgVoteDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &oracleVote) + accessOps, err := MsgVoteDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &oracleVote) require.NoError(t, err) err = acltypes.ValidateAccessOps(accessOps) require.NoError(t, err) diff --git a/aclmapping/utils/test_utils.go b/aclmapping/utils/test_utils.go deleted file mode 100644 index 5b39275708..0000000000 --- a/aclmapping/utils/test_utils.go +++ /dev/null @@ -1,9 +0,0 @@ -package utils - -import sdk "github.com/cosmos/cosmos-sdk/types" - -func CacheTxContext(ctx sdk.Context) (sdk.Context, sdk.CacheMultiStore) { - ms := ctx.MultiStore() - msCache := ms.CacheMultiStore() - return ctx.WithMultiStore(msCache), msCache -} diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index 2028e73625..3988c4b164 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -65,7 +65,7 @@ func WeightedOperations( } // 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, @@ -122,7 +122,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, From 0667f6a93416e50097d69dcb4cf9af6257674e50 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 04/41] Revert "Update IdentifierTemplate for TokenFactory (#350)" This reverts commit e81fc936d814a1afca2a154165eba74377fec145. --- aclmapping/tokenfactory/mappings.go | 144 +++++--------- aclmapping/tokenfactory/mappings_test.go | 234 ----------------------- aclmapping/utils/resource_type.go | 6 +- app/app.go | 1 - go.mod | 2 +- go.sum | 4 +- scripts/old_initialize_local.sh | 0 7 files changed, 52 insertions(+), 339 deletions(-) delete mode 100644 aclmapping/tokenfactory/mappings_test.go mode change 100755 => 100644 scripts/old_initialize_local.sh diff --git a/aclmapping/tokenfactory/mappings.go b/aclmapping/tokenfactory/mappings.go index 752e6f3155..0eda913365 100644 --- a/aclmapping/tokenfactory/mappings.go +++ b/aclmapping/tokenfactory/mappings.go @@ -7,194 +7,146 @@ import ( 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" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - tfktypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types" + utils "github.com/sei-protocol/sei-chain/aclmapping/utils" + tokenfactorymoduletypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types" ) var ErrInvalidMessageType = fmt.Errorf("invalid message received for TokenFactory Module") func GetTokenFactoryDependencyGenerators() aclkeeper.DependencyGeneratorMap { dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - MintMsgKey := acltypes.GenerateMessageKey(&tfktypes.MsgMint{}) + MintMsgKey := acltypes.GenerateMessageKey(&tokenfactorymoduletypes.MsgMint{}) dependencyGeneratorMap[MintMsgKey] = TokenFactoryMintDependencyGenerator - BurnMsgKey := acltypes.GenerateMessageKey(&tfktypes.MsgBurn{}) + BurnMsgKey := acltypes.GenerateMessageKey(&tokenfactorymoduletypes.MsgBurn{}) dependencyGeneratorMap[BurnMsgKey] = TokenFactoryBurnDependencyGenerator return dependencyGeneratorMap } func TokenFactoryMintDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - mintMsg, ok := msg.(*tfktypes.MsgMint) + mintMsg, ok := msg.(*tokenfactorymoduletypes.MsgMint) if !ok { return []sdkacltypes.AccessOperation{}, ErrInvalidMessageType } - moduleAdr := keeper.AccountKeeper.GetModuleAddress(tfktypes.ModuleName) - denom := mintMsg.GetAmount().Denom - - denomMetaDataKey := append([]byte(tfktypes.DenomAuthorityMetadataKey), []byte(denom)...) - tokenfactoryDenomKey := tfktypes.GetDenomPrefixStore(denom) - bankDenomMetaDataKey := banktypes.DenomMetadataKey(denom) - supplyKey := string(append(banktypes.SupplyKey, []byte(denom)...)) + denom := mintMsg.GetAmount().Denom return []sdkacltypes.AccessOperation{ // Reads denom data From BankKeeper { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_DENOM, - IdentifierTemplate: string(bankDenomMetaDataKey), - }, - - // Gets Authoritity data related to the denom - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_TOKENFACTORY_METADATA, - IdentifierTemplate: string(denomMetaDataKey), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: denom, }, // Gets Authoritity data related to the denom { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_TOKENFACTORY_DENOM, - IdentifierTemplate: string(tokenfactoryDenomKey), + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.TOKENFACTORY, denom), }, // Gets Module Account information { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.AddressStoreKey(moduleAdr)), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: string(banktypes.CreateAccountBalancesPrefix(moduleAdr)), + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, tokenfactorymoduletypes.ModuleName), }, - // Deposit into Sender's Bank Balance - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: string(banktypes.CreateAccountBalancesPrefixFromBech32(mintMsg.GetSender())), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: string(banktypes.CreateAccountBalancesPrefixFromBech32(mintMsg.GetSender())), - }, + // Sends coins to module account - deferred deposit - // Read and update supply after burn + // Updates Supply of the denom { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_SUPPLY, - IdentifierTemplate: supplyKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetPrefixedIdentifierTemplatePerModule(utils.BANK, "supply", denom), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_SUPPLY, - IdentifierTemplate: supplyKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetPrefixedIdentifierTemplatePerModule(utils.BANK, "supply", denom), }, + // Sends coins to the msgSender from the Module Account (deferred withdrawal) { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.CreateAddressStoreKeyFromBech32(mintMsg.GetSender())), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, mintMsg.Sender), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.CreateAddressStoreKeyFromBech32(mintMsg.GetSender())), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, mintMsg.Sender), }, - - // Coins removed from Module account (Deferred) - - // Last Operation should always be a commit - *acltypes.CommitAccessOp(), }, nil } func TokenFactoryBurnDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - burnMsg, ok := msg.(*tfktypes.MsgBurn) + burnMsg, ok := msg.(*tokenfactorymoduletypes.MsgBurn) if !ok { return []sdkacltypes.AccessOperation{}, ErrInvalidMessageType } - moduleAdr := keeper.AccountKeeper.GetModuleAddress(tfktypes.ModuleName) denom := burnMsg.GetAmount().Denom - - denomMetaDataKey := append([]byte(tfktypes.DenomAuthorityMetadataKey), []byte(denom)...) - tokenfactoryDenomKey := tfktypes.GetDenomPrefixStore(denom) - bankDenomMetaDataKey := banktypes.DenomMetadataKey(denom) - supplyKey := string(append(banktypes.SupplyKey, []byte(denom)...)) return []sdkacltypes.AccessOperation{ // Reads denom data From BankKeeper { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_DENOM, - IdentifierTemplate: string(bankDenomMetaDataKey), - }, - - // Gets Authoritity data related to the denom - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_TOKENFACTORY_METADATA, - IdentifierTemplate: string(denomMetaDataKey), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: denom, }, // Gets Authoritity data related to the denom { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_TOKENFACTORY_DENOM, - IdentifierTemplate: string(tokenfactoryDenomKey), + ResourceType: sdkacltypes.ResourceType_KV_TOKENFACTORY, + IdentifierTemplate: denom, }, - // Gets Module Account Balance + // Gets Module Account information { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH, - IdentifierTemplate: string(authtypes.AddressStoreKey(moduleAdr)), + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, tokenfactorymoduletypes.ModuleName), }, // Sends from Sender to Module account (deferred deposit) - // Checks balance for receiver { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: string(banktypes.CreateAccountBalancesPrefixFromBech32(burnMsg.GetSender())), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, burnMsg.Sender), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: string(banktypes.CreateAccountBalancesPrefixFromBech32(burnMsg.GetSender())), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, burnMsg.Sender), }, - // Read and update supply after burn + // Sends coins to the msgSender { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_SUPPLY, - IdentifierTemplate: supplyKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, burnMsg.Sender), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_SUPPLY, - IdentifierTemplate: supplyKey, + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, burnMsg.Sender), }, + // Coins removed from Module account (Deferred) + + // Updates Supply of the denom - they should be under the supply prefix - this should always be + // synchronous { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.CreateAddressStoreKeyFromBech32(burnMsg.GetSender())), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule("supply", denom), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.CreateAddressStoreKeyFromBech32(burnMsg.GetSender())), + ResourceType: sdkacltypes.ResourceType_KV_BANK, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule("supply", denom), }, - - // Coins removed from Module account (Deferred) - - // Last Operation should always be a commit - *acltypes.CommitAccessOp(), }, nil } diff --git a/aclmapping/tokenfactory/mappings_test.go b/aclmapping/tokenfactory/mappings_test.go deleted file mode 100644 index 8edfaf6af0..0000000000 --- a/aclmapping/tokenfactory/mappings_test.go +++ /dev/null @@ -1,234 +0,0 @@ -package aclTokenFactorymapping_test - -import ( - "fmt" - "testing" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - tkfactory "github.com/sei-protocol/sei-chain/aclmapping/tokenfactory" - aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils" - "github.com/sei-protocol/sei-chain/app/apptesting" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" - tokenfactorykeeper "github.com/sei-protocol/sei-chain/x/tokenfactory/keeper" - "github.com/sei-protocol/sei-chain/x/tokenfactory/types" - tokenfactorytypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" - - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" -) -type KeeperTestSuite struct { - apptesting.KeeperTestHelper - - queryClient tokenfactorytypes.QueryClient - msgServer tokenfactorytypes.MsgServer - // defaultDenom is on the suite, as it depends on the creator test address. - defaultDenom string - testDenom string - initalBalance sdk.Coins -} - -func TestKeeperTestSuite(t *testing.T) { - suite.Run(t, new(KeeperTestSuite)) -} - -// Runs before each test case -func (suite *KeeperTestSuite) SetupTest() { - suite.Setup() -} - -// Explicitly only run once during setup -func (suite *KeeperTestSuite) PrepareTest() { - suite.defaultDenom = "usei" - suite.testDenom = "foocoins" - - suite.initalBalance = sdk.Coins{sdk.NewInt64Coin(suite.defaultDenom, 100000000000)} - suite.FundAcc(suite.TestAccs[0], suite.initalBalance) - - suite.SetupTokenFactory() - suite.queryClient = tokenfactorytypes.NewQueryClient(suite.QueryHelper) - suite.msgServer = tokenfactorykeeper.NewMsgServerImpl(suite.App.TokenFactoryKeeper) - - res, err := suite.msgServer.CreateDenom( - sdk.WrapSDKContext(suite.Ctx), - types.NewMsgCreateDenom(suite.TestAccs[0].String(), suite.testDenom), - ) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - - if err != nil { - panic(err) - } - suite.testDenom = res.GetNewTokenDenom() - - _, err = suite.msgServer.Mint( - sdk.WrapSDKContext(suite.Ctx), - types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.testDenom, 1000000)), - ) - if err != nil { - panic(err) - } - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - - msgValidator := sdkacltypes.NewMsgValidator(aclutils.StoreKeyToResourceTypePrefixMap) - suite.Ctx = suite.Ctx.WithMsgValidator(msgValidator) -} - -func cacheTxContext(ctx sdk.Context) (sdk.Context, sdk.CacheMultiStore) { - ms := ctx.MultiStore() - msCache := ms.CacheMultiStore() - return ctx.WithMultiStore(msCache), msCache -} - -func (suite *KeeperTestSuite) TestMsgBurnDependencies() { - suite.PrepareTest() - - burnAmount := sdk.NewInt64Coin(suite.testDenom, 10) - addr1 := suite.TestAccs[0].String() - tests := []struct { - name string - expectedError error - msg *tokenfactorytypes.MsgBurn - dynamicDep bool - }{ - { - name: "default burn", - msg: tokenfactorytypes.NewMsgBurn(addr1, burnAmount), - expectedError: nil, - dynamicDep: true, - }, - { - name: "dont check synchronous", - msg: tokenfactorytypes.NewMsgBurn(addr1, burnAmount), - expectedError: nil, - dynamicDep: false, - }, - } - for _, tc := range tests { - suite.Run(fmt.Sprintf("Test Case: %s", tc.name), func() { - handlerCtx, cms := cacheTxContext(suite.Ctx) - _, err := suite.msgServer.Burn( - sdk.WrapSDKContext(handlerCtx), - tc.msg, - ) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - - depdenencies , _ := tkfactory.TokenFactoryBurnDependencyGenerator( - suite.App.AccessControlKeeper, - handlerCtx, - tc.msg, - ) - - if !tc.dynamicDep { - depdenencies = sdkacltypes.SynchronousAccessOps() - } - - if tc.expectedError != nil { - suite.Require().EqualError(err, tc.expectedError.Error()) - } else { - suite.Require().NoError(err) - } - - missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - suite.Require().Empty(missing) - }) - } -} - -func (suite *KeeperTestSuite) TestMsgMintDependencies() { - suite.PrepareTest() - - burnAmount := sdk.NewInt64Coin(suite.testDenom, 10) - addr1 := suite.TestAccs[0].String() - tests := []struct { - name string - expectedError error - msg *tokenfactorytypes.MsgMint - dynamicDep bool - }{ - { - name: "default mint", - msg: tokenfactorytypes.NewMsgMint(addr1, burnAmount), - expectedError: nil, - dynamicDep: true, - }, - { - name: "dont check synchronous", - msg: tokenfactorytypes.NewMsgMint(addr1, burnAmount), - expectedError: nil, - dynamicDep: false, - }, - } - for _, tc := range tests { - suite.Run(fmt.Sprintf("Test Case: %s", tc.name), func() { - handlerCtx, cms := cacheTxContext(suite.Ctx) - _, err := suite.msgServer.Mint( - sdk.WrapSDKContext(handlerCtx), - tc.msg, - ) - suite.App.BankKeeper.WriteDeferredOperations(handlerCtx) - - depdenencies , _ := tkfactory.TokenFactoryMintDependencyGenerator( - suite.App.AccessControlKeeper, - handlerCtx, - tc.msg, - ) - - if !tc.dynamicDep { - depdenencies = sdkacltypes.SynchronousAccessOps() - } - - if tc.expectedError != nil { - suite.Require().EqualError(err, tc.expectedError.Error()) - } else { - suite.Require().NoError(err) - } - - missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - suite.Require().Empty(missing) - }) - } -} - -func TestGeneratorInvalidMessageTypes(t *testing.T) { - accs := authtypes.GenesisAccounts{} - balances := []banktypes.Balance{} - - app := simapp.SetupWithGenesisAccounts(accs, balances...) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - oracleVote := oracletypes.MsgAggregateExchangeRateVote{ - ExchangeRates: "1usei", - Feeder: "test", - Validator: "validator", - } - - _, err := tkfactory.TokenFactoryBurnDependencyGenerator(app.AccessControlKeeper, ctx, &oracleVote) - require.Error(t, err) -} - -func TestMsgBeginBankSendGenerator(t *testing.T) { - priv1 := secp256k1.GenPrivKey() - addr1 := sdk.AccAddress(priv1.PubKey().Address()) - - accs := authtypes.GenesisAccounts{} - balances := []banktypes.Balance{} - - app := simapp.SetupWithGenesisAccounts(accs, balances...) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - sendMsg := tokenfactorytypes.MsgBurn{ - Sender: addr1.String(), - Amount: sdk.NewInt64Coin("usei", 10), - } - - accessOps, err := tkfactory.TokenFactoryBurnDependencyGenerator(app.AccessControlKeeper, ctx, &sendMsg) - require.NoError(t, err) - err = acltypes.ValidateAccessOps(accessOps) - require.NoError(t, err) -} diff --git a/aclmapping/utils/resource_type.go b/aclmapping/utils/resource_type.go index 5da04b0717..bbd421582f 100644 --- a/aclmapping/utils/resource_type.go +++ b/aclmapping/utils/resource_type.go @@ -43,11 +43,7 @@ var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMa aclsdktypes.ResourceType_KV_STAKING_VALIDATOR: stakingtypes.ValidatorsKey, }, tokenfactorytypes.StoreKey: { - aclsdktypes.ResourceType_KV_TOKENFACTORY: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_KV_TOKENFACTORY_DENOM: []byte(tokenfactorytypes.DenomsPrefixKey), - aclsdktypes.ResourceType_KV_TOKENFACTORY_METADATA: []byte(tokenfactorytypes.DenomAuthorityMetadataKey), - aclsdktypes.ResourceType_KV_TOKENFACTORY_ADMIN: []byte(tokenfactorytypes.AdminPrefixKey), - aclsdktypes.ResourceType_KV_TOKENFACTORY_CREATOR: []byte(tokenfactorytypes.AdminPrefixKey), + aclsdktypes.ResourceType_KV_TOKENFACTORY: aclsdktypes.EmptyPrefix, }, epochtypes.StoreKey: { aclsdktypes.ResourceType_KV_EPOCH: aclsdktypes.EmptyPrefix, diff --git a/app/app.go b/app/app.go index 1aa001451b..bb8743d6c7 100644 --- a/app/app.go +++ b/app/app.go @@ -524,7 +524,6 @@ func New( appCodec, app.keys[acltypes.StoreKey], app.GetSubspace(acltypes.ModuleName), - app.AccountKeeper, aclOpts..., ) // The last arguments can contain custom message handlers, and custom query handlers, diff --git a/go.mod b/go.mod index d2a7f14794..9bb3f28b35 100644 --- a/go.mod +++ b/go.mod @@ -133,7 +133,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.245 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.243 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 diff --git a/go.sum b/go.sum index 0af27f1059..ce5844c7b7 100644 --- a/go.sum +++ b/go.sum @@ -1101,8 +1101,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.245 h1:mOPiwp1ThCapVCVH8mrmXU7ugngLWsiWAftaZ5Ga63U= -github.com/sei-protocol/sei-cosmos v0.1.245/go.mod h1:KPV8lFdD2Ki/M2wZTpfX3LCcuMAZnmcUzYJycjbmOYM= +github.com/sei-protocol/sei-cosmos v0.1.243 h1:61ZYGaE/bdzgR3sknuAn+p3wQA0wcmLNZ4OQjvtZL5o= +github.com/sei-protocol/sei-cosmos v0.1.243/go.mod h1:KPV8lFdD2Ki/M2wZTpfX3LCcuMAZnmcUzYJycjbmOYM= 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= diff --git a/scripts/old_initialize_local.sh b/scripts/old_initialize_local.sh old mode 100755 new mode 100644 From c1e1058330c66b26fdd987237219b92fc1568951 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 05/41] Revert "[loadtest] Loadtest fixes" This reverts commit 68bfab5985fd8f1b91492a0a198bae6066e52d5f. --- loadtest/config.json | 4 +-- loadtest/main.go | 70 ++++++++++++++------------------------------ 2 files changed, 24 insertions(+), 50 deletions(-) diff --git a/loadtest/config.json b/loadtest/config.json index ddbc7b6805..e492b672ed 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -1,7 +1,7 @@ { "msgs_per_tx": 10, "chain_id": "sei-loadtest-testnet", - "txs_per_block": 400, + "orders_per_block": 400, "rounds": 5, "price_distribution": { "min": "45", @@ -25,7 +25,7 @@ } }, "message_type": "bank,dex,staking,tokenfactory", - "run_oracle": true, + "run_oracle": false, "contract_distribution": [ { "contract_address":"sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m", diff --git a/loadtest/main.go b/loadtest/main.go index b453e43ba2..cfeacbc6d6 100644 --- a/loadtest/main.go +++ b/loadtest/main.go @@ -107,19 +107,31 @@ func (c *LoadTestClient) generateMessage(config Config, key cryptotypes.PrivKey, Funds: amount, } case Staking: + msgType := config.MsgTypeDistr.SampleStakingMsgs() - delegatorAddr := sdk.AccAddress(key.PubKey().Address()).String() - chosenValidator := c.Validators[rand.Intn(len(c.Validators))].OperatorAddress - // Randomly pick someone to redelegate / unbond from - srcAddr := "" - for k := range c.DelegationMap[delegatorAddr] { - if k == chosenValidator { - continue + switch msgType { + case "delegate": + msg = &stakingtypes.MsgDelegate{ + DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), + ValidatorAddress: c.Validators[rand.Intn(len(c.Validators))].OperatorAddress, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, } - srcAddr = k - break + case "undelegate": + msg = &stakingtypes.MsgUndelegate{ + DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), + ValidatorAddress: c.Validators[rand.Intn(len(c.Validators))].OperatorAddress, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, + } + case "begin_redelegate": + msg = &stakingtypes.MsgBeginRedelegate{ + DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), + ValidatorSrcAddress: c.Validators[rand.Intn(len(c.Validators))].OperatorAddress, + ValidatorDstAddress: c.Validators[rand.Intn(len(c.Validators))].OperatorAddress, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, + } + default: + panic("Unknown message type") } - msg = c.generateStakingMsg(delegatorAddr, chosenValidator, srcAddr) case Tokenfactory: denomCreatorAddr := sdk.AccAddress(key.PubKey().Address()).String() // No denoms, let's mint @@ -269,44 +281,6 @@ func generateOracleMessage(key cryptotypes.PrivKey) sdk.Msg { return msg } -func (c *LoadTestClient) generateStakingMsg(delegatorAddr string, chosenValidator string, srcAddr string) sdk.Msg { - // Randomly unbond, redelegate or delegate - // However, if there are no delegations, do so first - var msg sdk.Msg - msgType := c.LoadTestConfig.MsgTypeDistr.SampleStakingMsgs() - if _, ok := c.DelegationMap[delegatorAddr]; !ok || msgType == "delegate" || srcAddr == "" { - msg = &stakingtypes.MsgDelegate{ - DelegatorAddress: delegatorAddr, - ValidatorAddress: chosenValidator, - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, - } - c.DelegationMap[delegatorAddr] = map[string]int{} - c.DelegationMap[delegatorAddr][chosenValidator] = 1 - } else { - if msgType == "redelegate" { - msg = &stakingtypes.MsgBeginRedelegate{ - DelegatorAddress: delegatorAddr, - ValidatorSrcAddress: srcAddr, - ValidatorDstAddress: chosenValidator, - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, - } - c.DelegationMap[delegatorAddr][chosenValidator]++ - } else { - msg = &stakingtypes.MsgUndelegate{ - DelegatorAddress: delegatorAddr, - ValidatorAddress: srcAddr, - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, - } - } - // Update delegation map - c.DelegationMap[delegatorAddr][srcAddr]-- - if c.DelegationMap[delegatorAddr][srcAddr] == 0 { - delete(c.DelegationMap, delegatorAddr) - } - } - return msg -} - func getLastHeight() int { out, err := exec.Command("curl", "http://localhost:26657/blockchain").Output() if err != nil { From 5e7184d5a969d82d93ab74e133e65d877a682dad Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 06/41] Revert "fix unit tests" This reverts commit 49eb8092557a08609ae385c11ff4162eb2b88a0d. --- wasmbinding/test/query_test.go | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/wasmbinding/test/query_test.go b/wasmbinding/test/query_test.go index 21c7dfc18c..848287a4ad 100644 --- a/wasmbinding/test/query_test.go +++ b/wasmbinding/test/query_test.go @@ -862,19 +862,13 @@ func TestQueryHandlerDependencyDecoratorTokenFactory(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ - { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - SelectorType: accesscontrol.AccessOperationSelectorType_NONE, - }, + AccessOps: []accesscontrol.AccessOperation{ { - Operation: acltypes.CommitAccessOp(), - SelectorType: accesscontrol.AccessOperationSelectorType_NONE, + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -890,19 +884,13 @@ func TestQueryHandlerDependencyDecoratorTokenFactory(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ - { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_Mem, - IdentifierTemplate: "*", - }, - SelectorType: accesscontrol.AccessOperationSelectorType_NONE, - }, + AccessOps: []accesscontrol.AccessOperation{ { - Operation: acltypes.CommitAccessOp(), - SelectorType: accesscontrol.AccessOperationSelectorType_NONE, + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_Mem, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -910,5 +898,5 @@ func TestQueryHandlerDependencyDecoratorTokenFactory(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ Custom: customQuery, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } From dc8720afcde350ab0cb2195baede51e29de1fea3 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 07/41] Revert "Fix Bank Send Unit Tests (#348)" This reverts commit 9c11837b0bb11476a5d9dd9f91ab4dff841a4c1a. --- x/tokenfactory/keeper/admins_test.go | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/x/tokenfactory/keeper/admins_test.go b/x/tokenfactory/keeper/admins_test.go index 0c3f3632c7..414519f320 100644 --- a/x/tokenfactory/keeper/admins_test.go +++ b/x/tokenfactory/keeper/admins_test.go @@ -17,14 +17,11 @@ func (suite *KeeperTestSuite) TestAdminMsgs() { queryRes, err := suite.queryClient.DenomAuthorityMetadata(suite.Ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ Denom: suite.defaultDenom, }) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) suite.Require().NoError(err) suite.Require().Equal(suite.TestAccs[0].String(), queryRes.AuthorityMetadata.Admin) // Test minting to admins own account _, err = suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 10))) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - addr0bal += 10 suite.Require().NoError(err) suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom).Amount.Int64() == addr0bal, suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[0], suite.defaultDenom)) @@ -37,16 +34,12 @@ func (suite *KeeperTestSuite) TestAdminMsgs() { // Test burning from own account _, err = suite.msgServer.Burn(sdk.WrapSDKContext(suite.Ctx), types.NewMsgBurn(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 5))) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - addr0bal -= 5 suite.Require().NoError(err) suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], suite.defaultDenom).Amount.Int64() == addr1bal) // Test Change Admin _, err = suite.msgServer.ChangeAdmin(sdk.WrapSDKContext(suite.Ctx), types.NewMsgChangeAdmin(suite.TestAccs[0].String(), suite.defaultDenom, suite.TestAccs[1].String())) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - queryRes, err = suite.queryClient.DenomAuthorityMetadata(suite.Ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ Denom: suite.defaultDenom, }) @@ -55,22 +48,16 @@ func (suite *KeeperTestSuite) TestAdminMsgs() { // Make sure old admin can no longer do actions _, err = suite.msgServer.Burn(sdk.WrapSDKContext(suite.Ctx), types.NewMsgBurn(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 5))) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - suite.Require().Error(err) // Make sure the new admin works _, err = suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[1].String(), sdk.NewInt64Coin(suite.defaultDenom, 5))) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - addr1bal += 5 suite.Require().NoError(err) suite.Require().True(suite.App.BankKeeper.GetBalance(suite.Ctx, suite.TestAccs[1], suite.defaultDenom).Amount.Int64() == addr1bal) // Try setting admin to empty _, err = suite.msgServer.ChangeAdmin(sdk.WrapSDKContext(suite.Ctx), types.NewMsgChangeAdmin(suite.TestAccs[1].String(), suite.defaultDenom, "")) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - suite.Require().NoError(err) queryRes, err = suite.queryClient.DenomAuthorityMetadata(suite.Ctx.Context(), &types.QueryDenomAuthorityMetadataRequest{ Denom: suite.defaultDenom, @@ -121,8 +108,6 @@ func (suite *KeeperTestSuite) TestMintDenom() { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { // Test minting to admins own account _, err := suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(tc.admin, sdk.NewInt64Coin(tc.mintDenom, 10))) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - if tc.valid { addr0bal += 10 suite.Require().NoError(err) @@ -142,8 +127,6 @@ func (suite *KeeperTestSuite) TestBurnDenom() { // mint 10 default token for testAcc[0] suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(suite.defaultDenom, 10))) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - addr0bal += 10 for _, tc := range []struct { @@ -185,8 +168,6 @@ func (suite *KeeperTestSuite) TestBurnDenom() { suite.Run(fmt.Sprintf("Case %s", tc.desc), func() { // Test minting to admins own account _, err := suite.msgServer.Burn(sdk.WrapSDKContext(suite.Ctx), types.NewMsgBurn(tc.admin, sdk.NewInt64Coin(tc.burnDenom, 10))) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - if tc.valid { addr0bal -= 10 suite.Require().NoError(err) @@ -247,19 +228,14 @@ func (suite *KeeperTestSuite) TestChangeAdminDenom() { // Create a denom and mint res, err := suite.msgServer.CreateDenom(sdk.WrapSDKContext(suite.Ctx), types.NewMsgCreateDenom(suite.TestAccs[0].String(), "bitcoin")) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) suite.Require().NoError(err) testDenom := res.GetNewTokenDenom() _, err = suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), types.NewMsgMint(suite.TestAccs[0].String(), sdk.NewInt64Coin(testDenom, 10))) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - suite.Require().NoError(err) _, err = suite.msgServer.ChangeAdmin(sdk.WrapSDKContext(suite.Ctx), tc.msgChangeAdmin(testDenom)) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - if tc.expectedChangeAdminPass { suite.Require().NoError(err) } else { @@ -282,8 +258,6 @@ func (suite *KeeperTestSuite) TestChangeAdminDenom() { // we test mint to test if admin authority is performed properly after admin change. if tc.msgMint != nil { _, err := suite.msgServer.Mint(sdk.WrapSDKContext(suite.Ctx), tc.msgMint(testDenom)) - suite.App.BankKeeper.WriteDeferredOperations(suite.Ctx) - if tc.expectedMintPass { suite.Require().NoError(err) } else { From c55eccec09d3eddcbd5b0485a7241a13101f227c Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 08/41] Revert "integrate with sei-cosmos changes (#347)" This reverts commit e1b1790656dde017a64ce3f739f3a1db338d57d8. --- aclmapping/wasm/mappings.go | 5 +- app/ante.go | 19 +- app/antedecorators/gas.go | 53 ------ app/antedecorators/gas_test.go | 77 -------- app/app.go | 38 +--- go.mod | 5 +- go.sum | 9 +- wasmbinding/message_plugin.go | 17 +- wasmbinding/query_plugin.go | 33 +--- wasmbinding/test/message_handler_test.go | 60 +++--- wasmbinding/test/query_test.go | 225 +++++++++-------------- wasmbinding/utils.go | 14 -- 12 files changed, 151 insertions(+), 404 deletions(-) delete mode 100644 app/antedecorators/gas.go delete mode 100644 app/antedecorators/gas_test.go delete mode 100644 wasmbinding/utils.go diff --git a/aclmapping/wasm/mappings.go b/aclmapping/wasm/mappings.go index 1559a41cc6..17e8acaeca 100644 --- a/aclmapping/wasm/mappings.go +++ b/aclmapping/wasm/mappings.go @@ -8,7 +8,6 @@ import ( 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" - "github.com/sei-protocol/sei-chain/utils" ) var ( @@ -42,12 +41,12 @@ func (wasmDepGen WasmDependencyGenerator) WasmExecuteContractGenerator(keeper ac if err != nil { return []sdkacltypes.AccessOperation{}, err } - wasmDependencyMapping, err := keeper.GetWasmDependencyMapping(ctx, contractAddr, executeContractMsg.Msg, true) + wasmDependencyMapping, err := keeper.GetWasmDependencyMapping(ctx, contractAddr) if err != nil { return []sdkacltypes.AccessOperation{}, err } if !wasmDependencyMapping.Enabled { return []sdkacltypes.AccessOperation{}, ErrWasmFunctionDependenciesDisabled } - return utils.Map(wasmDependencyMapping.AccessOps, func(op sdkacltypes.AccessOperationWithSelector) sdkacltypes.AccessOperation { return *op.Operation }), nil + return wasmDependencyMapping.AccessOps, nil } diff --git a/app/ante.go b/app/ante.go index 194c9c85d6..857d4f3127 100644 --- a/app/ante.go +++ b/app/ante.go @@ -5,7 +5,6 @@ import ( wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" "github.com/cosmos/cosmos-sdk/x/auth/ante" ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" @@ -24,13 +23,12 @@ import ( type HandlerOptions struct { ante.HandlerOptions - IBCKeeper *ibckeeper.Keeper - WasmConfig *wasmTypes.WasmConfig - OracleKeeper *oraclekeeper.Keeper - DexKeeper *dexkeeper.Keeper - NitroKeeper *nitrokeeper.Keeper - AccessControlKeeper *aclkeeper.Keeper - TXCounterStoreKey sdk.StoreKey + IBCKeeper *ibckeeper.Keeper + WasmConfig *wasmTypes.WasmConfig + OracleKeeper *oraclekeeper.Keeper + DexKeeper *dexkeeper.Keeper + NitroKeeper *nitrokeeper.Keeper + TXCounterStoreKey sdk.StoreKey TracingInfo *tracing.Info } @@ -54,9 +52,6 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk if options.NitroKeeper == nil { return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "nitro keeper is required for ante builder") } - if options.AccessControlKeeper == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "accesscontrol keeper is required for ante builder") - } if options.TracingInfo == nil { return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tracing info is required for ante builder") } @@ -75,7 +70,7 @@ 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 + sdk.DefaultWrappedAnteDecorator(ante.NewSetUpContextDecorator()), // 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)), sdk.DefaultWrappedAnteDecorator(wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit)), // after setup context to enforce limits early diff --git a/app/antedecorators/gas.go b/app/antedecorators/gas.go deleted file mode 100644 index d5be80fd12..0000000000 --- a/app/antedecorators/gas.go +++ /dev/null @@ -1,53 +0,0 @@ -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" -) - -const ( - GasMultiplierNumerator uint64 = 1 - DefaultGasMultiplierDenominator uint64 = 1 - WasmCorrectDependencyDiscountDenominator uint64 = 2 -) - -func GetGasMeterSetter(aclkeeper aclkeeper.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 { - return ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) - } - - denominator := uint64(1) - for _, msg := range tx.GetMsgs() { - candidateDenominator := getMessageMultiplierDenominator(ctx, msg, aclkeeper) - if candidateDenominator > denominator { - denominator = candidateDenominator - } - } - return ctx.WithGasMeter(types.NewMultiplierGasMeter(gasLimit, DefaultGasMultiplierDenominator, denominator)) - } -} - -func getMessageMultiplierDenominator(ctx sdk.Context, msg sdk.Msg, aclkeeper aclkeeper.Keeper) uint64 { - if wasmExecuteMsg, ok := msg.(*wasmtypes.MsgExecuteContract); ok { - addr, err := sdk.AccAddressFromBech32(wasmExecuteMsg.Contract) - if err != nil { - return DefaultGasMultiplierDenominator - } - mapping, err := aclkeeper.GetWasmDependencyMapping(ctx, addr, []byte{}, false) - if err != nil { - return DefaultGasMultiplierDenominator - } - // only give gas discount if none of the dependency (except COMMIT) has id "*" - for _, op := range mapping.AccessOps { - if op.Operation.AccessType != sdkacltypes.AccessType_COMMIT && op.Operation.IdentifierTemplate == "*" { - return DefaultGasMultiplierDenominator - } - } - return WasmCorrectDependencyDiscountDenominator - } - return DefaultGasMultiplierDenominator -} diff --git a/app/antedecorators/gas_test.go b/app/antedecorators/gas_test.go deleted file mode 100644 index 27baf0b972..0000000000 --- a/app/antedecorators/gas_test.go +++ /dev/null @@ -1,77 +0,0 @@ -package antedecorators_test - -import ( - "testing" - - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/accesscontrol" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - "github.com/sei-protocol/sei-chain/app" - "github.com/sei-protocol/sei-chain/app/antedecorators" - "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/proto/tendermint/types" -) - -type TestTx struct { - msgs []sdk.Msg -} - -func (t TestTx) GetMsgs() []sdk.Msg { - return t.msgs -} - -func (t TestTx) ValidateBasic() error { - return nil -} - -func TestMultiplierGasSetter(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - ctx := app.NewContext(false, types.Header{}).WithBlockHeight(2) - testMsg := wasmtypes.MsgExecuteContract{ - Contract: "sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw", - Msg: []byte("{}"), - } - testTx := TestTx{msgs: []sdk.Msg{&testMsg}} - // discounted mapping - app.AccessControlKeeper.SetWasmDependencyMapping(ctx, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ - { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "something", - }, - }, - { - Operation: acltypes.CommitAccessOp(), - }, - }, - }) - gasMeterSetter := antedecorators.GetGasMeterSetter(app.AccessControlKeeper) - ctxWithGasMeter := gasMeterSetter(false, ctx, 1000, testTx) - ctxWithGasMeter.GasMeter().ConsumeGas(2, "") - require.Equal(t, uint64(1), ctxWithGasMeter.GasMeter().GasConsumed()) - // not discounted mapping - app.AccessControlKeeper.SetWasmDependencyMapping(ctx, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ - { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - }, - { - Operation: acltypes.CommitAccessOp(), - }, - }, - }) - ctxWithGasMeter = gasMeterSetter(false, ctx, 1000, testTx) - ctxWithGasMeter.GasMeter().ConsumeGas(2, "") - require.Equal(t, uint64(2), ctxWithGasMeter.GasMeter().GasConsumed()) -} diff --git a/app/app.go b/app/app.go index bb8743d6c7..831989ae57 100644 --- a/app/app.go +++ b/app/app.go @@ -40,7 +40,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol" aclclient "github.com/cosmos/cosmos-sdk/x/accesscontrol/client" - aclconstants "github.com/cosmos/cosmos-sdk/x/accesscontrol/constants" aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" @@ -783,14 +782,13 @@ func New( SigGasConsumer: ante.DefaultSigVerificationGasConsumer, // BatchVerifier: app.batchVerifier, }, - IBCKeeper: app.IBCKeeper, - TXCounterStoreKey: keys[wasm.StoreKey], - WasmConfig: &wasmConfig, - OracleKeeper: &app.OracleKeeper, - DexKeeper: &app.DexKeeper, - NitroKeeper: &app.NitroKeeper, - TracingInfo: app.tracingInfo, - AccessControlKeeper: &app.AccessControlKeeper, + IBCKeeper: app.IBCKeeper, + TXCounterStoreKey: keys[wasm.StoreKey], + WasmConfig: &wasmConfig, + OracleKeeper: &app.OracleKeeper, + DexKeeper: &app.DexKeeper, + NitroKeeper: &app.NitroKeeper, + TracingInfo: app.tracingInfo, }, ) if err != nil { @@ -1202,7 +1200,6 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ lazyWriteEvents := app.BankKeeper.WriteDeferredDepositsToModuleAccounts(ctx) events = append(events, lazyWriteEvents...) - ctx = app.enrichContextWithTxResults(ctx, txResults) endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{ Height: req.GetHeight(), }) @@ -1212,27 +1209,6 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ return events, txResults, endBlockResp, nil } -func (app *App) enrichContextWithTxResults(ctx sdk.Context, txResults []*abci.ExecTxResult) sdk.Context { - wasmContractsWithIncorrectDependencies := []sdk.AccAddress{} - for _, txResult := range txResults { - if txResult.Codespace == acltypes.ModuleName && txResult.Code == 2 { - for _, event := range txResult.Events { - if event.Type == wasmbinding.EventTypeWasmContractWithIncorrectDependency { - for _, attr := range event.Attributes { - if attr.Key == wasmbinding.AttributeKeyWasmContractAddress { - addr, err := sdk.AccAddressFromBech32(attr.Value) - if err == nil { - wasmContractsWithIncorrectDependencies = append(wasmContractsWithIncorrectDependencies, addr) - } - } - } - } - } - } - } - return ctx.WithContext(context.WithValue(ctx.Context(), aclconstants.BadWasmDependencyAddressesKey, wasmContractsWithIncorrectDependencies)) -} - func (app *App) getFinalizeBlockResponse(appHash []byte, events []abci.Event, txResults []*abci.ExecTxResult, endBlockResp abci.ResponseEndBlock) abci.ResponseFinalizeBlock { return abci.ResponseFinalizeBlock{ Events: events, diff --git a/go.mod b/go.mod index 9bb3f28b35..c16e1b98cc 100644 --- a/go.mod +++ b/go.mod @@ -107,7 +107,6 @@ require ( github.com/rs/cors v1.8.2 // indirect github.com/rs/zerolog v1.26.1 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect - github.com/savaki/jq v0.0.0-20161209013833-0e6baecebbf8 // indirect github.com/spf13/afero v1.8.2 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect @@ -124,7 +123,7 @@ require ( golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect - golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // 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.8 // indirect gopkg.in/ini.v1 v1.66.4 // indirect @@ -133,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.243 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.239 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 diff --git a/go.sum b/go.sum index ce5844c7b7..b48804bb2f 100644 --- a/go.sum +++ b/go.sum @@ -1095,14 +1095,12 @@ github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0 github.com/sanposhiho/wastedassign/v2 v2.0.6/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI= github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= -github.com/savaki/jq v0.0.0-20161209013833-0e6baecebbf8 h1:ajJQhvqPSQFJJ4aV5mDAMx8F7iFi6Dxfo6y62wymLNs= -github.com/savaki/jq v0.0.0-20161209013833-0e6baecebbf8/go.mod h1:Nw/CCOXNyF5JDd6UpYxBwG5WWZ2FOJ/d5QnXL4KQ6vY= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= 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.243 h1:61ZYGaE/bdzgR3sknuAn+p3wQA0wcmLNZ4OQjvtZL5o= -github.com/sei-protocol/sei-cosmos v0.1.243/go.mod h1:KPV8lFdD2Ki/M2wZTpfX3LCcuMAZnmcUzYJycjbmOYM= +github.com/sei-protocol/sei-cosmos v0.1.239 h1:IuWt2PVB6kDVA7NHBRp5BGwgjw1Lg4dJT91yb4VmEZI= +github.com/sei-protocol/sei-cosmos v0.1.239/go.mod h1:c2dhT0+W9l83qjFJrQ6CcjhtHwHOoha5K1rtt4LeDBU= 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= @@ -1635,9 +1633,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-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY= -golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/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= diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index 5ea56529e1..e3776be2a6 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -1,18 +1,20 @@ package wasmbinding import ( + "fmt" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" wasmvmtypes "github.com/CosmWasm/wasmvm/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - "github.com/cosmos/cosmos-sdk/x/accesscontrol" aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - "github.com/sei-protocol/sei-chain/utils" ) +var ErrUnexpectedWasmDependency = fmt.Errorf("unexpected wasm dependency detected") + // forked from wasm func CustomMessageHandler( router wasmkeeper.MessageRouter, @@ -121,9 +123,7 @@ func (decorator SDKMessageDependencyDecorator) DispatchMsg(ctx sdk.Context, cont return nil, nil, err } // get the dependencies for the contract to validate against - // TODO: we need to carry wasmDependency in ctx instead of loading again here since here has no access to original msg payload - // which is required for populating id correctly. - wasmDependency, err := decorator.aclKeeper.GetWasmDependencyMapping(ctx, contractAddr, []byte{}, false) + wasmDependency, err := decorator.aclKeeper.GetWasmDependencyMapping(ctx, contractAddr) // If no mapping exists, or mapping is disabled, this message would behave as blocking for all resources if err == aclkeeper.ErrWasmDependencyMappingNotFound { // no mapping, we can just continue @@ -138,9 +138,7 @@ func (decorator SDKMessageDependencyDecorator) DispatchMsg(ctx sdk.Context, cont return decorator.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) } // convert wasm dependency to a map of resource access and identifier we can look up in - lookupMap := BuildWasmDependencyLookupMap( - utils.Map(wasmDependency.AccessOps, func(op sdkacltypes.AccessOperationWithSelector) sdkacltypes.AccessOperation { return *op.Operation }), - ) + lookupMap := BuildWasmDependencyLookupMap(wasmDependency.AccessOps) // wasm dependency enabled, we need to validate the message dependencies for _, msg := range sdkMsgs { accessOps := decorator.aclKeeper.GetMessageDependencies(ctx, msg) @@ -149,8 +147,7 @@ func (decorator SDKMessageDependencyDecorator) DispatchMsg(ctx sdk.Context, cont // first check for our specific resource access AND identifier template depsFulfilled := AreDependenciesFulfilled(lookupMap, accessOp) if !depsFulfilled { - emitIncorrectDependencyWasmEvent(ctx, contractAddr.String()) - return nil, nil, accesscontrol.ErrUnexpectedWasmDependency + return nil, nil, ErrUnexpectedWasmDependency } } } diff --git a/wasmbinding/query_plugin.go b/wasmbinding/query_plugin.go index db94e3162c..6ae594f48b 100644 --- a/wasmbinding/query_plugin.go +++ b/wasmbinding/query_plugin.go @@ -8,9 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/accesscontrol" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - acl "github.com/cosmos/cosmos-sdk/x/accesscontrol" aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" - "github.com/sei-protocol/sei-chain/utils" ) const ( @@ -54,9 +52,7 @@ type CustomQueryHandler struct { } func (queryHandler CustomQueryHandler) HandleQuery(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error) { - // TODO: we need to carry wasmDependency in ctx instead of loading again here since here has no access to original msg payload - // which is required for populating id correctly. - wasmDependency, err := queryHandler.aclKeeper.GetWasmDependencyMapping(ctx, caller, []byte{}, false) + wasmDependency, err := queryHandler.aclKeeper.GetWasmDependencyMapping(ctx, caller) // If no mapping exists, or mapping is disabled, this message would behave as blocking for all resources needToCheckDependencies := true if err == aclkeeper.ErrWasmDependencyMappingNotFound { @@ -69,21 +65,17 @@ func (queryHandler CustomQueryHandler) HandleQuery(ctx sdk.Context, caller sdk.A if !wasmDependency.Enabled { needToCheckDependencies = false } - lookupMap := BuildWasmDependencyLookupMap( - utils.Map(wasmDependency.AccessOps, func(op accesscontrol.AccessOperationWithSelector) accesscontrol.AccessOperation { return *op.Operation }), - ) + lookupMap := BuildWasmDependencyLookupMap(wasmDependency.AccessOps) if request.Bank != nil { // check for BANK resource type accessOp := accesscontrol.AccessOperation{ - ResourceType: accesscontrol.ResourceType_KV_BANK, - AccessType: accesscontrol.AccessType_READ, - // TODO: should IdentifierTemplate be based on the actual request? + ResourceType: accesscontrol.ResourceType_KV_BANK, + AccessType: accesscontrol.AccessType_READ, IdentifierTemplate: "*", } if needToCheckDependencies { if !AreDependenciesFulfilled(lookupMap, accessOp) { - emitIncorrectDependencyWasmEvent(ctx, caller.String()) - return nil, acl.ErrUnexpectedWasmDependency + return nil, ErrUnexpectedWasmDependency } } return queryHandler.QueryPlugins.Bank(ctx, request.Bank) @@ -113,8 +105,7 @@ func (queryHandler CustomQueryHandler) HandleQuery(ctx sdk.Context, caller sdk.A } if needToCheckDependencies { if !AreDependenciesFulfilled(lookupMap, accessOp) { - emitIncorrectDependencyWasmEvent(ctx, caller.String()) - return nil, acl.ErrUnexpectedWasmDependency + return nil, ErrUnexpectedWasmDependency } } return queryHandler.QueryPlugins.Custom(ctx, request.Custom) @@ -129,8 +120,7 @@ func (queryHandler CustomQueryHandler) HandleQuery(ctx sdk.Context, caller sdk.A } if needToCheckDependencies { if !AreDependenciesFulfilled(lookupMap, accessOp) { - emitIncorrectDependencyWasmEvent(ctx, caller.String()) - return nil, acl.ErrUnexpectedWasmDependency + return nil, ErrUnexpectedWasmDependency } } return queryHandler.QueryPlugins.IBC(ctx, caller, request.IBC) @@ -144,8 +134,7 @@ func (queryHandler CustomQueryHandler) HandleQuery(ctx sdk.Context, caller sdk.A } if needToCheckDependencies { if !AreDependenciesFulfilled(lookupMap, accessOp) { - emitIncorrectDependencyWasmEvent(ctx, caller.String()) - return nil, acl.ErrUnexpectedWasmDependency + return nil, ErrUnexpectedWasmDependency } } return queryHandler.QueryPlugins.Staking(ctx, request.Staking) @@ -160,8 +149,7 @@ func (queryHandler CustomQueryHandler) HandleQuery(ctx sdk.Context, caller sdk.A } if needToCheckDependencies { if !AreDependenciesFulfilled(lookupMap, accessOp) { - emitIncorrectDependencyWasmEvent(ctx, caller.String()) - return nil, acl.ErrUnexpectedWasmDependency + return nil, ErrUnexpectedWasmDependency } } return queryHandler.QueryPlugins.Stargate(ctx, request.Stargate) @@ -175,8 +163,7 @@ func (queryHandler CustomQueryHandler) HandleQuery(ctx sdk.Context, caller sdk.A } if needToCheckDependencies { if !AreDependenciesFulfilled(lookupMap, accessOp) { - emitIncorrectDependencyWasmEvent(ctx, caller.String()) - return nil, acl.ErrUnexpectedWasmDependency + return nil, ErrUnexpectedWasmDependency } } return queryHandler.QueryPlugins.Wasm(ctx, request.Wasm) diff --git a/wasmbinding/test/message_handler_test.go b/wasmbinding/test/message_handler_test.go index d72bc219d9..20dd685c6e 100644 --- a/wasmbinding/test/message_handler_test.go +++ b/wasmbinding/test/message_handler_test.go @@ -8,8 +8,7 @@ import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - "github.com/cosmos/cosmos-sdk/x/accesscontrol" + "github.com/cosmos/cosmos-sdk/types/accesscontrol" acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/sei-protocol/sei-chain/app" @@ -37,32 +36,29 @@ func TestMessageHandlerDependencyDecorator(t *testing.T) { testContext := app.NewContext(false, types.Header{}) // setup bank send message with aclkeeper - app.AccessControlKeeper.SetResourceDependencyMapping(testContext, sdkacltypes.MessageDependencyMapping{ + app.AccessControlKeeper.SetResourceDependencyMapping(testContext, accesscontrol.MessageDependencyMapping{ MessageKey: string(acltypes.GenerateMessageKey(&banktypes.MsgSend{})), - AccessOps: []sdkacltypes.AccessOperation{ + AccessOps: []accesscontrol.AccessOperation{ { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV, IdentifierTemplate: "*", }, - *acltypes.CommitAccessOp(), + acltypes.CommitAccessOp(), }, DynamicEnabled: false, }) // setup the wasm contract's dependency mapping - app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, sdkacltypes.WasmDependencyMapping{ + app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []sdkacltypes.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &sdkacltypes.AccessOperation{ - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_ANY, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_WRITE, + ResourceType: accesscontrol.ResourceType_ANY, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) @@ -87,18 +83,15 @@ func TestMessageHandlerDependencyDecorator(t *testing.T) { }, }, events) - app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, sdkacltypes.WasmDependencyMapping{ + app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []sdkacltypes.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &sdkacltypes.AccessOperation{ - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: "otherIdentifier", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_WRITE, + ResourceType: accesscontrol.ResourceType_KV, + IdentifierTemplate: "otherIdentifier", }, + acltypes.CommitAccessOp(), }, }) @@ -116,21 +109,18 @@ func TestMessageHandlerDependencyDecorator(t *testing.T) { }, }) // we expect an error now - require.Error(t, accesscontrol.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) // reenable wasm mapping that's correct - app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, sdkacltypes.WasmDependencyMapping{ + app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []sdkacltypes.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &sdkacltypes.AccessOperation{ - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_WRITE, + ResourceType: accesscontrol.ResourceType_KV, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) // lets try with a message that wont decode properly diff --git a/wasmbinding/test/query_test.go b/wasmbinding/test/query_test.go index 848287a4ad..f027cf88e3 100644 --- a/wasmbinding/test/query_test.go +++ b/wasmbinding/test/query_test.go @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/accesscontrol" - acl "github.com/cosmos/cosmos-sdk/x/accesscontrol" acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" "github.com/sei-protocol/sei-chain/app" keepertest "github.com/sei-protocol/sei-chain/testutil/keeper" @@ -442,16 +441,13 @@ func TestQueryHandlerDependencyDecoratorBank(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_BANK, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_BANK, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -463,16 +459,13 @@ func TestQueryHandlerDependencyDecoratorBank(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV_DEX, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_WRITE, + ResourceType: accesscontrol.ResourceType_KV_DEX, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -480,7 +473,7 @@ func TestQueryHandlerDependencyDecoratorBank(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ Bank: &wasmvmtypes.BankQuery{}, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } func TestQueryHandlerDependencyDecoratorIBC(t *testing.T) { @@ -493,16 +486,13 @@ func TestQueryHandlerDependencyDecoratorIBC(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_ANY, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_ANY, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -514,16 +504,13 @@ func TestQueryHandlerDependencyDecoratorIBC(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_WRITE, + ResourceType: accesscontrol.ResourceType_KV, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -531,7 +518,7 @@ func TestQueryHandlerDependencyDecoratorIBC(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ IBC: &wasmvmtypes.IBCQuery{}, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } func TestQueryHandlerDependencyDecoratorStaking(t *testing.T) { @@ -544,16 +531,13 @@ func TestQueryHandlerDependencyDecoratorStaking(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_STAKING, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_STAKING, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -565,16 +549,13 @@ func TestQueryHandlerDependencyDecoratorStaking(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV_DEX, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_WRITE, + ResourceType: accesscontrol.ResourceType_KV_DEX, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -582,7 +563,7 @@ func TestQueryHandlerDependencyDecoratorStaking(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ Staking: &wasmvmtypes.StakingQuery{}, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } func TestQueryHandlerDependencyDecoratorStargate(t *testing.T) { @@ -595,16 +576,13 @@ func TestQueryHandlerDependencyDecoratorStargate(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_ANY, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_ANY, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -616,16 +594,13 @@ func TestQueryHandlerDependencyDecoratorStargate(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_WRITE, + ResourceType: accesscontrol.ResourceType_KV, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -633,7 +608,7 @@ func TestQueryHandlerDependencyDecoratorStargate(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ Stargate: &wasmvmtypes.StargateQuery{}, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } func TestQueryHandlerDependencyDecoratorWasm(t *testing.T) { @@ -646,16 +621,13 @@ func TestQueryHandlerDependencyDecoratorWasm(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_WASM, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_WASM, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -667,16 +639,13 @@ func TestQueryHandlerDependencyDecoratorWasm(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV_DEX, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_WRITE, + ResourceType: accesscontrol.ResourceType_KV_DEX, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -684,7 +653,7 @@ func TestQueryHandlerDependencyDecoratorWasm(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ Wasm: &wasmvmtypes.WasmQuery{}, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } func TestQueryHandlerDependencyDecoratorDex(t *testing.T) { @@ -697,16 +666,13 @@ func TestQueryHandlerDependencyDecoratorDex(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_DEX, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_DEX, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -722,16 +688,13 @@ func TestQueryHandlerDependencyDecoratorDex(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_ORACLE, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_ORACLE, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -739,7 +702,7 @@ func TestQueryHandlerDependencyDecoratorDex(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ Custom: customQuery, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } func TestQueryHandlerDependencyDecoratorOracle(t *testing.T) { @@ -752,16 +715,13 @@ func TestQueryHandlerDependencyDecoratorOracle(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_ORACLE, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_ORACLE, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -777,16 +737,13 @@ func TestQueryHandlerDependencyDecoratorOracle(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_BANK, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_BANK, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -794,7 +751,7 @@ func TestQueryHandlerDependencyDecoratorOracle(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ Custom: customQuery, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } func TestQueryHandlerDependencyDecoratorEpoch(t *testing.T) { @@ -807,16 +764,13 @@ func TestQueryHandlerDependencyDecoratorEpoch(t *testing.T) { // setup the wasm contract's dependency mapping err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_EPOCH, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_EPOCH, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -832,16 +786,13 @@ func TestQueryHandlerDependencyDecoratorEpoch(t *testing.T) { err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ Enabled: true, - AccessOps: []accesscontrol.AccessOperationWithSelector{ + AccessOps: []accesscontrol.AccessOperation{ { - Operation: &accesscontrol.AccessOperation{ - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_BANK, - IdentifierTemplate: "*", - }, - }, { - Operation: acltypes.CommitAccessOp(), + AccessType: accesscontrol.AccessType_READ, + ResourceType: accesscontrol.ResourceType_KV_BANK, + IdentifierTemplate: "*", }, + acltypes.CommitAccessOp(), }, }) require.NoError(t, err) @@ -849,7 +800,7 @@ func TestQueryHandlerDependencyDecoratorEpoch(t *testing.T) { _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ Custom: customQuery, }) - require.Error(t, acl.ErrUnexpectedWasmDependency, err) + require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) } func TestQueryHandlerDependencyDecoratorTokenFactory(t *testing.T) { diff --git a/wasmbinding/utils.go b/wasmbinding/utils.go deleted file mode 100644 index b07702e978..0000000000 --- a/wasmbinding/utils.go +++ /dev/null @@ -1,14 +0,0 @@ -package wasmbinding - -import sdk "github.com/cosmos/cosmos-sdk/types" - -const ( - EventTypeWasmContractWithIncorrectDependency = "wasm-incorrect-dep" - AttributeKeyWasmContractAddress = "contract-addr" -) - -func emitIncorrectDependencyWasmEvent(ctx sdk.Context, contractAddr string) { - ctx.EventManager().EmitEvent( - sdk.NewEvent(EventTypeWasmContractWithIncorrectDependency, sdk.NewAttribute(AttributeKeyWasmContractAddress, contractAddr)), - ) -} From 843e8ebc9d4742252f704d6248c5d04a92cd23ff Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 09/41] Revert "Validate Concurrent Messages + Update BankSend (#345)" This reverts commit e4d31768a9acb38778f902d4fd4b816be910e587. --- aclmapping/bank/mappings.go | 37 ++---- aclmapping/bank/mappings_test.go | 158 ----------------------- aclmapping/utils/identifier_templates.go | 2 +- aclmapping/utils/resource_type.go | 51 -------- app/app.go | 45 ++----- go.mod | 2 +- go.sum | 4 +- store/testutils.go | 2 +- utils/metrics/metrics_util.go | 12 -- x/oracle/simulation/operations.go | 4 +- 10 files changed, 29 insertions(+), 288 deletions(-) delete mode 100644 aclmapping/bank/mappings_test.go delete mode 100644 aclmapping/utils/resource_type.go diff --git a/aclmapping/bank/mappings.go b/aclmapping/bank/mappings.go index 47989a1823..3d65fa90ba 100644 --- a/aclmapping/bank/mappings.go +++ b/aclmapping/bank/mappings.go @@ -7,7 +7,6 @@ import ( 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" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" utils "github.com/sei-protocol/sei-chain/aclmapping/utils" ) @@ -24,13 +23,12 @@ func GetBankDepedencyGenerator() aclkeeper.DependencyGeneratorMap { return dependencyGeneratorMap } +// TODO:: we can make resource types more granular (e.g KV_PARAM or KV_BANK_BALANCE) func MsgSendDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { msgSend, ok := msg.(*banktypes.MsgSend) if !ok { return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType } - fromAddrIdentifier := string(banktypes.CreateAccountBalancesPrefixFromBech32(msgSend.FromAddress)) - toAddrIdentifier := string(banktypes.CreateAccountBalancesPrefixFromBech32(msgSend.ToAddress)) accessOperations := []sdkacltypes.AccessOperation{ // MsgSend also checks if the coin denom is enabled, but the information is from the params. @@ -39,53 +37,46 @@ func MsgSendDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sd // Checks balance of sender { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: fromAddrIdentifier, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.FromAddress), }, // Reduce the amount from the sender's balance { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: fromAddrIdentifier, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.FromAddress), }, // Checks balance for receiver { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: toAddrIdentifier, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.ToAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK_BALANCES, - IdentifierTemplate: toAddrIdentifier, + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.ToAddress), }, // Tries to create the reciever's account if it doesn't exist { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.CreateAddressStoreKeyFromBech32(msgSend.ToAddress)), + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, msgSend.ToAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.CreateAddressStoreKeyFromBech32(msgSend.ToAddress)), - }, - - // Gets Account Info for the sender - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_AUTH_ADDRESS_STORE, - IdentifierTemplate: string(authtypes.CreateAddressStoreKeyFromBech32(msgSend.FromAddress)), + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, msgSend.ToAddress), }, + // Last Operation should always be a commit { ResourceType: sdkacltypes.ResourceType_ANY, AccessType: sdkacltypes.AccessType_COMMIT, IdentifierTemplate: utils.DefaultIDTemplate, }, } - return accessOperations, nil } diff --git a/aclmapping/bank/mappings_test.go b/aclmapping/bank/mappings_test.go deleted file mode 100644 index 9800592f0b..0000000000 --- a/aclmapping/bank/mappings_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package aclbankmapping - -import ( - "testing" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/cosmos/cosmos-sdk/simapp" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/bank" - "github.com/cosmos/cosmos-sdk/x/bank/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - aclutils "github.com/sei-protocol/sei-chain/aclmapping/utils" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" - "github.com/stretchr/testify/require" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" -) - - -func cacheTxContext(ctx sdk.Context) (sdk.Context, sdk.CacheMultiStore) { - ms := ctx.MultiStore() - msCache := ms.CacheMultiStore() - return ctx.WithMultiStore(msCache), msCache -} - -func TestMsgBankSendAclOps(t *testing.T) { - priv1 := secp256k1.GenPrivKey() - addr1 := sdk.AccAddress(priv1.PubKey().Address()) - priv2 := secp256k1.GenPrivKey() - addr2 := sdk.AccAddress(priv2.PubKey().Address()) - coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)} - - tests := []struct { - name string - expectedError error - msg *types.MsgSend - dynamicDep bool - }{ - { - name: "default send", - msg: types.NewMsgSend(addr1, addr2, coins), - expectedError: nil, - dynamicDep: true, - }, - { - name: "dont check synchronous", - msg: types.NewMsgSend(addr1, addr2, coins), - expectedError: nil, - dynamicDep: false, - }, - } - - acc1 := &authtypes.BaseAccount{ - Address: addr1.String(), - } - acc2 := &authtypes.BaseAccount{ - Address: addr2.String(), - } - accs := authtypes.GenesisAccounts{acc1, acc2} - balances := []types.Balance{ - { - Address: addr1.String(), - Coins: coins, - }, - { - Address: addr2.String(), - Coins: coins, - }, - } - - app := simapp.SetupWithGenesisAccounts(accs, balances...) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - handler := bank.NewHandler(app.BankKeeper) - msgValidator := sdkacltypes.NewMsgValidator(aclutils.StoreKeyToResourceTypePrefixMap) - ctx = ctx.WithMsgValidator(msgValidator) - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - handlerCtx, cms := cacheTxContext(ctx) - - _, err := handler(handlerCtx, tc.msg) - - depdenencies , _ := MsgSendDependencyGenerator(app.AccessControlKeeper, handlerCtx, tc.msg) - - if !tc.dynamicDep { - depdenencies = sdkacltypes.SynchronousAccessOps() - } - - if tc.expectedError != nil { - require.EqualError(t, err, tc.expectedError.Error()) - } else { - require.NoError(t, err) - } - missing := handlerCtx.MsgValidator().ValidateAccessOperations(depdenencies, cms.GetEvents()) - require.Empty(t, missing) - }) - } -} - -func TestGeneratorInvalidMessageTypes(t *testing.T) { - accs := authtypes.GenesisAccounts{} - balances := []types.Balance{} - - app := simapp.SetupWithGenesisAccounts(accs, balances...) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - oracleVote := oracletypes.MsgAggregateExchangeRateVote{ - ExchangeRates: "1usei", - Feeder: "test", - Validator: "validator", - } - - _, err := MsgSendDependencyGenerator(app.AccessControlKeeper, ctx, &oracleVote) - require.Error(t, err) -} - -func TestMsgBeginBankSendGenerator(t *testing.T) { - priv1 := secp256k1.GenPrivKey() - addr1 := sdk.AccAddress(priv1.PubKey().Address()) - priv2 := secp256k1.GenPrivKey() - addr2 := sdk.AccAddress(priv2.PubKey().Address()) - coins := sdk.Coins{sdk.NewInt64Coin("foocoin", 10)} - - acc1 := &authtypes.BaseAccount{ - Address: addr1.String(), - } - acc2 := &authtypes.BaseAccount{ - Address: addr2.String(), - } - accs := authtypes.GenesisAccounts{acc1, acc2} - balances := []types.Balance{ - { - Address: addr1.String(), - Coins: coins, - }, - { - Address: addr2.String(), - Coins: coins, - }, - } - - app := simapp.SetupWithGenesisAccounts(accs, balances...) - ctx := app.BaseApp.NewContext(false, tmproto.Header{}) - - sendMsg := banktypes.MsgSend{ - FromAddress: addr1.String(), - ToAddress: addr2.String(), - Amount: coins, - } - - accessOps, err := MsgSendDependencyGenerator(app.AccessControlKeeper, ctx, &sendMsg) - require.NoError(t, err) - err = acltypes.ValidateAccessOps(accessOps) - require.NoError(t, err) -} diff --git a/aclmapping/utils/identifier_templates.go b/aclmapping/utils/identifier_templates.go index ba79cecc2a..2eeea12ea3 100644 --- a/aclmapping/utils/identifier_templates.go +++ b/aclmapping/utils/identifier_templates.go @@ -1,4 +1,4 @@ -package utils +package util import ( "fmt" diff --git a/aclmapping/utils/resource_type.go b/aclmapping/utils/resource_type.go deleted file mode 100644 index bbd421582f..0000000000 --- a/aclmapping/utils/resource_type.go +++ /dev/null @@ -1,51 +0,0 @@ -package utils - -import ( - aclsdktypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - dextypes "github.com/sei-protocol/sei-chain/x/dex/types" - epochtypes "github.com/sei-protocol/sei-chain/x/epoch/types" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" - tokenfactorytypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types" -) - -var StoreKeyToResourceTypePrefixMap = aclsdktypes.StoreKeyToResourceTypePrefixMap{ - aclsdktypes.ParentNodeKey: { - aclsdktypes.ResourceType_ANY: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_KV: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_Mem: aclsdktypes.EmptyPrefix, - }, - dextypes.StoreKey: { - aclsdktypes.ResourceType_KV_DEX: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_DexMem: aclsdktypes.EmptyPrefix, - }, - banktypes.StoreKey: { - aclsdktypes.ResourceType_KV_BANK: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_KV_BANK_BALANCES: banktypes.BalancesPrefix, - aclsdktypes.ResourceType_KV_BANK_SUPPLY: banktypes.SupplyKey, - aclsdktypes.ResourceType_KV_BANK_DENOM: banktypes.DenomMetadataPrefix, - }, - authtypes.StoreKey: { - aclsdktypes.ResourceType_KV_AUTH: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_KV_AUTH_ADDRESS_STORE: authtypes.AddressStoreKeyPrefix, - }, - oracletypes.StoreKey: { - aclsdktypes.ResourceType_KV_ORACLE: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_KV_ORACLE_VOTE_TARGETS: oracletypes.VoteTargetKey, - aclsdktypes.ResourceType_KV_ORACLE_AGGREGATE_VOTES: oracletypes.AggregateExchangeRateVoteKey, - aclsdktypes.ResourceType_KV_ORACLE_FEEDERS: oracletypes.FeederDelegationKey, - }, - stakingtypes.StoreKey: { - aclsdktypes.ResourceType_KV_STAKING: aclsdktypes.EmptyPrefix, - aclsdktypes.ResourceType_KV_STAKING_DELEGATION: stakingtypes.DelegationKey, - aclsdktypes.ResourceType_KV_STAKING_VALIDATOR: stakingtypes.ValidatorsKey, - }, - tokenfactorytypes.StoreKey: { - aclsdktypes.ResourceType_KV_TOKENFACTORY: aclsdktypes.EmptyPrefix, - }, - epochtypes.StoreKey: { - aclsdktypes.ResourceType_KV_EPOCH: aclsdktypes.EmptyPrefix, - }, -} diff --git a/app/app.go b/app/app.go index 831989ae57..add16601b4 100644 --- a/app/app.go +++ b/app/app.go @@ -37,11 +37,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol" aclclient "github.com/cosmos/cosmos-sdk/x/accesscontrol/client" aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" + authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" @@ -1035,13 +1035,11 @@ func (app *App) ProcessTxConcurrent( resultChan chan<- ChannelResult, txCompletionSignalingMap acltypes.MessageCompletionSignalMapping, txBlockingSignalsMap acltypes.MessageCompletionSignalMapping, - txMsgAccessOpMapping acltypes.MsgIndexToAccessOpMapping, ) { defer wg.Done() // Store the Channels in the Context Object for each transaction ctx = ctx.WithTxBlockingChannels(getChannelsFromSignalMapping(txBlockingSignalsMap)) ctx = ctx.WithTxCompletionChannels(getChannelsFromSignalMapping(txCompletionSignalingMap)) - ctx = ctx.WithTxMsgAccessOps(txMsgAccessOpMapping) // Deliver the transaction and store the result in the channel @@ -1054,18 +1052,18 @@ func (app *App) ProcessBlockConcurrent( txs [][]byte, completionSignalingMap map[int]acltypes.MessageCompletionSignalMapping, blockingSignalsMap map[int]acltypes.MessageCompletionSignalMapping, - txMsgAccessOpMapping map[int]acltypes.MsgIndexToAccessOpMapping, -) ([]*abci.ExecTxResult, bool) { +) []*abci.ExecTxResult { defer metrics.BlockProcessLatency(time.Now(), metrics.CONCURRENT) + var waitGroup sync.WaitGroup + resultChan := make(chan ChannelResult) txResults := []*abci.ExecTxResult{} + // If there's no transactions then return empty results if len(txs) == 0 { - return txResults, true + return txResults } - var waitGroup sync.WaitGroup - resultChan := make(chan ChannelResult) // For each transaction, start goroutine and deliver TX for txIndex, txBytes := range txs { waitGroup.Add(1) @@ -1077,7 +1075,6 @@ func (app *App) ProcessBlockConcurrent( resultChan, completionSignalingMap[txIndex], blockingSignalsMap[txIndex], - txMsgAccessOpMapping[txIndex], ) } @@ -1101,16 +1098,7 @@ func (app *App) ProcessBlockConcurrent( txResults = append(txResults, txResultsMap[txIndex]) } - ok := true - for i, result := range txResults { - if result.GetCode() == sdkerrors.ErrInvalidConcurrencyExecution.ABCICode() { - ctx.Logger().Error(fmt.Sprintf("Invalid concurrent execution of deliverTx index=%d", i)) - metrics.IncrFailedConcurrentDeliverTxCounter() - ok = false - } - } - - return txResults, ok + return txResults } func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequest, lastCommit abci.CommitInfo) ([]abci.Event, []*abci.ExecTxResult, abci.ResponseEndBlock, error) { @@ -1166,24 +1154,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ // CacheMultiStore where it writes the data to the parent store (DeliverState) in sorted Key order to maintain // deterministic ordering between validators in the case of concurrent deliverTXs processBlockCtx, processBlockCache := app.CacheContext(ctx) - concurrentResults, ok := app.ProcessBlockConcurrent( - processBlockCtx, - txs, - dependencyDag.CompletionSignalingMap, - dependencyDag.BlockingSignalsMap, - dependencyDag.TxMsgAccessOpMapping, - ) - if ok { - ctx.Logger().Info("Concurrent Execution succeeded, proceeding to commit block") - txResults = concurrentResults - // Write the results back to the concurrent contexts - if concurrent execution fails, - // this should not be called and the state is rolled back and retried with synchronous execution - processBlockCache.Write() - } else { - ctx.Logger().Error("Concurrent Execution failed, retrying with Synchronous") - txResults = app.ProcessBlockSynchronous(ctx, txs) - } - + txResults = app.ProcessBlockConcurrent(processBlockCtx, txs, dependencyDag.CompletionSignalingMap, dependencyDag.BlockingSignalsMap) // Write the results back to the concurrent contexts processBlockCache.Write() case acltypes.ErrGovMsgInBlock: diff --git a/go.mod b/go.mod index c16e1b98cc..f1587068e7 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.239 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.200 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 diff --git a/go.sum b/go.sum index b48804bb2f..d143650f98 100644 --- a/go.sum +++ b/go.sum @@ -1099,8 +1099,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.239 h1:IuWt2PVB6kDVA7NHBRp5BGwgjw1Lg4dJT91yb4VmEZI= -github.com/sei-protocol/sei-cosmos v0.1.239/go.mod h1:c2dhT0+W9l83qjFJrQ6CcjhtHwHOoha5K1rtt4LeDBU= +github.com/sei-protocol/sei-cosmos v0.1.200 h1:EbHDzt0aAASO7fy8Dac04lLzm0xhF1O1ILiA+UD3w98= +github.com/sei-protocol/sei-cosmos v0.1.200/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= diff --git a/store/testutils.go b/store/testutils.go index 2a3efaac33..7a710bc745 100644 --- a/store/testutils.go +++ b/store/testutils.go @@ -11,7 +11,7 @@ import ( func NewTestKVStore() types.KVStore { mem := dbadapter.Store{DB: dbm.NewMemDB()} - return cachekv.NewStore(mem, storetypes.NewKVStoreKey("testStoreKey")) + return cachekv.NewStore(mem) } func NewTestCacheMultiStore(stores map[types.StoreKey]types.CacheWrapper) types.CacheMultiStore { diff --git a/utils/metrics/metrics_util.go b/utils/metrics/metrics_util.go index ec5ed3a0cb..6322357960 100644 --- a/utils/metrics/metrics_util.go +++ b/utils/metrics/metrics_util.go @@ -80,18 +80,6 @@ func IncrDagBuildErrorCounter(reason string) { ) } -// Counts the number of concurrent transactions that failed -// Metric Names: -// -// sei_tx_concurrent_delivertx_error -func IncrFailedConcurrentDeliverTxCounter() { - metrics.IncrCounterWithLabels( - []string{"sei", "tx", "concurrent", "delievertx", "error"}, - 1, - []metrics.Label{}, - ) -} - // Measures the time taken to execute a sudo msg // Metric Names: // diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index 3988c4b164..2028e73625 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -65,7 +65,7 @@ func WeightedOperations( } // 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, @@ -122,7 +122,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, From 14fc67ea12f0c98a642f396681e84ecc687ca2d8 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 10/41] Revert "Add concurrency for BurnMsg and MintMsg (#331)" This reverts commit 4a5cff06222592e53efdb3cc9a937cc2e5a23d15. --- aclmapping/dependency_generator.go | 10 +- aclmapping/tokenfactory/mappings.go | 152 ------------------ aclmapping/utils/identifier_templates.go | 1 - loadtest/config.json | 2 +- loadtest/scripts/metrics.py | 2 +- loadtest/scripts/populate_genesis_accounts.py | 21 ++- scripts/old_initialize_local.sh | 66 ++++---- x/mint/types/expected_keepers.go | 2 - x/oracle/keeper/test_utils.go | 0 x/tokenfactory/keeper/bankactions.go | 14 +- x/tokenfactory/types/expected_keepers.go | 6 - 11 files changed, 54 insertions(+), 222 deletions(-) delete mode 100644 aclmapping/tokenfactory/mappings.go mode change 100644 => 100755 x/oracle/keeper/test_utils.go diff --git a/aclmapping/dependency_generator.go b/aclmapping/dependency_generator.go index 3b276cdaf4..beec9783a8 100644 --- a/aclmapping/dependency_generator.go +++ b/aclmapping/dependency_generator.go @@ -4,7 +4,6 @@ import ( aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" aclbankmapping "github.com/sei-protocol/sei-chain/aclmapping/bank" acldexmapping "github.com/sei-protocol/sei-chain/aclmapping/dex" - acltokenfactorymapping "github.com/sei-protocol/sei-chain/aclmapping/tokenfactory" aclwasmmapping "github.com/sei-protocol/sei-chain/aclmapping/wasm" ) @@ -16,12 +15,11 @@ func NewCustomDependencyGenerator() CustomDependencyGenerator { func (customDepGen CustomDependencyGenerator) GetCustomDependencyGenerators() aclkeeper.DependencyGeneratorMap { dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - wasmDependencyGenerators := aclwasmmapping.NewWasmDependencyGenerator() - dependencyGeneratorMap = dependencyGeneratorMap.Merge(acldexmapping.GetDexDependencyGenerators()) - dependencyGeneratorMap = dependencyGeneratorMap.Merge(aclbankmapping.GetBankDepedencyGenerator()) - dependencyGeneratorMap = dependencyGeneratorMap.Merge(acltokenfactorymapping.GetTokenFactoryDependencyGenerators()) - dependencyGeneratorMap = dependencyGeneratorMap.Merge(wasmDependencyGenerators.GetWasmDependencyGenerators()) + dependencyGeneratorMap.Merge(acldexmapping.GetDexDependencyGenerators()) + dependencyGeneratorMap.Merge(aclbankmapping.GetBankDepedencyGenerator()) + wasmDependencyGenerators := aclwasmmapping.NewWasmDependencyGenerator() + dependencyGeneratorMap.Merge(wasmDependencyGenerators.GetWasmDependencyGenerators()) return dependencyGeneratorMap } diff --git a/aclmapping/tokenfactory/mappings.go b/aclmapping/tokenfactory/mappings.go deleted file mode 100644 index 0eda913365..0000000000 --- a/aclmapping/tokenfactory/mappings.go +++ /dev/null @@ -1,152 +0,0 @@ -package aclTokenFactorymapping - -import ( - "fmt" - - 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" - utils "github.com/sei-protocol/sei-chain/aclmapping/utils" - tokenfactorymoduletypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types" -) - -var ErrInvalidMessageType = fmt.Errorf("invalid message received for TokenFactory Module") - -func GetTokenFactoryDependencyGenerators() aclkeeper.DependencyGeneratorMap { - dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - MintMsgKey := acltypes.GenerateMessageKey(&tokenfactorymoduletypes.MsgMint{}) - dependencyGeneratorMap[MintMsgKey] = TokenFactoryMintDependencyGenerator - - BurnMsgKey := acltypes.GenerateMessageKey(&tokenfactorymoduletypes.MsgBurn{}) - dependencyGeneratorMap[BurnMsgKey] = TokenFactoryBurnDependencyGenerator - - return dependencyGeneratorMap -} - -func TokenFactoryMintDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - mintMsg, ok := msg.(*tokenfactorymoduletypes.MsgMint) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrInvalidMessageType - } - - denom := mintMsg.GetAmount().Denom - return []sdkacltypes.AccessOperation{ - // Reads denom data From BankKeeper - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: denom, - }, - - // Gets Authoritity data related to the denom - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.TOKENFACTORY, denom), - }, - - // Gets Module Account information - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, tokenfactorymoduletypes.ModuleName), - }, - - // Sends coins to module account - deferred deposit - - // Updates Supply of the denom - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetPrefixedIdentifierTemplatePerModule(utils.BANK, "supply", denom), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetPrefixedIdentifierTemplatePerModule(utils.BANK, "supply", denom), - }, - - // Sends coins to the msgSender from the Module Account (deferred withdrawal) - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, mintMsg.Sender), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, mintMsg.Sender), - }, - }, nil -} - -func TokenFactoryBurnDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - burnMsg, ok := msg.(*tokenfactorymoduletypes.MsgBurn) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrInvalidMessageType - } - - denom := burnMsg.GetAmount().Denom - return []sdkacltypes.AccessOperation{ - // Reads denom data From BankKeeper - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: denom, - }, - - // Gets Authoritity data related to the denom - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_TOKENFACTORY, - IdentifierTemplate: denom, - }, - - // Gets Module Account information - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, tokenfactorymoduletypes.ModuleName), - }, - - // Sends from Sender to Module account (deferred deposit) - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, burnMsg.Sender), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, burnMsg.Sender), - }, - - // Sends coins to the msgSender - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, burnMsg.Sender), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, burnMsg.Sender), - }, - - // Coins removed from Module account (Deferred) - - // Updates Supply of the denom - they should be under the supply prefix - this should always be - // synchronous - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule("supply", denom), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule("supply", denom), - }, - }, nil -} diff --git a/aclmapping/utils/identifier_templates.go b/aclmapping/utils/identifier_templates.go index 2eeea12ea3..f8297e628f 100644 --- a/aclmapping/utils/identifier_templates.go +++ b/aclmapping/utils/identifier_templates.go @@ -12,7 +12,6 @@ const ( BANK = "bank" AUTH = "auth" STAKING = "staking" - TOKENFACTORY = "tokenfactory" DefaultIDTemplate = "*" ) diff --git a/loadtest/config.json b/loadtest/config.json index e492b672ed..73f977931e 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -1,7 +1,7 @@ { "msgs_per_tx": 10, "chain_id": "sei-loadtest-testnet", - "orders_per_block": 400, + "txs_per_block": 400, "rounds": 5, "price_distribution": { "min": "45", diff --git a/loadtest/scripts/metrics.py b/loadtest/scripts/metrics.py index d59c90e0de..e698a930e8 100644 --- a/loadtest/scripts/metrics.py +++ b/loadtest/scripts/metrics.py @@ -47,7 +47,7 @@ def get_metrics(): 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, diff --git a/loadtest/scripts/populate_genesis_accounts.py b/loadtest/scripts/populate_genesis_accounts.py index 7255829242..dc63b713dc 100644 --- a/loadtest/scripts/populate_genesis_accounts.py +++ b/loadtest/scripts/populate_genesis_accounts.py @@ -5,14 +5,11 @@ import threading import time -from pathlib import Path - PARALLEISM=32 # Global Variable used for accounts # Does not need to be thread safe, each thread should only be writing to its own index global_accounts_mapping = {} -home_path = os.path.expanduser('~') def add_key(account_name, local=False): if local: @@ -37,6 +34,7 @@ def add_account(account_name, address, mnemonic, local=False): else: add_account_cmd = f"printf '12345678\n' | ~/go/bin/seid add-genesis-account {address} 1000000000usei" + home_path = os.path.expanduser('~') filename = f"{home_path}/test_accounts/{account_name}.json" os.makedirs(os.path.dirname(filename), exist_ok=True) with open(filename, 'w') as f: @@ -70,10 +68,10 @@ def create_genesis_account(account_index, account_name, local=False): retry_counter += 1 sleep_time += 0.5 time.sleep(sleep_time) - + if retry_counter >= 1000: exit(-1) - + global_accounts_mapping[account_index] = { "balance": { "address": address, @@ -122,14 +120,14 @@ def bulk_create_genesis_accounts(number_of_accounts, start_idx, is_local=False): print(f"Created account {i}") -def read_genesis_file(genesis_json_file_path): - with open(genesis_json_file_path, 'r') as f: +def read_genesis_file(): + with open("/root/.sei/config/genesis.json", 'r') as f: return json.load(f) -def write_genesis_file(genesis_json_file_path, data): +def write_genesis_file(data): print("Writing results to genesis file") - with open(genesis_json_file_path, 'w') as f: + with open("/root/.sei/config/genesis.json", 'w') as f: json.dump(data, f, indent=4) @@ -140,8 +138,7 @@ def main(): if len(args) > 1 and args[1] == "loc": is_local = True - genesis_json_file_path = f"{home_path}/.sei/config/genesis.json" - genesis_file = read_genesis_file(genesis_json_file_path) + genesis_file = read_genesis_file() num_threads = number_of_accounts // PARALLEISM threads = [] @@ -170,7 +167,7 @@ def main(): print(f'Created {num_accounts_created} accounts') assert num_accounts_created >= number_of_accounts - write_genesis_file(genesis_json_file_path, genesis_file) + write_genesis_file(genesis_file) if __name__ == "__main__": main() diff --git a/scripts/old_initialize_local.sh b/scripts/old_initialize_local.sh index 5047163db0..a5d2352308 100644 --- a/scripts/old_initialize_local.sh +++ b/scripts/old_initialize_local.sh @@ -1,44 +1,48 @@ - - #!/bin/bash -keyname=admin -#docker stop jaeger -#docker rm jaeger -#docker run -d --name jaeger \ -# -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ -# -p 5775:5775/udp \ -# -p 6831:6831/udp \ -# -p 6832:6832/udp \ -# -p 5778:5778 \ -# -p 16686:16686 \ -# -p 14250:14250 \ -# -p 14268:14268 \ -# -p 14269:14269 \ -# -p 9411:9411 \ -# jaegertracing/all-in-one:1.33 +echo -n OS Password: +read -s password +echo +echo -n Key Name: +read keyname +echo +echo -n Number of Test Accounts: +read numtestaccount +echo + +docker stop jaeger +docker rm jaeger +docker run -d --name jaeger \ + -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ + -p 5775:5775/udp \ + -p 6831:6831/udp \ + -p 6832:6832/udp \ + -p 5778:5778 \ + -p 16686:16686 \ + -p 14250:14250 \ + -p 14268:14268 \ + -p 14269:14269 \ + -p 9411:9411 \ + jaegertracing/all-in-one:1.33 -rm -rf ~/.sei echo "Building..." make install -#echo $password | sudo -S rm -r ~/.sei/ -#echo $password | sudo -S rm -r ~/test_accounts/ +echo $password | sudo -S rm -r ~/.sei/ +echo $password | sudo -S rm -r ~/test_accounts/ ~/go/bin/seid init demo --chain-id sei-chain -~/go/bin/seid keys add $keyname --keyring-backend test -#yes | ~/go/bin/seid keys add faucet -~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show $keyname -a --keyring-backend test) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom -~/go/bin/seid gentx $keyname 70000000000000000000usei --chain-id sei-chain --keyring-backend test -sed -i '' 's/mode = "full"/mode = "validator"/g' $HOME/.sei/config/config.toml -sed -i '' 's/indexer = \["null"\]/indexer = \["kv"\]/g' $HOME/.sei/config/config.toml +yes | ~/go/bin/seid keys add $keyname +yes | ~/go/bin/seid keys add faucet +printf '12345678\n' | ~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show $keyname -a) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom +printf '12345678\n' | ~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show faucet -a) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom +python3 ./loadtest/scripts/populate_genesis_accounts.py $numtestaccount loc +printf '12345678\n' | ~/go/bin/seid gentx $keyname 70000000000000000000usei --chain-id sei-chain +sed -i 's/mode = "full"/mode = "validator"/g' $HOME/.sei/config/config.toml +sed -i 's/indexer = \["null"\]/indexer = \["kv"\]/g' $HOME/.sei/config/config.toml KEY=$(jq '.pub_key' ~/.sei/config/priv_validator_key.json -c) jq '.validators = [{}]' ~/.sei/config/genesis.json > ~/.sei/config/tmp_genesis.json jq '.validators[0] += {"power":"70000000000000"}' ~/.sei/config/tmp_genesis.json > ~/.sei/config/tmp_genesis_2.json jq '.validators[0] += {"pub_key":'$KEY'}' ~/.sei/config/tmp_genesis_2.json > ~/.sei/config/tmp_genesis_3.json mv ~/.sei/config/tmp_genesis_3.json ~/.sei/config/genesis.json && rm ~/.sei/config/tmp_genesis.json && rm ~/.sei/config/tmp_genesis_2.json - -echo "Creating Accounts" -python3 loadtest/scripts/populate_genesis_accounts.py 50 loc - ~/go/bin/seid collect-gentxs cat ~/.sei/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="usei"' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json cat ~/.sei/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="usei"' > ~/.sei/config/tmp_genesis.json && mv ~/.sei/config/tmp_genesis.json ~/.sei/config/genesis.json @@ -77,4 +81,4 @@ else fi # start the chain with log tracing -GORACE="log_path=/tmp/race/seid_race" ~/go/bin/seid start --trace --chain-id sei-chain +GORACE="log_path=/tmp/race/seid_race" ~/go/bin/seid start --trace --chain-id sei-chain \ No newline at end of file diff --git a/x/mint/types/expected_keepers.go b/x/mint/types/expected_keepers.go index da49ab11b2..4ce2e3a31e 100644 --- a/x/mint/types/expected_keepers.go +++ b/x/mint/types/expected_keepers.go @@ -27,8 +27,6 @@ type BankKeeper interface { SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error MintCoins(ctx sdk.Context, name string, amt sdk.Coins) error - DeferredMintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error - DeferredBurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error } // EpochKeeper defines the contract needed to be fulfilled for epoch keepers diff --git a/x/oracle/keeper/test_utils.go b/x/oracle/keeper/test_utils.go old mode 100644 new mode 100755 diff --git a/x/tokenfactory/keeper/bankactions.go b/x/tokenfactory/keeper/bankactions.go index a052db180a..853c517ef8 100644 --- a/x/tokenfactory/keeper/bankactions.go +++ b/x/tokenfactory/keeper/bankactions.go @@ -1,8 +1,6 @@ package keeper import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sei-protocol/sei-chain/x/tokenfactory/types" @@ -15,8 +13,7 @@ func (k Keeper) mintTo(ctx sdk.Context, amount sdk.Coin, mintTo string) error { return err } - ctx.Logger().Info(fmt.Sprintf("Minting amount=%s for module=%s", amount.String(), types.ModuleName)) - err = k.bankKeeper.DeferredMintCoins(ctx, types.ModuleName, sdk.NewCoins(amount)) + err = k.bankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(amount)) if err != nil { return err } @@ -26,8 +23,7 @@ func (k Keeper) mintTo(ctx sdk.Context, amount sdk.Coin, mintTo string) error { return err } - ctx.Logger().Info(fmt.Sprintf("Sending Minted amount=%s to addr=%s", amount.String(), addr.String())) - return k.bankKeeper.DeferredSendCoinsFromModuleToAccount(ctx, types.ModuleName, + return k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, sdk.NewCoins(amount)) } @@ -44,8 +40,7 @@ func (k Keeper) burnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom string) erro return err } - ctx.Logger().Info(fmt.Sprintf("Sending amount=%s to module=%s from account=%s", amount.String(), types.ModuleName, addr.String())) - err = k.bankKeeper.DeferredSendCoinsFromAccountToModule(ctx, + err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, sdk.NewCoins(amount)) @@ -53,8 +48,7 @@ func (k Keeper) burnFrom(ctx sdk.Context, amount sdk.Coin, burnFrom string) erro return err } - ctx.Logger().Info(fmt.Sprintf("Burning amount=%s from module=%s", amount.String(), types.ModuleName)) - return k.bankKeeper.DeferredBurnCoins(ctx, types.ModuleName, sdk.NewCoins(amount)) + return k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(amount)) } // func (k Keeper) forceTransfer(ctx sdk.Context, amount sdk.Coin, fromAddr string, toAddr string) error { diff --git a/x/tokenfactory/types/expected_keepers.go b/x/tokenfactory/types/expected_keepers.go index 3b4e3c9e0a..1f750fd8d3 100644 --- a/x/tokenfactory/types/expected_keepers.go +++ b/x/tokenfactory/types/expected_keepers.go @@ -15,12 +15,6 @@ type BankKeeper interface { SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - - DeferredSendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amount sdk.Coins) error - DeferredSendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error - DeferredMintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error - DeferredBurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error - DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error UndelegateCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error From 90364498d4ab433206ff8d72bf7cb943e72e231c Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 11/41] Revert "Ezhu/granularize staking resources (#343)" This reverts commit 90e288c30eb970df7a2b85848c22e3e830496974. --- aclmapping/oracle/mappings.go | 2 +- aclmapping/staking/mappings.go | 60 +++++++++---------- aclmapping/staking/mappings_test.go | 93 ----------------------------- go.mod | 2 +- go.sum | 4 +- loadtest/config.json | 2 +- 6 files changed, 35 insertions(+), 128 deletions(-) delete mode 100644 aclmapping/staking/mappings_test.go diff --git a/aclmapping/oracle/mappings.go b/aclmapping/oracle/mappings.go index 84517eee09..adce4da9b4 100644 --- a/aclmapping/oracle/mappings.go +++ b/aclmapping/oracle/mappings.go @@ -41,7 +41,7 @@ func MsgVoteDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sd // validator is bonded check - READ // (both covered by below) { - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV_STAKING, AccessType: sdkacltypes.AccessType_READ, IdentifierTemplate: msgVote.Validator, }, diff --git a/aclmapping/staking/mappings.go b/aclmapping/staking/mappings.go index ed3eb9fc8c..18e8d68223 100644 --- a/aclmapping/staking/mappings.go +++ b/aclmapping/staking/mappings.go @@ -37,48 +37,48 @@ func MsgDelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, ms // Checks if there is a delegation object that already exists for (delegatorAddr, validatorAddr) { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.DelegatorAddress+msgDelegate.ValidatorAddress), }, // Store new delegator for (delegator, validator) { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.DelegatorAddress+msgDelegate.ValidatorAddress), }, // delegate coins from account validator account { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.ValidatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.ValidatorAddress), }, // Checks if the validators exchange rate is valid { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.ValidatorAddress), }, // Update validator shares and power index { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.ValidatorAddress), }, @@ -105,48 +105,48 @@ func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, // Get delegation/redelegations and error checking { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.DelegatorAddress+msgUndelegate.ValidatorAddress), }, // Update/delete delegation and update redelegation { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.DelegatorAddress+msgUndelegate.ValidatorAddress), }, // Update the delegator and validator account balances { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.ValidatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.ValidatorAddress), }, // Checks if the validators exchange rate is valid { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.ValidatorAddress), }, // Update validator shares and power index { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.ValidatorAddress), }, @@ -174,77 +174,77 @@ func MsgBeginRedelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Cont // Get dest delegation to see if it already exists { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorDstAddress), }, // Update/delete src and destination delegation after tokens have been unbonded { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_DELEGATION, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorDstAddress), }, // Update the delegator, src validator and dest validator account balances { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.DelegatorAddress), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorDstAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_BANK, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorDstAddress), }, // Update validators staking shares and power index { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorSrcAddress), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorDstAddress), }, { AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV_STAKING_VALIDATOR, + ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorDstAddress), }, diff --git a/aclmapping/staking/mappings_test.go b/aclmapping/staking/mappings_test.go deleted file mode 100644 index 09efb9dbe9..0000000000 --- a/aclmapping/staking/mappings_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package aclstakingmapping - -import ( - "testing" - "time" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - sdk "github.com/cosmos/cosmos-sdk/types" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/sei-protocol/sei-chain/app" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" - "github.com/stretchr/testify/require" -) - -func TestGeneratorInvalidMessageTypes(t *testing.T) { - tm := time.Now().UTC() - valPub := secp256k1.GenPrivKey().PubKey() - testWrapper := app.NewTestWrapper(t, tm, valPub) - - stakingDelegate := stakingtypes.MsgDelegate{ - DelegatorAddress: "delegator", - ValidatorAddress: "validator", - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, - } - oracleVote := oracletypes.MsgAggregateExchangeRateVote{ - ExchangeRates: "1usei", - Feeder: "test", - Validator: "validator", - } - - _, err := MsgDelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &oracleVote) - require.Error(t, err) - _, err = MsgUndelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingDelegate) - require.Error(t, err) - _, err = MsgBeginRedelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingDelegate) - require.Error(t, err) - -} - -func TestMsgDelegateGenerator(t *testing.T) { - tm := time.Now().UTC() - valPub := secp256k1.GenPrivKey().PubKey() - testWrapper := app.NewTestWrapper(t, tm, valPub) - - stakingDelegate := stakingtypes.MsgDelegate{ - DelegatorAddress: "delegator", - ValidatorAddress: "validator", - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, - } - - accessOps, err := MsgDelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingDelegate) - require.NoError(t, err) - err = acltypes.ValidateAccessOps(accessOps) - require.NoError(t, err) -} - -func TestMsgUndelegateGenerator(t *testing.T) { - tm := time.Now().UTC() - valPub := secp256k1.GenPrivKey().PubKey() - - testWrapper := app.NewTestWrapper(t, tm, valPub) - - stakingUndelegate := stakingtypes.MsgUndelegate{ - DelegatorAddress: "delegator", - ValidatorAddress: "validator", - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, - } - - accessOps, err := MsgUndelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingUndelegate) - require.NoError(t, err) - err = acltypes.ValidateAccessOps(accessOps) - require.NoError(t, err) -} - -func TestMsgBeginRedelegateGenerator(t *testing.T) { - tm := time.Now().UTC() - valPub := secp256k1.GenPrivKey().PubKey() - - testWrapper := app.NewTestWrapper(t, tm, valPub) - - stakingBeginRedelegate := stakingtypes.MsgBeginRedelegate{ - DelegatorAddress: "delegator", - ValidatorSrcAddress: "src_validator", - ValidatorDstAddress: "dst_validator", - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, - } - - accessOps, err := MsgBeginRedelegateDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &stakingBeginRedelegate) - require.NoError(t, err) - err = acltypes.ValidateAccessOps(accessOps) - require.NoError(t, err) -} diff --git a/go.mod b/go.mod index f1587068e7..8b81e8e1bd 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.200 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.199 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 diff --git a/go.sum b/go.sum index d143650f98..72feba1457 100644 --- a/go.sum +++ b/go.sum @@ -1099,8 +1099,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.200 h1:EbHDzt0aAASO7fy8Dac04lLzm0xhF1O1ILiA+UD3w98= -github.com/sei-protocol/sei-cosmos v0.1.200/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0= +github.com/sei-protocol/sei-cosmos v0.1.199 h1:p+kqO95BjKycKJcL+nPBib+nrygutYtV9/nimI4cCVs= +github.com/sei-protocol/sei-cosmos v0.1.199/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= diff --git a/loadtest/config.json b/loadtest/config.json index 73f977931e..ddbc7b6805 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -25,7 +25,7 @@ } }, "message_type": "bank,dex,staking,tokenfactory", - "run_oracle": false, + "run_oracle": true, "contract_distribution": [ { "contract_address":"sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m", From d982c9ae3acee86b5786ac8c66d944f62438e325 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 12/41] Revert "Oracle parallel (#334)" This reverts commit 67c0db3c0d92a3edb707eb2a8e9d651de5a7113a. --- Makefile | 54 +++++++++---------- aclmapping/oracle/mappings.go | 69 ------------------------ aclmapping/oracle/mappings_test.go | 30 ----------- aclmapping/utils/identifier_templates.go | 8 +-- app/antedecorators/gasless.go | 3 +- go.mod | 2 +- go.sum | 4 +- loadtest/config.json | 1 - loadtest/loadtest_client.go | 26 --------- loadtest/main.go | 12 ----- loadtest/sign.go | 40 -------------- loadtest/types.go | 1 - x/oracle/ante.go | 1 - 13 files changed, 33 insertions(+), 218 deletions(-) delete mode 100644 aclmapping/oracle/mappings.go delete mode 100644 aclmapping/oracle/mappings_test.go diff --git a/Makefile b/Makefile index 8a82afa15e..c43b83294c 100644 --- a/Makefile +++ b/Makefile @@ -10,26 +10,26 @@ export GO111MODULE = on LEDGER_ENABLED ?= true build_tags = netgo ifeq ($(LEDGER_ENABLED),true) - ifeq ($(OS),Windows_NT) - GCCEXE = $(shell where gcc.exe 2> NUL) - ifeq ($(GCCEXE),) - $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) - else - build_tags += ledger - endif - else - UNAME_S = $(shell uname -s) - ifeq ($(UNAME_S),OpenBSD) - $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) - else - GCC = $(shell command -v gcc 2> /dev/null) - ifeq ($(GCC),) - $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) - else - build_tags += ledger - endif - endif - endif + ifeq ($(OS),Windows_NT) + GCCEXE = $(shell where gcc.exe 2> NUL) + ifeq ($(GCCEXE),) + $(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false) + else + build_tags += ledger + endif + else + UNAME_S = $(shell uname -s) + ifeq ($(UNAME_S),OpenBSD) + $(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988)) + else + GCC = $(shell command -v gcc 2> /dev/null) + ifeq ($(GCC),) + $(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false) + else + build_tags += ledger + endif + endif + endif endif build_tags += $(BUILD_TAGS) @@ -43,13 +43,13 @@ build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags)) # process linker flags ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=sei \ - -X github.com/cosmos/cosmos-sdk/version.ServerName=seid \ - -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ - -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ - -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" + -X github.com/cosmos/cosmos-sdk/version.ServerName=seid \ + -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ + -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ + -X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" ifeq ($(LINK_STATICALLY),true) - ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static" + ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static" endif ldflags += $(LDFLAGS) ldflags := $(strip $(ldflags)) @@ -64,10 +64,6 @@ all: lint install install: go.sum go install $(BUILD_FLAGS) ./cmd/seid -loadtest: go.sum - go build $(BUILD_FLAGS) -o ./build/loadtest ./loadtest/ - - go.sum: go.mod @echo "--> Ensure dependencies have not been modified" @go mod verify diff --git a/aclmapping/oracle/mappings.go b/aclmapping/oracle/mappings.go deleted file mode 100644 index adce4da9b4..0000000000 --- a/aclmapping/oracle/mappings.go +++ /dev/null @@ -1,69 +0,0 @@ -package acloraclemapping - -import ( - "fmt" - - 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" - utils "github.com/sei-protocol/sei-chain/aclmapping/utils" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" -) - -var ErrorInvalidMsgType = fmt.Errorf("invalid message received for oracle module") - -func GetOracleDependencyGenerator() aclkeeper.DependencyGeneratorMap { - dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - - // vote - voteKey := acltypes.GenerateMessageKey(&oracletypes.MsgAggregateExchangeRateVote{}) - dependencyGeneratorMap[voteKey] = MsgVoteDependencyGenerator - - return dependencyGeneratorMap -} - -func MsgVoteDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - msgVote, ok := msg.(*oracletypes.MsgAggregateExchangeRateVote) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType - } - - accessOperations := []sdkacltypes.AccessOperation{ - // validate feeder - // read feeder delegation for val addr - READ - { - ResourceType: sdkacltypes.ResourceType_KV_ORACLE_FEEDERS, - AccessType: sdkacltypes.AccessType_READ, - IdentifierTemplate: msgVote.Validator, - }, - // read validator from staking - READ - // validator is bonded check - READ - // (both covered by below) - { - ResourceType: sdkacltypes.ResourceType_KV_STAKING, - AccessType: sdkacltypes.AccessType_READ, - IdentifierTemplate: msgVote.Validator, - }, - // get vote target (for all exchange rate tuples) -> blanket read on that prefix - READ - { - ResourceType: sdkacltypes.ResourceType_KV_ORACLE_VOTE_TARGETS, - AccessType: sdkacltypes.AccessType_READ, - IdentifierTemplate: utils.DefaultIDTemplate, - }, - - // set exchange rate vote - WRITE - { - ResourceType: sdkacltypes.ResourceType_KV_ORACLE_AGGREGATE_VOTES, - AccessType: sdkacltypes.AccessType_READ, - IdentifierTemplate: msgVote.Validator, - }, - // Last Operation should always be a commit - { - ResourceType: sdkacltypes.ResourceType_ANY, - AccessType: sdkacltypes.AccessType_COMMIT, - IdentifierTemplate: utils.DefaultIDTemplate, - }, - } - return accessOperations, nil -} diff --git a/aclmapping/oracle/mappings_test.go b/aclmapping/oracle/mappings_test.go deleted file mode 100644 index 0e7a6d29de..0000000000 --- a/aclmapping/oracle/mappings_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package acloraclemapping - -import ( - "testing" - "time" - - "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - "github.com/sei-protocol/sei-chain/app" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" - "github.com/stretchr/testify/require" -) - -func TestMsgVoteDependencyGenerator(t *testing.T) { - tm := time.Now().UTC() - valPub := secp256k1.GenPrivKey().PubKey() - - testWrapper := app.NewTestWrapper(t, tm, valPub) - - oracleVote := oracletypes.MsgAggregateExchangeRateVote{ - ExchangeRates: "1usei", - Feeder: "test", - Validator: "validator", - } - - accessOps, err := MsgVoteDependencyGenerator(testWrapper.App.AccessControlKeeper, testWrapper.Ctx, &oracleVote) - require.NoError(t, err) - err = acltypes.ValidateAccessOps(accessOps) - require.NoError(t, err) -} diff --git a/aclmapping/utils/identifier_templates.go b/aclmapping/utils/identifier_templates.go index f8297e628f..3098e33742 100644 --- a/aclmapping/utils/identifier_templates.go +++ b/aclmapping/utils/identifier_templates.go @@ -27,13 +27,13 @@ func GetOracleReadAccessOpsForValAndFeeder(feederAddr sdk.Address, valAddr sdk.A return []sdkacltypes.AccessOperation{ { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_ORACLE, - IdentifierTemplate: feederAddr.String(), + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: GetIdentifierTemplatePerModule("oracle", feederAddr.String()), }, { AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV_ORACLE, - IdentifierTemplate: valAddr.String(), + ResourceType: sdkacltypes.ResourceType_KV, + IdentifierTemplate: GetIdentifierTemplatePerModule("oracle", valAddr.String()), }, } } diff --git a/app/antedecorators/gasless.go b/app/antedecorators/gasless.go index 17591d0069..b4de31d13d 100644 --- a/app/antedecorators/gasless.go +++ b/app/antedecorators/gasless.go @@ -55,8 +55,7 @@ func (gd GaslessDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sdk 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 + // TODO: add tx gasless deps for nitro for nitrokeeper read default: continue } diff --git a/go.mod b/go.mod index 8b81e8e1bd..0012f55e9c 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.199 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.192 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 diff --git a/go.sum b/go.sum index 72feba1457..f65a89ab41 100644 --- a/go.sum +++ b/go.sum @@ -1099,8 +1099,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.199 h1:p+kqO95BjKycKJcL+nPBib+nrygutYtV9/nimI4cCVs= -github.com/sei-protocol/sei-cosmos v0.1.199/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0= +github.com/sei-protocol/sei-cosmos v0.1.192 h1:qrrzr2qHrj7zMDmU7KizOjlXm2uLROUtz8ogEYSxfSE= +github.com/sei-protocol/sei-cosmos v0.1.192/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= diff --git a/loadtest/config.json b/loadtest/config.json index ddbc7b6805..9bb560111c 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -25,7 +25,6 @@ } }, "message_type": "bank,dex,staking,tokenfactory", - "run_oracle": true, "contract_distribution": [ { "contract_address":"sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m", diff --git a/loadtest/loadtest_client.go b/loadtest/loadtest_client.go index 64e2dbcac5..f3c34d63cd 100644 --- a/loadtest/loadtest_client.go +++ b/loadtest/loadtest_client.go @@ -10,7 +10,6 @@ import ( "sync" "time" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" typestx "github.com/cosmos/cosmos-sdk/types/tx" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "google.golang.org/grpc" @@ -117,8 +116,6 @@ func (c *LoadTestClient) BuildTxs() (workgroups []*sync.WaitGroup, sendersList [ } } - valKeys := c.SignerClient.GetValKeys() - for i := 0; i < int(config.Rounds); i++ { fmt.Printf("Preparing %d-th round\n", i) @@ -149,8 +146,6 @@ func (c *LoadTestClient) BuildTxs() (workgroups []*sync.WaitGroup, sendersList [ }) } - senders = append(senders, c.GenerateOracleSenders(i, config, valKeys, wg)...) - sendersList = append(sendersList, senders) inactiveAccounts, activeAccounts = activeAccounts, inactiveAccounts } @@ -158,27 +153,6 @@ func (c *LoadTestClient) BuildTxs() (workgroups []*sync.WaitGroup, sendersList [ return workgroups, sendersList } -func (c *LoadTestClient) GenerateOracleSenders(i int, config Config, valKeys []cryptotypes.PrivKey, waitGroup *sync.WaitGroup) []func() string { - senders := []func() string{} - if config.RunOracle && i%2 == 0 { - for _, valKey := range valKeys { - // generate oracle tx - msg := generateOracleMessage(valKey) - txBuilder := TestConfig.TxConfig.NewTxBuilder() - _ = txBuilder.SetMsgs(msg) - seqDelta := uint64(i / 2) - mode := typestx.BroadcastMode_BROADCAST_MODE_SYNC - sender := SendTx(valKey, &txBuilder, mode, seqDelta, false, *c) - waitGroup.Add(1) - senders = append(senders, func() string { - defer waitGroup.Done() - return sender() - }) - } - } - return senders -} - func (c *LoadTestClient) SendTxs(workgroups []*sync.WaitGroup, sendersList [][]func() string) { lastHeight := getLastHeight() for i := 0; i < int(c.LoadTestConfig.Rounds); i++ { diff --git a/loadtest/main.go b/loadtest/main.go index cfeacbc6d6..a3f3656f04 100644 --- a/loadtest/main.go +++ b/loadtest/main.go @@ -23,7 +23,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/sei-protocol/sei-chain/app" dextypes "github.com/sei-protocol/sei-chain/x/dex/types" - oracletypes "github.com/sei-protocol/sei-chain/x/oracle/types" ) var TestConfig EncodingConfig @@ -270,17 +269,6 @@ func generateDexOrderPlacements(config Config, key cryptotypes.PrivKey, batchSiz return orderPlacements } -func generateOracleMessage(key cryptotypes.PrivKey) sdk.Msg { - valAddr := sdk.ValAddress(key.PubKey().Address()).String() - addr := sdk.AccAddress(key.PubKey().Address()).String() - msg := &oracletypes.MsgAggregateExchangeRateVote{ - ExchangeRates: "1usei,2uatom", - Feeder: addr, - Validator: valAddr, - } - return msg -} - func getLastHeight() int { out, err := exec.Command("curl", "http://localhost:26657/blockchain").Output() if err != nil { diff --git a/loadtest/sign.go b/loadtest/sign.go index 882b5f1f5c..b27bf53d26 100644 --- a/loadtest/sign.go +++ b/loadtest/sign.go @@ -11,11 +11,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" clienttx "github.com/cosmos/cosmos-sdk/client/tx" - "github.com/cosmos/cosmos-sdk/codec/legacy" - "github.com/cosmos/cosmos-sdk/crypto" "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/cosmos/cosmos-sdk/crypto/keys/sr25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx/signing" @@ -95,43 +92,6 @@ func (sc *SignerClient) GetKey(accountIdx uint64) cryptotypes.PrivKey { return privKey } -func (sc *SignerClient) GetValKeys() []cryptotypes.PrivKey { - valKeys := []cryptotypes.PrivKey{} - userHomeDir, _ := os.UserHomeDir() - valKeysFilePath := filepath.Join(userHomeDir, "exported_keys") - files, _ := os.ReadDir(valKeysFilePath) - for _, fn := range files { - // we dont expect subdirectories, so we can just handle files - valKeyFile := filepath.Join(valKeysFilePath, fn.Name()) - privKeyBz, err := os.ReadFile(valKeyFile) - if err != nil { - panic(err) - } - - privKeyBytes, algo, err := crypto.UnarmorDecryptPrivKey(string(privKeyBz), "12345678") - if err != nil { - panic(err) - } - - var privKey cryptotypes.PrivKey - if algo == string(hd.Sr25519Type) { - typedKey := &sr25519.PrivKey{} - if err := typedKey.UnmarshalJSON(privKeyBytes); err != nil { - panic(err) - } - privKey = typedKey - } else { - privKey, err = legacy.PrivKeyFromBytes(privKeyBytes) - if err != nil { - panic(err) - } - } - - valKeys = append(valKeys, privKey) - } - return valKeys -} - func (sc *SignerClient) SignTx(chainID string, txBuilder *client.TxBuilder, privKey cryptotypes.PrivKey, seqDelta uint64) { var sigsV2 []signing.SignatureV2 signerInfo := sc.GetAccountNumberSequenceNumber(privKey) diff --git a/loadtest/types.go b/loadtest/types.go index 70946a3574..961d7938ad 100644 --- a/loadtest/types.go +++ b/loadtest/types.go @@ -30,7 +30,6 @@ type Config struct { MsgsPerTx uint64 `json:"msgs_per_tx"` Rounds uint64 `json:"rounds"` MessageType string `json:"message_type"` - RunOracle bool `json:"run_oracle"` PriceDistr NumericDistribution `json:"price_distribution"` QuantityDistr NumericDistribution `json:"quantity_distribution"` MsgTypeDistr MsgTypeDistribution `json:"message_type_distribution"` diff --git a/x/oracle/ante.go b/x/oracle/ante.go index 2b0a903de3..3b3d37e93d 100644 --- a/x/oracle/ante.go +++ b/x/oracle/ante.go @@ -56,7 +56,6 @@ func (spd SpammingPreventionDecorator) AnteDeps(txDeps []sdkacltypes.AccessOpera 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 default: continue } From 88e13aafd1f82e99af387b5e5d7d8b97cd78bd7b Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 13/41] Revert "Ezhu/staking dep gen mappings v2 rebase (#338)" This reverts commit 1324183b965df5796aa05a776098bfacd8b0e4d6. --- aclmapping/staking/mappings.go | 260 ----------------------- aclmapping/utils/identifier_templates.go | 1 - go.mod | 2 +- go.sum | 4 +- loadtest/config.json | 13 +- loadtest/loadtest_client.go | 4 +- loadtest/main.go | 91 +++++--- loadtest/types.go | 31 +-- 8 files changed, 75 insertions(+), 331 deletions(-) delete mode 100644 aclmapping/staking/mappings.go diff --git a/aclmapping/staking/mappings.go b/aclmapping/staking/mappings.go deleted file mode 100644 index 18e8d68223..0000000000 --- a/aclmapping/staking/mappings.go +++ /dev/null @@ -1,260 +0,0 @@ -package aclstakingmapping - -import ( - "fmt" - - 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" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - utils "github.com/sei-protocol/sei-chain/aclmapping/utils" -) - -var ErrorInvalidMsgType = fmt.Errorf("invalid message received for staking module") - -func GetStakingDependencyGenerator() aclkeeper.DependencyGeneratorMap { - dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - - delegateKey := acltypes.GenerateMessageKey(&stakingtypes.MsgDelegate{}) - undelegateKey := acltypes.GenerateMessageKey(&stakingtypes.MsgUndelegate{}) - beginRedelegateKey := acltypes.GenerateMessageKey(&stakingtypes.MsgBeginRedelegate{}) - dependencyGeneratorMap[delegateKey] = MsgDelegateDependencyGenerator - dependencyGeneratorMap[undelegateKey] = MsgUndelegateDependencyGenerator - dependencyGeneratorMap[beginRedelegateKey] = MsgBeginRedelegateDependencyGenerator - - return dependencyGeneratorMap -} - -func MsgDelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - msgDelegate, ok := msg.(*stakingtypes.MsgDelegate) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType - } - - accessOperations := []sdkacltypes.AccessOperation{ - // Checks if the delegator exists - // Checks if there is a delegation object that already exists for (delegatorAddr, validatorAddr) - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.DelegatorAddress+msgDelegate.ValidatorAddress), - }, - // Store new delegator for (delegator, validator) - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.DelegatorAddress+msgDelegate.ValidatorAddress), - }, - - // delegate coins from account validator account - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.DelegatorAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.DelegatorAddress), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.ValidatorAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgDelegate.ValidatorAddress), - }, - - // Checks if the validators exchange rate is valid - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.ValidatorAddress), - }, - // Update validator shares and power index - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgDelegate.ValidatorAddress), - }, - - // Last Operation should always be a commit - { - ResourceType: sdkacltypes.ResourceType_ANY, - AccessType: sdkacltypes.AccessType_COMMIT, - IdentifierTemplate: utils.DefaultIDTemplate, - }, - } - - return accessOperations, nil -} - -func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - msgUndelegate, ok := msg.(*stakingtypes.MsgUndelegate) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType - } - - accessOperations := []sdkacltypes.AccessOperation{ - // Treat Delegations and Undelegations to have the same ACL since they are highly coupled, no point in finer granularization - - // Get delegation/redelegations and error checking - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.DelegatorAddress+msgUndelegate.ValidatorAddress), - }, - // Update/delete delegation and update redelegation - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.DelegatorAddress+msgUndelegate.ValidatorAddress), - }, - - // Update the delegator and validator account balances - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.DelegatorAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.DelegatorAddress), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.ValidatorAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgUndelegate.ValidatorAddress), - }, - - // Checks if the validators exchange rate is valid - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.ValidatorAddress), - }, - // Update validator shares and power index - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgUndelegate.ValidatorAddress), - }, - - // Last Operation should always be a commit - { - ResourceType: sdkacltypes.ResourceType_ANY, - AccessType: sdkacltypes.AccessType_COMMIT, - IdentifierTemplate: utils.DefaultIDTemplate, - }, - } - - return accessOperations, nil -} - -func MsgBeginRedelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - msgBeingRedelegate, ok := msg.(*stakingtypes.MsgBeginRedelegate) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType - } - - accessOperations := []sdkacltypes.AccessOperation{ - // Treat Delegations and Redelegations to have the same ACL since they are highly coupled, no point in finer granularization - - // Get src delegation to verify it has sufficient funds to undelegate - // Get dest delegation to see if it already exists - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorSrcAddress), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorDstAddress), - }, - // Update/delete src and destination delegation after tokens have been unbonded - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorSrcAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.DelegatorAddress+msgBeingRedelegate.ValidatorDstAddress), - }, - - // Update the delegator, src validator and dest validator account balances - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.DelegatorAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.DelegatorAddress), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorSrcAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorSrcAddress), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorDstAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgBeingRedelegate.ValidatorDstAddress), - }, - - // Update validators staking shares and power index - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorSrcAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorSrcAddress), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorDstAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.STAKING, msgBeingRedelegate.ValidatorDstAddress), - }, - - // Last Operation should always be a commit - { - ResourceType: sdkacltypes.ResourceType_ANY, - AccessType: sdkacltypes.AccessType_COMMIT, - IdentifierTemplate: utils.DefaultIDTemplate, - }, - } - - return accessOperations, nil -} diff --git a/aclmapping/utils/identifier_templates.go b/aclmapping/utils/identifier_templates.go index 3098e33742..ac28dad9ff 100644 --- a/aclmapping/utils/identifier_templates.go +++ b/aclmapping/utils/identifier_templates.go @@ -11,7 +11,6 @@ const ( ACCOUNT = "acc" BANK = "bank" AUTH = "auth" - STAKING = "staking" DefaultIDTemplate = "*" ) diff --git a/go.mod b/go.mod index 0012f55e9c..ad37b8bff5 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.192 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.176 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 diff --git a/go.sum b/go.sum index f65a89ab41..42cf1824a0 100644 --- a/go.sum +++ b/go.sum @@ -1099,8 +1099,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.192 h1:qrrzr2qHrj7zMDmU7KizOjlXm2uLROUtz8ogEYSxfSE= -github.com/sei-protocol/sei-cosmos v0.1.192/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0= +github.com/sei-protocol/sei-cosmos v0.1.176 h1:6UgAcryRx6C+UlouHDjxuY7T7hj3nck91QoeppyPdLc= +github.com/sei-protocol/sei-cosmos v0.1.176/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= diff --git a/loadtest/config.json b/loadtest/config.json index 9bb560111c..275d72b85d 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -1,7 +1,7 @@ { "msgs_per_tx": 10, "chain_id": "sei-loadtest-testnet", - "txs_per_block": 400, + "txs_per_block": 6000, "rounds": 5, "price_distribution": { "min": "45", @@ -14,15 +14,8 @@ "number_of_distinct_values": 20 }, "message_type_distribution": { - "dex": { - "limit_order_percentage": "0.2", - "market_order_percentage": "0.8" - }, - "staking": { - "delegate_percentage": "0.5", - "undelegate_percentage": "0.25", - "begin_redelegate_percentage": "0.25" - } + "limit_order_percentage": "0.2", + "market_order_percentage": "0.8" }, "message_type": "bank,dex,staking,tokenfactory", "contract_distribution": [ diff --git a/loadtest/loadtest_client.go b/loadtest/loadtest_client.go index f3c34d63cd..5afe724c1a 100644 --- a/loadtest/loadtest_client.go +++ b/loadtest/loadtest_client.go @@ -73,7 +73,7 @@ func NewLoadTestClient() *LoadTestClient { func (c *LoadTestClient) SetValidators() { if strings.Contains(c.LoadTestConfig.MessageType, "staking") { - if resp, err := c.StakingQueryClient.Validators(context.Background(), &stakingtypes.QueryValidatorsRequest{}); err != nil { + if resp, err := StakingQueryClient.Validators(context.Background(), &stakingtypes.QueryValidatorsRequest{}); err != nil { panic(err) } else { c.Validators = resp.Validators @@ -126,7 +126,7 @@ func (c *LoadTestClient) BuildTxs() (workgroups []*sync.WaitGroup, sendersList [ for j, account := range activeAccounts { key := c.SignerClient.GetKey(uint64(account)) - msg, failureExpected := c.generateMessage(config, key, config.MsgsPerTx) + msg, failureExpected := generateMessage(config, key, config.MsgsPerTx) txBuilder := TestConfig.TxConfig.NewTxBuilder() _ = txBuilder.SetMsgs(msg) seqDelta := uint64(i / 2) diff --git a/loadtest/main.go b/loadtest/main.go index a3f3656f04..ac77089769 100644 --- a/loadtest/main.go +++ b/loadtest/main.go @@ -25,7 +25,16 @@ import ( dextypes "github.com/sei-protocol/sei-chain/x/dex/types" ) -var TestConfig EncodingConfig +var ( + TestConfig EncodingConfig + StakingQueryClient stakingtypes.QueryClient + //// Staking specific variables + Validators []stakingtypes.Validator + // DelegationMap is a map of delegator -> validator -> delegated amount + DelegationMap map[string]map[string]int + //// Tokenfactory specific variables + TokenFactoryDenomOwner map[string]string +) const ( VortexData = "{\"position_effect\":\"Open\",\"leverage\":\"1\"}" @@ -74,7 +83,7 @@ func run() { fmt.Printf("%s - Finished\n", time.Now().Format("2006-01-02T15:04:05")) } -func (c *LoadTestClient) generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64) (sdk.Msg, bool) { +func generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64) (sdk.Msg, bool) { var msg sdk.Msg messageTypes := strings.Split(config.MessageType, ",") rand.Seed(time.Now().UnixNano()) @@ -106,36 +115,23 @@ func (c *LoadTestClient) generateMessage(config Config, key cryptotypes.PrivKey, Funds: amount, } case Staking: - msgType := config.MsgTypeDistr.SampleStakingMsgs() - - switch msgType { - case "delegate": - msg = &stakingtypes.MsgDelegate{ - DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), - ValidatorAddress: c.Validators[rand.Intn(len(c.Validators))].OperatorAddress, - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(5)}, + delegatorAddr := sdk.AccAddress(key.PubKey().Address()).String() + chosenValidator := Validators[rand.Intn(len(Validators))].OperatorAddress + // Randomly pick someone to redelegate / unbond from + srcAddr := "" + for k := range DelegationMap[delegatorAddr] { + if k == chosenValidator { + continue } - case "undelegate": - msg = &stakingtypes.MsgUndelegate{ - DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), - ValidatorAddress: c.Validators[rand.Intn(len(c.Validators))].OperatorAddress, - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, - } - case "begin_redelegate": - msg = &stakingtypes.MsgBeginRedelegate{ - DelegatorAddress: sdk.AccAddress(key.PubKey().Address()).String(), - ValidatorSrcAddress: c.Validators[rand.Intn(len(c.Validators))].OperatorAddress, - ValidatorDstAddress: c.Validators[rand.Intn(len(c.Validators))].OperatorAddress, - Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, - } - default: - panic("Unknown message type") + srcAddr = k + break } + msg = generateStakingMsg(delegatorAddr, chosenValidator, srcAddr) case Tokenfactory: denomCreatorAddr := sdk.AccAddress(key.PubKey().Address()).String() // No denoms, let's mint randNum := rand.Float64() - denom, ok := c.TokenFactoryDenomOwner[denomCreatorAddr] + denom, ok := TokenFactoryDenomOwner[denomCreatorAddr] switch { case !ok || randNum <= 0.33: subDenom := fmt.Sprintf("tokenfactory-created-denom-%d", time.Now().UnixMilli()) @@ -144,7 +140,7 @@ func (c *LoadTestClient) generateMessage(config Config, key cryptotypes.PrivKey, Sender: denomCreatorAddr, Subdenom: subDenom, } - c.TokenFactoryDenomOwner[denomCreatorAddr] = denom + TokenFactoryDenomOwner[denomCreatorAddr] = denom case randNum <= 0.66: msg = &tokenfactorytypes.MsgMint{ Sender: denomCreatorAddr, @@ -235,7 +231,7 @@ func generateDexOrderPlacements(config Config, key cryptotypes.PrivKey, batchSiz if config.MessageType == "failure_bank_malformed" { orderType = -1 } else { - dexMsgType := config.MsgTypeDistr.SampleDexMsgs() + dexMsgType := config.MsgTypeDistr.Sample() switch dexMsgType { case Limit: orderType = dextypes.OrderType_LIMIT @@ -269,6 +265,45 @@ func generateDexOrderPlacements(config Config, key cryptotypes.PrivKey, batchSiz return orderPlacements } +func generateStakingMsg(delegatorAddr string, chosenValidator string, srcAddr string) sdk.Msg { + // Randomly unbond, redelegate or delegate + // However, if there are no delegations, do so first + var msg sdk.Msg + randNum := rand.Float64() + if _, ok := DelegationMap[delegatorAddr]; !ok || randNum <= 0.33 || srcAddr == "" { + msg = &stakingtypes.MsgDelegate{ + DelegatorAddress: delegatorAddr, + ValidatorAddress: chosenValidator, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, + } + DelegationMap[delegatorAddr] = map[string]int{} + DelegationMap[delegatorAddr][chosenValidator] = 1 + } else { + + if randNum <= 0.66 { + msg = &stakingtypes.MsgBeginRedelegate{ + DelegatorAddress: delegatorAddr, + ValidatorSrcAddress: srcAddr, + ValidatorDstAddress: chosenValidator, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, + } + DelegationMap[delegatorAddr][chosenValidator]++ + } else { + msg = &stakingtypes.MsgUndelegate{ + DelegatorAddress: delegatorAddr, + ValidatorAddress: srcAddr, + Amount: sdk.Coin{Denom: "usei", Amount: sdk.NewInt(1)}, + } + } + // Update delegation map + DelegationMap[delegatorAddr][srcAddr]-- + if DelegationMap[delegatorAddr][srcAddr] == 0 { + delete(DelegationMap, delegatorAddr) + } + } + return msg +} + func getLastHeight() int { out, err := exec.Command("curl", "http://localhost:26657/blockchain").Output() if err != nil { diff --git a/loadtest/types.go b/loadtest/types.go index 961d7938ad..814eff066b 100644 --- a/loadtest/types.go +++ b/loadtest/types.go @@ -66,45 +66,22 @@ func (d *NumericDistribution) InvalidSample() sdk.Dec { return d.Max.Add(d.Max.Sub(d.Min).QuoInt64(d.NumDistinct).Mul(steps)) } -type DexMsgTypeDistribution struct { +type MsgTypeDistribution struct { LimitOrderPct sdk.Dec `json:"limit_order_percentage"` MarketOrderPct sdk.Dec `json:"market_order_percentage"` } -type StakingMsgTypeDistribution struct { - DelegatePct sdk.Dec `json:"delegate_percentage"` - UndelegatePct sdk.Dec `json:"undelegate_percentage"` - BeginRedelegatePct sdk.Dec `json:"begin_redelegate_percentage"` -} -type MsgTypeDistribution struct { - Dex DexMsgTypeDistribution `json:"dex"` - Staking StakingMsgTypeDistribution `json:"staking"` -} - -func (d *MsgTypeDistribution) SampleDexMsgs() string { - if !d.Dex.LimitOrderPct.Add(d.Dex.MarketOrderPct).Equal(sdk.OneDec()) { +func (d *MsgTypeDistribution) Sample() string { + if !d.LimitOrderPct.Add(d.MarketOrderPct).Equal(sdk.OneDec()) { panic("Distribution percentages must add up to 1") } randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) - if randNum.LT(d.Dex.LimitOrderPct) { + if randNum.LT(d.LimitOrderPct) { return Limit } return Market } -func (d *MsgTypeDistribution) SampleStakingMsgs() string { - if !d.Staking.DelegatePct.Add(d.Staking.UndelegatePct).Add(d.Staking.BeginRedelegatePct).Equal(sdk.OneDec()) { - panic("Distribution percentages must add up to 1") - } - randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) - if randNum.LT(d.Staking.DelegatePct) { - return "delegate" - } else if randNum.LT(d.Staking.DelegatePct.Add(d.Staking.UndelegatePct)) { - return "undelegate" - } - return "begin_redelegate" -} - type ContractDistributions []ContractDistribution func (d *ContractDistributions) Sample() string { From 36b6a118f09fb1c86da4381a026adf6137638c0f Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 14/41] Revert "Refactor Loadtest script (#336)" This reverts commit c8b83c701aefa707825b3f88c519518e8c7e311c. --- loadtest/config.json | 124 +++++++++---------- loadtest/loadtest_client.go | 173 -------------------------- loadtest/main.go | 240 ++++++++++++++++++++++++++++++++---- loadtest/sign.go | 67 ++-------- loadtest/tx.go | 17 ++- loadtest/types.go | 105 ---------------- 6 files changed, 298 insertions(+), 428 deletions(-) delete mode 100644 loadtest/loadtest_client.go delete mode 100644 loadtest/types.go diff --git a/loadtest/config.json b/loadtest/config.json index 275d72b85d..277844036e 100644 --- a/loadtest/config.json +++ b/loadtest/config.json @@ -1,63 +1,63 @@ { - "msgs_per_tx": 10, - "chain_id": "sei-loadtest-testnet", - "txs_per_block": 6000, - "rounds": 5, - "price_distribution": { - "min": "45", - "max": "55", - "number_of_distinct_values": 20 - }, - "quantity_distribution": { - "min": "1", - "max": "21", - "number_of_distinct_values": 20 - }, - "message_type_distribution": { - "limit_order_percentage": "0.2", - "market_order_percentage": "0.8" - }, - "message_type": "bank,dex,staking,tokenfactory", - "contract_distribution": [ - { - "contract_address":"sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m", - "percentage":"0.1" - }, - { - "contract_address":"sei1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqms7u8a", - "percentage":"0.1" - }, - { - "contract_address":"sei17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgsrtqewe", - "percentage":"0.1" - }, - { - "contract_address":"sei1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8tsy4qgdm", - "percentage":"0.1" - }, - { - "contract_address":"sei1hulx7cgvpfcvg83wk5h96sedqgn72n026w6nl47uht554xhvj9nstdktte", - "percentage":"0.1" - }, - { - "contract_address":"sei1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq8un0p6", - "percentage":"0.1" - }, - { - "contract_address":"sei1wl59k23zngj34l7d42y9yltask7rjlnxgccawc7ltrknp6n52fpsj6ctln", - "percentage":"0.1" - }, - { - "contract_address":"sei182nff4ttmvshn6yjlqj5czapfcav9434l2qzz8aahf5pxnyd33ts2pdy3l", - "percentage":"0.1" - }, - { - "contract_address":"sei1k8re7jwz6rnnwrktnejdwkwnncte7ek7gt29gvnl3sdrg9mtnqksw4tqd9", - "percentage":"0.1" - }, - { - "contract_address":"sei1nwnejwsdpqktusvh8qhxe5arsznjd5asdwutmaz9n5qcpl3dcmhs9eeuca", - "percentage":"0.1" - } - ] -} + "batch_size": 1, + "chain_id": "sei-loadtest-testnet", + "orders_per_block": 2, + "rounds": 5, + "price_distribution": { + "min": "45", + "max": "55", + "number_of_distinct_values": 20 + }, + "quantity_distribution": { + "min": "1", + "max": "21", + "number_of_distinct_values": 20 + }, + "dex_message_type_distribution": { + "limit_order_percentage": "0.2", + "market_order_percentage": "0.8" + }, + "message_type": "bank,dex,staking,tokenfactory", + "contract_distribution": [ + { + "contract_address":"sei14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9sh9m79m", + "percentage":"0.1" + }, + { + "contract_address":"sei1nc5tatafv6eyq7llkr2gv50ff9e22mnf70qgjlv737ktmt4eswrqms7u8a", + "percentage":"0.1" + }, + { + "contract_address":"sei17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9jfksztgw5uh69wac2pgsrtqewe", + "percentage":"0.1" + }, + { + "contract_address":"sei1yw4xvtc43me9scqfr2jr2gzvcxd3a9y4eq7gaukreugw2yd2f8tsy4qgdm", + "percentage":"0.1" + }, + { + "contract_address":"sei1hulx7cgvpfcvg83wk5h96sedqgn72n026w6nl47uht554xhvj9nstdktte", + "percentage":"0.1" + }, + { + "contract_address":"sei1fzm6gzyccl8jvdv3qq6hp9vs6ylaruervs4m06c7k0ntzn2f8faq8un0p6", + "percentage":"0.1" + }, + { + "contract_address":"sei1wl59k23zngj34l7d42y9yltask7rjlnxgccawc7ltrknp6n52fpsj6ctln", + "percentage":"0.1" + }, + { + "contract_address":"sei182nff4ttmvshn6yjlqj5czapfcav9434l2qzz8aahf5pxnyd33ts2pdy3l", + "percentage":"0.1" + }, + { + "contract_address":"sei1k8re7jwz6rnnwrktnejdwkwnncte7ek7gt29gvnl3sdrg9mtnqksw4tqd9", + "percentage":"0.1" + }, + { + "contract_address":"sei1nwnejwsdpqktusvh8qhxe5arsznjd5asdwutmaz9n5qcpl3dcmhs9eeuca", + "percentage":"0.1" + } + ] +} \ No newline at end of file diff --git a/loadtest/loadtest_client.go b/loadtest/loadtest_client.go deleted file mode 100644 index 5afe724c1a..0000000000 --- a/loadtest/loadtest_client.go +++ /dev/null @@ -1,173 +0,0 @@ -package main - -import ( - "context" - "encoding/json" - "fmt" - "os" - "path/filepath" - "strings" - "sync" - "time" - - typestx "github.com/cosmos/cosmos-sdk/types/tx" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "google.golang.org/grpc" -) - -type LoadTestClient struct { - LoadTestConfig Config - TestConfig EncodingConfig - TxClient typestx.ServiceClient - TxHashFile *os.File - SignerClient *SignerClient - ChainID string - TxHashList []string - TxHashListMutex *sync.Mutex - GrpcConn *grpc.ClientConn - StakingQueryClient stakingtypes.QueryClient - //// Staking specific variables - Validators []stakingtypes.Validator - // DelegationMap is a map of delegator -> validator -> delegated amount - DelegationMap map[string]map[string]int - //// Tokenfactory specific variables - TokenFactoryDenomOwner map[string]string -} - -func NewLoadTestClient() *LoadTestClient { - grpcConn, _ := grpc.Dial( - "127.0.0.1:9090", - grpc.WithInsecure(), - ) - TxClient := typestx.NewServiceClient(grpcConn) - - config := Config{} - pwd, _ := os.Getwd() - file, _ := os.ReadFile(pwd + "/loadtest/config.json") - if err := json.Unmarshal(file, &config); err != nil { - panic(err) - } - - // setup output files - userHomeDir, _ := os.UserHomeDir() - _ = os.Mkdir(filepath.Join(userHomeDir, "outputs"), os.ModePerm) - filename := filepath.Join(userHomeDir, "outputs", "test_tx_hash") - _ = os.Remove(filename) - outputFile, _ := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) - - return &LoadTestClient{ - LoadTestConfig: config, - TestConfig: TestConfig, - TxClient: TxClient, - TxHashFile: outputFile, - SignerClient: NewSignerClient(), - ChainID: config.ChainID, - TxHashList: []string{}, - TxHashListMutex: &sync.Mutex{}, - GrpcConn: grpcConn, - StakingQueryClient: stakingtypes.NewQueryClient(grpcConn), - DelegationMap: map[string]map[string]int{}, - TokenFactoryDenomOwner: map[string]string{}, - } -} - -func (c *LoadTestClient) SetValidators() { - if strings.Contains(c.LoadTestConfig.MessageType, "staking") { - if resp, err := StakingQueryClient.Validators(context.Background(), &stakingtypes.QueryValidatorsRequest{}); err != nil { - panic(err) - } else { - c.Validators = resp.Validators - } - } -} - -func (c *LoadTestClient) Close() { - c.GrpcConn.Close() -} - -func (c *LoadTestClient) AppendTxHash(txHash string) { - c.TxHashListMutex.Lock() - defer c.TxHashListMutex.Unlock() - - c.TxHashList = append(c.TxHashList, txHash) -} - -func (c *LoadTestClient) WriteTxHashToFile() { - file := c.TxHashFile - for _, txHash := range c.TxHashList { - txHashLine := fmt.Sprintf("%s\n", txHash) - if _, err := file.WriteString(txHashLine); err != nil { - panic(err) - } - } -} - -func (c *LoadTestClient) BuildTxs() (workgroups []*sync.WaitGroup, sendersList [][]func() string) { - config := c.LoadTestConfig - numberOfAccounts := config.TxsPerBlock / config.MsgsPerTx * 2 // * 2 because we need two sets of accounts - activeAccounts := []int{} - inactiveAccounts := []int{} - - for i := 0; i < int(numberOfAccounts); i++ { - if i%2 == 0 { - activeAccounts = append(activeAccounts, i) - } else { - inactiveAccounts = append(inactiveAccounts, i) - } - } - - for i := 0; i < int(config.Rounds); i++ { - fmt.Printf("Preparing %d-th round\n", i) - - wg := &sync.WaitGroup{} - var senders []func() string - workgroups = append(workgroups, wg) - - for j, account := range activeAccounts { - key := c.SignerClient.GetKey(uint64(account)) - - msg, failureExpected := generateMessage(config, key, config.MsgsPerTx) - txBuilder := TestConfig.TxConfig.NewTxBuilder() - _ = txBuilder.SetMsgs(msg) - seqDelta := uint64(i / 2) - mode := typestx.BroadcastMode_BROADCAST_MODE_SYNC - if j == len(activeAccounts)-1 { - mode = typestx.BroadcastMode_BROADCAST_MODE_BLOCK - } - // Note: There is a potential race condition here with seqnos - // in which a later seqno is delievered before an earlier seqno - // In practice, we haven't run into this issue so we'll leave this - // as is. - sender := SendTx(key, &txBuilder, mode, seqDelta, failureExpected, *c) - wg.Add(1) - senders = append(senders, func() string { - defer wg.Done() - return sender() - }) - } - - sendersList = append(sendersList, senders) - inactiveAccounts, activeAccounts = activeAccounts, inactiveAccounts - } - - return workgroups, sendersList -} - -func (c *LoadTestClient) SendTxs(workgroups []*sync.WaitGroup, sendersList [][]func() string) { - lastHeight := getLastHeight() - for i := 0; i < int(c.LoadTestConfig.Rounds); i++ { - newHeight := getLastHeight() - for newHeight == lastHeight { - time.Sleep(10 * time.Millisecond) - newHeight = getLastHeight() - } - fmt.Printf("Sending %d-th block\n", i) - senders := sendersList[i] - wg := workgroups[i] - for _, sender := range senders { - go sender() - } - wg.Wait() - lastHeight = newHeight - } -} diff --git a/loadtest/main.go b/loadtest/main.go index ac77089769..6d77980e13 100644 --- a/loadtest/main.go +++ b/loadtest/main.go @@ -1,33 +1,138 @@ package main import ( + "context" "encoding/json" + "flag" "fmt" "math/rand" + "os" "os/exec" + "path/filepath" "strconv" "strings" + "sync" "time" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" tokenfactorytypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/std" - "github.com/cosmos/cosmos-sdk/x/auth/tx" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/std" sdk "github.com/cosmos/cosmos-sdk/types" + typestx "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/auth/tx" "github.com/sei-protocol/sei-chain/app" + "github.com/sei-protocol/sei-chain/utils" dextypes "github.com/sei-protocol/sei-chain/x/dex/types" + "google.golang.org/grpc" ) +const ( + Bank string = "bank" + FailureBankMalformed string = "failure_bank_malformed" + FailureBankInvalid string = "failure_bank_invalid" + FailureDexMalformed string = "failure_dex_malformed" + FailureDexInvalid string = "failure_dex_invalid" + Dex string = "dex" + Staking string = "staking" + Tokenfactory string = "tokenfactory" + Limit string = "limit" + Market string = "market" +) + +type EncodingConfig struct { + InterfaceRegistry types.InterfaceRegistry + // NOTE: this field will be renamed to Codec + Marshaler codec.Codec + TxConfig client.TxConfig + Amino *codec.LegacyAmino +} + +type Config struct { + BatchSize uint64 `json:"batch_size"` + ChainID string `json:"chain_id"` + OrdersPerBlock uint64 `json:"orders_per_block"` + Rounds uint64 `json:"rounds"` + MessageType string `json:"message_type"` + PriceDistr NumericDistribution `json:"price_distribution"` + QuantityDistr NumericDistribution `json:"quantity_distribution"` + DexMsgTypeDistr MsgTypeDistribution `json:"dex_message_type_distribution"` + ContractDistr ContractDistributions `json:"contract_distribution"` + Constant bool `json:"constant"` + ConstLoadInterval int64 `json:"const_load_interval"` +} + +type NumericDistribution struct { + Min sdk.Dec `json:"min"` + Max sdk.Dec `json:"max"` + NumDistinct int64 `json:"number_of_distinct_values"` +} + +func (d *NumericDistribution) Sample() sdk.Dec { + steps := sdk.NewDec(rand.Int63n(d.NumDistinct)) + return d.Min.Add(d.Max.Sub(d.Min).QuoInt64(d.NumDistinct).Mul(steps)) +} + +// Invalid numeric distribution sample +func (d *NumericDistribution) InvalidSample() sdk.Dec { + steps := sdk.NewDec(rand.Int63n(d.NumDistinct)) + if rand.Float64() < 0.5 { + return d.Min.Add(d.Max.Sub(d.Min).QuoInt64(d.NumDistinct).Mul(steps)) + } + return d.Max.Add(d.Max.Sub(d.Min).QuoInt64(d.NumDistinct).Mul(steps)) +} + +type MsgTypeDistribution struct { + LimitOrderPct sdk.Dec `json:"limit_order_percentage"` + MarketOrderPct sdk.Dec `json:"market_order_percentage"` +} + +func (d *MsgTypeDistribution) Sample() string { + if !d.LimitOrderPct.Add(d.MarketOrderPct).Equal(sdk.OneDec()) { + panic("Distribution percentages must add up to 1") + } + randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) + if randNum.LT(d.LimitOrderPct) { + return Limit + } + return "market" +} + +type ContractDistributions []ContractDistribution + +func (d *ContractDistributions) Sample() string { + if !utils.Reduce(*d, func(i ContractDistribution, o sdk.Dec) sdk.Dec { return o.Add(i.Percentage) }, sdk.ZeroDec()).Equal(sdk.OneDec()) { + panic("Distribution percentages must add up to 1") + } + randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) + cumPct := sdk.ZeroDec() + for _, dist := range *d { + cumPct = cumPct.Add(dist.Percentage) + if randNum.LTE(cumPct) { + return dist.ContractAddr + } + } + panic("this should never be triggered") +} + +type ContractDistribution struct { + ContractAddr string `json:"contract_address"` + Percentage sdk.Dec `json:"percentage"` +} + var ( TestConfig EncodingConfig + TxClient typestx.ServiceClient StakingQueryClient stakingtypes.QueryClient + TxHashFile *os.File + ChainID string //// Staking specific variables Validators []stakingtypes.Validator // DelegationMap is a map of delegator -> validator -> delegated amount @@ -59,31 +164,112 @@ func init() { app.ModuleBasics.RegisterInterfaces(TestConfig.InterfaceRegistry) } -func run() { - client := NewLoadTestClient() - client.SetValidators() - config := client.LoadTestConfig - - defer client.Close() - - if config.TxsPerBlock < config.MsgsPerTx { - panic("Must have more TxsPerBlock than MsgsPerTx") +func run(config Config) { + ChainID = config.ChainID + grpcConn, _ := grpc.Dial( + "127.0.0.1:9090", + grpc.WithInsecure(), + ) + defer grpcConn.Close() + TxClient = typestx.NewServiceClient(grpcConn) + StakingQueryClient = stakingtypes.NewQueryClient(grpcConn) + createOutputFiles() + var mu sync.Mutex + batchSize := config.BatchSize + if config.OrdersPerBlock < batchSize { + panic("Must have more orders per block than batch size") + } + setValidators(config) + DelegationMap = map[string]map[string]int{} + TokenFactoryDenomOwner = map[string]string{} + numberOfAccounts := config.OrdersPerBlock / batchSize * 2 // * 2 because we need two sets of accounts + activeAccounts := []int{} + inactiveAccounts := []int{} + for i := 0; i < int(numberOfAccounts); i++ { + if i%2 == 0 { + activeAccounts = append(activeAccounts, i) + } else { + inactiveAccounts = append(inactiveAccounts, i) + } } + wgs := []*sync.WaitGroup{} + sendersList := [][]func() string{} configString, _ := json.Marshal(config) - fmt.Printf("Running with \n %s \n", string(configString)) + fmt.Printf("Running with \n %s \ns", string(configString)) fmt.Printf("%s - Starting block prepare\n", time.Now().Format("2006-01-02T15:04:05")) - workgroups, sendersList := client.BuildTxs() + for i := 0; i < int(config.Rounds); i++ { + fmt.Printf("Preparing %d-th round\n", i) + wg := &sync.WaitGroup{} + var senders []func() string + wgs = append(wgs, wg) + for j, account := range activeAccounts { + key := GetKey(uint64(account)) - client.SendTxs(workgroups, sendersList) + msg, failureExpected := generateMessage(config, key, batchSize) + txBuilder := TestConfig.TxConfig.NewTxBuilder() + _ = txBuilder.SetMsgs(msg) + seqDelta := uint64(i / 2) + mode := typestx.BroadcastMode_BROADCAST_MODE_SYNC + if j == len(activeAccounts)-1 { + mode = typestx.BroadcastMode_BROADCAST_MODE_BLOCK + } + // Note: There is a potential race condition here with seqnos + // in which a later seqno is delievered before an earlier seqno + // In practice, we haven't run into this issue so we'll leave this + // as is. + sender := SendTx(key, &txBuilder, mode, seqDelta, &mu, failureExpected) + wg.Add(1) + senders = append(senders, func() string { + defer wg.Done() + return sender() + }) + } + sendersList = append(sendersList, senders) - // Records the resulting TxHash to file - client.WriteTxHashToFile() + inactiveAccounts, activeAccounts = activeAccounts, inactiveAccounts + } + + lastHeight := getLastHeight() + for i := 0; i < int(config.Rounds); i++ { + newHeight := getLastHeight() + for newHeight == lastHeight { + time.Sleep(10 * time.Millisecond) + newHeight = getLastHeight() + } + fmt.Printf("Sending %d-th block\n", i) + senders := sendersList[i] + wg := wgs[i] + for _, sender := range senders { + go sender() + } + wg.Wait() + lastHeight = newHeight + } fmt.Printf("%s - Finished\n", time.Now().Format("2006-01-02T15:04:05")) } -func generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64) (sdk.Msg, bool) { +func createOutputFiles() { + userHomeDir, _ := os.UserHomeDir() + _ = os.Mkdir(filepath.Join(userHomeDir, "outputs"), os.ModePerm) + filename := filepath.Join(userHomeDir, "outputs", "test_tx_hash") + _ = os.Remove(filename) + file, _ := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644) + TxHashFile = file +} + +func setValidators(config Config) { + if strings.Contains(config.MessageType, "staking") { + if resp, err := StakingQueryClient.Validators(context.Background(), &stakingtypes.QueryValidatorsRequest{}); err != nil { + panic(err) + } else { + Validators = resp.Validators + } + } +} + +func generateMessage(config Config, key cryptotypes.PrivKey, batchSize uint64) (sdk.Msg, bool) { var msg sdk.Msg messageTypes := strings.Split(config.MessageType, ",") rand.Seed(time.Now().UnixNano()) @@ -103,7 +289,7 @@ func generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64) (s price := config.PriceDistr.Sample() quantity := config.QuantityDistr.Sample() contract := config.ContractDistr.Sample() - orderPlacements := generateDexOrderPlacements(config, key, msgPerTx, price, quantity) + orderPlacements := generateDexOrderPlacements(config, key, batchSize, price, quantity) amount, err := sdk.ParseCoinsNormalized(fmt.Sprintf("%d%s", price.Mul(quantity).Ceil().RoundInt64(), "usei")) if err != nil { panic(err) @@ -182,7 +368,7 @@ func generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64) (s price := config.PriceDistr.InvalidSample() quantity := config.QuantityDistr.InvalidSample() contract := config.ContractDistr.Sample() - orderPlacements := generateDexOrderPlacements(config, key, msgPerTx, price, quantity) + orderPlacements := generateDexOrderPlacements(config, key, batchSize, price, quantity) amount, err := sdk.ParseCoinsNormalized(fmt.Sprintf("%d%s", price.Mul(quantity).Ceil().RoundInt64(), "usei")) if err != nil { panic(err) @@ -197,7 +383,7 @@ func generateMessage(config Config, key cryptotypes.PrivKey, msgPerTx uint64) (s price := config.PriceDistr.Sample() quantity := config.QuantityDistr.Sample() contract := config.ContractDistr.Sample() - orderPlacements := generateDexOrderPlacements(config, key, msgPerTx, price, quantity) + orderPlacements := generateDexOrderPlacements(config, key, batchSize, price, quantity) var amountUsei int64 if rand.Float64() < 0.5 { amountUsei = 10000 * price.Mul(quantity).Ceil().RoundInt64() @@ -231,7 +417,7 @@ func generateDexOrderPlacements(config Config, key cryptotypes.PrivKey, batchSiz if config.MessageType == "failure_bank_malformed" { orderType = -1 } else { - dexMsgType := config.MsgTypeDistr.Sample() + dexMsgType := config.DexMsgTypeDistr.Sample() switch dexMsgType { case Limit: orderType = dextypes.OrderType_LIMIT @@ -321,5 +507,15 @@ func getLastHeight() int { } func main() { - run() + flag.Parse() + config := Config{} + pwd, _ := os.Getwd() + + fileName := "/loadtest/config.json" + file, _ := os.ReadFile(pwd + fileName) + if err := json.Unmarshal(file, &config); err != nil { + panic(err) + } + + run(config) } diff --git a/loadtest/sign.go b/loadtest/sign.go index b27bf53d26..0ebaccd94e 100644 --- a/loadtest/sign.go +++ b/loadtest/sign.go @@ -6,7 +6,6 @@ import ( "io" "os" "path/filepath" - "sync" "time" "github.com/cosmos/cosmos-sdk/client" @@ -27,43 +26,7 @@ type AccountInfo struct { Mnemonic string `json:"mnemonic"` } -type SignerInfo struct { - AccountNumber uint64 - SequenceNumber uint64 - mutex *sync.Mutex -} - -func NewSignerInfo(accountNumber uint64, sequenceNumber uint64) *SignerInfo { - return &SignerInfo{ - AccountNumber: accountNumber, - SequenceNumber: sequenceNumber, - mutex: &sync.Mutex{}, - } -} - -func (si *SignerInfo) IncrementAccountNumber() { - si.mutex.Lock() - defer si.mutex.Unlock() - si.AccountNumber++ -} - -type SignerClient struct { - CachedAccountSeqNum *sync.Map - CachedAccountKey *sync.Map -} - -func NewSignerClient() *SignerClient { - return &SignerClient{ - CachedAccountSeqNum: &sync.Map{}, - CachedAccountKey: &sync.Map{}, - } -} - -func (sc *SignerClient) GetKey(accountIdx uint64) cryptotypes.PrivKey { - if val, ok := sc.CachedAccountKey.Load(accountIdx); ok { - privKey := val.(cryptotypes.PrivKey) - return privKey - } +func GetKey(accountIdx uint64) cryptotypes.PrivKey { userHomeDir, _ := os.UserHomeDir() accountKeyFilePath := filepath.Join(userHomeDir, "test_accounts", fmt.Sprintf("ta%d.json", accountIdx)) jsonFile, err := os.Open(accountKeyFilePath) @@ -85,19 +48,12 @@ func (sc *SignerClient) GetKey(accountIdx uint64) cryptotypes.PrivKey { algo, _ := keyring.NewSigningAlgoFromString(algoStr, keyringAlgos) hdpath := hd.CreateHDPath(sdk.GetConfig().GetCoinType(), 0, 0).String() derivedPriv, _ := algo.Derive()(accountInfo.Mnemonic, "", hdpath) - privKey := algo.Generate()(derivedPriv) - - // Cache this so we don't need to regenerate it - sc.CachedAccountKey.Store(accountIdx, privKey) - return privKey + return algo.Generate()(derivedPriv) } -func (sc *SignerClient) SignTx(chainID string, txBuilder *client.TxBuilder, privKey cryptotypes.PrivKey, seqDelta uint64) { +func SignTx(txBuilder *client.TxBuilder, privKey cryptotypes.PrivKey, seqDelta uint64) { var sigsV2 []signing.SignatureV2 - signerInfo := sc.GetAccountNumberSequenceNumber(privKey) - accountNum := signerInfo.AccountNumber - seqNum := signerInfo.SequenceNumber - + accountNum, seqNum := GetAccountNumberSequenceNumber(privKey) seqNum += seqDelta sigV2 := signing.SignatureV2{ PubKey: privKey.PubKey(), @@ -111,7 +67,7 @@ func (sc *SignerClient) SignTx(chainID string, txBuilder *client.TxBuilder, priv _ = (*txBuilder).SetSignatures(sigsV2...) sigsV2 = []signing.SignatureV2{} signerData := xauthsigning.SignerData{ - ChainID: chainID, + ChainID: ChainID, AccountNumber: accountNum, Sequence: seqNum, } @@ -127,13 +83,7 @@ func (sc *SignerClient) SignTx(chainID string, txBuilder *client.TxBuilder, priv _ = (*txBuilder).SetSignatures(sigsV2...) } -func (sc *SignerClient) GetAccountNumberSequenceNumber(privKey cryptotypes.PrivKey) SignerInfo { - if val, ok := sc.CachedAccountSeqNum.Load(privKey); ok { - signerinfo := val.(SignerInfo) - signerinfo.IncrementAccountNumber() - return signerinfo - } - +func GetAccountNumberSequenceNumber(privKey cryptotypes.PrivKey) (uint64, uint64) { hexAccount := privKey.PubKey().Address() address, err := sdk.AccAddressFromHex(hexAccount.String()) if err != nil { @@ -160,8 +110,5 @@ func (sc *SignerClient) GetAccountNumberSequenceNumber(privKey cryptotypes.PrivK panic(err) } } - - signerInfo := *NewSignerInfo(account, seq) - sc.CachedAccountSeqNum.Store(privKey, signerInfo) - return signerInfo + return account, seq } diff --git a/loadtest/tx.go b/loadtest/tx.go index 5b0b8698f4..10af6ec221 100644 --- a/loadtest/tx.go +++ b/loadtest/tx.go @@ -3,6 +3,7 @@ package main import ( "context" "fmt" + "sync" "time" "github.com/cosmos/cosmos-sdk/client" @@ -17,17 +18,17 @@ func SendTx( txBuilder *client.TxBuilder, mode typestx.BroadcastMode, seqDelta uint64, + mu *sync.Mutex, failureExpected bool, - loadtestClient LoadTestClient, -) func() string { // TODO: do we need to return string? +) func() string { (*txBuilder).SetGasLimit(200000000) (*txBuilder).SetFeeAmount([]sdk.Coin{ sdk.NewCoin("usei", sdk.NewInt(10000000)), }) - loadtestClient.SignerClient.SignTx(loadtestClient.ChainID, txBuilder, key, seqDelta) + SignTx(txBuilder, key, seqDelta) txBytes, _ := TestConfig.TxConfig.TxEncoder()((*txBuilder).GetTx()) return func() string { - grpcRes, err := loadtestClient.TxClient.BroadcastTx( + grpcRes, err := TxClient.BroadcastTx( context.Background(), &typestx.BroadcastTxRequest{ Mode: mode, @@ -45,7 +46,7 @@ func SendTx( // retry after a second until either succeed or fail for some other reason fmt.Printf("Mempool full\n") time.Sleep(1 * time.Second) - grpcRes, err = loadtestClient.TxClient.BroadcastTx( + grpcRes, err = TxClient.BroadcastTx( context.Background(), &typestx.BroadcastTxRequest{ Mode: mode, @@ -63,7 +64,11 @@ func SendTx( if grpcRes.TxResponse.Code != 0 { fmt.Printf("Error: %d, %s\n", grpcRes.TxResponse.Code, grpcRes.TxResponse.RawLog) } else { - loadtestClient.AppendTxHash(grpcRes.TxResponse.TxHash) + mu.Lock() + defer mu.Unlock() + if _, err := TxHashFile.WriteString(fmt.Sprintf("%s\n", grpcRes.TxResponse.TxHash)); err != nil { + panic(err) + } return grpcRes.TxResponse.TxHash } return "" diff --git a/loadtest/types.go b/loadtest/types.go deleted file mode 100644 index 814eff066b..0000000000 --- a/loadtest/types.go +++ /dev/null @@ -1,105 +0,0 @@ -package main - -import ( - "fmt" - "math/rand" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sei-protocol/sei-chain/utils" -) - -const ( - Bank string = "bank" - FailureBankMalformed string = "failure_bank_malformed" - FailureBankInvalid string = "failure_bank_invalid" - FailureDexMalformed string = "failure_dex_malformed" - FailureDexInvalid string = "failure_dex_invalid" - Dex string = "dex" - Staking string = "staking" - Tokenfactory string = "tokenfactory" - Limit string = "limit" - Market string = "market" -) - -type Config struct { - ChainID string `json:"chain_id"` - TxsPerBlock uint64 `json:"txs_per_block"` - MsgsPerTx uint64 `json:"msgs_per_tx"` - Rounds uint64 `json:"rounds"` - MessageType string `json:"message_type"` - PriceDistr NumericDistribution `json:"price_distribution"` - QuantityDistr NumericDistribution `json:"quantity_distribution"` - MsgTypeDistr MsgTypeDistribution `json:"message_type_distribution"` - ContractDistr ContractDistributions `json:"contract_distribution"` - Constant bool `json:"constant"` - ConstLoadInterval int64 `json:"const_load_interval"` -} - -type EncodingConfig struct { - InterfaceRegistry types.InterfaceRegistry - // NOTE: this field will be renamed to Codec - Marshaler codec.Codec - TxConfig client.TxConfig - Amino *codec.LegacyAmino -} - -type NumericDistribution struct { - Min sdk.Dec `json:"min"` - Max sdk.Dec `json:"max"` - NumDistinct int64 `json:"number_of_distinct_values"` -} - -func (d *NumericDistribution) Sample() sdk.Dec { - steps := sdk.NewDec(rand.Int63n(d.NumDistinct)) - return d.Min.Add(d.Max.Sub(d.Min).QuoInt64(d.NumDistinct).Mul(steps)) -} - -// Invalid numeric distribution sample -func (d *NumericDistribution) InvalidSample() sdk.Dec { - steps := sdk.NewDec(rand.Int63n(d.NumDistinct)) - if rand.Float64() < 0.5 { - return d.Min.Add(d.Max.Sub(d.Min).QuoInt64(d.NumDistinct).Mul(steps)) - } - return d.Max.Add(d.Max.Sub(d.Min).QuoInt64(d.NumDistinct).Mul(steps)) -} - -type MsgTypeDistribution struct { - LimitOrderPct sdk.Dec `json:"limit_order_percentage"` - MarketOrderPct sdk.Dec `json:"market_order_percentage"` -} - -func (d *MsgTypeDistribution) Sample() string { - if !d.LimitOrderPct.Add(d.MarketOrderPct).Equal(sdk.OneDec()) { - panic("Distribution percentages must add up to 1") - } - randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) - if randNum.LT(d.LimitOrderPct) { - return Limit - } - return Market -} - -type ContractDistributions []ContractDistribution - -func (d *ContractDistributions) Sample() string { - if !utils.Reduce(*d, func(i ContractDistribution, o sdk.Dec) sdk.Dec { return o.Add(i.Percentage) }, sdk.ZeroDec()).Equal(sdk.OneDec()) { - panic("Distribution percentages must add up to 1") - } - randNum := sdk.MustNewDecFromStr(fmt.Sprintf("%f", rand.Float64())) - cumPct := sdk.ZeroDec() - for _, dist := range *d { - cumPct = cumPct.Add(dist.Percentage) - if randNum.LTE(cumPct) { - return dist.ContractAddr - } - } - panic("this should never be triggered") -} - -type ContractDistribution struct { - ContractAddr string `json:"contract_address"` - Percentage sdk.Dec `json:"percentage"` -} From da7faa82f9552ee622cd6e03c1cf18f9ab9edfcb Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 15/41] Revert "Optimize genesis account creation script (#320)" This reverts commit a0c0306f1a28ae82769e9770d6ac3019c6647c4e. --- loadtest/scripts/populate_genesis_accounts.py | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/loadtest/scripts/populate_genesis_accounts.py b/loadtest/scripts/populate_genesis_accounts.py index dc63b713dc..f2e8e8ece1 100644 --- a/loadtest/scripts/populate_genesis_accounts.py +++ b/loadtest/scripts/populate_genesis_accounts.py @@ -21,7 +21,6 @@ def add_key(account_name, local=False): stderr=subprocess.STDOUT, shell=True, ).decode() - splitted_outputs = add_key_output.split('\n') address = splitted_outputs[3].split(': ')[1] mnemonic = splitted_outputs[11] @@ -68,28 +67,6 @@ def create_genesis_account(account_index, account_name, local=False): retry_counter += 1 sleep_time += 0.5 time.sleep(sleep_time) - - if retry_counter >= 1000: - exit(-1) - - global_accounts_mapping[account_index] = { - "balance": { - "address": address, - "coins": [ - { - "denom": "usei", - "amount": "1000000000" - } - ] - }, - "account": { - "@type": "/cosmos.auth.v1beta1.BaseAccount", - "address": address, - "pub_key": None, - "account_number": "0", - "sequence": "0" - } - } if retry_counter >= 1000: exit(-1) From 03e0f6c1f6b59035e0c75eeef2bbc84ee8e531ad Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 16/41] Revert "Wasm gov (#316)" This reverts commit c3b421b6e25b6a7beeee39a02cc23e9333f13a6b. --- app/app.go | 3 +-- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/app.go b/app/app.go index add16601b4..294867fcf7 100644 --- a/app/app.go +++ b/app/app.go @@ -152,8 +152,7 @@ func getGovProposalHandlers() []govclient.ProposalHandler { upgradeclient.CancelProposalHandler, ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler, - aclclient.ResourceDependencyProposalHandler, - aclclient.WasmDependencyProposalHandler, + aclclient.ProposalHandler, // this line is used by starport scaffolding # stargate/app/govProposalHandler ) diff --git a/go.mod b/go.mod index ad37b8bff5..691228a071 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.176 + 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 diff --git a/go.sum b/go.sum index 42cf1824a0..b700853bbc 100644 --- a/go.sum +++ b/go.sum @@ -1099,8 +1099,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.176 h1:6UgAcryRx6C+UlouHDjxuY7T7hj3nck91QoeppyPdLc= -github.com/sei-protocol/sei-cosmos v0.1.176/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= From 8586b182d04a53c5f3f95d9650ba0c3b614341b6 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 17/41] Revert "Lazy Deposit All Module Accounts During EndBlock (#313)" This reverts commit 5ad4d9b9af8989df69746ebc9b035f1d9dfc8421. --- aclmapping/utils/identifier_templates.go | 22 +--------------------- app/abci.go | 10 +++++----- app/ante.go | 4 ++-- app/antedecorators/gasless.go | 20 -------------------- app/app.go | 10 ++-------- go.mod | 6 +++--- go.sum | 11 +++++------ loadtest/scripts/metrics.py | 3 --- x/oracle/ante.go | 21 +-------------------- 9 files changed, 19 insertions(+), 88 deletions(-) diff --git a/aclmapping/utils/identifier_templates.go b/aclmapping/utils/identifier_templates.go index ac28dad9ff..64685af380 100644 --- a/aclmapping/utils/identifier_templates.go +++ b/aclmapping/utils/identifier_templates.go @@ -1,11 +1,6 @@ package util -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" -) +import "fmt" const ( ACCOUNT = "acc" @@ -21,18 +16,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, - IdentifierTemplate: GetIdentifierTemplatePerModule("oracle", feederAddr.String()), - }, - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: GetIdentifierTemplatePerModule("oracle", valAddr.String()), - }, - } -} diff --git a/app/abci.go b/app/abci.go index bcaf0de3d6..10a841bd1e 100644 --- a/app/abci.go +++ b/app/abci.go @@ -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) } diff --git a/app/ante.go b/app/ante.go index 857d4f3127..f72e14aace 100644 --- a/app/ante.go +++ b/app/ante.go @@ -79,8 +79,8 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk sdk.DefaultWrappedAnteDecorator(ante.NewValidateBasicDecorator()), sdk.DefaultWrappedAnteDecorator(ante.NewTxTimeoutHeightDecorator()), sdk.DefaultWrappedAnteDecorator(ante.NewValidateMemoDecorator(options.AccountKeeper)), - ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), - ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker), + sdk.CustomDepWrappedAnteDecorator(ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper), depdecorators.SignerDepDecorator{ReadOnly: true}), + sdk.DefaultWrappedAnteDecorator(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 diff --git a/app/antedecorators/gasless.go b/app/antedecorators/gasless.go index b4de31d13d..ea9d39999e 100644 --- a/app/antedecorators/gasless.go +++ b/app/antedecorators/gasless.go @@ -4,8 +4,6 @@ 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" nitrokeeper "github.com/sei-protocol/sei-chain/x/nitro/keeper" nitrotypes "github.com/sei-protocol/sei-chain/x/nitro/types" @@ -46,24 +44,6 @@ func (gd GaslessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, return next(ctx, 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.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 - default: - continue - } - } - - return next(append(txDeps, deps...), tx) -} - func isTxGasless(tx sdk.Tx, ctx sdk.Context, oracleKeeper oraclekeeper.Keeper, nitroKeeper nitrokeeper.Keeper) bool { if len(tx.GetMsgs()) == 0 { // empty TX shouldn't be gasless diff --git a/app/app.go b/app/app.go index 294867fcf7..d1b8a25d01 100644 --- a/app/app.go +++ b/app/app.go @@ -1041,7 +1041,6 @@ 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) } @@ -1102,7 +1101,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).WithContextMemCache(sdk.NewContextMemCache()) + ctx = ctx.WithContext(goCtx) events := []abci.Event{} beginBlockReq := abci.RequestBeginBlock{ @@ -1142,7 +1141,6 @@ 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 { @@ -1155,6 +1153,7 @@ 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)) @@ -1166,14 +1165,9 @@ 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 diff --git a/go.mod b/go.mod index 691228a071..079cc07821 100644 --- a/go.mod +++ b/go.mod @@ -89,7 +89,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.16 // indirect + github.com/mattn/go-isatty v0.0.14 // 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 @@ -123,7 +123,7 @@ require ( golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect - golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect + golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect golang.org/x/text v0.3.8 // indirect gopkg.in/ini.v1 v1.66.4 // indirect @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.175 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.153 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 diff --git a/go.sum b/go.sum index b700853bbc..f9d4ef9745 100644 --- a/go.sum +++ b/go.sum @@ -810,9 +810,8 @@ 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= @@ -1099,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.175 h1:JFeAe8NeUvAnt4423O51HLzePN2WTmLHWv8iXeWZTA0= -github.com/sei-protocol/sei-cosmos v0.1.175/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0= +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-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= @@ -1633,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-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg= +golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/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= diff --git a/loadtest/scripts/metrics.py b/loadtest/scripts/metrics.py index e698a930e8..55074b6b30 100644 --- a/loadtest/scripts/metrics.py +++ b/loadtest/scripts/metrics.py @@ -41,20 +41,17 @@ 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)": { diff --git a/x/oracle/ante.go b/x/oracle/ante.go index 3b3d37e93d..8cd469fda5 100644 --- a/x/oracle/ante.go +++ b/x/oracle/ante.go @@ -4,10 +4,8 @@ import ( "sync" 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" + "github.com/sei-protocol/sei-chain/x/oracle/keeper" "github.com/sei-protocol/sei-chain/x/oracle/types" ) @@ -47,23 +45,6 @@ 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) { - deps := []sdkacltypes.AccessOperation{} - for _, msg := range tx.GetMsgs() { - // 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)...) - 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() From 5296f2690605424e5a551bd9c859256420f392e0 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 18/41] Revert "Wasm signal (#305)" This reverts commit 206f2bb0bc9c34eddf8542036fe782c2004340ba. --- aclmapping/dependency_generator.go | 11 +- aclmapping/wasm/mappings.go | 35 +- app/app.go | 35 +- go.mod | 2 +- go.sum | 4 +- wasmbinding/encoder.go | 43 --- wasmbinding/message_plugin.go | 224 +++++------- wasmbinding/query_plugin.go | 150 -------- wasmbinding/test/message_handler_test.go | 131 ------- wasmbinding/test/query_test.go | 442 ----------------------- wasmbinding/wasm.go | 21 +- x/dex/module_test.go | 4 +- 12 files changed, 157 insertions(+), 945 deletions(-) delete mode 100644 wasmbinding/encoder.go delete mode 100644 wasmbinding/test/message_handler_test.go diff --git a/aclmapping/dependency_generator.go b/aclmapping/dependency_generator.go index beec9783a8..2d875e4022 100644 --- a/aclmapping/dependency_generator.go +++ b/aclmapping/dependency_generator.go @@ -1,16 +1,19 @@ package aclmapping import ( + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" aclbankmapping "github.com/sei-protocol/sei-chain/aclmapping/bank" acldexmapping "github.com/sei-protocol/sei-chain/aclmapping/dex" aclwasmmapping "github.com/sei-protocol/sei-chain/aclmapping/wasm" ) -type CustomDependencyGenerator struct{} +type CustomDependencyGenerator struct { + WasmKeeper wasmkeeper.Keeper +} -func NewCustomDependencyGenerator() CustomDependencyGenerator { - return CustomDependencyGenerator{} +func NewCustomDependencyGenerator(wasmKeeper wasmkeeper.Keeper) CustomDependencyGenerator { + return CustomDependencyGenerator{WasmKeeper: wasmKeeper} } func (customDepGen CustomDependencyGenerator) GetCustomDependencyGenerators() aclkeeper.DependencyGeneratorMap { @@ -18,7 +21,7 @@ func (customDepGen CustomDependencyGenerator) GetCustomDependencyGenerators() ac dependencyGeneratorMap.Merge(acldexmapping.GetDexDependencyGenerators()) dependencyGeneratorMap.Merge(aclbankmapping.GetBankDepedencyGenerator()) - wasmDependencyGenerators := aclwasmmapping.NewWasmDependencyGenerator() + wasmDependencyGenerators := aclwasmmapping.NewWasmDependencyGenerator(customDepGen.WasmKeeper) dependencyGeneratorMap.Merge(wasmDependencyGenerators.GetWasmDependencyGenerators()) return dependencyGeneratorMap diff --git a/aclmapping/wasm/mappings.go b/aclmapping/wasm/mappings.go index 17e8acaeca..4dc3d1d1e2 100644 --- a/aclmapping/wasm/mappings.go +++ b/aclmapping/wasm/mappings.go @@ -1,8 +1,10 @@ package aclwasmmapping import ( + "encoding/json" "fmt" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" @@ -16,10 +18,14 @@ var ( ErrWasmFunctionDependenciesDisabled = fmt.Errorf("wasm function dependency mapping disabled") ) -type WasmDependencyGenerator struct{} +type WasmDependencyGenerator struct { + WasmKeeper wasmkeeper.Keeper +} -func NewWasmDependencyGenerator() WasmDependencyGenerator { - return WasmDependencyGenerator{} +func NewWasmDependencyGenerator(wasmKeeper wasmkeeper.Keeper) WasmDependencyGenerator { + return WasmDependencyGenerator{ + WasmKeeper: wasmKeeper, + } } func (wasmDepGen WasmDependencyGenerator) GetWasmDependencyGenerators() aclkeeper.DependencyGeneratorMap { @@ -41,7 +47,28 @@ func (wasmDepGen WasmDependencyGenerator) WasmExecuteContractGenerator(keeper ac if err != nil { return []sdkacltypes.AccessOperation{}, err } - wasmDependencyMapping, err := keeper.GetWasmDependencyMapping(ctx, contractAddr) + contractInfo := wasmDepGen.WasmKeeper.GetContractInfo(ctx, contractAddr) + codeID := contractInfo.CodeID + + jsonObj := make(map[string]interface{}) + jsonErr := json.Unmarshal(executeContractMsg.Msg, &jsonObj) + var wasmFunction string + if jsonErr != nil { + // try unmarshalling to string for execute function with no params + jsonErr2 := json.Unmarshal(executeContractMsg.Msg, &wasmFunction) + if jsonErr2 != nil { + return []sdkacltypes.AccessOperation{}, ErrInvalidWasmFunction + } + } else { + if len(jsonObj) != 1 { + return []sdkacltypes.AccessOperation{}, ErrInvalidWasmFunction + } + for fieldName := range jsonObj { + // this should only run once based on the check above + wasmFunction = fieldName + } + } + wasmDependencyMapping, err := keeper.GetWasmFunctionDependencyMapping(ctx, codeID, wasmFunction) if err != nil { return []sdkacltypes.AccessOperation{}, err } diff --git a/app/app.go b/app/app.go index d1b8a25d01..82ae2aa66b 100644 --- a/app/app.go +++ b/app/app.go @@ -515,35 +515,10 @@ func New( app.keys[nitrotypes.StoreKey], app.GetSubspace(nitrotypes.ModuleName), ) - - customDependencyGenerators := aclmapping.NewCustomDependencyGenerator() - aclOpts = append(aclOpts, aclkeeper.WithDependencyGeneratorMappings(customDependencyGenerators.GetCustomDependencyGenerators())) - app.AccessControlKeeper = aclkeeper.NewKeeper( - appCodec, - app.keys[acltypes.StoreKey], - app.GetSubspace(acltypes.ModuleName), - aclOpts..., - ) // The last arguments can contain custom message handlers, and custom query handlers, // if we want to allow any custom callbacks supportedFeatures := "iterator,staking,stargate,sei" - wasmOpts = append( - wasmbinding.RegisterCustomPlugins( - &app.OracleKeeper, - &app.DexKeeper, - &app.EpochKeeper, - &app.TokenFactoryKeeper, - &app.AccountKeeper, - app.MsgServiceRouter(), - app.IBCKeeper.ChannelKeeper, - scopedWasmKeeper, - app.BankKeeper, - appCodec, - app.TransferKeeper, - app.AccessControlKeeper, - ), - wasmOpts..., - ) + wasmOpts = append(wasmbinding.RegisterCustomPlugins(&app.OracleKeeper, &app.DexKeeper, &app.EpochKeeper, &app.TokenFactoryKeeper, &app.AccountKeeper, app.MsgServiceRouter()), wasmOpts...) app.WasmKeeper = wasm.NewKeeper( appCodec, keys[wasm.StoreKey], @@ -567,6 +542,14 @@ func New( dexModule := dexmodule.NewAppModule(appCodec, app.DexKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper, app.tracingInfo) epochModule := epochmodule.NewAppModule(appCodec, app.EpochKeeper, app.AccountKeeper, app.BankKeeper) + customDependencyGenerators := aclmapping.NewCustomDependencyGenerator(app.WasmKeeper) + aclOpts = append(aclOpts, aclkeeper.WithDependencyGeneratorMappings(customDependencyGenerators.GetCustomDependencyGenerators())) + app.AccessControlKeeper = aclkeeper.NewKeeper( + appCodec, + app.keys[acltypes.StoreKey], + app.GetSubspace(acltypes.ModuleName), + aclOpts..., + ) // register the proposal types govRouter := govtypes.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). diff --git a/go.mod b/go.mod index 079cc07821..478a6bef13 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,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.114 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 diff --git a/go.sum b/go.sum index f9d4ef9745..4e2af0f748 100644 --- a/go.sum +++ b/go.sum @@ -1098,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.114 h1:Cy5MnBdvql5VJw5pC104DsivQxPg0xkvVOuq6VwDiRk= +github.com/sei-protocol/sei-cosmos v0.1.114/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= diff --git a/wasmbinding/encoder.go b/wasmbinding/encoder.go deleted file mode 100644 index b26971ebdf..0000000000 --- a/wasmbinding/encoder.go +++ /dev/null @@ -1,43 +0,0 @@ -package wasmbinding - -import ( - "encoding/json" - - wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - dexwasm "github.com/sei-protocol/sei-chain/x/dex/client/wasm" - tokenfactorywasm "github.com/sei-protocol/sei-chain/x/tokenfactory/client/wasm" -) - -type SeiWasmMessage struct { - PlaceOrders json.RawMessage `json:"place_orders,omitempty"` - CancelOrders json.RawMessage `json:"cancel_orders,omitempty"` - CreateDenom json.RawMessage `json:"create_denom,omitempty"` - MintTokens json.RawMessage `json:"mint_tokens,omitempty"` - BurnTokens json.RawMessage `json:"burn_tokens,omitempty"` - ChangeAdmin json.RawMessage `json:"change_admin,omitempty"` -} - -func CustomEncoder(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error) { - var parsedMessage SeiWasmMessage - if err := json.Unmarshal(msg, &parsedMessage); err != nil { - return []sdk.Msg{}, sdkerrors.Wrap(err, "Error parsing Sei Wasm Message") - } - switch { - case parsedMessage.PlaceOrders != nil: - return dexwasm.EncodeDexPlaceOrders(parsedMessage.PlaceOrders, sender) - case parsedMessage.CancelOrders != nil: - return dexwasm.EncodeDexCancelOrders(parsedMessage.CancelOrders, sender) - case parsedMessage.CreateDenom != nil: - return tokenfactorywasm.EncodeTokenFactoryCreateDenom(parsedMessage.CreateDenom, sender) - case parsedMessage.MintTokens != nil: - return tokenfactorywasm.EncodeTokenFactoryMint(parsedMessage.MintTokens, sender) - case parsedMessage.BurnTokens != nil: - return tokenfactorywasm.EncodeTokenFactoryBurn(parsedMessage.BurnTokens, sender) - case parsedMessage.ChangeAdmin != nil: - return tokenfactorywasm.EncodeTokenFactoryChangeAdmin(parsedMessage.ChangeAdmin, sender) - default: - return []sdk.Msg{}, wasmvmtypes.UnsupportedRequest{Kind: "Unknown Sei Wasm Message"} - } -} diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index e3776be2a6..bdc16ed355 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -1,157 +1,129 @@ package wasmbinding import ( - "fmt" + "encoding/json" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" wasmvmtypes "github.com/CosmWasm/wasmvm/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/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" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + "github.com/sei-protocol/sei-chain/wasmbinding/bindings" + dexwasm "github.com/sei-protocol/sei-chain/x/dex/client/wasm" + tokenfactorywasm "github.com/sei-protocol/sei-chain/x/tokenfactory/client/wasm" ) -var ErrUnexpectedWasmDependency = fmt.Errorf("unexpected wasm dependency detected") - -// forked from wasm -func CustomMessageHandler( +// CustomMessageDecorator returns decorator for custom CosmWasm bindings messages +func CustomMessageDecorator( router wasmkeeper.MessageRouter, - channelKeeper wasmtypes.ChannelKeeper, - capabilityKeeper wasmtypes.CapabilityKeeper, - bankKeeper wasmtypes.Burner, - unpacker codectypes.AnyUnpacker, - portSource wasmtypes.ICS20TransferPortSource, - aclKeeper aclkeeper.Keeper, -) wasmkeeper.Messenger { - encoders := wasmkeeper.DefaultEncoders(unpacker, portSource) - encoders = encoders.Merge( - &wasmkeeper.MessageEncoders{ - Custom: CustomEncoder, - }) - return wasmkeeper.NewMessageHandlerChain( - NewSDKMessageDependencyDecorator(wasmkeeper.NewSDKMessageHandler(router, encoders), aclKeeper, encoders), - wasmkeeper.NewIBCRawPacketHandler(channelKeeper, capabilityKeeper), - wasmkeeper.NewBurnCoinMessageHandler(bankKeeper), - ) + accountKeeper *authkeeper.AccountKeeper, +) func(wasmkeeper.Messenger) wasmkeeper.Messenger { + return func(old wasmkeeper.Messenger) wasmkeeper.Messenger { + return &CustomMessenger{ + router: router, + wrapped: old, + accountKeeper: accountKeeper, + } + } } -// SDKMessageHandler can handles messages that can be encoded into sdk.Message types and routed. -type SDKMessageDependencyDecorator struct { - wrapped wasmkeeper.Messenger - aclKeeper aclkeeper.Keeper - encoders wasmkeeper.MessageEncoders +type CustomMessenger struct { + router wasmkeeper.MessageRouter + wrapped wasmkeeper.Messenger + accountKeeper *authkeeper.AccountKeeper } -func NewSDKMessageDependencyDecorator(handler wasmkeeper.Messenger, aclKeeper aclkeeper.Keeper, encoders wasmkeeper.MessageEncoders) SDKMessageDependencyDecorator { - return SDKMessageDependencyDecorator{ - wrapped: handler, - aclKeeper: aclKeeper, - encoders: encoders, - } +type SeiWasmMessage struct { + PlaceOrders json.RawMessage `json:"place_orders,omitempty"` + CancelOrders json.RawMessage `json:"cancel_orders,omitempty"` + CreateDenom json.RawMessage `json:"create_denom,omitempty"` + MintTokens json.RawMessage `json:"mint_tokens,omitempty"` + BurnTokens json.RawMessage `json:"burn_tokens,omitempty"` + ChangeAdmin json.RawMessage `json:"change_admin,omitempty"` } -func BuildWasmDependencyLookupMap(accessOps []sdkacltypes.AccessOperation) map[acltypes.ResourceAccess]map[string]struct{} { - lookupMap := make(map[acltypes.ResourceAccess]map[string]struct{}) - for _, accessOp := range accessOps { - resourceAccess := acltypes.ResourceAccess{ - ResourceType: accessOp.ResourceType, - AccessType: accessOp.AccessType, - } - if _, ok := lookupMap[resourceAccess]; !ok { - // we haven't added any identifiers for this resource type, so lets initialize the nested map (set) - lookupMap[resourceAccess] = make(map[string]struct{}) - } - lookupMap[resourceAccess][accessOp.IdentifierTemplate] = struct{}{} - } - return lookupMap -} +var _ wasmkeeper.Messenger = &CustomMessenger{} -func GenerateAllowedResourceAccess(resource sdkacltypes.ResourceType, access sdkacltypes.AccessType) []acltypes.ResourceAccess { - // by default, write, and unknown are ok - accesses := []acltypes.ResourceAccess{ - { - ResourceType: resource, - AccessType: sdkacltypes.AccessType_WRITE, - }, - { - ResourceType: resource, - AccessType: sdkacltypes.AccessType_UNKNOWN, - }, - } - if access == sdkacltypes.AccessType_READ { - accesses = append(accesses, acltypes.ResourceAccess{ - ResourceType: resource, - AccessType: access, - }) +// DispatchMsg executes on the bindingMsgs +func (m *CustomMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) ([]sdk.Event, [][]byte, error) { + if msg.Custom != nil { + return m.DispatchCustomMsg(ctx, contractAddr, contractIBCPortID, msg) } - return accesses + return m.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) } -func AreDependenciesFulfilled(lookupMap map[acltypes.ResourceAccess]map[string]struct{}, accessOp sdkacltypes.AccessOperation) bool { - currResourceAccesses := GenerateAllowedResourceAccess(accessOp.ResourceType, accessOp.AccessType) - for _, currResourceAccess := range currResourceAccesses { - if identifierMap, ok := lookupMap[currResourceAccess]; ok { - if _, ok := identifierMap[accessOp.IdentifierTemplate]; ok { - // we found a proper listed dependency, we can go to the next access op - return true - } - } +// DispatchCustomMsg function is forked from wasmd. sdk.Msg will be validated and routed to the corresponding module msg server in this function. +func (m *CustomMessenger) DispatchCustomMsg( + ctx sdk.Context, + contractAddr sdk.AccAddress, + contractIBCPortID string, + msg wasmvmtypes.CosmosMsg, +) (events []sdk.Event, data [][]byte, err error) { + var parsedMessage SeiWasmMessage + if err := json.Unmarshal(msg.Custom, &parsedMessage); err != nil { + return nil, nil, bindings.ErrParsingSeiWasmMsg } - // what about parent resources - parentResources := accessOp.ResourceType.GetParentResources() - // for each of the parent resources, we need at least one to be defined in the wasmDependencies - for _, parentResource := range parentResources { - // make parent resource access with same access type - parentResourceAccesses := GenerateAllowedResourceAccess(parentResource, accessOp.AccessType) - // for each of the parent resources, we check to see if its in the lookup map (identifier doesnt matter bc parent) - for _, parentResourceAccess := range parentResourceAccesses { - if _, parentResourcePresent := lookupMap[parentResourceAccess]; parentResourcePresent { - // we can continue to the next access op - return true - } - } + var sdkMsgs []sdk.Msg + switch { + case parsedMessage.PlaceOrders != nil: + sdkMsgs, err = dexwasm.EncodeDexPlaceOrders(parsedMessage.PlaceOrders, contractAddr) + case parsedMessage.CancelOrders != nil: + sdkMsgs, err = dexwasm.EncodeDexCancelOrders(parsedMessage.CancelOrders, contractAddr) + case parsedMessage.CreateDenom != nil: + sdkMsgs, err = tokenfactorywasm.EncodeTokenFactoryCreateDenom(parsedMessage.CreateDenom, contractAddr) + case parsedMessage.MintTokens != nil: + sdkMsgs, err = tokenfactorywasm.EncodeTokenFactoryMint(parsedMessage.MintTokens, contractAddr) + case parsedMessage.BurnTokens != nil: + sdkMsgs, err = tokenfactorywasm.EncodeTokenFactoryBurn(parsedMessage.BurnTokens, contractAddr) + case parsedMessage.ChangeAdmin != nil: + sdkMsgs, err = tokenfactorywasm.EncodeTokenFactoryChangeAdmin(parsedMessage.ChangeAdmin, contractAddr) + default: + sdkMsgs, err = []sdk.Msg{}, wasmvmtypes.UnsupportedRequest{Kind: "Unknown Sei Wasm Message"} } - return false -} - -func (decorator SDKMessageDependencyDecorator) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error) { - sdkMsgs, err := decorator.encoders.Encode(ctx, contractAddr, contractIBCPortID, msg) if err != nil { return nil, nil, err } - // get the dependencies for the contract to validate against - wasmDependency, err := decorator.aclKeeper.GetWasmDependencyMapping(ctx, contractAddr) - // If no mapping exists, or mapping is disabled, this message would behave as blocking for all resources - if err == aclkeeper.ErrWasmDependencyMappingNotFound { - // no mapping, we can just continue - return decorator.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) - } - if err != nil { - return nil, nil, err + + for _, sdkMsg := range sdkMsgs { + res, err := m.handleSdkMessage(ctx, contractAddr, sdkMsg) + if err != nil { + return nil, nil, err + } + // append data + data = append(data, res.Data) + // append events + sdkEvents := make([]sdk.Event, len(res.Events)) + for i := range res.Events { + sdkEvents[i] = sdk.Event(res.Events[i]) + } + events = append(events, sdkEvents...) } - if !wasmDependency.Enabled { - // if not enabled, just move on - // TODO: confirm that this is ok, is there ever a case where we should still verify dependencies for a disabled dependency? IDTS - return decorator.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) + return events, data, nil +} + +// This function is forked from wasmd. sdk.Msg will be validated and routed to the corresponding module msg server in this function. +func (m *CustomMessenger) handleSdkMessage(ctx sdk.Context, contractAddr sdk.Address, msg sdk.Msg) (*sdk.Result, error) { + if err := msg.ValidateBasic(); err != nil { + return nil, err } - // convert wasm dependency to a map of resource access and identifier we can look up in - lookupMap := BuildWasmDependencyLookupMap(wasmDependency.AccessOps) - // wasm dependency enabled, we need to validate the message dependencies - for _, msg := range sdkMsgs { - accessOps := decorator.aclKeeper.GetMessageDependencies(ctx, msg) - // go through each access op, and check if there is a completion signal for it OR a parent - for _, accessOp := range accessOps { - // first check for our specific resource access AND identifier template - depsFulfilled := AreDependenciesFulfilled(lookupMap, accessOp) - if !depsFulfilled { - return nil, nil, ErrUnexpectedWasmDependency - } + // make sure this account can send it + for _, acct := range msg.GetSigners() { + if !acct.Equals(contractAddr) { + return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "contract doesn't have permission") } } - // we've gone through all of the messages - // and verified their dependencies with the declared dependencies in the wasm contract dependencies, we can process it now - return decorator.wrapped.DispatchMsg(ctx, contractAddr, contractIBCPortID, msg) + + // find the handler and execute it + if handler := m.router.Handler(msg); handler != nil { + // ADR 031 request type routing + msgResult, err := handler(ctx, msg) + return msgResult, err + } + // legacy sdk.Msg routing + // Assuming that the app developer has migrated all their Msgs to + // proto messages and has registered all `Msg services`, then this + // path should never be called, because all those Msgs should be + // registered within the `msgServiceRouter` already. + return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg) } diff --git a/wasmbinding/query_plugin.go b/wasmbinding/query_plugin.go index 6ae594f48b..f1dff2c603 100644 --- a/wasmbinding/query_plugin.go +++ b/wasmbinding/query_plugin.go @@ -3,12 +3,9 @@ package wasmbinding import ( "encoding/json" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/accesscontrol" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" ) const ( @@ -45,150 +42,3 @@ func CustomQuerier(qp *QueryPlugin) func(ctx sdk.Context, request json.RawMessag } } } - -type CustomQueryHandler struct { - QueryPlugins wasmkeeper.QueryPlugins - aclKeeper aclkeeper.Keeper -} - -func (queryHandler CustomQueryHandler) HandleQuery(ctx sdk.Context, caller sdk.AccAddress, request wasmvmtypes.QueryRequest) ([]byte, error) { - wasmDependency, err := queryHandler.aclKeeper.GetWasmDependencyMapping(ctx, caller) - // If no mapping exists, or mapping is disabled, this message would behave as blocking for all resources - needToCheckDependencies := true - if err == aclkeeper.ErrWasmDependencyMappingNotFound { - // no mapping, we can just continue - needToCheckDependencies = false - } - if err != nil { - return nil, err - } - if !wasmDependency.Enabled { - needToCheckDependencies = false - } - lookupMap := BuildWasmDependencyLookupMap(wasmDependency.AccessOps) - if request.Bank != nil { - // check for BANK resource type - accessOp := accesscontrol.AccessOperation{ - ResourceType: accesscontrol.ResourceType_KV_BANK, - AccessType: accesscontrol.AccessType_READ, - IdentifierTemplate: "*", - } - if needToCheckDependencies { - if !AreDependenciesFulfilled(lookupMap, accessOp) { - return nil, ErrUnexpectedWasmDependency - } - } - return queryHandler.QueryPlugins.Bank(ctx, request.Bank) - - } - if request.Custom != nil { - // TODO: specially break down the custom - var contractQuery SeiQueryWrapper - if err := json.Unmarshal(request.Custom, &contractQuery); err != nil { - return nil, sdkerrors.Wrap(err, "Error parsing request data") - } - resourceType := accesscontrol.ResourceType_ANY - switch contractQuery.Route { - case OracleRoute: - resourceType = accesscontrol.ResourceType_KV_ORACLE - case DexRoute: - resourceType = accesscontrol.ResourceType_KV_DEX - case EpochRoute: - resourceType = accesscontrol.ResourceType_KV_EPOCH - case TokenFactoryRoute: - resourceType = accesscontrol.ResourceType_KV // TODO: change this to tokenfactory when rebasing a newer sei cosmos version with the enum - } - accessOp := accesscontrol.AccessOperation{ - ResourceType: resourceType, - AccessType: accesscontrol.AccessType_READ, - IdentifierTemplate: "*", - } - if needToCheckDependencies { - if !AreDependenciesFulfilled(lookupMap, accessOp) { - return nil, ErrUnexpectedWasmDependency - } - } - return queryHandler.QueryPlugins.Custom(ctx, request.Custom) - } - if request.IBC != nil { - // check for ANY resource type - // TODO: do we need a special resource type for IBC? - accessOp := accesscontrol.AccessOperation{ - ResourceType: accesscontrol.ResourceType_ANY, - AccessType: accesscontrol.AccessType_READ, - IdentifierTemplate: "*", - } - if needToCheckDependencies { - if !AreDependenciesFulfilled(lookupMap, accessOp) { - return nil, ErrUnexpectedWasmDependency - } - } - return queryHandler.QueryPlugins.IBC(ctx, caller, request.IBC) - } - if request.Staking != nil { - // check for STAKING resource type - accessOp := accesscontrol.AccessOperation{ - ResourceType: accesscontrol.ResourceType_KV_STAKING, - AccessType: accesscontrol.AccessType_READ, - IdentifierTemplate: "*", - } - if needToCheckDependencies { - if !AreDependenciesFulfilled(lookupMap, accessOp) { - return nil, ErrUnexpectedWasmDependency - } - } - return queryHandler.QueryPlugins.Staking(ctx, request.Staking) - } - if request.Stargate != nil { - // check for ANY resource type - // TODO: determine what Stargate dependency granularity looks like - accessOp := accesscontrol.AccessOperation{ - ResourceType: accesscontrol.ResourceType_ANY, - AccessType: accesscontrol.AccessType_READ, - IdentifierTemplate: "*", - } - if needToCheckDependencies { - if !AreDependenciesFulfilled(lookupMap, accessOp) { - return nil, ErrUnexpectedWasmDependency - } - } - return queryHandler.QueryPlugins.Stargate(ctx, request.Stargate) - } - if request.Wasm != nil { - // check for WASM resource type - accessOp := accesscontrol.AccessOperation{ - ResourceType: accesscontrol.ResourceType_KV_WASM, - AccessType: accesscontrol.AccessType_READ, - IdentifierTemplate: "*", - } - if needToCheckDependencies { - if !AreDependenciesFulfilled(lookupMap, accessOp) { - return nil, ErrUnexpectedWasmDependency - } - } - return queryHandler.QueryPlugins.Wasm(ctx, request.Wasm) - } - return nil, wasmvmtypes.Unknown{} -} - -func NewCustomQueryHandler(queryPlugins wasmkeeper.QueryPlugins, aclKeeper aclkeeper.Keeper) wasmkeeper.WasmVMQueryHandler { - return CustomQueryHandler{ - QueryPlugins: queryPlugins, - aclKeeper: aclKeeper, - } -} - -func CustomQueryHandlerDecorator(aclKeeper aclkeeper.Keeper, customQueryPlugin QueryPlugin) func(wasmkeeper.WasmVMQueryHandler) wasmkeeper.WasmVMQueryHandler { - // validate stuff, otherwise use default handler - return func(old wasmkeeper.WasmVMQueryHandler) wasmkeeper.WasmVMQueryHandler { - queryPlugins, ok := old.(wasmkeeper.QueryPlugins) - if !ok { - panic("Invalid query plugins") - } - - queryPlugins = queryPlugins.Merge(&wasmkeeper.QueryPlugins{ - Custom: CustomQuerier(&customQueryPlugin), - }) - return NewCustomQueryHandler(queryPlugins, aclKeeper) - } -} diff --git a/wasmbinding/test/message_handler_test.go b/wasmbinding/test/message_handler_test.go deleted file mode 100644 index 20dd685c6e..0000000000 --- a/wasmbinding/test/message_handler_test.go +++ /dev/null @@ -1,131 +0,0 @@ -package wasmbinding - -import ( - "encoding/json" - "testing" - - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/accesscontrol" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/sei-protocol/sei-chain/app" - "github.com/sei-protocol/sei-chain/wasmbinding" - "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/proto/tendermint/types" -) - -type MockMessenger struct{} - -func (m MockMessenger) DispatchMsg(ctx sdk.Context, contractAddr sdk.AccAddress, contractIBCPortID string, msg wasmvmtypes.CosmosMsg) (events []sdk.Event, data [][]byte, err error) { - return []sdk.Event{{ - Type: "test", - Attributes: []abci.EventAttribute{}, - }}, nil, nil -} - -func TestMessageHandlerDependencyDecorator(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - defaultEncoders := wasmkeeper.DefaultEncoders(app.AppCodec(), app.TransferKeeper) - dependencyDecorator := wasmbinding.NewSDKMessageDependencyDecorator(MockMessenger{}, app.AccessControlKeeper, defaultEncoders) - testContext := app.NewContext(false, types.Header{}) - - // setup bank send message with aclkeeper - app.AccessControlKeeper.SetResourceDependencyMapping(testContext, accesscontrol.MessageDependencyMapping{ - MessageKey: string(acltypes.GenerateMessageKey(&banktypes.MsgSend{})), - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - DynamicEnabled: false, - }) - - // setup the wasm contract's dependency mapping - app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_ANY, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - - events, _, _ := dependencyDecorator.DispatchMsg(testContext, contractAddr, "test", wasmvmtypes.CosmosMsg{ - Bank: &wasmvmtypes.BankMsg{ - Send: &wasmvmtypes.SendMsg{ - ToAddress: "sdfasdf", - Amount: []wasmvmtypes.Coin{ - { - Denom: "usei", - Amount: "12345", - }, - }, - }, - }, - }) - // we should have received the test event - require.Equal(t, []sdk.Event{ - { - Type: "test", - Attributes: []abci.EventAttribute{}, - }, - }, events) - - app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "otherIdentifier", - }, - acltypes.CommitAccessOp(), - }, - }) - - _, _, err = dependencyDecorator.DispatchMsg(testContext, contractAddr, "test", wasmvmtypes.CosmosMsg{ - Bank: &wasmvmtypes.BankMsg{ - Send: &wasmvmtypes.SendMsg{ - ToAddress: "sdfasdf", - Amount: []wasmvmtypes.Coin{ - { - Denom: "usei", - Amount: "12345", - }, - }, - }, - }, - }) - // we expect an error now - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) - - // reenable wasm mapping that's correct - app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - // lets try with a message that wont decode properly - _, _, err = dependencyDecorator.DispatchMsg(testContext, contractAddr, "test", wasmvmtypes.CosmosMsg{ - Custom: json.RawMessage{}, - }) - require.Error(t, wasmtypes.ErrUnknownMsg, err) -} diff --git a/wasmbinding/test/query_test.go b/wasmbinding/test/query_test.go index f027cf88e3..924652deed 100644 --- a/wasmbinding/test/query_test.go +++ b/wasmbinding/test/query_test.go @@ -6,12 +6,8 @@ import ( "testing" "time" - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/accesscontrol" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" "github.com/sei-protocol/sei-chain/app" keepertest "github.com/sei-protocol/sei-chain/testutil/keeper" "github.com/sei-protocol/sei-chain/wasmbinding" @@ -31,7 +27,6 @@ import ( tokenfactorybinding "github.com/sei-protocol/sei-chain/x/tokenfactory/client/wasm/bindings" tokenfactorytypes "github.com/sei-protocol/sei-chain/x/tokenfactory/types" "github.com/stretchr/testify/require" - "github.com/tendermint/tendermint/proto/tendermint/types" ) func SetupWasmbindingTest(t *testing.T) (*app.TestWrapper, func(ctx sdk.Context, request json.RawMessage) ([]byte, error)) { @@ -414,440 +409,3 @@ func TestWasmGetCreatorInDenomFeeWhitelist(t *testing.T) { require.NoError(t, err) require.Equal(t, tokenfactorytypes.QueryCreatorInDenomFeeWhitelistResponse{Whitelisted: true}, parsedRes2) } - -func MockQueryPlugins() wasmkeeper.QueryPlugins { - return wasmkeeper.QueryPlugins{ - Bank: func(ctx sdk.Context, request *wasmvmtypes.BankQuery) ([]byte, error) { return []byte{}, nil }, - IBC: func(ctx sdk.Context, caller sdk.AccAddress, request *wasmvmtypes.IBCQuery) ([]byte, error) { - return []byte{}, nil - }, - Custom: func(ctx sdk.Context, request json.RawMessage) ([]byte, error) { - println("test") - return []byte{}, nil - }, - Stargate: func(ctx sdk.Context, request *wasmvmtypes.StargateQuery) ([]byte, error) { return []byte{}, nil }, - Staking: func(ctx sdk.Context, request *wasmvmtypes.StakingQuery) ([]byte, error) { return []byte{}, nil }, - Wasm: func(ctx sdk.Context, request *wasmvmtypes.WasmQuery) ([]byte, error) { return []byte{}, nil }, - } -} - -func TestQueryHandlerDependencyDecoratorBank(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_BANK, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Bank: &wasmvmtypes.BankQuery{}, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV_DEX, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Bank: &wasmvmtypes.BankQuery{}, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} - -func TestQueryHandlerDependencyDecoratorIBC(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_ANY, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - IBC: &wasmvmtypes.IBCQuery{}, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - IBC: &wasmvmtypes.IBCQuery{}, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} - -func TestQueryHandlerDependencyDecoratorStaking(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_STAKING, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Staking: &wasmvmtypes.StakingQuery{}, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV_DEX, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Staking: &wasmvmtypes.StakingQuery{}, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} - -func TestQueryHandlerDependencyDecoratorStargate(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_ANY, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Stargate: &wasmvmtypes.StargateQuery{}, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Stargate: &wasmvmtypes.StargateQuery{}, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} - -func TestQueryHandlerDependencyDecoratorWasm(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_WASM, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Wasm: &wasmvmtypes.WasmQuery{}, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_WRITE, - ResourceType: accesscontrol.ResourceType_KV_DEX, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Wasm: &wasmvmtypes.WasmQuery{}, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} - -func TestQueryHandlerDependencyDecoratorDex(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_DEX, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - customQuery, err := json.Marshal(wasmbinding.SeiQueryWrapper{ - Route: wasmbinding.DexRoute, - }) - require.NoError(t, err) - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Custom: customQuery, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_ORACLE, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Custom: customQuery, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} - -func TestQueryHandlerDependencyDecoratorOracle(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_ORACLE, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - customQuery, err := json.Marshal(wasmbinding.SeiQueryWrapper{ - Route: wasmbinding.OracleRoute, - }) - require.NoError(t, err) - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Custom: customQuery, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_BANK, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Custom: customQuery, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} - -func TestQueryHandlerDependencyDecoratorEpoch(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_EPOCH, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - customQuery, err := json.Marshal(wasmbinding.SeiQueryWrapper{ - Route: wasmbinding.EpochRoute, - }) - require.NoError(t, err) - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Custom: customQuery, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV_BANK, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Custom: customQuery, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} - -func TestQueryHandlerDependencyDecoratorTokenFactory(t *testing.T) { - app := app.Setup(false) - contractAddr, err := sdk.AccAddressFromBech32("sei1y3pxq5dp900czh0mkudhjdqjq5m8cpmmps8yjw") - require.NoError(t, err) - queryDecorator := wasmbinding.NewCustomQueryHandler(MockQueryPlugins(), app.AccessControlKeeper) - testContext := app.NewContext(false, types.Header{}) - - // setup the wasm contract's dependency mapping - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_KV, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - customQuery, err := json.Marshal(wasmbinding.SeiQueryWrapper{ - Route: wasmbinding.TokenFactoryRoute, - }) - require.NoError(t, err) - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Custom: customQuery, - }) - require.NoError(t, err) - - err = app.AccessControlKeeper.SetWasmDependencyMapping(testContext, contractAddr, accesscontrol.WasmDependencyMapping{ - Enabled: true, - AccessOps: []accesscontrol.AccessOperation{ - { - AccessType: accesscontrol.AccessType_READ, - ResourceType: accesscontrol.ResourceType_Mem, - IdentifierTemplate: "*", - }, - acltypes.CommitAccessOp(), - }, - }) - require.NoError(t, err) - - _, err = queryDecorator.HandleQuery(testContext, contractAddr, wasmvmtypes.QueryRequest{ - Custom: customQuery, - }) - require.Error(t, wasmbinding.ErrUnexpectedWasmDependency, err) -} diff --git a/wasmbinding/wasm.go b/wasmbinding/wasm.go index 5d13ae9206..99baf4f180 100644 --- a/wasmbinding/wasm.go +++ b/wasmbinding/wasm.go @@ -3,9 +3,6 @@ package wasmbinding import ( "github.com/CosmWasm/wasmd/x/wasm" wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" dexwasm "github.com/sei-protocol/sei-chain/x/dex/client/wasm" dexkeeper "github.com/sei-protocol/sei-chain/x/dex/keeper" @@ -24,12 +21,6 @@ func RegisterCustomPlugins( tokenfactory *tokenfactorykeeper.Keeper, accountKeeper *authkeeper.AccountKeeper, router wasmkeeper.MessageRouter, - channelKeeper wasmtypes.ChannelKeeper, - capabilityKeeper wasmtypes.CapabilityKeeper, - bankKeeper wasmtypes.Burner, - unpacker codectypes.AnyUnpacker, - portSource wasmtypes.ICS20TransferPortSource, - aclKeeper aclkeeper.Keeper, ) []wasmkeeper.Option { dexHandler := dexwasm.NewDexWasmQueryHandler(dex) oracleHandler := oraclewasm.NewOracleWasmQueryHandler(oracle) @@ -37,13 +28,15 @@ func RegisterCustomPlugins( tokenfactoryHandler := tokenfactorywasm.NewTokenFactoryWasmQueryHandler(tokenfactory) wasmQueryPlugin := NewQueryPlugin(oracleHandler, dexHandler, epochHandler, tokenfactoryHandler) - queryOpt := wasmkeeper.WithQueryHandlerDecorator(CustomQueryHandlerDecorator(aclKeeper, *wasmQueryPlugin)) - messengerHandlerOpt := wasmkeeper.WithMessageHandler( - CustomMessageHandler(router, channelKeeper, capabilityKeeper, bankKeeper, unpacker, portSource, aclKeeper), + queryPluginOpt := wasmkeeper.WithQueryPlugins(&wasmkeeper.QueryPlugins{ + Custom: CustomQuerier(wasmQueryPlugin), + }) + messengerDecoratorOpt := wasmkeeper.WithMessageHandlerDecorator( + CustomMessageDecorator(router, accountKeeper), ) return []wasm.Option{ - queryOpt, - messengerHandlerOpt, + queryPluginOpt, + messengerDecoratorOpt, } } diff --git a/x/dex/module_test.go b/x/dex/module_test.go index dc3d404936..2a125e7d05 100644 --- a/x/dex/module_test.go +++ b/x/dex/module_test.go @@ -185,7 +185,7 @@ func TestEndBlockLimitOrder(t *testing.T) { bankkeeper := testApp.BankKeeper bankkeeper.MintCoins(ctx, minttypes.ModuleName, amounts) bankkeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, testAccount, amounts) - wasm, err := ioutil.ReadFile("./testdata/mars.wasm") + wasm, err := ioutil.ReadFile("./testdata/clearing_house.wasm") if err != nil { panic(err) } @@ -201,7 +201,7 @@ func TestEndBlockLimitOrder(t *testing.T) { if err != nil { panic(err) } - dexkeeper.SetContract(ctx, &types.ContractInfo{CodeId: 123, ContractAddr: contractAddr.String(), NeedHook: false, NeedOrderMatching: true}) + dexkeeper.SetContract(ctx, &types.ContractInfo{CodeId: 123, ContractAddr: contractAddr.String(), NeedHook: true, NeedOrderMatching: true}) dexkeeper.AddRegisteredPair(ctx, contractAddr.String(), pair) dexutils.GetMemState(ctx.Context()).GetBlockOrders(ctx, utils.ContractAddress(contractAddr.String()), utils.GetPairString(&pair)).Add( &types.Order{ From 91dca961a0f62d6d971c47babb7a40238d89f3e7 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 19/41] Revert "Add dependencies for ante handlers that read/write accounts (#314)" This reverts commit 5d39f905aadbb15ae0a224c353e69ad7634dce8a. --- aclmapping/utils/identifier_templates.go | 5 --- app/ante.go | 11 +++---- app/antedecorators/depdecorators/signers.go | 35 --------------------- app/params/config.go | 2 +- 4 files changed, 6 insertions(+), 47 deletions(-) delete mode 100644 app/antedecorators/depdecorators/signers.go diff --git a/aclmapping/utils/identifier_templates.go b/aclmapping/utils/identifier_templates.go index 64685af380..fc03b665e2 100644 --- a/aclmapping/utils/identifier_templates.go +++ b/aclmapping/utils/identifier_templates.go @@ -3,7 +3,6 @@ package util import "fmt" const ( - ACCOUNT = "acc" BANK = "bank" AUTH = "auth" DefaultIDTemplate = "*" @@ -12,7 +11,3 @@ const ( func GetIdentifierTemplatePerModule(module string, identifier string) string { return fmt.Sprintf("%s/%s", module, identifier) } - -func GetPrefixedIdentifierTemplatePerModule(module string, identifier string, prefix string) string { - return fmt.Sprintf("%s/%s/%s", module, prefix, identifier) -} diff --git a/app/ante.go b/app/ante.go index f72e14aace..5ba304a256 100644 --- a/app/ante.go +++ b/app/ante.go @@ -9,7 +9,6 @@ import ( ibcante "github.com/cosmos/ibc-go/v3/modules/core/ante" ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" "github.com/sei-protocol/sei-chain/app/antedecorators" - "github.com/sei-protocol/sei-chain/app/antedecorators/depdecorators" "github.com/sei-protocol/sei-chain/utils/tracing" "github.com/sei-protocol/sei-chain/x/dex" dexkeeper "github.com/sei-protocol/sei-chain/x/dex/keeper" @@ -79,16 +78,16 @@ 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.NewConsumeGasForTxSizeDecorator(options.AccountKeeper)), sdk.DefaultWrappedAnteDecorator(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 - sdk.CustomDepWrappedAnteDecorator(ante.NewSetPubKeyDecorator(options.AccountKeeper), depdecorators.SignerDepDecorator{ReadOnly: false}), + sdk.DefaultWrappedAnteDecorator(ante.NewSetPubKeyDecorator(options.AccountKeeper)), sdk.DefaultWrappedAnteDecorator(ante.NewValidateSigCountDecorator(options.AccountKeeper)), - sdk.CustomDepWrappedAnteDecorator(ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), depdecorators.SignerDepDecorator{ReadOnly: true}), - sdk.CustomDepWrappedAnteDecorator(sequentialVerifyDecorator, depdecorators.SignerDepDecorator{ReadOnly: true}), - sdk.CustomDepWrappedAnteDecorator(ante.NewIncrementSequenceDecorator(options.AccountKeeper), depdecorators.SignerDepDecorator{ReadOnly: false}), + sdk.DefaultWrappedAnteDecorator(ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer)), + sdk.DefaultWrappedAnteDecorator(sequentialVerifyDecorator), + sdk.DefaultWrappedAnteDecorator(ante.NewIncrementSequenceDecorator(options.AccountKeeper)), sdk.DefaultWrappedAnteDecorator(ibcante.NewAnteDecorator(options.IBCKeeper)), sdk.DefaultWrappedAnteDecorator(dex.NewTickSizeMultipleDecorator(*options.DexKeeper)), } diff --git a/app/antedecorators/depdecorators/signers.go b/app/antedecorators/depdecorators/signers.go deleted file mode 100644 index f123e8dca5..0000000000 --- a/app/antedecorators/depdecorators/signers.go +++ /dev/null @@ -1,35 +0,0 @@ -package depdecorators - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - utils "github.com/sei-protocol/sei-chain/aclmapping/utils" -) - -type SignerDepDecorator struct { - ReadOnly bool -} - -func (d SignerDepDecorator) AnteDeps(txDeps []sdkacltypes.AccessOperation, tx sdk.Tx, next sdk.AnteDepGenerator) (newTxDeps []sdkacltypes.AccessOperation, err error) { - sigTx, ok := tx.(authsigning.SigVerifiableTx) - if !ok { - return txDeps, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type") - } - var accessType sdkacltypes.AccessType - if d.ReadOnly { - accessType = sdkacltypes.AccessType_READ - } else { - accessType = sdkacltypes.AccessType_WRITE - } - for _, signer := range sigTx.GetSigners() { - txDeps = append(txDeps, sdkacltypes.AccessOperation{ - AccessType: accessType, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetPrefixedIdentifierTemplatePerModule(utils.ACCOUNT, signer.String(), string(authtypes.AddressStoreKeyPrefix)), - }) - } - return next(txDeps, tx) -} diff --git a/app/params/config.go b/app/params/config.go index 1b6e8c7fe2..07a0c81595 100644 --- a/app/params/config.go +++ b/app/params/config.go @@ -21,7 +21,7 @@ const ( Bech32PrefixAccAddr = "sei" ) -var UnsafeBypassCommitTimeoutOverride = true +var UnsafeBypassCommitTimeoutOverride bool = true var ( // Bech32PrefixAccPub defines the Bech32 prefix of an account's public key. From fe02514b180037b980f297f1faa024da926e5ee6 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 20/41] Revert "Add Gasless decorator back and remove CountTxDecorator (#311)" This reverts commit 93fa4bd8d69031e4d473b742d66e7944cd2076b5. --- app/ante.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/ante.go b/app/ante.go index 5ba304a256..5714854fb4 100644 --- a/app/ante.go +++ b/app/ante.go @@ -45,6 +45,9 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk if options.WasmConfig == nil { return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") } + if options.TXCounterStoreKey == nil { + return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") + } if options.OracleKeeper == nil { return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "oracle keeper is required for ante builder") } @@ -71,8 +74,8 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk anteDecorators := []sdk.AnteFullDecorator{ sdk.DefaultWrappedAnteDecorator(ante.NewSetUpContextDecorator()), // 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)), sdk.DefaultWrappedAnteDecorator(wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit)), // after setup context to enforce limits early + sdk.DefaultWrappedAnteDecorator(wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey)), sdk.DefaultWrappedAnteDecorator(ante.NewRejectExtensionOptionsDecorator()), sdk.DefaultWrappedAnteDecorator(oracle.NewSpammingPreventionDecorator(*options.OracleKeeper)), sdk.DefaultWrappedAnteDecorator(ante.NewValidateBasicDecorator()), From 7b74049302e0f1106f162ae60e7b76967cb1a25f Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 21/41] Revert "Branch another cache for all transactions (#309)" This reverts commit c2ce1edbc9015532ac9ba1d49a4fea6419a44937. --- app/app.go | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/app/app.go b/app/app.go index 82ae2aa66b..f4f71dc06f 100644 --- a/app/app.go +++ b/app/app.go @@ -1001,14 +1001,6 @@ type ChannelResult struct { result *abci.ExecTxResult } -// cacheContext returns a new context based off of the provided context with -// a branched multi-store. -func (app *App) CacheContext(ctx sdk.Context) (sdk.Context, sdk.CacheMultiStore) { - ms := ctx.MultiStore() - msCache := ms.CacheMultiStore() - return ctx.WithMultiStore(msCache), msCache -} - func (app *App) ProcessTxConcurrent( ctx sdk.Context, txIndex int, @@ -1129,15 +1121,7 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ switch err { case nil: // Only run concurrently if no error - // Branch off the current context and pass a cached context to the concurrent delivered TXs that are shared. - // runTx will write to this ephermeral CacheMultiStore, after the process block is done, Write() is called on this - // CacheMultiStore where it writes the data to the parent store (DeliverState) in sorted Key order to maintain - // deterministic ordering between validators in the case of concurrent deliverTXs - 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() + txResults = app.ProcessBlockConcurrent(ctx, txs, dependencyDag.CompletionSignalingMap, dependencyDag.BlockingSignalsMap) case acltypes.ErrGovMsgInBlock: ctx.Logger().Info(fmt.Sprintf("Gov msg found while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) From ef42284b6f254b52fc7f7ad06eec1668992d598c Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 22/41] Revert "Add msg send dynamic access ops (#303)" This reverts commit 2c5f14eac0c41b8d717375026ea72e40cfadf1e1. --- aclmapping/bank/mappings.go | 82 ------------------------ aclmapping/dependency_generator.go | 2 - aclmapping/utils/identifier_templates.go | 13 ---- 3 files changed, 97 deletions(-) delete mode 100644 aclmapping/bank/mappings.go delete mode 100644 aclmapping/utils/identifier_templates.go diff --git a/aclmapping/bank/mappings.go b/aclmapping/bank/mappings.go deleted file mode 100644 index 3d65fa90ba..0000000000 --- a/aclmapping/bank/mappings.go +++ /dev/null @@ -1,82 +0,0 @@ -package aclbankmapping - -import ( - "fmt" - - 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" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - utils "github.com/sei-protocol/sei-chain/aclmapping/utils" -) - -var ErrorInvalidMsgType = fmt.Errorf("invalid message received for bank module") - -func GetBankDepedencyGenerator() aclkeeper.DependencyGeneratorMap { - dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - - // dex place orders - placeOrdersKey := acltypes.GenerateMessageKey(&banktypes.MsgSend{}) - dependencyGeneratorMap[placeOrdersKey] = MsgSendDependencyGenerator - - return dependencyGeneratorMap -} - -// TODO:: we can make resource types more granular (e.g KV_PARAM or KV_BANK_BALANCE) -func MsgSendDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - msgSend, ok := msg.(*banktypes.MsgSend) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrorInvalidMsgType - } - - accessOperations := []sdkacltypes.AccessOperation{ - // MsgSend also checks if the coin denom is enabled, but the information is from the params. - // Changing the param would require a gov proposal, which is synchrounos by default - - // Checks balance of sender - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.FromAddress), - }, - // Reduce the amount from the sender's balance - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.FromAddress), - }, - - // Checks balance for receiver - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.ToAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.BANK, msgSend.ToAddress), - }, - - // Tries to create the reciever's account if it doesn't exist - { - AccessType: sdkacltypes.AccessType_READ, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, msgSend.ToAddress), - }, - { - AccessType: sdkacltypes.AccessType_WRITE, - ResourceType: sdkacltypes.ResourceType_KV, - IdentifierTemplate: utils.GetIdentifierTemplatePerModule(utils.AUTH, msgSend.ToAddress), - }, - - // Last Operation should always be a commit - { - ResourceType: sdkacltypes.ResourceType_ANY, - AccessType: sdkacltypes.AccessType_COMMIT, - IdentifierTemplate: utils.DefaultIDTemplate, - }, - } - return accessOperations, nil -} diff --git a/aclmapping/dependency_generator.go b/aclmapping/dependency_generator.go index 2d875e4022..5544aaf7bb 100644 --- a/aclmapping/dependency_generator.go +++ b/aclmapping/dependency_generator.go @@ -3,7 +3,6 @@ package aclmapping import ( wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" - aclbankmapping "github.com/sei-protocol/sei-chain/aclmapping/bank" acldexmapping "github.com/sei-protocol/sei-chain/aclmapping/dex" aclwasmmapping "github.com/sei-protocol/sei-chain/aclmapping/wasm" ) @@ -20,7 +19,6 @@ func (customDepGen CustomDependencyGenerator) GetCustomDependencyGenerators() ac dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) dependencyGeneratorMap.Merge(acldexmapping.GetDexDependencyGenerators()) - dependencyGeneratorMap.Merge(aclbankmapping.GetBankDepedencyGenerator()) wasmDependencyGenerators := aclwasmmapping.NewWasmDependencyGenerator(customDepGen.WasmKeeper) dependencyGeneratorMap.Merge(wasmDependencyGenerators.GetWasmDependencyGenerators()) diff --git a/aclmapping/utils/identifier_templates.go b/aclmapping/utils/identifier_templates.go deleted file mode 100644 index fc03b665e2..0000000000 --- a/aclmapping/utils/identifier_templates.go +++ /dev/null @@ -1,13 +0,0 @@ -package util - -import "fmt" - -const ( - BANK = "bank" - AUTH = "auth" - DefaultIDTemplate = "*" -) - -func GetIdentifierTemplatePerModule(module string, identifier string) string { - return fmt.Sprintf("%s/%s", module, identifier) -} From 6c2ffc5e4f74dd619c9b1f2c1d9515a79f0dad3f Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 23/41] Revert "[ante] Add ante dep generator default behavior (#294)" This reverts commit 0ada1dbed91d410a161154133251831d2015e456. --- app/ante.go | 60 +++++++++++++++--------------- app/antedecorators/gasless_test.go | 10 ++--- app/antedecorators/traced_test.go | 14 +++---- app/app.go | 5 +-- go.mod | 2 +- go.sum | 4 +- 6 files changed, 46 insertions(+), 49 deletions(-) diff --git a/app/ante.go b/app/ante.go index 5714854fb4..74e28d85cc 100644 --- a/app/ante.go +++ b/app/ante.go @@ -32,30 +32,30 @@ type HandlerOptions struct { TracingInfo *tracing.Info } -func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk.AnteDepGenerator, error) { +func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") } if options.BankKeeper == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") } if options.SignModeHandler == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } if options.WasmConfig == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "wasm config is required for ante builder") } if options.TXCounterStoreKey == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder") } if options.OracleKeeper == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "oracle keeper is required for ante builder") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "oracle keeper is required for ante builder") } if options.NitroKeeper == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "nitro keeper is required for ante builder") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "nitro keeper is required for ante builder") } if options.TracingInfo == nil { - return nil, nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tracing info is required for ante builder") + return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "tracing info is required for ante builder") } sigGasConsumer := options.SigGasConsumer @@ -71,31 +71,29 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk // sigVerifyDecorator = ante.NewBatchSigVerificationDecorator(options.BatchVerifier, sequentialVerifyDecorator) // } - anteDecorators := []sdk.AnteFullDecorator{ - sdk.DefaultWrappedAnteDecorator(ante.NewSetUpContextDecorator()), // outermost AnteDecorator. SetUpContext must be called first + anteDecorators := []sdk.AnteDecorator{ + ante.NewSetUpContextDecorator(), // 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(wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit)), // after setup context to enforce limits early - sdk.DefaultWrappedAnteDecorator(wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey)), - sdk.DefaultWrappedAnteDecorator(ante.NewRejectExtensionOptionsDecorator()), - sdk.DefaultWrappedAnteDecorator(oracle.NewSpammingPreventionDecorator(*options.OracleKeeper)), - sdk.DefaultWrappedAnteDecorator(ante.NewValidateBasicDecorator()), - sdk.DefaultWrappedAnteDecorator(ante.NewTxTimeoutHeightDecorator()), - sdk.DefaultWrappedAnteDecorator(ante.NewValidateMemoDecorator(options.AccountKeeper)), - sdk.DefaultWrappedAnteDecorator(ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper)), - sdk.DefaultWrappedAnteDecorator(ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TxFeeChecker)), + wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit), // after setup context to enforce limits early + wasmkeeper.NewCountTXDecorator(options.TXCounterStoreKey), + ante.NewRejectExtensionOptionsDecorator(), + oracle.NewSpammingPreventionDecorator(*options.OracleKeeper), + ante.NewValidateBasicDecorator(), + ante.NewTxTimeoutHeightDecorator(), + ante.NewValidateMemoDecorator(options.AccountKeeper), + 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()), + antedecorators.NewPriorityDecorator(), // SetPubKeyDecorator must be called before all signature verification decorators - sdk.DefaultWrappedAnteDecorator(ante.NewSetPubKeyDecorator(options.AccountKeeper)), - sdk.DefaultWrappedAnteDecorator(ante.NewValidateSigCountDecorator(options.AccountKeeper)), - sdk.DefaultWrappedAnteDecorator(ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer)), - sdk.DefaultWrappedAnteDecorator(sequentialVerifyDecorator), - sdk.DefaultWrappedAnteDecorator(ante.NewIncrementSequenceDecorator(options.AccountKeeper)), - sdk.DefaultWrappedAnteDecorator(ibcante.NewAnteDecorator(options.IBCKeeper)), - sdk.DefaultWrappedAnteDecorator(dex.NewTickSizeMultipleDecorator(*options.DexKeeper)), + ante.NewSetPubKeyDecorator(options.AccountKeeper), + ante.NewValidateSigCountDecorator(options.AccountKeeper), + ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), + sequentialVerifyDecorator, + ante.NewIncrementSequenceDecorator(options.AccountKeeper), + ibcante.NewAnteDecorator(options.IBCKeeper), + dex.NewTickSizeMultipleDecorator(*options.DexKeeper), } - anteHandler, anteDepGenerator := sdk.ChainAnteDecorators(anteDecorators...) - - return anteHandler, anteDepGenerator, nil + return sdk.ChainAnteDecorators(anteDecorators...), nil } diff --git a/app/antedecorators/gasless_test.go b/app/antedecorators/gasless_test.go index 7fb68025bc..439588bb5b 100644 --- a/app/antedecorators/gasless_test.go +++ b/app/antedecorators/gasless_test.go @@ -46,12 +46,12 @@ func (tx FakeTx) ValidateBasic() error { func TestGaslessDecorator(t *testing.T) { output = "" - anteDecorators := []sdk.AnteFullDecorator{ - sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorOne{}), - sdk.DefaultWrappedAnteDecorator(antedecorators.NewGaslessDecorator([]sdk.AnteDecorator{FakeAnteDecoratorTwo{}}, oraclekeeper.Keeper{}, nitrokeeper.Keeper{})), - sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorThree{}), + anteDecorators := []sdk.AnteDecorator{ + FakeAnteDecoratorOne{}, + antedecorators.NewGaslessDecorator([]sdk.AnteDecorator{FakeAnteDecoratorTwo{}}, oraclekeeper.Keeper{}, nitrokeeper.Keeper{}), + FakeAnteDecoratorThree{}, } - chainedHandler, _ := sdk.ChainAnteDecorators(anteDecorators...) + chainedHandler := sdk.ChainAnteDecorators(anteDecorators...) chainedHandler(sdk.Context{}, FakeTx{}, false) require.Equal(t, "onetwothree", output) } diff --git a/app/antedecorators/traced_test.go b/app/antedecorators/traced_test.go index efbca5cc44..4207e5e7d8 100644 --- a/app/antedecorators/traced_test.go +++ b/app/antedecorators/traced_test.go @@ -11,15 +11,15 @@ import ( func TestTracedDecorator(t *testing.T) { output = "" - anteDecorators := []sdk.AnteFullDecorator{ - sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorOne{}), - sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorTwo{}), - sdk.DefaultWrappedAnteDecorator(FakeAnteDecoratorThree{}), + anteDecorators := []sdk.AnteDecorator{ + FakeAnteDecoratorOne{}, + FakeAnteDecoratorTwo{}, + FakeAnteDecoratorThree{}, } - tracedDecorators := utils.Map(anteDecorators, func(d sdk.AnteFullDecorator) sdk.AnteFullDecorator { - return sdk.DefaultWrappedAnteDecorator(antedecorators.NewTracedAnteDecorator(d, nil)) + tracedDecorators := utils.Map(anteDecorators, func(d sdk.AnteDecorator) sdk.AnteDecorator { + return antedecorators.NewTracedAnteDecorator(d, nil) }) - chainedHandler, _ := sdk.ChainAnteDecorators(tracedDecorators...) + chainedHandler := sdk.ChainAnteDecorators(tracedDecorators...) chainedHandler(sdk.Context{}, FakeTx{}, false) require.Equal(t, "onetwothree", output) } diff --git a/app/app.go b/app/app.go index f4f71dc06f..fd26fb08da 100644 --- a/app/app.go +++ b/app/app.go @@ -754,7 +754,7 @@ func New( signModeHandler := encodingConfig.TxConfig.SignModeHandler() // app.batchVerifier = ante.NewSR25519BatchVerifier(app.AccountKeeper, signModeHandler) - anteHandler, anteDepGenerator, err := NewAnteHandlerAndDepGenerator( + anteHandler, err := NewAnteHandler( HandlerOptions{ HandlerOptions: ante.HandlerOptions{ AccountKeeper: app.AccountKeeper, @@ -778,7 +778,6 @@ func New( } app.SetAnteHandler(anteHandler) - app.SetAnteDepGenerator(anteDepGenerator) app.SetEndBlocker(app.EndBlocker) app.SetPrepareProposalHandler(app.PrepareProposalHandler) app.SetProcessProposalHandler(app.ProcessProposalHandler) @@ -1115,7 +1114,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) + dependencyDag, err := app.AccessControlKeeper.BuildDependencyDag(ctx, app.txDecoder, txs) var txResults []*abci.ExecTxResult switch err { diff --git a/go.mod b/go.mod index 478a6bef13..a9397c7473 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.114 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.105 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 diff --git a/go.sum b/go.sum index 4e2af0f748..61901fc63d 100644 --- a/go.sum +++ b/go.sum @@ -1098,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.114 h1:Cy5MnBdvql5VJw5pC104DsivQxPg0xkvVOuq6VwDiRk= -github.com/sei-protocol/sei-cosmos v0.1.114/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0= +github.com/sei-protocol/sei-cosmos v0.1.105 h1:45l/ZNaYrdyU87TNijE1OIciYI4wb3PXd95qr1HPAgE= +github.com/sei-protocol/sei-cosmos v0.1.105/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= From 644cdfa2ebcd91f2494b7a016264ef21d6b57d25 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 24/41] Revert "Add more parallel TX metrics (#296)" This reverts commit 567ffd951205b1be1f57460dcebd6191275054a6. --- app/app.go | 9 ++------ utils/metrics/labels.go | 6 ++---- utils/metrics/metrics_util.go | 40 ++++++++++++----------------------- 3 files changed, 18 insertions(+), 37 deletions(-) diff --git a/app/app.go b/app/app.go index fd26fb08da..6e79df1595 100644 --- a/app/app.go +++ b/app/app.go @@ -969,13 +969,11 @@ func (app *App) DeliverTxWithResult(ctx sdk.Context, tx []byte) *abci.ExecTxResu } func (app *App) ProcessBlockSynchronous(ctx sdk.Context, txs [][]byte) []*abci.ExecTxResult { - defer metrics.BlockProcessLatency(time.Now(), metrics.SYNCHRONOUS) - txResults := []*abci.ExecTxResult{} for _, tx := range txs { txResults = append(txResults, app.DeliverTxWithResult(ctx, tx)) - metrics.IncrTxProcessTypeCounter(metrics.SYNCHRONOUS) } + metrics.IncrTxProcessTypeCounter(metrics.SYNCHRONOUS) return txResults } @@ -1025,8 +1023,6 @@ func (app *App) ProcessBlockConcurrent( completionSignalingMap map[int]acltypes.MessageCompletionSignalMapping, blockingSignalsMap map[int]acltypes.MessageCompletionSignalMapping, ) []*abci.ExecTxResult { - defer metrics.BlockProcessLatency(time.Now(), metrics.CONCURRENT) - var waitGroup sync.WaitGroup resultChan := make(chan ChannelResult) txResults := []*abci.ExecTxResult{} @@ -1124,11 +1120,10 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ case acltypes.ErrGovMsgInBlock: ctx.Logger().Info(fmt.Sprintf("Gov msg found while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) - metrics.IncrDagBuildErrorCounter(metrics.GovMsgInBlock) + default: ctx.Logger().Error(fmt.Sprintf("Error while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) - metrics.IncrDagBuildErrorCounter(metrics.FailedToBuild) } endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{ diff --git a/utils/metrics/labels.go b/utils/metrics/labels.go index 282c97d060..85d8ff122b 100644 --- a/utils/metrics/labels.go +++ b/utils/metrics/labels.go @@ -1,8 +1,6 @@ package metrics const ( - CONCURRENT = "concurrent" - SYNCHRONOUS = "synchronous" - GovMsgInBlock = "gov-msg-in-block" - FailedToBuild = "failed-to-build" + CONCURRENT = "concurrent" + SYNCHRONOUS = "synchronous" ) diff --git a/utils/metrics/metrics_util.go b/utils/metrics/metrics_util.go index 6322357960..d3bb844bb8 100644 --- a/utils/metrics/metrics_util.go +++ b/utils/metrics/metrics_util.go @@ -54,32 +54,6 @@ func IncrTxProcessTypeCounter(processType string) { ) } -// Measures the time taken to process a block by the process type -// Metric Names: -// -// sei_process_block_miliseconds -// sei_process_block_miliseconds_count -// sei_process_block_miliseconds_sum -func BlockProcessLatency(start time.Time, processType string) { - metrics.MeasureSinceWithLabels( - []string{"sei", "process", "block", "milliseconds"}, - start.UTC(), - []metrics.Label{telemetry.NewLabel("type", processType)}, - ) -} - -// Measures the time taken to execute a sudo msg -// Metric Names: -// -// sei_tx_process_type_count -func IncrDagBuildErrorCounter(reason string) { - metrics.IncrCounterWithLabels( - []string{"sei", "dag", "build", "error"}, - 1, - []metrics.Label{telemetry.NewLabel("reason", reason)}, - ) -} - // Measures the time taken to execute a sudo msg // Metric Names: // @@ -92,3 +66,17 @@ func MeasureDeliverTxDuration(start time.Time) { start.UTC(), ) } + +// Measures the time taken to execute a sudo msg +// Metric Names: +// +// sei_dag_build_duration_miliseconds +// sei_dag_build_duration_miliseconds_count +// sei_dag_build_duration_miliseconds_sum +func MeasureBuildDagDuration(start time.Time, method string) { + metrics.MeasureSinceWithLabels( + []string{"sei", "dag", "build", "milliseconds"}, + start.UTC(), + []metrics.Label{telemetry.NewLabel("method", method)}, + ) +} From 638d70d0f22855a1a92a0b13ad3ec8289101c775 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 25/41] Revert "Add aclmapping options and mapping folder (#287)" This reverts commit c9522a540a2917b7a046e3af157e9bcb585845aa. --- aclmapping/dependency_generator.go | 26 ---------- aclmapping/dex/mappings.go | 34 ------------- aclmapping/wasm/mappings.go | 79 ------------------------------ app/app.go | 17 ++----- app/test_helpers.go | 2 - cmd/seid/cmd/root.go | 6 +-- go.mod | 2 +- go.sum | 4 +- testutil/network/network.go | 1 - 9 files changed, 10 insertions(+), 161 deletions(-) delete mode 100644 aclmapping/dependency_generator.go delete mode 100644 aclmapping/dex/mappings.go delete mode 100644 aclmapping/wasm/mappings.go diff --git a/aclmapping/dependency_generator.go b/aclmapping/dependency_generator.go deleted file mode 100644 index 5544aaf7bb..0000000000 --- a/aclmapping/dependency_generator.go +++ /dev/null @@ -1,26 +0,0 @@ -package aclmapping - -import ( - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" - acldexmapping "github.com/sei-protocol/sei-chain/aclmapping/dex" - aclwasmmapping "github.com/sei-protocol/sei-chain/aclmapping/wasm" -) - -type CustomDependencyGenerator struct { - WasmKeeper wasmkeeper.Keeper -} - -func NewCustomDependencyGenerator(wasmKeeper wasmkeeper.Keeper) CustomDependencyGenerator { - return CustomDependencyGenerator{WasmKeeper: wasmKeeper} -} - -func (customDepGen CustomDependencyGenerator) GetCustomDependencyGenerators() aclkeeper.DependencyGeneratorMap { - dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - - dependencyGeneratorMap.Merge(acldexmapping.GetDexDependencyGenerators()) - wasmDependencyGenerators := aclwasmmapping.NewWasmDependencyGenerator(customDepGen.WasmKeeper) - dependencyGeneratorMap.Merge(wasmDependencyGenerators.GetWasmDependencyGenerators()) - - return dependencyGeneratorMap -} diff --git a/aclmapping/dex/mappings.go b/aclmapping/dex/mappings.go deleted file mode 100644 index 58156eb64e..0000000000 --- a/aclmapping/dex/mappings.go +++ /dev/null @@ -1,34 +0,0 @@ -package acldexmapping - -import ( - "fmt" - - 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" - dexmoduletypes "github.com/sei-protocol/sei-chain/x/dex/types" -) - -var ErrPlaceOrdersGenerator = fmt.Errorf("invalid message received for type DexPlaceOrders") - -func GetDexDependencyGenerators() aclkeeper.DependencyGeneratorMap { - dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - - // dex place orders - placeOrdersKey := acltypes.GenerateMessageKey(&dexmoduletypes.MsgPlaceOrders{}) - dependencyGeneratorMap[placeOrdersKey] = DexPlaceOrdersDependencyGenerator - - return dependencyGeneratorMap -} - -func DexPlaceOrdersDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - placeOrdersMsg, ok := msg.(*dexmoduletypes.MsgPlaceOrders) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrPlaceOrdersGenerator - } - // TODO: This is not final, JUST AN EXAMPLE - return []sdkacltypes.AccessOperation{ - {AccessType: sdkacltypes.AccessType_WRITE, ResourceType: sdkacltypes.ResourceType_KV, IdentifierTemplate: placeOrdersMsg.ContractAddr}, - }, nil -} diff --git a/aclmapping/wasm/mappings.go b/aclmapping/wasm/mappings.go deleted file mode 100644 index 4dc3d1d1e2..0000000000 --- a/aclmapping/wasm/mappings.go +++ /dev/null @@ -1,79 +0,0 @@ -package aclwasmmapping - -import ( - "encoding/json" - "fmt" - - wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" - wasmtypes "github.com/CosmWasm/wasmd/x/wasm/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" -) - -var ( - ErrInvalidWasmExecuteMessage = fmt.Errorf("invalid message received for type WasmExecuteContract") - ErrInvalidWasmFunction = fmt.Errorf("unable to identify wasm function") - ErrWasmFunctionDependenciesDisabled = fmt.Errorf("wasm function dependency mapping disabled") -) - -type WasmDependencyGenerator struct { - WasmKeeper wasmkeeper.Keeper -} - -func NewWasmDependencyGenerator(wasmKeeper wasmkeeper.Keeper) WasmDependencyGenerator { - return WasmDependencyGenerator{ - WasmKeeper: wasmKeeper, - } -} - -func (wasmDepGen WasmDependencyGenerator) GetWasmDependencyGenerators() aclkeeper.DependencyGeneratorMap { - dependencyGeneratorMap := make(aclkeeper.DependencyGeneratorMap) - - // wasm execute - executeContractKey := acltypes.GenerateMessageKey(&wasmtypes.MsgExecuteContract{}) - dependencyGeneratorMap[executeContractKey] = wasmDepGen.WasmExecuteContractGenerator - - return dependencyGeneratorMap -} - -func (wasmDepGen WasmDependencyGenerator) WasmExecuteContractGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, msg sdk.Msg) ([]sdkacltypes.AccessOperation, error) { - executeContractMsg, ok := msg.(*wasmtypes.MsgExecuteContract) - if !ok { - return []sdkacltypes.AccessOperation{}, ErrInvalidWasmExecuteMessage - } - contractAddr, err := sdk.AccAddressFromBech32(executeContractMsg.Contract) - if err != nil { - return []sdkacltypes.AccessOperation{}, err - } - contractInfo := wasmDepGen.WasmKeeper.GetContractInfo(ctx, contractAddr) - codeID := contractInfo.CodeID - - jsonObj := make(map[string]interface{}) - jsonErr := json.Unmarshal(executeContractMsg.Msg, &jsonObj) - var wasmFunction string - if jsonErr != nil { - // try unmarshalling to string for execute function with no params - jsonErr2 := json.Unmarshal(executeContractMsg.Msg, &wasmFunction) - if jsonErr2 != nil { - return []sdkacltypes.AccessOperation{}, ErrInvalidWasmFunction - } - } else { - if len(jsonObj) != 1 { - return []sdkacltypes.AccessOperation{}, ErrInvalidWasmFunction - } - for fieldName := range jsonObj { - // this should only run once based on the check above - wasmFunction = fieldName - } - } - wasmDependencyMapping, err := keeper.GetWasmFunctionDependencyMapping(ctx, codeID, wasmFunction) - if err != nil { - return []sdkacltypes.AccessOperation{}, err - } - if !wasmDependencyMapping.Enabled { - return []sdkacltypes.AccessOperation{}, ErrWasmFunctionDependenciesDisabled - } - return wasmDependencyMapping.AccessOps, nil -} diff --git a/app/app.go b/app/app.go index 6e79df1595..4dcfe5cebb 100644 --- a/app/app.go +++ b/app/app.go @@ -14,7 +14,6 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/sei-protocol/sei-chain/aclmapping" appparams "github.com/sei-protocol/sei-chain/app/params" "github.com/sei-protocol/sei-chain/utils" "github.com/sei-protocol/sei-chain/wasmbinding" @@ -233,8 +232,6 @@ var ( // Boolean to only emit seid version and git commit metric once per chain initialization EmittedSeidVersionMetric bool = false - // EmptyAclmOpts defines a type alias for a list of wasm options. - EmptyACLOpts []aclkeeper.Option ) var ( @@ -351,7 +348,6 @@ func New( enabledProposals []wasm.ProposalType, appOpts servertypes.AppOptions, wasmOpts []wasm.Option, - aclOpts []aclkeeper.Option, baseAppOptions ...func(*baseapp.BaseApp), ) *App { appCodec := encodingConfig.Marshaler @@ -414,6 +410,11 @@ func New( // this line is used by starport scaffolding # stargate/app/scopedKeeper // add keepers + app.AccessControlKeeper = aclkeeper.NewKeeper( + appCodec, + app.keys[acltypes.StoreKey], + app.GetSubspace(acltypes.ModuleName), + ) app.AccountKeeper = authkeeper.NewAccountKeeper( appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, ) @@ -542,14 +543,6 @@ func New( dexModule := dexmodule.NewAppModule(appCodec, app.DexKeeper, app.AccountKeeper, app.BankKeeper, app.WasmKeeper, app.tracingInfo) epochModule := epochmodule.NewAppModule(appCodec, app.EpochKeeper, app.AccountKeeper, app.BankKeeper) - customDependencyGenerators := aclmapping.NewCustomDependencyGenerator(app.WasmKeeper) - aclOpts = append(aclOpts, aclkeeper.WithDependencyGeneratorMappings(customDependencyGenerators.GetCustomDependencyGenerators())) - app.AccessControlKeeper = aclkeeper.NewKeeper( - appCodec, - app.keys[acltypes.StoreKey], - app.GetSubspace(acltypes.ModuleName), - aclOpts..., - ) // register the proposal types govRouter := govtypes.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypes.ProposalHandler). diff --git a/app/test_helpers.go b/app/test_helpers.go index 406c9744fc..814b3b8604 100644 --- a/app/test_helpers.go +++ b/app/test_helpers.go @@ -140,7 +140,6 @@ func Setup(isCheckTx bool) *App { wasm.EnableAllProposals, &cosmostestutil.TestAppOpts{}, EmptyWasmOpts, - EmptyACLOpts, ) if !isCheckTx { genesisState := NewDefaultGenesisState(cdc) @@ -184,7 +183,6 @@ func SetupTestingAppWithLevelDb(isCheckTx bool) (*App, func()) { wasm.EnableAllProposals, &cosmostestutil.TestAppOpts{}, EmptyWasmOpts, - EmptyACLOpts, ) if !isCheckTx { genesisState := NewDefaultGenesisState(cdc) diff --git a/cmd/seid/cmd/root.go b/cmd/seid/cmd/root.go index cc1bd28d9c..ba67485460 100644 --- a/cmd/seid/cmd/root.go +++ b/cmd/seid/cmd/root.go @@ -21,7 +21,6 @@ import ( "github.com/cosmos/cosmos-sdk/snapshots" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -250,7 +249,6 @@ func newApp( wasm.EnableAllProposals, appOpts, []wasm.Option{}, - []aclkeeper.Option{}, baseapp.SetPruning(pruningOpts), baseapp.SetMinGasPrices(cast.ToString(appOpts.Get(server.FlagMinGasPrices))), baseapp.SetMinRetainBlocks(cast.ToUint64(appOpts.Get(server.FlagMinRetainBlocks))), @@ -286,12 +284,12 @@ func appExport( } if height != -1 { - exportableApp = app.New(logger, db, traceStore, false, map[int64]bool{}, cast.ToString(appOpts.Get(flags.FlagHome)), uint(1), encCfg, app.GetWasmEnabledProposals(), appOpts, app.EmptyWasmOpts, app.EmptyACLOpts) + exportableApp = app.New(logger, db, traceStore, false, map[int64]bool{}, cast.ToString(appOpts.Get(flags.FlagHome)), uint(1), encCfg, app.GetWasmEnabledProposals(), appOpts, app.EmptyWasmOpts) if err := exportableApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - exportableApp = app.New(logger, db, traceStore, true, map[int64]bool{}, cast.ToString(appOpts.Get(flags.FlagHome)), uint(1), encCfg, app.GetWasmEnabledProposals(), appOpts, app.EmptyWasmOpts, app.EmptyACLOpts) + exportableApp = app.New(logger, db, traceStore, true, map[int64]bool{}, cast.ToString(appOpts.Get(flags.FlagHome)), uint(1), encCfg, app.GetWasmEnabledProposals(), appOpts, app.EmptyWasmOpts) } return exportableApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs) diff --git a/go.mod b/go.mod index a9397c7473..3e6615eaa8 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.105 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.103 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 diff --git a/go.sum b/go.sum index 61901fc63d..d470efd348 100644 --- a/go.sum +++ b/go.sum @@ -1098,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.105 h1:45l/ZNaYrdyU87TNijE1OIciYI4wb3PXd95qr1HPAgE= -github.com/sei-protocol/sei-cosmos v0.1.105/go.mod h1:8ccWQxpBkWbpvBos/T4QO9K9gQxFs0duTqKRnagKo+0= +github.com/sei-protocol/sei-cosmos v0.1.103 h1:HIWnzmw3TuCtnGYqZj5jKbVztUqHU8rJm9eWQ8ji8po= +github.com/sei-protocol/sei-cosmos v0.1.103/go.mod h1:L4fVgFVReigFZAe+43UNhaCf3DQzUZvpN6LlBsWkub4= 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= diff --git a/testutil/network/network.go b/testutil/network/network.go index 67c394b375..84a7f7427e 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -60,7 +60,6 @@ func DefaultConfig() network.Config { wasm.EnableAllProposals, &simapp.EmptyAppOptions{}, nil, - app.EmptyACLOpts, baseapp.SetPruning(storetypes.NewPruningOptionsFromString(val.AppConfig.Pruning)), baseapp.SetMinGasPrices(val.AppConfig.MinGasPrices), ) From e7772cb53c2989028a85e1a5ce60f79d3ae8b3f9 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 26/41] Revert "Bump sei-cosmos and sei-tendermint for 2.0.0beta (#293)" This reverts commit d9254b6827308988bc2945f2085a5db6e5a975dc. --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3e6615eaa8..3fd86b9ba8 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.103 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.82 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 diff --git a/go.sum b/go.sum index d470efd348..6ef910b9b0 100644 --- a/go.sum +++ b/go.sum @@ -1098,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.103 h1:HIWnzmw3TuCtnGYqZj5jKbVztUqHU8rJm9eWQ8ji8po= -github.com/sei-protocol/sei-cosmos v0.1.103/go.mod h1:L4fVgFVReigFZAe+43UNhaCf3DQzUZvpN6LlBsWkub4= +github.com/sei-protocol/sei-cosmos v0.1.82 h1:vGsbp35KOZzP3YQoJ8T0MuWpLuC8Ea+6+F5QvHy9a5c= +github.com/sei-protocol/sei-cosmos v0.1.82/go.mod h1:L4fVgFVReigFZAe+43UNhaCf3DQzUZvpN6LlBsWkub4= 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= From 85cb4e6999d00b2a8f2e622a7d18684f56753f1f Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 27/41] Revert "Cherry-pick loadtesting changes and make a fix for parallel tx (#288)" This reverts commit 255fec90eb1f4a8cfcdd98101faad38c05ed0b03. --- app/app.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 4dcfe5cebb..ca0b8d1dd0 100644 --- a/app/app.go +++ b/app/app.go @@ -1002,8 +1002,8 @@ func (app *App) ProcessTxConcurrent( ) { defer wg.Done() // Store the Channels in the Context Object for each transaction - ctx = ctx.WithTxBlockingChannels(getChannelsFromSignalMapping(txBlockingSignalsMap)) - ctx = ctx.WithTxCompletionChannels(getChannelsFromSignalMapping(txCompletionSignalingMap)) + ctx.WithTxBlockingChannels(getChannelsFromSignalMapping(txBlockingSignalsMap)) + ctx.WithTxCompletionChannels(getChannelsFromSignalMapping(txCompletionSignalingMap)) // Deliver the transaction and store the result in the channel resultChan <- ChannelResult{txIndex, app.DeliverTxWithResult(ctx, txBytes)} From 3b9e8eb5111f8a15a64798e37d809a551095d2d4 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 28/41] Revert "[app] refactored graph into acl module (#286)" This reverts commit 9b2d20416c15e4f6401167b3bf1a24fc9381d9ab. --- app/app.go | 53 +++++++- app/graph.go | 321 ++++++++++++++++++++++++++++++++++++++++++++++ app/graph_test.go | 257 +++++++++++++++++++++++++++++++++++++ go.mod | 6 +- go.sum | 4 +- 5 files changed, 629 insertions(+), 12 deletions(-) create mode 100644 app/graph.go create mode 100644 app/graph_test.go diff --git a/app/app.go b/app/app.go index ca0b8d1dd0..4b358e2509 100644 --- a/app/app.go +++ b/app/app.go @@ -13,6 +13,7 @@ import ( "time" storetypes "github.com/cosmos/cosmos-sdk/store/types" + graph "github.com/yourbasic/graph" appparams "github.com/sei-protocol/sei-chain/app/params" "github.com/sei-protocol/sei-chain/utils" @@ -916,6 +917,44 @@ func (app *App) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestProcess }, nil } +func isGovMessage(msg sdk.Msg) bool { + switch msg.(type) { + case *govtypes.MsgVoteWeighted, *govtypes.MsgVote, *govtypes.MsgSubmitProposal, *govtypes.MsgDeposit: + return true + default: + return false + } +} + +func (app *App) BuildDependencyDag(ctx sdk.Context, txs [][]byte) (*Dag, error) { + defer metrics.MeasureBuildDagDuration(time.Now(), "BuildDependencyDag") + // contains the latest msg index for a specific Access Operation + dependencyDag := NewDag() + for txIndex, txBytes := range txs { + tx, err := app.txDecoder(txBytes) // TODO: results in repetitive decoding for txs with runtx decode (potential optimization) + if err != nil { + return nil, err + } + msgs := tx.GetMsgs() + for messageIndex, msg := range msgs { + if isGovMessage(msg) { + return nil, ErrGovMsgInBlock + } + msgDependencies := app.AccessControlKeeper.GetResourceDependencyMapping(ctx, acltypes.GenerateMessageKey(msg)) + for _, accessOp := range msgDependencies.GetAccessOps() { + // make a new node in the dependency dag + dependencyDag.AddNodeBuildDependency(messageIndex, txIndex, accessOp) + } + } + + } + + if !graph.Acyclic(&dependencyDag) { + return nil, ErrCycleInDAG + } + return &dependencyDag, nil +} + func (app *App) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) { startTime := time.Now() defer func() { @@ -971,7 +1010,7 @@ func (app *App) ProcessBlockSynchronous(ctx sdk.Context, txs [][]byte) []*abci.E } // Returns a mapping of the accessOperation to the channels -func getChannelsFromSignalMapping(signalMapping acltypes.MessageCompletionSignalMapping) sdkacltypes.MessageAccessOpsChannelMapping { +func getChannelsFromSignalMapping(signalMapping MessageCompletionSignalMapping) sdkacltypes.MessageAccessOpsChannelMapping { channelsMapping := make(sdkacltypes.MessageAccessOpsChannelMapping) for messageIndex, accessOperationsToSignal := range signalMapping { for accessOperation, completionSignals := range accessOperationsToSignal { @@ -997,8 +1036,8 @@ func (app *App) ProcessTxConcurrent( txBytes []byte, wg *sync.WaitGroup, resultChan chan<- ChannelResult, - txCompletionSignalingMap acltypes.MessageCompletionSignalMapping, - txBlockingSignalsMap acltypes.MessageCompletionSignalMapping, + txCompletionSignalingMap MessageCompletionSignalMapping, + txBlockingSignalsMap MessageCompletionSignalMapping, ) { defer wg.Done() // Store the Channels in the Context Object for each transaction @@ -1013,8 +1052,8 @@ func (app *App) ProcessTxConcurrent( func (app *App) ProcessBlockConcurrent( ctx sdk.Context, txs [][]byte, - completionSignalingMap map[int]acltypes.MessageCompletionSignalMapping, - blockingSignalsMap map[int]acltypes.MessageCompletionSignalMapping, + completionSignalingMap map[int]MessageCompletionSignalMapping, + blockingSignalsMap map[int]MessageCompletionSignalMapping, ) []*abci.ExecTxResult { var waitGroup sync.WaitGroup resultChan := make(chan ChannelResult) @@ -1103,14 +1142,14 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ // } // app.batchVerifier.VerifyTxs(ctx, typedTxs) - dependencyDag, err := app.AccessControlKeeper.BuildDependencyDag(ctx, app.txDecoder, txs) + dependencyDag, err := app.BuildDependencyDag(ctx, txs) var txResults []*abci.ExecTxResult switch err { case nil: // Only run concurrently if no error txResults = app.ProcessBlockConcurrent(ctx, txs, dependencyDag.CompletionSignalingMap, dependencyDag.BlockingSignalsMap) - case acltypes.ErrGovMsgInBlock: + case ErrGovMsgInBlock: ctx.Logger().Info(fmt.Sprintf("Gov msg found while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) diff --git a/app/graph.go b/app/graph.go new file mode 100644 index 0000000000..1b211bc61f --- /dev/null +++ b/app/graph.go @@ -0,0 +1,321 @@ +package app + +import ( + "fmt" + + acltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" + mapset "github.com/deckarep/golang-set" +) + +type DagNodeID int + +// Alias for mapping resource identifier to dag node IDs +type ResourceIdentifierNodeIDMapping = map[string][]DagNodeID + +type ResourceAccess struct { + ResourceType acltypes.ResourceType + AccessType acltypes.AccessType +} + +type DagNode struct { + NodeID DagNodeID + MessageIndex int + TxIndex int + AccessOperation acltypes.AccessOperation +} + +type DagEdge struct { + FromNodeID DagNodeID + ToNodeID DagNodeID +} + +type Dag struct { + NodeMap map[DagNodeID]DagNode + EdgesMap map[DagNodeID][]DagEdge // maps node Id (from node) and contains edge info + ResourceAccessMap map[ResourceAccess]ResourceIdentifierNodeIDMapping // maps resource type and access type to identifiers + node IDs + TxIndexMap map[int]DagNodeID // tracks latest node ID for a tx index + NextID DagNodeID + CompletionSignalingMap map[int]MessageCompletionSignalMapping // keys on tx index + BlockingSignalsMap map[int]MessageCompletionSignalMapping // keys on tx index +} + +// Alias for mapping MessageIndexId -> AccessOperations -> CompletionSignals +type MessageCompletionSignalMapping = map[int]map[acltypes.AccessOperation][]CompletionSignal + +type CompletionSignal struct { + FromNodeID DagNodeID + ToNodeID DagNodeID + CompletionAccessOperation acltypes.AccessOperation // this is the access operation that must complete in order to send the signal + BlockedAccessOperation acltypes.AccessOperation // this is the access operation that is blocked by the completion access operation + Channel chan interface{} +} + +func (dag *Dag) GetCompletionSignal(edge DagEdge) *CompletionSignal { + // only if tx indexes are different + fromNode := dag.NodeMap[edge.FromNodeID] + toNode := dag.NodeMap[edge.ToNodeID] + if fromNode.TxIndex == toNode.TxIndex { + // TODO: we may be able to remove this now since we don't created edges within a tx now + return nil + } + return &CompletionSignal{ + FromNodeID: fromNode.NodeID, + ToNodeID: toNode.NodeID, + CompletionAccessOperation: fromNode.AccessOperation, + BlockedAccessOperation: toNode.AccessOperation, + // channel used for signalling + Channel: make(chan interface{}), + } +} + +// Order returns the number of vertices in a graph. +func (dag Dag) Order() int { + return len(dag.NodeMap) +} + +// Visit calls the do function for each neighbor w of vertex v, used by the graph acyclic validator +func (dag Dag) Visit(v int, do func(w int, c int64) (skip bool)) (aborted bool) { + for _, edge := range dag.EdgesMap[DagNodeID(v)] { + // just have cost as zero because we only need for acyclic validation purposes + if do(int(edge.ToNodeID), 0) { + return true + } + } + return false +} + +func NewDag() Dag { + return Dag{ + NodeMap: make(map[DagNodeID]DagNode), + EdgesMap: make(map[DagNodeID][]DagEdge), + ResourceAccessMap: make(map[ResourceAccess]ResourceIdentifierNodeIDMapping), + TxIndexMap: make(map[int]DagNodeID), + NextID: 0, + CompletionSignalingMap: make(map[int]MessageCompletionSignalMapping), + BlockingSignalsMap: make(map[int]MessageCompletionSignalMapping), + } +} + +func GetResourceAccess(accessOp acltypes.AccessOperation) ResourceAccess { + return ResourceAccess{ + accessOp.ResourceType, + accessOp.AccessType, + } +} + +func (dag *Dag) AddNode(messageIndex int, txIndex int, accessOp acltypes.AccessOperation) DagNode { + dagNode := DagNode{ + NodeID: dag.NextID, + MessageIndex: messageIndex, + TxIndex: txIndex, + AccessOperation: accessOp, + } + dag.NodeMap[dag.NextID] = dagNode + dag.NextID++ + return dagNode +} + +func (dag *Dag) AddEdge(fromIndex DagNodeID, toIndex DagNodeID) *DagEdge { + // no-ops if the from or to node doesn't exist + if _, ok := dag.NodeMap[fromIndex]; !ok { + return nil + } + if _, ok := dag.NodeMap[toIndex]; !ok { + return nil + } + newEdge := DagEdge{fromIndex, toIndex} + dag.EdgesMap[fromIndex] = append(dag.EdgesMap[fromIndex], newEdge) + return &newEdge +} + +// This function is a helper used to build the dependency graph one access operation at a time. +// It will first add a node corresponding to the tx index and access operation (linking it to the previous most recent node for that tx if applicable) +// and then will build edges from any access operations on which the new node is dependent. +// +// This will be accomplished using the AccessOpsMap in dag which keeps track of which nodes access which resources. +// It will then create an edge between the relevant node upon which it is dependent, and this edge can later be used to build the completion signals +// that will allow the dependent goroutines to cordinate execution safely. +// +// It will also register the new node with AccessOpsMap so that future nodes that amy be dependent on this one can properly identify the dependency. +func (dag *Dag) AddNodeBuildDependency(messageIndex int, txIndex int, accessOp acltypes.AccessOperation) { + dagNode := dag.AddNode(messageIndex, txIndex, accessOp) + // update tx index map + dag.TxIndexMap[txIndex] = dagNode.NodeID + + nodeDependencies := dag.GetNodeDependencies(dagNode) + // build edges for each of the dependencies + for _, nodeDependency := range nodeDependencies { + edge := dag.AddEdge(nodeDependency, dagNode.NodeID) + // also add completion signal corresponding to the edge + if edge != nil { + maybeCompletionSignal := dag.GetCompletionSignal(*edge) + if maybeCompletionSignal != nil { + completionSignal := *maybeCompletionSignal + dag.AddCompletionSignal(completionSignal) + } + } + } + + // update access ops map with the latest node id using a specific access op + resourceAccess := GetResourceAccess(accessOp) + if _, exists := dag.ResourceAccessMap[resourceAccess]; !exists { + dag.ResourceAccessMap[resourceAccess] = make(ResourceIdentifierNodeIDMapping) + } + dag.ResourceAccessMap[resourceAccess][accessOp.IdentifierTemplate] = append(dag.ResourceAccessMap[resourceAccess][accessOp.IdentifierTemplate], dagNode.NodeID) +} + +func getAllNodeIDsFromIdentifierMapping(mapping ResourceIdentifierNodeIDMapping) (allNodeIDs []DagNodeID) { + for _, nodeIDs := range mapping { + allNodeIDs = append(allNodeIDs, nodeIDs...) + } + return +} + +func (dag *Dag) getDependencyWrites(node DagNode, dependentResource acltypes.ResourceType) mapset.Set { + nodeIDs := mapset.NewSet() + writeResourceAccess := ResourceAccess{ + dependentResource, + acltypes.AccessType_WRITE, + } + if identifierNodeMapping, ok := dag.ResourceAccessMap[writeResourceAccess]; ok { + var nodeIDsMaybeDependency []DagNodeID + if dependentResource != node.AccessOperation.ResourceType { + // we can add all node IDs as dependencies if applicable + nodeIDsMaybeDependency = getAllNodeIDsFromIdentifierMapping(identifierNodeMapping) + } else { + // TODO: otherwise we need to have partial filtering on identifiers + // for now, lets just perform exact matching on identifiers + nodeIDsMaybeDependency = identifierNodeMapping[node.AccessOperation.IdentifierTemplate] + } + for _, wn := range nodeIDsMaybeDependency { + writeNode := dag.NodeMap[wn] + // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) + // if from a previous transaction, we need to create an edge + if writeNode.TxIndex < node.TxIndex { + // this should be the COMMIT access op for the tx + lastTxNode := dag.NodeMap[dag.TxIndexMap[writeNode.TxIndex]] + nodeIDs.Add(lastTxNode.NodeID) + } + } + } + return nodeIDs +} + +func (dag *Dag) getDependencyUnknowns(node DagNode, dependentResource acltypes.ResourceType) mapset.Set { + nodeIDs := mapset.NewSet() + unknownResourceAccess := ResourceAccess{ + dependentResource, + acltypes.AccessType_UNKNOWN, + } + if identifierNodeMapping, ok := dag.ResourceAccessMap[unknownResourceAccess]; ok { + var nodeIDsMaybeDependency []DagNodeID + if dependentResource != node.AccessOperation.ResourceType { + // we can add all node IDs as dependencies if applicable + nodeIDsMaybeDependency = getAllNodeIDsFromIdentifierMapping(identifierNodeMapping) + } else { + // TODO: otherwise we need to have partial filtering on identifiers + // for now, lets just perform exact matching on identifiers + nodeIDsMaybeDependency = identifierNodeMapping[node.AccessOperation.IdentifierTemplate] + } + for _, un := range nodeIDsMaybeDependency { + uNode := dag.NodeMap[un] + // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) + // if from a previous transaction, we need to create an edge + if uNode.TxIndex < node.TxIndex { + // this should be the COMMIT access op for the tx + lastTxNode := dag.NodeMap[dag.TxIndexMap[uNode.TxIndex]] + nodeIDs.Add(lastTxNode.NodeID) + } + } + } + return nodeIDs +} + +func (dag *Dag) getDependencyReads(node DagNode, dependentResource acltypes.ResourceType) mapset.Set { + nodeIDs := mapset.NewSet() + readResourceAccess := ResourceAccess{ + dependentResource, + acltypes.AccessType_READ, + } + if identifierNodeMapping, ok := dag.ResourceAccessMap[readResourceAccess]; ok { + var nodeIDsMaybeDependency []DagNodeID + if dependentResource != node.AccessOperation.ResourceType { + // we can add all node IDs as dependencies if applicable + nodeIDsMaybeDependency = getAllNodeIDsFromIdentifierMapping(identifierNodeMapping) + } else { + // TODO: otherwise we need to have partial filtering on identifiers + // for now, lets just perform exact matching on identifiers + nodeIDsMaybeDependency = identifierNodeMapping[node.AccessOperation.IdentifierTemplate] + } + for _, rn := range nodeIDsMaybeDependency { + readNode := dag.NodeMap[rn] + // if from a previous transaction, we need to create an edge + if readNode.TxIndex < node.TxIndex { + nodeIDs.Add(readNode.NodeID) + } + } + } + return nodeIDs +} + +// given a node, and a dependent Resource, generate a set of nodes that are dependencies +func (dag *Dag) getNodeDependenciesForResource(node DagNode, dependentResource acltypes.ResourceType) mapset.Set { + nodeIDs := mapset.NewSet() + switch node.AccessOperation.AccessType { + case acltypes.AccessType_READ: + // for a read, we are blocked on prior writes and unknown + nodeIDs = nodeIDs.Union(dag.getDependencyWrites(node, dependentResource)) + nodeIDs = nodeIDs.Union(dag.getDependencyUnknowns(node, dependentResource)) + case acltypes.AccessType_WRITE, acltypes.AccessType_UNKNOWN: + // for write / unknown, we're blocked on prior writes, reads, and unknowns + nodeIDs = nodeIDs.Union(dag.getDependencyWrites(node, dependentResource)) + nodeIDs = nodeIDs.Union(dag.getDependencyUnknowns(node, dependentResource)) + nodeIDs = nodeIDs.Union(dag.getDependencyReads(node, dependentResource)) + } + return nodeIDs +} + +// This helper will identify nodes that are dependencies for the current node, and can then be used for creating edges between then for future completion signals +func (dag *Dag) GetNodeDependencies(node DagNode) []DagNodeID { + accessOp := node.AccessOperation + // get all parent resource types, we'll need to create edges for any of these + parentResources := accessOp.ResourceType.GetResourceDependencies() + nodeIDSet := mapset.NewSet() + for _, resource := range parentResources { + nodeIDSet = nodeIDSet.Union(dag.getNodeDependenciesForResource(node, resource)) + } + nodeDependencies := make([]DagNodeID, nodeIDSet.Cardinality()) + for i, x := range nodeIDSet.ToSlice() { + nodeDependencies[i] = x.(DagNodeID) + } + return nodeDependencies +} + +func (dag *Dag) AddCompletionSignal(completionSignal CompletionSignal) { + toNode := dag.NodeMap[completionSignal.ToNodeID] + if _, exists := dag.BlockingSignalsMap[toNode.TxIndex]; !exists { + dag.BlockingSignalsMap[toNode.TxIndex] = make(MessageCompletionSignalMapping) + } + if _, exists := dag.BlockingSignalsMap[toNode.TxIndex][toNode.MessageIndex]; !exists { + dag.BlockingSignalsMap[toNode.TxIndex][toNode.MessageIndex] = make(map[acltypes.AccessOperation][]CompletionSignal) + } + // add it to the right blocking signal in the right txindex + prevBlockSignalMapping := dag.BlockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] + dag.BlockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] = append(prevBlockSignalMapping, completionSignal) + + fromNode := dag.NodeMap[completionSignal.FromNodeID] + if _, exists := dag.CompletionSignalingMap[fromNode.TxIndex]; !exists { + dag.CompletionSignalingMap[fromNode.TxIndex] = make(MessageCompletionSignalMapping) + } + if _, exists := dag.CompletionSignalingMap[fromNode.TxIndex][fromNode.MessageIndex]; !exists { + dag.CompletionSignalingMap[fromNode.TxIndex][fromNode.MessageIndex] = make(map[acltypes.AccessOperation][]CompletionSignal) + } + // add it to the completion signal for the tx index + prevCompletionSignalMapping := dag.CompletionSignalingMap[fromNode.TxIndex][fromNode.MessageIndex][completionSignal.CompletionAccessOperation] + dag.CompletionSignalingMap[fromNode.TxIndex][fromNode.MessageIndex][completionSignal.CompletionAccessOperation] = append(prevCompletionSignalMapping, completionSignal) +} + +var ( + ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") + ErrGovMsgInBlock = fmt.Errorf("gov msg in block") +) diff --git a/app/graph_test.go b/app/graph_test.go new file mode 100644 index 0000000000..dea4c6c682 --- /dev/null +++ b/app/graph_test.go @@ -0,0 +1,257 @@ +package app_test + +import ( + "sort" + "testing" + + acltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" + "github.com/sei-protocol/sei-chain/app" + "github.com/stretchr/testify/require" + "github.com/yourbasic/graph" +) + +func TestCreateGraph(t *testing.T) { + dag := app.NewDag() + /** + tx1: write to A, read B, commit 1 + tx2: read A, read B, commit 2 + tx3: read A, read B, commit 3 + tx4: write B, commit 4 + expected dag + 1wA -> 1rB -> 1c =>v 2rA -> 2rB ----=\---> 2c + 3rB -------------> 3rA -> 3c V + \-----------------------------------=> 4wB -> 4c + **/ + + commitAccessOp := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_COMMIT, + ResourceType: acltypes.ResourceType_ANY, + IdentifierTemplate: "*", + } + writeAccessA := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_WRITE, + ResourceType: acltypes.ResourceType_KV, + IdentifierTemplate: "ResourceA", + } + readAccessA := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_READ, + ResourceType: acltypes.ResourceType_KV, + IdentifierTemplate: "ResourceA", + } + writeAccessB := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_WRITE, + ResourceType: acltypes.ResourceType_KV, + IdentifierTemplate: "ResourceB", + } + readAccessB := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_READ, + ResourceType: acltypes.ResourceType_KV, + IdentifierTemplate: "ResourceB", + } + + dag.AddNodeBuildDependency(0, 0, writeAccessA) // node id 0 + dag.AddNodeBuildDependency(0, 0, readAccessB) // node id 1 + dag.AddNodeBuildDependency(0, 0, commitAccessOp) // node id 2 + dag.AddNodeBuildDependency(0, 1, readAccessA) // node id 3 + dag.AddNodeBuildDependency(0, 1, readAccessB) // node id 4 + dag.AddNodeBuildDependency(0, 1, commitAccessOp) // node id 5 + dag.AddNodeBuildDependency(0, 2, readAccessB) // node id 6 + dag.AddNodeBuildDependency(0, 2, readAccessA) // node id 7 + dag.AddNodeBuildDependency(0, 2, commitAccessOp) // node id 8 + dag.AddNodeBuildDependency(0, 3, writeAccessB) // node id 9 + dag.AddNodeBuildDependency(0, 3, commitAccessOp) // node id 10 + + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[0]) + require.Equal( + t, + []app.DagEdge{{1, 9}}, + dag.EdgesMap[1], + ) + require.Equal( + t, + []app.DagEdge{{2, 3}, {2, 7}}, + dag.EdgesMap[2], + ) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[3]) + require.Equal( + t, + []app.DagEdge{{4, 9}}, + dag.EdgesMap[4], + ) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[5]) + require.Equal( + t, + []app.DagEdge{{6, 9}}, + dag.EdgesMap[6], + ) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[7]) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[8]) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[9]) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[10]) + + // assert dag is acyclic + acyclic := graph.Acyclic(dag) + require.True(t, acyclic) + + // test completion signals + completionSignalsMap, blockingSignalsMap := dag.CompletionSignalingMap, dag.BlockingSignalsMap + + channel0 := completionSignalsMap[0][0][commitAccessOp][0].Channel + channel1 := completionSignalsMap[0][0][commitAccessOp][1].Channel + channel2 := completionSignalsMap[1][0][readAccessB][0].Channel + channel3 := completionSignalsMap[0][0][readAccessB][0].Channel + channel4 := completionSignalsMap[2][0][readAccessB][0].Channel + + signal0 := app.CompletionSignal{2, 3, commitAccessOp, readAccessA, channel0} + signal1 := app.CompletionSignal{2, 7, commitAccessOp, readAccessA, channel1} + signal2 := app.CompletionSignal{4, 9, readAccessB, writeAccessB, channel2} + signal3 := app.CompletionSignal{1, 9, readAccessB, writeAccessB, channel3} + signal4 := app.CompletionSignal{6, 9, readAccessB, writeAccessB, channel4} + + require.Equal( + t, + []app.CompletionSignal{signal0, signal1}, + completionSignalsMap[0][0][commitAccessOp], + ) + require.Equal( + t, + []app.CompletionSignal{signal0}, + blockingSignalsMap[1][0][readAccessA], + ) + require.Equal( + t, + []app.CompletionSignal{signal1}, + blockingSignalsMap[2][0][readAccessA], + ) + + require.Equal( + t, + []app.CompletionSignal{signal2}, + completionSignalsMap[1][0][readAccessB], + ) + require.Equal( + t, + []app.CompletionSignal{signal3}, + completionSignalsMap[0][0][readAccessB], + ) + require.Equal( + t, + []app.CompletionSignal{signal4}, + completionSignalsMap[2][0][readAccessB], + ) + slice := blockingSignalsMap[3][0][writeAccessB] + sort.SliceStable(slice, func(p, q int) bool { + return slice[p].FromNodeID < slice[q].FromNodeID + }) + require.Equal( + t, + []app.CompletionSignal{signal3, signal2, signal4}, + slice, + ) +} + +func TestHierarchyDag(t *testing.T) { + dag := app.NewDag() + /** + tx1: write to A, commit 1 + tx2: read ALL, commit 2 + tx3: write B dexmem, commit 3 + tx4: read A, commit 4 + expected dag + 1wA -> 1c => 2rALL -> 2c + \ \=> 3wB c3 + \---=> 4rA c4 + **/ + + commit := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_COMMIT, + ResourceType: acltypes.ResourceType_ANY, + IdentifierTemplate: "*", + } + writeA := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_WRITE, + ResourceType: acltypes.ResourceType_KV, + IdentifierTemplate: "ResourceA", + } + readA := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_READ, + ResourceType: acltypes.ResourceType_KV, + IdentifierTemplate: "ResourceA", + } + writeB := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_WRITE, + ResourceType: acltypes.ResourceType_DexMem, + IdentifierTemplate: "ResourceB", + } + readAll := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_READ, + ResourceType: acltypes.ResourceType_ANY, + IdentifierTemplate: "*", + } + + dag.AddNodeBuildDependency(0, 0, writeA) // node id 0 + dag.AddNodeBuildDependency(0, 0, commit) // node id 1 + dag.AddNodeBuildDependency(0, 1, readAll) // node id 2 + dag.AddNodeBuildDependency(0, 1, commit) // node id 3 + dag.AddNodeBuildDependency(0, 2, writeB) // node id 4 + dag.AddNodeBuildDependency(0, 2, commit) // node id 5 + dag.AddNodeBuildDependency(0, 3, readA) // node id 6 + dag.AddNodeBuildDependency(0, 3, commit) // node id 7 + + // assert dag is acyclic + acyclic := graph.Acyclic(dag) + require.True(t, acyclic) + + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[0]) + require.Equal( + t, + []app.DagEdge{{1, 2}, {1, 6}}, + dag.EdgesMap[1], + ) + require.Equal( + t, + []app.DagEdge{{2, 4}}, + dag.EdgesMap[2], + ) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[3]) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[4]) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[5]) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[6]) + + // test completion signals + completionSignalsMap, blockingSignalsMap := dag.CompletionSignalingMap, dag.BlockingSignalsMap + + channel0 := completionSignalsMap[0][0][commit][0].Channel + channel1 := completionSignalsMap[0][0][commit][1].Channel + channel2 := completionSignalsMap[1][0][readAll][0].Channel + + signal0 := app.CompletionSignal{1, 2, commit, readAll, channel0} + signal1 := app.CompletionSignal{1, 6, commit, readA, channel1} + signal2 := app.CompletionSignal{2, 4, readAll, writeB, channel2} + + require.Equal( + t, + []app.CompletionSignal{signal0, signal1}, + completionSignalsMap[0][0][commit], + ) + require.Equal( + t, + []app.CompletionSignal{signal0}, + blockingSignalsMap[1][0][readAll], + ) + require.Equal( + t, + []app.CompletionSignal{signal1}, + blockingSignalsMap[3][0][readA], + ) + require.Equal( + t, + []app.CompletionSignal{signal2}, + completionSignalsMap[1][0][readAll], + ) + require.Equal( + t, + []app.CompletionSignal{signal2}, + blockingSignalsMap[2][0][writeB], + ) +} diff --git a/go.mod b/go.mod index 3fd86b9ba8..da7c0ddfa1 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/cosmos/cosmos-sdk v0.45.4 github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/ibc-go/v3 v3.0.0 + github.com/deckarep/golang-set v1.8.0 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.2 github.com/gorilla/mux v1.8.0 @@ -20,6 +21,7 @@ require ( github.com/stretchr/testify v1.8.0 github.com/tendermint/tendermint v0.37.0-dev github.com/tendermint/tm-db v0.6.8-0.20220519162814-e24b96538a12 + github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869 go.opentelemetry.io/otel v1.9.0 go.opentelemetry.io/otel/exporters/jaeger v1.9.0 go.opentelemetry.io/otel/sdk v1.9.0 @@ -48,7 +50,6 @@ require ( github.com/creachadair/taskgroup v0.3.2 // indirect github.com/danieljoos/wincred v1.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/deckarep/golang-set v1.8.0 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect github.com/dgraph-io/badger/v3 v3.2103.2 // indirect github.com/dgraph-io/ristretto v0.1.0 // indirect @@ -116,7 +117,6 @@ require ( github.com/tendermint/btcd v0.1.1 // indirect github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect github.com/tendermint/go-amino v0.16.0 // indirect - github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869 // indirect github.com/zondax/hid v0.9.0 // indirect go.etcd.io/bbolt v1.3.6 // indirect go.opencensus.io v0.23.0 // indirect @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.82 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.78 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 diff --git a/go.sum b/go.sum index 6ef910b9b0..95a945f5a3 100644 --- a/go.sum +++ b/go.sum @@ -1098,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.82 h1:vGsbp35KOZzP3YQoJ8T0MuWpLuC8Ea+6+F5QvHy9a5c= -github.com/sei-protocol/sei-cosmos v0.1.82/go.mod h1:L4fVgFVReigFZAe+43UNhaCf3DQzUZvpN6LlBsWkub4= +github.com/sei-protocol/sei-cosmos v0.1.78 h1:cPIp/vsmI7KFyP4fC7iyEQL77KXKIe4xUqIBk2XaJCo= +github.com/sei-protocol/sei-cosmos v0.1.78/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= 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= From ce94cd8c6c6c419d4f46e892a157dba283ce5c02 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 29/41] Revert "Add gov proposal handler for acl (#277)" This reverts commit bbb5a50c7415a1e8056bb868952f78dd2a94c7d5. --- app/app.go | 6 +----- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/app.go b/app/app.go index 4b358e2509..c195ba02ef 100644 --- a/app/app.go +++ b/app/app.go @@ -38,7 +38,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante" aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol" - aclclient "github.com/cosmos/cosmos-sdk/x/accesscontrol/client" aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" @@ -152,7 +151,6 @@ func getGovProposalHandlers() []govclient.ProposalHandler { upgradeclient.CancelProposalHandler, ibcclientclient.UpdateClientProposalHandler, ibcclientclient.UpgradeProposalHandler, - aclclient.ProposalHandler, // this line is used by starport scaffolding # stargate/app/govProposalHandler ) @@ -552,8 +550,7 @@ func New( AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). AddRoute(dexmoduletypes.RouterKey, dexmodule.NewProposalHandler(app.DexKeeper)). - AddRoute(tokenfactorytypes.RouterKey, tokenfactorymodule.NewProposalHandler(app.TokenFactoryKeeper)). - AddRoute(acltypes.ModuleName, aclmodule.NewProposalHandler(app.AccessControlKeeper)) + AddRoute(tokenfactorytypes.RouterKey, tokenfactorymodule.NewProposalHandler(app.TokenFactoryKeeper)) if len(enabledProposals) != 0 { govRouter.AddRoute(wasm.RouterKey, wasm.NewWasmProposalHandler(app.WasmKeeper, enabledProposals)) } @@ -1015,7 +1012,6 @@ func getChannelsFromSignalMapping(signalMapping MessageCompletionSignalMapping) for messageIndex, accessOperationsToSignal := range signalMapping { for accessOperation, completionSignals := range accessOperationsToSignal { var channels []chan interface{} - channelsMapping[messageIndex] = make(sdkacltypes.AccessOpsChannelMapping) for _, completionSignal := range completionSignals { channels = append(channels, completionSignal.Channel) } diff --git a/go.mod b/go.mod index da7c0ddfa1..deca309910 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.78 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.76 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 diff --git a/go.sum b/go.sum index 95a945f5a3..ba3e2871f2 100644 --- a/go.sum +++ b/go.sum @@ -1098,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.78 h1:cPIp/vsmI7KFyP4fC7iyEQL77KXKIe4xUqIBk2XaJCo= -github.com/sei-protocol/sei-cosmos v0.1.78/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= +github.com/sei-protocol/sei-cosmos v0.1.76 h1:y75Pn8hTc1SWndq/oMGzVu4mkF9ma6kVaA36AdFKxD8= +github.com/sei-protocol/sei-cosmos v0.1.76/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= 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= From 0beeec53fa6d494a833e4f915332987c9dccf0f7 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 30/41] Revert "Fix for DAG building switch cases (#282)" This reverts commit 9eebc8e9eef25e47c02fd0acf7ad261f199fea11. --- app/app.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/app.go b/app/app.go index c195ba02ef..c31092bebb 100644 --- a/app/app.go +++ b/app/app.go @@ -1141,17 +1141,16 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ dependencyDag, err := app.BuildDependencyDag(ctx, txs) var txResults []*abci.ExecTxResult + // TODO:: add metrics for async vs sync switch err { - case nil: - // Only run concurrently if no error - txResults = app.ProcessBlockConcurrent(ctx, txs, dependencyDag.CompletionSignalingMap, dependencyDag.BlockingSignalsMap) case ErrGovMsgInBlock: ctx.Logger().Info(fmt.Sprintf("Gov msg found while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) - - default: + case nil: ctx.Logger().Error(fmt.Sprintf("Error while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) + default: + txResults = app.ProcessBlockConcurrent(ctx, txs, dependencyDag.CompletionSignalingMap, dependencyDag.BlockingSignalsMap) } endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{ From 49d50816a3d8ed9ed17a80e285ca177a12080fa3 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 31/41] Revert "Optimize signals (#280)" This reverts commit fd9a3b689a902a3a9de8ec1ae3f541c3e3b45396. --- app/app.go | 3 +- app/graph.go | 98 ++++++++++++++++++++++++++--------------------- app/graph_test.go | 4 +- 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/app/app.go b/app/app.go index c31092bebb..33fe6b1e49 100644 --- a/app/app.go +++ b/app/app.go @@ -1150,7 +1150,8 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ ctx.Logger().Error(fmt.Sprintf("Error while building DAG, processing synchronously: %s", err)) txResults = app.ProcessBlockSynchronous(ctx, txs) default: - txResults = app.ProcessBlockConcurrent(ctx, txs, dependencyDag.CompletionSignalingMap, dependencyDag.BlockingSignalsMap) + completionSignalingMap, blockingSignalsMap := dependencyDag.BuildCompletionSignalMaps() + txResults = app.ProcessBlockConcurrent(ctx, txs, completionSignalingMap, blockingSignalsMap) } endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{ diff --git a/app/graph.go b/app/graph.go index 1b211bc61f..3c9f8edbdd 100644 --- a/app/graph.go +++ b/app/graph.go @@ -2,9 +2,11 @@ package app import ( "fmt" + "time" acltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" mapset "github.com/deckarep/golang-set" + "github.com/sei-protocol/sei-chain/utils/metrics" ) type DagNodeID int @@ -30,13 +32,11 @@ type DagEdge struct { } type Dag struct { - NodeMap map[DagNodeID]DagNode - EdgesMap map[DagNodeID][]DagEdge // maps node Id (from node) and contains edge info - ResourceAccessMap map[ResourceAccess]ResourceIdentifierNodeIDMapping // maps resource type and access type to identifiers + node IDs - TxIndexMap map[int]DagNodeID // tracks latest node ID for a tx index - NextID DagNodeID - CompletionSignalingMap map[int]MessageCompletionSignalMapping // keys on tx index - BlockingSignalsMap map[int]MessageCompletionSignalMapping // keys on tx index + NodeMap map[DagNodeID]DagNode + EdgesMap map[DagNodeID][]DagEdge // maps node Id (from node) and contains edge info + ResourceAccessMap map[ResourceAccess]ResourceIdentifierNodeIDMapping // maps resource type and access type to identifiers + node IDs + TxIndexMap map[int]DagNodeID // tracks latest node ID for a tx index + NextID DagNodeID } // Alias for mapping MessageIndexId -> AccessOperations -> CompletionSignals @@ -55,7 +55,6 @@ func (dag *Dag) GetCompletionSignal(edge DagEdge) *CompletionSignal { fromNode := dag.NodeMap[edge.FromNodeID] toNode := dag.NodeMap[edge.ToNodeID] if fromNode.TxIndex == toNode.TxIndex { - // TODO: we may be able to remove this now since we don't created edges within a tx now return nil } return &CompletionSignal{ @@ -86,13 +85,11 @@ func (dag Dag) Visit(v int, do func(w int, c int64) (skip bool)) (aborted bool) func NewDag() Dag { return Dag{ - NodeMap: make(map[DagNodeID]DagNode), - EdgesMap: make(map[DagNodeID][]DagEdge), - ResourceAccessMap: make(map[ResourceAccess]ResourceIdentifierNodeIDMapping), - TxIndexMap: make(map[int]DagNodeID), - NextID: 0, - CompletionSignalingMap: make(map[int]MessageCompletionSignalMapping), - BlockingSignalsMap: make(map[int]MessageCompletionSignalMapping), + NodeMap: make(map[DagNodeID]DagNode), + EdgesMap: make(map[DagNodeID][]DagEdge), + ResourceAccessMap: make(map[ResourceAccess]ResourceIdentifierNodeIDMapping), + TxIndexMap: make(map[int]DagNodeID), + NextID: 0, } } @@ -145,15 +142,7 @@ func (dag *Dag) AddNodeBuildDependency(messageIndex int, txIndex int, accessOp a nodeDependencies := dag.GetNodeDependencies(dagNode) // build edges for each of the dependencies for _, nodeDependency := range nodeDependencies { - edge := dag.AddEdge(nodeDependency, dagNode.NodeID) - // also add completion signal corresponding to the edge - if edge != nil { - maybeCompletionSignal := dag.GetCompletionSignal(*edge) - if maybeCompletionSignal != nil { - completionSignal := *maybeCompletionSignal - dag.AddCompletionSignal(completionSignal) - } - } + dag.AddEdge(nodeDependency, dagNode.NodeID) } // update access ops map with the latest node id using a specific access op @@ -291,28 +280,49 @@ func (dag *Dag) GetNodeDependencies(node DagNode) []DagNodeID { return nodeDependencies } -func (dag *Dag) AddCompletionSignal(completionSignal CompletionSignal) { - toNode := dag.NodeMap[completionSignal.ToNodeID] - if _, exists := dag.BlockingSignalsMap[toNode.TxIndex]; !exists { - dag.BlockingSignalsMap[toNode.TxIndex] = make(MessageCompletionSignalMapping) - } - if _, exists := dag.BlockingSignalsMap[toNode.TxIndex][toNode.MessageIndex]; !exists { - dag.BlockingSignalsMap[toNode.TxIndex][toNode.MessageIndex] = make(map[acltypes.AccessOperation][]CompletionSignal) - } - // add it to the right blocking signal in the right txindex - prevBlockSignalMapping := dag.BlockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] - dag.BlockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] = append(prevBlockSignalMapping, completionSignal) +// returns completion signaling map and blocking signals map +func (dag *Dag) BuildCompletionSignalMaps() ( + completionSignalingMap map[int]MessageCompletionSignalMapping, + blockingSignalsMap map[int]MessageCompletionSignalMapping, +) { + defer metrics.MeasureBuildDagDuration(time.Now(), "BuildCompletionSignalMaps") + completionSignalingMap = make(map[int]MessageCompletionSignalMapping) + blockingSignalsMap = make(map[int]MessageCompletionSignalMapping) + // go through every node + for _, node := range dag.NodeMap { + // for each node, assign its completion signaling, and also assign blocking signals for the destination nodes + if outgoingEdges, ok := dag.EdgesMap[node.NodeID]; ok { + for _, edge := range outgoingEdges { + maybeCompletionSignal := dag.GetCompletionSignal(edge) + if maybeCompletionSignal != nil { + completionSignal := *maybeCompletionSignal - fromNode := dag.NodeMap[completionSignal.FromNodeID] - if _, exists := dag.CompletionSignalingMap[fromNode.TxIndex]; !exists { - dag.CompletionSignalingMap[fromNode.TxIndex] = make(MessageCompletionSignalMapping) - } - if _, exists := dag.CompletionSignalingMap[fromNode.TxIndex][fromNode.MessageIndex]; !exists { - dag.CompletionSignalingMap[fromNode.TxIndex][fromNode.MessageIndex] = make(map[acltypes.AccessOperation][]CompletionSignal) + toNode := dag.NodeMap[edge.ToNodeID] + if _, exists := blockingSignalsMap[toNode.TxIndex]; !exists { + blockingSignalsMap[toNode.TxIndex] = make(MessageCompletionSignalMapping) + } + if _, exists := blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex]; !exists { + blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex] = make(map[acltypes.AccessOperation][]CompletionSignal) + } + // add it to the right blocking signal in the right txindex + prevBlockSignalMapping := blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] + blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] = append(prevBlockSignalMapping, completionSignal) + + if _, exists := completionSignalingMap[node.TxIndex]; !exists { + completionSignalingMap[node.TxIndex] = make(MessageCompletionSignalMapping) + } + if _, exists := completionSignalingMap[node.TxIndex][node.MessageIndex]; !exists { + completionSignalingMap[node.TxIndex][node.MessageIndex] = make(map[acltypes.AccessOperation][]CompletionSignal) + } + // add it to the completion signal for the tx index + prevCompletionSignalMapping := completionSignalingMap[node.TxIndex][node.MessageIndex][completionSignal.CompletionAccessOperation] + completionSignalingMap[node.TxIndex][node.MessageIndex][completionSignal.CompletionAccessOperation] = append(prevCompletionSignalMapping, completionSignal) + } + + } + } } - // add it to the completion signal for the tx index - prevCompletionSignalMapping := dag.CompletionSignalingMap[fromNode.TxIndex][fromNode.MessageIndex][completionSignal.CompletionAccessOperation] - dag.CompletionSignalingMap[fromNode.TxIndex][fromNode.MessageIndex][completionSignal.CompletionAccessOperation] = append(prevCompletionSignalMapping, completionSignal) + return completionSignalingMap, blockingSignalsMap } var ( diff --git a/app/graph_test.go b/app/graph_test.go index dea4c6c682..4b03d6793e 100644 --- a/app/graph_test.go +++ b/app/graph_test.go @@ -94,7 +94,7 @@ func TestCreateGraph(t *testing.T) { require.True(t, acyclic) // test completion signals - completionSignalsMap, blockingSignalsMap := dag.CompletionSignalingMap, dag.BlockingSignalsMap + completionSignalsMap, blockingSignalsMap := dag.BuildCompletionSignalMaps() channel0 := completionSignalsMap[0][0][commitAccessOp][0].Channel channel1 := completionSignalsMap[0][0][commitAccessOp][1].Channel @@ -219,7 +219,7 @@ func TestHierarchyDag(t *testing.T) { require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[6]) // test completion signals - completionSignalsMap, blockingSignalsMap := dag.CompletionSignalingMap, dag.BlockingSignalsMap + completionSignalsMap, blockingSignalsMap := dag.BuildCompletionSignalMaps() channel0 := completionSignalsMap[0][0][commit][0].Channel channel1 := completionSignalsMap[0][0][commit][1].Channel From 30860ef3d6ae1f2aba85ae4de844c3e43a7d4869 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 32/41] Revert "[app] Add behavior to process blocks with gov txs sync (#276)" This reverts commit ea2a9068039f3c97a40f95f08943fb13cc39130c. --- app/app.go | 26 ++++++-------------------- app/graph.go | 5 +---- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/app/app.go b/app/app.go index 33fe6b1e49..d63dbec6cf 100644 --- a/app/app.go +++ b/app/app.go @@ -914,15 +914,6 @@ func (app *App) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestProcess }, nil } -func isGovMessage(msg sdk.Msg) bool { - switch msg.(type) { - case *govtypes.MsgVoteWeighted, *govtypes.MsgVote, *govtypes.MsgSubmitProposal, *govtypes.MsgDeposit: - return true - default: - return false - } -} - func (app *App) BuildDependencyDag(ctx sdk.Context, txs [][]byte) (*Dag, error) { defer metrics.MeasureBuildDagDuration(time.Now(), "BuildDependencyDag") // contains the latest msg index for a specific Access Operation @@ -934,9 +925,6 @@ func (app *App) BuildDependencyDag(ctx sdk.Context, txs [][]byte) (*Dag, error) } msgs := tx.GetMsgs() for messageIndex, msg := range msgs { - if isGovMessage(msg) { - return nil, ErrGovMsgInBlock - } msgDependencies := app.AccessControlKeeper.GetResourceDependencyMapping(ctx, acltypes.GenerateMessageKey(msg)) for _, accessOp := range msgDependencies.GetAccessOps() { // make a new node in the dependency dag @@ -1139,17 +1127,15 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ // app.batchVerifier.VerifyTxs(ctx, typedTxs) dependencyDag, err := app.BuildDependencyDag(ctx, txs) - var txResults []*abci.ExecTxResult + txResults := []*abci.ExecTxResult{} // TODO:: add metrics for async vs sync - switch err { - case ErrGovMsgInBlock: - ctx.Logger().Info(fmt.Sprintf("Gov msg found while building DAG, processing synchronously: %s", err)) - txResults = app.ProcessBlockSynchronous(ctx, txs) - case nil: + if err != nil { ctx.Logger().Error(fmt.Sprintf("Error while building DAG, processing synchronously: %s", err)) - txResults = app.ProcessBlockSynchronous(ctx, txs) - default: + if err == ErrCycleInDAG { + txResults = app.ProcessBlockSynchronous(ctx, txs) + } + } else { completionSignalingMap, blockingSignalsMap := dependencyDag.BuildCompletionSignalMaps() txResults = app.ProcessBlockConcurrent(ctx, txs, completionSignalingMap, blockingSignalsMap) } diff --git a/app/graph.go b/app/graph.go index 3c9f8edbdd..c933594883 100644 --- a/app/graph.go +++ b/app/graph.go @@ -325,7 +325,4 @@ func (dag *Dag) BuildCompletionSignalMaps() ( return completionSignalingMap, blockingSignalsMap } -var ( - ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") - ErrGovMsgInBlock = fmt.Errorf("gov msg in block") -) +var ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") From fa94c97fb8a033c250fe5744dc1d62f95b76c2bf Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 33/41] Revert "[graph] Move metric to dag builder helper (#275)" This reverts commit c530c026491ff388c611510f828a83c9043e41a0. --- app/app.go | 1 - app/graph.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app.go b/app/app.go index d63dbec6cf..8194837913 100644 --- a/app/app.go +++ b/app/app.go @@ -915,7 +915,6 @@ func (app *App) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestProcess } func (app *App) BuildDependencyDag(ctx sdk.Context, txs [][]byte) (*Dag, error) { - defer metrics.MeasureBuildDagDuration(time.Now(), "BuildDependencyDag") // contains the latest msg index for a specific Access Operation dependencyDag := NewDag() for txIndex, txBytes := range txs { diff --git a/app/graph.go b/app/graph.go index c933594883..b97e2c3710 100644 --- a/app/graph.go +++ b/app/graph.go @@ -135,6 +135,7 @@ func (dag *Dag) AddEdge(fromIndex DagNodeID, toIndex DagNodeID) *DagEdge { // // It will also register the new node with AccessOpsMap so that future nodes that amy be dependent on this one can properly identify the dependency. func (dag *Dag) AddNodeBuildDependency(messageIndex int, txIndex int, accessOp acltypes.AccessOperation) { + defer metrics.MeasureBuildDagDuration(time.Now(), "AddNodeBuildDependency") dagNode := dag.AddNode(messageIndex, txIndex, accessOp) // update tx index map dag.TxIndexMap[txIndex] = dagNode.NodeID From f294cc1cb542bc4005c7d29c6d426b52ca261ede Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 34/41] Revert "Fixes for parallel TX and metrics (#272)" This reverts commit 30207e7a0f450e5605508046dc899ce682012cc2. --- app/abci.go | 3 -- app/app.go | 16 +++------- app/graph.go | 4 --- go.mod | 2 +- go.sum | 4 +-- loadtest/contracts/deploy_ten_contracts.sh | 6 ++-- utils/metrics/labels.go | 6 ---- utils/metrics/metrics_util.go | 36 ---------------------- x/dex/keeper/epoch.go | 2 +- 9 files changed, 12 insertions(+), 67 deletions(-) delete mode 100644 utils/metrics/labels.go diff --git a/app/abci.go b/app/abci.go index 10a841bd1e..35b2a84ae5 100644 --- a/app/abci.go +++ b/app/abci.go @@ -2,10 +2,8 @@ package app import ( "context" - "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/sei-protocol/sei-chain/utils/metrics" abci "github.com/tendermint/tendermint/abci/types" "go.opentelemetry.io/otel/attribute" ) @@ -33,7 +31,6 @@ 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 diff --git a/app/app.go b/app/app.go index 8194837913..f335ecd276 100644 --- a/app/app.go +++ b/app/app.go @@ -108,7 +108,6 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/sei-protocol/sei-chain/utils/metrics" "github.com/sei-protocol/sei-chain/utils/tracing" dexmodule "github.com/sei-protocol/sei-chain/x/dex" @@ -140,6 +139,8 @@ import ( wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" "go.opentelemetry.io/otel" + + "github.com/sei-protocol/sei-chain/utils/metrics" ) // this line is used by starport scaffolding # stargate/wasm/app/enabledProposals @@ -989,7 +990,6 @@ func (app *App) ProcessBlockSynchronous(ctx sdk.Context, txs [][]byte) []*abci.E for _, tx := range txs { txResults = append(txResults, app.DeliverTxWithResult(ctx, tx)) } - metrics.IncrTxProcessTypeCounter(metrics.SYNCHRONOUS) return txResults } @@ -1029,7 +1029,6 @@ func (app *App) ProcessTxConcurrent( // Deliver the transaction and store the result in the channel resultChan <- ChannelResult{txIndex, app.DeliverTxWithResult(ctx, txBytes)} - metrics.IncrTxProcessTypeCounter(metrics.CONCURRENT) } func (app *App) ProcessBlockConcurrent( @@ -1061,15 +1060,10 @@ func (app *App) ProcessBlockConcurrent( ) } - // Do not call waitGroup.Wait() synchronously as it blocks on channel reads - // until all the messages are read. This closes the channel once - // results are all read and prevent any further writes. - go func() { - waitGroup.Wait() - close(resultChan) - }() + // Waits for all the transactions to complete + waitGroup.Wait() - // Gather Results and store it based on txIndex and read results from channel + // Gather Results and store it based on txIndex // Concurrent results may be in different order than the original txIndex txResultsMap := map[int]*abci.ExecTxResult{} for result := range resultChan { diff --git a/app/graph.go b/app/graph.go index b97e2c3710..8301de3094 100644 --- a/app/graph.go +++ b/app/graph.go @@ -2,11 +2,9 @@ package app import ( "fmt" - "time" acltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" mapset "github.com/deckarep/golang-set" - "github.com/sei-protocol/sei-chain/utils/metrics" ) type DagNodeID int @@ -135,7 +133,6 @@ func (dag *Dag) AddEdge(fromIndex DagNodeID, toIndex DagNodeID) *DagEdge { // // It will also register the new node with AccessOpsMap so that future nodes that amy be dependent on this one can properly identify the dependency. func (dag *Dag) AddNodeBuildDependency(messageIndex int, txIndex int, accessOp acltypes.AccessOperation) { - defer metrics.MeasureBuildDagDuration(time.Now(), "AddNodeBuildDependency") dagNode := dag.AddNode(messageIndex, txIndex, accessOp) // update tx index map dag.TxIndexMap[txIndex] = dagNode.NodeID @@ -286,7 +283,6 @@ func (dag *Dag) BuildCompletionSignalMaps() ( completionSignalingMap map[int]MessageCompletionSignalMapping, blockingSignalsMap map[int]MessageCompletionSignalMapping, ) { - defer metrics.MeasureBuildDagDuration(time.Now(), "BuildCompletionSignalMaps") completionSignalingMap = make(map[int]MessageCompletionSignalMapping) blockingSignalsMap = make(map[int]MessageCompletionSignalMapping) // go through every node diff --git a/go.mod b/go.mod index deca309910..f8e7b079f4 100644 --- a/go.mod +++ b/go.mod @@ -132,7 +132,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.76 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.73 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 diff --git a/go.sum b/go.sum index ba3e2871f2..c5e84d1a7f 100644 --- a/go.sum +++ b/go.sum @@ -1098,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.76 h1:y75Pn8hTc1SWndq/oMGzVu4mkF9ma6kVaA36AdFKxD8= -github.com/sei-protocol/sei-cosmos v0.1.76/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= +github.com/sei-protocol/sei-cosmos v0.1.73 h1:yFG32zV8BGCbsS/AQYUNc2ZFWWZ2lXv505Gkf6vauKE= +github.com/sei-protocol/sei-cosmos v0.1.73/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= 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= diff --git a/loadtest/contracts/deploy_ten_contracts.sh b/loadtest/contracts/deploy_ten_contracts.sh index 3d65af5208..6c0dcb78a0 100644 --- a/loadtest/contracts/deploy_ten_contracts.sh +++ b/loadtest/contracts/deploy_ten_contracts.sh @@ -15,17 +15,17 @@ echo cd $seihome/loadtest/contracts/mars && cargo build && docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.6 + cosmwasm/rust-optimizer:0.12.5 cd $seihome/loadtest/contracts/saturn && cargo build && docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.6 + cosmwasm/rust-optimizer:0.12.5 cd $seihome/loadtest/contracts/venus && cargo build && docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.6 + cosmwasm/rust-optimizer:0.12.5 # Deploy all contracts echo "Deploying contracts..." diff --git a/utils/metrics/labels.go b/utils/metrics/labels.go deleted file mode 100644 index 85d8ff122b..0000000000 --- a/utils/metrics/labels.go +++ /dev/null @@ -1,6 +0,0 @@ -package metrics - -const ( - CONCURRENT = "concurrent" - SYNCHRONOUS = "synchronous" -) diff --git a/utils/metrics/metrics_util.go b/utils/metrics/metrics_util.go index d3bb844bb8..6bd198ee7c 100644 --- a/utils/metrics/metrics_util.go +++ b/utils/metrics/metrics_util.go @@ -44,39 +44,3 @@ func GaugeSeidVersionAndCommit(version string, commit string) { []metrics.Label{telemetry.NewLabel("seid_version", version), telemetry.NewLabel("commit", commit)}, ) } - -// sei_tx_process_type_count -func IncrTxProcessTypeCounter(processType string) { - metrics.IncrCounterWithLabels( - []string{"sei", "tx", "process", "type"}, - 1, - []metrics.Label{telemetry.NewLabel("type", processType)}, - ) -} - -// Measures the time taken to execute a sudo msg -// Metric Names: -// -// sei_deliver_tx_duration_miliseconds -// sei_deliver_tx_duration_miliseconds_count -// sei_deliver_tx_duration_miliseconds_sum -func MeasureDeliverTxDuration(start time.Time) { - metrics.MeasureSince( - []string{"sei", "deliver", "tx", "milliseconds"}, - start.UTC(), - ) -} - -// Measures the time taken to execute a sudo msg -// Metric Names: -// -// sei_dag_build_duration_miliseconds -// sei_dag_build_duration_miliseconds_count -// sei_dag_build_duration_miliseconds_sum -func MeasureBuildDagDuration(start time.Time, method string) { - metrics.MeasureSinceWithLabels( - []string{"sei", "dag", "build", "milliseconds"}, - start.UTC(), - []metrics.Label{telemetry.NewLabel("method", method)}, - ) -} diff --git a/x/dex/keeper/epoch.go b/x/dex/keeper/epoch.go index 33f8012af4..d9ca566b7d 100644 --- a/x/dex/keeper/epoch.go +++ b/x/dex/keeper/epoch.go @@ -14,7 +14,6 @@ func (k Keeper) SetEpoch(ctx sdk.Context, epoch uint64) { bz := make([]byte, 8) binary.BigEndian.PutUint64(bz, epoch) store.Set([]byte(EpochKey), bz) - ctx.Logger().Info(fmt.Sprintf("Current epoch %d", epoch)) } func (k Keeper) IsNewEpoch(ctx sdk.Context) (bool, uint64) { @@ -22,5 +21,6 @@ func (k Keeper) IsNewEpoch(ctx sdk.Context) (bool, uint64) { b := store.Get([]byte(EpochKey)) lastEpoch := binary.BigEndian.Uint64(b) currentEpoch := k.EpochKeeper.GetEpoch(ctx).CurrentEpoch + ctx.Logger().Info(fmt.Sprintf("Current epoch %d", currentEpoch)) return currentEpoch > lastEpoch, currentEpoch } From 1f69dfb845457c5ee89bdc9d5d0abf1492b2265e Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 35/41] Revert "[graph] Add resource hierarchy to dependency graph (#268)" This reverts commit da7c0706dcc5ff81e1c025ee8a5c6b5a26dcc1e4. --- app/graph.go | 208 ++++++++++++++-------------------------------- app/graph_test.go | 106 ----------------------- go.mod | 3 +- go.sum | 6 +- 4 files changed, 65 insertions(+), 258 deletions(-) diff --git a/app/graph.go b/app/graph.go index 8301de3094..a8e7dd69f5 100644 --- a/app/graph.go +++ b/app/graph.go @@ -4,19 +4,10 @@ import ( "fmt" acltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" - mapset "github.com/deckarep/golang-set" ) type DagNodeID int -// Alias for mapping resource identifier to dag node IDs -type ResourceIdentifierNodeIDMapping = map[string][]DagNodeID - -type ResourceAccess struct { - ResourceType acltypes.ResourceType - AccessType acltypes.AccessType -} - type DagNode struct { NodeID DagNodeID MessageIndex int @@ -30,11 +21,11 @@ type DagEdge struct { } type Dag struct { - NodeMap map[DagNodeID]DagNode - EdgesMap map[DagNodeID][]DagEdge // maps node Id (from node) and contains edge info - ResourceAccessMap map[ResourceAccess]ResourceIdentifierNodeIDMapping // maps resource type and access type to identifiers + node IDs - TxIndexMap map[int]DagNodeID // tracks latest node ID for a tx index - NextID DagNodeID + NodeMap map[DagNodeID]DagNode + EdgesMap map[DagNodeID][]DagEdge // maps node Id (from node) and contains edge info + AccessOpsMap map[acltypes.AccessOperation][]DagNodeID // tracks latest node to use a specific access op + TxIndexMap map[int]DagNodeID // tracks latest node ID for a tx index + NextID DagNodeID } // Alias for mapping MessageIndexId -> AccessOperations -> CompletionSignals @@ -83,18 +74,11 @@ func (dag Dag) Visit(v int, do func(w int, c int64) (skip bool)) (aborted bool) func NewDag() Dag { return Dag{ - NodeMap: make(map[DagNodeID]DagNode), - EdgesMap: make(map[DagNodeID][]DagEdge), - ResourceAccessMap: make(map[ResourceAccess]ResourceIdentifierNodeIDMapping), - TxIndexMap: make(map[int]DagNodeID), - NextID: 0, - } -} - -func GetResourceAccess(accessOp acltypes.AccessOperation) ResourceAccess { - return ResourceAccess{ - accessOp.ResourceType, - accessOp.AccessType, + NodeMap: make(map[DagNodeID]DagNode), + EdgesMap: make(map[DagNodeID][]DagEdge), + AccessOpsMap: make(map[acltypes.AccessOperation][]DagNodeID), + TxIndexMap: make(map[int]DagNodeID), + NextID: 0, } } @@ -140,141 +124,73 @@ func (dag *Dag) AddNodeBuildDependency(messageIndex int, txIndex int, accessOp a nodeDependencies := dag.GetNodeDependencies(dagNode) // build edges for each of the dependencies for _, nodeDependency := range nodeDependencies { - dag.AddEdge(nodeDependency, dagNode.NodeID) + dag.AddEdge(nodeDependency.NodeID, dagNode.NodeID) } // update access ops map with the latest node id using a specific access op - resourceAccess := GetResourceAccess(accessOp) - if _, exists := dag.ResourceAccessMap[resourceAccess]; !exists { - dag.ResourceAccessMap[resourceAccess] = make(ResourceIdentifierNodeIDMapping) - } - dag.ResourceAccessMap[resourceAccess][accessOp.IdentifierTemplate] = append(dag.ResourceAccessMap[resourceAccess][accessOp.IdentifierTemplate], dagNode.NodeID) -} - -func getAllNodeIDsFromIdentifierMapping(mapping ResourceIdentifierNodeIDMapping) (allNodeIDs []DagNodeID) { - for _, nodeIDs := range mapping { - allNodeIDs = append(allNodeIDs, nodeIDs...) - } - return + dag.AccessOpsMap[accessOp] = append(dag.AccessOpsMap[accessOp], dagNode.NodeID) } -func (dag *Dag) getDependencyWrites(node DagNode, dependentResource acltypes.ResourceType) mapset.Set { - nodeIDs := mapset.NewSet() - writeResourceAccess := ResourceAccess{ - dependentResource, - acltypes.AccessType_WRITE, - } - if identifierNodeMapping, ok := dag.ResourceAccessMap[writeResourceAccess]; ok { - var nodeIDsMaybeDependency []DagNodeID - if dependentResource != node.AccessOperation.ResourceType { - // we can add all node IDs as dependencies if applicable - nodeIDsMaybeDependency = getAllNodeIDsFromIdentifierMapping(identifierNodeMapping) - } else { - // TODO: otherwise we need to have partial filtering on identifiers - // for now, lets just perform exact matching on identifiers - nodeIDsMaybeDependency = identifierNodeMapping[node.AccessOperation.IdentifierTemplate] +// This helper will identify nodes that are dependencies for the current node, and can then be used for creating edges between then for future completion signals +func (dag *Dag) GetNodeDependencies(node DagNode) (nodeDependencies []DagNode) { + accessOp := node.AccessOperation + // if the blocking access ops are in access ops map, make an edge + switch accessOp.AccessType { + case acltypes.AccessType_READ: + // if we need to do a read, we need latest write as a dependency + // TODO: replace hardcoded access op dependencies with helper that generates (and also generates superseding resources too eg. Resource.ALL is blocking for Resource.KV) + writeAccessOp := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_WRITE, + ResourceType: accessOp.GetResourceType(), + IdentifierTemplate: accessOp.GetIdentifierTemplate(), } - for _, wn := range nodeIDsMaybeDependency { - writeNode := dag.NodeMap[wn] - // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) - // if from a previous transaction, we need to create an edge - if writeNode.TxIndex < node.TxIndex { - // this should be the COMMIT access op for the tx - lastTxNode := dag.NodeMap[dag.TxIndexMap[writeNode.TxIndex]] - nodeIDs.Add(lastTxNode.NodeID) + if writeNodeIDs, ok := dag.AccessOpsMap[writeAccessOp]; ok { + for _, wn := range writeNodeIDs { + writeNode := dag.NodeMap[wn] + // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) + // if from a previous transaction, we need to create an edge + if writeNode.TxIndex < node.TxIndex { + // this should be the COMMIT access op for the tx + lastTxNode := dag.NodeMap[dag.TxIndexMap[writeNode.TxIndex]] + nodeDependencies = append(nodeDependencies, lastTxNode) + } } } - } - return nodeIDs -} - -func (dag *Dag) getDependencyUnknowns(node DagNode, dependentResource acltypes.ResourceType) mapset.Set { - nodeIDs := mapset.NewSet() - unknownResourceAccess := ResourceAccess{ - dependentResource, - acltypes.AccessType_UNKNOWN, - } - if identifierNodeMapping, ok := dag.ResourceAccessMap[unknownResourceAccess]; ok { - var nodeIDsMaybeDependency []DagNodeID - if dependentResource != node.AccessOperation.ResourceType { - // we can add all node IDs as dependencies if applicable - nodeIDsMaybeDependency = getAllNodeIDsFromIdentifierMapping(identifierNodeMapping) - } else { - // TODO: otherwise we need to have partial filtering on identifiers - // for now, lets just perform exact matching on identifiers - nodeIDsMaybeDependency = identifierNodeMapping[node.AccessOperation.IdentifierTemplate] + case acltypes.AccessType_WRITE, acltypes.AccessType_UNKNOWN: + // if we need to do a write, we need read and write as dependencies + writeAccessOp := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_WRITE, + ResourceType: accessOp.GetResourceType(), + IdentifierTemplate: accessOp.GetIdentifierTemplate(), } - for _, un := range nodeIDsMaybeDependency { - uNode := dag.NodeMap[un] - // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) - // if from a previous transaction, we need to create an edge - if uNode.TxIndex < node.TxIndex { - // this should be the COMMIT access op for the tx - lastTxNode := dag.NodeMap[dag.TxIndexMap[uNode.TxIndex]] - nodeIDs.Add(lastTxNode.NodeID) + if writeNodeIDs, ok := dag.AccessOpsMap[writeAccessOp]; ok { + for _, wn := range writeNodeIDs { + // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) + writeNode := dag.NodeMap[wn] + // if from a previous transaction, we need to create an edge + if writeNode.TxIndex < node.TxIndex { + // we need to get the last node from that tx + lastTxNode := dag.NodeMap[dag.TxIndexMap[writeNode.TxIndex]] + nodeDependencies = append(nodeDependencies, lastTxNode) + } } } - } - return nodeIDs -} - -func (dag *Dag) getDependencyReads(node DagNode, dependentResource acltypes.ResourceType) mapset.Set { - nodeIDs := mapset.NewSet() - readResourceAccess := ResourceAccess{ - dependentResource, - acltypes.AccessType_READ, - } - if identifierNodeMapping, ok := dag.ResourceAccessMap[readResourceAccess]; ok { - var nodeIDsMaybeDependency []DagNodeID - if dependentResource != node.AccessOperation.ResourceType { - // we can add all node IDs as dependencies if applicable - nodeIDsMaybeDependency = getAllNodeIDsFromIdentifierMapping(identifierNodeMapping) - } else { - // TODO: otherwise we need to have partial filtering on identifiers - // for now, lets just perform exact matching on identifiers - nodeIDsMaybeDependency = identifierNodeMapping[node.AccessOperation.IdentifierTemplate] + readAccessOp := acltypes.AccessOperation{ + AccessType: acltypes.AccessType_READ, + ResourceType: accessOp.GetResourceType(), + IdentifierTemplate: accessOp.GetIdentifierTemplate(), } - for _, rn := range nodeIDsMaybeDependency { - readNode := dag.NodeMap[rn] - // if from a previous transaction, we need to create an edge - if readNode.TxIndex < node.TxIndex { - nodeIDs.Add(readNode.NodeID) + if readNodeIDs, ok := dag.AccessOpsMap[readAccessOp]; ok { + for _, rn := range readNodeIDs { + readNode := dag.NodeMap[rn] + // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) + // if from a previous transaction, we need to create an edge + if readNode.TxIndex < node.TxIndex { + nodeDependencies = append(nodeDependencies, readNode) + } } } } - return nodeIDs -} - -// given a node, and a dependent Resource, generate a set of nodes that are dependencies -func (dag *Dag) getNodeDependenciesForResource(node DagNode, dependentResource acltypes.ResourceType) mapset.Set { - nodeIDs := mapset.NewSet() - switch node.AccessOperation.AccessType { - case acltypes.AccessType_READ: - // for a read, we are blocked on prior writes and unknown - nodeIDs = nodeIDs.Union(dag.getDependencyWrites(node, dependentResource)) - nodeIDs = nodeIDs.Union(dag.getDependencyUnknowns(node, dependentResource)) - case acltypes.AccessType_WRITE, acltypes.AccessType_UNKNOWN: - // for write / unknown, we're blocked on prior writes, reads, and unknowns - nodeIDs = nodeIDs.Union(dag.getDependencyWrites(node, dependentResource)) - nodeIDs = nodeIDs.Union(dag.getDependencyUnknowns(node, dependentResource)) - nodeIDs = nodeIDs.Union(dag.getDependencyReads(node, dependentResource)) - } - return nodeIDs -} - -// This helper will identify nodes that are dependencies for the current node, and can then be used for creating edges between then for future completion signals -func (dag *Dag) GetNodeDependencies(node DagNode) []DagNodeID { - accessOp := node.AccessOperation - // get all parent resource types, we'll need to create edges for any of these - parentResources := accessOp.ResourceType.GetResourceDependencies() - nodeIDSet := mapset.NewSet() - for _, resource := range parentResources { - nodeIDSet = nodeIDSet.Union(dag.getNodeDependenciesForResource(node, resource)) - } - nodeDependencies := make([]DagNodeID, nodeIDSet.Cardinality()) - for i, x := range nodeIDSet.ToSlice() { - nodeDependencies[i] = x.(DagNodeID) - } return nodeDependencies } diff --git a/app/graph_test.go b/app/graph_test.go index 4b03d6793e..5cf8e08733 100644 --- a/app/graph_test.go +++ b/app/graph_test.go @@ -149,109 +149,3 @@ func TestCreateGraph(t *testing.T) { slice, ) } - -func TestHierarchyDag(t *testing.T) { - dag := app.NewDag() - /** - tx1: write to A, commit 1 - tx2: read ALL, commit 2 - tx3: write B dexmem, commit 3 - tx4: read A, commit 4 - expected dag - 1wA -> 1c => 2rALL -> 2c - \ \=> 3wB c3 - \---=> 4rA c4 - **/ - - commit := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_COMMIT, - ResourceType: acltypes.ResourceType_ANY, - IdentifierTemplate: "*", - } - writeA := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_WRITE, - ResourceType: acltypes.ResourceType_KV, - IdentifierTemplate: "ResourceA", - } - readA := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_READ, - ResourceType: acltypes.ResourceType_KV, - IdentifierTemplate: "ResourceA", - } - writeB := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_WRITE, - ResourceType: acltypes.ResourceType_DexMem, - IdentifierTemplate: "ResourceB", - } - readAll := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_READ, - ResourceType: acltypes.ResourceType_ANY, - IdentifierTemplate: "*", - } - - dag.AddNodeBuildDependency(0, 0, writeA) // node id 0 - dag.AddNodeBuildDependency(0, 0, commit) // node id 1 - dag.AddNodeBuildDependency(0, 1, readAll) // node id 2 - dag.AddNodeBuildDependency(0, 1, commit) // node id 3 - dag.AddNodeBuildDependency(0, 2, writeB) // node id 4 - dag.AddNodeBuildDependency(0, 2, commit) // node id 5 - dag.AddNodeBuildDependency(0, 3, readA) // node id 6 - dag.AddNodeBuildDependency(0, 3, commit) // node id 7 - - // assert dag is acyclic - acyclic := graph.Acyclic(dag) - require.True(t, acyclic) - - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[0]) - require.Equal( - t, - []app.DagEdge{{1, 2}, {1, 6}}, - dag.EdgesMap[1], - ) - require.Equal( - t, - []app.DagEdge{{2, 4}}, - dag.EdgesMap[2], - ) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[3]) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[4]) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[5]) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[6]) - - // test completion signals - completionSignalsMap, blockingSignalsMap := dag.BuildCompletionSignalMaps() - - channel0 := completionSignalsMap[0][0][commit][0].Channel - channel1 := completionSignalsMap[0][0][commit][1].Channel - channel2 := completionSignalsMap[1][0][readAll][0].Channel - - signal0 := app.CompletionSignal{1, 2, commit, readAll, channel0} - signal1 := app.CompletionSignal{1, 6, commit, readA, channel1} - signal2 := app.CompletionSignal{2, 4, readAll, writeB, channel2} - - require.Equal( - t, - []app.CompletionSignal{signal0, signal1}, - completionSignalsMap[0][0][commit], - ) - require.Equal( - t, - []app.CompletionSignal{signal0}, - blockingSignalsMap[1][0][readAll], - ) - require.Equal( - t, - []app.CompletionSignal{signal1}, - blockingSignalsMap[3][0][readA], - ) - require.Equal( - t, - []app.CompletionSignal{signal2}, - completionSignalsMap[1][0][readAll], - ) - require.Equal( - t, - []app.CompletionSignal{signal2}, - blockingSignalsMap[2][0][writeB], - ) -} diff --git a/go.mod b/go.mod index f8e7b079f4..67bba1d655 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/cosmos/cosmos-sdk v0.45.4 github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/ibc-go/v3 v3.0.0 - github.com/deckarep/golang-set v1.8.0 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.2 github.com/gorilla/mux v1.8.0 @@ -132,7 +131,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.73 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.69 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 diff --git a/go.sum b/go.sum index c5e84d1a7f..0455dd7c2b 100644 --- a/go.sum +++ b/go.sum @@ -291,8 +291,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14yDtF28KmMOgQ= -github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= -github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo= github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/denis-tingaikin/go-header v0.4.3/go.mod h1:0wOCWuN71D5qIgE2nz9KrKmuYBAC2Mra5RassOIQ2/c= github.com/denisenkom/go-mssqldb v0.12.0/go.mod h1:iiK0YP1ZeepvmBQk/QpLEhhTNJgfzrpArPY/aFvc9yU= @@ -1098,8 +1096,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.73 h1:yFG32zV8BGCbsS/AQYUNc2ZFWWZ2lXv505Gkf6vauKE= -github.com/sei-protocol/sei-cosmos v0.1.73/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= +github.com/sei-protocol/sei-cosmos v0.1.69 h1:jPFTf6vSg3DQ0FgKpQGw6ZEUuElKL2UJ3P8SBXbYnio= +github.com/sei-protocol/sei-cosmos v0.1.69/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= 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= From feaf114bda75a9cf5be43eab94239eeead38ea6d Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 36/41] Revert "Revert "Parallel TX Synchrnous Testing"" This reverts commit f343740112ca60bb46de5f8e7d54011241021701. --- loadtest/scripts/populate_genesis_accounts.py | 1 + scripts/old_initialize_local.sh | 60 ++++++++----------- 2 files changed, 27 insertions(+), 34 deletions(-) mode change 100644 => 100755 scripts/old_initialize_local.sh diff --git a/loadtest/scripts/populate_genesis_accounts.py b/loadtest/scripts/populate_genesis_accounts.py index f2e8e8ece1..100d1b35b6 100644 --- a/loadtest/scripts/populate_genesis_accounts.py +++ b/loadtest/scripts/populate_genesis_accounts.py @@ -21,6 +21,7 @@ def add_key(account_name, local=False): stderr=subprocess.STDOUT, shell=True, ).decode() + splitted_outputs = add_key_output.split('\n') address = splitted_outputs[3].split(': ')[1] mnemonic = splitted_outputs[11] diff --git a/scripts/old_initialize_local.sh b/scripts/old_initialize_local.sh old mode 100644 new mode 100755 index a5d2352308..9e1fd56a7e --- a/scripts/old_initialize_local.sh +++ b/scripts/old_initialize_local.sh @@ -1,43 +1,35 @@ -#!/bin/bash -echo -n OS Password: -read -s password -echo -echo -n Key Name: -read keyname -echo -echo -n Number of Test Accounts: -read numtestaccount -echo -docker stop jaeger -docker rm jaeger -docker run -d --name jaeger \ - -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ - -p 5775:5775/udp \ - -p 6831:6831/udp \ - -p 6832:6832/udp \ - -p 5778:5778 \ - -p 16686:16686 \ - -p 14250:14250 \ - -p 14268:14268 \ - -p 14269:14269 \ - -p 9411:9411 \ - jaegertracing/all-in-one:1.33 +#!/bin/bash + +keyname=admin +#docker stop jaeger +#docker rm jaeger +#docker run -d --name jaeger \ +# -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ +# -p 5775:5775/udp \ +# -p 6831:6831/udp \ +# -p 6832:6832/udp \ +# -p 5778:5778 \ +# -p 16686:16686 \ +# -p 14250:14250 \ +# -p 14268:14268 \ +# -p 14269:14269 \ +# -p 9411:9411 \ +# jaegertracing/all-in-one:1.33 +rm -rf ~/.sei echo "Building..." make install -echo $password | sudo -S rm -r ~/.sei/ -echo $password | sudo -S rm -r ~/test_accounts/ +#echo $password | sudo -S rm -r ~/.sei/ +#echo $password | sudo -S rm -r ~/test_accounts/ ~/go/bin/seid init demo --chain-id sei-chain -yes | ~/go/bin/seid keys add $keyname -yes | ~/go/bin/seid keys add faucet -printf '12345678\n' | ~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show $keyname -a) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom -printf '12345678\n' | ~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show faucet -a) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom -python3 ./loadtest/scripts/populate_genesis_accounts.py $numtestaccount loc -printf '12345678\n' | ~/go/bin/seid gentx $keyname 70000000000000000000usei --chain-id sei-chain -sed -i 's/mode = "full"/mode = "validator"/g' $HOME/.sei/config/config.toml -sed -i 's/indexer = \["null"\]/indexer = \["kv"\]/g' $HOME/.sei/config/config.toml +~/go/bin/seid keys add $keyname --keyring-backend test +#yes | ~/go/bin/seid keys add faucet +~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show $keyname -a --keyring-backend test) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom +~/go/bin/seid gentx $keyname 70000000000000000000usei --chain-id sei-chain --keyring-backend test +sed -i '' 's/mode = "full"/mode = "validator"/g' $HOME/.sei/config/config.toml +sed -i '' 's/indexer = \["null"\]/indexer = \["kv"\]/g' $HOME/.sei/config/config.toml KEY=$(jq '.pub_key' ~/.sei/config/priv_validator_key.json -c) jq '.validators = [{}]' ~/.sei/config/genesis.json > ~/.sei/config/tmp_genesis.json jq '.validators[0] += {"power":"70000000000000"}' ~/.sei/config/tmp_genesis.json > ~/.sei/config/tmp_genesis_2.json From d98cb270b4e3c1b05a8237494e1ace7351693509 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 37/41] Revert "Parallel TX Synchrnous Testing" This reverts commit b95b44cc9df4097483e3b48cd3da22552c7bd571. --- scripts/old_initialize_local.sh | 60 +++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 26 deletions(-) mode change 100755 => 100644 scripts/old_initialize_local.sh diff --git a/scripts/old_initialize_local.sh b/scripts/old_initialize_local.sh old mode 100755 new mode 100644 index 9e1fd56a7e..a5d2352308 --- a/scripts/old_initialize_local.sh +++ b/scripts/old_initialize_local.sh @@ -1,35 +1,43 @@ - - #!/bin/bash -keyname=admin -#docker stop jaeger -#docker rm jaeger -#docker run -d --name jaeger \ -# -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ -# -p 5775:5775/udp \ -# -p 6831:6831/udp \ -# -p 6832:6832/udp \ -# -p 5778:5778 \ -# -p 16686:16686 \ -# -p 14250:14250 \ -# -p 14268:14268 \ -# -p 14269:14269 \ -# -p 9411:9411 \ -# jaegertracing/all-in-one:1.33 +echo -n OS Password: +read -s password +echo +echo -n Key Name: +read keyname +echo +echo -n Number of Test Accounts: +read numtestaccount +echo + +docker stop jaeger +docker rm jaeger +docker run -d --name jaeger \ + -e COLLECTOR_ZIPKIN_HOST_PORT=:9411 \ + -p 5775:5775/udp \ + -p 6831:6831/udp \ + -p 6832:6832/udp \ + -p 5778:5778 \ + -p 16686:16686 \ + -p 14250:14250 \ + -p 14268:14268 \ + -p 14269:14269 \ + -p 9411:9411 \ + jaegertracing/all-in-one:1.33 -rm -rf ~/.sei echo "Building..." make install -#echo $password | sudo -S rm -r ~/.sei/ -#echo $password | sudo -S rm -r ~/test_accounts/ +echo $password | sudo -S rm -r ~/.sei/ +echo $password | sudo -S rm -r ~/test_accounts/ ~/go/bin/seid init demo --chain-id sei-chain -~/go/bin/seid keys add $keyname --keyring-backend test -#yes | ~/go/bin/seid keys add faucet -~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show $keyname -a --keyring-backend test) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom -~/go/bin/seid gentx $keyname 70000000000000000000usei --chain-id sei-chain --keyring-backend test -sed -i '' 's/mode = "full"/mode = "validator"/g' $HOME/.sei/config/config.toml -sed -i '' 's/indexer = \["null"\]/indexer = \["kv"\]/g' $HOME/.sei/config/config.toml +yes | ~/go/bin/seid keys add $keyname +yes | ~/go/bin/seid keys add faucet +printf '12345678\n' | ~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show $keyname -a) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom +printf '12345678\n' | ~/go/bin/seid add-genesis-account $(~/go/bin/seid keys show faucet -a) 100000000000000000000usei,100000000000000000000uusdc,100000000000000000000uatom +python3 ./loadtest/scripts/populate_genesis_accounts.py $numtestaccount loc +printf '12345678\n' | ~/go/bin/seid gentx $keyname 70000000000000000000usei --chain-id sei-chain +sed -i 's/mode = "full"/mode = "validator"/g' $HOME/.sei/config/config.toml +sed -i 's/indexer = \["null"\]/indexer = \["kv"\]/g' $HOME/.sei/config/config.toml KEY=$(jq '.pub_key' ~/.sei/config/priv_validator_key.json -c) jq '.validators = [{}]' ~/.sei/config/genesis.json > ~/.sei/config/tmp_genesis.json jq '.validators[0] += {"power":"70000000000000"}' ~/.sei/config/tmp_genesis.json > ~/.sei/config/tmp_genesis_2.json From b4f530a69e30b15f3616b5982d548cfe03dbb485 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 38/41] Revert "Dag optimization (#263)" This reverts commit ac3fdbf03afb5de1071f2f0890be78d7fe6f8854. --- app/graph.go | 24 ++++------- app/graph_test.go | 107 ++++++++++++++-------------------------------- 2 files changed, 41 insertions(+), 90 deletions(-) diff --git a/app/graph.go b/app/graph.go index a8e7dd69f5..05c958257d 100644 --- a/app/graph.go +++ b/app/graph.go @@ -118,6 +118,12 @@ func (dag *Dag) AddEdge(fromIndex DagNodeID, toIndex DagNodeID) *DagEdge { // It will also register the new node with AccessOpsMap so that future nodes that amy be dependent on this one can properly identify the dependency. func (dag *Dag) AddNodeBuildDependency(messageIndex int, txIndex int, accessOp acltypes.AccessOperation) { dagNode := dag.AddNode(messageIndex, txIndex, accessOp) + // if in TxIndexMap, make an edge from the previous node index + if lastTxNodeID, ok := dag.TxIndexMap[txIndex]; ok { + // TODO: we actually don't necessarily need these edges, but keeping for now so we can first determine that cycles can't be missed if we remove these + // add an edge between access ops in a transaction + dag.AddEdge(lastTxNodeID, dagNode.NodeID) + } // update tx index map dag.TxIndexMap[txIndex] = dagNode.NodeID @@ -199,8 +205,6 @@ func (dag *Dag) BuildCompletionSignalMaps() ( completionSignalingMap map[int]MessageCompletionSignalMapping, blockingSignalsMap map[int]MessageCompletionSignalMapping, ) { - completionSignalingMap = make(map[int]MessageCompletionSignalMapping) - blockingSignalsMap = make(map[int]MessageCompletionSignalMapping) // go through every node for _, node := range dag.NodeMap { // for each node, assign its completion signaling, and also assign blocking signals for the destination nodes @@ -210,23 +214,11 @@ func (dag *Dag) BuildCompletionSignalMaps() ( if maybeCompletionSignal != nil { completionSignal := *maybeCompletionSignal - toNode := dag.NodeMap[edge.ToNodeID] - if _, exists := blockingSignalsMap[toNode.TxIndex]; !exists { - blockingSignalsMap[toNode.TxIndex] = make(MessageCompletionSignalMapping) - } - if _, exists := blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex]; !exists { - blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex] = make(map[acltypes.AccessOperation][]CompletionSignal) - } // add it to the right blocking signal in the right txindex + toNode := dag.NodeMap[edge.ToNodeID] prevBlockSignalMapping := blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] = append(prevBlockSignalMapping, completionSignal) - if _, exists := completionSignalingMap[node.TxIndex]; !exists { - completionSignalingMap[node.TxIndex] = make(MessageCompletionSignalMapping) - } - if _, exists := completionSignalingMap[node.TxIndex][node.MessageIndex]; !exists { - completionSignalingMap[node.TxIndex][node.MessageIndex] = make(map[acltypes.AccessOperation][]CompletionSignal) - } // add it to the completion signal for the tx index prevCompletionSignalMapping := completionSignalingMap[node.TxIndex][node.MessageIndex][completionSignal.CompletionAccessOperation] completionSignalingMap[node.TxIndex][node.MessageIndex][completionSignal.CompletionAccessOperation] = append(prevCompletionSignalMapping, completionSignal) @@ -235,7 +227,7 @@ func (dag *Dag) BuildCompletionSignalMaps() ( } } } - return completionSignalingMap, blockingSignalsMap + return } var ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") diff --git a/app/graph_test.go b/app/graph_test.go index 5cf8e08733..622705eab1 100644 --- a/app/graph_test.go +++ b/app/graph_test.go @@ -1,7 +1,6 @@ package app_test import ( - "sort" "testing" acltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" @@ -49,22 +48,26 @@ func TestCreateGraph(t *testing.T) { IdentifierTemplate: "ResourceB", } - dag.AddNodeBuildDependency(0, 0, writeAccessA) // node id 0 - dag.AddNodeBuildDependency(0, 0, readAccessB) // node id 1 - dag.AddNodeBuildDependency(0, 0, commitAccessOp) // node id 2 - dag.AddNodeBuildDependency(0, 1, readAccessA) // node id 3 - dag.AddNodeBuildDependency(0, 1, readAccessB) // node id 4 - dag.AddNodeBuildDependency(0, 1, commitAccessOp) // node id 5 - dag.AddNodeBuildDependency(0, 2, readAccessB) // node id 6 - dag.AddNodeBuildDependency(0, 2, readAccessA) // node id 7 - dag.AddNodeBuildDependency(0, 2, commitAccessOp) // node id 8 - dag.AddNodeBuildDependency(0, 3, writeAccessB) // node id 9 - dag.AddNodeBuildDependency(0, 3, commitAccessOp) // node id 10 + dag.AddNodeBuildDependency(1, 1, writeAccessA) // node id 0 + dag.AddNodeBuildDependency(1, 1, readAccessB) // node id 1 + dag.AddNodeBuildDependency(1, 1, commitAccessOp) // node id 2 + dag.AddNodeBuildDependency(1, 2, readAccessA) // node id 3 + dag.AddNodeBuildDependency(1, 2, readAccessB) // node id 4 + dag.AddNodeBuildDependency(1, 2, commitAccessOp) // node id 5 + dag.AddNodeBuildDependency(1, 3, readAccessB) // node id 6 + dag.AddNodeBuildDependency(1, 3, readAccessA) // node id 7 + dag.AddNodeBuildDependency(1, 3, commitAccessOp) // node id 8 + dag.AddNodeBuildDependency(1, 4, writeAccessB) // node id 9 + dag.AddNodeBuildDependency(1, 4, commitAccessOp) // node id 10 - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[0]) require.Equal( t, - []app.DagEdge{{1, 9}}, + []app.DagEdge{{0, 1}}, + dag.EdgesMap[0], + ) + require.Equal( + t, + []app.DagEdge{{1, 2}, {1, 9}}, dag.EdgesMap[1], ) require.Equal( @@ -72,80 +75,36 @@ func TestCreateGraph(t *testing.T) { []app.DagEdge{{2, 3}, {2, 7}}, dag.EdgesMap[2], ) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[3]) require.Equal( t, - []app.DagEdge{{4, 9}}, - dag.EdgesMap[4], + []app.DagEdge{{3, 4}}, + dag.EdgesMap[3], ) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[5]) require.Equal( t, - []app.DagEdge{{6, 9}}, - dag.EdgesMap[6], + []app.DagEdge{{4, 5}, {4, 9}}, + dag.EdgesMap[4], ) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[7]) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[8]) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[9]) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[10]) - - // assert dag is acyclic - acyclic := graph.Acyclic(dag) - require.True(t, acyclic) - - // test completion signals - completionSignalsMap, blockingSignalsMap := dag.BuildCompletionSignalMaps() - - channel0 := completionSignalsMap[0][0][commitAccessOp][0].Channel - channel1 := completionSignalsMap[0][0][commitAccessOp][1].Channel - channel2 := completionSignalsMap[1][0][readAccessB][0].Channel - channel3 := completionSignalsMap[0][0][readAccessB][0].Channel - channel4 := completionSignalsMap[2][0][readAccessB][0].Channel - - signal0 := app.CompletionSignal{2, 3, commitAccessOp, readAccessA, channel0} - signal1 := app.CompletionSignal{2, 7, commitAccessOp, readAccessA, channel1} - signal2 := app.CompletionSignal{4, 9, readAccessB, writeAccessB, channel2} - signal3 := app.CompletionSignal{1, 9, readAccessB, writeAccessB, channel3} - signal4 := app.CompletionSignal{6, 9, readAccessB, writeAccessB, channel4} - + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[5]) require.Equal( t, - []app.CompletionSignal{signal0, signal1}, - completionSignalsMap[0][0][commitAccessOp], + []app.DagEdge{{6, 7}, {6, 9}}, + dag.EdgesMap[6], ) require.Equal( t, - []app.CompletionSignal{signal0}, - blockingSignalsMap[1][0][readAccessA], + []app.DagEdge{{7, 8}}, + dag.EdgesMap[7], ) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[8]) require.Equal( t, - []app.CompletionSignal{signal1}, - blockingSignalsMap[2][0][readAccessA], + []app.DagEdge{{9, 10}}, + dag.EdgesMap[9], ) + require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[10]) - require.Equal( - t, - []app.CompletionSignal{signal2}, - completionSignalsMap[1][0][readAccessB], - ) - require.Equal( - t, - []app.CompletionSignal{signal3}, - completionSignalsMap[0][0][readAccessB], - ) - require.Equal( - t, - []app.CompletionSignal{signal4}, - completionSignalsMap[2][0][readAccessB], - ) - slice := blockingSignalsMap[3][0][writeAccessB] - sort.SliceStable(slice, func(p, q int) bool { - return slice[p].FromNodeID < slice[q].FromNodeID - }) - require.Equal( - t, - []app.CompletionSignal{signal3, signal2, signal4}, - slice, - ) + // assert dag is acyclic + acyclic := graph.Acyclic(dag) + require.True(t, acyclic) } From 1ad2ffe8c469cd0de0e456b346893ba5c524beb8 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 39/41] Revert "Create Channels from DAG (#261)" This reverts commit 35b9cf4e9ed07e61e0c0d9137e6773c8d8018097. --- app/app.go | 146 +++++------------------------- app/graph.go | 43 +++------ app/graph_test.go | 24 ++--- go.mod | 2 +- go.sum | 4 +- x/oracle/simulation/operations.go | 4 +- 6 files changed, 54 insertions(+), 169 deletions(-) diff --git a/app/app.go b/app/app.go index f335ecd276..a8730d56cb 100644 --- a/app/app.go +++ b/app/app.go @@ -9,7 +9,6 @@ import ( "os" "path/filepath" "strings" - "sync" "time" storetypes "github.com/cosmos/cosmos-sdk/store/types" @@ -31,7 +30,6 @@ import ( servertypes "github.com/cosmos/cosmos-sdk/server/types" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" - sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" @@ -40,7 +38,6 @@ import ( aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol" aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" @@ -924,11 +921,11 @@ func (app *App) BuildDependencyDag(ctx sdk.Context, txs [][]byte) (*Dag, error) return nil, err } msgs := tx.GetMsgs() - for messageIndex, msg := range msgs { + for _, msg := range msgs { msgDependencies := app.AccessControlKeeper.GetResourceDependencyMapping(ctx, acltypes.GenerateMessageKey(msg)) - for _, accessOp := range msgDependencies.GetAccessOps() { + for _, accessOp := range msgDependencies.AccessOps { // make a new node in the dependency dag - dependencyDag.AddNodeBuildDependency(messageIndex, txIndex, accessOp) + dependencyDag.AddNodeBuildDependency(txIndex, accessOp) } } @@ -969,115 +966,6 @@ func (app *App) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) return &resp, nil } -func (app *App) DeliverTxWithResult(ctx sdk.Context, tx []byte) *abci.ExecTxResult { - deliverTxResp := app.DeliverTx(ctx, abci.RequestDeliverTx{ - Tx: tx, - }) - return &abci.ExecTxResult{ - Code: deliverTxResp.Code, - Data: deliverTxResp.Data, - Log: deliverTxResp.Log, - Info: deliverTxResp.Info, - GasWanted: deliverTxResp.GasWanted, - GasUsed: deliverTxResp.GasUsed, - Events: deliverTxResp.Events, - Codespace: deliverTxResp.Codespace, - } -} - -func (app *App) ProcessBlockSynchronous(ctx sdk.Context, txs [][]byte) []*abci.ExecTxResult { - txResults := []*abci.ExecTxResult{} - for _, tx := range txs { - txResults = append(txResults, app.DeliverTxWithResult(ctx, tx)) - } - return txResults -} - -// Returns a mapping of the accessOperation to the channels -func getChannelsFromSignalMapping(signalMapping MessageCompletionSignalMapping) sdkacltypes.MessageAccessOpsChannelMapping { - channelsMapping := make(sdkacltypes.MessageAccessOpsChannelMapping) - for messageIndex, accessOperationsToSignal := range signalMapping { - for accessOperation, completionSignals := range accessOperationsToSignal { - var channels []chan interface{} - for _, completionSignal := range completionSignals { - channels = append(channels, completionSignal.Channel) - } - channelsMapping[messageIndex][accessOperation] = channels - } - } - return channelsMapping -} - -type ChannelResult struct { - txIndex int - result *abci.ExecTxResult -} - -func (app *App) ProcessTxConcurrent( - ctx sdk.Context, - txIndex int, - txBytes []byte, - wg *sync.WaitGroup, - resultChan chan<- ChannelResult, - txCompletionSignalingMap MessageCompletionSignalMapping, - txBlockingSignalsMap MessageCompletionSignalMapping, -) { - defer wg.Done() - // Store the Channels in the Context Object for each transaction - ctx.WithTxBlockingChannels(getChannelsFromSignalMapping(txBlockingSignalsMap)) - ctx.WithTxCompletionChannels(getChannelsFromSignalMapping(txCompletionSignalingMap)) - - // Deliver the transaction and store the result in the channel - resultChan <- ChannelResult{txIndex, app.DeliverTxWithResult(ctx, txBytes)} -} - -func (app *App) ProcessBlockConcurrent( - ctx sdk.Context, - txs [][]byte, - completionSignalingMap map[int]MessageCompletionSignalMapping, - blockingSignalsMap map[int]MessageCompletionSignalMapping, -) []*abci.ExecTxResult { - var waitGroup sync.WaitGroup - resultChan := make(chan ChannelResult) - txResults := []*abci.ExecTxResult{} - - // If there's no transactions then return empty results - if len(txs) == 0 { - return txResults - } - - // For each transaction, start goroutine and deliver TX - for txIndex, txBytes := range txs { - waitGroup.Add(1) - go app.ProcessTxConcurrent( - ctx, - txIndex, - txBytes, - &waitGroup, - resultChan, - completionSignalingMap[txIndex], - blockingSignalsMap[txIndex], - ) - } - - // Waits for all the transactions to complete - waitGroup.Wait() - - // Gather Results and store it based on txIndex - // Concurrent results may be in different order than the original txIndex - txResultsMap := map[int]*abci.ExecTxResult{} - for result := range resultChan { - txResultsMap[result.txIndex] = result.result - } - - // Gather Results and store in array based on txIndex to preserve ordering - for txIndex := range txs { - txResults = append(txResults, txResultsMap[txIndex]) - } - - return txResults -} - 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) @@ -1119,18 +1007,30 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ // } // app.batchVerifier.VerifyTxs(ctx, typedTxs) - dependencyDag, err := app.BuildDependencyDag(ctx, txs) + dag, err := app.BuildDependencyDag(ctx, txs) txResults := []*abci.ExecTxResult{} - - // TODO:: add metrics for async vs sync if err != nil { - ctx.Logger().Error(fmt.Sprintf("Error while building DAG, processing synchronously: %s", err)) - if err == ErrCycleInDAG { - txResults = app.ProcessBlockSynchronous(ctx, txs) + // something went wrong in dag, process txs sequentially + for _, tx := range txs { + // ctx = ctx.WithContext(context.WithValue(ctx.Context(), ante.ContextKeyTxIndexKey, i)) + deliverTxResp := app.DeliverTx(ctx, abci.RequestDeliverTx{ + Tx: tx, + }) + txResults = append(txResults, &abci.ExecTxResult{ + Code: deliverTxResp.Code, + Data: deliverTxResp.Data, + Log: deliverTxResp.Log, + Info: deliverTxResp.Info, + GasWanted: deliverTxResp.GasWanted, + GasUsed: deliverTxResp.GasUsed, + Events: deliverTxResp.Events, + Codespace: deliverTxResp.Codespace, + }) } } else { - completionSignalingMap, blockingSignalsMap := dependencyDag.BuildCompletionSignalMaps() - txResults = app.ProcessBlockConcurrent(ctx, txs, completionSignalingMap, blockingSignalsMap) + // no error, lets process txs concurrently + _, _ = dag.BuildCompletionSignalMaps() + // TODO: create channel map here } endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{ diff --git a/app/graph.go b/app/graph.go index 05c958257d..3a846cccc2 100644 --- a/app/graph.go +++ b/app/graph.go @@ -3,14 +3,13 @@ package app import ( "fmt" - acltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" + acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" ) type DagNodeID int type DagNode struct { NodeID DagNodeID - MessageIndex int TxIndex int AccessOperation acltypes.AccessOperation } @@ -28,17 +27,6 @@ type Dag struct { NextID DagNodeID } -// Alias for mapping MessageIndexId -> AccessOperations -> CompletionSignals -type MessageCompletionSignalMapping = map[int]map[acltypes.AccessOperation][]CompletionSignal - -type CompletionSignal struct { - FromNodeID DagNodeID - ToNodeID DagNodeID - CompletionAccessOperation acltypes.AccessOperation // this is the access operation that must complete in order to send the signal - BlockedAccessOperation acltypes.AccessOperation // this is the access operation that is blocked by the completion access operation - Channel chan interface{} -} - func (dag *Dag) GetCompletionSignal(edge DagEdge) *CompletionSignal { // only if tx indexes are different fromNode := dag.NodeMap[edge.FromNodeID] @@ -51,8 +39,6 @@ func (dag *Dag) GetCompletionSignal(edge DagEdge) *CompletionSignal { ToNodeID: toNode.NodeID, CompletionAccessOperation: fromNode.AccessOperation, BlockedAccessOperation: toNode.AccessOperation, - // channel used for signalling - Channel: make(chan interface{}), } } @@ -82,10 +68,9 @@ func NewDag() Dag { } } -func (dag *Dag) AddNode(messageIndex int, txIndex int, accessOp acltypes.AccessOperation) DagNode { +func (dag *Dag) AddNode(txIndex int, accessOp acltypes.AccessOperation) DagNode { dagNode := DagNode{ NodeID: dag.NextID, - MessageIndex: messageIndex, TxIndex: txIndex, AccessOperation: accessOp, } @@ -116,8 +101,8 @@ func (dag *Dag) AddEdge(fromIndex DagNodeID, toIndex DagNodeID) *DagEdge { // that will allow the dependent goroutines to cordinate execution safely. // // It will also register the new node with AccessOpsMap so that future nodes that amy be dependent on this one can properly identify the dependency. -func (dag *Dag) AddNodeBuildDependency(messageIndex int, txIndex int, accessOp acltypes.AccessOperation) { - dagNode := dag.AddNode(messageIndex, txIndex, accessOp) +func (dag *Dag) AddNodeBuildDependency(txIndex int, accessOp acltypes.AccessOperation) { + dagNode := dag.AddNode(txIndex, accessOp) // if in TxIndexMap, make an edge from the previous node index if lastTxNodeID, ok := dag.TxIndexMap[txIndex]; ok { // TODO: we actually don't necessarily need these edges, but keeping for now so we can first determine that cycles can't be missed if we remove these @@ -201,10 +186,7 @@ func (dag *Dag) GetNodeDependencies(node DagNode) (nodeDependencies []DagNode) { } // returns completion signaling map and blocking signals map -func (dag *Dag) BuildCompletionSignalMaps() ( - completionSignalingMap map[int]MessageCompletionSignalMapping, - blockingSignalsMap map[int]MessageCompletionSignalMapping, -) { +func (dag *Dag) BuildCompletionSignalMaps() (completionSignalingMap map[int]map[acltypes.AccessOperation][]CompletionSignal, blockingSignalsMap map[int]map[acltypes.AccessOperation][]CompletionSignal) { // go through every node for _, node := range dag.NodeMap { // for each node, assign its completion signaling, and also assign blocking signals for the destination nodes @@ -213,15 +195,11 @@ func (dag *Dag) BuildCompletionSignalMaps() ( maybeCompletionSignal := dag.GetCompletionSignal(edge) if maybeCompletionSignal != nil { completionSignal := *maybeCompletionSignal - // add it to the right blocking signal in the right txindex toNode := dag.NodeMap[edge.ToNodeID] - prevBlockSignalMapping := blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] - blockingSignalsMap[toNode.TxIndex][toNode.MessageIndex][completionSignal.BlockedAccessOperation] = append(prevBlockSignalMapping, completionSignal) - + blockingSignalsMap[toNode.TxIndex][completionSignal.BlockedAccessOperation] = append(blockingSignalsMap[toNode.TxIndex][completionSignal.BlockedAccessOperation], completionSignal) // add it to the completion signal for the tx index - prevCompletionSignalMapping := completionSignalingMap[node.TxIndex][node.MessageIndex][completionSignal.CompletionAccessOperation] - completionSignalingMap[node.TxIndex][node.MessageIndex][completionSignal.CompletionAccessOperation] = append(prevCompletionSignalMapping, completionSignal) + completionSignalingMap[node.TxIndex][completionSignal.CompletionAccessOperation] = append(completionSignalingMap[node.TxIndex][completionSignal.CompletionAccessOperation], completionSignal) } } @@ -230,4 +208,11 @@ func (dag *Dag) BuildCompletionSignalMaps() ( return } +type CompletionSignal struct { + FromNodeID DagNodeID + ToNodeID DagNodeID + CompletionAccessOperation acltypes.AccessOperation // this is the access operation that must complete in order to send the signal + BlockedAccessOperation acltypes.AccessOperation // this is the access operation that is blocked by the completion access operation +} + var ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") diff --git a/app/graph_test.go b/app/graph_test.go index 622705eab1..ebc6b24cb4 100644 --- a/app/graph_test.go +++ b/app/graph_test.go @@ -3,7 +3,7 @@ package app_test import ( "testing" - acltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol" + acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" "github.com/sei-protocol/sei-chain/app" "github.com/stretchr/testify/require" "github.com/yourbasic/graph" @@ -48,17 +48,17 @@ func TestCreateGraph(t *testing.T) { IdentifierTemplate: "ResourceB", } - dag.AddNodeBuildDependency(1, 1, writeAccessA) // node id 0 - dag.AddNodeBuildDependency(1, 1, readAccessB) // node id 1 - dag.AddNodeBuildDependency(1, 1, commitAccessOp) // node id 2 - dag.AddNodeBuildDependency(1, 2, readAccessA) // node id 3 - dag.AddNodeBuildDependency(1, 2, readAccessB) // node id 4 - dag.AddNodeBuildDependency(1, 2, commitAccessOp) // node id 5 - dag.AddNodeBuildDependency(1, 3, readAccessB) // node id 6 - dag.AddNodeBuildDependency(1, 3, readAccessA) // node id 7 - dag.AddNodeBuildDependency(1, 3, commitAccessOp) // node id 8 - dag.AddNodeBuildDependency(1, 4, writeAccessB) // node id 9 - dag.AddNodeBuildDependency(1, 4, commitAccessOp) // node id 10 + dag.AddNodeBuildDependency(1, writeAccessA) // node id 0 + dag.AddNodeBuildDependency(1, readAccessB) // node id 1 + dag.AddNodeBuildDependency(1, commitAccessOp) // node id 2 + dag.AddNodeBuildDependency(2, readAccessA) // node id 3 + dag.AddNodeBuildDependency(2, readAccessB) // node id 4 + dag.AddNodeBuildDependency(2, commitAccessOp) // node id 5 + dag.AddNodeBuildDependency(3, readAccessB) // node id 6 + dag.AddNodeBuildDependency(3, readAccessA) // node id 7 + dag.AddNodeBuildDependency(3, commitAccessOp) // node id 8 + dag.AddNodeBuildDependency(4, writeAccessB) // node id 9 + dag.AddNodeBuildDependency(4, commitAccessOp) // node id 10 require.Equal( t, diff --git a/go.mod b/go.mod index 67bba1d655..5ce81ceb60 100644 --- a/go.mod +++ b/go.mod @@ -131,7 +131,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.69 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.67 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 diff --git a/go.sum b/go.sum index 0455dd7c2b..52c574d70b 100644 --- a/go.sum +++ b/go.sum @@ -1096,8 +1096,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.69 h1:jPFTf6vSg3DQ0FgKpQGw6ZEUuElKL2UJ3P8SBXbYnio= -github.com/sei-protocol/sei-cosmos v0.1.69/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= +github.com/sei-protocol/sei-cosmos v0.1.67 h1:AdjpHcaryUaGI4X9nnK13YWxPOguDveH2sH+06gBsCw= +github.com/sei-protocol/sei-cosmos v0.1.67/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= 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= diff --git a/x/oracle/simulation/operations.go b/x/oracle/simulation/operations.go index 2028e73625..3988c4b164 100644 --- a/x/oracle/simulation/operations.go +++ b/x/oracle/simulation/operations.go @@ -65,7 +65,7 @@ func WeightedOperations( } // 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, @@ -122,7 +122,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, From 2167370cf0deec98c8d7aeb8485d0ccb7ccf7723 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 40/41] Revert "[accesscontrol] Add dependency dag (#258)" This reverts commit 672184545c73d8576bf57361fe8619cb15e5dc5d. --- app/app.go | 69 ++++----------- app/graph.go | 218 ---------------------------------------------- app/graph_test.go | 110 ----------------------- go.mod | 3 +- go.sum | 6 +- 5 files changed, 20 insertions(+), 386 deletions(-) delete mode 100644 app/graph.go delete mode 100644 app/graph_test.go diff --git a/app/app.go b/app/app.go index a8730d56cb..46ae491f27 100644 --- a/app/app.go +++ b/app/app.go @@ -12,7 +12,6 @@ import ( "time" storetypes "github.com/cosmos/cosmos-sdk/store/types" - graph "github.com/yourbasic/graph" appparams "github.com/sei-protocol/sei-chain/app/params" "github.com/sei-protocol/sei-chain/utils" @@ -329,7 +328,7 @@ type App struct { optimisticProcessingInfo *OptimisticProcessingInfo // batchVerifier *ante.SR25519BatchVerifier - txDecoder sdk.TxDecoder + // txDecoder sdk.TxDecoder } // New returns a reference to an initialized blockchain app @@ -389,7 +388,7 @@ func New( Tracer: &tr, TracerContext: context.Background(), }, - txDecoder: encodingConfig.TxConfig.TxDecoder(), + // txDecoder: encodingConfig.TxConfig.TxDecoder(), } app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) @@ -912,31 +911,6 @@ func (app *App) ProcessProposalHandler(ctx sdk.Context, req *abci.RequestProcess }, nil } -func (app *App) BuildDependencyDag(ctx sdk.Context, txs [][]byte) (*Dag, error) { - // contains the latest msg index for a specific Access Operation - dependencyDag := NewDag() - for txIndex, txBytes := range txs { - tx, err := app.txDecoder(txBytes) // TODO: results in repetitive decoding for txs with runtx decode (potential optimization) - if err != nil { - return nil, err - } - msgs := tx.GetMsgs() - for _, msg := range msgs { - msgDependencies := app.AccessControlKeeper.GetResourceDependencyMapping(ctx, acltypes.GenerateMessageKey(msg)) - for _, accessOp := range msgDependencies.AccessOps { - // make a new node in the dependency dag - dependencyDag.AddNodeBuildDependency(txIndex, accessOp) - } - } - - } - - if !graph.Acyclic(&dependencyDag) { - return nil, ErrCycleInDAG - } - return &dependencyDag, nil -} - func (app *App) FinalizeBlocker(ctx sdk.Context, req *abci.RequestFinalizeBlock) (*abci.ResponseFinalizeBlock, error) { startTime := time.Now() defer func() { @@ -1007,32 +981,23 @@ func (app *App) ProcessBlock(ctx sdk.Context, txs [][]byte, req BlockProcessRequ // } // app.batchVerifier.VerifyTxs(ctx, typedTxs) - dag, err := app.BuildDependencyDag(ctx, txs) txResults := []*abci.ExecTxResult{} - if err != nil { - // something went wrong in dag, process txs sequentially - for _, tx := range txs { - // ctx = ctx.WithContext(context.WithValue(ctx.Context(), ante.ContextKeyTxIndexKey, i)) - deliverTxResp := app.DeliverTx(ctx, abci.RequestDeliverTx{ - Tx: tx, - }) - txResults = append(txResults, &abci.ExecTxResult{ - Code: deliverTxResp.Code, - Data: deliverTxResp.Data, - Log: deliverTxResp.Log, - Info: deliverTxResp.Info, - GasWanted: deliverTxResp.GasWanted, - GasUsed: deliverTxResp.GasUsed, - Events: deliverTxResp.Events, - Codespace: deliverTxResp.Codespace, - }) - } - } else { - // no error, lets process txs concurrently - _, _ = dag.BuildCompletionSignalMaps() - // TODO: create channel map here + for _, tx := range txs { + // ctx = ctx.WithContext(context.WithValue(ctx.Context(), ante.ContextKeyTxIndexKey, i)) + deliverTxResp := app.DeliverTx(ctx, abci.RequestDeliverTx{ + Tx: tx, + }) + txResults = append(txResults, &abci.ExecTxResult{ + Code: deliverTxResp.Code, + Data: deliverTxResp.Data, + Log: deliverTxResp.Log, + Info: deliverTxResp.Info, + GasWanted: deliverTxResp.GasWanted, + GasUsed: deliverTxResp.GasUsed, + Events: deliverTxResp.Events, + Codespace: deliverTxResp.Codespace, + }) } - endBlockResp := app.EndBlock(ctx, abci.RequestEndBlock{ Height: req.GetHeight(), }) diff --git a/app/graph.go b/app/graph.go deleted file mode 100644 index 3a846cccc2..0000000000 --- a/app/graph.go +++ /dev/null @@ -1,218 +0,0 @@ -package app - -import ( - "fmt" - - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" -) - -type DagNodeID int - -type DagNode struct { - NodeID DagNodeID - TxIndex int - AccessOperation acltypes.AccessOperation -} - -type DagEdge struct { - FromNodeID DagNodeID - ToNodeID DagNodeID -} - -type Dag struct { - NodeMap map[DagNodeID]DagNode - EdgesMap map[DagNodeID][]DagEdge // maps node Id (from node) and contains edge info - AccessOpsMap map[acltypes.AccessOperation][]DagNodeID // tracks latest node to use a specific access op - TxIndexMap map[int]DagNodeID // tracks latest node ID for a tx index - NextID DagNodeID -} - -func (dag *Dag) GetCompletionSignal(edge DagEdge) *CompletionSignal { - // only if tx indexes are different - fromNode := dag.NodeMap[edge.FromNodeID] - toNode := dag.NodeMap[edge.ToNodeID] - if fromNode.TxIndex == toNode.TxIndex { - return nil - } - return &CompletionSignal{ - FromNodeID: fromNode.NodeID, - ToNodeID: toNode.NodeID, - CompletionAccessOperation: fromNode.AccessOperation, - BlockedAccessOperation: toNode.AccessOperation, - } -} - -// Order returns the number of vertices in a graph. -func (dag Dag) Order() int { - return len(dag.NodeMap) -} - -// Visit calls the do function for each neighbor w of vertex v, used by the graph acyclic validator -func (dag Dag) Visit(v int, do func(w int, c int64) (skip bool)) (aborted bool) { - for _, edge := range dag.EdgesMap[DagNodeID(v)] { - // just have cost as zero because we only need for acyclic validation purposes - if do(int(edge.ToNodeID), 0) { - return true - } - } - return false -} - -func NewDag() Dag { - return Dag{ - NodeMap: make(map[DagNodeID]DagNode), - EdgesMap: make(map[DagNodeID][]DagEdge), - AccessOpsMap: make(map[acltypes.AccessOperation][]DagNodeID), - TxIndexMap: make(map[int]DagNodeID), - NextID: 0, - } -} - -func (dag *Dag) AddNode(txIndex int, accessOp acltypes.AccessOperation) DagNode { - dagNode := DagNode{ - NodeID: dag.NextID, - TxIndex: txIndex, - AccessOperation: accessOp, - } - dag.NodeMap[dag.NextID] = dagNode - dag.NextID++ - return dagNode -} - -func (dag *Dag) AddEdge(fromIndex DagNodeID, toIndex DagNodeID) *DagEdge { - // no-ops if the from or to node doesn't exist - if _, ok := dag.NodeMap[fromIndex]; !ok { - return nil - } - if _, ok := dag.NodeMap[toIndex]; !ok { - return nil - } - newEdge := DagEdge{fromIndex, toIndex} - dag.EdgesMap[fromIndex] = append(dag.EdgesMap[fromIndex], newEdge) - return &newEdge -} - -// This function is a helper used to build the dependency graph one access operation at a time. -// It will first add a node corresponding to the tx index and access operation (linking it to the previous most recent node for that tx if applicable) -// and then will build edges from any access operations on which the new node is dependent. -// -// This will be accomplished using the AccessOpsMap in dag which keeps track of which nodes access which resources. -// It will then create an edge between the relevant node upon which it is dependent, and this edge can later be used to build the completion signals -// that will allow the dependent goroutines to cordinate execution safely. -// -// It will also register the new node with AccessOpsMap so that future nodes that amy be dependent on this one can properly identify the dependency. -func (dag *Dag) AddNodeBuildDependency(txIndex int, accessOp acltypes.AccessOperation) { - dagNode := dag.AddNode(txIndex, accessOp) - // if in TxIndexMap, make an edge from the previous node index - if lastTxNodeID, ok := dag.TxIndexMap[txIndex]; ok { - // TODO: we actually don't necessarily need these edges, but keeping for now so we can first determine that cycles can't be missed if we remove these - // add an edge between access ops in a transaction - dag.AddEdge(lastTxNodeID, dagNode.NodeID) - } - // update tx index map - dag.TxIndexMap[txIndex] = dagNode.NodeID - - nodeDependencies := dag.GetNodeDependencies(dagNode) - // build edges for each of the dependencies - for _, nodeDependency := range nodeDependencies { - dag.AddEdge(nodeDependency.NodeID, dagNode.NodeID) - } - - // update access ops map with the latest node id using a specific access op - dag.AccessOpsMap[accessOp] = append(dag.AccessOpsMap[accessOp], dagNode.NodeID) -} - -// This helper will identify nodes that are dependencies for the current node, and can then be used for creating edges between then for future completion signals -func (dag *Dag) GetNodeDependencies(node DagNode) (nodeDependencies []DagNode) { - accessOp := node.AccessOperation - // if the blocking access ops are in access ops map, make an edge - switch accessOp.AccessType { - case acltypes.AccessType_READ: - // if we need to do a read, we need latest write as a dependency - // TODO: replace hardcoded access op dependencies with helper that generates (and also generates superseding resources too eg. Resource.ALL is blocking for Resource.KV) - writeAccessOp := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_WRITE, - ResourceType: accessOp.GetResourceType(), - IdentifierTemplate: accessOp.GetIdentifierTemplate(), - } - if writeNodeIDs, ok := dag.AccessOpsMap[writeAccessOp]; ok { - for _, wn := range writeNodeIDs { - writeNode := dag.NodeMap[wn] - // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) - // if from a previous transaction, we need to create an edge - if writeNode.TxIndex < node.TxIndex { - // this should be the COMMIT access op for the tx - lastTxNode := dag.NodeMap[dag.TxIndexMap[writeNode.TxIndex]] - nodeDependencies = append(nodeDependencies, lastTxNode) - } - } - } - case acltypes.AccessType_WRITE, acltypes.AccessType_UNKNOWN: - // if we need to do a write, we need read and write as dependencies - writeAccessOp := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_WRITE, - ResourceType: accessOp.GetResourceType(), - IdentifierTemplate: accessOp.GetIdentifierTemplate(), - } - if writeNodeIDs, ok := dag.AccessOpsMap[writeAccessOp]; ok { - for _, wn := range writeNodeIDs { - // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) - writeNode := dag.NodeMap[wn] - // if from a previous transaction, we need to create an edge - if writeNode.TxIndex < node.TxIndex { - // we need to get the last node from that tx - lastTxNode := dag.NodeMap[dag.TxIndexMap[writeNode.TxIndex]] - nodeDependencies = append(nodeDependencies, lastTxNode) - } - } - } - readAccessOp := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_READ, - ResourceType: accessOp.GetResourceType(), - IdentifierTemplate: accessOp.GetIdentifierTemplate(), - } - if readNodeIDs, ok := dag.AccessOpsMap[readAccessOp]; ok { - for _, rn := range readNodeIDs { - readNode := dag.NodeMap[rn] - // if accessOp exists already (and from a previous transaction), we need to define a dependency on the previous message (and make a edge between the two) - // if from a previous transaction, we need to create an edge - if readNode.TxIndex < node.TxIndex { - nodeDependencies = append(nodeDependencies, readNode) - } - } - } - } - return nodeDependencies -} - -// returns completion signaling map and blocking signals map -func (dag *Dag) BuildCompletionSignalMaps() (completionSignalingMap map[int]map[acltypes.AccessOperation][]CompletionSignal, blockingSignalsMap map[int]map[acltypes.AccessOperation][]CompletionSignal) { - // go through every node - for _, node := range dag.NodeMap { - // for each node, assign its completion signaling, and also assign blocking signals for the destination nodes - if outgoingEdges, ok := dag.EdgesMap[node.NodeID]; ok { - for _, edge := range outgoingEdges { - maybeCompletionSignal := dag.GetCompletionSignal(edge) - if maybeCompletionSignal != nil { - completionSignal := *maybeCompletionSignal - // add it to the right blocking signal in the right txindex - toNode := dag.NodeMap[edge.ToNodeID] - blockingSignalsMap[toNode.TxIndex][completionSignal.BlockedAccessOperation] = append(blockingSignalsMap[toNode.TxIndex][completionSignal.BlockedAccessOperation], completionSignal) - // add it to the completion signal for the tx index - completionSignalingMap[node.TxIndex][completionSignal.CompletionAccessOperation] = append(completionSignalingMap[node.TxIndex][completionSignal.CompletionAccessOperation], completionSignal) - } - - } - } - } - return -} - -type CompletionSignal struct { - FromNodeID DagNodeID - ToNodeID DagNodeID - CompletionAccessOperation acltypes.AccessOperation // this is the access operation that must complete in order to send the signal - BlockedAccessOperation acltypes.AccessOperation // this is the access operation that is blocked by the completion access operation -} - -var ErrCycleInDAG = fmt.Errorf("cycle detected in DAG") diff --git a/app/graph_test.go b/app/graph_test.go deleted file mode 100644 index ebc6b24cb4..0000000000 --- a/app/graph_test.go +++ /dev/null @@ -1,110 +0,0 @@ -package app_test - -import ( - "testing" - - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" - "github.com/sei-protocol/sei-chain/app" - "github.com/stretchr/testify/require" - "github.com/yourbasic/graph" -) - -func TestCreateGraph(t *testing.T) { - dag := app.NewDag() - /** - tx1: write to A, read B, commit 1 - tx2: read A, read B, commit 2 - tx3: read A, read B, commit 3 - tx4: write B, commit 4 - expected dag - 1wA -> 1rB -> 1c =>v 2rA -> 2rB ----=\---> 2c - 3rB -------------> 3rA -> 3c V - \-----------------------------------=> 4wB -> 4c - **/ - - commitAccessOp := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_COMMIT, - ResourceType: acltypes.ResourceType_ANY, - IdentifierTemplate: "*", - } - writeAccessA := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_WRITE, - ResourceType: acltypes.ResourceType_KV, - IdentifierTemplate: "ResourceA", - } - readAccessA := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_READ, - ResourceType: acltypes.ResourceType_KV, - IdentifierTemplate: "ResourceA", - } - writeAccessB := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_WRITE, - ResourceType: acltypes.ResourceType_KV, - IdentifierTemplate: "ResourceB", - } - readAccessB := acltypes.AccessOperation{ - AccessType: acltypes.AccessType_READ, - ResourceType: acltypes.ResourceType_KV, - IdentifierTemplate: "ResourceB", - } - - dag.AddNodeBuildDependency(1, writeAccessA) // node id 0 - dag.AddNodeBuildDependency(1, readAccessB) // node id 1 - dag.AddNodeBuildDependency(1, commitAccessOp) // node id 2 - dag.AddNodeBuildDependency(2, readAccessA) // node id 3 - dag.AddNodeBuildDependency(2, readAccessB) // node id 4 - dag.AddNodeBuildDependency(2, commitAccessOp) // node id 5 - dag.AddNodeBuildDependency(3, readAccessB) // node id 6 - dag.AddNodeBuildDependency(3, readAccessA) // node id 7 - dag.AddNodeBuildDependency(3, commitAccessOp) // node id 8 - dag.AddNodeBuildDependency(4, writeAccessB) // node id 9 - dag.AddNodeBuildDependency(4, commitAccessOp) // node id 10 - - require.Equal( - t, - []app.DagEdge{{0, 1}}, - dag.EdgesMap[0], - ) - require.Equal( - t, - []app.DagEdge{{1, 2}, {1, 9}}, - dag.EdgesMap[1], - ) - require.Equal( - t, - []app.DagEdge{{2, 3}, {2, 7}}, - dag.EdgesMap[2], - ) - require.Equal( - t, - []app.DagEdge{{3, 4}}, - dag.EdgesMap[3], - ) - require.Equal( - t, - []app.DagEdge{{4, 5}, {4, 9}}, - dag.EdgesMap[4], - ) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[5]) - require.Equal( - t, - []app.DagEdge{{6, 7}, {6, 9}}, - dag.EdgesMap[6], - ) - require.Equal( - t, - []app.DagEdge{{7, 8}}, - dag.EdgesMap[7], - ) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[8]) - require.Equal( - t, - []app.DagEdge{{9, 10}}, - dag.EdgesMap[9], - ) - require.Equal(t, []app.DagEdge(nil), dag.EdgesMap[10]) - - // assert dag is acyclic - acyclic := graph.Acyclic(dag) - require.True(t, acyclic) -} diff --git a/go.mod b/go.mod index 5ce81ceb60..915cf64c53 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,6 @@ require ( github.com/stretchr/testify v1.8.0 github.com/tendermint/tendermint v0.37.0-dev github.com/tendermint/tm-db v0.6.8-0.20220519162814-e24b96538a12 - github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869 go.opentelemetry.io/otel v1.9.0 go.opentelemetry.io/otel/exporters/jaeger v1.9.0 go.opentelemetry.io/otel/sdk v1.9.0 @@ -131,7 +130,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.67 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.66 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 diff --git a/go.sum b/go.sum index 52c574d70b..c76dfdfbac 100644 --- a/go.sum +++ b/go.sum @@ -1096,8 +1096,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.67 h1:AdjpHcaryUaGI4X9nnK13YWxPOguDveH2sH+06gBsCw= -github.com/sei-protocol/sei-cosmos v0.1.67/go.mod h1:Oaj7toqHCkwEEb+sDIWxtfTkPZxOpMXBXDMvIIqUjpw= +github.com/sei-protocol/sei-cosmos v0.1.66 h1:ow4z4wKm1iN1GoZAaz+kCB6nv+BKSLnhpFvyale785M= +github.com/sei-protocol/sei-cosmos v0.1.66/go.mod h1:3uCdb2FCio9uVQRPdZxZ1GqHqyb1moYH93xtTMa7DL8= 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= @@ -1249,8 +1249,6 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1: github.com/yagipy/maintidx v1.0.0/go.mod h1:0qNf/I/CCZXSMhsRsrEPDZ+DkekpKLXAJfsTACwgXLk= github.com/ybbus/jsonrpc v2.1.2+incompatible/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE= github.com/yeya24/promlinter v0.2.0/go.mod h1:u54lkmBOZrpEbQQ6gox2zWKKLKu2SGe+2KOiextY+IA= -github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869 h1:7v7L5lsfw4w8iqBBXETukHo4IPltmD+mWoLRYUmeGN8= -github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869/go.mod h1:Rfzr+sqaDreiCaoQbFCu3sTXxeFq/9kXRuyOoSlGQHE= github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= From 7fc04d05df10ea80af8d8a2758a303efffbf74b3 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Tue, 1 Nov 2022 11:53:59 -0400 Subject: [PATCH 41/41] Revert "Register accesscontrol module (#257)" This reverts commit 3e34d34cff42b574f8cd56226fe86975406c7426. --- app/app.go | 62 ++++++++++++++++-------------------------------------- go.mod | 6 +++--- go.sum | 8 +++---- 3 files changed, 25 insertions(+), 51 deletions(-) diff --git a/app/app.go b/app/app.go index 46ae491f27..f8db6e55d2 100644 --- a/app/app.go +++ b/app/app.go @@ -33,10 +33,6 @@ import ( "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth/ante" - - aclmodule "github.com/cosmos/cosmos-sdk/x/accesscontrol" - aclkeeper "github.com/cosmos/cosmos-sdk/x/accesscontrol/keeper" - acltypes "github.com/cosmos/cosmos-sdk/x/accesscontrol/types" authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" @@ -162,7 +158,6 @@ var ( // non-dependant module elements, such as codec registration // and genesis verification. ModuleBasics = module.NewBasicManager( - aclmodule.AppModuleBasic{}, auth.AppModuleBasic{}, genutil.AppModuleBasic{}, bank.AppModuleBasic{}, @@ -191,7 +186,6 @@ var ( // module account permissions maccPerms = map[string][]string{ - acltypes.ModuleName: nil, authtypes.FeeCollectorName: nil, distrtypes.ModuleName: nil, minttypes.ModuleName: {authtypes.Minter}, @@ -284,24 +278,23 @@ type App struct { memKeys map[string]*sdk.MemoryStoreKey // keepers - AccessControlKeeper aclkeeper.Keeper - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.Keeper - CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper stakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper - MintKeeper mintkeeper.Keeper - DistrKeeper distrkeeper.Keeper - GovKeeper govkeeper.Keeper - CrisisKeeper crisiskeeper.Keeper - UpgradeKeeper upgradekeeper.Keeper - ParamsKeeper paramskeeper.Keeper - IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly - EvidenceKeeper evidencekeeper.Keeper - TransferKeeper ibctransferkeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - WasmKeeper wasm.Keeper - OracleKeeper oraclekeeper.Keeper + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper govkeeper.Keeper + CrisisKeeper crisiskeeper.Keeper + UpgradeKeeper upgradekeeper.Keeper + ParamsKeeper paramskeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + WasmKeeper wasm.Keeper + OracleKeeper oraclekeeper.Keeper // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -356,7 +349,7 @@ func New( bApp.SetInterfaceRegistry(interfaceRegistry) keys := sdk.NewKVStoreKeys( - acltypes.StoreKey, authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, oracletypes.StoreKey, wasm.StoreKey, @@ -406,11 +399,6 @@ func New( // this line is used by starport scaffolding # stargate/app/scopedKeeper // add keepers - app.AccessControlKeeper = aclkeeper.NewKeeper( - appCodec, - app.keys[acltypes.StoreKey], - app.GetSubspace(acltypes.ModuleName), - ) app.AccountKeeper = authkeeper.NewAccountKeeper( appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, ) @@ -580,7 +568,6 @@ func New( app.AccountKeeper, app.StakingKeeper, app.BaseApp.DeliverTx, encodingConfig.TxConfig, ), - aclmodule.NewAppModule(appCodec, app.AccessControlKeeper), auth.NewAppModule(appCodec, app.AccountKeeper, nil), vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper), @@ -634,7 +621,6 @@ func New( wasm.ModuleName, tokenfactorytypes.ModuleName, nitrotypes.ModuleName, - acltypes.ModuleName, ) app.mm.SetOrderEndBlockers( @@ -661,7 +647,6 @@ func New( wasm.ModuleName, tokenfactorytypes.ModuleName, nitrotypes.ModuleName, - acltypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -693,7 +678,6 @@ func New( dexmoduletypes.ModuleName, nitrotypes.ModuleName, wasm.ModuleName, - acltypes.ModuleName, // this line is used by starport scaffolding # stargate/app/initGenesis ) @@ -833,15 +817,6 @@ func (app *App) SetStoreUpgradeHandlers() { // configure store loader that checks if version == upgradeHeight and applies store upgrades app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) } - - if upgradeInfo.Name == "2.0.0beta" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { - storeUpgrades := storetypes.StoreUpgrades{ - Added: []string{acltypes.StoreKey}, - } - - // configure store loader that checks if version == upgradeHeight and applies store upgrades - app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) - } } // AppName returns the name of the App @@ -1142,7 +1117,6 @@ func GetMaccPerms() map[string][]string { func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper { paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) - paramsKeeper.Subspace(acltypes.ModuleName) paramsKeeper.Subspace(authtypes.ModuleName) paramsKeeper.Subspace(banktypes.ModuleName) paramsKeeper.Subspace(stakingtypes.ModuleName) diff --git a/go.mod b/go.mod index 915cf64c53..5365061c13 100644 --- a/go.mod +++ b/go.mod @@ -24,8 +24,8 @@ require ( go.opentelemetry.io/otel/exporters/jaeger v1.9.0 go.opentelemetry.io/otel/sdk v1.9.0 go.opentelemetry.io/otel/trace v1.9.0 - google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc - google.golang.org/grpc v1.48.0 + google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a + google.golang.org/grpc v1.50.1 google.golang.org/protobuf v1.28.1 gopkg.in/yaml.v2 v2.4.0 ) @@ -130,7 +130,7 @@ require ( ) replace ( - github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.66 + github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.1.195 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 diff --git a/go.sum b/go.sum index c76dfdfbac..70864e68ad 100644 --- a/go.sum +++ b/go.sum @@ -1096,8 +1096,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.66 h1:ow4z4wKm1iN1GoZAaz+kCB6nv+BKSLnhpFvyale785M= -github.com/sei-protocol/sei-cosmos v0.1.66/go.mod h1:3uCdb2FCio9uVQRPdZxZ1GqHqyb1moYH93xtTMa7DL8= +github.com/sei-protocol/sei-cosmos v0.1.195 h1:WfHp+1x6DRH2jl936ogDLo443EtSvbNY62pZ7msVY9s= +github.com/sei-protocol/sei-cosmos v0.1.195/go.mod h1:bNUxufOqMG4cRokrw2Q30rQ1rOwJYjHTWsQoH+UZTFY= 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= @@ -1905,8 +1905,8 @@ google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3/go.mod h1:8w6bsBMX google.golang.org/genproto v0.0.0-20220429170224-98d788798c3e/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= -google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc h1:Nf+EdcTLHR8qDNN/KfkQL0u0ssxt9OhbaWCl5C0ucEI= -google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk= +google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a h1:GH6UPn3ixhWcKDhpnEC55S75cerLPdpp3hrhfKYjZgw= +google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a/go.mod h1:1vXfmgAz9N9Jx0QA82PqRVauvCz1SGSz739p0f183jM= google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=