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

Add concurrency and scale testing #22

Merged
merged 7 commits into from
Jul 29, 2024
Merged

Add concurrency and scale testing #22

merged 7 commits into from
Jul 29, 2024

Conversation

gartnera
Copy link
Member

@gartnera gartnera commented Jul 25, 2024

Add some custom tests to determine the limits and stability of the library.

Fix some data race issues found by the new tests. Also backport fb3ceba which I missed when I rebased the library (this fixes some more data races).

Related to zeta-chain/node#2562

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive test suite for a four-node threshold signature scheme (TSS) using the Zeta protocol, enhancing testing capabilities.
  • Improvements

    • Modified the CI workflow to include a test timeout, improving reliability and efficiency by preventing indefinite test runs.
    • Enhanced resource management by ensuring streams are only added when necessary, preventing potential memory issues.
    • Improved concurrency control during local state management, reducing risks of race conditions.
  • Bug Fixes

    • Addressed potential errors related to invalid stream handling by implementing proper checks before stream management operations.

Copy link

coderabbitai bot commented Jul 25, 2024

Walkthrough

This update enhances the overall reliability and efficiency of the system by introducing timeout settings in CI tests, optimizing stream management in the P2P communication code, and improving concurrency control in state management. Additionally, a new comprehensive test suite for a four-node threshold signature scheme is added, ensuring robust testing of key generation and signing processes under various conditions.

Changes

File Change Summary
.github/workflows/ci.yml Added -timeout 25m flag to the test command for improved test execution management.
p2p/communication.go, p2p/party_coordinator.go Repositioned stream management calls to enhance resource management by ensuring streams aren't added without valid subscribers or peer groups.
p2p/stream_helper.go Improved cleanup in ReleaseStream method by deleting both identified and unknown streams from unusedStreams.
storage/localstate_mgr.go Introduced read locks in GetLocalState method to enhance concurrency control, preventing race conditions.
tss/tss_4nodes_zeta_test.go Added a new test suite for a four-node threshold signature scheme, including setup, execution, and teardown processes.

Sequence Diagram(s)

sequenceDiagram
    participant CI
    participant TestJob
    participant StreamManager
    participant PeerGroup
    participant LocalStateMgr
    participant TSS

    CI->>TestJob: Start tests with timeout
    TestJob->>StreamManager: Manage streams
    StreamManager->>PeerGroup: Check for valid subscriber
    PeerGroup->>StreamManager: Valid/Invalid
    StreamManager->>StreamManager: Add/Close stream based on check

    LocalStateMgr->>LocalStateMgr: Acquire read lock
    LocalStateMgr->>LocalStateMgr: Access shared state
    LocalStateMgr->>LocalStateMgr: Release read lock

    TSS->>TSS: Run four-node threshold signature tests
Loading

Poem

In the fields where coders play,
Changes bloom like flowers in May.
With streams managed and tests that won’t stall,
Our rabbit heart leaps, we welcome them all!
Hopping through code, with joy we sing,
Here's to the changes that new features bring! 🐇✨


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 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 changed the title Add concurrent and scale testing Add concurrency and scale testing Jul 25, 2024
gartnera added 5 commits July 25, 2024 15:58
WARNING: DATA RACE
Read at 0x00c005b2f898 by goroutine 50785:
  gitlab.com/thorchain/tss/go-tss/p2p.(*StreamMgr).ReleaseStream()
      /home/alex/workspace/github.com/zeta-chain/go-tss/p2p/stream_helper.go:53 +0x1f0
  gitlab.com/thorchain/tss/go-tss/p2p.(*Communication).ReleaseStream()
      /home/alex/workspace/github.com/zeta-chain/go-tss/p2p/communication.go:484 +0x104
  gitlab.com/thorchain/tss/go-tss/tss.(*TssServer).KeySign.func1()
      /home/alex/workspace/github.com/zeta-chain/go-tss/tss/keysign.go:219 +0xc4
  runtime.deferreturn()
      /usr/local/go/src/runtime/panic.go:602 +0x5c
  gitlab.com/thorchain/tss/go-tss/tss.(*FourNodeScaleZetaSuite).doTestConcurrentKeySign.func1()
      /home/alex/workspace/github.com/zeta-chain/go-tss/tss/tss_4nodes_zeta_test.go:198 +0x294
  gitlab.com/thorchain/tss/go-tss/tss.(*FourNodeScaleZetaSuite).doTestConcurrentKeySign.gowrap1()
      /home/alex/workspace/github.com/zeta-chain/go-tss/tss/tss_4nodes_zeta_test.go:203 +0x44

Previous write at 0x00c005b2f898 by goroutine 72246:
  gitlab.com/thorchain/tss/go-tss/p2p.(*StreamMgr).AddStream()
      /home/alex/workspace/github.com/zeta-chain/go-tss/p2p/stream_helper.go:76 +0x13c
  gitlab.com/thorchain/tss/go-tss/p2p.(*Communication).readFromStream()
      /home/alex/workspace/github.com/zeta-chain/go-tss/p2p/communication.go:176 +0x334
  gitlab.com/thorchain/tss/go-tss/p2p.(*Communication).handleStream()
      /home/alex/workspace/github.com/zeta-chain/go-tss/p2p/communication.go:195 +0x10c
  gitlab.com/thorchain/tss/go-tss/p2p.(*Communication).handleStream-fm()
      <autogenerated>:1 +0x44
  github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).SetStreamHandler.func1()
      /home/alex/go/pkg/mod/github.com/zeta-chain/go-libp2p@v0.0.0-20240710192637-567fbaacc2b4/p2p/host/basic/basic_host.go:580 +0xb4
  github.com/libp2p/go-libp2p/p2p/host/basic.(*BasicHost).newStreamHandler.gowrap1()
      /home/alex/go/pkg/mod/github.com/zeta-chain/go-libp2p@v0.0.0-20240710192637-567fbaacc2b4/p2p/host/basic/basic_host.go:421 +0x6c
@gartnera gartnera requested a review from a team July 25, 2024 23:36
@gartnera gartnera marked this pull request as ready for review July 25, 2024 23:37
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: 9

Outside diff range, codebase verification and nitpick comments (3)
tss/tss_4nodes_zeta_test.go (1)

128-135: Use a more descriptive error message.

The panic message should be more descriptive to aid in debugging.

-  panic(err)
+  panic(fmt.Sprintf("Failed to generate random hash: %v", err))
p2p/communication.go (1)

180-183: Ensure proper logging for stream closure.

Add a log message when the stream is closed to aid in debugging.

-  _ = stream.Close()
+  if err := stream.Close(); err != nil {
+    c.logger.Error().Err(err).Msg("Failed to close stream")
+  } else {
+    c.logger.Debug().Msg("Stream closed successfully")
+  }
p2p/party_coordinator.go (1)

75-78: Ensure proper logging for stream closure.

Add a log message when the stream is closed to aid in debugging.

-  _ = stream.Close()
+  if err := stream.Close(); err != nil {
+    pc.logger.Error().Err(err).Msg("Failed to close stream")
+  } else {
+    pc.logger.Debug().Msg("Stream closed successfully")
+  }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 76ca65a and 2765ae9.

Files selected for processing (6)
  • .github/workflows/ci.yml (1 hunks)
  • p2p/communication.go (1 hunks)
  • p2p/party_coordinator.go (1 hunks)
  • p2p/stream_helper.go (2 hunks)
  • storage/localstate_mgr.go (1 hunks)
  • tss/tss_4nodes_zeta_test.go (1 hunks)
Additional comments not posted (4)
.github/workflows/ci.yml (1)

23-23: Confirm the correctness of the timeout flag and syntactical adjustment.

The addition of the -timeout 25m flag is beneficial for preventing tests from running indefinitely, improving the reliability of the CI pipeline. The change from --race to -race is a minor syntactical adjustment but should be verified for correctness.

p2p/stream_helper.go (2)

51-51: Ensure thread safety when reading from unusedStreams.

The read lock is correctly used to ensure thread safety when accessing unusedStreams.


61-61: Confirm the correctness of deleting the "UNKNOWN" entry.

Deleting the "UNKNOWN" entry from the unusedStreams map helps prevent potential memory leaks or stale references, enhancing the cleanup process.

storage/localstate_mgr.go (1)

116-119: Ensure thread safety when accessing keyGenState.

The introduction of read locks around the access to the keyGenState map helps prevent race conditions when multiple goroutines access the shared state concurrently, enhancing concurrency control.

Copy link

@swift1337 swift1337 left a comment

Choose a reason for hiding this comment

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

LGTM; at the same time I agree with @fbac that closing a stream in a consumer is not a good idea, however it's not your choice per se (but a rebasing thing)

@gartnera gartnera merged commit 9f5ae81 into master Jul 29, 2024
6 checks passed
@gartnera gartnera deleted the add-testing branch July 29, 2024 19:54
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.

3 participants