Skip to content

Commit

Permalink
chore: backport zetaclient v19.1.0 changes (#2721)
Browse files Browse the repository at this point in the history
* feat: parse inscription like witness data (#2524)

* parse inscription like witness data

* more comment

* remove unused code

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* pull origin

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Dmitry S <[email protected]>

* review feedbacks

* update review feedbacks

* update make generate

* fix linter

* remove over flow

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/tokenizer.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/tokenizer.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/tokenizer.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/tokenizer.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* update review feedback

* update code commnet

* update comment

* more comments

* Update changelog.md

---------

Co-authored-by: Dmitry S <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

fix version

* feat: detect memo in btc txn from OP_RETURN and inscription (#2533)

* parse inscription like witness data

* more comment

* remove unused code

* parse inscription

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* pull origin

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Dmitry S <[email protected]>

* review feedbacks

* update review feedbacks

* add mainnet txn

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* parse inscription like witness data

* more comment

* remove unused code

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: Dmitry S <[email protected]>

* Update zetaclient/chains/bitcoin/tx_script.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* pull origin

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Dmitry S <[email protected]>

* review feedbacks

* update review feedbacks

* update make generate

* fix linter

* remove over flow

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/tokenizer.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/tokenizer.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/tokenizer.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/tokenizer.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* update review feedback

* update code commnet

* update comment

* more comments

* Update changelog.md

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* Update zetaclient/chains/bitcoin/observer/inbound.go

Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* clean up

* format code

---------

Co-authored-by: Dmitry S <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>

* refactor(zetaclient)!: improve AppContext (#2568)

* Implement chain registry

* Rewrite test-cases for AppContext

* Drop `supplychecker`

* Refactor app ctx Update worker

* Refactor orchestrator

* Refactor observer&signer; DROP postBlockHeaders

* Fix test cases [1]

* Update changelog

* Allow Zeta Chain in appContext; address PR comments [1]

* Fix app context update

* Check for `chain.IsZeta()`

* Add AppContext.FilterChains

* Fix test cases [2]

* Fix test cases [3]

* Address PR comments [1]

* Address PR comments [2]

* Add tests for `slices`

* Fix e2e tests [1]

* Fix e2e tests [2]

* Resolve conflicts, converge codebase between PRs

* Add lodash; remove slices pkg

* Address PR comments

* Minor logging fix

* Address PR comments

tmp

* feat(zetaclient): add generic rpc metrics (#2597)

* feat(zetaclient): add generic rpc metrics

* feedback

* changelog

* fmt

* fix(zetaclient): use name in pending tx metric (#2642)

* feat(pkg): add `ticker` package (#2617)

* Add `pkg/ticker`

* Sample ticker usage in evm observer

* Change naming

* Address PR comments

* Address PR comments

* feat(zetaclient)!: Add support for EIP-1559 gas fees (#2634)

* Add Gas struct

* Add EIP-1559 fees

* Update changelog

* Add test cases for legacy vs dynamicFee txs

* Fix typo; Add E2E coverage

* Address PR comments

* Address PR comments

* Use gasFeeCap formula

* Revert "Use gasFeeCap formula"

This reverts commit 2260925.

* Address PR comments

* Fix e2e upgrade tests

* fix: adjust evm outbound tracker reporter to avoid submitting invalid hashes (#2628)

* refactor and fix evm outbound tracker reporter to avoid invalid hashes; print log when outbound tracker is full of invalid hashes

* add changelog entry

* used predefined log fields

* remove repeated fields information from log message; Devops team would configure Datadog to show the fields

* remove redundant fields in log message; unified logs

* remove pending transaction map from observer; the outbound tracker reporter will no longer report pending hash

* use bg.Work() to launch outbound tracker reporter goroutines

* bring the checking EnsureNoTrackers() back

* add more rationale to EVM outbound tracker submission

* sync observer and signers without wait on startup

* try fixing tss migration E2E failure by increase timeout

* feat: Solana relayer (fee payer) key importer, encryption and decryption (#2673)

* configure observer relayer key for Solana; remove hardcoded solana test key from zetaclient code

* implementation of relayer key importer, encryption and decryption

* integrate relayer key into E2E and Solana signer

* add relayer_key_balance metrics and unit tests

* use TrimSpace to trim password

* add changelog entry

* use relayer account array in E2E config; a few renaming; add private key validation when importing

* fix linter

* remove GetNetworkName method for simplification

* added PromptPassword method to prompt single password

* use network name as map index to store relayer key passwords

* moved relayer passwords to chain registry

* airdrop SOL token only if solana local node is available

---------

Co-authored-by: Lucas Bertrand <[email protected]>

* ci: Set Docker Workflow to use Go 1.22 (#2722)

* Set go 1.22.2

* Set go 1.22.2

* Set go 1.22

* Set go 1.22

* Refactor contrib/rpc and contrib/docker-scripts to use snapshots API (#2724)

Co-authored-by: Julian Rubino <[email protected]>

---------

Co-authored-by: dev-bitSmiley <[email protected]>
Co-authored-by: Dmitry S <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Francisco de Borja Aranda Castillejo <[email protected]>
Co-authored-by: Charlie Chen <[email protected]>
Co-authored-by: Lucas Bertrand <[email protected]>
Co-authored-by: Charlie <[email protected]>
Co-authored-by: Julian Rubino <[email protected]>
Co-authored-by: Julian Rubino <[email protected]>
  • Loading branch information
10 people authored Aug 16, 2024
1 parent 43a78ef commit 9d6d0ec
Show file tree
Hide file tree
Showing 126 changed files with 5,616 additions and 3,324 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build Stage
FROM golang:1.20-alpine3.18 AS builder
FROM golang:1.22-alpine3.18 AS builder

ENV GOPATH /go
ENV GOOS=linux
Expand Down
13 changes: 11 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# CHANGELOG

## Unreleased
## v19.1.0

* [2524](https://github.com/zeta-chain/node/pull/2524) - add inscription envolop parsing
* [2533](https://github.com/zeta-chain/node/pull/2533) - parse memo from both OP_RETURN and inscription
* [2568](https://github.com/zeta-chain/node/pull/2568) - improve AppContext by converging chains, chainParams, enabledChains, and additionalChains into a single zctx.Chain
* [2597](https://github.com/zeta-chain/node/pull/2597) - Add generic rpc metrics to zetaclient
* [2634](https://github.com/zeta-chain/node/pull/2634) - add support for EIP-1559 gas fees
* [2628](https://github.com/zeta-chain/node/pull/2628) - avoid submitting invalid hashes to outbound tracker
* [2673](https://github.com/zeta-chain/node/pull/2673) - add relayer key importer, encryption and decryption


## v19.0.1

Expand Down Expand Up @@ -592,4 +601,4 @@ Getting the correct TSS address for Bitcoin now requires proviidng the Bitcoin c
### CI

* [1218](https://github.com/zeta-chain/node/pull/1218) - cross-compile release binaries and simplify PR testings
* [1302](https://github.com/zeta-chain/node/pull/1302) - add mainnet builds to goreleaser
* [1302](https://github.com/zeta-chain/node/pull/1302) - add mainnet builds to goreleaser
22 changes: 0 additions & 22 deletions cmd/zetaclientd-supervisor/lib.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bufio"
"context"
"encoding/json"
"errors"
Expand All @@ -10,7 +9,6 @@ import (
"os"
"path"
"runtime"
"strings"
"sync"
"syscall"
"time"
Expand Down Expand Up @@ -383,23 +381,3 @@ func (s *zetaclientdSupervisor) downloadZetaclientd(ctx context.Context, plan *u
}
return nil
}

func promptPasswords() (string, string, error) {
reader := bufio.NewReader(os.Stdin)
fmt.Print("HotKey Password: ")
hotKeyPass, err := reader.ReadString('\n')
if err != nil {
return "", "", err
}
fmt.Print("TSS Password: ")
tssKeyPass, err := reader.ReadString('\n')
if err != nil {
return "", "", err
}

//trim delimiters
hotKeyPass = strings.TrimSuffix(hotKeyPass, "\n")
tssKeyPass = strings.TrimSuffix(tssKeyPass, "\n")

return hotKeyPass, tssKeyPass, err
}
8 changes: 6 additions & 2 deletions cmd/zetaclientd-supervisor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import (
"os"
"os/exec"
"os/signal"
"strings"
"syscall"
"time"

"golang.org/x/sync/errgroup"

"github.com/zeta-chain/zetacore/app"
zetaos "github.com/zeta-chain/zetacore/pkg/os"
"github.com/zeta-chain/zetacore/zetaclient/config"
)

Expand All @@ -36,7 +38,9 @@ func main() {
shutdownChan := make(chan os.Signal, 1)
signal.Notify(shutdownChan, syscall.SIGINT, syscall.SIGTERM)

hotkeyPassword, tssPassword, err := promptPasswords()
// prompt for all necessary passwords
titles := []string{"HotKey", "TSS", "Solana Relayer Key"}
passwords, err := zetaos.PromptPasswords(titles)
if err != nil {
logger.Error().Err(err).Msg("unable to get passwords")
os.Exit(1)
Expand Down Expand Up @@ -65,7 +69,7 @@ func main() {
cmd.Stderr = os.Stderr
// must reset the passwordInputBuffer every iteration because reads are stateful (seek to end)
passwordInputBuffer := bytes.Buffer{}
passwordInputBuffer.Write([]byte(hotkeyPassword + "\n" + tssPassword + "\n"))
passwordInputBuffer.Write([]byte(strings.Join(passwords, "\n") + "\n"))
cmd.Stdin = &passwordInputBuffer

eg, ctx := errgroup.WithContext(ctx)
Expand Down
93 changes: 46 additions & 47 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package main
import (
"context"
"fmt"
"os"
"strconv"
"strings"

"cosmossdk.io/errors"
"github.com/btcsuite/btcd/rpcclient"
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
Expand All @@ -14,10 +16,8 @@ import (
"github.com/rs/zerolog"
"github.com/spf13/cobra"

"github.com/zeta-chain/zetacore/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
"github.com/zeta-chain/zetacore/testutil/sample"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer"
evmobserver "github.com/zeta-chain/zetacore/zetaclient/chains/evm/observer"
"github.com/zeta-chain/zetacore/zetaclient/config"
Expand All @@ -35,11 +35,14 @@ type debugArguments struct {
}

func init() {
RootCmd.AddCommand(DebugCmd())
DebugCmd().Flags().
StringVar(&debugArgs.zetaCoreHome, "core-home", "/Users/tanmay/.zetacored", "peer address, e.g. /dns/tss1/tcp/6668/ipfs/16Uiu2HAmACG5DtqmQsHtXg4G2sLS65ttv84e7MrL4kapkjfmhxAp")
DebugCmd().Flags().StringVar(&debugArgs.zetaNode, "node", "46.4.15.110", "public ip address")
DebugCmd().Flags().StringVar(&debugArgs.zetaChainID, "chain-id", "athens_7001-1", "pre-params file path")
defaultHomeDir := os.ExpandEnv("$HOME/.zetacored")

cmd := DebugCmd()
cmd.Flags().StringVar(&debugArgs.zetaCoreHome, "core-home", defaultHomeDir, "zetacore home directory")
cmd.Flags().StringVar(&debugArgs.zetaNode, "node", "46.4.15.110", "public ip address")
cmd.Flags().StringVar(&debugArgs.zetaChainID, "chain-id", "athens_7001-1", "pre-params file path")

RootCmd.AddCommand(cmd)
}

func DebugCmd() *cobra.Command {
Expand All @@ -54,20 +57,16 @@ func debugCmd(_ *cobra.Command, args []string) error {
cobra.ExactArgs(2)
cfg, err := config.Load(debugArgs.zetaCoreHome)
if err != nil {
return err
return errors.Wrap(err, "failed to load config")
}

appContext := zctx.New(cfg, zerolog.Nop())
ctx := zctx.WithAppContext(context.Background(), appContext)
inboundHash := args[0]

chainID, err := strconv.ParseInt(args[1], 10, 64)
if err != nil {
return err
return errors.Wrap(err, "failed to parse chain id")
}

inboundHash := args[0]
var ballotIdentifier string

// create a new zetacore client
client, err := zetacore.NewClient(
&keys.Keys{OperatorAddress: sdk.MustAccAddressFromBech32(sample.AccAddress())},
Expand All @@ -80,21 +79,30 @@ func debugCmd(_ *cobra.Command, args []string) error {
if err != nil {
return err
}
chainParams, err := client.GetChainParams(ctx)
if err != nil {
return err

appContext := zctx.New(cfg, nil, zerolog.Nop())
ctx := zctx.WithAppContext(context.Background(), appContext)

if err := client.UpdateAppContext(ctx, appContext, zerolog.Nop()); err != nil {
return errors.Wrap(err, "failed to update app context")
}

var ballotIdentifier string

tssEthAddress, err := client.GetEVMTSSAddress(ctx)
if err != nil {
return err
}
chain, found := chains.GetChainFromChainID(chainID, appContext.GetAdditionalChains())
if !found {
return fmt.Errorf("invalid chain id")

chain, err := appContext.GetChain(chainID)
if err != nil {
return err
}

chainProto := chain.RawChain()

// get ballot identifier according to the chain type
if chains.IsEVMChain(chain.ChainId, appContext.GetAdditionalChains()) {
if chain.IsEVM() {
evmObserver := evmobserver.Observer{}
evmObserver.WithZetacoreClient(client)
var ethRPC *ethrpc.EthRPC
Expand All @@ -109,43 +117,34 @@ func debugCmd(_ *cobra.Command, args []string) error {
}
evmObserver.WithEvmClient(client)
evmObserver.WithEvmJSONRPC(ethRPC)
evmObserver.WithChain(chain)
evmObserver.WithChain(*chainProto)
}
}
hash := ethcommon.HexToHash(inboundHash)
tx, isPending, err := evmObserver.TransactionByHash(inboundHash)
if err != nil {
return fmt.Errorf("tx not found on chain %s , %d", err.Error(), chain.ChainId)
return fmt.Errorf("tx not found on chain %s, %d", err.Error(), chain.ID())
}

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)
return fmt.Errorf("tx receipt not found on chain %s, %d", err.Error(), chain.ID())
}

for _, chainParams := range chainParams {
if chainParams.ChainId == chainID {
evmObserver.SetChainParams(observertypes.ChainParams{
ChainId: chainID,
ConnectorContractAddress: chainParams.ConnectorContractAddress,
ZetaTokenContractAddress: chainParams.ZetaTokenContractAddress,
Erc20CustodyContractAddress: chainParams.Erc20CustodyContractAddress,
})
evmChainParams, found := appContext.GetEVMChainParams(chainID)
if !found {
return fmt.Errorf("missing chain params for chain %d", chainID)
}
evmChainParams.ZetaTokenContractAddress = chainParams.ZetaTokenContractAddress
if strings.EqualFold(tx.To, chainParams.ConnectorContractAddress) {
coinType = coin.CoinType_Zeta
} else if strings.EqualFold(tx.To, chainParams.Erc20CustodyContractAddress) {
coinType = coin.CoinType_ERC20
} else if strings.EqualFold(tx.To, tssEthAddress) {
coinType = coin.CoinType_Gas
}
}
params := chain.Params()

evmObserver.SetChainParams(*params)

if strings.EqualFold(tx.To, params.ConnectorContractAddress) {
coinType = coin.CoinType_Zeta
} else if strings.EqualFold(tx.To, params.Erc20CustodyContractAddress) {
coinType = coin.CoinType_ERC20
} else if strings.EqualFold(tx.To, tssEthAddress) {
coinType = coin.CoinType_Gas
}

switch coinType {
Expand All @@ -170,10 +169,10 @@ func debugCmd(_ *cobra.Command, args []string) error {
fmt.Println("CoinType not detected")
}
fmt.Println("CoinType : ", coinType)
} else if chains.IsBitcoinChain(chain.ChainId, appContext.GetAdditionalChains()) {
} else if chain.IsUTXO() {
btcObserver := btcobserver.Observer{}
btcObserver.WithZetacoreClient(client)
btcObserver.WithChain(chain)
btcObserver.WithChain(*chainProto)
connCfg := &rpcclient.ConnConfig{
Host: cfg.BitcoinConfig.RPCHost,
User: cfg.BitcoinConfig.RPCUsername,
Expand Down
36 changes: 8 additions & 28 deletions cmd/zetaclientd/encrypt_tss.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package main

import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"crypto/sha256"
"encoding/json"
"errors"
"io"
"os"
"path/filepath"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/zeta-chain/zetacore/pkg/crypto"
)

var encTssCmd = &cobra.Command{
Expand All @@ -25,9 +22,10 @@ func init() {
RootCmd.AddCommand(encTssCmd)
}

// EncryptTSSFile encrypts the given file with the given secret key
func EncryptTSSFile(_ *cobra.Command, args []string) error {
filePath := args[0]
secretKey := args[1]
password := args[1]

filePath = filepath.Clean(filePath)
data, err := os.ReadFile(filePath)
Expand All @@ -39,29 +37,11 @@ func EncryptTSSFile(_ *cobra.Command, args []string) error {
return errors.New("file does not contain valid json, may already be encrypted")
}

block, err := aes.NewCipher(getFragmentSeed(secretKey))
if err != nil {
return err
}

// Creating GCM mode
gcm, err := cipher.NewGCM(block)
// encrypt the data
cipherText, err := crypto.EncryptAES256GCM(data, password)
if err != nil {
return err
}
// Generating random nonce
nonce := make([]byte, gcm.NonceSize())
if _, err := io.ReadFull(rand.Reader, nonce); err != nil {
return err
return errors.Wrap(err, "failed to encrypt data")
}

cipherText := gcm.Seal(nonce, nonce, data, nil)
return os.WriteFile(filePath, cipherText, 0o600)
}

func getFragmentSeed(password string) []byte {
h := sha256.New()
h.Write([]byte(password))
seed := h.Sum(nil)
return seed
}
Loading

0 comments on commit 9d6d0ec

Please sign in to comment.