Skip to content

Commit

Permalink
imp logs
Browse files Browse the repository at this point in the history
  • Loading branch information
argonmining committed Aug 22, 2024
1 parent c17518c commit afe0bd1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class Pool {
private monitoring: Monitoring;
private sharesManager: SharesManager; // Add SharesManager property
private pushMetrics: PushMetrics; // Add PushMetrics property
private lastProcessedTimestamp = 0; // Add timestamp check

constructor(treasury: Treasury, stratum: Stratum, sharesManager: SharesManager) {
this.treasury = treasury;
Expand All @@ -30,7 +31,16 @@ export default class Pool {
this.pushMetrics = new PushMetrics(process.env.PUSHGATEWAY || ''); // Initialize PushMetrics

this.stratum.on('subscription', (ip: string, agent: string) => this.monitoring.log(`Pool: Miner ${ip} subscribed into notifications with ${agent}.`));
this.treasury.on('coinbase', (minerReward: bigint, poolFee: bigint) => this.allocate(minerReward, poolFee));
this.treasury.on('coinbase', (minerReward: bigint, poolFee: bigint) => {
const currentTimestamp = Date.now();
if (currentTimestamp - this.lastProcessedTimestamp < 1000) { // 1 second cooldown
this.monitoring.debug(`Pool: Skipping duplicate coinbase event. Last processed: ${this.lastProcessedTimestamp}, Current: ${currentTimestamp}`);
return;
}
this.lastProcessedTimestamp = currentTimestamp;
this.monitoring.log(`Pool: Processing coinbase event. Timestamp: ${currentTimestamp}`);
this.allocate(minerReward, poolFee).catch(console.error)
});
//this.treasury.on('revenue', (amount: bigint) => this.revenuize(amount));

this.monitoring.log(`Pool: Pool is active on port ${this.stratum.server.socket.port}.`);
Expand All @@ -44,12 +54,14 @@ export default class Pool {
}

private async allocate(minerReward: bigint, poolFee: bigint) {
this.monitoring.debug(`Pool: Starting allocation. Miner Reward: ${minerReward}, Pool Fee: ${poolFee}`);
const works = new Map<string, { minerId: string, difficulty: number }>();
let totalWork = 0;
const walletHashrateMap = new Map<string, number>();

// Get all shares since the last allocation
const shares = this.sharesManager.getSharesSinceLastAllocation();
this.monitoring.debug(`Pool: Retrieved ${shares.length} shares for allocation`);

for (const share of shares) {
const { address, difficulty, minerId } = share;
Expand Down Expand Up @@ -82,7 +94,7 @@ export default class Pool {

// Ensure totalWork is greater than 0 to prevent division by zero
if (totalWork === 0) {
if (DEBUG) this.monitoring.debug(`Pool: No work found for allocation in the current cycle.`);
this.monitoring.debug(`Pool: No work found for allocation in the current cycle. Total shares: ${shares.length}`);
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/stratum/sharesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export class SharesManager {
while (this.shareWindow.length > 0 && (this.shareWindow.peekFront()?.timestamp ?? 0) >= this.lastAllocationTime) {
shares.push(this.shareWindow.shift()!);
}
this.monitoring.debug(`SharesManager: Retrieved ${shares.length} shares. Last allocation time: ${this.lastAllocationTime}, Current time: ${currentTime}`);
this.lastAllocationTime = currentTime;
return shares;
}
Expand Down
4 changes: 2 additions & 2 deletions src/treasury/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export default class Treasury extends EventEmitter {
this.processor.addEventListener('maturity', (e) => {
// @ts-ignore
const reward = e.data.value
this.monitoring.log(`Treasury: Rewards to distribute on this coinbase cycle: ${reward}.`);
this.monitoring.log(`Treasury: Maturity event received. Reward: ${reward}, Event timestamp: ${Date.now()}`);
const poolFee = (reward * BigInt(this.fee * 100)) / 10000n
this.monitoring.log(`Treasury: Pool fees to retain on the coinbase cycle: ${poolFee}.`);
this.emit('coinbase', reward - poolFee, poolFee)
})

this.processor.start()
}
}
}

0 comments on commit afe0bd1

Please sign in to comment.