Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d2e2160
feat: add type alias for FieldString and helper function for it
saitunc Jan 7, 2026
4336578
refactor: change Field typed properties to FieldString type
saitunc Jan 7, 2026
be7c06e
refactor: update codebase to use string properties of Block
saitunc Jan 7, 2026
86f87db
refactor: allow Field in FieldString input
saitunc Jan 7, 2026
c29a51d
refactor: Infer JSON type of NetworkState and use in Block interface
saitunc Jan 7, 2026
adc99a0
refactor: update codebase for use of NetworkStateJson type
saitunc Jan 7, 2026
2483e82
refactor: remove unnecessary stringifications and type conversions
saitunc Jan 7, 2026
ae96af1
refactor: change use of NetworkState to NetworkStateJson in codebase
saitunc Jan 9, 2026
1093afe
refactor: refactor ClientBlock and used parts in codebase
saitunc Jan 9, 2026
0199877
refactor: update UntypedStateTransition with UntypedSTJson
saitunc Jan 12, 2026
76e1417
refactor: add utility function for hashing NetworkStateJson values
saitunc Jan 13, 2026
55d5dec
refactor: apply refactoring where NetworkStateJson is used
saitunc Jan 13, 2026
78aae19
refactor: add BlockHahMerkleTreewitnessJson and refactor with it
saitunc Jan 13, 2026
31db4aa
refactor: refactor BlockMapper and BlockResultMapper with new types
saitunc Jan 14, 2026
7706aa3
refactor: update methodId type to string
saitunc Jan 14, 2026
b46e81d
refactor: add minor change to use methodId
saitunc Jan 14, 2026
5934a13
refactor: rename UntypedSTJson to UntypedStateTranisitionJson
saitunc Jan 14, 2026
b017bb5
refactor: implement TransactionExecutionResultJson and use it for Block
saitunc Jan 14, 2026
d3c9336
refactor: refactor PrivateMempool to use PendingTransactionJson type
saitunc Jan 14, 2026
08f95bb
refactor: add serialization utility functions for non-provable types
saitunc Jan 15, 2026
d8558f9
refactor: use non-provable types in storage and mempool interfaces
saitunc Jan 15, 2026
564ba7a
refactor:use non-provable types in execution and tracing services
saitunc Jan 15, 2026
6905b36
refactor: update Prisma interactions to use non-provable types
saitunc Jan 15, 2026
fb4c854
refactor: use non-provable types in object mappers
saitunc Jan 15, 2026
d5b6d7b
refactor: update PendingTransaction related code PendingTransactionJs…
saitunc Jan 15, 2026
57ad69d
refactor(test): update with changes in codebase
saitunc Jan 15, 2026
a4ac392
refactor: use non-provable types in tracing and task layers
saitunc Jan 15, 2026
bc53d88
refactor: use non-provable types in tracing services
saitunc Jan 15, 2026
57c3520
style: run lint fix
saitunc Jan 15, 2026
08e7d35
Merge branch 'develop' into refactor/refactor-provable-types
saitunc Jan 15, 2026
2a37bb7
style: run lint fix
saitunc Jan 15, 2026
f041a12
Delete planning file
saitunc Jan 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions packages/api/src/graphql/modules/BlockResolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { inject } from "tsyringe";
import { Block, BlockStorage } from "@proto-kit/sequencer";
import { Block, BlockStorage, PendingTransaction } from "@proto-kit/sequencer";
import { Arg, Field, ObjectType, Query } from "type-graphql";

import { GraphqlModule, graphqlModule } from "../GraphqlModule";
Expand All @@ -10,17 +10,17 @@ import { BatchTransactionModel } from "./model/BatchTransactionModel";
export class BlockModel {
public static fromServiceLayerModel(block: Block) {
return new BlockModel(
Number(block.networkState.during.block.height.toBigInt()),
Number(block.networkState.during.block.height),
block.transactions.map((tx) =>
BatchTransactionModel.fromServiceLayerModel({
tx: tx.tx,
status: tx.status.toBoolean(),
tx: PendingTransaction.fromJSON(tx.tx),
status: tx.status,
statusMessage: tx.statusMessage,
})
),
block.transactionsHash.toString(),
block.hash.toString(),
block.previousBlockHash?.toString()
block.transactionsHash,
block.hash,
block.previousBlockHash
);
}

Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/graphql/modules/MempoolResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ export class MempoolResolver extends GraphqlModule {
description: "Adds a transaction to the mempool and validates it",
})
public async submitTx(@Arg("tx") tx: TransactionObject): Promise<string> {
const decoded = PendingTransaction.fromJSON(tx);
const decoded = PendingTransaction.fromJSON(tx).toJSON();
await this.mempool.add(decoded);

return decoded.hash().toString();
return decoded.hash;
}

// TODO Add retrieval of pending messages somewhere as well
Expand Down Expand Up @@ -162,6 +162,6 @@ export class MempoolResolver extends GraphqlModule {
})
public async transactions() {
const txs = await this.transactionStorage.getPendingUserTransactions();
return txs.map((x) => x.hash().toString());
return txs.map((x) => x.hash);
}
}
2 changes: 1 addition & 1 deletion packages/api/src/metrics/SequencerInstrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class SequencerInstrumentation extends InstrumentationBase<{}> {
super("protokit", "canary", {});
if (trigger !== undefined) {
trigger.events.on("block-produced", (block) => {
this.blockProduced(parseInt(block.height.toString(), 10));
this.blockProduced(parseInt(block.height, 10));
});
}
}
Expand Down
8 changes: 3 additions & 5 deletions packages/indexer/src/IndexerNotifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export class IndexerNotifier extends SequencerModule<Record<never, never>> {
this.indexSettlementTask.inputSerializer();

this.sequencer.events.on("block-metadata-produced", async (block) => {
log.debug(
"Notifiying the indexer about block",
block.block.height.toBigInt()
);
log.debug("Notifiying the indexer about block", block.block.height);
const payload = await inputSerializer.toJSON(block);
const sequencerId = this.sequencerIdProvider.getSequencerId();

Expand All @@ -69,7 +66,8 @@ export class IndexerNotifier extends SequencerModule<Record<never, never>> {
const txQueue = await this.taskQueue.getQueue(
this.indexPendingTxTask.name
);
const payload = await txInputSerializer.toJSON(tx);
// This part seems weird
const payload = await txInputSerializer.toJSON(tx.toJSON());
const sequencerId = this.sequencerIdProvider.getSequencerId();

const task: TaskPayload = {
Expand Down
7 changes: 3 additions & 4 deletions packages/indexer/src/tasks/IndexBlockTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ export class IndexBlockTask
await this.blockStorage.pushBlock(input.block);
await this.blockStorage.pushResult(input.result);
} catch (error) {
log.error("Failed to index block", input.block.height.toBigInt(), error);
return undefined;
log.error("Failed to index block", input.block.height, error);
return;
}

log.info(`Block ${input.block.height.toBigInt()} indexed sucessfully`);
return "";
log.info(`Block ${input.block.height} indexed sucessfully`);
}

public inputSerializer(): TaskSerializer<IndexBlockTaskParameters> {
Expand Down
10 changes: 6 additions & 4 deletions packages/indexer/src/tasks/IndexPendingTxTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
PendingTransaction,
PendingTransactionJSONType,
Task,
TaskSerializer,
TaskWorkerModule,
Expand All @@ -13,7 +13,7 @@ import { IndexPendingTxTaskParametersSerializer } from "./IndexPendingTxTaskPara
@injectable()
export class IndexPendingTxTask
extends TaskWorkerModule
implements Task<PendingTransaction, string | void>
implements Task<PendingTransactionJSONType, string | void>
{
public name = "index-pending-tx";

Expand All @@ -28,7 +28,9 @@ export class IndexPendingTxTask
// eslint-disable-next-line @typescript-eslint/no-empty-function
public async prepare(): Promise<void> {}

public async compute(input: PendingTransaction): Promise<string | void> {
public async compute(
input: PendingTransactionJSONType
): Promise<string | void> {
try {
await this.transactionStorage.pushUserTransaction(input);
return "";
Expand All @@ -38,7 +40,7 @@ export class IndexPendingTxTask
}
}

public inputSerializer(): TaskSerializer<PendingTransaction> {
public inputSerializer(): TaskSerializer<PendingTransactionJSONType> {
return this.taskSerializer;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/indexer/src/tasks/IndexPendingTxTaskParameters.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { PendingTransaction } from "@proto-kit/sequencer";
import { PendingTransactionJSONType } from "@proto-kit/sequencer";
import { TransactionMapper } from "@proto-kit/persistance";
import { injectable } from "tsyringe";

@injectable()
export class IndexPendingTxTaskParametersSerializer {
public constructor(public transactionMapper: TransactionMapper) {}

public toJSON(parameters: PendingTransaction): string {
public toJSON(parameters: PendingTransactionJSONType): string {
return JSON.stringify({
tx: this.transactionMapper.mapOut(parameters),
});
}

public fromJSON(json: string): PendingTransaction {
public fromJSON(json: string): PendingTransactionJSONType {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const parsed = JSON.parse(json) as {
tx: ReturnType<TransactionMapper["mapOut"]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { log } from "@proto-kit/common";
import { jest } from "@jest/globals";

import { Indexer } from "../src/Indexer";
import { GeneratedResolverFactoryGraphqlModule } from "../src/api/GeneratedResolverFactoryGraphqlModule";
import { GeneratedResolverFactoryGraphqlModule } from "../src";

log.setLevel("info");

Expand Down
4 changes: 1 addition & 3 deletions packages/indexer/test/IndexBlockTask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ describe("IndexBlockTask", () => {
const storage = indexer.resolve("BlockStorage");
const latestBlock = await storage.getLatestBlock();

expect(latestBlock?.block.hash.toBigInt()).toBe(
block.block.hash.toBigInt()
);
expect(latestBlock?.block.hash).toBe(block.block.hash);
});
});
4 changes: 2 additions & 2 deletions packages/indexer/test/IndexerNotifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function sendTransactions(
const txs = await mempool.getTxs();
console.log(
"txs",
txs.map((tx) => tx.nonce.toBigInt())
txs.map((tx) => tx.nonce)
);

return await appChain.produceBlock();
Expand Down Expand Up @@ -183,7 +183,7 @@ describe.skip("IndexerNotifier", () => {
.resolve(IndexBlockTaskParametersSerializer)
.fromJSON(addTaskSpy.mock.lastCall?.[0].payload!);

expect(block.height.toBigInt()).toBe(0n);
expect(block.height).toBe("0");
expect(block.transactions.length).toBe(2);
});
});
6 changes: 3 additions & 3 deletions packages/library/src/hooks/RuntimeFeeAnalyzerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ export class RuntimeFeeAnalyzerService extends ConfigurableModule<RuntimeFeeAnal
{
...values,

[methodId.toString()]: {
methodId,
[methodId]: {
methodId: BigInt(methodId),

baseFee:
this.config.methods[combinedMethodName]?.baseFee ??
Expand All @@ -129,7 +129,7 @@ export class RuntimeFeeAnalyzerService extends ConfigurableModule<RuntimeFeeAnal
{
...indexes,
// eslint-disable-next-line no-plusplus
[methodId.toString()]: BigInt(methodCounter++),
[methodId]: BigInt(methodCounter++),
},
];
},
Expand Down
10 changes: 5 additions & 5 deletions packages/module/src/runtime/MethodIdResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class MethodIdResolver {
this.runtime.assertIsValidModuleName(moduleName);

runtime.resolve(moduleName).runtimeMethodNames.forEach((methodName) => {
dict[this.getMethodId(moduleName, methodName).toString()] = {
dict[this.getMethodId(moduleName, methodName)] = {
moduleName,
methodName,
};
Expand Down Expand Up @@ -83,8 +83,8 @@ export class MethodIdResolver {
}, {});
}

public getMethodNameFromId(methodId: bigint): [string, string] | undefined {
const methodPath = this.dictionary[methodId.toString()];
public getMethodNameFromId(methodId: string): [string, string] | undefined {
const methodPath = this.dictionary[methodId];

if (methodPath === undefined) {
return undefined;
Expand All @@ -97,12 +97,12 @@ export class MethodIdResolver {
return [moduleName, methodName];
}

public getMethodId(moduleName: string, methodName: string): bigint {
public getMethodId(moduleName: string, methodName: string): string {
this.runtime.assertIsValidModuleName(moduleName);

return Poseidon.hash([
stringToField(moduleName),
stringToField(methodName),
]).toBigInt();
]).toString();
}
}
2 changes: 1 addition & 1 deletion packages/module/src/runtime/Runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class Runtime<Modules extends RuntimeModulesRecord>
* Encoding: "stringToField(module.name) << 128 + stringToField(method-name)"
*/
public getMethodById(
methodId: bigint
methodId: string
): ((...args: unknown[]) => Promise<unknown>) | undefined {
const methodDescriptor =
this.methodIdResolver.getMethodNameFromId(methodId);
Expand Down
22 changes: 11 additions & 11 deletions packages/persistance/src/services/prisma/PrismaBlockStorage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
TransactionExecutionResult,
TransactionExecutionResultJson,
Block,
BlockResult,
BlockQueue,
Expand Down Expand Up @@ -53,9 +53,10 @@ export class PrismaBlockStorage implements BlockQueue, BlockStorage {
if (dbResult === null) {
return undefined;
}
const transactions = dbResult.transactions.map<TransactionExecutionResult>(
(txresult) => this.transactionResultMapper.mapIn([txresult, txresult.tx])
);
const transactions =
dbResult.transactions.map<TransactionExecutionResultJson>((txresult) =>
this.transactionResultMapper.mapIn([txresult, txresult.tx])
);

return {
block: {
Expand All @@ -80,15 +81,15 @@ export class PrismaBlockStorage implements BlockQueue, BlockStorage {
public async pushBlock(block: Block): Promise<void> {
log.trace(
"Pushing block to DB. Txs:",
block.transactions.map((x) => x.tx.hash().toString())
block.transactions.map((x) => x.tx.hash)
);

const transactions = block.transactions.map<DBTransactionExecutionResult>(
(tx) => {
const encoded = this.transactionResultMapper.mapOut(tx);
return {
...encoded[0],
blockHash: block.hash.toString(),
blockHash: block.hash,
};
}
);
Expand Down Expand Up @@ -191,7 +192,7 @@ export class PrismaBlockStorage implements BlockQueue, BlockStorage {
if (result !== undefined) {
if (result.result === undefined) {
throw new Error(
`Block result for block ${result.block.height.toString()} not found`
`Block result for block ${result.block.height} not found`
);
}
return {
Expand Down Expand Up @@ -221,11 +222,10 @@ export class PrismaBlockStorage implements BlockQueue, BlockStorage {
});

return blocks.map((block, index) => {
const transactions = block.transactions.map<TransactionExecutionResult>(
(txresult) => {
const transactions =
block.transactions.map<TransactionExecutionResultJson>((txresult) => {
return this.transactionResultMapper.mapIn([txresult, txresult.tx]);
}
);
});
const decodedBlock = this.blockMapper.mapIn(block);
decodedBlock.transactions = transactions;

Expand Down
11 changes: 7 additions & 4 deletions packages/persistance/src/services/prisma/PrismaMessageStorage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { MessageStorage, PendingTransaction } from "@proto-kit/sequencer";
import {
MessageStorage,
PendingTransactionJSONType,
} from "@proto-kit/sequencer";
import { inject, injectable } from "tsyringe";

import type { PrismaConnection } from "../../PrismaDatabaseConnection";
Expand All @@ -21,7 +24,7 @@ export class PrismaMessageStorage implements MessageStorage {
const batches: {
fromMessagesHash: string;
toMessagesHash: string;
messages: PendingTransaction[];
messages: PendingTransactionJSONType[];
}[] = [];
let currentHash = fromMessagesHash;

Expand All @@ -43,7 +46,7 @@ export class PrismaMessageStorage implements MessageStorage {
| {
fromMessagesHash: string;
toMessagesHash: string;
messages: PendingTransaction[];
messages: PendingTransactionJSONType[];
}
| undefined
> {
Expand Down Expand Up @@ -84,7 +87,7 @@ export class PrismaMessageStorage implements MessageStorage {
public async pushMessages(
fromMessageHash: string,
toMessageHash: string,
messages: PendingTransaction[]
messages: PendingTransactionJSONType[]
): Promise<void> {
const transactions = messages.map((message) =>
this.transactionMapper.mapOut(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { inject, injectable } from "tsyringe";
import {
PendingTransaction,
PendingTransactionJSONType,
trace,
Tracer,
TransactionStorage,
Expand All @@ -19,7 +19,9 @@ export class PrismaTransactionStorage implements TransactionStorage {
) {}

@trace("db.txs.get")
public async getPendingUserTransactions(): Promise<PendingTransaction[]> {
public async getPendingUserTransactions(): Promise<
PendingTransactionJSONType[]
> {
const { prismaClient } = this.connection;

const txs = await prismaClient.transaction.findMany({
Expand Down Expand Up @@ -51,7 +53,9 @@ export class PrismaTransactionStorage implements TransactionStorage {
}
}

public async pushUserTransaction(tx: PendingTransaction): Promise<boolean> {
public async pushUserTransaction(
tx: PendingTransactionJSONType
): Promise<boolean> {
const { prismaClient } = this.connection;

const result = await prismaClient.transaction.createMany({
Expand All @@ -64,7 +68,7 @@ export class PrismaTransactionStorage implements TransactionStorage {

public async findTransaction(hash: string): Promise<
| {
transaction: PendingTransaction;
transaction: PendingTransactionJSONType;
block?: string;
batch?: number;
}
Expand Down
Loading