-
Notifications
You must be signed in to change notification settings - Fork 25
Description
π§© Intermediate Friendly
This issue is a good fit for contributors who are already familiar with the Hiero Swift SDK and feel comfortable navigating the codebase.
Intermediate Issues often involve:
- Exploring existing implementations
- Understanding how different components work together
- Making thoughtful changes that follow established patterns
The goal is to support deeper problem-solving while keeping the task clear, focused, and enjoyable to work on.
π Problem Description
The Client class has no way to configure how long a node remains excluded after experiencing errors. Currently, in Sources/Hiero/Client/NodeHealth.swift, the timing is hardcoded:
/// Duration to keep circuit open before testing recovery (5 minutes)
private static let circuitOpenDurationNanos: UInt64 = TimeInterval(5 * 60).nanosecondsOther Hiero SDKs (Java, Go, C++) provide configurable node readmit times:
getMinNodeReadmitTime()/setMinNodeReadmitTime()- Minimum time before reconsidering a failed nodegetMaxNodeReadmitTime()/setMaxNodeReadmitTime()- Maximum time a node can be excluded
This allows users to tune node recovery behavior based on their network conditions and reliability requirements.
Relevant files:
Sources/Hiero/Client/Client.swift- Main client classSources/Hiero/Client/NodeHealth.swift- Circuit breaker with hardcoded recovery durationSources/Hiero/Client/ConsensusNetwork.swift- Uses NodeHealth for node management
π‘ Expected Outcome
Add configurable node readmit time settings:
getMinNodeReadmitTime() -> TimeInterval- Returns the minimum readmit timesetMinNodeReadmitTime(_ time: TimeInterval)- Sets the minimum readmit timegetMaxNodeReadmitTime() -> TimeInterval- Returns the maximum readmit timesetMaxNodeReadmitTime(_ time: TimeInterval)- Sets the maximum readmit time
The implementation should:
- Replace the hardcoded
circuitOpenDurationNanoswith configurable values minNodeReadmitTimemaps to when unhealthy nodes can be reconsideredmaxNodeReadmitTimemaps to the circuit breaker recovery period- Store configuration in the Client
- Default to current behavior (reasonable defaults)
π§ Implementation Notes
Understanding the mapping:
In the Swift SDK's circuit breaker pattern:
- Unhealthy state: Node is temporarily excluded with exponential backoff
- Circuit open state: Node is excluded for a fixed recovery period (currently 5 minutes)
The readmit times in other SDKs map to:
minNodeReadmitTime: Initial/minimum backoff before retrying a failed nodemaxNodeReadmitTime: Maximum time before forcing a retry (circuit open duration)
Suggested approach:
-
Add private properties to
Client:private let _minNodeReadmitTime: NIOLockedValueBox<TimeInterval> private let _maxNodeReadmitTime: NIOLockedValueBox<TimeInterval>
-
Initialize with current defaults:
self._minNodeReadmitTime = .init(0.25) // 250ms (current initialBackoffInterval) self._maxNodeReadmitTime = .init(5 * 60) // 5 minutes (current circuitOpenDuration)
-
Add public getter/setter methods to
Client -
Modify
NodeHealthto accept these values instead of using hardcoded constants:- Pass values when creating
ConsensusNetwork - Or create a
NodeHealthConfigstruct
- Pass values when creating
-
Update
markUnhealthy()and circuit breaker logic to use the configured values
Key considerations:
- The
circuitOpenDurationNanosconstant needs to become configurable - Consider how this interacts with the existing backoff intervals
- Thread safety when values are changed at runtime
- Changes span
Client.swift,NodeHealth.swift, and possiblyConsensusNetwork.swift
Reference implementations:
- Java:
Client.getMinNodeReadmitTime()/setMinNodeReadmitTime(Duration)- stored in Network - Go:
Client.GetMinNodeReadmitTime()/SetMinNodeReadmitTime(Duration) - C++:
Client.getMinNodeReadmitTime()/setMinNodeReadmitTime(duration)
β Acceptance Criteria
To help get this change merged smoothly:
- Four methods added:
getMinNodeReadmitTime,setMinNodeReadmitTime,getMaxNodeReadmitTime,setMaxNodeReadmitTime - Hardcoded values in
NodeHealth.swiftreplaced with configurable values - Default behavior unchanged
- Follow existing project conventions
- Avoid breaking public APIs
- Include tests where appropriate
- Pass all CI checks
π Contribution Guide
To help your contribution go as smoothly as possible, we recommend following these steps:
- Comment
/assignto request the issue - Wait for assignment
- Fork the repository and create a branch
- Set up the project using the instructions in
README.md - Make the requested changes
- Sign each commit using
-s -S - Push your branch and open a pull request
Read Workflow Guide for step-by-step workflow guidance.
Read README.md for setup instructions.
β Pull requests cannot be merged without S and s signed commits.
See the Signing Guide.
π Additional Context or Resources
If you have questions, the community is happy to help:
https://discord.com/channels/905194001349627914/1337424839761465364
Useful files to review:
Sources/Hiero/Client/NodeHealth.swift- Circuit breaker implementationSources/Hiero/ExponentialBackoff.swift- Backoff algorithmSources/Hiero/Client/ConsensusNetwork.swift- How NodeHealth is used