mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-04 22:43:12 +00:00
Add until parameter
This commit is contained in:
parent
26079af3d4
commit
ff9b01a640
@ -49,6 +49,32 @@ logScope:
|
||||
declareCounter(codex_api_uploads, "codex API uploads")
|
||||
declareCounter(codex_api_downloads, "codex API downloads")
|
||||
|
||||
proc getLongestRequestEnd(
|
||||
node: CodexNodeRef, availabilityId: AvailabilityId
|
||||
): Future[?!SecondsSince1970] {.async: (raises: []).} =
|
||||
without contracts =? node.contracts.host:
|
||||
return failure("Sales unavailable")
|
||||
|
||||
let
|
||||
reservations = contracts.sales.context.reservations
|
||||
market = contracts.sales.context.market
|
||||
|
||||
try:
|
||||
without allReservations =? await reservations.all(Reservation, availabilityId):
|
||||
return failure("Cannot retrieve the reservations")
|
||||
|
||||
echo "all reservations is done"
|
||||
let requestEnds = allReservations.mapIt(await market.getRequestEnd(it.requestId))
|
||||
|
||||
if len(requestEnds) == 0:
|
||||
return success(0.SecondsSince1970)
|
||||
|
||||
return success(requestEnds.max)
|
||||
except CancelledError, CatchableError:
|
||||
error "Error when trying to get longest request end",
|
||||
error = getCurrentExceptionMsg()
|
||||
return failure("Cannot retrieve the request dates")
|
||||
|
||||
proc validate(pattern: string, value: string): int {.gcsafe, raises: [Defect].} =
|
||||
0
|
||||
|
||||
|
||||
@ -708,14 +708,14 @@ proc findAvailability*(
|
||||
let endTime = getTime().toUnix() + cast[int64](duration)
|
||||
for item in storables.items:
|
||||
if bytes =? (await item) and availability =? Availability.fromJson(bytes):
|
||||
if availability.enabled and size <= availability.freeSize and
|
||||
duration <= availability.duration and
|
||||
let enabled = availability.enabled
|
||||
if enabled and size <= availability.freeSize and duration <= availability.duration and
|
||||
collateralPerByte <= availability.maxCollateralPerByte and
|
||||
pricePerBytePerSecond >= availability.minPricePerBytePerSecond and
|
||||
(availability.until == 0 or availability.until >= endTime):
|
||||
trace "availability matched",
|
||||
id = availability.id,
|
||||
enabled = availability.enabled,
|
||||
enabled = enabled,
|
||||
size,
|
||||
availFreeSize = availability.freeSize,
|
||||
duration,
|
||||
|
||||
@ -448,7 +448,7 @@ asyncchecksuite "Sales":
|
||||
|
||||
var storingRequest: StorageRequest
|
||||
sales.onStore = proc(
|
||||
request: StorageRequest, slot: UInt256, onBatch: BatchProc
|
||||
request: StorageRequest, slot: uint64, onBatch: BatchProc
|
||||
): Future[?!void] {.async.} =
|
||||
storingRequest = request
|
||||
return success()
|
||||
|
||||
@ -33,7 +33,7 @@ twonodessuite "REST API":
|
||||
duration = 2.uint64,
|
||||
minPricePerBytePerSecond = minPricePerBytePerSecond,
|
||||
totalCollateral = totalCollateral,
|
||||
enabled = true.some,
|
||||
enabled = true,
|
||||
).get
|
||||
let space = client1.space().tryGet()
|
||||
check:
|
||||
@ -42,19 +42,6 @@ twonodessuite "REST API":
|
||||
space.quotaUsedBytes == 65592.NBytes
|
||||
space.quotaReservedBytes == 12.NBytes
|
||||
|
||||
test "created correctly an availability when not enabled by default", twoNodesConfig:
|
||||
let totalSize = 12.u256
|
||||
let minPricePerBytePerSecond = 1.u256
|
||||
let totalCollateral = totalSize * minPricePerBytePerSecond
|
||||
let availability = client1.postAvailability(
|
||||
totalSize = totalSize,
|
||||
duration = 2.u256,
|
||||
minPricePerBytePerSecond = minPricePerBytePerSecond,
|
||||
totalCollateral = totalCollateral,
|
||||
enabled = false.some,
|
||||
).get
|
||||
check availability.enabled == false
|
||||
|
||||
test "node lists local files", twoNodesConfig:
|
||||
let content1 = "some file contents"
|
||||
let content2 = "some other contents"
|
||||
|
||||
@ -145,7 +145,21 @@ multinodesuite "Sales":
|
||||
).get
|
||||
host.patchAvailability(availability.id, enabled = false.some)
|
||||
let updatedAvailability = (host.getAvailabilities().get).findItem(availability).get
|
||||
check updatedAvailability.enabled == false
|
||||
check updatedAvailability.enabled == false.some
|
||||
|
||||
test "updating availability - updating until", salesConfig:
|
||||
var until = cast[SecondsSince1970](getTime().toUnix())
|
||||
let availability = host.postAvailability(
|
||||
totalSize = 140000.u256,
|
||||
duration = 200.u256,
|
||||
minPricePerBytePerSecond = 3.u256,
|
||||
totalCollateral = 300.u256,
|
||||
until = until.some,
|
||||
).get
|
||||
until += 10.SecondsSince1970
|
||||
host.patchAvailability(availability.id, until = until.some)
|
||||
let updatedAvailability = (host.getAvailabilities().get).findItem(availability).get
|
||||
check updatedAvailability.until == until
|
||||
|
||||
test "updating availability - updating totalSize does not allow bellow utilized",
|
||||
salesConfig:
|
||||
@ -189,3 +203,19 @@ multinodesuite "Sales":
|
||||
(host.getAvailabilities().get).findItem(availability).get
|
||||
check newUpdatedAvailability.totalSize == originalSize + 20000
|
||||
check newUpdatedAvailability.freeSize - updatedAvailability.freeSize == 20000
|
||||
|
||||
test "updating availability fails with until negative", salesConfig:
|
||||
let availability = host.postAvailability(
|
||||
totalSize = 140000.u256,
|
||||
duration = 200.u256,
|
||||
minPricePerBytePerSecond = 3.u256,
|
||||
totalCollateral = 300.u256,
|
||||
).get
|
||||
|
||||
let response = host.patchAvailabilityRaw(
|
||||
availability.id, until = cast[SecondsSince1970](-1).some
|
||||
)
|
||||
|
||||
check:
|
||||
response.status == "400 Bad Request"
|
||||
response.body == "Until parameter must be greater or equal 0. Got: -1"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user