Skip to content

Commit

Permalink
fix coalescing error with min local sequence constant
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Dec 21, 2024
1 parent d126a8e commit a7d86c7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"--inspect-brk",
"--no-file-parallelism",
"--testTimeout=120000",
"packages/modules/packages/archivist/packages/memory/src/spec/MemoryArchivist.spec.ts"
"packages/modules/packages/bridge/packages/pub-sub/src/spec/PubSubBridge.adhoc.spec.ts"
],
"sourceMaps": true,
"resolveSourceMapLocations": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class AsyncQueryBusHost<TParams extends AsyncQueryBusHostParams = AsyncQu
await this.responsesArchivist(),
() => `Unable to contact responsesArchivist [${this.config?.intersect?.queries?.archivist}]`,
)
const queryDestination = (query as { $destination?: string[] })?.$destination
const queryDestination = query?.$destination
if (queryDestination && queryDestination?.includes(localModule.address)) {
// Find the query
const queryIndex = query.payload_hashes.indexOf(query.query)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,4 @@ describe('PubSubBridge', () => {
expect(exposedAfter).toBeArray()
expect(exposedAfter?.length).toBe(0)
})
})
}, 10_000)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const applyBoundWitnessDivinerQueryPayload = (filter?: BoundWitnessDivine
} = filter

const sortedPayloads = PayloadBuilder.sortByStorageMeta(payloads, order === 'desc' ? -1 : 1)
const parsedCursor = cursor ?? (order === 'desc') ? SequenceConstants.maxLocalSequence : SequenceConstants.minLocalSequence
const parsedCursor = cursor === undefined ? (order === 'desc') ? SequenceConstants.maxLocalSequence : SequenceConstants.minLocalSequence : cursor
const parsedOffset = (order === 'desc')
? sortedPayloads.findIndex(bw => bw._sequence < parsedCursor)
: sortedPayloads.findIndex(bw => bw._sequence > parsedCursor)
Expand All @@ -32,13 +32,13 @@ export const applyBoundWitnessDivinerQueryPayload = (filter?: BoundWitnessDivine
if (allAddresses?.length) bws = bws.filter(bw => containsAll(bw.addresses, allAddresses))
if (payload_hashes?.length) bws = bws.filter(bw => containsAll(bw.payload_hashes, payload_hashes))
if (payload_schemas?.length) bws = bws.filter(bw => containsAll(bw.payload_schemas, payload_schemas))
if (sourceQuery) bws = bws.filter(bw => ((bw as { $sourceQuery?: string })?.$sourceQuery) === sourceQuery)
if (sourceQuery) bws = bws.filter(bw => bw?.$sourceQuery === sourceQuery)
// If there's a destination filter of the right kind
if (destination && Array.isArray(destination) && destination?.length > 0) {
const targetFilter = assertEx(destination, () => 'Missing destination')
// Find all BWs that satisfy the destination constraint
bws = bws.filter((bw) => {
const targetDestinationField = (bw as { $destination?: string[] })?.$destination
const targetDestinationField = (bw as { $destination?: string | string[] })?.$destination
// If the destination field is an array and contains at least one element
return targetDestinationField !== undefined && Array.isArray(targetDestinationField) && targetDestinationField.length > 0
// Check that the targetDestinationField contains all the elements in the targetFilter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export interface BoundWitnessRequiredFields {
}

export interface BoundWitnessMeta {
// the query that initiated the bound witness
/**
* @field The address to which the query is directed
*/
$destination?: Address
/**
* @field The query that initiated the bound witness
*/
$sourceQuery?: Hash
}

Expand Down

0 comments on commit a7d86c7

Please sign in to comment.