From 45ee1b68ff8e8d48569d0441802dae5f5f9e6ce0 Mon Sep 17 00:00:00 2001 From: zakir <80246097+zakir-code@users.noreply.github.com> Date: Tue, 4 Jul 2023 11:17:00 +0800 Subject: [PATCH 01/30] chore: perf stats validator reward script --- contrib/stats/run.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/contrib/stats/run.sh b/contrib/stats/run.sh index 5d84d3e7b..7bea2d543 100755 --- a/contrib/stats/run.sh +++ b/contrib/stats/run.sh @@ -75,8 +75,13 @@ function calc_upgrade_time() { function show_validator_reward() { local decimals=18 + staking_token_denom=$(curl -s "$REST_RPC/cosmos/staking/v1beta1/params" | jq -r '.params.bond_denom') { - echo "moniker#operator_address#jailed#status#commission_rate#self_delegated#3rd_party_delegated#block_reward#tx_fee_reward" + if [ "$staking_token_denom" == "$MINT_DENOM" ]; then + echo "operator_address#jailed#status#commission_rate#self_delegated#3rd_party_delegated#block_reward#moniker" + else + echo "operator_address#jailed#status#commission_rate#self_delegated#3rd_party_delegated#block_reward#tx_fee_reward#moniker" + fi while read -r operator_address jailed status tokens commission_rate moniker; do acc_address=$(curl -s "$REST_RPC/fx/auth/v1/bech32/$operator_address?prefix=${BECH32_PREFIX}" | jq -r '.address') self_delegated=$(curl -s "$REST_RPC/cosmos/staking/v1beta1/delegations/$acc_address" | jq -r '.delegation_responses[]|select(.delegation.validator_address == "'"$operator_address"'")|.balance.amount') @@ -100,12 +105,16 @@ function show_validator_reward() { party_delegated=$(echo "$tokens-$self_delegated" | bc) commission_rate=$(printf "%.2f" "$(echo "scale=2;($commission_rate * 100)/1" | bc -l)") - self_delegated=$(echo "$self_delegated / 10^$decimals" | bc) - party_delegated=$(echo "$party_delegated / 10^$decimals" | bc) - block_reward=$(echo "$block_reward / 10^$decimals" | bc) - echo "$moniker#$operator_address#$jailed#$status#$commission_rate%#$self_delegated#$party_delegated#$block_reward#$tx_fee_reward" + self_delegated=$(echo "scale=2;$self_delegated / 10^$decimals" | bc) + party_delegated=$(echo "scale=2;$party_delegated / 10^$decimals" | bc) + block_reward=$(echo "scale=2;$block_reward / 10^$decimals" | bc) + if [ "$staking_token_denom" == "$MINT_DENOM" ]; then + echo "$operator_address#$jailed#$status#$commission_rate%#$self_delegated#$party_delegated#$block_reward#$moniker" + else + echo "$operator_address#$jailed#$status#$commission_rate%#$self_delegated#$party_delegated#$block_reward#$tx_fee_reward#$moniker" + fi done < <(curl -s "$REST_RPC/cosmos/staking/v1beta1/validators" | jq -r '.validators[]|"\(.operator_address) \(.jailed) \(.status) \(.tokens) \(.commission.commission_rates.rate) \(.description.moniker)"') - } | column -t -s"#" + } | column -t -R -s"#" } function show_validator_vote() { From c4865b75aae7f9d13d045c57eddaa801cc2d203d Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Thu, 15 Jun 2023 15:48:57 +0800 Subject: [PATCH 02/30] chore: update Go import paths to v5 --- Makefile | 2 +- README.md | 4 +- ante/ante_sigs_test.go | 2 +- ante/ante_test.go | 8 +-- ante/eth_test.go | 4 +- ante/fee_market_test.go | 4 +- ante/fees_test.go | 4 +- app/app.go | 30 +++++------ app/app_test.go | 2 +- app/encoding.go | 4 +- app/encoding_test.go | 2 +- app/export_test.go | 10 ++-- app/genesis.go | 6 +-- app/genesis_test.go | 4 +- app/keepers/keepers.go | 50 +++++++++--------- app/keepers/keepers_test.go | 22 ++++---- app/keepers/keys.go | 24 ++++----- app/modules.go | 52 +++++++++---------- app/modules_test.go | 2 +- app/upgrade.go | 4 +- app/upgrade_test.go | 34 ++++++------ app/upgrades/types.go | 2 +- app/upgrades/v4/constants.go | 10 ++-- app/upgrades/v4/upgrade.go | 24 ++++----- app/upgrades/v4/upgrade_test.go | 4 +- app/upgrades/v4_1/constants.go | 6 +-- app/upgrades/v4_1/upgrade.go | 6 +-- app/upgrades/v4_2/constants.go | 6 +-- app/upgrades/v4_2/upgrade.go | 10 ++-- client/cli/debug_test.go | 2 +- client/cli/gentx.go | 2 +- client/cli/keys/parse.go | 2 +- client/client_test.go | 16 +++--- client/grpc/grpc_client.go | 8 +-- client/grpc/grpc_client_test.go | 4 +- client/jsonrpc/abci_query.go | 2 +- client/jsonrpc/json_rpc.go | 2 +- client/jsonrpc/rpc_client_test.go | 4 +- cmd/config.go | 2 +- cmd/config_test.go | 2 +- cmd/doctor.go | 8 +-- cmd/doctor_test.go | 2 +- cmd/fxcored/main.go | 4 +- cmd/keys.go | 2 +- cmd/root.go | 26 +++++----- cmd/testnet.go | 8 +-- docs/swagger_test.go | 2 +- go.mod | 2 +- server/config/config_cmd.go | 2 +- server/config/config_cmd_test.go | 2 +- server/database_test.go | 4 +- server/grpc/auth/grpc_query.go | 2 +- server/log_filter_test.go | 2 +- server/rosetta.go | 2 +- server/start.go | 6 +-- server/start_test.go | 6 +-- tests/amino_test.go | 12 ++--- tests/ante_test.go | 2 +- tests/contract_test.go | 2 +- tests/crosschain_suite.go | 8 +-- tests/crosschain_test.go | 8 +-- tests/erc20_suite.go | 8 +-- tests/erc20_test.go | 12 ++--- tests/evm_suite.go | 10 ++-- tests/evm_test.go | 10 ++-- tests/integration_test.go | 6 +-- tests/migrate_test.go | 6 +-- tests/staking_suite.go | 8 +-- tests/staking_test.go | 6 +-- tests/store/subspace_test.go | 4 +- tests/suite.go | 16 +++--- tests/upgrade_time_calc_test.go | 2 +- testutil/helpers/key_test.go | 2 +- testutil/helpers/test_helpers.go | 6 +-- testutil/network.go | 10 ++-- testutil/network/network.go | 4 +- testutil/network/util.go | 6 +-- testutil/network_test.go | 8 +-- types/byte32_test.go | 2 +- types/contract.go | 2 +- types/eth_validation_test.go | 4 +- types/target_test.go | 2 +- x/arbitrum/client/cli/query.go | 4 +- x/arbitrum/client/cli/tx.go | 4 +- x/arbitrum/module.go | 8 +-- x/arbitrum/types/genesis.go | 2 +- x/arbitrum/types/genesis_test.go | 4 +- x/avalanche/client/cli/query.go | 4 +- x/avalanche/client/cli/tx.go | 4 +- x/avalanche/module.go | 8 +-- x/avalanche/types/genesis.go | 2 +- x/avalanche/types/genesis_test.go | 4 +- x/bsc/client/cli/query.go | 4 +- x/bsc/client/cli/tx.go | 4 +- x/bsc/module.go | 8 +-- x/bsc/types/genesis.go | 2 +- x/bsc/types/genesis_test.go | 4 +- x/crosschain/client/cli/query.go | 2 +- x/crosschain/client/cli/tx.go | 2 +- x/crosschain/client/cli/tx_proposal.go | 2 +- x/crosschain/client/proposal_handler.go | 2 +- x/crosschain/keeper/abci.go | 2 +- x/crosschain/keeper/abci_test.go | 10 ++-- x/crosschain/keeper/attestation.go | 2 +- x/crosschain/keeper/attestation_handler.go | 4 +- x/crosschain/keeper/batch.go | 2 +- x/crosschain/keeper/batch_test.go | 4 +- x/crosschain/keeper/bridge_token.go | 4 +- x/crosschain/keeper/bridge_token_test.go | 4 +- x/crosschain/keeper/delegate.go | 2 +- x/crosschain/keeper/evidence.go | 2 +- x/crosschain/keeper/evidence_test.go | 2 +- x/crosschain/keeper/genesis.go | 2 +- x/crosschain/keeper/genesis_test.go | 8 +-- x/crosschain/keeper/grpc_query.go | 18 +++---- x/crosschain/keeper/grpc_query_router.go | 4 +- x/crosschain/keeper/grpc_query_test.go | 24 ++++----- x/crosschain/keeper/hook.go | 2 +- x/crosschain/keeper/keeper.go | 4 +- x/crosschain/keeper/keeper_router.go | 2 +- x/crosschain/keeper/keeper_test.go | 26 +++++----- x/crosschain/keeper/migrations.go | 4 +- x/crosschain/keeper/msg_server.go | 4 +- x/crosschain/keeper/msg_server_router.go | 2 +- x/crosschain/keeper/msg_server_test.go | 10 ++-- x/crosschain/keeper/oracle.go | 2 +- x/crosschain/keeper/oracle_set.go | 2 +- x/crosschain/keeper/oracle_set_test.go | 4 +- x/crosschain/keeper/params.go | 2 +- x/crosschain/keeper/params_test.go | 4 +- x/crosschain/keeper/pool.go | 4 +- x/crosschain/keeper/pool_test.go | 6 +-- x/crosschain/keeper/proposal_legacy.go | 2 +- x/crosschain/keeper/proposal_legacy_test.go | 4 +- x/crosschain/keeper/relay_transfer.go | 4 +- x/crosschain/migrations/v4/migrator_param.go | 2 +- .../migrations/v4/migrator_param_test.go | 6 +-- x/crosschain/proposal_legacy.go | 4 +- x/crosschain/service.go | 2 +- x/crosschain/types/expected_keepers.go | 2 +- x/crosschain/types/key_test.go | 4 +- x/crosschain/types/msg_validate.go | 2 +- x/crosschain/types/msg_validator_test.go | 18 +++---- x/crosschain/types/msgs_test.go | 14 ++--- x/crosschain/types/params.go | 2 +- x/crosschain/types/types.go | 2 +- x/erc20/client/cli/query.go | 2 +- x/erc20/client/cli/tx.go | 4 +- x/erc20/client/cli/tx_proposal.go | 2 +- x/erc20/client/proposal_handler.go | 2 +- x/erc20/keeper/evm.go | 4 +- x/erc20/keeper/evm_test.go | 2 +- x/erc20/keeper/genesis.go | 4 +- x/erc20/keeper/grpc_query.go | 4 +- x/erc20/keeper/grpc_query_test.go | 6 +-- x/erc20/keeper/keeper.go | 4 +- x/erc20/keeper/keeper_test.go | 14 ++--- x/erc20/keeper/migrations.go | 4 +- x/erc20/keeper/mint.go | 2 +- x/erc20/keeper/mint_test.go | 4 +- x/erc20/keeper/msg_server.go | 4 +- x/erc20/keeper/msg_server_test.go | 6 +-- x/erc20/keeper/params.go | 2 +- x/erc20/keeper/params_test.go | 2 +- x/erc20/keeper/proposals.go | 4 +- x/erc20/keeper/proposals_test.go | 8 +-- x/erc20/keeper/token_pairs.go | 4 +- x/erc20/keeper/token_pairs_test.go | 6 +-- x/erc20/keeper/transfer_relation.go | 2 +- x/erc20/migrations/v4/migrator_param.go | 2 +- x/erc20/migrations/v4/migrator_param_test.go | 4 +- x/erc20/module.go | 6 +-- x/erc20/proposal.go | 4 +- x/erc20/types/contract_event.go | 2 +- x/erc20/types/contract_event_test.go | 2 +- x/erc20/types/msg.go | 2 +- x/erc20/types/proposal.go | 2 +- x/erc20/types/token_pair.go | 2 +- x/eth/client/cli/query.go | 4 +- x/eth/client/cli/tx.go | 4 +- x/eth/module.go | 8 +-- x/eth/types/genesis.go | 2 +- x/eth/types/genesis_test.go | 4 +- x/evm/keeper/contract_code.go | 4 +- x/evm/keeper/contract_code_test.go | 4 +- x/evm/keeper/genesis.go | 2 +- x/evm/keeper/keeper.go | 6 +-- x/evm/keeper/keeper_test.go | 6 +-- x/evm/keeper/msg_server.go | 2 +- x/evm/keeper/msg_server_test.go | 6 +-- x/evm/keeper/state_transition.go | 2 +- x/evm/keeper/statedb_test.go | 2 +- x/evm/module.go | 8 +-- .../crosschain/bridge_coin_amount.go | 6 +-- .../crosschain/bridge_coin_amount_test.go | 8 +-- x/evm/precompiles/crosschain/call_evm.go | 4 +- .../crosschain/cancel_sendtoexternal.go | 2 +- .../crosschain/cancel_sendtoexternal_test.go | 14 ++--- x/evm/precompiles/crosschain/contract.go | 4 +- x/evm/precompiles/crosschain/contract_test.go | 14 ++--- x/evm/precompiles/crosschain/crosschain.go | 6 +-- .../precompiles/crosschain/crosschain_test.go | 16 +++--- x/evm/precompiles/crosschain/events.go | 2 +- .../crosschain/fip20crosschain_test.go | 14 ++--- .../crosschain/increase_bridgefee.go | 4 +- .../crosschain/increase_bridgefee_test.go | 14 ++--- x/evm/precompiles/crosschain/interfaces.go | 4 +- x/evm/precompiles/crosschain/keys.go | 4 +- x/evm/precompiles/crosschain/methods.go | 4 +- x/evm/precompiles/staking/allowance_shares.go | 2 +- .../staking/allowance_shares_test.go | 8 +-- x/evm/precompiles/staking/approve_shares.go | 4 +- .../staking/approve_shares_test.go | 10 ++-- x/evm/precompiles/staking/contract.go | 2 +- x/evm/precompiles/staking/contract_test.go | 10 ++-- x/evm/precompiles/staking/delegate.go | 4 +- x/evm/precompiles/staking/delegate_test.go | 8 +-- x/evm/precompiles/staking/delegation.go | 2 +- .../precompiles/staking/delegation_rewards.go | 2 +- .../staking/delegation_rewards_test.go | 8 +-- x/evm/precompiles/staking/delegation_test.go | 8 +-- x/evm/precompiles/staking/events.go | 2 +- x/evm/precompiles/staking/keys.go | 4 +- x/evm/precompiles/staking/methods.go | 2 +- x/evm/precompiles/staking/transfer_shares.go | 4 +- .../staking/transfer_shares_test.go | 8 +-- x/evm/precompiles/staking/undelegate.go | 4 +- x/evm/precompiles/staking/undelegate_test.go | 8 +-- x/evm/precompiles/staking/withdraw.go | 2 +- x/evm/precompiles/staking/withdraw_test.go | 8 +-- x/evm/types/codec.go | 2 +- x/evm/types/msg.go | 2 +- x/gov/client/cli/query.go | 2 +- x/gov/client/cli/query_test.go | 2 +- x/gov/keeper/abci.go | 2 +- x/gov/keeper/grpc_query.go | 2 +- x/gov/keeper/grpc_query_test.go | 6 +-- x/gov/keeper/keeper.go | 4 +- x/gov/keeper/keeper_test.go | 16 +++--- x/gov/keeper/migrations.go | 2 +- x/gov/keeper/msg_server.go | 2 +- x/gov/keeper/msg_server_test.go | 8 +-- x/gov/keeper/params.go | 4 +- x/gov/keeper/params_test.go | 6 +-- x/gov/keeper/proposal.go | 2 +- x/gov/keeper/tally.go | 2 +- x/gov/keeper/tally_test.go | 6 +-- x/gov/migrations/v046/convert.go | 2 +- x/gov/migrations/v046/store_test.go | 4 +- x/gov/module.go | 6 +-- x/gov/types/msgs_test.go | 4 +- x/gov/types/params.go | 6 +-- x/gravity/keeper/grpc_query.go | 10 ++-- x/gravity/keeper/msg_server.go | 8 +-- x/gravity/service.go | 2 +- x/gravity/types/msgs.go | 2 +- x/ibc/applications/transfer/client/cli/tx.go | 2 +- x/ibc/applications/transfer/ibc_middleware.go | 6 +-- .../transfer/ibc_middleware_test.go | 4 +- x/ibc/applications/transfer/keeper/keeper.go | 4 +- .../transfer/keeper/keeper_test.go | 6 +-- .../transfer/keeper/msg_server.go | 2 +- .../transfer/keeper/msg_server_test.go | 4 +- x/ibc/applications/transfer/keeper/parse.go | 4 +- .../transfer/keeper/parse_test.go | 4 +- x/ibc/applications/transfer/keeper/relay.go | 6 +-- .../transfer/keeper/relay_test.go | 22 ++++---- x/ibc/applications/transfer/module.go | 6 +-- x/ibc/applications/transfer/transfer_test.go | 6 +-- .../transfer/types/expected_keepers.go | 4 +- .../applications/transfer/types/msgs_test.go | 2 +- x/ibc/ibcrouter/ibc_middleware.go | 6 +-- x/ibc/ibcrouter/ibc_middleware_test.go | 6 +-- .../ibcrouter/parser/receiver_parser_test.go | 2 +- x/ibc/testing/app.go | 6 +-- x/ibc/testing/chain.go | 2 +- x/migrate/client/cli/query.go | 2 +- x/migrate/client/cli/tx.go | 6 +-- x/migrate/keeper/bank.go | 2 +- x/migrate/keeper/bank_test.go | 4 +- x/migrate/keeper/distr_staking.go | 2 +- x/migrate/keeper/distr_staking_test.go | 8 +-- x/migrate/keeper/genesis.go | 4 +- x/migrate/keeper/gov.go | 2 +- x/migrate/keeper/gov_test.go | 8 +-- x/migrate/keeper/grpc_query.go | 2 +- x/migrate/keeper/grpc_query_test.go | 6 +-- x/migrate/keeper/keeper.go | 2 +- x/migrate/keeper/keeper_test.go | 8 +-- x/migrate/keeper/msg_server.go | 2 +- x/migrate/keeper/msg_server_test.go | 4 +- x/migrate/module.go | 6 +-- x/migrate/types/msg.go | 2 +- x/migrate/types/msg_test.go | 4 +- x/optimism/client/cli/query.go | 4 +- x/optimism/client/cli/tx.go | 4 +- x/optimism/module.go | 8 +-- x/optimism/types/genesis.go | 2 +- x/optimism/types/genesis_test.go | 4 +- x/polygon/client/cli/query.go | 4 +- x/polygon/client/cli/tx.go | 4 +- x/polygon/module.go | 8 +-- x/polygon/types/genesis.go | 2 +- x/polygon/types/genesis_test.go | 4 +- x/staking/keeper/genesis.go | 2 +- x/staking/keeper/genesis_test.go | 4 +- x/staking/keeper/keeper_test.go | 6 +-- x/staking/keeper/shares.go | 2 +- x/staking/keeper/shares_test.go | 2 +- x/staking/module.go | 4 +- x/tron/client/cli/query.go | 4 +- x/tron/client/cli/tx.go | 4 +- x/tron/keeper/grpc_query.go | 4 +- x/tron/keeper/grpc_query_test.go | 6 +-- x/tron/keeper/hook.go | 4 +- x/tron/keeper/keeper.go | 6 +-- x/tron/keeper/keeper_test.go | 12 ++--- x/tron/keeper/msg_server.go | 6 +-- x/tron/keeper/msg_server_test.go | 6 +-- x/tron/module.go | 10 ++-- x/tron/types/checkpoint.go | 4 +- x/tron/types/genesis.go | 2 +- x/tron/types/genesis_test.go | 6 +-- x/tron/types/msg_validate.go | 2 +- x/tron/types/signer.go | 2 +- x/tron/types/tron_address_test.go | 2 +- 326 files changed, 900 insertions(+), 900 deletions(-) diff --git a/Makefile b/Makefile index d51bba16a..a6819d953 100644 --- a/Makefile +++ b/Makefile @@ -238,7 +238,7 @@ contract-publish: ### Releasing ### ############################################################################### -PACKAGE_NAME := github.com/functionx/fx-core/v4 +PACKAGE_NAME := github.com/functionx/fx-core/v5 GOLANG_CROSS_VERSION := v1.19 release-dry-run: docker run --rm --privileged -e CGO_ENABLED=1 \ diff --git a/README.md b/README.md index f6abbc1d8..66ae371b0 100644 --- a/README.md +++ b/README.md @@ -3,11 +3,11 @@ **fxcore** is a blockchain built using Cosmos SDK and Tendermint and created with [Starport](https://github.com/tendermint/starport). [![Version](https://img.shields.io/github/v/release/functionx/fx-core.svg)](https://github.com/functionx/fx-core/releases/latest) -[![API Reference](https://pkg.go.dev/badge/github.com/functionx/fx-core.svg)](https://pkg.go.dev/github.com/functionx/fx-core/v4) +[![API Reference](https://pkg.go.dev/badge/github.com/functionx/fx-core.svg)](https://pkg.go.dev/github.com/functionx/fx-core/v5) [![License](https://img.shields.io/github/license/functionx/fx-core.svg)](https://github.com/functionx/fx-core/blob/main/LICENSE) [![Tests](https://github.com/functionx/fx-core/actions/workflows/test.yml/badge.svg)](https://github.com/functionx/fx-core/actions/workflows/test.yml) [![Lint](https://github.com/functionx/fx-core/actions/workflows/lint.yml/badge.svg)](https://github.com/functionx/fx-core/actions/workflows/lint.yml) -[![Go Report Card](https://goreportcard.com/badge/github.com/functionx/fx-core/v4)](https://goreportcard.com/report/github.com/functionx/fx-core/v4) +[![Go Report Card](https://goreportcard.com/badge/github.com/functionx/fx-core/v5)](https://goreportcard.com/report/github.com/functionx/fx-core/v5) **Note**: Requires [Go 1.19+](https://go.dev/dl) diff --git a/ante/ante_sigs_test.go b/ante/ante_sigs_test.go index 21c622547..5d969d26d 100644 --- a/ante/ante_sigs_test.go +++ b/ante/ante_sigs_test.go @@ -7,7 +7,7 @@ import ( "github.com/evmos/ethermint/x/evm/statedb" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func (suite *AnteTestSuite) TestSignatures() { diff --git a/ante/ante_test.go b/ante/ante_test.go index cda876e5c..317e92688 100644 --- a/ante/ante_test.go +++ b/ante/ante_test.go @@ -28,10 +28,10 @@ import ( "github.com/stretchr/testify/suite" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - fxante "github.com/functionx/fx-core/v4/ante" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" + fxante "github.com/functionx/fx-core/v5/ante" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" ) type AnteTestSuite struct { diff --git a/ante/eth_test.go b/ante/eth_test.go index d30509e37..fb9e6d715 100644 --- a/ante/eth_test.go +++ b/ante/eth_test.go @@ -10,8 +10,8 @@ import ( "github.com/evmos/ethermint/x/evm/statedb" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/ante" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/ante" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func (suite *AnteTestSuite) TestEthSigVerificationDecorator() { diff --git a/ante/fee_market_test.go b/ante/fee_market_test.go index 881175ae7..3362e18ff 100644 --- a/ante/fee_market_test.go +++ b/ante/fee_market_test.go @@ -9,8 +9,8 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/ante" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/ante" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func (suite *AnteTestSuite) TestGasWantedDecorator() { diff --git a/ante/fees_test.go b/ante/fees_test.go index 17dad0595..13b2b10b4 100644 --- a/ante/fees_test.go +++ b/ante/fees_test.go @@ -14,8 +14,8 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/evmos/ethermint/tests" - "github.com/functionx/fx-core/v4/ante" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/ante" + fxtypes "github.com/functionx/fx-core/v5/types" ) func (suite *AnteTestSuite) TestDeductFeeDecorator() { diff --git a/app/app.go b/app/app.go index 7b962b98a..58f26fbd0 100644 --- a/app/app.go +++ b/app/app.go @@ -33,21 +33,21 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" dbm "github.com/tendermint/tm-db" - fxante "github.com/functionx/fx-core/v4/ante" - "github.com/functionx/fx-core/v4/app/keepers" - _ "github.com/functionx/fx-core/v4/docs/statik" - fxcfg "github.com/functionx/fx-core/v4/server/config" - fxauth "github.com/functionx/fx-core/v4/server/grpc/auth" - gaspricev1 "github.com/functionx/fx-core/v4/server/grpc/gasprice/legacy/v1" - gaspricev2 "github.com/functionx/fx-core/v4/server/grpc/gasprice/legacy/v2" - fxrest "github.com/functionx/fx-core/v4/server/rest" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain" - "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/gravity" - gravitykeeper "github.com/functionx/fx-core/v4/x/gravity/keeper" - gravitytypes "github.com/functionx/fx-core/v4/x/gravity/types" + fxante "github.com/functionx/fx-core/v5/ante" + "github.com/functionx/fx-core/v5/app/keepers" + _ "github.com/functionx/fx-core/v5/docs/statik" + fxcfg "github.com/functionx/fx-core/v5/server/config" + fxauth "github.com/functionx/fx-core/v5/server/grpc/auth" + gaspricev1 "github.com/functionx/fx-core/v5/server/grpc/gasprice/legacy/v1" + gaspricev2 "github.com/functionx/fx-core/v5/server/grpc/gasprice/legacy/v2" + fxrest "github.com/functionx/fx-core/v5/server/rest" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain" + "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/gravity" + gravitykeeper "github.com/functionx/fx-core/v5/x/gravity/keeper" + gravitytypes "github.com/functionx/fx-core/v5/x/gravity/types" ) var _ servertypes.Application = (*App)(nil) diff --git a/app/app_test.go b/app/app_test.go index ec972bb79..8c260af17 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func TestUpgradeStateOnGenesis(t *testing.T) { diff --git a/app/encoding.go b/app/encoding.go index a8f828604..39c4f8d46 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -15,8 +15,8 @@ import ( "github.com/evmos/ethermint/crypto/ethsecp256k1" etherminttypes "github.com/evmos/ethermint/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - gravitytypes "github.com/functionx/fx-core/v4/x/gravity/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + gravitytypes "github.com/functionx/fx-core/v5/x/gravity/types" ) // EncodingConfig specifies the concrete encoding types to use for a given app. diff --git a/app/encoding_test.go b/app/encoding_test.go index 00ef1826e..7ea41c94e 100644 --- a/app/encoding_test.go +++ b/app/encoding_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" - "github.com/functionx/fx-core/v4/app" + "github.com/functionx/fx-core/v5/app" ) func TestMakeEncodingConfig_RegisterInterfaces(t *testing.T) { diff --git a/app/export_test.go b/app/export_test.go index 601f95bde..c68e5a7a6 100644 --- a/app/export_test.go +++ b/app/export_test.go @@ -21,11 +21,11 @@ import ( "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/testutil/network" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/network" + fxtypes "github.com/functionx/fx-core/v5/types" ) func TestUseExportGenesisDataRunNode(t *testing.T) { diff --git a/app/genesis.go b/app/genesis.go index 6d0638908..8ea3d0e79 100644 --- a/app/genesis.go +++ b/app/genesis.go @@ -25,9 +25,9 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" - fxtypes "github.com/functionx/fx-core/v4/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - fxstakingtypes "github.com/functionx/fx-core/v4/x/staking/types" + fxtypes "github.com/functionx/fx-core/v5/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) const ( diff --git a/app/genesis_test.go b/app/genesis_test.go index 7ce1fe8de..8497a1030 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/assert" - "github.com/functionx/fx-core/v4/app" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app" + fxtypes "github.com/functionx/fx-core/v5/types" ) func TestNewDefaultGenesisByDenom(t *testing.T) { diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 1588c2001..c38af9c88 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -53,31 +53,31 @@ import ( feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" "github.com/spf13/cast" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/erc20" - erc20keeper "github.com/functionx/fx-core/v4/x/erc20/keeper" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - fxevmkeeper "github.com/functionx/fx-core/v4/x/evm/keeper" - fxgovkeeper "github.com/functionx/fx-core/v4/x/gov/keeper" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" - gravitytypes "github.com/functionx/fx-core/v4/x/gravity/types" - fxtransfer "github.com/functionx/fx-core/v4/x/ibc/applications/transfer" - fxtransferkeeper "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/keeper" - "github.com/functionx/fx-core/v4/x/ibc/ibcrouter" - migratekeeper "github.com/functionx/fx-core/v4/x/migrate/keeper" - migratetypes "github.com/functionx/fx-core/v4/x/migrate/types" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - fxstakingkeeper "github.com/functionx/fx-core/v4/x/staking/keeper" - tronkeeper "github.com/functionx/fx-core/v4/x/tron/keeper" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/erc20" + erc20keeper "github.com/functionx/fx-core/v5/x/erc20/keeper" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + fxevmkeeper "github.com/functionx/fx-core/v5/x/evm/keeper" + fxgovkeeper "github.com/functionx/fx-core/v5/x/gov/keeper" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" + gravitytypes "github.com/functionx/fx-core/v5/x/gravity/types" + fxtransfer "github.com/functionx/fx-core/v5/x/ibc/applications/transfer" + fxtransferkeeper "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/keeper" + "github.com/functionx/fx-core/v5/x/ibc/ibcrouter" + migratekeeper "github.com/functionx/fx-core/v5/x/migrate/keeper" + migratetypes "github.com/functionx/fx-core/v5/x/migrate/types" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + fxstakingkeeper "github.com/functionx/fx-core/v5/x/staking/keeper" + tronkeeper "github.com/functionx/fx-core/v5/x/tron/keeper" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) type CrossChainKeepers struct { diff --git a/app/keepers/keepers_test.go b/app/keepers/keepers_test.go index f82a5099b..c742f35b6 100644 --- a/app/keepers/keepers_test.go +++ b/app/keepers/keepers_test.go @@ -16,17 +16,17 @@ import ( tmlog "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/app/keepers" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/app/keepers" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func TestNewAppKeeper(t *testing.T) { diff --git a/app/keepers/keys.go b/app/keepers/keys.go index 898927703..e30c8b78c 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -23,18 +23,18 @@ import ( evmtypes "github.com/evmos/ethermint/x/evm/types" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - precompilescrosschain "github.com/functionx/fx-core/v4/x/evm/precompiles/crosschain" - precompilesstaking "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" - migratetypes "github.com/functionx/fx-core/v4/x/migrate/types" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + precompilescrosschain "github.com/functionx/fx-core/v5/x/evm/precompiles/crosschain" + precompilesstaking "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" + migratetypes "github.com/functionx/fx-core/v5/x/migrate/types" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func (appKeepers *AppKeepers) generateKeys() { diff --git a/app/modules.go b/app/modules.go index db76c6b9e..3a6cb0af0 100644 --- a/app/modules.go +++ b/app/modules.go @@ -45,32 +45,32 @@ import ( "github.com/evmos/ethermint/x/feemarket" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" - "github.com/functionx/fx-core/v4/x/arbitrum" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - "github.com/functionx/fx-core/v4/x/avalanche" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - "github.com/functionx/fx-core/v4/x/bsc" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - crosschainclient "github.com/functionx/fx-core/v4/x/crosschain/client" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/erc20" - erc20client "github.com/functionx/fx-core/v4/x/erc20/client" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - "github.com/functionx/fx-core/v4/x/eth" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - fxevm "github.com/functionx/fx-core/v4/x/evm" - fxgov "github.com/functionx/fx-core/v4/x/gov" - fxibctransfer "github.com/functionx/fx-core/v4/x/ibc/applications/transfer" - fxibctransfertypes "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" - "github.com/functionx/fx-core/v4/x/migrate" - migratetypes "github.com/functionx/fx-core/v4/x/migrate/types" - "github.com/functionx/fx-core/v4/x/optimism" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" - "github.com/functionx/fx-core/v4/x/polygon" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - fxstaking "github.com/functionx/fx-core/v4/x/staking" - "github.com/functionx/fx-core/v4/x/tron" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/x/arbitrum" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + "github.com/functionx/fx-core/v5/x/avalanche" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + "github.com/functionx/fx-core/v5/x/bsc" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + crosschainclient "github.com/functionx/fx-core/v5/x/crosschain/client" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/erc20" + erc20client "github.com/functionx/fx-core/v5/x/erc20/client" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + "github.com/functionx/fx-core/v5/x/eth" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + fxevm "github.com/functionx/fx-core/v5/x/evm" + fxgov "github.com/functionx/fx-core/v5/x/gov" + fxibctransfer "github.com/functionx/fx-core/v5/x/ibc/applications/transfer" + fxibctransfertypes "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" + "github.com/functionx/fx-core/v5/x/migrate" + migratetypes "github.com/functionx/fx-core/v5/x/migrate/types" + "github.com/functionx/fx-core/v5/x/optimism" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" + "github.com/functionx/fx-core/v5/x/polygon" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + fxstaking "github.com/functionx/fx-core/v5/x/staking" + "github.com/functionx/fx-core/v5/x/tron" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func init() { diff --git a/app/modules_test.go b/app/modules_test.go index 684933824..217d8e7f4 100644 --- a/app/modules_test.go +++ b/app/modules_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func TestOnOrderBeginBlockers(t *testing.T) { diff --git a/app/upgrade.go b/app/upgrade.go index f8117a364..ecbfec03f 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -5,8 +5,8 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/functionx/fx-core/v4/app/upgrades" - "github.com/functionx/fx-core/v4/app/upgrades/v4_2" + "github.com/functionx/fx-core/v5/app/upgrades" + "github.com/functionx/fx-core/v5/app/upgrades/v4_2" ) func (app *App) GetUpgrade() upgrades.Upgrade { diff --git a/app/upgrade_test.go b/app/upgrade_test.go index 8c9fe4887..27e2fbf8b 100644 --- a/app/upgrade_test.go +++ b/app/upgrade_test.go @@ -23,23 +23,23 @@ import ( "github.com/tendermint/tendermint/store" dbm "github.com/tendermint/tm-db" - "github.com/functionx/fx-core/v4/app" - v4 "github.com/functionx/fx-core/v4/app/upgrades/v4" - "github.com/functionx/fx-core/v4/app/upgrades/v4_2" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - evmtypes "github.com/functionx/fx-core/v4/x/evm/types" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/app" + v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" + "github.com/functionx/fx-core/v5/app/upgrades/v4_2" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + evmtypes "github.com/functionx/fx-core/v5/x/evm/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func Test_TestnetUpgradeV4_2(t *testing.T) { diff --git a/app/upgrades/types.go b/app/upgrades/types.go index 32e6390a4..7bb6016cd 100644 --- a/app/upgrades/types.go +++ b/app/upgrades/types.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/functionx/fx-core/v4/app/keepers" + "github.com/functionx/fx-core/v5/app/keepers" ) // Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal diff --git a/app/upgrades/v4/constants.go b/app/upgrades/v4/constants.go index 66d061aaa..293667611 100644 --- a/app/upgrades/v4/constants.go +++ b/app/upgrades/v4/constants.go @@ -3,11 +3,11 @@ package v4 import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/functionx/fx-core/v4/app/upgrades" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - gravitytypes "github.com/functionx/fx-core/v4/x/gravity/types" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" + "github.com/functionx/fx-core/v5/app/upgrades" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + gravitytypes "github.com/functionx/fx-core/v5/x/gravity/types" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" ) var ( diff --git a/app/upgrades/v4/upgrade.go b/app/upgrades/v4/upgrade.go index 68287c785..98857e810 100644 --- a/app/upgrades/v4/upgrade.go +++ b/app/upgrades/v4/upgrade.go @@ -10,18 +10,18 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/app/keepers" - fxtypes "github.com/functionx/fx-core/v4/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - "github.com/functionx/fx-core/v4/x/crosschain/types" - erc20keeper "github.com/functionx/fx-core/v4/x/erc20/keeper" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - evmkeeper "github.com/functionx/fx-core/v4/x/evm/keeper" - "github.com/functionx/fx-core/v4/x/gov/keeper" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/app/keepers" + fxtypes "github.com/functionx/fx-core/v5/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + "github.com/functionx/fx-core/v5/x/crosschain/types" + erc20keeper "github.com/functionx/fx-core/v5/x/erc20/keeper" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + evmkeeper "github.com/functionx/fx-core/v5/x/evm/keeper" + "github.com/functionx/fx-core/v5/x/gov/keeper" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func CreateUpgradeHandler( diff --git a/app/upgrades/v4/upgrade_test.go b/app/upgrades/v4/upgrade_test.go index 7574e0fd0..8008e6f06 100644 --- a/app/upgrades/v4/upgrade_test.go +++ b/app/upgrades/v4/upgrade_test.go @@ -10,8 +10,8 @@ import ( "github.com/stretchr/testify/assert" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" ) func TestAccountConvertModuleAccount(t *testing.T) { diff --git a/app/upgrades/v4_1/constants.go b/app/upgrades/v4_1/constants.go index 156529345..d0cf53f01 100644 --- a/app/upgrades/v4_1/constants.go +++ b/app/upgrades/v4_1/constants.go @@ -3,9 +3,9 @@ package v4_1 import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" - "github.com/functionx/fx-core/v4/app/upgrades" - v4 "github.com/functionx/fx-core/v4/app/upgrades/v4" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app/upgrades" + v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" + fxtypes "github.com/functionx/fx-core/v5/types" ) // Deprecated: Please use v4.2.x diff --git a/app/upgrades/v4_1/upgrade.go b/app/upgrades/v4_1/upgrade.go index ce10aa0d0..10ff2d1cc 100644 --- a/app/upgrades/v4_1/upgrade.go +++ b/app/upgrades/v4_1/upgrade.go @@ -5,9 +5,9 @@ import ( "github.com/cosmos/cosmos-sdk/types/module" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/functionx/fx-core/v4/app/keepers" - v4 "github.com/functionx/fx-core/v4/app/upgrades/v4" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app/keepers" + v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" + fxtypes "github.com/functionx/fx-core/v5/types" ) func createUpgradeHandler( diff --git a/app/upgrades/v4_2/constants.go b/app/upgrades/v4_2/constants.go index d8355c7a7..166c77043 100644 --- a/app/upgrades/v4_2/constants.go +++ b/app/upgrades/v4_2/constants.go @@ -6,9 +6,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/app/upgrades" - v4 "github.com/functionx/fx-core/v4/app/upgrades/v4" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app/upgrades" + v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" + fxtypes "github.com/functionx/fx-core/v5/types" ) type Refund struct { diff --git a/app/upgrades/v4_2/upgrade.go b/app/upgrades/v4_2/upgrade.go index 7c31ca65b..5cd1d9e9b 100644 --- a/app/upgrades/v4_2/upgrade.go +++ b/app/upgrades/v4_2/upgrade.go @@ -6,11 +6,11 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/app/keepers" - v4 "github.com/functionx/fx-core/v4/app/upgrades/v4" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/app/keepers" + v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" ) func createUpgradeHandler( diff --git a/client/cli/debug_test.go b/client/cli/debug_test.go index 81beb18d6..5d072d2b2 100644 --- a/client/cli/debug_test.go +++ b/client/cli/debug_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/functionx/fx-core/v4/client/cli" + "github.com/functionx/fx-core/v5/client/cli" ) func TestToStringCmd(t *testing.T) { diff --git a/client/cli/gentx.go b/client/cli/gentx.go index 631cc1c83..0fe691b9b 100644 --- a/client/cli/gentx.go +++ b/client/cli/gentx.go @@ -32,7 +32,7 @@ import ( tmos "github.com/tendermint/tendermint/libs/os" tmtypes "github.com/tendermint/tendermint/types" - fxstakingtypes "github.com/functionx/fx-core/v4/x/staking/types" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) // GenTxCmd builds the application's gentx command. diff --git a/client/cli/keys/parse.go b/client/cli/keys/parse.go index 3a4a4cf5e..a2138ce71 100644 --- a/client/cli/keys/parse.go +++ b/client/cli/keys/parse.go @@ -12,7 +12,7 @@ import ( "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/client/cli" + "github.com/functionx/fx-core/v5/client/cli" ) const prefixFlag = "prefix" diff --git a/client/client_test.go b/client/client_test.go index d4e25c79f..80670c584 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -25,14 +25,14 @@ import ( "github.com/stretchr/testify/suite" ctypes "github.com/tendermint/tendermint/rpc/core/types" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/client/grpc" - "github.com/functionx/fx-core/v4/client/jsonrpc" - fxauth "github.com/functionx/fx-core/v4/server/grpc/auth" - "github.com/functionx/fx-core/v4/testutil" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/testutil/network" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/client/grpc" + "github.com/functionx/fx-core/v5/client/jsonrpc" + fxauth "github.com/functionx/fx-core/v5/server/grpc/auth" + "github.com/functionx/fx-core/v5/testutil" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/network" + fxtypes "github.com/functionx/fx-core/v5/types" ) type rpcTestClient interface { diff --git a/client/grpc/grpc_client.go b/client/grpc/grpc_client.go index a71a4e141..286dd8dc6 100644 --- a/client/grpc/grpc_client.go +++ b/client/grpc/grpc_client.go @@ -35,10 +35,10 @@ import ( "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/metadata" - "github.com/functionx/fx-core/v4/client" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - migratetypes "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/client" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + migratetypes "github.com/functionx/fx-core/v5/x/migrate/types" ) type Client struct { diff --git a/client/grpc/grpc_client_test.go b/client/grpc/grpc_client_test.go index 04094c567..8e87f8b63 100644 --- a/client/grpc/grpc_client_test.go +++ b/client/grpc/grpc_client_test.go @@ -7,8 +7,8 @@ import ( "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/stretchr/testify/assert" - "github.com/functionx/fx-core/v4/client/grpc" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/client/grpc" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func TestClient_QueryBalances(t *testing.T) { diff --git a/client/jsonrpc/abci_query.go b/client/jsonrpc/abci_query.go index 40628219e..22b03eaa6 100644 --- a/client/jsonrpc/abci_query.go +++ b/client/jsonrpc/abci_query.go @@ -13,7 +13,7 @@ import ( "github.com/gogo/protobuf/proto" ctypes "github.com/tendermint/tendermint/rpc/core/types" - gravitytypes "github.com/functionx/fx-core/v4/x/gravity/types" + gravitytypes "github.com/functionx/fx-core/v5/x/gravity/types" ) func (c *NodeRPC) QueryAccount(address string) (authtypes.AccountI, error) { diff --git a/client/jsonrpc/json_rpc.go b/client/jsonrpc/json_rpc.go index 4ed3e6669..a6098cd49 100644 --- a/client/jsonrpc/json_rpc.go +++ b/client/jsonrpc/json_rpc.go @@ -20,7 +20,7 @@ import ( ctypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/tendermint/tendermint/types" - "github.com/functionx/fx-core/v4/client" + "github.com/functionx/fx-core/v5/client" ) type jsonRPCCaller interface { diff --git a/client/jsonrpc/rpc_client_test.go b/client/jsonrpc/rpc_client_test.go index 159a33255..d6d05290f 100644 --- a/client/jsonrpc/rpc_client_test.go +++ b/client/jsonrpc/rpc_client_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/libs/log" - "github.com/functionx/fx-core/v4/client/jsonrpc" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/client/jsonrpc" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func TestNewWsClient(t *testing.T) { diff --git a/cmd/config.go b/cmd/config.go index c375da4f3..818b96e4b 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -10,7 +10,7 @@ import ( tmcfg "github.com/tendermint/tendermint/config" tmcli "github.com/tendermint/tendermint/libs/cli" - fxcfg "github.com/functionx/fx-core/v4/server/config" + fxcfg "github.com/functionx/fx-core/v5/server/config" ) const ( diff --git a/cmd/config_test.go b/cmd/config_test.go index b2867ac98..9543a3697 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -16,7 +16,7 @@ import ( "github.com/stretchr/testify/assert" tmcfg "github.com/tendermint/tendermint/config" - fxcfg "github.com/functionx/fx-core/v4/server/config" + fxcfg "github.com/functionx/fx-core/v5/server/config" ) func Test_updateCfgCmd(t *testing.T) { diff --git a/cmd/doctor.go b/cmd/doctor.go index 0df888aba..257aa338e 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -28,10 +28,10 @@ import ( tmtypes "github.com/tendermint/tendermint/types" tmversion "github.com/tendermint/tendermint/version" - "github.com/functionx/fx-core/v4/client/grpc" - "github.com/functionx/fx-core/v4/server" - fxcfg "github.com/functionx/fx-core/v4/server/config" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/client/grpc" + "github.com/functionx/fx-core/v5/server" + fxcfg "github.com/functionx/fx-core/v5/server/config" + fxtypes "github.com/functionx/fx-core/v5/types" ) const SPACE = " " diff --git a/cmd/doctor_test.go b/cmd/doctor_test.go index c9c40af3d..3be82d10a 100644 --- a/cmd/doctor_test.go +++ b/cmd/doctor_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) func Test_doctorCmd(t *testing.T) { diff --git a/cmd/fxcored/main.go b/cmd/fxcored/main.go index 5a33525b5..916a2c1bf 100644 --- a/cmd/fxcored/main.go +++ b/cmd/fxcored/main.go @@ -6,8 +6,8 @@ import ( "github.com/cosmos/cosmos-sdk/server" svrcmd "github.com/cosmos/cosmos-sdk/server/cmd" - "github.com/functionx/fx-core/v4/cmd" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/cmd" + fxtypes "github.com/functionx/fx-core/v5/types" ) func main() { diff --git a/cmd/keys.go b/cmd/keys.go index cefefc09b..a936cfd3e 100644 --- a/cmd/keys.go +++ b/cmd/keys.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/tendermint/libs/cli" - fxkeys "github.com/functionx/fx-core/v4/client/cli/keys" + fxkeys "github.com/functionx/fx-core/v5/client/cli/keys" ) // Commands registers a sub-tree of commands to interact with diff --git a/cmd/root.go b/cmd/root.go index e53919679..f85725281 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -31,19 +31,19 @@ import ( "github.com/tendermint/tendermint/libs/log" dbm "github.com/tendermint/tm-db" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/client/cli" - fxserver "github.com/functionx/fx-core/v4/server" - fxcfg "github.com/functionx/fx-core/v4/server/config" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumcli "github.com/functionx/fx-core/v4/x/arbitrum/client/cli" - avalanchecli "github.com/functionx/fx-core/v4/x/avalanche/client/cli" - bsccli "github.com/functionx/fx-core/v4/x/bsc/client/cli" - crosschaincli "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - ethcli "github.com/functionx/fx-core/v4/x/eth/client/cli" - optimismcli "github.com/functionx/fx-core/v4/x/optimism/client/cli" - polygoncli "github.com/functionx/fx-core/v4/x/polygon/client/cli" - troncli "github.com/functionx/fx-core/v4/x/tron/client/cli" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/client/cli" + fxserver "github.com/functionx/fx-core/v5/server" + fxcfg "github.com/functionx/fx-core/v5/server/config" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumcli "github.com/functionx/fx-core/v5/x/arbitrum/client/cli" + avalanchecli "github.com/functionx/fx-core/v5/x/avalanche/client/cli" + bsccli "github.com/functionx/fx-core/v5/x/bsc/client/cli" + crosschaincli "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + ethcli "github.com/functionx/fx-core/v5/x/eth/client/cli" + optimismcli "github.com/functionx/fx-core/v5/x/optimism/client/cli" + polygoncli "github.com/functionx/fx-core/v5/x/polygon/client/cli" + troncli "github.com/functionx/fx-core/v5/x/tron/client/cli" ) // NewRootCmd creates a new root command for simd. It is called once in the diff --git a/cmd/testnet.go b/cmd/testnet.go index 7ffeb8793..17f4c26c9 100644 --- a/cmd/testnet.go +++ b/cmd/testnet.go @@ -14,10 +14,10 @@ import ( "github.com/spf13/cobra" tmcfg "github.com/tendermint/tendermint/config" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil" - "github.com/functionx/fx-core/v4/testutil/network" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil" + "github.com/functionx/fx-core/v5/testutil/network" + fxtypes "github.com/functionx/fx-core/v5/types" ) const ( diff --git a/docs/swagger_test.go b/docs/swagger_test.go index c8eca1ba0..ecbfb1460 100644 --- a/docs/swagger_test.go +++ b/docs/swagger_test.go @@ -15,7 +15,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/stretchr/testify/assert" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func TestSwaggerConfig(t *testing.T) { diff --git a/go.mod b/go.mod index bb7f88df5..5d5913baf 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/functionx/fx-core/v4 +module github.com/functionx/fx-core/v5 go 1.19 diff --git a/server/config/config_cmd.go b/server/config/config_cmd.go index b5bec39f8..dea7c6250 100644 --- a/server/config/config_cmd.go +++ b/server/config/config_cmd.go @@ -13,7 +13,7 @@ import ( "github.com/spf13/viper" tmcfg "github.com/tendermint/tendermint/config" - "github.com/functionx/fx-core/v4/client/cli" + "github.com/functionx/fx-core/v5/client/cli" ) func CmdHandler(cmd *cobra.Command, args []string) error { diff --git a/server/config/config_cmd_test.go b/server/config/config_cmd_test.go index 503110dba..ef90066d3 100644 --- a/server/config/config_cmd_test.go +++ b/server/config/config_cmd_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/config" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) func Test_output(t *testing.T) { diff --git a/server/database_test.go b/server/database_test.go index 2f72fadf5..d6cdd7117 100644 --- a/server/database_test.go +++ b/server/database_test.go @@ -12,8 +12,8 @@ import ( tmtypes "github.com/tendermint/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/server" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/server" ) type DatabaseTestSuite struct { diff --git a/server/grpc/auth/grpc_query.go b/server/grpc/auth/grpc_query.go index 1bab2462d..d647c5b95 100644 --- a/server/grpc/auth/grpc_query.go +++ b/server/grpc/auth/grpc_query.go @@ -10,7 +10,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) var _ QueryServer = Querier{} diff --git a/server/log_filter_test.go b/server/log_filter_test.go index 21197ad75..e8875a86e 100644 --- a/server/log_filter_test.go +++ b/server/log_filter_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" tmlog "github.com/tendermint/tendermint/libs/log" - fxserver "github.com/functionx/fx-core/v4/server" + fxserver "github.com/functionx/fx-core/v5/server" ) func TestFxZeroLogWrapper(t *testing.T) { diff --git a/server/rosetta.go b/server/rosetta.go index 0d19275e7..9b26151de 100644 --- a/server/rosetta.go +++ b/server/rosetta.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/server/rosetta" "github.com/spf13/cobra" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) // RosettaCommand builds the rosetta root command given diff --git a/server/start.go b/server/start.go index 0fb35a1f9..7a287a640 100644 --- a/server/start.go +++ b/server/start.go @@ -52,8 +52,8 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - fxcfg "github.com/functionx/fx-core/v4/server/config" - fxtypes "github.com/functionx/fx-core/v4/types" + fxcfg "github.com/functionx/fx-core/v5/server/config" + fxtypes "github.com/functionx/fx-core/v5/types" ) const FlagApplicationDatabaseDir = "application-db-dir" @@ -660,7 +660,7 @@ func checkMainnetAndBlock(genesisDoc *tmtypes.GenesisDoc, config *tmcfg.Config) return errors.New("invalid version: The current block height is less than the v4.2.0 upgrade height(10_477_500)," + " please use the v3.x.x version to synchronize the block or download the latest snapshot") } - // return errors.New("invalid version: The current version is not released, please use the corresponding version") + return errors.New("invalid version: The current version is not released, please use the corresponding version") } return nil } diff --git a/server/start_test.go b/server/start_test.go index 42cee07d4..7c8d47d2f 100644 --- a/server/start_test.go +++ b/server/start_test.go @@ -20,9 +20,9 @@ import ( "github.com/stretchr/testify/require" tmcfg "github.com/tendermint/tendermint/config" - "github.com/functionx/fx-core/v4/app" - fxserver "github.com/functionx/fx-core/v4/server" - fxcfg "github.com/functionx/fx-core/v4/server/config" + "github.com/functionx/fx-core/v5/app" + fxserver "github.com/functionx/fx-core/v5/server" + fxcfg "github.com/functionx/fx-core/v5/server/config" ) var errCancelledInPreRun = errors.New("cancelled in prerun") diff --git a/tests/amino_test.go b/tests/amino_test.go index 781083b94..a6ec38a7b 100644 --- a/tests/amino_test.go +++ b/tests/amino_test.go @@ -17,12 +17,12 @@ import ( "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/require" - "github.com/functionx/fx-core/v4/app" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" - ibctransfertypes "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + "github.com/functionx/fx-core/v5/app" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" + ibctransfertypes "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) func TestAminoEncode(t *testing.T) { diff --git a/tests/ante_test.go b/tests/ante_test.go index 28a1ab6c2..f465f5a81 100644 --- a/tests/ante_test.go +++ b/tests/ante_test.go @@ -6,7 +6,7 @@ import ( distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func (suite *IntegrationTest) ByPassFeeTest() { diff --git a/tests/contract_test.go b/tests/contract_test.go index 2f219145c..c0199bbce 100644 --- a/tests/contract_test.go +++ b/tests/contract_test.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) func TestFIP20Code(t *testing.T) { diff --git a/tests/crosschain_suite.go b/tests/crosschain_suite.go index cbdab788e..9215578a1 100644 --- a/tests/crosschain_suite.go +++ b/tests/crosschain_suite.go @@ -15,10 +15,10 @@ import ( ethcrypto "github.com/ethereum/go-ethereum/crypto" tronaddress "github.com/fbsobreira/gotron-sdk/pkg/address" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) type CrosschainTestSuite struct { diff --git a/tests/crosschain_test.go b/tests/crosschain_test.go index 345ba0770..b1b36aa31 100644 --- a/tests/crosschain_test.go +++ b/tests/crosschain_test.go @@ -10,10 +10,10 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" ) func (suite *IntegrationTest) CrossChainTest() { diff --git a/tests/erc20_suite.go b/tests/erc20_suite.go index ad77d97c3..99d8cd6a4 100644 --- a/tests/erc20_suite.go +++ b/tests/erc20_suite.go @@ -12,10 +12,10 @@ import ( "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/functionx/fx-core/v4/client" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - precompilescrosschain "github.com/functionx/fx-core/v4/x/evm/precompiles/crosschain" + "github.com/functionx/fx-core/v5/client" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + precompilescrosschain "github.com/functionx/fx-core/v5/x/evm/precompiles/crosschain" ) type Erc20TestSuite struct { diff --git a/tests/erc20_test.go b/tests/erc20_test.go index c89119416..f864b5278 100644 --- a/tests/erc20_test.go +++ b/tests/erc20_test.go @@ -15,12 +15,12 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/functionx/fx-core/v4/client" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/client" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func (suite *IntegrationTest) ERC20Test() { diff --git a/tests/evm_suite.go b/tests/evm_suite.go index dedd6822a..b0a0a733a 100644 --- a/tests/evm_suite.go +++ b/tests/evm_suite.go @@ -15,11 +15,11 @@ import ( "github.com/ethereum/go-ethereum/ethclient" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/client" - "github.com/functionx/fx-core/v4/contract" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/client" + "github.com/functionx/fx-core/v5/contract" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" ) type EvmTestSuite struct { diff --git a/tests/evm_test.go b/tests/evm_test.go index ff1e2801b..b50c077db 100644 --- a/tests/evm_test.go +++ b/tests/evm_test.go @@ -17,11 +17,11 @@ import ( evmtypes "github.com/evmos/ethermint/x/evm/types" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/client" - "github.com/functionx/fx-core/v4/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/types" - fxevmtypes "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/client" + "github.com/functionx/fx-core/v5/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/types" + fxevmtypes "github.com/functionx/fx-core/v5/x/evm/types" ) func (suite *IntegrationTest) WFXTest() { diff --git a/tests/integration_test.go b/tests/integration_test.go index edbea1ac2..913c4a7d0 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -6,9 +6,9 @@ import ( "github.com/stretchr/testify/suite" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) type IntegrationTest struct { diff --git a/tests/migrate_test.go b/tests/migrate_test.go index 7c49c90d1..4ac03f7b6 100644 --- a/tests/migrate_test.go +++ b/tests/migrate_test.go @@ -16,9 +16,9 @@ import ( hd2 "github.com/evmos/ethermint/crypto/hd" "github.com/stretchr/testify/require" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - migratetypes "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + migratetypes "github.com/functionx/fx-core/v5/x/migrate/types" ) func (suite *IntegrationTest) migrateAccount(fromPrivateKey, toPrivateKey cryptotypes.PrivKey) { diff --git a/tests/staking_suite.go b/tests/staking_suite.go index 224e0693b..5708822fa 100644 --- a/tests/staking_suite.go +++ b/tests/staking_suite.go @@ -16,10 +16,10 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/functionx/fx-core/v4/client" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - fxtypes "github.com/functionx/fx-core/v4/types" - precompilesstaking "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + "github.com/functionx/fx-core/v5/client" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + fxtypes "github.com/functionx/fx-core/v5/types" + precompilesstaking "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) type StakingSuite struct { diff --git a/tests/staking_test.go b/tests/staking_test.go index 0b2fa3ccd..8bbb8ad5a 100644 --- a/tests/staking_test.go +++ b/tests/staking_test.go @@ -7,9 +7,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - precompilesstaking "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + precompilesstaking "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) func (suite *IntegrationTest) StakingTest() { diff --git a/tests/store/subspace_test.go b/tests/store/subspace_test.go index d8a6e722b..ca30ab3aa 100644 --- a/tests/store/subspace_test.go +++ b/tests/store/subspace_test.go @@ -12,8 +12,8 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/functionx/fx-core/v4/app" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/app" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" ) func Benchmark_Subspace(b *testing.B) { diff --git a/tests/suite.go b/tests/suite.go index 3b8bb0a69..a87a10a75 100644 --- a/tests/suite.go +++ b/tests/suite.go @@ -24,14 +24,14 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/suite" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/client/grpc" - "github.com/functionx/fx-core/v4/client/jsonrpc" - "github.com/functionx/fx-core/v4/testutil" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/testutil/network" - fxtypes "github.com/functionx/fx-core/v4/types" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/client/grpc" + "github.com/functionx/fx-core/v5/client/jsonrpc" + "github.com/functionx/fx-core/v5/testutil" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/network" + fxtypes "github.com/functionx/fx-core/v5/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" ) type TestSuite struct { diff --git a/tests/upgrade_time_calc_test.go b/tests/upgrade_time_calc_test.go index e949239ae..051c86803 100644 --- a/tests/upgrade_time_calc_test.go +++ b/tests/upgrade_time_calc_test.go @@ -12,7 +12,7 @@ import ( clienthttp "github.com/tendermint/tendermint/rpc/client/http" jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func TestCalculateUpgradeHeight(t *testing.T) { diff --git a/testutil/helpers/key_test.go b/testutil/helpers/key_test.go index 53941dd43..693e267cc 100644 --- a/testutil/helpers/key_test.go +++ b/testutil/helpers/key_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func TestPrivKeyFromMnemonic(t *testing.T) { diff --git a/testutil/helpers/test_helpers.go b/testutil/helpers/test_helpers.go index 76680966f..4764380cf 100644 --- a/testutil/helpers/test_helpers.go +++ b/testutil/helpers/test_helpers.go @@ -43,9 +43,9 @@ import ( tmtypes "github.com/tendermint/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/functionx/fx-core/v4/app" - fxtypes "github.com/functionx/fx-core/v4/types" - fxstakingtypes "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/app" + fxtypes "github.com/functionx/fx-core/v5/types" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) // ABCIConsensusParams defines the default Tendermint consensus params used in fxCore testing. diff --git a/testutil/network.go b/testutil/network.go index 563815fd6..88704c2c0 100644 --- a/testutil/network.go +++ b/testutil/network.go @@ -31,11 +31,11 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" dbm "github.com/tendermint/tm-db" - "github.com/functionx/fx-core/v4/app" - fxcfg "github.com/functionx/fx-core/v4/server/config" - "github.com/functionx/fx-core/v4/testutil/network" - fxtypes "github.com/functionx/fx-core/v4/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/app" + fxcfg "github.com/functionx/fx-core/v5/server/config" + "github.com/functionx/fx-core/v5/testutil/network" + fxtypes "github.com/functionx/fx-core/v5/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" ) // DefaultNetworkConfig returns a sane default configuration suitable for nearly all diff --git a/testutil/network/network.go b/testutil/network/network.go index 69a433c73..bcaddc4b1 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -41,8 +41,8 @@ import ( dbm "github.com/tendermint/tm-db" "google.golang.org/grpc" - fxcfg "github.com/functionx/fx-core/v4/server/config" - fxtypes "github.com/functionx/fx-core/v4/types" + fxcfg "github.com/functionx/fx-core/v5/server/config" + fxtypes "github.com/functionx/fx-core/v5/types" ) // package-wide network lock to only allow one test network at a time diff --git a/testutil/network/util.go b/testutil/network/util.go index 2de84a9e5..bceebdfa4 100644 --- a/testutil/network/util.go +++ b/testutil/network/util.go @@ -28,9 +28,9 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/server" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/server" + fxtypes "github.com/functionx/fx-core/v5/types" ) //gocyclo:ignore diff --git a/testutil/network_test.go b/testutil/network_test.go index 9eaa202c6..913a9dd8b 100644 --- a/testutil/network_test.go +++ b/testutil/network_test.go @@ -12,10 +12,10 @@ import ( hd2 "github.com/evmos/ethermint/crypto/hd" "github.com/stretchr/testify/suite" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/testutil/network" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/network" ) type IntegrationTestSuite struct { diff --git a/types/byte32_test.go b/types/byte32_test.go index 20456a7b9..b7af023d4 100644 --- a/types/byte32_test.go +++ b/types/byte32_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) func TestStrToByte32(t *testing.T) { diff --git a/types/contract.go b/types/contract.go index 90c12d8de..2afbfbb3f 100644 --- a/types/contract.go +++ b/types/contract.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" - "github.com/functionx/fx-core/v4/contract" + "github.com/functionx/fx-core/v5/contract" ) const ( diff --git a/types/eth_validation_test.go b/types/eth_validation_test.go index 661140abe..77905d61b 100644 --- a/types/eth_validation_test.go +++ b/types/eth_validation_test.go @@ -7,8 +7,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" ) func TestIsEmptyHash(t *testing.T) { diff --git a/types/target_test.go b/types/target_test.go index 5e621c996..e22be35fc 100644 --- a/types/target_test.go +++ b/types/target_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) func TestParseTargetIBC(t *testing.T) { diff --git a/x/arbitrum/client/cli/query.go b/x/arbitrum/client/cli/query.go index 7beb134f8..b52587fbe 100644 --- a/x/arbitrum/client/cli/query.go +++ b/x/arbitrum/client/cli/query.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/arbitrum/types" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/arbitrum/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" ) func GetQueryCmd() *cobra.Command { diff --git a/x/arbitrum/client/cli/tx.go b/x/arbitrum/client/cli/tx.go index 74fcd0b08..bdb9a612e 100644 --- a/x/arbitrum/client/cli/tx.go +++ b/x/arbitrum/client/cli/tx.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/arbitrum/types" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/arbitrum/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" ) func GetTxCmd() *cobra.Command { diff --git a/x/arbitrum/module.go b/x/arbitrum/module.go index 2f3600b6c..7330f532a 100644 --- a/x/arbitrum/module.go +++ b/x/arbitrum/module.go @@ -14,10 +14,10 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/arbitrum/client/cli" - "github.com/functionx/fx-core/v4/x/arbitrum/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/arbitrum/client/cli" + "github.com/functionx/fx-core/v5/x/arbitrum/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) // type check to ensure the interface is properly implemented diff --git a/x/arbitrum/types/genesis.go b/x/arbitrum/types/genesis.go index abb7309ba..ae238dae8 100644 --- a/x/arbitrum/types/genesis.go +++ b/x/arbitrum/types/genesis.go @@ -1,7 +1,7 @@ package types import ( - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func DefaultGenesisState() *crosschaintypes.GenesisState { diff --git a/x/arbitrum/types/genesis_test.go b/x/arbitrum/types/genesis_test.go index f695d31b5..2628769c3 100644 --- a/x/arbitrum/types/genesis_test.go +++ b/x/arbitrum/types/genesis_test.go @@ -7,8 +7,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func TestDefaultGenesisState(t *testing.T) { diff --git a/x/avalanche/client/cli/query.go b/x/avalanche/client/cli/query.go index 871674fa6..a4bfa7d51 100644 --- a/x/avalanche/client/cli/query.go +++ b/x/avalanche/client/cli/query.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/avalanche/types" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/avalanche/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" ) func GetQueryCmd() *cobra.Command { diff --git a/x/avalanche/client/cli/tx.go b/x/avalanche/client/cli/tx.go index 8eb43ea8b..360465f4a 100644 --- a/x/avalanche/client/cli/tx.go +++ b/x/avalanche/client/cli/tx.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/avalanche/types" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/avalanche/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" ) func GetTxCmd() *cobra.Command { diff --git a/x/avalanche/module.go b/x/avalanche/module.go index de32c1955..5619ef483 100644 --- a/x/avalanche/module.go +++ b/x/avalanche/module.go @@ -14,10 +14,10 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/avalanche/client/cli" - "github.com/functionx/fx-core/v4/x/avalanche/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/avalanche/client/cli" + "github.com/functionx/fx-core/v5/x/avalanche/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) // type check to ensure the interface is properly implemented diff --git a/x/avalanche/types/genesis.go b/x/avalanche/types/genesis.go index 214db3a46..854edfa3f 100644 --- a/x/avalanche/types/genesis.go +++ b/x/avalanche/types/genesis.go @@ -1,7 +1,7 @@ package types import ( - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func DefaultGenesisState() *crosschaintypes.GenesisState { diff --git a/x/avalanche/types/genesis_test.go b/x/avalanche/types/genesis_test.go index f14d40480..39fdef13c 100644 --- a/x/avalanche/types/genesis_test.go +++ b/x/avalanche/types/genesis_test.go @@ -7,8 +7,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func TestDefaultGenesisState(t *testing.T) { diff --git a/x/bsc/client/cli/query.go b/x/bsc/client/cli/query.go index 131f4ab14..e6ac62e15 100644 --- a/x/bsc/client/cli/query.go +++ b/x/bsc/client/cli/query.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" ) func GetQueryCmd() *cobra.Command { diff --git a/x/bsc/client/cli/tx.go b/x/bsc/client/cli/tx.go index f2e0700d8..0e451760f 100644 --- a/x/bsc/client/cli/tx.go +++ b/x/bsc/client/cli/tx.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" ) func GetTxCmd() *cobra.Command { diff --git a/x/bsc/module.go b/x/bsc/module.go index 5f48f641c..e7baebdbe 100644 --- a/x/bsc/module.go +++ b/x/bsc/module.go @@ -14,10 +14,10 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/bsc/client/cli" - "github.com/functionx/fx-core/v4/x/bsc/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/bsc/client/cli" + "github.com/functionx/fx-core/v5/x/bsc/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) // type check to ensure the interface is properly implemented diff --git a/x/bsc/types/genesis.go b/x/bsc/types/genesis.go index 720e61fdf..f737ea47e 100644 --- a/x/bsc/types/genesis.go +++ b/x/bsc/types/genesis.go @@ -1,7 +1,7 @@ package types import ( - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func DefaultGenesisState() *crosschaintypes.GenesisState { diff --git a/x/bsc/types/genesis_test.go b/x/bsc/types/genesis_test.go index 79aa20cfb..67ffb4ad5 100644 --- a/x/bsc/types/genesis_test.go +++ b/x/bsc/types/genesis_test.go @@ -7,8 +7,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func TestDefaultGenesisState(t *testing.T) { diff --git a/x/crosschain/client/cli/query.go b/x/crosschain/client/cli/query.go index 834fb3240..4adfe8a72 100644 --- a/x/crosschain/client/cli/query.go +++ b/x/crosschain/client/cli/query.go @@ -14,7 +14,7 @@ import ( "github.com/spf13/cobra" abcitype "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func GetQueryCmd(subCmd ...*cobra.Command) *cobra.Command { diff --git a/x/crosschain/client/cli/tx.go b/x/crosschain/client/cli/tx.go index 05fba4fae..1d4097c60 100644 --- a/x/crosschain/client/cli/tx.go +++ b/x/crosschain/client/cli/tx.go @@ -21,7 +21,7 @@ import ( troncommon "github.com/fbsobreira/gotron-sdk/pkg/common" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func GetTxCmd(subCmd ...*cobra.Command) *cobra.Command { diff --git a/x/crosschain/client/cli/tx_proposal.go b/x/crosschain/client/cli/tx_proposal.go index 545cf75be..2dea31304 100644 --- a/x/crosschain/client/cli/tx_proposal.go +++ b/x/crosschain/client/cli/tx_proposal.go @@ -11,7 +11,7 @@ import ( govv1betal "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func CmdUpdateChainOraclesProposal(chainName string) *cobra.Command { diff --git a/x/crosschain/client/proposal_handler.go b/x/crosschain/client/proposal_handler.go index 8a7ea9672..e87b41800 100644 --- a/x/crosschain/client/proposal_handler.go +++ b/x/crosschain/client/proposal_handler.go @@ -4,7 +4,7 @@ import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" ) var LegacyUpdateChainOraclesProposalHandler = govclient.NewProposalHandler(NewLegacyUpdateChainOraclesProposalCmd) diff --git a/x/crosschain/keeper/abci.go b/x/crosschain/keeper/abci.go index db5e59cab..45293390f 100644 --- a/x/crosschain/keeper/abci.go +++ b/x/crosschain/keeper/abci.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // EndBlocker is called at the end of every block diff --git a/x/crosschain/keeper/abci_test.go b/x/crosschain/keeper/abci_test.go index 550d0a3be..f8f788832 100644 --- a/x/crosschain/keeper/abci_test.go +++ b/x/crosschain/keeper/abci_test.go @@ -12,11 +12,11 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain" - "github.com/functionx/fx-core/v4/x/crosschain/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain" + "github.com/functionx/fx-core/v5/x/crosschain/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func (suite *KeeperTestSuite) TestABCIEndBlockDepositClaim() { diff --git a/x/crosschain/keeper/attestation.go b/x/crosschain/keeper/attestation.go index 14e961fde..5c54a9f7c 100644 --- a/x/crosschain/keeper/attestation.go +++ b/x/crosschain/keeper/attestation.go @@ -9,7 +9,7 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (k Keeper) Attest(ctx sdk.Context, oracleAddr sdk.AccAddress, claim types.ExternalClaim) (*types.Attestation, error) { diff --git a/x/crosschain/keeper/attestation_handler.go b/x/crosschain/keeper/attestation_handler.go index 2c86a59e3..7e180ba3d 100644 --- a/x/crosschain/keeper/attestation_handler.go +++ b/x/crosschain/keeper/attestation_handler.go @@ -6,8 +6,8 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // AttestationHandler Handle is the entry point for Attestation processing. diff --git a/x/crosschain/keeper/batch.go b/x/crosschain/keeper/batch.go index 6c965e330..524bfbebb 100644 --- a/x/crosschain/keeper/batch.go +++ b/x/crosschain/keeper/batch.go @@ -8,7 +8,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // BuildOutgoingTxBatch starts the following process chain: diff --git a/x/crosschain/keeper/batch_test.go b/x/crosschain/keeper/batch_test.go index fab31f3db..24d89348b 100644 --- a/x/crosschain/keeper/batch_test.go +++ b/x/crosschain/keeper/batch_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (suite *KeeperTestSuite) TestLastPendingBatchRequestByAddr() { diff --git a/x/crosschain/keeper/bridge_token.go b/x/crosschain/keeper/bridge_token.go index 02a0eda21..7b8370eb3 100644 --- a/x/crosschain/keeper/bridge_token.go +++ b/x/crosschain/keeper/bridge_token.go @@ -5,8 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (k Keeper) GetBridgeTokenDenom(ctx sdk.Context, tokenContract string) *types.BridgeToken { diff --git a/x/crosschain/keeper/bridge_token_test.go b/x/crosschain/keeper/bridge_token_test.go index 629087aaf..57515995f 100644 --- a/x/crosschain/keeper/bridge_token_test.go +++ b/x/crosschain/keeper/bridge_token_test.go @@ -3,8 +3,8 @@ package keeper_test import ( "fmt" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (suite *KeeperTestSuite) TestKeeper_BridgeToken() { diff --git a/x/crosschain/keeper/delegate.go b/x/crosschain/keeper/delegate.go index 3c72e0329..6159b1374 100644 --- a/x/crosschain/keeper/delegate.go +++ b/x/crosschain/keeper/delegate.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (k Keeper) GetOracleDelegateToken(ctx sdk.Context, delegateAddr sdk.AccAddress, valAddr sdk.ValAddress) (sdkmath.Int, error) { diff --git a/x/crosschain/keeper/evidence.go b/x/crosschain/keeper/evidence.go index c7ad47e2a..c755fc168 100644 --- a/x/crosschain/keeper/evidence.go +++ b/x/crosschain/keeper/evidence.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // SetPastExternalSignatureCheckpoint puts the checkpoint of a oracle set, batch into a set diff --git a/x/crosschain/keeper/evidence_test.go b/x/crosschain/keeper/evidence_test.go index f00f11bcf..6010198c3 100644 --- a/x/crosschain/keeper/evidence_test.go +++ b/x/crosschain/keeper/evidence_test.go @@ -5,7 +5,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func (suite *KeeperTestSuite) TestKeeper_PastExternalSignatureCheckpoint() { diff --git a/x/crosschain/keeper/genesis.go b/x/crosschain/keeper/genesis.go index ca7afd8a4..46915701a 100644 --- a/x/crosschain/keeper/genesis.go +++ b/x/crosschain/keeper/genesis.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // InitGenesis import module genesis diff --git a/x/crosschain/keeper/genesis_test.go b/x/crosschain/keeper/genesis_test.go index b6ae97a8e..117a63374 100644 --- a/x/crosschain/keeper/genesis_test.go +++ b/x/crosschain/keeper/genesis_test.go @@ -10,10 +10,10 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/require" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/crosschain/keeper" - "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/crosschain/keeper" + "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" ) // Tests that batches and transactions are preserved during chain restart diff --git a/x/crosschain/keeper/grpc_query.go b/x/crosschain/keeper/grpc_query.go index e0a9e8747..4b0f33a2c 100644 --- a/x/crosschain/keeper/grpc_query.go +++ b/x/crosschain/keeper/grpc_query.go @@ -9,15 +9,15 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) var _ types.QueryServer = Keeper{} diff --git a/x/crosschain/keeper/grpc_query_router.go b/x/crosschain/keeper/grpc_query_router.go index 286e369ac..6864a82c4 100644 --- a/x/crosschain/keeper/grpc_query_router.go +++ b/x/crosschain/keeper/grpc_query_router.go @@ -6,8 +6,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" ) var _ types.QueryServer = RouterKeeper{} diff --git a/x/crosschain/keeper/grpc_query_test.go b/x/crosschain/keeper/grpc_query_test.go index b85776cab..21b5c5ddf 100644 --- a/x/crosschain/keeper/grpc_query_test.go +++ b/x/crosschain/keeper/grpc_query_test.go @@ -22,18 +22,18 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain/keeper" - "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain/keeper" + "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) type CrossChainGrpcTestSuite struct { diff --git a/x/crosschain/keeper/hook.go b/x/crosschain/keeper/hook.go index 00a741dcc..03418279b 100644 --- a/x/crosschain/keeper/hook.go +++ b/x/crosschain/keeper/hook.go @@ -4,7 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) // TransferAfter diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index 9af23a806..21464cdac 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -11,8 +11,8 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/tendermint/tendermint/libs/log" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // Keeper maintains the link to storage and exposes getter/setter methods for the various parts of the state machine diff --git a/x/crosschain/keeper/keeper_router.go b/x/crosschain/keeper/keeper_router.go index cb18cf2fd..30a18b1d8 100644 --- a/x/crosschain/keeper/keeper_router.go +++ b/x/crosschain/keeper/keeper_router.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/libs/log" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // RouterKeeper maintains the link to storage and exposes getter/setter methods for the various parts of the state machine diff --git a/x/crosschain/keeper/keeper_test.go b/x/crosschain/keeper/keeper_test.go index c84c3e837..db52017a1 100644 --- a/x/crosschain/keeper/keeper_test.go +++ b/x/crosschain/keeper/keeper_test.go @@ -15,19 +15,19 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - arbitrumtypes "github.com/functionx/fx-core/v4/x/arbitrum/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain/keeper" - "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - optimismtypes "github.com/functionx/fx-core/v4/x/optimism/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - tronkeeper "github.com/functionx/fx-core/v4/x/tron/keeper" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain/keeper" + "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + tronkeeper "github.com/functionx/fx-core/v5/x/tron/keeper" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) type KeeperTestSuite struct { diff --git a/x/crosschain/keeper/migrations.go b/x/crosschain/keeper/migrations.go index ccd8d852c..2f30d51fe 100644 --- a/x/crosschain/keeper/migrations.go +++ b/x/crosschain/keeper/migrations.go @@ -3,8 +3,8 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - v4 "github.com/functionx/fx-core/v4/x/crosschain/migrations/v4" - "github.com/functionx/fx-core/v4/x/crosschain/types" + v4 "github.com/functionx/fx-core/v5/x/crosschain/migrations/v4" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // Migrator is a struct for handling in-place store migrations. diff --git a/x/crosschain/keeper/msg_server.go b/x/crosschain/keeper/msg_server.go index bee119fa2..0e78d2879 100644 --- a/x/crosschain/keeper/msg_server.go +++ b/x/crosschain/keeper/msg_server.go @@ -12,8 +12,8 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) var _ types.MsgServer = MsgServer{} diff --git a/x/crosschain/keeper/msg_server_router.go b/x/crosschain/keeper/msg_server_router.go index 0fa896a30..336f2350c 100644 --- a/x/crosschain/keeper/msg_server_router.go +++ b/x/crosschain/keeper/msg_server_router.go @@ -7,7 +7,7 @@ import ( errorsmod "cosmossdk.io/errors" errortypes "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) type msgServer struct { diff --git a/x/crosschain/keeper/msg_server_test.go b/x/crosschain/keeper/msg_server_test.go index 91aa829c2..779dd8730 100644 --- a/x/crosschain/keeper/msg_server_test.go +++ b/x/crosschain/keeper/msg_server_test.go @@ -18,11 +18,11 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func (suite *KeeperTestSuite) TestMsgBondedOracle() { diff --git a/x/crosschain/keeper/oracle.go b/x/crosschain/keeper/oracle.go index 406e123d5..648df011a 100644 --- a/x/crosschain/keeper/oracle.go +++ b/x/crosschain/keeper/oracle.go @@ -4,7 +4,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // --- PROPOSAL ORACLE --- // diff --git a/x/crosschain/keeper/oracle_set.go b/x/crosschain/keeper/oracle_set.go index 747c62884..59ab3fa3f 100644 --- a/x/crosschain/keeper/oracle_set.go +++ b/x/crosschain/keeper/oracle_set.go @@ -7,7 +7,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // --- ORACLE SET REQUESTS --- // diff --git a/x/crosschain/keeper/oracle_set_test.go b/x/crosschain/keeper/oracle_set_test.go index 231e64e6c..3c41dcbb0 100644 --- a/x/crosschain/keeper/oracle_set_test.go +++ b/x/crosschain/keeper/oracle_set_test.go @@ -9,8 +9,8 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (suite *KeeperTestSuite) TestLastPendingOracleSetRequestByAddr() { diff --git a/x/crosschain/keeper/params.go b/x/crosschain/keeper/params.go index 8d3146f63..bab40fca1 100644 --- a/x/crosschain/keeper/params.go +++ b/x/crosschain/keeper/params.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // GetParams returns the parameters from the store diff --git a/x/crosschain/keeper/params_test.go b/x/crosschain/keeper/params_test.go index 27cc8c200..e30e596e9 100644 --- a/x/crosschain/keeper/params_test.go +++ b/x/crosschain/keeper/params_test.go @@ -4,8 +4,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (suite *KeeperTestSuite) TestParams() { diff --git a/x/crosschain/keeper/pool.go b/x/crosschain/keeper/pool.go index 20ef98f67..071ffc951 100644 --- a/x/crosschain/keeper/pool.go +++ b/x/crosschain/keeper/pool.go @@ -9,8 +9,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // AddToOutgoingPool diff --git a/x/crosschain/keeper/pool_test.go b/x/crosschain/keeper/pool_test.go index fac5a89d9..a28e2b5a4 100644 --- a/x/crosschain/keeper/pool_test.go +++ b/x/crosschain/keeper/pool_test.go @@ -7,9 +7,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" ) func (suite *KeeperTestSuite) TestKeeper_Outgoing() { diff --git a/x/crosschain/keeper/proposal_legacy.go b/x/crosschain/keeper/proposal_legacy.go index db99701fd..f5791558c 100644 --- a/x/crosschain/keeper/proposal_legacy.go +++ b/x/crosschain/keeper/proposal_legacy.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // Deprecated diff --git a/x/crosschain/keeper/proposal_legacy_test.go b/x/crosschain/keeper/proposal_legacy_test.go index d004a3d24..a3ea89a15 100644 --- a/x/crosschain/keeper/proposal_legacy_test.go +++ b/x/crosschain/keeper/proposal_legacy_test.go @@ -5,8 +5,8 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (suite *KeeperTestSuite) TestUpdateCrossChainOraclesProposal() { diff --git a/x/crosschain/keeper/relay_transfer.go b/x/crosschain/keeper/relay_transfer.go index 98c22d0e0..b0c65b2c3 100644 --- a/x/crosschain/keeper/relay_transfer.go +++ b/x/crosschain/keeper/relay_transfer.go @@ -13,8 +13,8 @@ import ( ibcclienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func (k Keeper) RelayTransferHandler(ctx sdk.Context, eventNonce uint64, targetHex string, receiver sdk.AccAddress, coin sdk.Coin) error { diff --git a/x/crosschain/migrations/v4/migrator_param.go b/x/crosschain/migrations/v4/migrator_param.go index 7f2fb8d3d..2488e418e 100644 --- a/x/crosschain/migrations/v4/migrator_param.go +++ b/x/crosschain/migrations/v4/migrator_param.go @@ -5,7 +5,7 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func MigratorParam(ctx sdk.Context, legacySubspace types.Subspace, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { diff --git a/x/crosschain/migrations/v4/migrator_param_test.go b/x/crosschain/migrations/v4/migrator_param_test.go index 3c1d36e66..36ea240ac 100644 --- a/x/crosschain/migrations/v4/migrator_param_test.go +++ b/x/crosschain/migrations/v4/migrator_param_test.go @@ -9,9 +9,9 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/require" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - v4 "github.com/functionx/fx-core/v4/x/crosschain/migrations/v4" - "github.com/functionx/fx-core/v4/x/crosschain/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + v4 "github.com/functionx/fx-core/v5/x/crosschain/migrations/v4" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) type mockSubspace struct { diff --git a/x/crosschain/proposal_legacy.go b/x/crosschain/proposal_legacy.go index d8d0c7f4a..41bd88067 100644 --- a/x/crosschain/proposal_legacy.go +++ b/x/crosschain/proposal_legacy.go @@ -9,8 +9,8 @@ import ( errortypes "github.com/cosmos/cosmos-sdk/types/errors" govv1betal "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/functionx/fx-core/v4/x/crosschain/keeper" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/keeper" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // NewCrosschainProposalHandler diff --git a/x/crosschain/service.go b/x/crosschain/service.go index 839752558..616fe648c 100644 --- a/x/crosschain/service.go +++ b/x/crosschain/service.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/grpc-ecosystem/grpc-gateway/runtime" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { diff --git a/x/crosschain/types/expected_keepers.go b/x/crosschain/types/expected_keepers.go index 4a18847ca..d20019963 100644 --- a/x/crosschain/types/expected_keepers.go +++ b/x/crosschain/types/expected_keepers.go @@ -10,7 +10,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" tranfsertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) type StakingKeeper interface { diff --git a/x/crosschain/types/key_test.go b/x/crosschain/types/key_test.go index 4534cea59..58de45435 100644 --- a/x/crosschain/types/key_test.go +++ b/x/crosschain/types/key_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/assert" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) func TestGetBatchConfirmKey(t *testing.T) { diff --git a/x/crosschain/types/msg_validate.go b/x/crosschain/types/msg_validate.go index 9e7987c7a..3beccc812 100644 --- a/x/crosschain/types/msg_validate.go +++ b/x/crosschain/types/msg_validate.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) var _ MsgValidateBasic = &MsgValidate{} diff --git a/x/crosschain/types/msg_validator_test.go b/x/crosschain/types/msg_validator_test.go index b49730f29..52ead8bba 100644 --- a/x/crosschain/types/msg_validator_test.go +++ b/x/crosschain/types/msg_validator_test.go @@ -14,15 +14,15 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - _ "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + _ "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) const ( diff --git a/x/crosschain/types/msgs_test.go b/x/crosschain/types/msgs_test.go index 6982aba42..3bec328c0 100644 --- a/x/crosschain/types/msgs_test.go +++ b/x/crosschain/types/msgs_test.go @@ -5,13 +5,13 @@ import ( "github.com/stretchr/testify/assert" - _ "github.com/functionx/fx-core/v4/app" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + _ "github.com/functionx/fx-core/v5/app" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func TestValidateModuleName(t *testing.T) { diff --git a/x/crosschain/types/params.go b/x/crosschain/types/params.go index eb65d322a..3de44ae87 100644 --- a/x/crosschain/types/params.go +++ b/x/crosschain/types/params.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) const ( diff --git a/x/crosschain/types/types.go b/x/crosschain/types/types.go index 185e7d844..efc407f1b 100644 --- a/x/crosschain/types/types.go +++ b/x/crosschain/types/types.go @@ -12,7 +12,7 @@ import ( gethcommon "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) // --- ERC20Token --- // diff --git a/x/erc20/client/cli/query.go b/x/erc20/client/cli/query.go index cf6ffa763..ca72d4df9 100644 --- a/x/erc20/client/cli/query.go +++ b/x/erc20/client/cli/query.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client/flags" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // GetQueryCmd returns the parent command for all erc20 CLI query commands. diff --git a/x/erc20/client/cli/tx.go b/x/erc20/client/cli/tx.go index 957602fae..5ce878672 100644 --- a/x/erc20/client/cli/tx.go +++ b/x/erc20/client/cli/tx.go @@ -11,8 +11,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/spf13/cobra" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // NewTxCmd returns a root CLI command handler for certain modules/erc20 transaction commands. diff --git a/x/erc20/client/cli/tx_proposal.go b/x/erc20/client/cli/tx_proposal.go index d31b09bbe..0e32c67eb 100644 --- a/x/erc20/client/cli/tx_proposal.go +++ b/x/erc20/client/cli/tx_proposal.go @@ -16,7 +16,7 @@ import ( "google.golang.org/grpc/codes" grpcstatus "google.golang.org/grpc/status" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // NewLegacyRegisterCoinProposalCmd implements the command to submit a register-coin proposal diff --git a/x/erc20/client/proposal_handler.go b/x/erc20/client/proposal_handler.go index 86a9deca1..ddbc9f9b3 100644 --- a/x/erc20/client/proposal_handler.go +++ b/x/erc20/client/proposal_handler.go @@ -3,7 +3,7 @@ package client import ( govclient "github.com/cosmos/cosmos-sdk/x/gov/client" - "github.com/functionx/fx-core/v4/x/erc20/client/cli" + "github.com/functionx/fx-core/v5/x/erc20/client/cli" ) var ( diff --git a/x/erc20/keeper/evm.go b/x/erc20/keeper/evm.go index 65ddce4d1..74f0454c4 100644 --- a/x/erc20/keeper/evm.go +++ b/x/erc20/keeper/evm.go @@ -9,8 +9,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" evmtypes "github.com/evmos/ethermint/x/evm/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // QueryERC20 returns the data of a deployed ERC20 contract diff --git a/x/erc20/keeper/evm_test.go b/x/erc20/keeper/evm_test.go index 2367dcd6d..2dd24dc10 100644 --- a/x/erc20/keeper/evm_test.go +++ b/x/erc20/keeper/evm_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func (suite *KeeperTestSuite) TestQueryERC20() { diff --git a/x/erc20/keeper/genesis.go b/x/erc20/keeper/genesis.go index 74d7bb21c..759c196b8 100644 --- a/x/erc20/keeper/genesis.go +++ b/x/erc20/keeper/genesis.go @@ -5,8 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // InitGenesis import module genesis diff --git a/x/erc20/keeper/grpc_query.go b/x/erc20/keeper/grpc_query.go index 4e69e57c1..f22836c73 100644 --- a/x/erc20/keeper/grpc_query.go +++ b/x/erc20/keeper/grpc_query.go @@ -9,8 +9,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) var _ types.QueryServer = Keeper{} diff --git a/x/erc20/keeper/grpc_query_test.go b/x/erc20/keeper/grpc_query_test.go index 6e2e25919..408a442bd 100644 --- a/x/erc20/keeper/grpc_query_test.go +++ b/x/erc20/keeper/grpc_query_test.go @@ -7,9 +7,9 @@ import ( "github.com/cosmos/cosmos-sdk/types/query" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func (suite *KeeperTestSuite) TestQueryParams() { diff --git a/x/erc20/keeper/keeper.go b/x/erc20/keeper/keeper.go index 9cd38ba78..77f5c42f5 100644 --- a/x/erc20/keeper/keeper.go +++ b/x/erc20/keeper/keeper.go @@ -12,8 +12,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/tendermint/tendermint/libs/log" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // Keeper of this module maintains collections of erc20. diff --git a/x/erc20/keeper/keeper_test.go b/x/erc20/keeper/keeper_test.go index 52076597b..70cec931a 100644 --- a/x/erc20/keeper/keeper_test.go +++ b/x/erc20/keeper/keeper_test.go @@ -38,13 +38,13 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - fxserverconfig "github.com/functionx/fx-core/v4/server/config" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/app" + fxserverconfig "github.com/functionx/fx-core/v5/server/config" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" ) type KeeperTestSuite struct { diff --git a/x/erc20/keeper/migrations.go b/x/erc20/keeper/migrations.go index 2636fe350..5e2ee398c 100644 --- a/x/erc20/keeper/migrations.go +++ b/x/erc20/keeper/migrations.go @@ -3,8 +3,8 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - v4 "github.com/functionx/fx-core/v4/x/erc20/migrations/v4" - "github.com/functionx/fx-core/v4/x/erc20/types" + v4 "github.com/functionx/fx-core/v5/x/erc20/migrations/v4" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // Migrator is a struct for handling in-place store migrations. diff --git a/x/erc20/keeper/mint.go b/x/erc20/keeper/mint.go index 3ac7eacd0..51ccf24fa 100644 --- a/x/erc20/keeper/mint.go +++ b/x/erc20/keeper/mint.go @@ -6,7 +6,7 @@ import ( errortypes "github.com/cosmos/cosmos-sdk/types/errors" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // MintingEnabled checks that: diff --git a/x/erc20/keeper/mint_test.go b/x/erc20/keeper/mint_test.go index 1b6cadcdd..bd1a8030c 100644 --- a/x/erc20/keeper/mint_test.go +++ b/x/erc20/keeper/mint_test.go @@ -6,8 +6,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func (suite *KeeperTestSuite) TestMintingEnabled() { diff --git a/x/erc20/keeper/msg_server.go b/x/erc20/keeper/msg_server.go index 8ba5bca6c..7bf075e4f 100644 --- a/x/erc20/keeper/msg_server.go +++ b/x/erc20/keeper/msg_server.go @@ -16,8 +16,8 @@ import ( ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) var _ types.MsgServer = &Keeper{} diff --git a/x/erc20/keeper/msg_server_test.go b/x/erc20/keeper/msg_server_test.go index a8ba942bf..f10f3e2aa 100644 --- a/x/erc20/keeper/msg_server_test.go +++ b/x/erc20/keeper/msg_server_test.go @@ -13,9 +13,9 @@ import ( "github.com/ethereum/go-ethereum/common" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func (suite *KeeperTestSuite) TestConvertCoinNativeCoin() { diff --git a/x/erc20/keeper/params.go b/x/erc20/keeper/params.go index b42a8a547..323d69f63 100644 --- a/x/erc20/keeper/params.go +++ b/x/erc20/keeper/params.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // GetParams returns the total set of erc20 parameters. diff --git a/x/erc20/keeper/params_test.go b/x/erc20/keeper/params_test.go index 9e0ada798..bdd5a6b28 100644 --- a/x/erc20/keeper/params_test.go +++ b/x/erc20/keeper/params_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "time" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func (suite *KeeperTestSuite) TestParams() { diff --git a/x/erc20/keeper/proposals.go b/x/erc20/keeper/proposals.go index d6abfce59..d12286d0d 100644 --- a/x/erc20/keeper/proposals.go +++ b/x/erc20/keeper/proposals.go @@ -9,8 +9,8 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // RegisterNativeCoin deploys an erc20 contract and creates the token pair for the existing cosmos coin diff --git a/x/erc20/keeper/proposals_test.go b/x/erc20/keeper/proposals_test.go index e95c9a6bf..3ed455869 100644 --- a/x/erc20/keeper/proposals_test.go +++ b/x/erc20/keeper/proposals_test.go @@ -13,10 +13,10 @@ import ( "github.com/ethereum/go-ethereum/crypto" "golang.org/x/exp/slices" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" ) func (suite *KeeperTestSuite) setupRegisterERC20Pair() common.Address { diff --git a/x/erc20/keeper/token_pairs.go b/x/erc20/keeper/token_pairs.go index 650493764..a72d24826 100644 --- a/x/erc20/keeper/token_pairs.go +++ b/x/erc20/keeper/token_pairs.go @@ -6,8 +6,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // GetAllTokenPairs - get all registered token tokenPairs diff --git a/x/erc20/keeper/token_pairs_test.go b/x/erc20/keeper/token_pairs_test.go index 4eb6997c6..eb3b64d81 100644 --- a/x/erc20/keeper/token_pairs_test.go +++ b/x/erc20/keeper/token_pairs_test.go @@ -3,9 +3,9 @@ package keeper_test import ( "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func (suite *KeeperTestSuite) TestGetTokenPair() { diff --git a/x/erc20/keeper/transfer_relation.go b/x/erc20/keeper/transfer_relation.go index 327155ade..3c1a07231 100644 --- a/x/erc20/keeper/transfer_relation.go +++ b/x/erc20/keeper/transfer_relation.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func (k Keeper) RefundAfter(ctx sdk.Context, channel string, sequence uint64, sender sdk.AccAddress, amount sdk.Coin) error { diff --git a/x/erc20/migrations/v4/migrator_param.go b/x/erc20/migrations/v4/migrator_param.go index 23e06855a..e5f646efe 100644 --- a/x/erc20/migrations/v4/migrator_param.go +++ b/x/erc20/migrations/v4/migrator_param.go @@ -5,7 +5,7 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func MigratorParam(ctx sdk.Context, legacySubspace types.Subspace, storeKey storetypes.StoreKey, cdc codec.BinaryCodec) error { diff --git a/x/erc20/migrations/v4/migrator_param_test.go b/x/erc20/migrations/v4/migrator_param_test.go index 9216537a4..fabd242fc 100644 --- a/x/erc20/migrations/v4/migrator_param_test.go +++ b/x/erc20/migrations/v4/migrator_param_test.go @@ -9,8 +9,8 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/require" - v4 "github.com/functionx/fx-core/v4/x/erc20/migrations/v4" - "github.com/functionx/fx-core/v4/x/erc20/types" + v4 "github.com/functionx/fx-core/v5/x/erc20/migrations/v4" + "github.com/functionx/fx-core/v5/x/erc20/types" ) type mockSubspace struct { diff --git a/x/erc20/module.go b/x/erc20/module.go index 31055f942..ef7b80ffc 100644 --- a/x/erc20/module.go +++ b/x/erc20/module.go @@ -15,9 +15,9 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/erc20/client/cli" - "github.com/functionx/fx-core/v4/x/erc20/keeper" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/client/cli" + "github.com/functionx/fx-core/v5/x/erc20/keeper" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // type check to ensure the interface is properly implemented diff --git a/x/erc20/proposal.go b/x/erc20/proposal.go index 13bf7e240..620acac92 100644 --- a/x/erc20/proposal.go +++ b/x/erc20/proposal.go @@ -8,8 +8,8 @@ import ( govv1betal "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/x/erc20/keeper" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/keeper" + "github.com/functionx/fx-core/v5/x/erc20/types" ) // NewErc20ProposalHandler creates a governance handler to manage new proposal types. diff --git a/x/erc20/types/contract_event.go b/x/erc20/types/contract_event.go index d09f2229e..f72e0fe98 100644 --- a/x/erc20/types/contract_event.go +++ b/x/erc20/types/contract_event.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) const ( diff --git a/x/erc20/types/contract_event_test.go b/x/erc20/types/contract_event_test.go index 64f13219d..77f98041d 100644 --- a/x/erc20/types/contract_event_test.go +++ b/x/erc20/types/contract_event_test.go @@ -10,7 +10,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) func BenchmarkSingleParseEventLog(b *testing.B) { diff --git a/x/erc20/types/msg.go b/x/erc20/types/msg.go index 547c81deb..6aaa45d3a 100644 --- a/x/erc20/types/msg.go +++ b/x/erc20/types/msg.go @@ -11,7 +11,7 @@ import ( ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) var ( diff --git a/x/erc20/types/proposal.go b/x/erc20/types/proposal.go index 5a44dbee4..c7a30b293 100644 --- a/x/erc20/types/proposal.go +++ b/x/erc20/types/proposal.go @@ -10,7 +10,7 @@ import ( govv1betal "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) // constants diff --git a/x/erc20/types/token_pair.go b/x/erc20/types/token_pair.go index f63027bf6..c98ba6a4e 100644 --- a/x/erc20/types/token_pair.go +++ b/x/erc20/types/token_pair.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/tendermint/tendermint/crypto/tmhash" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) // NewTokenPair returns an instance of TokenPair diff --git a/x/eth/client/cli/query.go b/x/eth/client/cli/query.go index de03c1f25..94fc8c2cb 100644 --- a/x/eth/client/cli/query.go +++ b/x/eth/client/cli/query.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/eth/types" ) func GetQueryCmd() *cobra.Command { diff --git a/x/eth/client/cli/tx.go b/x/eth/client/cli/tx.go index 8419cf1ee..23c3891cd 100644 --- a/x/eth/client/cli/tx.go +++ b/x/eth/client/cli/tx.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - "github.com/functionx/fx-core/v4/x/eth/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/eth/types" ) func GetTxCmd() *cobra.Command { diff --git a/x/eth/module.go b/x/eth/module.go index e5b229f84..aaff65e5c 100644 --- a/x/eth/module.go +++ b/x/eth/module.go @@ -14,10 +14,10 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/eth/client/cli" - "github.com/functionx/fx-core/v4/x/eth/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/eth/client/cli" + "github.com/functionx/fx-core/v5/x/eth/types" ) // type check to ensure the interface is properly implemented diff --git a/x/eth/types/genesis.go b/x/eth/types/genesis.go index 1fa028a6e..bc12963a0 100644 --- a/x/eth/types/genesis.go +++ b/x/eth/types/genesis.go @@ -1,7 +1,7 @@ package types import ( - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func DefaultGenesisState() *crosschaintypes.GenesisState { diff --git a/x/eth/types/genesis_test.go b/x/eth/types/genesis_test.go index 270f15ceb..7ac364dc1 100644 --- a/x/eth/types/genesis_test.go +++ b/x/eth/types/genesis_test.go @@ -7,8 +7,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func TestDefaultGenesisState(t *testing.T) { diff --git a/x/evm/keeper/contract_code.go b/x/evm/keeper/contract_code.go index 7f8c71d80..4543cb6a3 100644 --- a/x/evm/keeper/contract_code.go +++ b/x/evm/keeper/contract_code.go @@ -13,8 +13,8 @@ import ( "github.com/evmos/ethermint/x/evm/statedb" evmtypes "github.com/evmos/ethermint/x/evm/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) // CreateContractWithCode create contract account and set code diff --git a/x/evm/keeper/contract_code_test.go b/x/evm/keeper/contract_code_test.go index 299c9a433..1d1aca872 100644 --- a/x/evm/keeper/contract_code_test.go +++ b/x/evm/keeper/contract_code_test.go @@ -10,8 +10,8 @@ import ( evmtypes "github.com/evmos/ethermint/x/evm/types" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" ) func (suite *KeeperTestSuite) TestKeeper_CreateContractWithCode() { diff --git a/x/evm/keeper/genesis.go b/x/evm/keeper/genesis.go index e0de50e3a..003d20cd9 100644 --- a/x/evm/keeper/genesis.go +++ b/x/evm/keeper/genesis.go @@ -11,7 +11,7 @@ import ( "github.com/evmos/ethermint/x/evm/types" abci "github.com/tendermint/tendermint/abci/types" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) // InitGenesis initializes genesis state based on exported genesis diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index fed88ee33..5f12bde11 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -13,9 +13,9 @@ import ( evmkeeper "github.com/evmos/ethermint/x/evm/keeper" "github.com/evmos/ethermint/x/evm/types" - fxserverconfig "github.com/functionx/fx-core/v4/server/config" - fxtypes "github.com/functionx/fx-core/v4/types" - fxevmtypes "github.com/functionx/fx-core/v4/x/evm/types" + fxserverconfig "github.com/functionx/fx-core/v5/server/config" + fxtypes "github.com/functionx/fx-core/v5/types" + fxevmtypes "github.com/functionx/fx-core/v5/x/evm/types" ) type Keeper struct { diff --git a/x/evm/keeper/keeper_test.go b/x/evm/keeper/keeper_test.go index 600f3b8aa..ebcbd489d 100644 --- a/x/evm/keeper/keeper_test.go +++ b/x/evm/keeper/keeper_test.go @@ -15,9 +15,9 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" ) type KeeperTestSuite struct { diff --git a/x/evm/keeper/msg_server.go b/x/evm/keeper/msg_server.go index 0e55875dd..3655b09bb 100644 --- a/x/evm/keeper/msg_server.go +++ b/x/evm/keeper/msg_server.go @@ -17,7 +17,7 @@ import ( tmbytes "github.com/tendermint/tendermint/libs/bytes" tmtypes "github.com/tendermint/tendermint/types" - fxevmtypes "github.com/functionx/fx-core/v4/x/evm/types" + fxevmtypes "github.com/functionx/fx-core/v5/x/evm/types" ) var _ types.MsgServer = &Keeper{} diff --git a/x/evm/keeper/msg_server_test.go b/x/evm/keeper/msg_server_test.go index ab54081e7..999a9b942 100644 --- a/x/evm/keeper/msg_server_test.go +++ b/x/evm/keeper/msg_server_test.go @@ -12,9 +12,9 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - fxevmtypes "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + fxevmtypes "github.com/functionx/fx-core/v5/x/evm/types" ) func (suite *KeeperTestSuite) TestKeeper_EthereumTx() { diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index a49eba5aa..e7f8ceac8 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -15,7 +15,7 @@ import ( "github.com/evmos/ethermint/x/evm/statedb" "github.com/evmos/ethermint/x/evm/types" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) // EVMConfig creates the EVMConfig based on current state diff --git a/x/evm/keeper/statedb_test.go b/x/evm/keeper/statedb_test.go index 71ff176e5..8ab7f0f46 100644 --- a/x/evm/keeper/statedb_test.go +++ b/x/evm/keeper/statedb_test.go @@ -4,7 +4,7 @@ import ( "github.com/ethereum/go-ethereum/common" ethermint "github.com/evmos/ethermint/types" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func (suite *KeeperTestSuite) TestKeeper_SetAccount() { diff --git a/x/evm/module.go b/x/evm/module.go index 5965f3310..afc2b4856 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -14,10 +14,10 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/client/cli" - "github.com/functionx/fx-core/v4/x/evm/keeper" - fxevmtypes "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/client/cli" + "github.com/functionx/fx-core/v5/x/evm/keeper" + fxevmtypes "github.com/functionx/fx-core/v5/x/evm/types" ) var ( diff --git a/x/evm/precompiles/crosschain/bridge_coin_amount.go b/x/evm/precompiles/crosschain/bridge_coin_amount.go index b8829d822..6442174d5 100644 --- a/x/evm/precompiles/crosschain/bridge_coin_amount.go +++ b/x/evm/precompiles/crosschain/bridge_coin_amount.go @@ -6,9 +6,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/core/vm" - fxtypes "github.com/functionx/fx-core/v4/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) func (c *Contract) BridgeCoinAmount(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, _ bool) ([]byte, error) { diff --git a/x/evm/precompiles/crosschain/bridge_coin_amount_test.go b/x/evm/precompiles/crosschain/bridge_coin_amount_test.go index 1d097fc36..9c9a1d660 100644 --- a/x/evm/precompiles/crosschain/bridge_coin_amount_test.go +++ b/x/evm/precompiles/crosschain/bridge_coin_amount_test.go @@ -12,10 +12,10 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/crosschain" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/crosschain" ) func TestBridgeCoinAmountABI(t *testing.T) { diff --git a/x/evm/precompiles/crosschain/call_evm.go b/x/evm/precompiles/crosschain/call_evm.go index 1f7a6f707..882689d4d 100644 --- a/x/evm/precompiles/crosschain/call_evm.go +++ b/x/evm/precompiles/crosschain/call_evm.go @@ -9,8 +9,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" - fxserverconfig "github.com/functionx/fx-core/v4/server/config" - fxtypes "github.com/functionx/fx-core/v4/types" + fxserverconfig "github.com/functionx/fx-core/v5/server/config" + fxtypes "github.com/functionx/fx-core/v5/types" ) type CallerRef struct { diff --git a/x/evm/precompiles/crosschain/cancel_sendtoexternal.go b/x/evm/precompiles/crosschain/cancel_sendtoexternal.go index 1d52d925e..4664ef8a0 100644 --- a/x/evm/precompiles/crosschain/cancel_sendtoexternal.go +++ b/x/evm/precompiles/crosschain/cancel_sendtoexternal.go @@ -8,7 +8,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) func (c *Contract) CancelSendToExternal(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) { diff --git a/x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go b/x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go index 44dc58ae5..76edc8a39 100644 --- a/x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go +++ b/x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go @@ -15,13 +15,13 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/crosschain" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/crosschain" ) func TestCancelSendToExternalABI(t *testing.T) { diff --git a/x/evm/precompiles/crosschain/contract.go b/x/evm/precompiles/crosschain/contract.go index f5903733d..c4ef23115 100644 --- a/x/evm/precompiles/crosschain/contract.go +++ b/x/evm/precompiles/crosschain/contract.go @@ -9,8 +9,8 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) type Contract struct { diff --git a/x/evm/precompiles/crosschain/contract_test.go b/x/evm/precompiles/crosschain/contract_test.go index 5eea91370..55eb5f1de 100644 --- a/x/evm/precompiles/crosschain/contract_test.go +++ b/x/evm/precompiles/crosschain/contract_test.go @@ -38,13 +38,13 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - fxserverconfig "github.com/functionx/fx-core/v4/server/config" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + "github.com/functionx/fx-core/v5/app" + fxserverconfig "github.com/functionx/fx-core/v5/server/config" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) type PrecompileTestSuite struct { diff --git a/x/evm/precompiles/crosschain/crosschain.go b/x/evm/precompiles/crosschain/crosschain.go index b209ff37d..45f19564c 100644 --- a/x/evm/precompiles/crosschain/crosschain.go +++ b/x/evm/precompiles/crosschain/crosschain.go @@ -16,9 +16,9 @@ import ( "github.com/ethereum/go-ethereum/core/vm" evmtypes "github.com/evmos/ethermint/x/evm/types" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) // FIP20CrossChain only for fip20 contract transferCrossChain called diff --git a/x/evm/precompiles/crosschain/crosschain_test.go b/x/evm/precompiles/crosschain/crosschain_test.go index 5f8bfff13..cc73721fb 100644 --- a/x/evm/precompiles/crosschain/crosschain_test.go +++ b/x/evm/precompiles/crosschain/crosschain_test.go @@ -17,14 +17,14 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - testcontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/crosschain" + testcontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/crosschain" ) func TestCrossChainABI(t *testing.T) { diff --git a/x/evm/precompiles/crosschain/events.go b/x/evm/precompiles/crosschain/events.go index df3398c1c..ef2a9136e 100644 --- a/x/evm/precompiles/crosschain/events.go +++ b/x/evm/precompiles/crosschain/events.go @@ -3,7 +3,7 @@ package crosschain import ( "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) var ( diff --git a/x/evm/precompiles/crosschain/fip20crosschain_test.go b/x/evm/precompiles/crosschain/fip20crosschain_test.go index b7065991b..75fd5e690 100644 --- a/x/evm/precompiles/crosschain/fip20crosschain_test.go +++ b/x/evm/precompiles/crosschain/fip20crosschain_test.go @@ -17,13 +17,13 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/crosschain" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/crosschain" ) func TestFIP20CrossChainABI(t *testing.T) { diff --git a/x/evm/precompiles/crosschain/increase_bridgefee.go b/x/evm/precompiles/crosschain/increase_bridgefee.go index 81e98f15a..8e98b328e 100644 --- a/x/evm/precompiles/crosschain/increase_bridgefee.go +++ b/x/evm/precompiles/crosschain/increase_bridgefee.go @@ -10,8 +10,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) // IncreaseBridgeFee add bridge fee to unbatched tx diff --git a/x/evm/precompiles/crosschain/increase_bridgefee_test.go b/x/evm/precompiles/crosschain/increase_bridgefee_test.go index 7bc6bc56c..0aaee30cb 100644 --- a/x/evm/precompiles/crosschain/increase_bridgefee_test.go +++ b/x/evm/precompiles/crosschain/increase_bridgefee_test.go @@ -14,13 +14,13 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/crosschain" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/crosschain" ) func TestIncreaseBridgeFeeABI(t *testing.T) { diff --git a/x/evm/precompiles/crosschain/interfaces.go b/x/evm/precompiles/crosschain/interfaces.go index 3a9a2c666..383043445 100644 --- a/x/evm/precompiles/crosschain/interfaces.go +++ b/x/evm/precompiles/crosschain/interfaces.go @@ -12,8 +12,8 @@ import ( evmtypes "github.com/evmos/ethermint/x/evm/types" tmbytes "github.com/tendermint/tendermint/libs/bytes" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/erc20/types" ) type Erc20Keeper interface { diff --git a/x/evm/precompiles/crosschain/keys.go b/x/evm/precompiles/crosschain/keys.go index c8d774e48..448bfbcdb 100644 --- a/x/evm/precompiles/crosschain/keys.go +++ b/x/evm/precompiles/crosschain/keys.go @@ -4,8 +4,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/contract" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/contract" + fxtypes "github.com/functionx/fx-core/v5/types" ) const ( diff --git a/x/evm/precompiles/crosschain/methods.go b/x/evm/precompiles/crosschain/methods.go index f12ec9551..2df5be7cb 100644 --- a/x/evm/precompiles/crosschain/methods.go +++ b/x/evm/precompiles/crosschain/methods.go @@ -7,8 +7,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/evm/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) // BridgeCoinAmountMethod query the amount of bridge coin diff --git a/x/evm/precompiles/staking/allowance_shares.go b/x/evm/precompiles/staking/allowance_shares.go index 230d9c0b6..0d7f47a01 100644 --- a/x/evm/precompiles/staking/allowance_shares.go +++ b/x/evm/precompiles/staking/allowance_shares.go @@ -4,7 +4,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/core/vm" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) func (c *Contract) AllowanceShares(ctx sdk.Context, _ *vm.EVM, contract *vm.Contract, _ bool) ([]byte, error) { diff --git a/x/evm/precompiles/staking/allowance_shares_test.go b/x/evm/precompiles/staking/allowance_shares_test.go index fd514cd2e..d26916485 100644 --- a/x/evm/precompiles/staking/allowance_shares_test.go +++ b/x/evm/precompiles/staking/allowance_shares_test.go @@ -15,10 +15,10 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) func TestStakingAllowanceSharesABI(t *testing.T) { diff --git a/x/evm/precompiles/staking/approve_shares.go b/x/evm/precompiles/staking/approve_shares.go index ac94b1d70..cd3b2e544 100644 --- a/x/evm/precompiles/staking/approve_shares.go +++ b/x/evm/precompiles/staking/approve_shares.go @@ -12,8 +12,8 @@ import ( "github.com/ethereum/go-ethereum/core/vm" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/x/evm/types" - fxstakingtypes "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/x/evm/types" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) func (c *Contract) ApproveShares(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) { diff --git a/x/evm/precompiles/staking/approve_shares_test.go b/x/evm/precompiles/staking/approve_shares_test.go index 2c410d02b..04a8ec461 100644 --- a/x/evm/precompiles/staking/approve_shares_test.go +++ b/x/evm/precompiles/staking/approve_shares_test.go @@ -16,11 +16,11 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" - fxstakingtypes "github.com/functionx/fx-core/v4/x/staking/types" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) func TestStakingApproveSharesABI(t *testing.T) { diff --git a/x/evm/precompiles/staking/contract.go b/x/evm/precompiles/staking/contract.go index 502f5c7d0..f1a87b2f8 100644 --- a/x/evm/precompiles/staking/contract.go +++ b/x/evm/precompiles/staking/contract.go @@ -9,7 +9,7 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) type Contract struct { diff --git a/x/evm/precompiles/staking/contract_test.go b/x/evm/precompiles/staking/contract_test.go index 697dabd16..658df40e9 100644 --- a/x/evm/precompiles/staking/contract_test.go +++ b/x/evm/precompiles/staking/contract_test.go @@ -25,11 +25,11 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + "github.com/functionx/fx-core/v5/app" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) const ( diff --git a/x/evm/precompiles/staking/delegate.go b/x/evm/precompiles/staking/delegate.go index a0adf0e1d..d01b4c6bb 100644 --- a/x/evm/precompiles/staking/delegate.go +++ b/x/evm/precompiles/staking/delegate.go @@ -14,8 +14,8 @@ import ( "github.com/ethereum/go-ethereum/core/vm" evmtypes "github.com/evmos/ethermint/x/evm/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) func (c *Contract) Delegate(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) { diff --git a/x/evm/precompiles/staking/delegate_test.go b/x/evm/precompiles/staking/delegate_test.go index 54e728e41..e0f3346bc 100644 --- a/x/evm/precompiles/staking/delegate_test.go +++ b/x/evm/precompiles/staking/delegate_test.go @@ -17,10 +17,10 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) func TestStakingDelegateABI(t *testing.T) { diff --git a/x/evm/precompiles/staking/delegation.go b/x/evm/precompiles/staking/delegation.go index 9c592ba6c..881bdd024 100644 --- a/x/evm/precompiles/staking/delegation.go +++ b/x/evm/precompiles/staking/delegation.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/core/vm" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) func (c *Contract) Delegation(ctx sdk.Context, _ *vm.EVM, contract *vm.Contract, _ bool) ([]byte, error) { diff --git a/x/evm/precompiles/staking/delegation_rewards.go b/x/evm/precompiles/staking/delegation_rewards.go index a32d868dd..2829f41e7 100644 --- a/x/evm/precompiles/staking/delegation_rewards.go +++ b/x/evm/precompiles/staking/delegation_rewards.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/core/vm" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) func (c *Contract) DelegationRewards(ctx sdk.Context, _ *vm.EVM, contract *vm.Contract, _ bool) ([]byte, error) { diff --git a/x/evm/precompiles/staking/delegation_rewards_test.go b/x/evm/precompiles/staking/delegation_rewards_test.go index d9b3f8c63..9ec8bb364 100644 --- a/x/evm/precompiles/staking/delegation_rewards_test.go +++ b/x/evm/precompiles/staking/delegation_rewards_test.go @@ -15,10 +15,10 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) func TestStakingDelegationRewardsABI(t *testing.T) { diff --git a/x/evm/precompiles/staking/delegation_test.go b/x/evm/precompiles/staking/delegation_test.go index 8d831a33a..2d7f5c770 100644 --- a/x/evm/precompiles/staking/delegation_test.go +++ b/x/evm/precompiles/staking/delegation_test.go @@ -13,10 +13,10 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) func TestStakingDelegationABI(t *testing.T) { diff --git a/x/evm/precompiles/staking/events.go b/x/evm/precompiles/staking/events.go index 5e379ee52..5b82c0f21 100644 --- a/x/evm/precompiles/staking/events.go +++ b/x/evm/precompiles/staking/events.go @@ -3,7 +3,7 @@ package staking import ( "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) var ( diff --git a/x/evm/precompiles/staking/keys.go b/x/evm/precompiles/staking/keys.go index a409a77cf..665718f2e 100644 --- a/x/evm/precompiles/staking/keys.go +++ b/x/evm/precompiles/staking/keys.go @@ -4,8 +4,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/contract" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/contract" + fxtypes "github.com/functionx/fx-core/v5/types" ) const ( diff --git a/x/evm/precompiles/staking/methods.go b/x/evm/precompiles/staking/methods.go index 6daeb2d70..548daf9fc 100644 --- a/x/evm/precompiles/staking/methods.go +++ b/x/evm/precompiles/staking/methods.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) var ( diff --git a/x/evm/precompiles/staking/transfer_shares.go b/x/evm/precompiles/staking/transfer_shares.go index c5df7f590..d97e47e40 100644 --- a/x/evm/precompiles/staking/transfer_shares.go +++ b/x/evm/precompiles/staking/transfer_shares.go @@ -15,8 +15,8 @@ import ( "github.com/ethereum/go-ethereum/core/vm" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/x/evm/types" - fxstakingtypes "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/x/evm/types" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) func (c *Contract) TransferShares(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) { diff --git a/x/evm/precompiles/staking/transfer_shares_test.go b/x/evm/precompiles/staking/transfer_shares_test.go index 7edb172f8..a288a04d2 100644 --- a/x/evm/precompiles/staking/transfer_shares_test.go +++ b/x/evm/precompiles/staking/transfer_shares_test.go @@ -14,10 +14,10 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" - fxstakingtypes "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) func TestStakingTransferSharesABI(t *testing.T) { diff --git a/x/evm/precompiles/staking/undelegate.go b/x/evm/precompiles/staking/undelegate.go index 20ca28f68..9ac1eaec7 100644 --- a/x/evm/precompiles/staking/undelegate.go +++ b/x/evm/precompiles/staking/undelegate.go @@ -15,8 +15,8 @@ import ( "github.com/ethereum/go-ethereum/core/vm" evmtypes "github.com/evmos/ethermint/x/evm/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) func (c *Contract) Undelegate(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) { diff --git a/x/evm/precompiles/staking/undelegate_test.go b/x/evm/precompiles/staking/undelegate_test.go index 763ca8b72..2e3010c0a 100644 --- a/x/evm/precompiles/staking/undelegate_test.go +++ b/x/evm/precompiles/staking/undelegate_test.go @@ -17,10 +17,10 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) func TestStakingUndelegateABI(t *testing.T) { diff --git a/x/evm/precompiles/staking/withdraw.go b/x/evm/precompiles/staking/withdraw.go index 9f4c12a58..9bf5bb507 100644 --- a/x/evm/precompiles/staking/withdraw.go +++ b/x/evm/precompiles/staking/withdraw.go @@ -11,7 +11,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/functionx/fx-core/v4/x/evm/types" + "github.com/functionx/fx-core/v5/x/evm/types" ) func (c *Contract) Withdraw(ctx sdk.Context, evm *vm.EVM, contract *vm.Contract, readonly bool) ([]byte, error) { diff --git a/x/evm/precompiles/staking/withdraw_test.go b/x/evm/precompiles/staking/withdraw_test.go index a4a2c92a6..95d14dbc0 100644 --- a/x/evm/precompiles/staking/withdraw_test.go +++ b/x/evm/precompiles/staking/withdraw_test.go @@ -16,10 +16,10 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - testscontract "github.com/functionx/fx-core/v4/tests/contract" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/evm/precompiles/staking" + testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) func TestStakingWithdrawABI(t *testing.T) { diff --git a/x/evm/types/codec.go b/x/evm/types/codec.go index 99ec6afef..86a973f12 100644 --- a/x/evm/types/codec.go +++ b/x/evm/types/codec.go @@ -8,7 +8,7 @@ import ( authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" govv1betal "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/functionx/fx-core/v4/x/evm/legacy" + "github.com/functionx/fx-core/v5/x/evm/legacy" ) // ModuleCdc is the codec for the module diff --git a/x/evm/types/msg.go b/x/evm/types/msg.go index f18eb8fd9..11bbdf4fd 100644 --- a/x/evm/types/msg.go +++ b/x/evm/types/msg.go @@ -6,7 +6,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) var _ sdk.Msg = &MsgCallContract{} diff --git a/x/gov/client/cli/query.go b/x/gov/client/cli/query.go index 39d8d40c9..60d1be232 100644 --- a/x/gov/client/cli/query.go +++ b/x/gov/client/cli/query.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/spf13/cobra" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" ) // GetQueryCmd returns the cli query commands for this module diff --git a/x/gov/client/cli/query_test.go b/x/gov/client/cli/query_test.go index e964199c3..a3fc85abe 100644 --- a/x/gov/client/cli/query_test.go +++ b/x/gov/client/cli/query_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" - "github.com/functionx/fx-core/v4/x/gov/client/cli" + "github.com/functionx/fx-core/v5/x/gov/client/cli" ) func TestCmdParams(t *testing.T) { diff --git a/x/gov/keeper/abci.go b/x/gov/keeper/abci.go index a18da19e7..6171022ea 100644 --- a/x/gov/keeper/abci.go +++ b/x/gov/keeper/abci.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" ) // EndBlocker called every block, process inflation, update validator set. diff --git a/x/gov/keeper/grpc_query.go b/x/gov/keeper/grpc_query.go index 8b9f6156c..ccb7fdf1d 100644 --- a/x/gov/keeper/grpc_query.go +++ b/x/gov/keeper/grpc_query.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/gov/types" + "github.com/functionx/fx-core/v5/x/gov/types" ) var _ types.QueryServer = Keeper{} diff --git a/x/gov/keeper/grpc_query_test.go b/x/gov/keeper/grpc_query_test.go index 3c5824b06..efd1db18a 100644 --- a/x/gov/keeper/grpc_query_test.go +++ b/x/gov/keeper/grpc_query_test.go @@ -4,9 +4,9 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - govtypes "github.com/functionx/fx-core/v4/x/gov/types" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + govtypes "github.com/functionx/fx-core/v5/x/gov/types" ) func (suite *KeeperTestSuite) TestGRPCQueryParams() { diff --git a/x/gov/keeper/keeper.go b/x/gov/keeper/keeper.go index eb158054e..99062e016 100644 --- a/x/gov/keeper/keeper.go +++ b/x/gov/keeper/keeper.go @@ -11,8 +11,8 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/gov/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/gov/types" ) type Keeper struct { diff --git a/x/gov/keeper/keeper_test.go b/x/gov/keeper/keeper_test.go index 25b232d2f..9c9754922 100644 --- a/x/gov/keeper/keeper_test.go +++ b/x/gov/keeper/keeper_test.go @@ -19,14 +19,14 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - evmtypes "github.com/functionx/fx-core/v4/x/evm/types" - "github.com/functionx/fx-core/v4/x/gov/keeper" - "github.com/functionx/fx-core/v4/x/gov/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + evmtypes "github.com/functionx/fx-core/v5/x/evm/types" + "github.com/functionx/fx-core/v5/x/gov/keeper" + "github.com/functionx/fx-core/v5/x/gov/types" ) type KeeperTestSuite struct { diff --git a/x/gov/keeper/migrations.go b/x/gov/keeper/migrations.go index 1f9cd8d3f..d3becae79 100644 --- a/x/gov/keeper/migrations.go +++ b/x/gov/keeper/migrations.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" - fxv046 "github.com/functionx/fx-core/v4/x/gov/migrations/v046" + fxv046 "github.com/functionx/fx-core/v5/x/gov/migrations/v046" ) // Migrator is a struct for handling in-place store migrations. diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index ea33a2418..e9cc4d2b7 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -16,7 +16,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/functionx/fx-core/v4/x/gov/types" + "github.com/functionx/fx-core/v5/x/gov/types" ) type msgServer struct { diff --git a/x/gov/keeper/msg_server_test.go b/x/gov/keeper/msg_server_test.go index 16c95fa4e..29118ce1a 100644 --- a/x/gov/keeper/msg_server_test.go +++ b/x/gov/keeper/msg_server_test.go @@ -16,10 +16,10 @@ import ( govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - "github.com/functionx/fx-core/v4/x/gov/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + "github.com/functionx/fx-core/v5/x/gov/types" ) func (suite *KeeperTestSuite) TestSubmitProposal() { diff --git a/x/gov/keeper/params.go b/x/gov/keeper/params.go index 9fbf252c4..1458356fe 100644 --- a/x/gov/keeper/params.go +++ b/x/gov/keeper/params.go @@ -5,8 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/gov/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/gov/types" ) // GetParams gets the gov module's parameters. diff --git a/x/gov/keeper/params_test.go b/x/gov/keeper/params_test.go index 80878601a..85eb62498 100644 --- a/x/gov/keeper/params_test.go +++ b/x/gov/keeper/params_test.go @@ -7,9 +7,9 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - "github.com/functionx/fx-core/v4/x/gov/types" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + "github.com/functionx/fx-core/v5/x/gov/types" ) func (suite *KeeperTestSuite) TestParams() { diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 1d2faa552..17f17f6d8 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" ) // SubmitProposal creates a new proposal given an array of messages diff --git a/x/gov/keeper/tally.go b/x/gov/keeper/tally.go index 858122d8f..0519f9dc1 100644 --- a/x/gov/keeper/tally.go +++ b/x/gov/keeper/tally.go @@ -6,7 +6,7 @@ import ( govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" ) // Tally iterates over the votes and updates the tally of a proposal based on the voting power of the diff --git a/x/gov/keeper/tally_test.go b/x/gov/keeper/tally_test.go index 68a3cabcf..25dd95b55 100644 --- a/x/gov/keeper/tally_test.go +++ b/x/gov/keeper/tally_test.go @@ -6,9 +6,9 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" ) func (suite *KeeperTestSuite) TestKeeper_Tally() { diff --git a/x/gov/migrations/v046/convert.go b/x/gov/migrations/v046/convert.go index 4193f9157..9fafdf9fe 100644 --- a/x/gov/migrations/v046/convert.go +++ b/x/gov/migrations/v046/convert.go @@ -11,7 +11,7 @@ import ( v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" ) func convertToNewProposal(oldProp v1beta1.Proposal) (v1.Proposal, error) { diff --git a/x/gov/migrations/v046/store_test.go b/x/gov/migrations/v046/store_test.go index 976c7fb0b..5f9ddaf54 100644 --- a/x/gov/migrations/v046/store_test.go +++ b/x/gov/migrations/v046/store_test.go @@ -13,8 +13,8 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/stretchr/testify/require" - fxv046 "github.com/functionx/fx-core/v4/x/gov/migrations/v046" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" + fxv046 "github.com/functionx/fx-core/v5/x/gov/migrations/v046" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" ) var voter = sdk.MustAccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh") diff --git a/x/gov/module.go b/x/gov/module.go index 8cbdb0663..90f35ddcc 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -20,9 +20,9 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/gov/client/cli" - "github.com/functionx/fx-core/v4/x/gov/keeper" - "github.com/functionx/fx-core/v4/x/gov/types" + "github.com/functionx/fx-core/v5/x/gov/client/cli" + "github.com/functionx/fx-core/v5/x/gov/keeper" + "github.com/functionx/fx-core/v5/x/gov/types" ) var ( diff --git a/x/gov/types/msgs_test.go b/x/gov/types/msgs_test.go index da7d1363c..653d004f7 100644 --- a/x/gov/types/msgs_test.go +++ b/x/gov/types/msgs_test.go @@ -9,8 +9,8 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/stretchr/testify/require" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/gov/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/gov/types" ) var ( diff --git a/x/gov/types/params.go b/x/gov/types/params.go index be188683a..bb32f4083 100644 --- a/x/gov/types/params.go +++ b/x/gov/types/params.go @@ -12,9 +12,9 @@ import ( govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/gogo/protobuf/proto" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - evmtypes "github.com/functionx/fx-core/v4/x/evm/types" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + evmtypes "github.com/functionx/fx-core/v5/x/evm/types" ) var ( diff --git a/x/gravity/keeper/grpc_query.go b/x/gravity/keeper/grpc_query.go index 992008eae..3469f52dc 100644 --- a/x/gravity/keeper/grpc_query.go +++ b/x/gravity/keeper/grpc_query.go @@ -4,11 +4,11 @@ package keeper import ( "context" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - "github.com/functionx/fx-core/v4/x/gravity/types" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + "github.com/functionx/fx-core/v5/x/gravity/types" ) type queryServer struct { diff --git a/x/gravity/keeper/msg_server.go b/x/gravity/keeper/msg_server.go index 9815147ed..6da551969 100644 --- a/x/gravity/keeper/msg_server.go +++ b/x/gravity/keeper/msg_server.go @@ -4,10 +4,10 @@ package keeper import ( "context" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - "github.com/functionx/fx-core/v4/x/gravity/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + "github.com/functionx/fx-core/v5/x/gravity/types" ) type msgServer struct { diff --git a/x/gravity/service.go b/x/gravity/service.go index 8945c485d..de4a61f85 100644 --- a/x/gravity/service.go +++ b/x/gravity/service.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/functionx/fx-core/v4/x/gravity/types" + "github.com/functionx/fx-core/v5/x/gravity/types" ) // RegisterGRPCGatewayRoutes diff --git a/x/gravity/types/msgs.go b/x/gravity/types/msgs.go index c3b0d4c31..7650390ad 100644 --- a/x/gravity/types/msgs.go +++ b/x/gravity/types/msgs.go @@ -9,7 +9,7 @@ import ( errortypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/tendermint/tendermint/crypto/tmhash" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) const ( diff --git a/x/ibc/applications/transfer/client/cli/tx.go b/x/ibc/applications/transfer/client/cli/tx.go index f44d37d4a..91577d884 100644 --- a/x/ibc/applications/transfer/client/cli/tx.go +++ b/x/ibc/applications/transfer/client/cli/tx.go @@ -17,7 +17,7 @@ import ( channelutils "github.com/cosmos/ibc-go/v6/modules/core/04-channel/client/utils" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) const ( diff --git a/x/ibc/applications/transfer/ibc_middleware.go b/x/ibc/applications/transfer/ibc_middleware.go index 5cf9b0032..f51806a7d 100644 --- a/x/ibc/applications/transfer/ibc_middleware.go +++ b/x/ibc/applications/transfer/ibc_middleware.go @@ -14,9 +14,9 @@ import ( porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types" "github.com/cosmos/ibc-go/v6/modules/core/exported" - "github.com/functionx/fx-core/v4/x/ibc" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/keeper" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + "github.com/functionx/fx-core/v5/x/ibc" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/keeper" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) var _ porttypes.Middleware = &IBCMiddleware{} diff --git a/x/ibc/applications/transfer/ibc_middleware_test.go b/x/ibc/applications/transfer/ibc_middleware_test.go index 0d321e496..1713a227d 100644 --- a/x/ibc/applications/transfer/ibc_middleware_test.go +++ b/x/ibc/applications/transfer/ibc_middleware_test.go @@ -6,8 +6,8 @@ import ( transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" "github.com/stretchr/testify/require" - _ "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + _ "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) func TestUnmarshalJSON(t *testing.T) { diff --git a/x/ibc/applications/transfer/keeper/keeper.go b/x/ibc/applications/transfer/keeper/keeper.go index 3cad66481..97987b601 100644 --- a/x/ibc/applications/transfer/keeper/keeper.go +++ b/x/ibc/applications/transfer/keeper/keeper.go @@ -12,8 +12,8 @@ import ( host "github.com/cosmos/ibc-go/v6/modules/core/24-host" "github.com/tendermint/tendermint/libs/log" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) // Keeper defines the IBC fungible transfer keeper diff --git a/x/ibc/applications/transfer/keeper/keeper_test.go b/x/ibc/applications/transfer/keeper/keeper_test.go index 358bfd39f..8caf183aa 100644 --- a/x/ibc/applications/transfer/keeper/keeper_test.go +++ b/x/ibc/applications/transfer/keeper/keeper_test.go @@ -8,9 +8,9 @@ import ( ibctesting "github.com/cosmos/ibc-go/v6/testing" "github.com/stretchr/testify/suite" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" - fxibctesting "github.com/functionx/fx-core/v4/x/ibc/testing" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" + fxibctesting "github.com/functionx/fx-core/v5/x/ibc/testing" ) type KeeperTestSuite struct { diff --git a/x/ibc/applications/transfer/keeper/msg_server.go b/x/ibc/applications/transfer/keeper/msg_server.go index ba6d1bf78..594920434 100644 --- a/x/ibc/applications/transfer/keeper/msg_server.go +++ b/x/ibc/applications/transfer/keeper/msg_server.go @@ -8,7 +8,7 @@ import ( errortypes "github.com/cosmos/cosmos-sdk/types/errors" transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) var ( diff --git a/x/ibc/applications/transfer/keeper/msg_server_test.go b/x/ibc/applications/transfer/keeper/msg_server_test.go index 4c4d2a046..0f32e22a0 100644 --- a/x/ibc/applications/transfer/keeper/msg_server_test.go +++ b/x/ibc/applications/transfer/keeper/msg_server_test.go @@ -5,8 +5,8 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" - fxtypes "github.com/functionx/fx-core/v4/types" - ibctesting "github.com/functionx/fx-core/v4/x/ibc/testing" + fxtypes "github.com/functionx/fx-core/v5/types" + ibctesting "github.com/functionx/fx-core/v5/x/ibc/testing" ) func (suite *KeeperTestSuite) TestMsgTransfer() { diff --git a/x/ibc/applications/transfer/keeper/parse.go b/x/ibc/applications/transfer/keeper/parse.go index 0fad04763..9bfa83b03 100644 --- a/x/ibc/applications/transfer/keeper/parse.go +++ b/x/ibc/applications/transfer/keeper/parse.go @@ -9,8 +9,8 @@ import ( channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) func parseIBCCoinDenom(packet channeltypes.Packet, packetDenom string) string { diff --git a/x/ibc/applications/transfer/keeper/parse_test.go b/x/ibc/applications/transfer/keeper/parse_test.go index 8cfe762c7..fef59e6ee 100644 --- a/x/ibc/applications/transfer/keeper/parse_test.go +++ b/x/ibc/applications/transfer/keeper/parse_test.go @@ -10,8 +10,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - _ "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + _ "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) func TestParseReceiveAndAmountByPacket(t *testing.T) { diff --git a/x/ibc/applications/transfer/keeper/relay.go b/x/ibc/applications/transfer/keeper/relay.go index c59befa49..0d9c0ca8a 100644 --- a/x/ibc/applications/transfer/keeper/relay.go +++ b/x/ibc/applications/transfer/keeper/relay.go @@ -16,9 +16,9 @@ import ( coretypes "github.com/cosmos/ibc-go/v6/modules/core/types" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) // make SendTransfer private diff --git a/x/ibc/applications/transfer/keeper/relay_test.go b/x/ibc/applications/transfer/keeper/relay_test.go index 47d414935..ed578374a 100644 --- a/x/ibc/applications/transfer/keeper/relay_test.go +++ b/x/ibc/applications/transfer/keeper/relay_test.go @@ -18,17 +18,17 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - avalanchetypes "github.com/functionx/fx-core/v4/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - fxtransfer "github.com/functionx/fx-core/v4/x/ibc/applications/transfer" - fxtransfertypes "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" - fxibctesting "github.com/functionx/fx-core/v4/x/ibc/testing" - polygontypes "github.com/functionx/fx-core/v4/x/polygon/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + fxtransfer "github.com/functionx/fx-core/v5/x/ibc/applications/transfer" + fxtransfertypes "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" + fxibctesting "github.com/functionx/fx-core/v5/x/ibc/testing" + polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func (suite *KeeperTestSuite) TestSendTransfer() { diff --git a/x/ibc/applications/transfer/module.go b/x/ibc/applications/transfer/module.go index 4f53ce775..2181b8053 100644 --- a/x/ibc/applications/transfer/module.go +++ b/x/ibc/applications/transfer/module.go @@ -15,9 +15,9 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/client/cli" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/keeper" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/client/cli" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/keeper" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" ) // type check to ensure the interface is properly implemented diff --git a/x/ibc/applications/transfer/transfer_test.go b/x/ibc/applications/transfer/transfer_test.go index 4a6eab32e..d396a8fe6 100644 --- a/x/ibc/applications/transfer/transfer_test.go +++ b/x/ibc/applications/transfer/transfer_test.go @@ -10,9 +10,9 @@ import ( ibctesting "github.com/cosmos/ibc-go/v6/testing" "github.com/stretchr/testify/suite" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" - fxibctesting "github.com/functionx/fx-core/v4/x/ibc/testing" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" + fxibctesting "github.com/functionx/fx-core/v5/x/ibc/testing" ) var defaultMsgRouter = "" diff --git a/x/ibc/applications/transfer/types/expected_keepers.go b/x/ibc/applications/transfer/types/expected_keepers.go index b89be0b21..b91611eee 100644 --- a/x/ibc/applications/transfer/types/expected_keepers.go +++ b/x/ibc/applications/transfer/types/expected_keepers.go @@ -5,8 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" ) type RefundHook interface { diff --git a/x/ibc/applications/transfer/types/msgs_test.go b/x/ibc/applications/transfer/types/msgs_test.go index 63df46e72..ed2f2a868 100644 --- a/x/ibc/applications/transfer/types/msgs_test.go +++ b/x/ibc/applications/transfer/types/msgs_test.go @@ -10,7 +10,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" "github.com/stretchr/testify/require" - _ "github.com/functionx/fx-core/v4/types" + _ "github.com/functionx/fx-core/v5/types" ) // define constants used for testing diff --git a/x/ibc/ibcrouter/ibc_middleware.go b/x/ibc/ibcrouter/ibc_middleware.go index ba156977f..f06abf09d 100644 --- a/x/ibc/ibcrouter/ibc_middleware.go +++ b/x/ibc/ibcrouter/ibc_middleware.go @@ -18,9 +18,9 @@ import ( "github.com/cosmos/ibc-go/v6/modules/core/exported" "github.com/tendermint/tendermint/libs/log" - fxtransfertypes "github.com/functionx/fx-core/v4/x/ibc/applications/transfer/types" - "github.com/functionx/fx-core/v4/x/ibc/ibcrouter/parser" - "github.com/functionx/fx-core/v4/x/ibc/ibcrouter/types" + fxtransfertypes "github.com/functionx/fx-core/v5/x/ibc/applications/transfer/types" + "github.com/functionx/fx-core/v5/x/ibc/ibcrouter/parser" + "github.com/functionx/fx-core/v5/x/ibc/ibcrouter/types" ) const ( diff --git a/x/ibc/ibcrouter/ibc_middleware_test.go b/x/ibc/ibcrouter/ibc_middleware_test.go index ecea89ed0..f4665006c 100644 --- a/x/ibc/ibcrouter/ibc_middleware_test.go +++ b/x/ibc/ibcrouter/ibc_middleware_test.go @@ -9,9 +9,9 @@ import ( "github.com/stretchr/testify/require" tmrand "github.com/tendermint/tendermint/libs/rand" - _ "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/x/ibc/ibcrouter" - "github.com/functionx/fx-core/v4/x/ibc/ibcrouter/parser" + _ "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/x/ibc/ibcrouter" + "github.com/functionx/fx-core/v5/x/ibc/ibcrouter/parser" ) func TestParseIncomingTransferField(t *testing.T) { diff --git a/x/ibc/ibcrouter/parser/receiver_parser_test.go b/x/ibc/ibcrouter/parser/receiver_parser_test.go index eb6ee5879..48375762a 100644 --- a/x/ibc/ibcrouter/parser/receiver_parser_test.go +++ b/x/ibc/ibcrouter/parser/receiver_parser_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/x/ibc/ibcrouter/parser" + "github.com/functionx/fx-core/v5/x/ibc/ibcrouter/parser" ) func TestParseReceiverDataTransfer(t *testing.T) { diff --git a/x/ibc/testing/app.go b/x/ibc/testing/app.go index f1ce7c13d..4587a3d54 100644 --- a/x/ibc/testing/app.go +++ b/x/ibc/testing/app.go @@ -18,9 +18,9 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/types" - fxstakingtypes "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/types" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) var DefaultTestingAppInit = helpers.SetupTestingApp diff --git a/x/ibc/testing/chain.go b/x/ibc/testing/chain.go index 55a2156d8..742bf07d6 100644 --- a/x/ibc/testing/chain.go +++ b/x/ibc/testing/chain.go @@ -14,7 +14,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) // ChainIDPrefix defines the default chain ID prefix for Evmos test chains diff --git a/x/migrate/client/cli/query.go b/x/migrate/client/cli/query.go index 114d58411..38d3fa0ca 100644 --- a/x/migrate/client/cli/query.go +++ b/x/migrate/client/cli/query.go @@ -14,7 +14,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) func GetQueryCmd() *cobra.Command { diff --git a/x/migrate/client/cli/tx.go b/x/migrate/client/cli/tx.go index 8d01e2b95..f26875f62 100644 --- a/x/migrate/client/cli/tx.go +++ b/x/migrate/client/cli/tx.go @@ -13,9 +13,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/spf13/cobra" - fxtypes "github.com/functionx/fx-core/v4/types" - erc20types "github.com/functionx/fx-core/v4/x/erc20/types" - "github.com/functionx/fx-core/v4/x/migrate/types" + fxtypes "github.com/functionx/fx-core/v5/types" + erc20types "github.com/functionx/fx-core/v5/x/erc20/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) func GetTxCmd() *cobra.Command { diff --git a/x/migrate/keeper/bank.go b/x/migrate/keeper/bank.go index 3ec13c6d6..5f552c39f 100644 --- a/x/migrate/keeper/bank.go +++ b/x/migrate/keeper/bank.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - migratetypes "github.com/functionx/fx-core/v4/x/migrate/types" + migratetypes "github.com/functionx/fx-core/v5/x/migrate/types" ) type BankMigrate struct { diff --git a/x/migrate/keeper/bank_test.go b/x/migrate/keeper/bank_test.go index 7bdcd005e..0842ce48d 100644 --- a/x/migrate/keeper/bank_test.go +++ b/x/migrate/keeper/bank_test.go @@ -6,8 +6,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/require" - ethtypes "github.com/functionx/fx-core/v4/x/eth/types" - migratekeeper "github.com/functionx/fx-core/v4/x/migrate/keeper" + ethtypes "github.com/functionx/fx-core/v5/x/eth/types" + migratekeeper "github.com/functionx/fx-core/v5/x/migrate/keeper" ) func (suite *KeeperTestSuite) TestMigrateBank() { diff --git a/x/migrate/keeper/distr_staking.go b/x/migrate/keeper/distr_staking.go index 3459ce990..b78b85d94 100644 --- a/x/migrate/keeper/distr_staking.go +++ b/x/migrate/keeper/distr_staking.go @@ -9,7 +9,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) type DistrStakingMigrate struct { diff --git a/x/migrate/keeper/distr_staking_test.go b/x/migrate/keeper/distr_staking_test.go index 56ea58f3e..e4e6fc75c 100644 --- a/x/migrate/keeper/distr_staking_test.go +++ b/x/migrate/keeper/distr_staking_test.go @@ -22,10 +22,10 @@ import ( abcitypes "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - fxtypes "github.com/functionx/fx-core/v4/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - migratekeeper "github.com/functionx/fx-core/v4/x/migrate/keeper" + "github.com/functionx/fx-core/v5/app" + fxtypes "github.com/functionx/fx-core/v5/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + migratekeeper "github.com/functionx/fx-core/v5/x/migrate/keeper" ) func (suite *KeeperTestSuite) TestMigrateStakingDelegate() { diff --git a/x/migrate/keeper/genesis.go b/x/migrate/keeper/genesis.go index 42f35bd86..7c5f84099 100644 --- a/x/migrate/keeper/genesis.go +++ b/x/migrate/keeper/genesis.go @@ -4,8 +4,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/migrate/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) // InitGenesis import module genesis diff --git a/x/migrate/keeper/gov.go b/x/migrate/keeper/gov.go index 788abeccb..d42be8a3d 100644 --- a/x/migrate/keeper/gov.go +++ b/x/migrate/keeper/gov.go @@ -11,7 +11,7 @@ import ( govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) type GovMigrate struct { diff --git a/x/migrate/keeper/gov_test.go b/x/migrate/keeper/gov_test.go index a5198385a..13c358722 100644 --- a/x/migrate/keeper/gov_test.go +++ b/x/migrate/keeper/gov_test.go @@ -8,10 +8,10 @@ import ( govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/ethereum/go-ethereum/common" - fxtypes "github.com/functionx/fx-core/v4/types" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" - migratekeeper "github.com/functionx/fx-core/v4/x/migrate/keeper" + fxtypes "github.com/functionx/fx-core/v5/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" + migratekeeper "github.com/functionx/fx-core/v5/x/migrate/keeper" ) func (suite *KeeperTestSuite) TestMigrateGovInactive() { diff --git a/x/migrate/keeper/grpc_query.go b/x/migrate/keeper/grpc_query.go index 25ebc3483..7878426e8 100644 --- a/x/migrate/keeper/grpc_query.go +++ b/x/migrate/keeper/grpc_query.go @@ -8,7 +8,7 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) var _ types.QueryServer = Keeper{} diff --git a/x/migrate/keeper/grpc_query_test.go b/x/migrate/keeper/grpc_query_test.go index 02e90df7c..2d235802a 100644 --- a/x/migrate/keeper/grpc_query_test.go +++ b/x/migrate/keeper/grpc_query_test.go @@ -12,9 +12,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/evmos/ethermint/crypto/ethsecp256k1" - fxtypes "github.com/functionx/fx-core/v4/types" - fxgovtypes "github.com/functionx/fx-core/v4/x/gov/types" - "github.com/functionx/fx-core/v4/x/migrate/types" + fxtypes "github.com/functionx/fx-core/v5/types" + fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) func (suite *KeeperTestSuite) TestMigrateRecord() { diff --git a/x/migrate/keeper/keeper.go b/x/migrate/keeper/keeper.go index 4a337b73b..2428ffefe 100644 --- a/x/migrate/keeper/keeper.go +++ b/x/migrate/keeper/keeper.go @@ -12,7 +12,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/tendermint/tendermint/libs/log" - "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) // secp256k1 diff --git a/x/migrate/keeper/keeper_test.go b/x/migrate/keeper/keeper_test.go index d3f89d2b9..14b593402 100644 --- a/x/migrate/keeper/keeper_test.go +++ b/x/migrate/keeper/keeper_test.go @@ -20,10 +20,10 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - migratetypes "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + migratetypes "github.com/functionx/fx-core/v5/x/migrate/types" ) type KeeperTestSuite struct { diff --git a/x/migrate/keeper/msg_server.go b/x/migrate/keeper/msg_server.go index 2fecf2195..1098c114b 100644 --- a/x/migrate/keeper/msg_server.go +++ b/x/migrate/keeper/msg_server.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) var _ types.MsgServer = &Keeper{} diff --git a/x/migrate/keeper/msg_server_test.go b/x/migrate/keeper/msg_server_test.go index c0da7a53d..47ab00837 100644 --- a/x/migrate/keeper/msg_server_test.go +++ b/x/migrate/keeper/msg_server_test.go @@ -5,8 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" - bsctypes "github.com/functionx/fx-core/v4/x/bsc/types" - "github.com/functionx/fx-core/v4/x/migrate/types" + bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" + "github.com/functionx/fx-core/v5/x/migrate/types" ) func (suite *KeeperTestSuite) TestMigrateAccount() { diff --git a/x/migrate/module.go b/x/migrate/module.go index ef9f15e66..1b5225b20 100644 --- a/x/migrate/module.go +++ b/x/migrate/module.go @@ -15,9 +15,9 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/migrate/client/cli" - "github.com/functionx/fx-core/v4/x/migrate/keeper" - "github.com/functionx/fx-core/v4/x/migrate/types" + "github.com/functionx/fx-core/v5/x/migrate/client/cli" + "github.com/functionx/fx-core/v5/x/migrate/keeper" + "github.com/functionx/fx-core/v5/x/migrate/types" ) // type check to ensure the interface is properly implemented diff --git a/x/migrate/types/msg.go b/x/migrate/types/msg.go index b71b5e3f6..f5499089a 100644 --- a/x/migrate/types/msg.go +++ b/x/migrate/types/msg.go @@ -9,7 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - fxtypes "github.com/functionx/fx-core/v4/types" + fxtypes "github.com/functionx/fx-core/v5/types" ) const TypeMsgMigrateAccount = "migrate_account" diff --git a/x/migrate/types/msg_test.go b/x/migrate/types/msg_test.go index c526f466f..8376d197c 100644 --- a/x/migrate/types/msg_test.go +++ b/x/migrate/types/msg_test.go @@ -10,8 +10,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/require" - _ "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/x/migrate/types" + _ "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/x/migrate/types" ) func TestMsgMigrateAccountRoute(t *testing.T) { diff --git a/x/optimism/client/cli/query.go b/x/optimism/client/cli/query.go index 119e4ad3c..d70dea6ed 100644 --- a/x/optimism/client/cli/query.go +++ b/x/optimism/client/cli/query.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - "github.com/functionx/fx-core/v4/x/optimism/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/optimism/types" ) func GetQueryCmd() *cobra.Command { diff --git a/x/optimism/client/cli/tx.go b/x/optimism/client/cli/tx.go index 1ddb8b2bc..9e56b07aa 100644 --- a/x/optimism/client/cli/tx.go +++ b/x/optimism/client/cli/tx.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - "github.com/functionx/fx-core/v4/x/optimism/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/optimism/types" ) func GetTxCmd() *cobra.Command { diff --git a/x/optimism/module.go b/x/optimism/module.go index 4cc632923..e690004e6 100644 --- a/x/optimism/module.go +++ b/x/optimism/module.go @@ -14,10 +14,10 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/optimism/client/cli" - "github.com/functionx/fx-core/v4/x/optimism/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/optimism/client/cli" + "github.com/functionx/fx-core/v5/x/optimism/types" ) // type check to ensure the interface is properly implemented diff --git a/x/optimism/types/genesis.go b/x/optimism/types/genesis.go index 716ae9818..573ce326a 100644 --- a/x/optimism/types/genesis.go +++ b/x/optimism/types/genesis.go @@ -1,7 +1,7 @@ package types import ( - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func DefaultGenesisState() *crosschaintypes.GenesisState { diff --git a/x/optimism/types/genesis_test.go b/x/optimism/types/genesis_test.go index 025484370..51f7e3969 100644 --- a/x/optimism/types/genesis_test.go +++ b/x/optimism/types/genesis_test.go @@ -7,8 +7,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func TestDefaultGenesisState(t *testing.T) { diff --git a/x/polygon/client/cli/query.go b/x/polygon/client/cli/query.go index 31430ef18..8a873bbee 100644 --- a/x/polygon/client/cli/query.go +++ b/x/polygon/client/cli/query.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - "github.com/functionx/fx-core/v4/x/polygon/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/polygon/types" ) func GetQueryCmd() *cobra.Command { diff --git a/x/polygon/client/cli/tx.go b/x/polygon/client/cli/tx.go index 527a2be28..8c5c9c1bb 100644 --- a/x/polygon/client/cli/tx.go +++ b/x/polygon/client/cli/tx.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - "github.com/functionx/fx-core/v4/x/polygon/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/polygon/types" ) func GetTxCmd() *cobra.Command { diff --git a/x/polygon/module.go b/x/polygon/module.go index 40ab55c5f..c075890d5 100644 --- a/x/polygon/module.go +++ b/x/polygon/module.go @@ -14,10 +14,10 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - cli2 "github.com/functionx/fx-core/v4/x/polygon/client/cli" - "github.com/functionx/fx-core/v4/x/polygon/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + cli2 "github.com/functionx/fx-core/v5/x/polygon/client/cli" + "github.com/functionx/fx-core/v5/x/polygon/types" ) // type check to ensure the interface is properly implemented diff --git a/x/polygon/types/genesis.go b/x/polygon/types/genesis.go index 1a79f9f94..694864ab8 100644 --- a/x/polygon/types/genesis.go +++ b/x/polygon/types/genesis.go @@ -1,7 +1,7 @@ package types import ( - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func DefaultGenesisState() *crosschaintypes.GenesisState { diff --git a/x/polygon/types/genesis_test.go b/x/polygon/types/genesis_test.go index 912741bf3..09e3e3005 100644 --- a/x/polygon/types/genesis_test.go +++ b/x/polygon/types/genesis_test.go @@ -7,8 +7,8 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func TestDefaultGenesisState(t *testing.T) { diff --git a/x/staking/keeper/genesis.go b/x/staking/keeper/genesis.go index 1d49c86e0..a5aaf0079 100644 --- a/x/staking/keeper/genesis.go +++ b/x/staking/keeper/genesis.go @@ -8,7 +8,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/x/staking/types" ) func (k Keeper) InitGenesis(ctx sdk.Context, data *types.GenesisState) (res []abci.ValidatorUpdate) { diff --git a/x/staking/keeper/genesis_test.go b/x/staking/keeper/genesis_test.go index 6a555173c..26c0ca5c4 100644 --- a/x/staking/keeper/genesis_test.go +++ b/x/staking/keeper/genesis_test.go @@ -8,8 +8,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/staking/types" ) func (suite *KeeperTestSuite) TestInitGenesis() { diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 0380e0285..81f4fb849 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -9,9 +9,9 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" ) type KeeperTestSuite struct { diff --git a/x/staking/keeper/shares.go b/x/staking/keeper/shares.go index 521455a0c..79fd97894 100644 --- a/x/staking/keeper/shares.go +++ b/x/staking/keeper/shares.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/x/staking/types" ) // SetAllowance sets the allowance of a spender for a delegator. diff --git a/x/staking/keeper/shares_test.go b/x/staking/keeper/shares_test.go index 6d7175dec..ab661bb58 100644 --- a/x/staking/keeper/shares_test.go +++ b/x/staking/keeper/shares_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "math/big" - "github.com/functionx/fx-core/v4/testutil/helpers" + "github.com/functionx/fx-core/v5/testutil/helpers" ) func (suite *KeeperTestSuite) TestAllowance() { diff --git a/x/staking/module.go b/x/staking/module.go index ed43ce0ee..a07701a69 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -12,8 +12,8 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/tendermint/tendermint/abci/types" - "github.com/functionx/fx-core/v4/x/staking/keeper" - "github.com/functionx/fx-core/v4/x/staking/types" + "github.com/functionx/fx-core/v5/x/staking/keeper" + "github.com/functionx/fx-core/v5/x/staking/types" ) var ( diff --git a/x/tron/client/cli/query.go b/x/tron/client/cli/query.go index 1bfb41c84..b1fd565e0 100644 --- a/x/tron/client/cli/query.go +++ b/x/tron/client/cli/query.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/tron/types" ) func GetQueryCmd() *cobra.Command { diff --git a/x/tron/client/cli/tx.go b/x/tron/client/cli/tx.go index d0c047011..358b896e1 100644 --- a/x/tron/client/cli/tx.go +++ b/x/tron/client/cli/tx.go @@ -4,8 +4,8 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/spf13/cobra" - "github.com/functionx/fx-core/v4/x/crosschain/client/cli" - "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/x/crosschain/client/cli" + "github.com/functionx/fx-core/v5/x/tron/types" ) func GetTxCmd() *cobra.Command { diff --git a/x/tron/keeper/grpc_query.go b/x/tron/keeper/grpc_query.go index ffe7907de..99bc2d9ae 100644 --- a/x/tron/keeper/grpc_query.go +++ b/x/tron/keeper/grpc_query.go @@ -7,8 +7,8 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/tron/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/tron/types" ) var _ crosschaintypes.QueryServer = Keeper{} diff --git a/x/tron/keeper/grpc_query_test.go b/x/tron/keeper/grpc_query_test.go index c54577931..63be39a2c 100644 --- a/x/tron/keeper/grpc_query_test.go +++ b/x/tron/keeper/grpc_query_test.go @@ -6,9 +6,9 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/functionx/fx-core/v4/testutil/helpers" - "github.com/functionx/fx-core/v4/x/crosschain/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/crosschain/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func (suite *KeeperTestSuite) TestKeeper_BatchFees() { diff --git a/x/tron/keeper/hook.go b/x/tron/keeper/hook.go index 9505e24d2..2d0e295ad 100644 --- a/x/tron/keeper/hook.go +++ b/x/tron/keeper/hook.go @@ -4,8 +4,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" - fxtypes "github.com/functionx/fx-core/v4/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + fxtypes "github.com/functionx/fx-core/v5/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) var _ fxtypes.TransactionHook = &Keeper{} diff --git a/x/tron/keeper/keeper.go b/x/tron/keeper/keeper.go index 8182e88ed..c0a159663 100644 --- a/x/tron/keeper/keeper.go +++ b/x/tron/keeper/keeper.go @@ -4,9 +4,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/libs/log" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/tron/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/tron/types" ) type Keeper struct { diff --git a/x/tron/keeper/keeper_test.go b/x/tron/keeper/keeper_test.go index ee0bd953f..43cd9ba91 100644 --- a/x/tron/keeper/keeper_test.go +++ b/x/tron/keeper/keeper_test.go @@ -14,12 +14,12 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/functionx/fx-core/v4/app" - "github.com/functionx/fx-core/v4/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - tronkeeper "github.com/functionx/fx-core/v4/x/tron/keeper" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/app" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + tronkeeper "github.com/functionx/fx-core/v5/x/tron/keeper" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) type KeeperTestSuite struct { diff --git a/x/tron/keeper/msg_server.go b/x/tron/keeper/msg_server.go index 09ca09007..23254e3f1 100644 --- a/x/tron/keeper/msg_server.go +++ b/x/tron/keeper/msg_server.go @@ -8,9 +8,9 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) var _ crosschaintypes.MsgServer = msgServer{} diff --git a/x/tron/keeper/msg_server_test.go b/x/tron/keeper/msg_server_test.go index 0428b884d..6a5b41b79 100644 --- a/x/tron/keeper/msg_server_test.go +++ b/x/tron/keeper/msg_server_test.go @@ -7,9 +7,9 @@ import ( "github.com/evmos/ethermint/crypto/ethsecp256k1" tmrand "github.com/tendermint/tendermint/libs/rand" - "github.com/functionx/fx-core/v4/testutil/helpers" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - trontypes "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/testutil/helpers" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) func (suite *KeeperTestSuite) Test_msgServer_ConfirmBatch() { diff --git a/x/tron/module.go b/x/tron/module.go index dd6a4813a..1b81f6b90 100644 --- a/x/tron/module.go +++ b/x/tron/module.go @@ -14,11 +14,11 @@ import ( "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" - crosschainkeeper "github.com/functionx/fx-core/v4/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/tron/client/cli" - "github.com/functionx/fx-core/v4/x/tron/keeper" - "github.com/functionx/fx-core/v4/x/tron/types" + crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/tron/client/cli" + "github.com/functionx/fx-core/v5/x/tron/keeper" + "github.com/functionx/fx-core/v5/x/tron/types" ) // type check to ensure the interface is properly implemented diff --git a/x/tron/types/checkpoint.go b/x/tron/types/checkpoint.go index f79946a1b..eea92e469 100644 --- a/x/tron/types/checkpoint.go +++ b/x/tron/types/checkpoint.go @@ -7,8 +7,8 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/fbsobreira/gotron-sdk/pkg/abi" - fxtypes "github.com/functionx/fx-core/v4/types" - "github.com/functionx/fx-core/v4/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) // GetCheckpointOracleSet returns the checkpoint diff --git a/x/tron/types/genesis.go b/x/tron/types/genesis.go index 750730eef..e8e31e14a 100644 --- a/x/tron/types/genesis.go +++ b/x/tron/types/genesis.go @@ -1,7 +1,7 @@ package types import ( - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) func DefaultGenesisState() *crosschaintypes.GenesisState { diff --git a/x/tron/types/genesis_test.go b/x/tron/types/genesis_test.go index 6670279f4..9735be8d5 100644 --- a/x/tron/types/genesis_test.go +++ b/x/tron/types/genesis_test.go @@ -7,9 +7,9 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - fxtypes "github.com/functionx/fx-core/v4/types" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" - "github.com/functionx/fx-core/v4/x/tron/types" + fxtypes "github.com/functionx/fx-core/v5/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/tron/types" ) func TestDefaultGenesisState(t *testing.T) { diff --git a/x/tron/types/msg_validate.go b/x/tron/types/msg_validate.go index 65e7f0a0e..9b386de34 100644 --- a/x/tron/types/msg_validate.go +++ b/x/tron/types/msg_validate.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" - crosschaintypes "github.com/functionx/fx-core/v4/x/crosschain/types" + crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" ) var _ crosschaintypes.MsgValidateBasic = &TronMsgValidate{} diff --git a/x/tron/types/signer.go b/x/tron/types/signer.go index 816f25f92..830bbe1a3 100644 --- a/x/tron/types/signer.go +++ b/x/tron/types/signer.go @@ -7,7 +7,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/fbsobreira/gotron-sdk/pkg/address" - "github.com/functionx/fx-core/v4/x/crosschain/types" + "github.com/functionx/fx-core/v5/x/crosschain/types" ) const tronSignaturePrefix = "\x19TRON Signed Message:\n32" diff --git a/x/tron/types/tron_address_test.go b/x/tron/types/tron_address_test.go index e5b0084ab..13f793d2c 100644 --- a/x/tron/types/tron_address_test.go +++ b/x/tron/types/tron_address_test.go @@ -5,7 +5,7 @@ import ( "github.com/stretchr/testify/require" - "github.com/functionx/fx-core/v4/x/tron/types" + "github.com/functionx/fx-core/v5/x/tron/types" ) func TestValidateTronAddress(t *testing.T) { From cb23492ce9a9122fc5b59a007741eeb1efed59b4 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Thu, 15 Jun 2023 16:11:26 +0800 Subject: [PATCH 03/30] feat: fxcore v5 upgrade * remove v4,v4_1,v4_2 upgrade --- app/upgrade.go | 4 +- app/upgrade_test.go | 471 +-------------------------- app/upgrades/v4/constants.go | 74 ----- app/upgrades/v4/upgrade.go | 195 ----------- app/upgrades/v4/upgrade_test.go | 30 -- app/upgrades/v4_1/constants.go | 27 -- app/upgrades/v4_2/constants.go | 54 --- app/upgrades/v4_2/upgrade.go | 72 ---- app/upgrades/v5/constants.go | 15 + app/upgrades/{v4_1 => v5}/upgrade.go | 26 +- 10 files changed, 38 insertions(+), 930 deletions(-) delete mode 100644 app/upgrades/v4/constants.go delete mode 100644 app/upgrades/v4/upgrade.go delete mode 100644 app/upgrades/v4/upgrade_test.go delete mode 100644 app/upgrades/v4_1/constants.go delete mode 100644 app/upgrades/v4_2/constants.go delete mode 100644 app/upgrades/v4_2/upgrade.go create mode 100644 app/upgrades/v5/constants.go rename app/upgrades/{v4_1 => v5}/upgrade.go (52%) diff --git a/app/upgrade.go b/app/upgrade.go index ecbfec03f..be5a9fdb3 100644 --- a/app/upgrade.go +++ b/app/upgrade.go @@ -6,11 +6,11 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/functionx/fx-core/v5/app/upgrades" - "github.com/functionx/fx-core/v5/app/upgrades/v4_2" + v5 "github.com/functionx/fx-core/v5/app/upgrades/v5" ) func (app *App) GetUpgrade() upgrades.Upgrade { - return v4_2.Upgrade() + return v5.Upgrade } // configure store loader that checks if version == upgradeHeight and applies store upgrades diff --git a/app/upgrade_test.go b/app/upgrade_test.go index 27e2fbf8b..419d4534c 100644 --- a/app/upgrade_test.go +++ b/app/upgrade_test.go @@ -1,48 +1,27 @@ package app_test import ( - "fmt" - "math/big" "os" "path/filepath" "testing" - sdkmath "cosmossdk.io/math" - cmtdbm "github.com/cometbft/cometbft-db" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/crypto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/tendermint/tendermint/store" dbm "github.com/tendermint/tm-db" "github.com/functionx/fx-core/v5/app" - v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" - "github.com/functionx/fx-core/v5/app/upgrades/v4_2" + v5 "github.com/functionx/fx-core/v5/app/upgrades/v5" "github.com/functionx/fx-core/v5/testutil/helpers" fxtypes "github.com/functionx/fx-core/v5/types" - arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" - avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" - "github.com/functionx/fx-core/v5/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v5/x/crosschain/types" - erc20types "github.com/functionx/fx-core/v5/x/erc20/types" - ethtypes "github.com/functionx/fx-core/v5/x/eth/types" - evmtypes "github.com/functionx/fx-core/v5/x/evm/types" - fxgovtypes "github.com/functionx/fx-core/v5/x/gov/types" - optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" - polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" - trontypes "github.com/functionx/fx-core/v5/x/tron/types" ) -func Test_TestnetUpgradeV4_2(t *testing.T) { +func Test_TestnetUpgrade(t *testing.T) { helpers.SkipTest(t, "Skipping local test: ", t.Name()) fxtypes.SetConfig(true) @@ -56,90 +35,16 @@ func Test_TestnetUpgradeV4_2(t *testing.T) { plan upgradetypes.Plan }{ { - name: "upgrade v4.2", - fromVersion: 3, - toVersion: 4, + name: "upgrade v5.0.x", + fromVersion: 4, + toVersion: 5, plan: upgradetypes.Plan{ - Name: v4_2.Upgrade().UpgradeName, - Info: "local test upgrade v4.2", + Name: v5.Upgrade.UpgradeName, + Info: "local test upgrade v5.0.x", }, }, } - blockStoreDB, err := cmtdbm.NewDB("blockstore", cmtdbm.GoLevelDBBackend, filepath.Join(fxtypes.GetDefaultNodeHome(), "data")) - require.NoError(t, err) - blockStore := store.NewBlockStore(blockStoreDB) - meta := blockStore.LoadBaseMeta() - require.Equal(t, fxtypes.TestnetChainId, meta.Header.ChainID, "only testnet can run this test") - - db, err := dbm.NewDB("application", dbm.GoLevelDBBackend, filepath.Join(fxtypes.GetDefaultNodeHome(), "data")) - require.NoError(t, err) - - makeEncodingConfig := app.MakeEncodingConfig() - myApp := app.New(log.NewFilter(log.NewTMLogger(os.Stdout), log.AllowAll()), - db, nil, false, map[int64]bool{}, fxtypes.GetDefaultNodeHome(), 0, - makeEncodingConfig, app.EmptyAppOptions{}) - // todo default DefaultStoreLoader New module verification failed - myApp.SetStoreLoader(upgradetypes.UpgradeStoreLoader(myApp.LastBlockHeight()+1, v4_2.Upgrade().StoreUpgrades())) - err = myApp.LoadLatestVersion() - require.NoError(t, err) - - ctx := newContext(t, myApp) - if ctx.ChainID() != fxtypes.TestnetChainId { - require.Fail(t, "only testnet can run this test") - } - - for _, testCase := range testCases { - t.Run(testCase.name, func(t *testing.T) { - testCase.plan.Height = ctx.BlockHeight() - - myApp.UpgradeKeeper.ApplyUpgrade(ctx, testCase.plan) - - checkVersionMap(t, ctx, myApp, getConsensusVersion(testCase.toVersion)) - }) - } - - // UpgradeAfter - checkFIP20LogicUpgrade(t, ctx, myApp) - checkWFXLogicUpgrade(t, ctx, myApp) - - myApp.EthKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) - myApp.BscKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) - myApp.TronKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) - myApp.PolygonKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) - myApp.AvalancheKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) -} - -func Test_MainnetUpgradeV4_2(t *testing.T) { - helpers.SkipTest(t, "Skipping local test: ", t.Name()) - - fxtypes.SetConfig(true) - fxtypes.SetChainId(fxtypes.MainnetChainId) // only for mainnet - - testCases := []struct { - name string - fromVersion int - toVersion int - LocalStoreBlockHeight uint64 - plan upgradetypes.Plan - }{ - { - name: "upgrade v4.2", - fromVersion: 3, - toVersion: 4, - plan: upgradetypes.Plan{ - Name: v4_2.Upgrade().UpgradeName, - Info: "local test upgrade v4.2", - }, - }, - } - - blockStoreDB, err := cmtdbm.NewDB("blockstore", cmtdbm.GoLevelDBBackend, filepath.Join(fxtypes.GetDefaultNodeHome(), "data")) - require.NoError(t, err) - blockStore := store.NewBlockStore(blockStoreDB) - meta := blockStore.LoadBaseMeta() - require.Equal(t, fxtypes.MainnetChainId, meta.Header.ChainID, "only mainnet can run this test") - db, err := dbm.NewDB("application", dbm.GoLevelDBBackend, filepath.Join(fxtypes.GetDefaultNodeHome(), "data")) require.NoError(t, err) @@ -148,37 +53,13 @@ func Test_MainnetUpgradeV4_2(t *testing.T) { db, nil, false, map[int64]bool{}, fxtypes.GetDefaultNodeHome(), 0, makeEncodingConfig, app.EmptyAppOptions{}) // todo default DefaultStoreLoader New module verification failed - myApp.SetStoreLoader(upgradetypes.UpgradeStoreLoader(myApp.LastBlockHeight()+1, v4_2.Upgrade().StoreUpgrades())) + myApp.SetStoreLoader(upgradetypes.UpgradeStoreLoader(myApp.LastBlockHeight()+1, v5.Upgrade.StoreUpgrades())) err = myApp.LoadLatestVersion() require.NoError(t, err) ctx := newContext(t, myApp) - if ctx.ChainID() != fxtypes.MainnetChainId { - require.Fail(t, "only mainnet can run this test") - } - - // UpgradeBefore - - // check arbitrum and optimism register usdt ,weth - checkDenomMetaData(t, ctx, myApp, true) - // check params migrated from x/param to module erc20 - checkERC20MigrateParamStore(t, ctx, myApp, true) - // check params migrated from x/param to module crosschain - checkCrossChainMigrateParamStore(t, ctx, myApp, true) - // check fxgovparams - checkFXGovParams(t, ctx, myApp, true) - - usdtToken, found := myApp.Erc20Keeper.GetTokenPair(ctx, "usdt") - require.True(t, found) - - beforeRefundBalance := make(map[common.Address]*big.Int, len(v4_2.PolygonUSDTRefunds)) - for _, r := range v4_2.PolygonUSDTRefunds { - beforeRefundBalance[r.Address] = getTokenBalanceOf(t, ctx, myApp, usdtToken.GetERC20Contract(), r.Address) - } - for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { - checkVersionMap(t, ctx, myApp, getConsensusVersion(testCase.fromVersion)) testCase.plan.Height = ctx.BlockHeight() myApp.UpgradeKeeper.ApplyUpgrade(ctx, testCase.plan) @@ -187,26 +68,6 @@ func Test_MainnetUpgradeV4_2(t *testing.T) { }) } - // check refund denom - checkRefundDenom(t, ctx, myApp) - - // check refund - for _, r := range v4_2.PolygonUSDTRefunds { - beforeBalance := beforeRefundBalance[r.Address] - balance := getTokenBalanceOf(t, ctx, myApp, usdtToken.GetERC20Contract(), r.Address) - require.Equal(t, balance, big.NewInt(0).Add(beforeBalance, r.Coins.AmountOf(v4_2.PolygonUSDTDenom).BigInt())) - } - - // UpgradeAfter - checkDenomMetaData(t, ctx, myApp, false) - checkERC20MigrateParamStore(t, ctx, myApp, false) - checkCrossChainMigrateParamStore(t, ctx, myApp, false) - checkFXGovParams(t, ctx, myApp, false) - - checkFIP20LogicUpgrade(t, ctx, myApp) - checkWFXLogicUpgrade(t, ctx, myApp) - checkCrossChainOracleDelegateInfo(t, myApp, ctx) - myApp.EthKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) myApp.BscKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) myApp.TronKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) @@ -214,52 +75,6 @@ func Test_MainnetUpgradeV4_2(t *testing.T) { myApp.AvalancheKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) } -func checkCrossChainOracleDelegateInfo(t *testing.T, myApp *app.App, ctx sdk.Context) { - bscRemoveOracles := v4.GetBscRemoveOracles(ctx.ChainID()) - // list to map - bscRemoveOraclesMap := make(map[string]bool) - for _, oracle := range bscRemoveOracles { - bscRemoveOraclesMap[oracle] = true - } - routerServer := keeper.NewMsgServerRouterImpl(myApp.CrosschainKeeper) - crosschainModules := []string{ethtypes.ModuleName, bsctypes.ModuleName, trontypes.ModuleName, polygontypes.ModuleName, avalanchetypes.ModuleName, arbitrumtypes.ModuleName, optimismtypes.ModuleName} - for _, crosschainModule := range crosschainModules { - oracles, err := myApp.CrosschainKeeper.Oracles(ctx, &crosschaintypes.QueryOraclesRequest{ChainName: crosschainModule}) - require.NoError(t, err) - for _, oracle := range oracles.Oracles { - delegateAddress := oracle.GetDelegateAddress(crosschainModule) - startingInfo := myApp.DistrKeeper.GetDelegatorStartingInfo(ctx, oracle.GetValidator(), delegateAddress) - if crosschainModule == bsctypes.ModuleName && bscRemoveOraclesMap[oracle.GetOracle().String()] { - require.EqualValues(t, uint64(0), startingInfo.Height) - require.EqualValues(t, uint64(0), startingInfo.PreviousPeriod) - require.True(t, startingInfo.Stake.IsNil()) - continue - } - require.True(t, startingInfo.Height > 0) - require.True(t, startingInfo.PreviousPeriod > 0) - require.EqualValues(t, sdk.NewDecFromInt(sdkmath.NewInt(10_000).MulRaw(1e18)).String(), startingInfo.Stake.String()) - - // test can get rewards - reward, err := myApp.DistrKeeper.DelegationRewards(ctx, &distributiontypes.QueryDelegationRewardsRequest{ - DelegatorAddress: delegateAddress.String(), - ValidatorAddress: oracle.GetValidator().String(), - }) - require.NoError(t, err) - - if reward.Rewards.IsZero() { - continue - } - - // test can withdraw rewards - _, err = routerServer.WithdrawReward(ctx, &crosschaintypes.MsgWithdrawReward{ - ChainName: crosschainModule, - OracleAddress: oracle.GetOracle().String(), - }) - require.NoError(t, err) - } - } -} - func newContext(t *testing.T, myApp *app.App) sdk.Context { chainId := fxtypes.MainnetChainId if os.Getenv("CHAIN_ID") == fxtypes.TestnetChainId { @@ -277,267 +92,6 @@ func newContext(t *testing.T, myApp *app.App) sdk.Context { return ctx } -func checkDenomMetaData(t *testing.T, ctx sdk.Context, myApp *app.App, isUpgradeBefore bool) { - denomAlias := v4.GetUpdateDenomAlias(ctx.ChainID()) - for _, da := range denomAlias { - denomKey := da.Denom - if isUpgradeBefore { - denomKey = da.Denom - _, found := myApp.BankKeeper.GetDenomMetaData(ctx, denomKey) - assert.False(t, found) - continue - } - md, found := myApp.BankKeeper.GetDenomMetaData(ctx, denomKey) - assert.True(t, found) - assert.True(t, len(md.DenomUnits) > 0) - assert.True(t, len(md.DenomUnits[0].Aliases) > 0) - if isUpgradeBefore { - assert.False(t, contain(md.DenomUnits[0].Aliases, da.Alias)) - } else { - assert.True(t, contain(md.DenomUnits[0].Aliases, da.Alias)) - } - } -} - -func checkFIP20LogicUpgrade(t *testing.T, ctx sdk.Context, myApp *app.App) { - // check fip20 logic upgrade - fipLogicAcc := myApp.EvmKeeper.GetAccount(ctx, fxtypes.GetFIP20().Address) - require.True(t, fipLogicAcc.IsContract()) - - fipLogic := fxtypes.GetFIP20() - codeHash := crypto.Keccak256Hash(fipLogic.Code) - require.Equal(t, codeHash.Bytes(), fipLogicAcc.CodeHash) - - code := myApp.EvmKeeper.GetCode(ctx, codeHash) - require.Equal(t, fipLogic.Code, code) -} - -func checkWFXLogicUpgrade(t *testing.T, ctx sdk.Context, myApp *app.App) { - // check wfx logic upgrade - wfxLogicAcc := myApp.EvmKeeper.GetAccount(ctx, fxtypes.GetWFX().Address) - require.True(t, wfxLogicAcc.IsContract()) - - wfxLogic := fxtypes.GetWFX() - codeHash := crypto.Keccak256Hash(wfxLogic.Code) - require.Equal(t, codeHash.Bytes(), wfxLogicAcc.CodeHash) - - code := myApp.EvmKeeper.GetCode(ctx, codeHash) - require.Equal(t, wfxLogic.Code, code) -} - -func checkFXGovParams(t *testing.T, ctx sdk.Context, myApp *app.App, isUpgradeBefore bool) { - defaultParams := myApp.GovKeeper.GetParams(ctx, "") - checkGovERC20ParamsUpgradeBefore(t, ctx, myApp, defaultParams, isUpgradeBefore) - checkGovEVMParamsUpgradeBefore(t, ctx, myApp, defaultParams, isUpgradeBefore) - checkGovEGFParamsUpgradeBefore(t, ctx, myApp, defaultParams, isUpgradeBefore) -} - -func checkGovEGFParamsUpgradeBefore(t *testing.T, ctx sdk.Context, myApp *app.App, defaultParams fxgovtypes.Params, isUpgradeBefore bool) { - if isUpgradeBefore { - egfParams := myApp.GovKeeper.GetParams(ctx, "/cosmos.distribution.v1beta1.CommunityPoolSpendProposal") - assert.NoError(t, egfParams.ValidateBasic()) - assert.NoError(t, egfParams.ValidateBasic()) - assert.EqualValues(t, egfParams.MinDeposit, defaultParams.MinDeposit) - assert.EqualValues(t, egfParams.MinInitialDeposit.String(), sdk.NewCoin(fxtypes.DefaultDenom, fxgovtypes.DefaultMinInitialDeposit).String()) - assert.EqualValues(t, egfParams.MaxDepositPeriod, defaultParams.MaxDepositPeriod) - assert.EqualValues(t, egfParams.VotingPeriod.String(), defaultParams.VotingPeriod.String()) - assert.EqualValues(t, egfParams.VetoThreshold, defaultParams.VetoThreshold) - assert.EqualValues(t, egfParams.Threshold, defaultParams.Threshold) - assert.EqualValues(t, egfParams.Quorum, defaultParams.Quorum) - - egf := myApp.GovKeeper.GetEGFParams(ctx) - assert.Error(t, egf.ValidateBasic()) - assert.False(t, egf.EgfDepositThreshold.IsValid()) - assert.EqualValues(t, egf.ClaimRatio, "") - return - } - egfParams := myApp.GovKeeper.GetParams(ctx, "/cosmos.distribution.v1beta1.CommunityPoolSpendProposal") - assert.NoError(t, egfParams.ValidateBasic()) - assert.EqualValues(t, egfParams.MinDeposit, defaultParams.MinDeposit) - assert.EqualValues(t, egfParams.MinInitialDeposit.String(), sdk.NewCoin(fxtypes.DefaultDenom, fxgovtypes.DefaultMinInitialDeposit).String()) - assert.EqualValues(t, egfParams.MaxDepositPeriod, defaultParams.MaxDepositPeriod) - assert.EqualValues(t, egfParams.VotingPeriod.String(), fxgovtypes.DefaultEgfVotingPeriod.String()) - assert.EqualValues(t, egfParams.VetoThreshold, defaultParams.VetoThreshold) - assert.EqualValues(t, egfParams.Threshold, defaultParams.Threshold) - assert.EqualValues(t, egfParams.Quorum, defaultParams.Quorum) - - egf := myApp.GovKeeper.GetEGFParams(ctx) - assert.NoError(t, egf.ValidateBasic()) - assert.EqualValues(t, egf.EgfDepositThreshold, sdk.NewCoin(fxtypes.DefaultDenom, fxgovtypes.DefaultEgfDepositThreshold)) - assert.EqualValues(t, egf.ClaimRatio, fxgovtypes.DefaultClaimRatio.String()) -} - -func checkGovEVMParamsUpgradeBefore(t *testing.T, ctx sdk.Context, myApp *app.App, defaultParams fxgovtypes.Params, isUpgradeBefore bool) { - if isUpgradeBefore { - evmParams := myApp.GovKeeper.GetParams(ctx, sdk.MsgTypeURL(&evmtypes.MsgCallContract{})) - assert.NoError(t, evmParams.ValidateBasic()) - assert.EqualValues(t, evmParams.MinDeposit, defaultParams.MinDeposit) - assert.EqualValues(t, evmParams.MinInitialDeposit.String(), sdk.NewCoin(fxtypes.DefaultDenom, fxgovtypes.DefaultMinInitialDeposit).String()) - assert.EqualValues(t, evmParams.MaxDepositPeriod, defaultParams.MaxDepositPeriod) - assert.EqualValues(t, evmParams.VotingPeriod.String(), defaultParams.VotingPeriod.String()) - assert.EqualValues(t, evmParams.VetoThreshold, defaultParams.VetoThreshold) - assert.EqualValues(t, evmParams.Threshold, defaultParams.Threshold) - assert.EqualValues(t, evmParams.Quorum, defaultParams.Quorum) - return - } - evmParams := myApp.GovKeeper.GetParams(ctx, sdk.MsgTypeURL(&evmtypes.MsgCallContract{})) - assert.NoError(t, evmParams.ValidateBasic()) - assert.EqualValues(t, evmParams.MinDeposit, defaultParams.MinDeposit) - assert.EqualValues(t, evmParams.MinInitialDeposit.String(), sdk.NewCoin(fxtypes.DefaultDenom, fxgovtypes.DefaultMinInitialDeposit).String()) - assert.EqualValues(t, evmParams.MaxDepositPeriod, defaultParams.MaxDepositPeriod) - assert.EqualValues(t, evmParams.VotingPeriod.String(), fxgovtypes.DefaultEvmVotingPeriod.String()) - assert.EqualValues(t, evmParams.VetoThreshold, defaultParams.VetoThreshold) - assert.EqualValues(t, evmParams.Threshold, defaultParams.Threshold) - assert.EqualValues(t, evmParams.Quorum, fxgovtypes.DefaultEvmQuorum.String()) -} - -func checkGovERC20ParamsUpgradeBefore(t *testing.T, ctx sdk.Context, myApp *app.App, defaultParams fxgovtypes.Params, isUpgradeBefore bool) { - if isUpgradeBefore { - erc20MsgType := []string{ - "/fx.erc20.v1.RegisterCoinProposal", - "/fx.erc20.v1.RegisterERC20Proposal", - "/fx.erc20.v1.ToggleTokenConversionProposal", - "/fx.erc20.v1.UpdateDenomAliasProposal", - sdk.MsgTypeURL(&erc20types.MsgRegisterCoin{}), - sdk.MsgTypeURL(&erc20types.MsgRegisterERC20{}), - sdk.MsgTypeURL(&erc20types.MsgToggleTokenConversion{}), - sdk.MsgTypeURL(&erc20types.MsgUpdateDenomAlias{}), - } - for _, erc20MsgType := range erc20MsgType { - // registered Msg - erc20params := myApp.GovKeeper.GetParams(ctx, erc20MsgType) - assert.NoError(t, erc20params.ValidateBasic()) - assert.EqualValues(t, erc20params.MinDeposit, defaultParams.MinDeposit) - assert.EqualValues(t, erc20params.MinInitialDeposit.String(), sdk.NewCoin(fxtypes.DefaultDenom, fxgovtypes.DefaultMinInitialDeposit).String()) - assert.EqualValues(t, erc20params.MaxDepositPeriod, defaultParams.MaxDepositPeriod) - assert.EqualValues(t, erc20params.VotingPeriod, defaultParams.VotingPeriod) - assert.EqualValues(t, erc20params.VetoThreshold, defaultParams.VetoThreshold) - assert.EqualValues(t, erc20params.Threshold, defaultParams.Threshold) - assert.EqualValues(t, erc20params.Quorum, defaultParams.Quorum) - } - return - } - erc20MsgType := []string{ - "/fx.erc20.v1.RegisterCoinProposal", - "/fx.erc20.v1.RegisterERC20Proposal", - "/fx.erc20.v1.ToggleTokenConversionProposal", - "/fx.erc20.v1.UpdateDenomAliasProposal", - sdk.MsgTypeURL(&erc20types.MsgRegisterCoin{}), - sdk.MsgTypeURL(&erc20types.MsgRegisterERC20{}), - sdk.MsgTypeURL(&erc20types.MsgToggleTokenConversion{}), - sdk.MsgTypeURL(&erc20types.MsgUpdateDenomAlias{}), - } - for _, erc20MsgType := range erc20MsgType { - // registered Msg - erc20params := myApp.GovKeeper.GetParams(ctx, erc20MsgType) - assert.NoError(t, erc20params.ValidateBasic()) - assert.EqualValues(t, erc20params.MinDeposit, defaultParams.MinDeposit) - assert.EqualValues(t, erc20params.MinInitialDeposit.String(), sdk.NewCoin(fxtypes.DefaultDenom, fxgovtypes.DefaultMinInitialDeposit).String()) - assert.EqualValues(t, erc20params.MaxDepositPeriod, defaultParams.MaxDepositPeriod) - assert.EqualValues(t, erc20params.VotingPeriod, defaultParams.VotingPeriod) - assert.EqualValues(t, erc20params.VetoThreshold, defaultParams.VetoThreshold) - assert.EqualValues(t, erc20params.Threshold, defaultParams.Threshold) - assert.EqualValues(t, erc20params.Quorum, fxgovtypes.DefaultErc20Quorum.String()) - } -} - -func checkERC20MigrateParamStore(t *testing.T, ctx sdk.Context, myApp *app.App, isUpgradeBefore bool) { - subspace := myApp.GetSubspace(erc20types.ModuleName) - var subspaceParams erc20types.Params - if isUpgradeBefore { - subspace = subspace.WithKeyTable(erc20types.ParamKeyTable()) - subspace.GetParamSet(ctx, &subspaceParams) - params := myApp.Erc20Keeper.GetParams(ctx) - assert.NotEqualValues(t, params.EnableErc20, subspaceParams.EnableErc20) - assert.NotEqualValues(t, params.EnableEVMHook, subspaceParams.EnableEVMHook) - assert.NotEqualValues(t, params.IbcTimeout, subspaceParams.IbcTimeout) - return - } - subspace.GetParamSet(ctx, &subspaceParams) - params := myApp.Erc20Keeper.GetParams(ctx) - assert.EqualValues(t, params.EnableErc20, subspaceParams.EnableErc20) - assert.EqualValues(t, params.EnableEVMHook, subspaceParams.EnableEVMHook) - assert.EqualValues(t, params.IbcTimeout, subspaceParams.IbcTimeout) -} - -func checkCrossChainMigrateParamStore(t *testing.T, ctx sdk.Context, myApp *app.App, isUpgradeBefore bool) { - crosschainsModule := []string{avalanchetypes.ModuleName, bsctypes.ModuleName, ethtypes.ModuleName, polygontypes.ModuleName, trontypes.ModuleName} - for _, moduleName := range crosschainsModule { - subspace := myApp.GetSubspace(moduleName) - var subspaceParams crosschaintypes.Params - if isUpgradeBefore { - subspace = subspace.WithKeyTable(crosschaintypes.ParamKeyTable()) - subspace.GetParamSet(ctx, &subspaceParams) - response, err := myApp.CrosschainKeeper.Params(ctx, &crosschaintypes.QueryParamsRequest{ChainName: moduleName}) - assert.NoError(t, err) - params := response.Params - assert.NotEqualValues(t, params.GravityId, subspaceParams.GravityId) - assert.NotEqualValues(t, params.AverageBlockTime, subspaceParams.AverageBlockTime) - assert.NotEqualValues(t, params.AverageExternalBlockTime, subspaceParams.AverageExternalBlockTime) - assert.NotEqualValues(t, params.ExternalBatchTimeout, subspaceParams.ExternalBatchTimeout) - assert.NotEqualValues(t, params.SignedWindow, subspaceParams.SignedWindow) - assert.NotEqualValues(t, params.SlashFraction, subspaceParams.SlashFraction) - assert.NotEqualValues(t, params.OracleSetUpdatePowerChangePercent, subspaceParams.OracleSetUpdatePowerChangePercent) - assert.NotEqualValues(t, params.IbcTransferTimeoutHeight, subspaceParams.IbcTransferTimeoutHeight) - assert.NotEqualValues(t, params.DelegateThreshold, subspaceParams.DelegateThreshold) - assert.NotEqualValues(t, params.DelegateMultiple, subspaceParams.DelegateMultiple) - return - } - subspace.GetParamSet(ctx, &subspaceParams) - response, err := myApp.CrosschainKeeper.Params(ctx, &crosschaintypes.QueryParamsRequest{ChainName: moduleName}) - assert.NoError(t, err) - params := response.Params - assert.EqualValues(t, params.GravityId, subspaceParams.GravityId) - assert.EqualValues(t, params.AverageBlockTime, subspaceParams.AverageBlockTime) - assert.EqualValues(t, params.AverageExternalBlockTime, subspaceParams.AverageExternalBlockTime) - assert.EqualValues(t, params.ExternalBatchTimeout, subspaceParams.ExternalBatchTimeout) - assert.EqualValues(t, params.SignedWindow, subspaceParams.SignedWindow) - assert.EqualValues(t, params.SlashFraction, subspaceParams.SlashFraction) - assert.EqualValues(t, params.OracleSetUpdatePowerChangePercent, subspaceParams.OracleSetUpdatePowerChangePercent) - assert.EqualValues(t, params.IbcTransferTimeoutHeight, subspaceParams.IbcTransferTimeoutHeight) - assert.EqualValues(t, params.DelegateThreshold, subspaceParams.DelegateThreshold) - assert.EqualValues(t, params.DelegateMultiple, subspaceParams.DelegateMultiple) - } - defaultParams := crosschaintypes.DefaultParams() - for _, newModule := range []string{arbitrumtypes.ModuleName, optimismtypes.ModuleName} { - response, err := myApp.CrosschainKeeper.Params(ctx, &crosschaintypes.QueryParamsRequest{ChainName: newModule}) - assert.NoError(t, err) - params := response.Params - assert.EqualValues(t, params.GravityId, fmt.Sprintf("fx-%s-bridge", newModule)) - assert.EqualValues(t, params.AverageBlockTime, defaultParams.AverageBlockTime) - assert.EqualValues(t, params.AverageExternalBlockTime, 500) - assert.EqualValues(t, params.ExternalBatchTimeout, defaultParams.ExternalBatchTimeout) - assert.EqualValues(t, params.SignedWindow, defaultParams.SignedWindow) - assert.EqualValues(t, params.SlashFraction, defaultParams.SlashFraction) - assert.EqualValues(t, params.OracleSetUpdatePowerChangePercent, defaultParams.OracleSetUpdatePowerChangePercent) - assert.EqualValues(t, params.IbcTransferTimeoutHeight, defaultParams.IbcTransferTimeoutHeight) - assert.EqualValues(t, params.DelegateThreshold, defaultParams.DelegateThreshold) - assert.EqualValues(t, params.DelegateMultiple, defaultParams.DelegateMultiple) - } -} - -func checkRefundDenom(t *testing.T, ctx sdk.Context, myApp *app.App) { - usdtMD, found := myApp.BankKeeper.GetDenomMetaData(ctx, "usdt") - require.True(t, found) - exist := false - for _, alias := range usdtMD.DenomUnits[0].Aliases { - if alias == v4_2.PolygonUSDTDenom { - exist = true - break - } - } - require.True(t, exist) -} - -func contain[T int | int64 | string](a []T, b T) bool { - for i := range a { - if a[i] == b { - return true - } - } - return false -} - func checkVersionMap(t *testing.T, ctx sdk.Context, myApp *app.App, versionMap module.VersionMap) { vm := myApp.UpgradeKeeper.GetModuleVersionMap(ctx) for k, v := range vm { @@ -597,12 +151,3 @@ func getConsensusVersion(appVersion int) (versionMap module.VersionMap) { } return versionMap } - -func getTokenBalanceOf(t *testing.T, ctx sdk.Context, myApp *app.App, token common.Address, addr common.Address) *big.Int { - var res struct { - Value *big.Int - } - err := myApp.EvmKeeper.QueryContract(ctx, addr, token, fxtypes.GetFIP20().ABI, "balanceOf", &res, addr) - require.NoError(t, err) - return res.Value -} diff --git a/app/upgrades/v4/constants.go b/app/upgrades/v4/constants.go deleted file mode 100644 index 293667611..000000000 --- a/app/upgrades/v4/constants.go +++ /dev/null @@ -1,74 +0,0 @@ -package v4 - -import ( - storetypes "github.com/cosmos/cosmos-sdk/store/types" - - "github.com/functionx/fx-core/v5/app/upgrades" - fxtypes "github.com/functionx/fx-core/v5/types" - arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" - gravitytypes "github.com/functionx/fx-core/v5/x/gravity/types" - optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" -) - -var ( - mainnetRemoveOracles = []string{ - "fx1d6xj9yekmpmyafwx9tvgzl2gmzcpe04n54853f", - "fx1jjpwenetj0u70peyyjy9lewwzjyg2y7suq3hct", - } - - testnetUpdateDenomAlias = []DenomAlias{ - {Denom: "weth", Alias: "arbitrum0x57b1E4C85B0f141aDE38b5573907BA8eF9aC2298"}, - {Denom: "usdt", Alias: "arbitrum0xEa99760Ecc3460154670B86E202233974883b153"}, - {Denom: "weth", Alias: "optimism0xd0fABb17BD2999A4A9fDF0F05c2386e7dF6519bb"}, - {Denom: "usdt", Alias: "optimism0xeb62B336778ac9E9CF1Aacfd268E0Eb013019DC5"}, - } - mainnetUpdateDenomAlias = []DenomAlias{ - {Denom: "weth", Alias: "arbitrum0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"}, - {Denom: "usdt", Alias: "arbitrum0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9"}, - {Denom: "weth", Alias: "optimism0x4200000000000000000000000000000000000006"}, - {Denom: "usdt", Alias: "optimism0x94b008aA00579c1307B0EF2c499aD98a8ce58e58"}, - } -) - -// Upgrade for fxv4 -// Deprecated: Please use v4.1.x -var Upgrade = upgrades.Upgrade{ - UpgradeName: "fxv4", - CreateUpgradeHandler: CreateUpgradeHandler, - StoreUpgrades: func() *storetypes.StoreUpgrades { - return &storetypes.StoreUpgrades{ - Added: []string{ - arbitrumtypes.ModuleName, - optimismtypes.ModuleName, - }, - Deleted: []string{ - gravitytypes.ModuleName, - }, - } - }, -} - -type DenomAlias struct { - Denom string - Alias string -} - -func GetUpdateDenomAlias(chainId string) []DenomAlias { - if fxtypes.TestnetChainId == chainId { - return testnetUpdateDenomAlias - } else if chainId == fxtypes.MainnetChainId { - return mainnetUpdateDenomAlias - } else { - panic("invalid chainId:" + chainId) - } -} - -func GetBscRemoveOracles(chainId string) []string { - if fxtypes.TestnetChainId == chainId { - return []string{} - } else if chainId == fxtypes.MainnetChainId { - return mainnetRemoveOracles - } else { - panic("invalid chainId:" + chainId) - } -} diff --git a/app/upgrades/v4/upgrade.go b/app/upgrades/v4/upgrade.go deleted file mode 100644 index 98857e810..000000000 --- a/app/upgrades/v4/upgrade.go +++ /dev/null @@ -1,195 +0,0 @@ -package v4 - -import ( - "fmt" - "strconv" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - evmtypes "github.com/evmos/ethermint/x/evm/types" - - "github.com/functionx/fx-core/v5/app/keepers" - fxtypes "github.com/functionx/fx-core/v5/types" - avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" - bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" - crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" - "github.com/functionx/fx-core/v5/x/crosschain/types" - erc20keeper "github.com/functionx/fx-core/v5/x/erc20/keeper" - ethtypes "github.com/functionx/fx-core/v5/x/eth/types" - evmkeeper "github.com/functionx/fx-core/v5/x/evm/keeper" - "github.com/functionx/fx-core/v5/x/gov/keeper" - polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" - trontypes "github.com/functionx/fx-core/v5/x/tron/types" -) - -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - app *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - cacheCtx, commit := ctx.CacheContext() - - // 1. initialize the evm module account - CreateEvmModuleAccount(cacheCtx, app.AccountKeeper) - - // 2. init go fx params - InitGovFXParams(cacheCtx, app.GovKeeper) - - // 3. update Logic code - UpdateLogicCode(cacheCtx, app.EvmKeeper) - - ctx.Logger().Info("start to run v4 migrations...", "module", "upgrade") - toVM, err := mm.RunMigrations(cacheCtx, configurator, fromVM) - if err != nil { - return fromVM, err - } - - // 4. update arbitrum and optimism denom alias, after bank module migration, because bank module migrates to fixing the bank denom bug - // discovered in https://github.com/cosmos/cosmos-sdk/pull/13821 - UpdateDenomAliases(cacheCtx, app.Erc20Keeper) - - // 5. reset cross chain module oracle delegate, bind oracle delegate starting info - err = ResetCrossChainModuleOracleDelegate(cacheCtx, app.CrossChainKeepers, app.StakingKeeper, app.DistrKeeper) - if err != nil { - return fromVM, err - } - - // 6. remove bsc oracles - RemoveBscOracle(cacheCtx, app.BscKeeper) - - commit() - ctx.Logger().Info("Upgrade complete") - return toVM, nil - } -} - -func ResetCrossChainModuleOracleDelegate(ctx sdk.Context, crossChainKeepers keepers.CrossChainKeepers, stakingKeeper types.StakingKeeper, distributionKeeper types.DistributionKeeper) error { - needHandlerModules := []string{ethtypes.ModuleName, bsctypes.ModuleName, polygontypes.ModuleName, trontypes.ModuleName, avalanchetypes.ModuleName} - type crossChainKeeper interface { - GetAllOracles(ctx sdk.Context, isOnline bool) (oracles types.Oracles) - } - moduleHandler := map[string]crossChainKeeper{ - ethtypes.ModuleName: crossChainKeepers.EthKeeper, - bsctypes.ModuleName: crossChainKeepers.BscKeeper, - trontypes.ModuleName: crossChainKeepers.TronKeeper, - polygontypes.ModuleName: crossChainKeepers.PolygonKeeper, - avalanchetypes.ModuleName: crossChainKeepers.AvalancheKeeper, - } - for _, handlerModule := range needHandlerModules { - handlerKeeper, ok := moduleHandler[handlerModule] - if !ok { - continue - } - oracles := handlerKeeper.GetAllOracles(ctx, false) - if len(oracles) <= 0 { - continue - } - - for _, oracle := range oracles { - if oracle.DelegateAmount.IsZero() { - continue - } - - delegateAddress := oracle.GetDelegateAddress(handlerModule) - startingInfo := distributionKeeper.GetDelegatorStartingInfo(ctx, oracle.GetValidator(), delegateAddress) - if startingInfo.Height > 0 { - continue - } - err := stakingKeeper.BeforeDelegationCreated(ctx, delegateAddress, oracle.GetValidator()) - if err != nil { - return err - } - err = stakingKeeper.AfterDelegationModified(ctx, delegateAddress, oracle.GetValidator()) - if err != nil { - return err - } - } - } - return nil -} - -func RemoveBscOracle(ctx sdk.Context, bscKeeper crosschainkeeper.Keeper) { - bscRemoveOracles := GetBscRemoveOracles(ctx.ChainID()) - if len(bscRemoveOracles) <= 0 { - return - } - - proposalOracle, found := bscKeeper.GetProposalOracle(ctx) - oracles := proposalOracle.Oracles - if !found || len(oracles) <= 0 { - return - } - - removeOracleMap := make(map[string]bool, len(bscRemoveOracles)) - for _, oracle := range bscRemoveOracles { - removeOracleMap[oracle] = true - } - - newOracle := []string{} - for _, oracle := range oracles { - if _, ok := removeOracleMap[oracle]; ok { - continue - } - newOracle = append(newOracle, oracle) - } - - if len(newOracle) == len(oracles) { - return - } - err := bscKeeper.UpdateChainOracles(ctx, newOracle) - if err != nil && ctx.ChainID() == fxtypes.TestnetChainId { - panic(err) - } -} - -func UpdateLogicCode(ctx sdk.Context, evmKeeper *evmkeeper.Keeper) { - UpdateFIP20LogicCode(ctx, evmKeeper) - UpdateWFXLogicCode(ctx, evmKeeper) -} - -func UpdateFIP20LogicCode(ctx sdk.Context, k *evmkeeper.Keeper) { - fip20 := fxtypes.GetFIP20() - if err := k.UpdateContractCode(ctx, fip20.Address, fip20.Code); err != nil { - panic(fmt.Sprintf("update fip logic code error: %s", err.Error())) - } - ctx.Logger().Info("update FIP20 contract", "module", "upgrade", "codeHash", fip20.CodeHash()) -} - -func UpdateWFXLogicCode(ctx sdk.Context, k *evmkeeper.Keeper) { - wfx := fxtypes.GetWFX() - if err := k.UpdateContractCode(ctx, wfx.Address, wfx.Code); err != nil { - panic(fmt.Sprintf("update wfx logic code error: %s", err.Error())) - } - ctx.Logger().Info("update WFX contract", "module", "upgrade", "codeHash", wfx.CodeHash()) -} - -func InitGovFXParams(ctx sdk.Context, keeper keeper.Keeper) { - if err := keeper.InitFxGovParams(ctx); err != nil { - panic(err) - } -} - -func CreateEvmModuleAccount(ctx sdk.Context, k authkeeper.AccountKeeper) { - account, _ := k.GetModuleAccountAndPermissions(ctx, evmtypes.ModuleName) - if account == nil { - panic("create evm module account empty") - } -} - -func UpdateDenomAliases(ctx sdk.Context, k erc20keeper.Keeper) { - denomAlias := GetUpdateDenomAlias(ctx.ChainID()) - for _, da := range denomAlias { - cacheCtx, commit := ctx.CacheContext() - - addFlag, err := k.UpdateDenomAliases(cacheCtx, da.Denom, da.Alias) - if err != nil { - ctx.Logger().Error("failed to update denom alias", "denom", da.Denom, "alias", da.Alias, "err", err.Error()) - continue - } - commit() - ctx.Logger().Info("update denom alias successfully", "denom", da.Denom, "alias", da.Alias, "add-flag", strconv.FormatBool(addFlag)) - } -} diff --git a/app/upgrades/v4/upgrade_test.go b/app/upgrades/v4/upgrade_test.go deleted file mode 100644 index 8008e6f06..000000000 --- a/app/upgrades/v4/upgrade_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package v4_test - -import ( - "fmt" - "testing" - - sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/assert" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - "github.com/functionx/fx-core/v5/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v5/types" -) - -func TestAccountConvertModuleAccount(t *testing.T) { - valSet, genAccs, balances := helpers.GenerateGenesisValidator(1, nil) - myApp := helpers.SetupWithGenesisValSet(t, valSet, genAccs, balances...) - ctx := myApp.NewContext(false, tmproto.Header{Height: myApp.LastBlockHeight()}) - moduleAddress, _ := myApp.AccountKeeper.GetModuleAddressAndPermissions(types.ModuleName) - account := myApp.AccountKeeper.GetAccount(ctx, moduleAddress) - assert.NotNil(t, account) - balance := sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1000).MulRaw(1e18))) - err := myApp.BankKeeper.MintCoins(ctx, types.ModuleName, balance) - assert.NoError(t, err) - err = myApp.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, account.GetAddress(), sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(500).MulRaw(1e18)))) - assert.Error(t, err) - assert.EqualError(t, err, fmt.Sprintf("%s is not allowed to receive funds: unauthorized", account.GetAddress().String())) -} diff --git a/app/upgrades/v4_1/constants.go b/app/upgrades/v4_1/constants.go deleted file mode 100644 index d0cf53f01..000000000 --- a/app/upgrades/v4_1/constants.go +++ /dev/null @@ -1,27 +0,0 @@ -package v4_1 - -import ( - storetypes "github.com/cosmos/cosmos-sdk/store/types" - - "github.com/functionx/fx-core/v5/app/upgrades" - v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" - fxtypes "github.com/functionx/fx-core/v5/types" -) - -// Deprecated: Please use v4.2.x -func Upgrade() upgrades.Upgrade { - upgrade := upgrades.Upgrade{ - UpgradeName: "v4.1.x", - CreateUpgradeHandler: createUpgradeHandler, - StoreUpgrades: v4.Upgrade.StoreUpgrades, - } - - // if testnet, store has been upgraded in v4 - if fxtypes.ChainId() == fxtypes.TestnetChainId { - upgrade.StoreUpgrades = func() *storetypes.StoreUpgrades { - return &storetypes.StoreUpgrades{} - } - } - - return upgrade -} diff --git a/app/upgrades/v4_2/constants.go b/app/upgrades/v4_2/constants.go deleted file mode 100644 index 166c77043..000000000 --- a/app/upgrades/v4_2/constants.go +++ /dev/null @@ -1,54 +0,0 @@ -package v4_2 - -import ( - sdkmath "cosmossdk.io/math" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/ethereum/go-ethereum/common" - - "github.com/functionx/fx-core/v5/app/upgrades" - v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" - fxtypes "github.com/functionx/fx-core/v5/types" -) - -type Refund struct { - Address common.Address - Coins sdk.Coins -} - -var ( - PolygonUSDTDenom = "polygon0xc2132D05D31c914a87C6611C10748AEb04B58e8F" - // SendToExternalRefund send to external refund - // fxcore tx: https://starscan.io/evm/tx/0x6795d921d532b68b886e8f776143a138688897a8b143f981545475df16f01728 - // polygon fork tx: https://polygonscan.com/tx/0xe7ea70c77960e78703942d895afaac5d6fe0f99cf2b894cbb5b2bcf36e5a82ce - // amount: 89724233, bridge-fee: 11988 - SendToExternalRefund = Refund{ - Address: common.HexToAddress("0x3Cf9771C961af8727EF5E9b955419cf80b34bcd4"), - Coins: sdk.NewCoins(sdk.NewCoin(PolygonUSDTDenom, sdkmath.NewInt(89724233).Add(sdkmath.NewInt(11988)))), - } - // SendToFxDelayedPayment send to fx delayed payment - // polygon tx: https://polygonscan.com/tx/0xebbcc9c9e91a081b7f3717b0d5d0a571e965ce3e0c65c11a9925e1142d829d1a - // amount: 99892059 - SendToFxDelayedPayment = Refund{ - Address: common.HexToAddress("0x17a3d2EEE4E3558f40c0c7A583A182f44d377759"), - Coins: sdk.NewCoins(sdk.NewCoin(PolygonUSDTDenom, sdk.NewInt(99892059))), - } - PolygonUSDTRefunds = []Refund{SendToExternalRefund, SendToFxDelayedPayment} -) - -func Upgrade() upgrades.Upgrade { - upgrade := upgrades.Upgrade{ - UpgradeName: "v4.2.x", - CreateUpgradeHandler: createUpgradeHandler, - StoreUpgrades: v4.Upgrade.StoreUpgrades, - } - - // if testnet, store has been upgraded in fxv4 - if fxtypes.ChainId() == fxtypes.TestnetChainId { - upgrade.StoreUpgrades = func() *storetypes.StoreUpgrades { - return &storetypes.StoreUpgrades{} - } - } - - return upgrade -} diff --git a/app/upgrades/v4_2/upgrade.go b/app/upgrades/v4_2/upgrade.go deleted file mode 100644 index 5cd1d9e9b..000000000 --- a/app/upgrades/v4_2/upgrade.go +++ /dev/null @@ -1,72 +0,0 @@ -package v4_2 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/ethereum/go-ethereum/common" - - "github.com/functionx/fx-core/v5/app/keepers" - v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" - fxtypes "github.com/functionx/fx-core/v5/types" - crosschainkeeper "github.com/functionx/fx-core/v5/x/crosschain/keeper" - erc20types "github.com/functionx/fx-core/v5/x/erc20/types" -) - -func createUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - app *keepers.AppKeepers, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // testnet upgrade - if ctx.ChainID() == fxtypes.TestnetChainId { - return fromVM, nil - } - - // mainnet upgrade - toVM, err := v4.CreateUpgradeHandler(mm, configurator, app)(ctx, plan, fromVM) - if err != nil { - return nil, err - } - - // refund polygon USDT, after erc20 module params migrate - for _, r := range PolygonUSDTRefunds { - cacheCtx, commit := ctx.CacheContext() - if err := CrossChainRefundToAccount(cacheCtx, app, app.PolygonKeeper, r.Address, r.Coins); err != nil { - ctx.Logger().Error("refund failed", "addr", r.Address.String(), "coins", r.Coins.String(), "err", err.Error()) - continue - } - commit() - ctx.Logger().Info("refund success", "addr", r.Address.String(), "coins", r.Coins.String()) - } - return toVM, nil - } -} - -func CrossChainRefundToAccount(ctx sdk.Context, app *keepers.AppKeepers, chk crosschainkeeper.Keeper, addr common.Address, coins sdk.Coins) error { - if err := app.BankKeeper.MintCoins(ctx, chk.ModuleName(), coins); err != nil { - return err - } - if err := app.BankKeeper.SendCoinsFromModuleToAccount(ctx, chk.ModuleName(), addr.Bytes(), coins); err != nil { - return err - } - for _, coin := range coins { - if coin.Denom == fxtypes.DefaultDenom { - ctx.Logger().Info("skip refund", "addr", addr.String(), "coin", coin.String()) - continue - } - targetCoin, err := app.Erc20Keeper.ConvertDenomToTarget(ctx, addr.Bytes(), coin, fxtypes.ParseFxTarget(fxtypes.ERC20Target)) - if err != nil { - return err - } - if _, err = app.Erc20Keeper.ConvertCoin(sdk.WrapSDKContext(ctx), &erc20types.MsgConvertCoin{ - Coin: targetCoin, - Receiver: addr.Hex(), - Sender: sdk.AccAddress(addr.Bytes()).String(), - }); err != nil { - return err - } - } - return nil -} diff --git a/app/upgrades/v5/constants.go b/app/upgrades/v5/constants.go new file mode 100644 index 000000000..57e70e875 --- /dev/null +++ b/app/upgrades/v5/constants.go @@ -0,0 +1,15 @@ +package v5 + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + + "github.com/functionx/fx-core/v5/app/upgrades" +) + +var Upgrade = upgrades.Upgrade{ + UpgradeName: "v5.0.x", + CreateUpgradeHandler: CreateUpgradeHandler, + StoreUpgrades: func() *storetypes.StoreUpgrades { + return &storetypes.StoreUpgrades{} + }, +} diff --git a/app/upgrades/v4_1/upgrade.go b/app/upgrades/v5/upgrade.go similarity index 52% rename from app/upgrades/v4_1/upgrade.go rename to app/upgrades/v5/upgrade.go index 10ff2d1cc..d21cc6190 100644 --- a/app/upgrades/v4_1/upgrade.go +++ b/app/upgrades/v5/upgrade.go @@ -1,4 +1,4 @@ -package v4_1 +package v5 import ( sdk "github.com/cosmos/cosmos-sdk/types" @@ -6,29 +6,29 @@ import ( upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/functionx/fx-core/v5/app/keepers" - v4 "github.com/functionx/fx-core/v5/app/upgrades/v4" fxtypes "github.com/functionx/fx-core/v5/types" ) -func createUpgradeHandler( +func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, app *keepers.AppKeepers, ) upgradetypes.UpgradeHandler { return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { - // testnet upgrade - if ctx.ChainID() == fxtypes.TestnetChainId { - cacheCtx, commit := ctx.CacheContext() + cacheCtx, commit := ctx.CacheContext() - // update logic code - v4.UpdateLogicCode(cacheCtx, app.EvmKeeper) + if ctx.ChainID() == fxtypes.TestnetChainId { // nolint:staticcheck + // todo repair validator + } - commit() - ctx.Logger().Info("Upgrade complete") - return fromVM, nil + ctx.Logger().Info("start to run v5 migrations...", "module", "upgrade") + toVM, err := mm.RunMigrations(cacheCtx, configurator, fromVM) + if err != nil { + return fromVM, err } - // mainnet upgrade - return v4.CreateUpgradeHandler(mm, configurator, app)(ctx, plan, fromVM) + commit() + ctx.Logger().Info("Upgrade complete") + return toVM, nil } } From 9035882e944b7268c09be3b801878c90f429e883 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Wed, 21 Jun 2023 18:55:09 +0800 Subject: [PATCH 04/30] fix: repair testnet fxv4 slash period --- app/upgrade_test.go | 148 +++++++++++++++---------- app/upgrades/v5/constants.go | 15 +++ app/upgrades/v5/repair.go | 207 +++++++++++++++++++++++++++++++++++ app/upgrades/v5/upgrade.go | 5 +- client/jsonrpc/json_rpc.go | 28 +++++ 5 files changed, 345 insertions(+), 58 deletions(-) create mode 100644 app/upgrades/v5/repair.go diff --git a/app/upgrade_test.go b/app/upgrade_test.go index 419d4534c..994d1392a 100644 --- a/app/upgrade_test.go +++ b/app/upgrade_test.go @@ -1,13 +1,17 @@ package app_test import ( + "fmt" "os" "path/filepath" + "sort" "testing" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -17,6 +21,7 @@ import ( "github.com/functionx/fx-core/v5/app" v5 "github.com/functionx/fx-core/v5/app/upgrades/v5" + "github.com/functionx/fx-core/v5/client/jsonrpc" "github.com/functionx/fx-core/v5/testutil/helpers" fxtypes "github.com/functionx/fx-core/v5/types" ) @@ -63,11 +68,11 @@ func Test_TestnetUpgrade(t *testing.T) { testCase.plan.Height = ctx.BlockHeight() myApp.UpgradeKeeper.ApplyUpgrade(ctx, testCase.plan) - - checkVersionMap(t, ctx, myApp, getConsensusVersion(testCase.toVersion)) }) } + checkSlashPeriod(t, ctx, myApp) + myApp.EthKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) myApp.BscKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) myApp.TronKeeper.EndBlocker(ctx.WithBlockHeight(ctx.BlockHeight() + 1)) @@ -92,62 +97,93 @@ func newContext(t *testing.T, myApp *app.App) sdk.Context { return ctx } -func checkVersionMap(t *testing.T, ctx sdk.Context, myApp *app.App, versionMap module.VersionMap) { - vm := myApp.UpgradeKeeper.GetModuleVersionMap(ctx) - for k, v := range vm { - require.Equal(t, versionMap[k], v, k) +func checkSlashPeriod(t *testing.T, ctx sdk.Context, myApp *app.App) { + for val := range v5.ValidatorSlashHeightTestnetFXV4 { + valAddr, err := sdk.ValAddressFromBech32(val) + require.NoError(t, err) + delegations := myApp.StakingKeeper.GetValidatorDelegations(ctx, valAddr) + + for _, del := range delegations { + cacheCtx, _ := ctx.CacheContext() + _, err := myApp.DistrKeeper.DelegationRewards(sdk.WrapSDKContext(cacheCtx), &distributiontypes.QueryDelegationRewardsRequest{ + DelegatorAddress: del.DelegatorAddress, + ValidatorAddress: del.ValidatorAddress, + }) + assert.NoError(t, err) + } + + // withdraw + for _, del := range delegations { + cacheCtx, _ := ctx.CacheContext() + _, err := myApp.DistrKeeper.WithdrawDelegationRewards(cacheCtx, del.GetDelegatorAddr(), del.GetValidatorAddr()) + assert.NoError(t, err) + } + + // undelegate + for _, del := range delegations { + cacheCtx, _ := ctx.CacheContext() + _, err := myApp.StakingKeeper.Undelegate(cacheCtx, del.GetDelegatorAddr(), del.GetValidatorAddr(), del.GetShares()) + assert.NoError(t, err) + } + + // delegate + count := 0 + for _, del := range delegations { + cacheCtx, _ := ctx.CacheContext() + fxBalance := myApp.BankKeeper.GetBalance(ctx, del.GetDelegatorAddr(), fxtypes.DefaultDenom) + if fxBalance.Amount.IsZero() { + continue + } + validator, found := myApp.StakingKeeper.GetValidator(ctx, del.GetValidatorAddr()) + require.True(t, found) + _, err := myApp.StakingKeeper.Delegate(cacheCtx, del.GetDelegatorAddr(), fxBalance.Amount, stakingtypes.Unbonded, validator, true) + assert.NoError(t, err) + count++ + } + assert.True(t, count > 0) } } -func getConsensusVersion(appVersion int) (versionMap module.VersionMap) { - // moduleName: v1,v2,v3 - historyVersions := map[string][]uint64{ - "auth": {0, 1, 2, 3}, - "authz": {0, 0, 1, 2}, - "avalanche": {0, 0, 1, 2, 3}, - "bank": {0, 1, 2, 3}, - "bsc": {1, 2, 3, 4}, - "capability": {1}, - "crisis": {1}, - "crosschain": {1}, - "distribution": {1, 2}, - "erc20": {0, 1, 2, 3}, - "evidence": {1}, - "evm": {0, 0, 3, 5}, - "eth": {0, 0, 1, 2, 3}, - "feegrant": {0, 0, 1, 2}, - "feemarket": {0, 0, 3, 4}, - "genutil": {1}, - "gov": {0, 1, 2, 3}, - "gravity": {1, 1, 2}, - "ibc": {1, 2}, - "migrate": {0, 1}, - "mint": {1}, - "other": {1}, - "params": {1}, - "polygon": {1, 2, 3, 4}, - "slashing": {1, 2}, - "staking": {0, 1, 2, 3}, - "transfer": {1, 1, 2}, // ibc-transfer - "fxtransfer": {0, 0, 1}, // fx-ibc-transfer - "tron": {1, 2, 3, 4}, - "upgrade": {0, 0, 1, 2}, - "vesting": {1}, - "arbitrum": {0, 0, 0, 1}, - "optimism": {0, 0, 0, 1}, - } - versionMap = make(map[string]uint64) - for key, versions := range historyVersions { - if len(versions) <= appVersion-1 { - // If not exist, select the last one - versionMap[key] = versions[len(versions)-1] - } else { - versionMap[key] = versions[appVersion-1] - } - // If the value is zero, the current version does not exist - if versionMap[key] == 0 { - delete(versionMap, key) +func TestSlashPeriodTestnetFXV4(t *testing.T) { + helpers.SkipTest(t, "Skipping local test:", t.Name()) + + fxtypes.SetConfig(true) + rpc := jsonrpc.NewNodeRPC(jsonrpc.NewClient("https://testnet-fx-json.functionx.io:26657")) + query := fmt.Sprintf("block.height > %d AND slash.reason = 'missing_signature'", fxtypes.TestnetBlockHeightV4) + + blockSearch, err := rpc.BlockSearch(query, 1, 100, "") + require.NoError(t, err) + + slashedFXV4 := make(map[string][]int64, len(v5.ValidatorSlashHeightTestnetFXV4)) + for _, block := range blockSearch.Blocks { + results, err := rpc.BlockResults(block.Block.Height) + require.NoError(t, err) + for _, result := range results.BeginBlockEvents { + if result.Type != slashingtypes.EventTypeLiveness { + continue + } + for _, attr := range result.Attributes { + if string(attr.Key) != slashingtypes.AttributeKeyAddress { + continue + } + valAddr, err := rpc.GetValAddressByCons(string(attr.Value)) + assert.NoError(t, err) + if _, ok := slashedFXV4[valAddr.String()]; ok { + slashedFXV4[valAddr.String()] = append(slashedFXV4[valAddr.String()], block.Block.Height) + } else { + slashedFXV4[valAddr.String()] = []int64{block.Block.Height} + } + } } } - return versionMap + assert.Equal(t, len(v5.ValidatorSlashHeightTestnetFXV4), len(slashedFXV4)) + + for val, h1 := range slashedFXV4 { + h2, ok := v5.ValidatorSlashHeightTestnetFXV4[val] + assert.True(t, ok, "val: %s", val) + sort.SliceStable(h1, func(i, j int) bool { + return h1[i] < h1[j] + }) + assert.Equal(t, h1, h2, "val: %s", val) + } } diff --git a/app/upgrades/v5/constants.go b/app/upgrades/v5/constants.go index 57e70e875..7bd137252 100644 --- a/app/upgrades/v5/constants.go +++ b/app/upgrades/v5/constants.go @@ -2,10 +2,25 @@ package v5 import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/functionx/fx-core/v5/app/upgrades" ) +type SlashPeriod struct { + Delegator sdk.AccAddress + Height uint64 + Period uint64 +} + +// ValidatorSlashHeightTestnetFXV4 is a map of testnet validator address to slash height +// todo check before testnet v5 release +var ValidatorSlashHeightTestnetFXV4 = map[string][]int64{ + "fxvaloper16d0jly49xgwm9tyf7lpf0splnfhrnttdejkz9h": {8787488, 8885841}, + "fxvaloper1xdqas5ak98us9eljqj5ppj5mhmku4slh2664l8": {8806427}, + "fxvaloper14lpap6mwytqtnrx6q9cnje2sen5a5wcctuwnsh": {8224664, 8457967, 8552303}, +} + var Upgrade = upgrades.Upgrade{ UpgradeName: "v5.0.x", CreateUpgradeHandler: CreateUpgradeHandler, diff --git a/app/upgrades/v5/repair.go b/app/upgrades/v5/repair.go new file mode 100644 index 000000000..6c4615b72 --- /dev/null +++ b/app/upgrades/v5/repair.go @@ -0,0 +1,207 @@ +package v5 + +import ( + "sort" + + sdk "github.com/cosmos/cosmos-sdk/types" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + fxtypes "github.com/functionx/fx-core/v5/types" + fxstakingkeeper "github.com/functionx/fx-core/v5/x/staking/keeper" +) + +func RepairSlashPeriod(ctx sdk.Context, sk fxstakingkeeper.Keeper, dk distrkeeper.Keeper) { + slashPeriod := delegatorNotSlash(ctx, sk, dk) + vals, newSlashPeriods := addSlashPeriodTestnetFXV4(ctx, slashPeriod) + for _, val := range vals { + valAddr, err := sdk.ValAddressFromBech32(val) + if err != nil { + panic(err) + } + fixSlashPeriodTestnetFXV4(ctx, dk, valAddr, newSlashPeriods[val]) + } +} + +func fixSlashPeriodTestnetFXV4(ctx sdk.Context, dk distrkeeper.Keeper, val sdk.ValAddress, periods []SlashPeriod) { + logger := ctx.Logger() + + currentRewards := dk.GetValidatorCurrentRewards(ctx, val) + currentHistoricalRewards := dk.GetValidatorHistoricalRewards(ctx, val, currentRewards.Period) + + periodHistoricalRewards := make(map[uint64]distrtypes.ValidatorHistoricalRewards, len(periods)) + for _, p := range periods { + if p.Delegator == nil { + continue + } + // get period starting info + startingInfo := dk.GetDelegatorStartingInfo(ctx, val, p.Delegator) + historicalRewards := dk.GetValidatorHistoricalRewards(ctx, val, startingInfo.PreviousPeriod) + periodHistoricalRewards[p.Period] = historicalRewards + dk.DeleteValidatorHistoricalReward(ctx, val, startingInfo.PreviousPeriod) + } + + slashBefore := false + for idx, p := range periods { + if p.Delegator != nil { + // set new period historical rewards + dk.SetValidatorHistoricalRewards(ctx, val, p.Period, periodHistoricalRewards[p.Period]) + } + + if p.Height < fxtypes.TestnetBlockHeightV4 || + p.Delegator != nil && !slashBefore { + continue + } + + if p.Delegator == nil { + referenceCount := uint32(1) + if idx == len(periods)-1 { + referenceCount += 1 + } + logger.Info("add slash period", "validator", val, "height", p.Height, "period", p.Period, "referenceCount", referenceCount) + lastHistoricalRewards := periodHistoricalRewards[periods[idx-1].Period] // todo + historicalRewards := distrtypes.NewValidatorHistoricalRewards(lastHistoricalRewards.CumulativeRewardRatio, referenceCount) + dk.SetValidatorHistoricalRewards(ctx, val, p.Period, historicalRewards) + periodHistoricalRewards[p.Period] = historicalRewards + + // add slash period + fraction, _ := sdk.NewDecFromStr("0.001") // todo + slashEvent := distrtypes.NewValidatorSlashEvent(p.Period, fraction) + dk.SetValidatorSlashEvent(ctx, val, p.Height, p.Period, slashEvent) + slashBefore = true + } else { + logger.Info("migrate slash period", "validator", val, "height", p.Height, "period", p.Period, "delegator", p.Delegator) + // set new starting info + startingInfo := dk.GetDelegatorStartingInfo(ctx, val, p.Delegator) + startingInfo.PreviousPeriod = p.Period + dk.SetDelegatorStartingInfo(ctx, val, p.Delegator, startingInfo) + } + + if idx == len(periods)-1 { + currentRewards.Period = p.Period + 1 + dk.SetValidatorCurrentRewards(ctx, val, currentRewards) + dk.SetValidatorHistoricalRewards(ctx, val, currentRewards.Period, currentHistoricalRewards) + } + } +} + +func addSlashPeriodTestnetFXV4(ctx sdk.Context, slashPeriod map[string][]SlashPeriod) ([]string, map[string][]SlashPeriod) { + vals := make([]string, 0, len(slashPeriod)) + newSlashPeriod := make(map[string][]SlashPeriod, len(slashPeriod)) + for val, periods := range slashPeriod { + if len(periods) == 0 { + ctx.Logger().Info("skip delegation empty", "address", val) + continue + } + heights, ok := ValidatorSlashHeightTestnetFXV4[val] + if !ok { + ctx.Logger().Info("skip validator not found", "address", val) + continue + } + + for _, height := range heights { + periods = append(periods, SlashPeriod{ + Delegator: nil, + Height: uint64(height), + Period: 0, + }) + } + sort.SliceStable(periods, func(i, j int) bool { + return periods[i].Height < periods[j].Height + }) + + // fix period with slash height + lastPeriod := uint64(0) + newPeriods := make([]SlashPeriod, 0, len(periods)) + for _, del := range periods { + if del.Delegator == nil && del.Period == 0 || // slash height + del.Period <= lastPeriod { // after slash height + del.Period = lastPeriod + 1 + } + lastPeriod = del.Period + newPeriods = append(newPeriods, del) + } + + newSlashPeriod[val] = newPeriods + vals = append(vals, val) + } + + // sort by validator address + sort.SliceStable(vals, func(i, j int) bool { + return vals[i] < vals[j] + }) + + return vals, newSlashPeriod +} + +func delegatorNotSlash(ctx sdk.Context, sk fxstakingkeeper.Keeper, dk distrkeeper.Keeper) map[string][]SlashPeriod { + valDels := validatorNotSlash(ctx, sk, dk) + sk.IterateAllDelegations(ctx, func(del stakingtypes.Delegation) (stop bool) { + if _, ok := valDels[del.ValidatorAddress]; !ok { + return false + } + startingInfo := dk.GetDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr()) + valDels[del.ValidatorAddress] = append(valDels[del.ValidatorAddress], SlashPeriod{ + Delegator: del.GetDelegatorAddr(), + Height: startingInfo.Height, + Period: startingInfo.PreviousPeriod, + }) + return false + }) + for val, dels := range valDels { + sort.SliceStable(dels, func(i, j int) bool { + return dels[i].Period < dels[j].Period + }) + valDels[val] = dels + } + return valDels +} + +func validatorNotSlash(ctx sdk.Context, sk fxstakingkeeper.Keeper, dk distrkeeper.Keeper) map[string][]SlashPeriod { + vals := make(map[string][]SlashPeriod, 50) + sk.IterateAllDelegations(ctx, func(del stakingtypes.Delegation) (stop bool) { + if _, ok := vals[del.GetValidatorAddr().String()]; ok { + return false + } + val, found := sk.GetValidator(ctx, del.GetValidatorAddr()) + if !found { + ctx.Logger().Error("validator not found", "validator", del.GetValidatorAddr().String()) + // if validator not found, skip + return false + } + currentStake := val.TokensFromShares(del.GetShares()) + stake := calculateSlashStake(ctx, dk, del) + + marginOfErr := sdk.SmallestDec().MulInt64(3) + if !stake.LTE(currentStake.Add(marginOfErr)) { + // if delegate after slash, no error + vals[del.GetValidatorAddr().String()] = make([]SlashPeriod, 0, 30) + } + return false + }) + return vals +} + +func calculateSlashStake(ctx sdk.Context, dk distrkeeper.Keeper, del stakingtypes.Delegation) sdk.Dec { + startingInfo := dk.GetDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr()) + startingPeriod := startingInfo.PreviousPeriod + stake := startingInfo.Stake + + startingHeight := startingInfo.Height + endingHeight := uint64(ctx.BlockHeight()) + + if endingHeight > startingHeight { + dk.IterateValidatorSlashEventsBetween(ctx, del.GetValidatorAddr(), startingHeight, endingHeight, + func(height uint64, event distrtypes.ValidatorSlashEvent) (stop bool) { + endingPeriod := event.ValidatorPeriod + if endingPeriod > startingPeriod { + stake = stake.MulTruncate(sdk.OneDec().Sub(event.Fraction)) + startingPeriod = endingPeriod + } + return false + }, + ) + } + return stake +} diff --git a/app/upgrades/v5/upgrade.go b/app/upgrades/v5/upgrade.go index d21cc6190..bf09fa901 100644 --- a/app/upgrades/v5/upgrade.go +++ b/app/upgrades/v5/upgrade.go @@ -17,8 +17,9 @@ func CreateUpgradeHandler( return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { cacheCtx, commit := ctx.CacheContext() - if ctx.ChainID() == fxtypes.TestnetChainId { // nolint:staticcheck - // todo repair validator + if ctx.ChainID() == fxtypes.TestnetChainId { + RepairSlashPeriod(ctx, app.StakingKeeper, app.DistrKeeper) + // todo repair register coin amount } ctx.Logger().Info("start to run v5 migrations...", "module", "upgrade") diff --git a/client/jsonrpc/json_rpc.go b/client/jsonrpc/json_rpc.go index a6098cd49..68a04488b 100644 --- a/client/jsonrpc/json_rpc.go +++ b/client/jsonrpc/json_rpc.go @@ -149,6 +149,24 @@ func (c *NodeRPC) GetStakeValidators(status stakingtypes.BondStatus) (stakingtyp return validators, err } +func (c *NodeRPC) GetValAddressByCons(consAddrStr string) (sdk.ValAddress, error) { + consAddr, err := sdk.ConsAddressFromBech32(consAddrStr) + if err != nil { + consAddr, err = hex.DecodeString(consAddrStr) + if err != nil { + return nil, errors.New("expected hex or bech32 address") + } + } + result, err := c.ABCIQueryIsOk("/store/staking/key", stakingtypes.GetValidatorByConsAddrKey(consAddr)) + if err != nil { + return nil, err + } + if result.Response.Value == nil { + return nil, fmt.Errorf("not found validator by consAddress: %s", consAddr.String()) + } + return result.Response.Value, nil +} + func (c *NodeRPC) BuildTx(privKey cryptotypes.PrivKey, msgs []sdk.Msg) (*tx.TxRaw, error) { return client.BuildTx(c, privKey, msgs) } @@ -489,6 +507,16 @@ func (c *NodeRPC) TxSearch(query string, page, perPage int, orderBy string) ( return result, nil } +func (c *NodeRPC) BlockSearch(query string, page, perPage int, orderBy string) (*ctypes.ResultBlockSearch, error) { + result := new(ctypes.ResultBlockSearch) + params := map[string]interface{}{"query": query, "prove": false, "page": strconv.Itoa(page), "per_page": strconv.Itoa(perPage), "order_by": orderBy} + err := c.caller.Call(c.ctx, "block_search", params, result) + if err != nil { + return nil, errors.Wrap(err, "BlockSearch") + } + return result, nil +} + func (c *NodeRPC) BroadcastEvidence(ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) { result := new(ctypes.ResultBroadcastEvidence) err := c.caller.Call(c.ctx, "broadcast_evidence", map[string]interface{}{"evidence": ev}, result) From f7bebaff252c4f0ea95be68964e55140d226f7d4 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Mon, 3 Jul 2023 17:31:01 +0800 Subject: [PATCH 05/30] feat: staking grant privilege * MsgGrantPrivilege * RejectValidatorGrantedDecorator --- ante/ante_test.go | 1 + ante/expected_keepers.go | 4 + ante/handler_options.go | 6 + ante/reject_msgs.go | 29 ++ ante/reject_msgs_test.go | 99 ++++ app/app.go | 1 + app/encoding_test.go | 4 +- app/keepers/keepers.go | 4 + go.mod | 2 +- proto/fx/staking/v1beta1/tx.proto | 22 + x/staking/client/cli/tx.go | 92 ++++ x/staking/keeper/keeper.go | 65 +++ x/staking/keeper/keeper_test.go | 98 ++++ x/staking/keeper/msg_server.go | 58 +++ x/staking/keeper/msg_server_test.go | 239 ++++++++++ x/staking/module.go | 33 +- x/staking/types/codec.go | 35 ++ x/staking/types/events.go | 2 + x/staking/types/expected_keepers.go | 15 + x/staking/types/keys.go | 11 +- x/staking/types/msg.go | 122 +++++ x/staking/types/msg_test.go | 123 +++++ x/staking/types/params.go | 7 + x/staking/types/tx.pb.go | 698 ++++++++++++++++++++++++++++ 24 files changed, 1761 insertions(+), 9 deletions(-) create mode 100644 ante/reject_msgs_test.go create mode 100644 proto/fx/staking/v1beta1/tx.proto create mode 100644 x/staking/client/cli/tx.go create mode 100644 x/staking/keeper/msg_server.go create mode 100644 x/staking/keeper/msg_server_test.go create mode 100644 x/staking/types/codec.go create mode 100644 x/staking/types/expected_keepers.go create mode 100644 x/staking/types/msg.go create mode 100644 x/staking/types/msg_test.go create mode 100644 x/staking/types/params.go create mode 100644 x/staking/types/tx.pb.go diff --git a/ante/ante_test.go b/ante/ante_test.go index 317e92688..8f559adaf 100644 --- a/ante/ante_test.go +++ b/ante/ante_test.go @@ -88,6 +88,7 @@ func (suite *AnteTestSuite) SetupTest() { EvmKeeper: suite.app.EvmKeeper, FeeMarketKeeper: suite.app.FeeMarketKeeper, IbcKeeper: suite.app.IBCKeeper, + StakingKeeper: suite.app.StakingKeeper, SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SigGasConsumer: fxante.DefaultSigVerificationGasConsumer, MaxTxGasWanted: 0, diff --git a/ante/expected_keepers.go b/ante/expected_keepers.go index fbce36500..fd07ea61b 100644 --- a/ante/expected_keepers.go +++ b/ante/expected_keepers.go @@ -62,3 +62,7 @@ type FeeMarketKeeper interface { type protoTxProvider interface { GetProtoTx() *tx.Tx } + +type StakingKeeper interface { + HasValidatorOperator(ctx sdk.Context, val sdk.ValAddress) bool +} diff --git a/ante/handler_options.go b/ante/handler_options.go index 15ead6727..918191db0 100644 --- a/ante/handler_options.go +++ b/ante/handler_options.go @@ -19,6 +19,7 @@ type HandlerOptions struct { FeegrantKeeper FeegrantKeeper EvmKeeper EVMKeeper FeeMarketKeeper FeeMarketKeeper + StakingKeeper StakingKeeper IbcKeeper *ibckeeper.Keeper SignModeHandler authsigning.SignModeHandler SigGasConsumer ante.SignatureVerificationGasConsumer @@ -45,6 +46,9 @@ func (options HandlerOptions) Validate() error { if options.EvmKeeper == nil { return errorsmod.Wrap(errortypes.ErrLogic, "evm keeper is required for AnteHandler") } + if options.StakingKeeper == nil { + return errorsmod.Wrap(errortypes.ErrLogic, "staking keeper is required for AnteHandler") + } return nil } @@ -57,6 +61,7 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { NewEthValidateBasicDecorator(options.EvmKeeper), NewEthSigVerificationDecorator(options.EvmKeeper), NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper), + NewRejectValidatorGrantedDecorator(options.StakingKeeper), // check if validator is granted, after account verification NewCanTransferDecorator(options.EvmKeeper), NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted), NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator. @@ -78,6 +83,7 @@ func newNormalTxAnteHandler(options HandlerOptions) sdk.AnteHandler { ante.NewValidateSigCountDecorator(options.AccountKeeper), NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), + NewRejectValidatorGrantedDecorator(options.StakingKeeper), // check if validator is granted, after sig verification ante.NewIncrementSequenceDecorator(options.AccountKeeper), ibcante.NewRedundantRelayDecorator(options.IbcKeeper), ) diff --git a/ante/reject_msgs.go b/ante/reject_msgs.go index 65a6b874d..75d4b8504 100644 --- a/ante/reject_msgs.go +++ b/ante/reject_msgs.go @@ -32,3 +32,32 @@ func (r RejectExtensionOptionsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, } return next(ctx, tx, simulate) } + +// RejectValidatorGrantedDecorator is an AnteDecorator that rejects all transactions from validator granted +type RejectValidatorGrantedDecorator struct { + sk StakingKeeper +} + +func NewRejectValidatorGrantedDecorator(sk StakingKeeper) RejectValidatorGrantedDecorator { + return RejectValidatorGrantedDecorator{ + sk: sk, + } +} + +func (r RejectValidatorGrantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { + if ctx.IsReCheckTx() { + return next(ctx, tx, simulate) + } + + msgs := tx.GetMsgs() + for _, msg := range msgs { + signers := msg.GetSigners() + for _, signer := range signers { + if r.sk.HasValidatorOperator(ctx, signer.Bytes()) { + return ctx, errorsmod.Wrap(errortypes.ErrInvalidAddress, "validator granted") + } + } + } + + return next(ctx, tx, simulate) +} diff --git a/ante/reject_msgs_test.go b/ante/reject_msgs_test.go new file mode 100644 index 000000000..0f6ddb504 --- /dev/null +++ b/ante/reject_msgs_test.go @@ -0,0 +1,99 @@ +package ante_test + +import ( + "math/big" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/ethereum/go-ethereum/common" + ethtypes "github.com/ethereum/go-ethereum/core/types" + + "github.com/functionx/fx-core/v5/ante" + "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" +) + +func (suite *AnteTestSuite) TestRejectValidatorGranted() { + val := helpers.NewEthPrivKey() + valAddr := sdk.ValAddress(val.PubKey().Address()) + addr := sdk.AccAddress(valAddr) + + grantAcct := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + suite.app.StakingKeeper.UpdateValidatorOperator(suite.ctx, valAddr, grantAcct) + + testCases := []struct { + name string + malleate func() sdk.Tx + expectPass bool + }{ + { + name: "success", + malleate: func() sdk.Tx { + testMsg := banktypes.MsgSend{ + FromAddress: grantAcct.String(), + ToAddress: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), + Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: fxtypes.DefaultDenom}}, + } + txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), fxtypes.DefaultDenom, &testMsg) + return txBuilder.GetTx() + }, + expectPass: true, + }, + { + name: "fail", + malleate: func() sdk.Tx { + testMsg := banktypes.MsgSend{ + FromAddress: addr.String(), + ToAddress: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), + Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: fxtypes.DefaultDenom}}, + } + txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), fxtypes.DefaultDenom, &testMsg) + return txBuilder.GetTx() + }, + expectPass: false, + }, + { + name: "fail with multiple msgs", + malleate: func() sdk.Tx { + msg1 := banktypes.MsgSend{ + FromAddress: addr.String(), + ToAddress: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), + Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: fxtypes.DefaultDenom}}, + } + msg2 := banktypes.MsgSend{ + FromAddress: addr.String(), + ToAddress: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), + Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: fxtypes.DefaultDenom}}, + } + txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), fxtypes.DefaultDenom, &msg1, &msg2) + return txBuilder.GetTx() + }, + expectPass: false, + }, + { + name: "failed eth tx", + malleate: func() sdk.Tx { + from := common.BytesToAddress(addr.Bytes()) + to := helpers.GenerateAddress() + emptyAccessList := ethtypes.AccessList{} + msg := suite.BuildTestEthTx(from, to, nil, make([]byte, 0), big.NewInt(0), big.NewInt(100), big.NewInt(50), &emptyAccessList) + return suite.CreateTestTx(msg, val, 1, false) + }, + expectPass: false, + }, + } + + dec := ante.NewRejectValidatorGrantedDecorator(suite.app.StakingKeeper) + for _, testCase := range testCases { + suite.Run(testCase.name, func() { + tx := testCase.malleate() + _, err := dec.AnteHandle(suite.ctx, tx, false, NextFn) + if testCase.expectPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + } + }) + } +} diff --git a/app/app.go b/app/app.go index 58f26fbd0..6e551b9a4 100644 --- a/app/app.go +++ b/app/app.go @@ -155,6 +155,7 @@ func New( EvmKeeper: myApp.EvmKeeper, FeeMarketKeeper: myApp.FeeMarketKeeper, IbcKeeper: myApp.IBCKeeper, + StakingKeeper: myApp.StakingKeeper, SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SigGasConsumer: fxante.DefaultSigVerificationGasConsumer, MaxTxGasWanted: maxGasWanted, diff --git a/app/encoding_test.go b/app/encoding_test.go index 7ea41c94e..c093e7250 100644 --- a/app/encoding_test.go +++ b/app/encoding_test.go @@ -37,13 +37,13 @@ func TestMakeEncodingConfig_RegisterInterfaces(t *testing.T) { count3++ t.Log(typeURLMap.Key()) } - assert.Equal(t, 258, count3) + assert.Equal(t, 260, count3) govContent := encodingConfig.InterfaceRegistry.ListImplementations("cosmos.gov.v1beta1.Content") assert.Equal(t, 14, len(govContent)) msgImplementations := encodingConfig.InterfaceRegistry.ListImplementations(sdk.MsgInterfaceProtoName) - assert.Equal(t, 99, len(msgImplementations)) + assert.Equal(t, 100, len(msgImplementations)) type govProposalMsg interface { GetAuthority() string diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index c38af9c88..db72f5bee 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -250,6 +250,10 @@ func NewAppKeeper( bApp.MsgServiceRouter(), appKeepers.AccountKeeper, ) + + // grant privileges + appKeepers.StakingKeeper = *appKeepers.StakingKeeper.SetAuthzKeeper(appKeepers.AuthzKeeper) + appKeepers.UpgradeKeeper = upgradekeeper.NewKeeper( skipUpgradeHeights, appKeepers.keys[upgradetypes.StoreKey], diff --git a/go.mod b/go.mod index 5d5913baf..b51c809b5 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.0.0-rc.0 github.com/armon/go-metrics v0.4.1 + github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cometbft/cometbft-db v0.7.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 @@ -61,7 +62,6 @@ require ( github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/btcsuite/btcd v0.23.4 // indirect - github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect diff --git a/proto/fx/staking/v1beta1/tx.proto b/proto/fx/staking/v1beta1/tx.proto new file mode 100644 index 000000000..4692f56bb --- /dev/null +++ b/proto/fx/staking/v1beta1/tx.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +package fx.staking.v1; + +import "google/protobuf/any.proto"; +import "cosmos_proto/cosmos.proto"; + +option go_package = "github.com/functionx/fx-core/x/staking/types"; + +//Msg defines the x/staking Msg service. +service Msg { + // GrantPrivilege defines a method for granting privilege to a validator. + rpc GrantPrivilege(MsgGrantPrivilege) returns (MsgGrantPrivilegeResponse); +} + +// MsgGrantPrivilege defines the GrantPrivilege message. +message MsgGrantPrivilege { + string validator_address = 1; // validator address + string from_address = 2; // from address + google.protobuf.Any to_pubkey = 3 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; // to pub_key + string signature = 4; // signature +} +message MsgGrantPrivilegeResponse {} \ No newline at end of file diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go new file mode 100644 index 000000000..34606bec7 --- /dev/null +++ b/x/staking/client/cli/tx.go @@ -0,0 +1,92 @@ +package cli + +import ( + "encoding/hex" + "fmt" + "strings" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" + "github.com/cosmos/cosmos-sdk/x/staking/client/cli" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/spf13/cobra" + + "github.com/functionx/fx-core/v5/x/staking/types" +) + +// NewTxCmd returns a root CLI command handler for all x/staking transaction commands. +func NewTxCmd() *cobra.Command { + stakingTxCmd := &cobra.Command{ + Use: stakingtypes.ModuleName, + Short: "Staking transaction subcommands", + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + stakingTxCmd.AddCommand( + cli.NewCreateValidatorCmd(), + cli.NewEditValidatorCmd(), + cli.NewDelegateCmd(), + cli.NewRedelegateCmd(), + cli.NewUnbondCmd(), + cli.NewCancelUnbondingDelegation(), + NewGrantPrivilegeCmd(), + ) + + return stakingTxCmd +} + +func NewGrantPrivilegeCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "grant-privilege [validator-address] [to-address]", + Short: "Grant validator privilege to an account", + Long: strings.TrimSpace( + fmt.Sprintf(`create a new grant authorization to an address to execute a transaction on validator: + +Examples: + $ %s tx %s grant-privilege fxvaloper1.. fx1.. --from=fx1.. + `, version.AppName, stakingtypes.ModuleName), + ), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + valAddr, err := sdk.ValAddressFromBech32(args[0]) + if err != nil { + return err + } + fromAddr := clientCtx.GetFromAddress() + toAddr, err := sdk.AccAddressFromBech32(args[1]) + if err != nil { + return err + } + toInfo, err := clientCtx.Keyring.KeyByAddress(toAddr) + if err != nil { + return err + } + // signature + sign, _, err := clientCtx.Keyring.Sign(toInfo.Name, types.GrantPrivilegeSignatureData(valAddr, fromAddr, toAddr)) + if err != nil { + return fmt.Errorf("sign grant privilege signature error %v", err) + } + msg := &types.MsgGrantPrivilege{ + ValidatorAddress: valAddr.String(), + FromAddress: fromAddr.String(), + ToPubkey: toInfo.PubKey, + Signature: hex.EncodeToString(sign), + } + if err = msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 74e313b5d..7948071bf 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -1,13 +1,21 @@ package keeper import ( + "time" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + + "github.com/functionx/fx-core/v5/x/staking/types" ) type Keeper struct { stakingkeeper.Keeper storeKey storetypes.StoreKey + + authzKeeper types.AuthzKeeper } // NewKeeper creates a new staking Keeper instance @@ -17,3 +25,60 @@ func NewKeeper(k stakingkeeper.Keeper, storeKey storetypes.StoreKey) Keeper { storeKey: storeKey, } } + +func (k *Keeper) SetAuthzKeeper(authzKeeper types.AuthzKeeper) *Keeper { + k.authzKeeper = authzKeeper + return k +} + +func (k Keeper) HasValidatorGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.ValAddress) bool { + operator, found := k.GetValidatorOperator(ctx, granter) + if !found { + return granter.Equals(grantee) + } + return operator.Equals(grantee) +} + +func (k Keeper) RevokeAuthorization(ctx sdk.Context, grantee, granter sdk.AccAddress) error { + authorizations, err := k.authzKeeper.GetAuthorizations(ctx, grantee, granter) + if err != nil { + return authz.ErrNoAuthorizationFound.Wrap(err.Error()) + } + for _, a := range authorizations { + if err = k.authzKeeper.DeleteGrant(ctx, grantee, granter, a.MsgTypeURL()); err != nil { + return err + } + } + return nil +} + +func (k Keeper) GrantAuthorization(ctx sdk.Context, grantee, granter sdk.AccAddress, auths []authz.Authorization, exp time.Time) error { + for _, a := range auths { + if err := k.authzKeeper.SaveGrant(ctx, grantee, granter, a, &exp); err != nil { + return err + } + } + return nil +} + +func (k Keeper) HasValidatorOperator(ctx sdk.Context, val sdk.ValAddress) bool { + store := ctx.KVStore(k.storeKey) + return store.Has(types.GetValidatorOperatorKey(val)) +} + +func (k Keeper) GetValidatorOperator(ctx sdk.Context, val sdk.ValAddress) (sdk.AccAddress, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GetValidatorOperatorKey(val)) + if bz == nil { + return nil, false + } + return bz, true +} + +func (k Keeper) UpdateValidatorOperator(ctx sdk.Context, val sdk.ValAddress, from sdk.AccAddress) { + store := ctx.KVStore(k.storeKey) + // remove old operator + store.Delete(types.GetValidatorOperatorKey(val)) + // add new operator + store.Set(types.GetValidatorOperatorKey(val), from.Bytes()) +} diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 81f4fb849..d3b423082 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -4,7 +4,14 @@ import ( "testing" sdkmath "cosmossdk.io/math" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/authz" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/stretchr/testify/suite" tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -12,6 +19,7 @@ import ( "github.com/functionx/fx-core/v5/app" "github.com/functionx/fx-core/v5/testutil/helpers" fxtypes "github.com/functionx/fx-core/v5/types" + "github.com/functionx/fx-core/v5/x/staking/types" ) type KeeperTestSuite struct { @@ -20,16 +28,24 @@ type KeeperTestSuite struct { ctx sdk.Context app *app.App signer *helpers.Signer + + valAccounts []authtypes.GenesisAccount } func TestKeeperTestSuite(t *testing.T) { + fxtypes.SetConfig(false) suite.Run(t, new(KeeperTestSuite)) } // Test helpers func (suite *KeeperTestSuite) SetupTest() { + suite.SetupSubTest() +} + +func (suite *KeeperTestSuite) SetupSubTest() { valNumber := tmrand.Intn(10) + 1 valSet, valAccounts, valBalances := helpers.GenerateGenesisValidator(valNumber, sdk.Coins{}) + suite.valAccounts = valAccounts suite.app = helpers.SetupWithGenesisValSet(suite.T(), valSet, valAccounts, valBalances...) suite.ctx = suite.app.NewContext(false, tmproto.Header{ @@ -41,3 +57,85 @@ func (suite *KeeperTestSuite) SetupTest() { suite.signer = helpers.NewSigner(helpers.NewEthPrivKey()) helpers.AddTestAddr(suite.app, suite.ctx, suite.signer.AccAddress(), sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(100).MulRaw(1e18)))) } + +func (suite *KeeperTestSuite) GenerateGrantPubkey() (cryptotypes.PrivKey, *codectypes.Any) { + priKey, _ := ethsecp256k1.GenerateKey() + pkAny, _ := codectypes.NewAnyWithValue(priKey.PubKey()) + return priKey, pkAny +} + +func (suite *KeeperTestSuite) GenerateConsKey() (cryptotypes.PrivKey, *codectypes.Any) { + priKey := ed25519.GenPrivKey() + pkAny, _ := codectypes.NewAnyWithValue(priKey.PubKey()) + return priKey, pkAny +} + +func (suite *KeeperTestSuite) TestHasValidatorGrant() { + val := sdk.ValAddress(suite.valAccounts[0].GetAddress()) + addr := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + + auth := suite.app.StakingKeeper.HasValidatorGrant(suite.ctx, addr, val) + suite.Require().False(auth) + + auth = suite.app.StakingKeeper.HasValidatorGrant(suite.ctx, sdk.AccAddress(val), val) + suite.Require().True(auth) + + suite.app.StakingKeeper.UpdateValidatorOperator(suite.ctx, val, addr) + + auth = suite.app.StakingKeeper.HasValidatorGrant(suite.ctx, addr, val) + suite.Require().True(auth) + + auth = suite.app.StakingKeeper.HasValidatorGrant(suite.ctx, sdk.AccAddress(val), val) + suite.Require().False(auth) +} + +func (suite *KeeperTestSuite) TestGrantRevokeAuthorization() { + addr1 := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + addr2 := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + + getAuths, err := suite.app.AuthzKeeper.GetAuthorizations(suite.ctx, addr2, addr1) + suite.Require().NoError(err) + suite.Require().Len(getAuths, 0) + + auths := make([]authz.Authorization, 0, 1) + a1 := authz.NewGenericAuthorization(sdk.MsgTypeURL(&banktypes.MsgSend{})) + auths = append(auths, a1) + err = suite.app.StakingKeeper.GrantAuthorization(suite.ctx, addr2, addr1, auths, types.GrantExpirationTime) + suite.Require().NoError(err) + + getAuths, err = suite.app.AuthzKeeper.GetAuthorizations(suite.ctx, addr2, addr1) + suite.Require().NoError(err) + suite.Require().Len(getAuths, 1) + suite.Require().Equal(sdk.MsgTypeURL(&banktypes.MsgSend{}), getAuths[0].MsgTypeURL()) + + err = suite.app.StakingKeeper.RevokeAuthorization(suite.ctx, addr2, addr1) + suite.Require().NoError(err) + + getAuths, err = suite.app.AuthzKeeper.GetAuthorizations(suite.ctx, addr2, addr1) + suite.Require().NoError(err) + suite.Require().Len(getAuths, 0) +} + +func (suite *KeeperTestSuite) TestValidatorOperator() { + val := sdk.ValAddress(suite.valAccounts[0].GetAddress()) + addr1 := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + addr2 := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + + found := suite.app.StakingKeeper.HasValidatorOperator(suite.ctx, val) + suite.Require().False(found) + + suite.app.StakingKeeper.UpdateValidatorOperator(suite.ctx, val, addr1) + + found = suite.app.StakingKeeper.HasValidatorOperator(suite.ctx, val) + suite.Require().True(found) + + operAddr, found := suite.app.StakingKeeper.GetValidatorOperator(suite.ctx, val) + suite.Require().True(found) + suite.Require().Equal(addr1, operAddr) + + suite.app.StakingKeeper.UpdateValidatorOperator(suite.ctx, val, addr2) + + operAddr, found = suite.app.StakingKeeper.GetValidatorOperator(suite.ctx, val) + suite.Require().True(found) + suite.Require().Equal(addr2, operAddr) +} diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go new file mode 100644 index 000000000..0f199524f --- /dev/null +++ b/x/staking/keeper/msg_server.go @@ -0,0 +1,58 @@ +package keeper + +import ( + "context" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/authz" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + "github.com/functionx/fx-core/v5/x/staking/types" +) + +var _ types.MsgServer = Keeper{} + +func (k Keeper) GrantPrivilege(goCtx context.Context, msg *types.MsgGrantPrivilege) (*types.MsgGrantPrivilegeResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + if err != nil { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) + } + fromAddr := sdk.MustAccAddressFromBech32(msg.FromAddress) + pk, err := types.ProtoAnyToAccountPubKey(msg.ToPubkey) + if err != nil { + return nil, err + } + toAddress := sdk.AccAddress(pk.Address()) + + // 1. validator + if _, found := k.GetValidator(ctx, valAddr); !found { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "validator %s not found", msg.ValidatorAddress) + } + // 2. from authorized + if !k.HasValidatorGrant(ctx, fromAddr, valAddr) { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "from address not authorized") + } + // 3. revoke old privilege + if err = k.RevokeAuthorization(ctx, fromAddr, sdk.AccAddress(valAddr)); err != nil { + return nil, err + } + // 4. grant new privilege + genericGrant := []authz.Authorization{authz.NewGenericAuthorization(sdk.MsgTypeURL(&authz.MsgGrant{}))} + if err = k.GrantAuthorization(ctx, toAddress, sdk.AccAddress(valAddr), genericGrant, types.GrantExpirationTime); err != nil { + return nil, err + } + // 5. update validator operator + k.UpdateValidatorOperator(ctx, valAddr, toAddress) + + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeGrantPrivilege, + sdk.NewAttribute(stakingtypes.AttributeKeyValidator, msg.ValidatorAddress), + sdk.NewAttribute(types.AttributeKeyFrom, msg.FromAddress), + sdk.NewAttribute(types.AttributeKeyTo, toAddress.String()), + )) + return &types.MsgGrantPrivilegeResponse{}, nil +} diff --git a/x/staking/keeper/msg_server_test.go b/x/staking/keeper/msg_server_test.go new file mode 100644 index 000000000..b29d67b40 --- /dev/null +++ b/x/staking/keeper/msg_server_test.go @@ -0,0 +1,239 @@ +package keeper_test + +import ( + "encoding/hex" + "fmt" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/staking/types" +) + +func (suite *KeeperTestSuite) TestGrantPrivilege() { + addrNotExist := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + testCase := []struct { + name string + malleate func() *types.MsgGrantPrivilege + expectPass bool + errMsg string + }{ + { + name: "success - secp256k1", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + valAddr := sdk.ValAddress(acc) + _, pkAny := suite.GenerateGrantPubkey() + return &types.MsgGrantPrivilege{ + ValidatorAddress: valAddr.String(), + FromAddress: acc.String(), + ToPubkey: pkAny, + } + }, + expectPass: true, + }, + { + name: "success - eth_secp256k1", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + valAddr := sdk.ValAddress(acc) + _, pkAny := suite.GenerateGrantPubkey() + return &types.MsgGrantPrivilege{ + ValidatorAddress: valAddr.String(), + FromAddress: acc.String(), + ToPubkey: pkAny, + } + }, + expectPass: true, + }, + { + name: "invalid validator address", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + return &types.MsgGrantPrivilege{ + ValidatorAddress: acc.String(), + FromAddress: acc.String(), + } + }, + expectPass: false, + errMsg: "invalid Bech32 prefix; expected fxvaloper, got fx: invalid address", + }, + { + name: "validator not found", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + _, pkAny := suite.GenerateGrantPubkey() + return &types.MsgGrantPrivilege{ + ValidatorAddress: sdk.ValAddress(addrNotExist).String(), + FromAddress: acc.String(), + ToPubkey: pkAny, + } + }, + expectPass: false, + errMsg: fmt.Sprintf("validator %s not found: unknown address", sdk.ValAddress(addrNotExist).String()), + }, + { + name: "from address not authorized", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + _, pkAny := suite.GenerateGrantPubkey() + return &types.MsgGrantPrivilege{ + ValidatorAddress: sdk.ValAddress(acc).String(), + FromAddress: addrNotExist.String(), + ToPubkey: pkAny, + } + }, + expectPass: false, + errMsg: "from address not authorized: unauthorized", + }, + { + name: "val not authorized", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + _, pkAny := suite.GenerateGrantPubkey() + msg := &types.MsgGrantPrivilege{ + ValidatorAddress: sdk.ValAddress(acc).String(), + FromAddress: acc.String(), + ToPubkey: pkAny, + } + _, err := suite.app.StakingKeeper.GrantPrivilege(sdk.WrapSDKContext(suite.ctx), msg) + suite.Require().NoError(err) + + return &types.MsgGrantPrivilege{ + ValidatorAddress: sdk.ValAddress(acc).String(), + FromAddress: acc.String(), + ToPubkey: pkAny, + } + }, + expectPass: false, + errMsg: "from address not authorized: unauthorized", + }, + { + name: "invalid pubkey - empty", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + valAddr := sdk.ValAddress(acc) + return &types.MsgGrantPrivilege{ + ValidatorAddress: valAddr.String(), + FromAddress: acc.String(), + ToPubkey: nil, + } + }, + expectPass: false, + errMsg: "empty pubkey: invalid pubkey", + }, + { + name: "invalid pubkey - invalid msg type", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + valAddr := sdk.ValAddress(acc) + pk, _ := codectypes.NewAnyWithValue(&banktypes.MsgSend{}) + return &types.MsgGrantPrivilege{ + ValidatorAddress: valAddr.String(), + FromAddress: acc.String(), + ToPubkey: pk, + } + }, + expectPass: false, + errMsg: "expecting cryptotypes.PubKey, got *types.MsgSend: invalid pubkey", + }, + { + name: "invalid pubkey - invalid key", + malleate: func() *types.MsgGrantPrivilege { + acc := suite.valAccounts[0].GetAddress() + valAddr := sdk.ValAddress(acc) + pk, _ := codectypes.NewAnyWithValue(ed25519.GenPrivKey().PubKey()) + return &types.MsgGrantPrivilege{ + ValidatorAddress: valAddr.String(), + FromAddress: acc.String(), + ToPubkey: pk, + } + }, + expectPass: false, + errMsg: "expecting *secp256k1.PubKey or *ethsecp256k1.PubKey, got *ed25519.PubKey: invalid pubkey", + }, + } + + for _, tc := range testCase { + suite.Run(tc.name, func() { + msg := tc.malleate() + _, err := suite.app.StakingKeeper.GrantPrivilege(sdk.WrapSDKContext(suite.ctx), msg) + if tc.expectPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + suite.Require().Equal(tc.errMsg, err.Error()) + } + }) + } +} + +func (suite *KeeperTestSuite) TestGrantAccount() { + key1 := helpers.NewPriKey() + key2 := helpers.NewPriKey() + eth3 := helpers.NewEthPrivKey() + eth4 := helpers.NewEthPrivKey() + + any1, _ := codectypes.NewAnyWithValue(key1.PubKey()) + any2, _ := codectypes.NewAnyWithValue(key2.PubKey()) + any3, _ := codectypes.NewAnyWithValue(eth3.PubKey()) + any4, _ := codectypes.NewAnyWithValue(eth4.PubKey()) + + addr1 := sdk.AccAddress(key1.PubKey().Address()) + addr2 := sdk.AccAddress(key2.PubKey().Address()) + addr3 := sdk.AccAddress(eth3.PubKey().Address()) + addr4 := sdk.AccAddress(eth4.PubKey().Address()) + + acc1 := suite.valAccounts[0].GetAddress() + valAddr1 := sdk.ValAddress(acc1) + + found := suite.app.StakingKeeper.HasValidatorOperator(suite.ctx, valAddr1) + suite.Require().False(found) + + // val1 grant to key1 + sign, err := key1.Sign(types.GrantPrivilegeSignatureData(valAddr1, acc1, addr1)) + suite.Require().NoError(err) + msgGrant := &types.MsgGrantPrivilege{FromAddress: acc1.String(), ToPubkey: any1, Signature: hex.EncodeToString(sign), ValidatorAddress: valAddr1.String()} + _, err = suite.app.StakingKeeper.GrantPrivilege(sdk.WrapSDKContext(suite.ctx), msgGrant) + suite.Require().NoError(err) + + operator, found := suite.app.StakingKeeper.GetValidatorOperator(suite.ctx, valAddr1) + suite.Require().True(found) + suite.Require().Equal(operator.String(), addr1.String()) + + // val1 grant key1 to key2 + sign, err = key2.Sign(types.GrantPrivilegeSignatureData(valAddr1, addr1, addr2)) + suite.Require().NoError(err) + msgGrant = &types.MsgGrantPrivilege{FromAddress: addr1.String(), ToPubkey: any2, Signature: hex.EncodeToString(sign), ValidatorAddress: valAddr1.String()} + _, err = suite.app.StakingKeeper.GrantPrivilege(sdk.WrapSDKContext(suite.ctx), msgGrant) + suite.Require().NoError(err) + + operator, found = suite.app.StakingKeeper.GetValidatorOperator(suite.ctx, valAddr1) + suite.Require().True(found) + suite.Require().Equal(operator.String(), addr2.String()) + + // val1 grant key2 to eth3 + sign, err = eth3.Sign(types.GrantPrivilegeSignatureData(valAddr1, addr2, addr3)) + suite.Require().NoError(err) + msgGrant = &types.MsgGrantPrivilege{FromAddress: addr2.String(), ToPubkey: any3, Signature: hex.EncodeToString(sign), ValidatorAddress: valAddr1.String()} + _, err = suite.app.StakingKeeper.GrantPrivilege(sdk.WrapSDKContext(suite.ctx), msgGrant) + suite.Require().NoError(err) + + operator, found = suite.app.StakingKeeper.GetValidatorOperator(suite.ctx, valAddr1) + suite.Require().True(found) + suite.Require().Equal(operator.String(), addr3.String()) + + // val1 grant eth3 to eth4 + sign, err = eth4.Sign(types.GrantPrivilegeSignatureData(valAddr1, addr3, addr4)) + suite.Require().NoError(err) + msgGrant = &types.MsgGrantPrivilege{FromAddress: addr3.String(), ToPubkey: any4, Signature: hex.EncodeToString(sign), ValidatorAddress: valAddr1.String()} + _, err = suite.app.StakingKeeper.GrantPrivilege(sdk.WrapSDKContext(suite.ctx), msgGrant) + suite.Require().NoError(err) + + operator, found = suite.app.StakingKeeper.GetValidatorOperator(suite.ctx, valAddr1) + suite.Require().True(found) + suite.Require().Equal(operator.String(), addr4.String()) +} diff --git a/x/staking/module.go b/x/staking/module.go index a07701a69..9e9bfa99a 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -6,14 +6,17 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" + fxstakingcli "github.com/functionx/fx-core/v5/x/staking/client/cli" "github.com/functionx/fx-core/v5/x/staking/keeper" - "github.com/functionx/fx-core/v5/x/staking/types" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) var ( @@ -28,17 +31,32 @@ type AppModuleBasic struct { // DefaultGenesis returns default genesis state as raw bytes for the staking // module. func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) + return cdc.MustMarshalJSON(fxstakingtypes.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the staking module. func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, bz json.RawMessage) error { - var data types.GenesisState + var data fxstakingtypes.GenesisState if err := cdc.UnmarshalJSON(bz, &data); err != nil { return fmt.Errorf("failed to unmarshal %s genesis state: %w", stakingtypes.ModuleName, err) } - return types.ValidateGenesis(&data) + return fxstakingtypes.ValidateGenesis(&data) +} + +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + stakingtypes.RegisterLegacyAminoCodec(cdc) + fxstakingtypes.RegisterLegacyAminoCodec(cdc) +} + +func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { + stakingtypes.RegisterInterfaces(registry) + fxstakingtypes.RegisterInterfaces(registry) +} + +// GetTxCmd returns the root tx command for the staking module. +func (AppModuleBasic) GetTxCmd() *cobra.Command { + return fxstakingcli.NewTxCmd() } type AppModule struct { @@ -57,10 +75,15 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak stakingtypes.Account } } +func (am AppModule) RegisterServices(cfg module.Configurator) { + fxstakingtypes.RegisterMsgServer(cfg.MsgServer(), am.Keeper) + am.AppModule.RegisterServices(cfg) +} + // InitGenesis performs genesis initialization for the staking module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState types.GenesisState + var genesisState fxstakingtypes.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) return am.Keeper.InitGenesis(ctx, &genesisState) diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go new file mode 100644 index 000000000..63b28a1b7 --- /dev/null +++ b/x/staking/types/codec.go @@ -0,0 +1,35 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" + authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" +) + +// ModuleCdc is the codec for the module +var ModuleCdc = codec.NewAminoCodec(codec.NewLegacyAmino()) + +func init() { + RegisterLegacyAminoCodec(ModuleCdc.LegacyAmino) + + // Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be + // used to properly serialize MsgGrant and MsgExec instances + RegisterLegacyAminoCodec(authzcodec.Amino) +} + +// RegisterInterfaces registers the client interfaces to protobuf Any. +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgGrantPrivilege{}, + ) + + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +// RegisterLegacyAminoCodec registers concrete types on the Amino codec +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgGrantPrivilege{}, "staking/MsgGrantPrivilege", nil) +} diff --git a/x/staking/types/events.go b/x/staking/types/events.go index 768c48bc3..d65e715f2 100644 --- a/x/staking/types/events.go +++ b/x/staking/types/events.go @@ -3,6 +3,7 @@ package types const ( EventTypeApproveShares = "approve_shares" EventTypeTransferShares = "transfer_shares" + EventTypeGrantPrivilege = "grant_privilege" AttributeKeyOwner = "owner" AttributeKeySpender = "spender" @@ -10,4 +11,5 @@ const ( AttributeKeyAmount = "amount" AttributeKeyFrom = "from" AttributeKeyRecipient = "recipient" + AttributeKeyTo = "to" ) diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go new file mode 100644 index 000000000..49f48ff1d --- /dev/null +++ b/x/staking/types/expected_keepers.go @@ -0,0 +1,15 @@ +package types + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" +) + +type AuthzKeeper interface { + SaveGrant(ctx sdk.Context, grantee, granter sdk.AccAddress, authorization authz.Authorization, expiration *time.Time) error + DeleteGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) error + GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress) ([]authz.Authorization, error) + GetAuthorization(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) (authz.Authorization, *time.Time) +} diff --git a/x/staking/types/keys.go b/x/staking/types/keys.go index 5d2df7d89..1183b4037 100644 --- a/x/staking/types/keys.go +++ b/x/staking/types/keys.go @@ -4,7 +4,12 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -var AllowanceKey = []byte{0x90} +const GrantPrivilegeSignaturePrefix = "GrantPrivilege:" + +var ( + AllowanceKey = []byte{0x90} + ValidatorOperatorKey = []byte{0x91} +) func GetAllowanceKey(valAddr sdk.ValAddress, owner, spender sdk.AccAddress) []byte { // key is of the form AllowanceKey || valAddrLen (1 byte) || valAddr || ownerAddrLen (1 byte) || ownerAddr || spenderAddrLen (1 byte) || spenderAddr @@ -20,3 +25,7 @@ func GetAllowanceKey(valAddr sdk.ValAddress, owner, spender sdk.AccAddress) []by return key } + +func GetValidatorOperatorKey(addr []byte) []byte { + return append(ValidatorOperatorKey, addr...) +} diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go new file mode 100644 index 000000000..1c7e0d4e1 --- /dev/null +++ b/x/staking/types/msg.go @@ -0,0 +1,122 @@ +package types + +import ( + "bytes" + "encoding/hex" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + errortypes "github.com/cosmos/cosmos-sdk/types/errors" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/evmos/ethermint/crypto/ethsecp256k1" +) + +const TypeMsgGrantPrivilege = "grant_privilege" + +var ( + _ sdk.Msg = &MsgGrantPrivilege{} + _ codectypes.UnpackInterfacesMessage = (*MsgGrantPrivilege)(nil) +) + +func NewMsgGrantPrivilege(val sdk.ValAddress, from sdk.AccAddress, pubKey cryptotypes.PubKey, signature string) (*MsgGrantPrivilege, error) { + var pkAny *codectypes.Any + if pubKey != nil { + var err error + if pkAny, err = codectypes.NewAnyWithValue(pubKey); err != nil { + return nil, err + } + } + return &MsgGrantPrivilege{ + ValidatorAddress: val.String(), + FromAddress: from.String(), + ToPubkey: pkAny, + Signature: signature, + }, nil +} + +func (m *MsgGrantPrivilege) Route() string { return stakingtypes.RouterKey } + +func (m *MsgGrantPrivilege) Type() string { return TypeMsgGrantPrivilege } + +func (m *MsgGrantPrivilege) ValidateBasic() error { + valAddr, err := sdk.ValAddressFromBech32(m.ValidatorAddress) + if err != nil { + return errortypes.ErrInvalidAddress.Wrapf("invalid validator address: %s", err) + } + fromAddress, err := sdk.AccAddressFromBech32(m.FromAddress) + if err != nil { + return errortypes.ErrInvalidAddress.Wrapf("invalid from address: %s", err) + } + + pk, err := ProtoAnyToAccountPubKey(m.ToPubkey) + if err != nil { + return err + } + toAddress := sdk.AccAddress(pk.Address()) + + // check same account + if bytes.Equal(fromAddress.Bytes(), toAddress.Bytes()) { + return errortypes.ErrInvalidRequest.Wrap("same account") + } + // check signature + if len(m.Signature) == 0 { + return errortypes.ErrInvalidRequest.Wrap("empty signature") + } + sig, err := hex.DecodeString(m.Signature) + if err != nil { + return errortypes.ErrInvalidRequest.Wrap("could not hex decode signature") + } + if !pk.VerifySignature(GrantPrivilegeSignatureData(valAddr, fromAddress, toAddress), sig) { + return errortypes.ErrInvalidRequest.Wrap("sig to pub key error") + } + return nil +} + +func (m *MsgGrantPrivilege) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) +} + +func (m *MsgGrantPrivilege) GetSigners() []sdk.AccAddress { + acc, err := sdk.AccAddressFromBech32(m.FromAddress) + if err != nil { + panic(err) + } + return []sdk.AccAddress{acc} +} + +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (m *MsgGrantPrivilege) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + var pubKey cryptotypes.PubKey + return unpacker.UnpackAny(m.ToPubkey, &pubKey) +} + +func ProtoAnyToAccountPubKey(any *codectypes.Any) (cryptotypes.PubKey, error) { + if any == nil { + return nil, errortypes.ErrInvalidPubKey.Wrap("empty pubkey") + } + pk, ok := any.GetCachedValue().(cryptotypes.PubKey) + if !ok { + return nil, errortypes.ErrInvalidPubKey.Wrapf("expecting cryptotypes.PubKey, got %T", any.GetCachedValue()) + } + _, ok1 := pk.(*secp256k1.PubKey) + _, ok2 := pk.(*ethsecp256k1.PubKey) + if !ok1 && !ok2 { + return nil, errortypes.ErrInvalidPubKey.Wrapf("expecting *secp256k1.PubKey or *ethsecp256k1.PubKey, got %T", pk) + } + return pk, nil +} + +func GrantPrivilegeSignatureData(val, from, to []byte) []byte { + prefixLen := len(GrantPrivilegeSignaturePrefix) + valLen := len(val) + fromLen := len(from) + toLen := len(to) + data := make([]byte, prefixLen+valLen+fromLen+toLen) + copy(data[:prefixLen], GrantPrivilegeSignaturePrefix) + copy(data[prefixLen:prefixLen+valLen], val) + copy(data[prefixLen+valLen:prefixLen+valLen+fromLen], from) + copy(data[prefixLen+valLen+fromLen:], to) + return data +} diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go new file mode 100644 index 000000000..5f555253b --- /dev/null +++ b/x/staking/types/msg_test.go @@ -0,0 +1,123 @@ +package types_test + +import ( + "encoding/hex" + "fmt" + "testing" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + sdk "github.com/cosmos/cosmos-sdk/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/evmos/ethermint/crypto/ethsecp256k1" + "github.com/stretchr/testify/require" + + "github.com/functionx/fx-core/v5/testutil/helpers" + "github.com/functionx/fx-core/v5/x/staking/types" +) + +func TestMsgGrantPrivilegeRoute(t *testing.T) { + val := sdk.ValAddress("val") + addr1 := sdk.AccAddress("from") + toKey := helpers.NewPriKey() + + msg, err := types.NewMsgGrantPrivilege(val, addr1, toKey.PubKey(), "signature") + require.NoError(t, err) + require.Equal(t, msg.Route(), stakingtypes.RouterKey) + require.Equal(t, msg.Type(), "grant_privilege") +} + +func TestMsgGrantPrivilegeValidation(t *testing.T) { + key1 := helpers.NewPriKey() + key2 := helpers.NewPriKey() + eth3 := helpers.NewEthPrivKey() + eth4 := helpers.NewEthPrivKey() + + any1, _ := codectypes.NewAnyWithValue(key1.PubKey()) + any2, _ := codectypes.NewAnyWithValue(key2.PubKey()) + any3, _ := codectypes.NewAnyWithValue(eth3.PubKey()) + any4, _ := codectypes.NewAnyWithValue(eth4.PubKey()) + + val := sdk.ValAddress(key1.PubKey().Address()) + addr1 := sdk.AccAddress(key1.PubKey().Address()) + addr2 := sdk.AccAddress(key2.PubKey().Address()) + addr3 := sdk.AccAddress(eth3.PubKey().Address()) + addr4 := sdk.AccAddress(eth4.PubKey().Address()) + + addr1addr2Sign, err := key2.Sign(types.GrantPrivilegeSignatureData(val, addr1, addr2)) + require.NoError(t, err) + + addr1addr3Sign, err := eth3.Sign(types.GrantPrivilegeSignatureData(val, addr1, addr3)) + require.NoError(t, err) + + addr3addr4Sign, err := eth4.Sign(types.GrantPrivilegeSignatureData(val, addr3, addr4)) + require.NoError(t, err) + + invalidAddr := "xxxxxxxxxxxx" + invalidPK, _ := codectypes.NewAnyWithValue(&banktypes.MsgSend{}) + invalidPKType, _ := codectypes.NewAnyWithValue(ed25519.GenPrivKey().PubKey()) + emptySign := "" + invalidSign := "xx xxx" + + cases := []struct { + name string + expectedErr string // empty means no error expected + msg *types.MsgGrantPrivilege + }{ + {"valid grant to acc address", "", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: any2, Signature: hex.EncodeToString(addr1addr2Sign)}}, + {"valid grant to eth address", "", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: any3, Signature: hex.EncodeToString(addr1addr3Sign)}}, + {"valid grant eth to eth address", "", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr3.String(), ToPubkey: any4, Signature: hex.EncodeToString(addr3addr4Sign)}}, + + {"empty validator address", "invalid validator address: empty address string is not allowed: invalid address", &types.MsgGrantPrivilege{ValidatorAddress: "", FromAddress: addr1.String(), ToPubkey: any2, Signature: hex.EncodeToString(addr1addr2Sign)}}, + {"invalid validator address", "invalid validator address: decoding bech32 failed: invalid separator index -1: invalid address", &types.MsgGrantPrivilege{FromAddress: addr1.String(), ToPubkey: any2, Signature: hex.EncodeToString(addr1addr2Sign), ValidatorAddress: invalidAddr}}, + + {"empty from address", "invalid from address: empty address string is not allowed: invalid address", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: "", ToPubkey: any2, Signature: hex.EncodeToString(addr1addr2Sign)}}, + {"invalid from address", "invalid from address: decoding bech32 failed: invalid separator index -1: invalid address", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: invalidAddr, ToPubkey: any2, Signature: hex.EncodeToString(addr1addr2Sign)}}, + + {"empty pubkey", "empty pubkey: invalid pubkey", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: nil, Signature: hex.EncodeToString(addr1addr2Sign)}}, + {"invalid pubkey type", "expecting cryptotypes.PubKey, got *types.MsgSend: invalid pubkey", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: invalidPK, Signature: hex.EncodeToString(addr1addr2Sign)}}, + {"invalid pubkey key type", "expecting *secp256k1.PubKey or *ethsecp256k1.PubKey, got *ed25519.PubKey: invalid pubkey", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: invalidPKType, Signature: hex.EncodeToString(addr1addr2Sign)}}, + + {"same from and to address", "same account: invalid request", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: any1, Signature: hex.EncodeToString(addr1addr2Sign)}}, + + {"empty signature", "empty signature: invalid request", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: any2, Signature: emptySign}}, + {"invalid signature", "could not hex decode signature: invalid request", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: any2, Signature: invalidSign}}, + {"signature key not equal to address", "sig to pub key error: invalid request", &types.MsgGrantPrivilege{ValidatorAddress: val.String(), FromAddress: addr1.String(), ToPubkey: any2, Signature: hex.EncodeToString(addr1addr3Sign)}}, + } + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + err := tc.msg.ValidateBasic() + if tc.expectedErr == "" { + require.Nil(t, err) + } else { + require.EqualError(t, err, tc.expectedErr) + } + }) + } +} + +func TestMsgGrantPrivilegeGetSignBytes(t *testing.T) { + val := sdk.ValAddress("val") + addr1 := sdk.AccAddress("input") + bz, _ := hex.DecodeString("0370c5fe92d864015703aff6d2f3a5608c3740e368370f0c25f090abc2e368b0be") + toPk := ðsecp256k1.PubKey{Key: bz} + sign := "0x1" + + msg, err := types.NewMsgGrantPrivilege(val, addr1, toPk, sign) + require.NoError(t, err) + + res := msg.GetSignBytes() + expected := `{"type":"staking/MsgGrantPrivilege","value":{"from_address":"cosmos1d9h8qat57ljhcm","signature":"0x1","to_pubkey":"A3DF/pLYZAFXA6/20vOlYIw3QONoNw8MJfCQq8LjaLC+","validator_address":"cosmosvaloper1weskc8rudzy"}}` + require.Equal(t, expected, string(res)) +} + +func TestMsgGrantPrivilegeGetSigners(t *testing.T) { + toKey := helpers.NewEthPrivKey() + msg, err := types.NewMsgGrantPrivilege(sdk.ValAddress{}, []byte("input111111111111111"), toKey.PubKey(), "") + require.NoError(t, err) + + res := msg.GetSigners() + require.Equal(t, fmt.Sprintf("%v", res), "[696E707574313131313131313131313131313131]") +} diff --git a/x/staking/types/params.go b/x/staking/types/params.go new file mode 100644 index 000000000..f10fe918e --- /dev/null +++ b/x/staking/types/params.go @@ -0,0 +1,7 @@ +package types + +import "time" + +// GrantExpirationTime period ends at Max Time supported by Amino +// (Dec 31, 9999 - 23:59:59 GMT). +var GrantExpirationTime = time.Unix(253402300799, 0) diff --git a/x/staking/types/tx.pb.go b/x/staking/types/tx.pb.go new file mode 100644 index 000000000..2ae63e1e1 --- /dev/null +++ b/x/staking/types/tx.pb.go @@ -0,0 +1,698 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: fx/staking/v1beta1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-proto" + types "github.com/cosmos/cosmos-sdk/codec/types" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgGrantPrivilege defines the GrantPrivilege message. +type MsgGrantPrivilege struct { + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + FromAddress string `protobuf:"bytes,2,opt,name=from_address,json=fromAddress,proto3" json:"from_address,omitempty"` + ToPubkey *types.Any `protobuf:"bytes,3,opt,name=to_pubkey,json=toPubkey,proto3" json:"to_pubkey,omitempty"` + Signature string `protobuf:"bytes,4,opt,name=signature,proto3" json:"signature,omitempty"` +} + +func (m *MsgGrantPrivilege) Reset() { *m = MsgGrantPrivilege{} } +func (m *MsgGrantPrivilege) String() string { return proto.CompactTextString(m) } +func (*MsgGrantPrivilege) ProtoMessage() {} +func (*MsgGrantPrivilege) Descriptor() ([]byte, []int) { + return fileDescriptor_1c6db236fc9c571c, []int{0} +} +func (m *MsgGrantPrivilege) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgGrantPrivilege) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgGrantPrivilege.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgGrantPrivilege) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGrantPrivilege.Merge(m, src) +} +func (m *MsgGrantPrivilege) XXX_Size() int { + return m.Size() +} +func (m *MsgGrantPrivilege) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGrantPrivilege.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgGrantPrivilege proto.InternalMessageInfo + +func (m *MsgGrantPrivilege) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +func (m *MsgGrantPrivilege) GetFromAddress() string { + if m != nil { + return m.FromAddress + } + return "" +} + +func (m *MsgGrantPrivilege) GetToPubkey() *types.Any { + if m != nil { + return m.ToPubkey + } + return nil +} + +func (m *MsgGrantPrivilege) GetSignature() string { + if m != nil { + return m.Signature + } + return "" +} + +type MsgGrantPrivilegeResponse struct { +} + +func (m *MsgGrantPrivilegeResponse) Reset() { *m = MsgGrantPrivilegeResponse{} } +func (m *MsgGrantPrivilegeResponse) String() string { return proto.CompactTextString(m) } +func (*MsgGrantPrivilegeResponse) ProtoMessage() {} +func (*MsgGrantPrivilegeResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1c6db236fc9c571c, []int{1} +} +func (m *MsgGrantPrivilegeResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgGrantPrivilegeResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgGrantPrivilegeResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgGrantPrivilegeResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgGrantPrivilegeResponse.Merge(m, src) +} +func (m *MsgGrantPrivilegeResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgGrantPrivilegeResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgGrantPrivilegeResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgGrantPrivilegeResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgGrantPrivilege)(nil), "fx.staking.v1.MsgGrantPrivilege") + proto.RegisterType((*MsgGrantPrivilegeResponse)(nil), "fx.staking.v1.MsgGrantPrivilegeResponse") +} + +func init() { proto.RegisterFile("fx/staking/v1beta1/tx.proto", fileDescriptor_1c6db236fc9c571c) } + +var fileDescriptor_1c6db236fc9c571c = []byte{ + // 353 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xcf, 0x4e, 0xea, 0x40, + 0x14, 0xc6, 0xe9, 0xe5, 0xe6, 0xe6, 0x32, 0xa8, 0x91, 0x86, 0x45, 0x01, 0xd3, 0x20, 0x2b, 0x12, + 0x65, 0x26, 0xe0, 0x13, 0xc0, 0x42, 0x17, 0x84, 0x84, 0xb0, 0x34, 0x26, 0x64, 0x5a, 0xa6, 0xe3, + 0x04, 0x98, 0xd3, 0xcc, 0x4c, 0x9b, 0xf6, 0x2d, 0x7c, 0x18, 0x1f, 0xc2, 0xb8, 0x30, 0x2c, 0x5d, + 0x1a, 0x78, 0x11, 0x63, 0xcb, 0x9f, 0x28, 0x0b, 0x97, 0xe7, 0xfb, 0x7e, 0x33, 0xe7, 0x3b, 0xe7, + 0xa0, 0x46, 0x90, 0x10, 0x6d, 0xe8, 0x5c, 0x48, 0x4e, 0xe2, 0xae, 0xc7, 0x0c, 0xed, 0x12, 0x93, + 0xe0, 0x50, 0x81, 0x01, 0xfb, 0x34, 0x48, 0xf0, 0xd6, 0xc4, 0x71, 0xb7, 0x5e, 0xe3, 0x00, 0x7c, + 0xc1, 0x48, 0x66, 0x7a, 0x51, 0x40, 0xa8, 0x4c, 0x73, 0xb2, 0x5e, 0xf3, 0x41, 0x2f, 0x41, 0x4f, + 0xb3, 0x8a, 0xe4, 0x45, 0x6e, 0xb5, 0xde, 0x2c, 0x54, 0x19, 0x69, 0x7e, 0xa7, 0xa8, 0x34, 0x63, + 0x25, 0x62, 0xb1, 0x60, 0x9c, 0xd9, 0x57, 0xa8, 0x12, 0xd3, 0x85, 0x98, 0x51, 0x03, 0x6a, 0x4a, + 0x67, 0x33, 0xc5, 0xb4, 0x76, 0xac, 0xa6, 0xd5, 0x2e, 0x4d, 0xce, 0xf7, 0x46, 0x3f, 0xd7, 0xed, + 0x4b, 0x74, 0x12, 0x28, 0x58, 0xee, 0xb9, 0x3f, 0x19, 0x57, 0xfe, 0xd2, 0x76, 0xc8, 0x10, 0x95, + 0x0c, 0x4c, 0xc3, 0xc8, 0x9b, 0xb3, 0xd4, 0x29, 0x36, 0xad, 0x76, 0xb9, 0x57, 0xc5, 0x79, 0x5e, + 0xbc, 0xcb, 0x8b, 0xfb, 0x32, 0x1d, 0x38, 0xaf, 0xcf, 0x9d, 0xea, 0x36, 0xa0, 0xaf, 0xd2, 0xd0, + 0x00, 0x1e, 0x47, 0xde, 0x90, 0xa5, 0x93, 0xff, 0x06, 0xc6, 0xd9, 0x7b, 0xfb, 0x02, 0x95, 0xb4, + 0xe0, 0x92, 0x9a, 0x48, 0x31, 0xe7, 0x6f, 0xd6, 0xec, 0x20, 0xb4, 0x1a, 0xa8, 0x76, 0x34, 0xcf, + 0x84, 0xe9, 0x10, 0xa4, 0x66, 0x3d, 0x1f, 0x15, 0x47, 0x9a, 0xdb, 0x0f, 0xe8, 0xec, 0xc7, 0xc0, + 0x4d, 0xfc, 0x6d, 0x99, 0xf8, 0xe8, 0x8b, 0x7a, 0xfb, 0x37, 0x62, 0xd7, 0x64, 0x70, 0xfb, 0xb2, + 0x76, 0xad, 0xd5, 0xda, 0xb5, 0x3e, 0xd6, 0xae, 0xf5, 0xb4, 0x71, 0x0b, 0xab, 0x8d, 0x5b, 0x78, + 0xdf, 0xb8, 0x85, 0xfb, 0x6b, 0x2e, 0xcc, 0x63, 0xe4, 0x61, 0x1f, 0x96, 0x24, 0x88, 0xa4, 0x6f, + 0x04, 0xc8, 0x84, 0x04, 0x49, 0xc7, 0x07, 0xc5, 0xc8, 0xe1, 0xd4, 0x26, 0x0d, 0x99, 0xf6, 0xfe, + 0x65, 0x9b, 0xb9, 0xf9, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x1c, 0xc7, 0x5f, 0xe7, 0x05, 0x02, 0x00, + 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // GrantPrivilege defines a method for granting privilege to a validator. + GrantPrivilege(ctx context.Context, in *MsgGrantPrivilege, opts ...grpc.CallOption) (*MsgGrantPrivilegeResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) GrantPrivilege(ctx context.Context, in *MsgGrantPrivilege, opts ...grpc.CallOption) (*MsgGrantPrivilegeResponse, error) { + out := new(MsgGrantPrivilegeResponse) + err := c.cc.Invoke(ctx, "/fx.staking.v1.Msg/GrantPrivilege", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // GrantPrivilege defines a method for granting privilege to a validator. + GrantPrivilege(context.Context, *MsgGrantPrivilege) (*MsgGrantPrivilegeResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) GrantPrivilege(ctx context.Context, req *MsgGrantPrivilege) (*MsgGrantPrivilegeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GrantPrivilege not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_GrantPrivilege_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgGrantPrivilege) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).GrantPrivilege(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/fx.staking.v1.Msg/GrantPrivilege", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).GrantPrivilege(ctx, req.(*MsgGrantPrivilege)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "fx.staking.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GrantPrivilege", + Handler: _Msg_GrantPrivilege_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "fx/staking/v1beta1/tx.proto", +} + +func (m *MsgGrantPrivilege) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgGrantPrivilege) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgGrantPrivilege) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signature) > 0 { + i -= len(m.Signature) + copy(dAtA[i:], m.Signature) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signature))) + i-- + dAtA[i] = 0x22 + } + if m.ToPubkey != nil { + { + size, err := m.ToPubkey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.FromAddress) > 0 { + i -= len(m.FromAddress) + copy(dAtA[i:], m.FromAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.FromAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgGrantPrivilegeResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgGrantPrivilegeResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgGrantPrivilegeResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgGrantPrivilege) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.FromAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.ToPubkey != nil { + l = m.ToPubkey.Size() + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Signature) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgGrantPrivilegeResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgGrantPrivilege) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgGrantPrivilege: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgGrantPrivilege: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field FromAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.FromAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToPubkey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.ToPubkey == nil { + m.ToPubkey = &types.Any{} + } + if err := m.ToPubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signature", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signature = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgGrantPrivilegeResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgGrantPrivilegeResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgGrantPrivilegeResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) From 3bd787476d123e7c41dbf5a9b7cc75a3415b428d Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Fri, 7 Jul 2023 17:42:00 +0800 Subject: [PATCH 06/30] feat: staking edit consensus key * MsgEditConsensusKey --- app/encoding_test.go | 4 +- app/keepers/keepers.go | 4 +- go.mod | 2 +- proto/fx/staking/v1beta1/tx.proto | 13 +- x/staking/client/cli/tx.go | 45 ++- x/staking/keeper/abci.go | 148 +++++++++ x/staking/keeper/abci_test.go | 63 ++++ x/staking/keeper/keeper.go | 129 +++++++- x/staking/keeper/keeper_test.go | 6 +- x/staking/keeper/msg_server.go | 64 ++++ x/staking/keeper/msg_server_test.go | 133 ++++++++ x/staking/module.go | 6 + x/staking/types/codec.go | 2 + x/staking/types/events.go | 8 +- x/staking/types/expected_keepers.go | 10 + x/staking/types/keys.go | 35 +- x/staking/types/msg.go | 57 +++- x/staking/types/msg_test.go | 104 ++++++ x/staking/types/tx.pb.go | 490 ++++++++++++++++++++++++++-- 19 files changed, 1281 insertions(+), 42 deletions(-) create mode 100644 x/staking/keeper/abci.go create mode 100644 x/staking/keeper/abci_test.go diff --git a/app/encoding_test.go b/app/encoding_test.go index c093e7250..dcf6dd742 100644 --- a/app/encoding_test.go +++ b/app/encoding_test.go @@ -37,13 +37,13 @@ func TestMakeEncodingConfig_RegisterInterfaces(t *testing.T) { count3++ t.Log(typeURLMap.Key()) } - assert.Equal(t, 260, count3) + assert.Equal(t, 262, count3) govContent := encodingConfig.InterfaceRegistry.ListImplementations("cosmos.gov.v1beta1.Content") assert.Equal(t, 14, len(govContent)) msgImplementations := encodingConfig.InterfaceRegistry.ListImplementations(sdk.MsgInterfaceProtoName) - assert.Equal(t, 100, len(msgImplementations)) + assert.Equal(t, 101, len(msgImplementations)) type govProposalMsg interface { GetAuthority() string diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index db72f5bee..f4aebfecb 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -202,7 +202,7 @@ func NewAppKeeper( appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.GetSubspace(stakingtypes.ModuleName), - ), appKeepers.keys[stakingtypes.StoreKey]) + ), appKeepers.keys[stakingtypes.StoreKey], appCodec) appKeepers.MintKeeper = mintkeeper.NewKeeper( appCodec, @@ -228,6 +228,8 @@ func NewAppKeeper( &appKeepers.StakingKeeper, appKeepers.GetSubspace(slashingtypes.ModuleName), ) + appKeepers.StakingKeeper = *appKeepers.StakingKeeper.SetSlashingKeeper(appKeepers.SlashingKeeper) + appKeepers.CrisisKeeper = crisiskeeper.NewKeeper( appKeepers.GetSubspace(crisistypes.ModuleName), invCheckPeriod, diff --git a/go.mod b/go.mod index b51c809b5..5d5913baf 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.0.0-rc.0 github.com/armon/go-metrics v0.4.1 - github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce github.com/cometbft/cometbft-db v0.7.0 github.com/cosmos/cosmos-proto v1.0.0-beta.3 @@ -62,6 +61,7 @@ require ( github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect github.com/btcsuite/btcd v0.23.4 // indirect + github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/btcutil v1.1.3 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect diff --git a/proto/fx/staking/v1beta1/tx.proto b/proto/fx/staking/v1beta1/tx.proto index 4692f56bb..eadb6b43a 100644 --- a/proto/fx/staking/v1beta1/tx.proto +++ b/proto/fx/staking/v1beta1/tx.proto @@ -10,6 +10,9 @@ option go_package = "github.com/functionx/fx-core/x/staking/types"; service Msg { // GrantPrivilege defines a method for granting privilege to a validator. rpc GrantPrivilege(MsgGrantPrivilege) returns (MsgGrantPrivilegeResponse); + + // EditConsensusKey defines a method for editing consensus pubkey of a validator. + rpc EditConsensusPubKey(MsgEditConsensusPubKey) returns (MsgEditConsensusPubKeyResponse); } // MsgGrantPrivilege defines the GrantPrivilege message. @@ -19,4 +22,12 @@ message MsgGrantPrivilege { google.protobuf.Any to_pubkey = 3 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; // to pub_key string signature = 4; // signature } -message MsgGrantPrivilegeResponse {} \ No newline at end of file +message MsgGrantPrivilegeResponse {} + +message MsgEditConsensusPubKey { + string validator_address = 1; + string from = 2; + google.protobuf.Any pubkey = 3 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"]; +} + +message MsgEditConsensusPubKeyResponse{} \ No newline at end of file diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index 34606bec7..de8cab57c 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/tx" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/version" "github.com/cosmos/cosmos-sdk/x/staking/client/cli" @@ -35,6 +36,7 @@ func NewTxCmd() *cobra.Command { cli.NewUnbondCmd(), cli.NewCancelUnbondingDelegation(), NewGrantPrivilegeCmd(), + NewEditConsensusPubKeyCmd(), ) return stakingTxCmd @@ -49,8 +51,7 @@ func NewGrantPrivilegeCmd() *cobra.Command { Examples: $ %s tx %s grant-privilege fxvaloper1.. fx1.. --from=fx1.. - `, version.AppName, stakingtypes.ModuleName), - ), + `, version.AppName, stakingtypes.ModuleName)), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientTxContext(cmd) @@ -90,3 +91,43 @@ Examples: flags.AddTxFlagsToCmd(cmd) return cmd } + +func NewEditConsensusPubKeyCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "edit-consensus-pubkey [validator-address] [pubkey]", + Short: "Edit an existing validator consensus public key", + Long: strings.TrimSpace( + fmt.Sprintf(`edit an existing validator consensus public key: + +Examples: + $ %s tx %s edit-consensus-pubkey fxvaloper1.. '{"@type":"/cosmos.crypto.ed25519.PubKey","key":"...."}' --from=fx1.. + `, version.AppName, stakingtypes.ModuleName)), + Args: cobra.ExactArgs(2), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + valAddr, err := sdk.ValAddressFromBech32(args[0]) + if err != nil { + return err + } + fromAddr := clientCtx.GetFromAddress() + var pk cryptotypes.PubKey + if err := clientCtx.Codec.UnmarshalInterfaceJSON([]byte(args[1]), &pk); err != nil { + return err + } + + msg, err := types.NewMsgEditConsensusPubKey(valAddr, fromAddr, pk) + if err != nil { + return err + } + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go new file mode 100644 index 000000000..bb0b8b6ea --- /dev/null +++ b/x/staking/keeper/abci.go @@ -0,0 +1,148 @@ +package keeper + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/staking" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/proto/tendermint/crypto" +) + +func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { + valUpdates := staking.EndBlocker(ctx, k.Keeper) + // remove consensus record after consensus update + k.RemoveValidatorConsensusKey(ctx) + // update validator consensus after abci update + k.UpdateValidatorConsensusKey(ctx) + // abci validator update + return k.ABCIValidatorUpdate(ctx, valUpdates) +} + +// RemoveValidatorConsensusKey delete validator record after UpdateValidatorConsensusKey +func (k Keeper) RemoveValidatorConsensusKey(ctx sdk.Context) { + k.IteratorValidatorDelConsensusAddr(ctx, func(valAddr sdk.ValAddress, delConsAddr sdk.ConsAddress) bool { + // remove del consensus address record + k.RemoveValidatorDelConsensusAddr(ctx, valAddr) + + // delete validator by old consensus address + k.RemoveValidatorOperatorByConsAddr(ctx, delConsAddr) + + // todo delete old consensus pubkey + + // todo delete old validator signing info + + return false + }) +} + +// UpdateValidatorConsensusKey update validator consensus pubkey after ABCIValidatorUpdate +func (k Keeper) UpdateValidatorConsensusKey(ctx sdk.Context) { + k.IteratorValidatorOldConsensusAddr(ctx, func(valAddr sdk.ValAddress, oldConsAddr sdk.ConsAddress) bool { + // delete old consensus address record + k.RemoveValidatorOldConsensusAddr(ctx, valAddr) + + // update validator consensus pubkey + newPubkey, found := k.GetValidatorNewConsensusPubKey(ctx, valAddr) + if !found { + return false + } + + // delete new consensus pubkey record + k.RemoveValidatorNewConsensusPubKey(ctx, valAddr) + + // update validator consensus pubkey + validator, found := k.GetValidator(ctx, valAddr) + if !found { + return false + } + newConsAddr := sdk.ConsAddress(newPubkey.Address()) + pkAny, err := codectypes.NewAnyWithValue(newPubkey) + if err != nil { + panic(err) + } + validator.ConsensusPubkey = pkAny + k.SetValidator(ctx, validator) + + // add consensus pubkey record + if err = k.slashingKeeper.AddPubkey(ctx, newPubkey); err != nil { + panic(err) + } + + // Update the signing info start height or create a new signing info + signingInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) + if !found { + panic("expected signing info to be found") + } + signingInfo.Address = newConsAddr.String() + k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, signingInfo) + + // set del consensus address + k.SetValidatorDelConsensusAddr(ctx, valAddr, oldConsAddr) + return false + }) +} + +// ABCIValidatorUpdate update old consensus pubkey to zero power, add new consensus pubkey to validator power +func (k Keeper) ABCIValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpdate) []abci.ValidatorUpdate { + proposer := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress) + + pkPower := make(map[crypto.PublicKey]int64, len(valUpdates)) + for _, valUpdate := range valUpdates { + pkPower[valUpdate.PubKey] = valUpdate.Power + } + + pkUpdate := make([]abci.ValidatorUpdate, 0, 50) + k.IteratorValidatorNewConsensusPubKey(ctx, func(valAddr sdk.ValAddress, newPubKey cryptotypes.PubKey) bool { + validator, found := k.GetValidator(ctx, valAddr) + if !found { + // validator not found, remove new pubkey update + k.RemoveValidatorNewConsensusPubKey(ctx, valAddr) + return false + } + + oldPubKey, err := validator.ConsPubKey() + if err != nil { + panic(err) + } + oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) + // if validator is proposer, skip this block + if oldConsAddr.Equals(proposer) { + return false + } + oldTmPk, err := cryptocodec.ToTmProtoPublicKey(oldPubKey) + if err != nil { + panic(err) + } + newTmPk, err := cryptocodec.ToTmProtoPublicKey(newPubKey) + if err != nil { + panic(err) + } + + power, ok := pkPower[oldTmPk] + // if power not found, use validator power + if !ok { + power = validator.ConsensusPower(k.PowerReduction(ctx)) + } + // set old tmPk power to 0, remove + pkUpdate = append(pkUpdate, abci.ValidatorUpdate{PubKey: oldTmPk, Power: 0}) + // add new tmPk with power + pkUpdate = append(pkUpdate, abci.ValidatorUpdate{PubKey: newTmPk, Power: power}) + + newConsAddr := sdk.ConsAddress(newPubKey.Address()) + // set new consensus address with validator + k.SetValidatorOperatorByConsAddr(ctx, newConsAddr, validator.GetOperator()) + // record validator new consensus address + k.SetValidatorOldConsensusAddr(ctx, valAddr, oldConsAddr) + return false + }) + + // joint pkPower and pkUpdate + newValUpdates := make([]abci.ValidatorUpdate, 0, len(pkPower)+len(pkUpdate)) + for tmPk, power := range pkPower { + newValUpdates = append(newValUpdates, abci.ValidatorUpdate{PubKey: tmPk, Power: power}) + } + newValUpdates = append(newValUpdates, pkUpdate...) + return newValUpdates +} diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go new file mode 100644 index 000000000..f45f470e4 --- /dev/null +++ b/x/staking/keeper/abci_test.go @@ -0,0 +1,63 @@ +package keeper_test + +import ( + "time" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + abci "github.com/tendermint/tendermint/abci/types" +) + +func (suite *KeeperTestSuite) TestABCIValidatorUpdates() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + _, tmAny := suite.GenerateConsKey() + pk, ok := tmAny.GetCachedValue().(cryptotypes.PubKey) + suite.Require().True(ok) + err := suite.app.StakingKeeper.SetValidatorNewConsensusPubKey(suite.ctx, valAddr, pk) + suite.Require().NoError(err) + + updates := suite.app.StakingKeeper.ABCIValidatorUpdate(suite.ctx, []abci.ValidatorUpdate{}) + + suite.Require().Len(updates, 2) +} + +func (suite *KeeperTestSuite) TestUpdateValidatorConsensus() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + consAddr, err := validator.GetConsAddr() + suite.Require().NoError(err) + suite.app.SlashingKeeper.SetValidatorSigningInfo(suite.ctx, consAddr, slashingtypes.NewValidatorSigningInfo(consAddr, 0, 0, time.UnixMicro(0), false, 0)) + + _, tmAny := suite.GenerateConsKey() + pk, ok := tmAny.GetCachedValue().(cryptotypes.PubKey) + suite.Require().True(ok) + err = suite.app.StakingKeeper.SetValidatorNewConsensusPubKey(suite.ctx, valAddr, pk) + suite.Require().NoError(err) + suite.app.StakingKeeper.SetValidatorOldConsensusAddr(suite.ctx, valAddr, consAddr) + + suite.app.StakingKeeper.UpdateValidatorConsensusKey(suite.ctx) + + _, found = suite.app.StakingKeeper.GetValidatorNewConsensusPubKey(suite.ctx, valAddr) + suite.Require().False(found) + valNew, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + valPk, err := valNew.ConsPubKey() + suite.Require().NoError(err) + suite.Require().Equal(pk.Address(), valPk.Address()) +} + +func (suite *KeeperTestSuite) TestRemoveValidatorConsensusKey() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + consAddr, err := validator.GetConsAddr() + suite.Require().NoError(err) + suite.app.StakingKeeper.SetValidatorDelConsensusAddr(suite.ctx, valAddr, consAddr) + + suite.app.StakingKeeper.RemoveValidatorConsensusKey(suite.ctx) + + _, found = suite.app.StakingKeeper.GetValidatorByConsAddr(suite.ctx, consAddr) + suite.Require().False(found) +} diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 7948071bf..b6adb6ae3 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -3,10 +3,14 @@ package keeper import ( "time" + "github.com/cosmos/cosmos-sdk/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/functionx/fx-core/v5/x/staking/types" ) @@ -14,18 +18,26 @@ import ( type Keeper struct { stakingkeeper.Keeper storeKey storetypes.StoreKey + cdc codec.Codec - authzKeeper types.AuthzKeeper + authzKeeper types.AuthzKeeper + slashingKeeper types.SlashingKeeper } // NewKeeper creates a new staking Keeper instance -func NewKeeper(k stakingkeeper.Keeper, storeKey storetypes.StoreKey) Keeper { +func NewKeeper(k stakingkeeper.Keeper, storeKey storetypes.StoreKey, cdc codec.Codec) Keeper { return Keeper{ Keeper: k, storeKey: storeKey, + cdc: cdc, } } +func (k *Keeper) SetSlashingKeeper(slashingKeeper types.SlashingKeeper) *Keeper { + k.slashingKeeper = slashingKeeper + return k +} + func (k *Keeper) SetAuthzKeeper(authzKeeper types.AuthzKeeper) *Keeper { k.authzKeeper = authzKeeper return k @@ -82,3 +94,116 @@ func (k Keeper) UpdateValidatorOperator(ctx sdk.Context, val sdk.ValAddress, fro // add new operator store.Set(types.GetValidatorOperatorKey(val), from.Bytes()) } + +func (k Keeper) SetValidatorOperatorByConsAddr(ctx sdk.Context, newConsAddr sdk.ConsAddress, valOperator sdk.ValAddress) { + store := ctx.KVStore(k.storeKey) + store.Set(stakingtypes.GetValidatorByConsAddrKey(newConsAddr), valOperator) +} + +func (k Keeper) RemoveValidatorOperatorByConsAddr(ctx sdk.Context, consAddrs ...sdk.ConsAddress) { + store := ctx.KVStore(k.storeKey) + for _, addr := range consAddrs { + store.Delete(stakingtypes.GetValidatorByConsAddrKey(addr)) + } +} + +func (k Keeper) SetValidatorOldConsensusAddr(ctx sdk.Context, valAddr sdk.ValAddress, newConsAddr sdk.ConsAddress) { + store := ctx.KVStore(k.storeKey) + store.Set(types.GetValidatorOldConsensusAddrKey(valAddr), newConsAddr) +} + +func (k Keeper) RemoveValidatorOldConsensusAddr(ctx sdk.Context, valAddrs sdk.ValAddress) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.GetValidatorOldConsensusAddrKey(valAddrs)) +} + +func (k Keeper) IteratorValidatorOldConsensusAddr(ctx sdk.Context, handler func(valAddr sdk.ValAddress, consAddr sdk.ConsAddress) (stop bool)) { + store := ctx.KVStore(k.storeKey) + + iter := sdk.KVStorePrefixIterator(store, types.ValidatorOldConsensusAddrKey) + defer iter.Close() + + for ; iter.Valid(); iter.Next() { + valAddr := sdk.ValAddress(types.AddressFromValidatorNewConsensusAddrKey(iter.Key())) + consAddr := sdk.ConsAddress(iter.Value()) + + if handler(valAddr, consAddr) { + break + } + } +} + +func (k Keeper) SetValidatorDelConsensusAddr(ctx sdk.Context, valAddr sdk.ValAddress, consAddr sdk.ConsAddress) { + store := ctx.KVStore(k.storeKey) + store.Set(types.GetValidatorDelConsensusAddrKey(valAddr), consAddr) +} + +func (k Keeper) RemoveValidatorDelConsensusAddr(ctx sdk.Context, valAddrs ...sdk.ValAddress) { + store := ctx.KVStore(k.storeKey) + for _, addr := range valAddrs { + store.Delete(types.GetValidatorDelConsensusAddrKey(addr)) + } +} + +func (k Keeper) IteratorValidatorDelConsensusAddr(ctx sdk.Context, handler func(valAddr sdk.ValAddress, address sdk.ConsAddress) (stop bool)) { + store := ctx.KVStore(k.storeKey) + + iter := sdk.KVStorePrefixIterator(store, types.ValidatorDelConsensusAddrKey) + defer iter.Close() + + for ; iter.Valid(); iter.Next() { + valAddr := sdk.ValAddress(types.AddressFromValidatorDelConsensusAddrKey(iter.Key())) + consAddr := sdk.ConsAddress(iter.Value()) + if handler(valAddr, consAddr) { + break + } + } +} + +func (k Keeper) GetValidatorNewConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) (cryptotypes.PubKey, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.GetValidatorNewConsensusPubKey(valAddr)) + if bz == nil { + return nil, false + } + var pubKey cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(bz, &pubKey); err != nil { + return nil, false + } + return pubKey, true +} + +func (k Keeper) SetValidatorNewConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress, pubKey cryptotypes.PubKey) error { + bz, err := k.cdc.MarshalInterfaceJSON(pubKey) + if err != nil { + return sdkerrors.ErrJSONMarshal.Wrapf("failed to marshal pubkey: %s", err.Error()) + } + store := ctx.KVStore(k.storeKey) + store.Set(types.GetValidatorNewConsensusPubKey(valAddr), bz) + return nil +} + +func (k Keeper) RemoveValidatorNewConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.GetValidatorNewConsensusPubKey(valAddr)) +} + +func (k Keeper) IteratorValidatorNewConsensusPubKey(ctx sdk.Context, handler func(valAddr sdk.ValAddress, pubKey cryptotypes.PubKey) (stop bool)) { + store := ctx.KVStore(k.storeKey) + + iter := sdk.KVStorePrefixIterator(store, types.ValidatorNewConsensusPubKey) + defer iter.Close() + + for ; iter.Valid(); iter.Next() { + valAddr := sdk.ValAddress(types.AddressFromValidatorNewConsensusPubKey(iter.Key())) + + var pk cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(iter.Value(), &pk); err != nil { + k.Logger(ctx).Error("failed to unmarshal pubKey", "validator", valAddr.String(), "err", err.Error()) + continue + } + if handler(valAddr, pk) { + break + } + } +} diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index d3b423082..c4ed8e0c0 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -43,16 +43,16 @@ func (suite *KeeperTestSuite) SetupTest() { } func (suite *KeeperTestSuite) SetupSubTest() { - valNumber := tmrand.Intn(10) + 1 + valNumber := tmrand.Intn(10) + 2 valSet, valAccounts, valBalances := helpers.GenerateGenesisValidator(valNumber, sdk.Coins{}) - suite.valAccounts = valAccounts - suite.app = helpers.SetupWithGenesisValSet(suite.T(), valSet, valAccounts, valBalances...) suite.ctx = suite.app.NewContext(false, tmproto.Header{ ChainID: fxtypes.MainnetChainId, Height: suite.app.LastBlockHeight() + 1, ProposerAddress: valSet.Proposer.Address.Bytes(), }) + suite.ctx = suite.ctx.WithConsensusParams(helpers.ABCIConsensusParams) + suite.valAccounts = valAccounts suite.signer = helpers.NewSigner(helpers.NewEthPrivKey()) helpers.AddTestAddr(suite.app, suite.ctx, suite.signer.AccAddress(), sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(100).MulRaw(1e18)))) diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 0f199524f..e91deef66 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -4,6 +4,7 @@ import ( "context" errorsmod "cosmossdk.io/errors" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" @@ -56,3 +57,66 @@ func (k Keeper) GrantPrivilege(goCtx context.Context, msg *types.MsgGrantPrivile )) return &types.MsgGrantPrivilegeResponse{}, nil } + +func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditConsensusPubKey) (*types.MsgEditConsensusPubKeyResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) + if err != nil { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) + } + fromAddr := sdk.MustAccAddressFromBech32(msg.From) + + if _, found := k.GetValidator(ctx, valAddr); !found { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "validator %s not found", msg.ValidatorAddress) + } + if !k.HasValidatorGrant(ctx, fromAddr, valAddr) { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "from address not authorized") + } + + pk, ok := msg.Pubkey.GetCachedValue().(cryptotypes.PubKey) + if !ok { + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "Expecting cryptotypes.PubKey, got %T", msg.Pubkey.GetCachedValue()) + } + newConsAddr := sdk.GetConsAddress(pk) + if _, found := k.GetValidatorByConsAddr(ctx, newConsAddr); found { + return nil, stakingtypes.ErrValidatorPubKeyExists + } + + cp := ctx.ConsensusParams() + if cp != nil && cp.Validator != nil { + pkType := pk.Type() + hasKeyType := false + for _, keyType := range cp.Validator.PubKeyTypes { + if pkType == keyType { + hasKeyType = true + break + } + } + if !hasKeyType { + return nil, errorsmod.Wrapf( + stakingtypes.ErrValidatorPubKeyTypeNotSupported, + "got: %s, expected: %s", pk.Type(), cp.Validator.PubKeyTypes, + ) + } + } + + // todo validator jailed/inactive, can update consensus pubkey? + // todo one block can not update more than 1/3 + + // set validator new consensus pubkey + if err = k.SetValidatorNewConsensusPubKey(ctx, valAddr, pk); err != nil { + return nil, err + } + + // todo the update process(2 block) can be delegate(undelegate,redelegate)? + + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeEditConsensusPubKey, + sdk.NewAttribute(stakingtypes.AttributeKeyValidator, msg.ValidatorAddress), + sdk.NewAttribute(types.AttributeKeyFrom, msg.From), + sdk.NewAttribute(types.AttributeKeyPubKey, newConsAddr.String()), + )) + + return &types.MsgEditConsensusPubKeyResponse{}, err +} diff --git a/x/staking/keeper/msg_server_test.go b/x/staking/keeper/msg_server_test.go index b29d67b40..5aaf3f65c 100644 --- a/x/staking/keeper/msg_server_test.go +++ b/x/staking/keeper/msg_server_test.go @@ -237,3 +237,136 @@ func (suite *KeeperTestSuite) TestGrantAccount() { suite.Require().True(found) suite.Require().Equal(operator.String(), addr4.String()) } + +func (suite *KeeperTestSuite) TestEditConsensusPubKey() { + unKnownAddr := helpers.NewPriKey().PubKey().Address() + _, tmAny := suite.GenerateConsKey() + testCase := []struct { + name string + malleate func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey + expectPass bool + errMsg string + }{ + { + name: "success", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: tmAny, + } + }, + expectPass: true, + }, + { + name: "success - granted", + malleate: func(val sdk.ValAddress, _ sdk.AccAddress) *types.MsgEditConsensusPubKey { + newFrom := helpers.NewEthPrivKey() + suite.app.StakingKeeper.UpdateValidatorOperator(suite.ctx, val, newFrom.PubKey().Address().Bytes()) + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: sdk.AccAddress(newFrom.PubKey().Address()).String(), + Pubkey: tmAny, + } + }, + expectPass: true, + }, + { + name: "fail - invalid validator", + malleate: func(_ sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: "", + From: from.String(), + Pubkey: tmAny, + } + }, + expectPass: false, + errMsg: "empty address string is not allowed: invalid address", + }, + { + name: "fail - validator not found", + malleate: func(_ sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: sdk.ValAddress(unKnownAddr).String(), + From: from.String(), + Pubkey: tmAny, + } + }, + expectPass: false, + errMsg: fmt.Sprintf("validator %s not found: unknown address", sdk.ValAddress(unKnownAddr).String()), + }, + { + name: "fail - from not authorized", + malleate: func(val sdk.ValAddress, _ sdk.AccAddress) *types.MsgEditConsensusPubKey { + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), + Pubkey: tmAny, + } + }, + expectPass: false, + errMsg: "from address not authorized: unauthorized", + }, + { + name: "fail - invalid pubkey", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + pkAny, err := codectypes.NewAnyWithValue(&banktypes.MsgSend{}) + if err != nil { + panic(err) + } + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: pkAny, + } + }, + expectPass: false, + errMsg: "Expecting cryptotypes.PubKey, got *types.MsgSend: invalid type", + }, + { + name: "fail - pubkey exist", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + addr := suite.valAccounts[1].GetAddress() + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(addr)) + suite.Require().True(found) + + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: validator.ConsensusPubkey, + } + }, + expectPass: false, + errMsg: "validator already exist for this pubkey; must use new validator pubkey", + }, + { + name: "fail - invalid pubkey type", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + pkAny, err := codectypes.NewAnyWithValue(helpers.NewEthPrivKey().PubKey()) + if err != nil { + panic(err) + } + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: pkAny, + } + }, + expectPass: false, + errMsg: "got: eth_secp256k1, expected: [ed25519]: validator pubkey type is not supported", + }, + } + for _, tc := range testCase { + suite.Run(tc.name, func() { + from := suite.valAccounts[0].GetAddress() + msg := tc.malleate(sdk.ValAddress(from), from) + _, err := suite.app.StakingKeeper.EditConsensusPubKey(sdk.WrapSDKContext(suite.ctx), msg) + if tc.expectPass { + suite.Require().NoError(err) + } else { + suite.Require().Error(err) + suite.Require().Equal(tc.errMsg, err.Error()) + } + }) + } +} diff --git a/x/staking/module.go b/x/staking/module.go index 9e9bfa99a..ce39afa14 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -80,6 +80,12 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { am.AppModule.RegisterServices(cfg) } +// EndBlock returns the end blocker for the staking module. It returns no validator +// updates. +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return am.Keeper.EndBlock(ctx) +} + // InitGenesis performs genesis initialization for the staking module. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { diff --git a/x/staking/types/codec.go b/x/staking/types/codec.go index 63b28a1b7..28b600ef7 100644 --- a/x/staking/types/codec.go +++ b/x/staking/types/codec.go @@ -24,6 +24,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), &MsgGrantPrivilege{}, + &MsgEditConsensusPubKey{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) @@ -32,4 +33,5 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { // RegisterLegacyAminoCodec registers concrete types on the Amino codec func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgGrantPrivilege{}, "staking/MsgGrantPrivilege", nil) + cdc.RegisterConcrete(&MsgEditConsensusPubKey{}, "staking/MsgEditConsensusPubKey", nil) } diff --git a/x/staking/types/events.go b/x/staking/types/events.go index d65e715f2..6eee1c24f 100644 --- a/x/staking/types/events.go +++ b/x/staking/types/events.go @@ -1,9 +1,10 @@ package types const ( - EventTypeApproveShares = "approve_shares" - EventTypeTransferShares = "transfer_shares" - EventTypeGrantPrivilege = "grant_privilege" + EventTypeApproveShares = "approve_shares" + EventTypeTransferShares = "transfer_shares" + EventTypeGrantPrivilege = "grant_privilege" + EventTypeEditConsensusPubKey = "edit_consensus_pubkey" AttributeKeyOwner = "owner" AttributeKeySpender = "spender" @@ -12,4 +13,5 @@ const ( AttributeKeyFrom = "from" AttributeKeyRecipient = "recipient" AttributeKeyTo = "to" + AttributeKeyPubKey = "pubkey" ) diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 49f48ff1d..580dda634 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -3,8 +3,10 @@ package types import ( "time" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/authz" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" ) type AuthzKeeper interface { @@ -13,3 +15,11 @@ type AuthzKeeper interface { GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress) ([]authz.Authorization, error) GetAuthorization(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) (authz.Authorization, *time.Time) } + +type SlashingKeeper interface { + AddPubkey(ctx sdk.Context, pubkey cryptotypes.PubKey) error + // todo DeletePubkey(ctx sdk.Context, pubkey sdk.ConsAddress) + GetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) (info slashingtypes.ValidatorSigningInfo, found bool) + SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) + // todo DeleteValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) +} diff --git a/x/staking/types/keys.go b/x/staking/types/keys.go index 1183b4037..2bbafe5a1 100644 --- a/x/staking/types/keys.go +++ b/x/staking/types/keys.go @@ -2,13 +2,17 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/kv" ) const GrantPrivilegeSignaturePrefix = "GrantPrivilege:" var ( - AllowanceKey = []byte{0x90} - ValidatorOperatorKey = []byte{0x91} + AllowanceKey = []byte{0x90} + ValidatorOperatorKey = []byte{0x91} + ValidatorNewConsensusPubKey = []byte{0x92} + ValidatorOldConsensusAddrKey = []byte{0x93} + ValidatorDelConsensusAddrKey = []byte{0x94} ) func GetAllowanceKey(valAddr sdk.ValAddress, owner, spender sdk.AccAddress) []byte { @@ -29,3 +33,30 @@ func GetAllowanceKey(valAddr sdk.ValAddress, owner, spender sdk.AccAddress) []by func GetValidatorOperatorKey(addr []byte) []byte { return append(ValidatorOperatorKey, addr...) } + +func GetValidatorNewConsensusPubKey(addr sdk.ValAddress) []byte { + return append(ValidatorNewConsensusPubKey, addr...) +} + +func GetValidatorOldConsensusAddrKey(addr sdk.ValAddress) []byte { + return append(ValidatorOldConsensusAddrKey, addr...) +} + +func GetValidatorDelConsensusAddrKey(addr sdk.ValAddress) []byte { + return append(ValidatorDelConsensusAddrKey, addr...) +} + +func AddressFromValidatorNewConsensusPubKey(key []byte) []byte { + kv.AssertKeyAtLeastLength(key, 3) + return key[1:] // remove prefix bytes and address length +} + +func AddressFromValidatorNewConsensusAddrKey(key []byte) []byte { + kv.AssertKeyAtLeastLength(key, 3) + return key[1:] // remove prefix bytes and address length +} + +func AddressFromValidatorDelConsensusAddrKey(key []byte) []byte { + kv.AssertKeyAtLeastLength(key, 3) + return key[1:] // remove prefix bytes and address length +} diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 1c7e0d4e1..3539b64c7 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -13,11 +13,16 @@ import ( "github.com/evmos/ethermint/crypto/ethsecp256k1" ) -const TypeMsgGrantPrivilege = "grant_privilege" +const ( + TypeMsgGrantPrivilege = "grant_privilege" + TypeMsgEditConsensusPubKey = "edit_consensus_pubkey" +) var ( _ sdk.Msg = &MsgGrantPrivilege{} _ codectypes.UnpackInterfacesMessage = (*MsgGrantPrivilege)(nil) + _ sdk.Msg = &MsgEditConsensusPubKey{} + _ codectypes.UnpackInterfacesMessage = (*MsgEditConsensusPubKey)(nil) ) func NewMsgGrantPrivilege(val sdk.ValAddress, from sdk.AccAddress, pubKey cryptotypes.PubKey, signature string) (*MsgGrantPrivilege, error) { @@ -120,3 +125,53 @@ func GrantPrivilegeSignatureData(val, from, to []byte) []byte { copy(data[prefixLen+valLen+fromLen:], to) return data } + +func NewMsgEditConsensusPubKey(val sdk.ValAddress, from sdk.AccAddress, pubKey cryptotypes.PubKey) (*MsgEditConsensusPubKey, error) { + var pkAny *codectypes.Any + if pubKey != nil { + var err error + if pkAny, err = codectypes.NewAnyWithValue(pubKey); err != nil { + return nil, err + } + } + return &MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: pkAny, + }, nil +} + +func (m *MsgEditConsensusPubKey) Route() string { return stakingtypes.RouterKey } + +func (m *MsgEditConsensusPubKey) Type() string { return TypeMsgEditConsensusPubKey } + +func (m *MsgEditConsensusPubKey) ValidateBasic() error { + if _, err := sdk.ValAddressFromBech32(m.ValidatorAddress); err != nil { + return errortypes.ErrInvalidAddress.Wrapf("invalid validator address: %s", err) + } + if _, err := sdk.AccAddressFromBech32(m.From); err != nil { + return errortypes.ErrInvalidAddress.Wrapf("invalid from address: %s", err) + } + if m.Pubkey == nil { + return stakingtypes.ErrEmptyValidatorPubKey + } + return nil +} + +func (m *MsgEditConsensusPubKey) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) +} + +func (m *MsgEditConsensusPubKey) GetSigners() []sdk.AccAddress { + acc, err := sdk.AccAddressFromBech32(m.From) + if err != nil { + panic(err) + } + return []sdk.AccAddress{acc} +} + +// UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces +func (m *MsgEditConsensusPubKey) UnpackInterfaces(unpacker codectypes.AnyUnpacker) error { + var pubKey cryptotypes.PubKey + return unpacker.UnpackAny(m.Pubkey, &pubKey) +} diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index 5f555253b..bc2cdc3a9 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -7,12 +7,14 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/stretchr/testify/require" + "github.com/functionx/fx-core/v5/app" "github.com/functionx/fx-core/v5/testutil/helpers" "github.com/functionx/fx-core/v5/x/staking/types" ) @@ -121,3 +123,105 @@ func TestMsgGrantPrivilegeGetSigners(t *testing.T) { res := msg.GetSigners() require.Equal(t, fmt.Sprintf("%v", res), "[696E707574313131313131313131313131313131]") } + +func consPubKey() cryptotypes.PubKey { + var pk cryptotypes.PubKey + pkStr := `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"ua9OcG6txvyZ2wSxeVR1+NDzUqO8TzZdoYxCyA48qAM="}` + if err := app.MakeEncodingConfig().Codec.UnmarshalInterfaceJSON([]byte(pkStr), &pk); err != nil { + panic(err) + } + return pk +} + +func TestMsgEditConsensusKey_Route(t *testing.T) { + val := sdk.ValAddress("val") + from := sdk.AccAddress("from") + pubKey := consPubKey() + + msg, err := types.NewMsgEditConsensusPubKey(val, from, pubKey) + require.NoError(t, err) + require.Equal(t, msg.Route(), stakingtypes.RouterKey) + require.Equal(t, msg.Type(), "edit_consensus_pubkey") +} + +func TestMsgEditConsensusKeyValidation(t *testing.T) { + key := helpers.NewPriKey() + val := sdk.ValAddress(key.PubKey().Address().Bytes()) + from := sdk.AccAddress(key.PubKey().Address().Bytes()) + + testCase := []struct { + name string + msg func() *types.MsgEditConsensusPubKey + expectError string + }{ + { + name: "valid", + msg: func() *types.MsgEditConsensusPubKey { + msg, err := types.NewMsgEditConsensusPubKey(val, from, consPubKey()) + require.NoError(t, err) + return msg + }, + }, + { + name: "invalid validator address", + msg: func() *types.MsgEditConsensusPubKey { + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: "", + From: from.String(), + Pubkey: nil, + } + }, + expectError: "invalid validator address: empty address string is not allowed: invalid address", + }, + { + name: "invalid from address", + msg: func() *types.MsgEditConsensusPubKey { + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: "", + Pubkey: nil, + } + }, + expectError: "invalid from address: empty address string is not allowed: invalid address", + }, + { + name: "invalid pubkey", + msg: func() *types.MsgEditConsensusPubKey { + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: nil, + } + }, + expectError: "empty validator public key", + }, + } + for _, tc := range testCase { + t.Run(tc.name, func(t *testing.T) { + err := tc.msg().ValidateBasic() + if len(tc.expectError) == 0 { + require.NoError(t, err) + } else { + require.EqualError(t, err, tc.expectError) + } + }) + } +} + +func TestMsgEditConsensusKeyGetSignBytes(t *testing.T) { + val := sdk.ValAddress("val") + from := sdk.AccAddress("from") + msg, err := types.NewMsgEditConsensusPubKey(val, from, consPubKey()) + require.NoError(t, err) + res := msg.GetSignBytes() + + expected := `{"type":"staking/MsgEditConsensusPubKey","value":{"from":"cosmos1veex7mgzt83cu","pubkey":"ua9OcG6txvyZ2wSxeVR1+NDzUqO8TzZdoYxCyA48qAM=","validator_address":"cosmosvaloper1weskc8rudzy"}}` + require.Equal(t, expected, string(res)) +} + +func TestMsgEditConsensusKeyGetSigners(t *testing.T) { + msg, err := types.NewMsgEditConsensusPubKey(sdk.ValAddress{}, []byte("input111111111111111"), consPubKey()) + require.NoError(t, err) + res := msg.GetSigners() + require.Equal(t, fmt.Sprintf("%v", res), "[696E707574313131313131313131313131313131]") +} diff --git a/x/staking/types/tx.pb.go b/x/staking/types/tx.pb.go index 2ae63e1e1..628274a6a 100644 --- a/x/staking/types/tx.pb.go +++ b/x/staking/types/tx.pb.go @@ -134,38 +134,140 @@ func (m *MsgGrantPrivilegeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgGrantPrivilegeResponse proto.InternalMessageInfo +type MsgEditConsensusPubKey struct { + ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty"` + From string `protobuf:"bytes,2,opt,name=from,proto3" json:"from,omitempty"` + Pubkey *types.Any `protobuf:"bytes,3,opt,name=pubkey,proto3" json:"pubkey,omitempty"` +} + +func (m *MsgEditConsensusPubKey) Reset() { *m = MsgEditConsensusPubKey{} } +func (m *MsgEditConsensusPubKey) String() string { return proto.CompactTextString(m) } +func (*MsgEditConsensusPubKey) ProtoMessage() {} +func (*MsgEditConsensusPubKey) Descriptor() ([]byte, []int) { + return fileDescriptor_1c6db236fc9c571c, []int{2} +} +func (m *MsgEditConsensusPubKey) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgEditConsensusPubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgEditConsensusPubKey.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgEditConsensusPubKey) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgEditConsensusPubKey.Merge(m, src) +} +func (m *MsgEditConsensusPubKey) XXX_Size() int { + return m.Size() +} +func (m *MsgEditConsensusPubKey) XXX_DiscardUnknown() { + xxx_messageInfo_MsgEditConsensusPubKey.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgEditConsensusPubKey proto.InternalMessageInfo + +func (m *MsgEditConsensusPubKey) GetValidatorAddress() string { + if m != nil { + return m.ValidatorAddress + } + return "" +} + +func (m *MsgEditConsensusPubKey) GetFrom() string { + if m != nil { + return m.From + } + return "" +} + +func (m *MsgEditConsensusPubKey) GetPubkey() *types.Any { + if m != nil { + return m.Pubkey + } + return nil +} + +type MsgEditConsensusPubKeyResponse struct { +} + +func (m *MsgEditConsensusPubKeyResponse) Reset() { *m = MsgEditConsensusPubKeyResponse{} } +func (m *MsgEditConsensusPubKeyResponse) String() string { return proto.CompactTextString(m) } +func (*MsgEditConsensusPubKeyResponse) ProtoMessage() {} +func (*MsgEditConsensusPubKeyResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_1c6db236fc9c571c, []int{3} +} +func (m *MsgEditConsensusPubKeyResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgEditConsensusPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgEditConsensusPubKeyResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgEditConsensusPubKeyResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgEditConsensusPubKeyResponse.Merge(m, src) +} +func (m *MsgEditConsensusPubKeyResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgEditConsensusPubKeyResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgEditConsensusPubKeyResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgEditConsensusPubKeyResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgGrantPrivilege)(nil), "fx.staking.v1.MsgGrantPrivilege") proto.RegisterType((*MsgGrantPrivilegeResponse)(nil), "fx.staking.v1.MsgGrantPrivilegeResponse") + proto.RegisterType((*MsgEditConsensusPubKey)(nil), "fx.staking.v1.MsgEditConsensusPubKey") + proto.RegisterType((*MsgEditConsensusPubKeyResponse)(nil), "fx.staking.v1.MsgEditConsensusPubKeyResponse") } func init() { proto.RegisterFile("fx/staking/v1beta1/tx.proto", fileDescriptor_1c6db236fc9c571c) } var fileDescriptor_1c6db236fc9c571c = []byte{ - // 353 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xcf, 0x4e, 0xea, 0x40, - 0x14, 0xc6, 0xe9, 0xe5, 0xe6, 0xe6, 0x32, 0xa8, 0x91, 0x86, 0x45, 0x01, 0xd3, 0x20, 0x2b, 0x12, - 0x65, 0x26, 0xe0, 0x13, 0xc0, 0x42, 0x17, 0x84, 0x84, 0xb0, 0x34, 0x26, 0x64, 0x5a, 0xa6, 0xe3, - 0x04, 0x98, 0xd3, 0xcc, 0x4c, 0x9b, 0xf6, 0x2d, 0x7c, 0x18, 0x1f, 0xc2, 0xb8, 0x30, 0x2c, 0x5d, - 0x1a, 0x78, 0x11, 0x63, 0xcb, 0x9f, 0x28, 0x0b, 0x97, 0xe7, 0xfb, 0x7e, 0x33, 0xe7, 0x3b, 0xe7, - 0xa0, 0x46, 0x90, 0x10, 0x6d, 0xe8, 0x5c, 0x48, 0x4e, 0xe2, 0xae, 0xc7, 0x0c, 0xed, 0x12, 0x93, - 0xe0, 0x50, 0x81, 0x01, 0xfb, 0x34, 0x48, 0xf0, 0xd6, 0xc4, 0x71, 0xb7, 0x5e, 0xe3, 0x00, 0x7c, - 0xc1, 0x48, 0x66, 0x7a, 0x51, 0x40, 0xa8, 0x4c, 0x73, 0xb2, 0x5e, 0xf3, 0x41, 0x2f, 0x41, 0x4f, - 0xb3, 0x8a, 0xe4, 0x45, 0x6e, 0xb5, 0xde, 0x2c, 0x54, 0x19, 0x69, 0x7e, 0xa7, 0xa8, 0x34, 0x63, - 0x25, 0x62, 0xb1, 0x60, 0x9c, 0xd9, 0x57, 0xa8, 0x12, 0xd3, 0x85, 0x98, 0x51, 0x03, 0x6a, 0x4a, - 0x67, 0x33, 0xc5, 0xb4, 0x76, 0xac, 0xa6, 0xd5, 0x2e, 0x4d, 0xce, 0xf7, 0x46, 0x3f, 0xd7, 0xed, - 0x4b, 0x74, 0x12, 0x28, 0x58, 0xee, 0xb9, 0x3f, 0x19, 0x57, 0xfe, 0xd2, 0x76, 0xc8, 0x10, 0x95, - 0x0c, 0x4c, 0xc3, 0xc8, 0x9b, 0xb3, 0xd4, 0x29, 0x36, 0xad, 0x76, 0xb9, 0x57, 0xc5, 0x79, 0x5e, - 0xbc, 0xcb, 0x8b, 0xfb, 0x32, 0x1d, 0x38, 0xaf, 0xcf, 0x9d, 0xea, 0x36, 0xa0, 0xaf, 0xd2, 0xd0, - 0x00, 0x1e, 0x47, 0xde, 0x90, 0xa5, 0x93, 0xff, 0x06, 0xc6, 0xd9, 0x7b, 0xfb, 0x02, 0x95, 0xb4, - 0xe0, 0x92, 0x9a, 0x48, 0x31, 0xe7, 0x6f, 0xd6, 0xec, 0x20, 0xb4, 0x1a, 0xa8, 0x76, 0x34, 0xcf, - 0x84, 0xe9, 0x10, 0xa4, 0x66, 0x3d, 0x1f, 0x15, 0x47, 0x9a, 0xdb, 0x0f, 0xe8, 0xec, 0xc7, 0xc0, - 0x4d, 0xfc, 0x6d, 0x99, 0xf8, 0xe8, 0x8b, 0x7a, 0xfb, 0x37, 0x62, 0xd7, 0x64, 0x70, 0xfb, 0xb2, - 0x76, 0xad, 0xd5, 0xda, 0xb5, 0x3e, 0xd6, 0xae, 0xf5, 0xb4, 0x71, 0x0b, 0xab, 0x8d, 0x5b, 0x78, - 0xdf, 0xb8, 0x85, 0xfb, 0x6b, 0x2e, 0xcc, 0x63, 0xe4, 0x61, 0x1f, 0x96, 0x24, 0x88, 0xa4, 0x6f, - 0x04, 0xc8, 0x84, 0x04, 0x49, 0xc7, 0x07, 0xc5, 0xc8, 0xe1, 0xd4, 0x26, 0x0d, 0x99, 0xf6, 0xfe, - 0x65, 0x9b, 0xb9, 0xf9, 0x0c, 0x00, 0x00, 0xff, 0xff, 0x1c, 0xc7, 0x5f, 0xe7, 0x05, 0x02, 0x00, - 0x00, + // 423 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x53, 0xdd, 0x8a, 0xd3, 0x40, + 0x14, 0xee, 0xb8, 0xcb, 0x62, 0x67, 0x55, 0xdc, 0x71, 0x91, 0x34, 0x2b, 0x21, 0x06, 0x84, 0x82, + 0x76, 0x86, 0xae, 0x4f, 0xb0, 0x2b, 0xae, 0x17, 0x4b, 0xa1, 0xf4, 0x52, 0x84, 0x32, 0x49, 0x26, + 0xe3, 0xd0, 0x76, 0x26, 0xcc, 0x4c, 0x42, 0xf2, 0x16, 0xbe, 0x82, 0xef, 0xe0, 0x43, 0x88, 0x17, + 0xd2, 0x4b, 0x2f, 0xa5, 0x7d, 0x11, 0x69, 0x7e, 0x5a, 0xb4, 0x05, 0x95, 0xbd, 0xcb, 0xf9, 0xbe, + 0xef, 0x9c, 0xf3, 0x7d, 0x27, 0x09, 0xbc, 0x48, 0x0a, 0x62, 0x2c, 0x9d, 0x09, 0xc9, 0x49, 0x3e, + 0x0c, 0x99, 0xa5, 0x43, 0x62, 0x0b, 0x9c, 0x6a, 0x65, 0x15, 0x7a, 0x98, 0x14, 0xb8, 0x21, 0x71, + 0x3e, 0x74, 0x7b, 0x5c, 0x29, 0x3e, 0x67, 0xa4, 0x22, 0xc3, 0x2c, 0x21, 0x54, 0x96, 0xb5, 0xd2, + 0xed, 0x45, 0xca, 0x2c, 0x94, 0x99, 0x56, 0x15, 0xa9, 0x8b, 0x9a, 0x0a, 0xbe, 0x03, 0x78, 0x36, + 0x32, 0xfc, 0x9d, 0xa6, 0xd2, 0x8e, 0xb5, 0xc8, 0xc5, 0x9c, 0x71, 0x86, 0x5e, 0xc2, 0xb3, 0x9c, + 0xce, 0x45, 0x4c, 0xad, 0xd2, 0x53, 0x1a, 0xc7, 0x9a, 0x19, 0xe3, 0x00, 0x1f, 0xf4, 0xbb, 0x93, + 0xc7, 0x5b, 0xe2, 0xaa, 0xc6, 0xd1, 0x73, 0xf8, 0x20, 0xd1, 0x6a, 0xb1, 0xd5, 0xdd, 0xab, 0x74, + 0xa7, 0x1b, 0xac, 0x95, 0xdc, 0xc2, 0xae, 0x55, 0xd3, 0x34, 0x0b, 0x67, 0xac, 0x74, 0x8e, 0x7c, + 0xd0, 0x3f, 0xbd, 0x3c, 0xc7, 0xb5, 0x5f, 0xdc, 0xfa, 0xc5, 0x57, 0xb2, 0xbc, 0x76, 0xbe, 0x7d, + 0x19, 0x9c, 0x37, 0x06, 0x23, 0x5d, 0xa6, 0x56, 0xe1, 0x71, 0x16, 0xde, 0xb2, 0x72, 0x72, 0xdf, + 0xaa, 0x71, 0xd5, 0x8f, 0x9e, 0xc1, 0xae, 0x11, 0x5c, 0x52, 0x9b, 0x69, 0xe6, 0x1c, 0x57, 0xcb, + 0x76, 0x40, 0x70, 0x01, 0x7b, 0x7b, 0x79, 0x26, 0xcc, 0xa4, 0x4a, 0x1a, 0x16, 0x7c, 0x06, 0xf0, + 0xe9, 0xc8, 0xf0, 0xb7, 0xb1, 0xb0, 0x6f, 0x36, 0x80, 0x34, 0x99, 0xa9, 0xe7, 0xff, 0x5f, 0x64, + 0x04, 0x8f, 0x37, 0xf1, 0x9a, 0xa8, 0xd5, 0x33, 0xba, 0x81, 0x27, 0x77, 0x0a, 0xd8, 0x74, 0x07, + 0x3e, 0xf4, 0x0e, 0x5b, 0x6c, 0x53, 0x5c, 0x2e, 0x01, 0x3c, 0x1a, 0x19, 0x8e, 0x3e, 0xc0, 0x47, + 0x7f, 0xbc, 0x37, 0x1f, 0xff, 0xf6, 0x4d, 0xe0, 0xbd, 0x4b, 0xb8, 0xfd, 0xbf, 0x29, 0xda, 0x2d, + 0x68, 0x06, 0x9f, 0x1c, 0xba, 0xd3, 0x8b, 0xfd, 0x01, 0x07, 0x64, 0xee, 0xe0, 0x9f, 0x64, 0xed, + 0xb2, 0xeb, 0x9b, 0xaf, 0x2b, 0x0f, 0x2c, 0x57, 0x1e, 0xf8, 0xb9, 0xf2, 0xc0, 0xa7, 0xb5, 0xd7, + 0x59, 0xae, 0xbd, 0xce, 0x8f, 0xb5, 0xd7, 0x79, 0xff, 0x8a, 0x0b, 0xfb, 0x31, 0x0b, 0x71, 0xa4, + 0x16, 0x24, 0xc9, 0x64, 0x64, 0x85, 0x92, 0x05, 0x49, 0x8a, 0x41, 0xa4, 0x34, 0x23, 0xbb, 0xdf, + 0xc3, 0x96, 0x29, 0x33, 0xe1, 0x49, 0x75, 0xec, 0xd7, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x48, + 0x74, 0x03, 0x05, 0x39, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -182,6 +284,8 @@ const _ = grpc.SupportPackageIsVersion4 type MsgClient interface { // GrantPrivilege defines a method for granting privilege to a validator. GrantPrivilege(ctx context.Context, in *MsgGrantPrivilege, opts ...grpc.CallOption) (*MsgGrantPrivilegeResponse, error) + // EditConsensusKey defines a method for editing consensus pubkey of a validator. + EditConsensusPubKey(ctx context.Context, in *MsgEditConsensusPubKey, opts ...grpc.CallOption) (*MsgEditConsensusPubKeyResponse, error) } type msgClient struct { @@ -201,10 +305,21 @@ func (c *msgClient) GrantPrivilege(ctx context.Context, in *MsgGrantPrivilege, o return out, nil } +func (c *msgClient) EditConsensusPubKey(ctx context.Context, in *MsgEditConsensusPubKey, opts ...grpc.CallOption) (*MsgEditConsensusPubKeyResponse, error) { + out := new(MsgEditConsensusPubKeyResponse) + err := c.cc.Invoke(ctx, "/fx.staking.v1.Msg/EditConsensusPubKey", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // GrantPrivilege defines a method for granting privilege to a validator. GrantPrivilege(context.Context, *MsgGrantPrivilege) (*MsgGrantPrivilegeResponse, error) + // EditConsensusKey defines a method for editing consensus pubkey of a validator. + EditConsensusPubKey(context.Context, *MsgEditConsensusPubKey) (*MsgEditConsensusPubKeyResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -214,6 +329,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) GrantPrivilege(ctx context.Context, req *MsgGrantPrivilege) (*MsgGrantPrivilegeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GrantPrivilege not implemented") } +func (*UnimplementedMsgServer) EditConsensusPubKey(ctx context.Context, req *MsgEditConsensusPubKey) (*MsgEditConsensusPubKeyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method EditConsensusPubKey not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -237,6 +355,24 @@ func _Msg_GrantPrivilege_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _Msg_EditConsensusPubKey_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgEditConsensusPubKey) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).EditConsensusPubKey(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/fx.staking.v1.Msg/EditConsensusPubKey", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).EditConsensusPubKey(ctx, req.(*MsgEditConsensusPubKey)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "fx.staking.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -245,6 +381,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "GrantPrivilege", Handler: _Msg_GrantPrivilege_Handler, }, + { + MethodName: "EditConsensusPubKey", + Handler: _Msg_EditConsensusPubKey_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "fx/staking/v1beta1/tx.proto", @@ -329,6 +469,78 @@ func (m *MsgGrantPrivilegeResponse) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } +func (m *MsgEditConsensusPubKey) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgEditConsensusPubKey) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgEditConsensusPubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Pubkey != nil { + { + size, err := m.Pubkey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + if len(m.From) > 0 { + i -= len(m.From) + copy(dAtA[i:], m.From) + i = encodeVarintTx(dAtA, i, uint64(len(m.From))) + i-- + dAtA[i] = 0x12 + } + if len(m.ValidatorAddress) > 0 { + i -= len(m.ValidatorAddress) + copy(dAtA[i:], m.ValidatorAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValidatorAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgEditConsensusPubKeyResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgEditConsensusPubKeyResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgEditConsensusPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -374,6 +586,36 @@ func (m *MsgGrantPrivilegeResponse) Size() (n int) { return n } +func (m *MsgEditConsensusPubKey) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValidatorAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.From) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Pubkey != nil { + l = m.Pubkey.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgEditConsensusPubKeyResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -612,6 +854,206 @@ func (m *MsgGrantPrivilegeResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgEditConsensusPubKey) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgEditConsensusPubKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgEditConsensusPubKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValidatorAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ValidatorAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field From", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.From = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pubkey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Pubkey == nil { + m.Pubkey = &types.Any{} + } + if err := m.Pubkey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgEditConsensusPubKeyResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgEditConsensusPubKeyResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgEditConsensusPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From 46c7d1c5a3f7c62d4de327d8969f15d04bc8afdd Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Mon, 10 Jul 2023 15:26:21 +0800 Subject: [PATCH 07/30] perf: edit consensus pubkey * update jailed/inactive validator immediately * update active validator not more than 1/3 power --- x/staking/keeper/keeper.go | 12 ++-- x/staking/keeper/keeper_test.go | 2 +- x/staking/keeper/msg_server.go | 105 +++++++++++++++++++++++++++----- 3 files changed, 94 insertions(+), 25 deletions(-) diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index b6adb6ae3..21cd8c73d 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -100,11 +100,9 @@ func (k Keeper) SetValidatorOperatorByConsAddr(ctx sdk.Context, newConsAddr sdk. store.Set(stakingtypes.GetValidatorByConsAddrKey(newConsAddr), valOperator) } -func (k Keeper) RemoveValidatorOperatorByConsAddr(ctx sdk.Context, consAddrs ...sdk.ConsAddress) { +func (k Keeper) RemoveValidatorOperatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) { store := ctx.KVStore(k.storeKey) - for _, addr := range consAddrs { - store.Delete(stakingtypes.GetValidatorByConsAddrKey(addr)) - } + store.Delete(stakingtypes.GetValidatorByConsAddrKey(consAddr)) } func (k Keeper) SetValidatorOldConsensusAddr(ctx sdk.Context, valAddr sdk.ValAddress, newConsAddr sdk.ConsAddress) { @@ -138,11 +136,9 @@ func (k Keeper) SetValidatorDelConsensusAddr(ctx sdk.Context, valAddr sdk.ValAdd store.Set(types.GetValidatorDelConsensusAddrKey(valAddr), consAddr) } -func (k Keeper) RemoveValidatorDelConsensusAddr(ctx sdk.Context, valAddrs ...sdk.ValAddress) { +func (k Keeper) RemoveValidatorDelConsensusAddr(ctx sdk.Context, valAddr sdk.ValAddress) { store := ctx.KVStore(k.storeKey) - for _, addr := range valAddrs { - store.Delete(types.GetValidatorDelConsensusAddrKey(addr)) - } + store.Delete(types.GetValidatorDelConsensusAddrKey(valAddr)) } func (k Keeper) IteratorValidatorDelConsensusAddr(ctx sdk.Context, handler func(valAddr sdk.ValAddress, address sdk.ConsAddress) (stop bool)) { diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index c4ed8e0c0..ae057f7e3 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -43,7 +43,7 @@ func (suite *KeeperTestSuite) SetupTest() { } func (suite *KeeperTestSuite) SetupSubTest() { - valNumber := tmrand.Intn(10) + 2 + valNumber := tmrand.Intn(5) + 6 valSet, valAccounts, valBalances := helpers.GenerateGenesisValidator(valNumber, sdk.Coins{}) suite.app = helpers.SetupWithGenesisValSet(suite.T(), valSet, valAccounts, valBalances...) suite.ctx = suite.app.NewContext(false, tmproto.Header{ diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index e91deef66..2da12c034 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -4,6 +4,8 @@ import ( "context" errorsmod "cosmossdk.io/errors" + "cosmossdk.io/math" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -66,23 +68,68 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) } fromAddr := sdk.MustAccAddressFromBech32(msg.From) - - if _, found := k.GetValidator(ctx, valAddr); !found { + validator, found := k.GetValidator(ctx, valAddr) + if !found { return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "validator %s not found", msg.ValidatorAddress) } + + // pubkey and address + newPubKey, err := k.validateAnyPubKey(ctx, msg.Pubkey) + if err != nil { + return nil, err + } + + // validator jailed/inactive, update pubkey + if validator.IsJailed() || validator.IsUnbonding() || validator.IsUnbonded() { + if err := k.updateValidatorPubKey(ctx, validator, newPubKey); err != nil { + return nil, err + } + emitEditConsensusPubKeyEvents(ctx, valAddr, fromAddr, newPubKey) + return &types.MsgEditConsensusPubKeyResponse{}, nil + } + + // update validator less than 1/3 total power + updatePower := math.NewInt(validator.ConsensusPower(k.PowerReduction(ctx))) + k.IteratorValidatorNewConsensusPubKey(ctx, func(addr sdk.ValAddress, _ cryptotypes.PubKey) bool { + power := k.GetLastValidatorPower(ctx, addr) + updatePower = updatePower.Add(math.NewInt(power)) + return false + }) + totalPowerOneThird := k.GetLastTotalPower(ctx).QuoRaw(3) + if updatePower.GTE(totalPowerOneThird) { + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, + "update power %s more than 1/3 total power %s", updatePower.String(), totalPowerOneThird.String()) + } + + // from authorized if !k.HasValidatorGrant(ctx, fromAddr, valAddr) { return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "from address not authorized") } - pk, ok := msg.Pubkey.GetCachedValue().(cryptotypes.PubKey) + // set validator new consensus pubkey + if err = k.SetValidatorNewConsensusPubKey(ctx, valAddr, newPubKey); err != nil { + return nil, err + } + + // todo the update process(2 block) can be delegate/undelegate/redelegate? + + emitEditConsensusPubKeyEvents(ctx, valAddr, fromAddr, newPubKey) + + return &types.MsgEditConsensusPubKeyResponse{}, err +} + +func (k Keeper) validateAnyPubKey(ctx sdk.Context, pubkey *codectypes.Any) (cryptotypes.PubKey, error) { + // pubkey type + pk, ok := pubkey.GetCachedValue().(cryptotypes.PubKey) if !ok { - return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "Expecting cryptotypes.PubKey, got %T", msg.Pubkey.GetCachedValue()) + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "Expecting cryptotypes.PubKey, got %T", pubkey.GetCachedValue()) } + // pubkey exist newConsAddr := sdk.GetConsAddress(pk) if _, found := k.GetValidatorByConsAddr(ctx, newConsAddr); found { return nil, stakingtypes.ErrValidatorPubKeyExists } - + // pubkey type supported cp := ctx.ConsensusParams() if cp != nil && cp.Validator != nil { pkType := pk.Type() @@ -100,23 +147,49 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon ) } } + return pk, nil +} - // todo validator jailed/inactive, can update consensus pubkey? - // todo one block can not update more than 1/3 +func (k Keeper) updateValidatorPubKey(ctx sdk.Context, validator stakingtypes.Validator, newPubKey cryptotypes.PubKey) error { + newConsAddr := sdk.ConsAddress(newPubKey.Address()) + // remove old cons address + consAddr, err := validator.GetConsAddr() + if err != nil { + return err + } + k.RemoveValidatorOperatorByConsAddr(ctx, consAddr) - // set validator new consensus pubkey - if err = k.SetValidatorNewConsensusPubKey(ctx, valAddr, pk); err != nil { - return nil, err + // update new cons address + pkAny, _ := codectypes.NewAnyWithValue(newPubKey) + validator.ConsensusPubkey = pkAny + if err := k.SetValidatorByConsAddr(ctx, validator); err != nil { + return err } + // add new sign info + info, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, consAddr) + if !found { + return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "validator signing info not found") + } + info.Address = newConsAddr.String() + k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, info) + + // todo delete old sign info - // todo the update process(2 block) can be delegate(undelegate,redelegate)? + // add new pubkey + if err := k.slashingKeeper.AddPubkey(ctx, newPubKey); err != nil { + return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, err.Error()) + } + // todo remove old pubkey + + return nil +} + +func emitEditConsensusPubKeyEvents(ctx sdk.Context, val sdk.ValAddress, from sdk.AccAddress, newPubKey cryptotypes.PubKey) { ctx.EventManager().EmitEvent(sdk.NewEvent( types.EventTypeEditConsensusPubKey, - sdk.NewAttribute(stakingtypes.AttributeKeyValidator, msg.ValidatorAddress), - sdk.NewAttribute(types.AttributeKeyFrom, msg.From), - sdk.NewAttribute(types.AttributeKeyPubKey, newConsAddr.String()), + sdk.NewAttribute(stakingtypes.AttributeKeyValidator, val.String()), + sdk.NewAttribute(types.AttributeKeyFrom, from.String()), + sdk.NewAttribute(types.AttributeKeyPubKey, newPubKey.String()), )) - - return &types.MsgEditConsensusPubKeyResponse{}, err } From 64951ad26216afd7466e985a174116b11296fcb7 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:00:51 +0800 Subject: [PATCH 08/30] refactor: slashing keeper * add DeleteConsensusPubKey * add DeleteValidatorSigningInfo --- app/keepers/keepers.go | 15 +++++++++------ app/modules.go | 2 +- x/slashing/keeper/keeper.go | 31 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 x/slashing/keeper/keeper.go diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index f4aebfecb..c04fb41ca 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -75,6 +75,7 @@ import ( migratetypes "github.com/functionx/fx-core/v5/x/migrate/types" optimismtypes "github.com/functionx/fx-core/v5/x/optimism/types" polygontypes "github.com/functionx/fx-core/v5/x/polygon/types" + fxslashingkeeper "github.com/functionx/fx-core/v5/x/slashing/keeper" fxstakingkeeper "github.com/functionx/fx-core/v5/x/staking/keeper" tronkeeper "github.com/functionx/fx-core/v5/x/tron/keeper" trontypes "github.com/functionx/fx-core/v5/x/tron/types" @@ -104,7 +105,7 @@ type AppKeepers struct { BankKeeper bankkeeper.Keeper CapabilityKeeper *capabilitykeeper.Keeper StakingKeeper fxstakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper + SlashingKeeper fxslashingkeeper.Keeper MintKeeper mintkeeper.Keeper DistrKeeper distrkeeper.Keeper GovKeeper fxgovkeeper.Keeper @@ -222,11 +223,13 @@ func NewAppKeeper( &appKeepers.StakingKeeper, authtypes.FeeCollectorName, ) - appKeepers.SlashingKeeper = slashingkeeper.NewKeeper( - appCodec, - appKeepers.keys[slashingtypes.StoreKey], - &appKeepers.StakingKeeper, - appKeepers.GetSubspace(slashingtypes.ModuleName), + appKeepers.SlashingKeeper = fxslashingkeeper.NewKeeper( + slashingkeeper.NewKeeper( + appCodec, + appKeepers.keys[slashingtypes.StoreKey], + &appKeepers.StakingKeeper, + appKeepers.GetSubspace(slashingtypes.ModuleName), + ), appKeepers.keys[slashingtypes.StoreKey], ) appKeepers.StakingKeeper = *appKeepers.StakingKeeper.SetSlashingKeeper(appKeepers.SlashingKeeper) diff --git a/app/modules.go b/app/modules.go index 3a6cb0af0..cae17af4d 100644 --- a/app/modules.go +++ b/app/modules.go @@ -168,7 +168,7 @@ func appModules( crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants), fxgov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil), - slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), + slashing.NewAppModule(appCodec, app.SlashingKeeper.Keeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), fxstaking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper), upgrade.NewAppModule(app.UpgradeKeeper), diff --git a/x/slashing/keeper/keeper.go b/x/slashing/keeper/keeper.go new file mode 100644 index 000000000..60bdc5f4a --- /dev/null +++ b/x/slashing/keeper/keeper.go @@ -0,0 +1,31 @@ +package keeper + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" +) + +type Keeper struct { + keeper.Keeper + + storeKey storetypes.StoreKey +} + +func NewKeeper(k keeper.Keeper, key storetypes.StoreKey) Keeper { + return Keeper{ + Keeper: k, + storeKey: key, + } +} + +func (k Keeper) DeleteConsensusPubKey(ctx sdk.Context, consAddr sdk.ConsAddress) { + store := ctx.KVStore(k.storeKey) + store.Delete(slashtypes.AddrPubkeyRelationKey(consAddr)) +} + +func (k Keeper) DeleteValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress) { + store := ctx.KVStore(k.storeKey) + store.Delete(slashtypes.ValidatorSigningInfoKey(consAddr)) +} From 327b8c58a028ed13f08c61c98b76547bc36e8af8 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:02:03 +0800 Subject: [PATCH 09/30] refactor: edit consensus pubkey * refactor ValidatorUpdate * remove old consensus pubkey * remove old validator signing info * fix updateValidatorPubKey set validator --- x/staking/keeper/abci.go | 216 ++++++++++++++++------------ x/staking/keeper/abci_test.go | 67 +++++---- x/staking/keeper/keeper.go | 122 ++++++++-------- x/staking/keeper/msg_server.go | 41 +++--- x/staking/types/events.go | 12 +- x/staking/types/expected_keepers.go | 8 +- x/staking/types/keys.go | 41 +++--- 7 files changed, 269 insertions(+), 238 deletions(-) diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index bb0b8b6ea..25b9f43a8 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -1,143 +1,118 @@ package keeper import ( + "errors" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/staking" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/proto/tendermint/crypto" + + "github.com/functionx/fx-core/v5/x/staking/types" ) func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { valUpdates := staking.EndBlocker(ctx, k.Keeper) - // remove consensus record after consensus update - k.RemoveValidatorConsensusKey(ctx) - // update validator consensus after abci update - k.UpdateValidatorConsensusKey(ctx) - // abci validator update - return k.ABCIValidatorUpdate(ctx, valUpdates) -} - -// RemoveValidatorConsensusKey delete validator record after UpdateValidatorConsensusKey -func (k Keeper) RemoveValidatorConsensusKey(ctx sdk.Context) { - k.IteratorValidatorDelConsensusAddr(ctx, func(valAddr sdk.ValAddress, delConsAddr sdk.ConsAddress) bool { - // remove del consensus address record - k.RemoveValidatorDelConsensusAddr(ctx, valAddr) - - // delete validator by old consensus address - k.RemoveValidatorOperatorByConsAddr(ctx, delConsAddr) - - // todo delete old consensus pubkey - - // todo delete old validator signing info - return false - }) + k.ConsensusProcess(ctx) + return k.ValidatorUpdate(ctx, valUpdates) } -// UpdateValidatorConsensusKey update validator consensus pubkey after ABCIValidatorUpdate -func (k Keeper) UpdateValidatorConsensusKey(ctx sdk.Context) { - k.IteratorValidatorOldConsensusAddr(ctx, func(valAddr sdk.ValAddress, oldConsAddr sdk.ConsAddress) bool { - // delete old consensus address record - k.RemoveValidatorOldConsensusAddr(ctx, valAddr) +func (k Keeper) ConsensusProcess(ctx sdk.Context) { + // process end, remove old consensus key + k.IteratorConsensusProcess(ctx, types.ProcessEnd, func(valAddr sdk.ValAddress, oldConsAddr sdk.ConsAddress) { + k.DeleteConsensusProcess(ctx, valAddr, types.ProcessEnd) - // update validator consensus pubkey - newPubkey, found := k.GetValidatorNewConsensusPubKey(ctx, valAddr) - if !found { - return false - } + // remove validator by old consensus address + k.RemoveValidatorConsAddr(ctx, oldConsAddr) - // delete new consensus pubkey record - k.RemoveValidatorNewConsensusPubKey(ctx, valAddr) + // remove old consensus pubkey + k.slashingKeeper.DeleteConsensusPubKey(ctx, oldConsAddr) - // update validator consensus pubkey - validator, found := k.GetValidator(ctx, valAddr) - if !found { - return false - } - newConsAddr := sdk.ConsAddress(newPubkey.Address()) - pkAny, err := codectypes.NewAnyWithValue(newPubkey) - if err != nil { - panic(err) - } - validator.ConsensusPubkey = pkAny - k.SetValidator(ctx, validator) - - // add consensus pubkey record - if err = k.slashingKeeper.AddPubkey(ctx, newPubkey); err != nil { - panic(err) - } + // remove old validator signing info + k.slashingKeeper.DeleteValidatorSigningInfo(ctx, oldConsAddr) - // Update the signing info start height or create a new signing info - signingInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) - if !found { - panic("expected signing info to be found") - } - signingInfo.Address = newConsAddr.String() - k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, signingInfo) + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeEndEditConsensusPubKey, + sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), + )) + }) - // set del consensus address - k.SetValidatorDelConsensusAddr(ctx, valAddr, oldConsAddr) - return false + // process start to end + k.IteratorConsensusProcess(ctx, types.ProcessStart, func(valAddr sdk.ValAddress, oldConsAddr sdk.ConsAddress) { + k.DeleteConsensusProcess(ctx, valAddr, types.ProcessStart) + k.SetConsensusProcess(ctx, valAddr, oldConsAddr, types.ProcessEnd) }) } -// ABCIValidatorUpdate update old consensus pubkey to zero power, add new consensus pubkey to validator power -func (k Keeper) ABCIValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpdate) []abci.ValidatorUpdate { +func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpdate) []abci.ValidatorUpdate { proposer := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress) - pkPower := make(map[crypto.PublicKey]int64, len(valUpdates)) for _, valUpdate := range valUpdates { pkPower[valUpdate.PubKey] = valUpdate.Power } - pkUpdate := make([]abci.ValidatorUpdate, 0, 50) - k.IteratorValidatorNewConsensusPubKey(ctx, func(valAddr sdk.ValAddress, newPubKey cryptotypes.PubKey) bool { + + k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, newPubKey cryptotypes.PubKey) { validator, found := k.GetValidator(ctx, valAddr) if !found { - // validator not found, remove new pubkey update - k.RemoveValidatorNewConsensusPubKey(ctx, valAddr) - return false + k.RemoveConsensusPubKey(ctx, valAddr) + return } - oldPubKey, err := validator.ConsPubKey() if err != nil { - panic(err) + k.RemoveConsensusPubKey(ctx, valAddr) + return } oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) // if validator is proposer, skip this block if oldConsAddr.Equals(proposer) { - return false + k.Logger(ctx).Info("validator is proposer, skip update", "address", valAddr.String()) + return } - oldTmPk, err := cryptocodec.ToTmProtoPublicKey(oldPubKey) - if err != nil { - panic(err) + + // no matter what happens next, clear new consensus pubkey + k.RemoveConsensusPubKey(ctx, valAddr) + + cacheCtx, commit := ctx.CacheContext() + // update validator pubkey + if err = k.updateValidator(cacheCtx, validator, newPubKey); err != nil { + k.Logger(ctx).Error("update validator", "address", valAddr.String(), "error", err.Error()) + return + } + // slash update + if err = k.updateSlashing(cacheCtx, newPubKey, oldConsAddr); err != nil { + k.Logger(ctx).Error("update slashing", "address", valAddr.String(), "error", err.Error()) + return } - newTmPk, err := cryptocodec.ToTmProtoPublicKey(newPubKey) + // new validator updates + newValUpdates, err := k.updateABICValidator(cacheCtx, pkPower, validator, newPubKey, oldPubKey) if err != nil { - panic(err) + k.Logger(ctx).Error("update abci validator", "address", valAddr.String(), "error", err.Error()) + return } + pkUpdate = append(pkUpdate, newValUpdates...) - power, ok := pkPower[oldTmPk] - // if power not found, use validator power - if !ok { - power = validator.ConsensusPower(k.PowerReduction(ctx)) - } - // set old tmPk power to 0, remove - pkUpdate = append(pkUpdate, abci.ValidatorUpdate{PubKey: oldTmPk, Power: 0}) - // add new tmPk with power - pkUpdate = append(pkUpdate, abci.ValidatorUpdate{PubKey: newTmPk, Power: power}) - - newConsAddr := sdk.ConsAddress(newPubKey.Address()) - // set new consensus address with validator - k.SetValidatorOperatorByConsAddr(ctx, newConsAddr, validator.GetOperator()) - // record validator new consensus address - k.SetValidatorOldConsensusAddr(ctx, valAddr, oldConsAddr) - return false - }) + // set consensus process start + k.SetConsensusProcess(ctx, valAddr, oldConsAddr, types.ProcessStart) + + k.Logger(ctx).Info("update consensus pubkey", "address", valAddr.String(), + "oldConsAddr", oldConsAddr.String(), "newConsAddr", sdk.ConsAddress(newPubKey.Address()).String()) + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeStartEditConsensusPubKey, + sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), + sdk.NewAttribute(types.AttributeOldConsAddr, oldConsAddr.String()), + sdk.NewAttribute(types.AttributeNewConsAddr, sdk.ConsAddress(newPubKey.Address()).String()), + )) + + // commit cache context + commit() + }) // joint pkPower and pkUpdate newValUpdates := make([]abci.ValidatorUpdate, 0, len(pkPower)+len(pkUpdate)) for tmPk, power := range pkPower { @@ -146,3 +121,56 @@ func (k Keeper) ABCIValidatorUpdate(ctx sdk.Context, valUpdates []abci.Validator newValUpdates = append(newValUpdates, pkUpdate...) return newValUpdates } + +func (k Keeper) updateValidator(ctx sdk.Context, validator stakingtypes.Validator, newPubKey cryptotypes.PubKey) error { + pkAny, err := codectypes.NewAnyWithValue(newPubKey) + if err != nil { + return err + } + validator.ConsensusPubkey = pkAny + k.SetValidator(ctx, validator) + + // set new consensus address with validator + k.SetValidatorConsAddr(ctx, sdk.ConsAddress(newPubKey.Address()), validator.GetOperator()) + return nil +} + +func (k Keeper) updateSlashing(ctx sdk.Context, newPubKey cryptotypes.PubKey, oldConsAddr sdk.ConsAddress) error { + // add new pubkey + if err := k.slashingKeeper.AddPubkey(ctx, newPubKey); err != nil { + return err + } + + newConsAddr := sdk.ConsAddress(newPubKey.Address()) + // add signing info + signingInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) + if !found { + return errors.New("expected signing info to be found") + } + signingInfo.Address = newConsAddr.String() + k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, signingInfo) + + return nil +} + +func (k Keeper) updateABICValidator(ctx sdk.Context, pkPower map[crypto.PublicKey]int64, validator stakingtypes.Validator, newPubKey, oldPubKey cryptotypes.PubKey) ([]abci.ValidatorUpdate, error) { + oldTmPk, err := cryptocodec.ToTmProtoPublicKey(oldPubKey) + if err != nil { + return nil, err + } + newTmPk, err := cryptocodec.ToTmProtoPublicKey(newPubKey) + if err != nil { + return nil, err + } + + power, ok := pkPower[oldTmPk] + // if power not found, use validator power + if !ok { + power = validator.ConsensusPower(k.PowerReduction(ctx)) + } + // set old tmPk power to 0, remove + oldTmPkUpdate := abci.ValidatorUpdate{PubKey: oldTmPk, Power: 0} + // add new tmPk with power + newTmPkUpdate := abci.ValidatorUpdate{PubKey: newTmPk, Power: power} + return []abci.ValidatorUpdate{oldTmPkUpdate, newTmPkUpdate}, nil +} diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go index f45f470e4..0b9796960 100644 --- a/x/staking/keeper/abci_test.go +++ b/x/staking/keeper/abci_test.go @@ -1,29 +1,20 @@ package keeper_test import ( + "fmt" "time" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" abci "github.com/tendermint/tendermint/abci/types" + + "github.com/functionx/fx-core/v5/x/staking/types" ) -func (suite *KeeperTestSuite) TestABCIValidatorUpdates() { +func (suite *KeeperTestSuite) TestValidatorUpdate() { valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) - _, tmAny := suite.GenerateConsKey() - pk, ok := tmAny.GetCachedValue().(cryptotypes.PubKey) - suite.Require().True(ok) - err := suite.app.StakingKeeper.SetValidatorNewConsensusPubKey(suite.ctx, valAddr, pk) - suite.Require().NoError(err) - - updates := suite.app.StakingKeeper.ABCIValidatorUpdate(suite.ctx, []abci.ValidatorUpdate{}) - suite.Require().Len(updates, 2) -} - -func (suite *KeeperTestSuite) TestUpdateValidatorConsensus() { - valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) suite.Require().True(found) consAddr, err := validator.GetConsAddr() @@ -33,31 +24,49 @@ func (suite *KeeperTestSuite) TestUpdateValidatorConsensus() { _, tmAny := suite.GenerateConsKey() pk, ok := tmAny.GetCachedValue().(cryptotypes.PubKey) suite.Require().True(ok) - err = suite.app.StakingKeeper.SetValidatorNewConsensusPubKey(suite.ctx, valAddr, pk) + err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, pk) suite.Require().NoError(err) - suite.app.StakingKeeper.SetValidatorOldConsensusAddr(suite.ctx, valAddr, consAddr) - suite.app.StakingKeeper.UpdateValidatorConsensusKey(suite.ctx) + found = suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, valAddr) + suite.Require().False(found) + + // validator update(process start) + updates := suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, []abci.ValidatorUpdate{}) + suite.Require().Len(updates, 2) + updates = suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, []abci.ValidatorUpdate{}) + suite.Require().Len(updates, 0) - _, found = suite.app.StakingKeeper.GetValidatorNewConsensusPubKey(suite.ctx, valAddr) + _, found = suite.app.StakingKeeper.GetConsensusPubKey(suite.ctx, valAddr) suite.Require().False(found) - valNew, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + + oldConsAddr, found := suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) suite.Require().True(found) - valPk, err := valNew.ConsPubKey() - suite.Require().NoError(err) - suite.Require().Equal(pk.Address(), valPk.Address()) -} + suite.Require().Equal(consAddr, oldConsAddr) + _, found = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessEnd) + suite.Require().False(found) -func (suite *KeeperTestSuite) TestRemoveValidatorConsensusKey() { - valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) - validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + // consensus process(process end) + suite.app.StakingKeeper.ConsensusProcess(suite.ctx) + + _, found = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) + suite.Require().False(found) + oldConsAddr, found = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessEnd) suite.Require().True(found) - consAddr, err := validator.GetConsAddr() + suite.Require().Equal(consAddr, oldConsAddr) + + _, err = suite.app.SlashingKeeper.GetPubkey(suite.ctx, oldConsAddr.Bytes()) suite.Require().NoError(err) - suite.app.StakingKeeper.SetValidatorDelConsensusAddr(suite.ctx, valAddr, consAddr) + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + + // consensus process(process delete) + suite.app.StakingKeeper.ConsensusProcess(suite.ctx) - suite.app.StakingKeeper.RemoveValidatorConsensusKey(suite.ctx) + _, found = suite.app.StakingKeeper.GetConsensusPubKey(suite.ctx, valAddr) + suite.Require().False(found) - _, found = suite.app.StakingKeeper.GetValidatorByConsAddr(suite.ctx, consAddr) + _, err = suite.app.SlashingKeeper.GetPubkey(suite.ctx, oldConsAddr.Bytes()) + suite.Require().ErrorContains(err, fmt.Sprintf("address %s not found", oldConsAddr.String())) + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) suite.Require().False(found) } diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 21cd8c73d..7032e1175 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -43,6 +43,8 @@ func (k *Keeper) SetAuthzKeeper(authzKeeper types.AuthzKeeper) *Keeper { return k } +// ValidatorGrant related functions + func (k Keeper) HasValidatorGrant(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.ValAddress) bool { operator, found := k.GetValidatorOperator(ctx, granter) if !found { @@ -73,6 +75,8 @@ func (k Keeper) GrantAuthorization(ctx sdk.Context, grantee, granter sdk.AccAddr return nil } +// ValidatorOperator related functions + func (k Keeper) HasValidatorOperator(ctx sdk.Context, val sdk.ValAddress) bool { store := ctx.KVStore(k.storeKey) return store.Has(types.GetValidatorOperatorKey(val)) @@ -95,111 +99,101 @@ func (k Keeper) UpdateValidatorOperator(ctx sdk.Context, val sdk.ValAddress, fro store.Set(types.GetValidatorOperatorKey(val), from.Bytes()) } -func (k Keeper) SetValidatorOperatorByConsAddr(ctx sdk.Context, newConsAddr sdk.ConsAddress, valOperator sdk.ValAddress) { +// ValidatorConsAddr related functions + +func (k Keeper) SetValidatorConsAddr(ctx sdk.Context, newConsAddr sdk.ConsAddress, valOperator sdk.ValAddress) { store := ctx.KVStore(k.storeKey) store.Set(stakingtypes.GetValidatorByConsAddrKey(newConsAddr), valOperator) } -func (k Keeper) RemoveValidatorOperatorByConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) { +func (k Keeper) RemoveValidatorConsAddr(ctx sdk.Context, consAddr sdk.ConsAddress) { store := ctx.KVStore(k.storeKey) store.Delete(stakingtypes.GetValidatorByConsAddrKey(consAddr)) } -func (k Keeper) SetValidatorOldConsensusAddr(ctx sdk.Context, valAddr sdk.ValAddress, newConsAddr sdk.ConsAddress) { - store := ctx.KVStore(k.storeKey) - store.Set(types.GetValidatorOldConsensusAddrKey(valAddr), newConsAddr) -} - -func (k Keeper) RemoveValidatorOldConsensusAddr(ctx sdk.Context, valAddrs sdk.ValAddress) { - store := ctx.KVStore(k.storeKey) - store.Delete(types.GetValidatorOldConsensusAddrKey(valAddrs)) -} +// ConsensusPubKey related functions -func (k Keeper) IteratorValidatorOldConsensusAddr(ctx sdk.Context, handler func(valAddr sdk.ValAddress, consAddr sdk.ConsAddress) (stop bool)) { +func (k Keeper) GetConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) (cryptotypes.PubKey, bool) { store := ctx.KVStore(k.storeKey) - - iter := sdk.KVStorePrefixIterator(store, types.ValidatorOldConsensusAddrKey) - defer iter.Close() - - for ; iter.Valid(); iter.Next() { - valAddr := sdk.ValAddress(types.AddressFromValidatorNewConsensusAddrKey(iter.Key())) - consAddr := sdk.ConsAddress(iter.Value()) - - if handler(valAddr, consAddr) { - break - } + bz := store.Get(types.GetConsensusPubKey(valAddr)) + if bz == nil { + return nil, false } + var pubKey cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(bz, &pubKey); err != nil { + return nil, false + } + return pubKey, true } -func (k Keeper) SetValidatorDelConsensusAddr(ctx sdk.Context, valAddr sdk.ValAddress, consAddr sdk.ConsAddress) { +func (k Keeper) SetConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress, pubKey cryptotypes.PubKey) error { + bz, err := k.cdc.MarshalInterfaceJSON(pubKey) + if err != nil { + return sdkerrors.ErrJSONMarshal.Wrapf("failed to marshal pubkey: %s", err.Error()) + } store := ctx.KVStore(k.storeKey) - store.Set(types.GetValidatorDelConsensusAddrKey(valAddr), consAddr) + store.Set(types.GetConsensusPubKey(valAddr), bz) + return nil } -func (k Keeper) RemoveValidatorDelConsensusAddr(ctx sdk.Context, valAddr sdk.ValAddress) { +func (k Keeper) RemoveConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) { store := ctx.KVStore(k.storeKey) - store.Delete(types.GetValidatorDelConsensusAddrKey(valAddr)) + store.Delete(types.GetConsensusPubKey(valAddr)) } -func (k Keeper) IteratorValidatorDelConsensusAddr(ctx sdk.Context, handler func(valAddr sdk.ValAddress, address sdk.ConsAddress) (stop bool)) { +func (k Keeper) IteratorConsensusPubKey(ctx sdk.Context, h func(valAddr sdk.ValAddress, pubKey cryptotypes.PubKey)) { store := ctx.KVStore(k.storeKey) - - iter := sdk.KVStorePrefixIterator(store, types.ValidatorDelConsensusAddrKey) + iter := sdk.KVStorePrefixIterator(store, types.ConsensusPubKey) defer iter.Close() - for ; iter.Valid(); iter.Next() { - valAddr := sdk.ValAddress(types.AddressFromValidatorDelConsensusAddrKey(iter.Key())) - consAddr := sdk.ConsAddress(iter.Value()) - if handler(valAddr, consAddr) { - break + valAddr := sdk.ValAddress(types.AddressFromConsensusPubKey(iter.Key())) + + var pk cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(iter.Value(), &pk); err != nil { + k.Logger(ctx).Error("failed to unmarshal pubKey", "validator", valAddr.String(), "err", err.Error()) + // if we can't unmarshal the pubkey, delete it + store.Delete(iter.Key()) + continue } + + h(valAddr, pk) } } -func (k Keeper) GetValidatorNewConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) (cryptotypes.PubKey, bool) { +// ConsensusProcess related functions + +func (k Keeper) GetConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, process types.CProcess) (sdk.ConsAddress, bool) { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.GetValidatorNewConsensusPubKey(valAddr)) + bz := store.Get(types.GetConsensusProcessKey(process, valAddr)) if bz == nil { return nil, false } - var pubKey cryptotypes.PubKey - if err := k.cdc.UnmarshalInterfaceJSON(bz, &pubKey); err != nil { - return nil, false - } - return pubKey, true + return sdk.ConsAddress(bz), true } -func (k Keeper) SetValidatorNewConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress, pubKey cryptotypes.PubKey) error { - bz, err := k.cdc.MarshalInterfaceJSON(pubKey) - if err != nil { - return sdkerrors.ErrJSONMarshal.Wrapf("failed to marshal pubkey: %s", err.Error()) - } +func (k Keeper) HasConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress) bool { store := ctx.KVStore(k.storeKey) - store.Set(types.GetValidatorNewConsensusPubKey(valAddr), bz) - return nil + return store.Has(types.GetConsensusProcessKey(types.ProcessStart, valAddr)) || + store.Has(types.GetConsensusProcessKey(types.ProcessEnd, valAddr)) } -func (k Keeper) RemoveValidatorNewConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) { +func (k Keeper) SetConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, consAddr sdk.ConsAddress, process types.CProcess) { store := ctx.KVStore(k.storeKey) - store.Delete(types.GetValidatorNewConsensusPubKey(valAddr)) + store.Set(types.GetConsensusProcessKey(process, valAddr), consAddr) } -func (k Keeper) IteratorValidatorNewConsensusPubKey(ctx sdk.Context, handler func(valAddr sdk.ValAddress, pubKey cryptotypes.PubKey) (stop bool)) { +func (k Keeper) DeleteConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, process types.CProcess) { store := ctx.KVStore(k.storeKey) + store.Delete(types.GetConsensusProcessKey(process, valAddr)) +} - iter := sdk.KVStorePrefixIterator(store, types.ValidatorNewConsensusPubKey) +func (k Keeper) IteratorConsensusProcess(ctx sdk.Context, process types.CProcess, h func(valAddr sdk.ValAddress, consAddr sdk.ConsAddress)) { + store := ctx.KVStore(k.storeKey) + iter := sdk.KVStorePrefixIterator(store, append(types.ConsensusProcessKey, process...)) defer iter.Close() - for ; iter.Valid(); iter.Next() { - valAddr := sdk.ValAddress(types.AddressFromValidatorNewConsensusPubKey(iter.Key())) - - var pk cryptotypes.PubKey - if err := k.cdc.UnmarshalInterfaceJSON(iter.Value(), &pk); err != nil { - k.Logger(ctx).Error("failed to unmarshal pubKey", "validator", valAddr.String(), "err", err.Error()) - continue - } - if handler(valAddr, pk) { - break - } + valAddr := sdk.ValAddress(types.AddressFromConsensusProcessKey(iter.Key())) + consAddr := sdk.ConsAddress(iter.Value()) + h(valAddr, consAddr) } } diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 2da12c034..e71767c2b 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -90,10 +90,9 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon // update validator less than 1/3 total power updatePower := math.NewInt(validator.ConsensusPower(k.PowerReduction(ctx))) - k.IteratorValidatorNewConsensusPubKey(ctx, func(addr sdk.ValAddress, _ cryptotypes.PubKey) bool { + k.IteratorConsensusPubKey(ctx, func(addr sdk.ValAddress, _ cryptotypes.PubKey) { power := k.GetLastValidatorPower(ctx, addr) updatePower = updatePower.Add(math.NewInt(power)) - return false }) totalPowerOneThird := k.GetLastTotalPower(ctx).QuoRaw(3) if updatePower.GTE(totalPowerOneThird) { @@ -107,11 +106,11 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon } // set validator new consensus pubkey - if err = k.SetValidatorNewConsensusPubKey(ctx, valAddr, newPubKey); err != nil { + if err = k.SetConsensusPubKey(ctx, valAddr, newPubKey); err != nil { return nil, err } - // todo the update process(2 block) can be delegate/undelegate/redelegate? + // todo can delegate/undelegate/redelegate when process update(complete in 3 block)? emitEditConsensusPubKeyEvents(ctx, valAddr, fromAddr, newPubKey) @@ -152,36 +151,36 @@ func (k Keeper) validateAnyPubKey(ctx sdk.Context, pubkey *codectypes.Any) (cryp func (k Keeper) updateValidatorPubKey(ctx sdk.Context, validator stakingtypes.Validator, newPubKey cryptotypes.PubKey) error { newConsAddr := sdk.ConsAddress(newPubKey.Address()) - // remove old cons address - consAddr, err := validator.GetConsAddr() + oldConsAddr, err := validator.GetConsAddr() if err != nil { return err } - k.RemoveValidatorOperatorByConsAddr(ctx, consAddr) - - // update new cons address - pkAny, _ := codectypes.NewAnyWithValue(newPubKey) - validator.ConsensusPubkey = pkAny - if err := k.SetValidatorByConsAddr(ctx, validator); err != nil { - return err + // add new pubkey + if err := k.slashingKeeper.AddPubkey(ctx, newPubKey); err != nil { + return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, err.Error()) } + // remove old pubkey + k.slashingKeeper.DeleteConsensusPubKey(ctx, oldConsAddr) + // add new sign info - info, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, consAddr) + info, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) if !found { return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "validator signing info not found") } info.Address = newConsAddr.String() k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, info) - // todo delete old sign info + // remove old sign info + k.slashingKeeper.DeleteValidatorSigningInfo(ctx, oldConsAddr) - // add new pubkey - if err := k.slashingKeeper.AddPubkey(ctx, newPubKey); err != nil { - return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, err.Error()) - } - - // todo remove old pubkey + // remove old cons address + k.RemoveValidatorConsAddr(ctx, oldConsAddr) + // update new cons address + pkAny, _ := codectypes.NewAnyWithValue(newPubKey) + validator.ConsensusPubkey = pkAny + k.SetValidator(ctx, validator) + k.SetValidatorConsAddr(ctx, newConsAddr, validator.GetOperator()) return nil } diff --git a/x/staking/types/events.go b/x/staking/types/events.go index 6eee1c24f..c070d81aa 100644 --- a/x/staking/types/events.go +++ b/x/staking/types/events.go @@ -1,10 +1,12 @@ package types const ( - EventTypeApproveShares = "approve_shares" - EventTypeTransferShares = "transfer_shares" - EventTypeGrantPrivilege = "grant_privilege" - EventTypeEditConsensusPubKey = "edit_consensus_pubkey" + EventTypeApproveShares = "approve_shares" + EventTypeTransferShares = "transfer_shares" + EventTypeGrantPrivilege = "grant_privilege" + EventTypeEditConsensusPubKey = "edit_consensus_pubkey" + EventTypeStartEditConsensusPubKey = "start_edit_consensus_pubkey" + EventTypeEndEditConsensusPubKey = "end_edit_consensus_pubkey" AttributeKeyOwner = "owner" AttributeKeySpender = "spender" @@ -14,4 +16,6 @@ const ( AttributeKeyRecipient = "recipient" AttributeKeyTo = "to" AttributeKeyPubKey = "pubkey" + AttributeOldConsAddr = "old_cons_addr" + AttributeNewConsAddr = "new_cons_addr" ) diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index 580dda634..cf6c4008a 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -18,8 +18,8 @@ type AuthzKeeper interface { type SlashingKeeper interface { AddPubkey(ctx sdk.Context, pubkey cryptotypes.PubKey) error - // todo DeletePubkey(ctx sdk.Context, pubkey sdk.ConsAddress) - GetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) (info slashingtypes.ValidatorSigningInfo, found bool) - SetValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) - // todo DeleteValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) + DeleteConsensusPubKey(ctx sdk.Context, consAddr sdk.ConsAddress) + GetValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress) (info slashingtypes.ValidatorSigningInfo, found bool) + SetValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) + DeleteValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress) } diff --git a/x/staking/types/keys.go b/x/staking/types/keys.go index 2bbafe5a1..34bc43f2f 100644 --- a/x/staking/types/keys.go +++ b/x/staking/types/keys.go @@ -7,12 +7,18 @@ import ( const GrantPrivilegeSignaturePrefix = "GrantPrivilege:" +type CProcess []byte + +var ( + ProcessStart CProcess = []byte{0x1} + ProcessEnd CProcess = []byte{0x2} +) + var ( - AllowanceKey = []byte{0x90} - ValidatorOperatorKey = []byte{0x91} - ValidatorNewConsensusPubKey = []byte{0x92} - ValidatorOldConsensusAddrKey = []byte{0x93} - ValidatorDelConsensusAddrKey = []byte{0x94} + AllowanceKey = []byte{0x90} + ValidatorOperatorKey = []byte{0x91} + ConsensusPubKey = []byte{0x92} + ConsensusProcessKey = []byte{0x93} ) func GetAllowanceKey(valAddr sdk.ValAddress, owner, spender sdk.AccAddress) []byte { @@ -34,29 +40,20 @@ func GetValidatorOperatorKey(addr []byte) []byte { return append(ValidatorOperatorKey, addr...) } -func GetValidatorNewConsensusPubKey(addr sdk.ValAddress) []byte { - return append(ValidatorNewConsensusPubKey, addr...) -} - -func GetValidatorOldConsensusAddrKey(addr sdk.ValAddress) []byte { - return append(ValidatorOldConsensusAddrKey, addr...) +func GetConsensusPubKey(addr sdk.ValAddress) []byte { + return append(ConsensusPubKey, addr...) } -func GetValidatorDelConsensusAddrKey(addr sdk.ValAddress) []byte { - return append(ValidatorDelConsensusAddrKey, addr...) +func GetConsensusProcessKey(process CProcess, addr sdk.ValAddress) []byte { + return append(ConsensusProcessKey, append(process, addr...)...) } -func AddressFromValidatorNewConsensusPubKey(key []byte) []byte { - kv.AssertKeyAtLeastLength(key, 3) - return key[1:] // remove prefix bytes and address length -} - -func AddressFromValidatorNewConsensusAddrKey(key []byte) []byte { - kv.AssertKeyAtLeastLength(key, 3) +func AddressFromConsensusPubKey(key []byte) []byte { + kv.AssertKeyAtLeastLength(key, 2) return key[1:] // remove prefix bytes and address length } -func AddressFromValidatorDelConsensusAddrKey(key []byte) []byte { +func AddressFromConsensusProcessKey(key []byte) []byte { kv.AssertKeyAtLeastLength(key, 3) - return key[1:] // remove prefix bytes and address length + return key[2:] // remove prefix bytes and address length } From e4fba0f3f59580ecc771ef69e3243e9826ca64b9 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Wed, 12 Jul 2023 18:29:20 +0800 Subject: [PATCH 10/30] fix: client jsonrpc * fix Commit params * fix Validators params * fix Client Call params --- client/jsonrpc/json_rpc.go | 4 ++-- client/jsonrpc/rpc_client.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/client/jsonrpc/json_rpc.go b/client/jsonrpc/json_rpc.go index 68a04488b..e6a6369aa 100644 --- a/client/jsonrpc/json_rpc.go +++ b/client/jsonrpc/json_rpc.go @@ -463,7 +463,7 @@ func (c *NodeRPC) Commit(height int64) (*ctypes.ResultCommit, error) { result := new(ctypes.ResultCommit) params := map[string]interface{}{} if height > 0 { - params = map[string]interface{}{"height": height} + params = map[string]interface{}{"height": strconv.FormatInt(height, 10)} } err := c.caller.Call(c.ctx, "commit", params, result) if err != nil { @@ -476,7 +476,7 @@ func (c *NodeRPC) Validators(height int64, page, perPage int) (*ctypes.ResultVal result := new(ctypes.ResultValidators) params := map[string]interface{}{} if height > 0 { - params = map[string]interface{}{"height": height, "page": page, "per_page": perPage} + params = map[string]interface{}{"height": strconv.FormatInt(height, 10), "page": strconv.Itoa(page), "per_page": strconv.Itoa(perPage)} } err := c.caller.Call(c.ctx, "validators", params, result) if err != nil { diff --git a/client/jsonrpc/rpc_client.go b/client/jsonrpc/rpc_client.go index 34c7d4abc..92730e606 100644 --- a/client/jsonrpc/rpc_client.go +++ b/client/jsonrpc/rpc_client.go @@ -337,7 +337,16 @@ func (cli *Client) SetTimeout(t time.Duration) { } func (cli *Client) Call(ctx context.Context, method string, params map[string]interface{}, result interface{}) (err error) { - payload, err := json.Marshal(params) + paramsMap := make(map[string]json.RawMessage, len(params)) + for name, value := range params { + valueJSON, err := tmjson.Marshal(value) + if err != nil { + return err + } + paramsMap[name] = valueJSON + } + + payload, err := json.Marshal(paramsMap) if err != nil { return } From bf93d4684ac5a5343c27256825c757ea1d03e0b1 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Wed, 12 Jul 2023 18:30:06 +0800 Subject: [PATCH 11/30] test: validator update evidence --- x/staking/keeper/abci_test.go | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go index 0b9796960..5ec39275e 100644 --- a/x/staking/keeper/abci_test.go +++ b/x/staking/keeper/abci_test.go @@ -1,14 +1,23 @@ package keeper_test import ( + "bytes" "fmt" + "testing" "time" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/crypto/tmhash" + "github.com/tendermint/tendermint/privval" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmtypes "github.com/tendermint/tendermint/types" + "github.com/functionx/fx-core/v5/client/jsonrpc" + "github.com/functionx/fx-core/v5/testutil/helpers" "github.com/functionx/fx-core/v5/x/staking/types" ) @@ -70,3 +79,63 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) suite.Require().False(found) } + +func TestValidatorUpdateEvidence(t *testing.T) { + helpers.SkipTest(t, "Skipping local test:", t.Name()) + + keyFilePath := "" + height := int64(100) + + rpc := jsonrpc.NewNodeRPC(jsonrpc.NewClient("http://localhost:26657")) + key := privval.LoadFilePVEmptyState(keyFilePath, "") + t.Log("address:", key.GetAddress().String()) + + // val power + valResp, err := rpc.Validators(height, 1, 100) + require.NoError(t, err) + valPowers := make([]*tmtypes.Validator, 0, len(valResp.Validators)) + for _, val := range valResp.Validators { + valPowers = append(valPowers, &tmtypes.Validator{ + Address: val.Address, + PubKey: val.PubKey, + VotingPower: val.VotingPower, + ProposerPriority: val.ProposerPriority, + }) + } + + // val commit + commitResp, err := rpc.Commit(height) + require.NoError(t, err) + commit := commitResp.Commit + cs := tmtypes.CommitSig{} + for _, sig := range commitResp.Commit.Signatures { + if !bytes.Equal(sig.ValidatorAddress, key.GetAddress()) { + continue + } + if sig.BlockIDFlag == tmtypes.BlockIDFlagNil { + t.Fatalf("block %d validator BlockIDFlag is nil, change block", height) + } + cs = sig + break + } + + voteA := tmtypes.Vote{ + ValidatorAddress: cs.ValidatorAddress, + Height: commit.Height, + Round: commit.Round, + Timestamp: cs.Timestamp, + Type: tmproto.SignedMsgType(commit.Type()), + BlockID: cs.BlockID(commit.BlockID), + Signature: cs.Signature, + } + + voteB := voteA + voteB.BlockID.Hash = tmhash.Sum([]byte("test")) + voteB.Signature, err = key.Key.PrivKey.Sign(tmtypes.VoteSignBytes(commitResp.ChainID, voteB.ToProto())) + require.NoError(t, err) + + // evidence + evidence := tmtypes.NewDuplicateVoteEvidence(&voteA, &voteB, commitResp.Header.Time, tmtypes.NewValidatorSet(valPowers)) + _, err = rpc.BroadcastEvidence(evidence) + require.NoError(t, err) +} From 877121ce8474aac708fb177ec499ba9546c50479 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Fri, 14 Jul 2023 19:06:06 +0800 Subject: [PATCH 12/30] refactor: authz module * refactor GetAuthorizations * fix GrantPrivilege --- app/keepers/keepers.go | 7 +++--- app/modules.go | 2 +- x/authz/keeper/keeper.go | 48 ++++++++++++++++++++++++++++++++++++++++ x/authz/keeper/keys.go | 35 +++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 x/authz/keeper/keeper.go create mode 100644 x/authz/keeper/keys.go diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index c04fb41ca..869170134 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -55,6 +55,7 @@ import ( fxtypes "github.com/functionx/fx-core/v5/types" arbitrumtypes "github.com/functionx/fx-core/v5/x/arbitrum/types" + fxauthzkeeper "github.com/functionx/fx-core/v5/x/authz/keeper" avalanchetypes "github.com/functionx/fx-core/v5/x/avalanche/types" bsctypes "github.com/functionx/fx-core/v5/x/bsc/types" "github.com/functionx/fx-core/v5/x/crosschain" @@ -119,7 +120,7 @@ type AppKeepers struct { FxTransferKeeper fxtransferkeeper.Keeper IBCTransferKeeper ibctransferkeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper - AuthzKeeper authzkeeper.Keeper + AuthzKeeper fxauthzkeeper.Keeper // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -249,12 +250,12 @@ func NewAppKeeper( ), ) - appKeepers.AuthzKeeper = authzkeeper.NewKeeper( + appKeepers.AuthzKeeper = fxauthzkeeper.NewKeeper(authzkeeper.NewKeeper( appKeepers.keys[authzkeeper.StoreKey], appCodec, bApp.MsgServiceRouter(), appKeepers.AccountKeeper, - ) + ), appKeepers.keys[authzkeeper.StoreKey], appCodec) // grant privileges appKeepers.StakingKeeper = *appKeepers.StakingKeeper.SetAuthzKeeper(appKeepers.AuthzKeeper) diff --git a/app/modules.go b/app/modules.go index cae17af4d..cd6aa4663 100644 --- a/app/modules.go +++ b/app/modules.go @@ -174,7 +174,7 @@ func appModules( upgrade.NewAppModule(app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), - authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper.Keeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), params.NewAppModule(app.ParamsKeeper), diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go new file mode 100644 index 000000000..c34ad5476 --- /dev/null +++ b/x/authz/keeper/keeper.go @@ -0,0 +1,48 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" +) + +type Keeper struct { + authzkeeper.Keeper + storeKey storetypes.StoreKey + cdc codec.BinaryCodec +} + +func NewKeeper(k authzkeeper.Keeper, sk storetypes.StoreKey, cdc codec.Codec) Keeper { + return Keeper{ + Keeper: k, + storeKey: sk, + cdc: cdc, + } +} + +// GetAuthorizations Returns list of `Authorizations` granted to the grantee by the granter. +func (k Keeper) GetAuthorizations(ctx sdk.Context, grantee sdk.AccAddress, granter sdk.AccAddress) ([]authz.Authorization, error) { + store := ctx.KVStore(k.storeKey) + key := grantStoreKey(grantee, granter, "") + iter := sdk.KVStorePrefixIterator(store, key) + defer iter.Close() + + var authorizations []authz.Authorization + for ; iter.Valid(); iter.Next() { + var authorization authz.Grant + if err := k.cdc.Unmarshal(iter.Value(), &authorization); err != nil { + return nil, err + } + + a, err := authorization.GetAuthorization() + if err != nil { + return nil, err + } + + authorizations = append(authorizations, a) + } + + return authorizations, nil +} diff --git a/x/authz/keeper/keys.go b/x/authz/keeper/keys.go new file mode 100644 index 000000000..96caef824 --- /dev/null +++ b/x/authz/keeper/keys.go @@ -0,0 +1,35 @@ +package keeper + +import ( + "reflect" + "unsafe" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" +) + +// grantStoreKey - return authorization store key +// Items are stored with the following key: values +// +// - 0x01: Grant +func grantStoreKey(grantee sdk.AccAddress, granter sdk.AccAddress, msgType string) []byte { + m := UnsafeStrToBytes(msgType) + granter = address.MustLengthPrefix(granter) + grantee = address.MustLengthPrefix(grantee) + key := sdk.AppendLengthPrefixedBytes(authzkeeper.GrantKey, granter, grantee, m) + + return key +} + +// UnsafeStrToBytes uses unsafe to convert string into byte array. Returned bytes +// must not be altered after this function is called as it will cause a segmentation fault. +func UnsafeStrToBytes(s string) []byte { + var buf []byte + sHdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) + bufHdr := (*reflect.SliceHeader)(unsafe.Pointer(&buf)) + bufHdr.Data = sHdr.Data + bufHdr.Cap = sHdr.Len + bufHdr.Len = sHdr.Len + return buf +} From 95c82d0920d1cd767910e35db6caffdd50c45c79 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Mon, 17 Jul 2023 11:30:55 +0800 Subject: [PATCH 13/30] test: staking multinode integration test * GrantPrivilege test * EditConsensusPubKey test --- tests/integration_test.go | 26 ++++++ tests/staking_suite.go | 40 +++++++- tests/staking_test.go | 191 ++++++++++++++++++++++++++++++++++++++ tests/suite.go | 84 ++++++++++++++++- testutil/network.go | 21 +++++ 5 files changed, 357 insertions(+), 5 deletions(-) diff --git a/tests/integration_test.go b/tests/integration_test.go index 913c4a7d0..298af2093 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -61,3 +61,29 @@ func (suite *IntegrationTest) TestRun() { suite.WFXCodeCheckTest() suite.ByPassFeeTest() } + +type IntegrationMultiNodeTest struct { + *TestSuiteMultiNode + staking StakingSuite + authz AuthzSuite + slasing SlashingSuite +} + +func TestIntegrationMultiNodeTest(t *testing.T) { + if os.Getenv("TEST_INTEGRATION") != "true" { + t.Skip("skip integration test") + } + + testSuiteMultiNode := NewTestSuiteMultiNode() + suite.Run(t, &IntegrationMultiNodeTest{ + TestSuiteMultiNode: testSuiteMultiNode, + staking: NewStakingSuite(testSuiteMultiNode.TestSuite), + authz: NewAuthzSuite(testSuiteMultiNode.TestSuite), + slasing: NewSlashingSuite(testSuiteMultiNode.TestSuite), + }) +} + +func (suite *IntegrationMultiNodeTest) TestRun() { + suite.StakingEditConsensusPubKey() + suite.StakingGrantPrivilege() +} diff --git a/tests/staking_suite.go b/tests/staking_suite.go index 5708822fa..89fc604d5 100644 --- a/tests/staking_suite.go +++ b/tests/staking_suite.go @@ -7,7 +7,9 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi" @@ -18,19 +20,23 @@ import ( "github.com/functionx/fx-core/v5/client" testscontract "github.com/functionx/fx-core/v5/tests/contract" + "github.com/functionx/fx-core/v5/testutil/helpers" fxtypes "github.com/functionx/fx-core/v5/types" precompilesstaking "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" ) type StakingSuite struct { Erc20TestSuite - abi abi.ABI + abi abi.ABI + grantKey cryptotypes.PrivKey } func NewStakingSuite(ts *TestSuite) StakingSuite { + key := helpers.NewEthPrivKey() return StakingSuite{ Erc20TestSuite: NewErc20TestSuite(ts), abi: precompilesstaking.GetABI(), + grantKey: key, } } @@ -42,6 +48,14 @@ func (suite *StakingSuite) Address() common.Address { return common.BytesToAddress(suite.privKey.PubKey().Address()) } +func (suite *StakingSuite) GrantPrivKey() cryptotypes.PrivKey { + return suite.grantKey +} + +func (suite *StakingSuite) GrantAddress() sdk.AccAddress { + return sdk.AccAddress(suite.grantKey.PubKey().Address()) +} + func (suite *StakingSuite) StakingQuery() stakingtypes.QueryClient { return suite.GRPCClient().StakingQuery() } @@ -278,3 +292,27 @@ func (suite *StakingSuite) LogReward(logs []*ethtypes.Log, valAddr string, addr } return big.NewInt(0) } + +type AuthzSuite struct { + *TestSuite +} + +func NewAuthzSuite(ts *TestSuite) AuthzSuite { + return AuthzSuite{TestSuite: ts} +} + +func (suite *AuthzSuite) AuthzQuery() authz.QueryClient { + return suite.GRPCClient().AuthzQuery() +} + +type SlashingSuite struct { + *TestSuite +} + +func NewSlashingSuite(ts *TestSuite) SlashingSuite { + return SlashingSuite{TestSuite: ts} +} + +func (suite *SlashingSuite) SlashingQuery() slashingtypes.QueryClient { + return suite.GRPCClient().SlashingQuery() +} diff --git a/tests/staking_test.go b/tests/staking_test.go index 8bbb8ad5a..3698ef5ab 100644 --- a/tests/staking_test.go +++ b/tests/staking_test.go @@ -1,15 +1,24 @@ package tests import ( + "encoding/hex" "math/big" + "time" sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/authz" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/functionx/fx-core/v5/app" "github.com/functionx/fx-core/v5/testutil/helpers" fxtypes "github.com/functionx/fx-core/v5/types" precompilesstaking "github.com/functionx/fx-core/v5/x/evm/precompiles/staking" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) func (suite *IntegrationTest) StakingTest() { @@ -421,3 +430,185 @@ func (suite *IntegrationTest) StakingSharesContractTest() { totalReward = sdkmath.NewIntFromBigInt(reward3).Add(sdkmath.NewIntFromBigInt(reward4).Add(sdkmath.NewIntFromBigInt(reward6))) suite.Require().Equal(contractBal.AmountOf(fxtypes.DefaultDenom).String(), totalReward.String()) } + +func (suite *IntegrationMultiNodeTest) StakingGrantPrivilege() { + initBalance := sdkmath.NewInt(2000).MulRaw(1e18) + suite.Send(suite.staking.AccAddress(), sdk.NewCoin(fxtypes.DefaultDenom, initBalance)) + + valResp, err := suite.staking.StakingQuery().Validators(suite.ctx, &stakingtypes.QueryValidatorsRequest{Status: stakingtypes.BondStatusBonded}) + suite.Require().NoError(err) + valAddr := valResp.Validators[0].GetOperator() + from := sdk.AccAddress(valAddr) + to := sdk.AccAddress(suite.staking.privKey.PubKey().Address()) + + to2 := suite.staking.GrantAddress() + suite.Send(to2, sdk.NewCoin(fxtypes.DefaultDenom, initBalance)) + + // check val with to grants + grantResp, err := suite.authz.AuthzQuery().Grants(suite.ctx, &authz.QueryGrantsRequest{Granter: from.String(), Grantee: to.String()}) + suite.Require().NoError(err) + suite.Require().Equal(0, len(grantResp.Grants)) + + // grant privilege val with to address + sign, err := suite.staking.privKey.Sign(fxstakingtypes.GrantPrivilegeSignatureData(valAddr, from, to)) + suite.Require().NoError(err) + msg, err := fxstakingtypes.NewMsgGrantPrivilege(valAddr, sdk.AccAddress(valAddr), suite.staking.privKey.PubKey(), hex.EncodeToString(sign)) + suite.Require().NoError(err) + suite.BroadcastTx(suite.GetValidatorPrivKeys(from), msg) + + // check val with to grants + grantResp, err = suite.authz.AuthzQuery().Grants(suite.ctx, &authz.QueryGrantsRequest{Granter: from.String(), Grantee: to.String()}) + suite.Require().NoError(err) + suite.Require().Equal(1, len(grantResp.Grants)) + + // val send coins error, not have privilege + msgSend := banktypes.NewMsgSend(from, to, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdk.NewInt(100)))) + _, err = suite.GRPCClient().BuildTxV1(suite.GetValidatorPrivKeys(from), []sdk.Msg{msgSend}, 500000, "", 0) + suite.Require().Error(err) + + // grant MsgSend privilege with to address + exp := time.Now().Add(time.Hour) + msgGrant, err := authz.NewMsgGrant(from, to, authz.NewGenericAuthorization(sdk.MsgTypeURL(&banktypes.MsgSend{})), &exp) + suite.Require().NoError(err) + msgExec := authz.NewMsgExec(to, []sdk.Msg{msgGrant, msgSend}) + + _, err = suite.GRPCClient().BuildTxV1(suite.staking.privKey, []sdk.Msg{&msgExec}, 500000, "", 0) + suite.Require().NoError(err) + tx := suite.BroadcastTx(suite.staking.privKey, &msgExec) + suite.Require().Equal(uint32(0), tx.Code) + + // check val with to grants + grantResp, err = suite.authz.AuthzQuery().Grants(suite.ctx, &authz.QueryGrantsRequest{Granter: from.String(), Grantee: to.String()}) + suite.Require().NoError(err) + suite.Require().Equal(2, len(grantResp.Grants)) + + // val grant to to2 address error, val not have privilege + sign, err = suite.staking.GrantPrivKey().Sign(fxstakingtypes.GrantPrivilegeSignatureData(valAddr, from, to2)) + suite.Require().NoError(err) + msg, err = fxstakingtypes.NewMsgGrantPrivilege(valAddr, from, suite.staking.GrantPrivKey().PubKey(), hex.EncodeToString(sign)) + suite.Require().NoError(err) + _, err = suite.GRPCClient().BuildTxV1(suite.staking.privKey, []sdk.Msg{msg}, 500000, "", 0) + suite.Require().Error(err) + + // to grant to to2 address + sign, err = suite.staking.GrantPrivKey().Sign(fxstakingtypes.GrantPrivilegeSignatureData(valAddr, to, to2)) + suite.Require().NoError(err) + msg, err = fxstakingtypes.NewMsgGrantPrivilege(valAddr, to, suite.staking.GrantPrivKey().PubKey(), hex.EncodeToString(sign)) + suite.Require().NoError(err) + _, err = suite.GRPCClient().BuildTxV1(suite.staking.privKey, []sdk.Msg{msg}, 500000, "", 0) + suite.NoError(err) + suite.BroadcastTx(suite.staking.privKey, msg) + + // check val with to grants + grantResp, err = suite.authz.AuthzQuery().Grants(suite.ctx, &authz.QueryGrantsRequest{Granter: from.String(), Grantee: to.String()}) + suite.Require().NoError(err) + suite.Require().Equal(0, len(grantResp.Grants)) + + // check to with to2 grants + grantResp, err = suite.authz.AuthzQuery().Grants(suite.ctx, &authz.QueryGrantsRequest{Granter: from.String(), Grantee: to2.String()}) + suite.Require().NoError(err) + suite.Require().Equal(1, len(grantResp.Grants)) + + // grant privilege edit consenus pubkey + msgGrant, err = authz.NewMsgGrant(from, suite.staking.GrantAddress(), authz.NewGenericAuthorization(sdk.MsgTypeURL(&fxstakingtypes.MsgEditConsensusPubKey{})), &exp) + suite.Require().NoError(err) + + // edit consenus pubkey + newPriKey := ed25519.GenPrivKey() + msgEdit, err := fxstakingtypes.NewMsgEditConsensusPubKey(valAddr, suite.staking.GrantAddress(), newPriKey.PubKey()) + suite.Require().NoError(err) + + msgExec = authz.NewMsgExec(suite.staking.GrantAddress(), []sdk.Msg{msgGrant, msgEdit}) + tx = suite.BroadcastTx(suite.staking.GrantPrivKey(), &msgExec) + suite.Require().Equal(uint32(0), tx.Code) +} + +func (suite *IntegrationMultiNodeTest) StakingEditConsensusPubKey() { + if suite.QueryBalances(suite.staking.AccAddress()).IsZero() { + suite.Send(suite.staking.AccAddress(), sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(2000).MulRaw(1e18))) + } + + // query all validator + valsResp, err := suite.staking.StakingQuery().Validators(suite.ctx, &stakingtypes.QueryValidatorsRequest{Status: stakingtypes.BondStatusBonded}) + suite.Require().NoError(err) + // val addr + valAddr := valsResp.Validators[2].GetOperator() + // val consensus pubkey + var oldPubKey cryptotypes.PubKey + err = app.MakeEncodingConfig().InterfaceRegistry.UnpackAny(valsResp.Validators[2].ConsensusPubkey, &oldPubKey) + suite.Require().NoError(err) + valFrom := sdk.AccAddress(valAddr) + // new consenus pubkey + newPriKey := ed25519.GenPrivKey() + + // check signing info + infos, err := suite.slasing.SlashingQuery().SigningInfos(suite.ctx, &slashingtypes.QuerySigningInfosRequest{}) + suite.Require().NoError(err) + for _, info := range infos.Info { + suite.True(info.MissedBlocksCounter == 0) + } + + // edit consensus pubkey to new consenus pubkey + msg, err := fxstakingtypes.NewMsgEditConsensusPubKey(valAddr, valFrom, newPriKey.PubKey()) + suite.Require().NoError(err) + suite.BroadcastTx(suite.GetValidatorPrivKeys(valFrom), msg) + + // wait 15 block + _, err = suite.network.WaitForHeightWithTimeout(suite.BlockNumber()+15, 30*time.Second) + suite.Require().NoError(err) + + // check signing info + infos, err = suite.slasing.SlashingQuery().SigningInfos(suite.ctx, &slashingtypes.QuerySigningInfosRequest{}) + suite.Require().NoError(err) + for _, info := range infos.Info { + if info.Address == sdk.ConsAddress(newPriKey.PubKey().Address()).String() { + suite.True(info.MissedBlocksCounter > 0) + continue + } + suite.True(info.MissedBlocksCounter == 0) + } + + // validator jailed + valResp, err := suite.staking.StakingQuery().Validator(suite.ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: valAddr.String()}) + suite.Require().NoError(err) + suite.Require().True(valResp.Validator.Jailed) + + // edit consensus pubkey to old consenus pubkey + msg, err = fxstakingtypes.NewMsgEditConsensusPubKey(valAddr, valFrom, oldPubKey) + suite.Require().NoError(err) + suite.BroadcastTx(suite.GetValidatorPrivKeys(valFrom), msg) + + // check signing info + infos, err = suite.slasing.SlashingQuery().SigningInfos(suite.ctx, &slashingtypes.QuerySigningInfosRequest{}) + suite.Require().NoError(err) + for _, info := range infos.Info { + if info.Address == sdk.ConsAddress(oldPubKey.Address()).String() { + suite.True(info.MissedBlocksCounter > 0) + continue + } + suite.True(info.MissedBlocksCounter == 0) + } + + // unjail validator + msgUnjail := slashingtypes.NewMsgUnjail(valAddr) + suite.BroadcastTx(suite.GetValidatorPrivKeys(valFrom), msgUnjail) + + // check validator unjailed + valResp, err = suite.staking.StakingQuery().Validator(suite.ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: valAddr.String()}) + suite.Require().NoError(err) + suite.Require().False(valResp.Validator.Jailed) + + // check signing info + infoResp, err := suite.slasing.SlashingQuery().SigningInfo(suite.ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: sdk.ConsAddress(oldPubKey.Address()).String()}) + suite.Require().NoError(err) + missBlock := infoResp.ValSigningInfo.MissedBlocksCounter + + // wait 15 block + _, err = suite.network.WaitForHeightWithTimeout(suite.BlockNumber()+15, 30*time.Second) + suite.Require().NoError(err) + + // check signing info + infoResp, err = suite.slasing.SlashingQuery().SigningInfo(suite.ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: sdk.ConsAddress(oldPubKey.Address()).String()}) + suite.Require().NoError(err) + suite.Require().Equal(missBlock, infoResp.ValSigningInfo.MissedBlocksCounter) +} diff --git a/tests/suite.go b/tests/suite.go index a87a10a75..2acf72a2d 100644 --- a/tests/suite.go +++ b/tests/suite.go @@ -40,6 +40,8 @@ type TestSuite struct { network *network.Network ctx context.Context proposalId uint64 + numValidator int + timeoutCommit time.Duration } func NewTestSuite() *TestSuite { @@ -48,6 +50,7 @@ func NewTestSuite() *TestSuite { useLocalNetwork: false, proposalId: 0, ctx: context.Background(), + numValidator: 1, } if os.Getenv("USE_LOCAL_NETWORK") == "true" { testSuite.useLocalNetwork = true @@ -71,20 +74,46 @@ func (suite *TestSuite) SetupSuite() { } suite.T().Log("setting up integration test suite") + numValidators := suite.numValidator + timeoutCommit := time.Millisecond + if numValidators > 1 { + timeoutCommit = 500 * time.Millisecond + } + suite.timeoutCommit = timeoutCommit + ibcGenesisOpt := func(config *network.Config) { config.GenesisState = testutil.IbcGenesisState(encCfg.Codec, config.GenesisState) } bankGenesisOpt := func(config *network.Config) { config.GenesisState = testutil.BankGenesisState(encCfg.Codec, config.GenesisState) } - cfg := testutil.DefaultNetworkConfig(encCfg, ibcGenesisOpt, bankGenesisOpt) - cfg.TimeoutCommit = time.Millisecond - cfg.NumValidators = 1 + govGenesisOpt := func(config *network.Config) { + votingPeriod := time.Millisecond + if numValidators > 1 { + votingPeriod = time.Duration(numValidators*5) * timeoutCommit + } + config.GenesisState = testutil.GovGenesisState(encCfg.Codec, config.GenesisState, votingPeriod) + } + slashingGenesisOpt := func(config *network.Config) { + signedBlocksWindow := int64(10) + minSignedPerWindow := sdk.NewDecWithPrec(2, 1) + downtimeJailDuration := 5 * time.Second + config.GenesisState = testutil.SlashingGenesisState(encCfg.Codec, config.GenesisState, signedBlocksWindow, minSignedPerWindow, downtimeJailDuration) + } + + cfg := testutil.DefaultNetworkConfig(encCfg, ibcGenesisOpt, bankGenesisOpt, govGenesisOpt, slashingGenesisOpt) + cfg.TimeoutCommit = timeoutCommit + cfg.NumValidators = numValidators // cfg.EnableTMLogging = true baseDir, err := os.MkdirTemp(suite.T().TempDir(), cfg.ChainID) suite.Require().NoError(err) suite.network, err = network.New(suite.T(), baseDir, cfg) + + time.Sleep(timeoutCommit * 10) + for suite.BlockNumber() <= 3 { + time.Sleep(timeoutCommit * 2) + } suite.Require().NoError(err) } @@ -120,6 +149,10 @@ func (suite *TestSuite) GetFirstValidator() *network.Validator { return suite.network.Validators[0] } +func (suite *TestSuite) GetAllValidators() []*network.Validator { + return suite.network.Validators +} + func (suite *TestSuite) GetFirstValPrivKey() cryptotypes.PrivKey { if suite.IsUseLocalNetwork() { k, err := keyring.New(suite.T().Name(), keyring.BackendTest, suite.network.BaseDir, os.Stdin, suite.network.Config.Codec) @@ -133,6 +166,30 @@ func (suite *TestSuite) GetFirstValPrivKey() cryptotypes.PrivKey { return privKey } +func (suite *TestSuite) GetAllValPrivKeys() []cryptotypes.PrivKey { + if suite.IsUseLocalNetwork() { + return []cryptotypes.PrivKey{suite.GetFirstValPrivKey()} + } + var privKeys []cryptotypes.PrivKey + for _, mnemonics := range suite.network.Config.Mnemonics { + privKey, err := helpers.PrivKeyFromMnemonic(mnemonics, hd.Secp256k1Type, 0, 0) + suite.NoError(err) + privKeys = append(privKeys, privKey) + } + return privKeys +} + +func (suite *TestSuite) GetValidatorPrivKeys(addr sdk.AccAddress) cryptotypes.PrivKey { + for _, mnemonics := range suite.network.Config.Mnemonics { + privKey, err := helpers.PrivKeyFromMnemonic(mnemonics, hd.Secp256k1Type, 0, 0) + suite.NoError(err) + if addr.Equals(sdk.AccAddress(privKey.PubKey().Address())) { + return privKey + } + } + return nil +} + func (suite *TestSuite) GRPCClient() *grpc.Client { if suite.GetFirstValidator().ClientCtx.GRPCClient != nil { return grpc.NewClient(suite.GetFirstValidator().ClientCtx) @@ -174,7 +231,7 @@ func (suite *TestSuite) GetMetadata(denom string) banktypes.Metadata { func (suite *TestSuite) BlockNumber() int64 { height, err := suite.GRPCClient().GetBlockHeight() - suite.Error(err) + suite.NoError(err) return height } @@ -216,6 +273,7 @@ func (suite *TestSuite) BroadcastTx(privKey cryptotypes.PrivKey, msgList ...sdk. // txResponse might be nil, but error is also nil suite.NotNil(txResponse) suite.T().Log("broadcast tx", "msg:", sdk.MsgTypeURL(msgList[0]), "txHash:", txResponse.TxHash) + suite.NoError(suite.network.WaitForNextBlock()) return txResponse } @@ -476,3 +534,21 @@ type unsafeExporter interface { // ExportPrivateKeyObject returns a private key in unarmored format. ExportPrivateKeyObject(uid string) (cryptotypes.PrivKey, error) } + +type TestSuiteMultiNode struct { + *TestSuite +} + +func NewTestSuiteMultiNode() *TestSuiteMultiNode { + testSuite := &TestSuite{ + Suite: suite.Suite{}, + useLocalNetwork: false, + proposalId: 0, + ctx: context.Background(), + numValidator: 4, + } + if os.Getenv("USE_LOCAL_NETWORK") == "true" { + testSuite.useLocalNetwork = true + } + return &TestSuiteMultiNode{TestSuite: testSuite} +} diff --git a/testutil/network.go b/testutil/network.go index 88704c2c0..4a86679c0 100644 --- a/testutil/network.go +++ b/testutil/network.go @@ -18,6 +18,7 @@ import ( distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v6/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types" @@ -173,6 +174,26 @@ func BankGenesisState(cdc codec.Codec, genesisState app.GenesisState) app.Genesi return genesisState } +func GovGenesisState(cdc codec.Codec, genesisState app.GenesisState, votingPeriod time.Duration) app.GenesisState { + var govGenState govv1beta1.GenesisState + cdc.MustUnmarshalJSON(genesisState[govtypes.ModuleName], &govGenState) + govGenState.VotingParams.VotingPeriod = votingPeriod + + genesisState[govtypes.ModuleName] = cdc.MustMarshalJSON(&govGenState) + return genesisState +} + +func SlashingGenesisState(cdc codec.Codec, genesisState app.GenesisState, signedBlocksWindow int64, minSignedPerWindow sdk.Dec, downtimeJailDuration time.Duration) app.GenesisState { + var slashingState slashingtypes.GenesisState + cdc.MustUnmarshalJSON(genesisState[slashingtypes.ModuleName], &slashingState) + slashingState.Params.SignedBlocksWindow = signedBlocksWindow + slashingState.Params.MinSignedPerWindow = minSignedPerWindow + slashingState.Params.DowntimeJailDuration = downtimeJailDuration + + genesisState[slashingtypes.ModuleName] = cdc.MustMarshalJSON(&slashingState) + return genesisState +} + func buildCapabilityGenesisState() capabilitytypes.GenesisState { capabilityState := capabilitytypes.GenesisState{} capabilityState.Index = 3 From 9d649e415d3e13695536be0985eecfc7d72662fc Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Mon, 17 Jul 2023 13:53:39 +0800 Subject: [PATCH 14/30] fix: staking EditConsensusPubKey * check updating status * authorized before operation * perf abci --- x/staking/keeper/abci.go | 12 +++++++++--- x/staking/keeper/keeper.go | 5 +++++ x/staking/keeper/msg_server.go | 17 ++++++++++------- x/staking/types/events.go | 12 ++++++------ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index 25b9f43a8..8977c5891 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -37,7 +37,7 @@ func (k Keeper) ConsensusProcess(ctx sdk.Context) { k.slashingKeeper.DeleteValidatorSigningInfo(ctx, oldConsAddr) ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeEndEditConsensusPubKey, + types.EventTypeEditedConsensusPubKey, sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), )) }) @@ -60,11 +60,13 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, newPubKey cryptotypes.PubKey) { validator, found := k.GetValidator(ctx, valAddr) if !found { + k.Logger(ctx).Error("validator not found", "address", valAddr.String()) k.RemoveConsensusPubKey(ctx, valAddr) return } oldPubKey, err := validator.ConsPubKey() if err != nil { + k.Logger(ctx).Error("invalid consensus pubkey", "address", valAddr.String(), "error", err.Error()) k.RemoveConsensusPubKey(ctx, valAddr) return } @@ -104,7 +106,7 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda "oldConsAddr", oldConsAddr.String(), "newConsAddr", sdk.ConsAddress(newPubKey.Address()).String()) ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeStartEditConsensusPubKey, + types.EventTypeEditingConsensusPubKey, sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), sdk.NewAttribute(types.AttributeOldConsAddr, oldConsAddr.String()), sdk.NewAttribute(types.AttributeNewConsAddr, sdk.ConsAddress(newPubKey.Address()).String()), @@ -113,6 +115,10 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda // commit cache context commit() }) + // no validator update consensus pubkey + if len(pkUpdate) == 0 { + return valUpdates + } // joint pkPower and pkUpdate newValUpdates := make([]abci.ValidatorUpdate, 0, len(pkPower)+len(pkUpdate)) for tmPk, power := range pkPower { @@ -145,7 +151,7 @@ func (k Keeper) updateSlashing(ctx sdk.Context, newPubKey cryptotypes.PubKey, ol // add signing info signingInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) if !found { - return errors.New("expected signing info to be found") + return errors.New("expected signing info not found") } signingInfo.Address = newConsAddr.String() k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, signingInfo) diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 7032e1175..3d143d7dc 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -126,6 +126,11 @@ func (k Keeper) GetConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) (cry return pubKey, true } +func (k Keeper) HasConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) bool { + store := ctx.KVStore(k.storeKey) + return store.Has(types.GetConsensusPubKey(valAddr)) +} + func (k Keeper) SetConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress, pubKey cryptotypes.PubKey) error { bz, err := k.cdc.MarshalInterfaceJSON(pubKey) if err != nil { diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index e71767c2b..dc44ba599 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -73,6 +73,16 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "validator %s not found", msg.ValidatorAddress) } + // authorized from address + if !k.HasValidatorGrant(ctx, fromAddr, valAddr) { + return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "from address not authorized") + } + + // check validator is updating consensus pubkey + if k.HasConsensusPubKey(ctx, valAddr) || k.HasConsensusProcess(ctx, valAddr) { + return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "validator %s is updating consensus pubkey", msg.ValidatorAddress) + } + // pubkey and address newPubKey, err := k.validateAnyPubKey(ctx, msg.Pubkey) if err != nil { @@ -100,18 +110,11 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon "update power %s more than 1/3 total power %s", updatePower.String(), totalPowerOneThird.String()) } - // from authorized - if !k.HasValidatorGrant(ctx, fromAddr, valAddr) { - return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "from address not authorized") - } - // set validator new consensus pubkey if err = k.SetConsensusPubKey(ctx, valAddr, newPubKey); err != nil { return nil, err } - // todo can delegate/undelegate/redelegate when process update(complete in 3 block)? - emitEditConsensusPubKeyEvents(ctx, valAddr, fromAddr, newPubKey) return &types.MsgEditConsensusPubKeyResponse{}, err diff --git a/x/staking/types/events.go b/x/staking/types/events.go index c070d81aa..62ea31932 100644 --- a/x/staking/types/events.go +++ b/x/staking/types/events.go @@ -1,12 +1,12 @@ package types const ( - EventTypeApproveShares = "approve_shares" - EventTypeTransferShares = "transfer_shares" - EventTypeGrantPrivilege = "grant_privilege" - EventTypeEditConsensusPubKey = "edit_consensus_pubkey" - EventTypeStartEditConsensusPubKey = "start_edit_consensus_pubkey" - EventTypeEndEditConsensusPubKey = "end_edit_consensus_pubkey" + EventTypeApproveShares = "approve_shares" + EventTypeTransferShares = "transfer_shares" + EventTypeGrantPrivilege = "grant_privilege" + EventTypeEditConsensusPubKey = "edit_consensus_pubkey" + EventTypeEditingConsensusPubKey = "editing_consensus_pubkey" + EventTypeEditedConsensusPubKey = "edited_consensus_pubkey" AttributeKeyOwner = "owner" AttributeKeySpender = "spender" From 40cb6793a5d410538b66fe2c7beea803182487b9 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Wed, 19 Jul 2023 11:41:02 +0800 Subject: [PATCH 15/30] refactor: staking EditConsensusPubKey --- x/staking/keeper/abci.go | 321 +++++++++++++++++++++++++++------ x/staking/keeper/abci_test.go | 59 ++++-- x/staking/keeper/keeper.go | 40 ++-- x/staking/keeper/msg_server.go | 96 +++------- x/staking/module.go | 9 +- 5 files changed, 360 insertions(+), 165 deletions(-) diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index 8977c5891..07217a041 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -2,126 +2,297 @@ package keeper import ( "errors" + "fmt" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/tendermint/tendermint/abci/types" + tmcrypto "github.com/tendermint/tendermint/crypto" + cryptoenc "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/proto/tendermint/crypto" "github.com/functionx/fx-core/v5/x/staking/types" ) -func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { - valUpdates := staking.EndBlocker(ctx, k.Keeper) - - k.ConsensusProcess(ctx) - return k.ValidatorUpdate(ctx, valUpdates) +func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { + staking.BeginBlocker(ctx, k.Keeper) + k.lastCommit = req.LastCommitInfo.GetVotes() } -func (k Keeper) ConsensusProcess(ctx sdk.Context) { - // process end, remove old consensus key - k.IteratorConsensusProcess(ctx, types.ProcessEnd, func(valAddr sdk.ValAddress, oldConsAddr sdk.ConsAddress) { - k.DeleteConsensusProcess(ctx, valAddr, types.ProcessEnd) +func (k *Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { + // staking EndBlocker + valUpdates := staking.EndBlocker(ctx, k.Keeper) + if len(k.lastCommit) == 0 { + return valUpdates + } + + // clear lastCommit after EndBlocker + defer func() { k.lastCommit = make([]abci.VoteInfo, 0) }() - // remove validator by old consensus address - k.RemoveValidatorConsAddr(ctx, oldConsAddr) + // convert valUpdate and lastCommit to map + pkPowerUpdate := make(map[crypto.PublicKey]int64, len(valUpdates)) + for _, valUpdate := range valUpdates { + pkPowerUpdate[valUpdate.PubKey] = valUpdate.Power + } + lastVote := make(map[string]bool, len(k.lastCommit)) + for _, voteInfo := range k.lastCommit { + lastVote[string(voteInfo.Validator.Address)] = true + } - // remove old consensus pubkey - k.slashingKeeper.DeleteConsensusPubKey(ctx, oldConsAddr) + // consensus process start and end + k.ConsensusProcess(ctx, pkPowerUpdate, lastVote) - // remove old validator signing info - k.slashingKeeper.DeleteValidatorSigningInfo(ctx, oldConsAddr) + // update validator consensus pubkey + return k.ValidatorUpdate(ctx, pkPowerUpdate, lastVote) +} - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeEditedConsensusPubKey, - sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), - )) +func (k Keeper) ConsensusProcess(ctx sdk.Context, pkPowerUpdate map[crypto.PublicKey]int64, lastVote map[string]bool) { + k.IteratorConsensusProcess(ctx, types.ProcessEnd, func(valAddr sdk.ValAddress, pkBytes []byte) { + err := k.processEnd(ctx, lastVote, valAddr, pkBytes) + if err != nil { + panic(err) + } }) - // process start to end - k.IteratorConsensusProcess(ctx, types.ProcessStart, func(valAddr sdk.ValAddress, oldConsAddr sdk.ConsAddress) { - k.DeleteConsensusProcess(ctx, valAddr, types.ProcessStart) - k.SetConsensusProcess(ctx, valAddr, oldConsAddr, types.ProcessEnd) + k.IteratorConsensusProcess(ctx, types.ProcessStart, func(valAddr sdk.ValAddress, pkBytes []byte) { + err := k.processStart(ctx, pkPowerUpdate, lastVote, valAddr, pkBytes) + if err != nil { + panic(err) + } }) } -func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpdate) []abci.ValidatorUpdate { - proposer := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress) - pkPower := make(map[crypto.PublicKey]int64, len(valUpdates)) - for _, valUpdate := range valUpdates { - pkPower[valUpdate.PubKey] = valUpdate.Power +func (k Keeper) processEnd(ctx sdk.Context, lastVote map[string]bool, valAddr sdk.ValAddress, pkBytes []byte) error { + k.DeleteConsensusProcess(ctx, valAddr, types.ProcessEnd) + + _, _, newConsAddr, err := k.getValidatorKey(ctx, valAddr) + if err != nil { + return err + } + _, oldTmPk, oldConsAddr, err := k.unmarshalPubKey(pkBytes) + if err != nil { + return err + } + + // case1: validator jailed current block + // case2: validator jailed previous block + // impossible case: power == 0 && !validator.Jailed, power != 0 && validator.Jailed + // case3: validator unjailed current block + // case4: validator always online + + lastVoted := lastVote[string(oldTmPk.Address())] + if lastVoted { + if err := k.updateSigningInfo(ctx, oldConsAddr, newConsAddr); err != nil { + panic(err) + } + } + + // remove validator by old consensus address + k.RemoveValidatorConsAddr(ctx, oldConsAddr) + + // remove old consensus pubkey + k.slashingKeeper.DeleteConsensusPubKey(ctx, oldConsAddr) + + // remove old validator signing info + k.slashingKeeper.DeleteValidatorSigningInfo(ctx, oldConsAddr) + + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeEditedConsensusPubKey, + sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), + )) + + return nil +} + +func (k Keeper) processStart( + ctx sdk.Context, + pkPowerUpdate map[crypto.PublicKey]int64, + lastVote map[string]bool, + valAddr sdk.ValAddress, + pkBytes []byte, +) error { + k.DeleteConsensusProcess(ctx, valAddr, types.ProcessStart) + + validator, newTmProtoPk, newConsAddr, err := k.getValidatorKey(ctx, valAddr) + if err != nil { + return err } + oldPubKey, oldTmPk, oldConsAddr, err := k.unmarshalPubKey(pkBytes) + if err != nil { + return err + } + + // set process end first + if err = k.SetConsensusProcess(ctx, valAddr, oldPubKey, types.ProcessEnd); err != nil { + return err + } + + power, ok := pkPowerUpdate[newTmProtoPk] // only new pk, validator consensus pk update previous block + if !ok { + power = validator.ConsensusPower(k.PowerReduction(ctx)) + } + + // case1: validator jailed current block(missed blocks/double sign/low power) + if ok && power == 0 && validator.Jailed { + return k.updateSigningInfo(ctx, oldConsAddr, newConsAddr) + } + + // case2: validator jailed previous block + if power == 0 && validator.Jailed { + return nil + } + + // impossible case: power != 0 && validator jailed, power == 0 && validator unjailed + // power !=0 && validator unjailed + + // case3: validator jailed previous block, unjailed current block + lastVoted := lastVote[string(oldTmPk.Address())] // only old pk, validator new pk vote in next block + if !lastVoted && !validator.Jailed { + return nil + } + + // case4: validator already online + // maybe miss block current height, update signing info + return k.updateSigningInfo(ctx, oldConsAddr, newConsAddr) +} + +func (k Keeper) getValidatorKey(ctx sdk.Context, valAddr sdk.ValAddress) (stakingtypes.Validator, crypto.PublicKey, sdk.ConsAddress, error) { + // todo validator not found ?? + validator, found := k.GetValidator(ctx, valAddr) + if !found { + return stakingtypes.Validator{}, crypto.PublicKey{}, nil, + fmt.Errorf("validator %s not found", valAddr.String()) + } + pubKey, err := validator.ConsPubKey() + if err != nil { + return stakingtypes.Validator{}, crypto.PublicKey{}, nil, + fmt.Errorf("invalid validator %s pubkey", valAddr.String()) + } + tmProtoPk, err := cryptocodec.ToTmProtoPublicKey(pubKey) + if err != nil { + return stakingtypes.Validator{}, crypto.PublicKey{}, nil, + fmt.Errorf("invalid validator %s pubkey", valAddr.String()) + } + consAddr := sdk.ConsAddress(pubKey.Address()) + return validator, tmProtoPk, consAddr, nil +} + +func (k Keeper) unmarshalPubKey(pkBytes []byte) (cryptotypes.PubKey, tmcrypto.PubKey, sdk.ConsAddress, error) { + var pubKey cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(pkBytes, &pubKey); err != nil { + return nil, nil, nil, fmt.Errorf("invalid pubkey") + } + tmProtoPk, err := cryptocodec.ToTmProtoPublicKey(pubKey) + if err != nil { + return nil, nil, nil, fmt.Errorf("invalid pubkey") + } + tmPk, err := cryptoenc.PubKeyFromProto(tmProtoPk) + if err != nil { + return nil, nil, nil, fmt.Errorf("invalid pubkey") + } + consAddr := sdk.ConsAddress(pubKey.Address()) + return pubKey, tmPk, consAddr, nil +} + +func (k Keeper) updateSigningInfo(ctx sdk.Context, oldConsAddr, newConsAddr sdk.ConsAddress) error { + oldSigningInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) + if !found { + return fmt.Errorf("validator %s not found signing info", oldConsAddr.String()) + } + newSigningInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, newConsAddr) + if !found { + return fmt.Errorf("validator %s not found signing info", newConsAddr.String()) + } + // double sign + if newSigningInfo.JailedUntil == evidencetypes.DoubleSignJailEndTime { + newSigningInfo.IndexOffset = oldSigningInfo.IndexOffset + newSigningInfo.MissedBlocksCounter = oldSigningInfo.MissedBlocksCounter + } else { + newSigningInfo = oldSigningInfo + newSigningInfo.Address = newConsAddr.String() + } + k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newSigningInfo) + return nil +} + +func (k Keeper) ValidatorUpdate(ctx sdk.Context, pkPowerUpdate map[crypto.PublicKey]int64, lastVote map[string]bool) []abci.ValidatorUpdate { + proposer := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress) pkUpdate := make([]abci.ValidatorUpdate, 0, 50) - k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, newPubKey cryptotypes.PubKey) { + k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, pkBytes []byte) bool { validator, found := k.GetValidator(ctx, valAddr) if !found { k.Logger(ctx).Error("validator not found", "address", valAddr.String()) k.RemoveConsensusPubKey(ctx, valAddr) - return + return false } oldPubKey, err := validator.ConsPubKey() if err != nil { k.Logger(ctx).Error("invalid consensus pubkey", "address", valAddr.String(), "error", err.Error()) k.RemoveConsensusPubKey(ctx, valAddr) - return + return false } oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) // if validator is proposer, skip this block if oldConsAddr.Equals(proposer) { k.Logger(ctx).Info("validator is proposer, skip update", "address", valAddr.String()) - return + return false } // no matter what happens next, clear new consensus pubkey k.RemoveConsensusPubKey(ctx, valAddr) + // unmarshal failed, remove new consensus pubkey + var newPubKey cryptotypes.PubKey + if err = k.cdc.UnmarshalInterfaceJSON(pkBytes, &newPubKey); err != nil { + k.Logger(ctx).Error("unmarshal new consensus pubkey", "validator", valAddr.String(), "err", err.Error()) + return false + } + cacheCtx, commit := ctx.CacheContext() // update validator pubkey if err = k.updateValidator(cacheCtx, validator, newPubKey); err != nil { k.Logger(ctx).Error("update validator", "address", valAddr.String(), "error", err.Error()) - return + return false } // slash update if err = k.updateSlashing(cacheCtx, newPubKey, oldConsAddr); err != nil { k.Logger(ctx).Error("update slashing", "address", valAddr.String(), "error", err.Error()) - return + return false } // new validator updates - newValUpdates, err := k.updateABICValidator(cacheCtx, pkPower, validator, newPubKey, oldPubKey) + newValUpdates, err := k.updateABICValidator(cacheCtx, pkPowerUpdate, lastVote, validator, newPubKey, oldPubKey) if err != nil { k.Logger(ctx).Error("update abci validator", "address", valAddr.String(), "error", err.Error()) - return + return false } - pkUpdate = append(pkUpdate, newValUpdates...) - // set consensus process start - k.SetConsensusProcess(ctx, valAddr, oldConsAddr, types.ProcessStart) + if err := k.SetConsensusProcess(ctx, valAddr, oldPubKey, types.ProcessStart); err != nil { + return false + } k.Logger(ctx).Info("update consensus pubkey", "address", valAddr.String(), "oldConsAddr", oldConsAddr.String(), "newConsAddr", sdk.ConsAddress(newPubKey.Address()).String()) - ctx.EventManager().EmitEvent(sdk.NewEvent( types.EventTypeEditingConsensusPubKey, sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), sdk.NewAttribute(types.AttributeOldConsAddr, oldConsAddr.String()), sdk.NewAttribute(types.AttributeNewConsAddr, sdk.ConsAddress(newPubKey.Address()).String()), )) - // commit cache context commit() + + pkUpdate = append(pkUpdate, newValUpdates...) + return false }) - // no validator update consensus pubkey - if len(pkUpdate) == 0 { - return valUpdates - } - // joint pkPower and pkUpdate - newValUpdates := make([]abci.ValidatorUpdate, 0, len(pkPower)+len(pkUpdate)) - for tmPk, power := range pkPower { + // joint pkPowerUpdate and pkUpdate + newValUpdates := make([]abci.ValidatorUpdate, 0, len(pkPowerUpdate)+len(pkUpdate)) + for tmPk, power := range pkPowerUpdate { newValUpdates = append(newValUpdates, abci.ValidatorUpdate{PubKey: tmPk, Power: power}) } newValUpdates = append(newValUpdates, pkUpdate...) @@ -159,24 +330,58 @@ func (k Keeper) updateSlashing(ctx sdk.Context, newPubKey cryptotypes.PubKey, ol return nil } -func (k Keeper) updateABICValidator(ctx sdk.Context, pkPower map[crypto.PublicKey]int64, validator stakingtypes.Validator, newPubKey, oldPubKey cryptotypes.PubKey) ([]abci.ValidatorUpdate, error) { - oldTmPk, err := cryptocodec.ToTmProtoPublicKey(oldPubKey) +func (k Keeper) updateABICValidator( + ctx sdk.Context, + pkPower map[crypto.PublicKey]int64, + lastVote map[string]bool, + validator stakingtypes.Validator, + newPubKey, oldPubKey cryptotypes.PubKey, +) ([]abci.ValidatorUpdate, error) { + oldTmProtoPk, err := cryptocodec.ToTmProtoPublicKey(oldPubKey) if err != nil { return nil, err } - newTmPk, err := cryptocodec.ToTmProtoPublicKey(newPubKey) + oldTmPk, err := cryptoenc.PubKeyFromProto(oldTmProtoPk) + if err != nil { + return nil, err + } + newTmProtoPk, err := cryptocodec.ToTmProtoPublicKey(newPubKey) if err != nil { return nil, err } - power, ok := pkPower[oldTmPk] - // if power not found, use validator power + power, ok := pkPower[oldTmProtoPk] + // if power not found, validator not update current block, cal validator power if !ok { power = validator.ConsensusPower(k.PowerReduction(ctx)) + } else { + // remove old pk power + delete(pkPower, oldTmProtoPk) + } + // set old pk power to 0 + oldPkUpdate := abci.ValidatorUpdate{PubKey: oldTmProtoPk, Power: 0} + // add new pk with power + newPkUpdate := abci.ValidatorUpdate{PubKey: newTmProtoPk, Power: power} + + // case1: validator jailed current block + if ok && power == 0 && validator.Jailed { + return []abci.ValidatorUpdate{oldPkUpdate}, nil } - // set old tmPk power to 0, remove - oldTmPkUpdate := abci.ValidatorUpdate{PubKey: oldTmPk, Power: 0} - // add new tmPk with power - newTmPkUpdate := abci.ValidatorUpdate{PubKey: newTmPk, Power: power} - return []abci.ValidatorUpdate{oldTmPkUpdate, newTmPkUpdate}, nil + + // case2: validator jailed previous block + if power == 0 && validator.Jailed { + return []abci.ValidatorUpdate{}, nil + } + + // impossible case: power == 0 && validator unjailed, power != 0 && validator jailed + // power !=0 && validator unjailed + + // case3: validator jailed previous block, unjailed current block + lastVoted := lastVote[string(oldTmPk.Address())] + if !lastVoted && !validator.Jailed { + return []abci.ValidatorUpdate{newPkUpdate}, nil + } + + // case4: validator already online + return []abci.ValidatorUpdate{oldPkUpdate, newPkUpdate}, nil } diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go index 5ec39275e..4ece52ef4 100644 --- a/x/staking/keeper/abci_test.go +++ b/x/staking/keeper/abci_test.go @@ -6,13 +6,15 @@ import ( "testing" "time" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" + cryptoenc "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/privval" + "github.com/tendermint/tendermint/proto/tendermint/crypto" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" @@ -39,44 +41,61 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { found = suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, valAddr) suite.Require().False(found) + pkPowerUpdate := make(map[crypto.PublicKey]int64) + lastVote := make(map[string]bool) + + validators := suite.app.StakingKeeper.GetValidators(suite.ctx, 100) + for _, val := range validators { + pubKey, err := val.ConsPubKey() + suite.Require().NoError(err) + tmProtoPk, err := cryptocodec.ToTmProtoPublicKey(pubKey) + suite.Require().NoError(err) + tmPk, err := cryptoenc.PubKeyFromProto(tmProtoPk) + suite.Require().NoError(err) + lastVote[string(tmPk.Address())] = true + } + // validator update(process start) - updates := suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, []abci.ValidatorUpdate{}) + updates := suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, pkPowerUpdate, lastVote) suite.Require().Len(updates, 2) - updates = suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, []abci.ValidatorUpdate{}) + updates = suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, pkPowerUpdate, lastVote) suite.Require().Len(updates, 0) _, found = suite.app.StakingKeeper.GetConsensusPubKey(suite.ctx, valAddr) suite.Require().False(found) - oldConsAddr, found := suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) - suite.Require().True(found) - suite.Require().Equal(consAddr, oldConsAddr) - _, found = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessEnd) - suite.Require().False(found) + oldPk, err := suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) + suite.Require().NoError(err) + suite.Require().Equal(consAddr, sdk.ConsAddress(oldPk.Address())) + nilPk, err := suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessEnd) + suite.Require().NoError(err) + suite.Require().Nil(nilPk) // consensus process(process end) - suite.app.StakingKeeper.ConsensusProcess(suite.ctx) + suite.app.StakingKeeper.ConsensusProcess(suite.ctx, pkPowerUpdate, lastVote) - _, found = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) - suite.Require().False(found) - oldConsAddr, found = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessEnd) - suite.Require().True(found) - suite.Require().Equal(consAddr, oldConsAddr) + nilPk, err = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) + suite.Require().NoError(err) + suite.Require().Nil(nilPk) + + oldPk, err = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessEnd) + suite.Require().NoError(err) + suite.Require().Equal(consAddr, sdk.ConsAddress(oldPk.Address())) - _, err = suite.app.SlashingKeeper.GetPubkey(suite.ctx, oldConsAddr.Bytes()) + _, err = suite.app.SlashingKeeper.GetPubkey(suite.ctx, oldPk.Address()) suite.Require().NoError(err) - _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(oldPk.Address())) suite.Require().True(found) // consensus process(process delete) - suite.app.StakingKeeper.ConsensusProcess(suite.ctx) + suite.app.StakingKeeper.ConsensusProcess(suite.ctx, pkPowerUpdate, lastVote) _, found = suite.app.StakingKeeper.GetConsensusPubKey(suite.ctx, valAddr) suite.Require().False(found) - _, err = suite.app.SlashingKeeper.GetPubkey(suite.ctx, oldConsAddr.Bytes()) - suite.Require().ErrorContains(err, fmt.Sprintf("address %s not found", oldConsAddr.String())) - _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + _, err = suite.app.SlashingKeeper.GetPubkey(suite.ctx, oldPk.Address()) + suite.Require().ErrorContains(err, fmt.Sprintf("address %s not found", sdk.ConsAddress(oldPk.Address()).String())) + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(oldPk.Address())) suite.Require().False(found) } diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 3d143d7dc..49de25a15 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + abci "github.com/tendermint/tendermint/abci/types" "github.com/functionx/fx-core/v5/x/staking/types" ) @@ -22,6 +23,8 @@ type Keeper struct { authzKeeper types.AuthzKeeper slashingKeeper types.SlashingKeeper + + lastCommit []abci.VoteInfo } // NewKeeper creates a new staking Keeper instance @@ -146,34 +149,31 @@ func (k Keeper) RemoveConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress) { store.Delete(types.GetConsensusPubKey(valAddr)) } -func (k Keeper) IteratorConsensusPubKey(ctx sdk.Context, h func(valAddr sdk.ValAddress, pubKey cryptotypes.PubKey)) { +func (k Keeper) IteratorConsensusPubKey(ctx sdk.Context, h func(valAddr sdk.ValAddress, pkBytes []byte) bool) { store := ctx.KVStore(k.storeKey) iter := sdk.KVStorePrefixIterator(store, types.ConsensusPubKey) defer iter.Close() for ; iter.Valid(); iter.Next() { valAddr := sdk.ValAddress(types.AddressFromConsensusPubKey(iter.Key())) - - var pk cryptotypes.PubKey - if err := k.cdc.UnmarshalInterfaceJSON(iter.Value(), &pk); err != nil { - k.Logger(ctx).Error("failed to unmarshal pubKey", "validator", valAddr.String(), "err", err.Error()) - // if we can't unmarshal the pubkey, delete it - store.Delete(iter.Key()) - continue + if h(valAddr, iter.Value()) { + break } - - h(valAddr, pk) } } // ConsensusProcess related functions -func (k Keeper) GetConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, process types.CProcess) (sdk.ConsAddress, bool) { +func (k Keeper) GetConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, process types.CProcess) (cryptotypes.PubKey, error) { store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetConsensusProcessKey(process, valAddr)) if bz == nil { - return nil, false + return nil, nil + } + var pubKey cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(bz, &pubKey); err != nil { + return nil, err } - return sdk.ConsAddress(bz), true + return pubKey, nil } func (k Keeper) HasConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress) bool { @@ -182,9 +182,14 @@ func (k Keeper) HasConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress) boo store.Has(types.GetConsensusProcessKey(types.ProcessEnd, valAddr)) } -func (k Keeper) SetConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, consAddr sdk.ConsAddress, process types.CProcess) { +func (k Keeper) SetConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, pubKey cryptotypes.PubKey, process types.CProcess) error { + bz, err := k.cdc.MarshalInterfaceJSON(pubKey) + if err != nil { + return sdkerrors.ErrJSONMarshal.Wrapf("failed to marshal pubkey: %s", err.Error()) + } store := ctx.KVStore(k.storeKey) - store.Set(types.GetConsensusProcessKey(process, valAddr), consAddr) + store.Set(types.GetConsensusProcessKey(process, valAddr), bz) + return nil } func (k Keeper) DeleteConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, process types.CProcess) { @@ -192,13 +197,12 @@ func (k Keeper) DeleteConsensusProcess(ctx sdk.Context, valAddr sdk.ValAddress, store.Delete(types.GetConsensusProcessKey(process, valAddr)) } -func (k Keeper) IteratorConsensusProcess(ctx sdk.Context, process types.CProcess, h func(valAddr sdk.ValAddress, consAddr sdk.ConsAddress)) { +func (k Keeper) IteratorConsensusProcess(ctx sdk.Context, process types.CProcess, h func(valAddr sdk.ValAddress, pkBytes []byte)) { store := ctx.KVStore(k.storeKey) iter := sdk.KVStorePrefixIterator(store, append(types.ConsensusProcessKey, process...)) defer iter.Close() for ; iter.Valid(); iter.Next() { valAddr := sdk.ValAddress(types.AddressFromConsensusProcessKey(iter.Key())) - consAddr := sdk.ConsAddress(iter.Value()) - h(valAddr, consAddr) + h(valAddr, iter.Value()) } } diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index dc44ba599..08ef1bdab 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -72,12 +72,10 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon if !found { return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "validator %s not found", msg.ValidatorAddress) } - // authorized from address if !k.HasValidatorGrant(ctx, fromAddr, valAddr) { return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "from address not authorized") } - // check validator is updating consensus pubkey if k.HasConsensusPubKey(ctx, valAddr) || k.HasConsensusProcess(ctx, valAddr) { return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "validator %s is updating consensus pubkey", msg.ValidatorAddress) @@ -88,26 +86,32 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon if err != nil { return nil, err } + newConsAddr := sdk.ConsAddress(newPubKey.Address()) - // validator jailed/inactive, update pubkey - if validator.IsJailed() || validator.IsUnbonding() || validator.IsUnbonded() { - if err := k.updateValidatorPubKey(ctx, validator, newPubKey); err != nil { - return nil, err + newPkFound := false + totalUpdatePower := math.NewInt(validator.ConsensusPower(k.PowerReduction(ctx))) + k.IteratorConsensusPubKey(ctx, func(addr sdk.ValAddress, pkBytes []byte) bool { + var pk cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(pkBytes, &pk); err != nil { + k.Logger(ctx).Error("failed to unmarshal pubKey", "validator", valAddr.String(), "err", err.Error()) + return false + } + if newConsAddr.Equals(sdk.ConsAddress(pk.Address())) { + newPkFound = true + return true } - emitEditConsensusPubKeyEvents(ctx, valAddr, fromAddr, newPubKey) - return &types.MsgEditConsensusPubKeyResponse{}, nil - } - - // update validator less than 1/3 total power - updatePower := math.NewInt(validator.ConsensusPower(k.PowerReduction(ctx))) - k.IteratorConsensusPubKey(ctx, func(addr sdk.ValAddress, _ cryptotypes.PubKey) { power := k.GetLastValidatorPower(ctx, addr) - updatePower = updatePower.Add(math.NewInt(power)) + totalUpdatePower = totalUpdatePower.Add(math.NewInt(power)) + return false }) - totalPowerOneThird := k.GetLastTotalPower(ctx).QuoRaw(3) - if updatePower.GTE(totalPowerOneThird) { - return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, - "update power %s more than 1/3 total power %s", updatePower.String(), totalPowerOneThird.String()) + + if newPkFound { // new pk already exists + return nil, stakingtypes.ErrValidatorPubKeyExists.Wrapf("new consensus pubkey %s already exists", newConsAddr.String()) + } + totalPowerOneThird := k.GetLastTotalPower(ctx).QuoRaw(3) // less than 1/3 total power + if totalUpdatePower.GTE(totalPowerOneThird) { + return nil, sdkerrors.ErrInvalidRequest.Wrapf("total update power %s more than 1/3 total power %s", + totalUpdatePower.String(), totalPowerOneThird.String()) } // set validator new consensus pubkey @@ -115,7 +119,12 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon return nil, err } - emitEditConsensusPubKeyEvents(ctx, valAddr, fromAddr, newPubKey) + ctx.EventManager().EmitEvent(sdk.NewEvent( + types.EventTypeEditConsensusPubKey, + sdk.NewAttribute(stakingtypes.AttributeKeyValidator, msg.ValidatorAddress), + sdk.NewAttribute(types.AttributeKeyFrom, msg.From), + sdk.NewAttribute(types.AttributeKeyPubKey, newPubKey.String()), + )) return &types.MsgEditConsensusPubKeyResponse{}, err } @@ -143,55 +152,8 @@ func (k Keeper) validateAnyPubKey(ctx sdk.Context, pubkey *codectypes.Any) (cryp } } if !hasKeyType { - return nil, errorsmod.Wrapf( - stakingtypes.ErrValidatorPubKeyTypeNotSupported, - "got: %s, expected: %s", pk.Type(), cp.Validator.PubKeyTypes, - ) + return nil, stakingtypes.ErrValidatorPubKeyTypeNotSupported.Wrapf("got: %s, expected: %s", pk.Type(), cp.Validator.PubKeyTypes) } } return pk, nil } - -func (k Keeper) updateValidatorPubKey(ctx sdk.Context, validator stakingtypes.Validator, newPubKey cryptotypes.PubKey) error { - newConsAddr := sdk.ConsAddress(newPubKey.Address()) - oldConsAddr, err := validator.GetConsAddr() - if err != nil { - return err - } - // add new pubkey - if err := k.slashingKeeper.AddPubkey(ctx, newPubKey); err != nil { - return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, err.Error()) - } - // remove old pubkey - k.slashingKeeper.DeleteConsensusPubKey(ctx, oldConsAddr) - - // add new sign info - info, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) - if !found { - return errorsmod.Wrap(sdkerrors.ErrUnknownAddress, "validator signing info not found") - } - info.Address = newConsAddr.String() - k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, info) - - // remove old sign info - k.slashingKeeper.DeleteValidatorSigningInfo(ctx, oldConsAddr) - - // remove old cons address - k.RemoveValidatorConsAddr(ctx, oldConsAddr) - - // update new cons address - pkAny, _ := codectypes.NewAnyWithValue(newPubKey) - validator.ConsensusPubkey = pkAny - k.SetValidator(ctx, validator) - k.SetValidatorConsAddr(ctx, newConsAddr, validator.GetOperator()) - return nil -} - -func emitEditConsensusPubKeyEvents(ctx sdk.Context, val sdk.ValAddress, from sdk.AccAddress, newPubKey cryptotypes.PubKey) { - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeEditConsensusPubKey, - sdk.NewAttribute(stakingtypes.AttributeKeyValidator, val.String()), - sdk.NewAttribute(types.AttributeKeyFrom, from.String()), - sdk.NewAttribute(types.AttributeKeyPubKey, newPubKey.String()), - )) -} diff --git a/x/staking/module.go b/x/staking/module.go index ce39afa14..47e59d27c 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -62,7 +62,7 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { type AppModule struct { staking.AppModule AppModuleBasic AppModuleBasic - Keeper keeper.Keeper + Keeper *keeper.Keeper } // NewAppModule creates a new AppModule object @@ -71,7 +71,7 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak stakingtypes.Account return AppModule{ AppModuleBasic: AppModuleBasic{AppModuleBasic: stakingAppModule.AppModuleBasic}, AppModule: stakingAppModule, - Keeper: keeper, + Keeper: &keeper, } } @@ -80,6 +80,11 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { am.AppModule.RegisterServices(cfg) } +// BeginBlock returns the begin blocker for the staking module. +func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { + am.Keeper.BeginBlock(ctx, req) +} + // EndBlock returns the end blocker for the staking module. It returns no validator // updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { From 19325035bcf0e90a90e32d9608e726a14d02be2f Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Fri, 21 Jul 2023 19:04:55 +0800 Subject: [PATCH 16/30] test: EditConsensusPubKey * fix EditConsensusPubKey --- tests/integration_test.go | 3 +- tests/staking_test.go | 107 ++++++- tests/suite.go | 16 +- testutil/helpers/test_helpers.go | 2 +- testutil/network/network.go | 8 + x/staking/keeper/abci.go | 52 ++-- x/staking/keeper/abci_test.go | 465 +++++++++++++++++++++++++++++-- x/staking/keeper/keeper_test.go | 116 +++++++- x/staking/keeper/msg_server.go | 24 ++ 9 files changed, 726 insertions(+), 67 deletions(-) diff --git a/tests/integration_test.go b/tests/integration_test.go index 298af2093..6eca4ab3b 100644 --- a/tests/integration_test.go +++ b/tests/integration_test.go @@ -84,6 +84,7 @@ func TestIntegrationMultiNodeTest(t *testing.T) { } func (suite *IntegrationMultiNodeTest) TestRun() { - suite.StakingEditConsensusPubKey() + suite.StakingEditPubKey() suite.StakingGrantPrivilege() + suite.StakingEditPubKeyJailBlock() } diff --git a/tests/staking_test.go b/tests/staking_test.go index 3698ef5ab..0a2a51de1 100644 --- a/tests/staking_test.go +++ b/tests/staking_test.go @@ -2,6 +2,7 @@ package tests import ( "encoding/hex" + "fmt" "math/big" "time" @@ -9,10 +10,12 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "google.golang.org/grpc/metadata" "github.com/functionx/fx-core/v5/app" "github.com/functionx/fx-core/v5/testutil/helpers" @@ -435,9 +438,9 @@ func (suite *IntegrationMultiNodeTest) StakingGrantPrivilege() { initBalance := sdkmath.NewInt(2000).MulRaw(1e18) suite.Send(suite.staking.AccAddress(), sdk.NewCoin(fxtypes.DefaultDenom, initBalance)) - valResp, err := suite.staking.StakingQuery().Validators(suite.ctx, &stakingtypes.QueryValidatorsRequest{Status: stakingtypes.BondStatusBonded}) - suite.Require().NoError(err) - valAddr := valResp.Validators[0].GetOperator() + allVals := suite.GetAllValidators() + valAddr := allVals[1].ValAddress + from := sdk.AccAddress(valAddr) to := sdk.AccAddress(suite.staking.privKey.PubKey().Address()) @@ -523,19 +526,21 @@ func (suite *IntegrationMultiNodeTest) StakingGrantPrivilege() { suite.Require().Equal(uint32(0), tx.Code) } -func (suite *IntegrationMultiNodeTest) StakingEditConsensusPubKey() { +func (suite *IntegrationMultiNodeTest) StakingEditPubKey() { if suite.QueryBalances(suite.staking.AccAddress()).IsZero() { suite.Send(suite.staking.AccAddress(), sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(2000).MulRaw(1e18))) } // query all validator - valsResp, err := suite.staking.StakingQuery().Validators(suite.ctx, &stakingtypes.QueryValidatorsRequest{Status: stakingtypes.BondStatusBonded}) + allVals := suite.GetAllValidators() + valAddr := allVals[2].ValAddress + valResp, err := suite.staking.StakingQuery().Validator(suite.ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: valAddr.String()}) suite.Require().NoError(err) // val addr - valAddr := valsResp.Validators[2].GetOperator() + validator := valResp.Validator // val consensus pubkey var oldPubKey cryptotypes.PubKey - err = app.MakeEncodingConfig().InterfaceRegistry.UnpackAny(valsResp.Validators[2].ConsensusPubkey, &oldPubKey) + err = app.MakeEncodingConfig().InterfaceRegistry.UnpackAny(validator.ConsensusPubkey, &oldPubKey) suite.Require().NoError(err) valFrom := sdk.AccAddress(valAddr) // new consenus pubkey @@ -554,7 +559,7 @@ func (suite *IntegrationMultiNodeTest) StakingEditConsensusPubKey() { suite.BroadcastTx(suite.GetValidatorPrivKeys(valFrom), msg) // wait 15 block - _, err = suite.network.WaitForHeightWithTimeout(suite.BlockNumber()+15, 30*time.Second) + _, err = suite.network.WaitNumberBlock(15) suite.Require().NoError(err) // check signing info @@ -569,7 +574,7 @@ func (suite *IntegrationMultiNodeTest) StakingEditConsensusPubKey() { } // validator jailed - valResp, err := suite.staking.StakingQuery().Validator(suite.ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: valAddr.String()}) + valResp, err = suite.staking.StakingQuery().Validator(suite.ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: valAddr.String()}) suite.Require().NoError(err) suite.Require().True(valResp.Validator.Jailed) @@ -582,7 +587,7 @@ func (suite *IntegrationMultiNodeTest) StakingEditConsensusPubKey() { infos, err = suite.slasing.SlashingQuery().SigningInfos(suite.ctx, &slashingtypes.QuerySigningInfosRequest{}) suite.Require().NoError(err) for _, info := range infos.Info { - if info.Address == sdk.ConsAddress(oldPubKey.Address()).String() { + if info.Address == sdk.ConsAddress(oldPubKey.Address()).String() || info.Address == sdk.ConsAddress(newPriKey.PubKey().Address()).String() { suite.True(info.MissedBlocksCounter > 0) continue } @@ -604,7 +609,7 @@ func (suite *IntegrationMultiNodeTest) StakingEditConsensusPubKey() { missBlock := infoResp.ValSigningInfo.MissedBlocksCounter // wait 15 block - _, err = suite.network.WaitForHeightWithTimeout(suite.BlockNumber()+15, 30*time.Second) + _, err = suite.network.WaitNumberBlock(15) suite.Require().NoError(err) // check signing info @@ -612,3 +617,83 @@ func (suite *IntegrationMultiNodeTest) StakingEditConsensusPubKey() { suite.Require().NoError(err) suite.Require().Equal(missBlock, infoResp.ValSigningInfo.MissedBlocksCounter) } + +func (suite *IntegrationMultiNodeTest) StakingEditPubKeyJailBlock() { + if suite.QueryBalances(suite.staking.AccAddress()).IsZero() { + suite.Send(suite.staking.AccAddress(), sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(2000).MulRaw(1e18))) + } + + // query all validator + allVals := suite.GetAllValidators() + valAddr := allVals[3].ValAddress + valResp, err := suite.staking.StakingQuery().Validator(suite.ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: valAddr.String()}) + suite.Require().NoError(err) + validator := valResp.Validator + + // val consensus pubkey + var oldPubKey cryptotypes.PubKey + err = app.MakeEncodingConfig().InterfaceRegistry.UnpackAny(validator.ConsensusPubkey, &oldPubKey) + suite.Require().NoError(err) + oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) + + valFrom := sdk.AccAddress(valAddr) + // new consenus pubkey + newPriKey := ed25519.GenPrivKey() + newPubKey := newPriKey.PubKey() + newConsAddr := sdk.ConsAddress(newPubKey.Address()) + + // edit consensus pubkey to new consenus pubkey and undelegate all + editPubkeyMsg, err := fxstakingtypes.NewMsgEditConsensusPubKey(valAddr, valFrom, newPubKey) + suite.Require().NoError(err) + undelegateMsg := stakingtypes.NewMsgUndelegate(sdk.AccAddress(valAddr), valAddr, sdk.NewCoin(fxtypes.DefaultDenom, validator.Tokens)) + txResp := suite.BroadcastTx(suite.GetValidatorPrivKeys(valFrom), editPubkeyMsg, undelegateMsg) + suite.Require().Equal(uint32(0), txResp.Code) + suite.Require().Greater(txResp.Height, int64(0)) + + _, _ = suite.network.WaitNumberBlock(10) + + valResp, err = suite.staking.StakingQuery().Validator(suite.ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: valAddr.String()}) + suite.Require().NoError(err) + suite.Require().True(valResp.Validator.Jailed) + + height := txResp.Height + + // block tx process + ctx := metadata.AppendToOutgoingContext(suite.ctx, grpctypes.GRPCBlockHeightHeader, fmt.Sprintf("%d", height)) + info1, err := suite.slasing.SlashingQuery().SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: oldConsAddr.String()}) + suite.NoError(err) + info2, err := suite.slasing.SlashingQuery().SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: newConsAddr.String()}) + suite.NoError(err) + suite.Equal(info1.ValSigningInfo.IndexOffset, info2.ValSigningInfo.IndexOffset) + suite.Equal(info1.ValSigningInfo.MissedBlocksCounter, info2.ValSigningInfo.MissedBlocksCounter) + + // block tx process +1 + ctx = metadata.AppendToOutgoingContext(suite.ctx, grpctypes.GRPCBlockHeightHeader, fmt.Sprintf("%d", height+1)) + info1, err = suite.slasing.SlashingQuery().SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: oldConsAddr.String()}) + suite.NoError(err) + info2, err = suite.slasing.SlashingQuery().SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: newConsAddr.String()}) + suite.NoError(err) + suite.Equal(info1.ValSigningInfo.IndexOffset, info2.ValSigningInfo.IndexOffset) + suite.Equal(info1.ValSigningInfo.MissedBlocksCounter, info2.ValSigningInfo.MissedBlocksCounter) + + // block tx process +2 + ctx = metadata.AppendToOutgoingContext(suite.ctx, grpctypes.GRPCBlockHeightHeader, fmt.Sprintf("%d", height+2)) + _, err = suite.slasing.SlashingQuery().SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: oldConsAddr.String()}) + suite.Error(err) + info2, err = suite.slasing.SlashingQuery().SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: newConsAddr.String()}) + suite.NoError(err) + suite.Equal(info1.ValSigningInfo.IndexOffset+1, info2.ValSigningInfo.IndexOffset) + + // delegate and unjail + delegateMsg := stakingtypes.NewMsgDelegate(sdk.AccAddress(valAddr), valAddr, sdk.NewCoin(fxtypes.DefaultDenom, validator.Tokens)) + unjailMsg := slashingtypes.NewMsgUnjail(valAddr) + editPubkeyMsg, err = fxstakingtypes.NewMsgEditConsensusPubKey(valAddr, valFrom, oldPubKey) + suite.Require().NoError(err) + _ = suite.BroadcastTx(suite.GetValidatorPrivKeys(valFrom), delegateMsg, unjailMsg, editPubkeyMsg) + + _, _ = suite.network.WaitNumberBlock(3) + + valResp, err = suite.staking.StakingQuery().Validator(suite.ctx, &stakingtypes.QueryValidatorRequest{ValidatorAddr: valAddr.String()}) + suite.Require().NoError(err) + suite.Require().False(valResp.Validator.Jailed) +} diff --git a/tests/suite.go b/tests/suite.go index 2acf72a2d..4754cefb0 100644 --- a/tests/suite.go +++ b/tests/suite.go @@ -42,6 +42,7 @@ type TestSuite struct { proposalId uint64 numValidator int timeoutCommit time.Duration + enableTMLogging bool } func NewTestSuite() *TestSuite { @@ -104,7 +105,9 @@ func (suite *TestSuite) SetupSuite() { cfg := testutil.DefaultNetworkConfig(encCfg, ibcGenesisOpt, bankGenesisOpt, govGenesisOpt, slashingGenesisOpt) cfg.TimeoutCommit = timeoutCommit cfg.NumValidators = numValidators - // cfg.EnableTMLogging = true + if suite.enableTMLogging { + cfg.EnableTMLogging = true + } baseDir, err := os.MkdirTemp(suite.T().TempDir(), cfg.ChainID) suite.Require().NoError(err) @@ -272,7 +275,7 @@ func (suite *TestSuite) BroadcastTx(privKey cryptotypes.PrivKey, msgList ...sdk. suite.NoError(err) // txResponse might be nil, but error is also nil suite.NotNil(txResponse) - suite.T().Log("broadcast tx", "msg:", sdk.MsgTypeURL(msgList[0]), "txHash:", txResponse.TxHash) + suite.T().Log("broadcast tx", "msg:", sdk.MsgTypeURL(msgList[0]), "height:", txResponse.Height, "txHash:", txResponse.TxHash) suite.NoError(suite.network.WaitForNextBlock()) return txResponse } @@ -545,10 +548,17 @@ func NewTestSuiteMultiNode() *TestSuiteMultiNode { useLocalNetwork: false, proposalId: 0, ctx: context.Background(), - numValidator: 4, + numValidator: 7, + // enableTMLogging: true, } if os.Getenv("USE_LOCAL_NETWORK") == "true" { testSuite.useLocalNetwork = true } return &TestSuiteMultiNode{TestSuite: testSuite} } + +func (suite *TestSuiteMultiNode) PrintBlock() { + height, err := suite.network.LatestHeight() + suite.NoError(err) + suite.T().Log("current block height:", height) +} diff --git a/testutil/helpers/test_helpers.go b/testutil/helpers/test_helpers.go index 4764380cf..939e353e5 100644 --- a/testutil/helpers/test_helpers.go +++ b/testutil/helpers/test_helpers.go @@ -170,7 +170,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs UnbondingHeight: int64(0), UnbondingTime: time.Unix(0, 0).UTC(), Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), - MinSelfDelegation: sdkmath.ZeroInt(), + MinSelfDelegation: sdkmath.OneInt().Mul(sdk.NewInt(10)), } validators = append(validators, validator) delegations = append(delegations, stakingtypes.NewDelegation(genAccs[i].GetAddress(), validator.GetOperator(), sdk.NewDecFromInt(bondAmt))) diff --git a/testutil/network/network.go b/testutil/network/network.go index bcaddc4b1..61c99f4bc 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -496,6 +496,14 @@ func (n *Network) WaitForHeight(h int64) (int64, error) { return n.WaitForHeightWithTimeout(h, 10*time.Second) } +func (n *Network) WaitNumberBlock(number int64) (int64, error) { + lastBlock, err := n.LatestHeight() + if err != nil { + return 0, err + } + return n.WaitForHeightWithTimeout(lastBlock+number, time.Duration(3*number)*n.Config.TimeoutCommit) +} + // WaitForHeightWithTimeout is the same as WaitForHeight except the caller can // provide a custom timeout. func (n *Network) WaitForHeightWithTimeout(h int64, t time.Duration) (int64, error) { diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index 07217a041..ca82be183 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -35,9 +35,9 @@ func (k *Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { defer func() { k.lastCommit = make([]abci.VoteInfo, 0) }() // convert valUpdate and lastCommit to map - pkPowerUpdate := make(map[crypto.PublicKey]int64, len(valUpdates)) + pkPowerUpdate := make(map[string]int64, len(valUpdates)) for _, valUpdate := range valUpdates { - pkPowerUpdate[valUpdate.PubKey] = valUpdate.Power + pkPowerUpdate[valUpdate.PubKey.String()] = valUpdate.Power } lastVote := make(map[string]bool, len(k.lastCommit)) for _, voteInfo := range k.lastCommit { @@ -48,26 +48,26 @@ func (k *Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { k.ConsensusProcess(ctx, pkPowerUpdate, lastVote) // update validator consensus pubkey - return k.ValidatorUpdate(ctx, pkPowerUpdate, lastVote) + return k.ValidatorUpdate(ctx, valUpdates, pkPowerUpdate, lastVote) } -func (k Keeper) ConsensusProcess(ctx sdk.Context, pkPowerUpdate map[crypto.PublicKey]int64, lastVote map[string]bool) { +func (k Keeper) ConsensusProcess(ctx sdk.Context, pkPowerUpdate map[string]int64, lastVote map[string]bool) { k.IteratorConsensusProcess(ctx, types.ProcessEnd, func(valAddr sdk.ValAddress, pkBytes []byte) { - err := k.processEnd(ctx, lastVote, valAddr, pkBytes) + err := k.consesnsusProcessEnd(ctx, lastVote, valAddr, pkBytes) if err != nil { panic(err) } }) k.IteratorConsensusProcess(ctx, types.ProcessStart, func(valAddr sdk.ValAddress, pkBytes []byte) { - err := k.processStart(ctx, pkPowerUpdate, lastVote, valAddr, pkBytes) + err := k.consensusProcessStart(ctx, pkPowerUpdate, lastVote, valAddr, pkBytes) if err != nil { panic(err) } }) } -func (k Keeper) processEnd(ctx sdk.Context, lastVote map[string]bool, valAddr sdk.ValAddress, pkBytes []byte) error { +func (k Keeper) consesnsusProcessEnd(ctx sdk.Context, lastVote map[string]bool, valAddr sdk.ValAddress, pkBytes []byte) error { k.DeleteConsensusProcess(ctx, valAddr, types.ProcessEnd) _, _, newConsAddr, err := k.getValidatorKey(ctx, valAddr) @@ -109,9 +109,9 @@ func (k Keeper) processEnd(ctx sdk.Context, lastVote map[string]bool, valAddr sd return nil } -func (k Keeper) processStart( +func (k Keeper) consensusProcessStart( ctx sdk.Context, - pkPowerUpdate map[crypto.PublicKey]int64, + pkPowerUpdate map[string]int64, lastVote map[string]bool, valAddr sdk.ValAddress, pkBytes []byte, @@ -132,7 +132,7 @@ func (k Keeper) processStart( return err } - power, ok := pkPowerUpdate[newTmProtoPk] // only new pk, validator consensus pk update previous block + power, ok := pkPowerUpdate[newTmProtoPk.String()] // only new pk, validator consensus pk update previous block if !ok { power = validator.ConsensusPower(k.PowerReduction(ctx)) } @@ -142,8 +142,14 @@ func (k Keeper) processStart( return k.updateSigningInfo(ctx, oldConsAddr, newConsAddr) } + lastVoted := lastVote[string(oldTmPk.Address())] // only old pk, validator new pk vote in next block + // case2: validator jailed previous block if power == 0 && validator.Jailed { + // jailed last-1 or last block + if lastVoted { + return k.updateSigningInfo(ctx, oldConsAddr, newConsAddr) + } return nil } @@ -151,12 +157,11 @@ func (k Keeper) processStart( // power !=0 && validator unjailed // case3: validator jailed previous block, unjailed current block - lastVoted := lastVote[string(oldTmPk.Address())] // only old pk, validator new pk vote in next block if !lastVoted && !validator.Jailed { return nil } - // case4: validator already online + // case4: validator always online or jailed(low power) last block, unjailed current block // maybe miss block current height, update signing info return k.updateSigningInfo(ctx, oldConsAddr, newConsAddr) } @@ -220,8 +225,7 @@ func (k Keeper) updateSigningInfo(ctx sdk.Context, oldConsAddr, newConsAddr sdk. return nil } -func (k Keeper) ValidatorUpdate(ctx sdk.Context, pkPowerUpdate map[crypto.PublicKey]int64, lastVote map[string]bool) []abci.ValidatorUpdate { - proposer := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress) +func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpdate, pkPowerUpdate map[string]int64, lastVote map[string]bool) []abci.ValidatorUpdate { pkUpdate := make([]abci.ValidatorUpdate, 0, 50) k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, pkBytes []byte) bool { @@ -238,11 +242,6 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, pkPowerUpdate map[crypto.Public return false } oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) - // if validator is proposer, skip this block - if oldConsAddr.Equals(proposer) { - k.Logger(ctx).Info("validator is proposer, skip update", "address", valAddr.String()) - return false - } // no matter what happens next, clear new consensus pubkey k.RemoveConsensusPubKey(ctx, valAddr) @@ -292,8 +291,10 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, pkPowerUpdate map[crypto.Public }) // joint pkPowerUpdate and pkUpdate newValUpdates := make([]abci.ValidatorUpdate, 0, len(pkPowerUpdate)+len(pkUpdate)) - for tmPk, power := range pkPowerUpdate { - newValUpdates = append(newValUpdates, abci.ValidatorUpdate{PubKey: tmPk, Power: power}) + for _, vu := range valUpdates { + if power, ok := pkPowerUpdate[vu.PubKey.String()]; ok { + newValUpdates = append(newValUpdates, abci.ValidatorUpdate{PubKey: vu.PubKey, Power: power}) + } } newValUpdates = append(newValUpdates, pkUpdate...) return newValUpdates @@ -317,7 +318,6 @@ func (k Keeper) updateSlashing(ctx sdk.Context, newPubKey cryptotypes.PubKey, ol if err := k.slashingKeeper.AddPubkey(ctx, newPubKey); err != nil { return err } - newConsAddr := sdk.ConsAddress(newPubKey.Address()) // add signing info signingInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) @@ -326,13 +326,12 @@ func (k Keeper) updateSlashing(ctx sdk.Context, newPubKey cryptotypes.PubKey, ol } signingInfo.Address = newConsAddr.String() k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, signingInfo) - return nil } func (k Keeper) updateABICValidator( ctx sdk.Context, - pkPower map[crypto.PublicKey]int64, + pkPower map[string]int64, lastVote map[string]bool, validator stakingtypes.Validator, newPubKey, oldPubKey cryptotypes.PubKey, @@ -349,14 +348,13 @@ func (k Keeper) updateABICValidator( if err != nil { return nil, err } - - power, ok := pkPower[oldTmProtoPk] + power, ok := pkPower[oldTmProtoPk.String()] // if power not found, validator not update current block, cal validator power if !ok { power = validator.ConsensusPower(k.PowerReduction(ctx)) } else { // remove old pk power - delete(pkPower, oldTmProtoPk) + delete(pkPower, oldTmProtoPk.String()) } // set old pk power to 0 oldPkUpdate := abci.ValidatorUpdate{PubKey: oldTmProtoPk, Power: 0} diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go index 4ece52ef4..00100a9e0 100644 --- a/x/staking/keeper/abci_test.go +++ b/x/staking/keeper/abci_test.go @@ -4,17 +4,14 @@ import ( "bytes" "fmt" "testing" - "time" - cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/require" - cryptoenc "github.com/tendermint/tendermint/crypto/encoding" + abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/privval" - "github.com/tendermint/tendermint/proto/tendermint/crypto" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" @@ -28,9 +25,9 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) suite.Require().True(found) - consAddr, err := validator.GetConsAddr() + oldPK, err := validator.ConsPubKey() suite.Require().NoError(err) - suite.app.SlashingKeeper.SetValidatorSigningInfo(suite.ctx, consAddr, slashingtypes.NewValidatorSigningInfo(consAddr, 0, 0, time.UnixMicro(0), false, 0)) + consAddr := sdk.ConsAddress(oldPK.Address()) _, tmAny := suite.GenerateConsKey() pk, ok := tmAny.GetCachedValue().(cryptotypes.PubKey) @@ -38,27 +35,17 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, pk) suite.Require().NoError(err) - found = suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, valAddr) - suite.Require().False(found) - - pkPowerUpdate := make(map[crypto.PublicKey]int64) + valUpdates := make([]abci.ValidatorUpdate, 0) + pkPowerUpdate := make(map[string]int64) lastVote := make(map[string]bool) - - validators := suite.app.StakingKeeper.GetValidators(suite.ctx, 100) - for _, val := range validators { - pubKey, err := val.ConsPubKey() - suite.Require().NoError(err) - tmProtoPk, err := cryptocodec.ToTmProtoPublicKey(pubKey) - suite.Require().NoError(err) - tmPk, err := cryptoenc.PubKeyFromProto(tmProtoPk) - suite.Require().NoError(err) - lastVote[string(tmPk.Address())] = true + for _, info := range suite.currentVoteInfo { + lastVote[string(info.Validator.Address)] = true } // validator update(process start) - updates := suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, pkPowerUpdate, lastVote) + updates := suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, valUpdates, pkPowerUpdate, lastVote) suite.Require().Len(updates, 2) - updates = suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, pkPowerUpdate, lastVote) + updates = suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, valUpdates, pkPowerUpdate, lastVote) suite.Require().Len(updates, 0) _, found = suite.app.StakingKeeper.GetConsensusPubKey(suite.ctx, valAddr) @@ -99,6 +86,438 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { suite.Require().False(found) } +func (suite *KeeperTestSuite) TestEditPubKeyJail() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + oldPk, err := validator.ConsPubKey() + suite.Require().NoError(err) + oldConsAddr := sdk.ConsAddress(oldPk.Address()) + + // new consensus pubkey + newPriv, _ := suite.GenerateConsKey() + newPk := newPriv.PubKey() + newConsAddr := sdk.ConsAddress(newPk.Address()) + + suite.Commit() + + // undelegate all and edit validator + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares()) + suite.Require().NoError(err) + err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) + suite.Require().NoError(err) + + // check + found = suite.app.StakingKeeper.HasConsensusPubKey(suite.ctx, valAddr) + suite.Require().True(found) + process, err := suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) + suite.Require().NoError(err) + suite.Require().Nil(process) + // next block + valUpdates := suite.CommitEndBlock() + + // validator jailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().True(validator.IsJailed()) + + // check + found = suite.app.StakingKeeper.HasConsensusPubKey(suite.ctx, valAddr) + suite.Require().False(found) + + oldSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + newSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + + process, err = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) + suite.Require().NoError(err) + suite.Require().NotNil(process) + + // next block + suite.CommitBeginBlock(valUpdates) + valUpdates = suite.CommitEndBlock() + + suite.True(suite.CurrentVoteFound(oldPk)) + suite.False(suite.NextVoteFound(newPk)) + + // check + oldSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + + // next block + suite.CommitBeginBlock(valUpdates) + _ = suite.CommitEndBlock() + + suite.False(suite.CurrentVoteFound(oldPk)) + suite.False(suite.NextVoteFound(newPk)) + + // check + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().False(found) + newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset+1, newSigningInfo.IndexOffset) +} + +func (suite *KeeperTestSuite) TestEditPubKeyJailAndUnjail() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + oldPK, err := validator.ConsPubKey() + suite.Require().NoError(err) + + delAmt := validator.GetTokens() + delShares := validator.GetDelegatorShares() + + // new consensus pubkey + newPriv, _ := suite.GenerateConsKey() + newPk := newPriv.PubKey() + + suite.Commit() + + // undelegate all and edit validator + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, delShares) + suite.Require().NoError(err) + err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) + suite.Require().NoError(err) + + // end block + valUpdates := suite.CommitEndBlock() + + // validator jailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().True(validator.IsJailed()) + + // next block + suite.CommitBeginBlock(valUpdates) + + suite.True(suite.CurrentVoteFound(oldPK)) + suite.False(suite.NextVoteFound(newPk)) + + // unjail + _, err = suite.app.StakingKeeper.Delegate(suite.ctx, sdk.AccAddress(valAddr), delAmt, stakingtypes.Unbonded, validator, true) + suite.Require().NoError(err) + err = suite.app.SlashingKeeper.Unjail(suite.ctx, valAddr) + suite.Require().NoError(err) + + // end block + valUpdates = suite.CommitEndBlock() + + suite.True(suite.CurrentVoteFound(oldPK)) + suite.False(suite.CurrentVoteFound(newPk)) + suite.False(suite.NextVoteFound(newPk)) + + // validator unjailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().False(validator.IsJailed()) + + // old signing info exist + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(oldPK.Address())) + suite.Require().True(found) + + // next block + suite.CommitBeginBlock(valUpdates) + _ = suite.CommitEndBlock() + + suite.False(suite.CurrentVoteFound(newPk)) + suite.True(suite.NextVoteFound(newPk)) + + // old signing info deleted + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(oldPK.Address())) + suite.Require().False(found) + // new signing info exist + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(newPk.Address())) + suite.Require().True(found) +} + +func (suite *KeeperTestSuite) TestEditPubKeyJailNextBlock() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + oldPK, err := validator.ConsPubKey() + suite.Require().NoError(err) + oldConsAddr := sdk.ConsAddress(oldPK.Address()) + + // new consensus pubkey + newPriv, _ := suite.GenerateConsKey() + newPk := newPriv.PubKey() + newConsAddr := sdk.ConsAddress(newPk.Address()) + + suite.Commit() + + // edit validator + err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) + suite.Require().NoError(err) + valUpdates := suite.CommitEndBlock() + + // check + found = suite.app.StakingKeeper.HasConsensusPubKey(suite.ctx, valAddr) + suite.Require().False(found) + + oldSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + newSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + + process, err := suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) + suite.Require().NoError(err) + suite.Require().NotNil(process) + + // next block begin + suite.CommitBeginBlock(valUpdates) + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares()) + suite.Require().NoError(err) + valUpdates = suite.CommitEndBlock() + + suite.True(suite.CurrentVoteFound(oldPK)) + suite.True(suite.NextVoteFound(newPk)) + + // validator jailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().True(validator.IsJailed()) + + oldSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + + process, err = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessEnd) + suite.Require().NoError(err) + suite.Require().NotNil(process) + + // next block begin + suite.CommitBeginBlock(valUpdates) + suite.CommitEndBlock() + + suite.False(suite.CurrentVoteFound(oldPK)) + suite.True(suite.CurrentVoteFound(newPk)) + suite.False(suite.NextVoteFound(newPk)) + + // check + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().False(found) + newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset+1, newSigningInfo.IndexOffset) + + found = suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, valAddr) + suite.Require().False(found) +} + +func (suite *KeeperTestSuite) TestEditPubKeyUnjailAndJailNextBlock() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + oldPk, err := validator.ConsPubKey() + suite.Require().NoError(err) + + delAmt := validator.GetTokens() + delShares := validator.GetDelegatorShares() + + // new consensus pubkey + newPriv, _ := suite.GenerateConsKey() + newPk := newPriv.PubKey() + + suite.Commit() + + // jailed by undelegate all + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, delShares) + suite.Require().NoError(err) + + // validator jailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().True(validator.IsJailed()) + + suite.Commit() + suite.Commit() + valUpdates := suite.CommitEndBlock() + + suite.False(suite.CurrentVoteFound(oldPk)) + suite.False(suite.NextVoteFound(oldPk)) + + suite.CommitBeginBlock(valUpdates) + // edit validator + err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) + suite.Require().NoError(err) + // unjail validator + _, err = suite.app.StakingKeeper.Delegate(suite.ctx, sdk.AccAddress(valAddr), delAmt, stakingtypes.Unbonded, validator, true) + suite.Require().NoError(err) + err = suite.app.SlashingKeeper.Unjail(suite.ctx, valAddr) + suite.Require().NoError(err) + // end block + valUpdates = suite.CommitEndBlock() + + // validator unjailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().False(validator.IsJailed()) + + consAddr, err := validator.GetConsAddr() + suite.Require().NoError(err) + suite.Require().Equal(consAddr, sdk.ConsAddress(newPk.Address())) + + suite.CommitBeginBlock(valUpdates) + // validator jailed + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, delShares) + suite.Require().NoError(err) + _ = suite.CommitEndBlock() + + suite.True(suite.NextVoteFound(newPk)) + + // validator jailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().True(validator.IsJailed()) +} + +func (suite *KeeperTestSuite) TestEditPubKeyJailedPrevBlock() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + oldPK, err := validator.ConsPubKey() + suite.Require().NoError(err) + oldConsAddr := sdk.ConsAddress(oldPK.Address()) + + // new consensus pubkey + newPriv, _ := suite.GenerateConsKey() + newPk := newPriv.PubKey() + newConsAddr := sdk.ConsAddress(newPk.Address()) + + suite.Commit() + + // jailed by undelegate all + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares()) + suite.Require().NoError(err) + + valUpdates := suite.CommitEndBlock() + + // check validator jailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().True(validator.IsJailed()) + + suite.CommitBeginBlock(valUpdates) + + // edit validator + err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) + suite.Require().NoError(err) + + // check + found = suite.app.StakingKeeper.HasConsensusPubKey(suite.ctx, valAddr) + suite.Require().True(found) + + // validator cons address equals to old cons address + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + addr, err := validator.GetConsAddr() + suite.Require().NoError(err) + suite.Require().Equal(oldConsAddr, addr) + + // next block + valUpdates = suite.CommitEndBlock() + + // check consensus pubkey + found = suite.app.StakingKeeper.HasConsensusPubKey(suite.ctx, valAddr) + suite.Require().False(found) + + // validator cons address equals to new cons address + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + addr, err = validator.GetConsAddr() + suite.Require().NoError(err) + suite.Require().Equal(newConsAddr, addr) + + // signing info equal + oldSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + newSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + + // next block + suite.CommitBeginBlock(valUpdates) + _ = suite.CommitEndBlock() + + // signing info equal + oldSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) +} + +func (suite *KeeperTestSuite) TestEditPubKeyJailedPrevBlockAndUnjail() { + valAddr := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + + delAmt := validator.GetTokens() + delShares := validator.GetDelegatorShares() + + // new consensus pubkey + newPriv, _ := suite.GenerateConsKey() + newPk := newPriv.PubKey() + + suite.Commit() + + // jailed by undelegate all + _, err := suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, delShares) + suite.Require().NoError(err) + valUpdates := suite.CommitEndBlock() + + suite.CommitBeginBlock(valUpdates) + valUpdates = suite.CommitEndBlock() + suite.CommitBeginBlock(valUpdates) + valUpdates = suite.CommitEndBlock() + + // check validator jailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().True(validator.IsJailed()) + + suite.CommitBeginBlock(valUpdates) + // edit validator + err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) + suite.Require().NoError(err) + // unjail validator + _, err = suite.app.StakingKeeper.Delegate(suite.ctx, sdk.AccAddress(valAddr), delAmt, stakingtypes.Unbonded, validator, true) + suite.Require().NoError(err) + err = suite.app.SlashingKeeper.Unjail(suite.ctx, valAddr) + suite.Require().NoError(err) + valUpdates = suite.CommitEndBlock() + + // validator unjailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().False(validator.IsJailed()) + + suite.False(suite.CurrentVoteFound(newPk)) + suite.False(suite.NextVoteFound(newPk)) + + suite.CommitBeginBlock(valUpdates) + _ = suite.CommitEndBlock() + + suite.False(suite.CurrentVoteFound(newPk)) + suite.True(suite.NextVoteFound(newPk)) +} + func TestValidatorUpdateEvidence(t *testing.T) { helpers.SkipTest(t, "Skipping local test:", t.Name()) diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index ae057f7e3..5969afbf7 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -2,6 +2,7 @@ package keeper_test import ( "testing" + "time" sdkmath "cosmossdk.io/math" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -11,8 +12,11 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/stretchr/testify/suite" + abci "github.com/tendermint/tendermint/abci/types" + cryptoenc "github.com/tendermint/tendermint/crypto/encoding" tmrand "github.com/tendermint/tendermint/libs/rand" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -29,7 +33,9 @@ type KeeperTestSuite struct { app *app.App signer *helpers.Signer - valAccounts []authtypes.GenesisAccount + valAccounts []authtypes.GenesisAccount + currentVoteInfo []abci.VoteInfo + nextVoteInfo []abci.VoteInfo } func TestKeeperTestSuite(t *testing.T) { @@ -54,6 +60,28 @@ func (suite *KeeperTestSuite) SetupSubTest() { suite.ctx = suite.ctx.WithConsensusParams(helpers.ABCIConsensusParams) suite.valAccounts = valAccounts + for _, validator := range valSet.Validators { + signingInfo := slashingtypes.NewValidatorSigningInfo( + validator.Address.Bytes(), + suite.ctx.BlockHeight(), + 100, + time.Unix(0, 0), + false, + 0, + ) + suite.app.SlashingKeeper.SetValidatorSigningInfo(suite.ctx, validator.Address.Bytes(), signingInfo) + } + + vals := suite.app.StakingKeeper.GetAllValidators(suite.ctx) + infos := make([]abci.VoteInfo, 0, len(vals)) + for _, val := range vals { + addr, err := val.GetConsAddr() + suite.Require().NoError(err) + infos = append(infos, abci.VoteInfo{Validator: abci.Validator{Address: addr, Power: 100}}) + } + suite.currentVoteInfo = infos + suite.nextVoteInfo = infos + suite.signer = helpers.NewSigner(helpers.NewEthPrivKey()) helpers.AddTestAddr(suite.app, suite.ctx, suite.signer.AccAddress(), sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(100).MulRaw(1e18)))) } @@ -70,6 +98,92 @@ func (suite *KeeperTestSuite) GenerateConsKey() (cryptotypes.PrivKey, *codectype return priKey, pkAny } +func (suite *KeeperTestSuite) SetSigningInfo(pk cryptotypes.PubKey, jailed ...bool) { + consAddr := sdk.ConsAddress(pk.Address()) + jailedUntil := time.Unix(0, 0) + if len(jailed) > 0 && jailed[0] { + jailedUntil = suite.ctx.BlockHeader().Time.Add(time.Second) + } + signingInfo := slashingtypes.NewValidatorSigningInfo(consAddr, 0, 0, jailedUntil, false, 0) + suite.app.SlashingKeeper.SetValidatorSigningInfo(suite.ctx, consAddr, signingInfo) + + err := suite.app.SlashingKeeper.AddPubkey(suite.ctx, pk) + suite.Require().NoError(err) +} + +func (suite *KeeperTestSuite) CommitEndBlock() []abci.ValidatorUpdate { + header := suite.ctx.BlockHeader() + res := suite.app.EndBlock(abci.RequestEndBlock{Height: header.Height}) + suite.app.Commit() + return res.ValidatorUpdates +} + +func (suite *KeeperTestSuite) CommitBeginBlock(valUpdate []abci.ValidatorUpdate) { + header := suite.ctx.BlockHeader() + + // begin block + header.Time = time.Now().UTC() + header.Height += 1 + + suite.app.BeginBlock(abci.RequestBeginBlock{ + Header: header, + LastCommitInfo: abci.LastCommitInfo{ + Votes: suite.currentVoteInfo, + }, + }) + suite.ctx = suite.app.NewContext(false, header) + + pkUpdate := make(map[string]int64, len(valUpdate)) + for _, pk := range valUpdate { + tmPk, err := cryptoenc.PubKeyFromProto(pk.PubKey) + suite.Require().NoError(err) + pkUpdate[sdk.ConsAddress(tmPk.Address()).String()] = pk.Power + } + + newVoteInfo := make([]abci.VoteInfo, 0, len(suite.currentVoteInfo)) + for _, info := range suite.nextVoteInfo { + consAddr := sdk.ConsAddress(info.Validator.Address) + power, ok := pkUpdate[consAddr.String()] + if ok && power == 0 { + delete(pkUpdate, consAddr.String()) + continue + } + newVoteInfo = append(newVoteInfo, info) + } + for addr, power := range pkUpdate { + consAddr, err := sdk.ConsAddressFromBech32(addr) + suite.Require().NoError(err) + newVoteInfo = append(newVoteInfo, abci.VoteInfo{Validator: abci.Validator{Address: consAddr, Power: power}}) + } + + suite.currentVoteInfo, suite.nextVoteInfo = suite.nextVoteInfo, newVoteInfo +} + +func (suite *KeeperTestSuite) CurrentVoteFound(pk cryptotypes.PubKey) bool { + consAddr := sdk.ConsAddress(pk.Address()) + for _, info := range suite.currentVoteInfo { + if consAddr.Equals(sdk.ConsAddress(info.Validator.Address)) { + return true + } + } + return false +} + +func (suite *KeeperTestSuite) NextVoteFound(pk cryptotypes.PubKey) bool { + consAddr := sdk.ConsAddress(pk.Address()) + for _, info := range suite.nextVoteInfo { + if consAddr.Equals(sdk.ConsAddress(info.Validator.Address)) { + return true + } + } + return false +} + +func (suite *KeeperTestSuite) Commit() { + valUpdates := suite.CommitEndBlock() + suite.CommitBeginBlock(valUpdates) +} + func (suite *KeeperTestSuite) TestHasValidatorGrant() { val := sdk.ValAddress(suite.valAccounts[0].GetAddress()) addr := sdk.AccAddress(helpers.GenerateAddress().Bytes()) diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 08ef1bdab..519c75ae6 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -10,6 +10,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/functionx/fx-core/v5/x/staking/types" @@ -72,6 +73,14 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon if !found { return nil, errorsmod.Wrapf(sdkerrors.ErrUnknownAddress, "validator %s not found", msg.ValidatorAddress) } + + // jailed by double sign, can't update consensus pubkey + if validator.IsJailed() { + if err := k.validateDoubleSign(ctx, validator); err != nil { + return nil, err + } + } + // authorized from address if !k.HasValidatorGrant(ctx, fromAddr, valAddr) { return nil, errorsmod.Wrapf(sdkerrors.ErrUnauthorized, "from address not authorized") @@ -157,3 +166,18 @@ func (k Keeper) validateAnyPubKey(ctx sdk.Context, pubkey *codectypes.Any) (cryp } return pk, nil } + +func (k Keeper) validateDoubleSign(ctx sdk.Context, validator stakingtypes.Validator) error { + consAddr, err := validator.GetConsAddr() + if err != nil { + return err + } + info, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, consAddr) + if !found { + return sdkerrors.ErrUnknownAddress.Wrapf("consensus %s not found", consAddr.String()) + } + if info.JailedUntil.Equal(evidencetypes.DoubleSignJailEndTime) { + return sdkerrors.ErrInvalidRequest.Wrapf("validator %s is jailed for double sign", validator.OperatorAddress) + } + return nil +} From 6d2ec132e1b26f6079ad4f9532a83d9c80745c6d Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Wed, 26 Jul 2023 18:31:48 +0800 Subject: [PATCH 17/30] perf: staking EditConsensusPubKey * check process validator power * test power --- x/staking/keeper/msg_server.go | 75 ++++++++----- x/staking/keeper/msg_server_test.go | 158 +++++++++++++++++++++++----- 2 files changed, 181 insertions(+), 52 deletions(-) diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 519c75ae6..0d4690176 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -95,32 +95,10 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon if err != nil { return nil, err } - newConsAddr := sdk.ConsAddress(newPubKey.Address()) - newPkFound := false - totalUpdatePower := math.NewInt(validator.ConsensusPower(k.PowerReduction(ctx))) - k.IteratorConsensusPubKey(ctx, func(addr sdk.ValAddress, pkBytes []byte) bool { - var pk cryptotypes.PubKey - if err := k.cdc.UnmarshalInterfaceJSON(pkBytes, &pk); err != nil { - k.Logger(ctx).Error("failed to unmarshal pubKey", "validator", valAddr.String(), "err", err.Error()) - return false - } - if newConsAddr.Equals(sdk.ConsAddress(pk.Address())) { - newPkFound = true - return true - } - power := k.GetLastValidatorPower(ctx, addr) - totalUpdatePower = totalUpdatePower.Add(math.NewInt(power)) - return false - }) - - if newPkFound { // new pk already exists - return nil, stakingtypes.ErrValidatorPubKeyExists.Wrapf("new consensus pubkey %s already exists", newConsAddr.String()) - } - totalPowerOneThird := k.GetLastTotalPower(ctx).QuoRaw(3) // less than 1/3 total power - if totalUpdatePower.GTE(totalPowerOneThird) { - return nil, sdkerrors.ErrInvalidRequest.Wrapf("total update power %s more than 1/3 total power %s", - totalUpdatePower.String(), totalPowerOneThird.String()) + // iterator edit validator with new pubkey + if err := k.iteratorEditValidator(ctx, validator, newPubKey); err != nil { + return nil, err } // set validator new consensus pubkey @@ -135,7 +113,7 @@ func (k Keeper) EditConsensusPubKey(goCtx context.Context, msg *types.MsgEditCon sdk.NewAttribute(types.AttributeKeyPubKey, newPubKey.String()), )) - return &types.MsgEditConsensusPubKeyResponse{}, err + return &types.MsgEditConsensusPubKeyResponse{}, nil } func (k Keeper) validateAnyPubKey(ctx sdk.Context, pubkey *codectypes.Any) (cryptotypes.PubKey, error) { @@ -181,3 +159,48 @@ func (k Keeper) validateDoubleSign(ctx sdk.Context, validator stakingtypes.Valid } return nil } + +func (k Keeper) iteratorEditValidator(ctx sdk.Context, validator stakingtypes.Validator, newPk cryptotypes.PubKey) error { + newConsAddr := sdk.ConsAddress(newPk.Address()) + + newPkFound := false + totalUpdatePower := math.NewInt(validator.ConsensusPower(k.PowerReduction(ctx))) + k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, pkBytes []byte) bool { + var pk cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(pkBytes, &pk); err != nil { + k.Logger(ctx).Error("failed to unmarshal pubKey", "validator", valAddr.String(), "err", err.Error()) + return false + } + if newConsAddr.Equals(sdk.ConsAddress(pk.Address())) { + newPkFound = true + return true + } + power := k.GetLastValidatorPower(ctx, valAddr) + totalUpdatePower = totalUpdatePower.Add(math.NewInt(power)) + return false + }) + if newPkFound { // new pk already exists + return stakingtypes.ErrValidatorPubKeyExists.Wrapf("new consensus pubkey %s already exists", newConsAddr.String()) + } + + // iterate validator consensus process start + k.IteratorConsensusProcess(ctx, types.ProcessStart, func(valAddr sdk.ValAddress, _ []byte) { + // NOTE: not need check pk, already update validator consensus pubkey + power := k.GetLastValidatorPower(ctx, valAddr) + totalUpdatePower = totalUpdatePower.Add(math.NewInt(power)) + }) + + // iterate validator consensus process end + k.IteratorConsensusProcess(ctx, types.ProcessEnd, func(valAddr sdk.ValAddress, _ []byte) { + // NOTE: not need check pk, already update validator consensus pubkey + power := k.GetLastValidatorPower(ctx, valAddr) + totalUpdatePower = totalUpdatePower.Add(math.NewInt(power)) + }) + + totalPowerOneThird := k.GetLastTotalPower(ctx).QuoRaw(3) // less than 1/3 total power + if totalUpdatePower.GTE(totalPowerOneThird) { + return sdkerrors.ErrInvalidRequest.Wrapf("total update power %s more than 1/3 total power %s", + totalUpdatePower.String(), totalPowerOneThird.String()) + } + return nil +} diff --git a/x/staking/keeper/msg_server_test.go b/x/staking/keeper/msg_server_test.go index 5aaf3f65c..834e3f8cc 100644 --- a/x/staking/keeper/msg_server_test.go +++ b/x/staking/keeper/msg_server_test.go @@ -4,12 +4,17 @@ import ( "encoding/hex" "fmt" + "cosmossdk.io/math" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" "github.com/functionx/fx-core/v5/x/staking/types" ) @@ -243,73 +248,105 @@ func (suite *KeeperTestSuite) TestEditConsensusPubKey() { _, tmAny := suite.GenerateConsKey() testCase := []struct { name string - malleate func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey + malleate func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) expectPass bool - errMsg string }{ { name: "success", - malleate: func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { return &types.MsgEditConsensusPubKey{ ValidatorAddress: val.String(), From: from.String(), Pubkey: tmAny, - } + }, "" }, expectPass: true, }, { name: "success - granted", - malleate: func(val sdk.ValAddress, _ sdk.AccAddress) *types.MsgEditConsensusPubKey { + malleate: func(val sdk.ValAddress, _ sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { newFrom := helpers.NewEthPrivKey() suite.app.StakingKeeper.UpdateValidatorOperator(suite.ctx, val, newFrom.PubKey().Address().Bytes()) return &types.MsgEditConsensusPubKey{ ValidatorAddress: val.String(), From: sdk.AccAddress(newFrom.PubKey().Address()).String(), Pubkey: tmAny, - } + }, "" }, expectPass: true, }, { name: "fail - invalid validator", - malleate: func(_ sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + malleate: func(_ sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { return &types.MsgEditConsensusPubKey{ ValidatorAddress: "", From: from.String(), Pubkey: tmAny, - } + }, "empty address string is not allowed: invalid address" + }, + expectPass: false, + }, + { + name: "fail - slashing double sign", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, val) + suite.Require().True(found) + consAddr, err := validator.GetConsAddr() + suite.Require().NoError(err) + info, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, consAddr) + suite.Require().True(found) + info.JailedUntil = evidencetypes.DoubleSignJailEndTime + suite.app.SlashingKeeper.SetValidatorSigningInfo(suite.ctx, consAddr, info) + + validator.Jailed = true + suite.app.StakingKeeper.SetValidator(suite.ctx, validator) + + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: tmAny, + }, fmt.Sprintf("validator %s is jailed for double sign: invalid request", val.String()) }, expectPass: false, - errMsg: "empty address string is not allowed: invalid address", }, { name: "fail - validator not found", - malleate: func(_ sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + malleate: func(_ sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { return &types.MsgEditConsensusPubKey{ ValidatorAddress: sdk.ValAddress(unKnownAddr).String(), From: from.String(), Pubkey: tmAny, - } + }, fmt.Sprintf("validator %s not found: unknown address", sdk.ValAddress(unKnownAddr).String()) }, expectPass: false, - errMsg: fmt.Sprintf("validator %s not found: unknown address", sdk.ValAddress(unKnownAddr).String()), }, { name: "fail - from not authorized", - malleate: func(val sdk.ValAddress, _ sdk.AccAddress) *types.MsgEditConsensusPubKey { + malleate: func(val sdk.ValAddress, _ sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { return &types.MsgEditConsensusPubKey{ ValidatorAddress: val.String(), From: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), Pubkey: tmAny, - } + }, "from address not authorized: unauthorized" + }, + expectPass: false, + }, + { + name: "fail - validator updating", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { + err := suite.app.StakingKeeper.SetConsensusProcess(suite.ctx, val, tmAny.GetCachedValue().(cryptotypes.PubKey), types.ProcessStart) + suite.Require().NoError(err) + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: tmAny, + }, fmt.Sprintf("validator %s is updating consensus pubkey: invalid request", val.String()) }, expectPass: false, - errMsg: "from address not authorized: unauthorized", }, { name: "fail - invalid pubkey", - malleate: func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { pkAny, err := codectypes.NewAnyWithValue(&banktypes.MsgSend{}) if err != nil { panic(err) @@ -318,14 +355,13 @@ func (suite *KeeperTestSuite) TestEditConsensusPubKey() { ValidatorAddress: val.String(), From: from.String(), Pubkey: pkAny, - } + }, "Expecting cryptotypes.PubKey, got *types.MsgSend: invalid type" }, expectPass: false, - errMsg: "Expecting cryptotypes.PubKey, got *types.MsgSend: invalid type", }, { name: "fail - pubkey exist", - malleate: func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { addr := suite.valAccounts[1].GetAddress() validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(addr)) suite.Require().True(found) @@ -334,14 +370,13 @@ func (suite *KeeperTestSuite) TestEditConsensusPubKey() { ValidatorAddress: val.String(), From: from.String(), Pubkey: validator.ConsensusPubkey, - } + }, "validator already exist for this pubkey; must use new validator pubkey" }, expectPass: false, - errMsg: "validator already exist for this pubkey; must use new validator pubkey", }, { name: "fail - invalid pubkey type", - malleate: func(val sdk.ValAddress, from sdk.AccAddress) *types.MsgEditConsensusPubKey { + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { pkAny, err := codectypes.NewAnyWithValue(helpers.NewEthPrivKey().PubKey()) if err != nil { panic(err) @@ -350,22 +385,93 @@ func (suite *KeeperTestSuite) TestEditConsensusPubKey() { ValidatorAddress: val.String(), From: from.String(), Pubkey: pkAny, - } + }, "got: eth_secp256k1, expected: [ed25519]: validator pubkey type is not supported" + }, + expectPass: false, + }, + { + name: "fail - new pubkey updated by other validator", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { + _, pkAny := suite.GenerateConsKey() + pk := pkAny.GetCachedValue().(cryptotypes.PubKey) + + otherVal := sdk.ValAddress(suite.valAccounts[1].GetAddress()) + err := suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, otherVal, pk) + suite.Require().NoError(err) + + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: pkAny, + }, fmt.Sprintf("new consensus pubkey %s already exists: validator already exist for this pubkey; must use new validator pubkey", sdk.ConsAddress(pk.Address())) + }, + expectPass: false, + }, + { + name: "fail - validator power more than 1/3", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { + amount := math.NewInt(10000).Mul(math.NewInt(1e18)) + helpers.AddTestAddr(suite.app, suite.ctx, from, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, amount))) + + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, val) + suite.Require().True(found) + _, err := suite.app.StakingKeeper.Delegate(suite.ctx, from, amount, stakingtypes.Unbonded, validator, true) + suite.Require().NoError(err) + + suite.Commit() + + valPower := suite.app.StakingKeeper.GetLastValidatorPower(suite.ctx, val) + totalPower := suite.app.StakingKeeper.GetLastTotalPower(suite.ctx) + + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: tmAny, + }, fmt.Sprintf("total update power %d more than 1/3 total power %s: invalid request", + valPower, totalPower.Quo(sdk.NewInt(3)).String()) + }, + expectPass: false, + }, + { + name: "fail - update power more than 1/3", + malleate: func(val sdk.ValAddress, from sdk.AccAddress) (*types.MsgEditConsensusPubKey, string) { + amount := math.NewInt(10000).Mul(math.NewInt(1e18)) + helpers.AddTestAddr(suite.app, suite.ctx, from, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, amount))) + + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(suite.valAccounts[1].GetAddress())) + suite.Require().True(found) + _, err := suite.app.StakingKeeper.Delegate(suite.ctx, from, amount, stakingtypes.Unbonded, validator, true) + suite.Require().NoError(err) + + suite.Commit() + + err = suite.app.StakingKeeper.SetConsensusProcess(suite.ctx, validator.GetOperator(), ed25519.GenPrivKey().PubKey(), types.ProcessStart) + suite.Require().NoError(err) + val1Power := suite.app.StakingKeeper.GetLastValidatorPower(suite.ctx, validator.GetOperator()) + + valPower := suite.app.StakingKeeper.GetLastValidatorPower(suite.ctx, val) + totalPower := suite.app.StakingKeeper.GetLastTotalPower(suite.ctx) + + return &types.MsgEditConsensusPubKey{ + ValidatorAddress: val.String(), + From: from.String(), + Pubkey: tmAny, + }, fmt.Sprintf("total update power %d more than 1/3 total power %s: invalid request", + valPower+val1Power, totalPower.Quo(sdk.NewInt(3)).String()) }, expectPass: false, - errMsg: "got: eth_secp256k1, expected: [ed25519]: validator pubkey type is not supported", }, } for _, tc := range testCase { suite.Run(tc.name, func() { from := suite.valAccounts[0].GetAddress() - msg := tc.malleate(sdk.ValAddress(from), from) + msg, errMsg := tc.malleate(sdk.ValAddress(from), from) _, err := suite.app.StakingKeeper.EditConsensusPubKey(sdk.WrapSDKContext(suite.ctx), msg) if tc.expectPass { suite.Require().NoError(err) } else { suite.Require().Error(err) - suite.Require().Equal(tc.errMsg, err.Error()) + suite.Require().Equal(errMsg, err.Error()) } }) } From 40211287547c8aa816f03bd735dbf1affe7cc610 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Thu, 27 Jul 2023 16:40:36 +0800 Subject: [PATCH 18/30] chore: upgrades repair height * new slash validator and height * perf TestSlashPeriodTestnetFXV4 --- app/upgrade_test.go | 34 +++++++++++++++++++++++++++------- app/upgrades/v5/constants.go | 6 ++++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/app/upgrade_test.go b/app/upgrade_test.go index 994d1392a..d9331324a 100644 --- a/app/upgrade_test.go +++ b/app/upgrade_test.go @@ -155,6 +155,7 @@ func TestSlashPeriodTestnetFXV4(t *testing.T) { require.NoError(t, err) slashedFXV4 := make(map[string][]int64, len(v5.ValidatorSlashHeightTestnetFXV4)) + slashedValFXV4 := make([]string, 0, len(v5.ValidatorSlashHeightTestnetFXV4)) for _, block := range blockSearch.Blocks { results, err := rpc.BlockResults(block.Block.Height) require.NoError(t, err) @@ -172,18 +173,37 @@ func TestSlashPeriodTestnetFXV4(t *testing.T) { slashedFXV4[valAddr.String()] = append(slashedFXV4[valAddr.String()], block.Block.Height) } else { slashedFXV4[valAddr.String()] = []int64{block.Block.Height} + slashedValFXV4 = append(slashedValFXV4, valAddr.String()) } } } } - assert.Equal(t, len(v5.ValidatorSlashHeightTestnetFXV4), len(slashedFXV4)) + eq := len(v5.ValidatorSlashHeightTestnetFXV4) == len(slashedFXV4) + assert.True(t, eq) + + if eq { + for val, h1 := range slashedFXV4 { + h2, ok := v5.ValidatorSlashHeightTestnetFXV4[val] + assert.True(t, ok, "val: %s", val) + sort.SliceStable(h1, func(i, j int) bool { + return h1[i] < h1[j] + }) + eq = assert.ObjectsAreEqual(h1, h2) + assert.True(t, eq, "val: %s", val) + } + } - for val, h1 := range slashedFXV4 { - h2, ok := v5.ValidatorSlashHeightTestnetFXV4[val] - assert.True(t, ok, "val: %s", val) - sort.SliceStable(h1, func(i, j int) bool { - return h1[i] < h1[j] + // print + if !eq { + sort.SliceStable(slashedValFXV4, func(i, j int) bool { + return slashedValFXV4[i] < slashedValFXV4[j] }) - assert.Equal(t, h1, h2, "val: %s", val) + for _, addr := range slashedValFXV4 { + heights := slashedFXV4[addr] + sort.SliceStable(heights, func(i, j int) bool { + return heights[i] < heights[j] + }) + t.Log("val:", addr, "heights:", heights) + } } } diff --git a/app/upgrades/v5/constants.go b/app/upgrades/v5/constants.go index 7bd137252..24ddd3a47 100644 --- a/app/upgrades/v5/constants.go +++ b/app/upgrades/v5/constants.go @@ -16,9 +16,11 @@ type SlashPeriod struct { // ValidatorSlashHeightTestnetFXV4 is a map of testnet validator address to slash height // todo check before testnet v5 release var ValidatorSlashHeightTestnetFXV4 = map[string][]int64{ - "fxvaloper16d0jly49xgwm9tyf7lpf0splnfhrnttdejkz9h": {8787488, 8885841}, - "fxvaloper1xdqas5ak98us9eljqj5ppj5mhmku4slh2664l8": {8806427}, "fxvaloper14lpap6mwytqtnrx6q9cnje2sen5a5wcctuwnsh": {8224664, 8457967, 8552303}, + "fxvaloper1695tvr34jdrmajtc0t6kzumaxxwhulfl7h6mq2": {9469704}, + "fxvaloper16d0jly49xgwm9tyf7lpf0splnfhrnttdejkz9h": {8787488, 8885841, 9416069}, + "fxvaloper1c863577qlc4sq64v5dsfunf5drykz7fnqkgdha": {9128756}, + "fxvaloper1xdqas5ak98us9eljqj5ppj5mhmku4slh2664l8": {8806427}, } var Upgrade = upgrades.Upgrade{ From 33cc6280bce649f034b8d98821f6a8b9837d340c Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Fri, 28 Jul 2023 18:22:21 +0800 Subject: [PATCH 19/30] refactor: end block update pubkey --- x/staking/keeper/abci.go | 324 ++++++++++++++-------------------- x/staking/keeper/abci_test.go | 8 +- x/staking/keeper/keeper.go | 3 - x/staking/module.go | 5 - 4 files changed, 139 insertions(+), 201 deletions(-) diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index ca82be183..37f3d14d1 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -9,229 +9,149 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/tendermint/tendermint/abci/types" - tmcrypto "github.com/tendermint/tendermint/crypto" - cryptoenc "github.com/tendermint/tendermint/crypto/encoding" - "github.com/tendermint/tendermint/proto/tendermint/crypto" - "github.com/functionx/fx-core/v5/x/staking/types" + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) -func (k *Keeper) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { - staking.BeginBlocker(ctx, k.Keeper) - k.lastCommit = req.LastCommitInfo.GetVotes() -} - func (k *Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { // staking EndBlocker valUpdates := staking.EndBlocker(ctx, k.Keeper) - if len(k.lastCommit) == 0 { - return valUpdates - } - - // clear lastCommit after EndBlocker - defer func() { k.lastCommit = make([]abci.VoteInfo, 0) }() - // convert valUpdate and lastCommit to map pkPowerUpdate := make(map[string]int64, len(valUpdates)) for _, valUpdate := range valUpdates { pkPowerUpdate[valUpdate.PubKey.String()] = valUpdate.Power } - lastVote := make(map[string]bool, len(k.lastCommit)) - for _, voteInfo := range k.lastCommit { - lastVote[string(voteInfo.Validator.Address)] = true - } // consensus process start and end - k.ConsensusProcess(ctx, pkPowerUpdate, lastVote) + k.ConsensusProcess(ctx) // update validator consensus pubkey - return k.ValidatorUpdate(ctx, valUpdates, pkPowerUpdate, lastVote) + return k.ValidatorUpdate(ctx, valUpdates, pkPowerUpdate) } -func (k Keeper) ConsensusProcess(ctx sdk.Context, pkPowerUpdate map[string]int64, lastVote map[string]bool) { - k.IteratorConsensusProcess(ctx, types.ProcessEnd, func(valAddr sdk.ValAddress, pkBytes []byte) { - err := k.consesnsusProcessEnd(ctx, lastVote, valAddr, pkBytes) - if err != nil { +func (k Keeper) ConsensusProcess(ctx sdk.Context) { + k.IteratorConsensusProcess(ctx, fxstakingtypes.ProcessEnd, func(valAddr sdk.ValAddress, pkBytes []byte) { + if err := k.consesnsusProcessEnd(ctx, valAddr, pkBytes); err != nil { panic(err) } }) - k.IteratorConsensusProcess(ctx, types.ProcessStart, func(valAddr sdk.ValAddress, pkBytes []byte) { - err := k.consensusProcessStart(ctx, pkPowerUpdate, lastVote, valAddr, pkBytes) - if err != nil { + k.IteratorConsensusProcess(ctx, fxstakingtypes.ProcessStart, func(valAddr sdk.ValAddress, pkBytes []byte) { + if err := k.consensusProcessStart(ctx, valAddr, pkBytes); err != nil { panic(err) } }) } -func (k Keeper) consesnsusProcessEnd(ctx sdk.Context, lastVote map[string]bool, valAddr sdk.ValAddress, pkBytes []byte) error { - k.DeleteConsensusProcess(ctx, valAddr, types.ProcessEnd) +func (k Keeper) consesnsusProcessEnd(ctx sdk.Context, valAddr sdk.ValAddress, pkBytes []byte) error { + k.DeleteConsensusProcess(ctx, valAddr, fxstakingtypes.ProcessEnd) - _, _, newConsAddr, err := k.getValidatorKey(ctx, valAddr) - if err != nil { - return err - } - _, oldTmPk, oldConsAddr, err := k.unmarshalPubKey(pkBytes) - if err != nil { - return err + var oldPubKey cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(pkBytes, &oldPubKey); err != nil { + return fmt.Errorf("invalid pubkey") } + oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) - // case1: validator jailed current block - // case2: validator jailed previous block - // impossible case: power == 0 && !validator.Jailed, power != 0 && validator.Jailed - // case3: validator unjailed current block - // case4: validator always online - - lastVoted := lastVote[string(oldTmPk.Address())] - if lastVoted { - if err := k.updateSigningInfo(ctx, oldConsAddr, newConsAddr); err != nil { - panic(err) - } + // old pk signing info + oldSigningInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) + if !found { + return fmt.Errorf("validator %s not found signing info", oldConsAddr.String()) } - // remove validator by old consensus address - k.RemoveValidatorConsAddr(ctx, oldConsAddr) - // remove old consensus pubkey + k.RemoveValidatorConsAddr(ctx, oldConsAddr) k.slashingKeeper.DeleteConsensusPubKey(ctx, oldConsAddr) - - // remove old validator signing info k.slashingKeeper.DeleteValidatorSigningInfo(ctx, oldConsAddr) - ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeEditedConsensusPubKey, - sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), - )) - - return nil -} - -func (k Keeper) consensusProcessStart( - ctx sdk.Context, - pkPowerUpdate map[string]int64, - lastVote map[string]bool, - valAddr sdk.ValAddress, - pkBytes []byte, -) error { - k.DeleteConsensusProcess(ctx, valAddr, types.ProcessStart) - - validator, newTmProtoPk, newConsAddr, err := k.getValidatorKey(ctx, valAddr) - if err != nil { - return err + // update validator new pk signing info + validator, found := k.GetValidator(ctx, valAddr) + if !found { + // NOTE: validator not found + // unbonded and undelegate all, will delete validator + // remove old consensus pubkey and return + k.Logger(ctx).Info("validator not found", "address", valAddr.String(), "process", "end") + return nil } - oldPubKey, oldTmPk, oldConsAddr, err := k.unmarshalPubKey(pkBytes) + newConsAddr, err := validator.GetConsAddr() if err != nil { return err } - - // set process end first - if err = k.SetConsensusProcess(ctx, valAddr, oldPubKey, types.ProcessEnd); err != nil { + if err = k.updateSigningInfo(ctx, newConsAddr, oldSigningInfo); err != nil { return err } - power, ok := pkPowerUpdate[newTmProtoPk.String()] // only new pk, validator consensus pk update previous block - if !ok { - power = validator.ConsensusPower(k.PowerReduction(ctx)) - } - - // case1: validator jailed current block(missed blocks/double sign/low power) - if ok && power == 0 && validator.Jailed { - return k.updateSigningInfo(ctx, oldConsAddr, newConsAddr) - } + // success event + ctx.EventManager().EmitEvent(sdk.NewEvent( + fxstakingtypes.EventTypeEditedConsensusPubKey, + sdk.NewAttribute(types.AttributeKeyValidator, valAddr.String()), + )) - lastVoted := lastVote[string(oldTmPk.Address())] // only old pk, validator new pk vote in next block + return nil +} - // case2: validator jailed previous block - if power == 0 && validator.Jailed { - // jailed last-1 or last block - if lastVoted { - return k.updateSigningInfo(ctx, oldConsAddr, newConsAddr) - } - return nil +func (k Keeper) consensusProcessStart(ctx sdk.Context, valAddr sdk.ValAddress, pkBytes []byte) error { + var oldPubKey cryptotypes.PubKey + if err := k.cdc.UnmarshalInterfaceJSON(pkBytes, &oldPubKey); err != nil { + return fmt.Errorf("invalid pubkey") } + oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) - // impossible case: power != 0 && validator jailed, power == 0 && validator unjailed - // power !=0 && validator unjailed - - // case3: validator jailed previous block, unjailed current block - if !lastVoted && !validator.Jailed { - return nil + // set process end and delete process start + if err := k.SetConsensusProcess(ctx, valAddr, oldPubKey, fxstakingtypes.ProcessEnd); err != nil { + return err } + k.DeleteConsensusProcess(ctx, valAddr, fxstakingtypes.ProcessStart) - // case4: validator always online or jailed(low power) last block, unjailed current block - // maybe miss block current height, update signing info - return k.updateSigningInfo(ctx, oldConsAddr, newConsAddr) -} - -func (k Keeper) getValidatorKey(ctx sdk.Context, valAddr sdk.ValAddress) (stakingtypes.Validator, crypto.PublicKey, sdk.ConsAddress, error) { - // todo validator not found ?? + // update validator new pk signing info validator, found := k.GetValidator(ctx, valAddr) if !found { - return stakingtypes.Validator{}, crypto.PublicKey{}, nil, - fmt.Errorf("validator %s not found", valAddr.String()) - } - pubKey, err := validator.ConsPubKey() - if err != nil { - return stakingtypes.Validator{}, crypto.PublicKey{}, nil, - fmt.Errorf("invalid validator %s pubkey", valAddr.String()) - } - tmProtoPk, err := cryptocodec.ToTmProtoPublicKey(pubKey) - if err != nil { - return stakingtypes.Validator{}, crypto.PublicKey{}, nil, - fmt.Errorf("invalid validator %s pubkey", valAddr.String()) + // NOTE: validator not found + // unbonded and undelegate all, will delete validator + // return nil and delete old consensus pubkey in end process + k.Logger(ctx).Info("validator not found", "address", valAddr.String(), "process", "start") + return nil } - consAddr := sdk.ConsAddress(pubKey.Address()) - return validator, tmProtoPk, consAddr, nil -} -func (k Keeper) unmarshalPubKey(pkBytes []byte) (cryptotypes.PubKey, tmcrypto.PubKey, sdk.ConsAddress, error) { - var pubKey cryptotypes.PubKey - if err := k.cdc.UnmarshalInterfaceJSON(pkBytes, &pubKey); err != nil { - return nil, nil, nil, fmt.Errorf("invalid pubkey") - } - tmProtoPk, err := cryptocodec.ToTmProtoPublicKey(pubKey) + newConsAddr, err := validator.GetConsAddr() if err != nil { - return nil, nil, nil, fmt.Errorf("invalid pubkey") - } - tmPk, err := cryptoenc.PubKeyFromProto(tmProtoPk) - if err != nil { - return nil, nil, nil, fmt.Errorf("invalid pubkey") + return err } - consAddr := sdk.ConsAddress(pubKey.Address()) - return pubKey, tmPk, consAddr, nil -} - -func (k Keeper) updateSigningInfo(ctx sdk.Context, oldConsAddr, newConsAddr sdk.ConsAddress) error { oldSigningInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) if !found { return fmt.Errorf("validator %s not found signing info", oldConsAddr.String()) } - newSigningInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, newConsAddr) + return k.updateSigningInfo(ctx, newConsAddr, oldSigningInfo) +} + +func (k Keeper) updateSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress, signingInfo slashingtypes.ValidatorSigningInfo) error { + newSigningInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, consAddr) if !found { - return fmt.Errorf("validator %s not found signing info", newConsAddr.String()) + return fmt.Errorf("validator %s not found signing info", consAddr.String()) } // double sign if newSigningInfo.JailedUntil == evidencetypes.DoubleSignJailEndTime { - newSigningInfo.IndexOffset = oldSigningInfo.IndexOffset - newSigningInfo.MissedBlocksCounter = oldSigningInfo.MissedBlocksCounter + newSigningInfo.IndexOffset = signingInfo.IndexOffset + newSigningInfo.MissedBlocksCounter = signingInfo.MissedBlocksCounter } else { - newSigningInfo = oldSigningInfo - newSigningInfo.Address = newConsAddr.String() + newSigningInfo = signingInfo + newSigningInfo.Address = consAddr.String() } - k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, newSigningInfo) + k.slashingKeeper.SetValidatorSigningInfo(ctx, consAddr, newSigningInfo) return nil } -func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpdate, pkPowerUpdate map[string]int64, lastVote map[string]bool) []abci.ValidatorUpdate { +func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpdate, pkPowerUpdate map[string]int64) []abci.ValidatorUpdate { pkUpdate := make([]abci.ValidatorUpdate, 0, 50) k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, pkBytes []byte) bool { validator, found := k.GetValidator(ctx, valAddr) if !found { - k.Logger(ctx).Error("validator not found", "address", valAddr.String()) + // NOTE: unbonded and undelegate all, will delete validator + k.Logger(ctx).Error("validator not found", "address", valAddr.String(), "process", "update") k.RemoveConsensusPubKey(ctx, valAddr) return false } @@ -265,23 +185,25 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda return false } // new validator updates - newValUpdates, err := k.updateABICValidator(cacheCtx, pkPowerUpdate, lastVote, validator, newPubKey, oldPubKey) + newValUpdates, err := k.updateABICValidator(cacheCtx, pkPowerUpdate, validator, newPubKey, oldPubKey) if err != nil { k.Logger(ctx).Error("update abci validator", "address", valAddr.String(), "error", err.Error()) return false } // set consensus process start - if err := k.SetConsensusProcess(ctx, valAddr, oldPubKey, types.ProcessStart); err != nil { + if err := k.SetConsensusProcess(ctx, valAddr, oldPubKey, fxstakingtypes.ProcessStart); err != nil { return false } k.Logger(ctx).Info("update consensus pubkey", "address", valAddr.String(), "oldConsAddr", oldConsAddr.String(), "newConsAddr", sdk.ConsAddress(newPubKey.Address()).String()) + + // event ctx.EventManager().EmitEvent(sdk.NewEvent( - types.EventTypeEditingConsensusPubKey, - sdk.NewAttribute(stakingtypes.AttributeKeyValidator, valAddr.String()), - sdk.NewAttribute(types.AttributeOldConsAddr, oldConsAddr.String()), - sdk.NewAttribute(types.AttributeNewConsAddr, sdk.ConsAddress(newPubKey.Address()).String()), + fxstakingtypes.EventTypeEditingConsensusPubKey, + sdk.NewAttribute(types.AttributeKeyValidator, valAddr.String()), + sdk.NewAttribute(fxstakingtypes.AttributeOldConsAddr, oldConsAddr.String()), + sdk.NewAttribute(fxstakingtypes.AttributeNewConsAddr, sdk.ConsAddress(newPubKey.Address()).String()), )) // commit cache context commit() @@ -300,7 +222,7 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda return newValUpdates } -func (k Keeper) updateValidator(ctx sdk.Context, validator stakingtypes.Validator, newPubKey cryptotypes.PubKey) error { +func (k Keeper) updateValidator(ctx sdk.Context, validator types.Validator, newPubKey cryptotypes.PubKey) error { pkAny, err := codectypes.NewAnyWithValue(newPubKey) if err != nil { return err @@ -322,64 +244,88 @@ func (k Keeper) updateSlashing(ctx sdk.Context, newPubKey cryptotypes.PubKey, ol // add signing info signingInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) if !found { - return errors.New("expected signing info not found") + // NOTE: validator create but not bonded enough token + return fmt.Errorf("validator %s not found signing info", oldConsAddr.String()) } signingInfo.Address = newConsAddr.String() k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, signingInfo) return nil } -func (k Keeper) updateABICValidator( - ctx sdk.Context, - pkPower map[string]int64, - lastVote map[string]bool, - validator stakingtypes.Validator, - newPubKey, oldPubKey cryptotypes.PubKey, -) ([]abci.ValidatorUpdate, error) { - oldTmProtoPk, err := cryptocodec.ToTmProtoPublicKey(oldPubKey) - if err != nil { - return nil, err - } - oldTmPk, err := cryptoenc.PubKeyFromProto(oldTmProtoPk) +//gocyclo:ignore +func (k Keeper) updateABICValidator(ctx sdk.Context, pkUpdate map[string]int64, val types.Validator, newPk, oldPk cryptotypes.PubKey) ([]abci.ValidatorUpdate, error) { + oldTmProtoPk, err := cryptocodec.ToTmProtoPublicKey(oldPk) if err != nil { return nil, err } - newTmProtoPk, err := cryptocodec.ToTmProtoPublicKey(newPubKey) + newTmProtoPk, err := cryptocodec.ToTmProtoPublicKey(newPk) if err != nil { return nil, err } - power, ok := pkPower[oldTmProtoPk.String()] + power, ok := pkUpdate[oldTmProtoPk.String()] // if power not found, validator not update current block, cal validator power if !ok { - power = validator.ConsensusPower(k.PowerReduction(ctx)) + power = val.ConsensusPower(k.PowerReduction(ctx)) } else { // remove old pk power - delete(pkPower, oldTmProtoPk.String()) + delete(pkUpdate, oldTmProtoPk.String()) } // set old pk power to 0 oldPkUpdate := abci.ValidatorUpdate{PubKey: oldTmProtoPk, Power: 0} // add new pk with power newPkUpdate := abci.ValidatorUpdate{PubKey: newTmProtoPk, Power: power} - // case1: validator jailed current block - if ok && power == 0 && validator.Jailed { - return []abci.ValidatorUpdate{oldPkUpdate}, nil - } + /* + a1: 1-block 2-block-edit 3-block ------ oldpk-0,newpk-power + a2: 1-block 2-block-(jailed|edit) 3-block 4-unblock ------ oldpk-0 - // case2: validator jailed previous block - if power == 0 && validator.Jailed { - return []abci.ValidatorUpdate{}, nil - } + b1: 1-unblock(jailed) 2-unblock-edit 3-unblock ------ nil + b2: 1-unblock(inactive) 2-unblock-edit 3-unblock ------ nil + b3: 1-unblock 2-unblock-(edit|(unjailed/active)) 3-unblock 4-block ------ newpk-power + + c1: 1-block-jailed 2-block-edit 3-unblock ------ nil + c2: 1-block-jailed 2-block-(edit|unjailed) 3-unblock 4-block ------ newpk-power + + d1: 1-unblock-(unjailed/active) 2-unblock-edit 3-block ------ oldpk-0,newpk-power + d2: 1-unblock-(unjailed/active) 2-unblock-(edit|jailed) 3-block 4-unblock ------ oldpk-0 + + e1: 1-block-jailed 2-block 3-unblock-edit 4-unblock ------ nil + e2: 1-block-jailed 2-block 3-unblock-(edit|unjailed) 4-unblock 5-block ------ newpk-power - // impossible case: power == 0 && validator unjailed, power != 0 && validator jailed - // power !=0 && validator unjailed + f1: 1-unblock-(unjailed/active) 2-unblock 3-block-edit 4-block ------ oldpk-0,newpk-power + f2: 1-unblock-(unjailed/active) 2-unblock 3-block-(edit|jailed) 4-block 5-unblock ------ oldpk-0 - // case3: validator jailed previous block, unjailed current block - lastVoted := lastVote[string(oldTmPk.Address())] - if !lastVoted && !validator.Jailed { + + // validator status + ok=true,power==0,jailed=true // jailed current block + ok=true,power==0,jailed=false // impossible + ok=true,power!=0,jailed=true // impossible + ok=true,power!=0,jailed=false // unjailed/active current block + ok=false,power==0,jailed=true // jailed previous block + ok=false,power==0,jailed=false // inactive validator + ok=false,power!=0,jailed=true // impossible + ok=false,power!=0,jailed=false // online validator + */ + + // validator jailed current block // a2,d2,f2 + if ok && power == 0 && val.Jailed { + return []abci.ValidatorUpdate{oldPkUpdate}, nil + } + // validator unjailed/active current block // b3,c2,e2 + if ok && power != 0 && !val.Jailed { return []abci.ValidatorUpdate{newPkUpdate}, nil } - - // case4: validator already online - return []abci.ValidatorUpdate{oldPkUpdate, newPkUpdate}, nil + // validator jailed previous block // b1,c1,e1 + if !ok && power == 0 && val.Jailed { + return []abci.ValidatorUpdate{}, nil + } + // validator inactive // b2 + if !ok && power == 0 && !val.Jailed { + return []abci.ValidatorUpdate{}, nil + } + // validator online // a1,d1,f1 + if !ok && power != 0 && !val.Jailed { + return []abci.ValidatorUpdate{oldPkUpdate, newPkUpdate}, nil + } + return nil, errors.New("impossible case") } diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go index 00100a9e0..0fa321875 100644 --- a/x/staking/keeper/abci_test.go +++ b/x/staking/keeper/abci_test.go @@ -43,9 +43,9 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { } // validator update(process start) - updates := suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, valUpdates, pkPowerUpdate, lastVote) + updates := suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, valUpdates, pkPowerUpdate) suite.Require().Len(updates, 2) - updates = suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, valUpdates, pkPowerUpdate, lastVote) + updates = suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, valUpdates, pkPowerUpdate) suite.Require().Len(updates, 0) _, found = suite.app.StakingKeeper.GetConsensusPubKey(suite.ctx, valAddr) @@ -59,7 +59,7 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { suite.Require().Nil(nilPk) // consensus process(process end) - suite.app.StakingKeeper.ConsensusProcess(suite.ctx, pkPowerUpdate, lastVote) + suite.app.StakingKeeper.ConsensusProcess(suite.ctx) nilPk, err = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessStart) suite.Require().NoError(err) @@ -75,7 +75,7 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { suite.Require().True(found) // consensus process(process delete) - suite.app.StakingKeeper.ConsensusProcess(suite.ctx, pkPowerUpdate, lastVote) + suite.app.StakingKeeper.ConsensusProcess(suite.ctx) _, found = suite.app.StakingKeeper.GetConsensusPubKey(suite.ctx, valAddr) suite.Require().False(found) diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 49de25a15..24e050807 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -11,7 +11,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - abci "github.com/tendermint/tendermint/abci/types" "github.com/functionx/fx-core/v5/x/staking/types" ) @@ -23,8 +22,6 @@ type Keeper struct { authzKeeper types.AuthzKeeper slashingKeeper types.SlashingKeeper - - lastCommit []abci.VoteInfo } // NewKeeper creates a new staking Keeper instance diff --git a/x/staking/module.go b/x/staking/module.go index 47e59d27c..acdc8eaa2 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -80,11 +80,6 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { am.AppModule.RegisterServices(cfg) } -// BeginBlock returns the begin blocker for the staking module. -func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { - am.Keeper.BeginBlock(ctx, req) -} - // EndBlock returns the end blocker for the staking module. It returns no validator // updates. func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { From 7f5a0f9a1fe6b5200767ebe706dfeceeb62f4fcc Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Wed, 2 Aug 2023 16:02:37 +0800 Subject: [PATCH 20/30] perf: staking end block * test update when validator delete --- x/staking/keeper/abci.go | 21 +-- x/staking/keeper/abci_test.go | 241 ++++++++++++++++++++++++++++++-- x/staking/keeper/keeper_test.go | 67 ++++++++- 3 files changed, 305 insertions(+), 24 deletions(-) diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index 37f3d14d1..59b26b70f 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -70,8 +70,9 @@ func (k Keeper) consesnsusProcessEnd(ctx sdk.Context, valAddr sdk.ValAddress, pk // update validator new pk signing info validator, found := k.GetValidator(ctx, valAddr) if !found { - // NOTE: validator not found - // unbonded and undelegate all, will delete validator + // NOTE: validator not found, because it deleted in below case + // 1. validator unbonded and undelegate all (tx) + // 2. unbonding to unbonded and validator share is zero (end block) // remove old consensus pubkey and return k.Logger(ctx).Info("validator not found", "address", valAddr.String(), "process", "end") return nil @@ -109,8 +110,9 @@ func (k Keeper) consensusProcessStart(ctx sdk.Context, valAddr sdk.ValAddress, p // update validator new pk signing info validator, found := k.GetValidator(ctx, valAddr) if !found { - // NOTE: validator not found - // unbonded and undelegate all, will delete validator + // NOTE: validator not found, because it deleted in below case + // 1. validator unbonded and undelegate all (tx) + // 2. unbonding to unbonded and validator share is zero (end block) // return nil and delete old consensus pubkey in end process k.Logger(ctx).Info("validator not found", "address", valAddr.String(), "process", "start") return nil @@ -148,9 +150,15 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda pkUpdate := make([]abci.ValidatorUpdate, 0, 50) k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, pkBytes []byte) bool { + // no matter what happens, clear new consensus pubkey + k.RemoveConsensusPubKey(ctx, valAddr) + + // check validator exist validator, found := k.GetValidator(ctx, valAddr) if !found { - // NOTE: unbonded and undelegate all, will delete validator + // NOTE: validator not found, because it deleted in below case + // 1. validator unbonded and undelegate all (tx) + // 2. unbonding to unbonded and validator share is zero (end block) k.Logger(ctx).Error("validator not found", "address", valAddr.String(), "process", "update") k.RemoveConsensusPubKey(ctx, valAddr) return false @@ -163,9 +171,6 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda } oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) - // no matter what happens next, clear new consensus pubkey - k.RemoveConsensusPubKey(ctx, valAddr) - // unmarshal failed, remove new consensus pubkey var newPubKey cryptotypes.PubKey if err = k.cdc.UnmarshalInterfaceJSON(pkBytes, &newPubKey); err != nil { diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go index 0fa321875..df46c64eb 100644 --- a/x/staking/keeper/abci_test.go +++ b/x/staking/keeper/abci_test.go @@ -5,8 +5,11 @@ import ( "fmt" "testing" + sdkmath "cosmossdk.io/math" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" @@ -17,6 +20,7 @@ import ( "github.com/functionx/fx-core/v5/client/jsonrpc" "github.com/functionx/fx-core/v5/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v5/types" "github.com/functionx/fx-core/v5/x/staking/types" ) @@ -102,8 +106,10 @@ func (suite *KeeperTestSuite) TestEditPubKeyJail() { suite.Commit() - // undelegate all and edit validator - _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares()) + // undelegate smaller min self delegate, and edit validator, can not undelegate all, it will be delete in end block + shares, err := validator.SharesFromTokensTruncated(validator.MinSelfDelegation.Sub(sdkmath.NewInt(1))) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares().Sub(shares)) suite.Require().NoError(err) err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) suite.Require().NoError(err) @@ -276,7 +282,10 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailNextBlock() { // next block begin suite.CommitBeginBlock(valUpdates) - _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares()) + // undelegate smaller min self delegate, can not undelegate all, it will be delete in end block + shares, err := validator.SharesFromTokensTruncated(validator.MinSelfDelegation.Sub(sdkmath.NewInt(1))) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares().Sub(shares)) suite.Require().NoError(err) valUpdates = suite.CommitEndBlock() @@ -332,10 +341,12 @@ func (suite *KeeperTestSuite) TestEditPubKeyUnjailAndJailNextBlock() { newPriv, _ := suite.GenerateConsKey() newPk := newPriv.PubKey() - suite.Commit() + suite.Commit(2) - // jailed by undelegate all - _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, delShares) + // undelegate smaller min self delegate, can not undelegate all, it will be delete in end block + shares, err := validator.SharesFromTokensTruncated(validator.MinSelfDelegation.Sub(sdkmath.NewInt(1))) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares().Sub(shares)) suite.Require().NoError(err) // validator jailed @@ -343,8 +354,7 @@ func (suite *KeeperTestSuite) TestEditPubKeyUnjailAndJailNextBlock() { suite.Require().True(found) suite.Require().True(validator.IsJailed()) - suite.Commit() - suite.Commit() + suite.Commit(3) valUpdates := suite.CommitEndBlock() suite.False(suite.CurrentVoteFound(oldPk)) @@ -401,8 +411,10 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailedPrevBlock() { suite.Commit() - // jailed by undelegate all - _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares()) + // undelegate smaller min self delegate, can not undelegate all, it will be delete in end block + shares, err := validator.SharesFromTokensTruncated(validator.MinSelfDelegation.Sub(sdkmath.NewInt(1))) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares().Sub(shares)) suite.Require().NoError(err) valUpdates := suite.CommitEndBlock() @@ -469,16 +481,16 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailedPrevBlockAndUnjail() { suite.Require().True(found) delAmt := validator.GetTokens() - delShares := validator.GetDelegatorShares() - // new consensus pubkey newPriv, _ := suite.GenerateConsKey() newPk := newPriv.PubKey() suite.Commit() - // jailed by undelegate all - _, err := suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, delShares) + // undelegate smaller min self delegate, can not undelegate all, it will be delete in end block + shares, err := validator.SharesFromTokensTruncated(validator.MinSelfDelegation.Sub(sdkmath.NewInt(1))) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares().Sub(shares)) suite.Require().NoError(err) valUpdates := suite.CommitEndBlock() @@ -518,6 +530,207 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailedPrevBlockAndUnjail() { suite.True(suite.NextVoteFound(newPk)) } +func (suite *KeeperTestSuite) TestEditPubKeyUnboundValidator() { + newPriKey := helpers.NewEthPrivKey() + accAddr := sdk.AccAddress(newPriKey.PubKey().Address()) + newConsPriKey := ed25519.GenPrivKey() + newConsPubKey := newConsPriKey.PubKey() + + helpers.AddTestAddr(suite.app, suite.ctx, accAddr, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdk.NewInt(10000).Mul(sdk.NewInt(1e18))))) + + // create validator + valAddr := sdk.ValAddress(accAddr) + selfDelegateCoin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1e17)) + des := stakingtypes.Description{Moniker: "test-node"} + rates := stakingtypes.CommissionRates{ + Rate: sdk.NewDecWithPrec(1, 2), + MaxRate: sdk.NewDecWithPrec(5, 2), + MaxChangeRate: sdk.NewDecWithPrec(1, 2), + } + newValMsg, err := stakingtypes.NewMsgCreateValidator(valAddr, newConsPubKey, selfDelegateCoin, des, rates, sdk.OneInt()) + suite.Require().NoError(err) + _, err = stakingkeeper.NewMsgServerImpl(suite.app.StakingKeeper.Keeper).CreateValidator(suite.ctx, newValMsg) + suite.Require().NoError(err) + + suite.Commit(3) + + // check validator + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().Equal(stakingtypes.Unbonded, validator.GetStatus()) + + // edit validator consensus pubkey + editConsPubKey := ed25519.GenPrivKey().PubKey() + editPubKeyMsg, err := types.NewMsgEditConsensusPubKey(valAddr, accAddr, editConsPubKey) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.EditConsensusPubKey(suite.ctx, editPubKeyMsg) + suite.Require().NoError(err) + + suite.Commit(3) + + // check validator + editValidator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) + suite.Require().True(found) + suite.Require().Equal(validator, editValidator) +} + +func (suite *KeeperTestSuite) TestEditPubKeyDeleteWithoutSigningInfo() { + initBalance := sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10000).Mul(sdkmath.NewInt(1e18)))) + accAddr1 := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + helpers.AddTestAddr(suite.app, suite.ctx, accAddr1, initBalance) + + selfDelegateCoin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1e17)) + des := stakingtypes.Description{Moniker: "test-node"} + rates := stakingtypes.CommissionRates{ + Rate: sdk.NewDecWithPrec(1, 2), + MaxRate: sdk.NewDecWithPrec(5, 2), + MaxChangeRate: sdk.NewDecWithPrec(1, 2), + } + oldPubKey := ed25519.GenPrivKey().PubKey() + + // create validator + newValMsg1, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(accAddr1), oldPubKey, selfDelegateCoin, des, rates, sdkmath.OneInt()) + suite.Require().NoError(err) + _, err = stakingkeeper.NewMsgServerImpl(suite.app.StakingKeeper.Keeper).CreateValidator(suite.ctx, newValMsg1) + suite.Require().NoError(err) + + suite.Commit(3) + + editConsPubKey := ed25519.GenPrivKey().PubKey() + // 1. edit and delete validator + editPubKeyMsg, err := types.NewMsgEditConsensusPubKey(sdk.ValAddress(accAddr1), accAddr1, editConsPubKey) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.EditConsensusPubKey(suite.ctx, editPubKeyMsg) + suite.Require().NoError(err) + undelMsg1 := stakingtypes.NewMsgUndelegate(accAddr1, sdk.ValAddress(accAddr1), selfDelegateCoin) + _, err = stakingkeeper.NewMsgServerImpl(suite.app.StakingKeeper.Keeper).Undelegate(suite.ctx, undelMsg1) + suite.Require().NoError(err) + suite.CommitEndBlock() + + // block +1, validator delete, process not exist, new signing info not exist, old signing info not exist + _, found := suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(accAddr1)) + suite.Require().False(found) + process := suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, sdk.ValAddress(accAddr1)) + suite.Require().False(process) + found = suite.app.SlashingKeeper.HasValidatorSigningInfo(suite.ctx, sdk.ConsAddress(editConsPubKey.Address())) + suite.Require().False(found) + oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) + suite.Require().NoError(err) + found = suite.app.SlashingKeeper.HasValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().False(found) +} + +func (suite *KeeperTestSuite) TestEditPubKeyDelete() { + valUpdates, accAddr, oldConsAddr := suite.CreateValidatorJailed() + editConsPubKey := ed25519.GenPrivKey().PubKey() + + suite.CommitBeginBlock(valUpdates) + // edit and delete validator + editPubKeyMsg, err := types.NewMsgEditConsensusPubKey(sdk.ValAddress(accAddr), accAddr, editConsPubKey) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.EditConsensusPubKey(suite.ctx, editPubKeyMsg) + suite.Require().NoError(err) + undelMsg1 := stakingtypes.NewMsgUndelegate(accAddr, sdk.ValAddress(accAddr), sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1e18).Mul(sdkmath.NewInt(10)))) + _, err = stakingkeeper.NewMsgServerImpl(suite.app.StakingKeeper.Keeper).Undelegate(suite.ctx, undelMsg1) + suite.Require().NoError(err) + _ = suite.CommitEndBlock() + + // validator delete, new signing info not exist, old signing info exist + _, found := suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().False(found) + found = suite.app.SlashingKeeper.HasValidatorSigningInfo(suite.ctx, sdk.ConsAddress(editConsPubKey.Address())) + suite.Require().False(found) + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) +} + +func (suite *KeeperTestSuite) TestEditPubKeyDeleteNextBlock() { + valUpdates, accAddr, oldConsAddr := suite.CreateValidatorJailed() + editConsPubKey := ed25519.GenPrivKey().PubKey() + + // edit pubkey + suite.CommitBeginBlock(valUpdates) + editPubKeyMsg, err := types.NewMsgEditConsensusPubKey(sdk.ValAddress(accAddr), accAddr, editConsPubKey) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.EditConsensusPubKey(suite.ctx, editPubKeyMsg) + suite.Require().NoError(err) + valUpdates = suite.CommitEndBlock() + + process := suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().True(process) + + // next block, validator delete + suite.CommitBeginBlock(valUpdates) + undelMsg := stakingtypes.NewMsgUndelegate(accAddr, sdk.ValAddress(accAddr), sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1e18).Mul(sdkmath.NewInt(10)))) + _, err = stakingkeeper.NewMsgServerImpl(suite.app.StakingKeeper.Keeper).Undelegate(suite.ctx, undelMsg) + suite.Require().NoError(err) + valUpdates = suite.CommitEndBlock() + + // validator delete and old and new signing info exist + _, found := suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().False(found) + process = suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().True(process) + found = suite.app.SlashingKeeper.HasValidatorSigningInfo(suite.ctx, sdk.ConsAddress(editConsPubKey.Address())) + suite.Require().True(found) + found = suite.app.SlashingKeeper.HasValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + + // block +1, old signing info deleted + suite.CommitBeginBlock(valUpdates) + _ = suite.CommitEndBlock() + + // old signing info deleted, process not exist + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().False(found) + process = suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().False(process) +} + +func (suite *KeeperTestSuite) TestEditPubKeyDeleteNextNextBlock() { + valUpdates, accAddr, oldConsAddr := suite.CreateValidatorJailed() + editConsPubKey := ed25519.GenPrivKey().PubKey() + + // edit pubkey + suite.CommitBeginBlock(valUpdates) + editPubKeyMsg, err := types.NewMsgEditConsensusPubKey(sdk.ValAddress(accAddr), accAddr, editConsPubKey) + suite.Require().NoError(err) + _, err = suite.app.StakingKeeper.EditConsensusPubKey(suite.ctx, editPubKeyMsg) + suite.Require().NoError(err) + valUpdates = suite.CommitEndBlock() + + process := suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().True(process) + + suite.CommitBeginBlock(valUpdates) + valUpdates = suite.CommitEndBlock() + + process = suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().True(process) + // validator exist, old and new signing info exist, new signing info exit + _, found := suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().True(found) + found = suite.app.SlashingKeeper.HasValidatorSigningInfo(suite.ctx, sdk.ConsAddress(editConsPubKey.Address())) + suite.Require().True(found) + found = suite.app.SlashingKeeper.HasValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + + suite.CommitBeginBlock(valUpdates) + // validator delete + undelMsg := stakingtypes.NewMsgUndelegate(accAddr, sdk.ValAddress(accAddr), sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1e18).Mul(sdkmath.NewInt(10)))) + _, err = stakingkeeper.NewMsgServerImpl(suite.app.StakingKeeper.Keeper).Undelegate(suite.ctx, undelMsg) + suite.Require().NoError(err) + _ = suite.CommitEndBlock() + + // validator delete, new signing info exist, old signing info not exist + _, found = suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().False(found) + found = suite.app.SlashingKeeper.HasValidatorSigningInfo(suite.ctx, sdk.ConsAddress(editConsPubKey.Address())) + suite.Require().True(found) + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().False(found) +} + func TestValidatorUpdateEvidence(t *testing.T) { helpers.SkipTest(t, "Skipping local test:", t.Name()) diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 5969afbf7..c717bed56 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -13,6 +13,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/stretchr/testify/suite" abci "github.com/tendermint/tendermint/abci/types" @@ -55,6 +57,7 @@ func (suite *KeeperTestSuite) SetupSubTest() { suite.ctx = suite.app.NewContext(false, tmproto.Header{ ChainID: fxtypes.MainnetChainId, Height: suite.app.LastBlockHeight() + 1, + Time: time.Now().UTC(), ProposerAddress: valSet.Proposer.Address.Bytes(), }) suite.ctx = suite.ctx.WithConsensusParams(helpers.ABCIConsensusParams) @@ -82,6 +85,11 @@ func (suite *KeeperTestSuite) SetupSubTest() { suite.currentVoteInfo = infos suite.nextVoteInfo = infos + stakingParams := suite.app.StakingKeeper.GetParams(suite.ctx) + stakingParams.UnbondingTime = time.Second + stakingParams.MaxValidators = 150 + suite.app.StakingKeeper.SetParams(suite.ctx, stakingParams) + suite.signer = helpers.NewSigner(helpers.NewEthPrivKey()) helpers.AddTestAddr(suite.app, suite.ctx, suite.signer.AccAddress(), sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(100).MulRaw(1e18)))) } @@ -122,7 +130,7 @@ func (suite *KeeperTestSuite) CommitBeginBlock(valUpdate []abci.ValidatorUpdate) header := suite.ctx.BlockHeader() // begin block - header.Time = time.Now().UTC() + header.Time = header.Time.Add(5 * time.Second) header.Height += 1 suite.app.BeginBlock(abci.RequestBeginBlock{ @@ -179,9 +187,64 @@ func (suite *KeeperTestSuite) NextVoteFound(pk cryptotypes.PubKey) bool { return false } -func (suite *KeeperTestSuite) Commit() { +func (suite *KeeperTestSuite) Commit(count ...int) { + number := 1 + if len(count) > 0 && count[0] > 0 { + number = count[0] + } + for i := 0; i < number; i++ { + valUpdates := suite.CommitEndBlock() + suite.CommitBeginBlock(valUpdates) + } +} + +func (suite *KeeperTestSuite) CreateValidatorJailed() ([]abci.ValidatorUpdate, sdk.AccAddress, sdk.ConsAddress) { + accAddr := sdk.AccAddress(helpers.GenerateAddress().Bytes()) + initBalance := sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10000).Mul(sdkmath.NewInt(1e18)))) + helpers.AddTestAddr(suite.app, suite.ctx, accAddr, initBalance) + + activeMinSelfDelegateCoin := sdkmath.NewInt(99).Mul(sdkmath.NewInt(1e18)) + activeSelfDelegateCoin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(100).Mul(sdkmath.NewInt(1e18))) + des := stakingtypes.Description{Moniker: "test-node"} + rates := stakingtypes.CommissionRates{ + Rate: sdk.NewDecWithPrec(1, 2), + MaxRate: sdk.NewDecWithPrec(5, 2), + MaxChangeRate: sdk.NewDecWithPrec(1, 2), + } + + consPubKey := ed25519.GenPrivKey().PubKey() + newValMsg, err := stakingtypes.NewMsgCreateValidator(sdk.ValAddress(accAddr), consPubKey, activeSelfDelegateCoin, des, rates, activeMinSelfDelegateCoin) + suite.Require().NoError(err) + _, err = stakingkeeper.NewMsgServerImpl(suite.app.StakingKeeper.Keeper).CreateValidator(suite.ctx, newValMsg) + suite.Require().NoError(err) + + suite.Commit(3) valUpdates := suite.CommitEndBlock() + + // validator not jailed + validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().True(found) + suite.Require().False(validator.IsJailed()) + suite.CommitBeginBlock(valUpdates) + // jailed validator + undelMsg2 := stakingtypes.NewMsgUndelegate(accAddr, sdk.ValAddress(accAddr), activeSelfDelegateCoin.SubAmount(sdkmath.NewInt(1e18).Mul(sdkmath.NewInt(10)))) + _, err = stakingkeeper.NewMsgServerImpl(suite.app.StakingKeeper.Keeper).Undelegate(suite.ctx, undelMsg2) + suite.Require().NoError(err) + suite.Commit(3) + valUpdates = suite.CommitEndBlock() + + // validator jailed + validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, sdk.ValAddress(accAddr)) + suite.Require().True(found) + suite.Require().True(validator.IsJailed()) + consAddr, err := validator.GetConsAddr() + suite.Require().NoError(err) + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, consAddr) + suite.Require().True(found) + // if not found, validator maybe not bounded + + return valUpdates, accAddr, consAddr } func (suite *KeeperTestSuite) TestHasValidatorGrant() { From 011dd088944fce9afb02c08623e2926c37265215 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Wed, 2 Aug 2023 18:56:32 +0800 Subject: [PATCH 21/30] perf: evm apply transaction * remove unused hooks --- app/keepers/keepers.go | 1 - app/keepers/keepers_test.go | 4 ++ x/evm/keeper/keeper.go | 17 +----- x/evm/keeper/state_transition.go | 98 +++++++------------------------- 4 files changed, 27 insertions(+), 93 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 869170134..482408790 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -321,7 +321,6 @@ func NewAppKeeper( ), appKeepers.AccountKeeper, ) - appKeepers.EvmKeeper = appKeepers.EvmKeeper.SetHooks(evmkeeper.NewMultiEvmHooks()) appKeepers.Erc20Keeper = erc20keeper.NewKeeper( appKeepers.keys[erc20types.StoreKey], diff --git a/app/keepers/keepers_test.go b/app/keepers/keepers_test.go index c742f35b6..150fec2e0 100644 --- a/app/keepers/keepers_test.go +++ b/app/keepers/keepers_test.go @@ -90,6 +90,10 @@ func checkStructField(t *testing.T, valueOf reflect.Value, name string) { case "storeKey": assert.False(t, valueOfField.IsNil(), typeOfField.Name) case "hooks": + // evm hooks deprecated + if valueOfField.Type().String() == "types.EvmHooks" { + continue + } t.Log("-> hooks: ", valueOfField.Type(), valueOfField.Kind()) assert.False(t, valueOfField.IsNil(), typeOfField.Name) } diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 5f12bde11..7125aacdc 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -23,11 +23,7 @@ type Keeper struct { // access to account state accountKeeper fxevmtypes.AccountKeeper - - // has evm hooks - hasHooks bool - - module common.Address + module common.Address } func NewKeeper(ek *evmkeeper.Keeper, ak fxevmtypes.AccountKeeper) *Keeper { @@ -44,17 +40,6 @@ func NewKeeper(ek *evmkeeper.Keeper, ak fxevmtypes.AccountKeeper) *Keeper { } } -// SetHooks sets the hooks for the EVM module -// It should be called only once during initialization, it panic if called more than once. -func (k *Keeper) SetHooks(eh types.EvmHooks) *Keeper { - if eh == nil { - panic("cannot to set nil evm hook") - } - k.Keeper.SetHooks(eh) - k.hasHooks = true - return k -} - // CallEVMWithoutGas performs a smart contract method call using contract data without gas func (k *Keeper) CallEVMWithoutGas( ctx sdk.Context, diff --git a/x/evm/keeper/state_transition.go b/x/evm/keeper/state_transition.go index e7f8ceac8..9de24d596 100644 --- a/x/evm/keeper/state_transition.go +++ b/x/evm/keeper/state_transition.go @@ -9,7 +9,6 @@ import ( "github.com/ethereum/go-ethereum/core" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" - "github.com/ethereum/go-ethereum/crypto" ethparams "github.com/ethereum/go-ethereum/params" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" "github.com/evmos/ethermint/x/evm/statedb" @@ -62,11 +61,6 @@ func (k *Keeper) EVMConfig(ctx sdk.Context, proposerAddress sdk.ConsAddress, cha // // For relevant discussion see: https://github.com/cosmos/cosmos-sdk/discussions/9072 func (k *Keeper) ApplyTransaction(ctx sdk.Context, msgEth *types.MsgEthereumTx) (*types.MsgEthereumTxResponse, error) { - var ( - bloom *big.Int - bloomReceipt ethtypes.Bloom - ) - cfg, err := k.EVMConfig(ctx, sdk.ConsAddress(ctx.BlockHeader().ProposerAddress), k.ChainID()) if err != nil { return nil, errorsmod.Wrap(err, "failed to load evm config") @@ -81,76 +75,14 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, msgEth *types.MsgEthereumTx) return nil, errorsmod.Wrap(err, "failed to return ethereum transaction as core message") } - // snapshot to contain the tx processing and post processing in same scope - var commit func() - tmpCtx := ctx - if k.hasHooks { - // Create a cache context to revert state when tx hooks fails, - // the cache context is only committed when both tx and hooks executed successfully. - // Didn't use `Snapshot` because the context stack has exponential complexity on certain operations, - // thus restricted to be used only inside `ApplyMessage`. - tmpCtx, commit = ctx.CacheContext() - } - - // pass true to commit the StateDB + // cache context to be committed later if tx is successful + tmpCtx, commit := ctx.CacheContext() res, err := k.ApplyMessageWithConfig(tmpCtx, msg, nil, true, cfg, txConfig) if err != nil { return nil, errorsmod.Wrap(err, "failed to apply ethereum core message") } - - logs := types.LogsToEthereum(res.Logs) - - // Compute block bloom filter - if len(logs) > 0 { - bloom = k.GetBlockBloomTransient(ctx) - bloom.Or(bloom, big.NewInt(0).SetBytes(ethtypes.LogsBloom(logs))) - bloomReceipt = ethtypes.BytesToBloom(bloom.Bytes()) - } - - cumulativeGasUsed := res.GasUsed - if ctx.BlockGasMeter() != nil { - limit := ctx.BlockGasMeter().Limit() - cumulativeGasUsed += ctx.BlockGasMeter().GasConsumed() - if cumulativeGasUsed > limit { - cumulativeGasUsed = limit - } - } - - var contractAddr common.Address - if msg.To() == nil { - contractAddr = crypto.CreateAddress(msg.From(), msg.Nonce()) - } - - receipt := ðtypes.Receipt{ - Type: ethTx.Type(), - PostState: nil, // TODO: intermediate state root - CumulativeGasUsed: cumulativeGasUsed, - Bloom: bloomReceipt, - Logs: logs, - TxHash: txConfig.TxHash, - ContractAddress: contractAddr, - GasUsed: res.GasUsed, - BlockHash: txConfig.BlockHash, - BlockNumber: big.NewInt(ctx.BlockHeight()), - TransactionIndex: txConfig.TxIndex, - } - if !res.Failed() { - receipt.Status = ethtypes.ReceiptStatusSuccessful - // Only call hooks if tx executed successfully. - if err = k.PostTxProcessing(tmpCtx, msg, receipt); err != nil { - // If hooks return error, revert the whole tx. - res.VmError = types.ErrPostTxProcessing.Error() - k.Logger(ctx).Error("tx post processing failed", "error", err) - - // If the tx failed in post processing hooks, we should clear the logs - res.Logs = nil - } else if commit != nil { - // PostTxProcessing is successful, commit the tmpCtx - commit() - // Since the post-processing can alter the log, we need to update the result - res.Logs = types.NewLogsFromEth(receipt.Logs) - } + commit() } // refund gas in order to match the Ethereum gas consumption instead of the default SDK one. @@ -158,10 +90,15 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, msgEth *types.MsgEthereumTx) return nil, errorsmod.Wrapf(err, "failed to refund gas leftover gas to sender %s", msg.From()) } - if len(receipt.Logs) > 0 { + // logs and bloom filter (tx failed, logs are empty) + if len(res.Logs) > 0 { + ethLogs := types.LogsToEthereum(res.Logs) + bloom := k.GetBlockBloomTransient(ctx) + bloom.Or(bloom, big.NewInt(0).SetBytes(ethtypes.LogsBloom(ethLogs))) + bloomReceipt := ethtypes.BytesToBloom(bloom.Bytes()) // Update transient block bloom filter - k.SetBlockBloomTransient(ctx, receipt.Bloom.Big()) - k.SetLogSizeTransient(ctx, uint64(txConfig.LogIndex)+uint64(len(receipt.Logs))) + k.SetBlockBloomTransient(ctx, bloomReceipt.Big()) + k.SetLogSizeTransient(ctx, uint64(txConfig.LogIndex)+uint64(len(ethLogs))) } k.SetTxIndexTransient(ctx, uint64(txConfig.TxIndex)+1) @@ -170,7 +107,6 @@ func (k *Keeper) ApplyTransaction(ctx sdk.Context, msgEth *types.MsgEthereumTx) if err != nil { return nil, errorsmod.Wrap(err, "failed to add transient gas used") } - // reset the gas meter for current cosmos transaction k.ResetGasMeterAndConsumeGas(ctx, totalGasUsed) return res, nil @@ -346,5 +282,15 @@ func (k *Keeper) ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLo return nil, errorsmod.Wrap(err, "failed to load evm config") } txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash())) - return k.ApplyMessageWithConfig(ctx, msg, tracer, commit, cfg, txConfig) + + // cache context to be committed later if tx is successful + tmpCtx, ctxCommit := ctx.CacheContext() + res, err := k.ApplyMessageWithConfig(tmpCtx, msg, tracer, commit, cfg, txConfig) + if err != nil { + return nil, errorsmod.Wrap(err, "failed to apply ethereum core message") + } + if !res.Failed() { + ctxCommit() + } + return res, nil } From 6a911c548d7d342fc1c9852618e9c05970960cbb Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Thu, 3 Aug 2023 15:44:01 +0800 Subject: [PATCH 22/30] perf: call tx with value --- x/erc20/keeper/keeper_test.go | 6 +++--- x/erc20/keeper/msg_server.go | 8 ++++---- x/erc20/keeper/proposals_test.go | 2 +- x/erc20/types/expected_keepers.go | 3 ++- x/evm/keeper/contract_code.go | 11 ++++++----- x/evm/keeper/contract_code_test.go | 2 +- x/evm/keeper/keeper.go | 6 +++++- x/evm/keeper/keeper_test.go | 14 +++++++------- x/evm/keeper/msg_server.go | 2 +- x/evm/keeper/msg_server_test.go | 2 +- x/evm/precompiles/crosschain/contract_test.go | 6 +++--- .../precompiles/staking/delegation_rewards_test.go | 3 +-- x/evm/precompiles/staking/delegation_test.go | 2 +- 13 files changed, 36 insertions(+), 31 deletions(-) diff --git a/x/erc20/keeper/keeper_test.go b/x/erc20/keeper/keeper_test.go index 70cec931a..2f32289d6 100644 --- a/x/erc20/keeper/keeper_test.go +++ b/x/erc20/keeper/keeper_test.go @@ -133,7 +133,7 @@ func (suite *KeeperTestSuite) DeployContract(from common.Address) (common.Addres contract, err := suite.app.Erc20Keeper.DeployUpgradableToken(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), "Test token", "TEST", 18) suite.Require().NoError(err) - _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), contract, fxtypes.GetFIP20().ABI, "transferOwnership", from) + _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), contract, nil, fxtypes.GetFIP20().ABI, "transferOwnership", from) suite.Require().NoError(err) return contract, nil } @@ -232,7 +232,7 @@ func (suite *KeeperTestSuite) MintERC20Token(signer *helpers.Signer, contractAdd func (suite *KeeperTestSuite) ModuleMintERC20Token(contractAddr, to common.Address, amount *big.Int) { erc20 := fxtypes.GetFIP20() - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), contractAddr, erc20.ABI, "mint", to, amount) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), contractAddr, nil, erc20.ABI, "mint", to, amount) suite.Require().NoError(err) suite.Require().Empty(rsp.VmError) } @@ -255,7 +255,7 @@ func (suite *KeeperTestSuite) TransferERC20TokenToModule(signer *helpers.Signer, func (suite *KeeperTestSuite) TransferERC20TokenToModuleWithoutHook(contractAddr, from common.Address, amount *big.Int) { erc20 := fxtypes.GetFIP20() moduleAddress := suite.app.AccountKeeper.GetModuleAddress(types.ModuleName) - _, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, from, contractAddr, erc20.ABI, "transfer", common.BytesToAddress(moduleAddress.Bytes()), amount) + _, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, from, contractAddr, nil, erc20.ABI, "transfer", common.BytesToAddress(moduleAddress.Bytes()), amount) suite.Require().NoError(err) } diff --git a/x/erc20/keeper/msg_server.go b/x/erc20/keeper/msg_server.go index 7bf075e4f..25fee6392 100644 --- a/x/erc20/keeper/msg_server.go +++ b/x/erc20/keeper/msg_server.go @@ -191,7 +191,7 @@ func (k Keeper) ConvertCoinNativeCoin(ctx sdk.Context, pair types.TokenPair, sen contract := pair.GetERC20Contract() // Mint Tokens and send to receiver - _, err := k.evmKeeper.ApplyContract(ctx, k.moduleAddress, contract, erc20, "mint", receiver, coin.Amount.BigInt()) + _, err := k.evmKeeper.ApplyContract(ctx, k.moduleAddress, contract, nil, erc20, "mint", receiver, coin.Amount.BigInt()) if err != nil { return err } @@ -214,7 +214,7 @@ func (k Keeper) ConvertERC20NativeCoin(ctx sdk.Context, pair types.TokenPair, se contract := pair.GetERC20Contract() // Burn escrowed tokens - _, err := k.evmKeeper.ApplyContract(ctx, k.moduleAddress, contract, erc20, "burn", sender, amount.BigInt()) + _, err := k.evmKeeper.ApplyContract(ctx, k.moduleAddress, contract, nil, erc20, "burn", sender, amount.BigInt()) if err != nil { return err } @@ -248,7 +248,7 @@ func (k Keeper) ConvertERC20NativeToken(ctx sdk.Context, pair types.TokenPair, s // Escrow tokens on module account contract := pair.GetERC20Contract() - res, err := k.evmKeeper.ApplyContract(ctx, sender, contract, erc20, "transfer", k.moduleAddress, amount.BigInt()) + res, err := k.evmKeeper.ApplyContract(ctx, sender, contract, nil, erc20, "transfer", k.moduleAddress, amount.BigInt()) if err != nil { return err } @@ -302,7 +302,7 @@ func (k Keeper) ConvertCoinNativeERC20(ctx sdk.Context, pair types.TokenPair, se contract := pair.GetERC20Contract() // Unescrow Tokens and send to receiver - res, err := k.evmKeeper.ApplyContract(ctx, k.moduleAddress, contract, erc20, "transfer", receiver, coin.Amount.BigInt()) + res, err := k.evmKeeper.ApplyContract(ctx, k.moduleAddress, contract, nil, erc20, "transfer", receiver, coin.Amount.BigInt()) if err != nil { return err } diff --git a/x/erc20/keeper/proposals_test.go b/x/erc20/keeper/proposals_test.go index 3ed455869..2ca8e6f3d 100644 --- a/x/erc20/keeper/proposals_test.go +++ b/x/erc20/keeper/proposals_test.go @@ -535,7 +535,7 @@ func (suite *KeeperTestSuite) TestRegisterERC20ConversionInvariant() { beforeMintBalance := suite.BalanceOf(contact, suite.signer.Address()) suite.Require().EqualValues(beforeMintBalance.String(), big.NewInt(0).String()) initBalance := sdkmath.NewInt(1000).MulRaw(1e18) - _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contact, fxtypes.GetFIP20().ABI, "mint", suite.signer.Address(), initBalance.BigInt()) + _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contact, nil, fxtypes.GetFIP20().ABI, "mint", suite.signer.Address(), initBalance.BigInt()) suite.Require().NoError(err) afterMintBalance := suite.BalanceOf(contact, suite.signer.Address()) suite.Require().EqualValues(afterMintBalance.String(), initBalance.String()) diff --git a/x/erc20/types/expected_keepers.go b/x/erc20/types/expected_keepers.go index c9dd38077..504e7d9dd 100644 --- a/x/erc20/types/expected_keepers.go +++ b/x/erc20/types/expected_keepers.go @@ -2,6 +2,7 @@ package types import ( "context" + "math/big" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -42,7 +43,7 @@ type BankKeeper interface { type EVMKeeper interface { GetAccountWithoutBalance(ctx sdk.Context, addr common.Address) *statedb.Account QueryContract(ctx sdk.Context, from, contract common.Address, abi abi.ABI, method string, res interface{}, constructorData ...interface{}) error - ApplyContract(ctx sdk.Context, from, contract common.Address, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) + ApplyContract(ctx sdk.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) DeployUpgradableContract(ctx sdk.Context, from, logic common.Address, logicData []byte, initializeAbi *abi.ABI, initializeArgs ...interface{}) (common.Address, error) } diff --git a/x/evm/keeper/contract_code.go b/x/evm/keeper/contract_code.go index 4543cb6a3..5babc4aa8 100644 --- a/x/evm/keeper/contract_code.go +++ b/x/evm/keeper/contract_code.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "fmt" + "math/big" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" @@ -81,7 +82,7 @@ func (k *Keeper) DeployContract(ctx sdk.Context, from common.Address, abi abi.AB return common.Address{}, err } - _, err = k.CallEVMWithoutGas(ctx, from, nil, data, true) + _, err = k.CallEVMWithoutGas(ctx, from, nil, nil, data, true) if err != nil { return common.Address{}, err } @@ -103,7 +104,7 @@ func (k *Keeper) DeployUpgradableContract(ctx sdk.Context, from, logic common.Ad // initialize contract if initializeAbi != nil { - _, err = k.ApplyContract(ctx, from, proxyContract, *initializeAbi, "initialize", initializeArgs...) + _, err = k.ApplyContract(ctx, from, proxyContract, nil, *initializeAbi, "initialize", initializeArgs...) if err != nil { return common.Address{}, err } @@ -117,7 +118,7 @@ func (k *Keeper) QueryContract(ctx sdk.Context, from, contract common.Address, a if err != nil { return errorsmod.Wrap(types.ErrABIPack, err.Error()) } - resp, err := k.CallEVMWithoutGas(ctx, from, &contract, args, false) + resp, err := k.CallEVMWithoutGas(ctx, from, &contract, nil, args, false) if err != nil { return err } @@ -128,12 +129,12 @@ func (k *Keeper) QueryContract(ctx sdk.Context, from, contract common.Address, a } // ApplyContract apply contract with args -func (k *Keeper) ApplyContract(ctx sdk.Context, from, contract common.Address, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) { +func (k *Keeper) ApplyContract(ctx sdk.Context, from, contract common.Address, value *big.Int, abi abi.ABI, method string, constructorData ...interface{}) (*evmtypes.MsgEthereumTxResponse, error) { args, err := abi.Pack(method, constructorData...) if err != nil { return nil, errorsmod.Wrap(types.ErrABIPack, err.Error()) } - resp, err := k.CallEVMWithoutGas(ctx, from, &contract, args, true) + resp, err := k.CallEVMWithoutGas(ctx, from, &contract, value, args, true) if err != nil { return nil, err } diff --git a/x/evm/keeper/contract_code_test.go b/x/evm/keeper/contract_code_test.go index 1d1aca872..c9cec52e7 100644 --- a/x/evm/keeper/contract_code_test.go +++ b/x/evm/keeper/contract_code_test.go @@ -87,7 +87,7 @@ func (suite *KeeperTestSuite) TestKeeper_ApplyContract() { suite.NoError(err) mintAmt := int64(tmrand.Uint32()) - _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, erc20.ABI, "mint", suite.signer.Address(), big.NewInt(mintAmt)) + _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, nil, erc20.ABI, "mint", suite.signer.Address(), big.NewInt(mintAmt)) suite.NoError(err) var balanceRes struct{ Value *big.Int } diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 7125aacdc..4912096cd 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -45,6 +45,7 @@ func (k *Keeper) CallEVMWithoutGas( ctx sdk.Context, from common.Address, contract *common.Address, + value *big.Int, data []byte, commit bool, ) (*types.MsgEthereumTxResponse, error) { @@ -62,11 +63,14 @@ func (k *Keeper) CallEVMWithoutGas( gasLimit = uint64(params.Block.MaxGas) } + if value == nil { + value = big.NewInt(0) + } msg := ethtypes.NewMessage( from, contract, nonce, - big.NewInt(0), // amount + value, // amount gasLimit, // gasLimit big.NewInt(0), // gasFeeCap big.NewInt(0), // gasTipCap diff --git a/x/evm/keeper/keeper_test.go b/x/evm/keeper/keeper_test.go index ebcbd489d..0876389d2 100644 --- a/x/evm/keeper/keeper_test.go +++ b/x/evm/keeper/keeper_test.go @@ -207,38 +207,38 @@ func (suite *KeeperTestSuite) Module(contract common.Address) common.Address { } func (suite *KeeperTestSuite) Approve(contract, spender common.Address, amount *big.Int) { - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, spender, contract, fxtypes.GetFIP20().ABI, "approve", suite.signer.Address(), amount) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, spender, contract, nil, fxtypes.GetFIP20().ABI, "approve", suite.signer.Address(), amount) suite.Require().NoError(err) suite.Require().False(rsp.Failed(), rsp) } // function transfer(address recipient, uint256 amount) public virtual override returns (bool) { func (suite *KeeperTestSuite) Transfer(contract, recipient common.Address, amount *big.Int) { - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, fxtypes.GetFIP20().ABI, "transfer", recipient, amount) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, nil, fxtypes.GetFIP20().ABI, "transfer", recipient, amount) suite.Require().NoError(err) suite.Require().False(rsp.Failed(), rsp) } func (suite *KeeperTestSuite) TransferFrom(contract, sender, recipient common.Address, amount *big.Int) { - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, fxtypes.GetFIP20().ABI, "transferFrom", sender, recipient, amount) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, nil, fxtypes.GetFIP20().ABI, "transferFrom", sender, recipient, amount) suite.Require().NoError(err) suite.Require().False(rsp.Failed(), rsp) } func (suite *KeeperTestSuite) Mint(contract, to common.Address, amount *big.Int) { - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, fxtypes.GetFIP20().ABI, "mint", to, amount) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, nil, fxtypes.GetFIP20().ABI, "mint", to, amount) suite.Require().NoError(err) suite.Require().False(rsp.Failed(), rsp) } func (suite *KeeperTestSuite) Burn(contract, from common.Address, amount *big.Int) { - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, fxtypes.GetFIP20().ABI, "burn", from, amount) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, nil, fxtypes.GetFIP20().ABI, "burn", from, amount) suite.Require().NoError(err) suite.Require().False(rsp.Failed(), rsp) } func (suite *KeeperTestSuite) TransferOwnership(contract, newOwner common.Address) { - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, fxtypes.GetFIP20().ABI, "transferOwnership", newOwner) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, nil, fxtypes.GetFIP20().ABI, "transferOwnership", newOwner) suite.Require().NoError(err) suite.Require().False(rsp.Failed(), rsp) } @@ -268,7 +268,7 @@ func (suite *KeeperTestSuite) Deposit(contract common.Address, amount *big.Int) } func (suite *KeeperTestSuite) Withdraw(contract common.Address, amount *big.Int) { - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, fxtypes.GetWFX().ABI, "withdraw", suite.signer.Address(), amount) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, nil, fxtypes.GetWFX().ABI, "withdraw", suite.signer.Address(), amount) suite.Require().NoError(err) suite.Require().False(rsp.Failed(), rsp) } diff --git a/x/evm/keeper/msg_server.go b/x/evm/keeper/msg_server.go index 3655b09bb..0735243f2 100644 --- a/x/evm/keeper/msg_server.go +++ b/x/evm/keeper/msg_server.go @@ -139,7 +139,7 @@ func (k *Keeper) CallContract(goCtx context.Context, msg *fxevmtypes.MsgCallCont if account == nil || !account.IsContract() { return nil, errorsmod.Wrapf(govtypes.ErrInvalidProposalMsg, "contract %s not found", contract.Hex()) } - _, err := k.CallEVMWithoutGas(ctx, k.module, &contract, common.Hex2Bytes(msg.Data), true) + _, err := k.CallEVMWithoutGas(ctx, k.module, &contract, nil, common.Hex2Bytes(msg.Data), true) if err != nil { return nil, err } diff --git a/x/evm/keeper/msg_server_test.go b/x/evm/keeper/msg_server_test.go index 999a9b942..0e0748785 100644 --- a/x/evm/keeper/msg_server_test.go +++ b/x/evm/keeper/msg_server_test.go @@ -132,7 +132,7 @@ func (suite *KeeperTestSuite) TestKeeper_CallContract() { _, err = suite.app.EvmKeeper.CallContract(sdk.WrapSDKContext(suite.ctx), failMsg) suite.Require().Error(err) // transferOwnership - _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, erc20.ABI, "transferOwnership", common.BytesToAddress(suite.app.AccountKeeper.GetModuleAddress(types.ModuleName))) + _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.signer.Address(), contract, nil, erc20.ABI, "transferOwnership", common.BytesToAddress(suite.app.AccountKeeper.GetModuleAddress(types.ModuleName))) suite.Require().NoError(err) // CallContract msg := &fxevmtypes.MsgCallContract{ diff --git a/x/evm/precompiles/crosschain/contract_test.go b/x/evm/precompiles/crosschain/contract_test.go index 55eb5f1de..9ae390a8d 100644 --- a/x/evm/precompiles/crosschain/contract_test.go +++ b/x/evm/precompiles/crosschain/contract_test.go @@ -158,7 +158,7 @@ func (suite *PrecompileTestSuite) DeployContract(from common.Address) (common.Ad contract, err := suite.app.Erc20Keeper.DeployUpgradableToken(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), "Test token", "TEST", 18) suite.Require().NoError(err) - _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), contract, fxtypes.GetFIP20().ABI, "transferOwnership", from) + _, err = suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), contract, nil, fxtypes.GetFIP20().ABI, "transferOwnership", from) suite.Require().NoError(err) return contract, nil } @@ -257,7 +257,7 @@ func (suite *PrecompileTestSuite) MintERC20Token(signer *helpers.Signer, contrac func (suite *PrecompileTestSuite) ModuleMintERC20Token(contractAddr, to common.Address, amount *big.Int) { erc20 := fxtypes.GetFIP20() - rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), contractAddr, erc20.ABI, "mint", to, amount) + rsp, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, suite.app.Erc20Keeper.ModuleAddress(), contractAddr, nil, erc20.ABI, "mint", to, amount) suite.Require().NoError(err) suite.Require().Empty(rsp.VmError) } @@ -294,7 +294,7 @@ func (suite *PrecompileTestSuite) TransferERC20TokenToModule(signer *helpers.Sig func (suite *PrecompileTestSuite) TransferERC20TokenToModuleWithoutHook(contractAddr, from common.Address, amount *big.Int) { erc20 := fxtypes.GetFIP20() moduleAddress := suite.app.AccountKeeper.GetModuleAddress(types.ModuleName) - _, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, from, contractAddr, erc20.ABI, "transfer", common.BytesToAddress(moduleAddress.Bytes()), amount) + _, err := suite.app.EvmKeeper.ApplyContract(suite.ctx, from, contractAddr, nil, erc20.ABI, "transfer", common.BytesToAddress(moduleAddress.Bytes()), amount) suite.Require().NoError(err) } diff --git a/x/evm/precompiles/staking/delegation_rewards_test.go b/x/evm/precompiles/staking/delegation_rewards_test.go index 9ec8bb364..248b7f970 100644 --- a/x/evm/precompiles/staking/delegation_rewards_test.go +++ b/x/evm/precompiles/staking/delegation_rewards_test.go @@ -149,8 +149,7 @@ func (suite *PrecompileTestSuite) TestDelegationRewards() { evmDenom := suite.app.EvmKeeper.GetParams(suite.ctx).EvmDenom pack, errArgs := tc.malleate(val0.GetOperator(), delAddr) - res, err = suite.app.EvmKeeper.CallEVMWithoutGas(suite.ctx, suite.signer.Address(), &stakingContract, pack, false) - + res, err = suite.app.EvmKeeper.CallEVMWithoutGas(suite.ctx, suite.signer.Address(), &stakingContract, nil, pack, false) if tc.result { suite.Require().NoError(err) suite.Require().False(res.Failed(), res.VmError) diff --git a/x/evm/precompiles/staking/delegation_test.go b/x/evm/precompiles/staking/delegation_test.go index 2d7f5c770..be220329f 100644 --- a/x/evm/precompiles/staking/delegation_test.go +++ b/x/evm/precompiles/staking/delegation_test.go @@ -164,7 +164,7 @@ func (suite *PrecompileTestSuite) TestDelegation() { suite.Commit() pack, errArgs := tc.malleate(val0.GetOperator(), delAddr) - res, err = suite.app.EvmKeeper.CallEVMWithoutGas(suite.ctx, suite.signer.Address(), &stakingContract, pack, false) + res, err = suite.app.EvmKeeper.CallEVMWithoutGas(suite.ctx, suite.signer.Address(), &stakingContract, nil, pack, false) delegation, found := suite.app.StakingKeeper.GetDelegation(suite.ctx, sdk.AccAddress(delAddr.Bytes()), val0.GetOperator()) suite.Require().True(found) From 82e2c265a34fec56aa34a5fdbb71f8b9ce6e7a90 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Thu, 3 Aug 2023 16:00:46 +0800 Subject: [PATCH 23/30] fix: staking update abci validator * last block voted and current block delegate/undelegate/redelegate --- x/staking/keeper/abci.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index 59b26b70f..bf3412609 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -160,13 +160,10 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda // 1. validator unbonded and undelegate all (tx) // 2. unbonding to unbonded and validator share is zero (end block) k.Logger(ctx).Error("validator not found", "address", valAddr.String(), "process", "update") - k.RemoveConsensusPubKey(ctx, valAddr) return false } oldPubKey, err := validator.ConsPubKey() if err != nil { - k.Logger(ctx).Error("invalid consensus pubkey", "address", valAddr.String(), "error", err.Error()) - k.RemoveConsensusPubKey(ctx, valAddr) return false } oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) @@ -174,14 +171,12 @@ func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpda // unmarshal failed, remove new consensus pubkey var newPubKey cryptotypes.PubKey if err = k.cdc.UnmarshalInterfaceJSON(pkBytes, &newPubKey); err != nil { - k.Logger(ctx).Error("unmarshal new consensus pubkey", "validator", valAddr.String(), "err", err.Error()) return false } cacheCtx, commit := ctx.CacheContext() // update validator pubkey if err = k.updateValidator(cacheCtx, validator, newPubKey); err != nil { - k.Logger(ctx).Error("update validator", "address", valAddr.String(), "error", err.Error()) return false } // slash update @@ -300,12 +295,14 @@ func (k Keeper) updateABICValidator(ctx sdk.Context, pkUpdate map[string]int64, f1: 1-unblock-(unjailed/active) 2-unblock 3-block-edit 4-block ------ oldpk-0,newpk-power f2: 1-unblock-(unjailed/active) 2-unblock 3-block-(edit|jailed) 4-block 5-unblock ------ oldpk-0 + g1: 1-block 2-block-(delegate|edit) 3-block 4-block ------ oldpk-0,newpk-power + // validator status ok=true,power==0,jailed=true // jailed current block ok=true,power==0,jailed=false // impossible ok=true,power!=0,jailed=true // impossible - ok=true,power!=0,jailed=false // unjailed/active current block + ok=true,power!=0,jailed=false // unjailed/active current block or delegate/undelegate/redelegate ok=false,power==0,jailed=true // jailed previous block ok=false,power==0,jailed=false // inactive validator ok=false,power!=0,jailed=true // impossible @@ -316,8 +313,24 @@ func (k Keeper) updateABICValidator(ctx sdk.Context, pkUpdate map[string]int64, if ok && power == 0 && val.Jailed { return []abci.ValidatorUpdate{oldPkUpdate}, nil } - // validator unjailed/active current block // b3,c2,e2 + // validator unjailed/active/delegate current block if ok && power != 0 && !val.Jailed { + hi, found := k.GetHistoricalInfo(ctx, ctx.BlockHeight()) + if !found { + return nil, fmt.Errorf("current height historical info not found") + } + lastVote := false + for _, lastVal := range hi.Valset { + if lastVal.OperatorAddress == val.OperatorAddress { + lastVote = true + break + } + } + // validator delegate/undelegate/redelegate current block // g1 + if lastVote { + return []abci.ValidatorUpdate{oldPkUpdate, newPkUpdate}, nil + } + // validator unjailed/active current block // b3,c2,e2 return []abci.ValidatorUpdate{newPkUpdate}, nil } // validator jailed previous block // b1,c1,e1 From 287bd3f2d1d0b7ec4ff059dc33ce3024ef955ba3 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Thu, 3 Aug 2023 18:36:19 +0800 Subject: [PATCH 24/30] refactor: staking abci update pubkey --- x/staking/keeper/abci.go | 235 +++++++++++----------------------- x/staking/keeper/abci_test.go | 12 +- x/staking/types/events.go | 3 +- 3 files changed, 78 insertions(+), 172 deletions(-) diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index bf3412609..4d12fb263 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -3,12 +3,12 @@ package keeper import ( "errors" "fmt" + "strconv" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -17,37 +17,39 @@ import ( fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) -func (k *Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { +func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { // staking EndBlocker valUpdates := staking.EndBlocker(ctx, k.Keeper) - // convert valUpdate and lastCommit to map - pkPowerUpdate := make(map[string]int64, len(valUpdates)) - for _, valUpdate := range valUpdates { - pkPowerUpdate[valUpdate.PubKey.String()] = valUpdate.Power - } - // consensus process start and end + // process pk update previous block k.ConsensusProcess(ctx) + // validators update current block, delayed next block + if len(valUpdates) > 0 { + return valUpdates + } + // update validator consensus pubkey - return k.ValidatorUpdate(ctx, valUpdates, pkPowerUpdate) + return k.ConsensusPubKeyUpdate(ctx) } func (k Keeper) ConsensusProcess(ctx sdk.Context) { k.IteratorConsensusProcess(ctx, fxstakingtypes.ProcessEnd, func(valAddr sdk.ValAddress, pkBytes []byte) { - if err := k.consesnsusProcessEnd(ctx, valAddr, pkBytes); err != nil { + // update signing info and remove old consensus pubkey + if err := k.processEnd(ctx, valAddr, pkBytes); err != nil { panic(err) } }) k.IteratorConsensusProcess(ctx, fxstakingtypes.ProcessStart, func(valAddr sdk.ValAddress, pkBytes []byte) { - if err := k.consensusProcessStart(ctx, valAddr, pkBytes); err != nil { + // update signing info + if err := k.processStart(ctx, valAddr, pkBytes); err != nil { panic(err) } }) } -func (k Keeper) consesnsusProcessEnd(ctx sdk.Context, valAddr sdk.ValAddress, pkBytes []byte) error { +func (k Keeper) processEnd(ctx sdk.Context, valAddr sdk.ValAddress, pkBytes []byte) error { k.DeleteConsensusProcess(ctx, valAddr, fxstakingtypes.ProcessEnd) var oldPubKey cryptotypes.PubKey @@ -73,8 +75,7 @@ func (k Keeper) consesnsusProcessEnd(ctx sdk.Context, valAddr sdk.ValAddress, pk // NOTE: validator not found, because it deleted in below case // 1. validator unbonded and undelegate all (tx) // 2. unbonding to unbonded and validator share is zero (end block) - // remove old consensus pubkey and return - k.Logger(ctx).Info("validator not found", "address", valAddr.String(), "process", "end") + k.slashingKeeper.DeleteConsensusPubKey(ctx, oldConsAddr) return nil } newConsAddr, err := validator.GetConsAddr() @@ -94,7 +95,9 @@ func (k Keeper) consesnsusProcessEnd(ctx sdk.Context, valAddr sdk.ValAddress, pk return nil } -func (k Keeper) consensusProcessStart(ctx sdk.Context, valAddr sdk.ValAddress, pkBytes []byte) error { +func (k Keeper) processStart(ctx sdk.Context, valAddr sdk.ValAddress, pkBytes []byte) error { + k.DeleteConsensusProcess(ctx, valAddr, fxstakingtypes.ProcessStart) + var oldPubKey cryptotypes.PubKey if err := k.cdc.UnmarshalInterfaceJSON(pkBytes, &oldPubKey); err != nil { return fmt.Errorf("invalid pubkey") @@ -105,7 +108,6 @@ func (k Keeper) consensusProcessStart(ctx sdk.Context, valAddr sdk.ValAddress, p if err := k.SetConsensusProcess(ctx, valAddr, oldPubKey, fxstakingtypes.ProcessEnd); err != nil { return err } - k.DeleteConsensusProcess(ctx, valAddr, fxstakingtypes.ProcessStart) // update validator new pk signing info validator, found := k.GetValidator(ctx, valAddr) @@ -113,8 +115,6 @@ func (k Keeper) consensusProcessStart(ctx sdk.Context, valAddr sdk.ValAddress, p // NOTE: validator not found, because it deleted in below case // 1. validator unbonded and undelegate all (tx) // 2. unbonding to unbonded and validator share is zero (end block) - // return nil and delete old consensus pubkey in end process - k.Logger(ctx).Info("validator not found", "address", valAddr.String(), "process", "start") return nil } @@ -135,7 +135,7 @@ func (k Keeper) updateSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress, sig return fmt.Errorf("validator %s not found signing info", consAddr.String()) } // double sign - if newSigningInfo.JailedUntil == evidencetypes.DoubleSignJailEndTime { + if newSigningInfo.Tombstoned { newSigningInfo.IndexOffset = signingInfo.IndexOffset newSigningInfo.MissedBlocksCounter = signingInfo.MissedBlocksCounter } else { @@ -146,80 +146,73 @@ func (k Keeper) updateSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress, sig return nil } -func (k Keeper) ValidatorUpdate(ctx sdk.Context, valUpdates []abci.ValidatorUpdate, pkPowerUpdate map[string]int64) []abci.ValidatorUpdate { - pkUpdate := make([]abci.ValidatorUpdate, 0, 50) - +func (k Keeper) ConsensusPubKeyUpdate(ctx sdk.Context) []abci.ValidatorUpdate { + valUpdates := make([]abci.ValidatorUpdate, 0, 50) k.IteratorConsensusPubKey(ctx, func(valAddr sdk.ValAddress, pkBytes []byte) bool { // no matter what happens, clear new consensus pubkey k.RemoveConsensusPubKey(ctx, valAddr) - // check validator exist - validator, found := k.GetValidator(ctx, valAddr) - if !found { - // NOTE: validator not found, because it deleted in below case - // 1. validator unbonded and undelegate all (tx) - // 2. unbonding to unbonded and validator share is zero (end block) - k.Logger(ctx).Error("validator not found", "address", valAddr.String(), "process", "update") - return false - } - oldPubKey, err := validator.ConsPubKey() - if err != nil { - return false - } - oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) - - // unmarshal failed, remove new consensus pubkey - var newPubKey cryptotypes.PubKey - if err = k.cdc.UnmarshalInterfaceJSON(pkBytes, &newPubKey); err != nil { - return false - } - cacheCtx, commit := ctx.CacheContext() - // update validator pubkey - if err = k.updateValidator(cacheCtx, validator, newPubKey); err != nil { - return false - } - // slash update - if err = k.updateSlashing(cacheCtx, newPubKey, oldConsAddr); err != nil { - k.Logger(ctx).Error("update slashing", "address", valAddr.String(), "error", err.Error()) - return false - } - // new validator updates - newValUpdates, err := k.updateABICValidator(cacheCtx, pkPowerUpdate, validator, newPubKey, oldPubKey) - if err != nil { - k.Logger(ctx).Error("update abci validator", "address", valAddr.String(), "error", err.Error()) - return false + pkUpdates, err := k.updateConsensusPubKey(cacheCtx, valAddr, pkBytes) + if err == nil { + valUpdates = append(valUpdates, pkUpdates...) + commit() } - // set consensus process start - if err := k.SetConsensusProcess(ctx, valAddr, oldPubKey, fxstakingtypes.ProcessStart); err != nil { - return false - } - - k.Logger(ctx).Info("update consensus pubkey", "address", valAddr.String(), - "oldConsAddr", oldConsAddr.String(), "newConsAddr", sdk.ConsAddress(newPubKey.Address()).String()) // event ctx.EventManager().EmitEvent(sdk.NewEvent( fxstakingtypes.EventTypeEditingConsensusPubKey, sdk.NewAttribute(types.AttributeKeyValidator, valAddr.String()), - sdk.NewAttribute(fxstakingtypes.AttributeOldConsAddr, oldConsAddr.String()), - sdk.NewAttribute(fxstakingtypes.AttributeNewConsAddr, sdk.ConsAddress(newPubKey.Address()).String()), + sdk.NewAttribute(fxstakingtypes.AttributeResult, strconv.FormatBool(err == nil)), )) - // commit cache context - commit() - - pkUpdate = append(pkUpdate, newValUpdates...) return false }) - // joint pkPowerUpdate and pkUpdate - newValUpdates := make([]abci.ValidatorUpdate, 0, len(pkPowerUpdate)+len(pkUpdate)) - for _, vu := range valUpdates { - if power, ok := pkPowerUpdate[vu.PubKey.String()]; ok { - newValUpdates = append(newValUpdates, abci.ValidatorUpdate{PubKey: vu.PubKey, Power: power}) + return valUpdates +} + +func (k Keeper) updateConsensusPubKey(ctx sdk.Context, valAddr sdk.ValAddress, pkBytes []byte) ([]abci.ValidatorUpdate, error) { + validator, found := k.GetValidator(ctx, valAddr) + if !found { + // NOTE: validator not found, because it deleted in below case + // 1. validator unbonded and undelegate all (tx) + // 2. unbonding to unbonded and validator share is zero (end block) + return nil, errors.New("validator not found") + } + oldPubKey, err := validator.ConsPubKey() + if err != nil { + return nil, fmt.Errorf("invalid old consensus pubkey") + } + oldConsAddr := sdk.ConsAddress(oldPubKey.Address()) + + var newPubKey cryptotypes.PubKey + if err = k.cdc.UnmarshalInterfaceJSON(pkBytes, &newPubKey); err != nil { + return nil, err + } + + // validator pubkey and consaddr + if err = k.updateValidator(ctx, validator, newPubKey); err != nil { + return nil, err + } + // pubkey and signing info + if err = k.updateSlashing(ctx, newPubKey, oldConsAddr); err != nil { + return nil, err + } + + // validator unjailed and bonded + var valUpdates []abci.ValidatorUpdate + if validator.IsBonded() { + // new validator updates + valUpdates, err = k.updateABCIValidator(ctx, validator, newPubKey, oldPubKey) + if err != nil { + return nil, err } } - newValUpdates = append(newValUpdates, pkUpdate...) - return newValUpdates + + // set consensus process, next 2 block will delete old consensus pubkey + if err = k.SetConsensusProcess(ctx, valAddr, oldPubKey, fxstakingtypes.ProcessStart); err != nil { + return nil, err + } + return valUpdates, nil } func (k Keeper) updateValidator(ctx sdk.Context, validator types.Validator, newPubKey cryptotypes.PubKey) error { @@ -245,15 +238,14 @@ func (k Keeper) updateSlashing(ctx sdk.Context, newPubKey cryptotypes.PubKey, ol signingInfo, found := k.slashingKeeper.GetValidatorSigningInfo(ctx, oldConsAddr) if !found { // NOTE: validator create but not bonded enough token - return fmt.Errorf("validator %s not found signing info", oldConsAddr.String()) + return fmt.Errorf("consensus address %s not found signing info", oldConsAddr.String()) } signingInfo.Address = newConsAddr.String() k.slashingKeeper.SetValidatorSigningInfo(ctx, newConsAddr, signingInfo) return nil } -//gocyclo:ignore -func (k Keeper) updateABICValidator(ctx sdk.Context, pkUpdate map[string]int64, val types.Validator, newPk, oldPk cryptotypes.PubKey) ([]abci.ValidatorUpdate, error) { +func (k Keeper) updateABCIValidator(ctx sdk.Context, val types.Validator, newPk, oldPk cryptotypes.PubKey) ([]abci.ValidatorUpdate, error) { oldTmProtoPk, err := cryptocodec.ToTmProtoPublicKey(oldPk) if err != nil { return nil, err @@ -262,88 +254,11 @@ func (k Keeper) updateABICValidator(ctx sdk.Context, pkUpdate map[string]int64, if err != nil { return nil, err } - power, ok := pkUpdate[oldTmProtoPk.String()] - // if power not found, validator not update current block, cal validator power - if !ok { - power = val.ConsensusPower(k.PowerReduction(ctx)) - } else { - // remove old pk power - delete(pkUpdate, oldTmProtoPk.String()) - } + valPower := val.ConsensusPower(k.PowerReduction(ctx)) // set old pk power to 0 oldPkUpdate := abci.ValidatorUpdate{PubKey: oldTmProtoPk, Power: 0} // add new pk with power - newPkUpdate := abci.ValidatorUpdate{PubKey: newTmProtoPk, Power: power} - - /* - a1: 1-block 2-block-edit 3-block ------ oldpk-0,newpk-power - a2: 1-block 2-block-(jailed|edit) 3-block 4-unblock ------ oldpk-0 + newPkUpdate := abci.ValidatorUpdate{PubKey: newTmProtoPk, Power: valPower} - b1: 1-unblock(jailed) 2-unblock-edit 3-unblock ------ nil - b2: 1-unblock(inactive) 2-unblock-edit 3-unblock ------ nil - b3: 1-unblock 2-unblock-(edit|(unjailed/active)) 3-unblock 4-block ------ newpk-power - - c1: 1-block-jailed 2-block-edit 3-unblock ------ nil - c2: 1-block-jailed 2-block-(edit|unjailed) 3-unblock 4-block ------ newpk-power - - d1: 1-unblock-(unjailed/active) 2-unblock-edit 3-block ------ oldpk-0,newpk-power - d2: 1-unblock-(unjailed/active) 2-unblock-(edit|jailed) 3-block 4-unblock ------ oldpk-0 - - e1: 1-block-jailed 2-block 3-unblock-edit 4-unblock ------ nil - e2: 1-block-jailed 2-block 3-unblock-(edit|unjailed) 4-unblock 5-block ------ newpk-power - - f1: 1-unblock-(unjailed/active) 2-unblock 3-block-edit 4-block ------ oldpk-0,newpk-power - f2: 1-unblock-(unjailed/active) 2-unblock 3-block-(edit|jailed) 4-block 5-unblock ------ oldpk-0 - - g1: 1-block 2-block-(delegate|edit) 3-block 4-block ------ oldpk-0,newpk-power - - - // validator status - ok=true,power==0,jailed=true // jailed current block - ok=true,power==0,jailed=false // impossible - ok=true,power!=0,jailed=true // impossible - ok=true,power!=0,jailed=false // unjailed/active current block or delegate/undelegate/redelegate - ok=false,power==0,jailed=true // jailed previous block - ok=false,power==0,jailed=false // inactive validator - ok=false,power!=0,jailed=true // impossible - ok=false,power!=0,jailed=false // online validator - */ - - // validator jailed current block // a2,d2,f2 - if ok && power == 0 && val.Jailed { - return []abci.ValidatorUpdate{oldPkUpdate}, nil - } - // validator unjailed/active/delegate current block - if ok && power != 0 && !val.Jailed { - hi, found := k.GetHistoricalInfo(ctx, ctx.BlockHeight()) - if !found { - return nil, fmt.Errorf("current height historical info not found") - } - lastVote := false - for _, lastVal := range hi.Valset { - if lastVal.OperatorAddress == val.OperatorAddress { - lastVote = true - break - } - } - // validator delegate/undelegate/redelegate current block // g1 - if lastVote { - return []abci.ValidatorUpdate{oldPkUpdate, newPkUpdate}, nil - } - // validator unjailed/active current block // b3,c2,e2 - return []abci.ValidatorUpdate{newPkUpdate}, nil - } - // validator jailed previous block // b1,c1,e1 - if !ok && power == 0 && val.Jailed { - return []abci.ValidatorUpdate{}, nil - } - // validator inactive // b2 - if !ok && power == 0 && !val.Jailed { - return []abci.ValidatorUpdate{}, nil - } - // validator online // a1,d1,f1 - if !ok && power != 0 && !val.Jailed { - return []abci.ValidatorUpdate{oldPkUpdate, newPkUpdate}, nil - } - return nil, errors.New("impossible case") + return []abci.ValidatorUpdate{oldPkUpdate, newPkUpdate}, nil } diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go index df46c64eb..5169106ea 100644 --- a/x/staking/keeper/abci_test.go +++ b/x/staking/keeper/abci_test.go @@ -12,7 +12,6 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/stretchr/testify/require" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/privval" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -39,17 +38,10 @@ func (suite *KeeperTestSuite) TestValidatorUpdate() { err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, pk) suite.Require().NoError(err) - valUpdates := make([]abci.ValidatorUpdate, 0) - pkPowerUpdate := make(map[string]int64) - lastVote := make(map[string]bool) - for _, info := range suite.currentVoteInfo { - lastVote[string(info.Validator.Address)] = true - } - // validator update(process start) - updates := suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, valUpdates, pkPowerUpdate) + updates := suite.app.StakingKeeper.ConsensusPubKeyUpdate(suite.ctx) suite.Require().Len(updates, 2) - updates = suite.app.StakingKeeper.ValidatorUpdate(suite.ctx, valUpdates, pkPowerUpdate) + updates = suite.app.StakingKeeper.ConsensusPubKeyUpdate(suite.ctx) suite.Require().Len(updates, 0) _, found = suite.app.StakingKeeper.GetConsensusPubKey(suite.ctx, valAddr) diff --git a/x/staking/types/events.go b/x/staking/types/events.go index 62ea31932..89e45f89b 100644 --- a/x/staking/types/events.go +++ b/x/staking/types/events.go @@ -16,6 +16,5 @@ const ( AttributeKeyRecipient = "recipient" AttributeKeyTo = "to" AttributeKeyPubKey = "pubkey" - AttributeOldConsAddr = "old_cons_addr" - AttributeNewConsAddr = "new_cons_addr" + AttributeResult = "result" ) From cc9b9a91637246a5f81872a0fc2c424c0d65d889 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Fri, 4 Aug 2023 16:02:18 +0800 Subject: [PATCH 25/30] test: abci update pubkey --- tests/staking_test.go | 4 +- testutil/helpers/test_helpers.go | 4 +- x/staking/keeper/abci_test.go | 110 ++++++++++++++++++------------- 3 files changed, 67 insertions(+), 51 deletions(-) diff --git a/tests/staking_test.go b/tests/staking_test.go index 0a2a51de1..0930b4a5d 100644 --- a/tests/staking_test.go +++ b/tests/staking_test.go @@ -656,7 +656,7 @@ func (suite *IntegrationMultiNodeTest) StakingEditPubKeyJailBlock() { suite.Require().NoError(err) suite.Require().True(valResp.Validator.Jailed) - height := txResp.Height + height := txResp.Height + 1 // val update, edit skip to next block // block tx process ctx := metadata.AppendToOutgoingContext(suite.ctx, grpctypes.GRPCBlockHeightHeader, fmt.Sprintf("%d", height)) @@ -682,7 +682,7 @@ func (suite *IntegrationMultiNodeTest) StakingEditPubKeyJailBlock() { suite.Error(err) info2, err = suite.slasing.SlashingQuery().SigningInfo(ctx, &slashingtypes.QuerySigningInfoRequest{ConsAddress: newConsAddr.String()}) suite.NoError(err) - suite.Equal(info1.ValSigningInfo.IndexOffset+1, info2.ValSigningInfo.IndexOffset) + suite.Equal(info1.ValSigningInfo.IndexOffset, info2.ValSigningInfo.IndexOffset) // delegate and unjail delegateMsg := stakingtypes.NewMsgDelegate(sdk.AccAddress(valAddr), valAddr, sdk.NewCoin(fxtypes.DefaultDenom, validator.Tokens)) diff --git a/testutil/helpers/test_helpers.go b/testutil/helpers/test_helpers.go index 939e353e5..e62ddd5dc 100644 --- a/testutil/helpers/test_helpers.go +++ b/testutil/helpers/test_helpers.go @@ -75,7 +75,7 @@ func Setup(isCheckTx bool, isShowLog bool) *app.App { } myApp := app.New(logger, dbm.NewMemDB(), - traceStore, true, map[int64]bool{}, os.TempDir(), 5, + traceStore, true, map[int64]bool{}, os.TempDir(), 1, app.MakeEncodingConfig(), app.EmptyAppOptions{}, ) if !isCheckTx { @@ -170,7 +170,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs UnbondingHeight: int64(0), UnbondingTime: time.Unix(0, 0).UTC(), Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()), - MinSelfDelegation: sdkmath.OneInt().Mul(sdk.NewInt(10)), + MinSelfDelegation: sdkmath.OneInt().Mul(sdkmath.NewInt(10)), } validators = append(validators, validator) delegations = append(delegations, stakingtypes.NewDelegation(genAccs[i].GetAddress(), validator.GetOperator(), sdk.NewDecFromInt(bondAmt))) diff --git a/x/staking/keeper/abci_test.go b/x/staking/keeper/abci_test.go index 5169106ea..5aa82ae85 100644 --- a/x/staking/keeper/abci_test.go +++ b/x/staking/keeper/abci_test.go @@ -113,6 +113,7 @@ func (suite *KeeperTestSuite) TestEditPubKeyJail() { suite.Require().NoError(err) suite.Require().Nil(process) // next block + suite.Commit(1) // val update, edit skip to next block valUpdates := suite.CommitEndBlock() // validator jailed @@ -138,29 +139,28 @@ func (suite *KeeperTestSuite) TestEditPubKeyJail() { suite.CommitBeginBlock(valUpdates) valUpdates = suite.CommitEndBlock() - suite.True(suite.CurrentVoteFound(oldPk)) - suite.False(suite.NextVoteFound(newPk)) - // check oldSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) suite.Require().True(found) newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) suite.Require().True(found) suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + process, err = suite.app.StakingKeeper.GetConsensusProcess(suite.ctx, valAddr, types.ProcessEnd) + suite.Require().NoError(err) + suite.Require().NotNil(process) // next block suite.CommitBeginBlock(valUpdates) _ = suite.CommitEndBlock() - suite.False(suite.CurrentVoteFound(oldPk)) - suite.False(suite.NextVoteFound(newPk)) - // check _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) suite.Require().False(found) newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, newConsAddr) suite.Require().True(found) - suite.Require().Equal(oldSigningInfo.IndexOffset+1, newSigningInfo.IndexOffset) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + found = suite.app.StakingKeeper.HasConsensusProcess(suite.ctx, valAddr) + suite.Require().False(found) } func (suite *KeeperTestSuite) TestEditPubKeyJailAndUnjail() { @@ -171,8 +171,9 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailAndUnjail() { oldPK, err := validator.ConsPubKey() suite.Require().NoError(err) - delAmt := validator.GetTokens() - delShares := validator.GetDelegatorShares() + delAmt := validator.GetTokens().Sub(sdkmath.NewInt(5)) // min self delegate: 10 + delShares, err := validator.SharesFromTokens(delAmt) + suite.Require().NoError(err) // new consensus pubkey newPriv, _ := suite.GenerateConsKey() @@ -186,8 +187,8 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailAndUnjail() { err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) suite.Require().NoError(err) - // end block - valUpdates := suite.CommitEndBlock() + suite.Commit() + valUpdates := suite.CommitEndBlock() // edit // validator jailed validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) @@ -197,9 +198,6 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailAndUnjail() { // next block suite.CommitBeginBlock(valUpdates) - suite.True(suite.CurrentVoteFound(oldPK)) - suite.False(suite.NextVoteFound(newPk)) - // unjail _, err = suite.app.StakingKeeper.Delegate(suite.ctx, sdk.AccAddress(valAddr), delAmt, stakingtypes.Unbonded, validator, true) suite.Require().NoError(err) @@ -207,11 +205,7 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailAndUnjail() { suite.Require().NoError(err) // end block - valUpdates = suite.CommitEndBlock() - - suite.True(suite.CurrentVoteFound(oldPK)) - suite.False(suite.CurrentVoteFound(newPk)) - suite.False(suite.NextVoteFound(newPk)) + valUpdates = suite.CommitEndBlock() // process start // validator unjailed validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) @@ -224,10 +218,7 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailAndUnjail() { // next block suite.CommitBeginBlock(valUpdates) - _ = suite.CommitEndBlock() - - suite.False(suite.CurrentVoteFound(newPk)) - suite.True(suite.NextVoteFound(newPk)) + _ = suite.CommitEndBlock() // process end // old signing info deleted _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(oldPK.Address())) @@ -325,20 +316,20 @@ func (suite *KeeperTestSuite) TestEditPubKeyUnjailAndJailNextBlock() { suite.Require().True(found) oldPk, err := validator.ConsPubKey() suite.Require().NoError(err) + oldConsAddr := sdk.ConsAddress(oldPk.Address()) - delAmt := validator.GetTokens() - delShares := validator.GetDelegatorShares() + delAmt := validator.Tokens.Sub(validator.MinSelfDelegation.Sub(sdkmath.NewInt(1))) + delShares, err := validator.SharesFromTokens(delAmt) + suite.Require().NoError(err) // new consensus pubkey newPriv, _ := suite.GenerateConsKey() newPk := newPriv.PubKey() - suite.Commit(2) // undelegate smaller min self delegate, can not undelegate all, it will be delete in end block - shares, err := validator.SharesFromTokensTruncated(validator.MinSelfDelegation.Sub(sdkmath.NewInt(1))) suite.Require().NoError(err) - _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares().Sub(shares)) + _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, delShares) suite.Require().NoError(err) // validator jailed @@ -349,20 +340,19 @@ func (suite *KeeperTestSuite) TestEditPubKeyUnjailAndJailNextBlock() { suite.Commit(3) valUpdates := suite.CommitEndBlock() - suite.False(suite.CurrentVoteFound(oldPk)) - suite.False(suite.NextVoteFound(oldPk)) - suite.CommitBeginBlock(valUpdates) // edit validator err = suite.app.StakingKeeper.SetConsensusPubKey(suite.ctx, valAddr, newPk) suite.Require().NoError(err) // unjail validator + validator, _ = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) _, err = suite.app.StakingKeeper.Delegate(suite.ctx, sdk.AccAddress(valAddr), delAmt, stakingtypes.Unbonded, validator, true) suite.Require().NoError(err) err = suite.app.SlashingKeeper.Unjail(suite.ctx, valAddr) suite.Require().NoError(err) // end block - valUpdates = suite.CommitEndBlock() + suite.Commit() + valUpdates = suite.CommitEndBlock() // edit // validator unjailed validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) @@ -373,18 +363,37 @@ func (suite *KeeperTestSuite) TestEditPubKeyUnjailAndJailNextBlock() { suite.Require().NoError(err) suite.Require().Equal(consAddr, sdk.ConsAddress(newPk.Address())) + // signing info equal + oldSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + newSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(newPk.Address())) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + suite.CommitBeginBlock(valUpdates) - // validator jailed _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, delShares) suite.Require().NoError(err) - _ = suite.CommitEndBlock() - - suite.True(suite.NextVoteFound(newPk)) + valUpdates = suite.CommitEndBlock() // process start // validator jailed validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) suite.Require().True(found) suite.Require().True(validator.IsJailed()) + + // signing info equal + oldSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().True(found) + newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(newPk.Address())) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) + suite.Require().Equal(oldSigningInfo.JailedUntil, newSigningInfo.JailedUntil) + + // next block + suite.CommitBeginBlock(valUpdates) + _ = suite.CommitEndBlock() // process end + + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, oldConsAddr) + suite.Require().False(found) } func (suite *KeeperTestSuite) TestEditPubKeyJailedPrevBlock() { @@ -484,13 +493,9 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailedPrevBlockAndUnjail() { suite.Require().NoError(err) _, err = suite.app.StakingKeeper.Undelegate(suite.ctx, sdk.AccAddress(valAddr), valAddr, validator.GetDelegatorShares().Sub(shares)) suite.Require().NoError(err) + suite.Commit(2) valUpdates := suite.CommitEndBlock() - suite.CommitBeginBlock(valUpdates) - valUpdates = suite.CommitEndBlock() - suite.CommitBeginBlock(valUpdates) - valUpdates = suite.CommitEndBlock() - // check validator jailed validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) suite.Require().True(found) @@ -505,21 +510,32 @@ func (suite *KeeperTestSuite) TestEditPubKeyJailedPrevBlockAndUnjail() { suite.Require().NoError(err) err = suite.app.SlashingKeeper.Unjail(suite.ctx, valAddr) suite.Require().NoError(err) - valUpdates = suite.CommitEndBlock() + suite.Commit() + valUpdates = suite.CommitEndBlock() // edit // validator unjailed validator, found = suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr) suite.Require().True(found) suite.Require().False(validator.IsJailed()) - suite.False(suite.CurrentVoteFound(newPk)) - suite.False(suite.NextVoteFound(newPk)) + suite.CommitBeginBlock(valUpdates) + valUpdates = suite.CommitEndBlock() // process start + + // signing info equal + oldSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(newPk.Address())) + suite.Require().True(found) + newSigningInfo, found := suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(newPk.Address())) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset, newSigningInfo.IndexOffset) suite.CommitBeginBlock(valUpdates) - _ = suite.CommitEndBlock() + _ = suite.CommitEndBlock() // process end - suite.False(suite.CurrentVoteFound(newPk)) - suite.True(suite.NextVoteFound(newPk)) + _, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(newPk.Address())) + suite.Require().True(found) + newSigningInfo, found = suite.app.SlashingKeeper.GetValidatorSigningInfo(suite.ctx, sdk.ConsAddress(newPk.Address())) + suite.Require().True(found) + suite.Require().Equal(oldSigningInfo.IndexOffset+1, newSigningInfo.IndexOffset) } func (suite *KeeperTestSuite) TestEditPubKeyUnboundValidator() { From 54ad417275697bebbfca3ce62ef8dd2033e5d512 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Mon, 7 Aug 2023 10:55:28 +0800 Subject: [PATCH 26/30] perf: edit consensus pubkey * consensus params nil --- x/staking/keeper/keeper_test.go | 1 + x/staking/keeper/msg_server.go | 23 ++++++++++++----------- x/staking/module.go | 4 ++-- x/staking/types/keys.go | 6 +++--- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index c717bed56..78a5a88f3 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -140,6 +140,7 @@ func (suite *KeeperTestSuite) CommitBeginBlock(valUpdate []abci.ValidatorUpdate) }, }) suite.ctx = suite.app.NewContext(false, header) + suite.ctx = suite.ctx.WithConsensusParams(helpers.ABCIConsensusParams) pkUpdate := make(map[string]int64, len(valUpdate)) for _, pk := range valUpdate { diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 0d4690176..060e9f30c 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -129,19 +129,20 @@ func (k Keeper) validateAnyPubKey(ctx sdk.Context, pubkey *codectypes.Any) (cryp } // pubkey type supported cp := ctx.ConsensusParams() - if cp != nil && cp.Validator != nil { - pkType := pk.Type() - hasKeyType := false - for _, keyType := range cp.Validator.PubKeyTypes { - if pkType == keyType { - hasKeyType = true - break - } - } - if !hasKeyType { - return nil, stakingtypes.ErrValidatorPubKeyTypeNotSupported.Wrapf("got: %s, expected: %s", pk.Type(), cp.Validator.PubKeyTypes) + if cp == nil || cp.Validator == nil { + return nil, sdkerrors.ErrInvalidRequest.Wrap("invalid consensus params") + } + pkType := pk.Type() + hasKeyType := false + for _, keyType := range cp.Validator.PubKeyTypes { + if pkType == keyType { + hasKeyType = true + break } } + if !hasKeyType { + return nil, stakingtypes.ErrValidatorPubKeyTypeNotSupported.Wrapf("got: %s, expected: %s", pk.Type(), cp.Validator.PubKeyTypes) + } return pk, nil } diff --git a/x/staking/module.go b/x/staking/module.go index acdc8eaa2..ce39afa14 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -62,7 +62,7 @@ func (AppModuleBasic) GetTxCmd() *cobra.Command { type AppModule struct { staking.AppModule AppModuleBasic AppModuleBasic - Keeper *keeper.Keeper + Keeper keeper.Keeper } // NewAppModule creates a new AppModule object @@ -71,7 +71,7 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak stakingtypes.Account return AppModule{ AppModuleBasic: AppModuleBasic{AppModuleBasic: stakingAppModule.AppModuleBasic}, AppModule: stakingAppModule, - Keeper: &keeper, + Keeper: keeper, } } diff --git a/x/staking/types/keys.go b/x/staking/types/keys.go index 34bc43f2f..b963cd71f 100644 --- a/x/staking/types/keys.go +++ b/x/staking/types/keys.go @@ -36,7 +36,7 @@ func GetAllowanceKey(valAddr sdk.ValAddress, owner, spender sdk.AccAddress) []by return key } -func GetValidatorOperatorKey(addr []byte) []byte { +func GetValidatorOperatorKey(addr sdk.ValAddress) []byte { return append(ValidatorOperatorKey, addr...) } @@ -50,10 +50,10 @@ func GetConsensusProcessKey(process CProcess, addr sdk.ValAddress) []byte { func AddressFromConsensusPubKey(key []byte) []byte { kv.AssertKeyAtLeastLength(key, 2) - return key[1:] // remove prefix bytes and address length + return key[1:] // remove prefix bytes } func AddressFromConsensusProcessKey(key []byte) []byte { kv.AssertKeyAtLeastLength(key, 3) - return key[2:] // remove prefix bytes and address length + return key[2:] // remove prefix bytes and process bytes } From 3cba9e2a15b43c92691b322251bf195b61d7ca7a Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Mon, 7 Aug 2023 18:14:20 +0800 Subject: [PATCH 27/30] refactor: ante reject validator address * grant privilege disable val address --- ante/ante_test.go | 1 - ante/decorator.go | 101 ++++++++++++++++++++++++++++ ante/eth.go | 17 +++-- ante/eth_test.go | 2 +- ante/fees.go | 23 +++++++ ante/handler_options.go | 10 +-- ante/reject_msgs.go | 29 -------- ante/reject_msgs_test.go | 95 +++++++++++++++++++------- app/app.go | 1 - app/keepers/keepers.go | 2 +- x/staking/keeper/keeper.go | 30 +++++++-- x/staking/keeper/msg_server.go | 5 ++ x/staking/types/expected_keepers.go | 6 ++ x/staking/types/keys.go | 8 +++ 14 files changed, 254 insertions(+), 76 deletions(-) diff --git a/ante/ante_test.go b/ante/ante_test.go index 8f559adaf..317e92688 100644 --- a/ante/ante_test.go +++ b/ante/ante_test.go @@ -88,7 +88,6 @@ func (suite *AnteTestSuite) SetupTest() { EvmKeeper: suite.app.EvmKeeper, FeeMarketKeeper: suite.app.FeeMarketKeeper, IbcKeeper: suite.app.IBCKeeper, - StakingKeeper: suite.app.StakingKeeper, SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SigGasConsumer: fxante.DefaultSigVerificationGasConsumer, MaxTxGasWanted: 0, diff --git a/ante/decorator.go b/ante/decorator.go index 5afc57f12..4a068675e 100644 --- a/ante/decorator.go +++ b/ante/decorator.go @@ -16,6 +16,8 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" "github.com/evmos/ethermint/crypto/ethsecp256k1" + + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) var ( @@ -222,3 +224,102 @@ func (sgcd SigGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula return next(ctx, tx, simulate) } + +// Verify all signatures for a tx and return an error if any are invalid. Note, +// the SigVerificationDecorator will not check signatures on ReCheck. +// +// CONTRACT: Pubkeys are set in context for all signers before this decorator runs +// CONTRACT: Tx must implement SigVerifiableTx interface +type SigVerificationDecorator struct { + ak AccountKeeper + signModeHandler authsigning.SignModeHandler +} + +func NewSigVerificationDecorator(ak AccountKeeper, signModeHandler authsigning.SignModeHandler) SigVerificationDecorator { + return SigVerificationDecorator{ + ak: ak, + signModeHandler: signModeHandler, + } +} + +//gocyclo:ignore +func (svd SigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { + sigTx, ok := tx.(authsigning.SigVerifiableTx) + if !ok { + return ctx, errorsmod.Wrap(errortypes.ErrTxDecode, "invalid transaction type") + } + + // stdSigs contains the sequence number, account number, and signatures. + // When simulating, this would just be a 0-length slice. + sigs, err := sigTx.GetSignaturesV2() + if err != nil { + return ctx, err + } + + signerAddrs := sigTx.GetSigners() + + // check that signer length and signature length are the same + if len(sigs) != len(signerAddrs) { + return ctx, errorsmod.Wrapf(errortypes.ErrUnauthorized, "invalid number of signer; expected: %d, got %d", len(signerAddrs), len(sigs)) + } + + for i, sig := range sigs { + acc, err := ante.GetSignerAcc(ctx, svd.ak, signerAddrs[i]) + if err != nil { + return ctx, err + } + + // retrieve pubkey + pubKey := acc.GetPubKey() + if !simulate && pubKey == nil { + return ctx, errorsmod.Wrap(errortypes.ErrInvalidPubKey, "pubkey on account is not set") + } + + // check if the account is disabled + if pubKey != nil && bytes.Equal(pubKey.Bytes(), fxstakingtypes.DisablePKBytes[:]) { + return ctx, errorsmod.Wrap(errortypes.ErrInvalidAddress, "account disabled") + } + + // Check account sequence number. + if sig.Sequence != acc.GetSequence() { + return ctx, errorsmod.Wrapf( + errortypes.ErrWrongSequence, + "account sequence mismatch, expected %d, got %d", acc.GetSequence(), sig.Sequence, + ) + } + + // retrieve signer data + genesis := ctx.BlockHeight() == 0 + chainID := ctx.ChainID() + var accNum uint64 + if !genesis { + accNum = acc.GetAccountNumber() + } + signerData := authsigning.SignerData{ + Address: acc.GetAddress().String(), + ChainID: chainID, + AccountNumber: accNum, + Sequence: acc.GetSequence(), + PubKey: pubKey, + } + + // no need to verify signatures on recheck tx + if !simulate && !ctx.IsReCheckTx() { + err := authsigning.VerifySignature(pubKey, signerData, sig.Data, svd.signModeHandler, tx) + if err != nil { + var errMsg string + if ante.OnlyLegacyAminoSigners(sig.Data) { + // If all signers are using SIGN_MODE_LEGACY_AMINO, we rely on VerifySignature to check account sequence number, + // and therefore communicate sequence number as a potential cause of error. + errMsg = fmt.Sprintf("signature verification failed; please verify account number (%d), sequence (%d) and chain-id (%s)", accNum, acc.GetSequence(), chainID) + } else { + errMsg = fmt.Sprintf("signature verification failed; please verify account number (%d) and chain-id (%s)", accNum, chainID) + } + return ctx, errorsmod.Wrap(errortypes.ErrUnauthorized, errMsg) + + } + } + } + + return next(ctx, tx, simulate) +} diff --git a/ante/eth.go b/ante/eth.go index fd97a6b3a..c904d2cbb 100644 --- a/ante/eth.go +++ b/ante/eth.go @@ -12,6 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" + "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" ethermint "github.com/evmos/ethermint/types" @@ -140,18 +141,24 @@ func (avd EthAccountVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx // EthGasConsumeDecorator validates enough intrinsic gas for the transaction and // gas consumption. type EthGasConsumeDecorator struct { - evmKeeper EVMKeeper - maxGasWanted uint64 + accountKeeper AccountKeeper + bankKeeper types.BankKeeper + evmKeeper EVMKeeper + maxGasWanted uint64 } // NewEthGasConsumeDecorator creates a new EthGasConsumeDecorator func NewEthGasConsumeDecorator( + accountKeeper AccountKeeper, + bankKeeper types.BankKeeper, evmKeeper EVMKeeper, maxGasWanted uint64, ) EthGasConsumeDecorator { return EthGasConsumeDecorator{ - evmKeeper, - maxGasWanted, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + evmKeeper: evmKeeper, + maxGasWanted: maxGasWanted, } } @@ -227,7 +234,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula return ctx, errorsmod.Wrapf(err, "failed to verify the fees") } - err = egcd.evmKeeper.DeductTxCostsFromUserBalance(ctx, fees, common.HexToAddress(msgEthTx.From)) + err = DeductTxCostsFromUserBalance(ctx, egcd.accountKeeper, egcd.bankKeeper, fees, common.HexToAddress(msgEthTx.From)) if err != nil { return ctx, errorsmod.Wrapf(err, "failed to deduct transaction costs from user balance") } diff --git a/ante/eth_test.go b/ante/eth_test.go index fb9e6d715..5d69563c3 100644 --- a/ante/eth_test.go +++ b/ante/eth_test.go @@ -335,7 +335,7 @@ func (suite *AnteTestSuite) TestEthGasConsumeDecorator() { }, } - dec := ante.NewEthGasConsumeDecorator(suite.app.EvmKeeper, config.DefaultMaxTxGasWanted) + dec := ante.NewEthGasConsumeDecorator(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.EvmKeeper, config.DefaultMaxTxGasWanted) for _, tc := range testCases { suite.Run(tc.name, func() { diff --git a/ante/fees.go b/ante/fees.go index 0a2e8241b..8fb311a7b 100644 --- a/ante/fees.go +++ b/ante/fees.go @@ -1,6 +1,7 @@ package ante import ( + "bytes" "fmt" "math" "math/big" @@ -10,9 +11,12 @@ import ( errortypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" evmtypes "github.com/evmos/ethermint/x/evm/types" tmstrings "github.com/tendermint/tendermint/libs/strings" + + fxstakingtypes "github.com/functionx/fx-core/v5/x/staking/types" ) // DeductFeeDecorator deducts fees from the first signer of the tx @@ -276,3 +280,22 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul return next(ctx, tx, simulate) } + +func DeductTxCostsFromUserBalance(ctx sdk.Context, ak AccountKeeper, bk types.BankKeeper, fees sdk.Coins, from common.Address) error { + // fetch sender account + signerAcc, err := ante.GetSignerAcc(ctx, ak, from.Bytes()) + if err != nil { + return errorsmod.Wrapf(err, "account not found for sender %s", from) + } + + // check if the account is disabled + if signerAcc.GetPubKey() != nil && bytes.Equal(signerAcc.GetPubKey().Bytes(), fxstakingtypes.DisablePKBytes[:]) { + return errorsmod.Wrap(errortypes.ErrInvalidAddress, "account disabled") + } + + // deduct the full gas cost from the user balance + if err := ante.DeductFees(bk, ctx, signerAcc, fees); err != nil { + return errorsmod.Wrapf(err, "failed to deduct full gas cost %s from the user %s balance", fees, from) + } + return nil +} diff --git a/ante/handler_options.go b/ante/handler_options.go index 918191db0..66a14c819 100644 --- a/ante/handler_options.go +++ b/ante/handler_options.go @@ -19,7 +19,6 @@ type HandlerOptions struct { FeegrantKeeper FeegrantKeeper EvmKeeper EVMKeeper FeeMarketKeeper FeeMarketKeeper - StakingKeeper StakingKeeper IbcKeeper *ibckeeper.Keeper SignModeHandler authsigning.SignModeHandler SigGasConsumer ante.SignatureVerificationGasConsumer @@ -46,9 +45,6 @@ func (options HandlerOptions) Validate() error { if options.EvmKeeper == nil { return errorsmod.Wrap(errortypes.ErrLogic, "evm keeper is required for AnteHandler") } - if options.StakingKeeper == nil { - return errorsmod.Wrap(errortypes.ErrLogic, "staking keeper is required for AnteHandler") - } return nil } @@ -61,9 +57,8 @@ func newEthAnteHandler(options HandlerOptions) sdk.AnteHandler { NewEthValidateBasicDecorator(options.EvmKeeper), NewEthSigVerificationDecorator(options.EvmKeeper), NewEthAccountVerificationDecorator(options.AccountKeeper, options.EvmKeeper), - NewRejectValidatorGrantedDecorator(options.StakingKeeper), // check if validator is granted, after account verification NewCanTransferDecorator(options.EvmKeeper), - NewEthGasConsumeDecorator(options.EvmKeeper, options.MaxTxGasWanted), + NewEthGasConsumeDecorator(options.AccountKeeper, options.BankKeeper, options.EvmKeeper, options.MaxTxGasWanted), NewEthIncrementSenderSequenceDecorator(options.AccountKeeper), // innermost AnteDecorator. NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper), NewEthEmitEventDecorator(options.EvmKeeper), // emit eth tx hash and index at the very last ante handler. @@ -82,8 +77,7 @@ func newNormalTxAnteHandler(options HandlerOptions) sdk.AnteHandler { NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators ante.NewValidateSigCountDecorator(options.AccountKeeper), NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer), - ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), - NewRejectValidatorGrantedDecorator(options.StakingKeeper), // check if validator is granted, after sig verification + NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler), ante.NewIncrementSequenceDecorator(options.AccountKeeper), ibcante.NewRedundantRelayDecorator(options.IbcKeeper), ) diff --git a/ante/reject_msgs.go b/ante/reject_msgs.go index 75d4b8504..65a6b874d 100644 --- a/ante/reject_msgs.go +++ b/ante/reject_msgs.go @@ -32,32 +32,3 @@ func (r RejectExtensionOptionsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, } return next(ctx, tx, simulate) } - -// RejectValidatorGrantedDecorator is an AnteDecorator that rejects all transactions from validator granted -type RejectValidatorGrantedDecorator struct { - sk StakingKeeper -} - -func NewRejectValidatorGrantedDecorator(sk StakingKeeper) RejectValidatorGrantedDecorator { - return RejectValidatorGrantedDecorator{ - sk: sk, - } -} - -func (r RejectValidatorGrantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { - if ctx.IsReCheckTx() { - return next(ctx, tx, simulate) - } - - msgs := tx.GetMsgs() - for _, msg := range msgs { - signers := msg.GetSigners() - for _, signer := range signers { - if r.sk.HasValidatorOperator(ctx, signer.Bytes()) { - return ctx, errorsmod.Wrap(errortypes.ErrInvalidAddress, "validator granted") - } - } - } - - return next(ctx, tx, simulate) -} diff --git a/ante/reject_msgs_test.go b/ante/reject_msgs_test.go index 0f6ddb504..c24b8cba0 100644 --- a/ante/reject_msgs_test.go +++ b/ante/reject_msgs_test.go @@ -2,60 +2,64 @@ package ante_test import ( "math/big" + "strings" sdkmath "cosmossdk.io/math" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/evmos/ethermint/server/config" "github.com/functionx/fx-core/v5/ante" + "github.com/functionx/fx-core/v5/app" "github.com/functionx/fx-core/v5/testutil/helpers" fxtypes "github.com/functionx/fx-core/v5/types" ) func (suite *AnteTestSuite) TestRejectValidatorGranted() { - val := helpers.NewEthPrivKey() - valAddr := sdk.ValAddress(val.PubKey().Address()) - addr := sdk.AccAddress(valAddr) - - grantAcct := sdk.AccAddress(helpers.GenerateAddress().Bytes()) - suite.app.StakingKeeper.UpdateValidatorOperator(suite.ctx, valAddr, grantAcct) - testCases := []struct { name string - malleate func() sdk.Tx + malleate func(addr sdk.AccAddress, val sdk.ValAddress, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64) sdk.Tx expectPass bool }{ { name: "success", - malleate: func() sdk.Tx { + malleate: func(addr sdk.AccAddress, val sdk.ValAddress, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64) sdk.Tx { testMsg := banktypes.MsgSend{ - FromAddress: grantAcct.String(), + FromAddress: addr.String(), ToAddress: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: fxtypes.DefaultDenom}}, } txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), fxtypes.DefaultDenom, &testMsg) - return txBuilder.GetTx() + tx, err := suite.CreateEmptyTestTx(txBuilder, privs, accNums, accSeqs) + suite.Require().NoError(err) + return tx }, expectPass: true, }, { - name: "fail", - malleate: func() sdk.Tx { + name: "fail - disable address", + malleate: func(addr sdk.AccAddress, valAddr sdk.ValAddress, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64) sdk.Tx { testMsg := banktypes.MsgSend{ FromAddress: addr.String(), ToAddress: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: fxtypes.DefaultDenom}}, } + err := suite.app.StakingKeeper.DisableValidatorAddress(suite.ctx, valAddr) + suite.Require().NoError(err) txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), fxtypes.DefaultDenom, &testMsg) - return txBuilder.GetTx() + tx, err := suite.CreateEmptyTestTx(txBuilder, privs, accNums, accSeqs) + suite.Require().NoError(err) + return tx }, expectPass: false, }, { name: "fail with multiple msgs", - malleate: func() sdk.Tx { + malleate: func(addr sdk.AccAddress, valAddr sdk.ValAddress, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64) sdk.Tx { msg1 := banktypes.MsgSend{ FromAddress: addr.String(), ToAddress: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), @@ -66,33 +70,72 @@ func (suite *AnteTestSuite) TestRejectValidatorGranted() { ToAddress: sdk.AccAddress(helpers.NewPriKey().PubKey().Address()).String(), Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: fxtypes.DefaultDenom}}, } + err := suite.app.StakingKeeper.DisableValidatorAddress(suite.ctx, valAddr) + suite.Require().NoError(err) + txBuilder := suite.CreateTestCosmosTxBuilder(sdkmath.NewInt(10), fxtypes.DefaultDenom, &msg1, &msg2) - return txBuilder.GetTx() + tx, err := suite.CreateEmptyTestTx(txBuilder, privs, accNums, accSeqs) + suite.Require().NoError(err) + return tx }, expectPass: false, }, { - name: "failed eth tx", - malleate: func() sdk.Tx { + name: "eth - success", + malleate: func(addr sdk.AccAddress, val sdk.ValAddress, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64) sdk.Tx { + from := common.BytesToAddress(addr.Bytes()) + to := helpers.GenerateAddress() + emptyAccessList := ethtypes.AccessList{} + + helpers.AddTestAddr(suite.app, suite.ctx, addr, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1e18)))) + + msg := suite.BuildTestEthTx(from, to, nil, make([]byte, 0), big.NewInt(0), big.NewInt(500000000000), big.NewInt(50), &emptyAccessList) + return suite.CreateTestTx(msg, privs[0], 0, false) + }, + expectPass: true, + }, + { + name: "eth - failed tx", + malleate: func(addr sdk.AccAddress, val sdk.ValAddress, privs []cryptotypes.PrivKey, accNums, accSeqs []uint64) sdk.Tx { from := common.BytesToAddress(addr.Bytes()) to := helpers.GenerateAddress() emptyAccessList := ethtypes.AccessList{} - msg := suite.BuildTestEthTx(from, to, nil, make([]byte, 0), big.NewInt(0), big.NewInt(100), big.NewInt(50), &emptyAccessList) - return suite.CreateTestTx(msg, val, 1, false) + + err := suite.app.StakingKeeper.DisableValidatorAddress(suite.ctx, sdk.ValAddress(addr)) + suite.Require().NoError(err) + + msg := suite.BuildTestEthTx(from, to, nil, make([]byte, 0), big.NewInt(0), big.NewInt(500000000000), big.NewInt(50), &emptyAccessList) + return suite.CreateTestTx(msg, privs[0], 0, false) }, expectPass: false, }, } - dec := ante.NewRejectValidatorGrantedDecorator(suite.app.StakingKeeper) - for _, testCase := range testCases { - suite.Run(testCase.name, func() { - tx := testCase.malleate() - _, err := dec.AnteHandle(suite.ctx, tx, false, NextFn) - if testCase.expectPass { + ethSigDec := ante.NewEthSigVerificationDecorator(suite.app.EvmKeeper) + dec := ante.NewSigVerificationDecorator(suite.app.AccountKeeper, app.MakeEncodingConfig().TxConfig.SignModeHandler()) + ethDec := ante.NewEthGasConsumeDecorator(suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.EvmKeeper, config.DefaultMaxTxGasWanted) + var err error + for _, tc := range testCases { + val := helpers.NewEthPrivKey() + valAddr := sdk.ValAddress(val.PubKey().Address()) + addr := sdk.AccAddress(valAddr) + account := authtypes.NewBaseAccount(addr, val.PubKey(), 0, 0) + suite.app.AccountKeeper.SetAccount(suite.ctx, account) + privs, accNums, accSeqs := []cryptotypes.PrivKey{val}, []uint64{0}, []uint64{0} + + suite.Run(tc.name, func() { + tx := tc.malleate(addr, valAddr, privs, accNums, accSeqs) + if strings.HasPrefix(tc.name, "eth") { + handler := sdk.ChainAnteDecorators(ethSigDec, ethDec) + _, err = handler(suite.ctx, tx, false) + } else { + _, err = dec.AnteHandle(suite.ctx, tx, false, NextFn) + } + if tc.expectPass { suite.Require().NoError(err) } else { suite.Require().Error(err) + suite.ErrorContains(err, "account disabled: invalid address") } }) } diff --git a/app/app.go b/app/app.go index 6e551b9a4..58f26fbd0 100644 --- a/app/app.go +++ b/app/app.go @@ -155,7 +155,6 @@ func New( EvmKeeper: myApp.EvmKeeper, FeeMarketKeeper: myApp.FeeMarketKeeper, IbcKeeper: myApp.IBCKeeper, - StakingKeeper: myApp.StakingKeeper, SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SigGasConsumer: fxante.DefaultSigVerificationGasConsumer, MaxTxGasWanted: maxGasWanted, diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 482408790..768e43332 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -204,7 +204,7 @@ func NewAppKeeper( appKeepers.AccountKeeper, appKeepers.BankKeeper, appKeepers.GetSubspace(stakingtypes.ModuleName), - ), appKeepers.keys[stakingtypes.StoreKey], appCodec) + ), appKeepers.keys[stakingtypes.StoreKey], appCodec, appKeepers.AccountKeeper) appKeepers.MintKeeper = mintkeeper.NewKeeper( appCodec, diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 24e050807..e5f1e8afa 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -4,6 +4,7 @@ import ( "time" "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,6 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/evmos/ethermint/crypto/ethsecp256k1" "github.com/functionx/fx-core/v5/x/staking/types" ) @@ -20,16 +22,18 @@ type Keeper struct { storeKey storetypes.StoreKey cdc codec.Codec + accountKeeper types.AccountKeeper authzKeeper types.AuthzKeeper slashingKeeper types.SlashingKeeper } // NewKeeper creates a new staking Keeper instance -func NewKeeper(k stakingkeeper.Keeper, storeKey storetypes.StoreKey, cdc codec.Codec) Keeper { +func NewKeeper(k stakingkeeper.Keeper, storeKey storetypes.StoreKey, cdc codec.Codec, ak types.AccountKeeper) Keeper { return Keeper{ - Keeper: k, - storeKey: storeKey, - cdc: cdc, + Keeper: k, + storeKey: storeKey, + cdc: cdc, + accountKeeper: ak, } } @@ -99,6 +103,24 @@ func (k Keeper) UpdateValidatorOperator(ctx sdk.Context, val sdk.ValAddress, fro store.Set(types.GetValidatorOperatorKey(val), from.Bytes()) } +func (k Keeper) DisableValidatorAddress(ctx sdk.Context, val sdk.ValAddress) error { + account := k.accountKeeper.GetAccount(ctx, sdk.AccAddress(val)) + if account == nil || account.GetPubKey() == nil { + return sdkerrors.ErrInvalidAddress.Wrap("invalid account") + } + pk := account.GetPubKey() + var disablePK cryptotypes.PubKey + disablePK = ðsecp256k1.PubKey{Key: types.DisablePKBytes[:]} + if pk.Type() == (&secp256k1.PubKey{}).Type() { + disablePK = &secp256k1.PubKey{Key: types.DisablePKBytes[:]} + } + if err := account.SetPubKey(disablePK); err != nil { + return err + } + k.accountKeeper.SetAccount(ctx, account) + return nil +} + // ValidatorConsAddr related functions func (k Keeper) SetValidatorConsAddr(ctx sdk.Context, newConsAddr sdk.ConsAddress, valOperator sdk.ValAddress) { diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 060e9f30c..2bc50f426 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -52,6 +52,11 @@ func (k Keeper) GrantPrivilege(goCtx context.Context, msg *types.MsgGrantPrivile // 5. update validator operator k.UpdateValidatorOperator(ctx, valAddr, toAddress) + // 6. disable validator address + if err = k.DisableValidatorAddress(ctx, valAddr); err != nil { + return nil, err + } + ctx.EventManager().EmitEvent(sdk.NewEvent( types.EventTypeGrantPrivilege, sdk.NewAttribute(stakingtypes.AttributeKeyValidator, msg.ValidatorAddress), diff --git a/x/staking/types/expected_keepers.go b/x/staking/types/expected_keepers.go index cf6c4008a..7e99b8c49 100644 --- a/x/staking/types/expected_keepers.go +++ b/x/staking/types/expected_keepers.go @@ -5,6 +5,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/authz" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" ) @@ -23,3 +24,8 @@ type SlashingKeeper interface { SetValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) DeleteValidatorSigningInfo(ctx sdk.Context, consAddr sdk.ConsAddress) } + +type AccountKeeper interface { + GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI + SetAccount(ctx sdk.Context, acc authtypes.AccountI) +} diff --git a/x/staking/types/keys.go b/x/staking/types/keys.go index b963cd71f..56c1e20fc 100644 --- a/x/staking/types/keys.go +++ b/x/staking/types/keys.go @@ -14,6 +14,14 @@ var ( ProcessEnd CProcess = []byte{0x2} ) +var DisablePKBytes = [33]byte{ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, +} + var ( AllowanceKey = []byte{0x90} ValidatorOperatorKey = []byte{0x91} From c3300d2c82fb1a58112e47d9ecf909ef6c455989 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Tue, 8 Aug 2023 11:25:41 +0800 Subject: [PATCH 28/30] chore: upgrade testnet v5 height * testnet v5 9773000 * remove todo --- app/upgrades/v5/constants.go | 1 - app/upgrades/v5/repair.go | 4 ++-- app/upgrades/v5/upgrade.go | 1 - cmd/doctor.go | 2 ++ tests/upgrade_time_calc_test.go | 1 + types/version.go | 14 +++++++------- x/migrate/keeper/msg_server.go | 2 -- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/app/upgrades/v5/constants.go b/app/upgrades/v5/constants.go index 24ddd3a47..8f0f52116 100644 --- a/app/upgrades/v5/constants.go +++ b/app/upgrades/v5/constants.go @@ -14,7 +14,6 @@ type SlashPeriod struct { } // ValidatorSlashHeightTestnetFXV4 is a map of testnet validator address to slash height -// todo check before testnet v5 release var ValidatorSlashHeightTestnetFXV4 = map[string][]int64{ "fxvaloper14lpap6mwytqtnrx6q9cnje2sen5a5wcctuwnsh": {8224664, 8457967, 8552303}, "fxvaloper1695tvr34jdrmajtc0t6kzumaxxwhulfl7h6mq2": {9469704}, diff --git a/app/upgrades/v5/repair.go b/app/upgrades/v5/repair.go index 6c4615b72..a7e62a7d0 100644 --- a/app/upgrades/v5/repair.go +++ b/app/upgrades/v5/repair.go @@ -60,13 +60,13 @@ func fixSlashPeriodTestnetFXV4(ctx sdk.Context, dk distrkeeper.Keeper, val sdk.V referenceCount += 1 } logger.Info("add slash period", "validator", val, "height", p.Height, "period", p.Period, "referenceCount", referenceCount) - lastHistoricalRewards := periodHistoricalRewards[periods[idx-1].Period] // todo + lastHistoricalRewards := periodHistoricalRewards[periods[idx-1].Period] historicalRewards := distrtypes.NewValidatorHistoricalRewards(lastHistoricalRewards.CumulativeRewardRatio, referenceCount) dk.SetValidatorHistoricalRewards(ctx, val, p.Period, historicalRewards) periodHistoricalRewards[p.Period] = historicalRewards // add slash period - fraction, _ := sdk.NewDecFromStr("0.001") // todo + fraction, _ := sdk.NewDecFromStr("0.001") slashEvent := distrtypes.NewValidatorSlashEvent(p.Period, fraction) dk.SetValidatorSlashEvent(ctx, val, p.Height, p.Period, slashEvent) slashBefore = true diff --git a/app/upgrades/v5/upgrade.go b/app/upgrades/v5/upgrade.go index bf09fa901..82914cc36 100644 --- a/app/upgrades/v5/upgrade.go +++ b/app/upgrades/v5/upgrade.go @@ -19,7 +19,6 @@ func CreateUpgradeHandler( if ctx.ChainID() == fxtypes.TestnetChainId { RepairSlashPeriod(ctx, app.StakingKeeper, app.DistrKeeper) - // todo repair register coin amount } ctx.Logger().Info("start to run v5 migrations...", "module", "upgrade") diff --git a/cmd/doctor.go b/cmd/doctor.go index 257aa338e..e9520abf1 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -300,6 +300,8 @@ func checkBlockchainData(bc blockchain, genesisId, privValidatorKeyFile string) fmt.Printf("%sVersion: V4\n", SPACE) } else if blockHeight < fxtypes.TestnetBlockHeightV42 { fmt.Printf("%sVersion: V4.1\n", SPACE) + } else if blockHeight < fxtypes.TestnetBlockHeightV5 { + fmt.Printf("%sVersion: V4.2\n", SPACE) } } return plan != nil, nil diff --git a/tests/upgrade_time_calc_test.go b/tests/upgrade_time_calc_test.go index 051c86803..334918830 100644 --- a/tests/upgrade_time_calc_test.go +++ b/tests/upgrade_time_calc_test.go @@ -19,6 +19,7 @@ func TestCalculateUpgradeHeight(t *testing.T) { helpers.SkipTest(t) blockInterval := 20000 + // example: UPGRADE_TIME=2023-08-10T08:00:00Z upgradeTime := os.Getenv("UPGRADE_TIME") if len(upgradeTime) <= 0 { upgradeTime = time.Now().AddDate(0, 0, 14).Format(time.RFC3339) diff --git a/types/version.go b/types/version.go index f8cd2eed0..122272609 100644 --- a/types/version.go +++ b/types/version.go @@ -21,15 +21,15 @@ const ( // testnet const ( - TestnetChainId = "dhobyghaut" - testnetEvmChainID = 90001 - TestnetGenesisHash = "06D0A9659E1EC5B0E57E8E2E5F1B1266094808BC9B4081E1A55011FEF4586ACE" - TestnetBlockHeightV2 = 3418880 - TestnetBlockHeightV3 = 6578000 - TestnetBlockHeightV4 = 8088000 - + TestnetChainId = "dhobyghaut" + testnetEvmChainID = 90001 + TestnetGenesisHash = "06D0A9659E1EC5B0E57E8E2E5F1B1266094808BC9B4081E1A55011FEF4586ACE" + TestnetBlockHeightV2 = 3418880 + TestnetBlockHeightV3 = 6578000 + TestnetBlockHeightV4 = 8088000 TestnetBlockHeightV41 = 8376000 TestnetBlockHeightV42 = 8481000 + TestnetBlockHeightV5 = 9773000 ) var ( diff --git a/x/migrate/keeper/msg_server.go b/x/migrate/keeper/msg_server.go index 1098c114b..0ed9b1d78 100644 --- a/x/migrate/keeper/msg_server.go +++ b/x/migrate/keeper/msg_server.go @@ -14,8 +14,6 @@ import ( var _ types.MsgServer = &Keeper{} -// todo lptoken with migrate? - func (k Keeper) MigrateAccount(goCtx context.Context, msg *types.MsgMigrateAccount) (*types.MsgMigrateAccountResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) From 77048b465b70eed7cf57ad40fc022c1f3cc7eeff Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Tue, 8 Aug 2023 14:09:39 +0800 Subject: [PATCH 29/30] docs: Changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45ec96f45..6104db59e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,17 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Change log +## [v5.0.0-rc0] + +### Features + +* Transfer validator permissions +* Edit consensus public key + +### Bug Fixes + +* Repair testnet slash period + ## [v4.2.1] ### Bug Fixes From 7f8203b6fb56a80718f4b3af2cc4e91aa8a9b117 Mon Sep 17 00:00:00 2001 From: devon <80245700+devon-chain@users.noreply.github.com> Date: Fri, 11 Aug 2023 15:18:13 +0800 Subject: [PATCH 30/30] chore: mainnet v5.0.0 upgrade * height 11601700 --- cmd/doctor.go | 2 ++ server/start.go | 7 +++++-- types/version.go | 13 +++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/doctor.go b/cmd/doctor.go index e9520abf1..82e897249 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -287,6 +287,8 @@ func checkBlockchainData(bc blockchain, genesisId, privValidatorKeyFile string) fmt.Printf("%sVersion: V2\n", SPACE) } else if blockHeight < fxtypes.MainnetBlockHeightV4 { fmt.Printf("%sVersion: v3\n", SPACE) + } else if blockHeight < fxtypes.MainnetBlockHeightV5 { + fmt.Printf("%sVersion: V4\n", SPACE) } } if chainId == fxtypes.TestnetChainId { diff --git a/server/start.go b/server/start.go index 7a287a640..cb61c0b08 100644 --- a/server/start.go +++ b/server/start.go @@ -649,7 +649,7 @@ func checkMainnetAndBlock(genesisDoc *tmtypes.GenesisDoc, config *tmcfg.Config) return nil } if blockStore.Height() < fxtypes.MainnetBlockHeightV2 { - return errors.New("invalid version: The current block height is less than the fxv2 upgrade height(8_756_000), " + + return errors.New("invalid version: The current block height is less than the fxv2 upgrade height(5_713_000), " + "sync block from scratch please use use fxcored v1.x.x") } if blockStore.Height() < fxtypes.MainnetBlockHeightV3 { @@ -660,7 +660,10 @@ func checkMainnetAndBlock(genesisDoc *tmtypes.GenesisDoc, config *tmcfg.Config) return errors.New("invalid version: The current block height is less than the v4.2.0 upgrade height(10_477_500)," + " please use the v3.x.x version to synchronize the block or download the latest snapshot") } - return errors.New("invalid version: The current version is not released, please use the corresponding version") + if blockStore.Height() < fxtypes.MainnetBlockHeightV5 { + return errors.New("invalid version: The current block height is less than the v5.0.0 upgrade height(11_601_700)," + + " please use the v4.x.x version to synchronize the block or download the latest snapshot") + } } return nil } diff --git a/types/version.go b/types/version.go index 122272609..2e997b805 100644 --- a/types/version.go +++ b/types/version.go @@ -17,6 +17,7 @@ const ( MainnetBlockHeightV2 = 5_713_000 MainnetBlockHeightV3 = 8_756_000 MainnetBlockHeightV4 = 10_477_500 + MainnetBlockHeightV5 = 11_601_700 ) // testnet @@ -24,12 +25,12 @@ const ( TestnetChainId = "dhobyghaut" testnetEvmChainID = 90001 TestnetGenesisHash = "06D0A9659E1EC5B0E57E8E2E5F1B1266094808BC9B4081E1A55011FEF4586ACE" - TestnetBlockHeightV2 = 3418880 - TestnetBlockHeightV3 = 6578000 - TestnetBlockHeightV4 = 8088000 - TestnetBlockHeightV41 = 8376000 - TestnetBlockHeightV42 = 8481000 - TestnetBlockHeightV5 = 9773000 + TestnetBlockHeightV2 = 3_418_880 + TestnetBlockHeightV3 = 6_578_000 + TestnetBlockHeightV4 = 8_088_000 + TestnetBlockHeightV41 = 8_376_000 + TestnetBlockHeightV42 = 8_481_000 + TestnetBlockHeightV5 = 9_773_000 ) var (