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

refactor: removing unnecessary pointers in context structure #1831

Merged
merged 22 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge branch 'develop' into refactor-config-context-follow-up
  • Loading branch information
skosito committed Mar 7, 2024
commit 1c7767326b9e9aa1be01606756088a62311f95e5
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ test :clean-test-dir run-test
test-hsm:
@go test ${HSM_BUILD_FLAGS} ${TEST_DIR}

test-coverage-exclude-core:
@go test ${TEST_BUILD_FLAGS} -v -coverprofile coverage.out $(go list ./... | grep -v /x/zetacore/)

# Generate the test coverage
# "|| exit 1" is used to return a non-zero exit code if the tests fail
test-coverage:
-@go test ${TEST_BUILD_FLAGS} -v -coverprofile coverage.out ${TEST_DIR}
@go test ${TEST_BUILD_FLAGS} -coverprofile coverage.out ${TEST_DIR} || exit 1

coverage-report: test-coverage
@go tool cover -html=coverage.out -o coverage.html
Expand Down
7 changes: 5 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@
### Features

* [1789](https://github.com/zeta-chain/node/issues/1789) - block cross-chain transactions that involve restricted addresses
* [1755](https://github.com/zeta-chain/node/issues/1755) - use evm JSON RPC for inbound tx (including blob tx) observation.
* [1815](https://github.com/zeta-chain/node/pull/1815) - add authority module for authorized actions

### Tests

* [1767](https://github.com/zeta-chain/node/pull/1767) - add unit tests for emissions module begin blocker
* [1816](https://github.com/zeta-chain/node/pull/1816) - add args to e2e tests
* [1791](https://github.com/zeta-chain/node/pull/1791) - add e2e tests for feature of restricted address
* [1787](https://github.com/zeta-chain/node/pull/1787) - add unit tests for cross-chain evm hooks and e2e test failed withdraw to BTC legacy address
* [1787](https://github.com/zeta-chain/node/pull/1787) - add unit tests for cross-chain evm hooks and e2e test failed withdraw to BTC legacy address
* [1840](https://github.com/zeta-chain/node/pull/1840) - fix code coverage test failures ignored in CI

### Chores

* [1814](https://github.com/zeta-chain/node/pull/1814) - fix code coverage ignore for protobuf generated files

## Version: v14

### Fixes
- [1817](https://github.com/zeta-chain/node/pull/1817) - Add migration script to fix pending and chain nonces on testnet

## Version: v13.0.0
Expand Down Expand Up @@ -62,6 +63,7 @@
* [1766](https://github.com/zeta-chain/node/pull/1766) - Refactors the `PostTxProcessing` EVM hook functionality to deal with invalid withdraw events
* [1630](https://github.com/zeta-chain/node/pull/1630) - added password prompts for hotkey and tss keyshare in zetaclient
* [1760](https://github.com/zeta-chain/node/pull/1760) - Make staking keeper private in crosschain module
* [1809](https://github.com/zeta-chain/node/pull/1809) - Refactored tryprocessout function in evm signer

### Fixes

Expand Down Expand Up @@ -98,6 +100,7 @@
* Added scripts for the new docker image that facilitate the start up automation.
* Adjusted the docker pipeline slightly to pull the version on PR from the app.go file.
* [1781](https://github.com/zeta-chain/node/pull/1781) - add codecov coverage report in CI
* fixed the download binary script to use relative pathing from binary_list file.

### Features

Expand Down
27 changes: 17 additions & 10 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"strings"
"sync"

"github.com/ethereum/go-ethereum/ethclient"
"github.com/onrik/ethrpc"
"github.com/zeta-chain/zetacore/zetaclient/bitcoin"
corecontext "github.com/zeta-chain/zetacore/zetaclient/core_context"
"github.com/zeta-chain/zetacore/zetaclient/evm"
Expand All @@ -18,7 +20,6 @@ import (
"github.com/btcsuite/btcd/rpcclient"
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/common"
Expand Down Expand Up @@ -101,26 +102,33 @@ func DebugCmd() *cobra.Command {
}
ob.WithZetaClient(bridge)
ob.WithLogger(chainLogger)
client := &ethclient.Client{}
var ethRPC *ethrpc.EthRPC
var client *ethclient.Client
coinType := common.CoinType_Cmd
for chain, evmConfig := range cfg.GetAllEVMConfigs() {
if chainID == chain {
ethRPC = ethrpc.NewEthRPC(evmConfig.Endpoint)
client, err = ethclient.Dial(evmConfig.Endpoint)
if err != nil {
return err
}
ob.WithEvmClient(client)
ob.WithEvmJSONRPC(ethRPC)
ob.WithChain(*common.GetChainFromChainID(chainID))
}
}
hash := ethcommon.HexToHash(txHash)
tx, isPending, err := client.TransactionByHash(context.Background(), hash)
tx, isPending, err := ob.TransactionByHash(txHash)
if err != nil {
return fmt.Errorf("tx not found on chain %s , %d", err.Error(), chain.ChainId)
}
if isPending {
return fmt.Errorf("tx is still pending")
}
receipt, err := client.TransactionReceipt(context.Background(), hash)
if err != nil {
return fmt.Errorf("tx receipt not found on chain %s, %d", err.Error(), chain.ChainId)
}

for _, chainParams := range chainParams {
if chainParams.ChainId == chainID {
Expand All @@ -135,32 +143,31 @@ func DebugCmd() *cobra.Command {
return fmt.Errorf("missing chain params for chain %d", chainID)
}
evmChainParams.ZetaTokenContractAddress = chainParams.ZetaTokenContractAddress
if strings.EqualFold(tx.To().Hex(), chainParams.ConnectorContractAddress) {
if strings.EqualFold(tx.To, chainParams.ConnectorContractAddress) {
coinType = common.CoinType_Zeta
} else if strings.EqualFold(tx.To().Hex(), chainParams.Erc20CustodyContractAddress) {
} else if strings.EqualFold(tx.To, chainParams.Erc20CustodyContractAddress) {
coinType = common.CoinType_ERC20
} else if strings.EqualFold(tx.To().Hex(), tssEthAddress) {
} else if strings.EqualFold(tx.To, tssEthAddress) {
coinType = common.CoinType_Gas
}

}
}

switch coinType {
case common.CoinType_Zeta:
ballotIdentifier, err = ob.CheckReceiptForCoinTypeZeta(txHash, false)
ballotIdentifier, err = ob.CheckAndVoteInboundTokenZeta(tx, receipt, false)
if err != nil {
return err
}

case common.CoinType_ERC20:
ballotIdentifier, err = ob.CheckReceiptForCoinTypeERC20(txHash, false)
ballotIdentifier, err = ob.CheckAndVoteInboundTokenERC20(tx, receipt, false)
if err != nil {
return err
}

case common.CoinType_Gas:
ballotIdentifier, err = ob.CheckReceiptForCoinTypeGas(txHash, false)
ballotIdentifier, err = ob.CheckAndVoteInboundTokenGas(tx, receipt, false)
if err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/zetaclientd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"syscall"
"time"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/libp2p/go-libp2p/core"
maddr "github.com/multiformats/go-multiaddr"
"github.com/pkg/errors"
Expand Down Expand Up @@ -209,6 +210,9 @@ func start(_ *cobra.Command, _ []string) error {

// Defensive check: Make sure the tss address is set to the current TSS address and not the newly generated one
tss.CurrentPubkey = currentTss.TssPubkey
if tss.EVMAddress() == (ethcommon.Address{}) || tss.BTCAddress() == "" {
startLogger.Error().Msg("TSS address is not set in zetacore")
}
startLogger.Info().Msgf("Current TSS address \n ETH : %s \n BTC : %s \n PubKey : %s ", tss.EVMAddress(), tss.BTCAddress(), tss.CurrentPubkey)
if len(appContext.ZetaCoreContext().GetEnabledChains()) == 0 {
startLogger.Error().Msgf("No chains enabled in updated config %s ", cfg.String())
Expand Down
11 changes: 11 additions & 0 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func CreateSignerMap(
loggers.Std.Error().Msgf("ChainParam not found for chain %s", evmConfig.Chain.String())
continue
}
if !evmChainParams.IsSupported {
continue
}
mpiAddress := ethcommon.HexToAddress(evmChainParams.ConnectorContractAddress)
erc20CustodyAddress := ethcommon.HexToAddress(evmChainParams.Erc20CustodyContractAddress)
signer, err := evm.NewEVMSigner(evmConfig.Chain, evmConfig.Endpoint, tss, config.GetConnectorABI(), config.GetERC20CustodyABI(), mpiAddress, erc20CustodyAddress, loggers, ts)
Expand Down Expand Up @@ -104,6 +107,14 @@ func CreateChainClientMap(
if evmConfig.Chain.IsZetaChain() {
continue
}
evmChainParams, found := appContext.ZetaCoreContext().GetEVMChainParams(evmConfig.Chain.ChainId)
if !found {
loggers.Std.Error().Msgf("ChainParam not found for chain %s", evmConfig.Chain.String())
continue
}
if !evmChainParams.IsSupported {
continue
}
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())
Expand Down
3 changes: 0 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ comment:

flags:
zetacore:
carryforward: true
paths:
- "x/"
zetaclient:
carryforward: true
paths:
- "zetaclient/"
common:
carryforward: true
paths:
- "common/"

Expand Down
4 changes: 4 additions & 0 deletions common/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ package common
const (
// DefaultGasPriceMultiplier is the default gas price multiplier for outbond txs
DefaultGasPriceMultiplier = 2

// DonationMessage is the message for donation transactions
// Transaction sent to the TSS or ERC20 Custody address containing this message are considered as a donation
DonationMessage = "I am rich!"
)
42 changes: 1 addition & 41 deletions contrib/docker-scripts/download_binaries.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import re
import requests
import os
import json
import logging
import sys
import shutil


# Logger class for easier logging setup
class Logger:
Expand All @@ -22,51 +19,14 @@ def __init__(self):
# Initialize logger instance
logger = Logger()

# Define the path where upgrades will be stored, using an environment variable for the base path
upgrade_path = f'{os.environ["DAEMON_HOME"]}/cosmovisor/upgrades/'


# Function to find the latest patch version of a binary based on major and optional minor version
def find_latest_patch_version(major_version, minor_version=None):
# Define a regex pattern to match version directories
pattern = re.compile(
f"v{major_version}\.{minor_version}\.(\d+)" if minor_version else f"v{major_version}\.0\.(\d+)")
# List directories that match the version pattern
versions = [folder for folder in os.listdir(upgrade_path) if pattern.match(folder)]
if versions:
try:
# Find the maximum version, assuming it's the latest patch
latest_patch_version = max(versions)
# Return the path to the binary of the latest patch version
return os.path.join(upgrade_path, latest_patch_version, "bin", "zetacored")
except ValueError as e:
logger.log.error(f"Error finding latest patch version: {e}")
return None
return None


# Function to replace an old binary with a new one
def replace_binary(source, target):
try:
# Log deletion of old binary
if os.path.exists(target):
logger.log.info(f"Deleted old binary: {target}")
os.remove(target)
# Copy the new binary to the target location
shutil.copy(source, target)
logger.log.info(f"Binary replaced: {target} -> {source}")
except Exception as e:
logger.log.error(f"Error replacing binary: {e}")


# Parse JSON from an environment variable to get binary download information
info = json.loads(os.environ["DOWNLOAD_BINARIES"])

try:
# Iterate over binaries to download
for binary in info["binaries"]:
download_link = binary["download_url"]
binary_location = binary["binary_location"]
binary_location = f'{os.environ["DAEMON_HOME"]}/{binary["binary_location"]}'
binary_directory = os.path.dirname(binary_location)
# Log download link
logger.log.info(f"DOWNLOAD LINK: {download_link}")
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_donation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package e2etests
import (
"math/big"

"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/zetaclient/evm"
)

// TestDonationEther tests donation of ether to the tss address
Expand All @@ -19,7 +19,7 @@ func TestDonationEther(r *runner.E2ERunner, args []string) {
panic("Invalid amount specified for TestDonationEther.")
}

txDonation, err := r.SendEther(r.TSSAddress, amount, []byte(evm.DonationMessage))
txDonation, err := r.SendEther(r.TSSAddress, amount, []byte(common.DonationMessage))
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/runner/bitcoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (runner *E2ERunner) DepositBTC(testHeader bool) {
0.11,
utxos[4:5],
btc,
[]byte(zetabitcoin.DonationMessage),
[]byte(common.DonationMessage),
runner.BTCDeployerAddress,
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions e2e/runner/setup_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
zetaeth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zeta.eth.sol"
zetaconnectoreth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.eth.sol"
"github.com/zeta-chain/zetacore/common"
"github.com/zeta-chain/zetacore/e2e/config"
"github.com/zeta-chain/zetacore/e2e/contracts/erc20"
"github.com/zeta-chain/zetacore/e2e/contracts/testdapp"
"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/zetaclient/evm"
)

const (
Expand Down Expand Up @@ -62,7 +62,7 @@ func (runner *E2ERunner) SetupEVM(contractsDeployed bool) {

// donate to the TSS address to avoid account errors because deploying gas token ZRC20 will automatically mint
// gas token on ZetaChain to initialize the pool
txDonation, err := runner.SendEther(runner.TSSAddress, big.NewInt(101000000000000000), []byte(evm.DonationMessage))
txDonation, err := runner.SendEther(runner.TSSAddress, big.NewInt(101000000000000000), []byte(common.DonationMessage))
if err != nil {
panic(err)
}
Expand Down
34 changes: 23 additions & 11 deletions testutil/network/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strconv"
"testing"

authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -77,17 +79,6 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage
GranteePubkeys: observerList,
BlockNumber: 5,
}
// set admin policy with first validator as admin
observerGenesis.Params.AdminPolicy = []*observertypes.Admin_Policy{
{
PolicyType: observertypes.Policy_Type_group1,
Address: "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax",
},
{
PolicyType: observertypes.Policy_Type_group2,
Address: "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax",
},
}
observerGenesis.CrosschainFlags = &observertypes.CrosschainFlags{
IsInboundEnabled: true,
IsOutboundEnabled: true,
Expand All @@ -96,10 +87,31 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage
observerGenesisBz, err := codec.MarshalJSON(&observerGenesis)
require.NoError(t, err)

// authority genesis state
var authorityGenesis authoritytypes.GenesisState
require.NoError(t, codec.UnmarshalJSON(genesisState[authoritytypes.ModuleName], &authorityGenesis))
policies := authoritytypes.Policies{
Items: []*authoritytypes.Policy{
{
PolicyType: authoritytypes.PolicyType_groupEmergency,
Address: "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax",
},
{
PolicyType: authoritytypes.PolicyType_groupAdmin,
Address: "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax",
},
},
}
authorityGenesis.Policies = policies
require.NoError(t, authorityGenesis.Validate())
authorityGenesisBz, err := codec.MarshalJSON(&authorityGenesis)
require.NoError(t, err)

genesisState[types.ModuleName] = crossChainGenesisBz
genesisState[stakingtypes.ModuleName] = stakingGenesisStateBz
genesisState[observertypes.ModuleName] = observerGenesisBz
genesisState[evmtypes.ModuleName] = evmGenesisBz
genesisState[authoritytypes.ModuleName] = authorityGenesisBz
}

func AddObserverData(t *testing.T, n int, genesisState map[string]json.RawMessage, codec codec.Codec, ballots []*observertypes.Ballot) *observertypes.GenesisState {
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.