Skip to content

Commit

Permalink
rebase develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Feb 6, 2024
2 parents 08abc49 + 83568e2 commit 4f768cb
Show file tree
Hide file tree
Showing 21 changed files with 780 additions and 454 deletions.
4 changes: 1 addition & 3 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
observerTypes "github.com/zeta-chain/zetacore/x/observer/types"
)

const releaseVersion = "v12.1.0"
const releaseVersion = "v12.2.0"

func SetupHandlers(app *App) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
Expand All @@ -17,7 +16,6 @@ func SetupHandlers(app *App) {
for m, mb := range app.mm.Modules {
vm[m] = mb.ConsensusVersion()
}
vm = VersionMigrator{vm}.TriggerMigration(observerTypes.ModuleName)

return app.mm.RunMigrations(ctx, app.configurator, vm)
})
Expand Down
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
## Unreleased

### Fixes

* [1638](https://github.com/zeta-chain/node/issues/1638) - additional check to make sure external chain height always increases
* [1672](https://github.com/zeta-chain/node/pull/1672) - paying 50% more than base gas price to buffer EIP1559 gas price increase
* [1642](https://github.com/zeta-chain/node/pull/1642) - Change WhitelistERC20 authorization from group1 to group2
* [1610](https://github.com/zeta-chain/node/issues/1610) - add pending outtx hash to tracker after monitoring for 10 minutes
* [1656](https://github.com/zeta-chain/node/issues/1656) - schedule bitcoin keysign with intervals to avoid keysign failures
* [1662](https://github.com/zeta-chain/node/issues/1662) - skip Goerli BlobTxType transactions introduced in Dencun upgrade
* [1663](https://github.com/zeta-chain/node/issues/1663) - skip Mumbai empty block if ethclient sanity check fails
* [1661](https://github.com/zeta-chain/node/issues/1661) - use estimated SegWit tx size for Bitcoin gas fee calculation
* [1667](https://github.com/zeta-chain/node/issues/1667) - estimate SegWit tx size in uinit of vByte

## Chores
* [1694](https://github.com/zeta-chain/node/pull/1694) - remove standalone network, use assert testing package for the entire node folder
Expand All @@ -14,6 +23,7 @@
* [1577](https://github.com/zeta-chain/node/pull/1577) - add chain header tests in E2E tests and fix admin tests

### Features
* [1658](https://github.com/zeta-chain/node/pull/1658) - modify emission distribution to use fixed block rewards

### Fixes
* [1535](https://github.com/zeta-chain/node/issues/1535) - Avoid voting on wrong ballots due to false blockNumber in EVM tx receipt
Expand Down
14 changes: 14 additions & 0 deletions common/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package common
import (
"fmt"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
)

func GetCoinType(coin string) (CoinType, error) {
Expand All @@ -16,3 +18,15 @@ func GetCoinType(coin string) (CoinType, error) {
// #nosec G701 always in range
return CoinType(coinInt), nil
}

func GetAzetaDecFromAmountInZeta(zetaAmount string) (sdk.Dec, error) {
zetaDec, err := sdk.NewDecFromStr(zetaAmount)
if err != nil {
return sdk.Dec{}, err
}
zetaToAzetaConvertionFactor, err := sdk.NewDecFromStr("1000000000000000000")
if err != nil {
return sdk.Dec{}, err
}
return zetaDec.Mul(zetaToAzetaConvertionFactor), nil
}
65 changes: 65 additions & 0 deletions common/coin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package common_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"github.com/zeta-chain/zetacore/common"
)

func Test_GetAzetaDecFromAmountInZeta(t *testing.T) {
tt := []struct {
name string
zetaAmount string
err assert.ErrorAssertionFunc
azetaAmount sdk.Dec
}{
{
name: "valid zeta amount",
zetaAmount: "210000000",
err: assert.NoError,
azetaAmount: sdk.MustNewDecFromStr("210000000000000000000000000"),
},
{
name: "very high zeta amount",
zetaAmount: "21000000000000000000",
err: assert.NoError,
azetaAmount: sdk.MustNewDecFromStr("21000000000000000000000000000000000000"),
},
{
name: "very low zeta amount",
zetaAmount: "1",
err: assert.NoError,
azetaAmount: sdk.MustNewDecFromStr("1000000000000000000"),
},
{
name: "zero zeta amount",
zetaAmount: "0",
err: assert.NoError,
azetaAmount: sdk.MustNewDecFromStr("0"),
},
{
name: "decimal zeta amount",
zetaAmount: "0.1",
err: assert.NoError,
azetaAmount: sdk.MustNewDecFromStr("100000000000000000"),
},
{
name: "invalid zeta amount",
zetaAmount: "%%%%%$#",
err: assert.Error,
azetaAmount: sdk.MustNewDecFromStr("0"),
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
azeta, err := common.GetAzetaDecFromAmountInZeta(tc.zetaAmount)
tc.err(t, err)
if err == nil {
assert.Equal(t, tc.azetaAmount, azeta)
}
})
}

}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ require (
gorm.io/gorm v1.24.6
)

require github.com/binance-chain/tss-lib v0.0.0-20201118045712-70b2cb4bf916
require (
github.com/binance-chain/tss-lib v0.0.0-20201118045712-70b2cb4bf916
github.com/onrik/ethrpc v1.2.0
)

require (
github.com/DataDog/zstd v1.5.2 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,7 @@ github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7Bd
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jaguilar/vt100 v0.0.0-20150826170717-2703a27b14ea/go.mod h1:QMdK4dGB3YhEW2BmA1wgGpPYI3HZy/5gD705PXKUVSg=
github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jarcoal/httpmock v1.3.0 h1:2RJ8GP0IIaWwcC9Fp2BmVi8Kog3v2Hn7VXM3fTd+nuc=
github.com/jbenet/go-cienv v0.1.0/go.mod h1:TqNnHUmJgXau0nCzC7kXWeotg3J9W34CUv5Djy1+FlA=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jbenet/go-temp-err-catcher v0.1.0 h1:zpb3ZH6wIE8Shj2sKS+khgRvf7T7RABoLk/+KKHggpk=
Expand Down Expand Up @@ -2358,6 +2359,8 @@ github.com/olekukonko/tablewriter v0.0.2-0.20190409134802-7e037d187b0c/go.mod h1
github.com/olekukonko/tablewriter v0.0.2/go.mod h1:rSAaSIOAGT9odnlyGlUfAJaoc5w2fSBUmeGDbRWPxyQ=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onrik/ethrpc v1.2.0 h1:BBcr1iWxW1RBP/eyZfzvSKtGgeqexq5qS0yyf4pmKbc=
github.com/onrik/ethrpc v1.2.0/go.mod h1:uvyqpn8+WbsTgBYfouImgEfpIMb0hR8fWGjwdgPHtFU=
github.com/onsi/ginkgo v0.0.0-20151202141238-7f8ab55aaf3b/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
2 changes: 1 addition & 1 deletion x/crosschain/keeper/msg_server_whitelist_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
// Authorized: admin policy group 1.
func (k msgServer) WhitelistERC20(goCtx context.Context, msg *types.MsgWhitelistERC20) (*types.MsgWhitelistERC20Response, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
if msg.Creator != k.zetaObserverKeeper.GetParams(ctx).GetAdminPolicyAccount(zetaObserverTypes.Policy_Type_group1) {
if msg.Creator != k.zetaObserverKeeper.GetParams(ctx).GetAdminPolicyAccount(zetaObserverTypes.Policy_Type_group2) {
return nil, errorsmod.Wrap(sdkerrors.ErrUnauthorized, "Deploy can only be executed by the correct policy account")
}
erc20Addr := ethcommon.HexToAddress(msg.Erc20Address)
Expand Down
35 changes: 23 additions & 12 deletions x/emissions/abci.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package emissions

import (
"fmt"
"sort"

sdkmath "cosmossdk.io/math"
Expand All @@ -11,29 +12,38 @@ import (
)

func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
emissionPoolBalance := keeper.GetReservesFactor(ctx)
blockRewards := types.BlockReward

reservesFactor, bondFactor, durationFactor := keeper.GetBlockRewardComponents(ctx)
blockRewards := reservesFactor.Mul(bondFactor).Mul(durationFactor)
if blockRewards.IsZero() {
if blockRewards.GT(emissionPoolBalance) {
ctx.Logger().Info(fmt.Sprintf("Block rewards %s are greater than emission pool balance %s", blockRewards.String(), emissionPoolBalance.String()))
return
}
validatorRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).ValidatorEmissionPercentage).Mul(blockRewards).TruncateInt()
observerRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).ObserverEmissionPercentage).Mul(blockRewards).TruncateInt()
tssSignerRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).TssSignerEmissionPercentage).Mul(blockRewards).TruncateInt()
err := DistributeValidatorRewards(ctx, validatorRewards, keeper.GetBankKeeper(), keeper.GetFeeCollector())
// Use a tmpCtx, which is a cache-wrapped context to avoid writing to the store
// We commit only if all three distributions are successful, if not the funds stay in the emission pool
tmpCtx, commit := ctx.CacheContext()
err := DistributeValidatorRewards(tmpCtx, validatorRewards, keeper.GetBankKeeper(), keeper.GetFeeCollector())
if err != nil {
panic(err)
ctx.Logger().Error(fmt.Sprintf("Error while distributing validator rewards %s", err))
return
}
err = DistributeObserverRewards(ctx, observerRewards, keeper)
err = DistributeObserverRewards(tmpCtx, observerRewards, keeper)
if err != nil {
panic(err)
ctx.Logger().Error(fmt.Sprintf("Error while distributing observer rewards %s", err))
return
}
err = DistributeTssRewards(ctx, tssSignerRewards, keeper.GetBankKeeper())
err = DistributeTssRewards(tmpCtx, tssSignerRewards, keeper.GetBankKeeper())
if err != nil {
panic(err)
ctx.Logger().Error(fmt.Sprintf("Error while distributing tss signer rewards %s", err))
return
}
types.EmitValidatorEmissions(ctx, bondFactor.String(), reservesFactor.String(),
durationFactor.String(),
commit()

types.EmitValidatorEmissions(ctx, "", "",
"",
validatorRewards.String(),
observerRewards.String(),
tssSignerRewards.String())
Expand All @@ -44,6 +54,7 @@ func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
// This function uses the distribution module of cosmos-sdk , by directly sending funds to the feecollector.
func DistributeValidatorRewards(ctx sdk.Context, amount sdkmath.Int, bankKeeper types.BankKeeper, feeCollector string) error {
coin := sdk.NewCoins(sdk.NewCoin(config.BaseDenom, amount))
ctx.Logger().Info(fmt.Sprintf(fmt.Sprintf("Distributing Validator Rewards Total:%s To FeeCollector : %s", amount.String(), feeCollector)))
return bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, feeCollector, coin)
}

Expand Down Expand Up @@ -76,7 +87,7 @@ func DistributeObserverRewards(ctx sdk.Context, amount sdkmath.Int, keeper keepe
if totalRewardsUnits > 0 && amount.IsPositive() {
rewardPerUnit = amount.Quo(sdk.NewInt(totalRewardsUnits))
}

ctx.Logger().Debug(fmt.Sprintf("Total Rewards Units : %d , rewards per Unit %s ,number of ballots :%d", totalRewardsUnits, rewardPerUnit.String(), len(ballotIdentifiers)))
sortedKeys := make([]string, 0, len(rewardsDistributer))
for k := range rewardsDistributer {
sortedKeys = append(sortedKeys, k)
Expand Down
Loading

0 comments on commit 4f768cb

Please sign in to comment.