90fd044766
- snowbridge-pezpallet-* → pezsnowbridge-pezpallet-* (201 refs) - pallet/ directories → pezpallet/ (4 locations) - Fixed pezpallet.rs self-include recursion bug - Fixed sc-chain-spec hardcoded crate name in derive macro - Reverted .pezpallet_by_name() to .pallet_by_name() (subxt API) - Added BizinikiwiConfig type alias for zombienet tests - Deleted obsolete session state files Verified: pezsnowbridge-pezpallet-*, pezpallet-staking, pezpallet-staking-async, pezframe-benchmarking-cli all pass cargo check
86 lines
3.5 KiB
JavaScript
86 lines
3.5 KiB
JavaScript
const utils = require("./utils");
|
|
|
|
async function run(nodeName, networkInfo, args) {
|
|
const {wsUri, userDefinedTypes} = networkInfo.nodesByName[nodeName];
|
|
const api = await zombie.connect(wsUri, userDefinedTypes);
|
|
|
|
// parse arguments
|
|
const exitAfterSeconds = Number(args[0]);
|
|
const bridgedChain = require("./chains/" + args[1]);
|
|
|
|
// start listening to new blocks
|
|
let atLeastOneMessageReceived = false;
|
|
let atLeastOneMessageDelivered = false;
|
|
const unsubscribe = await api.rpc.chain.subscribeNewHeads(async function (header) {
|
|
const apiAtParent = await api.at(header.parentHash);
|
|
const apiAtCurrent = await api.at(header.hash);
|
|
const currentEvents = await apiAtCurrent.query.system.events();
|
|
|
|
const messagesReceived = currentEvents.find((record) => {
|
|
return record.event.section == bridgedChain.messagesPalletName
|
|
&& record.event.method == "MessagesReceived";
|
|
}) != undefined;
|
|
const messagesDelivered = currentEvents.find((record) => {
|
|
return record.event.section == bridgedChain.messagesPalletName &&
|
|
record.event.method == "MessagesDelivered";
|
|
}) != undefined;
|
|
const hasMessageUpdates = messagesReceived || messagesDelivered;
|
|
atLeastOneMessageReceived = atLeastOneMessageReceived || messagesReceived;
|
|
atLeastOneMessageDelivered = atLeastOneMessageDelivered || messagesDelivered;
|
|
|
|
if (!hasMessageUpdates) {
|
|
// if there are no any message update transactions, we only expect mandatory GRANDPA
|
|
// headers and initial teyrchain headers
|
|
await utils.ensureOnlyMandatoryGrandpaHeadersImported(
|
|
bridgedChain,
|
|
apiAtParent,
|
|
apiAtCurrent,
|
|
currentEvents,
|
|
);
|
|
await utils.ensureOnlyInitialTeyrchainHeaderImported(
|
|
bridgedChain,
|
|
apiAtParent,
|
|
apiAtCurrent,
|
|
currentEvents,
|
|
);
|
|
} else {
|
|
const messageTransactions = (messagesReceived ? 1 : 0) + (messagesDelivered ? 1 : 0);
|
|
|
|
// otherwise we only accept at most one GRANDPA header
|
|
const newGrandpaHeaders = utils.countGrandpaHeaderImports(bridgedChain, currentEvents);
|
|
if (newGrandpaHeaders > 1) {
|
|
utils.logEvents(currentEvents);
|
|
throw new Error("Unexpected relay chain header import: " + newGrandpaHeaders + " / " + messageTransactions);
|
|
}
|
|
|
|
// ...and at most one teyrchain header
|
|
const newTeyrchainHeaders = utils.countTeyrchainHeaderImports(bridgedChain, currentEvents);
|
|
if (newTeyrchainHeaders > 1) {
|
|
utils.logEvents(currentEvents);
|
|
throw new Error("Unexpected teyrchain header import: " + newTeyrchainHeaders + " / " + messageTransactions);
|
|
}
|
|
}
|
|
});
|
|
|
|
// wait until we have received + delivered messages OR until timeout
|
|
await utils.pollUntil(
|
|
exitAfterSeconds,
|
|
() => {
|
|
return atLeastOneMessageReceived && atLeastOneMessageDelivered;
|
|
},
|
|
() => {
|
|
unsubscribe();
|
|
},
|
|
() => {
|
|
if (!atLeastOneMessageReceived) {
|
|
throw new Error("No messages received from bridged chain");
|
|
}
|
|
if (!atLeastOneMessageDelivered) {
|
|
throw new Error("No messages delivered to bridged chain");
|
|
}
|
|
},
|
|
);
|
|
}
|
|
|
|
module.exports = {run}
|