Skip to content

Commit

Permalink
Release/v1.4.x (#289)
Browse files Browse the repository at this point in the history
* x/interchainstaking/keeper: preallocate slice capacity in CalculateDeltas

Given that types.ValidatorIntents is already a slice, this change
just extracts its length and uses that as a slice capacity hint
to improve performance.

Fixes #97

* x/interchainstaking/keeper: use .IncrementBalanceWaitgroup() instead of naked ++

Instead of using a naked increment for an exported struct, this change
uses its .IncrementBalanceWaitgroup() which helps in logical checks.

Fixes #98

* x/interchainstaking/keeper: add fuzzers

Adds fuzzers that we've written to help find vulnerabilities.
While here, using go test -short to skip fuzzing being run in regular
tests per `make test`.

Updates #90

* bump proto-gen container to v0.9.0, to support go 1.19

* add channel close/reopen proposals

* lint/gofumpt

* regen proto files with additional comments

* error catching epochs added

* fixed test cases

* lint fix

* codecov secrets

* add no-op upgrade handler for v1.3.0

* added check for deposit addr (#281)

* Release/v1.3.2 (#285)

* UpdateWithdrawAddress callback patched

* added pagination fix

* keeper-tests added

* add deposit interval test

* add adjacent verification; add deposit callback tests;

* remove ibc/ prefix check from validateBasic

* gofumpt

* add rts functionality; enable/disable unbonding and deposits per zone; store decimals in zone struct; store first_seen and complete timestamps against receipts; add upgrade handler to migrate zones

* rebase fixes

* store added for self-consensus-state

* handle submission of PR claims against Quicksilver

* [WIP] verifying self claims

* added delete method

* claim from local chain

* lint fix

* update epoch hooks in cm

* update zone struct in tests

* support v0.47.x balances returned by kvstore lookup

* lint fix

* fix: harcoded prefix

* feature: [TG-420] add stats to zone(s) endpoints

* lint fixes

* use correct token in error message; fixes i#118

* gofumpt

* remove pedantic error checking in allocateLockupRewards

* defensive check against negative validator vp

* check for nil value in sdkAmount

* make errors deterministic

* improve error handling by propogating error

* be super defensive and check for negative values, not just zero equality

* reject nil value coins

* set the quick prefix in the correct place

* revert backwards incompatible changes to zones and related props

* fix lint

* tests and fixes for TG-416 slash withdrawal fix

* bump tenermint version

* bump tendermint to v0.34.25

* allow port to be reopened via tx

* pr fixes

* verbose logging

* skip zone allocations for zones with no price information

* lint

* extended upgrade handler to clear uni-5 records

* more verbose logging on unbonding satisfaction

* added logic to burn uqjunox

* other records removed and test case added

* lint fix

* check for innuendo specific upgrade-handler

* Deprecation warning fix and testchain included for upgradehandler

* imports tidy

* errors.Register deprecation fix

* deprecation fixes

* lint fix

---------

Co-authored-by: Emmanuel T Odeke <[email protected]>
Co-authored-by: Joe Bowman <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2023
1 parent d4a45f7 commit 6b36873
Show file tree
Hide file tree
Showing 112 changed files with 6,094 additions and 1,398 deletions.
1 change: 1 addition & 0 deletions .github/workflows/buildtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ jobs:
- name: Upload coverage reports to Codecov with GitHub Action
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # needed for private repo
files: ./coverage_nogen.txt
flags: unittests
fail_ci_if_error: true
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ $(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

build-docker:
DOCKER_BUILDKIT=1 $(DOCKER) build . -f Dockerfile -t quicksilverzone/quicksilver:$(DOCKER_VERSION)
DOCKER_BUILDKIT=1 $(DOCKER) build . -f Dockerfile -t quicksilverzone/quicksilver:$(DOCKER_VERSION) -t quicksilverzone/quicksilver:latest

build-docker-local: build
DOCKER_BUILDKIT=1 $(DOCKER) build -f Dockerfile.local . -t quicksilverzone/quicksilver:$(DOCKER_VERSION)
Expand Down Expand Up @@ -316,13 +316,13 @@ test-unit-cover: TEST_PACKAGES=$(PACKAGES_UNIT)

run-tests:
ifneq (,$(shell which tparse 2>/dev/null))
go test -mod=readonly -json $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES) | tparse
go test -short -mod=readonly -json $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES) | tparse
else
go test -mod=readonly $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES)
go test -short -mod=readonly $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES)
endif

test-import:
@go test ./tests/importer -v --vet=off --run=TestImportBlocks --datadir tmp \
@go test -short ./tests/importer -v --vet=off --run=TestImportBlocks --datadir tmp \
--blockchain blockchain
rm -rf tests/importer/tmp

Expand All @@ -336,13 +336,13 @@ test-rpc-pending:

test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
@go test -short -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

test-sim-custom-genesis-fast:
@echo "Running custom genesis simulation..."
@echo "By default, ${HOME}/.$(QS_DIR)/config/genesis.json will be used."
@go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=${HOME}/.$(QS_DIR)/config/genesis.json \
@go test -short -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=${HOME}/.$(QS_DIR)/config/genesis.json \
-Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h

test-sim-import-export: runsim
Expand All @@ -368,7 +368,7 @@ test-sim-multi-seed-short: runsim

test-sim-benchmark-invariants:
@echo "Running simulation invariant benchmarks..."
@go test -mod=readonly $(SIMAPP) -benchmem -bench=BenchmarkInvariants -run=^$ \
@go test -short -mod=readonly $(SIMAPP) -benchmem -bench=BenchmarkInvariants -run=^$ \
-Enabled=true -NumBlocks=1000 -BlockSize=200 \
-Period=1 -Commit=true -Seed=57 -v -timeout 24h

Expand All @@ -383,7 +383,7 @@ test-sim-multi-seed-long \
test-sim-benchmark-invariants

benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION)
@go test -short -mod=readonly -bench=. $(PACKAGES_NOSIMULATION)
.PHONY: benchmark

###############################################################################
Expand All @@ -408,8 +408,8 @@ format:
### Protobuf ###
###############################################################################

containerProtoVer=v0.7
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
containerProtoVer=0.9.0
containerProtoImage=ghcr.io/cosmos/proto-builder:$(containerProtoVer)
containerProtoGen=cosmos-sdk-proto-gen-$(containerProtoVer)
containerProtoGenSwagger=cosmos-sdk-proto-gen-swagger-$(containerProtoVer)
containerProtoFmt=cosmos-sdk-proto-fmt-$(containerProtoVer)
Expand Down
7 changes: 4 additions & 3 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
sdkioerrors "cosmossdk.io/errors"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmTypes "github.com/CosmWasm/wasmd/x/wasm/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
Expand All @@ -24,13 +25,13 @@ type HandlerOptions struct {

func NewAnteHandler(options HandlerOptions) sdk.AnteHandler {
if options.AccountKeeper == nil {
panic(sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler"))
panic(sdkioerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler"))
}
if options.BankKeeper == nil {
panic(sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler"))
panic(sdkioerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler"))
}
if options.SignModeHandler == nil {
panic(sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder"))
panic(sdkioerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder"))
}

sigGasConsumer := options.SigGasConsumer
Expand Down
27 changes: 17 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import (
"strings"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/gorilla/mux"
"github.com/prometheus/client_golang/prometheus"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
Expand Down Expand Up @@ -52,8 +43,17 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/gorilla/mux"
appconfig "github.com/ingenuity-build/quicksilver/cmd/config"
"github.com/ingenuity-build/quicksilver/utils"
"github.com/ingenuity-build/quicksilver/wasmbinding"
"github.com/prometheus/client_golang/prometheus"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmos "github.com/tendermint/tendermint/libs/os"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/x/evidence"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"
Expand Down Expand Up @@ -396,9 +396,14 @@ func NewQuicksilver(
proofOpsFn = utils.MockProofOps
}

selfProofOpsFn := utils.ValidateSelfProofOps
if mock {
selfProofOpsFn = utils.MockSelfProofOps
}

// use custom account for contracts
app.AccountKeeper = authkeeper.NewAccountKeeper(
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, sdk.Bech32MainPrefix,
appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, appconfig.Bech32PrefixAccAddr,
)
app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedAddrs(),
Expand Down Expand Up @@ -465,6 +470,7 @@ func NewQuicksilver(
app.ClaimsManagerKeeper = claimsmanagerkeeper.NewKeeper(
appCodec,
keys[claimsmanagertypes.StoreKey],
*app.IBCKeeper,
)

claimsmanagerModule := claimsmanager.NewAppModule(appCodec, app.ClaimsManagerKeeper)
Expand Down Expand Up @@ -500,6 +506,7 @@ func NewQuicksilver(
app.InterchainstakingKeeper,
authtypes.FeeCollectorName,
proofOpsFn,
selfProofOpsFn,
)
if err := app.InterchainQueryKeeper.SetCallbackHandler(interchainstakingtypes.ModuleName, app.InterchainstakingKeeper.CallbackHandler()); err != nil {
panic(err)
Expand Down
158 changes: 154 additions & 4 deletions app/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
package app

import (
"errors"
"fmt"
"strings"

sdkmath "cosmossdk.io/math"
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"
icqtypes "github.com/ingenuity-build/quicksilver/x/interchainquery/types"
icskeeper "github.com/ingenuity-build/quicksilver/x/interchainstaking/keeper"
"github.com/ingenuity-build/quicksilver/x/interchainstaking/types"
tokenfactorytypes "github.com/ingenuity-build/quicksilver/x/tokenfactory/types"
)

// upgrade name consts: vMMmmppUpgradeName (M=Major, m=minor, p=patch)
const (
ProductionChainID = "quicksilver-1"
InnuendoChainID = "innuendo-3"
Innuendo2ChainID = "innuendo-4"
ProductionChainID = "quicksilver-2"
InnuendoChainID = "innuendo-4"
DevnetChainID = "quicktest-1"

v010300UpgradeName = "v1.3.0"
v010400UpgradeName = "v1.4.0"
)

func setUpgradeHandlers(app *Quicksilver) {
// app.UpgradeKeeper.SetUpgradeHandler(v001000UpgradeName, getv001000Upgrade(app))
app.UpgradeKeeper.SetUpgradeHandler(v010300UpgradeName, noOpHandler(app))
app.UpgradeKeeper.SetUpgradeHandler(v010400UpgradeName, v010400UpgradeHandler(app))

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
Expand Down Expand Up @@ -46,3 +58,141 @@ func setUpgradeHandlers(app *Quicksilver) {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
}
}

func noOpHandler(app *Quicksilver) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
}
}

func v010400UpgradeHandler(app *Quicksilver) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// upgrade zones
app.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone types.Zone) (stop bool) {
zone.DepositsEnabled = true
zone.ReturnToSender = false
zone.UnbondingEnabled = false
zone.Decimals = 6
app.InterchainstakingKeeper.SetZone(ctx, &zone)
return false
})

// upgrade receipts
time := ctx.BlockTime()
for _, r := range app.InterchainstakingKeeper.AllReceipts(ctx) {
r.FirstSeen = &time
r.Completed = &time
app.InterchainstakingKeeper.SetReceipt(ctx, r)
}
if ctx.ChainID() == "innuendo-5" || ctx.ChainID() == "testchain1" {

// clear uni-5 unbondings
app.InterchainstakingKeeper.IteratePrefixedUnbondingRecords(ctx, []byte("uni-5"), func(_ int64, record types.UnbondingRecord) (stop bool) {
app.InterchainstakingKeeper.DeleteUnbondingRecord(ctx, record.ChainId, record.Validator, record.EpochNumber)
return false
})

// clear uni-5 redelegations
app.InterchainstakingKeeper.IteratePrefixedRedelegationRecords(ctx, []byte("uni-5"), func(_ int64, _ []byte, record types.RedelegationRecord) (stop bool) {
app.InterchainstakingKeeper.DeleteRedelegationRecord(ctx, record.ChainId, record.Source, record.Destination, record.EpochNumber)
return false
})

// remove uni-5 zone and related records
app.InterchainstakingKeeper.IterateZones(ctx, func(index int64, zone types.Zone) (stop bool) {
if zone.ChainId == "uni-5" {
// remove uni-5 delegation records
app.InterchainstakingKeeper.IterateAllDelegations(ctx, &zone, func(delegation types.Delegation) (stop bool) {
err := app.InterchainstakingKeeper.RemoveDelegation(ctx, &zone, delegation)
if err != nil {
panic(err)
}
return false
})

// remove uni-5 performance delegation records
app.InterchainstakingKeeper.IterateAllPerformanceDelegations(ctx, &zone, func(delegation types.Delegation) (stop bool) {
err := app.InterchainstakingKeeper.RemoveDelegation(ctx, &zone, delegation)
if err != nil {
panic(err)
}
return false
})
// remove uni-5 receipts
app.InterchainstakingKeeper.IterateZoneReceipts(ctx, &zone, func(index int64, receiptInfo types.Receipt) (stop bool) {
app.InterchainstakingKeeper.DeleteReceipt(ctx, icskeeper.GetReceiptKey(receiptInfo.ChainId, receiptInfo.Txhash))
return false
})

// remove zone withdrawal records
app.InterchainstakingKeeper.IterateZoneWithdrawalRecords(ctx, zone.ChainId, func(index int64, record types.WithdrawalRecord) (stop bool) {
app.InterchainstakingKeeper.DeleteWithdrawalRecord(ctx, zone.ChainId, record.Txhash, record.Status)
return false
})

app.InterchainstakingKeeper.DeleteZone(ctx, zone.ChainId)

}
return false
})

// remove uni-5 queries in state
app.InterchainQueryKeeper.IterateQueries(ctx, func(_ int64, queryInfo icqtypes.Query) (stop bool) {
if queryInfo.ChainId == "uni-5" {
app.InterchainQueryKeeper.DeleteQuery(ctx, queryInfo.Id)
}
return false
})

// burn uqjunox
addr1, err := AccAddressFromBech32("quick17v9kk34km3w6hdjs2sn5s5qjdu2zrm0m3rgtmq", "quick")
if err != nil {
return nil, err
}
addr2, err := AccAddressFromBech32("quick16x03wcp37kx5e8ehckjxvwcgk9j0cqnhcccnty", "quick")
if err != nil {
return nil, err
}

err = app.BankKeeper.SendCoinsFromAccountToModule(ctx, addr1, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(1600000))))
if err != nil {
return nil, err
}

err = app.BankKeeper.SendCoinsFromAccountToModule(ctx, addr2, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(200000000))))
if err != nil {
return nil, err
}

err = app.BankKeeper.SendCoinsFromModuleToModule(ctx, types.EscrowModuleAccount, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(400000))))
if err != nil {
return nil, err
}

err = app.BankKeeper.BurnCoins(ctx, tokenfactorytypes.ModuleName, sdk.NewCoins(sdk.NewCoin("uqjunox", sdkmath.NewInt(202000000))))
if err != nil {
return nil, err
}
}
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
}
}

// AccAddressFromBech32 creates an AccAddress from a Bech32 string.
func AccAddressFromBech32(address, prefix string) (addr sdk.AccAddress, err error) {
if len(strings.TrimSpace(address)) == 0 {
return sdk.AccAddress{}, errors.New("empty address string is not allowed")
}

bz, err := sdk.GetFromBech32(address, prefix)
if err != nil {
return nil, err
}

err = sdk.VerifyAddressFormat(bz)
if err != nil {
return nil, err
}

return bz, nil
}
Loading

0 comments on commit 6b36873

Please sign in to comment.