diff --git a/lbry/blockchain/sync/claims.py b/lbry/blockchain/sync/claims.py index 095fd5aaf..0e776594b 100644 --- a/lbry/blockchain/sync/claims.py +++ b/lbry/blockchain/sync/claims.py @@ -288,7 +288,7 @@ def update_claim_filters(blocking_channel_hashes, filtering_channel_hashes, p: P def select_reposts(channel_hashes, filter_type=0): return select( Claim.c.reposted_claim_hash, filter_type, Claim.c.channel_hash).where( - (Claim.c.channel_hash.in_(filtering_channel_hashes)) & (Claim.c.reposted_claim_hash.isnot(None))) + (Claim.c.channel_hash.in_(channel_hashes)) & (Claim.c.reposted_claim_hash.isnot(None))) p.ctx.execute(ClaimFilter.delete()) # order matters: first we insert the blocked ones. Then the filtered ones. diff --git a/lbry/db/queries/resolve.py b/lbry/db/queries/resolve.py index 7b6eff9e9..be576fc92 100644 --- a/lbry/db/queries/resolve.py +++ b/lbry/db/queries/resolve.py @@ -18,6 +18,7 @@ log = logging.getLogger(__name__) def resolve_claims(**constraints): censor = context().get_resolve_censor() rows = context().fetchall(select_claims(**constraints)) + rows = censor.apply(rows, level=2) return rows_to_txos(rows), censor diff --git a/lbry/schema/result.py b/lbry/schema/result.py index 2276ca38a..751128089 100644 --- a/lbry/schema/result.py +++ b/lbry/schema/result.py @@ -32,11 +32,11 @@ class Censor: self.censored = {} self.total = 0 - def apply(self, rows): - return [row for row in rows if not self.censor(row)] + def apply(self, rows, level=1): + return [row for row in rows if not self.censor(row, level)] - def censor(self, row) -> bool: - was_censored = row['censor_type'] > 0 + def censor(self, row, level=1) -> bool: + was_censored = row['censor_type'] >= level if was_censored: censoring_channel_hash = row['censor_owner_hash'] self.censored.setdefault(censoring_channel_hash, 0) diff --git a/tests/integration/blockchain/test_blockchain.py b/tests/integration/blockchain/test_blockchain.py index 065bc0771..72f36f62b 100644 --- a/tests/integration/blockchain/test_blockchain.py +++ b/tests/integration/blockchain/test_blockchain.py @@ -12,7 +12,7 @@ from lbry.crypto.base58 import Base58 from lbry.schema.claim import Claim, Stream, Channel from lbry.schema.result import Outputs from lbry.schema.support import Support -from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError +from lbry.error import LbrycrdEventSubscriptionError, LbrycrdUnauthorizedError, ResolveCensoredError from lbry.blockchain.lbrycrd import Lbrycrd from lbry.blockchain.sync import BlockchainSync from lbry.blockchain.dewies import dewies_to_lbc, lbc_to_dewies @@ -1405,6 +1405,14 @@ class TestClaimtrieSync(SyncingBlockchainTestCase): results = await self.db.search_claims(channel="@some_channel") self.assertEqual(len(results.rows), 0) self.assertEqual(results.censor.censored.get(moderator_chan.claim_hash), 3) # good, bad and repost + # direct resolves are still possible + result = await self.db.resolve([bad_content.permanent_url]) + self.assertEqual(bad_content.claim_id, result[bad_content.permanent_url].claim_id) + # blocklist, now applied to resolve as well + self.sync.blocking_channel_hashes.add(moderator_chan.claim_hash) + await self.generate(1) + result = await self.db.resolve([bad_content.permanent_url]) + self.assertIsInstance(result[bad_content.permanent_url], ResolveCensoredError) @skip