Skip to content

Commit

Permalink
Temp changes to the proof generation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 committed Feb 2, 2024
1 parent f422ba0 commit 03ac26e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/sibling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ export async function generateDipAuthorizedTxForSibling({
providerBlockHeight,
})

// Proof of commitment must be generated with the state root at the block before the last one finalized.
const dipRootProofBlockHash = await providerApi.rpc.chain.getBlockHash(
providerStateRootProofProviderBlockHeight.subn(1),
providerStateRootProofProviderBlockHeight,
)

const {
Expand All @@ -122,6 +121,7 @@ export async function generateDipAuthorizedTxForSibling({
version: proofVersion,
})

// TODO: Getting an invalid DID merkle proof now, need to be investigated further.
const { proof: dipIdentityProof } = await generateDipIdentityProof({
didUri,
providerApi,
Expand Down
20 changes: 11 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,30 @@ export async function generateProviderStateRootProof({
// Optional
providerBlockHeight,
}: ProviderStateRootProofOpts): Promise<ProviderStateRootProofRes> {
const [providerBlockNumber, providerBlockHash] = await (async () => {
const providerBlockNumber = await (async () => {
if (providerBlockHeight !== undefined) {
const blockHash =
await providerApi.rpc.chain.getBlockHash(providerBlockHeight)
return [providerBlockHeight, blockHash]
return providerBlockHeight
}
const providerLastFinalizedBlockHash =
await providerApi.rpc.chain.getFinalizedHead()
const providerLastFinalizedBlockHash = await providerApi.rpc.chain.getFinalizedHead()
const providerLastFinalizedBlockHeight = await providerApi.rpc.chain
.getHeader(providerLastFinalizedBlockHash)
.then((h) => h.number.toBn())
return [providerLastFinalizedBlockHeight, providerLastFinalizedBlockHash]
return providerLastFinalizedBlockHeight
})()
const providerApiAtBlock = await providerApi.at(providerBlockHash)
console.log(`Provider block height: ${providerBlockNumber}`)

Check failure on line 79 in src/utils.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

Unexpected console statement
// State for this block is finalized by the relaychain at the end of the next block, hence we take the next block and retrieve the relaychain validation data.
const nextProviderBlockNumber = providerBlockNumber.addn(1)
const nextProviderBlockHash = await providerApi.rpc.chain.getBlockHash(nextProviderBlockNumber)
const providerApiAtBlock = await providerApi.at(nextProviderBlockHash)
const providerChainId =
await providerApiAtBlock.query.parachainInfo.parachainId()
const relayParentBlockNumber =
await providerApiAtBlock.query.parachainSystem.lastRelayChainBlockNumber()
// This refers to the previously finalized block, we need the current one.
console.log(`Relay parent block number for the provider finalized block: ${relayParentBlockNumber}`)

Check failure on line 88 in src/utils.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

Unexpected console statement
const relayParentBlockHash = await relayApi.rpc.chain.getBlockHash(
relayParentBlockNumber,
)
console.log(`Relay parent block hash for the provider finalized block: ${relayParentBlockNumber}`)

Check failure on line 92 in src/utils.ts

View workflow job for this annotation

GitHub Actions / lint-and-build

Unexpected console statement

const proof = await relayApi.rpc.state.getReadProof(
[relayApi.query.paras.heads.key(providerChainId)],
Expand Down
6 changes: 3 additions & 3 deletions tests/peregrine-dip-consumer-template/.env.develop.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RELAY_IMAGE=parity/polkadot:v1.0.0
RELAY_ALICE_RPC=10001
RELAY_ALICE_RPC=50001
PROVIDER_IMAGE=kiltprotocol/kilt-node:latest-develop
PROVIDER_ALICE_RPC=10011
PROVIDER_ALICE_RPC=50010
CONSUMER_IMAGE=kiltprotocol/dip-consumer-node-template:latest-develop
CONSUMER_ALICE_RPC=10021
CONSUMER_ALICE_RPC=50060
9 changes: 5 additions & 4 deletions tests/peregrine-dip-consumer-template/develop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ describe("V0", () => {
withCrossModuleSystemImport<typeof import("@kiltprotocol/dip-sdk")>(
"..",
async (DipSdk) => {
// TODO: The provider block considered is the one where the state is changed, and so far so good.
// The problem stems from the fact that such state, even when it's finalized, will be included into a successive block by the relaychain, not the previous one.
// Hence, given a block number for the provider, the relay block to consider is the one in the validation data + 1.
it("Successful posts on the consumer's PostIt pallet using by default the latest provider finalized block", async () => {
const { consumerApi } = testConfig
const postText = "Hello, world!"
Expand All @@ -219,8 +222,7 @@ describe("V0", () => {
const postKey = blake2AsHex(
consumerApi
.createType(
`(${
config.blockNumberRuntimeType as string
`(${config.blockNumberRuntimeType as string
}, ${web3NameRuntimeType}, Bytes)`,
[blockNumber, web3Name, postText],
)
Expand Down Expand Up @@ -262,8 +264,7 @@ describe("V0", () => {
const postKey = blake2AsHex(
consumerApi
.createType(
`(${
config.blockNumberRuntimeType as string
`(${config.blockNumberRuntimeType as string
}, ${web3NameRuntimeType}, Bytes)`,
[blockNumber, web3Name, postText],
)
Expand Down

0 comments on commit 03ac26e

Please sign in to comment.