Skip to content

Commit

Permalink
chore: apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Russell Dempsey <[email protected]>
  • Loading branch information
achingbrain and SgtPooki authored Mar 1, 2024
1 parent ca1c458 commit d7d6334
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/interface/src/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ ProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProg
* Any blocks written to the blockstore as part of the session will propagate
* to the blockstore the session was created from.
*
* This method is optional to maintain compatibility with existing
* blockstores that do not support sessions.
*/
createSession(root: CID, options?: CreateSessionOptions<GetBlockProgressEvents>): Promise<Blockstore>
}
Expand Down Expand Up @@ -110,7 +108,7 @@ export interface CreateSessionOptions <ProgressEvents extends ProgressEvent<any,
*
* @default 5
*/
queryConcurrency?: number
providerQueryConcurrency?: number

/**
* How long each queried provider has to respond either that they have the
Expand Down Expand Up @@ -140,5 +138,5 @@ export interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, a

export const DEFAULT_SESSION_MIN_PROVIDERS = 1
export const DEFAULT_SESSION_MAX_PROVIDERS = 5
export const DEFAULT_SESSION_QUERY_CONCURRENCY = 5
export const DEFAULT_SESSION_PROVIDER_QUERY_CONCURRENCY = 5
export const DEFAULT_SESSION_PROVIDER_QUERY_TIMEOUT = 5000
7 changes: 4 additions & 3 deletions packages/utils/src/utils/networked-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ export class NetworkedStorage implements Blocks, Startable {
}
}

function isRetrievingBlockBroker (broker: BlockBroker): broker is Required<Pick<BlockBroker, 'retrieve'>> {
return typeof broker.retrieve === 'function'
}
export const getCidBlockVerifierFunction = (cid: CID, hasher: MultihashHasher): Required<BlockRetrievalOptions>['validateFn'] => {
if (hasher == null) {
throw new CodeError(`No hasher configured for multihash code 0x${cid.multihash.code.toString(16)}, please configure one. You can look up which hash this is at https://github.com/multiformats/multicodec/blob/master/table.csv`, 'ERR_UNKNOWN_HASH_ALG')
Expand Down Expand Up @@ -246,9 +249,7 @@ async function raceBlockRetrievers (cid: CID, blockBrokers: BlockBroker[], hashe
const retrievers: Array<Required<Pick<BlockBroker, 'retrieve'>>> = []

for (const broker of blockBrokers) {
if (broker.retrieve != null) {
// @ts-expect-error retrieve may be undefined even though we've just
// checked that it isn't
if (isRetrievingBlockBroker(broker)) {
retrievers.push(broker)
}
}
Expand Down

0 comments on commit d7d6334

Please sign in to comment.