Skip to content

Commit

Permalink
getLatestCommitmentBlockNumber after checkAnchorIsWitnessMode
Browse files Browse the repository at this point in the history
  • Loading branch information
madwiki committed Oct 12, 2022
1 parent 2c7f2b8 commit b5b7a0e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ async function syncBlock(appchain: ApiPromise, nextHeight: number) {
await storeCommitment(header.number.toNumber(), commitment);
}
});

const apiAt = await appchain.at(nextBlockHash);
const events = await apiAt.query.system.events();
const containsNewSession = events.findIndex(({ event: { section, method } }) => section === "session" && method === "NewSession") > -1;
if (containsNewSession) {
await storeSession(nextHeight);
}

let signedCommitmentHex: any;
if (justificationsHuman) {
(justificationsHuman as string[]).forEach(justificationHuman => {
Expand Down Expand Up @@ -246,7 +248,9 @@ async function handleSignedCommitment(
) {
const decodedSignedCommitment = decodeSignedCommitment(signedCommitmentHex);
const isWitnessMode = await checkAnchorIsWitnessMode();

if (isWitnessMode) {
return;
}
const blockNumberInAnchor = Number(await getLatestCommitmentBlockNumber());
const { blockNumber } = decodedSignedCommitment.commitment;

Expand All @@ -270,7 +274,7 @@ async function handleSignedCommitment(
)).toJSON();
const isAuthoritiesEqual = isEqual(currentAuthorities, previousAuthorities)

if (isWitnessMode || (unMarkedCommitments.length === 0 && (!isNewSession))) {
if (unMarkedCommitments.length === 0 && (!isNewSession)) {
return;
}

Expand Down

0 comments on commit b5b7a0e

Please sign in to comment.