Skip to content

Proto tx messages deduplicator#1728

Merged
alexeykiselev merged 8 commits into
masterfrom
proto-messages-filter
Jun 19, 2025
Merged

Proto tx messages deduplicator#1728
alexeykiselev merged 8 commits into
masterfrom
proto-messages-filter

Conversation

@nickeskov

@nickeskov nickeskov commented Jun 17, 2025

Copy link
Copy Markdown
Collaborator

This pull request introduces a message deduplication mechanism for peer.ProtoMessage objects, refactors message handling in the Node class, and adds tests to ensure the correctness of the new functionality. The changes aim to improve efficiency by filtering out duplicate transaction messages and simplifying the internal metrics tracking.

Message Deduplication and Filtering:

  • pkg/node/helpers.go: Added safeMap for thread-safe storage and deduplication of messages, and implemented deduplicateProtoMessages and deduplicateProtoTxMessages functions to filter duplicate transaction messages using a message ID filter based on its payloads. These functions ensure that only unique transaction messages are processed while bypassing non-transaction messages.

Refactoring in Node:

  • pkg/node/node.go: Updated the Run method to use the new deduplication mechanism (deduplicateProtoTxMessages) for processing peer.ProtoMessage objects. This refactor replaces chanLenProvider with aggregatedLenProvider for improved metrics tracking. [1] [2] [3]

Testing:

  • pkg/node/helpers_internal_test.go: Added unit tests for deduplicateProtoTxMessages to verify that duplicate transaction messages are filtered out while non-transaction messages remain unaffected. The tests use mock data and assertions to ensure correctness.

Minor Improvements:

  • pkg/p2p/peer/handle.go: Added a clarifying comment to explain the behavior of context cancellation in the Handle function.

@nickeskov nickeskov added wip This is a WIP, should not be merged right away do not merge The PR is not ready to be merged labels Jun 17, 2025
@nickeskov nickeskov force-pushed the proto-messages-filter branch from 70b60c8 to f68200d Compare June 19, 2025 12:53
@nickeskov nickeskov added enhancement New feature or request and removed wip This is a WIP, should not be merged right away do not merge The PR is not ready to be merged labels Jun 19, 2025
@nickeskov nickeskov changed the title Proto messages filter Proto tx messages filter Jun 19, 2025
@nickeskov nickeskov requested a review from Copilot June 19, 2025 12:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces a message deduplication mechanism for transaction-related proto messages, refactors message handling in the Node, and adds tests to ensure the correctness of the new behavior.

  • Introduces a thread‑safe map (safeMap) and payload filtering logic in pkg/node/helpers.go.
  • Updates the Node Run method in pkg/node/node.go to utilize the new deduplication mechanism.
  • Adds unit tests in pkg/node/helpers_internal_test.go to verify deduplication of duplicate transaction messages.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/p2p/peer/handle.go Added a clarifying comment regarding context cancellation.
pkg/node/node.go Refactored to use deduplicateProtoTxMessages and updated metrics.
pkg/node/helpers_internal_test.go Introduced unit tests for deduplication functionality.
pkg/node/helpers.go Implemented safeMap and deduplication support; potential issue noted.
Comments suppressed due to low confidence (1)

pkg/node/helpers.go:188

  • The 'max' function appears to be used without a definition or import. Please ensure that 'max' is defined or replace it with an appropriate alternative for determining the channel buffer size.
	filteredChan := make(chan protoMessageWrapper, max(cap(origMessageCh)-noFilteredChanSize, noFilteredChanSize))

@nickeskov nickeskov requested a review from alexeykiselev June 19, 2025 12:57
@nickeskov nickeskov changed the title Proto tx messages filter Proto tx messages deduplicator Jun 19, 2025
alexeykiselev
alexeykiselev previously approved these changes Jun 19, 2025
@alexeykiselev alexeykiselev merged commit bc6b4b8 into master Jun 19, 2025
23 of 25 checks passed
@alexeykiselev alexeykiselev deleted the proto-messages-filter branch June 19, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants