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

feat: storing l2 contract data #17

Merged
merged 62 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
d8ece8a
upgrade
FilipHarald Sep 10, 2024
efd1786
init frontend
FilipHarald Sep 10, 2024
f4cc726
working
FilipHarald Sep 10, 2024
bb6facb
fixed block-view
FilipHarald Sep 10, 2024
92495c9
extracted to hook
FilipHarald Sep 10, 2024
da282e0
ugly but works
FilipHarald Sep 10, 2024
78b2fc6
better JSON
FilipHarald Sep 10, 2024
203467a
small fixes
FilipHarald Sep 11, 2024
3cd9d47
Merge branch 'main' of github.com:aztlan-labs/chicmoz into block_and_…
FilipHarald Sep 12, 2024
8c0cce1
added commented log extraction
FilipHarald Sep 12, 2024
28356b1
Merge branch 'block_and_blocks_init_frontend' of github.com:aztlan-la…
FilipHarald Sep 12, 2024
58dab15
Merge branch 'main' of github.com:aztlan-labs/chicmoz into storing_l2…
FilipHarald Sep 13, 2024
09d03dc
fixed it
FilipHarald Sep 13, 2024
cf9cef9
Merge branch 'main' of github.com:aztlan-labs/chicmoz into storing_l2…
FilipHarald Sep 13, 2024
cb347b9
Merge branch 'fix_frontend_build' of github.com:aztlan-labs/chicmoz i…
FilipHarald Sep 13, 2024
b236688
fix
FilipHarald Sep 13, 2024
426da77
devnet working
FilipHarald Sep 14, 2024
96f798d
less comments
FilipHarald Sep 14, 2024
73592e3
sandbox
FilipHarald Sep 14, 2024
7bb0d77
better
FilipHarald Sep 14, 2024
6fe205e
proper ignored env-file
FilipHarald Sep 16, 2024
64405c5
done
FilipHarald Sep 16, 2024
4134df3
added example
FilipHarald Sep 16, 2024
8a2016b
should prefer sandbox
FilipHarald Sep 16, 2024
bfd9dbd
some help
FilipHarald Sep 16, 2024
a646072
Merge branch 'local_aztec_node' of github.com:aztlan-labs/chicmoz int…
FilipHarald Sep 16, 2024
4b979b5
fixed it
FilipHarald Sep 16, 2024
ba93aba
Merge branch 'local_aztec_node' of github.com:aztlan-labs/chicmoz int…
FilipHarald Sep 16, 2024
ead5bcd
better comments
FilipHarald Sep 16, 2024
76fab76
Merge branch 'local_aztec_node' of github.com:aztlan-labs/chicmoz int…
FilipHarald Sep 16, 2024
3d1d133
more improvement
FilipHarald Sep 16, 2024
84b42cd
Merge branch 'local_aztec_node' of github.com:aztlan-labs/chicmoz int…
FilipHarald Sep 16, 2024
e9d349c
Merge branch 'main' of github.com:aztlan-labs/chicmoz into storing_l2…
FilipHarald Sep 16, 2024
0be322d
MIGHT BE REVERTED
FilipHarald Sep 16, 2024
524063c
split getting of block DB
FilipHarald Sep 16, 2024
7967b89
done
FilipHarald Sep 16, 2024
6a21d3c
fixed stuff
FilipHarald Sep 16, 2024
8a34868
back to node RPC
FilipHarald Sep 16, 2024
074e960
no linter error
FilipHarald Sep 16, 2024
4e9ab6d
fixing libraries
FilipHarald Sep 16, 2024
f317529
added type and on-block function
FilipHarald Sep 16, 2024
4d846dc
DB-schema, done but not working
FilipHarald Sep 17, 2024
3a3ece3
no unsafe
FilipHarald Sep 17, 2024
20dc62b
migrations and store working
FilipHarald Sep 17, 2024
560563a
Merge branch 'block_api_improvements' of github.com:aztlan-labs/chicm…
FilipHarald Sep 17, 2024
353dad4
block hash in type
FilipHarald Sep 17, 2024
727cb96
http-api getbyaddress
FilipHarald Sep 17, 2024
f273eea
testing route in UI - not tested yet!
FilipHarald Sep 17, 2024
ace2a81
less diff
FilipHarald Sep 17, 2024
f7afb85
still not working
FilipHarald Sep 17, 2024
1b36b21
Merge branch 'main' of github.com:aztlan-labs/chicmoz into expose_san…
FilipHarald Sep 17, 2024
ab903af
sandbox....
FilipHarald Sep 17, 2024
c9168d5
fixed it
FilipHarald Sep 17, 2024
cd30265
less diff
FilipHarald Sep 17, 2024
e54a68f
less diff
FilipHarald Sep 17, 2024
2856699
Update k8s/local/skaffold.local.yaml
FilipHarald Sep 17, 2024
1e6ee9d
Merge branch 'expose_sandbox_locally' of github.com:aztlan-labs/chicm…
FilipHarald Sep 17, 2024
d09b5da
Merge branch 'expose_sandbox_locally' of github.com:aztlan-labs/chicm…
FilipHarald Sep 17, 2024
ff3a0e8
throwing when network i 0
FilipHarald Sep 17, 2024
829473c
working!
FilipHarald Sep 18, 2024
7022822
Merge branch 'main' of github.com:aztlan-labs/chicmoz into storing_l2…
FilipHarald Sep 18, 2024
40898bb
env-vars
FilipHarald Sep 18, 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
10 changes: 8 additions & 2 deletions k8s/local/aztec-devnet-node/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ spec:
- name: DEBUG
value: "aztec:*"
- name: ETHEREUM_HOST
value: "https://devnet-mainnet-fork.aztec.network:8545/$(CHICMOZ_AZTEC_API_KEY)" # TODO: WARNING! We need to have this as env-var
valueFrom:
secretKeyRef:
name: global
key: CHICMOZ_AZTEC_ETHEREUM_HOST
- name: L1_CHAIN_ID
value: "677692"
- name: ARCHIVER_POLLING_INTERVAL_MS
Expand All @@ -58,7 +61,10 @@ spec:
- name: AZTEC_PORT
value: "8080"
- name: FAUCET_ENDPOINT
value: "https://api.aztec.network/devnet/aztec-faucet/$(CHICMOZ_AZTEC_API_KEY)"
valueFrom:
secretKeyRef:
name: global
key: CHICMOZ_AZTEC_FAUCET_ENDPOINT
- name: PRIVATE_KEY
valueFrom:
secretKeyRef:
Expand Down
10 changes: 7 additions & 3 deletions k8s/local/aztec-listener/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spec:
- name: NODE_ENV
value: "development"
- name: BLOCK_INTERVAL_MS
value: "2000"
value: "5000"
- name: BATCH_SIZE
value: "50"
- name: CHAIN_NAME
Expand Down Expand Up @@ -72,6 +72,10 @@ spec:
- name: DISABLE_AZTEC
value: "false"
- name: AZTEC_RPC
# value: "http://aztec-devnet-node:8080" # DEVNET
value: "http://aztec-sandbox-node:8081" # SANDBOX
#value: "http://aztec-devnet-node:8080" # DEVNET
#value: "http://aztec-sandbox-node:8081" # SANDBOX
valueFrom:
secretKeyRef:
name: global
key: CHICMOZ_AZTEC_RPC
status: {}
2 changes: 0 additions & 2 deletions k8s/local/explorer-api/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ spec:
value: "admin"
- name: POSTGRES_PASSWORD
value: "secret-local-password"
- name: BLOCK_INTERVAL_MS
value: "2000"
- name: BLOCK_DB_VALIDATION_ENABLED
value: "false"
- name: BLOCK_DB_VALIDATION_INTERVAL
Expand Down
46 changes: 23 additions & 23 deletions k8s/local/skaffold.local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ build:
manifests:
rawYaml:
- k8s/local/common/namespace.yaml
# - k8s/local/explorer-ui/ingress.yaml
# - k8s/local/explorer-ui/deployment.yaml
# - k8s/local/explorer-ui/service.yaml
#- k8s/local/explorer-ui/ingress.yaml
#- k8s/local/explorer-ui/deployment.yaml
#- k8s/local/explorer-ui/service.yaml
- k8s/local/explorer-api/ingress.yaml
- k8s/local/explorer-api/deployment.yaml
- k8s/local/explorer-api/service.yaml
- k8s/local/auth/deployment.yaml
- k8s/local/auth/service.yaml
- k8s/local/dummy-node/ingress.yaml
- k8s/local/dummy-node/deployment.yaml
- k8s/local/dummy-node/service.yaml
# - k8s/local/dummy-node/ingress.yaml
# - k8s/local/dummy-node/deployment.yaml
# - k8s/local/dummy-node/service.yaml
- k8s/local/aztec-listener/deployment.yaml
#- k8s/local/aztec-devnet-node/deployment.yaml # DEVNET
#- k8s/local/aztec-devnet-node/service.yaml # DEVNET
Expand All @@ -70,9 +70,9 @@ manifests:
- k8s/local/anvil-ethereum-node/ingress.yaml # SANDBOX
- k8s/local/anvil-ethereum-node/deployment.yaml # SANDBOX
- k8s/local/anvil-ethereum-node/service.yaml # SANDBOX
- k8s/local/kafka-ui/configmap.yaml
- k8s/local/kafka-ui/configmap-env.yaml
- k8s/local/kafka-ui/ingress.yaml
# - k8s/local/kafka-ui/configmap.yaml
# - k8s/local/kafka-ui/configmap-env.yaml
# - k8s/local/kafka-ui/ingress.yaml
helm:
releases:
- name: ingress-nginx
Expand Down Expand Up @@ -137,17 +137,17 @@ manifests:
skipBuildDependencies: false
useHelmSecrets: false
wait: false
- name: kafka-ui
version: 0.7.6
remoteChart: kafka-ui
repo: https://provectus.github.io/kafka-ui-charts
namespace: chicmoz
setValues:
yamlApplicationConfigConfigMap.name: kafka-ui-configmap
yamlApplicationConfigConfigMap.keyName: config.yml
existingConfigMap: kafka-ui-helm-values
createNamespace: false
recreatePods: false
skipBuildDependencies: false
useHelmSecrets: false
wait: false
#- name: kafka-ui
# version: 0.7.6
# remoteChart: kafka-ui
# repo: https://provectus.github.io/kafka-ui-charts
# namespace: chicmoz
# setValues:
# yamlApplicationConfigConfigMap.name: kafka-ui-configmap
# yamlApplicationConfigConfigMap.keyName: config.yml
# existingConfigMap: kafka-ui-helm-values
# createNamespace: false
# recreatePods: false
# skipBuildDependencies: false
# useHelmSecrets: false
# wait: false
4 changes: 2 additions & 2 deletions packages/message-registry/src/aztec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NodeInfoAlias } from '@chicmoz-pkg/types';
import { NodeInfo } from '@chicmoz-pkg/types';

export type NewBlockEvent = {
nodeInfo: NodeInfoAlias;
nodeInfo: NodeInfo;
block?: string;
};

Expand Down
13 changes: 2 additions & 11 deletions packages/types/src/aztec/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
export * from "./l2Block.js";
export * from "./l2Contract.js";

// TODO: the import should work, but instead we're using a type alias
// import { type NodeInfo } from "@aztec/aztec.js";
export type NodeInfoAlias = {
nodeVersion: string;
l1ChainId: number;
protocolVersion: number;
enr: string | undefined;
l1ContractAddresses: object;
protocolContractAddresses: object;
};

export { type NodeInfo } from "@aztec/aztec.js";
42 changes: 1 addition & 41 deletions packages/types/src/aztec/l2Block.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,9 @@
import { z } from "zod";
import { deepPartial } from "../utils.js";
import { bufferSchema, frSchema } from "./utils.js";

// TODO: separate type for transaction?

type AztecFr = {
toString(): string;
};

type StringifiedAztecFr = {
type: "Fr";
value: string;
};

const frSchema = z.preprocess(
(val) => {
if ((val as StringifiedAztecFr).value)
return (val as StringifiedAztecFr).value;
else if ((val as AztecFr).toString) return (val as AztecFr).toString();
else return val;
},
z
.string()
.length(66)
.regex(/^0x[0-9a-fA-F]+$/)
);

type StringifiedBuffer = {
type: "Buffer";
data: number[];
};

const bufferSchema = z.preprocess(
(val) => {
if ((val as StringifiedBuffer).data)
return Buffer.from((val as StringifiedBuffer).data);
return val;
},
z.custom<Buffer>(
(value) => {
return value instanceof Buffer;
},
{ message: "Expected a Buffer" }
)
);

export const noteEncryptedLogEntrySchema = z.object({
data: z.string(),
});
Expand Down
41 changes: 41 additions & 0 deletions packages/types/src/aztec/l2Contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { z } from "zod";
import { aztecAddressSchema, bufferSchema, frSchema } from "./utils.js";
import { chicmozL2BlockSchema } from "./l2Block.js";

export const chicmozL2ContractInstanceDeployedEventSchema = z.object({
Mautjee marked this conversation as resolved.
Show resolved Hide resolved
address: aztecAddressSchema,
blockHash: chicmozL2BlockSchema.shape.hash,
version: z.number(),
salt: frSchema,
contractClassId: frSchema,
initializationHash: frSchema,
publicKeysHash: frSchema,
deployer: aztecAddressSchema,
});

export type ChicmozL2ContractInstanceDeployedEvent = z.infer<
typeof chicmozL2ContractInstanceDeployedEventSchema
>;

export const chicmozL2ContractClassRegisteredEventSchema = z.object({
blockHash: chicmozL2BlockSchema.shape.hash,
contractClassId: frSchema,
version: z.number(),
artifactHash: frSchema,
privateFunctionsRoot: frSchema,
packedPublicBytecode: bufferSchema,
});

export type ChicmozL2ContractClassRegisteredEvent = z.infer<
typeof chicmozL2ContractClassRegisteredEventSchema
>;

export const chicmozL2ContractInstanceDeluxeSchema = z.object({
...chicmozL2ContractInstanceDeployedEventSchema.shape,
...chicmozL2ContractClassRegisteredEventSchema.shape,
});

// TODO: come up with a better name for this type
export type ChicmozL2ContractInstanceDeluxe =
ChicmozL2ContractInstanceDeployedEvent &
ChicmozL2ContractClassRegisteredEvent;
54 changes: 54 additions & 0 deletions packages/types/src/aztec/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { z } from "zod";

export type AztecFr = {
toString(): string;
};

export type AztecAddress = {
toString(): string;
};

export type StringifiedAztecFr = {
type: "Fr";
value: `0x${string}`;
};

export type StringifiedAztecAddress = {
type: "AztecAddress";
value: `0x${string}`;
};

export const frSchema = z.preprocess(
(val) => {
if ((val as StringifiedAztecFr).value)
return (val as StringifiedAztecFr).value;
else if ((val as AztecFr).toString) return (val as AztecFr).toString();
else return val;
},
z
.string()
.length(66)
.regex(/^0x[0-9a-fA-F]+$/)
);

// NOTE: it's technically not the same as Fr but practically it is
export const aztecAddressSchema = frSchema;

export type StringifiedBuffer = {
type: "Buffer";
data: number[];
};

export const bufferSchema = z.preprocess(
(val) => {
if ((val as StringifiedBuffer).data)
return Buffer.from((val as StringifiedBuffer).data);
return val;
},
z.custom<Buffer>(
(value) => {
return value instanceof Buffer;
},
{ message: "Expected a Buffer" }
)
);
10 changes: 10 additions & 0 deletions packages/types/src/general.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from "zod";

export const hexStringSchema = z.custom<`0x${string}`>(
(value) => {
return (value as string).startsWith("0x");
},
{ message: "Expected a hex string" }
);

export type HexString = z.infer<typeof hexStringSchema>;
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./events.js";
export * from "./aztec/index.js";
export * from "./general.js";
4 changes: 2 additions & 2 deletions packages/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "ESNext" /* Specify what module code is generated. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"module": "NodeNext" /* Specify what module code is generated. */,
"moduleResolution": "NodeNext" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./build" /* Specify an output folder for all emitted files. */,
"rootDir": "./src" /* Specify the root folder within your source files. */,
Expand Down
1 change: 1 addition & 0 deletions services/aztec-listener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "UNLICENSED",
"dependencies": {
"@aztec/aztec.js": "0.53.0",
"@aztec/circuits.js": "0.53.0",
"@chicmoz-pkg/logger-server": "workspace:^",
"@chicmoz-pkg/message-bus": "workspace:^",
"@chicmoz-pkg/message-registry": "workspace:^",
Expand Down
11 changes: 7 additions & 4 deletions services/aztec-listener/scripts/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ async function runMigrations() {
console.log(`Retrying attempt ${attemptNumber} of ${retries}...`);
return true;
}
console.error(e.stack);
console.error(e);
return false;
},
});

console.log("🤩 Migrations complete!");

await pool.end();
console.log("🤩 Migrations complete!");
}

runMigrations().catch(console.error);
runMigrations().catch(async (e) => {
console.error(e);
await pool.end();
process.exit(1);
});
12 changes: 4 additions & 8 deletions services/aztec-listener/src/aztec/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IBackOffOptions, backOff } from "exponential-backoff";
import { NodeInfoAlias } from "@chicmoz-pkg/types";
import { NodeInfo } from "@chicmoz-pkg/types";
import { logger } from "../logger.js";
import {
getLatestHeight,
Expand All @@ -16,11 +16,7 @@ const backOffOptions: Partial<IBackOffOptions> = {
numOfAttempts: 10,
maxDelay: 10000,
retry: (e, attemptNumber: number) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (e.cause)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
logger.warn(e.cause);
else logger.warn(e);
logger.warn(e);

logger.info(
`🤡 We'll allow some errors during start-up, retrying attempt ${attemptNumber}...`
Expand All @@ -29,7 +25,7 @@ const backOffOptions: Partial<IBackOffOptions> = {
},
};

let nodeInfo: NodeInfoAlias;
let nodeInfo: NodeInfo;

export const init = async () => {
if (DISABLE_AZTEC) {
Expand All @@ -51,7 +47,7 @@ export const init = async () => {
// startCatchup({ untilHeight: currentHeight });
// Should it be blocking?

if (LISTEN_FOR_BLOCKS) await startPolling({ fromHeight: currentHeight });
if (LISTEN_FOR_BLOCKS) startPolling({ fromHeight: currentHeight });

return {
shutdownAztec: () => {
Expand Down
Loading