You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add timeout constants for ChainSync, BlockFetch, TxSubmission, Handshake,
and Keepalive protocols to prevent resource leaks. Values based on
Ouroboros Network Specification with comprehensive unit tests.
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
-`protocol/txsubmission/client.go` - Added received count validation
64
85
86
+
### Handshake Protocol
87
+
88
+
**State timeout constants:**
89
+
-`ProposeTimeout = 5s` - Timeout for client to propose protocol version
90
+
-`ConfirmTimeout = 5s` - Timeout for server to confirm or refuse version
91
+
92
+
**Files modified:**
93
+
-`protocol/handshake/handshake.go` - Added timeout constants and StateMap integration
94
+
95
+
### Keepalive Protocol
96
+
97
+
**State timeout constants:**
98
+
-`ClientTimeout = 60s` - Timeout for client to send keepalive request
99
+
-`ServerTimeout = 10s` - Timeout for server to respond to keepalive
100
+
101
+
**Files modified:**
102
+
-`protocol/keepalive/keepalive.go` - Added timeout constants and StateMap integration
103
+
65
104
## Protocol Violation Errors
66
105
67
106
**New error types defined in `protocol/error.go`:**
@@ -74,10 +113,16 @@ These errors cause connection termination as per the network specification.
74
113
75
114
## Other Mini-Protocols
76
115
77
-
The following protocols were evaluated and determined not to need additional queue limits:
78
-
-**KeepAlive** - Simple ping/pong protocol with minimal state
79
-
-**LocalStateQuery** - Request-response protocol with no pipelining
80
-
-**LocalTxSubmission** - Simple request-response for single transaction submission
116
+
All remaining protocols have appropriate timeout implementations:
117
+
118
+
-**LocalStateQuery** - Has AcquireTimeout (5s) and QueryTimeout (180s) for database queries
119
+
-**LocalTxMonitor** - Has AcquireTimeout (5s) and QueryTimeout (30s) for mempool monitoring
120
+
-**LocalTxSubmission** - Has Timeout (30s) for local transaction submission
121
+
-**PeerSharing** - Has Timeout (5s) for peer discovery requests
122
+
-**LeiosFetch** - Has Timeout (5s) for Leios block/transaction/vote fetching
123
+
-**LeiosNotify** - Has Timeout (60s) for Leios block/vote notifications
124
+
-**Handshake** - Has ProposeTimeout (5s) and ConfirmTimeout (5s) for protocol negotiation
125
+
-**Keepalive** - Has ClientTimeout (60s) and ServerTimeout (10s) for connection health
81
126
82
127
## Validation and Testing
83
128
@@ -86,19 +131,44 @@ The following protocols were evaluated and determined not to need additional que
86
131
- Tests configuration validation and panic behavior
87
132
- Verifies protocol violation errors are defined
88
133
- Ensures default values are reasonable and within limits
134
+
- Comprehensive timeout validation for all 11 mini-protocols
135
+
- Verifies StateMap entries use correct timeout constants
136
+
137
+
## Protocol State Timeouts
138
+
139
+
### Implementation
140
+
141
+
Each protocol state can define a timeout value that is enforced by the protocol framework. When a state transition takes too long, the connection is automatically terminated to prevent hanging connections and ensure protocol compliance.
142
+
143
+
### Timeout Values
144
+
145
+
The timeout values are based on the Ouroboros Network Specification and real-world network conditions:
146
+
147
+
-**Short timeouts (5-30s)**: For rapid protocol handshakes and responses
148
+
-**Medium timeouts (60-120s)**: For normal message exchanges and client requests
149
+
-**Long timeouts (300s)**: For waiting on new blocks or mempool queries
150
+
151
+
### Timeout Behavior
152
+
153
+
- Timeouts are set when entering a state with `StateMapEntry.Timeout > 0`
154
+
- If no state transition occurs within the timeout period, the protocol terminates
155
+
- Connection teardown includes proper error logging for debugging
156
+
- Terminal states (`AgencyNone`) do not have timeouts
89
157
90
158
## Behavior Changes
91
159
92
160
**Before:**
93
161
- No enforced limits on pipeline depth or queue sizes
94
162
- Potential for memory exhaustion from excessive pipelining
95
163
- No disconnect on protocol violations
164
+
- No state transition timeouts
96
165
97
166
**After:**
98
167
- Strict limits enforced as per network specification
99
168
- Automatic connection termination on limit violations
100
169
- Comprehensive logging of violations before disconnect
0 commit comments