Skip to content

cli, blockfetcher, statefetcher: migrate to searchv2 #3913

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

AliceInHunterland
Copy link
Contributor

@AliceInHunterland AliceInHunterland commented May 22, 2025

Close #3656
Close #3825
Close #3707

return 0, fmt.Errorf("no state object found")
}
s.lock.Lock()
s.lastStateObjectIndex = uint32(lastFoundIdx)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.Atoi
to a lower bit size type uint32 without an upper bound check.

Copilot Autofix

AI 3 days ago

To fix the issue, we need to ensure that the parsed integer (lastFoundIdx) is within the valid range for uint32 before performing the conversion. This can be achieved by adding explicit bounds checks using constants from the math package (math.MaxUint32 for the upper bound and 0 for the lower bound). If the value is out of range, the function should handle the error gracefully, such as by returning an error or a default value.

The changes will be made in the LatestStateObjectHeight function in the file pkg/services/statefetcher/statefetcher.go. Specifically:

  1. Add bounds checks for lastFoundIdx after parsing it with strconv.Atoi.
  2. If the value is out of range, return an appropriate error message.

Suggested changeset 1
pkg/services/statefetcher/statefetcher.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pkg/services/statefetcher/statefetcher.go b/pkg/services/statefetcher/statefetcher.go
--- a/pkg/services/statefetcher/statefetcher.go
+++ b/pkg/services/statefetcher/statefetcher.go
@@ -170,2 +170,7 @@
 	}
+	// Check bounds for uint32
+	if lastFoundIdx < 0 || lastFoundIdx > math.MaxUint32 {
+		s.isActive.CompareAndSwap(true, false)
+		return 0, fmt.Errorf("state object index out of range for uint32: %d", lastFoundIdx)
+	}
 	if lastFoundIdx == 0 || items[len(items)-1].ID.IsZero() {
EOF
@@ -170,2 +170,7 @@
}
// Check bounds for uint32
if lastFoundIdx < 0 || lastFoundIdx > math.MaxUint32 {
s.isActive.CompareAndSwap(true, false)
return 0, fmt.Errorf("state object index out of range for uint32: %d", lastFoundIdx)
}
if lastFoundIdx == 0 || items[len(items)-1].ID.IsZero() {
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link

codecov bot commented May 22, 2025

Codecov Report

Attention: Patch coverage is 3.67647% with 131 lines in your changes missing coverage. Please review.

Project coverage is 81.88%. Comparing base (92523bb) to head (78f762c).

Files with missing lines Patch % Lines
cli/util/upload_bin.go 2.08% 47 Missing ⚠️
pkg/services/statefetcher/statefetcher.go 0.00% 31 Missing ⚠️
pkg/services/helpers/neofs/neofs.go 0.00% 18 Missing ⚠️
cli/util/upload_state.go 0.00% 17 Missing ⚠️
pkg/services/blockfetcher/blockfetcher.go 0.00% 16 Missing ⚠️
cli/options/options.go 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3913      +/-   ##
==========================================
+ Coverage   81.78%   81.88%   +0.09%     
==========================================
  Files         345      345              
  Lines       48852    48809      -43     
==========================================
+ Hits        39954    39967      +13     
+ Misses       7229     7177      -52     
+ Partials     1669     1665       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roman-khimov
Copy link
Member

Rebase, please.

No need of additional PoolWrapper and loosing pool errors.

Signed-off-by: Ekaterina Pavlova <[email protected]>
Reverting c955c1e as nspcc-dev/neofs-node#2988 is fixed.

Close #3656

Signed-off-by: Ekaterina Pavlova <[email protected]>
Revert #3670. As NeoFS searchv2 result limit is 1000, the
DefaultSearchBatchSize could be little bit less to get full range with
one request, even if there are duplicates.

Close #3707

Signed-off-by: Ekaterina Pavlova <[email protected]>
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates several NeoFS-related modules—cli, blockfetcher, and statefetcher—to use the new SearchV2 API to address multiple issues. Key changes include refactoring the search and retrieval logic in statefetcher and blockfetcher, updating pool handling in multiple modules, and adjusting the index file and state upload workflows.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/services/statefetcher/statefetcher.go Updated LatestStateObjectHeight to use SearchV2 filters and type conversion.
pkg/services/helpers/neofs/neofs.go Changed the ObjectSearch API signature and adjusted error handling.
pkg/services/helpers/neofs/blockstorage.go Updated DefaultSearchBatchSize and changed PoolWrapper usage.
pkg/services/blockfetcher/blockfetcher.go Migrated object search and retrieval logic, using object IDs from SearchV2.
cli/util/upload_state.go Revised state object search logic with updated loop boundaries.
cli/util/upload_bin.go Updated pool usage and adjusted index file search and block upload logic.
cli/options/options.go Modified pool type handling in GetNeoFSClientPool.
Comments suppressed due to low confidence (3)

pkg/services/blockfetcher/blockfetcher.go:386

  • [nitpick] The condition 'if startIndex == startIndex+batchSize-1' is confusing; consider explicitly checking if batchSize equals 1 for improved readability.
if startIndex == startIndex+batchSize-1 {

pkg/services/helpers/neofs/blockstorage.go:32

  • [nitpick] Ensure that changing DefaultSearchBatchSize from 1 to 950 is based on performance benchmarks and that it does not inadvertently introduce duplicate object issues.
DefaultSearchBatchSize = 950

cli/util/upload_state.go:107

  • [nitpick] Verify that the adjustment of the starting index for uploading states (from stateObjCount to stateObjCount + 1) aligns with the intended off-by-one logic in the state upload process.
for state := stateObjCount + 1; state <= currentStateIndex; state++ {

@@ -126,6 +126,7 @@ func New(chain Ledger, cfg config.NeoFSStateFetcher, stateSyncInterval int, logg
return s, nil
}

// LatestStateObjectHeight returns the latest found in the container state object height.
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider rephrasing the doc comment for clarity. For example, "LatestStateObjectHeight returns the height of the most recent state object found in the container."

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants