Mise à jour de GitLab prévue ce dimanche 6 décembre 2020 à partir de 9h00 CEST | GitLab upgrade planned this Sunday December 6th 2020 from 9:00 AM CEST

Commit c34598b0 authored by Cédric Moreau's avatar Cédric Moreau

`ucoind sync` command working again

parent 2dc4e55b
...@@ -147,6 +147,32 @@ module.exports.database = { ...@@ -147,6 +147,32 @@ module.exports.database = {
} }
}; };
module.exports.openpgp = {
init: function (currency, conf, done) {
// Import PGP key
openpgp.keyring.importPrivateKey(conf.pgpkey, conf.pgppasswd);
if (!module.exports.fingerprint()) {
pgplogger.error("Wrong PGP key password.");
process.exit(1);
return;
}
done();
}
};
function initServices (currency, conf, done) {
// Init ALL services
service.init(openpgp, currency, conf);
// Load services contexts
service.load(done);
}
module.exports.services = {
init: initServices
};
module.exports.express = { module.exports.express = {
app: function (currency, conf, onLoaded) { app: function (currency, conf, onLoaded) {
...@@ -166,16 +192,19 @@ module.exports.express = { ...@@ -166,16 +192,19 @@ module.exports.express = {
app.use(express.cookieParser('your secret here')); app.use(express.cookieParser('your secret here'));
app.use(express.session()); app.use(express.session());
// Import PGP key async.series([
openpgp.keyring.importPrivateKey(conf.pgpkey, conf.pgppasswd); function (next) {
if (!module.exports.fingerprint()) { // OpenPGP functions
pgplogger.error("Wrong PGP key password."); module.exports.openpgp.init(currency, conf, next);
process.exit(1); },
return; function (next){
} initServices(currency, conf, next);
},
// HTTP Signatures function (next){
httpgp(app, conf, function (err) { // HTTP Signatures
httpgp(app, conf, next);
},
], function(err) {
// HTTPGP OK? // HTTPGP OK?
if (err) { if (err) {
...@@ -192,9 +221,6 @@ module.exports.express = { ...@@ -192,9 +221,6 @@ module.exports.express = {
app.use(express.errorHandler()); app.use(express.errorHandler());
} }
// Init ALL services
service.init(openpgp, currency, conf);
// Init Daemon // Init Daemon
var daemon = require('./daemon'); var daemon = require('./daemon');
daemon.init(conf, module.exports.fingerprint()); daemon.init(conf, module.exports.fingerprint());
...@@ -273,6 +299,25 @@ module.exports.express = { ...@@ -273,6 +299,25 @@ module.exports.express = {
var SyncService = service.Sync; var SyncService = service.Sync;
async.waterfall([ async.waterfall([
function (next) {
if(conf.ipv4){
logger.info('Connecting on interface %s...', conf.ipv4);
http.createServer(app).listen(conf.port, conf.ipv4, function(){
logger.info('uCoin server listening on ' + conf.ipv4 + ' port ' + conf.port);
next();
});
}
else next();
},
function (next) {
if(conf.ipv6){
logger.info('Connecting on interface %s...', conf.ipv6);
http.createServer(app).listen(conf.port, conf.ipv6, function(){
logger.info('uCoin server listening on ' + conf.ipv6 + ' port ' + conf.port);
});
}
else next();
},
function (next) { function (next) {
mongoose.model('Peer').find({ fingerprint: module.exports.fingerprint() }, next); mongoose.model('Peer').find({ fingerprint: module.exports.fingerprint() }, next);
}, },
...@@ -311,7 +356,7 @@ module.exports.express = { ...@@ -311,7 +356,7 @@ module.exports.express = {
}, },
function (signature, next) { function (signature, next) {
signature = signature.substring(signature.indexOf('-----BEGIN PGP SIGNATURE')); signature = signature.substring(signature.indexOf('-----BEGIN PGP SIGNATURE'));
PeeringService.persistPeering(raw2 + signature, module.exports.publicKey(), next); PeeringService.submit(raw2 + signature, module.exports.fingerprint(), next);
}, },
], function (err) { ], function (err) {
next(err); next(err);
...@@ -321,11 +366,11 @@ module.exports.express = { ...@@ -321,11 +366,11 @@ module.exports.express = {
} }
}, },
function (next){ function (next){
// Load services contexts mongoose.model('Peer').getTheOne(module.exports.fingerprint(), next);
service.load(next);
}, },
function (next){ function (peer, next){
// Set peer's statut to UP // Set peer's statut to UP
PeeringService.peer(peer);
PeeringService.peer().status = 'UP'; PeeringService.peer().status = 'UP';
PeeringService.peer().save(function (err) { PeeringService.peer().save(function (err) {
// Update it in memory // Update it in memory
...@@ -333,25 +378,6 @@ module.exports.express = { ...@@ -333,25 +378,6 @@ module.exports.express = {
next(err); next(err);
}); });
}, },
function (next) {
if(conf.ipv4){
logger.debug('Connecting on interface %s...', conf.ipv4);
http.createServer(app).listen(conf.port, conf.ipv4, function(){
logger.debug('uCoin server listening on ' + conf.ipv4 + ' port ' + conf.port);
next();
});
}
else next();
},
function (next) {
if(conf.ipv6){
logger.debug('Connecting on interface %s...', conf.ipv6);
http.createServer(app).listen(conf.port, conf.ipv6, function(){
logger.debug('uCoin server listening on ' + conf.ipv6 + ' port ' + conf.port);
});
}
else next();
},
function (next) { function (next) {
// Initialize managed keys // Initialize managed keys
PeeringService.initKeys(next); PeeringService.initKeys(next);
...@@ -370,12 +396,18 @@ module.exports.express = { ...@@ -370,12 +396,18 @@ module.exports.express = {
logger.info('Broadcasting UP/NEW signals...'); logger.info('Broadcasting UP/NEW signals...');
PeeringService.sendUpSignal(next); PeeringService.sendUpSignal(next);
}, },
function (next) { function (next){
// Create AM0 proposal if not existing mongoose.model('Amendment').current(function (err, am) {
mongoose.model('Amendment').getTheOneToBeVoted(0, function (err, am) { next(null, am);
});
},
function (currentAM, next) {
var nextAMNumber = currentAM && currentAM.number + 1 || 0;
// Create NEXT AM proposal if not existing
mongoose.model('Amendment').getTheOneToBeVoted(nextAMNumber, function (err, am) {
if (err || !am) { if (err || !am) {
logger.info('Creating root AM proposal...'); logger.info('Creating next AM (#%d) proposal...', nextAMNumber);
SyncService.createNext(null, next); SyncService.createNext(currentAM, next);
return; return;
} }
next(); next();
......
This diff is collapsed.
...@@ -209,23 +209,15 @@ AmendmentSchema.statics.nextNumber = function (done) { ...@@ -209,23 +209,15 @@ AmendmentSchema.statics.nextNumber = function (done) {
AmendmentSchema.statics.current = function (done) { AmendmentSchema.statics.current = function (done) {
this.find({ promoted: true }, function (err, amends) { this.find({ promoted: true }).sort({ number: -1 }).limit(1).exec(function (err, amends) {
if(amends && amends.length == 1){ if(amends && amends.length == 1){
done(err, amends[0]); done(err, amends[0]);
return; return;
} }
if(!amends || amends.length == 0){ else {
done('No current amendment'); done('No current amendment');
return; return;
} }
if(amends || amends.length > 1){
var current = undefined;
amends.forEach(function (am) {
if(!current || (current && current.number < am.number))
current = am;
});
done(err, current);
}
}); });
}; };
......
...@@ -64,10 +64,13 @@ function PeeringService(pgp, currency, conf) { ...@@ -64,10 +64,13 @@ function PeeringService(pgp, currency, conf) {
dbPeers.forEach(function(peer){ dbPeers.forEach(function(peer){
that.addPeer(peer); that.addPeer(peer);
}); });
Peer.getTheOne(that.cert.fingerprint, next); Peer.getTheOne(that.cert.fingerprint, function (err, selfPeer) {
if (selfPeer)
peer = selfPeer;
next();
});
}, },
function (selfPeer, next){ function (next){
peer = selfPeer;
logger.debug('Loaded service: Peering'); logger.debug('Loaded service: Peering');
next(); next();
}, },
...@@ -105,7 +108,7 @@ function PeeringService(pgp, currency, conf) { ...@@ -105,7 +108,7 @@ function PeeringService(pgp, currency, conf) {
next(null, pubkey.raw); next(null, pubkey.raw);
}, },
function (pubkey, next){ function (pubkey, next){
that.persistPeering(signedPR, pubkey, next); persistPeering(signedPR, pubkey, next);
} }
], callback); ], callback);
} }
...@@ -149,14 +152,14 @@ function PeeringService(pgp, currency, conf) { ...@@ -149,14 +152,14 @@ function PeeringService(pgp, currency, conf) {
wasStatus = peer.status; wasStatus = peer.status;
peer.setStatus(status.status, next); peer.setStatus(status.status, next);
peer.statusSigDate = status.sigDate; peer.statusSigDate = status.sigDate;
peers[peer.fingerprint].status = status;
} }
], function (err) { ], function (err) {
peers[peer.fingerprint].status = status;
callback(err, status, peer, wasStatus); callback(err, status, peer, wasStatus);
}); });
} }
this.persistPeering = function (signedPR, pubkey, done) { function persistPeering (signedPR, pubkey, done) {
var peer = new Peer(); var peer = new Peer();
async.waterfall([ async.waterfall([
function (next){ function (next){
...@@ -679,7 +682,7 @@ function PeeringService(pgp, currency, conf) { ...@@ -679,7 +682,7 @@ function PeeringService(pgp, currency, conf) {
function getForwardPeers (done) { function getForwardPeers (done) {
async.waterfall([ async.waterfall([
async.apply(Forward.find.bind(Forward), { to: this.cert.fingerprint }), async.apply(Forward.find.bind(Forward), { to: that.cert.fingerprint }),
function (fwds, next) { function (fwds, next) {
var fingerprints = _(fwds).map(function(fwd){ return fwd.fingerprint; }); var fingerprints = _(fwds).map(function(fwd){ return fwd.fingerprint; });
Peer.getList(fingerprints, next); Peer.getList(fingerprints, next);
......
...@@ -101,7 +101,55 @@ module.exports.get = function (pgp, currency, conf) { ...@@ -101,7 +101,55 @@ module.exports.get = function (pgp, currency, conf) {
}, next); }, next);
}, },
function (next){ function (next){
SyncService.createNext(am, next); Key.getMembers(next);
},
function (members, next){
// Update Merkle of proposed members
async.waterfall([
function (next){
Merkle.proposedMembers(next);
},
function (merkle, next){
var fingerprints = [];
members.forEach(function(m){
fingerprints.push(m.fingerprint);
});
fingerprints.sort();
merkle.initialize(fingerprints);
merkle.save(function (err) {
next(err);
});
},
], next);
},
function (next){
Key.getVoters(next);
},
function (voters, next){
// Update Merkle of proposed voters
async.waterfall([
function (next){
Merkle.proposedVoters(next);
},
function (merkle, next){
var fingerprints = [];
voters.forEach(function(v){
fingerprints.push(v.fingerprint);
});
fingerprints.sort();
merkle.initialize(fingerprints);
merkle.save(function (err) {
next(err);
});
},
], next);
},
function (next){
if (conf.createNext) {
SyncService.createNext(am, next);
} else {
next();
}
}, },
], cb); ], cb);
}, done); }, done);
......
...@@ -454,9 +454,9 @@ module.exports.get = function (pgp, currency, conf) { ...@@ -454,9 +454,9 @@ module.exports.get = function (pgp, currency, conf) {
} }
function updateUniversalDividend (amNext, amCurrent, done) { function updateUniversalDividend (amNext, amCurrent, done) {
// Time for Universal Dividend // Time for Universal Dividend (and we have members)
var delayPassedSinceRootAM = (amNext.generated - conf.sync.AMStart); var delayPassedSinceRootAM = (amNext.generated - conf.sync.AMStart);
if (delayPassedSinceRootAM > 0 && delayPassedSinceRootAM % conf.sync.UDFreq == 0) { if (delayPassedSinceRootAM > 0 && delayPassedSinceRootAM % conf.sync.UDFreq == 0 && amNext.membersCount > 0) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
Amendment.getPreviouslyPromotedWithDividend(next); Amendment.getPreviouslyPromotedWithDividend(next);
...@@ -799,11 +799,11 @@ module.exports.get = function (pgp, currency, conf) { ...@@ -799,11 +799,11 @@ module.exports.get = function (pgp, currency, conf) {
var stateFunc = async.apply(whatToDo.state[lastKeyState.toString()][statusTo.toString()] || doNothingWithState, key, statusTo); var stateFunc = async.apply(whatToDo.state[lastKeyState.toString()][statusTo.toString()] || doNothingWithState, key, statusTo);
if ((lastKeyState == 0 && statusTo == 1) || (lastKeyState == -1 && statusTo == 0)) { if ((lastKeyState == 0 && statusTo == 1) || (lastKeyState == -1 && statusTo == 0)) {
// Make positive change // Make positive change
console.log('> +%s', key); mathlog.info('VT +%s', key);
actionForVoters(merkleFunc, keysFunc, stateFunc, amNext, next); actionForVoters(merkleFunc, keysFunc, stateFunc, amNext, next);
} else if ((lastKeyState == 1 && statusTo == 0) || (lastKeyState == 0 && statusTo == -1)) { } else if ((lastKeyState == 1 && statusTo == 0) || (lastKeyState == 0 && statusTo == -1)) {
// Make negative change // Make negative change
console.log('> -%s', key); mathlog.info('VT -%s', key);
actionForVoters(merkleFunc, keysFunc, stateFunc, amNext, next); actionForVoters(merkleFunc, keysFunc, stateFunc, amNext, next);
} else { } else {
// Do nothing! // Do nothing!
......
...@@ -46,23 +46,28 @@ program ...@@ -46,23 +46,28 @@ program
.description('Tries to synchronise data with remote uCoin node') .description('Tries to synchronise data with remote uCoin node')
.action(connect(function (host, port, conf) { .action(connect(function (host, port, conf) {
// Init server // Disable daemon
server.express.app(program.currency, conf, function (err, app) { conf.sync.AMDaemon = "OFF";
// Synchronize async.series([
var Synchroniser = require('../app/lib/sync'); function (next){
var remote = new Synchroniser(host, port, false, server.pgp, program.currency, conf); server.openpgp.init(program.currency, conf, next);
async.waterfall([ },
function (next){ function (next){
remote.sync(next); server.services.init(program.currency, conf, next);
}, },
], function (err) { function (next){
if(err){ // Synchronize
logger.error('Error during sync:', err); var Synchroniser = require('../app/lib/sync');
} var remote = new Synchroniser(host, port, false, program.currency, conf);
server.database.disconnect(); remote.sync(next);
process.exit(); },
}); ], function (err) {
if(err){
logger.error('Error during sync:', err);
}
server.database.disconnect();
process.exit();
}); });
})); }));
...@@ -301,6 +306,9 @@ function overrideConf(conf) { ...@@ -301,6 +306,9 @@ function overrideConf(conf) {
MSExpires: config.sync.MSExpires || conf.sync.MSExpires || 3600*24*30.4375*6, // 6 months MSExpires: config.sync.MSExpires || conf.sync.MSExpires || 3600*24*30.4375*6, // 6 months
UCSBlockFreq: config.sync.UCSBlockFreq || conf.sync.UCSBlockFreq || 3600 // hourly UCSBlockFreq: config.sync.UCSBlockFreq || conf.sync.UCSBlockFreq || 3600 // hourly
}; };
// Specific internal settings
conf.createNext = true;
return conf; return conf;
} }
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
"hdc": "~0.5.0", "hdc": "~0.5.0",
"connect-pgp": "~0.2.1", "connect-pgp": "~0.2.1",
"underscore": "~1.5.2", "underscore": "~1.5.2",
"vucoin": "~0.10.0", "vucoin": "~0.12.0",
"request": "~2.31.0", "request": "~2.31.0",
"log4js": "~0.6.9" "log4js": "~0.6.9"
}, },
......
...@@ -67,7 +67,8 @@ var conf = { ...@@ -67,7 +67,8 @@ var conf = {
UDPercent: 0.5, // So it can be tested under 4 UD - this ultra high value of UD growth UDPercent: 0.5, // So it can be tested under 4 UD - this ultra high value of UD growth
Consensus: 2/3, Consensus: 2/3,
MSExpires: 3600*24*30 // 30 days MSExpires: 3600*24*30 // 30 days
} },
createNext: true
}; };
var amendments = { var amendments = {
......
...@@ -76,7 +76,8 @@ var conf = { ...@@ -76,7 +76,8 @@ var conf = {
UDPercent: 0.5, // So it can be tested under 4 UD - this ultra high value of UD growth UDPercent: 0.5, // So it can be tested under 4 UD - this ultra high value of UD growth
Consensus: 2/3, Consensus: 2/3,
MSExpires: 3600*24*30 // 30 days MSExpires: 3600*24*30 // 30 days
} },
createNext: true
}; };
var amendments = { var amendments = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment