@hardkas/localnet 0.5.4-alpha → 0.6.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-DPHHOGGK.js → chunk-6AICYLVR.js} +3 -2
- package/dist/{chunk-GVBX3TPM.js → chunk-M5T6T465.js} +3 -2
- package/dist/index.d.ts +17 -8
- package/dist/index.js +89 -28
- package/dist/{receipts-JSTNZMDD.js → receipts-7RMJMXXG.js} +1 -1
- package/dist/{traces-HDVV77MQ.js → traces-ZUBWSXYB.js} +1 -1
- package/package.json +7 -7
|
@@ -3,8 +3,9 @@ import fs from "fs/promises";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { existsSync } from "fs";
|
|
5
5
|
import { writeFileAtomic } from "@hardkas/core";
|
|
6
|
+
import { deterministicCompare } from "@hardkas/core";
|
|
6
7
|
function getDefaultTracesDir(cwd = process.cwd()) {
|
|
7
|
-
return path.join(cwd, ".hardkas", "
|
|
8
|
+
return path.join(cwd, ".hardkas", "artifacts");
|
|
8
9
|
}
|
|
9
10
|
function getTracePath(txId, cwd) {
|
|
10
11
|
validateTxId(txId);
|
|
@@ -49,7 +50,7 @@ async function listSimulatedTraces(options) {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
return traces.sort((a, b) => b.createdAt
|
|
53
|
+
return traces.sort((a, b) => deterministicCompare(b.createdAt, a.createdAt));
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
export {
|
|
@@ -3,8 +3,9 @@ import fs from "fs/promises";
|
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { existsSync } from "fs";
|
|
5
5
|
import { writeFileAtomic } from "@hardkas/core";
|
|
6
|
+
import { deterministicCompare } from "@hardkas/core";
|
|
6
7
|
function getDefaultReceiptsDir(cwd = process.cwd()) {
|
|
7
|
-
return path.join(cwd, ".hardkas", "
|
|
8
|
+
return path.join(cwd, ".hardkas", "artifacts");
|
|
8
9
|
}
|
|
9
10
|
function getReceiptPath(txId, cwd) {
|
|
10
11
|
validateTxId(txId);
|
|
@@ -49,7 +50,7 @@ async function listSimulatedReceipts(options) {
|
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
|
-
return receipts.sort((a, b) => b.createdAt
|
|
53
|
+
return receipts.sort((a, b) => deterministicCompare(b.createdAt, a.createdAt));
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
export {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as _hardkas_artifacts from '@hardkas/artifacts';
|
|
2
|
-
import { HardkasArtifactBase, Snapshot as Snapshot$1, ARTIFACT_SCHEMAS, TxReceipt
|
|
2
|
+
import { HardkasArtifactBase, Snapshot as Snapshot$1, TxPlan, ARTIFACT_SCHEMAS, TxReceipt } from '@hardkas/artifacts';
|
|
3
3
|
import * as _hardkas_simulator from '@hardkas/simulator';
|
|
4
|
-
import { ExecutionMode, NetworkId } from '@hardkas/core';
|
|
4
|
+
import { ExecutionMode, NetworkId, RuntimeContext } from '@hardkas/core';
|
|
5
5
|
import { KaspaRpcClient } from '@hardkas/kaspa-rpc';
|
|
6
6
|
|
|
7
7
|
interface HardkasAccount {
|
|
8
8
|
readonly name: string;
|
|
9
9
|
readonly address: string;
|
|
10
|
+
readonly evmAddress: string;
|
|
10
11
|
readonly balanceSompi: bigint;
|
|
11
12
|
}
|
|
12
13
|
declare function createDeterministicAccounts(input?: {
|
|
@@ -175,6 +176,15 @@ interface CreateInitialStateOptions {
|
|
|
175
176
|
}
|
|
176
177
|
declare function createInitialLocalnetState(options?: CreateInitialStateOptions): LocalnetState;
|
|
177
178
|
declare function resolveAccountAddressFromState(state: LocalnetState, nameOrAddress: string): string;
|
|
179
|
+
/**
|
|
180
|
+
* Mathematically reconstructs the deterministc localnet state at a specific past DAA score.
|
|
181
|
+
* Annoys UTXOs created after the target DAA and revives UTXOs spent after the target DAA.
|
|
182
|
+
*
|
|
183
|
+
* @param state The current localnet state
|
|
184
|
+
* @param targetDaa The block DAG score to revert to
|
|
185
|
+
* @returns A new immutable localnet state representing the exact state at the target DAA
|
|
186
|
+
*/
|
|
187
|
+
declare function reconstructStateAtDaa(state: LocalnetState, targetDaa: bigint | string): LocalnetState;
|
|
178
188
|
|
|
179
189
|
declare function getDefaultLocalnetDir(cwd?: string): string;
|
|
180
190
|
declare function getDefaultLocalnetStatePath(cwd?: string): string;
|
|
@@ -220,7 +230,7 @@ declare function createLocalnetSnapshot(state: LocalnetState, name?: string): Lo
|
|
|
220
230
|
/**
|
|
221
231
|
* Verifies the integrity of a snapshot.
|
|
222
232
|
*/
|
|
223
|
-
declare function verifySnapshot(snapshot:
|
|
233
|
+
declare function verifySnapshot(snapshot: Snapshot$1): SnapshotVerificationResult;
|
|
224
234
|
/**
|
|
225
235
|
* Restores a snapshot with atomic safety and verification.
|
|
226
236
|
*/
|
|
@@ -239,12 +249,11 @@ declare const DUST_LIMIT_SOMPI = 600n;
|
|
|
239
249
|
/**
|
|
240
250
|
* Applies a simulated payment to the localnet state with atomic safety and validation.
|
|
241
251
|
*/
|
|
242
|
-
declare function applySimulatedPayment(state: LocalnetState, input: SimulatedPaymentInput): SimulationResult;
|
|
252
|
+
declare function applySimulatedPayment(state: LocalnetState, input: SimulatedPaymentInput, ctx: RuntimeContext): SimulationResult;
|
|
243
253
|
/**
|
|
244
254
|
* Executes a pre-built transaction plan against the simulated state.
|
|
245
255
|
*/
|
|
246
|
-
declare function applySimulatedPlan(state: LocalnetState, planArtifact:
|
|
247
|
-
options?: {
|
|
256
|
+
declare function applySimulatedPlan(state: LocalnetState, planArtifact: TxPlan, ctx: RuntimeContext, options?: {
|
|
248
257
|
txId?: string;
|
|
249
258
|
}): SimulationResult;
|
|
250
259
|
|
|
@@ -338,7 +347,7 @@ interface SimulatedReplaySummary {
|
|
|
338
347
|
* Implements an honest replay model that differentiates between
|
|
339
348
|
* reproduced results and unimplemented consensus/bridge features.
|
|
340
349
|
*/
|
|
341
|
-
declare function verifyReplay(state: LocalnetState, originalPlan: TxPlan, originalReceipt: TxReceipt): ReplayVerificationReport;
|
|
350
|
+
declare function verifyReplay(state: LocalnetState, originalPlan: TxPlan, originalReceipt: TxReceipt, ctx: RuntimeContext): ReplayVerificationReport;
|
|
342
351
|
/**
|
|
343
352
|
* Loads receipt and trace for a transaction and produces a summary.
|
|
344
353
|
*/
|
|
@@ -404,4 +413,4 @@ interface ForkOptions {
|
|
|
404
413
|
}
|
|
405
414
|
declare function forkFromNetwork(rpc: KaspaRpcClient, opts: ForkOptions): Promise<LocalnetState>;
|
|
406
415
|
|
|
407
|
-
export { type CreateInitialStateOptions, DUST_LIMIT_SOMPI, type ForkOptions, type FundAddressInput, type HardkasAccount, type HardkasDevnet, type LocalnetAccount, type LocalnetState, type LocalnetUtxo, type ReplayInvariantResult, type ReplayVerificationReport, type SimulatedBlock, type SimulatedDag, SimulatedKaspaChain, type SimulatedPaymentInput, type SimulatedReplaySummary, type SimulatedUtxo, type SimulationResult, type Snapshot, type SnapshotRestoreResult, type SnapshotVerificationResult, type StateTransition, type StoredSimulatedTxReceipt, type StoredSimulatedTxTrace, type StoredTraceEvent, addSimulatedBlock, applySimulatedPayment, applySimulatedPlan, calculateAccountsHash, calculateStateHash, calculateUtxoSetHash, createDeterministicAccounts, createInitialLocalnetState, createLocalnetSnapshot, createSimulatedDag, findBestTip, forkFromNetwork, fundAddress, getAccountBalanceSompi, getAddressBalanceSompi, getDagColoring, getDefaultLocalnetDir, getDefaultLocalnetStatePath, getDefaultReceiptsDir, getDefaultTracesDir, getReceiptPath, getSelectedChain, getSimulatedReplaySummary, getSpendableUtxos, getTracePath, listSimulatedReceipts, listSimulatedTraces, loadLocalnetState, loadOrCreateLocalnetState, loadSimulatedReceipt, loadSimulatedTrace, moveSink, resetLocalnetState, resolveAccountAddress, resolveAccountAddressFromState, resolveConflictsDeterministically, restoreLocalnetSnapshot, saveLocalnetState, saveSimulatedReceipt, saveSimulatedTrace, startSimulatedDevnet, verifyReplay, verifySnapshot };
|
|
416
|
+
export { type CreateInitialStateOptions, DUST_LIMIT_SOMPI, type ForkOptions, type FundAddressInput, type HardkasAccount, type HardkasDevnet, type LocalnetAccount, type LocalnetState, type LocalnetUtxo, type ReplayInvariantResult, type ReplayVerificationReport, type SimulatedBlock, type SimulatedDag, SimulatedKaspaChain, type SimulatedPaymentInput, type SimulatedReplaySummary, type SimulatedUtxo, type SimulationResult, type Snapshot, type SnapshotRestoreResult, type SnapshotVerificationResult, type StateTransition, type StoredSimulatedTxReceipt, type StoredSimulatedTxTrace, type StoredTraceEvent, addSimulatedBlock, applySimulatedPayment, applySimulatedPlan, calculateAccountsHash, calculateStateHash, calculateUtxoSetHash, createDeterministicAccounts, createInitialLocalnetState, createLocalnetSnapshot, createSimulatedDag, findBestTip, forkFromNetwork, fundAddress, getAccountBalanceSompi, getAddressBalanceSompi, getDagColoring, getDefaultLocalnetDir, getDefaultLocalnetStatePath, getDefaultReceiptsDir, getDefaultTracesDir, getReceiptPath, getSelectedChain, getSimulatedReplaySummary, getSpendableUtxos, getTracePath, listSimulatedReceipts, listSimulatedTraces, loadLocalnetState, loadOrCreateLocalnetState, loadSimulatedReceipt, loadSimulatedTrace, moveSink, reconstructStateAtDaa, resetLocalnetState, resolveAccountAddress, resolveAccountAddressFromState, resolveConflictsDeterministically, restoreLocalnetSnapshot, saveLocalnetState, saveSimulatedReceipt, saveSimulatedTrace, startSimulatedDevnet, verifyReplay, verifySnapshot };
|
package/dist/index.js
CHANGED
|
@@ -4,16 +4,28 @@ import {
|
|
|
4
4
|
listSimulatedReceipts,
|
|
5
5
|
loadSimulatedReceipt,
|
|
6
6
|
saveSimulatedReceipt
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-M5T6T465.js";
|
|
8
8
|
import {
|
|
9
9
|
getDefaultTracesDir,
|
|
10
10
|
getTracePath,
|
|
11
11
|
listSimulatedTraces,
|
|
12
12
|
loadSimulatedTrace,
|
|
13
13
|
saveSimulatedTrace
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-6AICYLVR.js";
|
|
15
15
|
|
|
16
16
|
// src/accounts.ts
|
|
17
|
+
var DEFAULT_EVM_ADDRESSES = [
|
|
18
|
+
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
|
|
19
|
+
// alice
|
|
20
|
+
"0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
|
|
21
|
+
// bob
|
|
22
|
+
"0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC",
|
|
23
|
+
// carol
|
|
24
|
+
"0x90F79bf6EB2c4f870365E785982E1f101E93b906",
|
|
25
|
+
// dave
|
|
26
|
+
"0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65"
|
|
27
|
+
// erin
|
|
28
|
+
];
|
|
17
29
|
function createDeterministicAccounts(input) {
|
|
18
30
|
const count = input?.count ?? 5;
|
|
19
31
|
const initialBalanceSompi = input?.initialBalanceSompi ?? 1000n * 100000000n;
|
|
@@ -23,6 +35,7 @@ function createDeterministicAccounts(input) {
|
|
|
23
35
|
return {
|
|
24
36
|
name,
|
|
25
37
|
address: `kaspa:sim_${name}`,
|
|
38
|
+
evmAddress: DEFAULT_EVM_ADDRESSES[index] || `0x000000000000000000000000000000000000000${index}`,
|
|
26
39
|
balanceSompi: initialBalanceSompi
|
|
27
40
|
};
|
|
28
41
|
});
|
|
@@ -162,6 +175,21 @@ function resolveAccountAddressFromState(state, nameOrAddress) {
|
|
|
162
175
|
}
|
|
163
176
|
return nameOrAddress;
|
|
164
177
|
}
|
|
178
|
+
function reconstructStateAtDaa(state, targetDaa) {
|
|
179
|
+
const target = typeof targetDaa === "string" ? BigInt(targetDaa) : targetDaa;
|
|
180
|
+
const reconstructedUtxos = state.utxos.filter((u) => BigInt(u.createdAtDaaScore || "0") <= target).map((u) => {
|
|
181
|
+
if (u.spent && u.spentAtDaaScore && BigInt(u.spentAtDaaScore) > target) {
|
|
182
|
+
const { spentAtDaaScore: _, ...rest } = u;
|
|
183
|
+
return { ...rest, spent: false };
|
|
184
|
+
}
|
|
185
|
+
return u;
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
...state,
|
|
189
|
+
daaScore: target.toString(),
|
|
190
|
+
utxos: reconstructedUtxos
|
|
191
|
+
};
|
|
192
|
+
}
|
|
165
193
|
|
|
166
194
|
// src/store.ts
|
|
167
195
|
import fs from "fs/promises";
|
|
@@ -249,12 +277,13 @@ import {
|
|
|
249
277
|
calculateContentHash,
|
|
250
278
|
sortUtxosByOutpoint
|
|
251
279
|
} from "@hardkas/artifacts";
|
|
280
|
+
import { deterministicCompare } from "@hardkas/core";
|
|
252
281
|
function calculateUtxoSetHash(utxos) {
|
|
253
282
|
const sorted = sortUtxosByOutpoint(utxos);
|
|
254
283
|
return calculateContentHash(sorted);
|
|
255
284
|
}
|
|
256
285
|
function calculateAccountsHash(accounts) {
|
|
257
|
-
const sorted = [...accounts].sort((a, b) => a.address
|
|
286
|
+
const sorted = [...accounts || []].sort((a, b) => deterministicCompare(a.address, b.address));
|
|
258
287
|
return calculateContentHash(sorted);
|
|
259
288
|
}
|
|
260
289
|
function calculateStateHash(state) {
|
|
@@ -270,7 +299,7 @@ function createLocalnetSnapshot(state, name) {
|
|
|
270
299
|
const accountsHash = calculateAccountsHash(state.accounts);
|
|
271
300
|
const utxoSetHash = calculateUtxoSetHash(state.utxos);
|
|
272
301
|
const stateHash = calculateStateHash(state);
|
|
273
|
-
const
|
|
302
|
+
const snapshotDraft = {
|
|
274
303
|
schema: "hardkas.snapshot",
|
|
275
304
|
hardkasVersion: HARDKAS_VERSION2,
|
|
276
305
|
version: ARTIFACT_VERSION,
|
|
@@ -281,9 +310,14 @@ function createLocalnetSnapshot(state, name) {
|
|
|
281
310
|
utxoSetHash,
|
|
282
311
|
stateHash,
|
|
283
312
|
accounts: JSON.parse(JSON.stringify(state.accounts)),
|
|
284
|
-
utxos: JSON.parse(JSON.stringify(sortUtxosByOutpoint(state.utxos)))
|
|
313
|
+
utxos: JSON.parse(JSON.stringify(sortUtxosByOutpoint(state.utxos))),
|
|
314
|
+
networkId: state.networkId,
|
|
315
|
+
mode: state.mode
|
|
316
|
+
};
|
|
317
|
+
const snapshot = {
|
|
318
|
+
...snapshotDraft,
|
|
319
|
+
contentHash: calculateContentHash(snapshotDraft)
|
|
285
320
|
};
|
|
286
|
-
snapshot.contentHash = calculateContentHash(snapshot);
|
|
287
321
|
return {
|
|
288
322
|
...state,
|
|
289
323
|
snapshots: [...state.snapshots || [], snapshot]
|
|
@@ -343,7 +377,9 @@ import { buildPaymentPlan } from "@hardkas/tx-builder";
|
|
|
343
377
|
import {
|
|
344
378
|
createTxPlanArtifact,
|
|
345
379
|
createSimulatedTxReceipt,
|
|
346
|
-
calculateContentHash as calculateContentHash2
|
|
380
|
+
calculateContentHash as calculateContentHash2,
|
|
381
|
+
HARDKAS_VERSION as HARDKAS_VERSION3,
|
|
382
|
+
ARTIFACT_VERSION as ARTIFACT_VERSION2
|
|
347
383
|
} from "@hardkas/artifacts";
|
|
348
384
|
function buildDagContextFromState(state) {
|
|
349
385
|
if (state.dag) {
|
|
@@ -370,12 +406,18 @@ function generateDeterministicTxId(planArtifact, preStateHash, daaScore) {
|
|
|
370
406
|
return `simtx_${hash}`;
|
|
371
407
|
}
|
|
372
408
|
var DUST_LIMIT_SOMPI = 600n;
|
|
373
|
-
function applySimulatedPayment(state, input) {
|
|
409
|
+
function applySimulatedPayment(state, input, ctx) {
|
|
374
410
|
const errors = [];
|
|
375
411
|
const preStateHash = calculateStateHash(state);
|
|
376
412
|
try {
|
|
377
413
|
const fromAddress = resolveAccountAddressFromState(state, input.from);
|
|
414
|
+
if (!fromAddress) {
|
|
415
|
+
throw new Error(`Sender account/address not found: ${input.from}`);
|
|
416
|
+
}
|
|
378
417
|
const toAddress = resolveAccountAddressFromState(state, input.to);
|
|
418
|
+
if (!toAddress) {
|
|
419
|
+
throw new Error(`Recipient account/address not found: ${input.to}`);
|
|
420
|
+
}
|
|
379
421
|
const amountSompi = input.amountSompi;
|
|
380
422
|
const feeRateSompiPerMass = input.feeRateSompiPerMass ?? 1n;
|
|
381
423
|
if (amountSompi <= 0n) {
|
|
@@ -421,7 +463,8 @@ function applySimulatedPayment(state, input) {
|
|
|
421
463
|
from: { input: input.from, address: fromAddress },
|
|
422
464
|
to: { input: input.to, address: toAddress },
|
|
423
465
|
amountSompi,
|
|
424
|
-
plan
|
|
466
|
+
plan,
|
|
467
|
+
ctx
|
|
425
468
|
});
|
|
426
469
|
const nextDaaScore = (BigInt(state.daaScore) + 1n).toString();
|
|
427
470
|
const txId = generateDeterministicTxId(planArtifact, preStateHash, nextDaaScore);
|
|
@@ -462,7 +505,7 @@ function applySimulatedPayment(state, input) {
|
|
|
462
505
|
utxos: nextUtxos
|
|
463
506
|
};
|
|
464
507
|
const postStateHash = calculateStateHash(nextState);
|
|
465
|
-
const receipt = createSimulatedTxReceipt(planArtifact, txId, {
|
|
508
|
+
const receipt = createSimulatedTxReceipt(planArtifact, txId, ctx, {
|
|
466
509
|
spentUtxoIds,
|
|
467
510
|
createdUtxoIds,
|
|
468
511
|
daaScore: nextDaaScore,
|
|
@@ -478,29 +521,37 @@ function applySimulatedPayment(state, input) {
|
|
|
478
521
|
errors
|
|
479
522
|
};
|
|
480
523
|
} catch (error) {
|
|
524
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
481
525
|
const daaScore = state.daaScore || "0";
|
|
482
|
-
const txId = generateDeterministicFailedTxId(preStateHash,
|
|
526
|
+
const txId = generateDeterministicFailedTxId(preStateHash, errorMessage, daaScore);
|
|
483
527
|
const receipt = {
|
|
484
528
|
schema: "hardkas.txReceipt",
|
|
529
|
+
hardkasVersion: HARDKAS_VERSION3,
|
|
530
|
+
version: ARTIFACT_VERSION2,
|
|
485
531
|
status: "failed",
|
|
486
532
|
mode: "simulated",
|
|
533
|
+
networkId: state.networkId,
|
|
487
534
|
txId,
|
|
488
535
|
createdAt: "1970-01-01T00:00:00.000Z",
|
|
489
|
-
errors: [
|
|
536
|
+
errors: [errorMessage],
|
|
490
537
|
preStateHash,
|
|
491
538
|
postStateHash: preStateHash,
|
|
492
|
-
dagContext: buildDagContextFromState(state)
|
|
539
|
+
dagContext: buildDagContextFromState(state),
|
|
540
|
+
from: { address: "" },
|
|
541
|
+
to: { address: "" },
|
|
542
|
+
amountSompi: "0",
|
|
543
|
+
feeSompi: "0"
|
|
493
544
|
};
|
|
494
545
|
return {
|
|
495
546
|
ok: false,
|
|
496
547
|
state,
|
|
497
548
|
// No mutation
|
|
498
549
|
receipt,
|
|
499
|
-
errors: [
|
|
550
|
+
errors: [errorMessage]
|
|
500
551
|
};
|
|
501
552
|
}
|
|
502
553
|
}
|
|
503
|
-
function applySimulatedPlan(state, planArtifact, options) {
|
|
554
|
+
function applySimulatedPlan(state, planArtifact, ctx, options) {
|
|
504
555
|
const errors = [];
|
|
505
556
|
const preStateHash = calculateStateHash(state);
|
|
506
557
|
try {
|
|
@@ -543,7 +594,7 @@ function applySimulatedPlan(state, planArtifact, options) {
|
|
|
543
594
|
}
|
|
544
595
|
const nextState = { ...state, daaScore: nextDaaScore, utxos: nextUtxos };
|
|
545
596
|
const postStateHash = calculateStateHash(nextState);
|
|
546
|
-
const receipt = createSimulatedTxReceipt(planArtifact, txId, {
|
|
597
|
+
const receipt = createSimulatedTxReceipt(planArtifact, txId, ctx, {
|
|
547
598
|
spentUtxoIds,
|
|
548
599
|
createdUtxoIds,
|
|
549
600
|
daaScore: nextDaaScore,
|
|
@@ -553,20 +604,28 @@ function applySimulatedPlan(state, planArtifact, options) {
|
|
|
553
604
|
});
|
|
554
605
|
return { ok: true, state: nextState, receipt, planArtifact, errors };
|
|
555
606
|
} catch (error) {
|
|
607
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
556
608
|
const daaScore = state.daaScore || "0";
|
|
557
|
-
const txId = generateDeterministicFailedTxId(preStateHash,
|
|
609
|
+
const txId = generateDeterministicFailedTxId(preStateHash, errorMessage, daaScore);
|
|
558
610
|
const receipt = {
|
|
559
611
|
schema: "hardkas.txReceipt",
|
|
612
|
+
hardkasVersion: HARDKAS_VERSION3,
|
|
613
|
+
version: ARTIFACT_VERSION2,
|
|
560
614
|
status: "failed",
|
|
561
615
|
mode: "simulated",
|
|
616
|
+
networkId: state.networkId,
|
|
562
617
|
txId,
|
|
563
618
|
createdAt: "1970-01-01T00:00:00.000Z",
|
|
564
|
-
errors: [
|
|
619
|
+
errors: [errorMessage],
|
|
565
620
|
preStateHash,
|
|
566
621
|
postStateHash: preStateHash,
|
|
567
|
-
dagContext: buildDagContextFromState(state)
|
|
622
|
+
dagContext: buildDagContextFromState(state),
|
|
623
|
+
from: { address: "" },
|
|
624
|
+
to: { address: "" },
|
|
625
|
+
amountSompi: "0",
|
|
626
|
+
feeSompi: "0"
|
|
568
627
|
};
|
|
569
|
-
return { ok: false, state, receipt, errors: [
|
|
628
|
+
return { ok: false, state, receipt, errors: [errorMessage] };
|
|
570
629
|
}
|
|
571
630
|
}
|
|
572
631
|
|
|
@@ -576,7 +635,7 @@ import {
|
|
|
576
635
|
diffArtifacts
|
|
577
636
|
} from "@hardkas/artifacts";
|
|
578
637
|
import { coreEvents } from "@hardkas/core";
|
|
579
|
-
function verifyReplay(state, originalPlan, originalReceipt) {
|
|
638
|
+
function verifyReplay(state, originalPlan, originalReceipt, ctx) {
|
|
580
639
|
const errors = [];
|
|
581
640
|
const reportDivergences = [];
|
|
582
641
|
const currentPlanHash = calculateContentHash3(originalPlan);
|
|
@@ -607,7 +666,7 @@ function verifyReplay(state, originalPlan, originalReceipt) {
|
|
|
607
666
|
severity: "warning"
|
|
608
667
|
});
|
|
609
668
|
}
|
|
610
|
-
const result = applySimulatedPlan(state, originalPlan, { txId: originalReceipt.txId });
|
|
669
|
+
const result = applySimulatedPlan(state, originalPlan, ctx, { txId: originalReceipt.txId });
|
|
611
670
|
const replayReceipt = result.receipt;
|
|
612
671
|
const diff = diffArtifacts(originalReceipt, replayReceipt);
|
|
613
672
|
if (!diff.identical) {
|
|
@@ -654,8 +713,8 @@ function verifyReplay(state, originalPlan, originalReceipt) {
|
|
|
654
713
|
};
|
|
655
714
|
}
|
|
656
715
|
async function getSimulatedReplaySummary(txId, options = {}) {
|
|
657
|
-
const { loadSimulatedReceipt: loadSimulatedReceipt2 } = await import("./receipts-
|
|
658
|
-
const { loadSimulatedTrace: loadSimulatedTrace2 } = await import("./traces-
|
|
716
|
+
const { loadSimulatedReceipt: loadSimulatedReceipt2 } = await import("./receipts-7RMJMXXG.js");
|
|
717
|
+
const { loadSimulatedTrace: loadSimulatedTrace2 } = await import("./traces-ZUBWSXYB.js");
|
|
659
718
|
const receipt = await loadSimulatedReceipt2(txId, options);
|
|
660
719
|
const trace = await loadSimulatedTrace2(txId, options);
|
|
661
720
|
if (!receipt || !trace) {
|
|
@@ -683,6 +742,7 @@ import {
|
|
|
683
742
|
findSelectedParent,
|
|
684
743
|
GENESIS_HASH as SIM_GENESIS_HASH
|
|
685
744
|
} from "@hardkas/simulator";
|
|
745
|
+
import { deterministicCompare as deterministicCompare2 } from "@hardkas/core";
|
|
686
746
|
var dagIdMaps = /* @__PURE__ */ new WeakMap();
|
|
687
747
|
var dagReverseIdMaps = /* @__PURE__ */ new WeakMap();
|
|
688
748
|
function getIdMap(dag) {
|
|
@@ -810,7 +870,7 @@ function moveSink(dag, newSinkId, txProvider) {
|
|
|
810
870
|
const daaA = BigInt(a.daaScore);
|
|
811
871
|
const daaB = BigInt(b.daaScore);
|
|
812
872
|
if (daaA !== daaB) return daaA < daaB ? -1 : 1;
|
|
813
|
-
return a.id
|
|
873
|
+
return deterministicCompare2(a.id, b.id);
|
|
814
874
|
});
|
|
815
875
|
const acceptedTxIds = [];
|
|
816
876
|
const displacedTxIds = [];
|
|
@@ -918,7 +978,7 @@ function resolveConflictsDeterministically(txs, dag) {
|
|
|
918
978
|
const blockA = dag.blocks[a.blockId];
|
|
919
979
|
const blockB = dag.blocks[b.blockId];
|
|
920
980
|
if (!blockA || !blockB) {
|
|
921
|
-
if (!blockA && !blockB) return a.txId
|
|
981
|
+
if (!blockA && !blockB) return deterministicCompare2(a.txId, b.txId);
|
|
922
982
|
return !blockA ? 1 : -1;
|
|
923
983
|
}
|
|
924
984
|
const inPathA = dag.selectedPathToSink.includes(a.blockId);
|
|
@@ -933,8 +993,8 @@ function resolveConflictsDeterministically(txs, dag) {
|
|
|
933
993
|
const daaA = BigInt(blockA.daaScore);
|
|
934
994
|
const daaB = BigInt(blockB.daaScore);
|
|
935
995
|
if (daaA !== daaB) return daaA < daaB ? -1 : 1;
|
|
936
|
-
if (a.blockId !== b.blockId) return a.blockId
|
|
937
|
-
return a.txId
|
|
996
|
+
if (a.blockId !== b.blockId) return deterministicCompare2(a.blockId, b.blockId);
|
|
997
|
+
return deterministicCompare2(a.txId, b.txId);
|
|
938
998
|
});
|
|
939
999
|
const accepted = [];
|
|
940
1000
|
const displaced = [];
|
|
@@ -1080,6 +1140,7 @@ export {
|
|
|
1080
1140
|
loadSimulatedReceipt,
|
|
1081
1141
|
loadSimulatedTrace,
|
|
1082
1142
|
moveSink,
|
|
1143
|
+
reconstructStateAtDaa,
|
|
1083
1144
|
resetLocalnetState,
|
|
1084
1145
|
resolveAccountAddress,
|
|
1085
1146
|
resolveAccountAddressFromState,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hardkas/localnet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-alpha",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
".": "./dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@hardkas/artifacts": "0.
|
|
12
|
-
"@hardkas/core": "0.
|
|
13
|
-
"@hardkas/
|
|
14
|
-
"@hardkas/
|
|
15
|
-
"@hardkas/
|
|
16
|
-
"@hardkas/
|
|
11
|
+
"@hardkas/artifacts": "0.6.0-alpha",
|
|
12
|
+
"@hardkas/core": "0.6.0-alpha",
|
|
13
|
+
"@hardkas/query": "0.6.0-alpha",
|
|
14
|
+
"@hardkas/simulator": "0.6.0-alpha",
|
|
15
|
+
"@hardkas/kaspa-rpc": "0.6.0-alpha",
|
|
16
|
+
"@hardkas/tx-builder": "0.6.0-alpha"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"fast-check": "^4.8.0",
|