Skip to content

fix(sdk): panic GrpcContextProvider on async call inside sync code - #1870

Merged
lklimek merged 6 commits into
v1.0-devfrom
fix/sdk-context-provider-not-set
Jul 3, 2024
Merged

fix(sdk): panic GrpcContextProvider on async call inside sync code#1870
lklimek merged 6 commits into
v1.0-devfrom
fix/sdk-context-provider-not-set

Conversation

@lklimek

@lklimek lklimek commented Jun 3, 2024

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Two related issues fixed:

  1. Tokio::block_on() panics in sync fn in async context:
thread 'main' panicked at 'Cannot start a runtime from within a runtime. This 
happens because a function (like `block_on`) attempted to block the current 
thread while the thread is being used to drive asynchronous tasks.'
  1. Proof verification cannot fetch contracts
"proof: the contract could not be retrieved during verification: cannot get data contract: Proof verification error: context provider is not set"

This is caused because we have cyclical dependencies: Sdk uses GrpcContextProvider, and GrpcContextProvider uses Sdk.
Unfortunately, due to the way we initialize GrpcContextProvider, it uses an invalid, not complete copy of Sdk. This issue was introduced in #1838 .

What was done?

Issue 1: Implemented a workaround to safely call async code within sync context. This is done in new spawn_async fn that uses oneshot channel to synchronize with async thread.

Issue 2: Refactored GrpcContextProvider to allow setting sdk without need of &mut. This allows the use of Arc<> when referring to GrpcContextProvider, and helps ensure that it uses correct version of Sdk.

How Has This Been Tested?

GHA

Run dash-sdk tests against local network.

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

@lklimek lklimek changed the title fix(sdk): GrpcContextProvider panics when switching sync-async fix(sdk): panic GrpcContextProvider on async call inside sync code Jun 3, 2024
@lklimek
lklimek marked this pull request as ready for review June 3, 2024 13:40
@lklimek
lklimek merged commit 868be18 into v1.0-dev Jul 3, 2024
@lklimek
lklimek deleted the fix/sdk-context-provider-not-set branch July 3, 2024 08:45
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