-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement sender and receiver policies based on v1 result codes #514
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
Merged
b-garbacz
merged 11 commits into
improve-networking-layer-v2
from
491-implement-sender-polices-based-on-v1-resultcodes
Mar 6, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
46232c5
feat: align v1 result codes and error handling
leonardostsouza 4574a81
refactor: implement custom errors for ConnectionManager
leonardostsouza f725161
feat: update MessageOrchestrator retries and validator selection
leonardostsouza d4fb69a
feat: add transaction RPC helpers
leonardostsouza 0220937
refactor: rewrite message broadcast failure messages
leonardostsouza ab174e5
fix: Improve unstable acceptance tests
b-garbacz 816a835
test: enhance account endpoint tests to handle internal errors
b-garbacz 1539e01
doc: update sendSingleMessage method documentation for clarity and de…
b-garbacz 8ba1efc
refactor: rename result variable to success for clarity in MessageOrc…
b-garbacz a8196da
refactor(network): replace ResultCodePolicy with connectionPolicies a…
b-garbacz 9e91537
refactor: remove unused imports in ConnectionManager and V1LivenessOp…
b-garbacz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import { ResultCode } from '../../../utils/constants.js'; | ||
|
|
||
| // TODO: Consider how to behave with ResultCode.UNSPECIFIED | ||
|
|
||
| export const SENDER_ACTION = Object.freeze({ | ||
| UNDEFINED: 'UNDEFINED', | ||
| SUCCESS: 'SUCCESS', | ||
| ROTATE: 'ROTATE', | ||
| NO_ROTATE: 'NO_ROTATE', | ||
| }); | ||
|
|
||
| const SUCCESS_CODES = new Set([ | ||
| ResultCode.OK, | ||
| ]); | ||
|
|
||
| const ROTATE_CODES = new Set([ | ||
| ResultCode.UNSPECIFIED, | ||
| ResultCode.INVALID_PAYLOAD, | ||
| ResultCode.RATE_LIMITED, | ||
| ResultCode.SIGNATURE_INVALID, | ||
| ResultCode.UNEXPECTED_ERROR, | ||
| ResultCode.TIMEOUT, | ||
| ResultCode.NODE_HAS_NO_WRITE_ACCESS, | ||
| ResultCode.TX_ACCEPTED_PROOF_UNAVAILABLE, | ||
| ResultCode.NODE_OVERLOADED, | ||
| ResultCode.OPERATION_TYPE_UNKNOWN, | ||
| ResultCode.SCHEMA_VALIDATION_FAILED, | ||
| ResultCode.REQUESTER_ADDRESS_INVALID, | ||
| ResultCode.REQUESTER_PUBLIC_KEY_INVALID, | ||
| ResultCode.TX_HASH_MISMATCH, | ||
| ResultCode.TX_SIGNATURE_INVALID, | ||
| ResultCode.TX_EXPIRED, | ||
| ResultCode.TX_ALREADY_EXISTS, | ||
| ResultCode.OPERATION_ALREADY_COMPLETED, | ||
| ResultCode.REQUESTER_NOT_FOUND, | ||
| ResultCode.INSUFFICIENT_FEE_BALANCE, | ||
| ResultCode.EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP, | ||
| ResultCode.SELF_VALIDATION_FORBIDDEN, | ||
| ResultCode.ROLE_NODE_ENTRY_NOT_FOUND, | ||
| ResultCode.ROLE_NODE_ALREADY_WRITER, | ||
| ResultCode.ROLE_NODE_NOT_WHITELISTED, | ||
| ResultCode.ROLE_NODE_NOT_WRITER, | ||
| ResultCode.ROLE_NODE_IS_INDEXER, | ||
| ResultCode.ROLE_ADMIN_ENTRY_MISSING, | ||
| ResultCode.ROLE_INVALID_RECOVERY_CASE, | ||
| ResultCode.ROLE_UNKNOWN_OPERATION, | ||
| ResultCode.ROLE_INVALID_WRITER_KEY, | ||
| ResultCode.ROLE_INSUFFICIENT_FEE_BALANCE, | ||
| ResultCode.MSB_BOOTSTRAP_MISMATCH, | ||
| ResultCode.EXTERNAL_BOOTSTRAP_NOT_DEPLOYED, | ||
| ResultCode.EXTERNAL_BOOTSTRAP_TX_MISSING, | ||
| ResultCode.EXTERNAL_BOOTSTRAP_MISMATCH, | ||
| ResultCode.BOOTSTRAP_ALREADY_EXISTS, | ||
| ResultCode.TRANSFER_RECIPIENT_ADDRESS_INVALID, | ||
| ResultCode.TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID, | ||
| ResultCode.TRANSFER_AMOUNT_TOO_LARGE, | ||
| ResultCode.TRANSFER_SENDER_NOT_FOUND, | ||
| ResultCode.TRANSFER_INSUFFICIENT_BALANCE, | ||
| ResultCode.TRANSFER_RECIPIENT_BALANCE_OVERFLOW, | ||
| ResultCode.TX_HASH_INVALID_FORMAT, | ||
| ResultCode.INTERNAL_ENQUEUE_VALIDATION_FAILED, | ||
| ResultCode.TX_COMMITTED_RECEIPT_MISSING, | ||
| ResultCode.VALIDATOR_RESPONSE_TX_TYPE_INVALID, | ||
| ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN, | ||
| ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED, | ||
| ResultCode.VALIDATOR_RESPONSE_SCHEMA_INVALID, | ||
| ResultCode.PENDING_REQUEST_MISSING_TX_DATA, | ||
| ResultCode.PROOF_PAYLOAD_MISMATCH, | ||
| ResultCode.VALIDATOR_WRITER_KEY_NOT_REGISTERED, | ||
| ResultCode.VALIDATOR_ADDRESS_MISMATCH, | ||
| ResultCode.VALIDATOR_NODE_ENTRY_NOT_FOUND, | ||
| ResultCode.VALIDATOR_NODE_NOT_WRITER, | ||
| ResultCode.VALIDATOR_WRITER_KEY_MISMATCH, | ||
| ResultCode.VALIDATOR_TX_OBJECT_INVALID, | ||
| ResultCode.VALIDATOR_VA_MISSING, | ||
| ResultCode.TX_INVALID_PAYLOAD | ||
| ]); | ||
|
|
||
| const NO_ROTATE_CODES = new Set([ | ||
| ResultCode.TX_ALREADY_PENDING, | ||
| ]); | ||
|
|
||
| export function resultToValidatorAction(resultCode) { | ||
| if (SUCCESS_CODES.has(resultCode)) return SENDER_ACTION.SUCCESS; | ||
| if (ROTATE_CODES.has(resultCode)) return SENDER_ACTION.ROTATE; | ||
| if (NO_ROTATE_CODES.has(resultCode)) return SENDER_ACTION.NO_ROTATE; | ||
| return SENDER_ACTION.UNDEFINED; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if this line disappeared. Cant you just remove the flag from the Error? In general, that is also not great in terms of design. Exceptions (or things that throw) are done in a pub-sub design. That means that the emitter should work as broadcast and the observer (subscriber) should know how to handle those accordingly. If you pass a behavior flag, you are making it so the emitter know the behavior of the subscriber beforehand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could maybe check the result codes here and decide whether to close the connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so the plan is to create a new module that defines the behavior based on
V1ProtocolError, in a similar way toResultCodePolicy.jsIt would be even better to rename that file toResultCodesPolicies.js.In that module, we would have:
It will have one big benefit - centralizing all policies into a single file.
@leonardotc @jusufsuljic @leonardostsouza I’m going to merge the current PR as is, and then create a followup issue to refactor it in this direction.