forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Atproto sync package (bluesky-social#2752)
* first pass/port * reworking * authenticated commit parsing * authenticate identity evts * some testing * tidy & add firehose to queue * error handling * fix test * refactor sync queue + some tests * fix race in sync queue * rm firehose from syncqueue * add tests for queue utils * README * lint readme * filter before parsing * pr feedback * small fix * changesets * fix type * Rework dataplane subscription (bluesky-social#2766) * working sync package into appview subscription * add restart method to subscription for tests * fix another test * tidy subscription utils/files * remove dupe property * tidy after merge * fix start cursor on subscription * tweak process full subscription logic * fixes
- Loading branch information
Showing
40 changed files
with
1,681 additions
and
801 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@atproto/sync": minor | ||
--- | ||
|
||
Introduced initial sync package for consuming firehose (com.atproto.sync.subscribeRepos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@atproto/repo": minor | ||
--- | ||
|
||
Updated verifyProofs consumer method to verify Cid claims rather than record claims |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/bsky/src/data-plane/server/db/migrations/20240829T211238293Z-simplify-actor-sync.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Kysely } from 'kysely' | ||
|
||
export async function up(db: Kysely<unknown>): Promise<void> { | ||
await db.schema.alterTable('actor_sync').dropColumn('commitDataCid').execute() | ||
await db.schema.alterTable('actor_sync').dropColumn('rebaseCount').execute() | ||
await db.schema.alterTable('actor_sync').dropColumn('tooBigCount').execute() | ||
// Migration code | ||
} | ||
|
||
export async function down(db: Kysely<unknown>): Promise<void> { | ||
await db.schema | ||
.alterTable('actor_sync') | ||
.addColumn('commitDataCid', 'varchar', (col) => col.notNull()) | ||
.execute() | ||
await db.schema | ||
.alterTable('actor_sync') | ||
.addColumn('rebaseCount', 'integer', (col) => col.notNull()) | ||
.execute() | ||
await db.schema | ||
.alterTable('actor_sync') | ||
.addColumn('tooBigCount', 'integer', (col) => col.notNull()) | ||
.execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { Firehose, MemoryRunner } from '@atproto/sync' | ||
import { IdResolver } from '@atproto/identity' | ||
import { WriteOpAction } from '@atproto/repo' | ||
import { subLogger as log } from '../../logger' | ||
import { IndexingService } from './indexing' | ||
import { Database } from './db' | ||
import { BackgroundQueue } from './background' | ||
|
||
export class RepoSubscription { | ||
firehose: Firehose | ||
runner: MemoryRunner | ||
background: BackgroundQueue | ||
indexingSvc: IndexingService | ||
|
||
constructor( | ||
public opts: { service: string; db: Database; idResolver: IdResolver }, | ||
) { | ||
const { service, db, idResolver } = opts | ||
this.background = new BackgroundQueue(db) | ||
this.indexingSvc = new IndexingService(db, idResolver, this.background) | ||
|
||
const { runner, firehose } = createFirehose({ | ||
idResolver, | ||
service, | ||
indexingSvc: this.indexingSvc, | ||
}) | ||
this.runner = runner | ||
this.firehose = firehose | ||
} | ||
|
||
start() { | ||
this.firehose.start() | ||
} | ||
|
||
async restart() { | ||
await this.destroy() | ||
const { runner, firehose } = createFirehose({ | ||
idResolver: this.opts.idResolver, | ||
service: this.opts.service, | ||
indexingSvc: this.indexingSvc, | ||
}) | ||
this.runner = runner | ||
this.firehose = firehose | ||
this.start() | ||
} | ||
|
||
async processAll() { | ||
await this.runner.processAll() | ||
await this.background.processAll() | ||
} | ||
|
||
async destroy() { | ||
await this.firehose.destroy() | ||
await this.runner.destroy() | ||
await this.background.processAll() | ||
} | ||
} | ||
|
||
const createFirehose = (opts: { | ||
idResolver: IdResolver | ||
service: string | ||
indexingSvc: IndexingService | ||
}) => { | ||
const { idResolver, service, indexingSvc } = opts | ||
const runner = new MemoryRunner({ startCursor: 0 }) | ||
const firehose = new Firehose({ | ||
idResolver, | ||
runner, | ||
service, | ||
unauthenticatedHandles: true, // indexing service handles these | ||
unauthenticatedCommits: true, // @TODO there seems to be a very rare issue where the authenticator thinks a block is missing in deletion ops | ||
onError: (err) => log.error({ err }, 'error in subscription'), | ||
handleEvent: async (evt) => { | ||
if (evt.event === 'identity') { | ||
await indexingSvc.indexHandle(evt.did, evt.time, true) | ||
} else if (evt.event === 'account') { | ||
if (evt.active === false && evt.status === 'deleted') { | ||
await indexingSvc.deleteActor(evt.did) | ||
} else { | ||
await indexingSvc.updateActorStatus(evt.did, evt.active, evt.status) | ||
} | ||
} else { | ||
const indexFn = | ||
evt.event === 'delete' | ||
? indexingSvc.deleteRecord(evt.uri) | ||
: indexingSvc.indexRecord( | ||
evt.uri, | ||
evt.cid, | ||
evt.record, | ||
evt.event === 'create' | ||
? WriteOpAction.Create | ||
: WriteOpAction.Update, | ||
evt.time, | ||
) | ||
await Promise.all([ | ||
indexFn, | ||
indexingSvc.setCommitLastSeen(evt.did, evt.commit, evt.rev), | ||
indexingSvc.indexHandle(evt.did, evt.time), | ||
]) | ||
} | ||
}, | ||
}) | ||
return { firehose, runner } | ||
} |
Oops, something went wrong.