Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## Unreleased

### Added
- Added createdAt timestamp to block, batch and settlement models.[#502](https://github.com/proto-kit/framework/pull/502)
- Added missing block detection and recovery in the indexer.[#488](https://github.com/proto-kit/framework/pull/488)
- `@dependencyFactory` for static dependency factory type safety
- Added Mempool sorting [#395](https://github.com/proto-kit/framework/pull/395)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
Warnings:

- Added the required column `createdAt` to the `Batch` table without a default value. This is not possible if the table is not empty.
- Added the required column `createdAt` to the `Block` table without a default value. This is not possible if the table is not empty.
- Added the required column `createdAt` to the `Settlement` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "Batch" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL;

-- AlterTable
ALTER TABLE "Block" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL;

-- AlterTable
ALTER TABLE "Settlement" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL;
3 changes: 3 additions & 0 deletions packages/indexer/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ model Block {
fromStateRoot String

beforeBlockStateTransitions Json @db.Json
createdAt DateTime

parentHash String? @unique
parent Block? @relation("Parent", fields: [parentHash], references: [hash])
Expand All @@ -104,6 +105,7 @@ model Batch {
height Int @id

proof Json @db.Json
createdAt DateTime

blocks Block[]

Expand All @@ -128,6 +130,7 @@ model Settlement {
// transaction String
transactionHash String @id
promisedMessagesHash String
createdAt DateTime

batches Batch[]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- AlterTable
ALTER TABLE "Batch" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Block" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

-- AlterTable
ALTER TABLE "Settlement" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
3 changes: 3 additions & 0 deletions packages/persistance/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ model Block {
fromStateRoot String

beforeBlockStateTransitions Json @db.Json
createdAt DateTime @default(now())

parentHash String? @unique
parent Block? @relation("Parent", fields: [parentHash], references: [hash])
Expand All @@ -124,6 +125,7 @@ model Batch {
height Int @id

proof Json @db.Json
createdAt DateTime @default(now())

blocks Block[]

Expand All @@ -148,6 +150,7 @@ model Settlement {
// transaction String
transactionHash String @id
promisedMessagesHash String
createdAt DateTime @default(now())

batches Batch[]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class PrismaBatchStore implements BatchStorage {
data: {
proof: entity.proof as Prisma.InputJsonValue,
height,
createdAt: new Date(batch.createdAt),
blocks: {
connect: batch.blockHashes.map((hash) => ({
hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class BatchMapper implements ObjectMapper<
blockHashes: input[1],
proof: input[0].proof as JsonProof,
height: input[0].height,
createdAt: input[0].createdAt.getTime(),
};
}

Expand All @@ -23,6 +24,7 @@ export class BatchMapper implements ObjectMapper<
proof: input.proof,
height: input.height,
settlementTransactionHash: null,
createdAt: new Date(input.createdAt),
};
return [batch, []];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class BlockMapper implements ObjectMapper<Block, PrismaBlock> {
beforeBlockStateTransitions: this.stArrayMapper.mapIn(
input.beforeBlockStateTransitions
),
createdAt: new Date(input.createdAt).getTime(),
};
}

Expand All @@ -68,6 +69,7 @@ export class BlockMapper implements ObjectMapper<Block, PrismaBlock> {
beforeBlockStateTransitions: this.stArrayMapper.mapOut(
input.beforeBlockStateTransitions
),
createdAt: new Date(input.createdAt),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class SettlementMapper implements ObjectMapper<
batches,
transactionHash: settlement.transactionHash,
promisedMessagesHash: settlement.promisedMessagesHash,
createdAt: settlement.createdAt.getTime(),
};
}

Expand All @@ -23,6 +24,7 @@ export class SettlementMapper implements ObjectMapper<
{
promisedMessagesHash: input.promisedMessagesHash,
transactionHash: input.transactionHash,
createdAt: new Date(input.createdAt),
},
input.batches,
];
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/src/graphql/GraphqlTransactionSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class GraphqlTransactionSender
}
`;
const tx = transaction.toJSON();

const queryResult = await this.graphqlClient.client
.mutation(query, { tx })
.toPromise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class BatchProducerModule extends SequencerModule {
height,
fromNetworkState: batch.fromNetworkState,
toNetworkState: batch.toNetworkState,
createdAt: Date.now(),
},

changes: batch.changes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class BlockProductionService {
during: networkState,
},
beforeBlockStateTransitions,
createdAt: Date.now(),
};

const hash = Block.hash(block);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class BridgingSettlementInteraction implements SettleInteraction {
batches: [batch.height],
promisedMessagesHash: latestSequenceStateHash.toString(),
transactionHash,
createdAt: Date.now(),
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export class VanillaSettlementInteraction implements SettleInteraction {
batches: [batch.height],
promisedMessagesHash: latestSequenceStateHash.toString(),
transactionHash,
createdAt: Date.now(),
};
}
}
1 change: 1 addition & 0 deletions packages/sequencer/src/storage/model/Batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Batch {
proof: JsonProof;
blockHashes: string[];
height: number;
createdAt: number;
}

export interface SettleableBatch extends Batch {
Expand Down
2 changes: 2 additions & 0 deletions packages/sequencer/src/storage/model/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface Block {
toMessagesHash: Field;

beforeBlockStateTransitions: UntypedStateTransition[];
createdAt: number;
}

// eslint-disable-next-line @typescript-eslint/no-redeclare
Expand Down Expand Up @@ -106,6 +107,7 @@ export const BlockWithResult = {
beforeBlockStateTransitions: [],

previousBlockHash: undefined,
createdAt: Date.now(),
},
result: {
afterNetworkState: NetworkState.empty(),
Expand Down
1 change: 1 addition & 0 deletions packages/sequencer/src/storage/model/Settlement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface Settlement {
transactionHash: string;
promisedMessagesHash: string;
batches: number[];
createdAt: number;
}
Loading