Bounded test succeeded; native RandomX miner accepted one block
This commit is contained in:
+63
-3
@@ -5,7 +5,7 @@ import { postgresConfig } from '../server/market/postgres-config.ts';
|
||||
import { migrateCustody, grantCustodyRuntime, grantMoneroObserverRuntime,
|
||||
grantMoneroDepositCreditRuntime, grantMoneroDepositAllocatorRuntime, grantMoneroWithdrawalRuntime,
|
||||
grantPilotDepositReservationRuntime, grantPilotDepositAddressRuntime,
|
||||
grantPilotMoneroObserverRuntime } from '../server/market/postgres-schema.ts';
|
||||
grantPilotMoneroObserverRuntime, grantPilotMoneroDepositReviewRuntime } from '../server/market/postgres-schema.ts';
|
||||
import { initializeMainnetCustodyIdentity, parseMainnetCustodianId } from '../server/market/mainnet-custody-identity.ts';
|
||||
import { importSqliteCustody } from '../server/market/custody-import.ts';
|
||||
import { PostgresCustody } from '../server/market/postgres-custody.ts';
|
||||
@@ -18,21 +18,25 @@ import { assertCustodyDbActionAllowedOnNetwork, assertMainnetSchemaMigrationAckn
|
||||
assertPilotCustodyIdentityAcknowledged, assertPilotReservationGrantAcknowledged,
|
||||
assertPilotAddressGrantAcknowledged,
|
||||
assertPilotObserverGrantAcknowledged,
|
||||
assertPilotDepositReviewAcknowledged,
|
||||
parseCustodyDbArguments } from '../server/market/custody-db-args.ts';
|
||||
import { prepareDepositCreditReview, postReviewedDepositPendingCredit, prepareDepositCreditReleaseReview,
|
||||
releaseReviewedDepositCredit, reconcileDepositCreditReorgHolds, prepareDepositReorgResolution,
|
||||
resolveReleasedDepositReorgHold, type DepositCreditApproval, type DepositCreditReleaseApproval,
|
||||
type DepositReorgResolutionApproval } from '../server/market/monero-deposit-credit.ts';
|
||||
import { preparePilotMoneroDepositReview } from '../server/market/pilot-monero-deposit-review.ts';
|
||||
|
||||
// Explicit operator task, never invoked by node startup. No passwords or database URLs printed.
|
||||
const commandArgs = process.argv.slice(2);
|
||||
const depositActions = ['deposit-prepare-credit', 'deposit-stage-credit', 'deposit-prepare-release', 'deposit-release',
|
||||
'deposit-reconcile-holds', 'deposit-prepare-resolve-hold', 'deposit-resolve-hold'];
|
||||
const pilotReviewActions = ['pilot-deposit-prepare-review'];
|
||||
const custodyActions = ['migrate', 'migrate-mainnet-schema', 'initialize-mainnet-custody-identity', 'migrate-pilot-schema',
|
||||
'initialize-pilot-custody-identity', 'grant-runtime', 'grant-monero-observer-runtime',
|
||||
'grant-pilot-deposit-reservation-runtime',
|
||||
'grant-pilot-deposit-address-runtime',
|
||||
'grant-pilot-monero-observer-runtime',
|
||||
'grant-pilot-monero-review-runtime',
|
||||
'grant-monero-withdrawal-runtime',
|
||||
'grant-monero-deposit-allocator-runtime', 'grant-monero-credit-runtime',
|
||||
'import-sqlite', 'audit', 'resolve-integrity'];
|
||||
@@ -47,12 +51,42 @@ assertPilotCustodyIdentityAcknowledged(action, process.env.WIKIDECK_PILOT_CUSTOD
|
||||
assertPilotReservationGrantAcknowledged(action, process.env.WIKIDECK_PILOT_CUSTODY_OPERATIONS);
|
||||
assertPilotAddressGrantAcknowledged(action, process.env.WIKIDECK_PILOT_CUSTODY_OPERATIONS);
|
||||
assertPilotObserverGrantAcknowledged(action, process.env.WIKIDECK_PILOT_CUSTODY_OPERATIONS);
|
||||
assertPilotDepositReviewAcknowledged(action, process.env.WIKIDECK_PILOT_CUSTODY_OPERATIONS);
|
||||
if (action === 'initialize-mainnet-custody-identity' && process.env.WIKIDECK_MAINNET_CUSTODY_IDENTITY !== 'initialize-mainnet-custody-v1') {
|
||||
throw new Error('Mainnet custody identity initialization requires WIKIDECK_MAINNET_CUSTODY_IDENTITY=initialize-mainnet-custody-v1');
|
||||
}
|
||||
if (!custodyActions.includes(action) && !depositActions.includes(action)) throw new Error('Unsupported custody operation');
|
||||
if (!custodyActions.includes(action) && !depositActions.includes(action) && !pilotReviewActions.includes(action)) {
|
||||
throw new Error('Unsupported custody operation');
|
||||
}
|
||||
|
||||
function boundedPilotReviewSetting(name: string, fallback: number, minimum: number, maximum: number): number {
|
||||
const value = process.env[name];
|
||||
if (value === undefined) return fallback;
|
||||
if (!/^(0|[1-9]\d{0,8})$/.test(value)) throw new Error(`Invalid ${name}`);
|
||||
const parsed = Number(value);
|
||||
if (!Number.isSafeInteger(parsed) || parsed < minimum || parsed > maximum) throw new Error(`Invalid ${name}`);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
try {
|
||||
const config = await postgresConfig();
|
||||
const reviewRole = pilotReviewActions.includes(action) ? process.env.WIKIDECK_PILOT_REVIEW_DB_ROLE : undefined;
|
||||
let config;
|
||||
if (pilotReviewActions.includes(action)) {
|
||||
const reviewUrlFile = process.env.WIKIDECK_PILOT_REVIEW_PG_URL_FILE;
|
||||
const reviewCaFile = process.env.WIKIDECK_PILOT_REVIEW_PG_CA_FILE;
|
||||
if (!IS_PILOT || process.env.WIKIDECK_PILOT_MODE !== 'private-mock-only' || !reviewRole ||
|
||||
!/^[a-z][a-z0-9_]{0,62}$/.test(reviewRole) || !reviewUrlFile || !reviewCaFile) {
|
||||
throw new Error('Pilot review requires the private mock-only profile, exact review-role name, and dedicated PostgreSQL TLS secret files');
|
||||
}
|
||||
config = await postgresConfig({ ...process.env,
|
||||
WIKIDECK_CUSTODY_PG_URL_FILE: reviewUrlFile,
|
||||
WIKIDECK_CUSTODY_PG_CA_FILE: reviewCaFile,
|
||||
WIKIDECK_CUSTODY_PG_TRANSPORT: 'tls',
|
||||
WIKIDECK_CUSTODY_PG_LOCAL_TEST: undefined,
|
||||
WIKIDECK_CUSTODY_PG_INFRASTRUCTURE_ACK: undefined,
|
||||
});
|
||||
if (config.user !== reviewRole) throw new Error('Pilot review PostgreSQL secret does not use the configured read-only review role');
|
||||
} else config = await postgresConfig();
|
||||
if (action === 'audit') {
|
||||
const market = await PostgresCustody.open(config, { feeBps: 250, card: () => undefined });
|
||||
try { console.log(JSON.stringify(await market.audit())); } finally { await market.close(); }
|
||||
@@ -110,6 +144,16 @@ try {
|
||||
await grantPilotMoneroObserverRuntime(pool, argument ?? '');
|
||||
console.log('Pilot Monero observation-only role granted; no address allocation, credit, withdrawal, or public enrollment privileges.');
|
||||
}
|
||||
if (action === 'grant-pilot-monero-review-runtime') {
|
||||
if (!IS_PILOT || process.env.WIKIDECK_PILOT_MODE !== 'private-mock-only' ||
|
||||
process.env.WIKIDECK_PILOT_CUSTODY_OPERATIONS !== 'read-only-pilot-review-role-only' || extraArgument) {
|
||||
throw new Error('Pilot review role grant requires the private pilot profile, read-only-role acknowledgement, and one role name');
|
||||
}
|
||||
const identity = await pool.query('SELECT 1 FROM wk_custody.pilot_custody_identity WHERE singleton=1');
|
||||
if (!identity.rowCount) throw new Error('Initialize pilot custody identity before granting review access');
|
||||
await grantPilotMoneroDepositReviewRuntime(pool, argument ?? '');
|
||||
console.log('Pilot deposit review role granted read-only pilot evidence access; financial tables and all writes remain denied.');
|
||||
}
|
||||
if (action === 'grant-runtime') { await grantCustodyRuntime(pool, argument ?? ''); console.log('Runtime grants applied; no credentials printed.'); }
|
||||
if (action === 'grant-monero-observer-runtime') {
|
||||
await grantMoneroObserverRuntime(pool, argument ?? '');
|
||||
@@ -165,6 +209,22 @@ try {
|
||||
console.log(JSON.stringify(await resolveReleasedDepositReorgHold(pool, approval as DepositReorgResolutionApproval, policy)));
|
||||
}
|
||||
}
|
||||
if (pilotReviewActions.includes(action)) {
|
||||
if (!IS_PILOT || process.env.WIKIDECK_PILOT_MODE !== 'private-mock-only' || !argument || !extraArgument ||
|
||||
process.env.WIKIDECK_PILOT_CUSTODY_OPERATIONS !== 'pilot-deposit-review-preparation-only') {
|
||||
throw new Error('Pilot review requires the private pilot profile, preparation-only acknowledgement, wallet generation, and observation ID');
|
||||
}
|
||||
const currentUser = await pool.query('SELECT current_user AS role');
|
||||
if (currentUser.rows[0]?.role !== reviewRole) throw new Error('Pilot deposit review must use the dedicated read-only review role');
|
||||
const subject = await preparePilotMoneroDepositReview(pool, {
|
||||
walletGenerationId: argument,
|
||||
observationId: extraArgument,
|
||||
}, {
|
||||
minimumConfirmations: boundedPilotReviewSetting('WIKIDECK_PILOT_DEPOSIT_REVIEW_MIN_CONFIRMATIONS', 10, 10, 100_000),
|
||||
maximumObservationAgeMs: boundedPilotReviewSetting('WIKIDECK_PILOT_DEPOSIT_REVIEW_MAX_OBSERVATION_AGE_MS', 300_000, 10_000, 15 * 60_000),
|
||||
});
|
||||
console.log(JSON.stringify(subject));
|
||||
}
|
||||
if (action === 'import-sqlite') {
|
||||
if (!argument) throw new Error('Stopped source node DATA_DIR required');
|
||||
const directory = resolve(argument);
|
||||
|
||||
Reference in New Issue
Block a user