This commit is contained in:
Eric 2024-06-27 17:34:17 +10:00
parent 700ef5cd6f
commit 1dce3805cd
No known key found for this signature in database
2 changed files with 4 additions and 7 deletions

View File

@ -435,17 +435,14 @@ proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) =
# prevent underflow
if tolerance > nodes:
return RestApiResponse.error(Http400, "Tolerance cannot be greater than nodes")
return RestApiResponse.error(Http400, "Invalid parameters: `tolerance` cannot be greater than `nodes`")
let ecK = nodes - tolerance
let ecM = tolerance # for readability
echo "ecK: ", ecK
echo "ecM: ", ecM
echo "ecK <= 1 or ecK < ecM: ", ecK <= 1 or ecK < ecM
# ensure leopard constrainst of 1 < K ≥ M
if ecK <= 1 or ecK < ecM:
return RestApiResponse.error(Http400, "Invalid erasure coding parameters. Parameters must satify `1 < (nodes - tolerance) ≥ tolerance`")
return RestApiResponse.error(Http400, "Invalid parameters: parameters must satify `1 < (nodes - tolerance) ≥ tolerance`")
without expiry =? params.expiry:
return RestApiResponse.error(Http400, "Expiry required")

View File

@ -78,7 +78,7 @@ twonodessuite "REST API", debug1 = false, debug2 = false:
tolerance.uint)
check responseBefore.status == "400 Bad Request"
check responseBefore.body == "Invalid erasure coding parameters. Parameters must satify `1 < (nodes - tolerance) ≥ tolerance`"
check responseBefore.body == "Invalid parameters: parameters must satify `1 < (nodes - tolerance) ≥ tolerance`"
test "request storage fails if tolerance > nodes (underflow protection)":
let data = await RandomChunker.example(blocks=2)
@ -103,7 +103,7 @@ twonodessuite "REST API", debug1 = false, debug2 = false:
tolerance.uint)
check responseBefore.status == "400 Bad Request"
check responseBefore.body == "Tolerance cannot be greater than nodes"
check responseBefore.body == "Invalid parameters: `tolerance` cannot be greater than `nodes`"
test "request storage succeeds if nodes and tolerance within range":
let data = await RandomChunker.example(blocks=2)