@@ -1160,19 +1160,28 @@ func (as *accountSet) add(addr common.Address) {
1160
1160
as .accounts [addr ] = struct {}{}
1161
1161
}
1162
1162
1163
- // txLookup is used to track all transactions to allow lookups without contention
1163
+ // txLookup is used internally by TxPool to track transactions while allowing lookup without
1164
+ // mutex contention.
1165
+ //
1166
+ // Note, although this type is properly protected against concurrent access, it
1167
+ // is **not** a type that should ever be mutated or even exposed outside of the
1168
+ // transaction pool, since its internal state is tightly coupled with the pools
1169
+ // internal mechanisms. The sole purpose of the type is to permit out-of-bound
1170
+ // peeking into the pool in TxPool.Get without having to acquire the widely scoped
1171
+ // TxPool.mu mutex.
1164
1172
type txLookup struct {
1165
1173
all map [common.Hash ]* types.Transaction
1166
1174
lock sync.RWMutex
1167
1175
}
1168
1176
1177
+ // newTxLookup returns a new txLookup structure.
1169
1178
func newTxLookup () * txLookup {
1170
1179
return & txLookup {
1171
1180
all : make (map [common.Hash ]* types.Transaction ),
1172
1181
}
1173
1182
}
1174
1183
1175
- // calls f on each key and value present in the map
1184
+ // Range calls f on each key and value present in the map.
1176
1185
func (t * txLookup ) Range (f func (hash common.Hash , tx * types.Transaction ) bool ) {
1177
1186
t .lock .RLock ()
1178
1187
defer t .lock .RUnlock ()
@@ -1184,40 +1193,31 @@ func (t *txLookup) Range(f func(hash common.Hash, tx *types.Transaction) bool) {
1184
1193
}
1185
1194
}
1186
1195
1187
- // returns a transaction if it exists in the lookup, or nil if not found
1196
+ // Get returns a transaction if it exists in the lookup, or nil if not found.
1188
1197
func (t * txLookup ) Get (hash common.Hash ) * types.Transaction {
1189
1198
t .lock .RLock ()
1190
1199
defer t .lock .RUnlock ()
1191
1200
1192
1201
return t .all [hash ]
1193
1202
}
1194
1203
1195
- // returns a transaction if it exists in the lookup, and a bool indicating if it was found
1196
- func (t * txLookup ) Find (hash common.Hash ) (* types.Transaction , bool ) {
1197
- t .lock .RLock ()
1198
- defer t .lock .RUnlock ()
1199
-
1200
- value , ok := t .all [hash ]
1201
- return value , ok
1202
- }
1203
-
1204
- // returns the current number of items in the lookup
1204
+ // Count returns the current number of items in the lookup.
1205
1205
func (t * txLookup ) Count () int {
1206
1206
t .lock .RLock ()
1207
1207
defer t .lock .RUnlock ()
1208
1208
1209
1209
return len (t .all )
1210
1210
}
1211
1211
1212
- // add a transaction to the lookup
1212
+ // Add adds a transaction to the lookup.
1213
1213
func (t * txLookup ) Add (tx * types.Transaction ) {
1214
1214
t .lock .Lock ()
1215
1215
defer t .lock .Unlock ()
1216
1216
1217
1217
t .all [tx .Hash ()] = tx
1218
1218
}
1219
1219
1220
- // remove a transaction from the lookup
1220
+ // Remove removes a transaction from the lookup.
1221
1221
func (t * txLookup ) Remove (hash common.Hash ) {
1222
1222
t .lock .Lock ()
1223
1223
defer t .lock .Unlock ()
0 commit comments