@typeberry/lib 0.8.4 → 0.9.0-59ce083
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/package.json +6 -4
- package/packages/configs/index.d.ts +30 -1
- package/packages/configs/index.d.ts.map +1 -1
- package/packages/configs/index.js +4 -2
- package/packages/configs/typeberry-dev-full.json +29 -0
- package/packages/core/bytes/bytes.d.ts +1 -0
- package/packages/core/bytes/bytes.d.ts.map +1 -1
- package/packages/core/bytes/bytes.js +8 -0
- package/packages/core/utils/debug.d.ts +4 -2
- package/packages/core/utils/debug.d.ts.map +1 -1
- package/packages/core/utils/debug.js +18 -13
- package/packages/core/utils/debug.test.js +12 -6
- package/packages/core/utils/index.d.ts +1 -0
- package/packages/core/utils/index.d.ts.map +1 -1
- package/packages/core/utils/index.js +1 -0
- package/packages/core/utils/shutdown.d.ts +18 -0
- package/packages/core/utils/shutdown.d.ts.map +1 -0
- package/packages/core/utils/shutdown.js +3 -0
- package/packages/core/utils/shutdown.node.d.ts +5 -0
- package/packages/core/utils/shutdown.node.d.ts.map +1 -0
- package/packages/core/utils/shutdown.node.js +76 -0
- package/packages/core/utils/shutdown.test.d.ts +2 -0
- package/packages/core/utils/shutdown.test.d.ts.map +1 -0
- package/packages/core/utils/shutdown.test.js +164 -0
- package/packages/extensions/ipc/server.d.ts.map +1 -1
- package/packages/extensions/ipc/server.js +7 -0
- package/packages/jam/config-node/node-config.d.ts +2 -1
- package/packages/jam/config-node/node-config.d.ts.map +1 -1
- package/packages/jam/config-node/node-config.js +8 -3
- package/packages/jam/config-node/node-config.test.js +3 -3
- package/packages/jam/database-fjall/hybrid-states.d.ts +82 -0
- package/packages/jam/database-fjall/hybrid-states.d.ts.map +1 -0
- package/packages/jam/database-fjall/hybrid-states.js +169 -0
- package/packages/jam/database-fjall/hybrid-states.test.d.ts +2 -0
- package/packages/jam/database-fjall/hybrid-states.test.d.ts.map +1 -0
- package/packages/jam/database-fjall/hybrid-states.test.js +113 -0
- package/packages/jam/database-fjall/index.d.ts +3 -0
- package/packages/jam/database-fjall/index.d.ts.map +1 -0
- package/packages/jam/database-fjall/index.js +2 -0
- package/packages/jam/database-fjall/root.d.ts +58 -0
- package/packages/jam/database-fjall/root.d.ts.map +1 -0
- package/packages/jam/database-fjall/root.js +89 -0
- package/packages/jam/jamnp-s/tasks/ticket-distribution.d.ts +18 -10
- package/packages/jam/jamnp-s/tasks/ticket-distribution.d.ts.map +1 -1
- package/packages/jam/jamnp-s/tasks/ticket-distribution.js +44 -68
- package/packages/jam/jamnp-s/tasks/ticket-distribution.test.js +30 -8
- package/packages/jam/node/main-fuzz.d.ts +4 -1
- package/packages/jam/node/main-fuzz.d.ts.map +1 -1
- package/packages/jam/node/main-fuzz.js +142 -55
- package/packages/jam/node/main-importer.d.ts +13 -3
- package/packages/jam/node/main-importer.d.ts.map +1 -1
- package/packages/jam/node/main-importer.js +5 -3
- package/packages/jam/safrole/bandersnatch-vrf.d.ts +24 -4
- package/packages/jam/safrole/bandersnatch-vrf.d.ts.map +1 -1
- package/packages/jam/safrole/bandersnatch-vrf.js +63 -26
- package/packages/jam/safrole/bandersnatch-vrf.test.js +12 -9
- package/packages/jam/safrole/bandersnatch-wasm.d.ts +10 -0
- package/packages/jam/safrole/bandersnatch-wasm.d.ts.map +1 -1
- package/packages/jam/safrole/bandersnatch-wasm.js +12 -0
- package/packages/jam/safrole/safrole.js +5 -5
- package/packages/jam/safrole/safrole.test.js +13 -13
- package/packages/jam/ticket-pool/index.d.ts +4 -0
- package/packages/jam/ticket-pool/index.d.ts.map +1 -0
- package/packages/jam/ticket-pool/index.js +3 -0
- package/packages/jam/ticket-pool/pending-ticket-pool.d.ts +30 -0
- package/packages/jam/ticket-pool/pending-ticket-pool.d.ts.map +1 -0
- package/packages/jam/ticket-pool/pending-ticket-pool.js +56 -0
- package/packages/jam/ticket-pool/pending-ticket-pool.test.d.ts +2 -0
- package/packages/jam/ticket-pool/pending-ticket-pool.test.d.ts.map +1 -0
- package/packages/jam/ticket-pool/pending-ticket-pool.test.js +67 -0
- package/packages/jam/ticket-pool/ticket-validator.d.ts +47 -0
- package/packages/jam/ticket-pool/ticket-validator.d.ts.map +1 -0
- package/packages/jam/ticket-pool/ticket-validator.js +34 -0
- package/packages/jam/ticket-pool/ticket-validator.test.d.ts +2 -0
- package/packages/jam/ticket-pool/ticket-validator.test.d.ts.map +1 -0
- package/packages/jam/ticket-pool/ticket-validator.test.js +35 -0
- package/packages/jam/ticket-pool/verified-ticket-pool.d.ts +26 -0
- package/packages/jam/ticket-pool/verified-ticket-pool.d.ts.map +1 -0
- package/packages/jam/ticket-pool/verified-ticket-pool.js +41 -0
- package/packages/jam/ticket-pool/verified-ticket-pool.test.d.ts +2 -0
- package/packages/jam/ticket-pool/verified-ticket-pool.test.d.ts.map +1 -0
- package/packages/jam/ticket-pool/verified-ticket-pool.test.js +54 -0
- package/packages/workers/api-node/config.d.ts +21 -6
- package/packages/workers/api-node/config.d.ts.map +1 -1
- package/packages/workers/api-node/config.js +26 -19
- package/packages/workers/api-node/config.test.js +38 -1
- package/packages/workers/block-authorship/{generator.d.ts → block-generator.d.ts} +5 -5
- package/packages/workers/block-authorship/block-generator.d.ts.map +1 -0
- package/packages/workers/block-authorship/{generator.js → block-generator.js} +3 -3
- package/packages/workers/block-authorship/block-generator.test.d.ts +2 -0
- package/packages/workers/block-authorship/block-generator.test.d.ts.map +1 -0
- package/packages/workers/block-authorship/{generator.test.js → block-generator.test.js} +8 -8
- package/packages/workers/block-authorship/epoch-authoring-slots.d.ts +35 -0
- package/packages/workers/block-authorship/epoch-authoring-slots.d.ts.map +1 -0
- package/packages/workers/block-authorship/epoch-authoring-slots.js +86 -0
- package/packages/workers/block-authorship/epoch-tracker.d.ts +29 -0
- package/packages/workers/block-authorship/epoch-tracker.d.ts.map +1 -0
- package/packages/workers/block-authorship/epoch-tracker.js +80 -0
- package/packages/workers/block-authorship/index.d.ts.map +1 -1
- package/packages/workers/block-authorship/index.js +1 -1
- package/packages/workers/block-authorship/main.d.ts +3 -0
- package/packages/workers/block-authorship/main.d.ts.map +1 -1
- package/packages/workers/block-authorship/main.js +197 -315
- package/packages/workers/block-authorship/ticket-generator/bootstrap-main.d.ts +2 -0
- package/packages/workers/block-authorship/ticket-generator/bootstrap-main.d.ts.map +1 -0
- package/packages/workers/block-authorship/ticket-generator/bootstrap-main.js +23 -0
- package/packages/workers/block-authorship/ticket-generator/index.d.ts +16 -0
- package/packages/workers/block-authorship/ticket-generator/index.d.ts.map +1 -0
- package/packages/workers/block-authorship/ticket-generator/index.js +62 -0
- package/packages/workers/block-authorship/ticket-generator/protocol.d.ts +50 -0
- package/packages/workers/block-authorship/ticket-generator/protocol.d.ts.map +1 -0
- package/packages/workers/block-authorship/ticket-generator/protocol.js +54 -0
- package/packages/workers/block-authorship/{ticket-generator.d.ts → ticket-generator/ticket-generator.d.ts} +4 -0
- package/packages/workers/block-authorship/ticket-generator/ticket-generator.d.ts.map +1 -0
- package/packages/workers/block-authorship/{ticket-generator.js → ticket-generator/ticket-generator.js} +19 -9
- package/packages/workers/block-authorship/ticket-generator/ticket-generator.test.d.ts.map +1 -0
- package/packages/workers/block-authorship/{ticket-generator.test.js → ticket-generator/ticket-generator.test.js} +13 -9
- package/packages/workers/block-authorship/ticket-generator/worker-pool.d.ts +36 -0
- package/packages/workers/block-authorship/ticket-generator/worker-pool.d.ts.map +1 -0
- package/packages/workers/block-authorship/ticket-generator/worker-pool.js +111 -0
- package/packages/workers/block-authorship/ticket-validator.d.ts +31 -0
- package/packages/workers/block-authorship/ticket-validator.d.ts.map +1 -0
- package/packages/workers/block-authorship/ticket-validator.js +59 -0
- package/packages/workers/comms-authorship-network/protocol.d.ts +14 -4
- package/packages/workers/comms-authorship-network/protocol.d.ts.map +1 -1
- package/packages/workers/comms-authorship-network/protocol.js +12 -6
- package/packages/workers/comms-authorship-network/tickets-message.d.ts +0 -14
- package/packages/workers/comms-authorship-network/tickets-message.d.ts.map +1 -1
- package/packages/workers/comms-authorship-network/tickets-message.js +0 -17
- package/packages/workers/importer/importer.d.ts +2 -2
- package/packages/workers/importer/importer.d.ts.map +1 -1
- package/packages/workers/importer/importer.js +5 -5
- package/packages/workers/importer/stats.d.ts +1 -3
- package/packages/workers/importer/stats.d.ts.map +1 -1
- package/packages/workers/importer/stats.js +12 -12
- package/packages/workers/jam-network/main.d.ts.map +1 -1
- package/packages/workers/jam-network/main.js +25 -4
- package/packages/workers/block-authorship/generator.d.ts.map +0 -1
- package/packages/workers/block-authorship/generator.test.d.ts +0 -2
- package/packages/workers/block-authorship/generator.test.d.ts.map +0 -1
- package/packages/workers/block-authorship/ticket-generator.d.ts.map +0 -1
- package/packages/workers/block-authorship/ticket-generator.test.d.ts.map +0 -1
- /package/packages/configs/{typeberry-dev.json → typeberry-dev-tiny.json} +0 -0
- /package/packages/workers/block-authorship/{ticket-generator.test.d.ts → ticket-generator/ticket-generator.test.d.ts} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Logger } from "#@typeberry/logger";
|
|
2
|
+
import { DenyTicketsValidator, PendingTicketPool } from "#@typeberry/ticket-pool";
|
|
2
3
|
import { OK } from "#@typeberry/utils";
|
|
3
4
|
import { ce131 } from "../protocol/index.js";
|
|
4
5
|
const logger = Logger.new(import.meta.filename, "net:tickets");
|
|
@@ -12,6 +13,11 @@ const TICKET_AUX = {
|
|
|
12
13
|
* Uses CE-132 (proxy-to-all) for direct broadcast to all peers.
|
|
13
14
|
* Implements a maintain pattern similar to SyncTask: tickets are collected
|
|
14
15
|
* and periodically distributed to peers that haven't received them yet.
|
|
16
|
+
*
|
|
17
|
+
* Incoming tickets from peers are first run through a {@link TicketValidator};
|
|
18
|
+
* only validated tickets are added to the redistribution pool. The default
|
|
19
|
+
* validator denies everything, so callers must wire a real one via
|
|
20
|
+
* {@link setTicketValidator} before any networked ticket can be redistributed.
|
|
15
21
|
*/
|
|
16
22
|
export class TicketDistributionTask {
|
|
17
23
|
streamManager;
|
|
@@ -26,10 +32,8 @@ export class TicketDistributionTask {
|
|
|
26
32
|
streamManager.registerOutgoingHandlers(ce131.ClientHandler.new(chainSpec, ce131.STREAM_KIND_PROXY_TO_ALL));
|
|
27
33
|
return task;
|
|
28
34
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
/** Current epoch being tracked (cleared when epoch changes) */
|
|
32
|
-
currentEpoch = null;
|
|
35
|
+
pool = new PendingTicketPool();
|
|
36
|
+
validator = new DenyTicketsValidator();
|
|
33
37
|
constructor(streamManager, connections) {
|
|
34
38
|
this.streamManager = streamManager;
|
|
35
39
|
this.connections = connections;
|
|
@@ -38,14 +42,13 @@ export class TicketDistributionTask {
|
|
|
38
42
|
* Should be called periodically to distribute pending tickets to connected peers.
|
|
39
43
|
*/
|
|
40
44
|
maintainDistribution() {
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
const currentEpoch = this.pool.currentEpoch;
|
|
46
|
+
if (currentEpoch === null) {
|
|
47
|
+
return;
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
for (let ticketIdx = 0; ticketIdx < this.pendingTickets.length; ticketIdx++) {
|
|
48
|
-
const { epochIndex, ticket } = this.pendingTickets[ticketIdx];
|
|
49
|
+
const tickets = this.pool.getTickets();
|
|
50
|
+
for (let ticketIdx = 0; ticketIdx < tickets.length; ticketIdx++) {
|
|
51
|
+
const { epochIndex, ticket } = tickets[ticketIdx];
|
|
49
52
|
// Try to send to each connected peer
|
|
50
53
|
for (const peerInfo of this.connections.getConnectedPeers()) {
|
|
51
54
|
this.connections.withAuxData(peerInfo.peerId, TICKET_AUX, (maybeAux) => {
|
|
@@ -77,72 +80,45 @@ export class TicketDistributionTask {
|
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
/**
|
|
80
|
-
* Add a ticket to the
|
|
83
|
+
* Add a ticket to the redistribution pool.
|
|
81
84
|
* Clears pending tickets when epoch changes.
|
|
82
85
|
* Deduplicates tickets based on signature.
|
|
83
86
|
*/
|
|
84
87
|
addTicket(epochIndex, ticket) {
|
|
85
|
-
|
|
86
|
-
// after the epoch has already advanced — accepting it would roll back currentEpoch).
|
|
87
|
-
if (this.currentEpoch !== null && epochIndex < this.currentEpoch) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
// Epoch advanced — clear old tickets
|
|
91
|
-
if (this.currentEpoch !== null && epochIndex > this.currentEpoch) {
|
|
92
|
-
logger.log `[addTicket] Epoch changed from ${this.currentEpoch} to ${epochIndex}, clearing ${this.pendingTickets.length} old tickets`;
|
|
93
|
-
this.pendingTickets = [];
|
|
94
|
-
// Note: We don't need to clear aux data for all peers here.
|
|
95
|
-
// The aux data contains the epoch, so maintainDistribution will lazily
|
|
96
|
-
// reset it when it detects an epoch mismatch. This handles both connected
|
|
97
|
-
// and disconnected peers correctly.
|
|
98
|
-
}
|
|
99
|
-
this.currentEpoch = epochIndex;
|
|
100
|
-
/**
|
|
101
|
-
* Deduplicate: check if a ticket with the same signature already exists
|
|
102
|
-
*
|
|
103
|
-
* Here we are risking "poisoning" the local pendingTickets - i.e:
|
|
104
|
-
* 1. The adversary sees a signature and swaps the ticket attempt to something different.
|
|
105
|
-
* 2. This creates an invalid ticket, but prevents a valid ticket with the same signature from being included and distributed.
|
|
106
|
-
*
|
|
107
|
-
* TODO [MaSi]: The poisoning risk should be fixed during implementation of ticket validation.
|
|
108
|
-
*/
|
|
109
|
-
const isDuplicate = this.pendingTickets.some((pending) => pending.epochIndex === epochIndex && pending.ticket.signature.isEqualTo(ticket.signature));
|
|
110
|
-
if (!isDuplicate) {
|
|
111
|
-
this.pendingTickets.push({ epochIndex, ticket });
|
|
112
|
-
logger.info `[addTicket] Added ticket for epoch ${epochIndex}, total: ${this.pendingTickets.length}`;
|
|
113
|
-
}
|
|
88
|
+
this.pool.addTicket(epochIndex, ticket);
|
|
114
89
|
}
|
|
115
|
-
onTicketReceivedCallback = null;
|
|
116
90
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* This prevents redistribution of invalid tickets (e.g. those with a tampered `attempt` field).
|
|
91
|
+
* Replace the redistribution pool for the given epoch with the supplied tickets.
|
|
92
|
+
* Used when the authorship worker dumps the authoritative pool on an epoch boundary.
|
|
120
93
|
*/
|
|
121
|
-
|
|
122
|
-
this.
|
|
94
|
+
replacePool(epochIndex, tickets) {
|
|
95
|
+
this.pool.replace(epochIndex, tickets);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Register the validator that decides whether tickets received from peers should be
|
|
99
|
+
* accepted (and therefore redistributed). The default is {@link DenyTicketsValidator},
|
|
100
|
+
* so the caller must install a real validator for any peer ticket to make it through.
|
|
101
|
+
*/
|
|
102
|
+
setTicketValidator(validator) {
|
|
103
|
+
this.validator = validator;
|
|
123
104
|
}
|
|
124
105
|
onTicketReceived(epochIndex, ticket) {
|
|
125
106
|
logger.trace `Received ticket for epoch ${epochIndex}, attempt ${ticket.attempt}`;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
this.addTicket(epochIndex, ticket);
|
|
146
|
-
}
|
|
107
|
+
const validator = this.validator;
|
|
108
|
+
// Wrap with Promise.resolve().then() so a synchronous throw inside the validator
|
|
109
|
+
// funnels into the same .catch() as an async rejection.
|
|
110
|
+
Promise.resolve()
|
|
111
|
+
.then(() => validator.validate(epochIndex, [ticket]))
|
|
112
|
+
.then((result) => {
|
|
113
|
+
if (result.isOk) {
|
|
114
|
+
this.addTicket(epochIndex, ticket);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
logger.trace `Dropping ticket for epoch ${epochIndex}: ${result.error}`;
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
.catch((error) => {
|
|
121
|
+
logger.error `Error validating ticket for epoch ${epochIndex}, attempt ${ticket.attempt}: ${error}`;
|
|
122
|
+
});
|
|
147
123
|
}
|
|
148
124
|
}
|
|
@@ -8,7 +8,8 @@ import { tinyChainSpec } from "#@typeberry/config";
|
|
|
8
8
|
import { BANDERSNATCH_PROOF_BYTES } from "#@typeberry/crypto";
|
|
9
9
|
import { Logger } from "#@typeberry/logger";
|
|
10
10
|
import { createTestPeerPair, MockNetwork } from "#@typeberry/networking/testing.js";
|
|
11
|
-
import {
|
|
11
|
+
import { AcceptTicketsValidator, ValidationError } from "#@typeberry/ticket-pool";
|
|
12
|
+
import { OK, Result } from "#@typeberry/utils";
|
|
12
13
|
import { Connections } from "../peers.js";
|
|
13
14
|
import { StreamManager } from "../stream-manager.js";
|
|
14
15
|
import { TicketDistributionTask } from "./ticket-distribution.js";
|
|
@@ -34,6 +35,9 @@ describe("TicketDistributionTask", () => {
|
|
|
34
35
|
const receivedTickets = [];
|
|
35
36
|
// Use real TicketDistributionTask
|
|
36
37
|
const ticketTask = TicketDistributionTask.start(streamManager, connections, tinyChainSpec);
|
|
38
|
+
// Default validator accepts every ticket so the test asserts purely on distribution
|
|
39
|
+
// behaviour. Tests that exercise the rejection path overwrite this.
|
|
40
|
+
ticketTask.setTicketValidator(new AcceptTicketsValidator());
|
|
37
41
|
// Intercept received tickets by wrapping onTicketReceived behavior
|
|
38
42
|
// The task already adds received tickets to pending queue via addTicket,
|
|
39
43
|
// so we can track them by checking the pending queue growth or by
|
|
@@ -217,7 +221,7 @@ describe("TicketDistributionTask", () => {
|
|
|
217
221
|
assert.strictEqual(peer2.receivedTickets.length, 1);
|
|
218
222
|
assert.deepStrictEqual(peer2.receivedTickets[0].ticket, ticket);
|
|
219
223
|
});
|
|
220
|
-
it("should NOT redistribute ticket if
|
|
224
|
+
it("should NOT redistribute ticket if validator rejects", async () => {
|
|
221
225
|
const self = await init("self");
|
|
222
226
|
const peer1 = await init("peer1");
|
|
223
227
|
const peer2 = await init("peer2");
|
|
@@ -225,35 +229,53 @@ describe("TicketDistributionTask", () => {
|
|
|
225
229
|
self.openConnection(peer2);
|
|
226
230
|
await tick();
|
|
227
231
|
// Validation always rejects
|
|
228
|
-
self.ticketTask.
|
|
232
|
+
self.ticketTask.setTicketValidator({
|
|
233
|
+
validate: async () => Result.error(ValidationError.InvalidProof, () => "rejected"),
|
|
234
|
+
});
|
|
229
235
|
const ticket = createTestTicket(0);
|
|
230
236
|
peer1.ticketTask.addTicket(TEST_EPOCH, ticket);
|
|
231
237
|
peer1.ticketTask.maintainDistribution();
|
|
232
238
|
await tick();
|
|
233
|
-
// self.addTicket was NOT called (
|
|
239
|
+
// self.addTicket was NOT called (validator rejected), so nothing to redistribute
|
|
234
240
|
assert.strictEqual(self.receivedTickets.length, 0);
|
|
235
241
|
self.ticketTask.maintainDistribution();
|
|
236
242
|
await tick();
|
|
237
243
|
assert.strictEqual(peer2.receivedTickets.length, 0);
|
|
238
244
|
});
|
|
239
|
-
it("should redistribute ticket if
|
|
245
|
+
it("should redistribute ticket if validator accepts", async () => {
|
|
240
246
|
const self = await init("self");
|
|
241
247
|
const peer1 = await init("peer1");
|
|
242
248
|
const peer2 = await init("peer2");
|
|
243
249
|
self.openConnection(peer1);
|
|
244
250
|
self.openConnection(peer2);
|
|
245
251
|
await tick();
|
|
246
|
-
//
|
|
247
|
-
self.ticketTask.setOnTicketReceived(async () => true);
|
|
252
|
+
// Default init() already wires an AcceptTicketsValidator
|
|
248
253
|
const ticket = createTestTicket(0);
|
|
249
254
|
peer1.ticketTask.addTicket(TEST_EPOCH, ticket);
|
|
250
255
|
peer1.ticketTask.maintainDistribution();
|
|
251
256
|
await tick();
|
|
252
|
-
// self.addTicket WAS called
|
|
257
|
+
// self.addTicket WAS called
|
|
253
258
|
assert.strictEqual(self.receivedTickets.length, 1);
|
|
254
259
|
self.ticketTask.maintainDistribution();
|
|
255
260
|
await tick();
|
|
256
261
|
assert.strictEqual(peer2.receivedTickets.length, 1);
|
|
257
262
|
assert.deepStrictEqual(peer2.receivedTickets[0].ticket, ticket);
|
|
258
263
|
});
|
|
264
|
+
it("replacePool overwrites the redistribution pool", async () => {
|
|
265
|
+
const self = await init("self");
|
|
266
|
+
const peer1 = await init("peer1");
|
|
267
|
+
self.openConnection(peer1);
|
|
268
|
+
await tick();
|
|
269
|
+
// Locally added tickets first
|
|
270
|
+
self.ticketTask.addTicket(TEST_EPOCH, createTestTicket(0));
|
|
271
|
+
self.ticketTask.addTicket(TEST_EPOCH, createTestTicket(1));
|
|
272
|
+
// Pool dump replaces with a different set
|
|
273
|
+
const dump = [createTestTicket(2), createTestTicket(3)];
|
|
274
|
+
self.ticketTask.replacePool(TEST_EPOCH, dump);
|
|
275
|
+
self.ticketTask.maintainDistribution();
|
|
276
|
+
await tick();
|
|
277
|
+
assert.strictEqual(peer1.receivedTickets.length, 2);
|
|
278
|
+
assert.deepStrictEqual(peer1.receivedTickets[0].ticket, dump[0]);
|
|
279
|
+
assert.deepStrictEqual(peer1.receivedTickets[1].ticket, dump[1]);
|
|
280
|
+
});
|
|
259
281
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FuzzVersion } from "#@typeberry/ext-ipc";
|
|
2
2
|
import { v1 as fuzzV1 } from "#@typeberry/fuzz-proto";
|
|
3
|
+
import { type Closer } from "#@typeberry/utils";
|
|
3
4
|
import type { JamConfig } from "./jam-config.js";
|
|
4
5
|
export type FuzzConfig = {
|
|
5
6
|
version: FuzzVersion;
|
|
@@ -24,5 +25,7 @@ export declare function getFuzzDetails(): {
|
|
|
24
25
|
nodeVersion: fuzzV1.Version;
|
|
25
26
|
gpVersion: fuzzV1.Version;
|
|
26
27
|
};
|
|
27
|
-
export declare function mainFuzz(fuzzConfig: FuzzConfig, withRelPath: (v: string) => string): Promise<
|
|
28
|
+
export declare function mainFuzz(fuzzConfig: FuzzConfig, withRelPath: (v: string) => string): Promise<{
|
|
29
|
+
close: Closer;
|
|
30
|
+
}>;
|
|
28
31
|
//# sourceMappingURL=main-fuzz.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main-fuzz.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/node/main-fuzz.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"main-fuzz.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/node/main-fuzz.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIrD,OAAO,EAAE,KAAK,MAAM,EAAoC,MAAM,kBAAkB,CAAC;AAGjF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,EAAE,SAAS,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,uBAAuB,EAAE,OAAO,CAAC;CAClC,CAAC;AAoBF;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CASpF;AAED,iFAAiF;AACjF,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE5D;AAED,wBAAgB,cAAc;;;;EAM7B;AAED,wBAAsB,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAgLrH"}
|
|
@@ -8,12 +8,23 @@ import { v1 as fuzzV1 } from "#@typeberry/fuzz-proto";
|
|
|
8
8
|
import { HASH_SIZE } from "#@typeberry/hash";
|
|
9
9
|
import { Logger } from "#@typeberry/logger";
|
|
10
10
|
import { CURRENT_VERSION, Result, version } from "#@typeberry/utils";
|
|
11
|
-
import { logHostEnvironment } from "#@typeberry/workers-api-node";
|
|
11
|
+
import { FjallValuesSession, logHostEnvironment } from "#@typeberry/workers-api-node";
|
|
12
12
|
import { getChainSpec } from "./common.js";
|
|
13
13
|
import { mainImporter } from "./main-importer.js";
|
|
14
14
|
const logger = Logger.new(import.meta.filename, "fuzztarget");
|
|
15
15
|
/** Dedicated subdirectory under the configured base path that the fuzzer owns and wipes. */
|
|
16
16
|
const FUZZ_DB_SUBDIR = "typeberry-fuzz-db";
|
|
17
|
+
const FUZZ_DB_FJALL = "fjall-hybrid";
|
|
18
|
+
const FUZZ_DB_LMDB = "lmdb-hybrid";
|
|
19
|
+
const FUZZ_DB_OPTIONS = [FUZZ_DB_FJALL, FUZZ_DB_LMDB];
|
|
20
|
+
/** Subdirectory (under the fuzzer's db dir) holding the reused fjall values keyspace. */
|
|
21
|
+
const FUZZ_FJALL_VALUES_SUBDIR = "values-session";
|
|
22
|
+
/**
|
|
23
|
+
* Size of the fjall block-cache for the fuzz session. Values pile up across
|
|
24
|
+
* resets (for fjall we do not wipe between them), so this cache is what keeps
|
|
25
|
+
* the resident memory bounded.
|
|
26
|
+
*/
|
|
27
|
+
const FUZZ_FJALL_CACHE_BYTES = 128 * 1024 * 1024;
|
|
17
28
|
/**
|
|
18
29
|
* Resolve the directory the fuzzer should use for its on-disk database, or
|
|
19
30
|
* `undefined` for an in-memory database. The dedicated `FUZZ_DB_SUBDIR` is
|
|
@@ -50,7 +61,24 @@ export async function mainFuzz(fuzzConfig, withRelPath) {
|
|
|
50
61
|
logHostEnvironment(logger);
|
|
51
62
|
const { jamNodeConfig: config } = fuzzConfig;
|
|
52
63
|
const fuzzDbBase = resolveFuzzDbBase(config.node.databaseBasePath);
|
|
64
|
+
const rawFuzzDb = process.env.JAM_FUZZ_DB?.trim() ?? "";
|
|
65
|
+
// Using experimental fjall-hybrid by default, with an option to test lmdb as well.
|
|
66
|
+
const hybridStateBackend = rawFuzzDb === "" ? FUZZ_DB_FJALL : rawFuzzDb;
|
|
67
|
+
if (!isValidStateBackend(hybridStateBackend)) {
|
|
68
|
+
throw new Error(`JAM_FUZZ_DB must be one of: ${FUZZ_DB_OPTIONS} (got: "${rawFuzzDb}").`);
|
|
69
|
+
}
|
|
70
|
+
if (fuzzDbBase !== undefined) {
|
|
71
|
+
logger.info `🗄️ Fuzz persistent backend: ${hybridStateBackend}.`;
|
|
72
|
+
}
|
|
53
73
|
let runningNode = null;
|
|
74
|
+
// The fjall values keyspace is opened once per fuzz session and reused on
|
|
75
|
+
// every reset, because opening it is the slow part. Only the in-memory blocks
|
|
76
|
+
// and leaf sets are rebuilt for each vector. fjall-hybrid only.
|
|
77
|
+
let fjallSession = null;
|
|
78
|
+
// Set when close() starts. Guards resetState so a fuzz command arriving
|
|
79
|
+
// mid-shutdown can't build a fresh node that close() then orphans.
|
|
80
|
+
let isClosing = false;
|
|
81
|
+
let activeReset = null;
|
|
54
82
|
const chainSpec = getChainSpec(config.node.flavor);
|
|
55
83
|
const closeFuzzTarget = startFuzzTarget(fuzzConfig.version, fuzzConfig.socket, {
|
|
56
84
|
...getFuzzDetails(),
|
|
@@ -74,65 +102,124 @@ export async function mainFuzz(fuzzConfig, withRelPath) {
|
|
|
74
102
|
}
|
|
75
103
|
return runningNode.getStateEntries(hash);
|
|
76
104
|
},
|
|
77
|
-
resetState:
|
|
105
|
+
resetState: (header, state, ancestry) => {
|
|
106
|
+
const reset = (async () => {
|
|
107
|
+
if (isClosing) {
|
|
108
|
+
return Bytes.zero(HASH_SIZE).asOpaque();
|
|
109
|
+
}
|
|
110
|
+
if (runningNode !== null) {
|
|
111
|
+
const finish = runningNode.close();
|
|
112
|
+
runningNode = null;
|
|
113
|
+
await finish;
|
|
114
|
+
}
|
|
115
|
+
const buildNode = (databaseBasePath) => {
|
|
116
|
+
const isPersistent = databaseBasePath !== undefined;
|
|
117
|
+
return mainImporter({
|
|
118
|
+
...config,
|
|
119
|
+
node: {
|
|
120
|
+
...config.node,
|
|
121
|
+
databaseBasePath,
|
|
122
|
+
chainSpec: {
|
|
123
|
+
...config.node.chainSpec,
|
|
124
|
+
genesisHeader: Encoder.encodeObject(Header.Codec, header, chainSpec),
|
|
125
|
+
genesisState: new Map(state),
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
ancestry,
|
|
129
|
+
network: null,
|
|
130
|
+
}, withRelPath, {
|
|
131
|
+
initGenesisFromAncestry: fuzzConfig.initGenesisFromAncestry,
|
|
132
|
+
// Hybrid keeps leaf sets in RAM, so they must be windowed exactly
|
|
133
|
+
// like the in-memory backend; only the large values live on disk.
|
|
134
|
+
dummyFinalityDepth: 20,
|
|
135
|
+
pruneBlocks: true,
|
|
136
|
+
// The on-disk fuzz db is throwaway (we wipe it), so open it ephemeral and
|
|
137
|
+
// skip the fsync, we do not need durability here. On full spec ephemeral
|
|
138
|
+
// also turns on compression further down, so the big values do not grow the
|
|
139
|
+
// db too much. Tiny stays uncompressed, its db is small and speed matters more.
|
|
140
|
+
ephemeral: isPersistent,
|
|
141
|
+
stateBackend: isPersistent ? hybridStateBackend : "lmdb",
|
|
142
|
+
// Reuse the session keyspace (fjall-hybrid only, other backends
|
|
143
|
+
// ignore it). Nothing to pass for the in-memory fallback.
|
|
144
|
+
sharedFjallSession: isPersistent ? (fjallSession ?? undefined) : undefined,
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
if (fuzzDbBase !== undefined) {
|
|
148
|
+
try {
|
|
149
|
+
if (hybridStateBackend === FUZZ_DB_FJALL) {
|
|
150
|
+
// fjall-hybrid: open the values keyspace once and reuse it on every
|
|
151
|
+
// reset. The values partition is content-addressed and immutable, so
|
|
152
|
+
// it is fine that values pile up across resets, the unreferenced ones
|
|
153
|
+
// just sit there. `initializeDatabase` decides whether the db is
|
|
154
|
+
// already initialized from the in-memory blocks, which we rebuild on
|
|
155
|
+
// every reset, not from the values store, so reusing it does not
|
|
156
|
+
// resume the previous run.
|
|
157
|
+
if (fjallSession === null) {
|
|
158
|
+
// Start from a clean slate once, then keep the keyspace open.
|
|
159
|
+
await wipeFuzzDb(fuzzDbBase);
|
|
160
|
+
fjallSession = await FjallValuesSession.open(`${withRelPath(fuzzDbBase)}/${FUZZ_FJALL_VALUES_SUBDIR}`, {
|
|
161
|
+
ephemeral: true,
|
|
162
|
+
cacheSizeBytes: FUZZ_FJALL_CACHE_BYTES,
|
|
163
|
+
});
|
|
164
|
+
logger.info `🗄️ Opened reusable fjall values session at ${withRelPath(fuzzDbBase)}/${FUZZ_FJALL_VALUES_SUBDIR}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// lmdb-hybrid: keep the old behaviour, wipe and reopen on every
|
|
169
|
+
// reset. A fresh db each reset makes `initializeDatabase` set up
|
|
170
|
+
// genesis again instead of resuming the previous run.
|
|
171
|
+
await wipeFuzzDb(fuzzDbBase);
|
|
172
|
+
}
|
|
173
|
+
runningNode = await buildNode(fuzzDbBase);
|
|
174
|
+
return await runningNode.getBestStateRootHash();
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
// A partially-opened db may leak on failure; acceptable for this degraded fallback (proper cleanup belongs in mainImporter).
|
|
178
|
+
logger.warn `Failed to open persistent fuzz db at ${fuzzDbBase}, falling back to in-memory: ${e}`;
|
|
179
|
+
runningNode = null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
runningNode = await buildNode(undefined);
|
|
183
|
+
return await runningNode.getBestStateRootHash();
|
|
184
|
+
})();
|
|
185
|
+
activeReset = reset;
|
|
186
|
+
const clearActiveReset = () => {
|
|
187
|
+
if (activeReset === reset) {
|
|
188
|
+
activeReset = null;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
reset.then(clearActiveReset, clearActiveReset);
|
|
192
|
+
return reset;
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
close: async () => {
|
|
197
|
+
isClosing = true;
|
|
198
|
+
// Stop accepting connections + unlink the socket.
|
|
199
|
+
closeFuzzTarget();
|
|
200
|
+
// Drain the active session (flush + close DB). Swallow errors so a
|
|
201
|
+
// failing close still lets the process exit 0; the db is wiped next.
|
|
202
|
+
// The node references the shared fjall session, so it must close first.
|
|
203
|
+
if (activeReset !== null) {
|
|
204
|
+
await activeReset.catch((e) => logger.error `Error waiting for fuzz reset: ${e}`);
|
|
205
|
+
}
|
|
78
206
|
if (runningNode !== null) {
|
|
79
|
-
const
|
|
207
|
+
const node = runningNode;
|
|
80
208
|
runningNode = null;
|
|
81
|
-
await
|
|
209
|
+
await node.close().catch((e) => logger.error `Error closing fuzz node: ${e}`);
|
|
210
|
+
}
|
|
211
|
+
// Release the reused fjall values keyspace before wiping its files.
|
|
212
|
+
if (fjallSession !== null) {
|
|
213
|
+
const session = fjallSession;
|
|
214
|
+
fjallSession = null;
|
|
215
|
+
await session.close().catch((e) => logger.error `Error closing fjall session: ${e}`);
|
|
82
216
|
}
|
|
83
|
-
const buildNode = (databaseBasePath) => {
|
|
84
|
-
const isPersistent = databaseBasePath !== undefined;
|
|
85
|
-
return mainImporter({
|
|
86
|
-
...config,
|
|
87
|
-
node: {
|
|
88
|
-
...config.node,
|
|
89
|
-
databaseBasePath,
|
|
90
|
-
chainSpec: {
|
|
91
|
-
...config.node.chainSpec,
|
|
92
|
-
genesisHeader: Encoder.encodeObject(Header.Codec, header, chainSpec),
|
|
93
|
-
genesisState: new Map(state),
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
ancestry,
|
|
97
|
-
network: null,
|
|
98
|
-
}, withRelPath, {
|
|
99
|
-
initGenesisFromAncestry: fuzzConfig.initGenesisFromAncestry,
|
|
100
|
-
// Hybrid keeps leaf sets in RAM, so they must be windowed exactly
|
|
101
|
-
// like the in-memory backend; only the large values live on disk.
|
|
102
|
-
dummyFinalityDepth: 20,
|
|
103
|
-
pruneBlocks: true,
|
|
104
|
-
// Long full-spec sessions accumulate a large, never-pruned values db.
|
|
105
|
-
// Syncing lets the OS reclaim dirty mmap pages, and compression (full
|
|
106
|
-
// spec only, where values are big) bounds its on-disk/page-cache size.
|
|
107
|
-
// Tiny stays uncompressed since its db is small and speed matters more.
|
|
108
|
-
ephemeral: isPersistent,
|
|
109
|
-
stateBackend: isPersistent ? "hybrid" : "lmdb",
|
|
110
|
-
});
|
|
111
|
-
};
|
|
112
217
|
if (fuzzDbBase !== undefined) {
|
|
113
|
-
|
|
114
|
-
// so the on-disk db must be empty: otherwise initializeDatabase sees an
|
|
115
|
-
// already-initialized db and silently resumes the previous run's state.
|
|
116
|
-
await wipeFuzzDb(fuzzDbBase);
|
|
117
|
-
try {
|
|
118
|
-
runningNode = await buildNode(fuzzDbBase);
|
|
119
|
-
return await runningNode.getBestStateRootHash();
|
|
120
|
-
}
|
|
121
|
-
catch (e) {
|
|
122
|
-
// A partially-opened db may leak on failure; acceptable for this degraded fallback (proper cleanup belongs in mainImporter).
|
|
123
|
-
logger.warn `Failed to open persistent fuzz db at ${fuzzDbBase}, falling back to in-memory: ${e}`;
|
|
124
|
-
runningNode = null;
|
|
125
|
-
}
|
|
218
|
+
await wipeFuzzDb(fuzzDbBase).catch(() => { });
|
|
126
219
|
}
|
|
127
|
-
runningNode = await buildNode(undefined);
|
|
128
|
-
return await runningNode.getBestStateRootHash();
|
|
129
220
|
},
|
|
130
|
-
});
|
|
131
|
-
return () => {
|
|
132
|
-
closeFuzzTarget();
|
|
133
|
-
if (fuzzDbBase !== undefined) {
|
|
134
|
-
// best-effort cleanup on shutdown; ignore failures (dir may already be gone).
|
|
135
|
-
wipeFuzzDb(fuzzDbBase).catch(() => { });
|
|
136
|
-
}
|
|
137
221
|
};
|
|
138
222
|
}
|
|
223
|
+
function isValidStateBackend(val) {
|
|
224
|
+
return FUZZ_DB_OPTIONS.indexOf(val) !== -1;
|
|
225
|
+
}
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
+
import { type FjallValuesSession } from "#@typeberry/workers-api-node";
|
|
1
2
|
import type { JamConfig } from "./jam-config.js";
|
|
2
3
|
import type { NodeApi } from "./main.js";
|
|
4
|
+
export type StateBackend = "lmdb" | "lmdb-hybrid" | "fjall-hybrid";
|
|
3
5
|
export type ImporterOptions = {
|
|
4
6
|
initGenesisFromAncestry?: boolean;
|
|
5
7
|
dummyFinalityDepth?: number;
|
|
6
8
|
pruneBlocks?: boolean;
|
|
7
|
-
/** Open the
|
|
9
|
+
/** Open the database without fsync/compression. Only safe for throwaway dbs (e.g. fuzzing). */
|
|
8
10
|
ephemeral?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Persistent backend used when `databaseBasePath` is set. Defaults to full LMDB.
|
|
13
|
+
*/
|
|
14
|
+
stateBackend?: StateBackend;
|
|
15
|
+
/**
|
|
16
|
+
* Reuse an already-open fjall values session instead of opening a fresh
|
|
17
|
+
* keyspace. Only used when `stateBackend === "fjall-hybrid"`. The fuzz target
|
|
18
|
+
* opens one per run and reuses it across resets.
|
|
19
|
+
*/
|
|
20
|
+
sharedFjallSession?: FjallValuesSession;
|
|
11
21
|
};
|
|
12
22
|
export declare function mainImporter(config: JamConfig, withRelPath: (v: string) => string, options?: ImporterOptions): Promise<NodeApi>;
|
|
13
23
|
//# sourceMappingURL=main-importer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main-importer.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/node/main-importer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main-importer.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/node/main-importer.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,kBAAkB,EAIxB,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIzC,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,aAAa,GAAG,cAAc,CAAC;AAEnE,MAAM,MAAM,eAAe,GAAG;IAC5B,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+FAA+F;IAC/F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;OAEG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC,CAAC;AAEF,wBAAsB,YAAY,CAChC,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,EAClC,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,OAAO,CAAC,CAsGlB"}
|
|
@@ -6,7 +6,7 @@ import { Blake2b, HASH_SIZE } from "#@typeberry/hash";
|
|
|
6
6
|
import { createImporter, ImporterConfig } from "#@typeberry/importer";
|
|
7
7
|
import { tryAsU16 } from "#@typeberry/numbers";
|
|
8
8
|
import { CURRENT_SUITE, CURRENT_VERSION, Result, resultToString, version } from "#@typeberry/utils";
|
|
9
|
-
import { HybridWorkerConfig, InMemWorkerConfig, LmdbWorkerConfig } from "#@typeberry/workers-api-node";
|
|
9
|
+
import { HybridWorkerConfig, InMemWorkerConfig, LmdbWorkerConfig, } from "#@typeberry/workers-api-node";
|
|
10
10
|
import { getChainSpec, getDatabasePath, initializeDatabase, logger } from "./common.js";
|
|
11
11
|
const zeroHash = Bytes.zero(HASH_SIZE).asOpaque();
|
|
12
12
|
export async function mainImporter(config, withRelPath, options = {}) {
|
|
@@ -39,8 +39,8 @@ export async function mainImporter(config, withRelPath, options = {}) {
|
|
|
39
39
|
blake2b,
|
|
40
40
|
workerParams,
|
|
41
41
|
})
|
|
42
|
-
: dbBackend === "hybrid"
|
|
43
|
-
? HybridWorkerConfig.new({
|
|
42
|
+
: dbBackend === "lmdb-hybrid" || dbBackend === "fjall-hybrid"
|
|
43
|
+
? await HybridWorkerConfig.new({
|
|
44
44
|
nodeName,
|
|
45
45
|
chainSpec,
|
|
46
46
|
blake2b,
|
|
@@ -48,6 +48,8 @@ export async function mainImporter(config, withRelPath, options = {}) {
|
|
|
48
48
|
workerParams,
|
|
49
49
|
ephemeral,
|
|
50
50
|
compression,
|
|
51
|
+
backend: dbBackend === "lmdb-hybrid" ? "lmdb" : "fjall",
|
|
52
|
+
sharedFjallSession: options.sharedFjallSession,
|
|
51
53
|
})
|
|
52
54
|
: LmdbWorkerConfig.new({
|
|
53
55
|
nodeName,
|
|
@@ -21,13 +21,33 @@ declare function verifySeal(bandersnatch: BandernsatchWasm, authorKey: Bandersna
|
|
|
21
21
|
declare function getRingCommitment(bandersnatch: BandernsatchWasm, validators: BandersnatchKey[]): Promise<Result<BandersnatchRingRoot, null>>;
|
|
22
22
|
declare function verifyTickets(bandersnatch: BandernsatchWasm, numberOfValidators: number, epochRoot: BandersnatchRingRoot, tickets: readonly SignedTicket[], entropy: EntropyHash): Promise<{
|
|
23
23
|
isValid: boolean;
|
|
24
|
-
|
|
25
|
-
}
|
|
24
|
+
tickets: EntropyHash[];
|
|
25
|
+
}>;
|
|
26
26
|
declare function generateSeal(bandersnatch: BandernsatchWasm, authorKey: BandersnatchSecretSeed, input: BytesBlob, auxData: BytesBlob): Promise<Result<BandersnatchVrfSignature, null>>;
|
|
27
27
|
export type VrfOutputHash = Opaque<OpaqueHash, "VRF Output Hash">;
|
|
28
28
|
declare function getVrfOutputHash(bandersnatch: BandernsatchWasm, authorKey: BandersnatchSecretSeed, input: BytesBlob): Promise<Result<VrfOutputHash, null>>;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Batch-generate signed tickets for multiple validators in a single native call,
|
|
31
|
+
* reusing the ring prover setup across all of them. Returns one ticket list per
|
|
32
|
+
* validator, in the same order as `proverKeyIndices`/`secrets`.
|
|
31
33
|
*/
|
|
32
|
-
declare function generateTickets(bandersnatch: BandernsatchWasm, ringKeys: BandersnatchKey[],
|
|
34
|
+
declare function generateTickets(bandersnatch: BandernsatchWasm, ringKeys: BandersnatchKey[], proverKeyIndices: readonly number[], secrets: readonly BandersnatchSecretSeed[], entropy: EntropyHash, ticketsPerValidator: number): Promise<Result<SignedTicket[][], null>>;
|
|
35
|
+
/**
|
|
36
|
+
* Build the concatenated ring-VRF inputs for ticket generation: one
|
|
37
|
+
* `JAM_TICKET_SEAL || entropy || attempt_byte` input per attempt.
|
|
38
|
+
*
|
|
39
|
+
* Exposed so the worker-pool path can build the same inputs to hand off to a
|
|
40
|
+
* worker thread without re-deriving the layout.
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildTicketVrfInputs(entropy: EntropyHash, ticketsPerValidator: number): {
|
|
43
|
+
inputsData: Uint8Array;
|
|
44
|
+
vrfInputDataLen: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Parse the raw output of `batchGenerateRingVrfForValidators` into per-validator
|
|
48
|
+
* ticket lists. Records are ordered validator-major, then attempt-major; each
|
|
49
|
+
* record is `status byte || signature`. A malformed batch yields a single error
|
|
50
|
+
* byte. Exposed so the worker-pool path can parse a worker's raw result.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseTicketsBatchOutput(result: Uint8Array, numValidators: number, ticketsPerValidator: number): Result<SignedTicket[][], null>;
|
|
33
53
|
//# sourceMappingURL=bandersnatch-vrf.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bandersnatch-vrf.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/safrole/bandersnatch-vrf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAsB,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAS,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"bandersnatch-vrf.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/safrole/bandersnatch-vrf.ts"],"names":[],"mappings":"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"}
|