@@ -30,6 +30,8 @@ var Blockchain = module.exports = function (opts) {
3030 header : genesisHeader
3131 }
3232
33+ this . BlockHeader = genesisHeader . constructor
34+
3335 if ( opts . checkpoint ) {
3436 this . checkpoint = opts . checkpoint
3537 this . checkpoint . hash = u . toHash ( this . checkpoint . header . hash )
@@ -39,7 +41,10 @@ var Blockchain = module.exports = function (opts) {
3941 this . initialized = false
4042 this . closed = false
4143
42- this . store = opts . store || new BlockStore ( { path : opts . path } )
44+ this . store = opts . store || new BlockStore ( {
45+ path : opts . path ,
46+ BlockHeader : this . BlockHeader
47+ } )
4348 this . _initStore ( function ( err ) {
4449 if ( err && err !== storeClosedError ) return self . _error ( err )
4550 else if ( err && err === storeClosedError ) return
@@ -358,8 +363,8 @@ Blockchain.prototype._listenForUpdates = function () {
358363 var self = this
359364 this . peerGroup . on ( 'inv' , function ( peer , message ) {
360365 message . inventory . forEach ( function ( item ) {
361- if ( item . type === Inventory . TYPE . BLOCK
362- || item . type === Inventory . TYPE . FILTERED_BLOCK ) {
366+ if ( item . type === Inventory . TYPE . BLOCK ||
367+ item . type === Inventory . TYPE . FILTERED_BLOCK ) {
363368 if ( self . lastInv && self . lastInv . compare ( item . hash ) === 0 ) return
364369 self . lastInv = item . hash
365370 self . _getHeaders ( )
@@ -444,18 +449,18 @@ Blockchain.prototype.processHeader = function (prev, header, cb) {
444449 return cb ( new Error ( 'Block does not connect to previous' ) , block )
445450 }
446451 // TODO: testnet difficulty rules (for now we are just not verifying testnet block difficulty)
447- if ( this . network !== bitcore . Networks . testnet
448- && ! self . shouldRetarget ( height )
449- && header . bits !== prev . header . bits ) {
452+ if ( this . network !== bitcore . Networks . testnet &&
453+ ! self . shouldRetarget ( height ) &&
454+ header . bits !== prev . header . bits ) {
450455 return cb ( new Error ( 'Unexpected difficulty change' ) , block )
451456 }
452457 if ( ! header . validProofOfWork ( ) ) {
453458 return cb ( new Error ( 'Invalid proof of work' ) , block )
454459 }
455460 // TODO: other checks (timestamp, version)
456- if ( self . shouldRetarget ( height )
461+ if ( self . shouldRetarget ( height ) &&
457462 // don't verify retarget if it requires checking before our checkpoint
458- && ! ( this . checkpoint && height - this . checkpoint . height < this . interval ) ) {
463+ ! ( this . checkpoint && height - this . checkpoint . height < this . interval ) ) {
459464 return self . calculateTarget ( block , function ( err , target ) {
460465 if ( err ) return cb ( err , block )
461466
0 commit comments