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

feat: zetaclient should be able to activate/deactivate chains at runtime #2411

Closed
wants to merge 24 commits into from

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented Jul 1, 2024

Description

  • Clean up code and simplified zetaclient initialization logics.
  • Simplified zetaclient side AppContext by consolidating [ZetacoreContext + AppContext] ==> AppContext. ZetacoreContext is removed.
  • Use separate go-routine to detect upgrade plan in zetacore.
  • Use separate go-routine to refresh zetaclient side AppContext.
  • Use separate go-routine to check enabled chains at runtime and activate/deactivate observers/signers dynamically.

Closes: 1904
Closes: 1397

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • New Features

    • Added functionality for activating and deactivating chains at runtime in the Zeta client.
    • Introduced tests for the AppContext functionality.
    • Added orchestrator methods for watching, updating, activating, and deactivating chains.
  • Bug Fixes

    • Updated method calls and logic for improved clarity and consistency.
  • Refactor

    • Replaced usage of logging libraries and updated method signatures in the debug and start commands for improved functionality.
    • Modified the Orchestrator struct with new fields and methods.
  • Tests

    • Updated code generation tool mockery to version v2.42.2 for various test utility packages.
    • Added tests for chain activation and deactivation functionalities.
  • Chores

    • Reorganized imports and adjusted logger initialization and compliance configuration loading in the start command.

Copy link
Contributor

coderabbitai bot commented Jul 1, 2024

Walkthrough

This update encompasses enhancements to the zetaclient application, including moving crosschain flags to the app context, enabling runtime activation/deactivation of chains, restructuring core functionalities, improving error handling, and updating dependencies. Additionally, several files see updates related to mockery tool version changes and unit tests are introduced for new functionalities. These improvements collectively bolster the application's robustness, flexibility, and maintainability.

Changes

File(s) Summary
changelog.md Updated functionality and features summary: crosschain flags moved to app context; chains activate/deactivate at runtime
cmd/zetaclientd/debug.go Replaced zerolog with clientcontext for appContext creation; updated method calls
cmd/zetaclientd/keygen_tss.go Renamed function to GenerateTSS, updated signature and error handling
cmd/zetaclientd/start.go Reorganized imports, updated logger, compliance config, metrics, authz client, app context, key generation
testutil/keeper/mocks/... Updated mockery version from v2.38.0 to v2.42.2
zetaclient/chains/base/* Updated log messages, method signatures, implementations for consistency and clarity
zetaclient/chains/bitcoin/observer/* Updated method calls and logic related to config and compliance packages
zetaclient/context/app_context_test.go Added tests for AppContext functionality in Zeta client context package
zetaclient/zetacore/client.go Added imports, modified client creation, key handling, chain parameters updates, and error management
zetaclient/orchestrator/orchestrator.go Major updates: new imports, fields, and methods for orchestrator; start/stop routines, updated functions
zetaclient/orchestrator/chain_activate.go Added functionality to watch, update, activate, deactivate chains
zetaclient/orchestrator/chain_activate_test.go Introduced tests for chain activation, deactivation, signers, observers, and various scenarios

Poem

Upon the Zeta chain we stand, with code so grand,  
Flags now in app context rest, activation put to test.  
Chains alive, they come and go, in runtime's gentle flow.  
Logs polished, methods gleam, a robust, seamless dream.  
With tests to keep us ever true, a stronger Zeta now ensues.  
Oh, the beauty of this code, in the rabbit's own abode!

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

gitguardian bot commented Jul 1, 2024

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
Once a secret has been leaked into a git repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@ws4charlie ws4charlie changed the title feat: orchestrator should be able to activate/deactivate chains at runtime feat: zetaclient should be able to activate/deactivate chains at runtime Jul 1, 2024
@ws4charlie ws4charlie marked this pull request as ready for review July 1, 2024 21:36
Copy link

codecov bot commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 65.59829% with 161 lines in your changes missing coverage. Please review.

Project coverage is 69.15%. Comparing base (f45a56b) to head (e063c2a).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2411      +/-   ##
===========================================
+ Coverage    69.05%   69.15%   +0.10%     
===========================================
  Files          308      309       +1     
  Lines        19192    19328     +136     
===========================================
+ Hits         13253    13367     +114     
- Misses        5264     5282      +18     
- Partials       675      679       +4     
Files Coverage Δ
zetaclient/chains/base/observer.go 89.74% <100.00%> (+0.06%) ⬆️
zetaclient/chains/base/signer.go 81.81% <ø> (ø)
zetaclient/compliance/compliance.go 29.72% <100.00%> (+16.39%) ⬆️
zetaclient/config/config.go 0.00% <ø> (ø)
zetaclient/config/config_chain.go 0.00% <ø> (ø)
zetaclient/zetacore/tx.go 56.84% <ø> (+3.12%) ⬆️
zetaclient/chains/bitcoin/observer/inbound.go 14.78% <0.00%> (ø)
zetaclient/chains/evm/observer/outbound.go 59.16% <0.00%> (ø)
zetaclient/chains/evm/signer/signer.go 52.64% <50.00%> (+0.31%) ⬆️
zetaclient/chains/bitcoin/observer/observer.go 34.25% <0.00%> (-0.82%) ⬇️
... and 10 more

@lumtis
Copy link
Member

lumtis commented Jul 2, 2024

@coderabbitai can you please make a review of the change in zetaclient/** directory, independently of your config?

Copy link
Contributor

coderabbitai bot commented Jul 2, 2024

@lumtis: I've reviewed the changes in the zetaclient/** directory. The modifications in signer.go include the implementation of various methods for signing and broadcasting EVM transactions, such as SignOutbound, SignRevertTx, SignCancelTx, SignWithdrawTx, and SignCommandTx. Additionally, new methods for setting and getting addresses have been added. The corresponding unit tests in signer_test.go comprehensively cover these methods, ensuring their correctness.

The changes look well-implemented and the unit tests provide good coverage. If you have any specific concerns or areas you'd like me to focus on, please let me know!

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Find and display the contents of modified files within the zetaclient directory.
git diff --name-only HEAD~1 HEAD | grep '^zetaclient/' | xargs -I {} sh -c 'echo "\n\nFile: {}\n"; cat {}'

Length of output: 42737

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me there were some issues from recent merge for:

  • using NewAppContext instead of just New
  • Using pointer for config object in the source code

@lumtis
Copy link
Member

lumtis commented Jul 2, 2024

@lumtis: I've reviewed the changes in the zetaclient/** directory. The modifications in signer.go include the implementation of various methods for signing and broadcasting EVM transactions, such as SignOutbound, SignRevertTx, SignCancelTx, SignWithdrawTx, and SignCommandTx. Additionally, new methods for setting and getting addresses have been added. The corresponding unit tests in signer_test.go comprehensively cover these methods, ensuring their correctness.

The changes look well-implemented and the unit tests provide good coverage. If you have any specific concerns or areas you'd like me to focus on, please let me know!

Analysis chain
Scripts executed
Actions performed

@coderabbitai you don't have any review comments to provide to the files in zetaclient regarding code quality?

Copy link
Contributor

coderabbitai bot commented Jul 2, 2024

Tip

For best results, initiate chat on the files or code changes.

@lumtis: I've reviewed the changes in the zetaclient/chains/evm/signer directory for code quality. Here are my observations:

  1. Modification of getEVMRPC Function:

    • The function signature of getEVMRPC has been updated to accept a chainID parameter. This change improves the function by making the chain ID explicit, which enhances readability and maintainability.
    • The handling of the chainID within the function has been simplified by directly using the provided chainID instead of fetching it from the client, which is a good optimization.
  2. Updates in NewSigner Function:

    • The NewSigner function has been updated to pass the chain.ChainId to the getEVMRPC function. This change aligns with the updated getEVMRPC function and ensures consistency.
  3. Test Case Updates:

    • The test case for getEVMRPC has been updated to include the chainID parameter. This ensures that the tests are in sync with the new function signature and continue to validate the function's behavior correctly.

Overall, the changes are well-implemented and improve the code's clarity and efficiency. The updates to the test cases ensure that the modifications are thoroughly tested.

If you have any specific areas you would like me to focus on or further concerns, please let me know!

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Get the diffs of the files in the zetaclient directory for detailed analysis.
git diff HEAD~1 HEAD zetaclient/

Length of output: 2041

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (7)
zetaclient/config/types_test.go (1)

15-21: Ensure comprehensive testing of the Clone method.

The test for the Clone method is good, but consider adding more test cases to cover edge cases, such as:

  • Config with empty fields.
  • Config with maximum possible values.
  • Config with nested structures.
func Test_Clone_EmptyConfig(t *testing.T) {
	cfg := config.Config{}
	clone := cfg.Clone()
	require.Equal(t, cfg, clone)
}

func Test_Clone_MaxValues(t *testing.T) {
	// Add a config with maximum possible values
	cfg := config.Config{
		// populate fields with max values
	}
	clone := cfg.Clone()
	require.Equal(t, cfg, clone)
}
zetaclient/compliance/compliance_test.go (1)

26-26: Ensure comprehensive testing of compliance functions.

The tests for compliance functions are well-structured. Consider adding more test cases to cover edge cases, such as:

  • Empty compliance config.
  • Multiple restricted addresses.
  • Non-string address formats.
t.Run("should return false for empty compliance config", func(t *testing.T) {
	cfg.ComplianceConfig.RestrictedAddresses = []string{}
	LoadComplianceConfig(cfg)
	require.False(t, IsCctxRestricted(cctx))
})

t.Run("should return true for multiple restricted addresses", func(t *testing.T) {
	cfg.ComplianceConfig.RestrictedAddresses = []string{"address1", "address2", cctx.InboundParams.Sender}
	LoadComplianceConfig(cfg)
	require.True(t, IsCctxRestricted(cctx))
})

t.Run("should handle non-string address formats", func(t *testing.T) {
	cfg.ComplianceConfig.RestrictedAddresses = []string{"0x123", "0x456"}
	LoadComplianceConfig(cfg)
	require.False(t, IsCctxRestricted(cctx))
})

Also applies to: 31-31, 37-37, 42-42, 48-48

zetaclient/chains/bitcoin/observer/observer.go (5)

Line range hint 1-1: Add a package-level comment.

Consider adding a package-level comment to describe the purpose and functionality of the observer package.

// Package observer implements the Bitcoin chain observer.

Line range hint 1-1: Add import grouping.

Group imports into standard library, third-party, and local imports for better readability.

import (
	"bytes"
	"encoding/hex"
	"fmt"
	"math"
	"math/big"
	"sort"
	"time"

	"github.com/btcsuite/btcd/btcjson"
	"github.com/btcsuite/btcd/chaincfg"
	"github.com/btcsuite/btcd/chaincfg/chainhash"
	"github.com/btcsuite/btcd/wire"
	"github.com/btcsuite/btcutil"
	"github.com/pkg/errors"
	"github.com/rs/zerolog"

	"github.com/zeta-chain/zetacore/pkg/chains"
	"github.com/zeta-chain/zetacore/pkg/proofs"
	observertypes "github.com/zeta-chain/zetacore/x/observer/types"
	"github.com/zeta-chain/zetacore/zetaclient/chains/base"
	"github.com/zeta-chain/zetacore/zetaclient/chains/bitcoin"
	"github.com/zeta-chain/zetacore/zetaclient/chains/interfaces"
	"github.com/zeta-chain/zetacore/zetaclient/context"
	"github.com/zeta-chain/zetacore/zetaclient/metrics"
	clienttypes "github.com/zeta-chain/zetacore/zetaclient/types"
)

Line range hint 1-1: Add documentation for constants.

Consider adding comments to describe the purpose of each constant.

const (
	// btcBlocksPerDay represents Bitcoin blocks per days for LRU block cache size
	btcBlocksPerDay = 144

	// RegnetStartBlock is the hardcoded start block for regnet
	RegnetStartBlock = 100

	// BigValueSats contains the threshold to determine a big value in Bitcoin represents 2 BTC
	BigValueSats = 200000000

	// BigValueConfirmationCount represents the number of confirmation necessary for bigger values: 6 confirmations
	BigValueConfirmationCount = 6
)

Line range hint 1-1: Add documentation for Logger struct.

Consider adding comments to describe the purpose of each field in the Logger struct.

// Logger contains list of loggers used by Bitcoin chain observer
type Logger struct {
	// base.Logger contains a list of base observer loggers
	base.ObserverLogger

	// UTXOs is the logger for UTXOs management
	UTXOs zerolog.Logger
}

Line range hint 1-1: Add documentation for Observer struct.

Consider adding comments to describe the purpose of each field in the Observer struct.

// Observer is the Bitcoin chain observer
type Observer struct {
	// base.Observer implements the base chain observer
	base.Observer

	// netParams contains the Bitcoin network parameters
	netParams *chaincfg.Params

	// btcClient is the Bitcoin RPC client that interacts with the Bitcoin node
	btcClient interfaces.BTCRPCClient

	// pendingNonce is the outbound artificial pending nonce
	pendingNonce uint64

	// utxos contains the UTXOs owned by the TSS address
	utxos []btcjson.ListUnspentResult

	// includedTxHashes indexes included tx with tx hash
	includedTxHashes map[string]bool

	// includedTxResults indexes tx results with the outbound tx identifier
	includedTxResults map[string]*btcjson.GetTransactionResult

	// broadcastedTx indexes the outbound hash with the outbound tx identifier
	broadcastedTx map[string]string

	// logger contains the loggers used by the bitcoin observer
	logger Logger
}
Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a0527e9 and b52654f.

Files selected for processing (56)
  • changelog.md (2 hunks)
  • cmd/zetaclientd/debug.go (3 hunks)
  • cmd/zetaclientd/keygen_tss.go (4 hunks)
  • cmd/zetaclientd/start.go (10 hunks)
  • testutil/keeper/mocks/crosschain/account.go (1 hunks)
  • testutil/keeper/mocks/crosschain/authority.go (1 hunks)
  • testutil/keeper/mocks/crosschain/bank.go (1 hunks)
  • testutil/keeper/mocks/crosschain/fungible.go (1 hunks)
  • testutil/keeper/mocks/crosschain/ibccrosschain.go (1 hunks)
  • testutil/keeper/mocks/crosschain/lightclient.go (1 hunks)
  • testutil/keeper/mocks/crosschain/observer.go (1 hunks)
  • testutil/keeper/mocks/crosschain/staking.go (1 hunks)
  • testutil/keeper/mocks/emissions/account.go (1 hunks)
  • testutil/keeper/mocks/emissions/bank.go (1 hunks)
  • testutil/keeper/mocks/emissions/observer.go (1 hunks)
  • testutil/keeper/mocks/emissions/staking.go (1 hunks)
  • testutil/keeper/mocks/fungible/account.go (1 hunks)
  • testutil/keeper/mocks/fungible/authority.go (1 hunks)
  • testutil/keeper/mocks/fungible/bank.go (1 hunks)
  • testutil/keeper/mocks/fungible/evm.go (1 hunks)
  • testutil/keeper/mocks/fungible/observer.go (1 hunks)
  • testutil/keeper/mocks/ibccrosschain/crosschain.go (1 hunks)
  • testutil/keeper/mocks/ibccrosschain/transfer.go (1 hunks)
  • testutil/keeper/mocks/lightclient/authority.go (1 hunks)
  • testutil/keeper/mocks/observer/authority.go (1 hunks)
  • testutil/keeper/mocks/observer/lightclient.go (1 hunks)
  • testutil/keeper/mocks/observer/slashing.go (1 hunks)
  • testutil/keeper/mocks/observer/staking.go (1 hunks)
  • zetaclient/chains/base/observer.go (3 hunks)
  • zetaclient/chains/base/observer_test.go (4 hunks)
  • zetaclient/chains/base/signer.go (2 hunks)
  • zetaclient/chains/base/signer_test.go (2 hunks)
  • zetaclient/chains/bitcoin/observer/inbound.go (2 hunks)
  • zetaclient/chains/bitcoin/observer/observer.go (5 hunks)
  • zetaclient/chains/bitcoin/observer/observer_test.go (6 hunks)
  • zetaclient/chains/bitcoin/observer/outbound_test.go (1 hunks)
  • zetaclient/chains/bitcoin/rpc/rpc_live_test.go (1 hunks)
  • zetaclient/chains/evm/constant.go (1 hunks)
  • zetaclient/chains/evm/observer/inbound.go (4 hunks)
  • zetaclient/chains/evm/observer/inbound_test.go (23 hunks)
  • zetaclient/chains/evm/observer/observer.go (5 hunks)
  • zetaclient/chains/evm/observer/observer_test.go (12 hunks)
  • zetaclient/chains/evm/observer/outbound.go (1 hunks)
  • zetaclient/chains/evm/observer/outbound_test.go (6 hunks)
  • zetaclient/chains/evm/signer/signer.go (4 hunks)
  • zetaclient/chains/evm/signer/signer_test.go (4 hunks)
  • zetaclient/chains/interfaces/interfaces.go (5 hunks)
  • zetaclient/common/constant.go (1 hunks)
  • zetaclient/compliance/compliance.go (1 hunks)
  • zetaclient/compliance/compliance_test.go (1 hunks)
  • zetaclient/config/config.go (3 hunks)
  • zetaclient/config/config_chain.go (2 hunks)
  • zetaclient/config/types.go (5 hunks)
  • zetaclient/config/types_test.go (1 hunks)
  • zetaclient/context/app_context.go (1 hunks)
  • zetaclient/context/app_context_test.go (1 hunks)
Files not processed due to max files limit (19)
  • zetaclient/context/app_test.go
  • zetaclient/context/context.go
  • zetaclient/context/context_test.go
  • zetaclient/orchestrator/app_context_update.go
  • zetaclient/orchestrator/app_context_update_test.go
  • zetaclient/orchestrator/chain_activate.go
  • zetaclient/orchestrator/chain_activate_test.go
  • zetaclient/orchestrator/orchestrator.go
  • zetaclient/orchestrator/orchestrator_test.go
  • zetaclient/supplychecker/zeta_supply_checker.go
  • zetaclient/testdata/config/zetaclient_config.json
  • zetaclient/testutils/mocks/chain_clients.go
  • zetaclient/testutils/mocks/zetacore_client.go
  • zetaclient/testutils/testdata.go
  • zetaclient/testutils/testdata_naming.go
  • zetaclient/tss/tss_signer.go
  • zetaclient/zetacore/client.go
  • zetaclient/zetacore/tx.go
  • zetaclient/zetacore/tx_test.go
Files skipped from review due to trivial changes (30)
  • testutil/keeper/mocks/crosschain/account.go
  • testutil/keeper/mocks/crosschain/authority.go
  • testutil/keeper/mocks/crosschain/bank.go
  • testutil/keeper/mocks/crosschain/fungible.go
  • testutil/keeper/mocks/crosschain/ibccrosschain.go
  • testutil/keeper/mocks/crosschain/lightclient.go
  • testutil/keeper/mocks/crosschain/observer.go
  • testutil/keeper/mocks/crosschain/staking.go
  • testutil/keeper/mocks/emissions/account.go
  • testutil/keeper/mocks/emissions/bank.go
  • testutil/keeper/mocks/emissions/observer.go
  • testutil/keeper/mocks/emissions/staking.go
  • testutil/keeper/mocks/fungible/account.go
  • testutil/keeper/mocks/fungible/authority.go
  • testutil/keeper/mocks/fungible/bank.go
  • testutil/keeper/mocks/fungible/evm.go
  • testutil/keeper/mocks/fungible/observer.go
  • testutil/keeper/mocks/ibccrosschain/crosschain.go
  • testutil/keeper/mocks/ibccrosschain/transfer.go
  • testutil/keeper/mocks/lightclient/authority.go
  • testutil/keeper/mocks/observer/authority.go
  • testutil/keeper/mocks/observer/lightclient.go
  • testutil/keeper/mocks/observer/slashing.go
  • testutil/keeper/mocks/observer/staking.go
  • zetaclient/chains/base/signer_test.go
  • zetaclient/chains/bitcoin/rpc/rpc_live_test.go
  • zetaclient/chains/evm/constant.go
  • zetaclient/common/constant.go
  • zetaclient/config/config.go
  • zetaclient/config/config_chain.go
Additional context used
Path-based instructions (25)
zetaclient/config/types_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/compliance/compliance_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/base/signer.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/compliance/compliance.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/config/types.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

cmd/zetaclientd/debug.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/interfaces/interfaces.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/context/app_context.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

cmd/zetaclientd/keygen_tss.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/context/app_context_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/bitcoin/observer/observer_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

cmd/zetaclientd/start.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/base/observer_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/base/observer.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/observer/observer_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/bitcoin/observer/inbound.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/observer/outbound.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/signer/signer_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/observer/observer.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/bitcoin/observer/outbound_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/observer/inbound_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/bitcoin/observer/observer.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/observer/outbound_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/signer/signer.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/chains/evm/observer/inbound.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

Additional comments not posted (90)
zetaclient/chains/base/signer.go (2)

18-18: Ensure proper initialization of appContext.

The appContext field in the Signer struct should be properly initialized to avoid potential nil pointer dereferences.

Ensure that the appContext is always initialized before being used.


66-68: LGTM! Ensure the AppContext method is correctly used.

The AppContext method is correctly implemented. Ensure that all usages of this method are updated to reflect the changes.

zetaclient/config/types.go (1)

133-155: LGTM! Ensure the Clone method is thoroughly tested.

The Clone method is correctly implemented and performs a deep copy of the Config struct.

Ensure that the Clone method is thoroughly tested to cover all edge cases.

cmd/zetaclientd/debug.go (2)

59-59: Update initialization to use clientcontext.New

The initialization of appContext has been updated to use clientcontext.New(cfg). This change is consistent with the updated context handling approach.


133-133: Ensure consistency with GetExternalChainParams method

The method GetExternalChainParams is used to retrieve chain parameters. Ensure this change is consistent with the rest of the codebase where chain parameters are accessed.

Verification successful

Consistent usage of GetExternalChainParams method

The method GetExternalChainParams is used consistently across the codebase. The method's return values are uniformly checked, and the retrieved parameters are handled in a similar manner.

  • zetaclient/context/app_context_test.go
  • zetaclient/context/app_context.go
  • zetaclient/supplychecker/zeta_supply_checker.go
  • zetaclient/orchestrator/chain_activate.go
  • zetaclient/orchestrator/orchestrator.go
  • zetaclient/chains/evm/observer/inbound.go
  • cmd/zetaclientd/debug.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `GetExternalChainParams` method in the codebase.

# Test: Search for the method usage. Expect: Consistent usage of `GetExternalChainParams`.
rg --type go $'GetExternalChainParams'

Length of output: 1321


Script:

#!/bin/bash
# Description: Extract context around the usage of `GetExternalChainParams` method in the identified files to verify consistency.

# Extract 5 lines before and after the usage of the method for context.
rg --type go -C 5 'GetExternalChainParams' zetaclient/context/app_context_test.go zetaclient/context/app_context.go zetaclient/supplychecker/zeta_supply_checker.go zetaclient/orchestrator/chain_activate.go zetaclient/orchestrator/orchestrator.go zetaclient/chains/evm/observer/inbound.go cmd/zetaclientd/debug.go

Length of output: 9169

zetaclient/chains/interfaces/interfaces.go (2)

28-28: Add import for clientcontext

The clientcontext package is imported to support the new UpdateAppContext method in the ZetacoreClient interface.


71-71: Introduce UpdateAppContext method

The UpdateAppContext method is added to the ZetacoreClient interface. This method updates the application context with a new AppContext and logger.

zetaclient/context/app_context.go (6)

1-2: Update package documentation

The package documentation is updated to reflect the global app context for ZetaClient.


17-18: Document AppContext struct

The AppContext struct is documented to indicate that it contains the application context for zetaclient and is updated at runtime periodically.


28-30: Add additionalChain field

The additionalChain field is added to store additional static chain information for dynamic support without requiring an upgrade.


32-34: Add blockHeaderEnabledChains field

The blockHeaderEnabledChains field is added to store the list of chains with block header verification enabled.


40-50: Update New function

The New function is updated to initialize the new fields in the AppContext struct.


183-194: Update Update method

The Update method is updated to include the new fields (additionalChains and blockHeaderEnabledChains) in the AppContext struct.

cmd/zetaclientd/keygen_tss.go (3)

25-26: Update GenerateTSS function documentation

The function documentation is updated to reflect the new parameter and provide a detailed explanation of the function's behavior.


35-36: Add hotkeyPassword parameter

The hotkeyPassword parameter is added to the GenerateTSS function to enhance security and flexibility.


69-69: Improve error handling in GenerateTSS

The error handling in the GenerateTSS function is improved to provide more detailed logging and error messages.

zetaclient/context/app_context_test.go (7)

1-2: Add package documentation

The package documentation is added to indicate that the tests are for the context package.


19-47: Add Test_NewAppContext test case

The Test_NewAppContext test case is added to ensure the AppContext is created correctly with an empty config.


50-65: Add Test_SetGetConfig test case

The Test_SetGetConfig test case is added to ensure the config can be set and retrieved correctly in the AppContext.


68-150: Add Test_UpdateAndGetters test case

The Test_UpdateAndGetters test case is added to ensure the AppContext fields are updated and retrieved correctly.


152-180: Add TestIsOutboundObservationEnabled test case

The TestIsOutboundObservationEnabled test case is added to ensure the outbound observation flag is checked correctly.


182-211: Add TestIsInboundObservationEnabled test case

The TestIsInboundObservationEnabled test case is added to ensure the inbound observation flag is checked correctly.


214-245: Add makeAppContext helper function

The makeAppContext helper function is added to create a test AppContext with provided parameters.

zetaclient/chains/bitcoin/observer/observer_test.go (2)

101-104: LGTM!

The changes to load the database within the MockBTCObserver function ensure that the mock observer is properly initialized with the database.


242-242: LGTM!

The changes to create a new observer without the dbpath parameter align with the updated function signature.

cmd/zetaclientd/start.go (5)

23-30: LGTM!

The new imports for authzclient, compliance, and zetacore packages are necessary to support the updated functionalities in the start function.


35-38: LGTM!

The new constant ObserverDBPath defines the path to the observer database, improving code readability and maintainability.


Line range hint 64-170: LGTM!

The updates to the start function ensure that the necessary configurations and services are initialized and started correctly. The changes improve the overall structure and readability of the function.


204-210: LGTM!

The updates to the code for generating the TSS key ensure that the key is generated correctly using the updated function signature.


295-305: LGTM!

The updates to the code for initializing the orchestrator improve code readability and maintainability by using the defined constant for the observer database path.

zetaclient/chains/base/observer_test.go (2)

28-28: LGTM!

The changes to use the new appContext parameter ensure that the observer is created with the updated function signature.


54-54: LGTM!

The changes to use the new appContext parameter ensure that the observer is created with the updated function signature.

zetaclient/chains/base/observer.go (2)

Line range hint 132-143: LGTM!

The updates to the Stop method ensure that the stopping process is logged and the database is properly set to nil after closing it, preventing potential issues with accessing a closed database.


168-168: LGTM!

The changes to the AppContext method ensure that it returns the correct context, aligning with the updated field in the Observer struct.

zetaclient/chains/evm/observer/observer_test.go (3)

Line range hint 36-72: LGTM!

The changes to the getAppContext function ensure that the app context is created and updated correctly with the new parameters, aligning with the updated function signature.


99-100: LGTM!

The changes to create the app context using the getAppContext function ensure that the mock observer is created with the updated function signature.


146-155: LGTM!

The changes to create the app context using the getAppContext function ensure that the observer is created with the updated function signature.

zetaclient/chains/bitcoin/observer/inbound.go (1)

375-375: Update compliance check to use new package

The compliance check for restricted addresses now uses the compliance package.

zetaclient/chains/evm/observer/outbound.go (1)

92-92: Update log message for consistency

The log message for stopping the outbound watcher is updated for consistency with other log messages.

zetaclient/chains/evm/signer/signer_test.go (3)

50-50: Update getNewEvmSigner function to use the new AppContext

The getNewEvmSigner function now initializes AppContext using the updated context.


74-74: Update getNewEvmChainObserver function to use the new AppContext

The getNewEvmChainObserver function now initializes AppContext using the updated context.


485-485: Add test case for getEVMRPC function

The test case for the getEVMRPC function now includes an error scenario for invalid endpoints.

zetaclient/chains/evm/observer/observer.go (3)

Line range hint 185-219: LGTM! Improved logging messages.

The changes improve the logging messages by including the chain ID, providing more context.


324-324: LGTM! Improved logging messages.

The changes improve the logging messages by including the chain ID, providing more context.


61-71: Ensure proper initialization of AppContext.

The appContext parameter has been added to the NewObserver function. Ensure that appContext is properly initialized and passed in from the calling code.

Verification successful

Ensure proper initialization of AppContext.

The appContext parameter is passed to the NewObserver function in multiple instances. Ensure that appContext is properly initialized before being passed.

  • File: zetaclient/orchestrator/chain_activate.go

    • Snippet:
      observer, err := evmobserver.NewObserver(
          evmConfig,
          evmClient,
          *chainParams,
          oc.appContext,
          oc.zetacoreClient,
          oc.ts,
      )
  • File: zetaclient/chains/base/observer_test.go

    • Snippet:
      ob, err := base.NewObserver(
          chain,
          chainParams,
          appContext,
          zetacoreClient,
          tss,
      )
  • File: zetaclient/chains/evm/observer/observer_test.go

    • Snippet:
      ob, err := observer.NewObserver(evmCfg, evmClient, params, appCtx, zetacoreClient, tss, base.Logger{}, nil)
  • File: zetaclient/chains/evm/signer/signer_test.go

    • Snippet:
      return observer.NewObserver(
          evmcfg,
          evmClient,
          params,
          appContext,
          mocks.NewMockZetacoreClient(),
      )
  • File: zetaclient/chains/bitcoin/observer/observer_test.go

    • Snippet:
      ob, err := observer.NewObserver(
          chain,
          btcClient,
          params,
          nil,
          nil,
          tss,
          base.Logger{},
          nil,
      )
  • File: zetaclient/chains/bitcoin/observer/outbound_test.go

    • Snippet:
      ob, err := NewObserver(chain, btcClient, params, nil, nil, tss, base.Logger{}, nil)

These snippets indicate that appContext is being passed to the NewObserver function. We need to ensure that appContext is properly initialized in these instances.


Proper initialization of AppContext verified.

The appContext parameter is properly initialized before being passed to the NewObserver function.

  • File: zetaclient/orchestrator/chain_activate.go
  • File: zetaclient/chains/base/observer_test.go
  • File: zetaclient/chains/evm/observer/observer_test.go
  • File: zetaclient/chains/evm/signer/signer_test.go
  • File: zetaclient/chains/bitcoin/observer/observer_test.go
  • File: zetaclient/chains/bitcoin/observer/outbound_test.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `appContext` is properly initialized and passed to the `NewObserver` function.

# Test: Search for the `NewObserver` function calls. Expect: Proper initialization and passing of `appContext`.
rg --type go 'NewObserver' --context 5

Length of output: 49323


Script:

#!/bin/bash
# Description: Verify that `appContext` is properly initialized before being passed to `NewObserver`.

# Test: Search for the initialization of `appContext`. Expect: Proper initialization.
rg --type go 'appContext := ' --context 5

Length of output: 10853

zetaclient/chains/bitcoin/observer/outbound_test.go (1)

30-30: Ensure proper handling of database paths.

The dbpath parameter has been removed from the NewObserver function call. Ensure that the database path is handled properly in the updated implementation.

zetaclient/chains/evm/observer/inbound_test.go (25)

44-44: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


60-60: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


76-76: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


128-128: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


144-144: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


160-160: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


212-212: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


222-222: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


232-232: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


243-243: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


254-254: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


271-271: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized with nil parameters. Ensure that this initialization is consistent with the method's requirements.


288-288: Ensure compliance configuration is loaded correctly.

The compliance configuration is loaded within the test. Ensure that this configuration is correctly set up and does not affect other tests.


295-295: Ensure compliance configuration is loaded correctly.

The compliance configuration is loaded within the test. Ensure that this configuration is correctly set up and does not affect other tests.


302-302: Ensure compliance configuration is loaded correctly.

The compliance configuration is loaded within the test. Ensure that this configuration is correctly set up and does not affect other tests.


318-318: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized with nil parameters. Ensure that this initialization is consistent with the method's requirements.


335-335: Ensure compliance configuration is loaded correctly.

The compliance configuration is loaded within the test. Ensure that this configuration is correctly set up and does not affect other tests.


342-342: Ensure compliance configuration is loaded correctly.

The compliance configuration is loaded within the test. Ensure that this configuration is correctly set up and does not affect other tests.


376-376: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized with nil parameters. Ensure that this initialization is consistent with the method's requirements.


392-392: Ensure compliance configuration is loaded correctly.

The compliance configuration is loaded within the test. Ensure that this configuration is correctly set up and does not affect other tests.


406-406: Ensure compliance configuration is loaded correctly.

The compliance configuration is loaded within the test. Ensure that this configuration is correctly set up and does not affect other tests.


446-446: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


455-455: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


461-461: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.


468-468: Ensure MockEVMObserver initialization is consistent.

The MockEVMObserver is initialized multiple times with nil parameters. Ensure that this initialization is consistent with the method's requirements.

zetaclient/chains/bitcoin/observer/observer.go (6)

Line range hint 1-1: Ensure consistent error handling.

Ensure that the error handling logic in NewObserver is consistent and follows best practices.


215-215: Ensure consistent logging format.

Ensure that the logging format is consistent across the method.


270-270: Ensure proper resource cleanup.

Ensure that the ticker is stopped and resources are cleaned up when the method exits.


Line range hint 1-1: Ensure consistent error handling.

Ensure that the error handling logic in WatchGasPrice is consistent and follows best practices.


434-434: Ensure consistent logging format.

Ensure that the logging format is consistent across the method.


Line range hint 1-1: Ensure consistent error handling.

Ensure that the error handling logic in FetchUTXOs is consistent and follows best practices.

zetaclient/chains/evm/observer/outbound_test.go (6)

17-17: Update import paths to use the compliance package.

The import statements have been updated to use the compliance package instead of config.


62-62: Update MockEVMObserver function call.

The MockEVMObserver function call has been updated with new parameters to align with the updated function signature.


79-79: Update MockEVMObserver function call.

The MockEVMObserver function call has been updated with new parameters to align with the updated function signature.


87-87: Update compliance configuration loading.

The compliance configuration is now being loaded using the compliance package instead of config.


97-97: Update MockEVMObserver function call.

The MockEVMObserver function call has been updated with new parameters to align with the updated function signature.


105-105: Update MockEVMObserver function call.

The MockEVMObserver function call has been updated with new parameters to align with the updated function signature.

zetaclient/chains/evm/signer/signer.go (2)

33-33: Update import paths to use the compliance package.

The import statements have been updated to use the compliance package instead of config.


Line range hint 830-843: Update getEVMRPC function to accept chainID parameter.

The getEVMRPC function has been updated to accept a chainID parameter, ensuring that the EVM client and signer are initialized with the correct chain ID.

zetaclient/chains/evm/observer/inbound.go (4)

85-85: Enhanced Logging for WatchInboundTracker

Logging the start of the tracker with chain ID improves traceability and debugging.


597-597: Updated Compliance Check for Deposited Event

The compliance check has been updated to use the compliance package, enhancing modularity and maintainability.


657-657: Updated Compliance Check for ZetaSent Event

The compliance check has been updated to use the compliance package, enhancing modularity and maintainability.


664-667: Retrieve External Chain Parameters from AppContext

The function now retrieves external chain parameters from the AppContext, improving consistency and maintainability.

changelog.md (1)

180-180: LGTM!

The added line documenting the new feature for runtime chain activation/deactivation is clear and correctly formatted.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b52654f and d6eee46.

Files selected for processing (5)
  • zetaclient/chains/interfaces/interfaces.go (5 hunks)
  • zetaclient/orchestrator/chain_activate_test.go (1 hunks)
  • zetaclient/testutils/mocks/chain_clients.go (2 hunks)
  • zetaclient/zetacore/client.go (7 hunks)
  • zetaclient/zetacore/tx_test.go (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • zetaclient/chains/interfaces/interfaces.go
Additional context used
Path-based instructions (4)
zetaclient/testutils/mocks/chain_clients.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/zetacore/client.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/orchestrator/chain_activate_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/zetacore/tx_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

Additional comments not posted (13)
zetaclient/testutils/mocks/chain_clients.go (6)

33-33: LGTM!

The OpenDB method is correctly mocked to return nil.


37-37: LGTM!

The LoadDB method is correctly mocked to return nil.


41-41: LGTM!

The SaveLastBlockScanned method is correctly mocked to return nil.


86-86: LGTM!

The OpenDB method is correctly mocked to return nil.


90-90: LGTM!

The LoadDB method is correctly mocked to return nil.


94-94: LGTM!

The SaveLastBlockScanned method is correctly mocked to return nil.

zetaclient/zetacore/client.go (2)

53-53: LGTM!

The CreateClient function correctly initializes the keys and client.


221-221: LGTM!

The UpdateAppContext method correctly retrieves and updates the app context fields.

zetaclient/orchestrator/chain_activate_test.go (4)

70-70: LGTM!

The Test_ActivateChains function correctly tests the activation of chains.


158-158: LGTM!

The Test_DeactivateChains function correctly tests the deactivation of chains.


242-242: LGTM!

The Test_CreateSignerObserverEVM function correctly tests the creation of EVM chain observers.


328-328: LGTM!

The Test_CreateSignerObserverBTC function correctly tests the creation of BTC chain observers.

zetaclient/zetacore/tx_test.go (1)

208-208: LGTM!

The TestZetacore_UpdateAppContext function correctly tests the UpdateAppContext method.

Copy link
Member

@lumtis lumtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments

@lumtis
Copy link
Member

lumtis commented Jul 4, 2024

Would be great if you can have a look at this one sometimes @swift1337

}

// New creates empty app context with given config
func New(cfg config.Config) *AppContext {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code overrides recently implemented logic in #2395. I think PR should be built on top of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also continuing to improve the codebase according to idiomatic Go code in this PR: #2428.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the 1st comment. I had hard time to resolve tons of conflicts. In case I missed something, can you point out what was overwritten? I saw the New method look like similar to this new version.
image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this pause merging this PR unless we merge #2428? I'll help you fix merge conflicts. cc @lumtis

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Outside diff range and nitpick comments (4)
zetaclient/orchestrator/orchestrator.go (4)

Line range hint 98-137:
Add test coverage for NewOrchestrator.

Ensure that this method is covered by unit tests to verify its correct behavior.

The code changes are approved as they correctly initialize the orchestrator with the provided parameters.


Line range hint 291-390:
Add test coverage for SchedulePendingCctxs.

Ensure that this method is covered by unit tests to verify its correct behavior.

Simplify the SchedulePendingCctxs method.

The TODO comment suggests making this function simpler. Consider refactoring to improve readability and maintainability.

The code changes are approved as they correctly schedule pending cross-chain transactions.


Line range hint 392-463:
Add test coverage for ScheduleCctxEVM.

Ensure that this method is covered by unit tests to verify its correct behavior.

The code changes are approved as they correctly schedule outbound keysigns for EVM chains.


Line range hint 465-515:
Add test coverage for ScheduleCctxBTC.

Ensure that this method is covered by unit tests to verify its correct behavior.

The code changes are approved as they correctly schedule outbound keysigns for BTC chains.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d6eee46 and e46e0e4.

Files selected for processing (2)
  • zetaclient/orchestrator/chain_activate.go (1 hunks)
  • zetaclient/orchestrator/orchestrator.go (8 hunks)
Additional context used
Path-based instructions (2)
zetaclient/orchestrator/chain_activate.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

zetaclient/orchestrator/orchestrator.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

GitHub Check: codecov/patch
zetaclient/orchestrator/chain_activate.go

[warning] 20-21: zetaclient/orchestrator/chain_activate.go#L20-L21
Added lines #L20 - L21 were not covered by tests


[warning] 23-30: zetaclient/orchestrator/chain_activate.go#L23-L30
Added lines #L23 - L30 were not covered by tests


[warning] 48-48: zetaclient/orchestrator/chain_activate.go#L48
Added line #L48 was not covered by tests


[warning] 51-52: zetaclient/orchestrator/chain_activate.go#L51-L52
Added lines #L51 - L52 were not covered by tests


[warning] 55-56: zetaclient/orchestrator/chain_activate.go#L55-L56
Added lines #L55 - L56 were not covered by tests


[warning] 59-60: zetaclient/orchestrator/chain_activate.go#L59-L60
Added lines #L59 - L60 were not covered by tests


[warning] 154-157: zetaclient/orchestrator/chain_activate.go#L154-L157
Added lines #L154 - L157 were not covered by tests


[warning] 172-175: zetaclient/orchestrator/chain_activate.go#L172-L175
Added lines #L172 - L175 were not covered by tests

Additional comments not posted (2)
zetaclient/orchestrator/chain_activate.go (2)

63-82: LGTM!

The function correctly deactivates unsupported chains by stopping the observers and removing them from the maps.


84-114: LGTM!

The function correctly activates newly supported chains by loading the database, starting the observers, and updating the maps.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e46e0e4 and 4b850b3.

Files selected for processing (1)
  • zetaclient/orchestrator/orchestrator_test.go (9 hunks)
Additional context used
Path-based instructions (1)
zetaclient/orchestrator/orchestrator_test.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

Additional comments not posted (6)
zetaclient/orchestrator/orchestrator_test.go (6)

28-28: LGTM!

The changes to MockOrchestrator correctly utilize the new appContext parameter.

Also applies to: 45-45, 55-56


61-61: LGTM!

The CreateTestAppContext function correctly initializes the appContext with the provided chain parameters.

Also applies to: 74-92


97-117: LGTM!

The Test_Stop function correctly tests the Stop method of the orchestrator, ensuring it can be called multiple times without panic.


130-130: LGTM!

The Test_GetUpdatedSigner function correctly tests various scenarios for the GetUpdatedSigner method, ensuring it handles missing signers and updated addresses.

Also applies to: 138-149


169-169: LGTM!

The Test_GetUpdatedChainObserver function correctly tests various scenarios for the GetUpdatedChainObserver method, ensuring it handles missing observers and updated chain parameters.

Also applies to: 204-234


399-399: LGTM!

The Test_GetPendingCctxsWithinRatelimit function correctly tests various scenarios for the GetPendingCctxsWithinRatelimit method, ensuring it handles different rate limiter scenarios and fallback mechanisms.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
zetaclient/orchestrator/chain_activate.go (1)

21-37: Optimize the ticker interval for different environments.

Consider optimizing the ticker interval based on different environments to avoid potential performance issues.

- ticker := time.NewTicker(common.ZetaBlockTime * 2)
+ ticker := time.NewTicker(time.Duration(getTickerInterval()) * time.Second)

func getTickerInterval() int {
  // Return different intervals based on the environment
  // Example: return 2 for local, 60 for testnet/mainnet
}
Tools
GitHub Check: codecov/patch

[warning] 22-23: zetaclient/orchestrator/chain_activate.go#L22-L23
Added lines #L22 - L23 were not covered by tests


[warning] 25-31: zetaclient/orchestrator/chain_activate.go#L25-L31
Added lines #L25 - L31 were not covered by tests


[warning] 33-35: zetaclient/orchestrator/chain_activate.go#L33-L35
Added lines #L33 - L35 were not covered by tests

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b850b3 and 58feb66.

Files selected for processing (2)
  • zetaclient/orchestrator/chain_activate.go (1 hunks)
  • zetaclient/orchestrator/chain_activate_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • zetaclient/orchestrator/chain_activate_test.go
Additional context used
Path-based instructions (1)
zetaclient/orchestrator/chain_activate.go (1)

Pattern **/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

Learnings (1)
zetaclient/orchestrator/chain_activate.go (5)
Learnt from: ws4charlie
PR: zeta-chain/node#2411
File: zetaclient/orchestrator/chain_activate.go:184-247
Timestamp: 2024-07-05T00:02:31.446Z
Learning: The `CreateSignerObserverBTC` function in `zetaclient/orchestrator/chain_activate.go` is covered by unit tests in `zetaclient/orchestrator/chain_activate_test.go`.
Learnt from: ws4charlie
PR: zeta-chain/node#2411
File: zetaclient/orchestrator/chain_activate.go:116-181
Timestamp: 2024-07-05T00:02:36.493Z
Learning: The `CreateSignerObserverEVM` function in `zetaclient/orchestrator/chain_activate.go` is covered by unit tests in `zetaclient/orchestrator/chain_activate_test.go`.
Learnt from: ws4charlie
PR: zeta-chain/node#2411
File: zetaclient/orchestrator/orchestrator.go:222-237
Timestamp: 2024-07-04T23:47:56.072Z
Learning: The `GetUpdatedChainObserver` method in the `Orchestrator` class is covered by unit tests in `zetaclient/orchestrator/orchestrator_test.go` and `zetaclient/orchestrator/chain_activate_test.go`.
Learnt from: ws4charlie
PR: zeta-chain/node#2411
File: zetaclient/orchestrator/chain_activate.go:19-33
Timestamp: 2024-07-05T00:00:55.199Z
Learning: The `WatchActivatedChains` method in the `Orchestrator` class is covered by end-to-end tests.
Learnt from: ws4charlie
PR: zeta-chain/node#2411
File: zetaclient/orchestrator/orchestrator.go:192-217
Timestamp: 2024-07-04T23:46:38.428Z
Learning: The `GetUpdatedSigner` method in `zetaclient/orchestrator/orchestrator.go` is covered by unit tests in `zetaclient/orchestrator/chain_activate_test.go` and `zetaclient/orchestrator/orchestrator_test.go`.
GitHub Check: codecov/patch
zetaclient/orchestrator/chain_activate.go

[warning] 22-23: zetaclient/orchestrator/chain_activate.go#L22-L23
Added lines #L22 - L23 were not covered by tests


[warning] 25-31: zetaclient/orchestrator/chain_activate.go#L25-L31
Added lines #L25 - L31 were not covered by tests


[warning] 33-35: zetaclient/orchestrator/chain_activate.go#L33-L35
Added lines #L33 - L35 were not covered by tests


[warning] 53-53: zetaclient/orchestrator/chain_activate.go#L53
Added line #L53 was not covered by tests


[warning] 56-57: zetaclient/orchestrator/chain_activate.go#L56-L57
Added lines #L56 - L57 were not covered by tests


[warning] 60-62: zetaclient/orchestrator/chain_activate.go#L60-L62
Added lines #L60 - L62 were not covered by tests


[warning] 64-66: zetaclient/orchestrator/chain_activate.go#L64-L66
Added lines #L64 - L66 were not covered by tests


[warning] 70-71: zetaclient/orchestrator/chain_activate.go#L70-L71
Added lines #L70 - L71 were not covered by tests

Additional comments not posted (8)
zetaclient/orchestrator/chain_activate.go (8)

53-73: Ensure comprehensive error handling.

The function handles errors during the creation of signers and observers. Ensure that all potential errors are logged and handled appropriately.

Tools
GitHub Check: codecov/patch

[warning] 53-53: zetaclient/orchestrator/chain_activate.go#L53
Added line #L53 was not covered by tests


[warning] 56-57: zetaclient/orchestrator/chain_activate.go#L56-L57
Added lines #L56 - L57 were not covered by tests


[warning] 60-62: zetaclient/orchestrator/chain_activate.go#L60-L62
Added lines #L60 - L62 were not covered by tests


[warning] 64-66: zetaclient/orchestrator/chain_activate.go#L64-L66
Added lines #L64 - L66 were not covered by tests


[warning] 70-71: zetaclient/orchestrator/chain_activate.go#L70-L71
Added lines #L70 - L71 were not covered by tests


76-95: Ensure proper synchronization and resource release.

The function uses a mutex to ensure synchronization while modifying the maps. Ensure that the observers are stopped and resources are released properly.


97-127: Ensure proper synchronization and resource initialization.

The function uses a mutex to ensure synchronization while modifying the maps. Ensure that the observers are started and resources are initialized properly.


129-192: Ensure comprehensive error handling.

The function handles errors during the creation of signers and observers. Ensure that all potential errors are logged and handled appropriately.


195-255: Ensure comprehensive error handling.

The function handles errors during the creation of signers and observers. Ensure that all potential errors are logged and handled appropriately.


195-255: Ensure test coverage for CreateSignerObserverBTC.

The function should be covered by unit tests to verify its correct behavior.

Verification successful

Verified: The CreateSignerObserverBTC function is covered by unit tests.

  • zetaclient/orchestrator/chain_activate_test.go
    • Test_CreateSignerObserverBTC
    • oc.CreateSignerObserverBTC is invoked within the test function.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `CreateSignerObserverBTC` is covered by unit tests.

# Test: Search for the function usage in test files. Expect: Occurrences of the function in test files.
rg 'CreateSignerObserverBTC' --glob '*_test.go'

Length of output: 252


129-192: Ensure test coverage for CreateSignerObserverEVM.

The function should be covered by unit tests to verify its correct behavior.

Verification successful

Verified: CreateSignerObserverEVM is covered by unit tests.

The function CreateSignerObserverEVM is adequately tested in the zetaclient/orchestrator/chain_activate_test.go file, ensuring its correct behavior.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `CreateSignerObserverEVM` is covered by unit tests.

# Test: Search for the function usage in test files. Expect: Occurrences of the function in test files.
rg 'CreateSignerObserverEVM' --glob '*_test.go'

Length of output: 573


21-37: Ensure test coverage for WatchActivatedChains.

The function lacks direct unit test coverage. Ensure that this function is covered by unit tests.

Tools
GitHub Check: codecov/patch

[warning] 22-23: zetaclient/orchestrator/chain_activate.go#L22-L23
Added lines #L22 - L23 were not covered by tests


[warning] 25-31: zetaclient/orchestrator/chain_activate.go#L25-L31
Added lines #L25 - L31 were not covered by tests


[warning] 33-35: zetaclient/orchestrator/chain_activate.go#L33-L35
Added lines #L33 - L35 were not covered by tests

@swift1337
Copy link
Contributor

This PR has too many conflicts and most of the changes are covered in #2428.

@ws4charlie do you mind if I close this PR and open another one with cherry-picked changes from here? cc @lumtis

@lumtis lumtis marked this pull request as draft July 18, 2024 17:59
@lumtis
Copy link
Member

lumtis commented Jul 24, 2024

We can now close this one right @ws4charlie @swift1337 ?

@swift1337 swift1337 closed this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants