Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database connectors for Prisma (Postgres) and Redis #102

Merged
merged 63 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6ac8898
Change Block prod pipeline to Untyped ST object
rpanic Dec 23, 2023
64b922c
Added Prisma and Redis connections
rpanic Dec 23, 2023
bcdbfb1
Added object mappers
rpanic Dec 23, 2023
b9c100e
async stores: made commit and openTx async
rpanic Dec 23, 2023
cd508ea
Implemented first few Prisma stores
rpanic Dec 23, 2023
a06107b
Added redis merkle tree store
rpanic Dec 23, 2023
0973890
Added transactionsHash as id for blocks and references them in batch
rpanic Dec 28, 2023
227300a
Implemented Prisma Batch storage
rpanic Dec 28, 2023
9c82923
Merge branch 'feature/database-factory' into feature/persistance
rpanic Dec 30, 2023
00b1473
Merge changes fix
rpanic Dec 30, 2023
0245814
Changed datatype in stateservice from bigint to decimal
rpanic Dec 30, 2023
6fb2337
Dependency providers for prisma & redis databases
rpanic Dec 30, 2023
2ef56a3
Fixed error for mock proofs
rpanic Jan 1, 2024
7449296
Merge branch 'refactor/state-transition-refactor' into feature/persis…
rpanic Jan 2, 2024
13d12ae
Moved UnprovenBlock types to own file
rpanic Jan 2, 2024
6803953
Removed stateDiff from block model
rpanic Jan 2, 2024
4291359
Added stack package to execute hosted sequencer
rpanic Jan 2, 2024
d067ba7
Link to parent block + metadata linkage by blockhash
rpanic Jan 2, 2024
03f465f
Fixed injection issue for services with masks
rpanic Jan 2, 2024
7fe8fd2
Fixed bugs
rpanic Jan 2, 2024
b1e7280
Fixed wrong linkage of metadata in PrismaBlockStorage
rpanic Jan 3, 2024
1ba995c
Fixed log.trace
rpanic Jan 3, 2024
158fe9f
Fixed pipeline to correctly retrieve latest blocks
rpanic Jan 3, 2024
aa6be56
Added test for multi-block batches
rpanic Jan 4, 2024
9e67061
Added configurability for Prisma Connector
rpanic Jan 4, 2024
4e72fff
Fixed a few minor issues
rpanic Jan 4, 2024
bd59fdf
Committed migrations
rpanic Jan 4, 2024
fcc9406
Optimized preloading behaviour for sequencing
rpanic Jan 5, 2024
91a2de7
Merge branch 'feature/block-hooks-2' into feature/persistance
rpanic Jan 13, 2024
bf01482
Fixed merge problems
rpanic Jan 13, 2024
97f8b1a
Merge branch 'feature/block-hooks-2' into feature/persistance
rpanic Jan 13, 2024
7ba9dc3
Adapted prisma mappers to new block schema
rpanic Jan 15, 2024
108b47d
Merge branch 'feature/block-hooks-2' into feature/persistance
rpanic Jan 15, 2024
d8b2911
Few fixes
rpanic Jan 15, 2024
b0c04f6
Merge branch 'feature/block-hooks-2' into feature/persistance
rpanic Jan 15, 2024
98bc025
Added hash to block
rpanic Jan 15, 2024
e53b8b7
Fixes
rpanic Jan 15, 2024
f8d8d0b
Fixed errors
rpanic Jan 24, 2024
6534623
Optimized loading of merkletree nodes
rpanic Jan 30, 2024
b4fb02a
Added batch storage assertion to prod test
rpanic Jan 31, 2024
ae6080a
Improven error message for redis connection failure
rpanic Jan 31, 2024
2593dce
Merge branch 'feature/settlement' into feature/persistance
rpanic Feb 4, 2024
3a437d9
Fixed merge errors
rpanic Feb 4, 2024
a910476
Adapted schema to integrate messages
rpanic Feb 4, 2024
365aca3
Added Prisma stores for Messages and Settlements
rpanic Feb 5, 2024
dcb0293
Fixed correct relaying of errors in sub-tasks
rpanic Feb 5, 2024
aca1646
Created module to hold both a redis and prisma connection
rpanic Feb 6, 2024
3d4d140
Fixed DependencyFactory module name typing
rpanic Feb 6, 2024
1c8091a
Changed AsyncStateService to properly batch reads and writes
rpanic Feb 7, 2024
29855cd
Fixed issue where block prod flow would hang up because of mismatchin…
rpanic Feb 7, 2024
26274cf
Fixed a few smaller issues
rpanic Feb 7, 2024
520536f
Exported new persistance classes
rpanic Feb 8, 2024
dd2920d
Refactored batch storage
rpanic Feb 13, 2024
a9d8339
Fixed proven network state query
rpanic Feb 13, 2024
31fc721
Added TransactionStorage, refactoring
rpanic Feb 13, 2024
7dccd0c
Fixed wrong starting point for block heights
rpanic Feb 14, 2024
586ac16
Implemented transaction inclusion gql endpoint properly
rpanic Jan 30, 2024
d552d16
Merged TransactionRepository and TransactionStorage
rpanic Feb 14, 2024
0e545e0
Refactoring
rpanic Feb 14, 2024
c81ee64
Merge branch 'develop' into feature/persistance
rpanic Feb 14, 2024
dd6595f
Fixed tests
rpanic Feb 14, 2024
7a4f77f
Added prisma client generation to build script
rpanic Feb 14, 2024
1be398c
Merge pull request #105 from proto-kit/feature/transaction-inclusion
rpanic Mar 7, 2024
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
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
"nodejs/declare": "off",
"unicorn/prefer-event-target": "off",
"putout/putout": "off",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off"
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
"no-undef-init": "off"
},

"overrides": [
Expand Down
183 changes: 183 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/api/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../.eslintrc",
"rules": {
"new-cap": "off"
}
}
47 changes: 25 additions & 22 deletions packages/api/src/graphql/modules/BlockStorageResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable new-cap */
import { inject, injectable } from "tsyringe";
import { Arg, Field, ObjectType, Query, Resolver } from "type-graphql";
import { IsBoolean } from "class-validator";
Expand All @@ -13,6 +12,10 @@ import { MOCK_PROOF } from "@proto-kit/common";
import { graphqlModule, GraphqlModule } from "../GraphqlModule";

import { TransactionObject } from "./MempoolResolver";
import {
UnprovenBlockModel,
UnprovenBlockResolver,
} from "./UnprovenBlockResolver";

@ObjectType()
export class ComputedBlockTransactionModel {
Expand Down Expand Up @@ -48,32 +51,25 @@ export class ComputedBlockTransactionModel {

@ObjectType()
export class ComputedBlockModel {
public static fromServiceLayerModel({
bundles,
proof,
}: ComputedBlock): ComputedBlockModel {
public static fromServiceLayerModel(
{ bundles, proof }: ComputedBlock,
blocks: (UnprovenBlockModel | undefined)[]
): ComputedBlockModel {
return new ComputedBlockModel(
bundles.map((bundle) =>
bundle.map((tx) =>
ComputedBlockTransactionModel.fromServiceLayerModel(tx)
)
bundles.map(
(bundle) => blocks.find((block) => block?.hash === bundle)!
),
proof.proof === MOCK_PROOF
? "mock-proof"
: JSON.stringify(proof.toJSON())
proof.proof === MOCK_PROOF ? "mock-proof" : JSON.stringify(proof)
);
}

@Field(() => [[ComputedBlockTransactionModel]])
public bundles: ComputedBlockTransactionModel[][];
@Field(() => [UnprovenBlockModel])
public bundles: UnprovenBlockModel[];

@Field()
public proof: string;

public constructor(
bundles: ComputedBlockTransactionModel[][],
proof: string
) {
public constructor(bundles: UnprovenBlockModel[], proof: string) {
this.bundles = bundles;
this.proof = proof;
}
Expand All @@ -84,7 +80,8 @@ export class BlockStorageResolver extends GraphqlModule {
// TODO seperate these two block interfaces
public constructor(
@inject("BlockStorage")
private readonly blockStorage: BlockStorage & HistoricalBlockStorage
private readonly blockStorage: BlockStorage & HistoricalBlockStorage,
private readonly unprovenResolver: UnprovenBlockResolver
) {
super();
}
Expand All @@ -97,10 +94,16 @@ export class BlockStorageResolver extends GraphqlModule {
const blockHeight =
height ?? (await this.blockStorage.getCurrentBlockHeight()) - 1;

const block = await this.blockStorage.getBlockAt(blockHeight);
const batch = await this.blockStorage.getBlockAt(blockHeight);

if (block !== undefined) {
return ComputedBlockModel.fromServiceLayerModel(block);
if (batch !== undefined) {
const blocks = await Promise.all(
batch.bundles.map((bundle) =>
// TODO Find a graphql-native way of doing this relational 1-n mapping
this.unprovenResolver.block(undefined, bundle)
)
);
return ComputedBlockModel.fromServiceLayerModel(batch, blocks);
}
return undefined;
}
Expand Down
Loading
Loading