Skip to content

feat!: use Helia's blockBroker interface#406

Merged
SgtPooki merged 10 commits intomasterfrom
feat/use-blockBroker-interface
Nov 29, 2023
Merged

feat!: use Helia's blockBroker interface#406
SgtPooki merged 10 commits intomasterfrom
feat/use-blockBroker-interface

Conversation

@SgtPooki
Copy link
Copy Markdown
Member

@SgtPooki SgtPooki commented Nov 29, 2023

  • Update Helia and libp2p dependencies
    • also updated others. basically ncu '/ipfs|libp2p|ipld|multi/'
  • Use Helia blockBroker interface for block retrieval
  • Use kubo-rpc-client as a blockBroker
    • Use Kubo as a trustless gateway
    • Remove dependency on kubo-rpc-client (and many older ipfs dependencies)
  • Remove all places where kuboClient was passed through since that is no longer needed.
  • Update hashers passed to helia so it can support parsing of multiple content types
  • Disable libp2p autoDialer because we only want to fetch on demand.

These updates also put a big dent in dependencies holding back ipfs-webui ipfs/ipfs-webui#1965

@SgtPooki SgtPooki requested a review from a team as a code owner November 29, 2023 01:10
@SgtPooki SgtPooki requested a review from lidel November 29, 2023 01:10
@SgtPooki SgtPooki changed the title feat: use Helia's blockBroker interface feat!: use Helia's blockBroker interface Nov 29, 2023
Copy link
Copy Markdown
Contributor

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow 🤩

Copy link
Copy Markdown
Member Author

@SgtPooki SgtPooki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review and explainers

Comment on lines +94 to +97
const { doInitHelia } = props
useEffect(() => {
props.doInitHelia()
}, [props])
doInitHelia()
}, [doInitHelia])
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes an issue where doInitHelia was being called on every page load.

Comment on lines +82 to +95
/**
* replace bigint or other non-JSON-serializable values with appropriate values for the react-inspector
* Note that data for some blocks (e.g. bafyreicnokmhmrnlp2wjhyk2haep4tqxiptwfrp2rrs7rzq7uk766chqvq) currently do not
* look like NormalizedDagNode['data']
*
* @param {import('../../types').NormalizedDagNode['data']} data
*/
const getObjectInspectorData = (data) => {
if (data == null) return data
if (data.blockSizes != null) {
data.blockSizes = data.blockSizes.map(Number)
}
return data
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needed since the unixfs update uses bigint now.

Comment on lines +97 to 113
/**
* @param {object} props
* @param {import('react-i18next').TFunction} props.t
* @param {boolean} props.tReady
* @param {string} props.className
* @param {string} props.type
* @param {string} props.cid
* @param {string} props.localPath
* @param {bigint} props.size
* @param {import('../../types').NormalizedDagNode['data']} props.data
* @param {object[]} props.links
* @param {string} props.format
* @param {Function} props.onLinkClick
* @param {string} props.gatewayUrl
* @param {string} props.publicGatewayUrl
*/
const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, publicGatewayUrl, ...props }) => {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some types

* @param {string} props.publicGatewayUrl
*/
const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, publicGatewayUrl, ...props }) => {
if (!tReady) return null
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is always true in testing, but may not always be in prod.

{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
<label className='dtc silver tracked ttu f7' style={{ width: 48 }}>Size</label>
<div className='dtc truncate charcoal monospace'>{humansize(size)}</div>
<div className='dtc truncate charcoal monospace'>{humansize(Number(size))}</div>
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bigint conversion

Comment on lines 10 to 13
interface CodecWrapper<DecodedType = any> {
decode: (bytes: Uint8Array) => DecodedType
resolve: (path: string, bytes: Uint8Array) => Promise<ResolveType<DecodedType>>
decode(bytes: Uint8Array): DecodedType
resolve(path: string, bytes: Uint8Array): Promise<ResolveType<DecodedType>>
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint-config-ipfs auto lint updates

const timeoutId = setTimeout(() => { abortController.abort('Request timed out') }, timeout)
const rawBlock = await Promise.any([kuboClient.block.get(cid), getBlockFromAnyGateway(cid, abortController.signal), helia.blockstore.get(cid, { signal: abortController.signal })])
abortController.abort('Content obtained') // abort any other requests.
const rawBlock = await helia.blockstore.get(cid, { signal: abortController.signal })
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so much nicer =D

}

export async function addDagNodeToHelia <T> (helia: Helia, codec: { encode: (n: T) => Uint8Array, code: number }, node: T, digestFn?: DigestFn): Promise<CID> {
export async function addDagNodeToHelia <T> (helia: Helia, codec: { encode(n: T): Uint8Array, code: number }, node: T, digestFn?: DigestFn): Promise<CID> {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eslint-config-ipfs auto lint updates

identify: identifyService(),
autoNAT: autoNATService()
autoNAT: autoNATService(),
delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev')
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use delegated routingv1httpApi instead of local kubo

Comment on lines +5 to +22
export default defineConfig((configEnv) => mergeConfig(
viteConfig(configEnv),
defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: './test/unit/setup.js',
include: [
'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'
],
deps: {
inline: [
'ipld-explorer-components'
]
}
}
}
}))
})
))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearing out package-lock.json and refreshing it caused an error here.. vitest must've updated their api (they're still pre v1)

@SgtPooki SgtPooki merged commit c964a76 into master Nov 29, 2023
@SgtPooki SgtPooki deleted the feat/use-blockBroker-interface branch November 29, 2023 18:54
github-actions bot pushed a commit that referenced this pull request Nov 30, 2023
## [5.0.0](v4.0.3...v5.0.0) (2023-11-30)

### ⚠ BREAKING CHANGES

* update of many ipfs/ipld/libp2p/helia deps that may break consumers. API of ipld-explorer-components has not changed.

### Features

* use Helia's blockBroker interface ([#406](#406)) ([c964a76](c964a76))
* use ipfs-css colors and add dag-jose example ([#408](#408)) ([4e96491](4e96491))

### Trivial Changes

* bump protobufjs from 6.11.3 to 6.11.4 ([#393](#393)) ([f8db274](f8db274))
* **ci:** remove circleci config ([#388](#388)) ([13698af](13698af))
* pull new translations ([#390](#390)) ([2caac4a](2caac4a))
* pull new translations ([#396](#396)) ([73799f8](73799f8))
* pull new translations ([#405](#405)) ([5805bd8](5805bd8))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants