From e6620180894c3f87a8af6ae2bae9c1e1ae345218 Mon Sep 17 00:00:00 2001 From: supaiku Date: Wed, 16 Jan 2019 00:51:17 +0100 Subject: [PATCH 1/5] fix: backport slot check from master --- .../__tests__/blockchain.test.ts | 42 ++++++++++ .../utils/is-blocked-chained.test.ts | 80 +++++++++++++++++-- packages/core-blockchain/src/blockchain.ts | 7 ++ .../src/utils/is-block-chained.ts | 9 ++- packages/crypto/src/crypto/slots.ts | 3 +- 5 files changed, 129 insertions(+), 12 deletions(-) diff --git a/packages/core-blockchain/__tests__/blockchain.test.ts b/packages/core-blockchain/__tests__/blockchain.test.ts index c803f856c7..33036445f0 100644 --- a/packages/core-blockchain/__tests__/blockchain.test.ts +++ b/packages/core-blockchain/__tests__/blockchain.test.ts @@ -258,6 +258,48 @@ describe("Blockchain", () => { }); }); + describe("handleIncommingBlock", () => { + it("should be ok", () => { + const dispatch = blockchain.dispatch; + const enqueueBlocks = blockchain.enqueueBlocks; + blockchain.dispatch = jest.fn(() => true); + blockchain.enqueueBlocks = jest.fn(() => true); + + const block = { + height: 100, + timestamp: slots.getEpochTime(), + }; + + blockchain.handleIncomingBlock(block); + + expect(blockchain.dispatch).toHaveBeenCalled(); + expect(blockchain.enqueueBlocks).toHaveBeenCalled(); + + blockchain.dispatch = dispatch; + blockchain.enqueueBlocks = enqueueBlocks; + }); + + it("should not handle block from future slot", () => { + const dispatch = blockchain.dispatch; + const enqueueBlocks = blockchain.enqueueBlocks; + blockchain.dispatch = jest.fn(() => true); + blockchain.enqueueBlocks = jest.fn(() => true); + + const block = { + height: 100, + timestamp: slots.getSlotTime(slots.getNextSlot()), + }; + + blockchain.handleIncomingBlock(block); + + expect(blockchain.dispatch).not.toHaveBeenCalled(); + expect(blockchain.enqueueBlocks).not.toHaveBeenCalled(); + + blockchain.dispatch = dispatch; + blockchain.enqueueBlocks = enqueueBlocks; + }); + }); + describe("isSynced", () => { describe("with a block param", () => { it("should be ok", () => { diff --git a/packages/core-blockchain/__tests__/utils/is-blocked-chained.test.ts b/packages/core-blockchain/__tests__/utils/is-blocked-chained.test.ts index 5dfdff6eaf..295e567452 100644 --- a/packages/core-blockchain/__tests__/utils/is-blocked-chained.test.ts +++ b/packages/core-blockchain/__tests__/utils/is-blocked-chained.test.ts @@ -1,6 +1,6 @@ import "jest-extended"; -import { models } from "@arkecosystem/crypto"; +import { models, slots } from "@arkecosystem/crypto"; import { isBlockChained } from "../../src/utils"; describe("isChained", () => { @@ -8,7 +8,7 @@ describe("isChained", () => { const previousBlock = { data: { id: "1", - timestamp: 1, + timestamp: slots.getSlotTime(0), height: 1, previousBlock: null, }, @@ -17,20 +17,20 @@ describe("isChained", () => { const nextBlock = { data: { id: "2", - timestamp: 2, + timestamp: slots.getSlotTime(1), height: 2, previousBlock: "1", }, - } as models.IBlock; + } as models.IBlock; expect(isBlockChained(previousBlock, nextBlock)).toBeTrue(); }); - it("should not be ok", () => { + it("should not chain when previous block does not match", () => { const previousBlock = { data: { id: "2", - timestamp: 2, + timestamp: slots.getSlotTime(0), height: 2, previousBlock: null, }, @@ -39,8 +39,74 @@ describe("isChained", () => { const nextBlock = { data: { id: "1", - timestamp: 1, + timestamp: slots.getSlotTime(1), + height: 3, + previousBlock: "1", + }, + } as models.IBlock; + + expect(isBlockChained(previousBlock, nextBlock)).toBeFalse(); + }); + + it("should not chain when next height is not plus 1", () => { + const previousBlock = { + data: { + id: "1", + timestamp: slots.getSlotTime(0), + height: 1, + previousBlock: null, + }, + } as models.IBlock; + + const nextBlock = { + data: { + id: "2", + timestamp: slots.getSlotTime(1), + height: 3, + previousBlock: "1", + }, + } as models.IBlock; + + expect(isBlockChained(previousBlock, nextBlock)).toBeFalse(); + }); + + it("should not chain when same slot", () => { + const previousBlock = { + data: { + id: "1", + timestamp: slots.getSlotTime(0), + height: 1, + previousBlock: null, + }, + } as models.IBlock; + + const nextBlock = { + data: { + id: "2", + timestamp: slots.getSlotTime(0), + height: 3, + previousBlock: "1", + }, + } as models.IBlock; + + expect(isBlockChained(previousBlock, nextBlock)).toBeFalse(); + }); + + it("should not chain when lower slot", () => { + const previousBlock = { + data: { + id: "1", + timestamp: slots.getSlotTime(1), height: 1, + previousBlock: null, + }, + } as models.IBlock; + + const nextBlock = { + data: { + id: "2", + timestamp: slots.getSlotTime(0), + height: 3, previousBlock: "1", }, } as models.IBlock; diff --git a/packages/core-blockchain/src/blockchain.ts b/packages/core-blockchain/src/blockchain.ts index a595dfe786..6487ce87e2 100644 --- a/packages/core-blockchain/src/blockchain.ts +++ b/packages/core-blockchain/src/blockchain.ts @@ -231,6 +231,13 @@ export class Blockchain implements blockchain.IBlockchain { )} from ${block.ip}`, ); + const currentSlot = slots.getSlotNumber(); + const receivedSlot = slots.getSlotNumber(block.timestamp); + if (receivedSlot > currentSlot) { + logger.info(`Discarded block ${block.height.toLocaleString()} because it takes a future slot.`); + return; + } + if (this.state.started && this.state.blockchain.value === "idle") { this.dispatch("NEWBLOCK"); this.enqueueBlocks([block]); diff --git a/packages/core-blockchain/src/utils/is-block-chained.ts b/packages/core-blockchain/src/utils/is-block-chained.ts index 6b6d7f0bc0..5f3396a3e2 100644 --- a/packages/core-blockchain/src/utils/is-block-chained.ts +++ b/packages/core-blockchain/src/utils/is-block-chained.ts @@ -1,9 +1,12 @@ -import { models } from "@arkecosystem/crypto"; +import { models, slots } from "@arkecosystem/crypto"; export const isBlockChained = (previousBlock: models.IBlock, nextBlock: models.IBlock): boolean => { const followsPrevious = nextBlock.data.previousBlock === previousBlock.data.id; - const isFuture = nextBlock.data.timestamp > previousBlock.data.timestamp; const isPlusOne = nextBlock.data.height === previousBlock.data.height + 1; - return followsPrevious && isFuture && isPlusOne; + const previousSlot = slots.getSlotNumber(previousBlock.data.timestamp); + const nextSlot = slots.getSlotNumber(nextBlock.data.timestamp); + const isAfterPreviousSlot = previousSlot < nextSlot; + + return followsPrevious && isPlusOne && isAfterPreviousSlot; }; diff --git a/packages/crypto/src/crypto/slots.ts b/packages/crypto/src/crypto/slots.ts index 540e72b1c1..86e2112c80 100644 --- a/packages/crypto/src/crypto/slots.ts +++ b/packages/crypto/src/crypto/slots.ts @@ -91,7 +91,6 @@ class Slots { /** * Get the next slot number. - * @return {Number} */ public getNextSlot(): number { return this.getSlotNumber() + 1; @@ -125,4 +124,4 @@ class Slots { } } -export const slots = new Slots(); \ No newline at end of file +export const slots = new Slots(); From 533be5e69d06901066201439b0ff443ce37d2573 Mon Sep 17 00:00:00 2001 From: supaiku Date: Wed, 16 Jan 2019 02:42:25 +0100 Subject: [PATCH 2/5] refactor: add ExceptionHandler to BlockProcessor to handle exceptional blocks separately --- .../src/processor/block-processor.ts | 29 ++++++------ .../processor/handlers/exception-handler.ts | 21 +++++++++ .../src/processor/handlers/index.ts | 1 + packages/core-blockchain/src/state-machine.ts | 4 +- .../src/utils/validate-generator.ts | 6 +-- .../src/repositories/blocks.ts | 2 +- packages/core-database/src/wallet-manager.ts | 4 +- packages/crypto/src/crypto/crypto.ts | 13 ++++-- packages/crypto/src/models/block.ts | 6 ++- packages/crypto/src/models/transaction.ts | 9 +++- .../src/networks/devnet/exceptions.json | 44 ++++++++++++++++++- 11 files changed, 106 insertions(+), 33 deletions(-) create mode 100644 packages/core-blockchain/src/processor/handlers/exception-handler.ts diff --git a/packages/core-blockchain/src/processor/block-processor.ts b/packages/core-blockchain/src/processor/block-processor.ts index 35d87782ea..47d70f6807 100644 --- a/packages/core-blockchain/src/processor/block-processor.ts +++ b/packages/core-blockchain/src/processor/block-processor.ts @@ -2,7 +2,7 @@ import { app } from "@arkecosystem/core-container"; import { Logger } from "@arkecosystem/core-interfaces"; -import { isException, models } from "@arkecosystem/crypto"; +import { models } from "@arkecosystem/crypto"; import { Blockchain } from "../blockchain"; import { isBlockChained } from "../utils/is-block-chained"; import { validateGenerator } from "../utils/validate-generator"; @@ -11,6 +11,7 @@ import { AcceptBlockHandler, AlreadyForgedHandler, BlockHandler, + ExceptionHandler, InvalidGeneratorHandler, UnchainedHandler, VerificationFailedHandler, @@ -35,6 +36,10 @@ export class BlockProcessor { } public async getHandler(block: models.Block): Promise { + if (block.isException) { + return new ExceptionHandler(this.blockchain, block); + } + if (!this.verifyBlock(block)) { return new VerificationFailedHandler(this.blockchain, block); } @@ -63,21 +68,13 @@ export class BlockProcessor { private verifyBlock(block: models.Block): boolean { const verified = block.verification.verified; if (!verified) { - if (isException(block.data)) { - this.logger.warn( - `Block ${block.data.height.toLocaleString()} (${ - block.data.id - }) verification failed, but accepting because it is an exception.`, - ); - } else { - this.logger.warn( - `Block ${block.data.height.toLocaleString()} (${ - block.data.id - }) disregarded because verification failed :scroll:`, - ); - this.logger.warn(JSON.stringify(block.verification, null, 4)); - return false; - } + this.logger.warn( + `Block ${block.data.height.toLocaleString()} (${ + block.data.id + }) disregarded because verification failed :scroll:`, + ); + this.logger.warn(JSON.stringify(block.verification, null, 4)); + return false; } return true; diff --git a/packages/core-blockchain/src/processor/handlers/exception-handler.ts b/packages/core-blockchain/src/processor/handlers/exception-handler.ts new file mode 100644 index 0000000000..f40e869f67 --- /dev/null +++ b/packages/core-blockchain/src/processor/handlers/exception-handler.ts @@ -0,0 +1,21 @@ +import { BlockProcessorResult } from "../block-processor"; +import { AcceptBlockHandler } from "./accept-block-handler"; +import { BlockHandler } from "./block-handler"; + +export class ExceptionHandler extends BlockHandler { + public async execute(): Promise { + // Ensure the block has not been forged yet, as an exceptional + // block bypasses all other checks. + const forgedBlock = await this.blockchain.database.getBlock(this.block.data.id); + if (forgedBlock) { + super.execute(); + return BlockProcessorResult.Rejected; + } + + this.logger.warn( + `Block ${this.block.data.height.toLocaleString()} (${this.block.data.id}) forcibly accepted. :exclamation:`, + ); + + return new AcceptBlockHandler(this.blockchain, this.block).execute(); + } +} diff --git a/packages/core-blockchain/src/processor/handlers/index.ts b/packages/core-blockchain/src/processor/handlers/index.ts index 1bdfc241d6..924075ccec 100644 --- a/packages/core-blockchain/src/processor/handlers/index.ts +++ b/packages/core-blockchain/src/processor/handlers/index.ts @@ -1,6 +1,7 @@ export * from "./accept-block-handler"; export * from "./already-forged-handler"; export * from "./block-handler"; +export * from "./exception-handler"; export * from "./invalid-generator-handler"; export * from "./unchained-handler"; export * from "./verification-failed-handler"; diff --git a/packages/core-blockchain/src/state-machine.ts b/packages/core-blockchain/src/state-machine.ts index 6097a8ea97..2d60fc6da6 100644 --- a/packages/core-blockchain/src/state-machine.ts +++ b/packages/core-blockchain/src/state-machine.ts @@ -4,7 +4,7 @@ import { app } from "@arkecosystem/core-container"; import { EventEmitter, Logger } from "@arkecosystem/core-interfaces"; import { roundCalculator } from "@arkecosystem/core-utils"; -import { models, slots } from "@arkecosystem/crypto"; +import { isException, models, slots } from "@arkecosystem/crypto"; import pluralize from "pluralize"; import { config as localConfig } from "./config"; @@ -320,7 +320,7 @@ blockchainMachine.actionMap = (blockchain: Blockchain) => ({ } const empty = !blocks || blocks.length === 0; - const chained = !empty && isBlockChained(lastDownloadedBlock, { data: blocks[0] }); + const chained = !empty && (isBlockChained(lastDownloadedBlock, { data: blocks[0] }) || isException(blocks[0])); if (chained) { logger.info( diff --git a/packages/core-blockchain/src/utils/validate-generator.ts b/packages/core-blockchain/src/utils/validate-generator.ts index af6b19dcab..f517b58948 100644 --- a/packages/core-blockchain/src/utils/validate-generator.ts +++ b/packages/core-blockchain/src/utils/validate-generator.ts @@ -1,15 +1,11 @@ import { app } from "@arkecosystem/core-container"; import { Logger } from "@arkecosystem/core-interfaces"; -import { isException, models, slots } from "@arkecosystem/crypto"; +import { models, slots } from "@arkecosystem/crypto"; export const validateGenerator = async (block: models.Block): Promise => { const database = app.resolvePlugin("database"); const logger = app.resolvePlugin("logger"); - if (isException(block.data)) { - return true; - } - const delegates = await database.getActiveDelegates(block.data.height); const slot = slots.getSlotNumber(block.data.timestamp); const forgingDelegate = delegates[slot % delegates.length]; diff --git a/packages/core-database-postgres/src/repositories/blocks.ts b/packages/core-database-postgres/src/repositories/blocks.ts index f3ef237914..ce2438442f 100644 --- a/packages/core-database-postgres/src/repositories/blocks.ts +++ b/packages/core-database-postgres/src/repositories/blocks.ts @@ -11,7 +11,7 @@ export class BlocksRepository extends Repository { * @return {Promise} */ public async findById(id) { - return this.db.one(sql.findById, { id }); + return this.db.oneOrNone(sql.findById, { id }); } /** diff --git a/packages/core-database/src/wallet-manager.ts b/packages/core-database/src/wallet-manager.ts index 4547cdad50..7c99be1103 100644 --- a/packages/core-database/src/wallet-manager.ts +++ b/packages/core-database/src/wallet-manager.ts @@ -1,7 +1,7 @@ import { app } from "@arkecosystem/core-container"; import { Logger } from "@arkecosystem/core-interfaces"; import { roundCalculator } from "@arkecosystem/core-utils"; -import { constants, crypto, formatArktoshi, isException, models } from "@arkecosystem/crypto"; +import { constants, crypto, formatArktoshi, models } from "@arkecosystem/crypto"; import pluralize from "pluralize"; const { Wallet } = models; @@ -446,7 +446,7 @@ export class WalletManager { } // handle exceptions / verify that we can apply the transaction to the sender - if (isException(data)) { + if (transaction.isException) { this.logger.warn(`Transaction ${data.id} forcibly applied because it has been added as an exception.`); } else if (!sender.canApply(data, errors)) { this.logger.error( diff --git a/packages/crypto/src/crypto/crypto.ts b/packages/crypto/src/crypto/crypto.ts index 5137202edb..130c5d4043 100644 --- a/packages/crypto/src/crypto/crypto.ts +++ b/packages/crypto/src/crypto/crypto.ts @@ -8,7 +8,6 @@ import { Address, KeyPair, Keys, PublicKey, WIF } from "../identities"; import { configManager } from "../managers"; import { feeManager } from "../managers"; import { ITransactionData } from "../models"; -import { INetwork } from "../networks"; import { Bignum } from "../utils"; import { HashAlgorithms } from "./hash-algorithms"; @@ -25,7 +24,11 @@ class Crypto { /** * Get the byte representation of the transaction. */ - public getBytes(transaction: ITransactionData, skipSignature: boolean = false, skipSecondSignature: boolean = false): Buffer { + public getBytes( + transaction: ITransactionData, + skipSignature: boolean = false, + skipSecondSignature: boolean = false, + ): Buffer { if (transaction.version && transaction.version !== 1) { throw new Error("not supported yet"); } @@ -183,7 +186,11 @@ class Crypto { /** * Get transaction hash. */ - public getHash(transaction: ITransactionData, skipSignature: boolean = false, skipSecondSignature: boolean = false): Buffer { + public getHash( + transaction: ITransactionData, + skipSignature: boolean = false, + skipSecondSignature: boolean = false, + ): Buffer { if (transaction.version && transaction.version !== 1) { throw new Error("not supported yet"); } diff --git a/packages/crypto/src/models/block.ts b/packages/crypto/src/models/block.ts index ad79ee636f..fa9cc7d66d 100644 --- a/packages/crypto/src/models/block.ts +++ b/packages/crypto/src/models/block.ts @@ -4,7 +4,7 @@ import { crypto, slots } from "../crypto"; import { BlockDeserializer } from "../deserializers"; import { configManager } from "../managers/config"; import { BlockSerializer } from "../serializers"; -import { Bignum } from "../utils"; +import { Bignum, isException } from "../utils"; import { ITransactionData, Transaction } from "./transaction"; export interface BlockVerification { @@ -148,6 +148,7 @@ export class Block implements IBlock { public data: IBlockData; public transactions: Transaction[]; public verification: BlockVerification; + public isException?: boolean; constructor(data: IBlockData | string) { if (typeof data === "string") { @@ -179,6 +180,9 @@ export class Block implements IBlock { this.verification = this.verify(); + // Mark Block as exception if id is whitelisted + this.isException = isException(this.data); + // order of transactions messed up in mainnet V1 // TODO: move this to network constants exception using block ids if ( diff --git a/packages/crypto/src/models/transaction.ts b/packages/crypto/src/models/transaction.ts index 888a5dfeb2..9053636c73 100644 --- a/packages/crypto/src/models/transaction.ts +++ b/packages/crypto/src/models/transaction.ts @@ -126,6 +126,8 @@ export class Transaction implements ITransactionData { public timelock?: any; public timelockType?: number; + public isException?: boolean; + constructor(data: string | ITransactionData) { if (typeof data === "string") { this.serialized = data; @@ -134,7 +136,10 @@ export class Transaction implements ITransactionData { } this.data = Transaction.deserialize(this.serialized); - this.verified = (this.data.type <= 4 && crypto.verify(this.data)) || isException(this.data); + this.verified = this.data.type <= 4 && crypto.verify(this.data); + + // Mark Transaction as exception if id is whitelisted. + this.isException = isException(this.data); // TODO: remove this [ @@ -164,7 +169,7 @@ export class Transaction implements ITransactionData { } public verify(): boolean { - return this.verified; + return this.verified || this.isException; } public toJson(): any { diff --git a/packages/crypto/src/networks/devnet/exceptions.json b/packages/crypto/src/networks/devnet/exceptions.json index b186ecbacd..602e90cacb 100644 --- a/packages/crypto/src/networks/devnet/exceptions.json +++ b/packages/crypto/src/networks/devnet/exceptions.json @@ -1,5 +1,47 @@ { - "blocks": ["15895730198424359628", "14746174532446639362"], + "blocks": [ + "15895730198424359628", + "14746174532446639362", + "15249141324902969334", + "12360802297474246584", + "2565729258675312304", + "12614646598841308905", + "8274406339991077743", + "1661383348822169561", + "15467742607784975524", + "3665174254391236833", + "18033869253067308940", + "9121030900295704150", + "4296553458016414976", + "6837659293375391985", + "16540521480028827748", + "1485997193168364918", + "14159698257459587584", + "7561147498738550191", + "6247200360319694668", + "7363268091423233950", + "8738693892321921533", + "9014317427571908796", + "15519361274991733193", + "14013227271822852495", + "12603272471546364995", + "1944108005996955253", + "8469356042757089608", + "3433946900869474802", + "11257633501887013743", + "2997965849869498353", + "9196430932294555781", + "6730395143580220680", + "5806654366498055250", + "13290912469992409149", + "9502002558776276513", + "330791153715252718", + "12084096509112875921", + "7079194814443264009", + "15946707936026547597", + "1641736062116508620", + "5245034769798442586" + ], "transactions": [ "76bd168e57a4431a64617c4e7864df1e0be89831eabaa230e37643efae2def6f", "90d06cb306dcc33faba59545e03d91ee83b0409e66a45ffe6a9e3b1049a0c521", From 12a48e59bd17f6c881200711ed33798333194bd6 Mon Sep 17 00:00:00 2001 From: supaiku Date: Wed, 16 Jan 2019 03:29:32 +0100 Subject: [PATCH 3/5] refactor: remove flag again --- .../core-blockchain/src/processor/block-processor.ts | 4 ++-- packages/core-database/src/wallet-manager.ts | 4 ++-- packages/crypto/src/models/block.ts | 6 +----- packages/crypto/src/models/transaction.ts | 9 ++------- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/core-blockchain/src/processor/block-processor.ts b/packages/core-blockchain/src/processor/block-processor.ts index 47d70f6807..29d51782db 100644 --- a/packages/core-blockchain/src/processor/block-processor.ts +++ b/packages/core-blockchain/src/processor/block-processor.ts @@ -2,7 +2,7 @@ import { app } from "@arkecosystem/core-container"; import { Logger } from "@arkecosystem/core-interfaces"; -import { models } from "@arkecosystem/crypto"; +import { isException, models } from "@arkecosystem/crypto"; import { Blockchain } from "../blockchain"; import { isBlockChained } from "../utils/is-block-chained"; import { validateGenerator } from "../utils/validate-generator"; @@ -36,7 +36,7 @@ export class BlockProcessor { } public async getHandler(block: models.Block): Promise { - if (block.isException) { + if (isException(block.data)) { return new ExceptionHandler(this.blockchain, block); } diff --git a/packages/core-database/src/wallet-manager.ts b/packages/core-database/src/wallet-manager.ts index 7c99be1103..4547cdad50 100644 --- a/packages/core-database/src/wallet-manager.ts +++ b/packages/core-database/src/wallet-manager.ts @@ -1,7 +1,7 @@ import { app } from "@arkecosystem/core-container"; import { Logger } from "@arkecosystem/core-interfaces"; import { roundCalculator } from "@arkecosystem/core-utils"; -import { constants, crypto, formatArktoshi, models } from "@arkecosystem/crypto"; +import { constants, crypto, formatArktoshi, isException, models } from "@arkecosystem/crypto"; import pluralize from "pluralize"; const { Wallet } = models; @@ -446,7 +446,7 @@ export class WalletManager { } // handle exceptions / verify that we can apply the transaction to the sender - if (transaction.isException) { + if (isException(data)) { this.logger.warn(`Transaction ${data.id} forcibly applied because it has been added as an exception.`); } else if (!sender.canApply(data, errors)) { this.logger.error( diff --git a/packages/crypto/src/models/block.ts b/packages/crypto/src/models/block.ts index fa9cc7d66d..ad79ee636f 100644 --- a/packages/crypto/src/models/block.ts +++ b/packages/crypto/src/models/block.ts @@ -4,7 +4,7 @@ import { crypto, slots } from "../crypto"; import { BlockDeserializer } from "../deserializers"; import { configManager } from "../managers/config"; import { BlockSerializer } from "../serializers"; -import { Bignum, isException } from "../utils"; +import { Bignum } from "../utils"; import { ITransactionData, Transaction } from "./transaction"; export interface BlockVerification { @@ -148,7 +148,6 @@ export class Block implements IBlock { public data: IBlockData; public transactions: Transaction[]; public verification: BlockVerification; - public isException?: boolean; constructor(data: IBlockData | string) { if (typeof data === "string") { @@ -180,9 +179,6 @@ export class Block implements IBlock { this.verification = this.verify(); - // Mark Block as exception if id is whitelisted - this.isException = isException(this.data); - // order of transactions messed up in mainnet V1 // TODO: move this to network constants exception using block ids if ( diff --git a/packages/crypto/src/models/transaction.ts b/packages/crypto/src/models/transaction.ts index 9053636c73..888a5dfeb2 100644 --- a/packages/crypto/src/models/transaction.ts +++ b/packages/crypto/src/models/transaction.ts @@ -126,8 +126,6 @@ export class Transaction implements ITransactionData { public timelock?: any; public timelockType?: number; - public isException?: boolean; - constructor(data: string | ITransactionData) { if (typeof data === "string") { this.serialized = data; @@ -136,10 +134,7 @@ export class Transaction implements ITransactionData { } this.data = Transaction.deserialize(this.serialized); - this.verified = this.data.type <= 4 && crypto.verify(this.data); - - // Mark Transaction as exception if id is whitelisted. - this.isException = isException(this.data); + this.verified = (this.data.type <= 4 && crypto.verify(this.data)) || isException(this.data); // TODO: remove this [ @@ -169,7 +164,7 @@ export class Transaction implements ITransactionData { } public verify(): boolean { - return this.verified || this.isException; + return this.verified; } public toJson(): any { From 97b0bf8926f8b2877729d969e65515f98ebed4d6 Mon Sep 17 00:00:00 2001 From: supaiku Date: Wed, 16 Jan 2019 03:33:13 +0100 Subject: [PATCH 4/5] refactor: simplify --- .../src/processor/handlers/exception-handler.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/core-blockchain/src/processor/handlers/exception-handler.ts b/packages/core-blockchain/src/processor/handlers/exception-handler.ts index f40e869f67..52f05e8bec 100644 --- a/packages/core-blockchain/src/processor/handlers/exception-handler.ts +++ b/packages/core-blockchain/src/processor/handlers/exception-handler.ts @@ -8,8 +8,7 @@ export class ExceptionHandler extends BlockHandler { // block bypasses all other checks. const forgedBlock = await this.blockchain.database.getBlock(this.block.data.id); if (forgedBlock) { - super.execute(); - return BlockProcessorResult.Rejected; + return super.execute(); } this.logger.warn( From ed8a0a8af2fc6144f8f0d3b0e5ecb528789873f8 Mon Sep 17 00:00:00 2001 From: supaiku Date: Wed, 16 Jan 2019 03:40:16 +0100 Subject: [PATCH 5/5] misc: typo --- packages/core-blockchain/__tests__/blockchain.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-blockchain/__tests__/blockchain.test.ts b/packages/core-blockchain/__tests__/blockchain.test.ts index 33036445f0..999665687c 100644 --- a/packages/core-blockchain/__tests__/blockchain.test.ts +++ b/packages/core-blockchain/__tests__/blockchain.test.ts @@ -258,7 +258,7 @@ describe("Blockchain", () => { }); }); - describe("handleIncommingBlock", () => { + describe("handleIncomingBlock", () => { it("should be ok", () => { const dispatch = blockchain.dispatch; const enqueueBlocks = blockchain.enqueueBlocks;