Skip to content

Commit 20c1adf

Browse files
author
ralfshift
committed
Shift 7.1.0t
Disable multiple lock transactions per block per account Remove unused endpoints from API Dependency update
1 parent 49f32f9 commit 20c1adf

7 files changed

Lines changed: 47 additions & 45 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## SHIFT version 7.0.0t
1+
## SHIFT version 7.1.0t
22

33
## Installation
44

api/http/transactions.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ var httpApi = require('../../helpers/httpApi');
1616
* - get /multisignatures
1717
* - get /unconfirmed/get
1818
* - get /unconfirmed
19-
* - get /locks
20-
* - get /locks/get
21-
* - get /pins
22-
* - get /pins/get
23-
* - get /pins/getBytes
24-
* - get /pins/verify
2519
* - put /
2620
* @memberof module:transactions
2721
* @requires helpers/Router

helpers/constants.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,16 @@
5858
* @property {number} unconfirmedTransactionTimeOut - 1080 blocks
5959
*/
6060
module.exports = {
61-
currentVersion: '7.0.0t',
61+
currentVersion: '7.1.0t',
6262
minVersion: [
6363
{ height: 1, ver: '^6.0.1t'},
6464
{ height: 370000, ver: '^6.3.0t'},
6565
{ height: 640000, ver: '^6.5.0t'},
6666
{ height: 1617500, ver: '^6.8.0t'},
6767
{ height: 2700000, ver: '>=6.8.0'},
6868
{ height: 2725930, ver: '>6.9.0'},
69-
{ height: 2924610, ver: '^7.0.0'}
69+
{ height: 2924610, ver: '^7.0.0'},
70+
{ height: 2954429, ver: '^7.1.0'}
7071
],
7172
activeDelegates: 101,
7273
addressLength: 208,

logic/lock.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ Lock.prototype.verify = function (trs, sender, cb) {
112112
}
113113

114114
var lastBlock = modules.blocks.lastBlock.get();
115-
self.calcLockBytes(lastBlock.height, trs.amount, trs.timestamp, function(err, result){
115+
self.calcLockBytes(lastBlock.height, trs.amount, trs.timestamp, function(err, bytes){
116116
if (err) {
117117
// Unable to calculate | incomplete stats
118118
return setImmediate(cb, err, trs);
119119
}
120120

121-
var lockBytes = Math.round(result);
122-
121+
var lockBytes = Math.floor(bytes);
123122
if (lockBytes < trs.asset.lock.bytes) {
124-
return setImmediate(cb, 'Bytes to lock (' +trs.asset.lock.bytes+ ') cannot exceed calculated bytes (' +lockBytes+ ')');
123+
var err = 'Bytes to lock (' + trs.asset.lock.bytes + ') cannot exceed calculated bytes (' + lockBytes + ')';
124+
return setImmediate(cb, err);
125125
}
126126

127127
return setImmediate(cb, err, trs);
@@ -132,31 +132,34 @@ Lock.prototype.verify = function (trs, sender, cb) {
132132
return setImmediate(cb, err);
133133
}
134134

135+
var totalAmount = new bignum(trs.amount.toString());
136+
var lockedBalance = new bignum(sender.locked_balance.toString());
137+
if (lockedBalance.lessThan(totalAmount)) {
138+
var err = "SHIFT to unlock " + totalAmount.div(Math.pow(10,8)) + " cannot exceed locked SHIFT (" + lockedBalance.div(Math.pow(10,8)) + ')';
139+
return setImmediate(cb, err);
140+
}
141+
135142
var publicKey = trs.senderPublicKey;
136-
self.calcUnlockBytes(trs, function (err, bytes) {
137-
if (err || !bytes) {
143+
self.calcUnlockBytes(trs, function (err, unlockBytes) {
144+
if (err || !unlockBytes) {
138145
return cb('calcUnlockBytes error: ' + err);
139146
}
140147

141-
var unlockBytes = new bignum(bytes.toString()).toNumber();
142-
143-
modules.locks.getLockedBytes(publicKey, function (err, bytes) {
144-
if (err) {
148+
modules.locks.getLockedBytes(publicKey, function (err, lockedBytes) {
149+
if (err || !lockedBytes) {
145150
return cb('getLockedBytes error: ' + err);
146151
}
147152

148-
var lockedBytes = new bignum(bytes.toString()).toNumber();
149-
150153
if (lockedBytes < trs.asset.lock.bytes) {
151-
return setImmediate(cb, "Bytes to unlock " + trs.asset.lock.bytes + " cannot exceed locked bytes (" +lockedBytes+ ')');
154+
return setImmediate(cb, "Bytes to unlock " + trs.asset.lock.bytes + " cannot exceed locked bytes (" + lockedBytes + ')');
152155
}
153156

154-
modules.pins.getPinnedBytes(publicKey, function (err, bytes) {
155-
var pinnedBytes = new bignum(bytes.toString()).toNumber();
157+
modules.pins.getPinnedBytes(publicKey, function (err, pinnedBytes) {
156158
var availableLockedBytes = lockedBytes - pinnedBytes;
157159

158-
if (availableLockedBytes - unlockBytes < 0) {
159-
return setImmediate(cb, 'Account does not have enough available bytes locked to complete unlock request');
160+
if (availableLockedBytes < unlockBytes) {
161+
var err = 'Account does not have enough available bytes locked to complete unlock request';
162+
return setImmediate(cb, err);
160163
}
161164

162165
return setImmediate(cb, err, trs);
@@ -252,7 +255,6 @@ Lock.prototype.calcLockBytes = function (height, amount, timestamp, cb) {
252255

253256
Lock.prototype.calcUnlockBytes = function (trs, cb) {
254257
var publicKey = trs.senderPublicKey;
255-
var amount = trs.amount;
256258

257259
modules.locks.getLockedBytes(publicKey, function (err, bytes) {
258260
if (err || !bytes) {
@@ -266,13 +268,13 @@ Lock.prototype.calcUnlockBytes = function (trs, cb) {
266268
return setImmediate(cb, "Locked balance is 0");
267269
}
268270

269-
var lockedBalance = new bignum(balance.toString()).toNumber();
270-
271-
if (amount > lockedBalance) {
272-
return setImmediate(cb, "Amount to unlock " + amount + " cannot exceed locked balance " + lockedBalance);
271+
var lockedBalance = new bignum(balance.toString());
272+
var totalAmount = new bignum(trs.amount.toString());
273+
if (lockedBalance.lessThan(totalAmount)) {
274+
return setImmediate(cb, "Amount to unlock " + totalAmount.div(Math.pow(10,8)) + " cannot exceed locked balance " + lockedBalance.div(Math.pow(10,8)));
273275
}
274276

275-
var bytes = (lockedBytes / lockedBalance) * amount;
277+
var bytes = Math.round((lockedBytes / lockedBalance) * trs.amount);
276278

277279
return setImmediate(cb, null, bytes);
278280
});
@@ -323,7 +325,7 @@ Lock.prototype.apply = function (trs, block, sender, cb) {
323325
return setImmediate(cb, err);
324326
}
325327

326-
library.logger.trace('Logic/Lock->apply ' + (trs.type == 8 ? 'lock' : 'unlock'), {sender: trs.senderId, balance: lockAmount, bytes: lockBytes, height: block.height});
328+
library.logger.trace('Logic/Lock->apply ' + (trs.type == transactionTypes.LOCK ? 'lock' : 'unlock'), {sender: trs.senderId, balance: lockAmount, bytes: lockBytes, height: block.height});
327329

328330
modules.accounts.mergeAccountAndGet({
329331
address: trs.senderId,
@@ -354,7 +356,6 @@ Lock.prototype.undo = function (trs, block, sender, cb) {
354356
return setImmediate(cb, err);
355357
}
356358

357-
358359
modules.accounts.mergeAccountAndGet({
359360
address: trs.senderId,
360361
locked_balance: lockAmount,
@@ -377,7 +378,7 @@ Lock.prototype.applyUnconfirmed = function (trs, sender, cb) {
377378
return setImmediate(cb, err);
378379
}
379380

380-
library.logger.trace('Logic/Lock->applyUnconfirmed ' + (trs.type == 8 ? 'lock' : 'unlock'), {sender: trs.senderId, balance: lockAmount, bytes: lockBytes});
381+
library.logger.trace('Logic/Lock->applyUnconfirmed ' + (trs.type == transactionTypes.LOCK ? 'lock' : 'unlock'), {sender: trs.senderId, balance: lockAmount, bytes: lockBytes});
381382

382383
modules.accounts.mergeAccountAndGet({
383384
address: trs.senderId,

logic/pin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Pin.prototype.verify = function (trs, sender, cb) {
114114
mostRecentPin = false;
115115
}
116116

117-
if (mostRecentPin.timestamp > trs.timestamp) {
117+
if (mostRecentPin && mostRecentPin.timestamp > trs.timestamp) {
118118
return setImmediate(cb, "Timestamp cannot be older than the previous pin");
119119
}
120120

@@ -253,7 +253,7 @@ Pin.prototype.apply = function (trs, block, sender, cb) {
253253
return setImmediate(cb, err);
254254
}
255255

256-
library.logger.trace('Logic/Pin->apply ' + (trs.type == 10 ? 'pin' : 'unpin'), {sender: trs.senderId, bytes: pinBytes, height: block.height});
256+
library.logger.trace('Logic/Pin->apply ' + (trs.type == transactionTypes.PIN ? 'pin' : 'unpin'), {sender: trs.senderId, bytes: pinBytes, height: block.height});
257257

258258
modules.accounts.mergeAccountAndGet({
259259
address: trs.senderId,
@@ -311,7 +311,7 @@ Pin.prototype.applyUnconfirmed = function (trs, sender, cb) {
311311
return setImmediate(cb, err);
312312
}
313313

314-
library.logger.trace('Logic/Pin->apply ' + (trs.type == 10 ? 'pin' : 'unpin'), {sender: trs.senderId, bytes: pinBytes});
314+
library.logger.trace('Logic/Pin->apply ' + (trs.type == transactionTypes.PIN ? 'pin' : 'unpin'), {sender: trs.senderId, bytes: pinBytes});
315315

316316
modules.accounts.mergeAccountAndGet({
317317
address: trs.senderId,

logic/transactionPool.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,19 @@ __private.processVerifyTransaction = function (transaction, broadcast, cb) {
761761
});
762762
},
763763
function assetExists (sender, waterCb) {
764-
if (transaction.type === transactionTypes.PIN || transaction.type === transactionTypes.UNPIN) {
764+
if (transaction.type === transactionTypes.LOCK || transaction.type === transactionTypes.UNLOCK ||
765+
transaction.type === transactionTypes.PIN || transaction.type === transactionTypes.UNPIN
766+
){
765767
var transactions = self.getUnconfirmedTransactionList(true, constants.maxTxsPerBlock);
766768
async.eachSeries(transactions, function (trs, eachSeriesCb) {
767-
if (transaction.senderId === trs.senderId &&
768-
transaction.type === trs.type &&
769-
transaction.asset.pin.hash === trs.asset.pin.hash) {
770-
return setImmediate(eachSeriesCb, 'Pin transaction is already being processed');
769+
if (transaction.senderId === trs.senderId && transaction.type === trs.type) {
770+
if (transaction.type === transactionTypes.LOCK || transaction.type === transactionTypes.UNLOCK) {
771+
return setImmediate(eachSeriesCb, 'A lock transaction is already being processed');
772+
}
773+
if (transaction.type === transactionTypes.PIN || transaction.type === transactionTypes.UNPIN && transaction.asset.pin.hash === trs.asset.pin.hash) {
774+
return setImmediate(eachSeriesCb, 'This pin transaction is already being processed');
775+
}
776+
return setImmediate(eachSeriesCb);
771777
} else {
772778
return setImmediate(eachSeriesCb);
773779
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shift",
3-
"version": "7.0.0t",
3+
"version": "7.1.0t",
44
"private": true,
55
"scripts": {
66
"start": "node app.js",
@@ -35,7 +35,7 @@
3535
"ip": "https://github.com/shiftproject/node-ip/tarball/master",
3636
"json-schema": "=0.2.3",
3737
"json-sql": "https://github.com/LiskHQ/json-sql/tarball/master",
38-
"lodash": "=4.17.11",
38+
"lodash": "=4.17.13",
3939
"method-override": "=2.3.10",
4040
"nan": "=2.2.1",
4141
"npm": "=2.15.10",

0 commit comments

Comments
 (0)