Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/app_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
47 changes: 47 additions & 0 deletions app/upgrades/052/precision_test.go
Original file line number Diff line number Diff line change
@@ -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, "")
}
22 changes: 22 additions & 0 deletions app/upgrades/052/upgrades.go
Original file line number Diff line number Diff line change
@@ -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{},
}
8 changes: 5 additions & 3 deletions e2e/gastracking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand All @@ -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],
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 0 additions & 4 deletions e2e/rewards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 11 additions & 3 deletions e2e/testing/chain_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
}

Expand Down
13 changes: 13 additions & 0 deletions types/precision.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion x/rewards/keeper/min_cons_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down