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

[Relayminer] refactor: relayerSessionsManager#waitForBlock() #648

Merged
merged 30 commits into from
Jul 12, 2024

Conversation

bryanchriswhite
Copy link
Contributor

@bryanchriswhite bryanchriswhite commented Jul 2, 2024

Summary

  • Refactor relayerSessionsManager#waitForBlock() to use replayObservable#SubscribeFromLatestBufferedOffset() to ensure that the awaited height is contained in block clients replay buffer.
  • Reduce (possibly eliminate) flakiness of TestRelayerSessionsManager_Start() by slowing it down.

Issue

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Testing

Documentation changes (only if making doc changes)

  • make docusaurus_start; only needed if you make doc changes

Local Testing (only if making code changes)

  • Unit Tests: make go_develop_and_test
  • LocalNet E2E Tests: make test_e2e
  • See quickstart guide for instructions

PR Testing (only if making code changes)

  • DevNet E2E Tests: Add the devnet-test-e2e label to the PR.
    • THIS IS VERY EXPENSIVE, so only do it after all the reviews are complete.
    • Optionally run make trigger_ci if you want to re-trigger tests without any code changes
    • If tests fail, try re-running failed tests only using the GitHub UI as shown here

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

Summary by CodeRabbit

  • New Features

    • Introduced a method to retrieve the current number of elements in the replay buffer.
  • Bug Fixes

    • Added checks for nil values in claimsWindowOpenBlock and proofsWindowOpenBlock to trigger appropriate warning messages and avoid errors.
  • Refactor

    • Renamed replayBufferSize to replayBufferCap for improved clarity across the codebase.
    • Updated function parameter names and logic to enhance readability and maintain consistency.
  • Tests

    • Enhanced test coverage by adding cases and adjusting parameters to simulate asynchronous processing and block observation scenarios effectively.

@bryanchriswhite bryanchriswhite added bug Something isn't working relayminer Changes related to the Relayminer devnet-test-e2e labels Jul 2, 2024
@bryanchriswhite bryanchriswhite self-assigned this Jul 2, 2024
Copy link

coderabbitai bot commented Jul 2, 2024

Walkthrough

The changes primarily involve renaming a parameter related to buffer capacity across multiple files for clarity and consistency. Additionally, there are updates to handle nil cases in relayer sessions and enhancements in test cases to improve coverage and reliability.

Changes

Files Change Summary
pkg/observable/channel/map.go, pkg/observable/channel/replay.go, pkg/observable/channel/replay_test.go, pkg/observable/interface.go Renamed replayBufferSize to replayBufferCap to clarify its role as a capacity limit. Added GetReplayBufferSize method for buffer size retrieval.
pkg/relayer/session/claim.go Added checks for nil claimsWindowOpenBlock, with warning logs and signals.
pkg/relayer/session/proof.go Added handling for nil proofsWindowOpenBlock, with warning logs.
pkg/relayer/session/session.go Renamed height to targetHeight in waitForBlock function and included logic to check replay buffer size.
pkg/relayer/session/session_test.go Enhanced test cases with additional scenarios, asynchronous processing simulations, and clearer comments.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Observable
    participant RelayerSessionsManager

    Client->>Observable: Call MapReplay with replayBufferCap
    Observable->>Observable: Store replayBufferCap
    Observable->>Client: Return ReplayObservable

    Client->>RelayerSessionsManager: Trigger claim creation
    RelayerSessionsManager->>RelayerSessionsManager: Check claimsWindowOpenBlock
    alt claimsWindowOpenBlock is nil
        RelayerSessionsManager->>Client: Log warning and send signal
    else claimsWindowOpenBlock is valid
        RelayerSessionsManager->>Client: Process claim
    end

    Client->>RelayerSessionsManager: Trigger proof creation
    RelayerSessionsManager->>RelayerSessionsManager: Check proofsWindowOpenBlock
    alt proofsWindowOpenBlock is nil
        RelayerSessionsManager->>Client: Log warning and handle failure
    else proofsWindowOpenBlock is valid
        RelayerSessionsManager->>Client: Process proof
    end
Loading

Poem

In the code where buffers play,
A cap now guides the replay.
Claims and proofs with care proceed,
Ensuring checks in time of need.
Tests enhanced and names refined,
In this update, greatness defined.
Hopping forward, code aligned!


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

github-actions bot commented Jul 2, 2024

The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.

You may need to run make trigger_ci to submit an empty commit that'll trigger the tests.

GCP workloads (requires changing the namespace to 648)
Grafana network dashboard for devnet-issue-{issue-id}

@github-actions github-actions bot added devnet push-image CI related - pushes images to ghcr.io labels Jul 2, 2024
@bryanchriswhite bryanchriswhite linked an issue Jul 2, 2024 that may be closed by this pull request
6 tasks
@bryanchriswhite bryanchriswhite marked this pull request as ready for review July 2, 2024 12:47
@bryanchriswhite bryanchriswhite marked this pull request as draft July 2, 2024 12:57
@bryanchriswhite bryanchriswhite force-pushed the issues/553/fix/relayer-session-manager branch from a3fb7b3 to ed9f13e Compare July 2, 2024 13:45
@bryanchriswhite bryanchriswhite marked this pull request as ready for review July 2, 2024 13:46
@bryanchriswhite bryanchriswhite marked this pull request as draft July 4, 2024 07:41
@bryanchriswhite bryanchriswhite marked this pull request as ready for review July 4, 2024 07:58
…elayer-session-manager

* issues/553/fix/replay-observable:
  fix: failing tests
bryanchriswhite and others added 9 commits July 5, 2024 23:38
Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
Co-authored-by: Daniel Olshansky <olshansky.daniel@gmail.com>
…elayer-session-manager

* issues/553/fix/replay-observable:
  chore: go imports
  chore: update comment
  chore: update comment
  chore: review feedback improvements
  [Relayminer] refactor: query `min_relay_difficulty_bits` param (#655)
  [Docs] Claim expiration (#649)
  [LoadTest] Passing non-existing plans variable (#661)
  Tiny: updating labels in tiltfile
  [Load Testing] fix: relay stress test duration calculation (#651)
  [LocalNet] Grafana stress test dashboard changes (#641)
@bryanchriswhite bryanchriswhite requested a review from Olshansk July 6, 2024 09:32
Copy link
Contributor

@red-0ne red-0ne left a comment

Choose a reason for hiding this comment

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

Small NIT, otherwise LGTM.

pkg/relayer/session/session.go Outdated Show resolved Hide resolved
@bryanchriswhite bryanchriswhite changed the base branch from issues/553/fix/replay-observable to main July 12, 2024 07:12
…session-manager

* pokt/main:
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
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: 1

Outside diff range, codebase verification and nitpick comments (1)
pkg/relayer/session/session_test.go (1)

164-168: Consider centralizing the sleep duration in waitSimulateIO.

The sleep duration of 50 milliseconds is hardcoded. Consider centralizing it in a local constant or function for better maintainability and readability.

-  time.Sleep(50 * time.Millisecond)
+  const sleepDuration = 50 * time.Millisecond
+  time.Sleep(sleepDuration)
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 208a228 and c6966ec.

Files selected for processing (8)
  • pkg/observable/channel/map.go (1 hunks)
  • pkg/observable/channel/replay.go (7 hunks)
  • pkg/observable/channel/replay_test.go (8 hunks)
  • pkg/observable/interface.go (1 hunks)
  • pkg/relayer/session/claim.go (1 hunks)
  • pkg/relayer/session/proof.go (1 hunks)
  • pkg/relayer/session/session.go (1 hunks)
  • pkg/relayer/session/session_test.go (4 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/observable/interface.go
Additional context used
GitHub Check: misspell
pkg/relayer/session/proof.go

[warning] 106-106: [misspell] pkg/relayer/session/proof.go#L106
"whic" is a misspelling of "which"

Additional comments not posted (32)
pkg/observable/channel/map.go (2)

71-75: The changes look good!

The function parameter has been correctly renamed to replayBufferCap, and the logic is consistent with the intended functionality.


67-68: Update the parameter name in the function signature.

The parameter name in the comment has been updated to replayBufferCap, but the function parameter itself should also be updated to maintain consistency.

- // The resulting observable will receive the last replayBufferCap
+ // The resulting observable will receive the last replayBufferSize

Likely invalid or redundant comment.

pkg/relayer/session/session_test.go (11)

53-53: The changes look good!

The setup for the dependencies in the TestRelayerSessionsManager_Start function is correctly implemented.


103-105: The changes look good!

The wait for the relayer sessions manager to start is correctly implemented using waitSimulateIO.


110-111: The changes look good!

The wait for the relayer sessions manager to create a session tree is correctly implemented using waitSimulateIO.


118-119: The changes look good!

The wait for the relayer sessions manager to process non-actionable blocks is correctly implemented using waitSimulateIO.


124-126: The changes look good!

The calculation and emission of the claim window open height are correctly implemented.


132-134: The changes look good!

The emission of the claim open height block to the blockPublishCh is correctly implemented.


135-136: The changes look good!

The wait for the relayer sessions manager to process the claim open height block is correctly implemented using waitSimulateIO.


141-142: The changes look good!

The wait for the relayer sessions manager to process the trigger claim block is correctly implemented using waitSimulateIO.


145-148: The changes look good!

The calculation and emission of the proof window open height block are correctly implemented.


149-150: The changes look good!

The wait for the relayer sessions manager to process the proof window open height block is correctly implemented using waitSimulateIO.


161-162: The changes look good!

The wait for the relayer sessions manager to process the trigger proof block is correctly implemented using waitSimulateIO.

pkg/observable/channel/replay.go (8)

17-19: The changes look good!

The variable has been correctly renamed to replayBufferCap, and the comment is consistent with the new name.


32-40: The changes look good!

The parameter has been correctly renamed to replayBufferCap, and the logic is consistent with the intended functionality.


43-55: The changes look good!

The parameter has been correctly renamed to replayBufferCap, and the logic is consistent with the intended functionality.


73-77: The changes look good!

The parameter has been correctly renamed to replayBufferCap, and the warning log is consistent with the new name.


125-125: The changes look good!

The Subscribe method correctly uses the new SubscribeFromLatestBufferedOffset method with the replayBufferCap parameter.


Line range hint 134-147: The changes look good!

The SubscribeFromLatestBufferedOffset method is correctly implemented with the new parameter name replayBufferCap.


179-184: The changes look good!

The new GetReplayBufferSize method is correctly implemented and provides a useful utility for retrieving the current size of the replay buffer.


201-204: The changes look good!

The buffer management logic in the initBufferingObservable method is consistent with the new parameter name replayBufferCap.

pkg/relayer/session/claim.go (1)

116-125: Handle the case where claimsWindowOpenBlock is nil.

The added conditional block correctly handles the case where claimsWindowOpenBlock is nil, which ensures robustness in scenarios where the block is not observed.

pkg/relayer/session/proof.go (1)

104-116: Good handling of nil proofsWindowOpenBlock.

The added conditional block properly handles the edge case where the block might not be observed. The warning log and sending the session trees to a failure channel are appropriate actions.

Tools
GitHub Check: misspell

[warning] 106-106: [misspell] pkg/relayer/session/proof.go#L106
"whic" is a misspelling of "which"

pkg/observable/channel/replay_test.go (4)

66-67: Consistent variable naming.

The variable name replayBufferCap is consistent with the recent changes and improves clarity.


80-80: Correct usage of replayBufferCap.

The usage of replayBufferCap in channel.ToReplayObservable is correct and aligns with the recent changes.


153-154: Consistent initialization of test parameters.

The initialization of replayBufferCap and related test parameters is consistent with the recent changes.


310-311: Correct usage of replayBufferCap and endOffset in test cases.

The usage of replayBufferCap and endOffset in test cases is correct and aligns with the recent changes.

pkg/relayer/session/session.go (5)

314-346: Good handling of replay buffer size in waitForBlock.

The changes ensure that the target block is observed only if the replay buffer contains enough blocks. This prevents issues where the block might not be observed due to insufficient buffer size.


326-332: Informative comment on minNumReplayBlocks.

The comment provides clarity on the purpose of minNumReplayBlocks and the conditions under which the replay buffer is necessary.


334-343: Informative TODO comment on handling replay buffer size.

The TODO comment is informative and outlines the steps to be taken once the block query client is implemented.


344-346: Appropriate handling of insufficient replay buffer size.

The conditional block appropriately handles the case where the replay buffer size is insufficient to observe the target block.


348-351: Correct loop logic to observe target block.

The loop logic is correct and ensures that the function blocks until the target block is observed.

@@ -30,6 +30,8 @@ import (
sharedtypes "github.com/pokt-network/poktroll/x/shared/types"
)

// TODO_TEST: Add a test case which simulates a cold-started relayminer with unclaimed relays.
Copy link

Choose a reason for hiding this comment

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

Reminder: Add a test case for cold-started relayminer.

The TODO comment indicates that a test case for simulating a cold-started relayminer with unclaimed relays is missing.

Do you want me to generate the unit testing code or open a GitHub issue to track this task?

@bryanchriswhite bryanchriswhite dismissed Olshansk’s stale review July 12, 2024 11:12

Comments addressed

@bryanchriswhite
Copy link
Contributor Author

bryanchriswhite commented Jul 12, 2024

E2E tests passing locally but failed to run in CI:

image

Prior run failed:

image

@bryanchriswhite bryanchriswhite merged commit 0ba2f5c into main Jul 12, 2024
9 of 10 checks passed
@bryanchriswhite bryanchriswhite deleted the issues/553/fix/relayer-session-manager branch July 12, 2024 11:15
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ent-balances

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ation-overserviced

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
bryanchriswhite added a commit that referenced this pull request Jul 15, 2024
…ation-use-index

* pokt/main:
  [TODOs] refactor: proof path calculation (#659)
  [Dependencies] bump go-getter and ibc-go (#691)
  [Relayminer] refactor: `relayerSessionsManager#waitForBlock()` (#648)
  [Observables] chore: add `ReplayObservable#SubscribeFromLatestBufferedOffset()` (#647)
  [Observability] Add claim relays counter (#644)
  [Code Health] chore: log unused error when updating relay mining difficulty (#683)
  [Testing] chore: uncomment proof CLI query tests (#668)
  build(deps): bump ws from 7.5.9 to 7.5.10 in /docusaurus (#686)
  build(deps): bump webpack-dev-middleware from 5.3.3 to 5.3.4 in /docusaurus (#688)
  build(deps): bump express from 4.18.2 to 4.19.2 in /docusaurus (#687)
  build(deps): bump follow-redirects from 1.15.3 to 1.15.6 in /docusaurus (#685)
  build(deps): bump braces from 3.0.2 to 3.0.3 in /docusaurus (#689)
  [CosmosSDK] Bump to v0.50.7 (#682)
okdas pushed a commit that referenced this pull request Nov 14, 2024
Co-authored-by: Redouane Lakrache <r3d0ne@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working devnet devnet-test-e2e push-image CI related - pushes images to ghcr.io relayminer Changes related to the Relayminer
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[Relayminer] Add ReplayObservable#SubscribeFromBufferEndOffset() method
3 participants