Revert "Fix DATUM PPLNS coinbaser snapshots"

This reverts commit 1943ea7768.
This commit is contained in:
Ben
2026-06-21 11:12:09 -04:00
parent 1943ea7768
commit bdd3c7c3ae
8 changed files with 18 additions and 214 deletions
@@ -51,15 +51,6 @@ export interface ExpectedPayout {
percent: number;
}
export interface CreatePayoutSnapshotInput {
blockHeight: number;
coinbaseValueSats: number;
networkDifficulty: number;
method?: string;
maxCoinbaseOutputs?: number;
coinbaseWeightBudget?: number;
}
const DEFAULT_MAX_COINBASE_OUTPUTS = 10;
const DEFAULT_MIN_OUTPUT_SATS = 546;
const DEFAULT_PAYOUT_METHOD = 'pplns';
@@ -84,15 +75,15 @@ export class PayoutSnapshotService {
private readonly dataSource: DataSource,
) { }
public async createSnapshotForTemplate(input: CreatePayoutSnapshotInput): Promise<PayoutSnapshotForTemplate | null> {
public async createSnapshotForTemplate(input: {
blockHeight: number;
coinbaseValueSats: number;
networkDifficulty: number;
}): Promise<PayoutSnapshotForTemplate | null> {
if (!this.snapshotsEnabled || input.coinbaseValueSats <= 0 || input.networkDifficulty <= 0) {
return null;
}
const method = this.normalizeMethod(input.method);
const maxCoinbaseOutputs = this.resolvePositiveInt(input.maxCoinbaseOutputs, this.maxCoinbaseOutputs);
const coinbaseWeightBudget = this.resolvePositiveInt(input.coinbaseWeightBudget, this.coinbaseWeightBudget);
return this.dataSource.transaction(async manager => {
const effectiveWindowFactor = await this.getEffectiveWindowFactor(manager);
const windowTargetDifficulty = input.networkDifficulty * effectiveWindowFactor;
@@ -102,7 +93,6 @@ export class PayoutSnapshotService {
}
const existing = await this.getExistingSnapshot(manager, {
method,
blockHeight: input.blockHeight,
coinbaseValueSats: input.coinbaseValueSats,
windowEndShareIndex: window.windowEndShareIndex,
@@ -124,9 +114,9 @@ export class PayoutSnapshotService {
feeAddress: this.feeAddress,
feePercent: this.feePercent,
minOutputSats: this.minOutputSats,
coinbaseWeightBudget,
coinbaseWeightBudget: this.coinbaseWeightBudget,
});
const entries = this.limitCoinbaseOutputs(distribution.entries, maxCoinbaseOutputs);
const entries = this.limitCoinbaseOutputs(distribution.entries);
if (entries.every(entry => !entry.includedInCoinbase)) {
return null;
}
@@ -186,7 +176,7 @@ export class PayoutSnapshotService {
)
RETURNING "id"::text AS "id"
`, [
method,
this.method,
PPLNS_PAYOUT_MODE,
input.blockHeight,
input.coinbaseValueSats.toString(),
@@ -196,7 +186,7 @@ export class PayoutSnapshotService {
this.feeAddress,
distribution.feeSats.toString(),
this.minOutputSats,
coinbaseWeightBudget,
this.coinbaseWeightBudget,
window.startBatchId,
window.endBatchId,
window.windowStartShareIndex,
@@ -400,10 +390,9 @@ export class PayoutSnapshotService {
FROM "payout_snapshot"
WHERE "status" = 'finalized'
AND "payoutMode" = $1
AND "method" = $2
ORDER BY "createdAt" DESC, "id" DESC
LIMIT 1
`, [PPLNS_PAYOUT_MODE, this.method]);
`, [PPLNS_PAYOUT_MODE]);
if (snapshot?.id == null) {
return null;
}
@@ -425,7 +414,6 @@ export class PayoutSnapshotService {
FROM "payout_snapshot"
WHERE "status" = 'finalized'
AND "payoutMode" = $2
AND "method" = $3
ORDER BY "createdAt" DESC, "id" DESC
LIMIT 1
)
@@ -449,7 +437,7 @@ export class PayoutSnapshotService {
AND e."includedInCoinbase" = true
AND e."payoutSats" > 0
LIMIT 1
`, [address, PPLNS_PAYOUT_MODE, this.method]);
`, [address, PPLNS_PAYOUT_MODE]);
if (row == null) {
return null;
@@ -566,7 +554,7 @@ export class PayoutSnapshotService {
private async getExistingSnapshot(
manager: EntityManager,
input: { method: string; blockHeight: number; coinbaseValueSats: number; windowEndShareIndex: string },
input: { blockHeight: number; coinbaseValueSats: number; windowEndShareIndex: string },
): Promise<PayoutSnapshotForTemplate | null> {
const [snapshot] = await manager.query(`
SELECT "id"::text AS "id"
@@ -580,7 +568,7 @@ export class PayoutSnapshotService {
ORDER BY "id" DESC
LIMIT 1
`, [
input.method,
this.method,
input.blockHeight,
input.coinbaseValueSats.toString(),
input.windowEndShareIndex,
@@ -701,7 +689,7 @@ export class PayoutSnapshotService {
]);
}
private limitCoinbaseOutputs(entries: PayoutDistributionEntry[], maxCoinbaseOutputs: number): PayoutDistributionEntry[] {
private limitCoinbaseOutputs(entries: PayoutDistributionEntry[]): PayoutDistributionEntry[] {
let included = 0;
let removedPayoutSats = 0;
const limitedEntries = entries.map(entry => {
@@ -709,7 +697,7 @@ export class PayoutSnapshotService {
return entry;
}
included++;
if (included <= maxCoinbaseOutputs) {
if (included <= this.maxCoinbaseOutputs) {
return entry;
}
removedPayoutSats += entry.payoutSats;
@@ -773,17 +761,6 @@ export class PayoutSnapshotService {
return Number.isInteger(value) && value > 0 ? value : defaultValue;
}
private resolvePositiveInt(value: number | undefined, defaultValue: number): number {
return Number.isInteger(value) && value > 0 ? value : defaultValue;
}
private normalizeMethod(method?: string): string {
const normalized = method?.trim();
return normalized == null || normalized.length === 0
? this.method
: normalized.slice(0, 32);
}
private readNonNegativeInt(name: string, defaultValue: number): number {
const value = Number(process.env[name]);
return Number.isInteger(value) && value >= 0 ? value : defaultValue;