Skip to content

Commit 48c532c

Browse files
Testnet Release 3.0.7 (#930)
- Prevent remote control to crash finalize command. - Use latest Kadence from v5 branch which includes fix for the Hashcash. - Use Churn plugin to filter invalid connections.
1 parent d8c0570 commit 48c532c

File tree

12 files changed

+255
-124
lines changed

12 files changed

+255
-124
lines changed

config/config.json

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@
7777
"bootstraps": ["https://developbs.origintrial.me:5278/#05edf19bd36906240503e2e2e2f18d13f8211d2f"],
7878
"remoteWhitelist": ["54.93.223.161", "127.0.0.1"],
7979
"solutionDifficulty": 8,
80-
"identityDifficulty": 8
80+
"identityDifficulty": 8,
81+
"churnPlugin": {
82+
"cooldownBaseTimeout": "5m",
83+
"cooldownMultiplier": 2,
84+
"cooldownResetTime": "60m"
85+
}
8186
},
8287
"bugSnag": {
8388
"releaseStage": "development"
@@ -156,7 +161,7 @@
156161
"network_id": "rinkeby",
157162
"gas_limit": "2000000",
158163
"gas_price": "20000000000",
159-
"hub_contract_address": "0x16d553B9765b6Aa9fE7C45Dfa1a1839fD88DD7bc",
164+
"hub_contract_address": "0xA272797Bfc59946388D89CdB6821dEeC927E0E36",
160165
"plugins": [
161166
{
162167
"enabled": false,
@@ -178,7 +183,12 @@
178183
"bootstraps": ["https://stagingbs.origintrial.me:5278/#1754b56ce26212eab45bc523c36e1d4bf57ea30e"],
179184
"remoteWhitelist": ["54.93.223.161", "127.0.0.1"],
180185
"solutionDifficulty": 14,
181-
"identityDifficulty": 12
186+
"identityDifficulty": 12,
187+
"churnPlugin": {
188+
"cooldownBaseTimeout": "5m",
189+
"cooldownMultiplier": 2,
190+
"cooldownResetTime": "60m"
191+
}
182192
},
183193
"bugSnag": {
184194
"releaseStage": "staging"
@@ -279,7 +289,12 @@
279289
"bootstraps": ["https://82.196.10.12:5278/#e2f7ab11d0dd34595dfb2e71b4937ec8d790df84"],
280290
"remoteWhitelist": ["54.93.223.161", "127.0.0.1"],
281291
"solutionDifficulty": 14,
282-
"identityDifficulty": 12
292+
"identityDifficulty": 12,
293+
"churnPlugin": {
294+
"cooldownBaseTimeout": "5m",
295+
"cooldownMultiplier": 2,
296+
"cooldownResetTime": "60m"
297+
}
283298
},
284299
"bugSnag": {
285300
"releaseStage": "stable"
@@ -383,7 +398,12 @@
383398
],
384399
"remoteWhitelist": ["127.0.0.1", "localhost"],
385400
"solutionDifficulty": 14,
386-
"identityDifficulty": 12
401+
"identityDifficulty": 12,
402+
"churnPlugin": {
403+
"cooldownBaseTimeout": "5m",
404+
"cooldownMultiplier": 2,
405+
"cooldownResetTime": "60m"
406+
}
387407
},
388408
"bugSnag": {
389409
"releaseStage": "testnet"
@@ -487,7 +507,12 @@
487507
],
488508
"remoteWhitelist": ["127.0.0.1"],
489509
"solutionDifficulty": 14,
490-
"identityDifficulty": 12
510+
"identityDifficulty": 12,
511+
"churnPlugin": {
512+
"cooldownBaseTimeout": "5m",
513+
"cooldownMultiplier": 2,
514+
"cooldownResetTime": "60m"
515+
}
491516
},
492517
"bugSnag": {
493518
"releaseStage": "mariner"

modules/Blockchain/Ethereum/migrations/2_total_migration.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ module.exports = async (deployer, network, accounts) => {
272272
console.log(`\t Holding contract address: \t\t${holding.address}`);
273273
break;
274274
case 'rinkeby':
275-
await deployer.deploy(Hub, { gas: 6000000, from: accounts[0] })
275+
await deployer.deploy(Hub)
276276
.then((result) => {
277277
hub = result;
278278
});
@@ -281,21 +281,18 @@ module.exports = async (deployer, network, accounts) => {
281281
profileStorage = await deployer.deploy(
282282
ProfileStorage,
283283
hub.address,
284-
{ gas: 6000000, from: accounts[0] },
285284
);
286285
await hub.setContractAddress('ProfileStorage', profileStorage.address);
287286

288287
holdingStorage = await deployer.deploy(
289288
HoldingStorage,
290289
hub.address,
291-
{ gas: 6000000, from: accounts[0] },
292290
);
293291
await hub.setContractAddress('HoldingStorage', holdingStorage.address);
294292

295293
litigationStorage = await deployer.deploy(
296294
LitigationStorage,
297295
hub.address,
298-
{ gas: 6000000, from: accounts[0] },
299296
);
300297
await hub.setContractAddress('LitigationStorage', litigationStorage.address);
301298

@@ -304,23 +301,21 @@ module.exports = async (deployer, network, accounts) => {
304301

305302
await hub.setContractAddress('Token', '0x98d9a611ad1b5761bdc1daac42c48e4d54cf5882');
306303

307-
profile = await deployer.deploy(Profile, hub.address, { gas: 7000000, from: accounts[0] });
304+
profile = await deployer.deploy(Profile, hub.address);
308305
await hub.setContractAddress('Profile', profile.address);
309306

310-
holding = await deployer.deploy(Holding, hub.address, { gas: 7000000, from: accounts[0] });
307+
holding = await deployer.deploy(Holding, hub.address);
311308
await hub.setContractAddress('Holding', holding.address);
312309

313310
litigation = await deployer.deploy(
314311
Litigation,
315312
hub.address,
316-
{ gas: 7000000, from: accounts[0] },
317313
);
318314
await hub.setContractAddress('Litigation', litigation.address);
319315

320316
replacement = await deployer.deploy(
321317
Replacement,
322318
hub.address,
323-
{ gas: 7000000, from: accounts[0] },
324319
);
325320
await hub.setContractAddress('Replacement', replacement.address);
326321

modules/Blockchain/Ethereum/truffle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = {
4747
update: {
4848
host: 'localhost', // Connect to geth on the specified
4949
port: 8545,
50-
provider: () => new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/${process.env.RINKEBY_ACCESS_KEY}`),
50+
provider: () => new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/v3/${process.env.RINKEBY_ACCESS_KEY}`),
5151
network_id: 4,
5252
gas: 6000000, // Gas limit used for deploys
5353
websockets: true,
@@ -71,17 +71,17 @@ module.exports = {
7171
rinkeby: {
7272
host: 'localhost', // Connect to geth on the specified
7373
port: 8545,
74-
provider: () => new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/${process.env.RINKEBY_ACCESS_KEY}`),
74+
provider: () => new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/v3/${process.env.RINKEBY_ACCESS_KEY}`),
7575
network_id: 4,
76-
gas: 6000000, // Gas limit used for deploys
76+
gas: 6500000, // Gas limit used for deploys
7777
websockets: true,
7878
skipDryRun: true,
7979
},
8080

8181
live: {
8282
host: 'localhost',
8383
port: 8545,
84-
provider: () => new HDWalletProvider(mnemonic, `https://mainnet.infura.io/${process.env.MAINNET_ACCESS_KEY}`),
84+
provider: () => new HDWalletProvider(mnemonic, `https://mainnet.infura.io/v3/${process.env.MAINNET_ACCESS_KEY}`),
8585
network_id: 1,
8686
gas: 6000000, // Gas limit used for deploys
8787
websockets: true,

modules/RemoteControl.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ class RemoteControl {
367367
async (bid) => {
368368
const holding = await this._findHoldingByBid(bid);
369369

370+
if (holding == null || holding.data_set_id == null) {
371+
this.log.debug('Failed to get holding data for for bid %s.', bid);
372+
return;
373+
}
374+
370375
const dataInfo = await Models.data_info.findOne({
371376
where: {
372377
data_set_id: holding.data_set_id,

modules/command/dh/dh-offer-finalized-command.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,26 @@ class DhOfferFinalizedCommand extends Command {
5454
this.logger.important(`I've been chosen for offer ${offerId}.`);
5555

5656
await this.remoteControl.onCompletedBids();
57-
const scheduledTime = (bid.holding_time_in_minutes * 60 * 1000) + (60 * 1000);
58-
return {
59-
commands: [
60-
{
61-
name: 'dhPayOutCommand',
62-
delay: scheduledTime,
63-
retries: 3,
64-
transactional: false,
65-
data: {
66-
offerId,
67-
viaAPI: false,
57+
58+
if (this.config.disableAutoPayouts !== true) {
59+
const scheduledTime =
60+
(bid.holding_time_in_minutes * 60 * 1000) + (60 * 1000);
61+
return {
62+
commands: [
63+
{
64+
name: 'dhPayOutCommand',
65+
delay: scheduledTime,
66+
retries: 3,
67+
transactional: false,
68+
data: {
69+
offerId,
70+
viaAPI: false,
71+
},
6872
},
69-
},
70-
],
71-
};
73+
],
74+
};
75+
}
76+
return Command.empty();
7277
}
7378

7479
bid.status = 'NOT_CHOSEN';

modules/logger.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ require('winston-daily-rotate-file');
33
// eslint-disable-next-line
44
require('winston-papertrail').Papertrail;
55
require('winston-loggly-bulk');
6+
const util = require('util');
7+
68
const runtimeConfigJson = require('../config/config.json')[process.env.NODE_ENV];
79

810
const colors = require('colors/safe');
@@ -121,13 +123,12 @@ class Logger {
121123

122124
// Extend logger object to properly log 'Error' types
123125
const origLog = logger.log;
124-
logger.log = (level, msg) => {
125-
if (msg instanceof Error) {
126-
// eslint-disable-next-line prefer-rest-params
127-
const args = Array.prototype.slice.call(arguments);
128-
args[1] = msg.stack;
129-
origLog.apply(logger, args);
126+
logger.log = (level, ...rest) => {
127+
if (rest[0] instanceof Error) {
128+
rest[1] = rest[0].stack;
129+
origLog.apply(logger, rest);
130130
} else {
131+
const msg = util.format(...rest);
131132
const transformed = Logger.transformLog(level, msg);
132133
if (!transformed) {
133134
return;

modules/network/kademlia/kademlia.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,29 @@ class Kademlia {
244244
}));
245245
this.log.info('Hashcash initialised');
246246

247+
this.node.blacklist = this.node.plugin(kadence.churnfilter({
248+
cooldownBaseTimeout: this.config.network.churnPlugin.cooldownBaseTimeout,
249+
cooldownMultiplier: this.config.network.churnPlugin.cooldownMultiplier,
250+
cooldownResetTime: this.config.network.churnPlugin.cooldownResetTime,
251+
}));
252+
this.log.info('Churn filter initialised');
253+
254+
// Patch Churn to ignore all outgoing requests towards blacklisted contacts.
255+
const send = this.node.send.bind(this.node);
256+
this.node.send = function (method, params, target, handler) {
257+
try {
258+
const contactId = target[0].toString('hex');
259+
if (this.node.blacklist.hasBlock(contactId)) {
260+
this.log.debug('Trying to send to blacklisted contact: %s.', contactId);
261+
return handler(Error('Contact blacklisted.'));
262+
}
263+
send(method, params, target, handler);
264+
} catch (e) {
265+
this.log.error('Failed to check for blacklist');
266+
handler(Error('Failed to check for blacklist.'));
267+
}
268+
}.bind(this);
269+
247270
if (this.config.onion_enabled) {
248271
this.enableOnion();
249272
}
@@ -254,8 +277,8 @@ class Kademlia {
254277

255278
// Use verbose logging if enabled
256279
if (process.env.LOGS_LEVEL_DEBUG) {
257-
this.node.rpc.deserializer.append(new IncomingMessage(this.log));
258-
this.node.rpc.serializer.prepend(new OutgoingMessage(this.log));
280+
this.node.rpc.deserializer.append(() => new IncomingMessage(this.log));
281+
this.node.rpc.serializer.prepend(() => new OutgoingMessage(this.log));
259282
}
260283
// Cast network nodes to an array
261284
if (typeof this.config.network.bootstraps === 'string') {

0 commit comments

Comments
 (0)