From 8740b65a7942440df2ddd2698a47b6d1cf4ad4ec Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 13 Mar 2023 13:29:07 +0100 Subject: [PATCH] wip: memory cache specific behavior --- codex/stores/memorystore.nim | 12 ++++++------ .../blockexchange/discovery/testdiscovery.nim | 4 ++-- .../discovery/testdiscoveryengine.nim | 14 +++++++------- tests/codex/blockexchange/engine/testengine.nim | 2 +- tests/codex/storageproofs/testnetwork.nim | 2 +- tests/codex/storageproofs/testpor.nim | 4 ++-- tests/codex/storageproofs/teststpstore.nim | 2 +- tests/codex/testerasure.nim | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/codex/stores/memorystore.nim b/codex/stores/memorystore.nim index 92ce5e1d..9885999f 100644 --- a/codex/stores/memorystore.nim +++ b/codex/stores/memorystore.nim @@ -39,9 +39,9 @@ type InvalidBlockSize* = object of CodexError const - MiB* = 1024 * 1024 # bytes, 1 mebibyte = 1,048,576 bytes + MiB* = 1024 * 1024 DefaultCacheSizeMiB* = 5 - DefaultCacheSize* = DefaultCacheSizeMiB * MiB # bytes + DefaultCacheSize* = DefaultCacheSizeMiB * MiB method getBlock*(self: MemoryStore, cid: Cid): Future[?!Block] {.async.} = trace "Getting block from cache", cid @@ -163,8 +163,8 @@ method close*(self: MemoryStore): Future[void] {.async.} = func new*( _: type MemoryStore, blocks: openArray[Block] = [], - capacity: Positive = DefaultCacheSize, # in bytes - chunkSize: Positive = DefaultChunkSize # in bytes + capacity: Positive = DefaultCacheSize, + chunkSize: Positive = DefaultChunkSize ): MemoryStore {.raises: [Defect, ValueError].} = if capacity < chunkSize: raise newException(ValueError, "capacity cannot be less than chunkSize") @@ -174,7 +174,7 @@ func new*( bytesUsed: 0, capacity: capacity) - # for blk in blocks: - # discard store.putBlockSync(blk) + for blk in blocks: + discard store.putBlockSync(blk) return store diff --git a/tests/codex/blockexchange/discovery/testdiscovery.nim b/tests/codex/blockexchange/discovery/testdiscovery.nim index 6a06c5ff..5beed798 100644 --- a/tests/codex/blockexchange/discovery/testdiscovery.nim +++ b/tests/codex/blockexchange/discovery/testdiscovery.nim @@ -33,7 +33,7 @@ suite "Block Advertising and Discovery": discovery: DiscoveryEngine wallet: WalletRef network: BlockExcNetwork - localStore: CacheStore + localStore: MemoryStore engine: BlockExcEngine pendingBlocks: PendingBlocksManager @@ -49,7 +49,7 @@ suite "Block Advertising and Discovery": blockDiscovery = MockDiscovery.new() wallet = WalletRef.example network = BlockExcNetwork.new(switch) - localStore = CacheStore.new(blocks.mapIt( it )) + localStore = MemoryStore.new(blocks.mapIt( it )) peerStore = PeerCtxStore.new() pendingBlocks = PendingBlocksManager.new() diff --git a/tests/codex/blockexchange/discovery/testdiscoveryengine.nim b/tests/codex/blockexchange/discovery/testdiscoveryengine.nim index 6ac98b2d..4c3726b7 100644 --- a/tests/codex/blockexchange/discovery/testdiscoveryengine.nim +++ b/tests/codex/blockexchange/discovery/testdiscoveryengine.nim @@ -46,7 +46,7 @@ suite "Test Discovery Engine": test "Should Query Wants": var - localStore = CacheStore.new() + localStore = MemoryStore.new() discoveryEngine = DiscoveryEngine.new( localStore, peerStore, @@ -66,7 +66,7 @@ suite "Test Discovery Engine": test "Should Advertise Haves": var - localStore = CacheStore.new(blocks.mapIt( it )) + localStore = MemoryStore.new(blocks.mapIt( it )) discoveryEngine = DiscoveryEngine.new( localStore, peerStore, @@ -90,7 +90,7 @@ suite "Test Discovery Engine": test "Should queue discovery request": var - localStore = CacheStore.new() + localStore = MemoryStore.new() discoveryEngine = DiscoveryEngine.new( localStore, peerStore, @@ -113,7 +113,7 @@ suite "Test Discovery Engine": test "Should queue advertise request": var - localStore = CacheStore.new(@[blocks[0]]) + localStore = MemoryStore.new(@[blocks[0]]) discoveryEngine = DiscoveryEngine.new( localStore, peerStore, @@ -135,7 +135,7 @@ suite "Test Discovery Engine": test "Should not request more than minPeersPerBlock": var - localStore = CacheStore.new() + localStore = MemoryStore.new() minPeers = 2 discoveryEngine = DiscoveryEngine.new( localStore, @@ -170,7 +170,7 @@ suite "Test Discovery Engine": test "Should not request if there is already an inflight discovery request": var - localStore = CacheStore.new() + localStore = MemoryStore.new() discoveryEngine = DiscoveryEngine.new( localStore, peerStore, @@ -204,7 +204,7 @@ suite "Test Discovery Engine": test "Should not request if there is already an inflight advertise request": var - localStore = CacheStore.new() + localStore = MemoryStore.new() discoveryEngine = DiscoveryEngine.new( localStore, peerStore, diff --git a/tests/codex/blockexchange/engine/testengine.nim b/tests/codex/blockexchange/engine/testengine.nim index 12abd6f6..8e04d7a6 100644 --- a/tests/codex/blockexchange/engine/testengine.nim +++ b/tests/codex/blockexchange/engine/testengine.nim @@ -69,7 +69,7 @@ suite "NetworkStore engine basic": sendWantList: sendWantList, )) - localStore = CacheStore.new(blocks.mapIt( it )) + localStore = MemoryStore.new(blocks.mapIt( it )) discovery = DiscoveryEngine.new( localStore, peerStore, diff --git a/tests/codex/storageproofs/testnetwork.nim b/tests/codex/storageproofs/testnetwork.nim index 7d7cd582..0fa040c3 100644 --- a/tests/codex/storageproofs/testnetwork.nim +++ b/tests/codex/storageproofs/testnetwork.nim @@ -48,7 +48,7 @@ suite "Storage Proofs Network": setupAll: chunker = RandomChunker.new(Rng.instance(), size = DataSetSize, chunkSize = BlockSize) - store = CacheStore.new(cacheSize = DataSetSize, chunkSize = BlockSize) + store = MemoryStore.new(capacity = DataSetSize, chunkSize = BlockSize) manifest = Manifest.new(blockSize = BlockSize).tryGet() (spk, ssk) = st.keyGen() diff --git a/tests/codex/storageproofs/testpor.nim b/tests/codex/storageproofs/testpor.nim index e1527aff..a0602978 100644 --- a/tests/codex/storageproofs/testpor.nim +++ b/tests/codex/storageproofs/testpor.nim @@ -29,7 +29,7 @@ suite "BLS PoR": setup: chunker = RandomChunker.new(Rng.instance(), size = DataSetSize, chunkSize = BlockSize) - store = CacheStore.new(cacheSize = DataSetSize, chunkSize = BlockSize) + store = MemoryStore.new(capacity = DataSetSize, chunkSize = BlockSize) manifest = Manifest.new(blockSize = BlockSize).tryGet() (spk, ssk) = st.keyGen() @@ -88,7 +88,7 @@ suite "Test Serialization": setupAll: chunker = RandomChunker.new(Rng.instance(), size = DataSetSize, chunkSize = BlockSize) - store = CacheStore.new(cacheSize = DataSetSize, chunkSize = BlockSize) + store = MemoryStore.new(capacity = DataSetSize, chunkSize = BlockSize) manifest = Manifest.new(blockSize = BlockSize).tryGet() while ( diff --git a/tests/codex/storageproofs/teststpstore.nim b/tests/codex/storageproofs/teststpstore.nim index 190e67bb..a36d5ad6 100644 --- a/tests/codex/storageproofs/teststpstore.nim +++ b/tests/codex/storageproofs/teststpstore.nim @@ -34,7 +34,7 @@ suite "Test PoR store": setupAll: chunker = RandomChunker.new(Rng.instance(), size = DataSetSize, chunkSize = BlockSize) - store = CacheStore.new(cacheSize = DataSetSize, chunkSize = BlockSize) + store = MemoryStore.new(capacity = DataSetSize, chunkSize = BlockSize) manifest = Manifest.new(blockSize = BlockSize).tryGet() (spk, ssk) = st.keyGen() diff --git a/tests/codex/testerasure.nim b/tests/codex/testerasure.nim index 6f1bf882..77c6e5f3 100644 --- a/tests/codex/testerasure.nim +++ b/tests/codex/testerasure.nim @@ -28,7 +28,7 @@ suite "Erasure encode/decode": rng = Rng.instance() chunker = RandomChunker.new(rng, size = dataSetSize, chunkSize = BlockSize) manifest = !Manifest.new(blockSize = BlockSize) - store = CacheStore.new(cacheSize = (dataSetSize * 2), chunkSize = BlockSize) + store = MemoryStore.new(capacity = (dataSetSize * 2), chunkSize = BlockSize) erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider) while (