Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into validate_blob
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 7, 2024
2 parents cc638bf + fea4dec commit 2f594db
Show file tree
Hide file tree
Showing 34 changed files with 15,315 additions and 10,695 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ jobs:
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
- name: test & coverage report creation
run: |
nix develop -c make test
nix develop .#rocksdb -c make test-versiondb
nix develop .#rocksdb -c make test test-versiondb
if: steps.changed-files.outputs.any_changed == 'true'
- name: filter out proto files
run: |
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## UNRELEASED

### State Machine Breaking

* (memiavl)[#1618](https://github.com/crypto-org-chain/cronos/pull/1618) memiavl change initial version logic to be
compatible with iavl 1.2.0.

### Improvements

* [#1592](https://github.com/crypto-org-chain/cronos/pull/1592) Change the default parallelism of the block-stm to minimum between GOMAXPROCS and NumCPU
Expand All @@ -16,6 +21,9 @@

* [#1609](https://github.com/crypto-org-chain/cronos/pull/1609) Fix query address-by-acc-num by account_id instead of id.
* [#1611](https://github.com/crypto-org-chain/cronos/pull/1611) Fix multisig account failed on threshold encode after send tx.
* [#1617](https://github.com/crypto-org-chain/cronos/pull/1617) Fix unsuppored sign mode SIGN_MODE_TEXTUAL for bank transfer.
* [#1621](https://github.com/crypto-org-chain/cronos/pull/1621) Update ethermint to the fix of broken opBlockhash and tx validation.
* [#1623](https://github.com/crypto-org-chain/cronos/pull/1623) Ensure expedited related gov params pass the basic validation.

*Sep 13, 2024*

Expand Down
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@ build: check-network print-ledger go.sum
install: check-network print-ledger go.sum
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/cronosd

test:
test: test-memiavl test-store
@go test -tags=objstore -v -mod=readonly $(PACKAGES) -coverprofile=$(COVERAGE) -covermode=atomic
@cd memiavl; go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic; cd ..
@cd store; go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic; cd ..

test-memiavl:
@cd memiavl; go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;

test-store:
@cd store; go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;

test-versiondb:
@cd versiondb; go test -tags rocksdb -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic; cd ..
@cd versiondb; go test -tags=objstore,rocksdb -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;

.PHONY: clean build install test
.PHONY: clean build install test test-memiavl test-store test-versiondb

clean:
rm -rf $(BUILDDIR)/
Expand Down
22 changes: 20 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path/filepath"
stdruntime "runtime"
"slices"
"sort"

"filippo.io/age"
Expand Down Expand Up @@ -62,13 +63,15 @@ import (
mempool "github.com/cosmos/cosmos-sdk/types/mempool"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/types/msgservice"
sigtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/version"
"github.com/cosmos/cosmos-sdk/x/auth"
authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
Expand Down Expand Up @@ -514,6 +517,21 @@ func New(
authAddr,
logger,
)
// optional: enable sign mode textual by overwriting the default tx config (after setting the bank keeper)
enabledSignModes := slices.Clone(authtx.DefaultSignModes)
enabledSignModes = append(enabledSignModes, sigtypes.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := authtx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
}
txConfig, err := authtx.NewTxConfigWithOptions(
appCodec,
txConfigOpts,
)
if err != nil {
panic(err)
}
app.txConfig = txConfig
app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
Expand Down Expand Up @@ -936,7 +954,7 @@ func New(

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
// Make sure it's called after `app.mm` and `app.configurator` are set.
app.RegisterUpgradeHandlers(app.appCodec, app.IBCKeeper.ClientKeeper)
app.RegisterUpgradeHandlers(app.appCodec)

// add test gRPC service for testing gRPC queries in isolation
// testdata.RegisterQueryServer(app.GRPCQueryRouter(), testdata.QueryImpl{})
Expand Down Expand Up @@ -981,7 +999,7 @@ func New(
app.SetPreBlocker(app.PreBlocker)
app.SetBeginBlocker(app.BeginBlocker)
app.SetEndBlocker(app.EndBlocker)
if err := app.setAnteHandler(encodingConfig.TxConfig,
if err := app.setAnteHandler(txConfig,
cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted)),
cast.ToStringSlice(appOpts.Get(FlagBlockedAddresses)),
); err != nil {
Expand Down
68 changes: 66 additions & 2 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ package app
import (
"context"
"fmt"
"time"

sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
clientkeeper "github.com/cosmos/ibc-go/v8/modules/core/02-client/keeper"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clientkeeper.Keeper) {
func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec) {
planName := "v1.4"
app.UpgradeKeeper.SetUpgradeHandler(planName, func(ctx context.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
m, err := app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
Expand All @@ -26,6 +30,14 @@ func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clie
params := app.ICAHostKeeper.GetParams(sdkCtx)
params.HostEnabled = false
app.ICAHostKeeper.SetParams(sdkCtx, params)
evmParams := app.EvmKeeper.GetParams(sdkCtx)
evmParams.HeaderHashNum = evmtypes.DefaultHeaderHashNum
if err := app.EvmKeeper.SetParams(sdkCtx, evmParams); err != nil {
return m, err
}
if err := UpdateExpeditedParams(ctx, app.GovKeeper); err != nil {
return m, err
}
}
return m, nil
})
Expand All @@ -45,3 +57,55 @@ func (app *App) RegisterUpgradeHandlers(cdc codec.BinaryCodec, clientKeeper clie
}
}
}

func UpdateExpeditedParams(ctx context.Context, gov govkeeper.Keeper) error {
govParams, err := gov.Params.Get(ctx)
if err != nil {
return err
}
if len(govParams.MinDeposit) > 0 {
minDeposit := govParams.MinDeposit[0]
expeditedAmount := minDeposit.Amount.MulRaw(govv1.DefaultMinExpeditedDepositTokensRatio)
govParams.ExpeditedMinDeposit = sdk.NewCoins(sdk.NewCoin(minDeposit.Denom, expeditedAmount))
}
threshold, err := sdkmath.LegacyNewDecFromStr(govParams.Threshold)
if err != nil {
return fmt.Errorf("invalid threshold string: %w", err)
}
expeditedThreshold, err := sdkmath.LegacyNewDecFromStr(govParams.ExpeditedThreshold)
if err != nil {
return fmt.Errorf("invalid expedited threshold string: %w", err)
}
if expeditedThreshold.LTE(threshold) {
expeditedThreshold = threshold.Mul(DefaultThresholdRatio())
}
if expeditedThreshold.GT(sdkmath.LegacyOneDec()) {
expeditedThreshold = sdkmath.LegacyOneDec()
}
govParams.ExpeditedThreshold = expeditedThreshold.String()
if govParams.ExpeditedVotingPeriod != nil && govParams.VotingPeriod != nil && *govParams.ExpeditedVotingPeriod >= *govParams.VotingPeriod {
votingPeriod := DurationToDec(*govParams.VotingPeriod)
period := DecToDuration(DefaultPeriodRatio().Mul(votingPeriod))
govParams.ExpeditedVotingPeriod = &period
}
if err := govParams.ValidateBasic(); err != nil {
return err
}
return gov.Params.Set(ctx, govParams)
}

func DefaultThresholdRatio() sdkmath.LegacyDec {
return govv1.DefaultExpeditedThreshold.Quo(govv1.DefaultThreshold)
}

func DefaultPeriodRatio() sdkmath.LegacyDec {
return DurationToDec(govv1.DefaultExpeditedPeriod).Quo(DurationToDec(govv1.DefaultPeriod))
}

func DurationToDec(d time.Duration) sdkmath.LegacyDec {
return sdkmath.LegacyMustNewDecFromStr(fmt.Sprintf("%f", d.Seconds()))
}

func DecToDuration(d sdkmath.LegacyDec) time.Duration {
return time.Second * time.Duration(d.RoundInt64())
}
120 changes: 120 additions & 0 deletions app/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package app_test

import (
"testing"
"time"

"cosmossdk.io/math"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/crypto-org-chain/cronos/v2/app"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
"github.com/stretchr/testify/suite"
)

type AppTestSuite struct {
suite.Suite

ctx sdk.Context
app *app.App
govParams govv1.Params
}

func TestAppTestSuite(t *testing.T) {
suite.Run(t, new(AppTestSuite))
}

func (suite *AppTestSuite) SetupTest() {
checkTx := false
privKey, err := ethsecp256k1.GenerateKey()
suite.Require().NoError(err)
suite.app = app.Setup(suite.T(), sdk.AccAddress(privKey.PubKey().Address()).String())
suite.ctx = suite.app.NewContext(checkTx).WithBlockHeader(tmproto.Header{Height: 1, ChainID: app.TestAppChainID, Time: time.Now().UTC()})
suite.govParams, err = suite.app.GovKeeper.Params.Get(suite.ctx)
suite.Require().NoError(err)
suite.Require().Equal(govv1.DefaultParams(), suite.govParams)
}

func (suite *AppTestSuite) TestUpdateExpeditedParams() {
const baseDenom = "basetcro"

testCases := []struct {
name string
malleate func()
exp func(params govv1.Params)
}{
{
name: "update ExpeditedMinDeposit with baseDenom",
malleate: func() {
suite.govParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(baseDenom, math.NewInt(2000000000000)))
},
exp: func(params govv1.Params) {
expected := sdk.NewCoins(sdk.NewCoin(suite.govParams.MinDeposit[0].Denom, suite.govParams.MinDeposit[0].Amount.MulRaw(govv1.DefaultMinExpeditedDepositTokensRatio)))
suite.Require().Equal(expected[0], params.ExpeditedMinDeposit[0])
},
},
{
name: "update ExpeditedThreshold when DefaultExpeditedThreshold >= Threshold",
malleate: func() {
suite.govParams.Threshold = "0.99"
},
exp: func(params govv1.Params) {
suite.Require().Equal(math.LegacyOneDec().String(), params.ExpeditedThreshold)
},
},
{
name: "update ExpeditedThreshold when DefaultExpeditedThreshold >= Threshold",
malleate: func() {
suite.govParams.Threshold = govv1.DefaultExpeditedThreshold.String()
},
exp: func(params govv1.Params) {
expected := app.DefaultThresholdRatio().Mul(math.LegacyMustNewDecFromStr(suite.govParams.Threshold))
suite.Require().Equal(expected.String(), params.ExpeditedThreshold)
},
},
{
name: "no update ExpeditedThreshold when DefaultExpeditedThreshold < Threshold",
malleate: func() {
suite.govParams.Threshold = govv1.DefaultExpeditedThreshold.Quo(math.LegacyMustNewDecFromStr("1.1")).String()
},
exp: func(params govv1.Params) {
suite.Require().Equal(suite.govParams.ExpeditedThreshold, params.ExpeditedThreshold)
},
},
{
name: "update ExpeditedVotingPeriod when DefaultExpeditedPeriod >= VotingPeriod",
malleate: func() {
period := govv1.DefaultExpeditedPeriod
suite.govParams.VotingPeriod = &period
},
exp: func(params govv1.Params) {
votingPeriod := app.DurationToDec(*suite.govParams.VotingPeriod)
expected := app.DecToDuration(app.DefaultPeriodRatio().Mul(votingPeriod))
suite.Require().Equal(expected, *params.ExpeditedVotingPeriod)
},
},
{
name: "no update ExpeditedVotingPeriod when DefaultExpeditedPeriod < VotingPeriod",
malleate: func() {
period := govv1.DefaultExpeditedPeriod + 1
suite.govParams.VotingPeriod = &period
},
exp: func(params govv1.Params) {
suite.Require().Equal(*suite.govParams.ExpeditedVotingPeriod, *params.ExpeditedVotingPeriod)
},
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()
tc.malleate()
suite.Require().NoError(suite.app.GovKeeper.Params.Set(suite.ctx, suite.govParams))
suite.Require().NoError(app.UpdateExpeditedParams(suite.ctx, suite.app.GovKeeper))
params, err := suite.app.GovKeeper.Params.Get(suite.ctx)
suite.Require().NoError(err)
tc.exp(params)
})
}
}
15 changes: 15 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/gov/v1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "GovV1Params",
"Proposal": "GovV1Proposal",
"Proposals": "GovV1Proposal",
"Vote": "GovV1Vote",
"Votes": "GovV1Votes",
"Deposit": "GovV1Deposit",
"Deposits": "GovV1Deposit",
"TallyResult": "GovV1TallyResult"
}
}
},
{
"url": "./tmp-swagger-gen/cosmos/mint/v1beta1/query.swagger.json",
"operationIds": {
Expand Down
Loading

0 comments on commit 2f594db

Please sign in to comment.