chaindb: checksum.
This commit is contained in:
parent
ef51f4f842
commit
b273bec120
@ -191,7 +191,7 @@ Chain.prototype.resetHeight = function resetHeight(height) {
|
||||
existing = this.db.get(i);
|
||||
assert(existing);
|
||||
delete this.heightLookup[existing.hash];
|
||||
this.db.del(i);
|
||||
this.db.remove(i);
|
||||
}
|
||||
|
||||
this.tip = this.db.get(height);
|
||||
@ -690,6 +690,7 @@ Chain.prototype.fromJSON = function fromJSON(json) {
|
||||
*/
|
||||
|
||||
var BLOCK_SIZE = 112;
|
||||
// var BLOCK_SIZE = 116;
|
||||
|
||||
function ChainDB(chain, options) {
|
||||
if (!(this instanceof ChainDB))
|
||||
@ -897,7 +898,7 @@ ChainDB.prototype.saveAsync = function save(entry, callback) {
|
||||
});
|
||||
};
|
||||
|
||||
ChainDB.prototype.del = function del(height) {
|
||||
ChainDB.prototype.remove = function remove(height) {
|
||||
assert(height >= 0);
|
||||
|
||||
this._write(this._nullBlock, height * BLOCK_SIZE);
|
||||
@ -908,7 +909,12 @@ ChainDB.prototype.del = function del(height) {
|
||||
if ((height + 1) * BLOCK_SIZE === this.size) {
|
||||
while (this.isNull(height))
|
||||
height--;
|
||||
|
||||
if (height < 0)
|
||||
height = 0;
|
||||
|
||||
fs.ftruncateSync(this.fd, (height + 1) * BLOCK_SIZE);
|
||||
|
||||
this.size = (height + 1) * BLOCK_SIZE;
|
||||
this.tip = height;
|
||||
}
|
||||
@ -1097,11 +1103,14 @@ ChainBlock.prototype.toRaw = function toRaw() {
|
||||
utils.writeU32(res, this.bits, 72);
|
||||
utils.writeU32(res, this.nonce, 76);
|
||||
utils.copy(this.chainwork.toArray('be', 32), res, 80);
|
||||
// utils.copy(utils.checksum(res.slice(0, 112)), res, 112);
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
ChainBlock.fromRaw = function fromRaw(chain, height, p) {
|
||||
// if (!utils.isEqual(utils.checksum(p.slice(0, 112)), p.slice(112, 116)))
|
||||
// throw new Error('Bad checksum');
|
||||
return new ChainBlock(chain, {
|
||||
height: height,
|
||||
hash: utils.toHex(utils.dsha256(p.slice(0, 80))),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user