diff --git a/waku/waku_store_sync/storage/range_processing.nim b/waku/waku_store_sync/storage/range_processing.nim index 7eff113ce9..333ac051e3 100644 --- a/waku/waku_store_sync/storage/range_processing.nim +++ b/waku/waku_store_sync/storage/range_processing.nim @@ -1,4 +1,4 @@ -import std/math, chronos +import chronos import ../../waku_core/time, ../common @@ -28,7 +28,8 @@ proc equalPartitioning*(slice: Slice[ID], count: int): seq[Slice[ID]] = if totalLength < count: return @[] - var (parts, rem) = divmod(totalLength, count) + let parts = totalLength div count + var rem = totalLength mod count var bounds = newSeqOfCap[Slice[ID]](count) diff --git a/waku/waku_store_sync/storage/seq_storage.nim b/waku/waku_store_sync/storage/seq_storage.nim index 7e25080604..0fc3fcd94d 100644 --- a/waku/waku_store_sync/storage/seq_storage.nim +++ b/waku/waku_store_sync/storage/seq_storage.nim @@ -5,7 +5,10 @@ import ../../waku_core/time, ../common, ./range_processing, ./storage type SeqStorage* = ref object of SyncStorage elements: seq[ID] + # Numer of parts a range will be splitted into. partitionCount: int + + # Number of element in a range for which item sets are used instead of fingerprints. lengthThreshold: int method length*(self: SeqStorage): int = @@ -54,7 +57,9 @@ method prune*(self: SeqStorage, timestamp: Timestamp): int {.raises: [].} = return idx -proc fingerprinting(self: SeqStorage, sliceOpt: Option[Slice[int]]): Fingerprint = +proc computefingerprintFromSlice( + self: SeqStorage, sliceOpt: Option[Slice[int]] +): Fingerprint = ## XOR all hashes of a slice of the storage. var fingerprint = EmptyFingerprint @@ -88,11 +93,11 @@ proc findIdxBounds(self: SeqStorage, slice: Slice[ID]): Option[Slice[int]] = return some(lower ..< upper) -method fingerprinting*( +method computeFingerprint*( self: SeqStorage, bounds: Slice[ID] ): Fingerprint {.raises: [].} = let idxSliceOpt = self.findIdxBounds(bounds) - return self.fingerprinting(idxSliceOpt) + return self.computefingerprintFromSlice(idxSliceOpt) proc processFingerprintRange*( self: SeqStorage, @@ -124,7 +129,8 @@ proc processFingerprintRange*( output.itemSets.add(state) return - for partitionBounds in equalPartitioning(inputBounds, self.partitionCount): + let partitions = equalPartitioning(inputBounds, self.partitionCount) + for partitionBounds in partitions: let sliceOpt = self.findIdxBounds(partitionBounds) let slice = diff --git a/waku/waku_store_sync/storage/storage.nim b/waku/waku_store_sync/storage/storage.nim index e8bdfbd21b..dbf2ad0021 100644 --- a/waku/waku_store_sync/storage/storage.nim +++ b/waku/waku_store_sync/storage/storage.nim @@ -7,22 +7,22 @@ type SyncStorage* = ref object of RootObj method insert*( self: SyncStorage, element: ID ): Result[void, string] {.base, gcsafe, raises: [].} = - discard + return err("insert method not implemented for SyncStorage") method batchInsert*( self: SyncStorage, elements: seq[ID] ): Result[void, string] {.base, gcsafe, raises: [].} = - discard + return err("batchInsert method not implemented for SyncStorage") method prune*( self: SyncStorage, timestamp: Timestamp ): int {.base, gcsafe, raises: [].} = - discard + -1 -method fingerprinting*( +method computeFingerprint*( self: SyncStorage, bounds: Slice[ID] ): Fingerprint {.base, gcsafe, raises: [].} = - discard + return EmptyFingerprint method processPayload*( self: SyncStorage, @@ -30,7 +30,7 @@ method processPayload*( hashToSend: var seq[Fingerprint], hashToRecv: var seq[Fingerprint], ): SyncPayload {.base, gcsafe, raises: [].} = - discard + return SyncPayload() method length*(self: SyncStorage): int {.base, gcsafe, raises: [].} = - discard + -1