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: integrated base Observer structure into existing EVM/BTC observers #2359

Merged
merged 32 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
61f7f02
save local new files to remote
ws4charlie Jun 4, 2024
695caa7
initiated base observer
ws4charlie Jun 4, 2024
1500138
move base to chains folder
ws4charlie Jun 4, 2024
2cdff62
moved logger to base package
ws4charlie Jun 5, 2024
d2d19f1
added base signer and logger
ws4charlie Jun 6, 2024
7b358d8
Merge branch 'develop' of https://github.com/zeta-chain/node into ref…
ws4charlie Jun 6, 2024
9da97f9
Merge branch 'develop' into refactor-base-signer-observer
ws4charlie Jun 17, 2024
f6784ee
added changelog entry
ws4charlie Jun 17, 2024
bad53bb
Merge branch 'develop' into refactor-base-signer-observer
ws4charlie Jun 17, 2024
13e6251
integrated base signer into evm/bitcoin; integrated base observer int…
ws4charlie Jun 19, 2024
b51ab8a
integrated base observer to evm and bitcoin chain
ws4charlie Jun 20, 2024
5edd452
Merge branch 'develop' of https://github.com/zeta-chain/node into ref…
ws4charlie Jun 20, 2024
7d1650b
added changelog entry
ws4charlie Jun 20, 2024
0cb55e1
cherry pick base Signer structure integration
ws4charlie Jun 20, 2024
2b4b01c
updated PR number in changelog
ws4charlie Jun 20, 2024
d882b05
updated PR number in changelog
ws4charlie Jun 20, 2024
921ca67
Merge branch 'develop' into refactor-integrate-base-signer
ws4charlie Jun 20, 2024
cdbf149
cherry picked the integration of base Observer
ws4charlie Jun 20, 2024
625e633
moved pure RPC methods to rpc package
ws4charlie Jun 20, 2024
df1dcbe
Merge branch 'develop' of https://github.com/zeta-chain/node into ref…
ws4charlie Jun 21, 2024
45d1a9c
moved Mutex to base Observer struct
ws4charlie Jun 21, 2024
642e54e
type check on cached block, header
ws4charlie Jun 21, 2024
72061f3
Merge branch 'develop' into refactor-integrate-base-observer
ws4charlie Jun 21, 2024
0ee1e60
update changelog PR number and added unit test for Stop() method
ws4charlie Jun 21, 2024
e6111eb
Merge branch 'develop' into refactor-integrate-base-observer
ws4charlie Jun 24, 2024
0652bf4
replace magic numbers with constants
ws4charlie Jun 24, 2024
f5914d8
updated method name in logging
ws4charlie Jun 24, 2024
44e99fa
Merge branch 'develop' of https://github.com/zeta-chain/node into ref…
ws4charlie Jun 24, 2024
a96898d
Move sqlite-mem db to testutils
swift1337 Jun 25, 2024
956f681
Merge branch 'develop' into refactor-integrate-base-observer
ws4charlie Jun 25, 2024
ab0c960
Add base signer's Lock & Unlock
swift1337 Jun 25, 2024
5925d10
Merge branch 'refactor-integrate-base-observer' of github.com:zeta-ch…
swift1337 Jun 25, 2024
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* [2340](https://github.com/zeta-chain/node/pull/2340) - add ValidateInbound method for cctx orchestrator
* [2344](https://github.com/zeta-chain/node/pull/2344) - group common data of EVM/Bitcoin signer and observer using base structs
* [2357](https://github.com/zeta-chain/node/pull/2357) - integrate base Signer structure into EVM/Bitcoin Signer
* [2359](https://github.com/zeta-chain/node/pull/2359) - integrate base Observer structure into EVM/Bitcoin Observer
swift1337 marked this conversation as resolved.
Show resolved Hide resolved

### Tests

Expand Down
9 changes: 2 additions & 7 deletions cmd/zetaclientd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"strconv"
"strings"
"sync"

"github.com/btcsuite/btcd/rpcclient"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -86,9 +85,7 @@ func DebugCmd() *cobra.Command {

// get ballot identifier according to the chain type
if chains.IsEVMChain(chain.ChainId) {
evmObserver := evmobserver.Observer{
Mu: &sync.Mutex{},
}
evmObserver := evmobserver.Observer{}
evmObserver.WithZetacoreClient(client)
var ethRPC *ethrpc.EthRPC
var client *ethclient.Client
Expand Down Expand Up @@ -164,9 +161,7 @@ func DebugCmd() *cobra.Command {
}
fmt.Println("CoinType : ", coinType)
} else if chains.IsBitcoinChain(chain.ChainId) {
btcObserver := btcobserver.Observer{
Mu: &sync.Mutex{},
}
btcObserver := btcobserver.Observer{}
btcObserver.WithZetacoreClient(client)
btcObserver.WithChain(*chains.GetChainFromChainID(chainID))
connCfg := &rpcclient.ConnConfig{
Expand Down
60 changes: 53 additions & 7 deletions cmd/zetaclientd/utils.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package main

import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"

"github.com/zeta-chain/zetacore/zetaclient/authz"
"github.com/zeta-chain/zetacore/zetaclient/chains/base"
btcobserver "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/observer"
btcrpc "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/rpc"
btcsigner "github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin/signer"
evmobserver "github.com/zeta-chain/zetacore/zetaclient/chains/evm/observer"
evmsigner "github.com/zeta-chain/zetacore/zetaclient/chains/evm/signer"
Expand Down Expand Up @@ -116,33 +120,75 @@ func CreateChainObserverMap(
logger base.Logger,
ts *metrics.TelemetryServer,
) (map[int64]interfaces.ChainObserver, error) {
zetacoreContext := appContext.ZetacoreContext()
observerMap := make(map[int64]interfaces.ChainObserver)
// EVM observers
for _, evmConfig := range appContext.Config().GetAllEVMConfigs() {
if evmConfig.Chain.IsZetaChain() {
continue
}
_, found := appContext.ZetacoreContext().GetEVMChainParams(evmConfig.Chain.ChainId)
chainParams, found := zetacoreContext.GetEVMChainParams(evmConfig.Chain.ChainId)
if !found {
logger.Std.Error().Msgf("ChainParam not found for chain %s", evmConfig.Chain.String())
continue
}
co, err := evmobserver.NewObserver(appContext, zetacoreClient, tss, dbpath, logger, evmConfig, ts)

// create EVM client
evmClient, err := ethclient.Dial(evmConfig.Endpoint)
if err != nil {
logger.Std.Error().Err(err).Msgf("error dailing endpoint %s", evmConfig.Endpoint)
continue
}

// create EVM chain observer
observer, err := evmobserver.NewObserver(
evmConfig,
evmClient,
*chainParams,
zetacoreContext,
zetacoreClient,
tss,
dbpath,
logger,
ts,
)
if err != nil {
logger.Std.Error().Err(err).Msgf("NewObserver error for evm chain %s", evmConfig.Chain.String())
continue
}
observerMap[evmConfig.Chain.ChainId] = co
observerMap[evmConfig.Chain.ChainId] = observer
}

// BTC observer
_, chainParams, found := zetacoreContext.GetBTCChainParams()
if !found {
return nil, fmt.Errorf("bitcoin chains params not found")
}

// create BTC chain observer
btcChain, btcConfig, enabled := appContext.GetBTCChainAndConfig()
if enabled {
co, err := btcobserver.NewObserver(appContext, btcChain, zetacoreClient, tss, dbpath, logger, btcConfig, ts)
btcClient, err := btcrpc.NewRPCClient(btcConfig)
if err != nil {
logger.Std.Error().Err(err).Msgf("NewObserver error for bitcoin chain %s", btcChain.String())

logger.Std.Error().Err(err).Msgf("error creating rpc client for bitcoin chain %s", btcChain.String())
} else {
observerMap[btcChain.ChainId] = co
// create BTC chain observer
observer, err := btcobserver.NewObserver(
btcChain,
btcClient,
*chainParams,
zetacoreContext,
zetacoreClient,
tss,
dbpath,
logger,
ts,
)
if err != nil {
logger.Std.Error().Err(err).Msgf("NewObserver error for bitcoin chain %s", btcChain.String())
} else {
observerMap[btcChain.ChainId] = observer
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions testutil/sample/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strconv"
"testing"

"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/cometbft/cometbft/crypto/secp256k1"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand Down Expand Up @@ -60,6 +61,11 @@ func Hash() ethcommon.Hash {
return EthAddress().Hash()
}

// BtcHash returns a sample btc hash
func BtcHash() chainhash.Hash {
return chainhash.Hash(Hash())
}

// PubKey returns a sample account PubKey
func PubKey(r *rand.Rand) cryptotypes.PubKey {
seed := []byte(strconv.Itoa(r.Int()))
Expand Down
Loading
Loading