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

Fix codec issue for dense-pull-ledger-diff #982

Merged
merged 5 commits into from
Jan 14, 2023
Merged

Conversation

Dengjianping
Copy link
Contributor

@Dengjianping Dengjianping commented Jan 11, 2023

Signed-off-by: Dengjianping djptux@gmail.com

Description

The workaround is that I implement From trait for DensePullResponse.

impl From<PullResponse> for DensePullResponse {
    #[inline]
    fn from(resp: PullResponse) -> DensePullResponse {
        Self {
            should_continue: resp.should_continue,
            receivers: base64::encode(resp.receivers.encode()),
            senders: base64::encode(resp.senders.encode()),
            senders_receivers_total: resp.senders_receivers_total,
            next_checkpoint: None,
        }
    }
}

When client api calls runtime api, PullResponse will be converted into DensePullResponse.

#[async_trait]
impl<B, C> PullApiServer for Pull<B, C>
where
    B: Block,
    C: 'static + ProvideRuntimeApi<B> + HeaderBackend<B>,
    C::Api: PullLedgerDiffApi<B>,
{
    #[inline]
    fn dense_pull_ledger_diff(
        &self,
        checkpoint: Checkpoint,
        max_receivers: u64,
        max_senders: u64,
    ) -> RpcResult<DensePullResponse> {
        let api = self.client.runtime_api();
        let at = BlockId::hash(self.client.info().finalized_hash);
        api.pull_ledger_diff(&at, checkpoint.into(), max_receivers, max_senders)
            .map(Into::into) // PullResponse to DensePullResponse
            .map_err(|err| {
                CallError::Custom(ErrorObject::owned(
                    PULL_LEDGER_DIFF_ERROR,
                    "Unable to compute dense state diff for pull",
                    Some(format!("{err:?}")),
                ))
                .into()
            })
    }
}

Now the response will be returned correctly.

{
  should_continue: false,
  receivers: 'J0vqVrFQV45G3bIfUnzxdKGRsPRjkbhqScQf0WmosgRP8vqVpKI5YlkgM8468+rxNqpE..`
  senders: 'AA==',
  senders_receivers_total: '0x02000000000000000000000000000000',
  next_checkpoint: null
}

So the runtime api dense_pull_ledger_diff can be removed, RuntimeDensePullResponse is not necessary anymore.
code is more cleaner.

closes #979

Before we can approve this PR for merge, please make sure that all the following items have been checked off:

  • Connected to an issue with discussion and accepted design using zenhub "Connect issue" button below
  • Added one label out of the L- group to this PR
  • Added one or more labels from the A- and C- groups to this PR
  • Explicitly labelled A-calamari, A-dolphin and/or A-manta if your changes are meant for/impact either of these (CI depends on it)
  • Re-reviewed Files changed in the Github PR explorer.

Situational Notes:

  • If adding functionality, write unit tests!
  • If importing a new pallet, choose a proper module index for it, and allow it in BaseFilter. Ensure every extrinsic works from front-end. If there's corresponding tool, ensure both work for each other.
  • If needed, update our Javascript/Typescript APIs. These APIs are officially used by exchanges or community developers.
  • If modifying existing runtime storage items, make sure to implement storage migrations for the runtime and test them with try-runtime. This includes migrations inherited from upstream changes, and you can search the diffs for modifications of #[pallet::storage] items to check for any.

Signed-off-by: Dengjianping <djptux@gmail.com>
Signed-off-by: Dengjianping <djptux@gmail.com>
@Dengjianping Dengjianping self-assigned this Jan 11, 2023
@Dengjianping Dengjianping added C-bug Category: Issues documenting a bug A-calamari Area: Issues and PRs related to the Calamari Runtime P-high Priority: High A-dolphin Area: Issues and PRs related to the Dolphin Runtime A-manta-pay Area: Issues and PRs related to the MantaPay Pallet L-fixed Log: Issues and PRs related to bug fixes A-client Client - i.e. not upgradeable with the runtime - changes labels Jan 11, 2023
@Dengjianping
Copy link
Contributor Author

I will submit typescript based client test cases in another pr soon once this pr gets merged.

@Dengjianping Dengjianping marked this pull request as ready for review January 11, 2023 07:58
@Dengjianping Dengjianping added this to the v4.0.1 milestone Jan 11, 2023
@ghzlatarev
Copy link
Contributor

@Dengjianping description please.

flame4
flame4 previously approved these changes Jan 11, 2023
Copy link
Contributor

@flame4 flame4 left a comment

Choose a reason for hiding this comment

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

Cool solution!

@Dengjianping
Copy link
Contributor Author

@Dengjianping description please.

Added.

ghzlatarev
ghzlatarev previously approved these changes Jan 11, 2023
ferrell-code
ferrell-code previously approved these changes Jan 11, 2023
Signed-off-by: Dengjianping <djptux@gmail.com>
@Dengjianping Dengjianping dismissed stale reviews from ghzlatarev and flame4 via f690dcb January 12, 2023 04:59
Signed-off-by: Dengjianping <djptux@gmail.com>
Copy link
Contributor

@Garandor Garandor left a comment

Choose a reason for hiding this comment

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

LGTM except for the test failure

Copy link
Contributor

@ghzlatarev ghzlatarev left a comment

Choose a reason for hiding this comment

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

LGTM , the unit tests should pass after #981 is merged.

@Dengjianping Dengjianping merged commit a69c6e2 into manta Jan 14, 2023
@Dengjianping Dengjianping deleted the fix-codec-skip branch January 14, 2023 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-calamari Area: Issues and PRs related to the Calamari Runtime A-client Client - i.e. not upgradeable with the runtime - changes A-dolphin Area: Issues and PRs related to the Dolphin Runtime A-manta-pay Area: Issues and PRs related to the MantaPay Pallet C-bug Category: Issues documenting a bug L-fixed Log: Issues and PRs related to bug fixes P-high Priority: High
Projects
None yet
Development

Successfully merging this pull request may close these issues.

senders and receivers are empty in the response of dense_pull_ledger_diff
5 participants