diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c77d87f..2e88ce32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ Contains all the PRs that improved the code without changing the behaviours. - [#368](https://github.com/archway-network/archway/pull/368) - github actions should fetch tags as well for deploy workflow - [#369](https://github.com/archway-network/archway/pull/369) - CODEOWNERS: small set to expand, not large set that filters - [#370](https://github.com/archway-network/archway/pull/370) - login to ghcr +- [#382](https://github.com/archway-network/archway/pull/382) - adjust default power reduction ### Changed diff --git a/app/app.go b/app/app.go index 3a7781e6..2080f905 100644 --- a/app/app.go +++ b/app/app.go @@ -111,6 +111,7 @@ import ( wasmclient "github.com/CosmWasm/wasmd/x/wasm/client" archwayappparams "github.com/archway-network/archway/app/params" + archway "github.com/archway-network/archway/types" // unnamed import of statik for swagger UI support _ "github.com/cosmos/cosmos-sdk/client/docs/statik" @@ -228,6 +229,12 @@ var ( _ servertypes.Application = (*ArchwayApp)(nil) ) +func init() { + // sets the default power reduction in order to ensure that on high precision numbers, which is a default for archway + // the network does not get stalled due to an integer overflow in some edge cases. + sdk.DefaultPowerReduction = archway.DefaultPowerReduction +} + // ArchwayApp extended ABCI application type ArchwayApp struct { *baseapp.BaseApp diff --git a/app/app_upgrades.go b/app/app_upgrades.go index 46236384..7f9a4fd2 100644 --- a/app/app_upgrades.go +++ b/app/app_upgrades.go @@ -8,13 +8,15 @@ import ( "github.com/archway-network/archway/app/upgrades" upgrade_0_3 "github.com/archway-network/archway/app/upgrades/03" upgrade_0_4 "github.com/archway-network/archway/app/upgrades/04" + upgrade_0_5_2 "github.com/archway-network/archway/app/upgrades/052" ) // UPGRADES var Upgrades = []upgrades.Upgrade{ - upgrade_0_3.Upgrade, // v0.3.0 - upgrade_0_4.Upgrade, // v0.4.0 + upgrade_0_3.Upgrade, // v0.3.0 + upgrade_0_4.Upgrade, // v0.4.0 + upgrade_0_5_2.Upgrade, // v0.5.2 } func (app *ArchwayApp) setupUpgrades() { diff --git a/app/upgrades/052/precision_test.go b/app/upgrades/052/precision_test.go new file mode 100644 index 00000000..b85e9a80 --- /dev/null +++ b/app/upgrades/052/precision_test.go @@ -0,0 +1,47 @@ +//go:build precision_test + +// NOTE: this test is run as a separate build tag as it modifies a global +// variable that is used in other tests. In a concurrent environment this +// might cause unforeseen issues, so we isolate it. +package upgrade052_test + +import ( + "testing" + + e2eTesting "github.com/archway-network/archway/e2e/testing" + archway "github.com/archway-network/archway/types" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" +) + +func TestPrecisionBreakages(t *testing.T) { + attoPrec := archway.DefaultPowerReduction + microPrecision := sdk.NewInt(1_000_000) + stake := func(shouldPass bool, errContains string) { + chainBad := e2eTesting.NewTestChain(t, 1, + e2eTesting.WithGenDefaultCoinBalance(attoPrec.MulRaw(1_000_000_000).String()), + e2eTesting.WithBondAmount(attoPrec.MulRaw(1).String()), + e2eTesting.WithDefaultFeeAmount(attoPrec.MulRaw(1).String()), + e2eTesting.WithValidatorsNum(2), + ) + acc := chainBad.GetAccount(1) + + _, _, _, err := chainBad.SendMsgs(acc, shouldPass, []sdk.Msg{ + &stakingtypes.MsgDelegate{ + DelegatorAddress: acc.Address.String(), + ValidatorAddress: sdk.ValAddress(chainBad.GetCurrentValSet().Validators[0].Address).String(), + Amount: sdk.NewCoin("stake", attoPrec.MulRaw(100_000_000)), + }, + }) + if !shouldPass { + require.ErrorContains(t, err, errContains) + } + } + // setup bad power reduction + sdk.DefaultPowerReduction = microPrecision + stake(false, "Int64() out of bound") + // fix power reduction + sdk.DefaultPowerReduction = attoPrec + stake(true, "") +} diff --git a/app/upgrades/052/upgrades.go b/app/upgrades/052/upgrades.go new file mode 100644 index 00000000..699bbca8 --- /dev/null +++ b/app/upgrades/052/upgrades.go @@ -0,0 +1,22 @@ +package upgrade052 + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + + "github.com/archway-network/archway/app/upgrades" +) + +const Name = "v0.5.2" + +var Upgrade = upgrades.Upgrade{ + UpgradeName: Name, + CreateUpgradeHandler: func(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + return mm.RunMigrations(ctx, cfg, fromVM) + } + }, + StoreUpgrades: storetypes.StoreUpgrades{}, +} diff --git a/e2e/gastracking_test.go b/e2e/gastracking_test.go index ca1fb5b5..0029cfd7 100644 --- a/e2e/gastracking_test.go +++ b/e2e/gastracking_test.go @@ -5,6 +5,8 @@ import ( "strconv" "time" + archway "github.com/archway-network/archway/types" + wasmdTypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" abci "github.com/tendermint/tendermint/abci/types" @@ -41,7 +43,7 @@ func (s *E2ETestSuite) TestGasTrackingAndRewardsDistribution() { 1000000, ), // Set default Tx fee for non-manual transaction like Upload / Instantiate - e2eTesting.WithDefaultFeeAmount("10000"), + e2eTesting.WithDefaultFeeAmount("500000000000000"), ) trackingKeeper, rewardsKeeper := chain.GetApp().TrackingKeeper, chain.GetApp().RewardsKeeper @@ -50,7 +52,7 @@ func (s *E2ETestSuite) TestGasTrackingAndRewardsDistribution() { accAddrs, accPrivKeys := e2eTesting.GenAccounts(1) // an empty account // Inputs - txFees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000))) + txFees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(500_000_000_000_000))) rewardsAcc := e2eTesting.Account{ Address: accAddrs[0], PrivKey: accPrivKeys[0], @@ -81,7 +83,7 @@ func (s *E2ETestSuite) TestGasTrackingAndRewardsDistribution() { } // Send some coins to the rewardsAcc to pay withdraw Tx fees - rewardsAccInitialBalance := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1000000))) + rewardsAccInitialBalance := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(1).Mul(archway.DefaultPowerReduction))) { s.Require().NoError( chain.GetApp().BankKeeper.SendCoins( diff --git a/e2e/rewards_test.go b/e2e/rewards_test.go index 231d4e0e..ac6dc925 100644 --- a/e2e/rewards_test.go +++ b/e2e/rewards_test.go @@ -236,8 +236,6 @@ func (s *E2ETestSuite) TestRewardsWithdrawProfitAndFees() { // TestRewardsParamMaxWithdrawRecordsLimit check the x/rewards's MaxWithdrawRecords param limit (rough estimation). // Limit is defined by the block gas limit (100M). func (s *E2ETestSuite) TestRewardsParamMaxWithdrawRecordsLimit() { - s.T().Skip("Skipped to save CI time, should be used manually to estimate a new limit") - rewardsTypes.MaxWithdrawRecordsParamLimit = uint64(29500) // an actual value is (thisValue - 1), refer to the query below chain := e2eTesting.NewTestChain(s.T(), 1, @@ -312,8 +310,6 @@ func (s *E2ETestSuite) TestRewardsParamMaxWithdrawRecordsLimit() { // TestRewardsRecordsQueryLimit defines the x/rewards's RewardsRecords query limit (rough estimation). // Limit is defined by the max CosmWasm VM. func (s *E2ETestSuite) TestRewardsRecordsQueryLimit() { - s.T().Skip("Skipped to save CI time, should be used manually to estimate a new limit") - rewardsTypes.MaxRecordsQueryLimit = uint64(7716) // an actual value is (thisValue - 1), refer to the query below chain := e2eTesting.NewTestChain(s.T(), 1) diff --git a/e2e/testing/chain_options.go b/e2e/testing/chain_options.go index 25021772..4947656c 100644 --- a/e2e/testing/chain_options.go +++ b/e2e/testing/chain_options.go @@ -6,6 +6,8 @@ import ( mintTypes "github.com/cosmos/cosmos-sdk/x/mint/types" abci "github.com/tendermint/tendermint/abci/types" + archway "github.com/archway-network/archway/types" + "github.com/archway-network/archway/app" rewardsTypes "github.com/archway-network/archway/x/rewards/types" ) @@ -33,9 +35,15 @@ func defaultChainConfig() chainConfig { return chainConfig{ ValidatorsNum: 1, GenAccountsNum: 5, - GenBalanceAmount: "1000000000", - BondAmount: "1000000", - DefaultFeeAmt: "100", + GenBalanceAmount: archway.DefaultPowerReduction.MulRaw(100).String(), + BondAmount: archway.DefaultPowerReduction.MulRaw(1).String(), + DefaultFeeAmt: archway.DefaultPowerReduction.QuoRaw(10).String(), // 0.1 + } +} + +func WithValidatorsNum(num int) TestChainConfigOption { + return func(cfg *chainConfig) { + cfg.ValidatorsNum = num } } diff --git a/types/precision.go b/types/precision.go new file mode 100644 index 00000000..22d47fc6 --- /dev/null +++ b/types/precision.go @@ -0,0 +1,13 @@ +package types + +import ( + "math/big" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +const ( + BaseDenomUnit = 18 +) + +var DefaultPowerReduction = sdk.NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewInt(BaseDenomUnit), nil)) // 10^18 diff --git a/x/rewards/keeper/min_cons_fee.go b/x/rewards/keeper/min_cons_fee.go index 7ebd707a..de62d6e6 100644 --- a/x/rewards/keeper/min_cons_fee.go +++ b/x/rewards/keeper/min_cons_fee.go @@ -61,7 +61,7 @@ func (k Keeper) ComputationalPriceOfGas(ctx sdk.Context) sdk.DecCoin { return minPoG } if minPoG.Denom != antiDoSPoG.Denom { - panic("conflict between anti dos denom and min price of gas denom") + panic("conflict between anti dos denom and min price of gas denom: %s != %s" + minPoG.Denom + antiDoSPoG.Denom) } return sdk.NewDecCoinFromDec(minPoG.Denom, sdk.MaxDec(minPoG.Amount, antiDoSPoG.Amount)) }