fix(pstoreds): Fix cyclic batch threshold handling and add error checking for peer ID decoding #3274
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.
Summary
This pull request improves robustness and correctness in the
pstoreds
package by:cyclicBatch
threshold initialization that could cause unintended immediate commits.uniquePeerIds
to skip invalid datastore entries instead of causing potential panics.uniquePeerIds
.Changes
threshold
field innewCyclicBatch
.base32.RawStdEncoding.DecodeString
andpeer.IDFromBytes
when extracting peer IDs.cyclic_batch_test.go
with a test verifying that batching only happens after the configured threshold is reached.peerstore_test.go
with a test verifying that invalid datastore entries are gracefully skipped inuniquePeerIds
.Motivation
Robust error handling and correct thresholding are critical in persistent peerstore operations to ensure system stability, especially under datastore corruption scenarios or large-scale peer management.
Adding unit tests ensures that regressions in these critical code paths are less likely to occur in the future.
Testing
All new unit tests pass:
go test ./p2p/host/peerstore/pstoreds/...
No regressions in existing functionality.