From b446d2a2e80548f08480032f87b80d93d727f262 Mon Sep 17 00:00:00 2001 From: bhartnett <51288821+bhartnett@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:09:43 +0800 Subject: [PATCH] Fluffy: Cleanup state bridge preimages backend and add logging for transfer limit reached (#2896) --- fluffy/network/wire/portal_stream.nim | 6 +++++- .../portal_bridge/state_bridge/database.nim | 18 +----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/fluffy/network/wire/portal_stream.nim b/fluffy/network/wire/portal_stream.nim index fb221bd93..941ed65c6 100644 --- a/fluffy/network/wire/portal_stream.nim +++ b/fluffy/network/wire/portal_stream.nim @@ -91,7 +91,11 @@ proc canAddPendingTransfer( try: let contentIds = transfers[nodeId] - (contentIds.len() < limit) and not contentIds.contains(contentId) + if (contentIds.len() < limit) and not contentIds.contains(contentId): + return true + else: + debug "Pending transfer limit reached for peer", nodeId, contentId + return false except KeyError as e: raiseAssert(e.msg) diff --git a/fluffy/tools/portal_bridge/state_bridge/database.nim b/fluffy/tools/portal_bridge/state_bridge/database.nim index 114ac6d51..517fd3834 100644 --- a/fluffy/tools/portal_bridge/state_bridge/database.nim +++ b/fluffy/tools/portal_bridge/state_bridge/database.nim @@ -37,13 +37,7 @@ type tx: TransactionRef updatedCache: TrieDatabaseRef - PreimagesBackendRef = ref object of RootObj - cfHandle: ColFamilyHandleRef - tx: TransactionRef - updatedCache: TrieDatabaseRef - - DatabaseBackendRef = - AccountsBackendRef | StorageBackendRef | BytecodeBackendRef | PreimagesBackendRef + DatabaseBackendRef = AccountsBackendRef | StorageBackendRef | BytecodeBackendRef DatabaseRef* = ref object rocksDb: OptimisticTxDbRef @@ -51,7 +45,6 @@ type accountsBackend: AccountsBackendRef storageBackend: StorageBackendRef bytecodeBackend: BytecodeBackendRef - preimagesBackend: PreimagesBackendRef proc init*(T: type DatabaseRef, baseDir: string): Result[T, string] = let dbPath = baseDir / "db" @@ -79,9 +72,6 @@ proc init*(T: type DatabaseRef, baseDir: string): Result[T, string] = bytecodeBackend = BytecodeBackendRef( cfHandle: db.getColFamilyHandle(COL_FAMILY_NAME_BYTECODE).get() ) - preimagesBackend = PreimagesBackendRef( - cfHandle: db.getColFamilyHandle(COL_FAMILY_NAME_PREIMAGES).get() - ) ok( T( @@ -90,7 +80,6 @@ proc init*(T: type DatabaseRef, baseDir: string): Result[T, string] = accountsBackend: accountsBackend, storageBackend: storageBackend, bytecodeBackend: bytecodeBackend, - preimagesBackend: preimagesBackend, ) ) @@ -138,9 +127,6 @@ proc getStorageBackend*(db: DatabaseRef): TrieDatabaseRef {.inline.} = proc getBytecodeBackend*(db: DatabaseRef): TrieDatabaseRef {.inline.} = trieDB(db.bytecodeBackend) -proc getPreimagesBackend*(db: DatabaseRef): TrieDatabaseRef {.inline.} = - trieDB(db.preimagesBackend) - proc getAccountsUpdatedCache*(db: DatabaseRef): TrieDatabaseRef {.inline.} = db.accountsBackend.updatedCache @@ -179,12 +165,10 @@ proc beginTransaction*(db: DatabaseRef): Result[void, string] = db.accountsBackend.tx = tx db.storageBackend.tx = tx db.bytecodeBackend.tx = tx - db.preimagesBackend.tx = tx db.accountsBackend.updatedCache = newMemoryDB() db.storageBackend.updatedCache = newMemoryDB() db.bytecodeBackend.updatedCache = newMemoryDB() - db.preimagesBackend.updatedCache = nil # not used ok()