mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
Compare commits
129 Commits
14401bd2fb
...
1d2504b085
Author | SHA1 | Date | |
---|---|---|---|
|
1d2504b085 | ||
|
30728b75e9 | ||
|
e822edfe8d | ||
|
d2406d4efd | ||
|
e8e2e3abd3 | ||
|
2da75122b3 | ||
|
ed5646b71a | ||
|
4aa67c9efb | ||
|
bd3d947e9b | ||
|
a8c86f7f8b | ||
|
058d9f2285 | ||
|
3709a23632 | ||
|
04dfd2a2e9 | ||
|
932664efac | ||
|
c949c06fce | ||
|
14ca626365 | ||
|
008b421fd2 | ||
|
ac1fd4360d | ||
|
d35b277cab | ||
|
2c248aff18 | ||
|
4ab0d3ee27 | ||
|
8d761147a2 | ||
|
4917eb5976 | ||
|
f8d5f29078 | ||
|
efee71e2e6 | ||
|
6190839ddc | ||
|
c1efdaa507 | ||
|
62c5eaf515 | ||
|
48c349c127 | ||
|
4b09c6cd37 | ||
|
02e96e6424 | ||
|
b3a8343a19 | ||
|
c6e4563cac | ||
|
7d4828f415 | ||
|
1fbf607360 | ||
|
154dd509ee | ||
|
986172d3a7 | ||
|
4fabd4d011 | ||
|
e25cc5f531 | ||
|
6202424c27 | ||
|
c7ed82b4f4 | ||
|
a3f3aaaecc | ||
|
701a0ba97e | ||
|
1e0194262d | ||
|
e3e47e5e2f | ||
|
93cceff23c | ||
|
1680cd6b32 | ||
|
284181edc9 | ||
|
422e940c28 | ||
|
bb5d5130cf | ||
|
b53783447b | ||
|
6f2b402294 | ||
|
82139161be | ||
|
4798eea3ff | ||
|
ee01ac7a7b | ||
|
47cee39c64 | ||
|
521f558f5d | ||
|
adb09a7c82 | ||
|
3da66a87e6 | ||
|
19a202669a | ||
|
eaf81e9465 | ||
|
817a8a151a | ||
|
78114aed73 | ||
|
34a76200f0 | ||
|
fe8c36f891 | ||
|
8357cc2191 | ||
|
f8e102fbd5 | ||
|
d1c3f36bbe | ||
|
89d3829646 | ||
|
ffad9dbdd5 | ||
|
0bbaeb0393 | ||
|
cc4f72b165 | ||
|
6a197a5db5 | ||
|
e787cd052e | ||
|
2454c94596 | ||
|
454733f55b | ||
|
14e1e3a7d4 | ||
|
ca3ab93657 | ||
|
c8bf4644c1 | ||
|
667e532aaa | ||
|
32a0193c45 | ||
|
be5bf62ab8 | ||
|
7ca43024e4 | ||
|
c9d900be2c | ||
|
8f93ca2048 | ||
|
e34c94aa62 | ||
|
a548de05c2 | ||
|
7f73061c13 | ||
|
da8a4f8787 | ||
|
e96fd1735d | ||
|
eb9d3a3ed8 | ||
|
a681a5e631 | ||
|
6b41ed84b8 | ||
|
17691e95a8 | ||
|
cf2d83b020 | ||
|
5c0f27b952 | ||
|
322f2ac056 | ||
|
9bfd1ffd7d | ||
|
f5384a1f11 | ||
|
2a1e9a6631 | ||
|
069be95dde | ||
|
1d944d5219 | ||
|
11d3ba3466 | ||
|
2bc0c62570 | ||
|
58d04e2996 | ||
|
ad387e6a42 | ||
|
550ecc8027 | ||
|
5914f1db85 | ||
|
ad03a75679 | ||
|
c0df29333b | ||
|
45aa631f18 | ||
|
614d4e40fe | ||
|
7efee6d536 | ||
|
c59a491788 | ||
|
2bccb6deaf | ||
|
7b5de0a12a | ||
|
4d62f47773 | ||
|
3767030005 | ||
|
58621577ae | ||
|
f00727fe85 | ||
|
b170f3bdd5 | ||
|
1aa1348944 | ||
|
ffd306ef52 | ||
|
c63fab1317 | ||
|
f70349ab02 | ||
|
1d4ccf6657 | ||
|
aca738fbc6 | ||
|
39146747ac | ||
|
967c6857e8 |
@ -1,9 +1,15 @@
|
|||||||
out/
|
out/
|
||||||
**/node_modules/
|
**/node_modules/
|
||||||
.git/
|
.git/
|
||||||
docs/
|
.github/
|
||||||
tests/
|
tests/
|
||||||
|
|
||||||
|
ci/
|
||||||
contracts/
|
contracts/
|
||||||
|
contrib/
|
||||||
|
docs/
|
||||||
|
networks/
|
||||||
|
scratch/
|
||||||
|
|
||||||
go.work
|
go.work
|
||||||
go.work.sum
|
go.work.sum
|
||||||
|
20
.github/mergify.yml
vendored
20
.github/mergify.yml
vendored
@ -25,6 +25,8 @@ pull_request_rules:
|
|||||||
- release/v0.21.x
|
- release/v0.21.x
|
||||||
- release/v0.23.x
|
- release/v0.23.x
|
||||||
- release/v0.24.x
|
- release/v0.24.x
|
||||||
|
- release/v0.25.x
|
||||||
|
- release/v0.26.x
|
||||||
|
|
||||||
- name: Backport patches to the release/v0.17.x branch
|
- name: Backport patches to the release/v0.17.x branch
|
||||||
conditions:
|
conditions:
|
||||||
@ -79,3 +81,21 @@ pull_request_rules:
|
|||||||
backport:
|
backport:
|
||||||
branches:
|
branches:
|
||||||
- release/v0.24.x
|
- release/v0.24.x
|
||||||
|
|
||||||
|
- name: Backport patches to the release/v0.25.x branch
|
||||||
|
conditions:
|
||||||
|
- base=master
|
||||||
|
- label=A:backport/v0.25.x
|
||||||
|
actions:
|
||||||
|
backport:
|
||||||
|
branches:
|
||||||
|
- release/v0.25.x
|
||||||
|
|
||||||
|
- name: Backport patches to the release/v0.26.x branch
|
||||||
|
conditions:
|
||||||
|
- base=master
|
||||||
|
- label=A:backport/v0.26.x
|
||||||
|
actions:
|
||||||
|
backport:
|
||||||
|
branches:
|
||||||
|
- release/v0.26.x
|
||||||
|
@ -33,7 +33,7 @@ kava config chain-id "${CHAIN_ID}"
|
|||||||
kava config keyring-backend test
|
kava config keyring-backend test
|
||||||
|
|
||||||
# wait for transactions to be committed per CLI command
|
# wait for transactions to be committed per CLI command
|
||||||
kava config broadcast-mode block
|
kava config broadcast-mode sync
|
||||||
|
|
||||||
# setup god's wallet
|
# setup god's wallet
|
||||||
echo "${KAVA_TESTNET_GOD_MNEMONIC}" | kava keys add --recover god
|
echo "${KAVA_TESTNET_GOD_MNEMONIC}" | kava keys add --recover god
|
||||||
@ -80,7 +80,7 @@ printf "original evm util module params\n %s" , "$originalEvmUtilParams"
|
|||||||
# change the params of the chain like a god - make it so 🖖🏽
|
# change the params of the chain like a god - make it so 🖖🏽
|
||||||
# make sure to update god committee member permissions for the module
|
# make sure to update god committee member permissions for the module
|
||||||
# and params being updated (see below for example)
|
# and params being updated (see below for example)
|
||||||
# https://github.com/Kava-Labs/kava/pull/1556/files#diff-0bd6043650c708661f37bbe6fa5b29b52149e0ec0069103c3954168fc9f12612R900-R903
|
# https://github.com/0glabs/0g-chain/pull/1556/files#diff-0bd6043650c708661f37bbe6fa5b29b52149e0ec0069103c3954168fc9f12612R900-R903
|
||||||
kava tx committee submit-proposal 1 "$proposalFileName" --gas 2000000 --gas-prices 0.01ukava --from god -y
|
kava tx committee submit-proposal 1 "$proposalFileName" --gas 2000000 --gas-prices 0.01ukava --from god -y
|
||||||
|
|
||||||
# fetch current module params
|
# fetch current module params
|
||||||
|
4
.github/scripts/install-rocksdb.sh
vendored
4
.github/scripts/install-rocksdb.sh
vendored
@ -7,9 +7,9 @@ sudo apt-get install -y libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev liblz4
|
|||||||
# get rocksdb sources
|
# get rocksdb sources
|
||||||
git clone https://github.com/facebook/rocksdb.git /home/runner/rocksdb
|
git clone https://github.com/facebook/rocksdb.git /home/runner/rocksdb
|
||||||
|
|
||||||
cd /home/runner/rocksdb
|
cd /home/runner/rocksdb || exit 1
|
||||||
|
|
||||||
git checkout "$ROCKSDB_VERSION"
|
git checkout "$ROCKSDB_VERSION"
|
||||||
|
|
||||||
# install rocksdb locally
|
# install rocksdb locally
|
||||||
sudo make -j $(nproc --all) install-shared
|
sudo make -j "$(nproc --all)" install-shared && sudo ldconfig
|
||||||
|
25
.github/scripts/seed-internal-testnet.sh
vendored
25
.github/scripts/seed-internal-testnet.sh
vendored
@ -1,6 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
|
# by sleeping 1 block in between tx's
|
||||||
|
# we can emulate the behavior of the
|
||||||
|
# the deprecated and now removed (as of Kava 16)
|
||||||
|
# broadcast mode of `block` in order to
|
||||||
|
# minimize the chance tx's fail due to an
|
||||||
|
# account sequence number mismatch
|
||||||
|
AVG_SECONDS_BETWEEN_BLOCKS=6.5
|
||||||
|
|
||||||
# configure kava binary to talk to the desired chain endpoint
|
# configure kava binary to talk to the desired chain endpoint
|
||||||
kava config node "${CHAIN_API_URL}"
|
kava config node "${CHAIN_API_URL}"
|
||||||
kava config chain-id "${CHAIN_ID}"
|
kava config chain-id "${CHAIN_ID}"
|
||||||
@ -9,7 +17,7 @@ kava config chain-id "${CHAIN_ID}"
|
|||||||
kava config keyring-backend test
|
kava config keyring-backend test
|
||||||
|
|
||||||
# wait for transactions to be committed per CLI command
|
# wait for transactions to be committed per CLI command
|
||||||
kava config broadcast-mode block
|
kava config broadcast-mode sync
|
||||||
|
|
||||||
# setup dev wallet
|
# setup dev wallet
|
||||||
echo "${DEV_WALLET_MNEMONIC}" | kava keys add --recover dev-wallet
|
echo "${DEV_WALLET_MNEMONIC}" | kava keys add --recover dev-wallet
|
||||||
@ -23,6 +31,8 @@ echo "sweet ocean blush coil mobile ten floor sample nuclear power legend where
|
|||||||
# fund evm-contract-deployer account (using issuance)
|
# fund evm-contract-deployer account (using issuance)
|
||||||
kava tx issuance issue 200000000ukava kava1van3znl6597xgwwh46jgquutnqkwvwszjg04fz --from dev-wallet --gas-prices 0.5ukava -y
|
kava tx issuance issue 200000000ukava kava1van3znl6597xgwwh46jgquutnqkwvwszjg04fz --from dev-wallet --gas-prices 0.5ukava -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# deploy and fund USDC ERC20 contract
|
# deploy and fund USDC ERC20 contract
|
||||||
MULTICHAIN_USDC_CONTRACT_DEPLOY=$(npx hardhat --network "${ERC20_DEPLOYER_NETWORK_NAME}" deploy-erc20 "USD Coin" USDC 6)
|
MULTICHAIN_USDC_CONTRACT_DEPLOY=$(npx hardhat --network "${ERC20_DEPLOYER_NETWORK_NAME}" deploy-erc20 "USD Coin" USDC 6)
|
||||||
MULTICHAIN_USDC_CONTRACT_ADDRESS=${MULTICHAIN_USDC_CONTRACT_DEPLOY: -42}
|
MULTICHAIN_USDC_CONTRACT_ADDRESS=${MULTICHAIN_USDC_CONTRACT_DEPLOY: -42}
|
||||||
@ -96,6 +106,8 @@ npx hardhat --network "${ERC20_DEPLOYER_NETWORK_NAME}" mint-erc20 "$TETHER_USDT_
|
|||||||
kava tx issuance issue 6000000000ukava kava1vlpsrmdyuywvaqrv7rx6xga224sqfwz3fyfhwq \
|
kava tx issuance issue 6000000000ukava kava1vlpsrmdyuywvaqrv7rx6xga224sqfwz3fyfhwq \
|
||||||
--from dev-wallet --gas-prices 0.5ukava -y
|
--from dev-wallet --gas-prices 0.5ukava -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# parse space seperated list of validators
|
# parse space seperated list of validators
|
||||||
# into bash array
|
# into bash array
|
||||||
read -r -a GENESIS_VALIDATOR_ADDRESS_ARRAY <<<"$GENESIS_VALIDATOR_ADDRESSES"
|
read -r -a GENESIS_VALIDATOR_ADDRESS_ARRAY <<<"$GENESIS_VALIDATOR_ADDRESSES"
|
||||||
@ -103,11 +115,14 @@ read -r -a GENESIS_VALIDATOR_ADDRESS_ARRAY <<<"$GENESIS_VALIDATOR_ADDRESSES"
|
|||||||
# delegate 300KAVA to each validator
|
# delegate 300KAVA to each validator
|
||||||
for validator in "${GENESIS_VALIDATOR_ADDRESS_ARRAY[@]}"; do
|
for validator in "${GENESIS_VALIDATOR_ADDRESS_ARRAY[@]}"; do
|
||||||
kava tx staking delegate "${validator}" 300000000ukava --from dev-wallet --gas-prices 0.5ukava -y
|
kava tx staking delegate "${validator}" 300000000ukava --from dev-wallet --gas-prices 0.5ukava -y
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
done
|
done
|
||||||
|
|
||||||
# create a text proposal
|
# create a text proposal
|
||||||
kava tx gov submit-legacy-proposal --deposit 1000000000ukava --type "Text" --title "Example Proposal" --description "This is an example proposal" --gas auto --gas-adjustment 1.2 --from dev-wallet --gas-prices 0.01ukava -y
|
kava tx gov submit-legacy-proposal --deposit 1000000000ukava --type "Text" --title "Example Proposal" --description "This is an example proposal" --gas auto --gas-adjustment 1.2 --from dev-wallet --gas-prices 0.01ukava -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# setup god's wallet
|
# setup god's wallet
|
||||||
echo "${KAVA_TESTNET_GOD_MNEMONIC}" | kava keys add --recover god
|
echo "${KAVA_TESTNET_GOD_MNEMONIC}" | kava keys add --recover god
|
||||||
|
|
||||||
@ -155,13 +170,17 @@ printf "original evm util module params\n %s" , "$originalEvmUtilParams"
|
|||||||
# change the params of the chain like a god - make it so 🖖🏽
|
# change the params of the chain like a god - make it so 🖖🏽
|
||||||
# make sure to update god committee member permissions for the module
|
# make sure to update god committee member permissions for the module
|
||||||
# and params being updated (see below for example)
|
# and params being updated (see below for example)
|
||||||
# https://github.com/Kava-Labs/kava/pull/1556/files#diff-0bd6043650c708661f37bbe6fa5b29b52149e0ec0069103c3954168fc9f12612R900-R903
|
# https://github.com/0glabs/0g-chain/pull/1556/files#diff-0bd6043650c708661f37bbe6fa5b29b52149e0ec0069103c3954168fc9f12612R900-R903
|
||||||
# committee 1 is the stability committee. on internal testnet, this has only one member.
|
# committee 1 is the stability committee. on internal testnet, this has only one member.
|
||||||
kava tx committee submit-proposal 1 "$proposalFileName" --gas 2000000 --gas-prices 0.01ukava --from god -y
|
kava tx committee submit-proposal 1 "$proposalFileName" --gas 2000000 --gas-prices 0.01ukava --from god -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# vote on the proposal. this assumes no other committee proposal has ever been submitted (id=1)
|
# vote on the proposal. this assumes no other committee proposal has ever been submitted (id=1)
|
||||||
kava tx committee vote 1 yes --gas 2000000 --gas-prices 0.01ukava --from god -y
|
kava tx committee vote 1 yes --gas 2000000 --gas-prices 0.01ukava --from god -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# fetch current module params
|
# fetch current module params
|
||||||
updatedEvmUtilParams=$(curl https://api.app.internal.testnet.us-east.production.kava.io/kava/evmutil/v1beta1/params)
|
updatedEvmUtilParams=$(curl https://api.app.internal.testnet.us-east.production.kava.io/kava/evmutil/v1beta1/params)
|
||||||
printf "updated evm util module params\n %s" , "$updatedEvmUtilParams"
|
printf "updated evm util module params\n %s" , "$updatedEvmUtilParams"
|
||||||
@ -172,3 +191,5 @@ kava tx evmutil convert-cosmos-coin-to-erc20 \
|
|||||||
"$DEV_TEST_WALLET_ADDRESS" \
|
"$DEV_TEST_WALLET_ADDRESS" \
|
||||||
1000000hard \
|
1000000hard \
|
||||||
--from dev-wallet --gas 2000000 --gas-prices 0.001ukava -y
|
--from dev-wallet --gas 2000000 --gas-prices 0.001ukava -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
25
.github/scripts/seed-protonet.sh
vendored
25
.github/scripts/seed-protonet.sh
vendored
@ -1,6 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
|
# by sleeping 1 block in between tx's
|
||||||
|
# we can emulate the behavior of the
|
||||||
|
# the deprecated and now removed (as of Kava 16)
|
||||||
|
# broadcast mode of `block` in order to
|
||||||
|
# minimize the chance tx's fail due to an
|
||||||
|
# account sequence number mismatch
|
||||||
|
AVG_SECONDS_BETWEEN_BLOCKS=6.5
|
||||||
|
|
||||||
# configure kava binary to talk to the desired chain endpoint
|
# configure kava binary to talk to the desired chain endpoint
|
||||||
kava config node "${CHAIN_API_URL}"
|
kava config node "${CHAIN_API_URL}"
|
||||||
kava config chain-id "${CHAIN_ID}"
|
kava config chain-id "${CHAIN_ID}"
|
||||||
@ -9,7 +17,7 @@ kava config chain-id "${CHAIN_ID}"
|
|||||||
kava config keyring-backend test
|
kava config keyring-backend test
|
||||||
|
|
||||||
# wait for transactions to be committed per CLI command
|
# wait for transactions to be committed per CLI command
|
||||||
kava config broadcast-mode block
|
kava config broadcast-mode sync
|
||||||
|
|
||||||
# setup dev wallet
|
# setup dev wallet
|
||||||
echo "${DEV_WALLET_MNEMONIC}" | kava keys add --recover dev-wallet
|
echo "${DEV_WALLET_MNEMONIC}" | kava keys add --recover dev-wallet
|
||||||
@ -23,9 +31,13 @@ echo "sweet ocean blush coil mobile ten floor sample nuclear power legend where
|
|||||||
# fund evm-contract-deployer account (using issuance)
|
# fund evm-contract-deployer account (using issuance)
|
||||||
kava tx issuance issue 200000000ukava kava1van3znl6597xgwwh46jgquutnqkwvwszjg04fz --from dev-wallet --gas-prices 0.5ukava -y
|
kava tx issuance issue 200000000ukava kava1van3znl6597xgwwh46jgquutnqkwvwszjg04fz --from dev-wallet --gas-prices 0.5ukava -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# fund 5k kava to x/community account
|
# fund 5k kava to x/community account
|
||||||
kava tx community fund-community-pool 5000000000ukava --from dev-wallet --gas-prices 0.5ukava -y
|
kava tx community fund-community-pool 5000000000ukava --from dev-wallet --gas-prices 0.5ukava -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# deploy and fund USDC ERC20 contract
|
# deploy and fund USDC ERC20 contract
|
||||||
MULTICHAIN_USDC_CONTRACT_DEPLOY=$(npx hardhat --network "${ERC20_DEPLOYER_NETWORK_NAME}" deploy-erc20 "USD Coin" USDC 6)
|
MULTICHAIN_USDC_CONTRACT_DEPLOY=$(npx hardhat --network "${ERC20_DEPLOYER_NETWORK_NAME}" deploy-erc20 "USD Coin" USDC 6)
|
||||||
MULTICHAIN_USDC_CONTRACT_ADDRESS=${MULTICHAIN_USDC_CONTRACT_DEPLOY: -42}
|
MULTICHAIN_USDC_CONTRACT_ADDRESS=${MULTICHAIN_USDC_CONTRACT_DEPLOY: -42}
|
||||||
@ -89,6 +101,8 @@ npx hardhat --network "${ERC20_DEPLOYER_NETWORK_NAME}" mint-erc20 "$AXL_USDC_CON
|
|||||||
kava tx issuance issue 6000000000ukava kava1vlpsrmdyuywvaqrv7rx6xga224sqfwz3fyfhwq \
|
kava tx issuance issue 6000000000ukava kava1vlpsrmdyuywvaqrv7rx6xga224sqfwz3fyfhwq \
|
||||||
--from dev-wallet --gas-prices 0.5ukava -y
|
--from dev-wallet --gas-prices 0.5ukava -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# parse space seperated list of validators
|
# parse space seperated list of validators
|
||||||
# into bash array
|
# into bash array
|
||||||
read -r -a GENESIS_VALIDATOR_ADDRESS_ARRAY <<< "$GENESIS_VALIDATOR_ADDRESSES"
|
read -r -a GENESIS_VALIDATOR_ADDRESS_ARRAY <<< "$GENESIS_VALIDATOR_ADDRESSES"
|
||||||
@ -97,11 +111,14 @@ read -r -a GENESIS_VALIDATOR_ADDRESS_ARRAY <<< "$GENESIS_VALIDATOR_ADDRESSES"
|
|||||||
for validator in "${GENESIS_VALIDATOR_ADDRESS_ARRAY[@]}"
|
for validator in "${GENESIS_VALIDATOR_ADDRESS_ARRAY[@]}"
|
||||||
do
|
do
|
||||||
kava tx staking delegate "${validator}" 300000000ukava --from dev-wallet --gas-prices 0.5ukava -y
|
kava tx staking delegate "${validator}" 300000000ukava --from dev-wallet --gas-prices 0.5ukava -y
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
done
|
done
|
||||||
|
|
||||||
# create a text proposal
|
# create a text proposal
|
||||||
kava tx gov submit-legacy-proposal --deposit 1000000000ukava --type "Text" --title "Example Proposal" --description "This is an example proposal" --gas auto --gas-adjustment 1.2 --from dev-wallet --gas-prices 0.01ukava -y
|
kava tx gov submit-legacy-proposal --deposit 1000000000ukava --type "Text" --title "Example Proposal" --description "This is an example proposal" --gas auto --gas-adjustment 1.2 --from dev-wallet --gas-prices 0.01ukava -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# setup god's wallet
|
# setup god's wallet
|
||||||
echo "${KAVA_TESTNET_GOD_MNEMONIC}" | kava keys add --recover god
|
echo "${KAVA_TESTNET_GOD_MNEMONIC}" | kava keys add --recover god
|
||||||
|
|
||||||
@ -147,12 +164,16 @@ printf "original evm util module params\n %s" , "$originalEvmUtilParams"
|
|||||||
# change the params of the chain like a god - make it so 🖖🏽
|
# change the params of the chain like a god - make it so 🖖🏽
|
||||||
# make sure to update god committee member permissions for the module
|
# make sure to update god committee member permissions for the module
|
||||||
# and params being updated (see below for example)
|
# and params being updated (see below for example)
|
||||||
# https://github.com/Kava-Labs/kava/pull/1556/files#diff-0bd6043650c708661f37bbe6fa5b29b52149e0ec0069103c3954168fc9f12612R900-R903
|
# https://github.com/0glabs/0g-chain/pull/1556/files#diff-0bd6043650c708661f37bbe6fa5b29b52149e0ec0069103c3954168fc9f12612R900-R903
|
||||||
kava tx committee submit-proposal 1 "$proposalFileName" --gas 2000000 --gas-prices 0.01ukava --from god -y
|
kava tx committee submit-proposal 1 "$proposalFileName" --gas 2000000 --gas-prices 0.01ukava --from god -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# vote on the proposal. this assumes no other committee proposal has ever been submitted (id=1)
|
# vote on the proposal. this assumes no other committee proposal has ever been submitted (id=1)
|
||||||
kava tx committee vote 1 yes --gas 2000000 --gas-prices 0.01ukava --from god -y
|
kava tx committee vote 1 yes --gas 2000000 --gas-prices 0.01ukava --from god -y
|
||||||
|
|
||||||
|
sleep $AVG_SECONDS_BETWEEN_BLOCKS
|
||||||
|
|
||||||
# fetch current module params
|
# fetch current module params
|
||||||
updatedEvmUtilParams=$(curl https://api.app.internal.testnet.us-east.production.kava.io/kava/evmutil/v1beta1/params)
|
updatedEvmUtilParams=$(curl https://api.app.internal.testnet.us-east.production.kava.io/kava/evmutil/v1beta1/params)
|
||||||
printf "updated evm util module params\n %s" , "$updatedEvmUtilParams"
|
printf "updated evm util module params\n %s" , "$updatedEvmUtilParams"
|
||||||
|
21
.github/workflows/cd-internal-testnet.yml
vendored
21
.github/workflows/cd-internal-testnet.yml
vendored
@ -1,5 +1,6 @@
|
|||||||
name: Continuous Deployment (Internal Testnet)
|
name: Continuous Deployment (Internal Testnet)
|
||||||
# run after every successful CI job of new commits to the master branch
|
# run after every successful CI job of new commits to the master branch
|
||||||
|
# if deploy version or config has changed
|
||||||
on:
|
on:
|
||||||
workflow_run:
|
workflow_run:
|
||||||
workflows: [Continuous Integration (Kava Master)]
|
workflows: [Continuous Integration (Kava Master)]
|
||||||
@ -7,6 +8,23 @@ on:
|
|||||||
- completed
|
- completed
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
changed_files:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
# define output for first job forwarding output of changedInternalTestnetConfig job
|
||||||
|
outputs:
|
||||||
|
changedInternalTestnetConfig: ${{ steps.changed-internal-testnet-config.outputs.any_changed }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
|
||||||
|
- name: Get all changed internal testnet files
|
||||||
|
id: changed-internal-testnet-config
|
||||||
|
uses: tj-actions/changed-files@v42
|
||||||
|
with:
|
||||||
|
# Avoid using single or double quotes for multiline patterns
|
||||||
|
files: |
|
||||||
|
ci/env/kava-internal-testnet/**
|
||||||
|
|
||||||
# in order:
|
# in order:
|
||||||
# enter standby (prevents autoscaling group from killing node during deploy)
|
# enter standby (prevents autoscaling group from killing node during deploy)
|
||||||
# stop kava
|
# stop kava
|
||||||
@ -14,8 +32,9 @@ jobs:
|
|||||||
# download updated binary and genesis
|
# download updated binary and genesis
|
||||||
# reset application database state (only done on internal testnet)
|
# reset application database state (only done on internal testnet)
|
||||||
reset-chain-to-zero-state:
|
reset-chain-to-zero-state:
|
||||||
|
needs: [changed_files]
|
||||||
# only start cd pipeline if last ci run was successful
|
# only start cd pipeline if last ci run was successful
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
if: ${{ github.event.workflow_run.conclusion == 'success' && needs.changed_files.outputs.changedInternalTestnetConfig == 'true' }}
|
||||||
uses: ./.github/workflows/cd-reset-internal-testnet.yml
|
uses: ./.github/workflows/cd-reset-internal-testnet.yml
|
||||||
with:
|
with:
|
||||||
aws-region: us-east-1
|
aws-region: us-east-1
|
||||||
|
54
.github/workflows/cd-protonet-manual.yml
vendored
Normal file
54
.github/workflows/cd-protonet-manual.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
name: Manual Deployment (Protonet)
|
||||||
|
# allow to be triggered manually
|
||||||
|
on: workflow_dispatch
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# in order:
|
||||||
|
# enter standby (prevents autoscaling group from killing node during deploy)
|
||||||
|
# stop kava
|
||||||
|
# take ebs + zfs snapshots
|
||||||
|
# download updated binary and genesis
|
||||||
|
# reset application database state (only done on internal testnet)
|
||||||
|
reset-chain-to-zero-state:
|
||||||
|
uses: ./.github/workflows/cd-reset-internal-testnet.yml
|
||||||
|
with:
|
||||||
|
aws-region: us-east-1
|
||||||
|
chain-id: proto_2221-17000
|
||||||
|
ssm-document-name: kava-testnet-internal-node-update
|
||||||
|
playbook-name: reset-protonet-playbook.yml
|
||||||
|
playbook-infrastructure-branch: master
|
||||||
|
secrets: inherit
|
||||||
|
|
||||||
|
# start kava with new binary and genesis state on api, peer and seed nodes, place nodes in service once they start and are synched to live
|
||||||
|
start-chain-api:
|
||||||
|
uses: ./.github/workflows/cd-start-chain.yml
|
||||||
|
with:
|
||||||
|
aws-region: us-east-1
|
||||||
|
chain-id: proto_2221-17000
|
||||||
|
ssm-document-name: kava-testnet-internal-node-update
|
||||||
|
playbook-name: start-chain-api-playbook.yml
|
||||||
|
playbook-infrastructure-branch: master
|
||||||
|
secrets: inherit
|
||||||
|
needs: [reset-chain-to-zero-state]
|
||||||
|
|
||||||
|
# setup test and development accounts and balances, deploy contracts by calling the chain's api
|
||||||
|
seed-chain-state:
|
||||||
|
uses: ./.github/workflows/cd-seed-chain.yml
|
||||||
|
with:
|
||||||
|
chain-api-url: https://rpc.app.protonet.us-east.production.kava.io:443
|
||||||
|
chain-id: proto_2221-17000
|
||||||
|
seed-script-filename: seed-protonet.sh
|
||||||
|
erc20-deployer-network-name: protonet
|
||||||
|
genesis_validator_addresses: "kavavaloper14w4avgdvqrlpww6l5dhgj4egfn6ln7gmtp7r2m"
|
||||||
|
kava_version_filepath: ./ci/env/kava-protonet/KAVA.VERSION
|
||||||
|
secrets: inherit
|
||||||
|
needs: [start-chain-api]
|
||||||
|
post-pipeline-metrics:
|
||||||
|
uses: ./.github/workflows/metric-pipeline.yml
|
||||||
|
if: always() # always run so we metric failures and successes
|
||||||
|
with:
|
||||||
|
aws-region: us-east-1
|
||||||
|
metric-name: kava.deploys.testnet.proto
|
||||||
|
namespace: Kava/ContinuousDeployment
|
||||||
|
secrets: inherit
|
||||||
|
needs: [seed-chain-state]
|
12
.github/workflows/cd-reset-internal-testnet.yml
vendored
12
.github/workflows/cd-reset-internal-testnet.yml
vendored
@ -36,7 +36,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: take the chain offline
|
- name: take the chain offline
|
||||||
run: bash ${GITHUB_WORKSPACE}/.github/scripts/put-all-chain-nodes-on-standby.sh
|
run: bash ${GITHUB_WORKSPACE}/.github/scripts/put-all-chain-nodes-on-standby.sh
|
||||||
env:
|
env:
|
||||||
@ -45,18 +45,16 @@ jobs:
|
|||||||
AWS_ACCESS_KEY_ID: ${{ secrets.CI_AWS_KEY_ID }}
|
AWS_ACCESS_KEY_ID: ${{ secrets.CI_AWS_KEY_ID }}
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_AWS_KEY_SECRET }}
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_AWS_KEY_SECRET }}
|
||||||
- name: checkout infrastructure repo
|
- name: checkout infrastructure repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: Kava-Labs/infrastructure
|
repository: Kava-Labs/infrastructure
|
||||||
token: ${{ secrets.KAVA_PRIVATE_GITHUB_ACCESS_TOKEN }}
|
token: ${{ secrets.KAVA_PRIVATE_GITHUB_ACCESS_TOKEN }}
|
||||||
path: infrastructure
|
path: infrastructure
|
||||||
ref: master
|
ref: master
|
||||||
- name: set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- name: build kava node updater
|
- name: build kava node updater
|
||||||
run: cd infrastructure/cli/kava-node-updater && make install && cd ../../../
|
run: cd infrastructure/cli/kava-node-updater && make install && cd ../../../
|
||||||
- name: run reset playbook on all chain nodes
|
- name: run reset playbook on all chain nodes
|
||||||
|
22
.github/workflows/cd-seed-chain.yml
vendored
22
.github/workflows/cd-seed-chain.yml
vendored
@ -32,25 +32,23 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from master
|
- name: checkout repo from master
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: master
|
ref: master
|
||||||
- name: checkout version of kava used by network
|
- name: checkout version of kava used by network
|
||||||
run: |
|
run: |
|
||||||
git pull -p
|
git pull -p
|
||||||
git checkout $(cat ${KAVA_VERSION_FILEPATH})
|
git checkout $(cat ${KAVA_VERSION_FILEPATH})
|
||||||
env:
|
env:
|
||||||
KAVA_VERSION_FILEPATH: ${{ inputs.kava_version_filepath }}
|
KAVA_VERSION_FILEPATH: ${{ inputs.kava_version_filepath }}
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- name: build kava binary
|
- name: build kava binary
|
||||||
run: make install
|
run: make install
|
||||||
- name: checkout go evm tools repo
|
- name: checkout go evm tools repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: ethereum/go-ethereum
|
repository: ethereum/go-ethereum
|
||||||
path: go-ethereum
|
path: go-ethereum
|
||||||
@ -61,7 +59,7 @@ jobs:
|
|||||||
make devtools
|
make devtools
|
||||||
working-directory: go-ethereum
|
working-directory: go-ethereum
|
||||||
- name: checkout kava bridge repo for deploying evm contracts
|
- name: checkout kava bridge repo for deploying evm contracts
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: Kava-Labs/kava-bridge
|
repository: Kava-Labs/kava-bridge
|
||||||
path: kava-bridge
|
path: kava-bridge
|
||||||
@ -78,11 +76,11 @@ jobs:
|
|||||||
- name: compile default erc20 contracts
|
- name: compile default erc20 contracts
|
||||||
run: make compile-contracts
|
run: make compile-contracts
|
||||||
working-directory: kava-bridge
|
working-directory: kava-bridge
|
||||||
- name: download seed script from master
|
- name: download seed script from current commit
|
||||||
run: wget https://raw.githubusercontent.com/Kava-Labs/kava/master/.github/scripts/${SEED_SCRIPT_FILENAME} && chmod +x ${SEED_SCRIPT_FILENAME}
|
run: wget https://raw.githubusercontent.com/Kava-Labs/kava/${GITHUB_SHA}/.github/scripts/${SEED_SCRIPT_FILENAME} && chmod +x ${SEED_SCRIPT_FILENAME}
|
||||||
working-directory: kava-bridge/contract
|
working-directory: kava-bridge/contract
|
||||||
env:
|
env:
|
||||||
SEED_SCRIPT_FILENAME: ${{ inputs.seed-script-filename }}
|
SEED_SCRIPT_FILENAME: ${{ inputs.seed-script-filename }}
|
||||||
- name: run seed scripts
|
- name: run seed scripts
|
||||||
run: bash ./${SEED_SCRIPT_FILENAME}
|
run: bash ./${SEED_SCRIPT_FILENAME}
|
||||||
working-directory: kava-bridge/contract
|
working-directory: kava-bridge/contract
|
||||||
|
12
.github/workflows/cd-start-chain.yml
vendored
12
.github/workflows/cd-start-chain.yml
vendored
@ -32,7 +32,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: take the chain offline
|
- name: take the chain offline
|
||||||
run: bash ${GITHUB_WORKSPACE}/.github/scripts/put-all-chain-nodes-on-standby.sh
|
run: bash ${GITHUB_WORKSPACE}/.github/scripts/put-all-chain-nodes-on-standby.sh
|
||||||
env:
|
env:
|
||||||
@ -41,18 +41,16 @@ jobs:
|
|||||||
AWS_ACCESS_KEY_ID: ${{ secrets.CI_AWS_KEY_ID }}
|
AWS_ACCESS_KEY_ID: ${{ secrets.CI_AWS_KEY_ID }}
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_AWS_KEY_SECRET }}
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.CI_AWS_KEY_SECRET }}
|
||||||
- name: checkout infrastructure repo
|
- name: checkout infrastructure repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
repository: Kava-Labs/infrastructure
|
repository: Kava-Labs/infrastructure
|
||||||
token: ${{ secrets.KAVA_PRIVATE_GITHUB_ACCESS_TOKEN }}
|
token: ${{ secrets.KAVA_PRIVATE_GITHUB_ACCESS_TOKEN }}
|
||||||
path: infrastructure
|
path: infrastructure
|
||||||
ref: master
|
ref: master
|
||||||
- name: set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- name: build kava node updater
|
- name: build kava node updater
|
||||||
run: cd infrastructure/cli/kava-node-updater && make install && cd ../../../
|
run: cd infrastructure/cli/kava-node-updater && make install && cd ../../../
|
||||||
- name: run start-chain playbook on all chain nodes
|
- name: run start-chain playbook on all chain nodes
|
||||||
|
42
.github/workflows/ci-default.yml
vendored
42
.github/workflows/ci-default.yml
vendored
@ -7,28 +7,30 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
cache-dependency-path: |
|
||||||
cache: true
|
go.sum
|
||||||
|
tests/e2e/kvtool/go.sum
|
||||||
- name: build application
|
- name: build application
|
||||||
run: make build
|
run: make build
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
cache-dependency-path: |
|
||||||
cache: true
|
go.sum
|
||||||
|
tests/e2e/kvtool/go.sum
|
||||||
- name: run unit tests
|
- name: run unit tests
|
||||||
run: make test
|
run: make test
|
||||||
- name: run e2e tests
|
- name: run e2e tests
|
||||||
@ -37,13 +39,13 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: save version of kava that will be deployed if this pr is merged
|
- name: save version of kava that will be deployed if this pr is merged
|
||||||
id: kava-version
|
id: kava-version
|
||||||
run: |
|
run: |
|
||||||
echo "KAVA_VERSION=$(cat ./ci/env/kava-internal-testnet/KAVA.VERSION)" >> $GITHUB_OUTPUT
|
echo "KAVA_VERSION=$(cat ./ci/env/kava-internal-testnet/KAVA.VERSION)" >> $GITHUB_OUTPUT
|
||||||
- name: checkout repo from master
|
- name: checkout repo from master
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: master
|
ref: master
|
||||||
- name: checkout version of kava that will be deployed if this pr is merged
|
- name: checkout version of kava that will be deployed if this pr is merged
|
||||||
@ -53,28 +55,24 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
KAVA_VERSION: ${{ steps.kava-version.outputs.KAVA_VERSION }}
|
KAVA_VERSION: ${{ steps.kava-version.outputs.KAVA_VERSION }}
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- name: build kava cli
|
- name: build kava cli
|
||||||
run: make install
|
run: make install
|
||||||
- name: checkout repo from current commit to validate current branch's genesis
|
- name: checkout repo from current commit to validate current branch's genesis
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: validate testnet genesis
|
- name: validate testnet genesis
|
||||||
run: kava validate-genesis ci/env/kava-internal-testnet/genesis.json
|
run: kava validate-genesis ci/env/kava-internal-testnet/genesis.json
|
||||||
validate-protonet-genesis:
|
validate-protonet-genesis:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- name: build kava cli
|
- name: build kava cli
|
||||||
run: make install
|
run: make install
|
||||||
- name: validate protonet genesis
|
- name: validate protonet genesis
|
||||||
|
71
.github/workflows/ci-docker.yml
vendored
71
.github/workflows/ci-docker.yml
vendored
@ -6,6 +6,14 @@ on:
|
|||||||
dockerhub-username:
|
dockerhub-username:
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
|
# this workflow publishes a rocksdb & goleveldb docker images with these tags:
|
||||||
|
# - <commit-hash>-goleveldb
|
||||||
|
# - <extra-image-tag>-goleveldb
|
||||||
|
# - <commit-hash>-rocksdb
|
||||||
|
# - <extra-image-tag>-rocksdb
|
||||||
|
extra-image-tag:
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
secrets:
|
secrets:
|
||||||
CI_DOCKERHUB_TOKEN:
|
CI_DOCKERHUB_TOKEN:
|
||||||
required: true
|
required: true
|
||||||
@ -14,34 +22,81 @@ on:
|
|||||||
# you can use images built by this action in future jobs.
|
# you can use images built by this action in future jobs.
|
||||||
# https://docs.docker.com/build/ci/github-actions/examples/#share-built-image-between-jobs
|
# https://docs.docker.com/build/ci/github-actions/examples/#share-built-image-between-jobs
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
docker-goleveldb:
|
||||||
# https://github.com/marketplace/actions/build-and-push-docker-images
|
# https://github.com/marketplace/actions/build-and-push-docker-images
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# ensure working with latest code
|
# ensure working with latest code
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
# generate a git commit hash to be used as image tag
|
# generate a git commit hash to be used as image tag
|
||||||
- name: Generate short hash
|
- name: Generate short hash
|
||||||
id: commit-hash
|
id: commit-hash
|
||||||
run: echo "short=$( git rev-parse --short $GITHUB_SHA )" >> $GITHUB_OUTPUT
|
run: echo "short=$( git rev-parse --short $GITHUB_SHA )" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
# qemu is used to emulate different platform architectures
|
# qemu is used to emulate different platform architectures
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
# cross-platform build of the image
|
# cross-platform build of the image
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
# authenticate for publish to docker hub
|
# authenticate for publish to docker hub
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v2
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
username: ${{ inputs.dockerhub-username }}
|
username: ${{ inputs.dockerhub-username }}
|
||||||
password: ${{ secrets.CI_DOCKERHUB_TOKEN }}
|
password: ${{ secrets.CI_DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
# publish to docker hub, tag with short git hash
|
# publish to docker hub, tag with short git hash
|
||||||
- name: Build and push
|
- name: Build and push (goleveldb)
|
||||||
uses: docker/build-push-action@v3
|
uses: docker/build-push-action@v5
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
push: true
|
push: true
|
||||||
tags: kava/kava:${{ steps.commit-hash.outputs.short }},kava/kava:master
|
tags: kava/kava:${{ steps.commit-hash.outputs.short }}-goleveldb,kava/kava:${{ inputs.extra-image-tag }}-goleveldb
|
||||||
|
|
||||||
|
docker-rocksdb:
|
||||||
|
# https://github.com/marketplace/actions/build-and-push-docker-images
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
# ensure working with latest code
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# generate a git commit hash to be used as image tag
|
||||||
|
- name: Generate short hash
|
||||||
|
id: commit-hash
|
||||||
|
run: echo "short=$( git rev-parse --short $GITHUB_SHA )" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# qemu is used to emulate different platform architectures
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
# cross-platform build of the image
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
# authenticate for publish to docker hub
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
username: ${{ inputs.dockerhub-username }}
|
||||||
|
password: ${{ secrets.CI_DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
|
# publish to docker hub, tag with short git hash
|
||||||
|
- name: Build and push (rocksdb)
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile-rocksdb
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: true
|
||||||
|
tags: kava/kava:${{ steps.commit-hash.outputs.short }}-rocksdb,kava/kava:${{ inputs.extra-image-tag }}-rocksdb
|
||||||
|
2
.github/workflows/ci-lint.yml
vendored
2
.github/workflows/ci-lint.yml
vendored
@ -8,7 +8,7 @@ jobs:
|
|||||||
golangci-lint:
|
golangci-lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@master
|
- uses: actions/checkout@v4
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: reviewdog/action-golangci-lint@v2
|
uses: reviewdog/action-golangci-lint@v2
|
||||||
with:
|
with:
|
||||||
|
11
.github/workflows/ci-master.yml
vendored
11
.github/workflows/ci-master.yml
vendored
@ -19,19 +19,17 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- name: set build tag
|
- name: set build tag
|
||||||
run: echo "BUILD_TAG=$(date +%s)-$(git rev-parse HEAD | cut -c 1-8)" >> $GITHUB_ENV
|
run: echo "BUILD_TAG=$(date +%s)-$(git rev-parse HEAD | cut -c 1-8)" >> $GITHUB_ENV
|
||||||
- name: build rocksdb dependency
|
- name: build rocksdb dependency
|
||||||
run: bash ${GITHUB_WORKSPACE}/.github/scripts/install-rocksdb.sh
|
run: bash ${GITHUB_WORKSPACE}/.github/scripts/install-rocksdb.sh
|
||||||
env:
|
env:
|
||||||
ROCKSDB_VERSION: v8.1.1
|
ROCKSDB_VERSION: v8.10.0
|
||||||
- name: Build and upload release artifacts
|
- name: Build and upload release artifacts
|
||||||
run: bash ${GITHUB_WORKSPACE}/.github/scripts/publish-internal-release-artifacts.sh
|
run: bash ${GITHUB_WORKSPACE}/.github/scripts/publish-internal-release-artifacts.sh
|
||||||
env:
|
env:
|
||||||
@ -45,6 +43,7 @@ jobs:
|
|||||||
uses: ./.github/workflows/ci-docker.yml
|
uses: ./.github/workflows/ci-docker.yml
|
||||||
with:
|
with:
|
||||||
dockerhub-username: kavaops
|
dockerhub-username: kavaops
|
||||||
|
extra-image-tag: master
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
post-pipeline-metrics:
|
post-pipeline-metrics:
|
||||||
uses: ./.github/workflows/metric-pipeline.yml
|
uses: ./.github/workflows/metric-pipeline.yml
|
||||||
|
35
.github/workflows/ci-release.yml
vendored
Normal file
35
.github/workflows/ci-release.yml
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
name: Continuous Integration (Release)
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v[0-9]+.[0-9]+.[0-9]+*"
|
||||||
|
jobs:
|
||||||
|
# run per commit ci checks against released version
|
||||||
|
lint-checks:
|
||||||
|
uses: ./.github/workflows/ci-lint.yml
|
||||||
|
# run default ci checks against released version
|
||||||
|
default-checks:
|
||||||
|
uses: ./.github/workflows/ci-default.yml
|
||||||
|
|
||||||
|
# get the version tag that triggered this workflow
|
||||||
|
get-version-tag:
|
||||||
|
# prep version release only if all checks pass
|
||||||
|
needs: [lint-checks, default-checks]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
git-tag: ${{ steps.git-tag.outputs.tag }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- id: git-tag
|
||||||
|
run: echo "tag=$(git describe --always --tags --match='v*')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
|
# build and upload versions of kava for use on internal infrastructure
|
||||||
|
# configurations for databases, cpu architectures and operating systems
|
||||||
|
docker:
|
||||||
|
# only run if all checks pass
|
||||||
|
needs: get-version-tag
|
||||||
|
uses: ./.github/workflows/ci-docker.yml
|
||||||
|
with:
|
||||||
|
dockerhub-username: kavaops
|
||||||
|
extra-image-tag: ${{ needs.get-version-tag.outputs.git-tag }}
|
||||||
|
secrets: inherit
|
18
.github/workflows/ci-rocksdb-build.yml
vendored
18
.github/workflows/ci-rocksdb-build.yml
vendored
@ -1,7 +1,7 @@
|
|||||||
name: Continuous Integration (Rocksdb Build)
|
name: Continuous Integration (Rocksdb Build)
|
||||||
|
|
||||||
env:
|
env:
|
||||||
ROCKSDB_VERSION: v8.1.1
|
ROCKSDB_VERSION: v8.10.0
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
@ -10,13 +10,11 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- name: build rocksdb dependency
|
- name: build rocksdb dependency
|
||||||
run: bash ${GITHUB_WORKSPACE}/.github/scripts/install-rocksdb.sh
|
run: bash ${GITHUB_WORKSPACE}/.github/scripts/install-rocksdb.sh
|
||||||
- name: build application
|
- name: build application
|
||||||
@ -34,14 +32,12 @@ jobs:
|
|||||||
&& sudo make -j$(nproc) install-shared
|
&& sudo make -j$(nproc) install-shared
|
||||||
&& sudo ldconfig
|
&& sudo ldconfig
|
||||||
- name: checkout repo from current commit
|
- name: checkout repo from current commit
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version: "1.20"
|
go-version-file: go.mod
|
||||||
check-latest: true
|
|
||||||
cache: true
|
|
||||||
- name: run unit tests
|
- name: run unit tests
|
||||||
run: make test-rocksdb
|
run: make test-rocksdb
|
||||||
|
6
.github/workflows/proto.yml
vendored
6
.github/workflows/proto.yml
vendored
@ -8,11 +8,11 @@ jobs:
|
|||||||
name: "Check Proto"
|
name: "Check Proto"
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-go@v3
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
go-version-file: go.mod
|
||||||
cache: true
|
|
||||||
- run: go mod download
|
- run: go mod download
|
||||||
- run: make install-build-deps
|
- run: make install-build-deps
|
||||||
- run: make check-proto-deps
|
- run: make check-proto-deps
|
||||||
|
25
.github/workflows/upload-release-assets.yml
vendored
Normal file
25
.github/workflows/upload-release-assets.yml
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
name: Upload Release Assets
|
||||||
|
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [created]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v4
|
||||||
|
with:
|
||||||
|
go-version: '1.21'
|
||||||
|
- name: Build
|
||||||
|
run: sudo LINK_STATICALLY=true make build-release
|
||||||
|
- name: Rename file
|
||||||
|
run: sudo mv ./out/linux/0gchaind ./out/linux/0gchaind-linux-${{ github.ref_name }}
|
||||||
|
- name: Upload Release Asset
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: ./out/linux/0gchaind-linux-${{ github.ref_name }}
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.ZG_UPLOAD_ASSET }}
|
5
.gitignore
vendored
5
.gitignore
vendored
@ -41,3 +41,8 @@ build/linux
|
|||||||
# Go workspace files
|
# Go workspace files
|
||||||
go.work
|
go.work
|
||||||
go.work.sum
|
go.work.sum
|
||||||
|
.build/0gchaind
|
||||||
|
.build/da
|
||||||
|
|
||||||
|
# runtime
|
||||||
|
run
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
golang 1.20
|
golang 1.21
|
||||||
nodejs 18.16.0
|
nodejs 18.16.0
|
||||||
|
46
CHANGELOG.md
46
CHANGELOG.md
@ -36,15 +36,33 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [v0.26.0]
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- (cli) [#1785] Add `shard` CLI command to support creating partitions of data for standalone nodes
|
||||||
|
- (cdp) [#1818] Add module param and logic for running x/cdp begin blocker every `n` blocks
|
||||||
|
- (cli) [#1804] Add `rocksdb compact` command for manual DB compaction of state or blockstore
|
||||||
|
- (cosmos-sdk) [#1811] [#1846] Upgrades app to cosmos-sdk v0.47.10 with iavl v1 support
|
||||||
|
- (validator-vesting) [#1832] Add grpc query service to replace removed legacy querier
|
||||||
|
- (incentive) [#1836] Update x/incentive cli to use grpc query client
|
||||||
|
- (ibc) [#1839] Add ibc packet forward middleware for ibc transfers
|
||||||
|
- (evmutil) [#1848] Update evm native conversion logic to handle bep3 assets
|
||||||
|
|
||||||
|
## [v0.25.0]
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- (community) [#1704] Add module params
|
- (community) [#1704] Add module params
|
||||||
- (community) [#1706] Add disable inflation upgrade
|
- (community) [#1706] Add disable inflation upgrade
|
||||||
- (community) [#1745] Enable params update via governance with `MsgUpdateParams`
|
- (community) [#1745] Enable params update via governance with `MsgUpdateParams`
|
||||||
|
- (client) [#1784] Add Kava gRPC client
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
- (ethermint) [#1788] Fixes issue where tracing a transaction could show it's status as successful when isolated in simulation even if the tx when executed on the chain failed due to an error such as exhausting the block gas meter
|
||||||
- (evmutil) [#1655] Initialize x/evmutil module account in InitGenesis
|
- (evmutil) [#1655] Initialize x/evmutil module account in InitGenesis
|
||||||
|
cosmos ledger app 2.34.12
|
||||||
|
|
||||||
## State Machine Breaking
|
## State Machine Breaking
|
||||||
|
|
||||||
@ -56,9 +74,19 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
- (community) [#1755] Keep funds in `x/community` in `CommunityPoolLendWithdrawProposal` handler
|
- (community) [#1755] Keep funds in `x/community` in `CommunityPoolLendWithdrawProposal` handler
|
||||||
- (staking) [#1761] Set validator minimum commission to 5% for all validators under 5%
|
- (staking) [#1761] Set validator minimum commission to 5% for all validators under 5%
|
||||||
|
|
||||||
## [v0.24.1](https://github.com/Kava-Labs/kava/releases/tag/v0.24.1)
|
## [v0.24.3]
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- (deps) [#1770] Bump ledger-cosmos-go to v0.13.1 to resolve signing error with
|
||||||
|
- (rocksdb) [#1767] Fix resolution of rocksdb database path introduced in v0.24.2
|
||||||
|
|
||||||
|
**Note**: There was a bug released as v0.24.2. The tag has been removed and the commit should not be used.
|
||||||
|
|
||||||
|
## [v0.24.1]
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- (metrics) [#1668] Adds non-state breaking x/metrics module for custom telemetry.
|
- (metrics) [#1668] Adds non-state breaking x/metrics module for custom telemetry.
|
||||||
- (metrics) [#1669] Add performance timing metrics to all Begin/EndBlockers
|
- (metrics) [#1669] Add performance timing metrics to all Begin/EndBlockers
|
||||||
- (community) [#1751] Add `AnnualizedRewards` query endpoint
|
- (community) [#1751] Add `AnnualizedRewards` query endpoint
|
||||||
@ -302,6 +330,16 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
|
|||||||
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
|
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
|
||||||
large-scale simulations remotely using aws-batch
|
large-scale simulations remotely using aws-batch
|
||||||
|
|
||||||
|
[#1846]: https://github.com/Kava-Labs/kava/pull/1846
|
||||||
|
[#1848]: https://github.com/Kava-Labs/kava/pull/1848
|
||||||
|
[#1839]: https://github.com/Kava-Labs/kava/pull/1839
|
||||||
|
[#1836]: https://github.com/Kava-Labs/kava/pull/1836
|
||||||
|
[#1832]: https://github.com/Kava-Labs/kava/pull/1832
|
||||||
|
[#1811]: https://github.com/Kava-Labs/kava/pull/1811
|
||||||
|
[#1804]: https://github.com/Kava-Labs/kava/pull/1804
|
||||||
|
[#1785]: https://github.com/Kava-Labs/kava/pull/1785
|
||||||
|
[#1784]: https://github.com/Kava-Labs/kava/pull/1784
|
||||||
|
[#1770]: https://github.com/Kava-Labs/kava/pull/1770
|
||||||
[#1755]: https://github.com/Kava-Labs/kava/pull/1755
|
[#1755]: https://github.com/Kava-Labs/kava/pull/1755
|
||||||
[#1761]: https://github.com/Kava-Labs/kava/pull/1761
|
[#1761]: https://github.com/Kava-Labs/kava/pull/1761
|
||||||
[#1752]: https://github.com/Kava-Labs/kava/pull/1752
|
[#1752]: https://github.com/Kava-Labs/kava/pull/1752
|
||||||
@ -354,10 +392,12 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
|
|||||||
[#750]: https://github.com/Kava-Labs/kava/pull/750
|
[#750]: https://github.com/Kava-Labs/kava/pull/750
|
||||||
[#751]: https://github.com/Kava-Labs/kava/pull/751
|
[#751]: https://github.com/Kava-Labs/kava/pull/751
|
||||||
[#780]: https://github.com/Kava-Labs/kava/pull/780
|
[#780]: https://github.com/Kava-Labs/kava/pull/780
|
||||||
[unreleased]: https://github.com/Kava-Labs/kava/compare/v0.24.0...HEAD
|
[unreleased]: https://github.com/Kava-Labs/kava/compare/v0.25.0...HEAD
|
||||||
|
[v0.25.0]: https://github.com/Kava-Labs/kava/compare/v0.25.0...v0.24.3
|
||||||
|
[v0.24.3]: https://github.com/Kava-Labs/kava/compare/v0.24.3...v0.24.1
|
||||||
|
[v0.24.1]: https://github.com/Kava-Labs/kava/compare/v0.24.1...v0.24.0
|
||||||
[v0.24.0]: https://github.com/Kava-Labs/kava/compare/v0.24.0...v0.23.2
|
[v0.24.0]: https://github.com/Kava-Labs/kava/compare/v0.24.0...v0.23.2
|
||||||
[v0.23.2]: https://github.com/Kava-Labs/kava/compare/v0.23.1...v0.23.2
|
[v0.23.2]: https://github.com/Kava-Labs/kava/compare/v0.23.1...v0.23.2
|
||||||
[v0.23.1]: https://github.com/Kava-Labs/kava/compare/v0.23.0...v0.23.1
|
|
||||||
[v0.23.0]: https://github.com/Kava-Labs/kava/compare/v0.21.1...v0.23.0
|
[v0.23.0]: https://github.com/Kava-Labs/kava/compare/v0.21.1...v0.23.0
|
||||||
[v0.16.1]: https://github.com/Kava-Labs/kava/compare/v0.16.0...v0.16.1
|
[v0.16.1]: https://github.com/Kava-Labs/kava/compare/v0.16.0...v0.16.1
|
||||||
[v0.16.0]: https://github.com/Kava-Labs/kava/compare/v0.15.2...v0.16.0
|
[v0.16.0]: https://github.com/Kava-Labs/kava/compare/v0.15.2...v0.16.0
|
||||||
|
27
Dockerfile
27
Dockerfile
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.20-alpine AS build-env
|
FROM golang:1.21-alpine AS build-env
|
||||||
|
|
||||||
# Set up dependencies
|
# Set up dependencies
|
||||||
# bash, jq, curl for debugging
|
# bash, jq, curl for debugging
|
||||||
@ -7,9 +7,27 @@ FROM golang:1.20-alpine AS build-env
|
|||||||
RUN apk add bash git make libc-dev gcc linux-headers eudev-dev jq curl
|
RUN apk add bash git make libc-dev gcc linux-headers eudev-dev jq curl
|
||||||
|
|
||||||
# Set working directory for the build
|
# Set working directory for the build
|
||||||
WORKDIR /root/kava
|
WORKDIR /root/0g-chain
|
||||||
# default home directory is /root
|
# default home directory is /root
|
||||||
|
|
||||||
|
# Copy dependency files first to facilitate dependency caching
|
||||||
|
COPY ./go.mod ./
|
||||||
|
COPY ./go.sum ./
|
||||||
|
|
||||||
|
# Download dependencies
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
|
go version && go mod download
|
||||||
|
|
||||||
|
# Cosmwasm - Download correct libwasmvm version
|
||||||
|
RUN ARCH=$(uname -m) && WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | sed 's/.* //') && \
|
||||||
|
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$ARCH.a \
|
||||||
|
-O /lib/libwasmvm.$ARCH.a && \
|
||||||
|
# verify checksum
|
||||||
|
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
|
||||||
|
sha256sum /lib/libwasmvm.$ARCH.a | grep $(cat /tmp/checksums.txt | grep libwasmvm_muslc.$ARCH | cut -d ' ' -f 1)
|
||||||
|
|
||||||
|
|
||||||
# Add source files
|
# Add source files
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
@ -18,11 +36,12 @@ COPY . .
|
|||||||
# Mount go build and mod caches as container caches, persisted between builder invocations
|
# Mount go build and mod caches as container caches, persisted between builder invocations
|
||||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
--mount=type=cache,target=/go/pkg/mod \
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
|
LINK_STATICALLY=true \
|
||||||
make install
|
make install
|
||||||
|
|
||||||
FROM alpine:3.15
|
FROM alpine:3.15
|
||||||
|
|
||||||
RUN apk add bash jq curl
|
RUN apk add bash jq curl
|
||||||
COPY --from=build-env /go/bin/kava /bin/kava
|
COPY --from=build-env /go/bin/0gchaind /bin/0gchaind
|
||||||
|
|
||||||
CMD ["kava"]
|
CMD ["0gchaind"]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.20-bullseye AS kava-builder
|
FROM golang:1.20-bullseye AS chain-builder
|
||||||
|
|
||||||
# Set up dependencies
|
# Set up dependencies
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
@ -10,7 +10,7 @@ WORKDIR /root
|
|||||||
# default home directory is /root
|
# default home directory is /root
|
||||||
|
|
||||||
# install rocksdb
|
# install rocksdb
|
||||||
ARG rocksdb_version=v8.1.1
|
ARG rocksdb_version=v8.10.0
|
||||||
ENV ROCKSDB_VERSION=$rocksdb_version
|
ENV ROCKSDB_VERSION=$rocksdb_version
|
||||||
|
|
||||||
RUN git clone https://github.com/facebook/rocksdb.git \
|
RUN git clone https://github.com/facebook/rocksdb.git \
|
||||||
@ -19,16 +19,26 @@ RUN git clone https://github.com/facebook/rocksdb.git \
|
|||||||
&& make -j$(nproc) install-shared \
|
&& make -j$(nproc) install-shared \
|
||||||
&& ldconfig
|
&& ldconfig
|
||||||
|
|
||||||
# Add source files for kava
|
WORKDIR /root/0gchain
|
||||||
COPY . kava
|
# Copy dependency files first to facilitate dependency caching
|
||||||
|
COPY ./go.mod ./
|
||||||
|
COPY ./go.sum ./
|
||||||
|
|
||||||
ARG kava_database_backend=rocksdb
|
# Download dependencies
|
||||||
ENV KAVA_DATABASE_BACKEND=$kava_database_backend
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
|
go version && go mod download
|
||||||
|
|
||||||
|
# Add source files
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ARG 0gchain_database_backend=rocksdb
|
||||||
|
ENV 0GCHAIN_DATABASE_BACKEND=$0gchain_database_backend
|
||||||
|
|
||||||
# Mount go build and mod caches as container caches, persisted between builder invocations
|
# Mount go build and mod caches as container caches, persisted between builder invocations
|
||||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
--mount=type=cache,target=/go/pkg/mod \
|
--mount=type=cache,target=/go/pkg/mod \
|
||||||
cd kava && make install COSMOS_BUILD_OPTIONS=$KAVA_DATABASE_BACKEND
|
make install COSMOS_BUILD_OPTIONS=$0GCHAIN_DATABASE_BACKEND
|
||||||
|
|
||||||
|
|
||||||
FROM ubuntu:22.04
|
FROM ubuntu:22.04
|
||||||
@ -38,10 +48,10 @@ RUN apt-get update \
|
|||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# copy rocksdb shared objects
|
# copy rocksdb shared objects
|
||||||
COPY --from=kava-builder /usr/local/lib/ /usr/local/lib/
|
COPY --from=chain-builder /usr/local/lib/ /usr/local/lib/
|
||||||
RUN ldconfig
|
RUN ldconfig
|
||||||
|
|
||||||
# copy kava binary
|
# copy 0g-chain binary
|
||||||
COPY --from=kava-builder /go/bin/kava /bin/kava
|
COPY --from=chain-builder /go/bin/0gchaind /bin/0gchaind
|
||||||
|
|
||||||
CMD ["kava"]
|
CMD ["0gchaind"]
|
||||||
|
60
Makefile
60
Makefile
@ -1,9 +1,13 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
### Project Info ###
|
### Project Info ###
|
||||||
################################################################################
|
################################################################################
|
||||||
PROJECT_NAME := kava# unique namespace for project
|
PROJECT_NAME := 0g-chain# unique namespace for project
|
||||||
|
BINARY_NAME := 0gchaind
|
||||||
|
MAIN_ENTRY := ./cmd/$(BINARY_NAME)
|
||||||
|
DOCKER_IMAGE_NAME := 0glabs/$(PROJECT_NAME)
|
||||||
GO_BIN ?= go
|
GO_BIN ?= go
|
||||||
|
ARCH := $(shell uname -m)
|
||||||
|
WASMVM_VERSION := $(shell $(GO_BIN) list -m github.com/CosmWasm/wasmvm | sed 's/.* //')
|
||||||
|
|
||||||
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||||
GIT_COMMIT := $(shell git rev-parse HEAD)
|
GIT_COMMIT := $(shell git rev-parse HEAD)
|
||||||
@ -28,7 +32,7 @@ VERSION := $(GIT_COMMIT_SHORT)
|
|||||||
VERSION_NUMBER := $(VERSION)
|
VERSION_NUMBER := $(VERSION)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
TENDERMINT_VERSION := $(shell $(GO_BIN) list -m github.com/tendermint/tendermint | sed 's:.* ::')
|
TENDERMINT_VERSION := $(shell $(GO_BIN) list -m github.com/cometbft/cometbft | sed 's:.* ::')
|
||||||
COSMOS_SDK_VERSION := $(shell $(GO_BIN) list -m github.com/cosmos/cosmos-sdk | sed 's:.* ::')
|
COSMOS_SDK_VERSION := $(shell $(GO_BIN) list -m github.com/cosmos/cosmos-sdk | sed 's:.* ::')
|
||||||
|
|
||||||
.PHONY: print-git-info
|
.PHONY: print-git-info
|
||||||
@ -37,7 +41,7 @@ print-git-info:
|
|||||||
|
|
||||||
.PHONY: print-version
|
.PHONY: print-version
|
||||||
print-version:
|
print-version:
|
||||||
@echo "kava $(VERSION)\ntendermint $(TENDERMINT_VERSION)\ncosmos $(COSMOS_SDK_VERSION)"
|
@echo "$(BINARY_NAME) $(VERSION)\ntendermint $(TENDERMINT_VERSION)\ncosmos $(COSMOS_SDK_VERSION)"
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
### Project Settings ###
|
### Project Settings ###
|
||||||
@ -45,7 +49,7 @@ print-version:
|
|||||||
LEDGER_ENABLED ?= true
|
LEDGER_ENABLED ?= true
|
||||||
DOCKER:=docker
|
DOCKER:=docker
|
||||||
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
|
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
|
||||||
HTTPS_GIT := https://github.com/Kava-Labs/kava.git
|
HTTPS_GIT := https://github.com/0glabs/0g-chain.git
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
### Machine Info ###
|
### Machine Info ###
|
||||||
@ -76,7 +80,7 @@ print-machine-info:
|
|||||||
BUILD_DIR := build# build files
|
BUILD_DIR := build# build files
|
||||||
BIN_DIR := $(BUILD_DIR)/bin# for binary dev dependencies
|
BIN_DIR := $(BUILD_DIR)/bin# for binary dev dependencies
|
||||||
BUILD_CACHE_DIR := $(BUILD_DIR)/.cache# caching for non-artifact outputs
|
BUILD_CACHE_DIR := $(BUILD_DIR)/.cache# caching for non-artifact outputs
|
||||||
OUT_DIR := out# for artifact intermediates and outputs
|
OUT_DIR := ./.build# for artifact intermediates and outputs
|
||||||
|
|
||||||
ROOT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))# absolute path to root
|
ROOT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))# absolute path to root
|
||||||
export PATH := $(ROOT_DIR)/$(BIN_DIR):$(PATH)# add local bin first in path
|
export PATH := $(ROOT_DIR)/$(BIN_DIR):$(PATH)# add local bin first in path
|
||||||
@ -142,12 +146,12 @@ build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
|
|||||||
|
|
||||||
# process linker flags
|
# process linker flags
|
||||||
|
|
||||||
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=kava \
|
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(PROJECT_NAME) \
|
||||||
-X github.com/cosmos/cosmos-sdk/version.AppName=kava \
|
-X github.com/cosmos/cosmos-sdk/version.AppName=$(PROJECT_NAME) \
|
||||||
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION_NUMBER) \
|
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION_NUMBER) \
|
||||||
-X github.com/cosmos/cosmos-sdk/version.Commit=$(GIT_COMMIT) \
|
-X github.com/cosmos/cosmos-sdk/version.Commit=$(GIT_COMMIT) \
|
||||||
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
|
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
|
||||||
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TENDERMINT_VERSION)
|
-X github.com/cometbft/cometbft/version.TMCoreSemVer=$(TENDERMINT_VERSION)
|
||||||
|
|
||||||
# DB backend selection
|
# DB backend selection
|
||||||
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
|
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
|
||||||
@ -172,6 +176,10 @@ endif
|
|||||||
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
|
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
|
||||||
ldflags += -w -s
|
ldflags += -w -s
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(LINK_STATICALLY),true)
|
||||||
|
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static -lm"
|
||||||
|
endif
|
||||||
ldflags += $(LDFLAGS)
|
ldflags += $(LDFLAGS)
|
||||||
ldflags := $(strip $(ldflags))
|
ldflags := $(strip $(ldflags))
|
||||||
|
|
||||||
@ -188,16 +196,20 @@ all: install
|
|||||||
|
|
||||||
build: go.sum
|
build: go.sum
|
||||||
ifeq ($(OS), Windows_NT)
|
ifeq ($(OS), Windows_NT)
|
||||||
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/kava.exe ./cmd/kava
|
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/$(BINARY_NAME).exe $(MAIN_ENTRY)
|
||||||
else
|
else
|
||||||
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/kava ./cmd/kava
|
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/$(BINARY_NAME) $(MAIN_ENTRY)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
build-release: go.sum
|
||||||
|
wget -q https://github.com/CosmWasm/wasmvm/releases/download/$(WASMVM_VERSION)/libwasmvm_muslc.$(ARCH).a -O /lib/libwasmvm.$(ARCH).a
|
||||||
|
$(GO_BIN) build -mod=readonly $(BUILD_FLAGS) -o out/$(shell $(GO_BIN) env GOOS)/$(BINARY_NAME) $(MAIN_ENTRY)
|
||||||
|
|
||||||
build-linux: go.sum
|
build-linux: go.sum
|
||||||
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
|
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
|
||||||
|
|
||||||
install: go.sum
|
install: go.sum
|
||||||
$(GO_BIN) install -mod=readonly $(BUILD_FLAGS) ./cmd/kava
|
$(GO_BIN) install -mod=readonly $(BUILD_FLAGS) $(MAIN_ENTRY)
|
||||||
|
|
||||||
########################################
|
########################################
|
||||||
### Tools & dependencies
|
### Tools & dependencies
|
||||||
@ -219,6 +231,7 @@ go.sum: go.mod
|
|||||||
# Set to exclude riot links as they trigger false positives
|
# Set to exclude riot links as they trigger false positives
|
||||||
link-check:
|
link-check:
|
||||||
@$(GO_BIN) get -u github.com/raviqqe/liche@f57a5d1c5be4856454cb26de155a65a4fd856ee3
|
@$(GO_BIN) get -u github.com/raviqqe/liche@f57a5d1c5be4856454cb26de155a65a4fd856ee3
|
||||||
|
# TODO: replace kava in following line with project name
|
||||||
liche -r . --exclude "^http://127.*|^https://riot.im/app*|^http://kava-testnet*|^https://testnet-dex*|^https://kava3.data.kava.io*|^https://ipfs.io*|^https://apps.apple.com*|^https://kava.quicksync.io*"
|
liche -r . --exclude "^http://127.*|^https://riot.im/app*|^http://kava-testnet*|^https://testnet-dex*|^https://kava3.data.kava.io*|^https://ipfs.io*|^https://apps.apple.com*|^https://kava.quicksync.io*"
|
||||||
|
|
||||||
|
|
||||||
@ -233,26 +246,26 @@ format:
|
|||||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs misspell -w
|
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs misspell -w
|
||||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/tendermint
|
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/tendermint
|
||||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk
|
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk
|
||||||
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/kava-labs/kava
|
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/0glabs/0g-chain
|
||||||
.PHONY: format
|
.PHONY: format
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
### Localnet ###
|
### Localnet ###
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# Build docker image and tag as kava/kava:local
|
# Build docker image and tag as 0glabs/0g-chain:local
|
||||||
docker-build:
|
docker-build:
|
||||||
DOCKER_BUILDKIT=1 $(DOCKER) build -t kava/kava:local .
|
DOCKER_BUILDKIT=1 $(DOCKER) build -t $(DOCKER_IMAGE_NAME):local .
|
||||||
|
|
||||||
docker-build-rocksdb:
|
docker-build-rocksdb:
|
||||||
DOCKER_BUILDKIT=1 $(DOCKER) build -f Dockerfile-rocksdb -t kava/kava:local .
|
DOCKER_BUILDKIT=1 $(DOCKER) build -f Dockerfile-rocksdb -t $(DOCKER_IMAGE_NAME):local .
|
||||||
|
|
||||||
build-docker-local-kava:
|
build-docker-local-0gchain:
|
||||||
@$(MAKE) -C networks/local
|
@$(MAKE) -C networks/local
|
||||||
|
|
||||||
# Run a 4-node testnet locally
|
# Run a 4-node testnet locally
|
||||||
localnet-start: build-linux localnet-stop
|
localnet-start: build-linux localnet-stop
|
||||||
@if ! [ -f build/node0/kvd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/kvd:Z kava/kavanode testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
|
@if ! [ -f build/node0/kvd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/kvd:Z $(DOCKER_IMAGE_NAME)-node testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
|
||||||
docker-compose up -d
|
docker-compose up -d
|
||||||
|
|
||||||
localnet-stop:
|
localnet-stop:
|
||||||
@ -261,7 +274,7 @@ localnet-stop:
|
|||||||
# Launch a new single validator chain
|
# Launch a new single validator chain
|
||||||
start:
|
start:
|
||||||
./contrib/devnet/init-new-chain.sh
|
./contrib/devnet/init-new-chain.sh
|
||||||
kava start
|
$(BINARY_NAME) start
|
||||||
|
|
||||||
#proto-format:
|
#proto-format:
|
||||||
#@echo "Formatting Protobuf files"
|
#@echo "Formatting Protobuf files"
|
||||||
@ -302,7 +315,7 @@ test:
|
|||||||
@$(GO_BIN) test $$($(GO_BIN) list ./... | grep -v 'contrib' | grep -v 'tests/e2e')
|
@$(GO_BIN) test $$($(GO_BIN) list ./... | grep -v 'contrib' | grep -v 'tests/e2e')
|
||||||
|
|
||||||
test-rocksdb:
|
test-rocksdb:
|
||||||
@go test -tags=rocksdb ./cmd/kava/opendb
|
@go test -tags=rocksdb $(MAIN_ENTRY)/opendb
|
||||||
|
|
||||||
# Run cli integration tests
|
# Run cli integration tests
|
||||||
# `-p 4` to use 4 cores, `-tags cli_test` to tell $(GO_BIN) not to ignore the cli package
|
# `-p 4` to use 4 cores, `-tags cli_test` to tell $(GO_BIN) not to ignore the cli package
|
||||||
@ -318,18 +331,19 @@ test-migrate:
|
|||||||
# This submits an AWS Batch job to run a lot of sims, each within a docker image. Results are uploaded to S3
|
# This submits an AWS Batch job to run a lot of sims, each within a docker image. Results are uploaded to S3
|
||||||
start-remote-sims:
|
start-remote-sims:
|
||||||
# build the image used for running sims in, and tag it
|
# build the image used for running sims in, and tag it
|
||||||
docker build -f simulations/Dockerfile -t kava/kava-sim:master .
|
docker build -f simulations/Dockerfile -t $(DOCKER_IMAGE_NAME)-sim:master .
|
||||||
# push that image to the hub
|
# push that image to the hub
|
||||||
docker push kava/kava-sim:master
|
docker push $(DOCKER_IMAGE_NAME)-sim:master
|
||||||
# submit an array job on AWS Batch, using 1000 seeds, spot instances
|
# submit an array job on AWS Batch, using 1000 seeds, spot instances
|
||||||
aws batch submit-job \
|
aws batch submit-job \
|
||||||
-—job-name "master-$(VERSION)" \
|
-—job-name "master-$(VERSION)" \
|
||||||
-—job-queue “simulation-1-queue-spot" \
|
-—job-queue “simulation-1-queue-spot" \
|
||||||
-—array-properties size=1000 \
|
-—array-properties size=1000 \
|
||||||
-—job-definition kava-sim-master \
|
-—job-definition $(BINARY_NAME)-sim-master \
|
||||||
-—container-override environment=[{SIM_NAME=master-$(VERSION)}]
|
-—container-override environment=[{SIM_NAME=master-$(VERSION)}]
|
||||||
|
|
||||||
update-kvtool:
|
update-kvtool:
|
||||||
|
git submodule init || true
|
||||||
git submodule update
|
git submodule update
|
||||||
cd tests/e2e/kvtool && make install
|
cd tests/e2e/kvtool && make install
|
||||||
|
|
||||||
|
28
README.md
28
README.md
@ -1,36 +1,29 @@
|
|||||||
|
<!---
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="./kava-logo.svg" width="300">
|
<img src="./0g-logo.svg" width="300">
|
||||||
</p>
|
</p>
|
||||||
|
--->
|
||||||
|
|
||||||
|
# 0G Chain
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
|
|
||||||
[![version](https://img.shields.io/github/tag/kava-labs/kava.svg)](https://github.com/kava-labs/kava/releases/latest)
|
### [Telegram](https://t.me/web3_0glabs) | [Discord](https://discord.com/invite/0glabs)
|
||||||
[![CircleCI](https://circleci.com/gh/Kava-Labs/kava/tree/master.svg?style=shield)](https://circleci.com/gh/Kava-Labs/kava/tree/master)
|
|
||||||
[![Go Report Card](https://goreportcard.com/badge/github.com/kava-labs/kava)](https://goreportcard.com/report/github.com/kava-labs/kava)
|
|
||||||
[![API Reference](https://godoc.org/github.com/Kava-Labs/kava?status.svg)](https://godoc.org/github.com/Kava-Labs/kava)
|
|
||||||
[![GitHub](https://img.shields.io/github/license/kava-labs/kava.svg)](https://github.com/Kava-Labs/kava/blob/master/LICENSE.md)
|
|
||||||
[![Twitter Follow](https://img.shields.io/twitter/follow/KAVA_CHAIN.svg?label=Follow&style=social)](https://twitter.com/KAVA_CHAIN)
|
|
||||||
[![Discord Chat](https://img.shields.io/discord/704389840614981673.svg)](https://discord.com/invite/kQzh3Uv)
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div align="center">
|
Reference implementation of 0G Chain, the first modular AI chain. Built using the [cosmos-sdk](https://github.com/cosmos/cosmos-sdk).
|
||||||
|
|
||||||
### [Telegram](https://t.me/kavalabs) | [Medium](https://medium.com/kava-labs) | [Discord](https://discord.gg/JJYnuCx)
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
Reference implementation of Kava, a blockchain for cross-chain DeFi. Built using the [cosmos-sdk](https://github.com/cosmos/cosmos-sdk).
|
|
||||||
|
|
||||||
|
<!---
|
||||||
## Mainnet
|
## Mainnet
|
||||||
|
|
||||||
The current recommended version of the software for mainnet is [v0.24.1](https://github.com/Kava-Labs/kava/releases/tag/v0.24.1). The master branch of this repository often contains considerable development work since the last mainnet release and is __not__ runnable on mainnet.
|
The current recommended version of the software for mainnet is [v0.25.0](https://github.com/Kava-Labs/kava/releases/tag/v0.25.0) The master branch of this repository often contains considerable development work since the last mainnet release and is __not__ runnable on mainnet.
|
||||||
|
|
||||||
### Installation and Setup
|
### Installation and Setup
|
||||||
For detailed instructions see [the Kava docs](https://docs.kava.io/docs/participate/validator-node).
|
For detailed instructions see [the Kava docs](https://docs.kava.io/docs/participate/validator-node).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git checkout v0.24.1
|
git checkout v0.25.0
|
||||||
make install
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -63,3 +56,4 @@ If you find a security issue, please report it to security [at] kava.io. Dependi
|
|||||||
Copyright © Kava Labs, Inc. All rights reserved.
|
Copyright © Kava Labs, Inc. All rights reserved.
|
||||||
|
|
||||||
Licensed under the [Apache v2 License](LICENSE.md).
|
Licensed under the [Apache v2 License](LICENSE.md).
|
||||||
|
--->
|
@ -11,15 +11,15 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
dbm "github.com/cometbft/cometbft-db"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
dbm "github.com/tendermint/tm-db"
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
|
|
||||||
|
"cosmossdk.io/simapp"
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
|
||||||
"github.com/cosmos/cosmos-sdk/store"
|
"github.com/cosmos/cosmos-sdk/store"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/module"
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
@ -32,15 +32,10 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/x/auction"
|
"github.com/0glabs/0g-chain/x/bep3"
|
||||||
"github.com/kava-labs/kava/x/bep3"
|
"github.com/0glabs/0g-chain/x/committee"
|
||||||
"github.com/kava-labs/kava/x/cdp"
|
"github.com/0glabs/0g-chain/x/pricefeed"
|
||||||
"github.com/kava-labs/kava/x/committee"
|
validatorvesting "github.com/0glabs/0g-chain/x/validator-vesting"
|
||||||
"github.com/kava-labs/kava/x/incentive"
|
|
||||||
"github.com/kava-labs/kava/x/kavadist"
|
|
||||||
"github.com/kava-labs/kava/x/pricefeed"
|
|
||||||
"github.com/kava-labs/kava/x/swap"
|
|
||||||
validatorvesting "github.com/kava-labs/kava/x/validator-vesting"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type StoreKeysPrefixes struct {
|
type StoreKeysPrefixes struct {
|
||||||
@ -280,7 +275,7 @@ func TestAppStateDeterminism(t *testing.T) {
|
|||||||
config.ExportParamsPath = ""
|
config.ExportParamsPath = ""
|
||||||
config.OnOperation = false
|
config.OnOperation = false
|
||||||
config.AllInvariants = false
|
config.AllInvariants = false
|
||||||
config.ChainID = helpers.SimAppChainID
|
config.ChainID = sims.SimAppChainID
|
||||||
|
|
||||||
numTimesToRunPerSeed := 2
|
numTimesToRunPerSeed := 2
|
||||||
appHashList := make([]json.RawMessage, numTimesToRunPerSeed)
|
appHashList := make([]json.RawMessage, numTimesToRunPerSeed)
|
||||||
|
@ -8,8 +8,13 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
|
|
||||||
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
|
tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
||||||
|
ctypes "github.com/cometbft/cometbft/rpc/core/types"
|
||||||
|
jsonrpctypes "github.com/cometbft/cometbft/rpc/jsonrpc/types"
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||||
@ -18,10 +23,6 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
|
||||||
jsonrpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SimulateRequestTestSuite struct {
|
type SimulateRequestTestSuite struct {
|
||||||
@ -51,9 +52,9 @@ func (suite *SimulateRequestTestSuite) TearDownTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||||
fromAddr, err := sdk.AccAddressFromBech32("kava1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
fromAddr, err := sdk.AccAddressFromBech32("0g1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
toAddr, err := sdk.AccAddressFromBech32("kava1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
toAddr, err := sdk.AccAddressFromBech32("0g1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
simRequest := app.SimulateRequest{
|
simRequest := app.SimulateRequest{
|
||||||
@ -61,11 +62,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
|||||||
bank.MsgSend{
|
bank.MsgSend{
|
||||||
FromAddress: fromAddr,
|
FromAddress: fromAddr,
|
||||||
ToAddress: toAddr,
|
ToAddress: toAddr,
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e6)),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Fee: auth.StdFee{
|
Fee: auth.StdFee{
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(5e4))),
|
Amount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(5e4)),
|
||||||
Gas: 1e6,
|
Gas: 1e6,
|
||||||
},
|
},
|
||||||
Memo: "test memo",
|
Memo: "test memo",
|
||||||
|
@ -5,16 +5,16 @@ import (
|
|||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
|
||||||
errorsmod "cosmossdk.io/errors"
|
errorsmod "cosmossdk.io/errors"
|
||||||
|
tmlog "github.com/cometbft/cometbft/libs/log"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
|
authante "github.com/cosmos/cosmos-sdk/x/auth/ante"
|
||||||
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
|
||||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||||
ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante"
|
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
|
||||||
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"
|
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
|
||||||
evmante "github.com/evmos/ethermint/app/ante"
|
evmante "github.com/evmos/ethermint/app/ante"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
tmlog "github.com/tendermint/tendermint/libs/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
|
// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
|
||||||
|
@ -7,9 +7,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
|
tmdb "github.com/cometbft/cometbft-db"
|
||||||
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||||
@ -17,17 +21,15 @@ import (
|
|||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
|
||||||
tmdb "github.com/tendermint/tm-db"
|
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
bep3types "github.com/kava-labs/kava/x/bep3/types"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
|
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||||
|
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,20 +54,21 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
|||||||
App: *app.NewApp(
|
App: *app.NewApp(
|
||||||
log.NewNopLogger(),
|
log.NewNopLogger(),
|
||||||
tmdb.NewMemDB(),
|
tmdb.NewMemDB(),
|
||||||
app.DefaultNodeHome,
|
chaincfg.DefaultNodeHome,
|
||||||
nil,
|
nil,
|
||||||
encodingConfig,
|
encodingConfig,
|
||||||
opts,
|
opts,
|
||||||
|
baseapp.SetChainID(app.TestChainId),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
chainID := "kavatest_1-1"
|
chainID := app.TestChainId
|
||||||
tApp = tApp.InitializeFromGenesisStatesWithTimeAndChainID(
|
tApp = tApp.InitializeFromGenesisStatesWithTimeAndChainID(
|
||||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
|
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
chainID,
|
chainID,
|
||||||
app.NewFundedGenStateWithSameCoins(
|
app.NewFundedGenStateWithSameCoins(
|
||||||
tApp.AppCodec(),
|
tApp.AppCodec(),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e9)),
|
||||||
testAddresses,
|
testAddresses,
|
||||||
),
|
),
|
||||||
newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
||||||
@ -106,18 +109,18 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
stdTx, err := helpers.GenSignedMockTx(
|
stdTx, err := sims.GenSignedMockTx(
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
encodingConfig.TxConfig,
|
encodingConfig.TxConfig,
|
||||||
[]sdk.Msg{
|
[]sdk.Msg{
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
tc.address,
|
tc.address,
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1_000_000)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1_000_000)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
helpers.DefaultGenTxGas,
|
sims.DefaultGenTxGas,
|
||||||
chainID,
|
chainID,
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
[]uint64{0}, // fixed sequence numbers will cause tests to fail sig verification if the same address is used twice
|
[]uint64{0}, // fixed sequence numbers will cause tests to fail sig verification if the same address is used twice
|
||||||
@ -209,7 +212,7 @@ func TestAppAnteHandler_RejectMsgsInAuthz(t *testing.T) {
|
|||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
chainID := "kavatest_1-1"
|
chainID := app.TestChainId
|
||||||
encodingConfig := app.MakeEncodingConfig()
|
encodingConfig := app.MakeEncodingConfig()
|
||||||
|
|
||||||
testcases := []struct {
|
testcases := []struct {
|
||||||
@ -238,12 +241,12 @@ func TestAppAnteHandler_RejectMsgsInAuthz(t *testing.T) {
|
|||||||
chainID,
|
chainID,
|
||||||
)
|
)
|
||||||
|
|
||||||
stdTx, err := helpers.GenSignedMockTx(
|
stdTx, err := sims.GenSignedMockTx(
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
encodingConfig.TxConfig,
|
encodingConfig.TxConfig,
|
||||||
[]sdk.Msg{tc.msg},
|
[]sdk.Msg{tc.msg},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
helpers.DefaultGenTxGas,
|
sims.DefaultGenTxGas,
|
||||||
chainID,
|
chainID,
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
|
@ -5,13 +5,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/kava-labs/kava/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
||||||
@ -38,18 +39,18 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
|
|||||||
fetcher := mockAddressFetcher(testAddresses[1:]...)
|
fetcher := mockAddressFetcher(testAddresses[1:]...)
|
||||||
|
|
||||||
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
||||||
tx, err := helpers.GenSignedMockTx(
|
tx, err := sims.GenSignedMockTx(
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
txConfig,
|
txConfig,
|
||||||
[]sdk.Msg{
|
[]sdk.Msg{
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100_000_000)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
helpers.DefaultGenTxGas,
|
sims.DefaultGenTxGas,
|
||||||
"testing-chain-id",
|
"testing-chain-id",
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
@ -73,23 +74,23 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
|
|||||||
|
|
||||||
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
||||||
|
|
||||||
tx, err := helpers.GenSignedMockTx(
|
tx, err := sims.GenSignedMockTx(
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
txConfig,
|
txConfig,
|
||||||
[]sdk.Msg{
|
[]sdk.Msg{
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||||
),
|
),
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[2],
|
testAddresses[2],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
helpers.DefaultGenTxGas,
|
sims.DefaultGenTxGas,
|
||||||
"testing-chain-id",
|
"testing-chain-id",
|
||||||
[]uint64{0, 123},
|
[]uint64{0, 123},
|
||||||
[]uint64{0, 123},
|
[]uint64{0, 123},
|
||||||
@ -114,18 +115,18 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
|
|||||||
|
|
||||||
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
decorator := ante.NewAuthenticatedMempoolDecorator(fetcher)
|
||||||
|
|
||||||
tx, err := helpers.GenSignedMockTx(
|
tx, err := sims.GenSignedMockTx(
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
txConfig,
|
txConfig,
|
||||||
[]sdk.Msg{
|
[]sdk.Msg{
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
helpers.DefaultGenTxGas,
|
sims.DefaultGenTxGas,
|
||||||
"testing-chain-id",
|
"testing-chain-id",
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/cosmos/cosmos-sdk/x/authz"
|
"github.com/cosmos/cosmos-sdk/x/authz"
|
||||||
@ -14,8 +14,9 @@ import (
|
|||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/kava-labs/kava/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
|
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
|
||||||
@ -58,7 +59,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
checkTx: false,
|
checkTx: false,
|
||||||
@ -128,7 +129,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
[]sdk.Msg{banktypes.NewMsgSend(
|
[]sdk.Msg{banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[3],
|
testAddresses[3],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)),
|
||||||
)}),
|
)}),
|
||||||
},
|
},
|
||||||
checkTx: false,
|
checkTx: false,
|
||||||
@ -161,7 +162,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[3],
|
testAddresses[3],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)),
|
||||||
),
|
),
|
||||||
&evmtypes.MsgEthereumTx{},
|
&evmtypes.MsgEthereumTx{},
|
||||||
},
|
},
|
||||||
@ -212,12 +213,12 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
tx, err := helpers.GenSignedMockTx(
|
tx, err := sims.GenSignedMockTx(
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
txConfig,
|
txConfig,
|
||||||
tc.msgs,
|
tc.msgs,
|
||||||
sdk.NewCoins(),
|
sdk.NewCoins(),
|
||||||
helpers.DefaultGenTxGas,
|
sims.DefaultGenTxGas,
|
||||||
"testing-chain-id",
|
"testing-chain-id",
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
"github.com/cosmos/cosmos-sdk/types/tx/signing"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
||||||
@ -20,6 +20,11 @@ import (
|
|||||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
|
|
||||||
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
|
"github.com/cometbft/cometbft/crypto/tmhash"
|
||||||
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||||
|
tmversion "github.com/cometbft/cometbft/proto/tendermint/version"
|
||||||
|
"github.com/cometbft/cometbft/version"
|
||||||
"github.com/evmos/ethermint/crypto/ethsecp256k1"
|
"github.com/evmos/ethermint/crypto/ethsecp256k1"
|
||||||
"github.com/evmos/ethermint/ethereum/eip712"
|
"github.com/evmos/ethermint/ethereum/eip712"
|
||||||
"github.com/evmos/ethermint/tests"
|
"github.com/evmos/ethermint/tests"
|
||||||
@ -27,23 +32,17 @@ import (
|
|||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
||||||
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
|
|
||||||
"github.com/tendermint/tendermint/version"
|
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
cdptypes "github.com/kava-labs/kava/x/cdp/types"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
evmutilkeeper "github.com/kava-labs/kava/x/evmutil/keeper"
|
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
evmutiltestutil "github.com/kava-labs/kava/x/evmutil/testutil"
|
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
evmutiltypes "github.com/kava-labs/kava/x/evmutil/types"
|
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
hardtypes "github.com/kava-labs/kava/x/hard/types"
|
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||||
pricefeedtypes "github.com/kava-labs/kava/x/pricefeed/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ChainID = "kavatest_1-1"
|
ChainID = app.TestChainId
|
||||||
USDCCoinDenom = "erc20/usdc"
|
USDCCoinDenom = "erc20/usdc"
|
||||||
USDCCDPType = "erc20-usdc"
|
USDCCDPType = "erc20-usdc"
|
||||||
)
|
)
|
||||||
@ -138,6 +137,7 @@ func (suite *EIP712TestSuite) createTestEIP712CosmosTxBuilder(
|
|||||||
func (suite *EIP712TestSuite) SetupTest() {
|
func (suite *EIP712TestSuite) SetupTest() {
|
||||||
tApp := app.NewTestApp()
|
tApp := app.NewTestApp()
|
||||||
suite.tApp = tApp
|
suite.tApp = tApp
|
||||||
|
|
||||||
cdc := tApp.AppCodec()
|
cdc := tApp.AppCodec()
|
||||||
suite.evmutilKeeper = tApp.GetEvmutilKeeper()
|
suite.evmutilKeeper = tApp.GetEvmutilKeeper()
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
// Genesis states
|
// Genesis states
|
||||||
evmGs := evmtypes.NewGenesisState(
|
evmGs := evmtypes.NewGenesisState(
|
||||||
evmtypes.NewParams(
|
evmtypes.NewParams(
|
||||||
"akava", // evmDenom
|
chaincfg.EvmDenom, // evmDenom
|
||||||
false, // allowedUnprotectedTxs
|
false, // allowedUnprotectedTxs
|
||||||
true, // enableCreate
|
true, // enableCreate
|
||||||
true, // enableCall
|
true, // enableCall
|
||||||
@ -172,47 +172,6 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
feemarketGenesis.Params.EnableHeight = 1
|
feemarketGenesis.Params.EnableHeight = 1
|
||||||
feemarketGenesis.Params.NoBaseFee = false
|
feemarketGenesis.Params.NoBaseFee = false
|
||||||
|
|
||||||
cdpGenState := cdptypes.DefaultGenesisState()
|
|
||||||
cdpGenState.Params.GlobalDebtLimit = sdk.NewInt64Coin("usdx", 53000000000000)
|
|
||||||
cdpGenState.Params.CollateralParams = cdptypes.CollateralParams{
|
|
||||||
{
|
|
||||||
Denom: USDCCoinDenom,
|
|
||||||
Type: USDCCDPType,
|
|
||||||
LiquidationRatio: sdk.MustNewDecFromStr("1.01"),
|
|
||||||
DebtLimit: sdk.NewInt64Coin("usdx", 500000000000),
|
|
||||||
StabilityFee: sdk.OneDec(),
|
|
||||||
AuctionSize: sdkmath.NewIntFromUint64(10000000000),
|
|
||||||
LiquidationPenalty: sdk.MustNewDecFromStr("0.05"),
|
|
||||||
CheckCollateralizationIndexCount: sdkmath.NewInt(10),
|
|
||||||
KeeperRewardPercentage: sdk.MustNewDecFromStr("0.01"),
|
|
||||||
SpotMarketID: "usdc:usd",
|
|
||||||
LiquidationMarketID: "usdc:usd:30",
|
|
||||||
ConversionFactor: sdkmath.NewInt(18),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
hardGenState := hardtypes.DefaultGenesisState()
|
|
||||||
hardGenState.Params.MoneyMarkets = []hardtypes.MoneyMarket{
|
|
||||||
{
|
|
||||||
Denom: "usdx",
|
|
||||||
BorrowLimit: hardtypes.BorrowLimit{
|
|
||||||
HasMaxLimit: true,
|
|
||||||
MaximumLimit: sdk.MustNewDecFromStr("100000000000"),
|
|
||||||
LoanToValue: sdk.MustNewDecFromStr("1"),
|
|
||||||
},
|
|
||||||
SpotMarketID: "usdx:usd",
|
|
||||||
ConversionFactor: sdkmath.NewInt(1_000_000),
|
|
||||||
InterestRateModel: hardtypes.InterestRateModel{
|
|
||||||
BaseRateAPY: sdk.MustNewDecFromStr("0.05"),
|
|
||||||
BaseMultiplier: sdk.MustNewDecFromStr("2"),
|
|
||||||
Kink: sdk.MustNewDecFromStr("0.8"),
|
|
||||||
JumpMultiplier: sdk.MustNewDecFromStr("10"),
|
|
||||||
},
|
|
||||||
ReserveFactor: sdk.MustNewDecFromStr("0.05"),
|
|
||||||
KeeperRewardPercentage: sdk.ZeroDec(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
pricefeedGenState := pricefeedtypes.DefaultGenesisState()
|
pricefeedGenState := pricefeedtypes.DefaultGenesisState()
|
||||||
pricefeedGenState.Params.Markets = []pricefeedtypes.Market{
|
pricefeedGenState.Params.Markets = []pricefeedtypes.Market{
|
||||||
{
|
{
|
||||||
@ -261,15 +220,13 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
genState := app.GenesisState{
|
genState := app.GenesisState{
|
||||||
evmtypes.ModuleName: cdc.MustMarshalJSON(evmGs),
|
evmtypes.ModuleName: cdc.MustMarshalJSON(evmGs),
|
||||||
feemarkettypes.ModuleName: cdc.MustMarshalJSON(feemarketGenesis),
|
feemarkettypes.ModuleName: cdc.MustMarshalJSON(feemarketGenesis),
|
||||||
cdptypes.ModuleName: cdc.MustMarshalJSON(&cdpGenState),
|
|
||||||
hardtypes.ModuleName: cdc.MustMarshalJSON(&hardGenState),
|
|
||||||
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||||
}
|
}
|
||||||
|
|
||||||
// funds our test accounts with some ukava
|
// funds our test accounts with some gas denom
|
||||||
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
||||||
tApp.AppCodec(),
|
tApp.AppCodec(),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e9)),
|
||||||
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -334,6 +291,11 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
)
|
)
|
||||||
suite.usdcEVMAddr = pair.GetAddress()
|
suite.usdcEVMAddr = pair.GetAddress()
|
||||||
|
|
||||||
|
// update consensus params
|
||||||
|
cParams := tApp.GetConsensusParams(suite.ctx)
|
||||||
|
cParams.Block.MaxGas = sims.DefaultGenTxGas * 20
|
||||||
|
tApp.StoreConsensusParams(suite.ctx, cParams)
|
||||||
|
|
||||||
// Add a contract to evmutil conversion pair
|
// Add a contract to evmutil conversion pair
|
||||||
evmutilParams := suite.evmutilKeeper.GetParams(suite.ctx)
|
evmutilParams := suite.evmutilKeeper.GetParams(suite.ctx)
|
||||||
evmutilParams.EnabledConversionPairs =
|
evmutilParams.EnabledConversionPairs =
|
||||||
@ -351,45 +313,17 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
params := evmKeeper.GetParams(suite.ctx)
|
params := evmKeeper.GetParams(suite.ctx)
|
||||||
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
||||||
{
|
{
|
||||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
MsgTypeUrl: "/zgc.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||||
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||||
{Name: "initiator", Type: "string"},
|
{Name: "initiator", Type: "string"},
|
||||||
{Name: "receiver", Type: "string"},
|
{Name: "receiver", Type: "string"},
|
||||||
{Name: "kava_erc20_address", Type: "string"},
|
{Name: "zgchain_erc20_address", Type: "string"},
|
||||||
{Name: "amount", Type: "string"},
|
{Name: "amount", Type: "string"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgCreateCDP",
|
MsgTypeUrl: "/zgc.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||||
MsgValueTypeName: "MsgValueCDPCreate",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "sender", Type: "string"},
|
|
||||||
{Name: "collateral", Type: "Coin"},
|
|
||||||
{Name: "principal", Type: "Coin"},
|
|
||||||
{Name: "collateral_type", Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgDeposit",
|
|
||||||
MsgValueTypeName: "MsgValueCDPDeposit",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "depositor", Type: "string"},
|
|
||||||
{Name: "owner", Type: "string"},
|
|
||||||
{Name: "collateral", Type: "Coin"},
|
|
||||||
{Name: "collateral_type", Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgDeposit",
|
|
||||||
MsgValueTypeName: "MsgValueHardDeposit",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "depositor", Type: "string"},
|
|
||||||
{Name: "amount", Type: "Coin[]"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertCoinToERC20",
|
|
||||||
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||||
{Name: "initiator", Type: "string"},
|
{Name: "initiator", Type: "string"},
|
||||||
@ -397,23 +331,6 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
{Name: "amount", Type: "Coin"},
|
{Name: "amount", Type: "Coin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgRepayDebt",
|
|
||||||
MsgValueTypeName: "MsgValueCDPRepayDebt",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "sender", Type: "string"},
|
|
||||||
{Name: "collateral_type", Type: "string"},
|
|
||||||
{Name: "payment", Type: "Coin"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgWithdraw",
|
|
||||||
MsgValueTypeName: "MsgValueHardWithdraw",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "depositor", Type: "string"},
|
|
||||||
{Name: "amount", Type: "Coin[]"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
evmKeeper.SetParams(suite.ctx, params)
|
evmKeeper.SetParams(suite.ctx, params)
|
||||||
|
|
||||||
@ -459,7 +376,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
|
|||||||
suite.tApp.FundModuleAccount(
|
suite.tApp.FundModuleAccount(
|
||||||
suite.ctx,
|
suite.ctx,
|
||||||
evmutiltypes.ModuleName,
|
evmutiltypes.ModuleName,
|
||||||
sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(0))),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(0)),
|
||||||
)
|
)
|
||||||
|
|
||||||
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
||||||
@ -481,40 +398,43 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
failCheckTx bool
|
failCheckTx bool
|
||||||
errMsg string
|
errMsg string
|
||||||
}{
|
}{
|
||||||
{
|
// TODO: need fix
|
||||||
name: "processes deposit eip712 messages successfully",
|
// {
|
||||||
usdcDepositAmt: 100,
|
// name: "processes deposit eip712 messages successfully",
|
||||||
usdxToMintAmt: 99,
|
// usdcDepositAmt: 100,
|
||||||
},
|
// usdxToMintAmt: 99,
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
name: "fails when convertion more erc20 usdc than balance",
|
name: "fails when convertion more erc20 usdc than balance",
|
||||||
usdcDepositAmt: 51_000,
|
usdcDepositAmt: 51_000,
|
||||||
usdxToMintAmt: 100,
|
usdxToMintAmt: 100,
|
||||||
errMsg: "transfer amount exceeds balance",
|
errMsg: "transfer amount exceeds balance",
|
||||||
},
|
},
|
||||||
{
|
// TODO: need fix
|
||||||
name: "fails when minting more usdx than allowed",
|
// {
|
||||||
usdcDepositAmt: 100,
|
// name: "fails when minting more usdx than allowed",
|
||||||
usdxToMintAmt: 100,
|
// usdcDepositAmt: 100,
|
||||||
errMsg: "proposed collateral ratio is below liquidation ratio",
|
// usdxToMintAmt: 100,
|
||||||
},
|
// errMsg: "proposed collateral ratio is below liquidation ratio",
|
||||||
{
|
// },
|
||||||
name: "fails when trying to convert usdc for another address",
|
// TODO: need fix
|
||||||
usdcDepositAmt: 100,
|
// {
|
||||||
usdxToMintAmt: 90,
|
// name: "fails when trying to convert usdc for another address",
|
||||||
errMsg: "unauthorized",
|
// usdcDepositAmt: 100,
|
||||||
failCheckTx: true,
|
// usdxToMintAmt: 90,
|
||||||
updateMsgs: func(msgs []sdk.Msg) []sdk.Msg {
|
// errMsg: "unauthorized",
|
||||||
convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
// failCheckTx: true,
|
||||||
suite.testEVMAddr2,
|
// updateMsgs: func(msgs []sdk.Msg) []sdk.Msg {
|
||||||
suite.testAddr,
|
// convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
||||||
suite.usdcEVMAddr,
|
// suite.testEVMAddr2,
|
||||||
suite.getEVMAmount(100),
|
// suite.testAddr,
|
||||||
)
|
// suite.usdcEVMAddr,
|
||||||
msgs[0] = &convertMsg
|
// suite.getEVMAmount(100),
|
||||||
return msgs
|
// )
|
||||||
},
|
// msgs[0] = &convertMsg
|
||||||
},
|
// return msgs
|
||||||
|
// },
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
name: "fails when trying to convert erc20 for non-whitelisted contract",
|
name: "fails when trying to convert erc20 for non-whitelisted contract",
|
||||||
usdcDepositAmt: 100,
|
usdcDepositAmt: 100,
|
||||||
@ -541,7 +461,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
var option *codectypes.Any
|
var option *codectypes.Any
|
||||||
option, _ = codectypes.NewAnyWithValue(ðerminttypes.ExtensionOptionsWeb3Tx{
|
option, _ = codectypes.NewAnyWithValue(ðerminttypes.ExtensionOptionsWeb3Tx{
|
||||||
FeePayer: suite.testAddr.String(),
|
FeePayer: suite.testAddr.String(),
|
||||||
TypedDataChainID: 1,
|
TypedDataChainID: 2221,
|
||||||
FeePayerSig: []byte("sig"),
|
FeePayerSig: []byte("sig"),
|
||||||
})
|
})
|
||||||
builder, _ := txBuilder.(authtx.ExtensionOptionsTxBuilder)
|
builder, _ := txBuilder.(authtx.ExtensionOptionsTxBuilder)
|
||||||
@ -556,7 +476,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
errMsg: "insufficient funds",
|
errMsg: "insufficient funds",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||||
bk := suite.tApp.GetBankKeeper()
|
bk := suite.tApp.GetBankKeeper()
|
||||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, "ukava")
|
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.GasDenom)
|
||||||
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
||||||
return txBuilder
|
return txBuilder
|
||||||
},
|
},
|
||||||
@ -568,9 +488,9 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
failCheckTx: true,
|
failCheckTx: true,
|
||||||
errMsg: "invalid chain-id",
|
errMsg: "invalid chain-id",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20))
|
||||||
return suite.createTestEIP712CosmosTxBuilder(
|
return suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(helpers.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -581,9 +501,9 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
failCheckTx: true,
|
failCheckTx: true,
|
||||||
errMsg: "invalid pubkey",
|
errMsg: "invalid pubkey",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20))
|
||||||
return suite.createTestEIP712CosmosTxBuilder(
|
return suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(helpers.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -601,29 +521,17 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
suite.usdcEVMAddr,
|
suite.usdcEVMAddr,
|
||||||
usdcAmt,
|
usdcAmt,
|
||||||
)
|
)
|
||||||
usdxAmt := sdkmath.NewInt(1_000_000).Mul(sdkmath.NewInt(tc.usdxToMintAmt))
|
|
||||||
mintMsg := cdptypes.NewMsgCreateCDP(
|
|
||||||
suite.testAddr,
|
|
||||||
sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
|
||||||
sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
|
||||||
USDCCDPType,
|
|
||||||
)
|
|
||||||
lendMsg := hardtypes.NewMsgDeposit(
|
|
||||||
suite.testAddr,
|
|
||||||
sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
|
||||||
)
|
|
||||||
msgs := []sdk.Msg{
|
msgs := []sdk.Msg{
|
||||||
&convertMsg,
|
&convertMsg,
|
||||||
&mintMsg,
|
|
||||||
&lendMsg,
|
|
||||||
}
|
}
|
||||||
if tc.updateMsgs != nil {
|
if tc.updateMsgs != nil {
|
||||||
msgs = tc.updateMsgs(msgs)
|
msgs = tc.updateMsgs(msgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20))
|
||||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(helpers.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
if tc.updateTx != nil {
|
if tc.updateTx != nil {
|
||||||
txBuilder = tc.updateTx(txBuilder, msgs)
|
txBuilder = tc.updateTx(txBuilder, msgs)
|
||||||
@ -659,17 +567,17 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
suite.Require().Equal(sdk.ZeroInt(), amt.Amount)
|
suite.Require().Equal(sdk.ZeroInt(), amt.Amount)
|
||||||
|
|
||||||
// validate cdp
|
// validate cdp
|
||||||
cdp, found := suite.tApp.GetCDPKeeper().GetCdpByOwnerAndCollateralType(suite.ctx, suite.testAddr, USDCCDPType)
|
// cdp, found := suite.tApp.GetCDPKeeper().GetCdpByOwnerAndCollateralType(suite.ctx, suite.testAddr, USDCCDPType)
|
||||||
suite.Require().True(found)
|
// suite.Require().True(found)
|
||||||
suite.Require().Equal(suite.testAddr, cdp.Owner)
|
// suite.Require().Equal(suite.testAddr, cdp.Owner)
|
||||||
suite.Require().Equal(sdk.NewCoin(USDCCoinDenom, suite.getEVMAmount(100)), cdp.Collateral)
|
// suite.Require().Equal(sdk.NewCoin(USDCCoinDenom, suite.getEVMAmount(100)), cdp.Collateral)
|
||||||
suite.Require().Equal(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000)), cdp.Principal)
|
// suite.Require().Equal(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000)), cdp.Principal)
|
||||||
|
|
||||||
// validate hard
|
// validate hard
|
||||||
hardDeposit, found := suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
// hardDeposit, found := suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||||
suite.Require().True(found)
|
// suite.Require().True(found)
|
||||||
suite.Require().Equal(suite.testAddr, hardDeposit.Depositor)
|
// suite.Require().Equal(suite.testAddr, hardDeposit.Depositor)
|
||||||
suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000))), hardDeposit.Amount)
|
// suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000))), hardDeposit.Amount)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().NotEqual(resDeliverTx.Code, uint32(0), resCheckTx.Log)
|
suite.Require().NotEqual(resDeliverTx.Code, uint32(0), resCheckTx.Log)
|
||||||
suite.Require().Contains(resDeliverTx.Log, tc.errMsg)
|
suite.Require().Contains(resDeliverTx.Log, tc.errMsg)
|
||||||
@ -689,27 +597,15 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
|||||||
suite.usdcEVMAddr,
|
suite.usdcEVMAddr,
|
||||||
usdcAmt,
|
usdcAmt,
|
||||||
)
|
)
|
||||||
usdxAmt := sdkmath.NewInt(1_000_000).Mul(sdkmath.NewInt(99))
|
|
||||||
mintMsg := cdptypes.NewMsgCreateCDP(
|
|
||||||
suite.testAddr,
|
|
||||||
sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
|
||||||
sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
|
||||||
USDCCDPType,
|
|
||||||
)
|
|
||||||
lendMsg := hardtypes.NewMsgDeposit(
|
|
||||||
suite.testAddr,
|
|
||||||
sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
|
||||||
)
|
|
||||||
depositMsgs := []sdk.Msg{
|
depositMsgs := []sdk.Msg{
|
||||||
&convertMsg,
|
&convertMsg,
|
||||||
&mintMsg,
|
|
||||||
&lendMsg,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// deliver deposit msg
|
// deliver deposit msg
|
||||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20))
|
||||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(helpers.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
||||||
)
|
)
|
||||||
txBytes, err := encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx())
|
txBytes, err := encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx())
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
@ -721,10 +617,10 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
|||||||
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)
|
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)
|
||||||
|
|
||||||
// validate hard
|
// validate hard
|
||||||
hardDeposit, found := suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
// hardDeposit, found := suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||||
suite.Require().True(found)
|
// suite.Require().True(found)
|
||||||
suite.Require().Equal(suite.testAddr, hardDeposit.Depositor)
|
// suite.Require().Equal(suite.testAddr, hardDeposit.Depositor)
|
||||||
suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000))), hardDeposit.Amount)
|
// suite.Require().Equal(sdk.NewCoins(sdk.NewCoin("usdx", sdkmath.NewInt(99_000_000))), hardDeposit.Amount)
|
||||||
|
|
||||||
// validate erc20 balance
|
// validate erc20 balance
|
||||||
coinBal, err := suite.evmutilKeeper.QueryERC20BalanceOf(suite.ctx, suite.usdcEVMAddr, suite.testEVMAddr)
|
coinBal, err := suite.evmutilKeeper.QueryERC20BalanceOf(suite.ctx, suite.usdcEVMAddr, suite.testEVMAddr)
|
||||||
@ -737,24 +633,13 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
|||||||
suite.testEVMAddr.String(),
|
suite.testEVMAddr.String(),
|
||||||
sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
sdk.NewCoin(USDCCoinDenom, usdcAmt),
|
||||||
)
|
)
|
||||||
cdpWithdrawMsg := cdptypes.NewMsgRepayDebt(
|
|
||||||
suite.testAddr,
|
|
||||||
USDCCDPType,
|
|
||||||
sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt),
|
|
||||||
)
|
|
||||||
hardWithdrawMsg := hardtypes.NewMsgWithdraw(
|
|
||||||
suite.testAddr,
|
|
||||||
sdk.NewCoins(sdk.NewCoin(cdptypes.DefaultStableDenom, usdxAmt)),
|
|
||||||
)
|
|
||||||
withdrawMsgs := []sdk.Msg{
|
withdrawMsgs := []sdk.Msg{
|
||||||
&hardWithdrawMsg,
|
|
||||||
&cdpWithdrawMsg,
|
|
||||||
&withdrawConvertMsg,
|
&withdrawConvertMsg,
|
||||||
}
|
}
|
||||||
|
|
||||||
// deliver withdraw msg
|
// deliver withdraw msg
|
||||||
txBuilder = suite.createTestEIP712CosmosTxBuilder(
|
txBuilder = suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(helpers.DefaultGenTxGas*10), gasAmt, withdrawMsgs,
|
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, withdrawMsgs,
|
||||||
)
|
)
|
||||||
txBytes, err = encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx())
|
txBytes, err = encodingConfig.TxConfig.TxEncoder()(txBuilder.GetTx())
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
@ -766,10 +651,10 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
|||||||
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)
|
suite.Require().Equal(resDeliverTx.Code, uint32(0), resDeliverTx.Log)
|
||||||
|
|
||||||
// validate hard & cdp should be repayed
|
// validate hard & cdp should be repayed
|
||||||
_, found = suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
// _, found = suite.tApp.GetHardKeeper().GetDeposit(suite.ctx, suite.testAddr)
|
||||||
suite.Require().False(found)
|
// suite.Require().False(found)
|
||||||
_, found = suite.tApp.GetCDPKeeper().GetCdpByOwnerAndCollateralType(suite.ctx, suite.testAddr, USDCCDPType)
|
// _, found = suite.tApp.GetCDPKeeper().GetCdpByOwnerAndCollateralType(suite.ctx, suite.testAddr, USDCCDPType)
|
||||||
suite.Require().False(found)
|
// suite.Require().False(found)
|
||||||
|
|
||||||
// validate user cosmos erc20/usd balance
|
// validate user cosmos erc20/usd balance
|
||||||
bk := suite.tApp.GetBankKeeper()
|
bk := suite.tApp.GetBankKeeper()
|
||||||
|
@ -4,15 +4,16 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||||
|
tmtime "github.com/cometbft/cometbft/types/time"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
||||||
tmtime "github.com/tendermint/tendermint/types/time"
|
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/kava-labs/kava/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustParseDecCoins(value string) sdk.DecCoins {
|
func mustParseDecCoins(value string) sdk.DecCoins {
|
||||||
@ -30,7 +31,7 @@ func TestEvmMinGasFilter(t *testing.T) {
|
|||||||
|
|
||||||
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
||||||
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
||||||
EvmDenom: "akava",
|
EvmDenom: chaincfg.EvmDenom,
|
||||||
})
|
})
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -44,29 +45,29 @@ func TestEvmMinGasFilter(t *testing.T) {
|
|||||||
mustParseDecCoins(""),
|
mustParseDecCoins(""),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price",
|
"zero ua0gi gas price",
|
||||||
mustParseDecCoins("0ukava"),
|
mustParseDecCoins("0ua0gi"),
|
||||||
mustParseDecCoins("0ukava"),
|
mustParseDecCoins("0ua0gi"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non-zero ukava gas price",
|
"non-zero ua0gi gas price",
|
||||||
mustParseDecCoins("0.001ukava"),
|
mustParseDecCoins("0.001ua0gi"),
|
||||||
mustParseDecCoins("0.001ukava"),
|
mustParseDecCoins("0.001ua0gi"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price, min akava price",
|
"zero ua0gi gas price, min neuron price",
|
||||||
mustParseDecCoins("0ukava;100000akava"),
|
mustParseDecCoins("0ua0gi;100000neuron"),
|
||||||
mustParseDecCoins("0ukava"), // akava is removed
|
mustParseDecCoins("0ua0gi"), // neuron is removed
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price, min akava price, other token",
|
"zero ua0gi gas price, min neuron price, other token",
|
||||||
mustParseDecCoins("0ukava;100000akava;0.001other"),
|
mustParseDecCoins("0ua0gi;100000neuron;0.001other"),
|
||||||
mustParseDecCoins("0ukava;0.001other"), // akava is removed
|
mustParseDecCoins("0ua0gi;0.001other"), // neuron is removed
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non-zero ukava gas price, min akava price",
|
"non-zero ua0gi gas price, min neuron price",
|
||||||
mustParseDecCoins("0.25ukava;100000akava;0.001other"),
|
mustParseDecCoins("0.25ua0gi;100000neuron;0.001other"),
|
||||||
mustParseDecCoins("0.25ukava;0.001other"), // akava is removed
|
mustParseDecCoins("0.25ua0gi;0.001other"), // neuron is removed
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
errorsmod "cosmossdk.io/errors"
|
errorsmod "cosmossdk.io/errors"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sdk.AnteDecorator = VestingAccountDecorator{}
|
var _ sdk.AnteDecorator = VestingAccountDecorator{}
|
||||||
@ -17,9 +16,9 @@ type VestingAccountDecorator struct {
|
|||||||
func NewVestingAccountDecorator() VestingAccountDecorator {
|
func NewVestingAccountDecorator() VestingAccountDecorator {
|
||||||
return VestingAccountDecorator{
|
return VestingAccountDecorator{
|
||||||
disabledMsgTypeUrls: []string{
|
disabledMsgTypeUrls: []string{
|
||||||
sdk.MsgTypeURL(&vesting.MsgCreateVestingAccount{}),
|
// sdk.MsgTypeURL(&vesting.MsgCreateVestingAccount{}),
|
||||||
sdk.MsgTypeURL(&vesting.MsgCreatePermanentLockedAccount{}),
|
// sdk.MsgTypeURL(&vesting.MsgCreatePermanentLockedAccount{}),
|
||||||
sdk.MsgTypeURL(&vesting.MsgCreatePeriodicVestingAccount{}),
|
// sdk.MsgTypeURL(&vesting.MsgCreatePeriodicVestingAccount{}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,14 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/simapp/helpers"
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/kava-labs/kava/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
||||||
@ -33,7 +34,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"MsgCreateVestingAccount",
|
"MsgCreateVestingAccount",
|
||||||
vesting.NewMsgCreateVestingAccount(
|
vesting.NewMsgCreateVestingAccount(
|
||||||
testAddresses[0], testAddresses[1],
|
testAddresses[0], testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
@ -44,7 +45,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"MsgCreateVestingAccount",
|
"MsgCreateVestingAccount",
|
||||||
vesting.NewMsgCreatePermanentLockedAccount(
|
vesting.NewMsgCreatePermanentLockedAccount(
|
||||||
testAddresses[0], testAddresses[1],
|
testAddresses[0], testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||||
),
|
),
|
||||||
true,
|
true,
|
||||||
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||||
@ -63,7 +64,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"other messages not affected",
|
"other messages not affected",
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0], testAddresses[1],
|
testAddresses[0], testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
"",
|
"",
|
||||||
@ -72,14 +73,14 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
tx, err := helpers.GenSignedMockTx(
|
tx, err := sims.GenSignedMockTx(
|
||||||
rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
txConfig,
|
txConfig,
|
||||||
[]sdk.Msg{
|
[]sdk.Msg{
|
||||||
tt.msg,
|
tt.msg,
|
||||||
},
|
},
|
||||||
sdk.NewCoins(),
|
sdk.NewCoins(),
|
||||||
helpers.DefaultGenTxGas,
|
sims.DefaultGenTxGas,
|
||||||
"testing-chain-id",
|
"testing-chain-id",
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
[]uint64{0},
|
[]uint64{0},
|
||||||
|
653
app/app.go
653
app/app.go
File diff suppressed because it is too large
Load Diff
@ -8,25 +8,29 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
|
db "github.com/cometbft/cometbft-db"
|
||||||
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"
|
||||||
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||||
|
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
|
||||||
|
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
|
||||||
db "github.com/tendermint/tm-db"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewApp(t *testing.T) {
|
func TestNewApp(t *testing.T) {
|
||||||
SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
NewApp(
|
NewApp(
|
||||||
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
||||||
db.NewMemDB(),
|
db.NewMemDB(),
|
||||||
DefaultNodeHome,
|
chaincfg.DefaultNodeHome,
|
||||||
nil,
|
nil,
|
||||||
MakeEncodingConfig(),
|
MakeEncodingConfig(),
|
||||||
DefaultOptions,
|
DefaultOptions,
|
||||||
@ -34,9 +38,9 @@ func TestNewApp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExport(t *testing.T) {
|
func TestExport(t *testing.T) {
|
||||||
SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
db := db.NewMemDB()
|
db := db.NewMemDB()
|
||||||
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions)
|
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, chaincfg.DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
||||||
|
|
||||||
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())
|
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())
|
||||||
|
|
||||||
@ -45,21 +49,23 @@ func TestExport(t *testing.T) {
|
|||||||
|
|
||||||
initRequest := abci.RequestInitChain{
|
initRequest := abci.RequestInitChain{
|
||||||
Time: time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
|
Time: time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC),
|
||||||
ChainId: "kavatest_1-1",
|
ChainId: TestChainId,
|
||||||
InitialHeight: 1,
|
InitialHeight: 1,
|
||||||
ConsensusParams: tmtypes.TM2PB.ConsensusParams(tmtypes.DefaultConsensusParams()),
|
ConsensusParams: sims.DefaultConsensusParams,
|
||||||
Validators: nil,
|
Validators: nil,
|
||||||
AppStateBytes: stateBytes,
|
AppStateBytes: stateBytes,
|
||||||
}
|
}
|
||||||
app.InitChain(initRequest)
|
app.InitChain(initRequest)
|
||||||
app.Commit()
|
app.Commit()
|
||||||
|
|
||||||
exportedApp, err := app.ExportAppStateAndValidators(false, []string{})
|
exportedApp, err := app.ExportAppStateAndValidators(false, []string{}, []string{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Assume each module is exported correctly, so only check modules in genesis are present in export
|
// Assume each module is exported correctly, so only check modules in genesis are present in export
|
||||||
initialModules, err := unmarshalJSONKeys(initRequest.AppStateBytes)
|
initialModules, err := unmarshalJSONKeys(initRequest.AppStateBytes)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
// note ibctm is only registered in the BasicManager and not module manager so can be ignored
|
||||||
|
initialModules = removeIbcTmModule(initialModules)
|
||||||
exportedModules, err := unmarshalJSONKeys(exportedApp.AppState)
|
exportedModules, err := unmarshalJSONKeys(exportedApp.AppState)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.ElementsMatch(t, initialModules, exportedModules)
|
assert.ElementsMatch(t, initialModules, exportedModules)
|
||||||
@ -143,3 +149,13 @@ func unmarshalJSONKeys(jsonBytes []byte) ([]string, error) {
|
|||||||
|
|
||||||
return keys, nil
|
return keys, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeIbcTmModule(modules []string) []string {
|
||||||
|
var result []string
|
||||||
|
for _, str := range modules {
|
||||||
|
if str != ibctm.ModuleName && str != solomachine.ModuleName {
|
||||||
|
result = append(result, str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
|
||||||
|
|
||||||
const (
|
|
||||||
// Bech32MainPrefix defines the Bech32 prefix for account addresses
|
|
||||||
Bech32MainPrefix = "kava"
|
|
||||||
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
|
||||||
Bech32PrefixAccPub = Bech32MainPrefix + "pub"
|
|
||||||
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
|
||||||
Bech32PrefixValAddr = Bech32MainPrefix + "val" + "oper"
|
|
||||||
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
|
||||||
Bech32PrefixValPub = Bech32MainPrefix + "val" + "oper" + "pub"
|
|
||||||
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
|
||||||
Bech32PrefixConsAddr = Bech32MainPrefix + "val" + "cons"
|
|
||||||
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
|
||||||
Bech32PrefixConsPub = Bech32MainPrefix + "val" + "cons" + "pub"
|
|
||||||
|
|
||||||
Bip44CoinType = 459 // see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
|
||||||
)
|
|
||||||
|
|
||||||
// SetSDKConfig configures the global config with kava app specific parameters.
|
|
||||||
// It does not seal the config to allow modification in tests.
|
|
||||||
func SetSDKConfig() *sdk.Config {
|
|
||||||
config := sdk.GetConfig()
|
|
||||||
SetBech32AddressPrefixes(config)
|
|
||||||
SetBip44CoinType(config)
|
|
||||||
return config
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBech32AddressPrefixes sets the global prefix to be used when serializing addresses to bech32 strings.
|
|
||||||
func SetBech32AddressPrefixes(config *sdk.Config) {
|
|
||||||
config.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32PrefixAccPub)
|
|
||||||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
|
||||||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
|
|
||||||
func SetBip44CoinType(config *sdk.Config) {
|
|
||||||
config.SetCoinType(Bip44CoinType)
|
|
||||||
}
|
|
@ -3,7 +3,7 @@ package app
|
|||||||
import (
|
import (
|
||||||
enccodec "github.com/evmos/ethermint/encoding/codec"
|
enccodec "github.com/evmos/ethermint/encoding/codec"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app/params"
|
"github.com/0glabs/0g-chain/app/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MakeEncodingConfig creates an EncodingConfig and registers the app's types on it.
|
// MakeEncodingConfig creates an EncodingConfig and registers the app's types on it.
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||||
|
|
||||||
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
servertypes "github.com/cosmos/cosmos-sdk/server/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// ExportAppStateAndValidators export the state of the app for a genesis file
|
// ExportAppStateAndValidators export the state of the app for a genesis file
|
||||||
func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string,
|
func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string, modulesToExport []string,
|
||||||
) (servertypes.ExportedApp, error) {
|
) (servertypes.ExportedApp, error) {
|
||||||
// as if they could withdraw from the start of the next block
|
// as if they could withdraw from the start of the next block
|
||||||
// block time is not available and defaults to Jan 1st, 0001
|
// block time is not available and defaults to Jan 1st, 0001
|
||||||
@ -26,7 +26,7 @@ func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []
|
|||||||
app.prepForZeroHeightGenesis(ctx, jailWhiteList)
|
app.prepForZeroHeightGenesis(ctx, jailWhiteList)
|
||||||
}
|
}
|
||||||
|
|
||||||
genState := app.mm.ExportGenesis(ctx, app.appCodec)
|
genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
|
||||||
newAppState, err := json.MarshalIndent(genState, "", " ")
|
newAppState, err := json.MarshalIndent(genState, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return servertypes.ExportedApp{}, err
|
return servertypes.ExportedApp{}, err
|
||||||
@ -42,7 +42,7 @@ func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []
|
|||||||
|
|
||||||
// prepare for fresh start at zero height
|
// prepare for fresh start at zero height
|
||||||
// NOTE zero height genesis is a temporary feature which will be deprecated
|
// NOTE zero height genesis is a temporary feature which will be deprecated
|
||||||
// in favour of export at a block height
|
// in favour of export at a block height
|
||||||
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []string) {
|
func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []string) {
|
||||||
applyWhiteList := false
|
applyWhiteList := false
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Package params defines the simulation parameters for the Kava app.
|
Package params defines the simulation parameters for the 0gChain app.
|
||||||
|
|
||||||
It contains the default weights used for each transaction used on the module's
|
It contains the default weights used for each transaction used on the module's
|
||||||
simulation. These weights define the chance for a transaction to be simulated at
|
simulation. These weights define the chance for a transaction to be simulated at
|
||||||
|
@ -8,10 +8,6 @@ import (
|
|||||||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
earnkeeper "github.com/kava-labs/kava/x/earn/keeper"
|
|
||||||
liquidkeeper "github.com/kava-labs/kava/x/liquid/keeper"
|
|
||||||
liquidtypes "github.com/kava-labs/kava/x/liquid/types"
|
|
||||||
savingskeeper "github.com/kava-labs/kava/x/savings/keeper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ govv1.TallyHandler = TallyHandler{}
|
var _ govv1.TallyHandler = TallyHandler{}
|
||||||
@ -20,23 +16,16 @@ var _ govv1.TallyHandler = TallyHandler{}
|
|||||||
type TallyHandler struct {
|
type TallyHandler struct {
|
||||||
gk govkeeper.Keeper
|
gk govkeeper.Keeper
|
||||||
stk stakingkeeper.Keeper
|
stk stakingkeeper.Keeper
|
||||||
svk savingskeeper.Keeper
|
|
||||||
ek earnkeeper.Keeper
|
|
||||||
lk liquidkeeper.Keeper
|
|
||||||
bk bankkeeper.Keeper
|
bk bankkeeper.Keeper
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTallyHandler creates a new tally handler.
|
// NewTallyHandler creates a new tally handler.
|
||||||
func NewTallyHandler(
|
func NewTallyHandler(
|
||||||
gk govkeeper.Keeper, stk stakingkeeper.Keeper, svk savingskeeper.Keeper,
|
gk govkeeper.Keeper, stk stakingkeeper.Keeper, bk bankkeeper.Keeper,
|
||||||
ek earnkeeper.Keeper, lk liquidkeeper.Keeper, bk bankkeeper.Keeper,
|
|
||||||
) TallyHandler {
|
) TallyHandler {
|
||||||
return TallyHandler{
|
return TallyHandler{
|
||||||
gk: gk,
|
gk: gk,
|
||||||
stk: stk,
|
stk: stk,
|
||||||
svk: svk,
|
|
||||||
ek: ek,
|
|
||||||
lk: lk,
|
|
||||||
bk: bk,
|
bk: bk,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,34 +94,34 @@ func (th TallyHandler) Tally(
|
|||||||
})
|
})
|
||||||
|
|
||||||
// get voter bkava and update total voting power and results
|
// get voter bkava and update total voting power and results
|
||||||
addrBkava := th.getAddrBkava(ctx, voter).toCoins()
|
// addrBkava := th.getAddrBkava(ctx, voter).toCoins()
|
||||||
for _, coin := range addrBkava {
|
// for _, coin := range addrBkava {
|
||||||
valAddr, err := liquidtypes.ParseLiquidStakingTokenDenom(coin.Denom)
|
// valAddr, err := liquidtypes.ParseLiquidStakingTokenDenom(coin.Denom)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
break
|
// break
|
||||||
}
|
// }
|
||||||
|
|
||||||
// reduce delegator shares by the amount of voter bkava for the validator
|
// // reduce delegator shares by the amount of voter bkava for the validator
|
||||||
valAddrStr := valAddr.String()
|
// valAddrStr := valAddr.String()
|
||||||
if val, ok := currValidators[valAddrStr]; ok {
|
// if val, ok := currValidators[valAddrStr]; ok {
|
||||||
val.DelegatorDeductions = val.DelegatorDeductions.Add(sdk.NewDecFromInt(coin.Amount))
|
// val.DelegatorDeductions = val.DelegatorDeductions.Add(sdk.NewDecFromInt(coin.Amount))
|
||||||
currValidators[valAddrStr] = val
|
// currValidators[valAddrStr] = val
|
||||||
}
|
// }
|
||||||
|
|
||||||
// votingPower = amount of ukava coin
|
// // votingPower = amount of ukava coin
|
||||||
stakedCoins, err := th.lk.GetStakedTokensForDerivatives(ctx, sdk.NewCoins(coin))
|
// stakedCoins, err := th.lk.GetStakedTokensForDerivatives(ctx, sdk.NewCoins(coin))
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
// error is returned only if the bkava denom is incorrect, which should never happen here.
|
// // error is returned only if the bkava denom is incorrect, which should never happen here.
|
||||||
panic(err)
|
// panic(err)
|
||||||
}
|
// }
|
||||||
votingPower := sdk.NewDecFromInt(stakedCoins.Amount)
|
// votingPower := sdk.NewDecFromInt(stakedCoins.Amount)
|
||||||
|
|
||||||
for _, option := range vote.Options {
|
// for _, option := range vote.Options {
|
||||||
subPower := votingPower.Mul(sdk.MustNewDecFromStr(option.Weight))
|
// subPower := votingPower.Mul(sdk.MustNewDecFromStr(option.Weight))
|
||||||
results[option.Option] = results[option.Option].Add(subPower)
|
// results[option.Option] = results[option.Option].Add(subPower)
|
||||||
}
|
// }
|
||||||
totalVotingPower = totalVotingPower.Add(votingPower)
|
// totalVotingPower = totalVotingPower.Add(votingPower)
|
||||||
}
|
// }
|
||||||
|
|
||||||
th.gk.DeleteVote(ctx, vote.ProposalId, voter)
|
th.gk.DeleteVote(ctx, vote.ProposalId, voter)
|
||||||
return false
|
return false
|
||||||
@ -154,7 +143,7 @@ func (th TallyHandler) Tally(
|
|||||||
totalVotingPower = totalVotingPower.Add(votingPower)
|
totalVotingPower = totalVotingPower.Add(votingPower)
|
||||||
}
|
}
|
||||||
|
|
||||||
tallyParams := th.gk.GetTallyParams(ctx)
|
tallyParams := th.gk.GetParams(ctx)
|
||||||
tallyResults = govv1.NewTallyResultFromMap(results)
|
tallyResults = govv1.NewTallyResultFromMap(results)
|
||||||
|
|
||||||
// TODO: Upgrade the spec to cover all of these cases & remove pseudocode.
|
// TODO: Upgrade the spec to cover all of these cases & remove pseudocode.
|
||||||
@ -166,7 +155,7 @@ func (th TallyHandler) Tally(
|
|||||||
// If there is not enough quorum of votes, the proposal fails
|
// If there is not enough quorum of votes, the proposal fails
|
||||||
percentVoting := totalVotingPower.Quo(sdk.NewDecFromInt(th.stk.TotalBondedTokens(ctx)))
|
percentVoting := totalVotingPower.Quo(sdk.NewDecFromInt(th.stk.TotalBondedTokens(ctx)))
|
||||||
if percentVoting.LT(sdk.MustNewDecFromStr(tallyParams.Quorum)) {
|
if percentVoting.LT(sdk.MustNewDecFromStr(tallyParams.Quorum)) {
|
||||||
return false, true, tallyResults
|
return false, tallyParams.BurnVoteQuorum, tallyResults
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no one votes (everyone abstains), proposal fails
|
// If no one votes (everyone abstains), proposal fails
|
||||||
@ -176,7 +165,7 @@ func (th TallyHandler) Tally(
|
|||||||
|
|
||||||
// If more than 1/3 of voters veto, proposal fails
|
// If more than 1/3 of voters veto, proposal fails
|
||||||
if results[govv1.OptionNoWithVeto].Quo(totalVotingPower).GT(sdk.MustNewDecFromStr(tallyParams.VetoThreshold)) {
|
if results[govv1.OptionNoWithVeto].Quo(totalVotingPower).GT(sdk.MustNewDecFromStr(tallyParams.VetoThreshold)) {
|
||||||
return false, true, tallyResults
|
return false, tallyParams.BurnVoteVeto, tallyResults
|
||||||
}
|
}
|
||||||
|
|
||||||
// If more than 1/2 of non-abstaining voters vote Yes, proposal passes
|
// If more than 1/2 of non-abstaining voters vote Yes, proposal passes
|
||||||
@ -219,38 +208,38 @@ func (th TallyHandler) getAddrBkava(ctx sdk.Context, addr sdk.AccAddress) bkavaB
|
|||||||
|
|
||||||
// addBkavaFromWallet adds all addr balances of bkava in x/bank.
|
// addBkavaFromWallet adds all addr balances of bkava in x/bank.
|
||||||
func (th TallyHandler) addBkavaFromWallet(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
func (th TallyHandler) addBkavaFromWallet(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
||||||
coins := th.bk.GetAllBalances(ctx, addr)
|
// coins := th.bk.GetAllBalances(ctx, addr)
|
||||||
for _, coin := range coins {
|
// for _, coin := range coins {
|
||||||
if th.lk.IsDerivativeDenom(ctx, coin.Denom) {
|
// if th.lk.IsDerivativeDenom(ctx, coin.Denom) {
|
||||||
bkava.add(coin)
|
// bkava.add(coin)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// addBkavaFromSavings adds all addr deposits of bkava in x/savings.
|
// addBkavaFromSavings adds all addr deposits of bkava in x/savings.
|
||||||
func (th TallyHandler) addBkavaFromSavings(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
func (th TallyHandler) addBkavaFromSavings(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
||||||
deposit, found := th.svk.GetDeposit(ctx, addr)
|
// deposit, found := th.svk.GetDeposit(ctx, addr)
|
||||||
if !found {
|
// if !found {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
for _, coin := range deposit.Amount {
|
// for _, coin := range deposit.Amount {
|
||||||
if th.lk.IsDerivativeDenom(ctx, coin.Denom) {
|
// if th.lk.IsDerivativeDenom(ctx, coin.Denom) {
|
||||||
bkava.add(coin)
|
// bkava.add(coin)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// addBkavaFromEarn adds all addr deposits of bkava in x/earn.
|
// addBkavaFromEarn adds all addr deposits of bkava in x/earn.
|
||||||
func (th TallyHandler) addBkavaFromEarn(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
func (th TallyHandler) addBkavaFromEarn(ctx sdk.Context, addr sdk.AccAddress, bkava bkavaByDenom) {
|
||||||
shares, found := th.ek.GetVaultAccountShares(ctx, addr)
|
// shares, found := th.ek.GetVaultAccountShares(ctx, addr)
|
||||||
if !found {
|
// if !found {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
for _, share := range shares {
|
// for _, share := range shares {
|
||||||
if th.lk.IsDerivativeDenom(ctx, share.Denom) {
|
// if th.lk.IsDerivativeDenom(ctx, share.Denom) {
|
||||||
if coin, err := th.ek.ConvertToAssets(ctx, share); err == nil {
|
// if coin, err := th.ek.ConvertToAssets(ctx, share); err == nil {
|
||||||
bkava.add(coin)
|
// bkava.add(coin)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
@ -15,10 +16,6 @@ import (
|
|||||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
||||||
|
|
||||||
earntypes "github.com/kava-labs/kava/x/earn/types"
|
|
||||||
liquidtypes "github.com/kava-labs/kava/x/liquid/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// d is an alias for sdk.MustNewDecFromStr
|
// d is an alias for sdk.MustNewDecFromStr
|
||||||
@ -44,12 +41,13 @@ func (suite *tallyHandlerSuite) SetupTest() {
|
|||||||
genesisTime := time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)
|
genesisTime := time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
suite.ctx = suite.app.NewContext(false, tmproto.Header{Height: 1, Time: genesisTime})
|
suite.ctx = suite.app.NewContext(false, tmproto.Header{Height: 1, Time: genesisTime})
|
||||||
|
|
||||||
suite.staking = stakingHelper{suite.app.GetStakingKeeper()}
|
stakingKeeper := *suite.app.GetStakingKeeper()
|
||||||
|
suite.staking = stakingHelper{stakingKeeper}
|
||||||
suite.staking.setBondDenom(suite.ctx, "ukava")
|
suite.staking.setBondDenom(suite.ctx, "ukava")
|
||||||
|
|
||||||
suite.tallier = NewTallyHandler(
|
suite.tallier = NewTallyHandler(
|
||||||
suite.app.GetGovKeeper(),
|
suite.app.GetGovKeeper(),
|
||||||
suite.app.GetStakingKeeper(),
|
stakingKeeper,
|
||||||
suite.app.GetSavingsKeeper(),
|
suite.app.GetSavingsKeeper(),
|
||||||
suite.app.GetEarnKeeper(),
|
suite.app.GetEarnKeeper(),
|
||||||
suite.app.GetLiquidKeeper(),
|
suite.app.GetLiquidKeeper(),
|
||||||
@ -215,11 +213,12 @@ func (suite *tallyHandlerSuite) TestTallyOutcomes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *tallyHandlerSuite) setTallyParams(quorum, threshold, veto sdk.Dec) {
|
func (suite *tallyHandlerSuite) setTallyParams(quorum, threshold, veto sdk.Dec) {
|
||||||
suite.app.GetGovKeeper().SetTallyParams(suite.ctx, govv1.TallyParams{
|
params := suite.app.GetGovKeeper().GetParams(suite.ctx)
|
||||||
Quorum: quorum.String(),
|
params.Quorum = quorum.String()
|
||||||
Threshold: threshold.String(),
|
params.Threshold = threshold.String()
|
||||||
VetoThreshold: veto.String(),
|
params.VetoThreshold = veto.String()
|
||||||
})
|
params.BurnVoteQuorum = true
|
||||||
|
suite.app.GetGovKeeper().SetParams(suite.ctx, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *tallyHandlerSuite) voteOnProposal(
|
func (suite *tallyHandlerSuite) voteOnProposal(
|
||||||
@ -240,7 +239,7 @@ func (suite *tallyHandlerSuite) voteOnProposal(
|
|||||||
|
|
||||||
func (suite *tallyHandlerSuite) createProposal() govv1.Proposal {
|
func (suite *tallyHandlerSuite) createProposal() govv1.Proposal {
|
||||||
gk := suite.app.GetGovKeeper()
|
gk := suite.app.GetGovKeeper()
|
||||||
deposit := gk.GetDepositParams(suite.ctx).MinDeposit
|
deposit := gk.GetParams(suite.ctx).MinDeposit
|
||||||
proposer := suite.createAccount(deposit...)
|
proposer := suite.createAccount(deposit...)
|
||||||
|
|
||||||
msg, err := govv1beta1.NewMsgSubmitProposal(
|
msg, err := govv1beta1.NewMsgSubmitProposal(
|
||||||
@ -250,7 +249,7 @@ func (suite *tallyHandlerSuite) createProposal() govv1.Proposal {
|
|||||||
)
|
)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
msgServerv1 := govkeeper.NewMsgServerImpl(gk)
|
msgServerv1 := govkeeper.NewMsgServerImpl(&gk)
|
||||||
|
|
||||||
govAcct := gk.GetGovernanceAccount(suite.ctx).GetAddress()
|
govAcct := gk.GetGovernanceAccount(suite.ctx).GetAddress()
|
||||||
msgServer := govkeeper.NewLegacyMsgServerImpl(govAcct.String(), msgServerv1)
|
msgServer := govkeeper.NewLegacyMsgServerImpl(govAcct.String(), msgServerv1)
|
||||||
@ -269,39 +268,40 @@ func (suite *tallyHandlerSuite) newBondCoin(amount sdkmath.Int) sdk.Coin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *tallyHandlerSuite) allowBKavaEarnDeposits() {
|
func (suite *tallyHandlerSuite) allowBKavaEarnDeposits() {
|
||||||
ek := suite.app.GetEarnKeeper()
|
// ek := suite.app.GetEarnKeeper()
|
||||||
earnParams := ek.GetParams(suite.ctx)
|
// earnParams := ek.GetParams(suite.ctx)
|
||||||
|
|
||||||
vault := earntypes.NewAllowedVault(
|
// vault := earntypes.NewAllowedVault(
|
||||||
liquidtypes.DefaultDerivativeDenom,
|
// liquidtypes.DefaultDerivativeDenom,
|
||||||
earntypes.StrategyTypes{earntypes.STRATEGY_TYPE_SAVINGS},
|
// earntypes.StrategyTypes{earntypes.STRATEGY_TYPE_SAVINGS},
|
||||||
false,
|
// false,
|
||||||
nil,
|
// nil,
|
||||||
)
|
// )
|
||||||
|
|
||||||
earnParams.AllowedVaults = append(earnParams.AllowedVaults, vault)
|
// earnParams.AllowedVaults = append(earnParams.AllowedVaults, vault)
|
||||||
ek.SetParams(suite.ctx, earnParams)
|
// ek.SetParams(suite.ctx, earnParams)
|
||||||
|
|
||||||
sk := suite.app.GetSavingsKeeper()
|
// sk := suite.app.GetSavingsKeeper()
|
||||||
savingsParams := sk.GetParams(suite.ctx)
|
// savingsParams := sk.GetParams(suite.ctx)
|
||||||
savingsParams.SupportedDenoms = append(savingsParams.SupportedDenoms, liquidtypes.DefaultDerivativeDenom)
|
// savingsParams.SupportedDenoms = append(savingsParams.SupportedDenoms, liquidtypes.DefaultDerivativeDenom)
|
||||||
sk.SetParams(suite.ctx, savingsParams)
|
// sk.SetParams(suite.ctx, savingsParams)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *tallyHandlerSuite) earnDeposit(owner sdk.AccAddress, derivative sdk.Coin) {
|
func (suite *tallyHandlerSuite) earnDeposit(owner sdk.AccAddress, derivative sdk.Coin) {
|
||||||
ek := suite.app.GetEarnKeeper()
|
// ek := suite.app.GetEarnKeeper()
|
||||||
|
|
||||||
err := ek.Deposit(suite.ctx, owner, derivative, earntypes.STRATEGY_TYPE_SAVINGS)
|
// err := ek.Deposit(suite.ctx, owner, derivative, earntypes.STRATEGY_TYPE_SAVINGS)
|
||||||
suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *tallyHandlerSuite) mintDerivative(owner sdk.AccAddress, validator sdk.ValAddress, amount sdkmath.Int) sdk.Coin {
|
func (suite *tallyHandlerSuite) mintDerivative(owner sdk.AccAddress, validator sdk.ValAddress, amount sdkmath.Int) sdk.Coin {
|
||||||
lk := suite.app.GetLiquidKeeper()
|
// lk := suite.app.GetLiquidKeeper()
|
||||||
|
|
||||||
minted, err := lk.MintDerivative(suite.ctx, owner, validator, suite.newBondCoin(amount))
|
// minted, err := lk.MintDerivative(suite.ctx, owner, validator, suite.newBondCoin(amount))
|
||||||
suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
return minted
|
// return minted
|
||||||
|
return sdk.NewCoin("ukava", amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *tallyHandlerSuite) delegateToNewBondedValidator(delegator sdk.AccAddress, amount sdkmath.Int) stakingtypes.ValidatorI {
|
func (suite *tallyHandlerSuite) delegateToNewBondedValidator(delegator sdk.AccAddress, amount sdkmath.Int) stakingtypes.ValidatorI {
|
||||||
@ -369,7 +369,7 @@ func (h stakingHelper) createUnbondedValidator(ctx sdk.Context, address sdk.ValA
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
msgServer := stakingkeeper.NewMsgServerImpl(h.keeper)
|
msgServer := stakingkeeper.NewMsgServerImpl(&h.keeper)
|
||||||
_, err = msgServer.CreateValidator(sdk.WrapSDKContext(ctx), msg)
|
_, err = msgServer.CreateValidator(sdk.WrapSDKContext(ctx), msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -389,7 +389,7 @@ func (h stakingHelper) delegate(ctx sdk.Context, delegator sdk.AccAddress, valid
|
|||||||
h.newBondCoin(ctx, amount),
|
h.newBondCoin(ctx, amount),
|
||||||
)
|
)
|
||||||
|
|
||||||
msgServer := stakingkeeper.NewMsgServerImpl(h.keeper)
|
msgServer := stakingkeeper.NewMsgServerImpl(&h.keeper)
|
||||||
_, err := msgServer.Delegate(sdk.WrapSDKContext(ctx), msg)
|
_, err := msgServer.Delegate(sdk.WrapSDKContext(ctx), msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sdk.Dec{}, err
|
return sdk.Dec{}, err
|
||||||
|
@ -13,10 +13,10 @@ import (
|
|||||||
// All methods return the builder so method calls can be chained together.
|
// All methods return the builder so method calls can be chained together.
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// // create a single account genesis state
|
|
||||||
// builder := NewAuthBankGenesisBuilder().WithSimpleAccount(testUserAddress, testCoins)
|
|
||||||
// genesisState := builder.BuildMarshalled()
|
|
||||||
//
|
//
|
||||||
|
// // create a single account genesis state
|
||||||
|
// builder := NewAuthBankGenesisBuilder().WithSimpleAccount(testUserAddress, testCoins)
|
||||||
|
// genesisState := builder.BuildMarshalled()
|
||||||
type AuthBankGenesisBuilder struct {
|
type AuthBankGenesisBuilder struct {
|
||||||
AuthGenesis authtypes.GenesisState
|
AuthGenesis authtypes.GenesisState
|
||||||
BankGenesis banktypes.GenesisState
|
BankGenesis banktypes.GenesisState
|
||||||
|
@ -9,6 +9,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
|
tmdb "github.com/cometbft/cometbft-db"
|
||||||
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
|
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||||
|
tmtypes "github.com/cometbft/cometbft/types"
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||||
@ -35,36 +40,22 @@ import (
|
|||||||
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
|
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
|
||||||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
|
||||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
|
||||||
tmdb "github.com/tendermint/tm-db"
|
|
||||||
|
|
||||||
auctionkeeper "github.com/kava-labs/kava/x/auction/keeper"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
bep3keeper "github.com/kava-labs/kava/x/bep3/keeper"
|
bep3keeper "github.com/0glabs/0g-chain/x/bep3/keeper"
|
||||||
cdpkeeper "github.com/kava-labs/kava/x/cdp/keeper"
|
committeekeeper "github.com/0glabs/0g-chain/x/committee/keeper"
|
||||||
committeekeeper "github.com/kava-labs/kava/x/committee/keeper"
|
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
communitykeeper "github.com/kava-labs/kava/x/community/keeper"
|
issuancekeeper "github.com/0glabs/0g-chain/x/issuance/keeper"
|
||||||
earnkeeper "github.com/kava-labs/kava/x/earn/keeper"
|
pricefeedkeeper "github.com/0glabs/0g-chain/x/pricefeed/keeper"
|
||||||
evmutilkeeper "github.com/kava-labs/kava/x/evmutil/keeper"
|
|
||||||
hardkeeper "github.com/kava-labs/kava/x/hard/keeper"
|
|
||||||
incentivekeeper "github.com/kava-labs/kava/x/incentive/keeper"
|
|
||||||
issuancekeeper "github.com/kava-labs/kava/x/issuance/keeper"
|
|
||||||
kavadistkeeper "github.com/kava-labs/kava/x/kavadist/keeper"
|
|
||||||
liquidkeeper "github.com/kava-labs/kava/x/liquid/keeper"
|
|
||||||
pricefeedkeeper "github.com/kava-labs/kava/x/pricefeed/keeper"
|
|
||||||
routerkeeper "github.com/kava-labs/kava/x/router/keeper"
|
|
||||||
savingskeeper "github.com/kava-labs/kava/x/savings/keeper"
|
|
||||||
swapkeeper "github.com/kava-labs/kava/x/swap/keeper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emptyTime time.Time
|
emptyTime time.Time
|
||||||
testChainID = "kavatest_1-1"
|
|
||||||
defaultInitialHeight int64 = 1
|
defaultInitialHeight int64 = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const TestChainId = "kavatest_2221-1"
|
||||||
|
|
||||||
// TestApp is a simple wrapper around an App. It exposes internal keepers for use in integration tests.
|
// TestApp is a simple wrapper around an App. It exposes internal keepers for use in integration tests.
|
||||||
// This file also contains test helpers. Ideally they would be in separate package.
|
// This file also contains test helpers. Ideally they would be in separate package.
|
||||||
// Basic Usage:
|
// Basic Usage:
|
||||||
@ -88,7 +79,7 @@ type TestApp struct {
|
|||||||
//
|
//
|
||||||
// Note, it also sets the sdk config with the app's address prefix, coin type, etc.
|
// Note, it also sets the sdk config with the app's address prefix, coin type, etc.
|
||||||
func NewTestApp() TestApp {
|
func NewTestApp() TestApp {
|
||||||
SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
|
|
||||||
return NewTestAppFromSealed()
|
return NewTestAppFromSealed()
|
||||||
}
|
}
|
||||||
@ -99,7 +90,10 @@ func NewTestAppFromSealed() TestApp {
|
|||||||
|
|
||||||
encCfg := MakeEncodingConfig()
|
encCfg := MakeEncodingConfig()
|
||||||
|
|
||||||
app := NewApp(log.NewNopLogger(), db, DefaultNodeHome, nil, encCfg, DefaultOptions)
|
app := NewApp(
|
||||||
|
log.NewNopLogger(), db, chaincfg.DefaultNodeHome, nil,
|
||||||
|
encCfg, DefaultOptions, baseapp.SetChainID(TestChainId),
|
||||||
|
)
|
||||||
return TestApp{App: *app}
|
return TestApp{App: *app}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,30 +101,19 @@ func NewTestAppFromSealed() TestApp {
|
|||||||
func (tApp TestApp) GetAccountKeeper() authkeeper.AccountKeeper { return tApp.accountKeeper }
|
func (tApp TestApp) GetAccountKeeper() authkeeper.AccountKeeper { return tApp.accountKeeper }
|
||||||
func (tApp TestApp) GetBankKeeper() bankkeeper.Keeper { return tApp.bankKeeper }
|
func (tApp TestApp) GetBankKeeper() bankkeeper.Keeper { return tApp.bankKeeper }
|
||||||
func (tApp TestApp) GetMintKeeper() mintkeeper.Keeper { return tApp.mintKeeper }
|
func (tApp TestApp) GetMintKeeper() mintkeeper.Keeper { return tApp.mintKeeper }
|
||||||
func (tApp TestApp) GetStakingKeeper() stakingkeeper.Keeper { return tApp.stakingKeeper }
|
func (tApp TestApp) GetStakingKeeper() *stakingkeeper.Keeper { return tApp.stakingKeeper }
|
||||||
func (tApp TestApp) GetSlashingKeeper() slashingkeeper.Keeper { return tApp.slashingKeeper }
|
func (tApp TestApp) GetSlashingKeeper() slashingkeeper.Keeper { return tApp.slashingKeeper }
|
||||||
func (tApp TestApp) GetDistrKeeper() distkeeper.Keeper { return tApp.distrKeeper }
|
func (tApp TestApp) GetDistrKeeper() distkeeper.Keeper { return tApp.distrKeeper }
|
||||||
func (tApp TestApp) GetGovKeeper() govkeeper.Keeper { return tApp.govKeeper }
|
func (tApp TestApp) GetGovKeeper() govkeeper.Keeper { return tApp.govKeeper }
|
||||||
func (tApp TestApp) GetCrisisKeeper() crisiskeeper.Keeper { return tApp.crisisKeeper }
|
func (tApp TestApp) GetCrisisKeeper() crisiskeeper.Keeper { return tApp.crisisKeeper }
|
||||||
func (tApp TestApp) GetParamsKeeper() paramskeeper.Keeper { return tApp.paramsKeeper }
|
func (tApp TestApp) GetParamsKeeper() paramskeeper.Keeper { return tApp.paramsKeeper }
|
||||||
func (tApp TestApp) GetKavadistKeeper() kavadistkeeper.Keeper { return tApp.kavadistKeeper }
|
|
||||||
func (tApp TestApp) GetAuctionKeeper() auctionkeeper.Keeper { return tApp.auctionKeeper }
|
|
||||||
func (tApp TestApp) GetIssuanceKeeper() issuancekeeper.Keeper { return tApp.issuanceKeeper }
|
func (tApp TestApp) GetIssuanceKeeper() issuancekeeper.Keeper { return tApp.issuanceKeeper }
|
||||||
func (tApp TestApp) GetBep3Keeper() bep3keeper.Keeper { return tApp.bep3Keeper }
|
func (tApp TestApp) GetBep3Keeper() bep3keeper.Keeper { return tApp.bep3Keeper }
|
||||||
func (tApp TestApp) GetPriceFeedKeeper() pricefeedkeeper.Keeper { return tApp.pricefeedKeeper }
|
func (tApp TestApp) GetPriceFeedKeeper() pricefeedkeeper.Keeper { return tApp.pricefeedKeeper }
|
||||||
func (tApp TestApp) GetSwapKeeper() swapkeeper.Keeper { return tApp.swapKeeper }
|
|
||||||
func (tApp TestApp) GetCDPKeeper() cdpkeeper.Keeper { return tApp.cdpKeeper }
|
|
||||||
func (tApp TestApp) GetHardKeeper() hardkeeper.Keeper { return tApp.hardKeeper }
|
|
||||||
func (tApp TestApp) GetCommitteeKeeper() committeekeeper.Keeper { return tApp.committeeKeeper }
|
func (tApp TestApp) GetCommitteeKeeper() committeekeeper.Keeper { return tApp.committeeKeeper }
|
||||||
func (tApp TestApp) GetIncentiveKeeper() incentivekeeper.Keeper { return tApp.incentiveKeeper }
|
|
||||||
func (tApp TestApp) GetEvmutilKeeper() evmutilkeeper.Keeper { return tApp.evmutilKeeper }
|
func (tApp TestApp) GetEvmutilKeeper() evmutilkeeper.Keeper { return tApp.evmutilKeeper }
|
||||||
func (tApp TestApp) GetEvmKeeper() *evmkeeper.Keeper { return tApp.evmKeeper }
|
func (tApp TestApp) GetEvmKeeper() *evmkeeper.Keeper { return tApp.evmKeeper }
|
||||||
func (tApp TestApp) GetSavingsKeeper() savingskeeper.Keeper { return tApp.savingsKeeper }
|
|
||||||
func (tApp TestApp) GetFeeMarketKeeper() feemarketkeeper.Keeper { return tApp.feeMarketKeeper }
|
func (tApp TestApp) GetFeeMarketKeeper() feemarketkeeper.Keeper { return tApp.feeMarketKeeper }
|
||||||
func (tApp TestApp) GetLiquidKeeper() liquidkeeper.Keeper { return tApp.liquidKeeper }
|
|
||||||
func (tApp TestApp) GetEarnKeeper() earnkeeper.Keeper { return tApp.earnKeeper }
|
|
||||||
func (tApp TestApp) GetRouterKeeper() routerkeeper.Keeper { return tApp.routerKeeper }
|
|
||||||
func (tApp TestApp) GetCommunityKeeper() communitykeeper.Keeper { return tApp.communityKeeper }
|
|
||||||
|
|
||||||
func (tApp TestApp) GetKVStoreKey(key string) *storetypes.KVStoreKey {
|
func (tApp TestApp) GetKVStoreKey(key string) *storetypes.KVStoreKey {
|
||||||
return tApp.keys[key]
|
return tApp.keys[key]
|
||||||
@ -170,7 +153,7 @@ func GenesisStateWithSingleValidator(
|
|||||||
balances := []banktypes.Balance{
|
balances := []banktypes.Balance{
|
||||||
{
|
{
|
||||||
Address: acc.GetAddress().String(),
|
Address: acc.GetAddress().String(),
|
||||||
Coins: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(100000000000000))),
|
Coins: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100000000000000)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +216,7 @@ func genesisStateWithValSet(
|
|||||||
}
|
}
|
||||||
// set validators and delegations
|
// set validators and delegations
|
||||||
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
||||||
currentStakingGenesis.Params.BondDenom = "ukava"
|
currentStakingGenesis.Params.BondDenom = chaincfg.GasDenom // TODO:
|
||||||
|
|
||||||
stakingGenesis := stakingtypes.NewGenesisState(
|
stakingGenesis := stakingtypes.NewGenesisState(
|
||||||
currentStakingGenesis.Params,
|
currentStakingGenesis.Params,
|
||||||
@ -253,13 +236,13 @@ func genesisStateWithValSet(
|
|||||||
|
|
||||||
for range delegations {
|
for range delegations {
|
||||||
// add delegated tokens to total supply
|
// add delegated tokens to total supply
|
||||||
totalSupply = totalSupply.Add(sdk.NewCoin("ukava", bondAmt))
|
totalSupply = totalSupply.Add(chaincfg.MakeCoinForGasDenom(bondAmt))
|
||||||
}
|
}
|
||||||
|
|
||||||
// add bonded amount to bonded pool module account
|
// add bonded amount to bonded pool module account
|
||||||
balances = append(balances, banktypes.Balance{
|
balances = append(balances, banktypes.Balance{
|
||||||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
||||||
Coins: sdk.Coins{sdk.NewCoin("ukava", bondAmt)},
|
Coins: sdk.Coins{chaincfg.MakeCoinForGasDenom(bondAmt)},
|
||||||
})
|
})
|
||||||
|
|
||||||
bankGenesis := banktypes.NewGenesisState(
|
bankGenesis := banktypes.NewGenesisState(
|
||||||
@ -267,6 +250,7 @@ func genesisStateWithValSet(
|
|||||||
balances,
|
balances,
|
||||||
totalSupply,
|
totalSupply,
|
||||||
currentBankGenesis.DenomMetadata,
|
currentBankGenesis.DenomMetadata,
|
||||||
|
currentBankGenesis.SendEnabled,
|
||||||
)
|
)
|
||||||
|
|
||||||
// set genesis state
|
// set genesis state
|
||||||
@ -280,13 +264,13 @@ func genesisStateWithValSet(
|
|||||||
// InitializeFromGenesisStates calls InitChain on the app using the provided genesis states.
|
// InitializeFromGenesisStates calls InitChain on the app using the provided genesis states.
|
||||||
// If any module genesis states are missing, defaults are used.
|
// If any module genesis states are missing, defaults are used.
|
||||||
func (tApp TestApp) InitializeFromGenesisStates(genesisStates ...GenesisState) TestApp {
|
func (tApp TestApp) InitializeFromGenesisStates(genesisStates ...GenesisState) TestApp {
|
||||||
return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(emptyTime, testChainID, defaultInitialHeight, true, genesisStates...)
|
return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(emptyTime, TestChainId, defaultInitialHeight, true, genesisStates...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeFromGenesisStatesWithTime calls InitChain on the app using the provided genesis states and time.
|
// InitializeFromGenesisStatesWithTime calls InitChain on the app using the provided genesis states and time.
|
||||||
// If any module genesis states are missing, defaults are used.
|
// If any module genesis states are missing, defaults are used.
|
||||||
func (tApp TestApp) InitializeFromGenesisStatesWithTime(genTime time.Time, genesisStates ...GenesisState) TestApp {
|
func (tApp TestApp) InitializeFromGenesisStatesWithTime(genTime time.Time, genesisStates ...GenesisState) TestApp {
|
||||||
return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(genTime, testChainID, defaultInitialHeight, true, genesisStates...)
|
return tApp.InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(genTime, TestChainId, defaultInitialHeight, true, genesisStates...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeFromGenesisStatesWithTimeAndChainID calls InitChain on the app using the provided genesis states, time, and chain id.
|
// InitializeFromGenesisStatesWithTimeAndChainID calls InitChain on the app using the provided genesis states, time, and chain id.
|
||||||
@ -343,8 +327,8 @@ func (tApp TestApp) InitializeFromGenesisStatesWithTimeAndChainIDAndHeight(
|
|||||||
AppStateBytes: stateBytes,
|
AppStateBytes: stateBytes,
|
||||||
ChainId: chainID,
|
ChainId: chainID,
|
||||||
// Set consensus params, which is needed by x/feemarket
|
// Set consensus params, which is needed by x/feemarket
|
||||||
ConsensusParams: &abci.ConsensusParams{
|
ConsensusParams: &tmproto.ConsensusParams{
|
||||||
Block: &abci.BlockParams{
|
Block: &tmproto.BlockParams{
|
||||||
MaxBytes: 200000,
|
MaxBytes: 200000,
|
||||||
MaxGas: 20000000,
|
MaxGas: 20000000,
|
||||||
},
|
},
|
||||||
|
128
app/upgrades.go
128
app/upgrades.go
@ -1,3 +1,129 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
func (app App) RegisterUpgradeHandlers() {}
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
|
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/types/module"
|
||||||
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
|
||||||
|
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
|
||||||
|
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
|
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||||
|
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||||
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
|
paramstypes "github.com/cosmos/cosmos-sdk/x/params/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"
|
||||||
|
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
|
||||||
|
ibcwasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types"
|
||||||
|
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
|
||||||
|
ibctmmigrations "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint/migrations"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
UpgradeName_Testnet = "v0.3.0"
|
||||||
|
|
||||||
|
CDPLiquidationBlockInterval = int64(50)
|
||||||
|
)
|
||||||
|
|
||||||
|
// RegisterUpgradeHandlers registers the upgrade handlers for the app.
|
||||||
|
func (app App) RegisterUpgradeHandlers() {
|
||||||
|
app.upgradeKeeper.SetUpgradeHandler(
|
||||||
|
UpgradeName_Testnet,
|
||||||
|
upgradeHandler(app, UpgradeName_Testnet),
|
||||||
|
)
|
||||||
|
|
||||||
|
upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
doUpgrade := upgradeInfo.Name == UpgradeName_Testnet
|
||||||
|
|
||||||
|
if doUpgrade && !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
|
||||||
|
storeUpgrades := storetypes.StoreUpgrades{
|
||||||
|
Added: []string{
|
||||||
|
crisistypes.ModuleName,
|
||||||
|
consensustypes.ModuleName,
|
||||||
|
packetforwardtypes.ModuleName,
|
||||||
|
ibcwasmtypes.ModuleName,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure store loader that checks if version == upgradeHeight and applies store upgrades
|
||||||
|
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// upgradeHandler returns an UpgradeHandler for the given upgrade parameters.
|
||||||
|
func upgradeHandler(
|
||||||
|
app App,
|
||||||
|
name string,
|
||||||
|
) upgradetypes.UpgradeHandler {
|
||||||
|
return func(
|
||||||
|
ctx sdk.Context,
|
||||||
|
plan upgradetypes.Plan,
|
||||||
|
fromVM module.VersionMap,
|
||||||
|
) (module.VersionMap, error) {
|
||||||
|
app.Logger().Info(fmt.Sprintf("running %s upgrade handler", name))
|
||||||
|
|
||||||
|
baseAppLegacySS := app.paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable())
|
||||||
|
|
||||||
|
// Set param key table for params module migration
|
||||||
|
for _, subspace := range app.paramsKeeper.GetSubspaces() {
|
||||||
|
subspace := subspace
|
||||||
|
var keyTable paramstypes.KeyTable
|
||||||
|
switch subspace.Name() {
|
||||||
|
// sdk
|
||||||
|
case authtypes.ModuleName:
|
||||||
|
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
case banktypes.ModuleName:
|
||||||
|
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck,nolintlint
|
||||||
|
case stakingtypes.ModuleName:
|
||||||
|
keyTable = stakingtypes.ParamKeyTable()
|
||||||
|
case minttypes.ModuleName:
|
||||||
|
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
case distrtypes.ModuleName:
|
||||||
|
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck,nolintlint
|
||||||
|
case slashingtypes.ModuleName:
|
||||||
|
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
case govtypes.ModuleName:
|
||||||
|
keyTable = govv1.ParamKeyTable() //nolint:staticcheck
|
||||||
|
case crisistypes.ModuleName:
|
||||||
|
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
|
||||||
|
// ibc
|
||||||
|
case ibctransfertypes.ModuleName:
|
||||||
|
keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck
|
||||||
|
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if !subspace.HasKeyTable() {
|
||||||
|
// NOTE: This modifies the internal map used to store the key table entries
|
||||||
|
// which is a pointer.
|
||||||
|
subspace.WithKeyTable(keyTable)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// optional migration: prune expired tendermint consensus states to save storage space
|
||||||
|
// see https://github.com/cosmos/ibc-go/blob/v7.2.0/docs/migrations/v6-to-v7.md#chains
|
||||||
|
if _, err := ibctmmigrations.PruneExpiredConsensusStates(ctx, app.appCodec, app.ibcKeeper.ClientKeeper); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// migrate tendermint consensus parameters from x/params module to a
|
||||||
|
// dedicated x/consensus module.
|
||||||
|
baseapp.MigrateParams(ctx, baseAppLegacySS, &app.consensusParamsKeeper)
|
||||||
|
|
||||||
|
// run migrations for all modules and return new consensus version map
|
||||||
|
versionMap, err := app.mm.RunMigrations(ctx, app.configurator, fromVM)
|
||||||
|
|
||||||
|
return versionMap, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -28,9 +28,9 @@ DIRS := $(BUILD_CACHE_DIR) $(BIN_DIR)
|
|||||||
### Tool Versions ###
|
### Tool Versions ###
|
||||||
################################################################################
|
################################################################################
|
||||||
GO_BIN ?= go
|
GO_BIN ?= go
|
||||||
PROTOC_VERSION ?= v21.9
|
PROTOC_VERSION ?= v25.1
|
||||||
BUF_VERSION ?= v1.9.0
|
BUF_VERSION ?= v1.28.1
|
||||||
PROTOC_GEN_GOCOSMOS_VERSION ?= v0.3.1
|
PROTOC_GEN_GOCOSMOS_VERSION ?= $(shell $(GO_BIN) list -m -f '{{.Version}}' github.com/cosmos/gogoproto)
|
||||||
PROTOC_GEN_GRPC_GATEWAY_VERSION ?= $(shell $(GO_BIN) list -m github.com/grpc-ecosystem/grpc-gateway| sed 's:.* ::')
|
PROTOC_GEN_GRPC_GATEWAY_VERSION ?= $(shell $(GO_BIN) list -m github.com/grpc-ecosystem/grpc-gateway| sed 's:.* ::')
|
||||||
PROTOC_GEN_DOC_VERSION ?= v1.5.1
|
PROTOC_GEN_DOC_VERSION ?= v1.5.1
|
||||||
SWAGGER_COMBINE_VERSION ?= v1.4.0
|
SWAGGER_COMBINE_VERSION ?= v1.4.0
|
||||||
@ -68,7 +68,7 @@ $(PROTOC_VERSION_FILE):
|
|||||||
mkdir -p protoc && cd protoc; \
|
mkdir -p protoc && cd protoc; \
|
||||||
curl -sOL $(PROTOC_DOWNLOAD_URL); \
|
curl -sOL $(PROTOC_DOWNLOAD_URL); \
|
||||||
unzip -q $(PROTOC_ARCHIVE_NAME) bin/protoc
|
unzip -q $(PROTOC_ARCHIVE_NAME) bin/protoc
|
||||||
@cp $(BUILD_CACHE_DIR)/protoc/bin/protoc $(BIN_DIR)/protoc
|
@cp -f $(BUILD_CACHE_DIR)/protoc/bin/protoc $(BIN_DIR)/protoc
|
||||||
@rm -rf $(BUILD_CACHE_DIR)/protoc
|
@rm -rf $(BUILD_CACHE_DIR)/protoc
|
||||||
|
|
||||||
PROTOC := $(BIN_DIR)/protoc
|
PROTOC := $(BIN_DIR)/protoc
|
||||||
@ -93,7 +93,7 @@ $(BUF_VERSION_FILE):
|
|||||||
mkdir -p buf && cd buf; \
|
mkdir -p buf && cd buf; \
|
||||||
curl -sOL $(BUF_DOWNLOAD_URL); \
|
curl -sOL $(BUF_DOWNLOAD_URL); \
|
||||||
tar -xzf $(BUF_ARCHIVE_NAME) buf/bin/buf
|
tar -xzf $(BUF_ARCHIVE_NAME) buf/bin/buf
|
||||||
@cp $(BUILD_CACHE_DIR)/buf/buf/bin/buf $(BIN_DIR)/buf
|
@cp -f $(BUILD_CACHE_DIR)/buf/buf/bin/buf $(BIN_DIR)/buf
|
||||||
@rm -rf $(BUILD_CACHE_DIR)/buf
|
@rm -rf $(BUILD_CACHE_DIR)/buf
|
||||||
|
|
||||||
BUF := $(BIN_DIR)/buf
|
BUF := $(BIN_DIR)/buf
|
||||||
@ -113,8 +113,8 @@ $(PROTOC_GEN_GOCOSMOS_VERSION_FILE):
|
|||||||
@touch $(PROTOC_GEN_GOCOSMOS_VERSION_FILE)
|
@touch $(PROTOC_GEN_GOCOSMOS_VERSION_FILE)
|
||||||
@cd $(BUILD_CACHE_DIR); \
|
@cd $(BUILD_CACHE_DIR); \
|
||||||
mkdir -p protoc-gen-gocosmos && cd protoc-gen-gocosmos; \
|
mkdir -p protoc-gen-gocosmos && cd protoc-gen-gocosmos; \
|
||||||
git clone -q https://github.com/regen-network/cosmos-proto.git; \
|
git clone -q https://github.com/cosmos/gogoproto.git; \
|
||||||
cd cosmos-proto; \
|
cd gogoproto; \
|
||||||
git checkout -q $(PROTOC_GEN_GOCOSMOS_VERSION); \
|
git checkout -q $(PROTOC_GEN_GOCOSMOS_VERSION); \
|
||||||
GOBIN=$(ROOT_DIR)/$(BIN_DIR) $(GO_BIN) install ./protoc-gen-gocosmos
|
GOBIN=$(ROOT_DIR)/$(BIN_DIR) $(GO_BIN) install ./protoc-gen-gocosmos
|
||||||
@rm -rf $(BUILD_CACHE_DIR)/protoc-gen-gocosmos
|
@rm -rf $(BUILD_CACHE_DIR)/protoc-gen-gocosmos
|
||||||
@ -185,7 +185,7 @@ $(PROTOC_GEN_DOC_VERSION_FILE):
|
|||||||
mkdir -p protoc-gen-doc && cd protoc-gen-doc; \
|
mkdir -p protoc-gen-doc && cd protoc-gen-doc; \
|
||||||
curl -sOL $(PROTOC_GEN_DOC_DOWNLOAD_URL); \
|
curl -sOL $(PROTOC_GEN_DOC_DOWNLOAD_URL); \
|
||||||
tar -xzf $(PROTOC_GEN_DOC_ARCHIVE_NAME) protoc-gen-doc
|
tar -xzf $(PROTOC_GEN_DOC_ARCHIVE_NAME) protoc-gen-doc
|
||||||
@cp $(BUILD_CACHE_DIR)/protoc-gen-doc/protoc-gen-doc $(BIN_DIR)/protoc-gen-doc
|
@cp -f $(BUILD_CACHE_DIR)/protoc-gen-doc/protoc-gen-doc $(BIN_DIR)/protoc-gen-doc
|
||||||
@rm -rf $(BUILD_CACHE_DIR)/protoc-gen-doc
|
@rm -rf $(BUILD_CACHE_DIR)/protoc-gen-doc
|
||||||
|
|
||||||
PROTOC_GEN_DOC := $(BIN_DIR)/protoc-gen-doc
|
PROTOC_GEN_DOC := $(BIN_DIR)/protoc-gen-doc
|
||||||
|
@ -14,13 +14,23 @@ PROTOBUF_ANY_DOWNLOAD_URL = https://raw.githubusercontent.com/protocolbuffers/pr
|
|||||||
#
|
#
|
||||||
# Proto dependencies under go.mod
|
# Proto dependencies under go.mod
|
||||||
#
|
#
|
||||||
GOGO_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/gogo/protobuf)
|
GOGO_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/cosmos/gogoproto)
|
||||||
TENDERMINT_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/tendermint/tendermint)
|
TENDERMINT_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/cometbft/cometbft)
|
||||||
COSMOS_PROTO_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/cosmos/cosmos-proto)
|
COSMOS_PROTO_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/cosmos/cosmos-proto)
|
||||||
COSMOS_SDK_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/cosmos/cosmos-sdk)
|
COSMOS_SDK_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/cosmos/cosmos-sdk)
|
||||||
IBC_GO_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/cosmos/ibc-go/v6)
|
IBC_GO_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/cosmos/ibc-go/v7)
|
||||||
ETHERMINT_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/evmos/ethermint)
|
ETHERMINT_PATH := $(shell $(GO_BIN) list -m -f '{{.Dir}}' github.com/evmos/ethermint)
|
||||||
|
|
||||||
|
#
|
||||||
|
# ICS23 Proof Proto
|
||||||
|
#
|
||||||
|
ICS23_VERSION := $(shell $(GO_BIN) list -m -f '{{.Version}}' github.com/cosmos/ics23/go)
|
||||||
|
|
||||||
|
ICS23_PROOFS_PROTO_PATH := cosmos/ics23/v1/proofs.proto
|
||||||
|
ICS23_PROOFS_PROTO_LOCAL_PATH := third_party/proto/$(ICS23_PROOFS_PROTO_PATH)
|
||||||
|
|
||||||
|
ICS23_PROOFS_PROTO_DOWNLOAD_URL := https://raw.githubusercontent.com/cosmos/ics23/go/$(ICS23_VERSION)/proto/$(ICS23_PROOFS_PROTO_PATH)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Common target directories
|
# Common target directories
|
||||||
#
|
#
|
||||||
@ -44,18 +54,20 @@ proto-update-deps: check-rsync ## Update all third party proto files
|
|||||||
@curl -sSL $(PROTOBUF_ANY_DOWNLOAD_URL)/any.proto > $(PROTOBUF_GOOGLE_TYPES)/any.proto
|
@curl -sSL $(PROTOBUF_ANY_DOWNLOAD_URL)/any.proto > $(PROTOBUF_GOOGLE_TYPES)/any.proto
|
||||||
|
|
||||||
@mkdir -p client/docs
|
@mkdir -p client/docs
|
||||||
@cp $(COSMOS_SDK_PATH)/client/docs/swagger-ui/swagger.yaml client/docs/cosmos-swagger.yml
|
@cp -f $(COSMOS_SDK_PATH)/client/docs/swagger-ui/swagger.yaml client/docs/cosmos-swagger.yml
|
||||||
@cp $(IBC_GO_PATH)/docs/client/swagger-ui/swagger.yaml client/docs/ibc-go-swagger.yml
|
@cp -f $(IBC_GO_PATH)/docs/client/swagger-ui/swagger.yaml client/docs/ibc-go-swagger.yml
|
||||||
|
|
||||||
@mkdir -p $(COSMOS_PROTO_TYPES)
|
@mkdir -p $(COSMOS_PROTO_TYPES)
|
||||||
@cp $(COSMOS_PROTO_PATH)/proto/cosmos_proto/cosmos.proto $(COSMOS_PROTO_TYPES)/cosmos.proto
|
@cp -f $(COSMOS_PROTO_PATH)/proto/cosmos_proto/cosmos.proto $(COSMOS_PROTO_TYPES)/cosmos.proto
|
||||||
|
|
||||||
|
@mkdir -p $(dir $(ICS23_PROOFS_PROTO_LOCAL_PATH))
|
||||||
|
@curl -sSL $(ICS23_PROOFS_PROTO_DOWNLOAD_URL) > $(ICS23_PROOFS_PROTO_LOCAL_PATH)
|
||||||
|
|
||||||
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(GOGO_PATH)/gogoproto third_party/proto
|
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(GOGO_PATH)/gogoproto third_party/proto
|
||||||
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(TENDERMINT_PATH)/proto third_party
|
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(TENDERMINT_PATH)/proto third_party
|
||||||
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(COSMOS_SDK_PATH)/proto third_party
|
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(COSMOS_SDK_PATH)/proto third_party
|
||||||
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(IBC_GO_PATH)/proto third_party
|
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(IBC_GO_PATH)/proto third_party
|
||||||
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(ETHERMINT_PATH)/proto third_party
|
@$(RSYNC_BIN) -r --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r --include "*.proto" --include='*/' --exclude='*' $(ETHERMINT_PATH)/proto third_party
|
||||||
@cp -f $(IBC_GO_PATH)/third_party/proto/proofs.proto third_party/proto/proofs.proto
|
|
||||||
|
|
||||||
.PHONY: check-proto-deps
|
.PHONY: check-proto-deps
|
||||||
check-proto-deps: proto-update-deps ## Return error code 1 if proto dependencies are not changed
|
check-proto-deps: proto-update-deps ## Return error code 1 if proto dependencies are not changed
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
.PHONY: proto-lint check-proto-lint
|
.PHONY: proto-lint check-proto-lint
|
||||||
proto-lint check-proto-lint: install-build-deps
|
proto-lint check-proto-lint: install-build-deps
|
||||||
@echo "Linting proto file"
|
@echo "Linting proto file"
|
||||||
@$(BUF) lint
|
@$(BUF) lint proto
|
||||||
|
|
||||||
.PHONY: proto-gen
|
.PHONY: proto-gen
|
||||||
proto-gen: install-build-deps
|
proto-gen: install-build-deps
|
||||||
@echo "Generating go proto files"
|
@echo "Generating go proto files"
|
||||||
@$(BUF) generate --template proto/buf.gen.gogo.yaml proto
|
@$(BUF) generate --template proto/buf.gen.gogo.yaml proto
|
||||||
@cp -r out/github.com/kava-labs/kava/* ./
|
@cp -r out/github.com/0glabs/0g-chain/* ./
|
||||||
@rm -rf out/github.com
|
@rm -rf out/github.com
|
||||||
|
|
||||||
.PHONY: check-proto-gen
|
.PHONY: check-proto-gen
|
||||||
|
22
chaincfg/coin.go
Normal file
22
chaincfg/coin.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Bip44CoinType satisfies EIP84. See https://github.com/ethereum/EIPs/issues/84 for more info.
|
||||||
|
Bip44CoinType uint32 = 459 // TODO: need new coin type for 0g-chain (a0gi)
|
||||||
|
// eth = 60
|
||||||
|
// kava = 459 // see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||||
|
// BIP44HDPath is the default BIP44 HD path used on Ethereum.
|
||||||
|
//BIP44HDPath = ethaccounts.DefaultBaseDerivationPath.String()
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO: Implement BIP44CoinType and BIP44HDPath
|
||||||
|
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
|
||||||
|
func setBip44CoinType(config *sdk.Config) {
|
||||||
|
config.SetCoinType(Bip44CoinType)
|
||||||
|
//config.SetPurpose(sdk.Purpose) // Shared
|
||||||
|
//config.SetFullFundraiserPath(BIP44HDPath) //nolint: staticcheck
|
||||||
|
}
|
57
chaincfg/coin_helper.go
Normal file
57
chaincfg/coin_helper.go
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"cosmossdk.io/math"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func toBigInt(amount any) *big.Int {
|
||||||
|
if amount == nil {
|
||||||
|
return big.NewInt(0)
|
||||||
|
}
|
||||||
|
var val *big.Int
|
||||||
|
switch amount.(type) {
|
||||||
|
case int:
|
||||||
|
val = big.NewInt(int64(amount.(int)))
|
||||||
|
case int32:
|
||||||
|
val = big.NewInt(int64(amount.(int32)))
|
||||||
|
case int64:
|
||||||
|
val = big.NewInt(amount.(int64))
|
||||||
|
case string:
|
||||||
|
var ok bool
|
||||||
|
val, ok = new(big.Int).SetString(amount.(string), 0)
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Sprintf("invalid amount string: %s", amount.(string)))
|
||||||
|
}
|
||||||
|
case math.Int:
|
||||||
|
val = amount.(math.Int).BigInt()
|
||||||
|
case *big.Int:
|
||||||
|
val = amount.(*big.Int)
|
||||||
|
case float64:
|
||||||
|
val = decimal.NewFromFloat(amount.(float64)).BigInt()
|
||||||
|
default:
|
||||||
|
panic(fmt.Sprintf("invalid amount type: %T", amount))
|
||||||
|
}
|
||||||
|
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeCoinForStandardDenom(amount any) sdk.Coin {
|
||||||
|
return makeCoin(StandardDenom, toBigInt(amount))
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeCoinForGasDenom(amount any) sdk.Coin {
|
||||||
|
return makeCoin(GasDenom, toBigInt(amount))
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeCoinForEvmDenom(amount any) sdk.Coin {
|
||||||
|
return makeCoin(EvmDenom, toBigInt(amount))
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCoin(denom string, amount *big.Int) sdk.Coin {
|
||||||
|
return sdk.NewCoin(denom, math.NewIntFromBigInt(amount))
|
||||||
|
}
|
17
chaincfg/config.go
Normal file
17
chaincfg/config.go
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
AppName = "0gchaind"
|
||||||
|
EnvPrefix = "0GCHAIN"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SetSDKConfig() *sdk.Config {
|
||||||
|
config := sdk.GetConfig()
|
||||||
|
setBech32Prefixes(config)
|
||||||
|
setBip44CoinType(config)
|
||||||
|
return config
|
||||||
|
}
|
37
chaincfg/denoms.go
Normal file
37
chaincfg/denoms.go
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
StandardDenom = "a0gi"
|
||||||
|
|
||||||
|
GasDenom = "ua0gi"
|
||||||
|
|
||||||
|
EvmDenom = "neuron"
|
||||||
|
|
||||||
|
BondDenom = EvmDenom
|
||||||
|
|
||||||
|
GasDenomUnit = 6
|
||||||
|
|
||||||
|
EvmDenomUnit = 18
|
||||||
|
|
||||||
|
GasDenomConversionMultiplier = 1e12
|
||||||
|
EvmDenomConversionMultiplier = 1e18
|
||||||
|
)
|
||||||
|
|
||||||
|
// RegisterDenoms registers the base and gas denominations to the SDK.
|
||||||
|
func RegisterDenoms() {
|
||||||
|
if err := sdk.RegisterDenom(StandardDenom, sdk.OneDec()); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := sdk.RegisterDenom(GasDenom, sdk.NewDecWithPrec(1, GasDenomUnit)); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := sdk.RegisterDenom(EvmDenom, sdk.NewDecWithPrec(1, EvmDenomUnit)); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
80
chaincfg/denoms_test.go
Normal file
80
chaincfg/denoms_test.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRegisterDenoms(t *testing.T) {
|
||||||
|
RegisterDenoms()
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
from sdk.Coin
|
||||||
|
targetDenom string
|
||||||
|
expCoin sdk.Coin
|
||||||
|
expErr error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"standard to gas",
|
||||||
|
MakeCoinForStandardDenom(99),
|
||||||
|
GasDenom,
|
||||||
|
MakeCoinForGasDenom(99 * (EvmDenomConversionMultiplier / GasDenomConversionMultiplier)),
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"gas to standard",
|
||||||
|
MakeCoinForGasDenom(5e7),
|
||||||
|
StandardDenom,
|
||||||
|
MakeCoinForStandardDenom(50),
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"standard to base",
|
||||||
|
MakeCoinForStandardDenom(22),
|
||||||
|
EvmDenom,
|
||||||
|
MakeCoinForEvmDenom(22 * EvmDenomConversionMultiplier),
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"base to standard",
|
||||||
|
MakeCoinForEvmDenom("97000000000000000000"),
|
||||||
|
StandardDenom,
|
||||||
|
MakeCoinForStandardDenom(97),
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"gas to base",
|
||||||
|
MakeCoinForGasDenom(33),
|
||||||
|
EvmDenom,
|
||||||
|
MakeCoinForEvmDenom(33 * GasDenomConversionMultiplier),
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"base to gas",
|
||||||
|
MakeCoinForEvmDenom("770000000000000"),
|
||||||
|
GasDenom,
|
||||||
|
MakeCoinForGasDenom(770000000000000 / GasDenomConversionMultiplier),
|
||||||
|
nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
ret, err := sdk.ConvertCoin(tt.from, tt.targetDenom)
|
||||||
|
if tt.expErr != nil {
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("expErr is not nil, but got nil")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expErr is nil, but got %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, tt.expCoin, ret)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
25
chaincfg/homedir.go
Normal file
25
chaincfg/homedir.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
stdlog "log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
HomeDirName = ".0gchain"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DefaultNodeHome default home directories for the application daemon
|
||||||
|
DefaultNodeHome string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
userHomeDir, err := os.UserHomeDir()
|
||||||
|
if err != nil {
|
||||||
|
stdlog.Printf("Failed to get home dir %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultNodeHome = filepath.Join(userHomeDir, HomeDirName)
|
||||||
|
}
|
76
chaincfg/mint.go
Normal file
76
chaincfg/mint.go
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Xmax, _ = sdk.NewDecFromStr("1.0") // upper limit on staked supply (as % of circ supply)
|
||||||
|
Ymin, _ = sdk.NewDecFromStr("0.05") // target APY at upper limit
|
||||||
|
|
||||||
|
Xmin, _ = sdk.NewDecFromStr("0.2") // lower limit on staked supply (as % of circ supply)
|
||||||
|
Ymax, _ = sdk.NewDecFromStr("0.15") // target APY at lower limit
|
||||||
|
|
||||||
|
decayRate, _ = sdk.NewDecFromStr("10")
|
||||||
|
)
|
||||||
|
|
||||||
|
func decExp(x sdk.Dec) sdk.Dec {
|
||||||
|
xDec := decimal.NewFromBigInt(x.BigInt(), -18)
|
||||||
|
expDec, _ := xDec.ExpTaylor(18)
|
||||||
|
expInt := expDec.Shift(18).BigInt()
|
||||||
|
return sdk.NewDecFromBigIntWithPrec(expInt, 18)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NextInflationRate(ctx sdk.Context, minter minttypes.Minter, params minttypes.Params, bondedRatio sdk.Dec, circulatingRatio sdk.Dec) sdk.Dec {
|
||||||
|
X := bondedRatio.Quo(circulatingRatio)
|
||||||
|
|
||||||
|
var apy sdk.Dec
|
||||||
|
if X.LT(Xmin) {
|
||||||
|
apy = Ymax
|
||||||
|
} else {
|
||||||
|
exp := decayRate.Neg().Mul(Xmax.Sub(Xmin))
|
||||||
|
c := decExp(exp)
|
||||||
|
d := Ymin.Sub(Ymax.Mul(c)).Quo(sdk.OneDec().Sub(c))
|
||||||
|
expBonded := decayRate.Neg().Mul(X.Sub(Xmin))
|
||||||
|
cBonded := decExp(expBonded)
|
||||||
|
e := Ymax.Sub(d).Mul(cBonded)
|
||||||
|
apy = d.Add(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
inflation := apy.Mul(bondedRatio)
|
||||||
|
|
||||||
|
// // The target annual inflation rate is recalculated for each previsions cycle. The
|
||||||
|
// // inflation is also subject to a rate change (positive or negative) depending on
|
||||||
|
// // the distance from the desired ratio (67%). The maximum rate change possible is
|
||||||
|
// // defined to be 13% per year, however the annual inflation is capped as between
|
||||||
|
// // 7% and 20%.
|
||||||
|
|
||||||
|
// // (1 - bondedRatio/GoalBonded) * InflationRateChange
|
||||||
|
// inflationRateChangePerYear := sdk.OneDec().
|
||||||
|
// Sub(bondedRatio.Quo(params.GoalBonded)).
|
||||||
|
// Mul(params.InflationRateChange)
|
||||||
|
// inflationRateChange := inflationRateChangePerYear.Quo(sdk.NewDec(int64(params.BlocksPerYear)))
|
||||||
|
|
||||||
|
// // adjust the new annual inflation for this next cycle
|
||||||
|
// inflation := minter.Inflation.Add(inflationRateChange) // note inflationRateChange may be negative
|
||||||
|
// if inflation.GT(params.InflationMax) {
|
||||||
|
// inflation = params.InflationMax
|
||||||
|
// }
|
||||||
|
// if inflation.LT(params.InflationMin) {
|
||||||
|
// inflation = params.InflationMin
|
||||||
|
// }
|
||||||
|
|
||||||
|
ctx.Logger().Info(
|
||||||
|
"nextInflationRate",
|
||||||
|
"bondedRatio", bondedRatio,
|
||||||
|
"circulatingRatio", circulatingRatio,
|
||||||
|
"apy", apy,
|
||||||
|
"inflation", inflation,
|
||||||
|
"params", params,
|
||||||
|
"minter", minter,
|
||||||
|
)
|
||||||
|
return inflation
|
||||||
|
}
|
44
chaincfg/prefix.go
Normal file
44
chaincfg/prefix.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package chaincfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Bech32Prefix defines the Bech32 prefix used for EthAccounts
|
||||||
|
Bech32Prefix = "0g"
|
||||||
|
|
||||||
|
// PrefixAccount is the prefix for account keys
|
||||||
|
PrefixAccount = "acc"
|
||||||
|
// PrefixValidator is the prefix for validator keys
|
||||||
|
PrefixValidator = "val"
|
||||||
|
// PrefixConsensus is the prefix for consensus keys
|
||||||
|
PrefixConsensus = "cons"
|
||||||
|
// PrefixPublic is the prefix for public keys
|
||||||
|
PrefixPublic = "pub"
|
||||||
|
// PrefixOperator is the prefix for operator keys
|
||||||
|
PrefixOperator = "oper"
|
||||||
|
|
||||||
|
// PrefixAddress is the prefix for addresses
|
||||||
|
PrefixAddress = "addr"
|
||||||
|
|
||||||
|
// Bech32PrefixAccAddr defines the Bech32 prefix of an account's address
|
||||||
|
Bech32PrefixAccAddr = Bech32Prefix
|
||||||
|
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
||||||
|
Bech32PrefixAccPub = Bech32Prefix + PrefixPublic
|
||||||
|
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
||||||
|
Bech32PrefixValAddr = Bech32Prefix + PrefixValidator + PrefixOperator
|
||||||
|
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
||||||
|
Bech32PrefixValPub = Bech32Prefix + PrefixValidator + PrefixOperator + PrefixPublic
|
||||||
|
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
||||||
|
Bech32PrefixConsAddr = Bech32Prefix + PrefixValidator + PrefixConsensus
|
||||||
|
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
||||||
|
Bech32PrefixConsPub = Bech32Prefix + PrefixValidator + PrefixConsensus + PrefixPublic
|
||||||
|
)
|
||||||
|
|
||||||
|
// setBech32Prefixes sets the global prefixes to be used when serializing addresses and public keys to Bech32 strings.
|
||||||
|
func setBech32Prefixes(config *sdk.Config) {
|
||||||
|
config.SetBech32PrefixForAccount(Bech32PrefixAccAddr, Bech32PrefixAccPub)
|
||||||
|
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
||||||
|
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
||||||
|
}
|
4
ci/env/kava-internal-testnet/genesis.json
vendored
4
ci/env/kava-internal-testnet/genesis.json
vendored
@ -582,6 +582,10 @@
|
|||||||
"denom": "erc20/axelar/wbtc",
|
"denom": "erc20/axelar/wbtc",
|
||||||
"amount": "1000000000"
|
"amount": "1000000000"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"denom": "erc20/tether/usdt",
|
||||||
|
"amount": "100000000000"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"denom": "hard",
|
"denom": "hard",
|
||||||
"amount": "1000000000"
|
"amount": "1000000000"
|
||||||
|
24
ci/env/kava-protonet/genesis.json
vendored
24
ci/env/kava-protonet/genesis.json
vendored
@ -837,6 +837,7 @@
|
|||||||
"gov_denom": "ukava",
|
"gov_denom": "ukava",
|
||||||
"params": {
|
"params": {
|
||||||
"circuit_breaker": false,
|
"circuit_breaker": false,
|
||||||
|
"liquidation_block_interval": 500,
|
||||||
"collateral_params": [
|
"collateral_params": [
|
||||||
{
|
{
|
||||||
"auction_size": "50000000000",
|
"auction_size": "50000000000",
|
||||||
@ -2177,6 +2178,23 @@
|
|||||||
"quorum": "0.334000000000000000",
|
"quorum": "0.334000000000000000",
|
||||||
"threshold": "0.500000000000000000",
|
"threshold": "0.500000000000000000",
|
||||||
"veto_threshold": "0.334000000000000000"
|
"veto_threshold": "0.334000000000000000"
|
||||||
|
},
|
||||||
|
"params": {
|
||||||
|
"min_deposit": [
|
||||||
|
{
|
||||||
|
"denom": "ukava",
|
||||||
|
"amount": "10000000"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"max_deposit_period": "172800s",
|
||||||
|
"voting_period": "600s",
|
||||||
|
"quorum": "0.334000000000000000",
|
||||||
|
"threshold": "0.500000000000000000",
|
||||||
|
"veto_threshold": "0.334000000000000000",
|
||||||
|
"min_initial_deposit_ratio": "0.000000000000000000",
|
||||||
|
"burn_vote_quorum": false,
|
||||||
|
"burn_proposal_deposit_prevote": false,
|
||||||
|
"burn_vote_veto": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hard": {
|
"hard": {
|
||||||
@ -2982,6 +3000,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"params": null,
|
"params": null,
|
||||||
|
"packetfowardmiddleware": {
|
||||||
|
"params": {
|
||||||
|
"fee_percentage": "0.000000000000000000"
|
||||||
|
},
|
||||||
|
"in_flight_packets": {}
|
||||||
|
},
|
||||||
"pricefeed": {
|
"pricefeed": {
|
||||||
"params": {
|
"params": {
|
||||||
"markets": [
|
"markets": [
|
||||||
|
@ -14,9 +14,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/cometbft/cometbft/crypto/ed25519"
|
||||||
|
tmtypes "github.com/cometbft/cometbft/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
"github.com/cosmos/cosmos-sdk/tests"
|
||||||
@ -62,36 +62,36 @@ func TestKvCLIKeysAddRecover(t *testing.T) {
|
|||||||
|
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
||||||
|
|
||||||
// test old bip44 coin type
|
// test old bip44 coin type
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
require.Equal(t, "0g1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
||||||
|
|
||||||
// Cleanup testing directories
|
// Cleanup testing directories
|
||||||
f.Cleanup()
|
f.Cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
func TestZgChainCLIKeysAddRecoverHDPath(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
f := InitFixtures(t)
|
f := InitFixtures(t)
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
||||||
require.Equal(t, "kava1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
require.Equal(t, "0g1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
||||||
require.Equal(t, "kava1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
require.Equal(t, "0g1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
||||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
||||||
|
|
||||||
// test old bip44 coin type
|
// test old bip44 coin type
|
||||||
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
|
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
|
||||||
require.Equal(t, "kava1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
require.Equal(t, "0g1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
||||||
|
|
||||||
exitSuccess, _, _ := f.KeysAddRecover("test-recover-fail", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path --hd-path 44'/459'/0'/0/0")
|
exitSuccess, _, _ := f.KeysAddRecover("test-recover-fail", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path --hd-path 44'/459'/0'/0/0")
|
||||||
require.False(t, exitSuccess)
|
require.False(t, exitSuccess)
|
||||||
@ -99,11 +99,11 @@ func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
|||||||
// test -hd-path flag
|
// test -hd-path flag
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH6", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/0'/0/0")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH6", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/0'/0/0")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
|
||||||
|
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH7", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/2'/0/17")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH7", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/2'/0/17")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
|
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
|
||||||
|
|
||||||
// Cleanup testing directories
|
// Cleanup testing directories
|
||||||
f.Cleanup()
|
f.Cleanup()
|
||||||
@ -813,7 +813,7 @@ func TestKvCLISubmitCommunityPoolSpendProposal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestKvCLIQueryTxPagination(t *testing.T) {
|
func TestKvCLIQueryTxPagination(t *testing.T) {
|
||||||
// Skip until https://github.com/tendermint/tendermint/issues/4432 has been
|
// Skip until https://github.com/cometbft/cometbft/issues/4432 has been
|
||||||
// resolved and included in a release.
|
// resolved and included in a release.
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/cometbft/cometbft/types"
|
||||||
|
|
||||||
|
"cosmossdk.io/simapp"
|
||||||
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
"github.com/cosmos/cosmos-sdk/crypto/keys"
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/cosmos/cosmos-sdk/simapp"
|
|
||||||
"github.com/cosmos/cosmos-sdk/tests"
|
"github.com/cosmos/cosmos-sdk/tests"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
@ -28,7 +28,7 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/x/slashing"
|
"github.com/cosmos/cosmos-sdk/x/slashing"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -65,8 +65,7 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// set the address prefixes
|
// set the address prefixes
|
||||||
config := sdk.GetConfig()
|
chaincfg.SetSDKConfig()
|
||||||
app.SetBech32AddressPrefixes(config)
|
|
||||||
// config.Seal()
|
// config.Seal()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +91,7 @@ type Fixtures struct {
|
|||||||
|
|
||||||
// NewFixtures creates a new instance of Fixtures with many vars set
|
// NewFixtures creates a new instance of Fixtures with many vars set
|
||||||
func NewFixtures(t *testing.T) *Fixtures {
|
func NewFixtures(t *testing.T) *Fixtures {
|
||||||
tmpDir, err := ioutil.TempDir("", "kava_integration_"+t.Name()+"_")
|
tmpDir, err := ioutil.TempDir("", "0gchain_integration_"+t.Name()+"_")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
servAddr, port, err := server.FreeTCPAddr()
|
servAddr, port, err := server.FreeTCPAddr()
|
||||||
@ -201,9 +200,9 @@ func (f *Fixtures) Flags() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
//___________________________________________________________________________________
|
||||||
// kavad
|
// 0gchaind
|
||||||
|
|
||||||
// UnsafeResetAll is kavad unsafe-reset-all
|
// UnsafeResetAll is 0gchaind unsafe-reset-all
|
||||||
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
||||||
executeWrite(f.T, addFlags(cmd, flags))
|
executeWrite(f.T, addFlags(cmd, flags))
|
||||||
@ -211,7 +210,7 @@ func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
|||||||
require.NoError(f.T, err)
|
require.NoError(f.T, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// KvInit is kavad init
|
// KvInit is 0gchaind init
|
||||||
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
||||||
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
|
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
|
||||||
@ -229,25 +228,25 @@ func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
|||||||
f.ChainID = chainID
|
f.ChainID = chainID
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddGenesisAccount is kavad add-genesis-account
|
// AddGenesisAccount is 0gchaind add-genesis-account
|
||||||
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
|
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.KvdBinary, address, coins, f.KvdHome)
|
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.KvdBinary, address, coins, f.KvdHome)
|
||||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenTx is kavad gentx
|
// GenTx is 0gchaind gentx
|
||||||
func (f *Fixtures) GenTx(name string, flags ...string) {
|
func (f *Fixtures) GenTx(name string, flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s --keyring-backend=test", f.KvdBinary, name, f.KvdHome, f.KvcliHome)
|
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s --keyring-backend=test", f.KvdBinary, name, f.KvdHome, f.KvcliHome)
|
||||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectGenTxs is kavad collect-gentxs
|
// CollectGenTxs is 0gchaind collect-gentxs
|
||||||
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
||||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GDStart runs kavad start with the appropriate flags and returns a process
|
// GDStart runs 0gchaind start with the appropriate flags and returns a process
|
||||||
func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
||||||
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v --pruning=everything", f.KvdBinary, f.KvdHome, f.RPCAddr, f.P2PAddr)
|
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v --pruning=everything", f.KvdBinary, f.KvdHome, f.RPCAddr, f.P2PAddr)
|
||||||
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
|
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
|
||||||
@ -256,7 +255,7 @@ func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
|||||||
return proc
|
return proc
|
||||||
}
|
}
|
||||||
|
|
||||||
// GDTendermint returns the results of kavad tendermint [query]
|
// GDTendermint returns the results of 0gchaind tendermint [query]
|
||||||
func (f *Fixtures) GDTendermint(query string) string {
|
func (f *Fixtures) GDTendermint(query string) string {
|
||||||
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
||||||
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
||||||
@ -265,7 +264,7 @@ func (f *Fixtures) GDTendermint(query string) string {
|
|||||||
return strings.TrimSpace(stdout)
|
return strings.TrimSpace(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateGenesis runs kavad validate-genesis
|
// ValidateGenesis runs 0gchaind validate-genesis
|
||||||
func (f *Fixtures) ValidateGenesis() {
|
func (f *Fixtures) ValidateGenesis() {
|
||||||
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
||||||
executeWriteCheckErr(f.T, cmd)
|
executeWriteCheckErr(f.T, cmd)
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
},
|
},
|
||||||
"externalDocs": {
|
"externalDocs": {
|
||||||
"description": "GitHub",
|
"description": "GitHub",
|
||||||
"url": "https://github.com/Kava-Labs/kava"
|
"url": "https://github.com/0glabs/0g-chain"
|
||||||
},
|
},
|
||||||
"host": "api.data.kava.io",
|
"host": "api.data.kava.io",
|
||||||
"schemes": ["https"],
|
"schemes": ["https"],
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
74
client/grpc/README.md
Normal file
74
client/grpc/README.md
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
# Kava gRPC Client
|
||||||
|
|
||||||
|
The Kava gRPC client is a tool for making gRPC queries on a Kava chain.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Easy-to-use gRPC client for the Kava chain.
|
||||||
|
- Access all query clients for Cosmos and Kava modules using `client.Query` (e.g., `client.Query.Bank.Balance`).
|
||||||
|
- Utilize utility functions for common queries (e.g., `client.BaseAccount(str)`).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Creating a new client
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
kavaGrpc "github.com/0glabs/0g-chain/client/grpc"
|
||||||
|
)
|
||||||
|
grpcUrl := "https://grpc.kava.io:443"
|
||||||
|
client, err := kavaGrpc.NewClient(grpcUrl)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Making grpc queries
|
||||||
|
|
||||||
|
Query clients for both Cosmos and Kava modules are available via `client.Query`.
|
||||||
|
|
||||||
|
Example: Query Cosmos module `x/bank` for address balance
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
rsp, err := client.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||||
|
Address: "kava19rjk5qmmwywnzfccwzyn02jywgpwjqf60afj92",
|
||||||
|
Denom: "ukava",
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
Example: Query Kava module `x/evmutil` for params
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
rsp, err := client.Query.Evmutil.Params(
|
||||||
|
context.Background(), &evmutiltypes.QueryParamsRequest{},
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Query Utilities
|
||||||
|
|
||||||
|
Utility functions for common queries are available directly on the client.
|
||||||
|
|
||||||
|
Example: Util query to get a base account
|
||||||
|
|
||||||
|
```go
|
||||||
|
kavaAcc := "kava19rjk5qmmwywnzfccwzyn02jywgpwjqf60afj92"
|
||||||
|
rsp, err := client.BaseAccount(kavaAcc)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Printf("account sequence for %s: %d\n", kavaAcc, rsp.Sequence)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Query Tests
|
||||||
|
|
||||||
|
To test queries, a Kava node is required. Therefore, the e2e tests for the gRPC client queries can be found in the `tests/e2e` directory. Tests for new utility queries should be added as e2e tests under the `test/e2e` directory.
|
50
client/grpc/client.go
Normal file
50
client/grpc/client.go
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package grpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/client/grpc/query"
|
||||||
|
"github.com/0glabs/0g-chain/client/grpc/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// KavaGrpcClient enables the usage of kava grpc query clients and query utils
|
||||||
|
type KavaGrpcClient struct {
|
||||||
|
config KavaGrpcClientConfig
|
||||||
|
|
||||||
|
// Query clients for cosmos and kava modules
|
||||||
|
Query *query.QueryClient
|
||||||
|
|
||||||
|
// Utils for common queries (ie fetch an unpacked BaseAccount)
|
||||||
|
*util.Util
|
||||||
|
}
|
||||||
|
|
||||||
|
// KavaGrpcClientConfig is a configuration struct for a KavaGrpcClient
|
||||||
|
type KavaGrpcClientConfig struct {
|
||||||
|
// note: add future config options here
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new KavaGrpcClient via a grpc url
|
||||||
|
func NewClient(grpcUrl string) (*KavaGrpcClient, error) {
|
||||||
|
return NewClientWithConfig(grpcUrl, NewDefaultConfig())
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientWithConfig creates a new KavaGrpcClient via a grpc url and config
|
||||||
|
func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpcClient, error) {
|
||||||
|
if grpcUrl == "" {
|
||||||
|
return nil, errors.New("grpc url cannot be empty")
|
||||||
|
}
|
||||||
|
query, error := query.NewQueryClient(grpcUrl)
|
||||||
|
if error != nil {
|
||||||
|
return nil, error
|
||||||
|
}
|
||||||
|
client := &KavaGrpcClient{
|
||||||
|
Query: query,
|
||||||
|
Util: util.NewUtil(query),
|
||||||
|
config: config,
|
||||||
|
}
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDefaultConfig() KavaGrpcClientConfig {
|
||||||
|
return KavaGrpcClientConfig{}
|
||||||
|
}
|
15
client/grpc/client_test.go
Normal file
15
client/grpc/client_test.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package grpc_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/client/grpc"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewClient_InvalidEndpoint(t *testing.T) {
|
||||||
|
_, err := grpc.NewClient("invalid-url")
|
||||||
|
require.ErrorContains(t, err, "unknown grpc url scheme")
|
||||||
|
_, err = grpc.NewClient("")
|
||||||
|
require.ErrorContains(t, err, "grpc url cannot be empty")
|
||||||
|
}
|
@ -1,25 +1,21 @@
|
|||||||
package util
|
package query
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"google.golang.org/grpc/metadata"
|
|
||||||
|
|
||||||
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewGrpcConnection parses a GRPC endpoint and creates a connection to it
|
// newGrpcConnection parses a GRPC endpoint and creates a connection to it
|
||||||
func NewGrpcConnection(endpoint string) (*grpc.ClientConn, error) {
|
func newGrpcConnection(ctx context.Context, endpoint string) (*grpc.ClientConn, error) {
|
||||||
grpcUrl, err := url.Parse(endpoint)
|
grpcUrl, err := url.Parse(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("failed to parse grpc connection \"%s\": %v", endpoint, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var creds credentials.TransportCredentials
|
var creds credentials.TransportCredentials
|
||||||
@ -33,15 +29,10 @@ func NewGrpcConnection(endpoint string) (*grpc.ClientConn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
secureOpt := grpc.WithTransportCredentials(creds)
|
secureOpt := grpc.WithTransportCredentials(creds)
|
||||||
grpcConn, err := grpc.Dial(grpcUrl.Host, secureOpt)
|
grpcConn, err := grpc.DialContext(ctx, grpcUrl.Host, secureOpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return grpcConn, nil
|
return grpcConn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CtxAtHeight(height int64) context.Context {
|
|
||||||
heightStr := strconv.FormatInt(height, 10)
|
|
||||||
return metadata.AppendToOutgoingContext(context.Background(), grpctypes.GRPCBlockHeightHeader, heightStr)
|
|
||||||
}
|
|
7
client/grpc/query/doc.go
Normal file
7
client/grpc/query/doc.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/*
|
||||||
|
The query package includes Cosmos and Kava gRPC query clients.
|
||||||
|
|
||||||
|
To ensure that the `QueryClient` stays updated, add new module query clients
|
||||||
|
to the `QueryClient` whenever new modules with grpc queries are added to the Kava app.
|
||||||
|
*/
|
||||||
|
package query
|
125
client/grpc/query/query.go
Normal file
125
client/grpc/query/query.go
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
package query
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
|
||||||
|
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
|
||||||
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
authz "github.com/cosmos/cosmos-sdk/x/authz"
|
||||||
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
consensustypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
|
||||||
|
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
|
||||||
|
evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types"
|
||||||
|
govv1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||||
|
govv1beta1types "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
||||||
|
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
|
||||||
|
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
|
||||||
|
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"
|
||||||
|
|
||||||
|
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
|
||||||
|
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
|
||||||
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
|
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||||
|
|
||||||
|
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||||
|
committeetypes "github.com/0glabs/0g-chain/x/committee/types"
|
||||||
|
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
|
issuancetypes "github.com/0glabs/0g-chain/x/issuance/types"
|
||||||
|
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// QueryClient is a wrapper with all Cosmos and Kava grpc query clients
|
||||||
|
type QueryClient struct {
|
||||||
|
// cosmos-sdk query clients
|
||||||
|
|
||||||
|
Tm tmservice.ServiceClient
|
||||||
|
Tx txtypes.ServiceClient
|
||||||
|
Auth authtypes.QueryClient
|
||||||
|
Authz authz.QueryClient
|
||||||
|
Bank banktypes.QueryClient
|
||||||
|
Distribution disttypes.QueryClient
|
||||||
|
Evidence evidencetypes.QueryClient
|
||||||
|
Gov govv1types.QueryClient
|
||||||
|
GovBeta govv1beta1types.QueryClient
|
||||||
|
Mint minttypes.QueryClient
|
||||||
|
Params paramstypes.QueryClient
|
||||||
|
Slashing slashingtypes.QueryClient
|
||||||
|
Staking stakingtypes.QueryClient
|
||||||
|
Upgrade upgradetypes.QueryClient
|
||||||
|
Consensus consensustypes.QueryClient
|
||||||
|
|
||||||
|
// 3rd party query clients
|
||||||
|
|
||||||
|
Evm evmtypes.QueryClient
|
||||||
|
Feemarket feemarkettypes.QueryClient
|
||||||
|
IbcClient ibcclienttypes.QueryClient
|
||||||
|
IbcTransfer ibctransfertypes.QueryClient
|
||||||
|
|
||||||
|
// kava module query clients
|
||||||
|
|
||||||
|
Auction auctiontypes.QueryClient
|
||||||
|
Bep3 bep3types.QueryClient
|
||||||
|
Cdp cdptypes.QueryClient
|
||||||
|
Committee committeetypes.QueryClient
|
||||||
|
Community communitytypes.QueryClient
|
||||||
|
Earn earntypes.QueryClient
|
||||||
|
Evmutil evmutiltypes.QueryClient
|
||||||
|
Hard hardtypes.QueryClient
|
||||||
|
Incentive incentivetypes.QueryClient
|
||||||
|
Issuance issuancetypes.QueryClient
|
||||||
|
Kavadist kavadisttypes.QueryClient
|
||||||
|
Liquid liquidtypes.QueryClient
|
||||||
|
Pricefeed pricefeedtypes.QueryClient
|
||||||
|
Savings savingstypes.QueryClient
|
||||||
|
Swap swaptypes.QueryClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewQueryClient creates a new QueryClient and initializes all the module query clients
|
||||||
|
func NewQueryClient(grpcEndpoint string) (*QueryClient, error) {
|
||||||
|
conn, err := newGrpcConnection(context.Background(), grpcEndpoint)
|
||||||
|
if err != nil {
|
||||||
|
return &QueryClient{}, err
|
||||||
|
}
|
||||||
|
client := &QueryClient{
|
||||||
|
Tm: tmservice.NewServiceClient(conn),
|
||||||
|
Tx: txtypes.NewServiceClient(conn),
|
||||||
|
Auth: authtypes.NewQueryClient(conn),
|
||||||
|
Authz: authz.NewQueryClient(conn),
|
||||||
|
Bank: banktypes.NewQueryClient(conn),
|
||||||
|
Distribution: disttypes.NewQueryClient(conn),
|
||||||
|
Evidence: evidencetypes.NewQueryClient(conn),
|
||||||
|
Gov: govv1types.NewQueryClient(conn),
|
||||||
|
GovBeta: govv1beta1types.NewQueryClient(conn),
|
||||||
|
Mint: minttypes.NewQueryClient(conn),
|
||||||
|
Params: paramstypes.NewQueryClient(conn),
|
||||||
|
Slashing: slashingtypes.NewQueryClient(conn),
|
||||||
|
Staking: stakingtypes.NewQueryClient(conn),
|
||||||
|
Upgrade: upgradetypes.NewQueryClient(conn),
|
||||||
|
Consensus: consensustypes.NewQueryClient(conn),
|
||||||
|
|
||||||
|
Evm: evmtypes.NewQueryClient(conn),
|
||||||
|
Feemarket: feemarkettypes.NewQueryClient(conn),
|
||||||
|
IbcClient: ibcclienttypes.NewQueryClient(conn),
|
||||||
|
IbcTransfer: ibctransfertypes.NewQueryClient(conn),
|
||||||
|
|
||||||
|
Auction: auctiontypes.NewQueryClient(conn),
|
||||||
|
Bep3: bep3types.NewQueryClient(conn),
|
||||||
|
Cdp: cdptypes.NewQueryClient(conn),
|
||||||
|
Committee: committeetypes.NewQueryClient(conn),
|
||||||
|
Community: communitytypes.NewQueryClient(conn),
|
||||||
|
Earn: earntypes.NewQueryClient(conn),
|
||||||
|
Evmutil: evmutiltypes.NewQueryClient(conn),
|
||||||
|
Hard: hardtypes.NewQueryClient(conn),
|
||||||
|
Incentive: incentivetypes.NewQueryClient(conn),
|
||||||
|
Issuance: issuancetypes.NewQueryClient(conn),
|
||||||
|
Kavadist: kavadisttypes.NewQueryClient(conn),
|
||||||
|
Liquid: liquidtypes.NewQueryClient(conn),
|
||||||
|
Pricefeed: pricefeedtypes.NewQueryClient(conn),
|
||||||
|
Savings: savingstypes.NewQueryClient(conn),
|
||||||
|
Swap: swaptypes.NewQueryClient(conn),
|
||||||
|
}
|
||||||
|
return client, nil
|
||||||
|
}
|
74
client/grpc/query/query_test.go
Normal file
74
client/grpc/query/query_test.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package query_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/client/grpc/query"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewQueryClient_InvalidGprc(t *testing.T) {
|
||||||
|
t.Run("valid connection", func(t *testing.T) {
|
||||||
|
conn, err := query.NewQueryClient("http://localhost:1234")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, conn)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("non-empty url", func(t *testing.T) {
|
||||||
|
_, err := query.NewQueryClient("")
|
||||||
|
require.ErrorContains(t, err, "unknown grpc url scheme")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("invalid url scheme", func(t *testing.T) {
|
||||||
|
_, err := query.NewQueryClient("ftp://localhost:1234")
|
||||||
|
require.ErrorContains(t, err, "unknown grpc url scheme")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNewQueryClient_ValidClient(t *testing.T) {
|
||||||
|
t.Run("all clients are created", func(t *testing.T) {
|
||||||
|
client, err := query.NewQueryClient("http://localhost:1234")
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotNil(t, client)
|
||||||
|
|
||||||
|
// validate cosmos clients
|
||||||
|
require.NotNil(t, client.Tm)
|
||||||
|
require.NotNil(t, client.Tx)
|
||||||
|
require.NotNil(t, client.Auth)
|
||||||
|
require.NotNil(t, client.Authz)
|
||||||
|
require.NotNil(t, client.Bank)
|
||||||
|
require.NotNil(t, client.Distribution)
|
||||||
|
require.NotNil(t, client.Evidence)
|
||||||
|
require.NotNil(t, client.Gov)
|
||||||
|
require.NotNil(t, client.GovBeta)
|
||||||
|
require.NotNil(t, client.Mint)
|
||||||
|
require.NotNil(t, client.Params)
|
||||||
|
require.NotNil(t, client.Slashing)
|
||||||
|
require.NotNil(t, client.Staking)
|
||||||
|
require.NotNil(t, client.Upgrade)
|
||||||
|
require.NotNil(t, client.Consensus)
|
||||||
|
|
||||||
|
// validate 3rd party clients
|
||||||
|
require.NotNil(t, client.Evm)
|
||||||
|
require.NotNil(t, client.Feemarket)
|
||||||
|
require.NotNil(t, client.IbcClient)
|
||||||
|
require.NotNil(t, client.IbcTransfer)
|
||||||
|
|
||||||
|
// validate kava clients
|
||||||
|
require.NotNil(t, client.Auction)
|
||||||
|
require.NotNil(t, client.Bep3)
|
||||||
|
require.NotNil(t, client.Cdp)
|
||||||
|
require.NotNil(t, client.Committee)
|
||||||
|
require.NotNil(t, client.Community)
|
||||||
|
require.NotNil(t, client.Earn)
|
||||||
|
require.NotNil(t, client.Evmutil)
|
||||||
|
require.NotNil(t, client.Hard)
|
||||||
|
require.NotNil(t, client.Incentive)
|
||||||
|
require.NotNil(t, client.Issuance)
|
||||||
|
require.NotNil(t, client.Kavadist)
|
||||||
|
require.NotNil(t, client.Liquid)
|
||||||
|
require.NotNil(t, client.Pricefeed)
|
||||||
|
require.NotNil(t, client.Savings)
|
||||||
|
require.NotNil(t, client.Swap)
|
||||||
|
})
|
||||||
|
}
|
41
client/grpc/util/account.go
Normal file
41
client/grpc/util/account.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Account fetches an account via an address and returns the unpacked account
|
||||||
|
func (u *Util) Account(addr string) (authtypes.AccountI, error) {
|
||||||
|
res, err := u.query.Auth.Account(context.Background(), &authtypes.QueryAccountRequest{
|
||||||
|
Address: addr,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to fetch account: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var acc authtypes.AccountI
|
||||||
|
err = u.encodingConfig.Marshaler.UnpackAny(res.Account, &acc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to unpack account: %w", err)
|
||||||
|
}
|
||||||
|
return acc, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BaseAccount fetches a base account via an address or returns an error if
|
||||||
|
// the account is not a base account
|
||||||
|
func (u *Util) BaseAccount(addr string) (authtypes.BaseAccount, error) {
|
||||||
|
acc, err := u.Account(addr)
|
||||||
|
if err != nil {
|
||||||
|
return authtypes.BaseAccount{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
bAcc, ok := acc.(*authtypes.BaseAccount)
|
||||||
|
if !ok {
|
||||||
|
return authtypes.BaseAccount{}, fmt.Errorf("%s is not a base account", addr)
|
||||||
|
}
|
||||||
|
|
||||||
|
return *bAcc, nil
|
||||||
|
}
|
8
client/grpc/util/doc.go
Normal file
8
client/grpc/util/doc.go
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
The util package contains utility functions for the Kava gRPC client.
|
||||||
|
|
||||||
|
For example, `account.go` includes account-related query helpers.
|
||||||
|
In this file, utilities such as `client.Util.BaseAccount(addr)` is exposed to
|
||||||
|
query an account and return an unpacked `BaseAccount` instance.
|
||||||
|
*/
|
||||||
|
package util
|
32
client/grpc/util/util.go
Normal file
32
client/grpc/util/util.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
|
||||||
|
"google.golang.org/grpc/metadata"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/app/params"
|
||||||
|
query "github.com/0glabs/0g-chain/client/grpc/query"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Util contains utility functions for the Kava gRPC client
|
||||||
|
type Util struct {
|
||||||
|
query *query.QueryClient
|
||||||
|
encodingConfig params.EncodingConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUtil creates a new Util instance
|
||||||
|
func NewUtil(query *query.QueryClient) *Util {
|
||||||
|
return &Util{
|
||||||
|
query: query,
|
||||||
|
encodingConfig: app.MakeEncodingConfig(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u *Util) CtxAtHeight(height int64) context.Context {
|
||||||
|
heightStr := strconv.FormatInt(height, 10)
|
||||||
|
return metadata.AppendToOutgoingContext(context.Background(), grpctypes.GRPCBlockHeightHeader, heightStr)
|
||||||
|
}
|
@ -13,7 +13,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/cometbft/cometbft/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
@ -132,7 +132,7 @@ func (br BaseReq) ValidateBasic(w http.ResponseWriter) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadRESTReq reads and unmarshals a Request's body to the the BaseReq struct.
|
// ReadRESTReq reads and unmarshals a Request's body to the BaseReq struct.
|
||||||
// Writes an error response to ResponseWriter and returns false if errors occurred.
|
// Writes an error response to ResponseWriter and returns false if errors occurred.
|
||||||
func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.LegacyAmino, req interface{}) bool {
|
func ReadRESTReq(w http.ResponseWriter, r *http.Request, cdc *codec.LegacyAmino, req interface{}) bool {
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
|
@ -12,15 +12,14 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/client/rest"
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||||
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
|
|
||||||
"github.com/cosmos/cosmos-sdk/types"
|
"github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/kava-labs/kava/client/rest"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBaseReq_Sanitize(t *testing.T) {
|
func TestBaseReq_Sanitize(t *testing.T) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -7,6 +7,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
cometbftdb "github.com/cometbft/cometbft-db"
|
||||||
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
|
tmtypes "github.com/cometbft/cometbft/types"
|
||||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
@ -19,20 +22,18 @@ import (
|
|||||||
ethermintflags "github.com/evmos/ethermint/server/flags"
|
ethermintflags "github.com/evmos/ethermint/server/flags"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/tendermint/tendermint/libs/log"
|
|
||||||
db "github.com/tendermint/tm-db"
|
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/kava-labs/kava/app/params"
|
"github.com/0glabs/0g-chain/app/params"
|
||||||
metricstypes "github.com/kava-labs/kava/x/metrics/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagMempoolEnableAuth = "mempool.enable-authentication"
|
flagMempoolEnableAuth = "mempool.enable-authentication"
|
||||||
flagMempoolAuthAddresses = "mempool.authorized-addresses"
|
flagMempoolAuthAddresses = "mempool.authorized-addresses"
|
||||||
|
flagSkipLoadLatest = "skip-load-latest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// appCreator holds functions used by the sdk server to control the kava app.
|
// appCreator holds functions used by the sdk server to control the 0g-chain app.
|
||||||
// The methods implement types in cosmos-sdk/server/types
|
// The methods implement types in cosmos-sdk/server/types
|
||||||
type appCreator struct {
|
type appCreator struct {
|
||||||
encodingConfig params.EncodingConfig
|
encodingConfig params.EncodingConfig
|
||||||
@ -41,7 +42,7 @@ type appCreator struct {
|
|||||||
// newApp loads config from AppOptions and returns a new app.
|
// newApp loads config from AppOptions and returns a new app.
|
||||||
func (ac appCreator) newApp(
|
func (ac appCreator) newApp(
|
||||||
logger log.Logger,
|
logger log.Logger,
|
||||||
db db.DB,
|
db cometbftdb.DB,
|
||||||
traceStore io.Writer,
|
traceStore io.Writer,
|
||||||
appOpts servertypes.AppOptions,
|
appOpts servertypes.AppOptions,
|
||||||
) servertypes.Application {
|
) servertypes.Application {
|
||||||
@ -62,7 +63,7 @@ func (ac appCreator) newApp(
|
|||||||
|
|
||||||
homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
|
homeDir := cast.ToString(appOpts.Get(flags.FlagHome))
|
||||||
snapshotDir := filepath.Join(homeDir, "data", "snapshots") // TODO can these directory names be imported from somewhere?
|
snapshotDir := filepath.Join(homeDir, "data", "snapshots") // TODO can these directory names be imported from somewhere?
|
||||||
snapshotDB, err := sdk.NewLevelDB("metadata", snapshotDir)
|
snapshotDB, err := cometbftdb.NewDB("metadata", server.GetAppDBBackend(appOpts), snapshotDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -89,10 +90,26 @@ func (ac appCreator) newApp(
|
|||||||
cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)),
|
cast.ToUint32(appOpts.Get(server.FlagStateSyncSnapshotKeepRecent)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Setup chainId
|
||||||
|
chainID := cast.ToString(appOpts.Get(flags.FlagChainID))
|
||||||
|
if len(chainID) == 0 {
|
||||||
|
// fallback to genesis chain-id
|
||||||
|
appGenesis, err := tmtypes.GenesisDocFromFile(filepath.Join(homeDir, "config", "genesis.json"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
chainID = appGenesis.ChainID
|
||||||
|
}
|
||||||
|
|
||||||
|
skipLoadLatest := false
|
||||||
|
if appOpts.Get(flagSkipLoadLatest) != nil {
|
||||||
|
skipLoadLatest = cast.ToBool(appOpts.Get(flagSkipLoadLatest))
|
||||||
|
}
|
||||||
|
|
||||||
return app.NewApp(
|
return app.NewApp(
|
||||||
logger, db, homeDir, traceStore, ac.encodingConfig,
|
logger, db, homeDir, traceStore, ac.encodingConfig,
|
||||||
app.Options{
|
app.Options{
|
||||||
SkipLoadLatest: false,
|
SkipLoadLatest: skipLoadLatest,
|
||||||
SkipUpgradeHeights: skipUpgradeHeights,
|
SkipUpgradeHeights: skipUpgradeHeights,
|
||||||
SkipGenesisInvariants: cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)),
|
SkipGenesisInvariants: cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)),
|
||||||
InvariantCheckPeriod: cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
|
InvariantCheckPeriod: cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
|
||||||
@ -100,7 +117,6 @@ func (ac appCreator) newApp(
|
|||||||
MempoolAuthAddresses: mempoolAuthAddresses,
|
MempoolAuthAddresses: mempoolAuthAddresses,
|
||||||
EVMTrace: cast.ToString(appOpts.Get(ethermintflags.EVMTracer)),
|
EVMTrace: cast.ToString(appOpts.Get(ethermintflags.EVMTracer)),
|
||||||
EVMMaxGasWanted: cast.ToUint64(appOpts.Get(ethermintflags.EVMMaxTxGasWanted)),
|
EVMMaxGasWanted: cast.ToUint64(appOpts.Get(ethermintflags.EVMMaxTxGasWanted)),
|
||||||
TelemetryOptions: metricstypes.TelemetryOptionsFromAppOpts(appOpts),
|
|
||||||
},
|
},
|
||||||
baseapp.SetPruning(pruningOpts),
|
baseapp.SetPruning(pruningOpts),
|
||||||
baseapp.SetMinGasPrices(strings.Replace(cast.ToString(appOpts.Get(server.FlagMinGasPrices)), ";", ",", -1)),
|
baseapp.SetMinGasPrices(strings.Replace(cast.ToString(appOpts.Get(server.FlagMinGasPrices)), ";", ",", -1)),
|
||||||
@ -114,18 +130,20 @@ func (ac appCreator) newApp(
|
|||||||
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))),
|
baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(server.FlagIAVLCacheSize))),
|
||||||
baseapp.SetIAVLDisableFastNode(cast.ToBool(iavlDisableFastNode)),
|
baseapp.SetIAVLDisableFastNode(cast.ToBool(iavlDisableFastNode)),
|
||||||
baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(server.FlagIAVLLazyLoading))),
|
baseapp.SetIAVLLazyLoading(cast.ToBool(appOpts.Get(server.FlagIAVLLazyLoading))),
|
||||||
|
baseapp.SetChainID(chainID),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// appExport writes out an app's state to json.
|
// appExport writes out an app's state to json.
|
||||||
func (ac appCreator) appExport(
|
func (ac appCreator) appExport(
|
||||||
logger log.Logger,
|
logger log.Logger,
|
||||||
db db.DB,
|
db cometbftdb.DB,
|
||||||
traceStore io.Writer,
|
traceStore io.Writer,
|
||||||
height int64,
|
height int64,
|
||||||
forZeroHeight bool,
|
forZeroHeight bool,
|
||||||
jailAllowedAddrs []string,
|
jailAllowedAddrs []string,
|
||||||
appOpts servertypes.AppOptions,
|
appOpts servertypes.AppOptions,
|
||||||
|
modulesToExport []string,
|
||||||
) (servertypes.ExportedApp, error) {
|
) (servertypes.ExportedApp, error) {
|
||||||
homePath, ok := appOpts.Get(flags.FlagHome).(string)
|
homePath, ok := appOpts.Get(flags.FlagHome).(string)
|
||||||
if !ok || homePath == "" {
|
if !ok || homePath == "" {
|
||||||
@ -146,7 +164,7 @@ func (ac appCreator) appExport(
|
|||||||
} else {
|
} else {
|
||||||
tempApp = app.NewApp(logger, db, homePath, traceStore, ac.encodingConfig, options)
|
tempApp = app.NewApp(logger, db, homePath, traceStore, ac.encodingConfig, options)
|
||||||
}
|
}
|
||||||
return tempApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
|
return tempApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport)
|
||||||
}
|
}
|
||||||
|
|
||||||
// addStartCmdFlags adds flags to the server start command.
|
// addStartCmdFlags adds flags to the server start command.
|
@ -1,16 +1,16 @@
|
|||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
tmtypes "github.com/cometbft/cometbft/types"
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
"github.com/cosmos/cosmos-sdk/version"
|
||||||
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/kava-labs/kava/app/params"
|
"github.com/0glabs/0g-chain/app/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AssertInvariantsCmd(config params.EncodingConfig) *cobra.Command {
|
func AssertInvariantsCmd(config params.EncodingConfig) *cobra.Command {
|
@ -1,5 +1,5 @@
|
|||||||
// Sourced from https://github.com/evmos/ethermint/blob/main/cmd/ethermintd/genaccounts.go
|
// Sourced from https://github.com/evmos/ethermint/blob/main/cmd/ethermintd/genaccounts.go
|
||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
56
cmd/0gchaind/iavlviewer/data.go
Normal file
56
cmd/0gchaind/iavlviewer/data.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package iavlviewer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/cosmos/iavl"
|
||||||
|
ethermintserver "github.com/evmos/ethermint/server"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newDataCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "data <prefix> [version number]",
|
||||||
|
Short: "View all keys, hash, & size of tree.",
|
||||||
|
Args: cobra.RangeArgs(1, 2),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
prefix := args[0]
|
||||||
|
version := 0
|
||||||
|
if len(args) == 2 {
|
||||||
|
var err error
|
||||||
|
version, err = parseVersion(args[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tree, err := openPrefixTree(opts, cmd, prefix, version)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printKeys(tree)
|
||||||
|
hash, err := tree.Hash()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Printf("Hash: %X\n", hash)
|
||||||
|
fmt.Printf("Size: %X\n", tree.Size())
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func printKeys(tree *iavl.MutableTree) {
|
||||||
|
fmt.Println("Printing all keys with hashed values (to detect diff)")
|
||||||
|
tree.Iterate(func(key []byte, value []byte) bool { //nolint:errcheck
|
||||||
|
printKey := parseWeaveKey(key)
|
||||||
|
digest := sha256.Sum256(value)
|
||||||
|
fmt.Printf(" %s\n %X\n", printKey, digest)
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
42
cmd/0gchaind/iavlviewer/hash.go
Normal file
42
cmd/0gchaind/iavlviewer/hash.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package iavlviewer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
ethermintserver "github.com/evmos/ethermint/server"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newHashCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "hash <prefix> [version number]",
|
||||||
|
Short: "Print the root hash of the iavl tree.",
|
||||||
|
Args: cobra.RangeArgs(1, 2),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
prefix := args[0]
|
||||||
|
version := 0
|
||||||
|
if len(args) == 2 {
|
||||||
|
var err error
|
||||||
|
version, err = parseVersion(args[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tree, err := openPrefixTree(opts, cmd, prefix, version)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
hash, err := tree.Hash()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Printf("Hash: %X\n", hash)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
83
cmd/0gchaind/iavlviewer/root.go
Normal file
83
cmd/0gchaind/iavlviewer/root.go
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
package iavlviewer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
dbm "github.com/cometbft/cometbft-db"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
|
ethermintserver "github.com/evmos/ethermint/server"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/cosmos/iavl"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultCacheSize int = 10000
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "iavlviewer <data|hash|shape|versions> <prefix> [version number]",
|
||||||
|
Short: "Output various data, hashes, and calculations for an iavl tree",
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.AddCommand(newDataCmd(opts))
|
||||||
|
cmd.AddCommand(newHashCmd(opts))
|
||||||
|
cmd.AddCommand(newShapeCmd(opts))
|
||||||
|
cmd.AddCommand(newVersionsCmd(opts))
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseVersion(arg string) (int, error) {
|
||||||
|
version, err := strconv.Atoi(arg)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("invalid version number: '%s'", arg)
|
||||||
|
}
|
||||||
|
return version, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func openPrefixTree(opts ethermintserver.StartOptions, cmd *cobra.Command, prefix string, version int) (*iavl.MutableTree, error) {
|
||||||
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||||
|
ctx := server.GetServerContextFromCmd(cmd)
|
||||||
|
ctx.Config.SetRoot(clientCtx.HomeDir)
|
||||||
|
|
||||||
|
db, err := opts.DBOpener(ctx.Viper, clientCtx.HomeDir, server.GetAppDBBackend(ctx.Viper))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to open database at %s: %s", clientCtx.HomeDir, err)
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err := db.Close(); err != nil {
|
||||||
|
ctx.Logger.Error("error closing db", "error", err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
tree, err := readTree(db, version, []byte(prefix))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to read tree with prefix %s: %s", prefix, err)
|
||||||
|
}
|
||||||
|
return tree, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadTree loads an iavl tree from the directory
|
||||||
|
// If version is 0, load latest, otherwise, load named version
|
||||||
|
// The prefix represents which iavl tree you want to read. The iaviwer will always set a prefix.
|
||||||
|
func readTree(db dbm.DB, version int, prefix []byte) (*iavl.MutableTree, error) {
|
||||||
|
if len(prefix) != 0 {
|
||||||
|
db = dbm.NewPrefixDB(db, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
tree, err := iavl.NewMutableTree(db, DefaultCacheSize, false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ver, err := tree.LoadVersion(int64(version))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
fmt.Printf("Latest version: %d\n", ver)
|
||||||
|
fmt.Printf("Got version: %d\n", version)
|
||||||
|
return tree, err
|
||||||
|
}
|
47
cmd/0gchaind/iavlviewer/shape.go
Normal file
47
cmd/0gchaind/iavlviewer/shape.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package iavlviewer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cosmos/iavl"
|
||||||
|
ethermintserver "github.com/evmos/ethermint/server"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newShapeCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "shape <prefix> [version number]",
|
||||||
|
Short: "View shape of iavl tree.",
|
||||||
|
Args: cobra.RangeArgs(1, 2),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
prefix := args[0]
|
||||||
|
version := 0
|
||||||
|
if len(args) == 2 {
|
||||||
|
var err error
|
||||||
|
version, err = parseVersion(args[1])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tree, err := openPrefixTree(opts, cmd, prefix, version)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printShape(tree)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func printShape(tree *iavl.MutableTree) {
|
||||||
|
// shape := tree.RenderShape(" ", nil)
|
||||||
|
// TODO: handle this error
|
||||||
|
shape, _ := tree.RenderShape(" ", nodeEncoder)
|
||||||
|
fmt.Println(strings.Join(shape, "\n"))
|
||||||
|
}
|
74
cmd/0gchaind/iavlviewer/versions.go
Normal file
74
cmd/0gchaind/iavlviewer/versions.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package iavlviewer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/cosmos/iavl"
|
||||||
|
ethermintserver "github.com/evmos/ethermint/server"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func newVersionsCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "versions <prefix>",
|
||||||
|
Short: "Print all versions of iavl tree",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
prefix := args[0]
|
||||||
|
tree, err := openPrefixTree(opts, cmd, prefix, 15)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printVersions(tree)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func printVersions(tree *iavl.MutableTree) {
|
||||||
|
versions := tree.AvailableVersions()
|
||||||
|
fmt.Println("Available versions:")
|
||||||
|
for _, v := range versions {
|
||||||
|
fmt.Printf(" %d\n", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// parseWeaveKey assumes a separating : where all in front should be ascii,
|
||||||
|
// and all afterwards may be ascii or binary
|
||||||
|
func parseWeaveKey(key []byte) string {
|
||||||
|
cut := bytes.IndexRune(key, ':')
|
||||||
|
if cut == -1 {
|
||||||
|
return encodeID(key)
|
||||||
|
}
|
||||||
|
prefix := key[:cut]
|
||||||
|
id := key[cut+1:]
|
||||||
|
return fmt.Sprintf("%s:%s", encodeID(prefix), encodeID(id))
|
||||||
|
}
|
||||||
|
|
||||||
|
// casts to a string if it is printable ascii, hex-encodes otherwise
|
||||||
|
func encodeID(id []byte) string {
|
||||||
|
for _, b := range id {
|
||||||
|
if b < 0x20 || b >= 0x80 {
|
||||||
|
return strings.ToUpper(hex.EncodeToString(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func nodeEncoder(id []byte, depth int, isLeaf bool) string {
|
||||||
|
prefix := fmt.Sprintf("-%d ", depth)
|
||||||
|
if isLeaf {
|
||||||
|
prefix = fmt.Sprintf("*%d ", depth)
|
||||||
|
}
|
||||||
|
if len(id) == 0 {
|
||||||
|
return fmt.Sprintf("%s<nil>", prefix)
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%s%s", prefix, parseWeaveKey(id))
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
package client
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
|
||||||
|
"github.com/cometbft/cometbft/libs/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/tendermint/tendermint/libs/cli"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
ethclient "github.com/evmos/ethermint/client"
|
ethclient "github.com/evmos/ethermint/client"
|
||||||
@ -18,9 +18,9 @@ import (
|
|||||||
|
|
||||||
var ethFlag = "eth"
|
var ethFlag = "eth"
|
||||||
|
|
||||||
// KeyCommands registers a sub-tree of commands to interact with
|
// keyCommands registers a sub-tree of commands to interact with
|
||||||
// local private key storage.
|
// local private key storage.
|
||||||
func KeyCommands(defaultNodeHome string) *cobra.Command {
|
func keyCommands(defaultNodeHome string) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "keys",
|
Use: "keys",
|
||||||
Short: "Manage your application's keys",
|
Short: "Manage your application's keys",
|
||||||
@ -52,6 +52,13 @@ The pass backend requires GnuPG: https://gnupg.org/
|
|||||||
addCmd := keys.AddKeyCommand()
|
addCmd := keys.AddKeyCommand()
|
||||||
addCmd.Flags().Bool(ethFlag, false, "use default evm coin-type (60) and key signing algorithm (\"eth_secp256k1\")")
|
addCmd.Flags().Bool(ethFlag, false, "use default evm coin-type (60) and key signing algorithm (\"eth_secp256k1\")")
|
||||||
|
|
||||||
|
algoFlag := addCmd.Flag(flags.FlagKeyType)
|
||||||
|
algoFlag.DefValue = string(hd.EthSecp256k1Type)
|
||||||
|
err := algoFlag.Value.Set(string(hd.EthSecp256k1Type))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
addCmd.RunE = runAddCmd
|
addCmd.RunE = runAddCmd
|
||||||
|
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
@ -100,7 +107,7 @@ func runAddCmd(cmd *cobra.Command, args []string) error {
|
|||||||
eth, _ := cmd.Flags().GetBool(ethFlag)
|
eth, _ := cmd.Flags().GetBool(ethFlag)
|
||||||
if eth {
|
if eth {
|
||||||
cmd.Print("eth flag specified: using coin-type 60 and signing algorithm eth_secp256k1\n")
|
cmd.Print("eth flag specified: using coin-type 60 and signing algorithm eth_secp256k1\n")
|
||||||
cmd.Flags().Set(flags.FlagKeyAlgorithm, string(hd.EthSecp256k1Type))
|
cmd.Flags().Set(flags.FlagKeyType, string(hd.EthSecp256k1Type))
|
||||||
cmd.Flags().Set("coin-type", "60")
|
cmd.Flags().Set("coin-type", "60")
|
||||||
}
|
}
|
||||||
|
|
@ -6,14 +6,13 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/kava-labs/kava/cmd/kava/cmd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
rootCmd := cmd.NewRootCmd()
|
chaincfg.SetSDKConfig().Seal()
|
||||||
|
rootCmd := NewRootCmd()
|
||||||
if err := svrcmd.Execute(rootCmd, cmd.EnvPrefix, app.DefaultNodeHome); err != nil {
|
if err := svrcmd.Execute(rootCmd, chaincfg.EnvPrefix, chaincfg.DefaultNodeHome); err != nil {
|
||||||
switch e := err.(type) {
|
switch e := err.(type) {
|
||||||
case server.ErrorCode:
|
case server.ErrorCode:
|
||||||
os.Exit(e.Code)
|
os.Exit(e.Code)
|
@ -1,4 +1,4 @@
|
|||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newQueryCmd creates all the commands for querying blockchain state.
|
// newQueryCmd creates all the commands for querying blockchain state.
|
216
cmd/0gchaind/rocksdb/compact.go
Normal file
216
cmd/0gchaind/rocksdb/compact.go
Normal file
@ -0,0 +1,216 @@
|
|||||||
|
//go:build rocksdb
|
||||||
|
// +build rocksdb
|
||||||
|
|
||||||
|
package rocksdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/cmd/opendb"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
|
"github.com/linxGnu/grocksdb"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
flagPrintStatsInterval = "print-stats-interval"
|
||||||
|
)
|
||||||
|
|
||||||
|
var allowedDBs = []string{"application", "blockstore", "state"}
|
||||||
|
|
||||||
|
func CompactRocksDBCmd() *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: fmt.Sprintf(
|
||||||
|
"compact <%s>",
|
||||||
|
strings.Join(allowedDBs, "|"),
|
||||||
|
),
|
||||||
|
Short: "force compacts RocksDB",
|
||||||
|
Long: `This is a utility command that performs a force compaction on the state or
|
||||||
|
blockstore. This should only be run once the node has stopped.`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||||
|
|
||||||
|
statsIntervalStr, err := cmd.Flags().GetString(flagPrintStatsInterval)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
statsInterval, err := time.ParseDuration(statsIntervalStr)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to parse duration for --%s: %w", flagPrintStatsInterval, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||||
|
ctx := server.GetServerContextFromCmd(cmd)
|
||||||
|
|
||||||
|
if server.GetAppDBBackend(ctx.Viper) != "rocksdb" {
|
||||||
|
return errors.New("compaction is currently only supported with rocksdb")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !slices.Contains(allowedDBs, args[0]) {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"invalid db name, must be one of the following: %s",
|
||||||
|
strings.Join(allowedDBs, ", "),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return compactRocksDBs(clientCtx.HomeDir, logger, args[0], statsInterval)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flags().String(flagPrintStatsInterval, "1m", "duration string for how often to print compaction stats")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// compactRocksDBs performs a manual compaction on the given db.
|
||||||
|
func compactRocksDBs(
|
||||||
|
rootDir string,
|
||||||
|
logger log.Logger,
|
||||||
|
dbName string,
|
||||||
|
statsInterval time.Duration,
|
||||||
|
) error {
|
||||||
|
dbPath := filepath.Join(rootDir, "data", dbName+".db")
|
||||||
|
|
||||||
|
dbOpts, cfOpts, err := opendb.LoadLatestOptions(dbPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.Info("opening db", "path", dbPath)
|
||||||
|
db, _, err := grocksdb.OpenDbColumnFamilies(
|
||||||
|
dbOpts,
|
||||||
|
dbPath,
|
||||||
|
[]string{opendb.DefaultColumnFamilyName},
|
||||||
|
[]*grocksdb.Options{cfOpts},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("failed to initialize cometbft db", "path", dbPath, "err", err)
|
||||||
|
return fmt.Errorf("failed to open db %s %w", dbPath, err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
logColumnFamilyMetadata(db, logger)
|
||||||
|
|
||||||
|
logger.Info("starting compaction...", "db", dbPath)
|
||||||
|
|
||||||
|
done := make(chan bool)
|
||||||
|
registerSignalHandler(db, logger, done)
|
||||||
|
startCompactionStatsOutput(db, logger, done, statsInterval)
|
||||||
|
|
||||||
|
// Actually run the compaction
|
||||||
|
db.CompactRange(grocksdb.Range{Start: nil, Limit: nil})
|
||||||
|
logger.Info("done compaction", "db", dbPath)
|
||||||
|
|
||||||
|
done <- true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// bytesToMB converts bytes to megabytes.
|
||||||
|
func bytesToMB(bytes uint64) float64 {
|
||||||
|
return float64(bytes) / 1024 / 1024
|
||||||
|
}
|
||||||
|
|
||||||
|
// logColumnFamilyMetadata outputs the column family and level metadata.
|
||||||
|
func logColumnFamilyMetadata(
|
||||||
|
db *grocksdb.DB,
|
||||||
|
logger log.Logger,
|
||||||
|
) {
|
||||||
|
metadata := db.GetColumnFamilyMetadata()
|
||||||
|
|
||||||
|
logger.Info(
|
||||||
|
"column family metadata",
|
||||||
|
"name", metadata.Name(),
|
||||||
|
"sizeMB", bytesToMB(metadata.Size()),
|
||||||
|
"fileCount", metadata.FileCount(),
|
||||||
|
"levels", len(metadata.LevelMetas()),
|
||||||
|
)
|
||||||
|
|
||||||
|
for _, level := range metadata.LevelMetas() {
|
||||||
|
logger.Info(
|
||||||
|
fmt.Sprintf("level %d metadata", level.Level()),
|
||||||
|
"sstMetas", strconv.Itoa(len(level.SstMetas())),
|
||||||
|
"sizeMB", strconv.FormatFloat(bytesToMB(level.Size()), 'f', 2, 64),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// startCompactionStatsOutput starts a goroutine that outputs compaction stats
|
||||||
|
// every minute.
|
||||||
|
func startCompactionStatsOutput(
|
||||||
|
db *grocksdb.DB,
|
||||||
|
logger log.Logger,
|
||||||
|
done chan bool,
|
||||||
|
statsInterval time.Duration,
|
||||||
|
) {
|
||||||
|
go func() {
|
||||||
|
ticker := time.NewTicker(statsInterval)
|
||||||
|
isClosed := false
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
// Make sure we don't try reading from the closed db.
|
||||||
|
// We continue the loop so that we can make sure the done channel
|
||||||
|
// does not stall indefinitely from repeated writes and no reader.
|
||||||
|
case <-done:
|
||||||
|
logger.Debug("stopping compaction stats output")
|
||||||
|
isClosed = true
|
||||||
|
case <-ticker.C:
|
||||||
|
if !isClosed {
|
||||||
|
compactionStats := db.GetProperty("rocksdb.stats")
|
||||||
|
fmt.Printf("%s\n", compactionStats)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// registerSignalHandler registers a signal handler that will cancel any running
|
||||||
|
// compaction when the user presses Ctrl+C.
|
||||||
|
func registerSignalHandler(
|
||||||
|
db *grocksdb.DB,
|
||||||
|
logger log.Logger,
|
||||||
|
done chan bool,
|
||||||
|
) {
|
||||||
|
// https://github.com/facebook/rocksdb/wiki/RocksDB-FAQ
|
||||||
|
// Q: Can I close the DB when a manual compaction is in progress?
|
||||||
|
//
|
||||||
|
// A: No, it's not safe to do that. However, you call
|
||||||
|
// CancelAllBackgroundWork(db, true) in another thread to abort the
|
||||||
|
// running compactions, so that you can close the DB sooner. Since
|
||||||
|
// 6.5, you can also speed it up using
|
||||||
|
// DB::DisableManualCompaction().
|
||||||
|
c := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for sig := range c {
|
||||||
|
logger.Info(fmt.Sprintf(
|
||||||
|
"received %s signal, aborting running compaction... Do NOT kill me before compaction is cancelled. I will exit when compaction is cancelled.",
|
||||||
|
sig,
|
||||||
|
))
|
||||||
|
db.DisableManualCompaction()
|
||||||
|
logger.Info("manual compaction disabled")
|
||||||
|
|
||||||
|
// Stop the logging
|
||||||
|
done <- true
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
19
cmd/0gchaind/rocksdb/rocksdb.go
Normal file
19
cmd/0gchaind/rocksdb/rocksdb.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
//go:build rocksdb
|
||||||
|
// +build rocksdb
|
||||||
|
|
||||||
|
package rocksdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RocksDBCmd defines the root command containing subcommands that assist in
|
||||||
|
// rocksdb related tasks such as manual compaction.
|
||||||
|
var RocksDBCmd = &cobra.Command{
|
||||||
|
Use: "rocksdb",
|
||||||
|
Short: "RocksDB util commands",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RocksDBCmd.AddCommand(CompactRocksDBCmd())
|
||||||
|
}
|
14
cmd/0gchaind/rocksdb/rocksdb_dummy.go
Normal file
14
cmd/0gchaind/rocksdb/rocksdb_dummy.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//go:build !rocksdb
|
||||||
|
// +build !rocksdb
|
||||||
|
|
||||||
|
package rocksdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RocksDBCmd defines the root command when the rocksdb build tag is not set.
|
||||||
|
var RocksDBCmd = &cobra.Command{
|
||||||
|
Use: "rocksdb",
|
||||||
|
Short: "RocksDB util commands, disabled because rocksdb build tag not set",
|
||||||
|
}
|
@ -1,40 +1,48 @@
|
|||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/config"
|
"github.com/cosmos/cosmos-sdk/client/config"
|
||||||
"github.com/cosmos/cosmos-sdk/client/debug"
|
"github.com/cosmos/cosmos-sdk/client/debug"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
|
|
||||||
|
tmcfg "github.com/cometbft/cometbft/config"
|
||||||
|
tmcli "github.com/cometbft/cometbft/libs/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
"github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
||||||
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
||||||
|
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
|
||||||
ethermintclient "github.com/evmos/ethermint/client"
|
ethermintclient "github.com/evmos/ethermint/client"
|
||||||
"github.com/evmos/ethermint/crypto/hd"
|
"github.com/evmos/ethermint/crypto/hd"
|
||||||
ethermintserver "github.com/evmos/ethermint/server"
|
ethermintserver "github.com/evmos/ethermint/server"
|
||||||
servercfg "github.com/evmos/ethermint/server/config"
|
servercfg "github.com/evmos/ethermint/server/config"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
tmcfg "github.com/tendermint/tendermint/config"
|
|
||||||
tmcli "github.com/tendermint/tendermint/libs/cli"
|
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/kava-labs/kava/app/params"
|
"github.com/0glabs/0g-chain/app/params"
|
||||||
kavaclient "github.com/kava-labs/kava/client"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/kava-labs/kava/cmd/kava/opendb"
|
"github.com/0glabs/0g-chain/cmd/0gchaind/iavlviewer"
|
||||||
|
"github.com/0glabs/0g-chain/cmd/0gchaind/rocksdb"
|
||||||
|
"github.com/0glabs/0g-chain/cmd/opendb"
|
||||||
|
"github.com/0glabs/0g-chain/crypto/vrf"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EnvPrefix is the prefix environment variables must have to configure the app.
|
func customKeyringOptions() keyring.Option {
|
||||||
const EnvPrefix = "KAVA"
|
return func(options *keyring.Options) {
|
||||||
|
options.SupportedAlgos = append(hd.SupportedAlgorithms, vrf.VrfAlgo)
|
||||||
|
options.SupportedAlgosLedger = append(hd.SupportedAlgorithmsLedger, vrf.VrfAlgo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewRootCmd creates a new root command for the kava blockchain.
|
// NewRootCmd creates a new root command for the 0g-chain blockchain.
|
||||||
func NewRootCmd() *cobra.Command {
|
func NewRootCmd() *cobra.Command {
|
||||||
app.SetSDKConfig().Seal()
|
|
||||||
|
|
||||||
encodingConfig := app.MakeEncodingConfig()
|
encodingConfig := app.MakeEncodingConfig()
|
||||||
|
|
||||||
initClientCtx := client.Context{}.
|
initClientCtx := client.Context{}.
|
||||||
WithCodec(encodingConfig.Marshaler).
|
WithCodec(encodingConfig.Marshaler).
|
||||||
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
|
||||||
@ -42,14 +50,13 @@ func NewRootCmd() *cobra.Command {
|
|||||||
WithLegacyAmino(encodingConfig.Amino).
|
WithLegacyAmino(encodingConfig.Amino).
|
||||||
WithInput(os.Stdin).
|
WithInput(os.Stdin).
|
||||||
WithAccountRetriever(types.AccountRetriever{}).
|
WithAccountRetriever(types.AccountRetriever{}).
|
||||||
WithBroadcastMode(flags.BroadcastBlock).
|
WithBroadcastMode(flags.FlagBroadcastMode).
|
||||||
WithHomeDir(app.DefaultNodeHome).
|
WithHomeDir(chaincfg.DefaultNodeHome).
|
||||||
WithKeyringOptions(hd.EthSecp256k1Option()).
|
WithKeyringOptions(customKeyringOptions()).
|
||||||
WithViper(EnvPrefix)
|
WithViper(chaincfg.EnvPrefix)
|
||||||
|
|
||||||
rootCmd := &cobra.Command{
|
rootCmd := &cobra.Command{
|
||||||
Use: "kava",
|
Use: chaincfg.AppName,
|
||||||
Short: "Daemon and CLI for the Kava blockchain.",
|
Short: "Daemon and CLI for the 0g-chain blockchain.",
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
|
||||||
cmd.SetOut(cmd.OutOrStdout())
|
cmd.SetOut(cmd.OutOrStdout())
|
||||||
cmd.SetErr(cmd.ErrOrStderr())
|
cmd.SetErr(cmd.ErrOrStderr())
|
||||||
@ -68,7 +75,7 @@ func NewRootCmd() *cobra.Command {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
customAppTemplate, customAppConfig := servercfg.AppConfig("ukava")
|
customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.GasDenom)
|
||||||
|
|
||||||
return server.InterceptConfigsPreRunHandler(
|
return server.InterceptConfigsPreRunHandler(
|
||||||
cmd,
|
cmd,
|
||||||
@ -79,19 +86,23 @@ func NewRootCmd() *cobra.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
addSubCmds(rootCmd, encodingConfig, app.DefaultNodeHome)
|
addSubCmds(rootCmd, encodingConfig, chaincfg.DefaultNodeHome)
|
||||||
|
|
||||||
return rootCmd
|
return rootCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// addSubCmds registers all the sub commands used by kava.
|
// addSubCmds registers all the sub commands used by 0g-chain.
|
||||||
func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, defaultNodeHome string) {
|
func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, defaultNodeHome string) {
|
||||||
|
gentxModule, ok := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
|
||||||
|
if !ok {
|
||||||
|
panic(fmt.Errorf("expected %s module to be an instance of type %T", genutiltypes.ModuleName, genutil.AppModuleBasic{}))
|
||||||
|
}
|
||||||
|
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
StatusCommand(),
|
StatusCommand(),
|
||||||
ethermintclient.ValidateChainID(
|
ethermintclient.ValidateChainID(
|
||||||
genutilcli.InitCmd(app.ModuleBasics, defaultNodeHome),
|
genutilcli.InitCmd(app.ModuleBasics, defaultNodeHome),
|
||||||
),
|
),
|
||||||
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome),
|
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, defaultNodeHome, gentxModule.GenTxValidator),
|
||||||
AssertInvariantsCmd(encodingConfig),
|
AssertInvariantsCmd(encodingConfig),
|
||||||
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome),
|
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, defaultNodeHome),
|
||||||
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
|
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
|
||||||
@ -108,7 +119,7 @@ func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, de
|
|||||||
|
|
||||||
opts := ethermintserver.StartOptions{
|
opts := ethermintserver.StartOptions{
|
||||||
AppCreator: ac.newApp,
|
AppCreator: ac.newApp,
|
||||||
DefaultNodeHome: app.DefaultNodeHome,
|
DefaultNodeHome: chaincfg.DefaultNodeHome,
|
||||||
DBOpener: opendb.OpenDB,
|
DBOpener: opendb.OpenDB,
|
||||||
}
|
}
|
||||||
// ethermintserver adds additional flags to start the JSON-RPC server for evm support
|
// ethermintserver adds additional flags to start the JSON-RPC server for evm support
|
||||||
@ -123,6 +134,9 @@ func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, de
|
|||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
newQueryCmd(),
|
newQueryCmd(),
|
||||||
newTxCmd(),
|
newTxCmd(),
|
||||||
kavaclient.KeyCommands(app.DefaultNodeHome),
|
keyCommands(chaincfg.DefaultNodeHome),
|
||||||
|
rocksdb.RocksDBCmd,
|
||||||
|
newShardCmd(opts),
|
||||||
|
iavlviewer.NewCmd(opts),
|
||||||
)
|
)
|
||||||
}
|
}
|
319
cmd/0gchaind/shard.go
Normal file
319
cmd/0gchaind/shard.go
Normal file
@ -0,0 +1,319 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
dbm "github.com/cometbft/cometbft-db"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
|
pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/store/rootmulti"
|
||||||
|
|
||||||
|
tmconfig "github.com/cometbft/cometbft/config"
|
||||||
|
"github.com/cometbft/cometbft/node"
|
||||||
|
tmstate "github.com/cometbft/cometbft/state"
|
||||||
|
"github.com/cometbft/cometbft/store"
|
||||||
|
|
||||||
|
ethermintserver "github.com/evmos/ethermint/server"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
flagShardStartBlock = "start"
|
||||||
|
flagShardEndBlock = "end"
|
||||||
|
flagShardOnlyAppState = "only-app-state"
|
||||||
|
flagShardForceAppVersion = "force-app-version"
|
||||||
|
flagShardOnlyCometbftState = "only-cometbft-state"
|
||||||
|
// TODO: --preserve flag for creating & operating on a copy?
|
||||||
|
|
||||||
|
// allow using -1 to mean "latest" (perform no rollbacks)
|
||||||
|
shardEndBlockLatest = -1
|
||||||
|
)
|
||||||
|
|
||||||
|
func newShardCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "shard --home <path-to-home-dir> --start <start-block> --end <end-block> [--only-app-state] [--only-cometbft-state] [--force-app-version <app-version>]",
|
||||||
|
Short: "Strip all blocks from the database outside of a given range",
|
||||||
|
Long: `shard opens a local kava home directory's databases and removes all blocks outside a range defined by --start and --end. The range is inclusive of the end block.
|
||||||
|
|
||||||
|
It works by first rolling back the latest state to the block before the end block, and then by pruning all state before the start block.
|
||||||
|
|
||||||
|
Setting the end block to -1 signals to keep the latest block (no rollbacks).
|
||||||
|
|
||||||
|
The application.db can be loaded at a particular height via the --force-app-version option. This is useful if the sharding process is prematurely terminated while the application.db is being sharded.
|
||||||
|
|
||||||
|
The --only-app-state flag can be used to skip the pruning of the blockstore and cometbft state. This matches the functionality of the cosmos-sdk's "prune" command. Note that rolled back blocks will still affect all stores.
|
||||||
|
|
||||||
|
Similarly, the --only-cometbft-state flag skips pruning app state. This can be useful if the shard command is prematurely terminated during the shard process.
|
||||||
|
|
||||||
|
The shard command only flags the iavl tree nodes for deletion. Actual removal from the databases will be performed when each database is compacted.
|
||||||
|
|
||||||
|
WARNING: this is a destructive action.`,
|
||||||
|
Example: `Create a 1M block data shard (keeps blocks kava 1,000,000 to 2,000,000)
|
||||||
|
$ kava shard --home path/to/.kava --start 1000000 --end 2000000
|
||||||
|
|
||||||
|
Prune all blocks up to 5,000,000:
|
||||||
|
$ kava shard --home path/to/.kava --start 5000000 --end -1
|
||||||
|
|
||||||
|
Prune first 1M blocks _without_ affecting blockstore or cometBFT state:
|
||||||
|
$ kava shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
//////////////////////////
|
||||||
|
// parse & validate flags
|
||||||
|
//////////////////////////
|
||||||
|
startBlock, err := cmd.Flags().GetInt64(flagShardStartBlock)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
endBlock, err := cmd.Flags().GetInt64(flagShardEndBlock)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if (endBlock == 0 || endBlock < startBlock) && endBlock != shardEndBlockLatest {
|
||||||
|
return fmt.Errorf("end block (%d) must be greater than start block (%d)", endBlock, startBlock)
|
||||||
|
}
|
||||||
|
onlyAppState, err := cmd.Flags().GetBool(flagShardOnlyAppState)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
forceAppVersion, err := cmd.Flags().GetInt64(flagShardForceAppVersion)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
onlyCometbftState, err := cmd.Flags().GetBool(flagShardOnlyCometbftState)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||||
|
|
||||||
|
ctx := server.GetServerContextFromCmd(cmd)
|
||||||
|
ctx.Config.SetRoot(clientCtx.HomeDir)
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
// manage db connection
|
||||||
|
////////////////////////
|
||||||
|
// connect to database
|
||||||
|
db, err := opts.DBOpener(ctx.Viper, clientCtx.HomeDir, server.GetAppDBBackend(ctx.Viper))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// close db connection when done
|
||||||
|
defer func() {
|
||||||
|
if err := db.Close(); err != nil {
|
||||||
|
ctx.Logger.Error("error closing db", "error", err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
// load multistore
|
||||||
|
///////////////////
|
||||||
|
// create app in order to load the multistore
|
||||||
|
// skip loading the latest version so the desired height can be manually loaded
|
||||||
|
ctx.Viper.Set("skip-load-latest", true)
|
||||||
|
|
||||||
|
app := opts.AppCreator(ctx.Logger, db, nil, ctx.Viper).(*app.App)
|
||||||
|
if forceAppVersion == shardEndBlockLatest {
|
||||||
|
if err := app.LoadLatestVersion(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := app.LoadVersion(forceAppVersion); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// get the multistore
|
||||||
|
cms := app.CommitMultiStore()
|
||||||
|
multistore, ok := cms.(*rootmulti.Store)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("only sharding of rootmulti.Store type is supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
// shard application.db
|
||||||
|
////////////////////////
|
||||||
|
if !onlyCometbftState {
|
||||||
|
if err := shardApplicationDb(multistore, startBlock, endBlock); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("[%s] skipping sharding of application.db\n", flagShardOnlyCometbftState)
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////
|
||||||
|
// shard blockstore.db & state.db
|
||||||
|
//////////////////////////////////
|
||||||
|
// open block store & cometbft state
|
||||||
|
blockStore, stateStore, err := openCometBftDbs(ctx.Config)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to open cometbft dbs: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !onlyAppState {
|
||||||
|
if err := shardCometBftDbs(blockStore, stateStore, startBlock, endBlock); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("[%s] skipping sharding of blockstore.db and state.db\n", flagShardOnlyAppState)
|
||||||
|
fmt.Printf("blockstore contains blocks %d - %d\n", blockStore.Base(), blockStore.Height())
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Flags().String(flags.FlagHome, opts.DefaultNodeHome, "The application home directory")
|
||||||
|
cmd.Flags().Int64(flagShardStartBlock, 1, "Start block of data shard (inclusive)")
|
||||||
|
cmd.Flags().Int64(flagShardEndBlock, 0, "End block of data shard (inclusive)")
|
||||||
|
cmd.Flags().Bool(flagShardOnlyAppState, false, "Skip pruning of blockstore & cometbft state")
|
||||||
|
cmd.Flags().Bool(flagShardOnlyCometbftState, false, "Skip pruning of application state")
|
||||||
|
cmd.Flags().Int64(flagShardForceAppVersion, shardEndBlockLatest, "Instead of loading latest, force set the version of the multistore that is loaded")
|
||||||
|
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// shardApplicationDb prunes the multistore up to startBlock and rolls it back to endBlock
|
||||||
|
func shardApplicationDb(multistore *rootmulti.Store, startBlock, endBlock int64) error {
|
||||||
|
//////////////////////////////
|
||||||
|
// Rollback state to endBlock
|
||||||
|
//////////////////////////////
|
||||||
|
// handle desired endblock being latest
|
||||||
|
latest := multistore.LastCommitID().Version
|
||||||
|
if latest == 0 {
|
||||||
|
return fmt.Errorf("failed to find latest height >0")
|
||||||
|
}
|
||||||
|
fmt.Printf("latest height: %d\n", latest)
|
||||||
|
if endBlock == shardEndBlockLatest {
|
||||||
|
endBlock = latest
|
||||||
|
}
|
||||||
|
shardSize := endBlock - startBlock + 1
|
||||||
|
|
||||||
|
// error if requesting block range the database does not have
|
||||||
|
if endBlock > latest {
|
||||||
|
return fmt.Errorf("data does not contain end block (%d): latest version is %d", endBlock, latest)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("pruning data down to heights %d - %d (%d blocks)\n", startBlock, endBlock, shardSize)
|
||||||
|
|
||||||
|
// set pruning options to prevent no-ops from `PruneStores`
|
||||||
|
multistore.SetPruning(pruningtypes.PruningOptions{KeepRecent: uint64(shardSize), Interval: 0})
|
||||||
|
|
||||||
|
// rollback application state
|
||||||
|
if err := multistore.RollbackToVersion(endBlock); err != nil {
|
||||||
|
return fmt.Errorf("failed to rollback application state: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
// Prune blocks to startBlock
|
||||||
|
//////////////////////////////
|
||||||
|
// enumerate all heights to prune
|
||||||
|
pruneHeights := make([]int64, 0, latest-shardSize)
|
||||||
|
for i := int64(1); i < startBlock; i++ {
|
||||||
|
pruneHeights = append(pruneHeights, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(pruneHeights) > 0 {
|
||||||
|
fmt.Printf("pruning application state to height %d\n", startBlock)
|
||||||
|
if err := multistore.PruneStores(true, pruneHeights); err != nil {
|
||||||
|
return fmt.Errorf("failed to prune application state: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// shardCometBftDbs shrinks blockstore.db & state.db down to the desired block range
|
||||||
|
func shardCometBftDbs(blockStore *store.BlockStore, stateStore tmstate.Store, startBlock, endBlock int64) error {
|
||||||
|
var err error
|
||||||
|
latest := blockStore.Height()
|
||||||
|
if endBlock == shardEndBlockLatest {
|
||||||
|
endBlock = latest
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
// Rollback state to endBlock
|
||||||
|
//////////////////////////////
|
||||||
|
// prep for outputting progress repeatedly to same line
|
||||||
|
needsRollback := endBlock < latest
|
||||||
|
progress := "rolling back blockstore & cometbft state to height %d"
|
||||||
|
numChars := len(fmt.Sprintf(progress, latest))
|
||||||
|
clearLine := fmt.Sprintf("\r%s\r", strings.Repeat(" ", numChars))
|
||||||
|
printRollbackProgress := func(h int64) {
|
||||||
|
fmt.Print(clearLine)
|
||||||
|
fmt.Printf(progress, h)
|
||||||
|
}
|
||||||
|
|
||||||
|
// rollback tendermint db
|
||||||
|
height := latest
|
||||||
|
for height > endBlock {
|
||||||
|
beforeRollbackHeight := height
|
||||||
|
printRollbackProgress(height - 1)
|
||||||
|
height, _, err = tmstate.Rollback(blockStore, stateStore, true)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to rollback cometbft state: %w", err)
|
||||||
|
}
|
||||||
|
if beforeRollbackHeight == height {
|
||||||
|
return fmt.Errorf("attempting to rollback cometbft state height %d failed (no rollback performed)", height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if needsRollback {
|
||||||
|
fmt.Println()
|
||||||
|
} else {
|
||||||
|
fmt.Printf("latest store height is already %d\n", latest)
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
// Prune blocks to startBlock
|
||||||
|
//////////////////////////////
|
||||||
|
// get starting block of block store
|
||||||
|
baseBlock := blockStore.Base()
|
||||||
|
|
||||||
|
// only prune if data exists, otherwise blockStore.PruneBlocks will panic
|
||||||
|
if baseBlock < startBlock {
|
||||||
|
// prune block store
|
||||||
|
fmt.Printf("pruning block store from %d - %d\n", baseBlock, startBlock)
|
||||||
|
if _, err := blockStore.PruneBlocks(startBlock); err != nil {
|
||||||
|
return fmt.Errorf("failed to prune block store (retainHeight=%d): %s", startBlock, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// prune cometbft state
|
||||||
|
fmt.Printf("pruning cometbft state from %d - %d\n", baseBlock, startBlock)
|
||||||
|
if err := stateStore.PruneStates(baseBlock, startBlock); err != nil {
|
||||||
|
return fmt.Errorf("failed to prune cometbft state store (%d - %d): %s", baseBlock, startBlock, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("blockstore and cometbft state begins at block %d\n", baseBlock)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// inspired by https://github.com/Kava-Labs/cometbft/blob/277b0853db3f67865a55aa1c54f59790b5f591be/node/node.go#L234
|
||||||
|
func openCometBftDbs(config *tmconfig.Config) (blockStore *store.BlockStore, stateStore tmstate.Store, err error) {
|
||||||
|
dbProvider := node.DefaultDBProvider
|
||||||
|
|
||||||
|
var blockStoreDB dbm.DB
|
||||||
|
blockStoreDB, err = dbProvider(&node.DBContext{ID: "blockstore", Config: config})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
blockStore = store.NewBlockStore(blockStoreDB)
|
||||||
|
|
||||||
|
stateDB, err := dbProvider(&node.DBContext{ID: "state", Config: config})
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stateStore = tmstate.NewStore(stateDB, tmstate.StoreOptions{
|
||||||
|
DiscardABCIResponses: config.Storage.DiscardABCIResponses,
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/libs/bytes"
|
"github.com/cometbft/cometbft/libs/bytes"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/cometbft/cometbft/p2p"
|
||||||
coretypes "github.com/tendermint/tendermint/rpc/core/types"
|
coretypes "github.com/cometbft/cometbft/rpc/core/types"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
@ -1,4 +1,4 @@
|
|||||||
package cmd
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
@ -6,7 +6,7 @@ import (
|
|||||||
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newTxCmd creates all commands for submitting blockchain transactions.
|
// newTxCmd creates all commands for submitting blockchain transactions.
|
@ -6,8 +6,8 @@ package opendb
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
dbm "github.com/cometbft/cometbft-db"
|
||||||
"github.com/cosmos/cosmos-sdk/server/types"
|
"github.com/cosmos/cosmos-sdk/server/types"
|
||||||
dbm "github.com/tendermint/tm-db"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// OpenDB is a copy of default DBOpener function used by ethermint, see for details:
|
// OpenDB is a copy of default DBOpener function used by ethermint, see for details:
|
@ -29,10 +29,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
dbm "github.com/cometbft/cometbft-db"
|
||||||
"github.com/cosmos/cosmos-sdk/server/types"
|
"github.com/cosmos/cosmos-sdk/server/types"
|
||||||
"github.com/linxGnu/grocksdb"
|
"github.com/linxGnu/grocksdb"
|
||||||
"github.com/spf13/cast"
|
"github.com/spf13/cast"
|
||||||
dbm "github.com/tendermint/tm-db"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrUnexpectedConfiguration = errors.New("unexpected rocksdb configuration, rocksdb should have only one column family named default")
|
var ErrUnexpectedConfiguration = errors.New("unexpected rocksdb configuration, rocksdb should have only one column family named default")
|
||||||
@ -41,7 +41,7 @@ const (
|
|||||||
// default tm-db block cache size for RocksDB
|
// default tm-db block cache size for RocksDB
|
||||||
defaultBlockCacheSize = 1 << 30
|
defaultBlockCacheSize = 1 << 30
|
||||||
|
|
||||||
defaultColumnFamilyName = "default"
|
DefaultColumnFamilyName = "default"
|
||||||
|
|
||||||
enableMetricsOptName = "rocksdb.enable-metrics"
|
enableMetricsOptName = "rocksdb.enable-metrics"
|
||||||
reportMetricsIntervalSecsOptName = "rocksdb.report-metrics-interval-secs"
|
reportMetricsIntervalSecsOptName = "rocksdb.report-metrics-interval-secs"
|
||||||
@ -81,7 +81,7 @@ const (
|
|||||||
func OpenDB(appOpts types.AppOptions, home string, backendType dbm.BackendType) (dbm.DB, error) {
|
func OpenDB(appOpts types.AppOptions, home string, backendType dbm.BackendType) (dbm.DB, error) {
|
||||||
dataDir := filepath.Join(home, "data")
|
dataDir := filepath.Join(home, "data")
|
||||||
if backendType == dbm.RocksDBBackend {
|
if backendType == dbm.RocksDBBackend {
|
||||||
return openRocksdb(filepath.Join(dataDir, "application.db"), appOpts)
|
return openRocksdb(dataDir, appOpts)
|
||||||
}
|
}
|
||||||
|
|
||||||
return dbm.NewDB("application", backendType, dataDir)
|
return dbm.NewDB("application", backendType, dataDir)
|
||||||
@ -90,7 +90,8 @@ func OpenDB(appOpts types.AppOptions, home string, backendType dbm.BackendType)
|
|||||||
// openRocksdb loads existing options, overrides some of them with appOpts and opens database
|
// openRocksdb loads existing options, overrides some of them with appOpts and opens database
|
||||||
// option will be overridden only in case if it explicitly specified in appOpts
|
// option will be overridden only in case if it explicitly specified in appOpts
|
||||||
func openRocksdb(dir string, appOpts types.AppOptions) (dbm.DB, error) {
|
func openRocksdb(dir string, appOpts types.AppOptions) (dbm.DB, error) {
|
||||||
dbOpts, cfOpts, err := loadLatestOptions(dir)
|
optionsPath := filepath.Join(dir, "application.db")
|
||||||
|
dbOpts, cfOpts, err := LoadLatestOptions(optionsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -111,10 +112,10 @@ func openRocksdb(dir string, appOpts types.AppOptions) (dbm.DB, error) {
|
|||||||
return newRocksDBWithOptions("application", dir, dbOpts, cfOpts, readOpts, enableMetrics, reportMetricsIntervalSecs)
|
return newRocksDBWithOptions("application", dir, dbOpts, cfOpts, readOpts, enableMetrics, reportMetricsIntervalSecs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loadLatestOptions loads and returns database and column family options
|
// LoadLatestOptions loads and returns database and column family options
|
||||||
// if options file not found, it means database isn't created yet, in such case default tm-db options will be returned
|
// if options file not found, it means database isn't created yet, in such case default tm-db options will be returned
|
||||||
// if database exists it should have only one column family named default
|
// if database exists it should have only one column family named default
|
||||||
func loadLatestOptions(dir string) (*grocksdb.Options, *grocksdb.Options, error) {
|
func LoadLatestOptions(dir string) (*grocksdb.Options, *grocksdb.Options, error) {
|
||||||
latestOpts, err := grocksdb.LoadLatestOptions(dir, grocksdb.NewDefaultEnv(), true, grocksdb.NewLRUCache(defaultBlockCacheSize))
|
latestOpts, err := grocksdb.LoadLatestOptions(dir, grocksdb.NewDefaultEnv(), true, grocksdb.NewLRUCache(defaultBlockCacheSize))
|
||||||
if err != nil && strings.HasPrefix(err.Error(), "NotFound: ") {
|
if err != nil && strings.HasPrefix(err.Error(), "NotFound: ") {
|
||||||
return newDefaultOptions(), newDefaultOptions(), nil
|
return newDefaultOptions(), newDefaultOptions(), nil
|
||||||
@ -126,7 +127,7 @@ func loadLatestOptions(dir string) (*grocksdb.Options, *grocksdb.Options, error)
|
|||||||
cfNames := latestOpts.ColumnFamilyNames()
|
cfNames := latestOpts.ColumnFamilyNames()
|
||||||
cfOpts := latestOpts.ColumnFamilyOpts()
|
cfOpts := latestOpts.ColumnFamilyOpts()
|
||||||
// db should have only one column family named default
|
// db should have only one column family named default
|
||||||
ok := len(cfNames) == 1 && cfNames[0] == defaultColumnFamilyName
|
ok := len(cfNames) == 1 && cfNames[0] == DefaultColumnFamilyName
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil, ErrUnexpectedConfiguration
|
return nil, nil, ErrUnexpectedConfiguration
|
||||||
}
|
}
|
||||||
@ -311,7 +312,7 @@ func newRocksDBWithOptions(
|
|||||||
dbOpts.EnableStatistics()
|
dbOpts.EnableStatistics()
|
||||||
}
|
}
|
||||||
|
|
||||||
db, _, err := grocksdb.OpenDbColumnFamilies(dbOpts, dbPath, []string{defaultColumnFamilyName}, []*grocksdb.Options{cfOpts})
|
db, _, err := grocksdb.OpenDbColumnFamilies(dbOpts, dbPath, []string{DefaultColumnFamilyName}, []*grocksdb.Options{cfOpts})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
@ -83,7 +83,7 @@ func TestOpenRocksdb(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
dbOpts, cfOpts, err := loadLatestOptions(filepath.Join(dir, "application.db"))
|
dbOpts, cfOpts, err := LoadLatestOptions(filepath.Join(dir, "application.db"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, tc.maxOpenFiles, dbOpts.GetMaxOpenFiles())
|
require.Equal(t, tc.maxOpenFiles, dbOpts.GetMaxOpenFiles())
|
||||||
require.Equal(t, tc.maxFileOpeningThreads, dbOpts.GetMaxFileOpeningThreads())
|
require.Equal(t, tc.maxFileOpeningThreads, dbOpts.GetMaxFileOpeningThreads())
|
||||||
@ -108,7 +108,7 @@ func TestOpenRocksdb(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
dbOpts, cfOpts, err := loadLatestOptions(filepath.Join(dir, "application.db"))
|
dbOpts, cfOpts, err := LoadLatestOptions(filepath.Join(dir, "application.db"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, defaultOpts.GetMaxOpenFiles(), dbOpts.GetMaxOpenFiles())
|
require.Equal(t, defaultOpts.GetMaxOpenFiles(), dbOpts.GetMaxOpenFiles())
|
||||||
require.Equal(t, defaultOpts.GetMaxFileOpeningThreads(), dbOpts.GetMaxFileOpeningThreads())
|
require.Equal(t, defaultOpts.GetMaxFileOpeningThreads(), dbOpts.GetMaxFileOpeningThreads())
|
||||||
@ -190,7 +190,7 @@ func TestLoadLatestOptions(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
dbOpts, cfOpts, err := loadLatestOptions(filepath.Join(dir, "application.db"))
|
dbOpts, cfOpts, err := LoadLatestOptions(filepath.Join(dir, "application.db"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, tc.maxOpenFiles, dbOpts.GetMaxOpenFiles())
|
require.Equal(t, tc.maxOpenFiles, dbOpts.GetMaxOpenFiles())
|
||||||
require.Equal(t, tc.maxFileOpeningThreads, dbOpts.GetMaxFileOpeningThreads())
|
require.Equal(t, tc.maxFileOpeningThreads, dbOpts.GetMaxFileOpeningThreads())
|
||||||
@ -210,7 +210,7 @@ func TestLoadLatestOptions(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
dbOpts, cfOpts, err := loadLatestOptions(filepath.Join(dir, "application.db"))
|
dbOpts, cfOpts, err := LoadLatestOptions(filepath.Join(dir, "application.db"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, defaultOpts.GetMaxOpenFiles(), dbOpts.GetMaxOpenFiles())
|
require.Equal(t, defaultOpts.GetMaxOpenFiles(), dbOpts.GetMaxOpenFiles())
|
||||||
require.Equal(t, defaultOpts.GetMaxFileOpeningThreads(), dbOpts.GetMaxFileOpeningThreads())
|
require.Equal(t, defaultOpts.GetMaxFileOpeningThreads(), dbOpts.GetMaxFileOpeningThreads())
|
||||||
@ -368,7 +368,7 @@ func TestNewRocksDBWithOptions(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, db.Close())
|
require.NoError(t, db.Close())
|
||||||
|
|
||||||
dbOpts, cfOpts, err = loadLatestOptions(filepath.Join(dir, "application.db"))
|
dbOpts, cfOpts, err = LoadLatestOptions(filepath.Join(dir, "application.db"))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 999, dbOpts.GetMaxOpenFiles())
|
require.Equal(t, 999, dbOpts.GetMaxOpenFiles())
|
||||||
require.Equal(t, defaultOpts.GetMaxFileOpeningThreads(), dbOpts.GetMaxFileOpeningThreads())
|
require.Equal(t, defaultOpts.GetMaxFileOpeningThreads(), dbOpts.GetMaxFileOpeningThreads())
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user