Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed Nov 14, 2024
1 parent cae06bc commit d46adf8
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
2 changes: 2 additions & 0 deletions solo-chains/node/tanssi-relay-service/src/dev_rpcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct DevRpc {
#[jsonrpsee::core::async_trait]
impl DevApiServer for DevRpc {
async fn enable_para_inherent_candidate(&self) -> RpcResult<()> {
log::info!("entering here");
let mock_para_inherent_channel = self.mock_para_inherent_channel.clone();
// Push the message to the shared channel where it will be queued up
// to be injected in to an upcoming block.
Expand All @@ -55,6 +56,7 @@ impl DevApiServer for DevRpc {
.await
.map_err(|err| internal_err(err.to_string()))?;

log::info!("SENEDING ENABLE");
Ok(())
}

Expand Down
12 changes: 5 additions & 7 deletions solo-chains/node/tanssi-relay-service/src/dev_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,7 @@ where
Err(err) => return Err(InherentError::Blockchain(err)),
};

let parent_hash = client
.hash(parent_header_relay.number.saturating_sub(1))
.unwrap()
.unwrap();
let parent_hash = parent;

let parent_header = match client.header(parent_hash) {
Ok(Some(h)) => h,
Expand Down Expand Up @@ -364,7 +361,7 @@ where
polkadot_primitives::ValidatorId::from_slice(&type_public_pair)
{
if validator_keys_to_find == &validator {
let persisted_validation_data = runtime_api
let mut persisted_validation_data = runtime_api
.persisted_validation_data(
parent_hash,
para[0],
Expand All @@ -373,6 +370,9 @@ where
.unwrap()
.unwrap();

// if we dont do this we have a backed candidate every 2 blocks
persisted_validation_data.relay_parent_storage_root = parent_header.state_root;

let persisted_validation_data_hash = persisted_validation_data.hash();
let validation_code_hash = runtime_api
.validation_code_hash(
Expand Down Expand Up @@ -431,8 +431,6 @@ where
.unwrap()
.benchmark_signature();

log::info!("after sig");

let validity_votes = vec![ValidityAttestation::Explicit(signature)];

backed_cand.push(BackedCandidate::<H256>::new(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import "@tanssi/api-augment";
import { describeSuite, customDevRpcRequest, expect } from "@moonwall/cli";
import { ApiPromise } from "@polkadot/api";
import { jumpBlocks, jumpSessions, jumpToSession } from "util/block";
import { filterAndApply } from "@moonwall/util";
import { EventRecord } from "@polkadot/types/interfaces";
import { bool, u32, u8, Vec } from "@polkadot/types-codec";
import { before } from "node:test";
import { getHeaderFromRelay } from "util/relayInterface.ts";

describeSuite({
id: "DTR1401",
title: "Paras inherent tests",
foundationMethods: "dev",

testCases: ({ it, context }) => {
let polkadotJs: ApiPromise;

before(async () => {
polkadotJs = context.polkadotJs();
});

it({
id: "E01",
title: "Paras heads should be updated every block",
test: async function () {
const parasHeadGenesis = await context.polkadotJs().query.paras.heads(2000);
await context.createBlock();
// Send RPC call to enable para inherent candidate generation
await customDevRpcRequest("mock_enableParaInherentCandidate", []);
// Since collators are not assigned until session 2, we need to go till session 2 to actually see heads being injected
await jumpToSession(context, 3);
await context.createBlock();
const parasHeadAfterOneBlock = await context.polkadotJs().query.paras.heads(2000);
expect(parasHeadAfterOneBlock).to.not.be.eq(parasHeadGenesis);
await context.createBlock();
// we create one more block to test we are persisting candidates every block
const parasHeadAfterTwoBlocks = await context.polkadotJs().query.paras.heads(2000);
expect(parasHeadAfterOneBlock).to.not.be.eq(parasHeadAfterTwoBlocks);
const header2000 = await getHeaderFromRelay(context.polkadotJs(), 2000);
expect(header2000.number.toBigInt()).to.be.equal(31n);
},
});
},
});
13 changes: 10 additions & 3 deletions test/util/relayInterface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { ApiPromise } from "@polkadot/api";
import type { Header, ParaId } from "@polkadot/types/interfaces";
import type { Header, ParaId, HeadData } from "@polkadot/types/interfaces";
import { u8aToHex, u8aToU8a, isU8a, hexToU8a, compactToU8a, compactFromU8a, compactFromU8aLim } from "@polkadot/util"
import { bool, u32, u8, Bytes } from "@polkadot/types-codec";
import { TypeRegistry } from "@polkadot/types";

export async function getHeaderFromRelay(relayApi: ApiPromise, paraId: ParaId): Promise<Header | null> {
// Get the latest header from relay storage
const encoded = await relayApi.query.paras.heads(paraId);
const header = await relayApi.createType("Header", encoded);
const registry = new TypeRegistry();
const headerEncoded: HeadData = await relayApi.createType("HeadData", encoded.toHex());
const nonEncodedHeader = new Bytes(registry, headerEncoded.toU8a(true)).toHex()

const header = await relayApi.createType("SpRuntimeHeader", nonEncodedHeader);
return header;
}
}

0 comments on commit d46adf8

Please sign in to comment.