diff --git a/app/lib/blockchain/DuniterBlockchain.ts b/app/lib/blockchain/DuniterBlockchain.ts index faeec03d731e958e4fa3faae4dc22f06b6a93264..05dc9136bbfb276ca67d39e2b8f26cfc9d4ec5ef 100644 --- a/app/lib/blockchain/DuniterBlockchain.ts +++ b/app/lib/blockchain/DuniterBlockchain.ts @@ -45,6 +45,7 @@ export class DuniterBlockchain { static async checkBlock( block: BlockDTO, withPoWAndSignature: boolean, + ignoreIssuer: boolean, conf: ConfDTO, dal: FileDAL ) { @@ -78,7 +79,7 @@ export class DuniterBlockchain { if (Indexer.rulePreviousIssuer(block, HEAD) === false) throw Error("rulePreviousIssuer"); // BR_G101 - if (Indexer.ruleIssuerIsMember(HEAD) === false) + if (!ignoreIssuer && Indexer.ruleIssuerIsMember(HEAD) === false) throw Error("ruleIssuerIsMember"); // BR_G54 if (Indexer.ruleIssuersCount(block, HEAD) === false) @@ -215,7 +216,7 @@ export class DuniterBlockchain { }; const isMember = await dal.isMember(block.issuer); - if (!isMember) { + if (!ignoreIssuer && !isMember) { if (block.number == 0) { if (!matchesList(new RegExp("^" + block.issuer + ":"), block.joiners)) { throw Error("Block not signed by the root members"); diff --git a/app/lib/computation/BlockchainContext.ts b/app/lib/computation/BlockchainContext.ts index 9ca3e66e5281a46cf6e4edc19a098c96a861d277..a0589908f1a50ae43493ff21daafcd25d29a0ada 100644 --- a/app/lib/computation/BlockchainContext.ts +++ b/app/lib/computation/BlockchainContext.ts @@ -123,11 +123,13 @@ export class BlockchainContext { async checkBlock( block: BlockDTO, - withPoWAndSignature: boolean + withPoWAndSignature: boolean, + ignoreIssuer: boolean ): Promise<any> { return DuniterBlockchain.checkBlock( block, withPoWAndSignature, + ignoreIssuer, this.conf, this.dal ); @@ -205,7 +207,8 @@ export class BlockchainContext { async checkAndAddBlock(block: BlockDTO, trim = true) { const { index, HEAD } = await this.checkBlock( block, - constants.WITH_SIGNATURES_AND_POW + constants.WITH_SIGNATURES_AND_POW, + false ); return await this.addBlock(block, index, HEAD, trim); } diff --git a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts index c28345513b657b605e01e032a312b83954e4b013..ceb33b67f9a389d549d8ab1999f891f897f459c3 100644 --- a/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts +++ b/app/modules/crawler/lib/sync/v2/GlobalIndexStream.ts @@ -591,6 +591,7 @@ export class GlobalIndexStream extends Duplex { const { index, HEAD } = await DuniterBlockchain.checkBlock( dto, constants.WITH_SIGNATURES_AND_POW, + false, this.conf, this.dal ); diff --git a/app/modules/prover/index.ts b/app/modules/prover/index.ts index 4ca5f1a495ef276c1ca9f8adf586d2b1a2c1d7fa..8bdca8b55ece27112c7955ef0394ec891cc28b54 100644 --- a/app/modules/prover/index.ts +++ b/app/modules/prover/index.ts @@ -122,6 +122,10 @@ export const ProverDependency = { desc: "With gen-* commands: the generated block is submitted to this node only.", }, + { + value: "--nocheck-issuer", + desc: "With gen-* commands: ignore issuer rule.", + }, { value: "--submit-host <host>", desc: @@ -276,7 +280,11 @@ function generateAndSend( const parsed = parsers.parseBlock.syncWrite( block.getRawSigned() ); - await server.BlockchainService.checkBlock(parsed, false); + await server.BlockchainService.checkBlock( + parsed, + false, + program.nocheckIssuer + ); logger.info("Acceptable block"); next(); } catch (e) { diff --git a/app/service/BlockchainService.ts b/app/service/BlockchainService.ts index 75e3172cda714db0558281198325b2303dfacd1d..63c4d5c78d535199f4bf932ca6507ac7976b38b5 100644 --- a/app/service/BlockchainService.ts +++ b/app/service/BlockchainService.ts @@ -165,9 +165,9 @@ export class BlockchainService extends FIFOService { return bb; } - checkBlock(block: any, withPoWAndSignature = true) { + checkBlock(block: any, withPoWAndSignature = true, ignoreIssuer = false) { const dto = BlockDTO.fromJSONObject(block); - return this.mainContext.checkBlock(dto, withPoWAndSignature); + return this.mainContext.checkBlock(dto, withPoWAndSignature, ignoreIssuer); } /**