From 4766f34cbba3504f9ebca0a3e0058bc508e92090 Mon Sep 17 00:00:00 2001 From: Jonathan Zernik Date: Tue, 16 Feb 2021 15:08:39 -0800 Subject: [PATCH] Remove unique constraint on offer squeak hash client addr (#857) * Remove unique constraint on squeak hash and client addr in sent offer * Reinitialize db migrations --- ..._all.py => 67e84bbfd641_initialize_all.py} | 8 ++--- squeaknode/db/models.py | 2 -- squeaknode/node/squeak_controller.py | 32 ++++++++----------- 3 files changed, 17 insertions(+), 25 deletions(-) rename squeaknode/db/alembic/versions/{b703368566fe_initialize_all.py => 67e84bbfd641_initialize_all.py} (97%) diff --git a/squeaknode/db/alembic/versions/b703368566fe_initialize_all.py b/squeaknode/db/alembic/versions/67e84bbfd641_initialize_all.py similarity index 97% rename from squeaknode/db/alembic/versions/b703368566fe_initialize_all.py rename to squeaknode/db/alembic/versions/67e84bbfd641_initialize_all.py index 37654420..641482e1 100644 --- a/squeaknode/db/alembic/versions/b703368566fe_initialize_all.py +++ b/squeaknode/db/alembic/versions/67e84bbfd641_initialize_all.py @@ -1,8 +1,8 @@ """Initialize all -Revision ID: b703368566fe +Revision ID: 67e84bbfd641 Revises: -Create Date: 2021-02-12 01:39:23.841767 +Create Date: 2021-02-16 14:58:44.662161 """ import sqlalchemy as sa @@ -12,7 +12,7 @@ import squeaknode.db.models # revision identifiers, used by Alembic. -revision = 'b703368566fe' +revision = '67e84bbfd641' down_revision = None branch_labels = None depends_on = None @@ -114,8 +114,6 @@ def upgrade(): length=64), nullable=False), sa.PrimaryKeyConstraint('sent_offer_id'), sa.UniqueConstraint('payment_hash'), - sa.UniqueConstraint('squeak_hash', 'client_addr', - name='uq_sent_offer_squeak_hash_client_addr'), sqlite_autoincrement=True ) op.create_table('sent_payment', diff --git a/squeaknode/db/models.py b/squeaknode/db/models.py index e59f027d..6d7cf9c7 100644 --- a/squeaknode/db/models.py +++ b/squeaknode/db/models.py @@ -155,8 +155,6 @@ class Models: Column("invoice_timestamp", Integer, nullable=False), Column("invoice_expiry", Integer, nullable=False), Column("client_addr", String(64), nullable=False), - UniqueConstraint('squeak_hash', 'client_addr', - name='uq_sent_offer_squeak_hash_client_addr'), sqlite_autoincrement=True, ) diff --git a/squeaknode/node/squeak_controller.py b/squeaknode/node/squeak_controller.py index 61d5d979..c0f60b57 100644 --- a/squeaknode/node/squeak_controller.py +++ b/squeaknode/node/squeak_controller.py @@ -41,7 +41,6 @@ class SqueakController: self.squeak_rate_limiter = squeak_rate_limiter self.payment_processor = payment_processor self.config = config - self.create_offer_lock = threading.Lock() def save_uploaded_squeak(self, squeak: CSqueak) -> bytes: return self.save_squeak( @@ -143,24 +142,21 @@ class SqueakController: ) def get_saved_sent_offer(self, squeak_hash: bytes, client_addr: str) -> SentOffer: - with self.create_offer_lock: - # Check if there is an existing offer for the hash/client_addr combination - sent_offer = self.squeak_db.get_sent_offer_by_squeak_hash_and_client_addr( - squeak_hash, - client_addr, - ) - if sent_offer: - return sent_offer - squeak = self.get_squeak(squeak_hash) - # sent_offer = self.create_offer( - # squeak, client_addr, self.config.core.price_msat) - sent_offer = self.squeak_core.create_offer( - squeak, - client_addr, - self.config.core.price_msat, - ) - self.squeak_db.insert_sent_offer(sent_offer) + # Check if there is an existing offer for the hash/client_addr combination + sent_offer = self.squeak_db.get_sent_offer_by_squeak_hash_and_client_addr( + squeak_hash, + client_addr, + ) + if sent_offer: return sent_offer + squeak = self.get_squeak(squeak_hash) + sent_offer = self.squeak_core.create_offer( + squeak, + client_addr, + self.config.core.price_msat, + ) + self.squeak_db.insert_sent_offer(sent_offer) + return sent_offer def create_signing_profile(self, profile_name: str) -> int: if len(profile_name) == 0: