diff --git a/lbry/blockchain/sync.py b/lbry/blockchain/sync.py index adec68368..7d6a55a81 100644 --- a/lbry/blockchain/sync.py +++ b/lbry/blockchain/sync.py @@ -18,7 +18,7 @@ from lbry.db.sync import ( condition_spent_claims, condition_spent_supports, select_missing_supports, process_claim_changes ) -from lbry.db.utils import greatest +from lbry.db.utils import least from lbry.schema.url import normalize_name from .lbrycrd import Lbrycrd @@ -369,7 +369,7 @@ def process_metadata(starting_height: int, ending_height: int, initial_sync: boo [(Claim.c.claim_hash == takeover['claim_hash'], takeover['height'])], else_=None ), - activation_height=greatest(Claim.c.activation_height, takeover['height']), + activation_height=least(Claim.c.activation_height, takeover['height']), ) ) p.ctx.execute(update_claims) diff --git a/lbry/db/utils.py b/lbry/db/utils.py index bc8d30be0..3f5d94006 100644 --- a/lbry/db/utils.py +++ b/lbry/db/utils.py @@ -28,6 +28,21 @@ def sqlite_greatest(element, compiler, **kw): return "max(%s)" % compiler.process(element.clauses, **kw) +class least(FunctionElement): # pylint: disable=invalid-name + type = Numeric() + name = 'least' + + +@compiles(least) +def default_least(element, compiler, **kw): + return "least(%s)" % compiler.process(element.clauses, **kw) + + +@compiles(least, 'sqlite') +def sqlite_least(element, compiler, **kw): + return "min(%s)" % compiler.process(element.clauses, **kw) + + def chunk(rows, step): it, total = iter(rows), len(rows) for _ in range(0, total, step): diff --git a/tests/integration/blockchain/test_blockchain.py b/tests/integration/blockchain/test_blockchain.py index a4669edfb..27d909f8c 100644 --- a/tests/integration/blockchain/test_blockchain.py +++ b/tests/integration/blockchain/test_blockchain.py @@ -933,7 +933,7 @@ class TestClaimtrieSync(SyncingBlockchainTestCase): ]) await self.state( controlling=('Claim C', '3.0', '3.0', 115), - active=[('Claim A', '1.0', '1.0', 115)], + active=[('Claim A', '1.0', '1.0', 113)], accepted=[] )