Skip to content

Commit

Permalink
chore: implement feedback from peer-review.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitdevos committed Dec 6, 2021
1 parent 36d17a9 commit 3b3b25f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/logion/services/blockconsumption.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ export class BlockConsumer {
await this.transactionSynchronizer.addTransactions(block);
for (let i = 0; i < block.extrinsics.length; ++i) {
const extrinsic = block.extrinsics[i];
if (extrinsic.error) {
logger.info("Skipping extrinsic with error: %s", toString(extrinsic))
} else if (extrinsic.method.pallet !== "timestamp") {
if (extrinsic.method.pallet !== "timestamp") {
logger.info("Processing extrinsic: %s", toString(extrinsic))
await this.locSynchronizer.updateLocRequests(extrinsic, timestamp);
await this.protectionSynchronizer.updateProtectionRequests(extrinsic);
Expand Down
6 changes: 5 additions & 1 deletion src/logion/services/locsynchronization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LocRequestAggregateRoot, LocRequestRepository } from '../model/locreque
import { ExtrinsicDataExtractor } from "./extrinsic.data.extractor";
import { decimalToUuid } from '../lib/uuid';
import { JsonArgs } from './call';
import { JsonExtrinsic } from "./types/responses/Extrinsic";
import { JsonExtrinsic, toString } from "./types/responses/Extrinsic";
import { Moment } from "moment";
import { Log } from "../util/Log";

Expand All @@ -19,6 +19,10 @@ export class LocSynchronizer {

async updateLocRequests(extrinsic: JsonExtrinsic, timestamp: Moment) {
if (extrinsic.method.pallet === "logionLoc") {
if (extrinsic.error) {
logger.info("updateLocRequests() - Skipping extrinsic with error: %s", toString(extrinsic))
return
}
if (extrinsic.method.method === "createLoc") {
const locId = this.extractLocId(extrinsic.args);
await this.mutateLoc(locId, loc => loc.setLocCreatedDate(timestamp));
Expand Down
6 changes: 5 additions & 1 deletion src/logion/services/protectionsynchronization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { injectable } from 'inversify';
import { ProtectionRequestRepository, FetchProtectionRequestsSpecification } from '../model/protectionrequest.model';
import { ExtrinsicDataExtractor } from "./extrinsic.data.extractor";
import { JsonArgs } from './call';
import { JsonExtrinsic } from "./types/responses/Extrinsic";
import { JsonExtrinsic, toString } from "./types/responses/Extrinsic";
import { Log } from "../util/Log";

const { logger } = Log;
Expand All @@ -24,6 +24,10 @@ export class ProtectionSynchronizer {

async updateProtectionRequests(extrinsic: JsonExtrinsic): Promise<void> {
if (extrinsic.method.pallet === "verifiedRecovery") {
if (extrinsic.error) {
logger.info("updateProtectionRequests() - Skipping extrinsic with error: %s", toString(extrinsic))
return
}
if (extrinsic.method.method === "createRecovery" && this.nodeOwnerInFriends(extrinsic.args)) {
const signer = extrinsic.signer!;
const requests = await this.protectionRequestRepository.findBy(new FetchProtectionRequestsSpecification({
Expand Down
6 changes: 3 additions & 3 deletions test/unit/services/blockconsumption.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("BlockConsumer", () => {
protectionSynchronizer.verify(instance => instance.updateProtectionRequests(extrinsic.object()), Times.Exactly(5));
});

it("does not consume extrinsics with errors", async () => {
it("consumes extrinsics with errors", async () => {
// Given
const head = 10002n;
blockService.setup(instance => instance.getHeadBlockNumber()).returns(Promise.resolve(head));
Expand Down Expand Up @@ -146,8 +146,8 @@ describe("BlockConsumer", () => {
syncPointRepository.verify(instance => instance.save(syncPoint.object()));

transactionSynchronizer.verify(instance => instance.addTransactions(block.object()), Times.Exactly(1));
locSynchronizer.verify(instance => instance.updateLocRequests(extrinsic.object(), timestamp), Times.Never());
protectionSynchronizer.verify(instance => instance.updateProtectionRequests(extrinsic.object()), Times.Never());
locSynchronizer.verify(instance => instance.updateLocRequests(extrinsic.object(), timestamp), Times.Exactly(1));
protectionSynchronizer.verify(instance => instance.updateProtectionRequests(extrinsic.object()), Times.Exactly(1));
});

it("deletes all and restarts given out of sync", async () => {
Expand Down

0 comments on commit 3b3b25f

Please sign in to comment.