[contracts] Replace size by slotSize
This commit is contained in:
parent
6ec2d3bf8f
commit
3a3d083345
|
@ -13,11 +13,11 @@ type
|
||||||
expiry*: UInt256
|
expiry*: UInt256
|
||||||
nonce*: array[32, byte]
|
nonce*: array[32, byte]
|
||||||
StorageAsk* = object
|
StorageAsk* = object
|
||||||
size*: UInt256
|
slots*: uint64
|
||||||
|
slotSize*: UInt256
|
||||||
duration*: UInt256
|
duration*: UInt256
|
||||||
proofProbability*: UInt256
|
proofProbability*: UInt256
|
||||||
reward*: UInt256
|
reward*: UInt256
|
||||||
slots*: uint64
|
|
||||||
StorageContent* = object
|
StorageContent* = object
|
||||||
cid*: string
|
cid*: string
|
||||||
erasure*: StorageErasure
|
erasure*: StorageErasure
|
||||||
|
@ -40,11 +40,11 @@ func fromTuple(_: type StorageRequest, tupl: tuple): StorageRequest =
|
||||||
|
|
||||||
func fromTuple(_: type StorageAsk, tupl: tuple): StorageAsk =
|
func fromTuple(_: type StorageAsk, tupl: tuple): StorageAsk =
|
||||||
StorageAsk(
|
StorageAsk(
|
||||||
size: tupl[0],
|
slots: tupl[0],
|
||||||
duration: tupl[1],
|
slotSize: tupl[1],
|
||||||
proofProbability: tupl[2],
|
duration: tupl[2],
|
||||||
reward: tupl[3],
|
proofProbability: tupl[3],
|
||||||
slots: tupl[4]
|
reward: tupl[4]
|
||||||
)
|
)
|
||||||
|
|
||||||
func fromTuple(_: type StorageContent, tupl: tuple): StorageContent =
|
func fromTuple(_: type StorageContent, tupl: tuple): StorageContent =
|
||||||
|
@ -135,3 +135,6 @@ func price*(ask: StorageAsk): UInt256 =
|
||||||
|
|
||||||
func price*(request: StorageRequest): UInt256 =
|
func price*(request: StorageRequest): UInt256 =
|
||||||
request.ask.price
|
request.ask.price
|
||||||
|
|
||||||
|
func size*(ask: StorageAsk): UInt256 =
|
||||||
|
ask.slots.u256 * ask.slotSize
|
||||||
|
|
|
@ -260,7 +260,8 @@ proc requestStorage*(self: CodexNodeRef,
|
||||||
|
|
||||||
let request = StorageRequest(
|
let request = StorageRequest(
|
||||||
ask: StorageAsk(
|
ask: StorageAsk(
|
||||||
size: encoded.size.u256,
|
slots: nodes + tolerance,
|
||||||
|
slotSize: (encoded.blockSize * encoded.steps).u256,
|
||||||
duration: duration,
|
duration: duration,
|
||||||
reward: reward
|
reward: reward
|
||||||
),
|
),
|
||||||
|
|
|
@ -95,7 +95,7 @@ func remove*(sales: Sales, availability: Availability) =
|
||||||
|
|
||||||
func findAvailability(sales: Sales, ask: StorageAsk): ?Availability =
|
func findAvailability(sales: Sales, ask: StorageAsk): ?Availability =
|
||||||
for availability in sales.available:
|
for availability in sales.available:
|
||||||
if ask.size <= availability.size and
|
if ask.slotSize <= availability.size and
|
||||||
ask.duration <= availability.duration and
|
ask.duration <= availability.duration and
|
||||||
ask.pricePerSlot >= availability.minPrice:
|
ask.pricePerSlot >= availability.minPrice:
|
||||||
return some availability
|
return some availability
|
||||||
|
|
|
@ -20,16 +20,19 @@ suite "Purchasing":
|
||||||
purchasing = Purchasing.new(market, clock)
|
purchasing = Purchasing.new(market, clock)
|
||||||
request = StorageRequest(
|
request = StorageRequest(
|
||||||
ask: StorageAsk(
|
ask: StorageAsk(
|
||||||
|
slots: uint8.example.uint64,
|
||||||
|
slotSize: uint32.example.u256,
|
||||||
duration: uint16.example.u256,
|
duration: uint16.example.u256,
|
||||||
size: uint32.example.u256,
|
reward: uint8.example.u256
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
test "submits a storage request when asked":
|
test "submits a storage request when asked":
|
||||||
discard purchasing.purchase(request)
|
discard purchasing.purchase(request)
|
||||||
let submitted = market.requested[0]
|
let submitted = market.requested[0]
|
||||||
|
check submitted.ask.slots == request.ask.slots
|
||||||
|
check submitted.ask.slotSize == request.ask.slotSize
|
||||||
check submitted.ask.duration == request.ask.duration
|
check submitted.ask.duration == request.ask.duration
|
||||||
check submitted.ask.size == request.ask.size
|
|
||||||
check submitted.ask.reward == request.ask.reward
|
check submitted.ask.reward == request.ask.reward
|
||||||
|
|
||||||
test "remembers purchases":
|
test "remembers purchases":
|
||||||
|
|
|
@ -14,10 +14,10 @@ suite "Sales":
|
||||||
)
|
)
|
||||||
var request = StorageRequest(
|
var request = StorageRequest(
|
||||||
ask: StorageAsk(
|
ask: StorageAsk(
|
||||||
|
slots: 4,
|
||||||
|
slotSize: 100.u256,
|
||||||
duration: 60.u256,
|
duration: 60.u256,
|
||||||
size: 100.u256,
|
|
||||||
reward: 10.u256,
|
reward: 10.u256,
|
||||||
slots: 4
|
|
||||||
),
|
),
|
||||||
content: StorageContent(
|
content: StorageContent(
|
||||||
cid: "some cid"
|
cid: "some cid"
|
||||||
|
@ -73,7 +73,7 @@ suite "Sales":
|
||||||
test "ignores request when no matching storage is available":
|
test "ignores request when no matching storage is available":
|
||||||
sales.add(availability)
|
sales.add(availability)
|
||||||
var tooBig = request
|
var tooBig = request
|
||||||
tooBig.ask.size = request.ask.size + 1
|
tooBig.ask.slotSize = request.ask.slotSize + 1
|
||||||
discard await market.requestStorage(tooBig)
|
discard await market.requestStorage(tooBig)
|
||||||
check sales.available == @[availability]
|
check sales.available == @[availability]
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ proc example*(_: type StorageRequest): StorageRequest =
|
||||||
StorageRequest(
|
StorageRequest(
|
||||||
client: Address.example,
|
client: Address.example,
|
||||||
ask: StorageAsk(
|
ask: StorageAsk(
|
||||||
size: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte
|
slots: 4,
|
||||||
|
slotSize: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte
|
||||||
duration: (10 * 60 * 60).u256, # 10 hours
|
duration: (10 * 60 * 60).u256, # 10 hours
|
||||||
proofProbability: 4.u256, # require a proof roughly once every 4 periods
|
proofProbability: 4.u256, # require a proof roughly once every 4 periods
|
||||||
reward: 84.u256,
|
reward: 84.u256
|
||||||
slots: 4
|
|
||||||
),
|
),
|
||||||
content: StorageContent(
|
content: StorageContent(
|
||||||
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob",
|
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob",
|
||||||
|
|
Loading…
Reference in New Issue