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