Fid Blockchain.validate for genesis blocks

This commit is contained in:
Garrett Mills 2021-04-10 21:08:19 -05:00
parent 0cb78fef35
commit 0580d2274f
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246

View File

@ -272,6 +272,10 @@ export class Blockchain extends Unit {
const blocks = collect<Block>(chain) const blocks = collect<Block>(chain)
return ( return (
await blocks.promiseMap(async (block, idx) => { await blocks.promiseMap(async (block, idx) => {
if ( await block.isGenesis() ) {
return true
}
const previous: Block | undefined = blocks.at(idx - 1) const previous: Block | undefined = blocks.at(idx - 1)
if ( !previous ) { if ( !previous ) {
this.logging.debug(`Chain is invalid: block ${idx} is missing previous ${idx - 1}.`) this.logging.debug(`Chain is invalid: block ${idx} is missing previous ${idx - 1}.`)
@ -295,10 +299,6 @@ export class Blockchain extends Unit {
return false return false
} }
if ( await block.isGenesis() ) {
return true
}
if ( !(await this.validateProofOfWork(block, previous)) ) { if ( !(await this.validateProofOfWork(block, previous)) ) {
this.logging.debug(`Chain is invalid: block ${idx} failed proof of work validation`) this.logging.debug(`Chain is invalid: block ${idx} failed proof of work validation`)
return false; return false;