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

Remove all dynamic peer discovery #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Dec 10, 2024

Remove all dynamic peer discovery logic and rely on precomputed bootstrap addresses.

See zeta-chain/node#3289

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a function to generate multiple bootstrap addresses for local tests, improving flexibility in test configurations.
  • Bug Fixes

    • Enhanced error handling during bootstrap address generation in multiple test suites.
  • Refactor

    • Updated test setups to utilize dynamically generated bootstrap peers instead of hardcoded addresses.
    • Removed the peer discovery mechanism from the communication structure, simplifying peer management.
  • Chores

    • Updated port numbers across various test suites for consistency.

Copy link

coderabbitai bot commented Dec 10, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 golangci-lint (1.62.2)

level=warning msg="[config_reader] The configuration option linters.errcheck.ignore is deprecated, please use linters.errcheck.exclude-functions."
level=warning msg="The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused."
level=warning msg="The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner. Replaced by revive."
level=error msg="[linters_context] deadcode: This linter is fully inactivated: it will not produce any reports."
level=error msg="[linters_context] golint: This linter is fully inactivated: it will not produce any reports."

📝 Walkthrough

Walkthrough

The pull request introduces significant changes across several files, primarily focusing on the implementation of a new function, TestBootstrapAddrs, in conversion/tss_helper.go. This function generates bootstrap addresses for testing purposes. Corresponding updates are made in various test files to replace hardcoded multiaddresses with dynamically generated bootstrap addresses. Additionally, the p2p package undergoes modifications, including the removal of the PeerDiscovery component, simplifying peer management. The overall structure of the tests remains intact, but the setup processes are enhanced for clarity and maintainability.

Changes

File Change Summary
conversion/tss_helper.go Added TestBootstrapAddrs(ports []int, testPubKeys []string) ([]maddr.Multiaddr, error) function for generating bootstrap addresses. Updated import statements to include fmt and maddr.
keygen/ecdsa/keygen_test.go Removed maddr import. Updated SetUpTest to use conversion.TestBootstrapAddrs for bootstrap peers instead of hardcoded multiaddress.
keygen/eddsa/keygen_test.go Removed maddr import. Updated SetUpTest to utilize conversion.TestBootstrapAddrs for bootstrap peers, replacing the previous multiaddress creation.
keysign/ecdsa/keysign_old_test.go Updated SetUpTest to replace hardcoded bootstrap peer with conversion.TestBootstrapAddrs.
keysign/ecdsa/keysign_test.go Updated SetUpTest to use dynamically generated bootstrap peers via conversion.TestBootstrapAddrs.
keysign/eddsa/keysign_test.go Updated SetUpTest to replace hardcoded bootstrap peer with conversion.TestBootstrapAddrs, enhancing flexibility in peer configuration.
p2p/communication.go Removed discovery field from Communication struct. Updated startChannel and Stop methods to eliminate peer discovery logic.
p2p/discovery.go Deleted file containing the PeerDiscovery implementation, which managed peer connections and bootstrap peers.
p2p/discovery_test.go Deleted test file for the PeerDiscovery mechanism, which validated peer discovery functionality.
tss/tss_4nodes_test.go Updated bootstrapPeer to bootstrapPeers (slice of maddr.Multiaddr). Modified SetUpTest to use conversion.TestBootstrapAddrs for initializing bootstrap peers.
tss/tss_4nodes_zeta_test.go Updated bootstrapPeer to bootstrapPeers (slice of maddr.Multiaddr). Modified SetUpSuite to utilize conversion.TestBootstrapAddrs for bootstrap addresses.

Possibly related PRs

Suggested reviewers

  • brewmaster012
  • ws4charlie

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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.

@gartnera gartnera force-pushed the remove-dynamic-peer-discovery branch 2 times, most recently from 01805c5 to 8e95a62 Compare December 10, 2024 21:31
Copy link

@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

🧹 Outside diff range and nitpick comments (4)
conversion/tss_helper.go (1)

61-76: Add input validation for empty slices and length mismatch.

The function should validate that both input slices are non-empty and have matching lengths before processing.

 func TestBootstrapAddrs(ports []int, testPubKeys []string) ([]maddr.Multiaddr, error) {
+    if len(ports) == 0 || len(testPubKeys) == 0 {
+        return nil, fmt.Errorf("empty input: ports=%d, pubkeys=%d", len(ports), len(testPubKeys))
+    }
+    if len(ports) != len(testPubKeys) {
+        return nil, fmt.Errorf("length mismatch: ports=%d, pubkeys=%d", len(ports), len(testPubKeys))
+    }
     res := make([]maddr.Multiaddr, len(ports))
     for i := 0; i < len(ports); i++ {
tss/tss_4nodes_zeta_test.go (1)

224-240: Consider adding context to error returns in getTssServer.

The error handling could be more informative by wrapping errors with context.

 func (s *FourNodeScaleZetaSuite) getTssServer(c *C, index int, conf common.TssConfig) *TssServer {
     priKey, err := conversion.GetPriKey(testPriKeyArr[index])
-    c.Assert(err, IsNil)
+    c.Assert(err, IsNil, Commentf("failed to get private key for index %d", index))
     baseHome := path.Join(s.tmpDir, strconv.Itoa(index))
     if _, err := os.Stat(baseHome); os.IsNotExist(err) {
         err := os.MkdirAll(baseHome, os.ModePerm)
-        c.Assert(err, IsNil)
+        c.Assert(err, IsNil, Commentf("failed to create directory %s", baseHome))
     }
keygen/eddsa/keygen_test.go (1)

117-120: Consider extracting common communication setup logic.

The communication setup logic is repeated for each node. Consider extracting it into a helper method to improve maintainability.

+func (s *EddsaKeygenTestSuite) setupCommunication(i int, ports []int, bootstrapPeers []maddr.Multiaddr, whitelistedPeers []peer.ID, buf []byte) (*p2p.Communication, error) {
+    comm, err := p2p.NewCommunication(bootstrapPeers, ports[i], "", whitelistedPeers)
+    if err != nil {
+        return nil, fmt.Errorf("failed to create communication for node %d: %w", i, err)
+    }
+    if err := comm.Start(buf); err != nil {
+        return nil, fmt.Errorf("failed to start communication for node %d: %w", i, err)
+    }
+    return comm, nil
+}

Then use it in the setup:

-        comm, err := p2p.NewCommunication(bootstrapPeers, ports[i], "", whitelistedPeers)
-        c.Assert(err, IsNil)
-        c.Assert(comm.Start(buf), IsNil)
-        s.comms[i] = comm
+        comm, err := s.setupCommunication(i, ports, bootstrapPeers, whitelistedPeers, buf)
+        c.Assert(err, IsNil)
+        s.comms[i] = comm
tss/tss_4nodes_test.go (1)

98-100: Simplify server initialization logic

The server initialization and restart logic could be further simplified by removing the redundant conditional blocks since they perform identical operations.

Consider applying this refactor:

-if idx == 0 {
-    s.servers[idx] = s.getTssServer(c, idx, s.tssConfig)
-} else {
-    s.servers[idx] = s.getTssServer(c, idx, s.tssConfig)
-}
+s.servers[idx] = s.getTssServer(c, idx, s.tssConfig)

And similarly for the restart logic:

-if shutdownIdx == 0 {
-    s.servers[shutdownIdx] = s.getTssServer(c, shutdownIdx, s.tssConfig)
-} else {
-    s.servers[shutdownIdx] = s.getTssServer(c, shutdownIdx, s.tssConfig)
-}
+s.servers[shutdownIdx] = s.getTssServer(c, shutdownIdx, s.tssConfig)

Also applies to: 320-322

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8535262 and f486d1f.

📒 Files selected for processing (11)
  • conversion/tss_helper.go (2 hunks)
  • keygen/ecdsa/keygen_test.go (2 hunks)
  • keygen/eddsa/keygen_test.go (2 hunks)
  • keysign/ecdsa/keysign_old_test.go (2 hunks)
  • keysign/ecdsa/keysign_test.go (2 hunks)
  • keysign/eddsa/keysign_test.go (2 hunks)
  • p2p/communication.go (0 hunks)
  • p2p/discovery.go (0 hunks)
  • p2p/discovery_test.go (0 hunks)
  • tss/tss_4nodes_test.go (4 hunks)
  • tss/tss_4nodes_zeta_test.go (3 hunks)
💤 Files with no reviewable changes (3)
  • p2p/discovery_test.go
  • p2p/communication.go
  • p2p/discovery.go
🧰 Additional context used
📓 Learnings (1)
tss/tss_4nodes_zeta_test.go (1)
Learnt from: gartnera
PR: zeta-chain/go-tss#22
File: tss/tss_4nodes_zeta_test.go:40-78
Timestamp: 2024-11-12T13:20:12.657Z
Learning: In the `SetUpSuite` function of `FourNodeScaleZetaSuite`, directories are cleaned up before the setup starts.
🔇 Additional comments (11)
tss/tss_4nodes_zeta_test.go (1)

28-34: LGTM! Clean struct definition with clear field purposes.

The updated struct fields properly reflect the removal of dynamic peer discovery.

keygen/eddsa/keygen_test.go (1)

105-106: LGTM! Proper error handling for bootstrap address generation.

The error check is appropriate and maintains test reliability.

keysign/eddsa/keysign_test.go (2)

142-143: LGTM: Proper initialization of bootstrap addresses

The implementation correctly generates and validates bootstrap addresses for the test setup.


154-154: LGTM: Appropriate communication setup

The communication initialization properly utilizes the bootstrap peers for node connectivity.

keygen/ecdsa/keygen_test.go (2)

119-120: LGTM: Consistent bootstrap address initialization

The implementation maintains consistency with other test files in generating bootstrap addresses.


131-131: LGTM: Proper communication setup

The communication initialization correctly uses the bootstrap peers.

tss/tss_4nodes_test.go (3)

64-68: LGTM: Improved bootstrap peer management

The change from a single bootstrap peer to a list of peers enhances the test suite's flexibility and reliability.


75-82: LGTM: Proper test setup initialization

The implementation correctly initializes the test environment with appropriate error handling.


373-373: LGTM: Proper TSS instance initialization

The NewTss call correctly utilizes the bootstrap peers list.

keysign/ecdsa/keysign_old_test.go (1)

Line range hint 126-144: LGTM: Bootstrap peer configuration properly implemented

The changes correctly implement the transition from dynamic peer discovery to bootstrap-based peer configuration, aligning with the PR objectives.

keysign/ecdsa/keysign_test.go (1)

Line range hint 145-157: LGTM: Consistent bootstrap peer implementation

The changes maintain consistency with other test files and properly implement the bootstrap-based peer configuration. The error handling is robust with appropriate assertions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants