mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-17 05:21:27 +02:00
Update to how we store share data to avoid transactional locks.
This commit is contained in:
+31
-40
@@ -181,10 +181,10 @@ function Database(){
|
||||
|
||||
this.storeBulkShares = function(shareObject) {
|
||||
let cachedData = {
|
||||
global_stats: global.database.getCache('global_stats'),
|
||||
pplns_stats: global.database.getCache('pplns_stats'),
|
||||
pps_stats: global.database.getCache('pps_stats'),
|
||||
solo_stats: global.database.getCache('solo_stats')
|
||||
global_stats: {totalHashes: 0, roundHashes: 0},
|
||||
pplns_stats: {totalHashes: 0, roundHashes: 0},
|
||||
pps_stats: {totalHashes: 0, roundHashes: 0},
|
||||
solo_stats: {totalHashes: 0, roundHashes: 0}
|
||||
};
|
||||
let shares = {}; // Shares keyed by blockID
|
||||
let shareCount = 0;
|
||||
@@ -202,13 +202,6 @@ function Database(){
|
||||
minerID = minerID + '.' + share.paymentID;
|
||||
}
|
||||
let minerIDWithIdentifier = minerID + "_" + share.identifier;
|
||||
// this.incrementCacheData('global_stats', [{location: 'totalHashes', value: share.shares}, {location: 'roundHashes', value: share.shares}]);
|
||||
if (!cachedData.global_stats.hasOwnProperty('totalHashes') || cachedData.global_stats.totalHashes === null) {
|
||||
cachedData.global_stats.totalHashes = 0;
|
||||
}
|
||||
if (!cachedData.global_stats.hasOwnProperty('roundHashes') || cachedData.global_stats.roundHashes === null || share.foundBlock) {
|
||||
cachedData.global_stats.roundHashes = 0;
|
||||
}
|
||||
cachedData.global_stats.totalHashes += share.shares;
|
||||
cachedData.global_stats.roundHashes += share.shares;
|
||||
let stats_type = 'pplns_stats';
|
||||
@@ -223,39 +216,13 @@ function Database(){
|
||||
stats_type = 'solo_stats';
|
||||
break;
|
||||
}
|
||||
if (!cachedData[stats_type].hasOwnProperty('totalHashes') || cachedData[stats_type].totalHashes === null) {
|
||||
cachedData[stats_type].totalHashes = 0;
|
||||
}
|
||||
if (!cachedData[stats_type].hasOwnProperty('roundHashes') || cachedData[stats_type].roundHashes === null || share.foundBlock) {
|
||||
cachedData[stats_type].roundHashes = 0;
|
||||
}
|
||||
cachedData[stats_type].totalHashes += share.shares;
|
||||
cachedData[stats_type].roundHashes += share.shares;
|
||||
if (!cachedData.hasOwnProperty(minerID)) {
|
||||
let minerCache = global.database.getCache(minerID);
|
||||
if (minerCache === false) {
|
||||
minerCache = {totalHashes: 0, goodShares: 0};
|
||||
}
|
||||
cachedData[minerID] = minerCache;
|
||||
cachedData[minerID] = {totalHashes: 0, goodShares: 0};
|
||||
}
|
||||
if (!cachedData.hasOwnProperty(minerIDWithIdentifier)) {
|
||||
let minerCache = global.database.getCache(minerIDWithIdentifier);
|
||||
if (minerCache === false) {
|
||||
minerCache = {totalHashes: 0, goodShares: 0};
|
||||
}
|
||||
cachedData[minerIDWithIdentifier] = minerCache;
|
||||
}
|
||||
if (!cachedData[minerIDWithIdentifier].hasOwnProperty('totalHashes') || cachedData[minerIDWithIdentifier].totalHashes === null) {
|
||||
cachedData[minerIDWithIdentifier].totalHashes = 0;
|
||||
}
|
||||
if (!cachedData[minerIDWithIdentifier].hasOwnProperty('goodShares') || cachedData[minerIDWithIdentifier].goodShares === null) {
|
||||
cachedData[minerIDWithIdentifier].goodShares = 0;
|
||||
}
|
||||
if (!cachedData[minerID].hasOwnProperty('totalHashes') || cachedData[minerID].totalHashes === null) {
|
||||
cachedData[minerID].totalHashes = 0;
|
||||
}
|
||||
if (!cachedData[minerID].hasOwnProperty('goodShares') || cachedData[minerID].goodShares === null) {
|
||||
cachedData[minerID].goodShares = 0;
|
||||
cachedData[minerIDWithIdentifier] = {totalHashes: 0, goodShares: 0};
|
||||
}
|
||||
cachedData[minerIDWithIdentifier].totalHashes += share.shares;
|
||||
cachedData[minerID].totalHashes += share.shares;
|
||||
@@ -266,10 +233,30 @@ function Database(){
|
||||
}
|
||||
if(shareObject.length === shareCount){
|
||||
// Perform insert and return
|
||||
let inCache = 'notNull';
|
||||
while (inCache !== null){
|
||||
let txn_ro = global.database.env.beginTxn({readOnly: true});
|
||||
inCache = txn_ro.getString(global.database.cacheDB, 'cacheUpdate');
|
||||
txn_ro.abort();
|
||||
}
|
||||
|
||||
let txn = global.database.env.beginTxn();
|
||||
for (let key in cachedData){
|
||||
if (cachedData.hasOwnProperty(key)){
|
||||
txn.putString(global.database.cacheDB, key, JSON.stringify(cachedData[key]));
|
||||
let cacheStore = txn.getString(global.database.cacheDB, key);
|
||||
if (cacheStore === null){
|
||||
txn.putString(global.database.cacheDB, key, JSON.stringify(cachedData[key]));
|
||||
} else {
|
||||
let json_cache = JSON.parse(cacheStore);
|
||||
if (json_cache.hasOwnProperty('totalHashes')){
|
||||
json_cache.totalHashes += cachedData[key].totalHashes;
|
||||
json_cache.goodShares += cachedData[key].goodShares;
|
||||
} else {
|
||||
json_cache.totalHashes = cachedData[key].totalHashes;
|
||||
json_cache.goodShares = cachedData[key].goodShares;
|
||||
}
|
||||
txn.putString(global.database.cacheDB, key, JSON.stringify(json_cache));
|
||||
}
|
||||
}
|
||||
}
|
||||
let blocksSeen = 0;
|
||||
@@ -511,11 +498,15 @@ function Database(){
|
||||
|
||||
this.bulkSetCache = function(cacheUpdates){
|
||||
let txn = this.env.beginTxn();
|
||||
txn.putString(this.cacheDB, 'cacheUpdate', 'cacheUpdate');
|
||||
txn.commit();
|
||||
txn = this.env.beginTxn();
|
||||
for (let key in cacheUpdates){
|
||||
if (cacheUpdates.hasOwnProperty(key)){
|
||||
txn.putString(this.cacheDB, key, JSON.stringify(cacheUpdates[key]));
|
||||
}
|
||||
}
|
||||
txn.del(this.cacheDB, 'cacheUpdate');
|
||||
txn.commit();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user