-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(processor): log verification errors (#452)
* Remove console logs * Remove forger errors * Remove UnexpectedError * Remove extra exceptions * Add ValidatorExceptions * Handler throws errors * Improve logs * style: resolve style guide violations --------- Co-authored-by: sebastijankuzner <[email protected]>
- Loading branch information
1 parent
f72fc66
commit 035a4a8
Showing
18 changed files
with
81 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
export * from "./base"; | ||
export * from "./cache"; | ||
export * from "./cli"; | ||
export * from "./config"; | ||
export * from "./consensus"; | ||
export * from "./container"; | ||
export * from "./crypto"; | ||
export * from "./filesystem"; | ||
export * from "./forger"; | ||
export * from "./logic"; | ||
export * from "./p2p"; | ||
export * from "./plugins"; | ||
export * from "./pool"; | ||
export * from "./processor"; | ||
export * from "./runtime"; | ||
export * from "./state"; | ||
export * from "./validation"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Block } from "../contracts/crypto"; | ||
import { Exception } from "./base"; | ||
|
||
export class ValidatorException extends Exception {} | ||
|
||
export class BlockNotChained extends ValidatorException { | ||
public constructor(block: Block) { | ||
super(`Block ${block.data.id} is not chained.`); | ||
} | ||
} | ||
|
||
export class BlockNotVerified extends ValidatorException { | ||
public constructor(block: Block, reason: string) { | ||
super(`Block ${block.data.id} is not verified, because: ${reason}.`); | ||
} | ||
} | ||
|
||
export class InvalidTimestamp extends ValidatorException { | ||
public constructor(block: Block) { | ||
super(`Block ${block.data.id} timestamp is too low.`); | ||
} | ||
} | ||
|
||
export class InvalidGenerator extends ValidatorException { | ||
public constructor(block: Block, expectedValidator: string) { | ||
super( | ||
`Block ${block.data.id} has invalid generator. Block generator is ${block.data.generatorPublicKey} instead ${expectedValidator}.`, | ||
); | ||
} | ||
} | ||
|
||
export class IncompatibleTransactions extends ValidatorException { | ||
public constructor(block: Block) { | ||
super(`Block ${block.data.id} contains incompatible transaction.`); | ||
} | ||
} | ||
|
||
export class InvalidNonce extends ValidatorException { | ||
public constructor(block: Block, sender: string) { | ||
super(`Block ${block.data.id} contains invalid nonce for sender ${sender}.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 3 additions & 5 deletions
8
packages/processor/source/verifiers/incompatible-transactions-verifier.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import { injectable } from "@mainsail/container"; | ||
import { Contracts } from "@mainsail/contracts"; | ||
import { Contracts, Exceptions } from "@mainsail/contracts"; | ||
|
||
@injectable() | ||
export class IncompatibleTransactionsVerifier implements Contracts.Processor.Handler { | ||
public async execute(unit: Contracts.Processor.ProcessableUnit): Promise<boolean> { | ||
public async execute(unit: Contracts.Processor.ProcessableUnit): Promise<void> { | ||
const block = unit.getBlock(); | ||
|
||
for (let index = 1; index < block.transactions.length; index++) { | ||
if (block.transactions[index].data.version !== block.transactions[0].data.version) { | ||
return false; | ||
throw new Exceptions.IncompatibleTransactions(block); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters