Skip to content

refactor(StreamProvider): remove unnecessary stream multiplexing - #400

Merged
cryptodev-2s merged 9 commits into
mainfrom
cryptodev2s/refactor-providers-stream-connection
Jan 23, 2025
Merged

cryptodev-2s merged 9 commits into
mainfrom
cryptodev2s/refactor-providers-stream-connection

Conversation

@cryptodev-2s

@cryptodev-2s cryptodev-2s commented Jan 23, 2025 •

Copy link
Copy Markdown
Contributor

Eliminate redundant stream multiplexing within StreamProvider and move the multiplexing logic to the consumer side.

Changelog: See changelog changes

@cryptodev-2s cryptodev-2s self-assigned this Jan 23, 2025
@cryptodev-2s
cryptodev-2s requested a review from a team January 23, 2025 15:00
@cryptodev-2s
cryptodev-2s marked this pull request as draft January 23, 2025 15:00
Comment thread src/extension-provider/createExternalExtensionProvider.ts Outdated
@cryptodev-2s
cryptodev-2s force-pushed the cryptodev2s/refactor-providers-stream-connection branch from d936335 to 745d3c5 Compare January 23, 2025 15:57
@cryptodev-2s
cryptodev-2s marked this pull request as ready for review January 23, 2025 16:03
Comment thread src/MetaMaskInpageProvider.ts

@Gudahtt Gudahtt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Just one last requested change for the inpage provider options.

It would be great to see the changelog entries before approving as well

@Gudahtt
Gudahtt dismissed their stale review January 23, 2025 16:26

Requested changes have been made

@cryptodev-2s
cryptodev-2s requested a review from Gudahtt January 23, 2025 17:05
Gudahtt
Gudahtt previously approved these changes Jan 23, 2025

@Gudahtt Gudahtt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

Gudahtt
Gudahtt previously approved these changes Jan 23, 2025
Comment thread src/initializeInpageProvider.ts Outdated
Comment on lines +68 to +71
let warningMsg = `Lost connection to "${jsonRpcStreamName}".`;
if (error?.stack) {
warningMsg += `\n${error.stack}`;
}

@jiexi jiexi Jan 23, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thoughts on just stringifying and logging the entire error object?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried to use the same pattern that was used earlier and as still in here https://github.com/MetaMask/providers/blob/main/src/StreamProvider.ts#L155

But I haven't nothing against making this change

@jiexi

jiexi commented Jan 23, 2025

Copy link
Copy Markdown
Member

Why not move the stream multiplexing outside of this package entirely? I ask because I have a POC branch for adding Multichain API support over WindowPostMessage that requires me to instantiate yet another ObjectMultiplex and substream outside of the inpage provider instantiator. It seems to make more sense and is cleaner if we just remove this substream creation responsibility from these providers. I.e. the providers should just operate off the original Duplex Stream instance given to them and that's it

@Gudahtt

Gudahtt commented Jan 23, 2025 •

Copy link
Copy Markdown
Member

@jiexi I had the same thought. I'm not 100% sure how I feel about the idea, but agreed that it's worth considering.

However I still see this PR as a step towards that.

Extracting the steam multiplexing completely has some potential downsides, but this step does not (as far as I can tell).

@cryptodev-2s
cryptodev-2s merged commit df85bdf into main Jan 23, 2025
@cryptodev-2s
cryptodev-2s deleted the cryptodev2s/refactor-providers-stream-connection branch January 23, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamProvider: remove unnecessary stream multiplexing

3 participants