-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: add grandpa justifications mock rpc #695
Open
qiweiii
wants to merge
7
commits into
master
Choose a base branch
from
feat/rpc-for-bridge-init
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+150
−4
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1dd06d8
feat: add grandpa justifications mock rpc
qiweiii ab99178
fix grandpa subscription
ermalkaleci e18ee10
state_getReadProof
ermalkaleci 83e11be
update comment
ermalkaleci 550b8fa
impl beefy justification
ermalkaleci fdc1a77
fix proof
ermalkaleci 848d9f5
fix justification
ermalkaleci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Handler } from '../shared.js' | ||
|
||
export const grandpa_subscribeJustifications: Handler<void, string> = async (context, _params, { subscribe }) => { | ||
let update = () => {} | ||
|
||
const id = context.chain.headState.subscribeHead(() => update()) | ||
const callback = subscribe('grandpa_justifications', id, () => context.chain.headState.unsubscribeHead(id)) | ||
|
||
update = async () => { | ||
const mockProof = '0x' + '7'.repeat(64) | ||
callback(mockProof) | ||
} | ||
|
||
setTimeout(update, 50) | ||
|
||
return id | ||
} | ||
|
||
export const grandpa_unsubscribeJustifications: Handler<[string], void> = async ( | ||
_context, | ||
[subid], | ||
{ unsubscribe }, | ||
) => { | ||
unsubscribe(subid) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`grandpa rpc > subscribeJustifications 1`] = ` | ||
[ | ||
[ | ||
"0x7777777777777777777777777777777777777777777777777777777777777777", | ||
], | ||
] | ||
`; | ||
|
||
exports[`grandpa rpc > subscribeJustifications 2`] = `"0x7ba5ba52f5b88fa5bcab5c1a0f7e158d845d93e1c70e9a5b42a7c3a9af681ee7"`; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import { api, delay, dev, mockCallback, setupApi } from './helper.js' | ||
|
||
setupApi({ | ||
endpoint: ['wss://rpc.ibp.network/polkadot'], | ||
blockHash: '0xb012d04c56b65cfa1f47cb1f884d920f95d0097b1ed42f5da18d5e2a436c2f3e', | ||
}) | ||
|
||
describe('grandpa rpc', () => { | ||
it('subscribeJustifications', async () => { | ||
const { callback, next } = mockCallback() | ||
const unsub = await api.rpc.grandpa.subscribeJustifications(callback) | ||
|
||
await next() | ||
expect(callback.mock.calls).toMatchSnapshot() | ||
|
||
callback.mockClear() | ||
|
||
expect(await dev.newBlock()).toMatchSnapshot() | ||
|
||
await next() | ||
|
||
expect(callback.mock.calls).toMatchSnapshot() | ||
|
||
callback.mockClear() | ||
|
||
unsub() | ||
|
||
expect(await dev.newBlock()).toMatchSnapshot() | ||
|
||
await delay(100) | ||
|
||
expect(callback).not.toHaveBeenCalled() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way we could get a real proof here ? As far as I know, for this we don't need signing keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@serban300 I've implemented
state_getReadProof
to return proof of requested keys but thetrie_state_root
won't be the same as blocktrie_state_root
. I don't know if correct hash is required and not sure if we can do that. Can you give this a try first before I look deeper into the implementation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ermalkaleci thanks ! Yes, will try this. Just have to prioritize some reviews first, and then I will get to this. Hopefully this week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked. This doesn't work. I'm getting an error when validating the storage proof. We would need the
trie_state_root
to be the same as the blocktrie_state_root
. Since I think that's how we're validating the proof. Would that be possible ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure