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
This commit is contained in:
Jonathan Zernik 2021-02-16 15:08:39 -08:00 committed by GitHub
parent 9350207201
commit 4766f34cbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 25 deletions

View file

@ -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',

View file

@ -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,
)

View file

@ -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: