Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(StreamProvider): remove unnecessary stream multiplexing #400

Merged
merged 9 commits into from
Jan 23, 2025

Conversation

cryptodev-2s
Copy link
Contributor

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

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 as a code owner January 23, 2025 15:00
@cryptodev-2s cryptodev-2s marked this pull request as draft January 23, 2025 15:00
@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
Copy link
Member

@Gudahtt Gudahtt left a comment

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
Copy link
Member

@Gudahtt Gudahtt left a comment

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 on lines +68 to +71
let warningMsg = `Lost connection to "${jsonRpcStreamName}".`;
if (error?.stack) {
warningMsg += `\n${error.stack}`;
}
Copy link
Contributor

@jiexi jiexi Jan 23, 2025

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
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
Copy link
Contributor

jiexi commented Jan 23, 2025

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
Copy link
Member

Gudahtt commented Jan 23, 2025

@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
18 checks passed
@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