diff --git a/app/lib/dal/sqliteDAL/BlockDAL.js b/app/lib/dal/sqliteDAL/BlockDAL.js index f305eee70a773268a4781eee7a94c3286f94a130..50cae80e976e75cf9bd784c08fa0c72b79c27e42 100644 --- a/app/lib/dal/sqliteDAL/BlockDAL.js +++ b/app/lib/dal/sqliteDAL/BlockDAL.js @@ -24,6 +24,7 @@ function BlockDAL(db) { this.fields = ['fork', 'hash', 'signature', 'currency', 'issuer', 'parameters', 'previousHash', 'previousIssuer', 'version', 'membersCount', 'monetaryMass', 'UDTime', 'medianTime', 'dividend', 'time', 'powMin', 'number', 'nonce', 'transactions', 'certifications', 'identities', 'joiners', 'actives', 'leavers', 'excluded']; this.arrays = ['identities','certifications','actives','excluded','leavers','joiners','transactions']; this.bigintegers = ['monetaryMass','dividend']; + this.booleans = ['wrong']; this.pkFields = ['number','hash']; this.init = () => co(function *() { @@ -60,6 +61,7 @@ function BlockDAL(db) { ');' + 'CREATE INDEX IF NOT EXISTS idx_block_hash ON block (hash);' + 'CREATE INDEX IF NOT EXISTS idx_block_fork ON block (fork);' + + 'ALTER TABLE block ADD COLUMN `wrong` BOOLEAN NOT NULL DEFAULT 0;' + 'COMMIT;', []); }); @@ -118,11 +120,8 @@ function BlockDAL(db) { function saveBlockAs(block, fork) { return co(function *() { - let existing = yield that.getEntity(block); - if (existing) { - return that.query('UPDATE block SET fork = ? WHERE number = ? and hash = ?', [fork, block.number, block.hash]); - } - yield that.insert(block); + block.fork = fork; + return yield that.saveEntity(block); }); } diff --git a/app/service/PeeringService.js b/app/service/PeeringService.js index 9eedb52d58fec8e6086f5d064eeaf5848ddab69d..e5467b1a7664dd46c92c7f4c58ccaab680c7f67b 100644 --- a/app/service/PeeringService.js +++ b/app/service/PeeringService.js @@ -427,7 +427,7 @@ function PeeringService(server, pair, dal) { err.code == "EINVAL" || err.code == "ECONNREFUSED" || err.code == "ETIMEDOUT" - || err.httpCode !== 404); + || (err.httpCode !== undefined && err.httpCode !== 404)); } function processAscendingUntilNoBlock(p, node, current) { diff --git a/test/integration/branches_switch.js b/test/integration/branches_switch.js index 1ea608f1e58f89847e846d5f0b9aee1adc4eacee..39334d282ee7bbc3558f49c484f3af30699adcaa 100644 --- a/test/integration/branches_switch.js +++ b/test/integration/branches_switch.js @@ -81,7 +81,7 @@ describe("Switch", function() { yield commit(s2)(); // So we now have: // S1 01234 - // S2 `345678 + // S2 `3456789 yield sync(3, 8, s2, s1); // S1 should have switched to the other branch }); @@ -100,5 +100,19 @@ describe("Switch", function() { number: 8 }); }); + + it('/block/7 should have valid monetary mass', function() { + return co(function *() { + let block = yield s1.dal.getBlock(7); + block.should.have.property('UDTime').not.equal(null); + }); + }); + + it('/block/8 should have valid monetary mass', function() { + return co(function *() { + let block = yield s1.dal.getBlock(8); + block.should.have.property('UDTime').not.equal(null); + }); + }); }); });