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

updates #2

Open
wants to merge 1 commit into
base: dong/v0.50.8
Choose a base branch
from
Open
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
64 changes: 64 additions & 0 deletions .github/workflows/automated-release-cosmovisor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
on:
push:
tags:
- "cosmovisor-v*"

name: Automated release cosmovisor

jobs:
build:
name: Build and upload release assets
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.20
id: go

- name: Checkout code
uses: actions/checkout@v2

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: true

# build & upload cosmovisor

- name: Build cosmovisor
run: make cosmovisor

- name: Upload cosmovisor
id: upload-cosmovisor-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cosmovisor/cosmovisor
asset_name: cosmovisor
asset_content_type: application/bin

# build & upload cosmovisor arm64

- name: Build cosmovisor arm64
run: GOARCH=arm64 make build

- name: Upload cosmovisor arm64
id: upload-cosmovisor-release-asset-arm
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: cosmovisor/cosmovisor
asset_name: cosmovisor-arm
asset_content_type: application/bin
279 changes: 179 additions & 100 deletions api/cosmos/staking/v1beta1/staking.pulsar.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ message Params {
(amino.dont_omitempty) = true,
(cosmos_proto.scalar) = "cosmos.Dec"
];
// min_global_self_delegation is the validators' self declared minimum self delegation.
string min_global_self_delegation = 10 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}

// DelegationResponse is equivalent to Delegation except that it contains a
Expand Down
3 changes: 3 additions & 0 deletions x/auth/vesting/exported/exported.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
type VestingAccount interface {
sdk.AccountI

// AddOriginalVesting increases the original vesting spreading the amount according to the
// vesting account strategy.
AddOriginalVesting(amount sdk.Coins)
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
// defined as the vesting coins that are not delegated.
//
Expand Down
51 changes: 51 additions & 0 deletions x/auth/vesting/types/vesting_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,51 @@ func (cva ContinuousVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coi
return cva.OriginalVesting.Sub(cva.GetVestedCoins(blockTime)...)
}

// AddOriginalVesting increases the original vesting spreading the amount according to the
// vesting account strategy.
func (cva *ContinuousVestingAccount) AddOriginalVesting(amount sdk.Coins) {
cva.OriginalVesting = cva.OriginalVesting.Add(amount...)
}

// LockedCoins returns the set of coins that are not spendable (i.e. locked),
// defined as the vesting coins that are not delegated.
func (cva ContinuousVestingAccount) LockedCoins(blockTime time.Time) sdk.Coins {
return cva.BaseVestingAccount.LockedCoinsFromVesting(cva.GetVestingCoins(blockTime))
}

// AddOriginalVesting increases the original vesting spreading the amount according to the
// vesting account strategy. For the periodic vesting it also equally increases the periods amount based on
// the period amount and total vesting amount.
func (pva *PeriodicVestingAccount) AddOriginalVesting(amount sdk.Coins) {
amount = amount.Sort()
incSum := sdk.NewCoins()
for i, period := range pva.VestingPeriods {
for _, incCoin := range amount {
incDenom := incCoin.Denom
prevOriginalAmt := pva.OriginalVesting.AmountOf(incDenom)
periodAmt := period.Amount.AmountOf(incDenom)
if periodAmt.IsZero() {
continue
}
incPeriodAmt := incCoin.Amount.ToLegacyDec().Mul(periodAmt.ToLegacyDec()).Quo(prevOriginalAmt.ToLegacyDec()).TruncateInt()
incPeriodCoin := sdk.NewCoin(incDenom, incPeriodAmt)
period.Amount = period.Amount.Add(incPeriodCoin)
incSum = incSum.Add(incPeriodCoin)
pva.VestingPeriods[i] = period
}
}

// new denoms and truncation remainder will be added to the last period
remainder := amount.Sub(incSum...)
if !remainder.IsZero() && len(pva.VestingPeriods) != 0 {
lastPeriod := pva.VestingPeriods[len(pva.VestingPeriods)-1]
lastPeriod.Amount = lastPeriod.Amount.Add(remainder...)
pva.VestingPeriods[len(pva.VestingPeriods)-1] = lastPeriod
}

pva.OriginalVesting = pva.OriginalVesting.Add(amount...)
}

// TrackDelegation tracks a desired delegation amount by setting the appropriate
// values for the amount of delegated vesting, delegated free, and reducing the
// overall amount of base coins.
Expand Down Expand Up @@ -424,6 +463,12 @@ func (dva DelayedVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins {
return nil
}

// AddOriginalVesting increases the original vesting spreading the amount according to the
// vesting account strategy.
func (dva *DelayedVestingAccount) AddOriginalVesting(amount sdk.Coins) {
dva.OriginalVesting = dva.OriginalVesting.Add(amount...)
}

// GetVestingCoins returns the total number of vesting coins for a delayed
// vesting account.
func (dva DelayedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
Expand Down Expand Up @@ -486,6 +531,12 @@ func (plva PermanentLockedAccount) GetVestingCoins(_ time.Time) sdk.Coins {
return plva.OriginalVesting
}

// AddOriginalVesting increases the original vesting spreading the amount according to the
// vesting account strategy.
func (plva *PermanentLockedAccount) AddOriginalVesting(amount sdk.Coins) {
plva.OriginalVesting = plva.OriginalVesting.Add(amount...)
}

// LockedCoins returns the set of coins that are not spendable (i.e. locked),
// defined as the vesting coins that are not delegated.
func (plva PermanentLockedAccount) LockedCoins(_ time.Time) sdk.Coins {
Expand Down
101 changes: 98 additions & 3 deletions x/auth/vesting/types/vesting_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import (
)

var (
stakeDenom = "stake"
feeDenom = "fee"
emptyCoins = sdk.Coins{}
stakeDenom = "stake"
feeDenom = "fee"
customDenom = "custom"
emptyCoins = sdk.Coins{}
)

type VestingAccountTestSuite struct {
Expand Down Expand Up @@ -90,6 +91,100 @@ func TestGetVestedCoinsContVestingAcc(t *testing.T) {
require.Equal(t, origCoins, vestedCoins)
}

func TestAddOriginalVestingContVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
cva, err := types.NewContinuousVestingAccount(bacc, origCoins, now.Unix(), endTime.Unix())
require.NoError(t, err)

cva.AddOriginalVesting(origCoins)
err = cva.Validate()
require.NoError(t, err)

require.Equal(t, origCoins.Add(origCoins...), cva.OriginalVesting)
}

func TestAddOriginalVestingDelVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)

bacc, origCoins := initBaseAccount()
dva, err := types.NewDelayedVestingAccount(bacc, origCoins, endTime.Unix())
require.NoError(t, err)

dva.AddOriginalVesting(origCoins)
err = dva.Validate()
require.NoError(t, err)
require.Equal(t, origCoins.Add(origCoins...), dva.OriginalVesting)
}

func TestAddOriginalVestingPeriodicVestingAcc(t *testing.T) {
now := tmtime.Now()

_, _, addr := testdata.KeyTestPubAddr()
initialOrigCoins := sdk.Coins{
sdk.NewInt64Coin(feeDenom, 1000),
sdk.NewInt64Coin(stakeDenom, 100),
}

bacc := authtypes.NewBaseAccountWithAddress(addr)

initialPeriods := []types.Period{
{Length: int64(12 * 60 * 60), Amount: sdk.Coins{
sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)},
},
{Length: int64(6 * 60 * 60), Amount: sdk.Coins{
sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)},
},
{Length: int64(6 * 60 * 60), Amount: sdk.Coins{
sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)},
},
}

pva, err := types.NewPeriodicVestingAccount(bacc, initialOrigCoins, now.Unix(), initialPeriods)
require.NoError(t, err)
err = pva.Validate()
require.NoError(t, err)

incOrigCoins := sdk.Coins{
sdk.NewInt64Coin(feeDenom, 1),
sdk.NewInt64Coin(stakeDenom, 10),
sdk.NewInt64Coin(customDenom, 100),
sdk.NewInt64Coin("zero-denom", 0),
}

pva.AddOriginalVesting(incOrigCoins)
err = pva.Validate()
require.NoError(t, err)
require.Equal(t, initialOrigCoins.Add(incOrigCoins...), pva.OriginalVesting)

expectedPeriods := []types.Period{
{Length: int64(12 * 60 * 60), Amount: sdk.Coins{
sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 55)},
},
{Length: int64(6 * 60 * 60), Amount: sdk.Coins{
sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 27)},
},
{Length: int64(6 * 60 * 60), Amount: sdk.Coins{
sdk.NewInt64Coin(customDenom, 100), sdk.NewInt64Coin(feeDenom, 251), sdk.NewInt64Coin(stakeDenom, 28)},
},
}
require.Equal(t, expectedPeriods, pva.VestingPeriods)
}

func TestAddOriginalVestingPermLockedVestingAcc(t *testing.T) {
bacc, origCoins := initBaseAccount()
plva, err := types.NewPermanentLockedAccount(bacc, origCoins)
require.NoError(t, err)

plva.AddOriginalVesting(origCoins)
err = plva.Validate()
require.NoError(t, err)
require.Equal(t, origCoins.Add(origCoins...), plva.OriginalVesting)
}

func TestGetVestingCoinsContVestingAcc(t *testing.T) {
now := tmtime.Now()
endTime := now.Add(24 * time.Hour)
Expand Down
2 changes: 1 addition & 1 deletion x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewBaseKeeper(
logger log.Logger,
) BaseKeeper {
if _, err := ak.AddressCodec().StringToBytes(authority); err != nil {
panic(fmt.Errorf("invalid bank authority address: %w", err))
panic(fmt.Errorf("invalid bank authority address 00=%s: %w", authority, err))
}

// add the module name to the logger
Expand Down
5 changes: 3 additions & 2 deletions x/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/cosmos/cosmos-sdk/x/bank/types"
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
// disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/cosmos/cosmos-sdk/x/simulation"
)

Expand Down Expand Up @@ -428,7 +429,7 @@ func getModuleAccounts(ak types.AccountKeeper, ctx sdk.Context, moduleAccCount i
moduleAccounts := make([]simtypes.Account, moduleAccCount)

for i := 0; i < moduleAccCount; i++ {
acc := ak.GetModuleAccount(ctx, disttypes.ModuleName)
acc := ak.GetModuleAccount(ctx, govtypes.ModuleName)
mAcc := simtypes.Account{
Address: acc.GetAddress(),
PrivKey: nil,
Expand Down
4 changes: 4 additions & 0 deletions x/distribution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ rewards = rewards + (R(B) - R(PN)) * stake
The historical rewards are calculated retroactively by playing back all the slashes and then attenuating the delegator's stake at each step.
The final calculated stake is equivalent to the actual staked coins in the delegation with a margin of error due to rounding errors.

For the vesting account, with the coins still locked in vesting, the reward amount will be equally spread in the vesting
based on the vesting account type strategy: for all types, the OriginalVesting amount will be increased by the reward amount. For the PeriodicVestingAccount
the amount will be additionally spread among the periods based on the amount in each period.

Response:

```protobuf reference
Expand Down
18 changes: 18 additions & 0 deletions x/distribution/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"

vestexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

Expand Down Expand Up @@ -257,6 +259,7 @@ func (k Keeper) withdrawDelegationRewards(ctx context.Context, val stakingtypes.
if err != nil {
return nil, err
}
k.addVestingRewards(ctx, del.GetDelegatorAddr(), finalRewards)
}

// update the outstanding rewards and the community pool only if the
Expand Down Expand Up @@ -318,3 +321,18 @@ func (k Keeper) withdrawDelegationRewards(ctx context.Context, val stakingtypes.

return finalRewards, nil
}

func (k Keeper) addVestingRewards(ctx context.Context, delAddr string, amt sdk.Coins) error {
delAcc, err := sdk.AccAddressFromBech32(delAddr)
if err != nil {
return err
}
sdkCtx := sdk.UnwrapSDKContext(ctx)
vacc, ok := k.authKeeper.GetAccount(ctx, delAcc).(vestexported.VestingAccount)
if !ok || vacc.GetVestingCoins(sdkCtx.BlockTime()).IsZero() {
return fmt.Errorf("addVestingRewards fail")
}
vacc.AddOriginalVesting(amt)
k.authKeeper.SetAccount(ctx, vacc)
return nil
}
Loading
Loading