Skip to content

Commit 36e1b9c

Browse files
author
Matthew Orris
committed
# Goal
This PR aims to remove the `rustup install toolchain nightly` commands from the individual GitHub jobs that use the `ci-base-image` that previously did not have the `nightly` toolchain. Closes #1727 # Discussion The changes in the previous PR (#1700) to add the `nightly` toolchain to `ci-base-image` were not published to DockerHub until the `merge-pr.yml` workflow actions were successfully run. Therefore the `nightly` toolchain was not available for CI to use in `ci-base-image`. In that PR, the `nightly` toolchain was installed in the individual jobs where it was needed to pass CI. Now that the PR has been merged, `ci-base-image` has been updated with both the `stable` and `nightly` toolchains and the redundant `rustup install` commands can be removed from `verify-pr-commit.yml`.
1 parent 831337e commit 36e1b9c

24 files changed

+492
-172
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ jobs:
348348
uses: actions/configure-pages@v3
349349
- name: Build Docs
350350
run: |
351-
rustup target add wasm32-unknown-unknown
351+
rustup target add wasm32-unknown-unknown --toolchain nightly-2023-07-13
352352
RUSTDOCFLAGS="--enable-index-page -Zunstable-options" cargo +nightly-2023-07-13 doc --no-deps --workspace --features frequency
353353
- name: Fix file permissions
354354
shell: sh

.github/workflows/rococo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ env:
1616
jobs:
1717
run-e2e:
1818
name: Run E2E Tests
19-
runs-on: ubuntu-20.04
19+
runs-on: [self-hosted, Linux, X64, build, v2]
2020
container: ghcr.io/libertydsnp/frequency/ci-base-image
2121
steps:
2222
- name: Validate

.github/workflows/verify-pr-commit.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ jobs:
199199
- name: Check Out Repo
200200
uses: actions/checkout@v4
201201
- name: Check
202-
# Remove these install commands when ci-base-image has nightly toolchain
203202
run: |
204-
rustup toolchain install nightly-2023-07-13
205-
rustup target add x86_64-unknown-linux-gnu --toolchain nightly-2023-07-13
206203
cargo +nightly-2023-07-13 fmt --check
207204
208205
lint-rust-code:
@@ -215,10 +212,7 @@ jobs:
215212
- name: Check Out Repo
216213
uses: actions/checkout@v4
217214
- name: Lint
218-
# Remove these install commands when ci-base-image has nightly toolchain
219215
run: |
220-
rustup toolchain install nightly-2023-07-13
221-
rustup target add x86_64-unknown-linux-gnu --toolchain nightly-2023-07-13
222216
SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo +nightly-2023-07-13 clippy \
223217
--features runtime-benchmarks,frequency-lint-check \
224218
-- \
@@ -234,9 +228,7 @@ jobs:
234228
- name: Check Out Repo
235229
uses: actions/checkout@v4
236230
- name: Build Docs
237-
# Remove these install commands when ci-base-image has nightly toolchain
238231
run: |
239-
rustup toolchain install nightly-2023-07-13
240232
rustup target add wasm32-unknown-unknown --toolchain nightly-2023-07-13
241233
RUSTDOCFLAGS="--enable-index-page --check -Zunstable-options" cargo +nightly-2023-07-13 doc --no-deps --features frequency
242234
@@ -643,8 +635,7 @@ jobs:
643635
if: needs.changes.outputs.run-e2e == 'true'
644636
needs: [build-binaries, verify-js-api-augment]
645637
name: Run E2E Tests
646-
runs-on: ubuntu-20.04
647-
container: ghcr.io/libertydsnp/frequency/ci-base-image
638+
runs-on: [self-hosted, Linux, X64, build, v2]
648639
steps:
649640
- name: Check Out Repo
650641
uses: actions/checkout@v4

e2e/package-lock.json

Lines changed: 22 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
"@polkadot/util": "12.5.1",
2525
"helia": "^2.0.3",
2626
"multiformats": "^12.1.1",
27-
"rxjs": "^7.8.1"
27+
"rxjs": "^7.8.1",
28+
"workerpool": "^6.5.1"
2829
},
2930
"devDependencies": {
3031
"@polkadot/typegen": "10.9.1",
3132
"@types/mocha": "^10.0.2",
33+
"@types/workerpool": "^6.4.5",
3234
"@typescript-eslint/eslint-plugin": "^6.7.3",
3335
"@typescript-eslint/parser": "^6.7.3",
3436
"mocha": "^10.2.0",

e2e/scaffolding/extrinsicHelpers.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,6 @@ export class ExtrinsicHelper {
211211
return firstValueFrom(ExtrinsicHelper.api.rpc.chain.getBlock());
212212
}
213213

214-
/** engine_createBlock **/
215-
public static createBlock(): Promise<CreatedBlock> {
216-
return firstValueFrom(ExtrinsicHelper.api.rpc.engine.createBlock(true, true));
217-
}
218-
219214
/** Query Extrinsics */
220215
public static getAccountInfo(address: string): Promise<FrameSystemAccountInfo> {
221216
return ExtrinsicHelper.apiPromise.query.system.account(address);
@@ -243,6 +238,11 @@ export class ExtrinsicHelper {
243238
return new Extrinsic(() => ExtrinsicHelper.api.tx.schemas.createSchema(JSON.stringify(model), modelType, payloadLocation), keys, ExtrinsicHelper.api.events.schemas.SchemaCreated);
244239
}
245240

241+
/** Schema v2 Extrinsics */
242+
public static createSchemaV2(keys: KeyringPair, model: any, modelType: "AvroBinary" | "Parquet", payloadLocation: "OnChain" | "IPFS" | "Itemized" | "Paginated", grant: ("AppendOnly"| "SignatureRequired")[]): Extrinsic {
243+
return new Extrinsic(() => ExtrinsicHelper.api.tx.schemas.createSchemaV2(JSON.stringify(model), modelType, payloadLocation, grant), keys, ExtrinsicHelper.api.events.schemas.SchemaCreated);
244+
}
245+
246246
/** Generic Schema Extrinsics */
247247
public static createSchemaWithSettingsGov(keys: KeyringPair, model: any, modelType: "AvroBinary" | "Parquet", payloadLocation: "OnChain" | "IPFS"| "Itemized" | "Paginated", grant: "AppendOnly"| "SignatureRequired"): Extrinsic {
248248
return new Extrinsic(() => ExtrinsicHelper.api.tx.schemas.createSchemaViaGovernance(keys.publicKey, JSON.stringify(model), modelType, payloadLocation, [grant]), keys, ExtrinsicHelper.api.events.schemas.SchemaCreated);
@@ -425,7 +425,7 @@ export class ExtrinsicHelper {
425425
if (hasRelayChain()) {
426426
await new Promise((r) => setTimeout(r, 4_000));
427427
} else {
428-
await ExtrinsicHelper.createBlock();
428+
await firstValueFrom(ExtrinsicHelper.api.rpc.engine.createBlock(true, true));
429429
}
430430
currentBlock = await getBlockNumber();
431431
}

e2e/scaffolding/globalHooks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { cryptoWaitReady } from "@polkadot/util-crypto";
2+
import workerpool from 'workerpool';
23
import { ExtrinsicHelper } from "./extrinsicHelpers";
34
import { fundingSources, getFundingSource, getRootFundingSource, getSudo } from "./funding";
45
import { TEST_EPOCH_LENGTH, drainKeys, getNonce, setEpochLength } from "./helpers";
@@ -28,7 +29,7 @@ function drainAllSources() {
2829
}
2930

3031
export async function mochaGlobalSetup() {
31-
console.log('Global Setup Start');
32+
console.log('Global Setup Start', "Reported CPU Count: ", workerpool.cpus);
3233
await cryptoWaitReady();
3334
await ExtrinsicHelper.initialize();
3435
await fundAllSources();

e2e/scenarios/grantDelegation.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ describe("Delegation Scenario Tests", function () {
313313

314314
it("revoked delegation should be reflected in all previously-granted schema permissions", async () => {
315315
// Make a block first to make sure the state has rolled to the next block
316-
await ExtrinsicHelper.createBlock();
316+
const currentBlock = (await ExtrinsicHelper.apiPromise.rpc.chain.getBlock()).block.header.number.toNumber();
317+
ExtrinsicHelper.runToBlock(currentBlock + 1);
317318
const delegationsResponse = await ExtrinsicHelper.apiPromise.rpc.msa.grantedSchemaIdsByMsaId(msaId, providerId);
318319
assert(delegationsResponse.isSome);
319320
const delegations: SchemaGrantResponse[] = delegationsResponse.unwrap().toArray();

e2e/schemas/createSchema.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ describe("#createSchema", function () {
2626
});
2727
});
2828

29+
it("should fail if account does not have enough tokens v2", async function () {
30+
31+
await assert.rejects(ExtrinsicHelper.createSchemaV2(accountWithNoFunds, AVRO_GRAPH_CHANGE, "AvroBinary", "OnChain",[]).signAndSend(), {
32+
name: 'RpcError',
33+
message: /Inability to pay some fees/,
34+
});
35+
});
36+
2937
it("should fail to create invalid schema", async function () {
3038
const f = ExtrinsicHelper.createSchema(keys, new Array(1000, 3), "AvroBinary", "OnChain");
3139

@@ -34,13 +42,28 @@ describe("#createSchema", function () {
3442
});
3543
});
3644

45+
it("should fail to create invalid schema v2", async function () {
46+
const f = ExtrinsicHelper.createSchemaV2(keys, new Array(1000, 3), "AvroBinary", "OnChain", []);
47+
48+
await assert.rejects(f.fundAndSend(fundingSource), {
49+
name: 'InvalidSchema',
50+
});
51+
});
52+
3753
it("should fail to create schema less than minimum size", async function () {
3854
const f = ExtrinsicHelper.createSchema(keys, {}, "AvroBinary", "OnChain");
3955
await assert.rejects(f.fundAndSend(fundingSource), {
4056
name: 'LessThanMinSchemaModelBytes',
4157
});
4258
});
4359

60+
it("should fail to create schema less than minimum size v2", async function () {
61+
const f = ExtrinsicHelper.createSchemaV2(keys, {}, "AvroBinary", "OnChain", []);
62+
await assert.rejects(f.fundAndSend(fundingSource), {
63+
name: 'LessThanMinSchemaModelBytes',
64+
});
65+
});
66+
4467
it("should fail to create schema greater than maximum size", async function () {
4568
const maxBytes = (await ExtrinsicHelper.getSchemaMaxBytes()).toNumber();
4669

@@ -59,6 +82,24 @@ describe("#createSchema", function () {
5982
});
6083
});
6184

85+
it("should fail to create schema greater than maximum size v2", async function () {
86+
const maxBytes = (await ExtrinsicHelper.getSchemaMaxBytes()).toNumber();
87+
88+
// Create a schema whose JSON representation is exactly 1 byte larger than the max allowed
89+
const hugeSchema = {
90+
type: "record",
91+
fields: [],
92+
}
93+
const hugeSize = JSON.stringify(hugeSchema).length;
94+
const sizeToFill = maxBytes - hugeSize - ',"name":""'.length + 1;
95+
hugeSchema["name"] = Array.from(Array(sizeToFill).keys()).map(i => 'a').join('');
96+
97+
const f = ExtrinsicHelper.createSchemaV2(keys, hugeSchema, "AvroBinary", "OnChain", []);
98+
await assert.rejects(f.fundAndSend(fundingSource), {
99+
name: 'ExceedsMaxSchemaModelBytes',
100+
});
101+
});
102+
62103
it("should successfully create an Avro GraphChange schema", async function () {
63104
const f = ExtrinsicHelper.createSchema(keys, AVRO_GRAPH_CHANGE, "AvroBinary", "OnChain");
64105
const [createSchemaEvent, eventMap] = await f.fundAndSend(fundingSource);
@@ -67,4 +108,12 @@ describe("#createSchema", function () {
67108
assert.notEqual(createSchemaEvent, undefined);
68109
});
69110

111+
it("should successfully create an Avro GraphChange schema v2", async function () {
112+
const f = ExtrinsicHelper.createSchemaV2(keys, AVRO_GRAPH_CHANGE, "AvroBinary", "OnChain", []);
113+
const [createSchemaEvent, eventMap] = await f.fundAndSend(fundingSource);
114+
115+
assertExtrinsicSuccess(eventMap);
116+
assert.notEqual(createSchemaEvent, undefined);
117+
});
118+
70119
})

pallets/messages/src/benchmarking.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use frame_support::{assert_ok, pallet_prelude::DispatchResult};
1313
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
1414
use sp_runtime::traits::One;
1515

16-
const AVERAGE_NUMBER_OF_MESSAGES: u32 = 499;
1716
const IPFS_SCHEMA_ID: u16 = 50;
1817
const IPFS_PAYLOAD_LENGTH: u32 = 10;
1918

@@ -23,7 +22,7 @@ fn onchain_message<T: Config>(schema_id: SchemaId) -> DispatchResult {
2322
let payload = Vec::from(
2423
"{'fromId': 123, 'content': '232323', 'fromId': 123, 'content': '232323'}".as_bytes(),
2524
);
26-
let bounded_payload: BoundedVec<u8, T::MaxMessagePayloadSizeBytes> =
25+
let bounded_payload: BoundedVec<u8, T::MessagesMaxPayloadSizeBytes> =
2726
payload.try_into().expect("Invalid payload");
2827
MessagesPallet::<T>::add_message(
2928
provider_id.into(),
@@ -40,7 +39,7 @@ fn ipfs_message<T: Config>(schema_id: SchemaId) -> DispatchResult {
4039
let payload =
4140
Vec::from("bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq".as_bytes());
4241
let provider_id = ProviderId(1);
43-
let bounded_payload: BoundedVec<u8, T::MaxMessagePayloadSizeBytes> =
42+
let bounded_payload: BoundedVec<u8, T::MessagesMaxPayloadSizeBytes> =
4443
payload.try_into().expect("Invalid payload");
4544

4645
MessagesPallet::<T>::add_message(
@@ -63,8 +62,10 @@ fn create_schema<T: Config>(location: PayloadLocation) -> DispatchResult {
6362
}
6463

6564
benchmarks! {
65+
// this is temporary to avoid massive PoV sizes which will break the chain until rework on messages
66+
#[pov_mode = Measured]
6667
add_onchain_message {
67-
let n in 0 .. T::MaxMessagePayloadSizeBytes::get() - 1;
68+
let n in 0 .. T::MessagesMaxPayloadSizeBytes::get() - 1;
6869
let message_source_id = DelegatorId(2);
6970
let caller: T::AccountId = whitelisted_caller();
7071
let schema_id = 1;
@@ -77,19 +78,21 @@ benchmarks! {
7778
assert_ok!(T::MsaBenchmarkHelper::set_delegation_relationship(ProviderId(1), message_source_id.into(), [schema_id].to_vec()));
7879

7980
let payload = vec![1; n as usize];
80-
81-
for j in 1 .. AVERAGE_NUMBER_OF_MESSAGES {
81+
let average_messages_per_block: u32 = T::MaxMessagesPerBlock::get() / 2;
82+
for j in 1 .. average_messages_per_block {
8283
assert_ok!(onchain_message::<T>(schema_id));
8384
}
8485
}: _ (RawOrigin::Signed(caller), Some(message_source_id.into()), schema_id, payload)
8586
verify {
8687
assert_eq!(
8788
MessagesPallet::<T>::get_messages(
8889
BlockNumberFor::<T>::one(), schema_id).len(),
89-
AVERAGE_NUMBER_OF_MESSAGES as usize
90+
average_messages_per_block as usize
9091
);
9192
}
9293

94+
// this is temporary to avoid massive PoV sizes which will break the chain until rework on messages
95+
#[pov_mode = Measured]
9396
add_ipfs_message {
9497
let caller: T::AccountId = whitelisted_caller();
9598
let cid = "bafkreidgvpkjawlxz6sffxzwgooowe5yt7i6wsyg236mfoks77nywkptdq".as_bytes().to_vec();
@@ -99,16 +102,16 @@ benchmarks! {
99102
assert_ok!(create_schema::<T>(PayloadLocation::IPFS));
100103
}
101104
assert_ok!(T::MsaBenchmarkHelper::add_key(ProviderId(1).into(), caller.clone()));
102-
103-
for j in 1 .. AVERAGE_NUMBER_OF_MESSAGES {
105+
let average_messages_per_block: u32 = T::MaxMessagesPerBlock::get() / 2;
106+
for j in 1 .. average_messages_per_block {
104107
assert_ok!(ipfs_message::<T>(IPFS_SCHEMA_ID));
105108
}
106109
}: _ (RawOrigin::Signed(caller),IPFS_SCHEMA_ID, cid, IPFS_PAYLOAD_LENGTH)
107110
verify {
108111
assert_eq!(
109112
MessagesPallet::<T>::get_messages(
110113
BlockNumberFor::<T>::one(), IPFS_SCHEMA_ID).len(),
111-
AVERAGE_NUMBER_OF_MESSAGES as usize
114+
average_messages_per_block as usize
112115
);
113116
}
114117

0 commit comments

Comments
 (0)