Skip to content

Commit 448695e

Browse files
authored
Merge pull request #243 from proto-kit/fix/base-memory-state-service
Fix for Mempool and BP using different State Services
2 parents 2d6b3d5 + c2eb14c commit 448695e

File tree

2 files changed

+103
-4
lines changed

2 files changed

+103
-4
lines changed

packages/common/src/config/ModuleContainer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
DependencyContainer,
55
Frequency,
66
InjectionToken,
7-
instancePerContainerCachingFactory,
7+
instanceCachingFactory,
88
isClassProvider,
99
isFactoryProvider,
1010
isTokenProvider,
@@ -417,9 +417,7 @@ export class ModuleContainer<
417417
// this enables us to have a singletoned factory
418418
// that returns the same instance for each resolve
419419
this.container.register(key, {
420-
useFactory: instancePerContainerCachingFactory(
421-
declaration.useFactory
422-
),
420+
useFactory: instanceCachingFactory(declaration.useFactory),
423421
});
424422
} else if (isClassProvider(declaration)) {
425423
this.container.register(key, declaration, {

packages/sequencer/test/integration/BlockProduction.test.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,107 @@ describe("block production", () => {
307307
expect(newState).toBeUndefined();
308308
}, 30_000);
309309

310+
it("should produce txs in non-consecutive blocks", async () => {
311+
log.setLevel("TRACE");
312+
313+
const privateKey = PrivateKey.random();
314+
const publicKey = privateKey.toPublicKey();
315+
316+
const privateKey2 = PrivateKey.random();
317+
const publicKey2 = privateKey2.toPublicKey();
318+
319+
await mempool.add(
320+
createTransaction({
321+
runtime,
322+
method: ["Balance", "setBalanceIf"],
323+
privateKey,
324+
args: [publicKey, UInt64.from(100), Bool(true)],
325+
nonce: 0,
326+
})
327+
);
328+
329+
// let [block, batch] = await blockTrigger.produceBlockAndBatch();
330+
const block = await blockTrigger.produceBlock();
331+
332+
expect(block).toBeDefined();
333+
334+
expect(block!.transactions).toHaveLength(1);
335+
expect(block!.transactions[0].status.toBoolean()).toBe(true);
336+
expect(block!.transactions[0].statusMessage).toBeUndefined();
337+
338+
expect(block!.transactions[0].stateTransitions).toHaveLength(1);
339+
expect(block!.transactions[0].protocolTransitions).toHaveLength(2);
340+
341+
await blockTrigger.produceBlock();
342+
343+
await mempool.add(
344+
createTransaction({
345+
runtime,
346+
method: ["Balance", "setBalanceIf"],
347+
privateKey: privateKey2,
348+
args: [publicKey2, UInt64.from(100), Bool(true)],
349+
nonce: 0,
350+
})
351+
);
352+
await blockTrigger.produceBlock();
353+
354+
await mempool.add(
355+
createTransaction({
356+
runtime,
357+
method: ["Balance", "setBalanceIf"],
358+
privateKey: privateKey2,
359+
args: [publicKey2, UInt64.from(100), Bool(true)],
360+
nonce: 1,
361+
})
362+
);
363+
await blockTrigger.produceBlock();
364+
365+
await mempool.add(
366+
createTransaction({
367+
runtime,
368+
method: ["Balance", "setBalanceIf"],
369+
privateKey: privateKey2,
370+
args: [publicKey2, UInt64.from(100), Bool(true)],
371+
nonce: 2,
372+
})
373+
);
374+
await blockTrigger.produceBlock();
375+
376+
await mempool.add(
377+
createTransaction({
378+
runtime,
379+
method: ["Balance", "setBalanceIf"],
380+
privateKey: privateKey2,
381+
args: [publicKey2, UInt64.from(100), Bool(true)],
382+
nonce: 3,
383+
})
384+
);
385+
await blockTrigger.produceBlock();
386+
387+
// Second tx
388+
await mempool.add(
389+
createTransaction({
390+
runtime,
391+
method: ["Balance", "setBalanceIf"],
392+
privateKey,
393+
args: [publicKey, UInt64.from(100), Bool(true)],
394+
nonce: 1,
395+
})
396+
);
397+
398+
log.info("Starting second block");
399+
400+
const block2 = await blockTrigger.produceBlock();
401+
402+
expect(block2).toBeDefined();
403+
404+
expect(block2!.transactions).toHaveLength(1);
405+
console.log(block2!.transactions[0]);
406+
console.log(block2!.transactions[0].statusMessage);
407+
expect(block2!.transactions[0].status.toBoolean()).toBe(true);
408+
expect(block2!.transactions[0].statusMessage).toBeUndefined();
409+
}, 60_000);
410+
310411
const numberTxs = 3;
311412

312413
it("should produce block with multiple transaction", async () => {

0 commit comments

Comments
 (0)