Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update x/stakingplus to use Finschia/cosmos-sdk #1217

Closed
wants to merge 16 commits into from
3 changes: 3 additions & 0 deletions .github/pr_labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
# - docs/architecture/**/*
"C:x/foundation":
- x/foundation/**/*

"C:x/stakingplus":
- x/stakingplus/**/*
31 changes: 31 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,34 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: x/foundation/

test-x-stakingplus:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.21"
check-latest: true
cache: true
cache-dependency-path: x/stakingplus/go.sum
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
x/stakingplus/**/*.go
x/stakingplus/go.mod
x/stakingplus/go.sum
- name: tests
if: env.GIT_DIFF
run: |
cd x/stakingplus
go test -mod=readonly -timeout 30m -coverprofile=coverage.out -covermode=atomic -tags='norace ledger test_ledger_mock rocksdb_build' ./...
- name: sonarcloud
if: ${{ env.GIT_DIFF && !github.event.pull_request.draft && env.SONAR_TOKEN != null }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
projectBaseDir: x/stakingplus/
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased](https://github.com/Finschia/finschia-sdk/compare/v0.48.0...HEAD)

### Features
* (x/staking) [\#1214](https://github.com/Finschia/finschia-sdk/pull/1214) update x/stakingplus to use Finschia/cosmos-sdk
* (x/foundation) [\#1198](https://github.com/Finschia/finschia-sdk/pull/1198) update x/foundation to use Finschia/cosmos-sdk
* (all) [\#1205](https://github.com/Finschia/finschia-sdk/pull/1205) delegate native logics to Finschia/cosmos-sdk
* (consensus) [\#1178](https://github.com/Finschia/finschia-sdk/pull/1178) change the consensus from Ostracon to Tendermint v0.34.24
Expand Down
1 change: 1 addition & 0 deletions go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ use (
./simapp
./tests
./x/foundation
./x/stakingplus
)
1 change: 1 addition & 0 deletions scripts/mockgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

mockgen_cmd="mockgen"
$mockgen_cmd -source=x/foundation/expected_keepers.go -package testutil -destination x/foundation/testutil/expected_keepers_mocks.go
$mockgen_cmd -source=x/stakingplus/expected_keepers.go -package testutil -destination x/stakingplus/testutil/expected_keepers_mocks.go
4 changes: 2 additions & 2 deletions scripts/protocgen-pulsar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ echo "Cleaning API directory"
echo "Generating API module"
(cd proto; buf generate --template buf.gen.pulsar.yaml)

echo "Generate Pulsar Test Data"
(cd testutil/testdata; buf generate --template buf.gen.pulsar.yaml)
# echo "Generate Pulsar Test Data"
# (cd testutil/testdata; buf generate --template buf.gen.pulsar.yaml)
4 changes: 2 additions & 2 deletions simapp/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
_ "github.com/cosmos/cosmos-sdk/x/slashing" // import for side-effects
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
_ "github.com/cosmos/cosmos-sdk/x/staking" // import for side-effects
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

foundationmodulev1 "github.com/Finschia/finschia-sdk/api/lbm/foundation/module/v1"
foundation "github.com/Finschia/finschia-sdk/x/foundation"
_ "github.com/Finschia/finschia-sdk/x/foundation/module" // import for side-effects
_ "github.com/Finschia/finschia-sdk/x/foundation/module" // import for side-effects
_ "github.com/Finschia/finschia-sdk/x/stakingplus/module" // import for side-effects
)

var (
Expand Down
6 changes: 3 additions & 3 deletions simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"

foundationmodule "github.com/Finschia/finschia-sdk/x/foundation/module"
stakingplusmodule "github.com/Finschia/finschia-sdk/x/stakingplus/module"
)

func TestSimAppExportAndBlockedAddrs(t *testing.T) {
Expand Down Expand Up @@ -203,7 +203,7 @@ func TestRunMigrations(t *testing.T) {
"bank": 1,
"auth": auth.AppModule{}.ConsensusVersion(),
"authz": authzmodule.AppModule{}.ConsensusVersion(),
"staking": staking.AppModule{}.ConsensusVersion(),
"staking": stakingplusmodule.AppModule{}.ConsensusVersion(),
"mint": mint.AppModule{}.ConsensusVersion(),
"distribution": distribution.AppModule{}.ConsensusVersion(),
"slashing": slashing.AppModule{}.ConsensusVersion(),
Expand Down Expand Up @@ -254,7 +254,7 @@ func TestInitGenesisOnMigration(t *testing.T) {
"bank": bank.AppModule{}.ConsensusVersion(),
"auth": auth.AppModule{}.ConsensusVersion(),
"authz": authzmodule.AppModule{}.ConsensusVersion(),
"staking": staking.AppModule{}.ConsensusVersion(),
"staking": stakingplusmodule.AppModule{}.ConsensusVersion(),
"mint": mint.AppModule{}.ConsensusVersion(),
"distribution": distribution.AppModule{}.ConsensusVersion(),
"slashing": slashing.AppModule{}.ConsensusVersion(),
Expand Down
2 changes: 2 additions & 0 deletions simapp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
cosmossdk.io/x/upgrade v0.1.1
github.com/Finschia/finschia-sdk/api v0.0.0-20231227090232-78fde403b78c
github.com/Finschia/finschia-sdk/x/foundation v0.0.0-00010101000000-000000000000
github.com/Finschia/finschia-sdk/x/stakingplus v0.0.0-00010101000000-000000000000
github.com/cometbft/cometbft v0.38.2
github.com/cosmos/cosmos-db v1.0.0
// this version is not used as it is always replaced by the latest Cosmos SDK version
Expand Down Expand Up @@ -206,6 +207,7 @@ replace (
// Simapp always use the latest version of the finschia-sdk
github.com/Finschia/finschia-sdk/api => ../api
github.com/Finschia/finschia-sdk/x/foundation => ../x/foundation
github.com/Finschia/finschia-sdk/x/stakingplus => ../x/stakingplus
// Fix upstream GHSA-h395-qcrw-5vmq and GHSA-3vp4-m3rf-835h vulnerabilities.
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
Expand Down
32 changes: 32 additions & 0 deletions x/stakingplus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
sidebar_position: 1
---

# `x/stakingplus`

## Abstract

This paper specifies the Staking Plus module of the Finschia-sdk, which extends existing [Staking module](https://github.com/cosmos/cosmos-sdk/blob/v0.50.2/x/staking/README.md) of the Cosmos-SDK.

The module enables Finschia-sdk based blockchain to support an advanced Proof-of-Stake system. In this system, holders of the native staking token of the chain can become validators and can delegate tokens to validators, ultimately determining the effective validator set for the system.

This module is almost identical to the previous Staking module of the Cosmos-SDK, but introduces some breaking changes. For example, you must have x/foundation UpdateValidatorAuthsProposal passed before sending x/stakingplus MsgCreateValidator, or the message would fail.

In this document, we describe only the changes introduced by Finschia-SDK. Refer to the [original document](https://github.com/cosmos/cosmos-sdk/blob/v0.50.2/x/staking/README.md) for more information.

# Messages

## Msg/CreateValidator

A validator is created using the `Msg/CreateValidator` service message.

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.50.2/proto/cosmos/staking/v1beta1/tx.proto#L20-L21

+++ https://github.com/cosmos/cosmos-sdk/blob/v0.50.2/proto/cosmos/staking/v1beta1/tx.proto#L50-L73

This service message is expected to fail if:

- one of the conditions described in the staking module of the Cosmos-SDK is met.
- the operator address is not registered on x/foundation through UpdateValidatorAuthsProposal. TODO: add a ref to x/foundation spec file.

The other [statements](https://github.com/cosmos/cosmos-sdk/blob/v0.50.2/x/staking/README.md#msgcreatevalidator) on this message in the exising document are still valid.
36 changes: 36 additions & 0 deletions x/stakingplus/authz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package stakingplus

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/Finschia/finschia-sdk/x/foundation"
)

var _ foundation.Authorization = (*CreateValidatorAuthorization)(nil)

func (a CreateValidatorAuthorization) MsgTypeURL() string {
return sdk.MsgTypeURL(&stakingtypes.MsgCreateValidator{})
}

func (a CreateValidatorAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (foundation.AcceptResponse, error) {
mCreate, ok := msg.(*stakingtypes.MsgCreateValidator)
if !ok {
return foundation.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch")
}

if mCreate.ValidatorAddress != a.ValidatorAddress {
return foundation.AcceptResponse{}, sdkerrors.ErrUnauthorized.Wrap("validator address differs from the authorization's")
}

return foundation.AcceptResponse{Accept: true}, nil
}

func (a CreateValidatorAuthorization) ValidateBasic() error {
if _, err := sdk.ValAddressFromBech32(a.ValidatorAddress); err != nil {
return err
}

return nil
}
Loading
Loading