Skip to content

Commit

Permalink
Merge branch 'develop' into test-remove-usdt-mentions-from-e2e-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito authored Mar 11, 2024
2 parents e9a4096 + 828529c commit 1e6977b
Show file tree
Hide file tree
Showing 26 changed files with 386 additions and 122 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* [1511](https://github.com/zeta-chain/node/pull/1511) - move ballot voting logic from `crosschain` to `observer`
* [1783](https://github.com/zeta-chain/node/pull/1783) - refactor zetaclient metrics naming and structure
* [1774](https://github.com/zeta-chain/node/pull/1774) - split params and config in zetaclient
* [1831](https://github.com/zeta-chain/node/pull/1831) - removing unnecessary pointers in context structure

### Features

Expand All @@ -30,6 +31,10 @@
* [1840](https://github.com/zeta-chain/node/pull/1840) - fix code coverage test failures ignored in CI
* [1851](https://github.com/zeta-chain/node/pull/1851) - rename usdt to erc20 in e2e tests

### Fixes

* [1861](https://github.com/zeta-chain/node/pull/1861) - fix `ObserverSlashAmount` invalid read

### Chores

* [1814](https://github.com/zeta-chain/node/pull/1814) - fix code coverage ignore for protobuf generated files
Expand Down
6 changes: 3 additions & 3 deletions cmd/zetaclientd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func SetupConfigForTest() {

}

func InitLogger(cfg *config.Config) (clientcommon.ClientLogger, error) {
func InitLogger(cfg config.Config) (clientcommon.ClientLogger, error) {
// open compliance log file
file, err := OpenComplianceLogFile(cfg)
if err != nil {
Expand Down Expand Up @@ -92,10 +92,10 @@ func InitLogger(cfg *config.Config) (clientcommon.ClientLogger, error) {
}, nil
}

func OpenComplianceLogFile(cfg *config.Config) (*os.File, error) {
func OpenComplianceLogFile(cfg config.Config) (*os.File, error) {
// use zetacore home as default
logPath := cfg.ZetaCoreHome
if cfg.ComplianceConfig != nil && cfg.ComplianceConfig.LogPath != "" {
if cfg.ComplianceConfig.LogPath != "" {
logPath = cfg.ComplianceConfig.LogPath
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/zetaclientd/p2p_diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/zeta-chain/zetacore/zetaclient/config"
)

func RunDiagnostics(startLogger zerolog.Logger, peers p2p.AddrList, bridgePk cryptotypes.PrivKey, cfg *config.Config) error {
func RunDiagnostics(startLogger zerolog.Logger, peers p2p.AddrList, bridgePk cryptotypes.PrivKey, cfg config.Config) error {

startLogger.Warn().Msg("P2P Diagnostic mode enabled")
startLogger.Warn().Msgf("seed peer: %s", peers)
Expand Down
5 changes: 3 additions & 2 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ func start(_ *cobra.Command, _ []string) error {
// For existing keygen, this should directly proceed to the next step
ticker := time.NewTicker(time.Second * 1)
for range ticker.C {
if appContext.ZetaCoreContext().GetKeygen().Status != observerTypes.KeygenStatus_KeyGenSuccess {
startLogger.Info().Msgf("Waiting for TSS Keygen to be a success, current status %s", appContext.ZetaCoreContext().GetKeygen().Status)
keyGen := appContext.ZetaCoreContext().GetKeygen()
if keyGen.Status != observerTypes.KeygenStatus_KeyGenSuccess {
startLogger.Info().Msgf("Waiting for TSS Keygen to be a success, current status %s", keyGen.Status)
continue
}
break
Expand Down
16 changes: 7 additions & 9 deletions cmd/zetaclientd/start_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"google.golang.org/grpc"
)

func waitForZetaCore(configData *config.Config, logger zerolog.Logger) {
func waitForZetaCore(config config.Config, logger zerolog.Logger) {
// wait until zetacore is up
logger.Debug().Msg("Waiting for ZetaCore to open 9090 port...")
for {
_, err := grpc.Dial(
fmt.Sprintf("%s:9090", configData.ZetaCoreURL),
fmt.Sprintf("%s:9090", config.ZetaCoreURL),
grpc.WithInsecure(),
)
if err != nil {
Expand Down Expand Up @@ -54,20 +54,18 @@ func validatePeer(seedPeer string) error {
// maskCfg sensitive fields are masked, currently only the EVM endpoints and bitcoin credentials,
//
// other fields can be added.
func maskCfg(cfg *config.Config) string {
maskedCfg := config.NewConfig()
func maskCfg(cfg config.Config) string {
maskedCfg := cfg

// Deep copy since cfg contains some references
*maskedCfg = *cfg
maskedCfg.BitcoinConfig = &config.BTCConfig{
maskedCfg.BitcoinConfig = config.BTCConfig{
RPCUsername: cfg.BitcoinConfig.RPCUsername,
RPCPassword: cfg.BitcoinConfig.RPCPassword,
RPCHost: cfg.BitcoinConfig.RPCHost,
RPCParams: cfg.BitcoinConfig.RPCParams,
}
maskedCfg.EVMChainConfigs = map[int64]*config.EVMConfig{}
maskedCfg.EVMChainConfigs = map[int64]config.EVMConfig{}
for key, val := range cfg.EVMChainConfigs {
maskedCfg.EVMChainConfigs[key] = &config.EVMConfig{
maskedCfg.EVMChainConfigs[key] = config.EVMConfig{
Chain: val.Chain,
Endpoint: val.Endpoint,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func CreateAuthzSigner(granter string, grantee sdk.AccAddress) {
authz.SetupAuthZSignerList(granter, grantee)
}

func CreateZetaBridge(cfg *config.Config, telemetry *metrics.TelemetryServer, hotkeyPassword string) (*zetabridge.ZetaCoreBridge, error) {
func CreateZetaBridge(cfg config.Config, telemetry *metrics.TelemetryServer, hotkeyPassword string) (*zetabridge.ZetaCoreBridge, error) {
hotKey := cfg.AuthzHotkey
if cfg.HsmMode {
hotKey = cfg.HsmHotKey
Expand Down Expand Up @@ -115,7 +115,7 @@ func CreateChainClientMap(
if !evmChainParams.IsSupported {
continue
}
co, err := evm.NewEVMChainClient(appContext, bridge, tss, dbpath, loggers, *evmConfig, ts)
co, err := evm.NewEVMChainClient(appContext, bridge, tss, dbpath, loggers, evmConfig, ts)
if err != nil {
loggers.Std.Error().Err(err).Msgf("NewEVMChainClient error for chain %s", evmConfig.Chain.String())
continue
Expand Down
19 changes: 16 additions & 3 deletions x/emissions/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
observerRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).ObserverEmissionPercentage).Mul(blockRewards).TruncateInt()
tssSignerRewards := sdk.MustNewDecFromStr(keeper.GetParams(ctx).TssSignerEmissionPercentage).Mul(blockRewards).TruncateInt()

// TODO : Replace hardcoded slash amount with a parameter
// https://github.com/zeta-chain/node/pull/1861
slashAmount, ok := sdkmath.NewIntFromString(types.ObserverSlashAmount)
if !ok {
ctx.Logger().Error(fmt.Sprintf("Error while parsing observer slash amount %s", types.ObserverSlashAmount))
return
}

// 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()
Expand All @@ -30,7 +38,7 @@ func BeginBlocker(ctx sdk.Context, keeper keeper.Keeper) {
ctx.Logger().Error(fmt.Sprintf("Error while distributing validator rewards %s", err))
return
}
err = DistributeObserverRewards(tmpCtx, observerRewards, keeper)
err = DistributeObserverRewards(tmpCtx, observerRewards, keeper, slashAmount)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Error while distributing observer rewards %s", err))
return
Expand Down Expand Up @@ -63,7 +71,12 @@ func DistributeValidatorRewards(ctx sdk.Context, amount sdkmath.Int, bankKeeper
// NotVoted or Unsuccessful votes are slashed
// rewards given or slashed amounts are in azeta

func DistributeObserverRewards(ctx sdk.Context, amount sdkmath.Int, keeper keeper.Keeper) error {
func DistributeObserverRewards(
ctx sdk.Context,
amount sdkmath.Int,
keeper keeper.Keeper,
slashAmount sdkmath.Int,
) error {

rewardsDistributer := map[string]int64{}
totalRewardsUnits := int64(0)
Expand Down Expand Up @@ -113,7 +126,7 @@ func DistributeObserverRewards(ctx sdk.Context, amount sdkmath.Int, keeper keepe
continue
}
if observerRewardUnits < 0 {
slashAmount := keeper.GetParams(ctx).ObserverSlashAmount

keeper.SlashObserverEmission(ctx, observerAddress.String(), slashAmount)
finalDistributionList = append(finalDistributionList, &types.ObserverEmission{
EmissionType: types.EmissionType_Slash,
Expand Down
4 changes: 3 additions & 1 deletion x/emissions/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func TestBeginBlocker(t *testing.T) {
}

func TestDistributeObserverRewards(t *testing.T) {
keepertest.SetConfig(false)
observerSet := sample.ObserverSet(4)

tt := []struct {
Expand Down Expand Up @@ -286,8 +287,9 @@ func TestDistributeObserverRewards(t *testing.T) {
ctx = ctx.WithBlockHeight(100)

// Distribute the rewards and check if the rewards are distributed correctly
err = emissionsModule.DistributeObserverRewards(ctx, tc.totalRewardsForBlock, *k)
err = emissionsModule.DistributeObserverRewards(ctx, tc.totalRewardsForBlock, *k, tc.slashAmount)
require.NoError(t, err)

for i, observer := range observerSet.ObserverList {
observerEmission, found := k.GetWithdrawableEmission(ctx, observer)
require.True(t, found, "withdrawable emission not found for observer %d", i)
Expand Down
7 changes: 6 additions & 1 deletion x/emissions/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package emissions_test
import (
"testing"

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

"github.com/stretchr/testify/require"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/testutil/nullify"
Expand All @@ -12,8 +14,11 @@ import (
)

func TestGenesis(t *testing.T) {
params := types.DefaultParams()
params.ObserverSlashAmount = sdk.Int{}

genesisState := types.GenesisState{
Params: types.DefaultParams(),
Params: params,
WithdrawableEmissions: []types.WithdrawableEmissions{
sample.WithdrawableEmissions(t),
sample.WithdrawableEmissions(t),
Expand Down
17 changes: 1 addition & 16 deletions x/emissions/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
"testing"

sdkmath "cosmossdk.io/math"
"github.com/stretchr/testify/require"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types"
Expand All @@ -26,7 +25,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "",
},
Expand All @@ -41,7 +39,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(-10),
},
isPanic: "slash amount cannot be less than 0",
},
Expand All @@ -56,7 +53,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "max bond factor cannot be higher that 0.25",
},
Expand All @@ -71,7 +67,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "min bond factor cannot be lower that 0.75",
},
Expand All @@ -86,7 +81,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "invalid block time",
},
Expand All @@ -101,7 +95,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "block time cannot be less than or equal to 0",
},
Expand All @@ -116,7 +109,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "target bond ratio cannot be more than 100 percent",
},
Expand All @@ -131,7 +123,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "target bond ratio cannot be less than 0 percent",
},
Expand All @@ -146,7 +137,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "validator emission percentage cannot be more than 100 percent",
},
Expand All @@ -161,7 +151,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "validator emission percentage cannot be less than 0 percent",
},
Expand All @@ -176,7 +165,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "-00.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "observer emission percentage cannot be less than 0 percent",
},
Expand All @@ -191,7 +179,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "150.25",
TssSignerEmissionPercentage: "00.25",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "observer emission percentage cannot be more than 100 percent",
},
Expand All @@ -206,12 +193,11 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "102.22",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "tss emission percentage cannot be more than 100 percent",
},
{
name: "tss signer percentage too loo",
name: "tss signer percentage too low",
params: emissionstypes.Params{
MaxBondFactor: "1.25",
MinBondFactor: "0.75",
Expand All @@ -221,7 +207,6 @@ func TestKeeper_GetParams(t *testing.T) {
ObserverEmissionPercentage: "00.25",
TssSignerEmissionPercentage: "-102.22",
DurationFactorConstant: "0.001877876953694702",
ObserverSlashAmount: sdkmath.NewInt(100000000000000000),
},
isPanic: "tss emission percentage cannot be less than 0 percent",
},
Expand Down
6 changes: 6 additions & 0 deletions x/emissions/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const (

EmissionScheduledYears = 4
AvgBlockTime = "5.7"

// ObserverSlashAmount is the amount of tokens to be slashed from observer in case of incorrect vote
// it is set to 0.1 ZETA
// TODO: replace this with a parameter
// https://github.com/zeta-chain/node/pull/1861
ObserverSlashAmount = "100000000000000000"
)

func KeyPrefix(p string) []byte {
Expand Down
Loading

0 comments on commit 1e6977b

Please sign in to comment.