Skip to content

Commit

Permalink
Bundle mainnet genesis state (#165)
Browse files Browse the repository at this point in the history
* Bundle mainnet genesis

* convert type to json object

* default fields for genesis block

* use binary proto encoded format

* modify deserialization vitest

* update packages

---------

Co-authored-by: Tal Derei <[email protected]>
Co-authored-by: turbocrime <[email protected]>
  • Loading branch information
3 people authored Aug 20, 2024
1 parent bbf940d commit edd6fac
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 121 deletions.
16 changes: 8 additions & 8 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
"@penumbra-labs/registry": "11.0.0",
"@penumbra-zone/bech32m": "^7.0.0",
"@penumbra-zone/client": "^18.0.0",
"@penumbra-zone/crypto-web": "^21.0.0",
"@penumbra-zone/getters": "^15.0.0",
"@penumbra-zone/crypto-web": "^22.0.0",
"@penumbra-zone/getters": "^16.0.0",
"@penumbra-zone/keys": "^4.2.1",
"@penumbra-zone/perspective": "^25.0.0",
"@penumbra-zone/perspective": "^26.0.0",
"@penumbra-zone/protobuf": "^6.0.0",
"@penumbra-zone/query": "^26.0.0",
"@penumbra-zone/services": "^29.0.0",
"@penumbra-zone/storage": "^25.0.0",
"@penumbra-zone/query": "^27.0.0",
"@penumbra-zone/services": "^30.0.0",
"@penumbra-zone/storage": "^26.0.0",
"@penumbra-zone/transport-chrome": "^8.0.1",
"@penumbra-zone/transport-dom": "^7.5.0",
"@penumbra-zone/types": "^20.0.0",
"@penumbra-zone/wasm": "^25.0.0",
"@penumbra-zone/types": "^21.0.0",
"@penumbra-zone/wasm": "^26.0.0",
"@radix-ui/react-icons": "^1.3.0",
"@repo/context": "workspace:*",
"@repo/ui": "workspace:*",
Expand Down
Binary file added apps/extension/public/penumbra-1-genesis.bin
Binary file not shown.
19 changes: 10 additions & 9 deletions packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "(MIT OR Apache-2.0)",
"type": "module",
"scripts": {
"lint": "eslint \"**/*.ts*\""
"lint": "eslint \"**/*.ts*\"",
"test": "vitest run"
},
"files": [
"src/",
Expand All @@ -18,17 +19,17 @@
"@bufbuild/protobuf": "^1.10.0",
"@penumbra-labs/registry": "11.0.0",
"@penumbra-zone/bech32m": "^7.0.0",
"@penumbra-zone/crypto-web": "^21.0.0",
"@penumbra-zone/getters": "^15.0.0",
"@penumbra-zone/perspective": "^25.0.0",
"@penumbra-zone/crypto-web": "^22.0.0",
"@penumbra-zone/getters": "^16.0.0",
"@penumbra-zone/perspective": "^26.0.0",
"@penumbra-zone/protobuf": "^6.0.0",
"@penumbra-zone/query": "^26.0.0",
"@penumbra-zone/services": "^29.0.0",
"@penumbra-zone/storage": "^25.0.0",
"@penumbra-zone/query": "^27.0.0",
"@penumbra-zone/services": "^30.0.0",
"@penumbra-zone/storage": "^26.0.0",
"@penumbra-zone/transport-chrome": "^8.0.1",
"@penumbra-zone/transport-dom": "^7.5.0",
"@penumbra-zone/types": "^20.0.0",
"@penumbra-zone/wasm": "^25.0.0",
"@penumbra-zone/types": "^21.0.0",
"@penumbra-zone/wasm": "^26.0.0",
"exponential-backoff": "^3.1.1"
}
}
12 changes: 12 additions & 0 deletions packages/context/src/genesis.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, test, expect } from 'vitest';
import { CompactBlock } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/compact_block/v1/compact_block_pb';
import { join } from 'path';
import { readFileSync } from 'fs';

describe('Genesis block type conversion', () => {
test('penumbra-1 deserializes correctly', () => {
const filePath = join(__dirname, '../../../apps/extension/public/penumbra-1-genesis.bin');
const genesisBinaryData = readFileSync(filePath);
expect(() => CompactBlock.fromBinary(new Uint8Array(genesisBinaryData))).not.toThrow();
});
});
9 changes: 9 additions & 0 deletions packages/context/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FullViewingKey, WalletId } from '@penumbra-zone/protobuf/penumbra/core/
import { ChainRegistryClient } from '@penumbra-labs/registry';
import { AppParameters } from '@penumbra-zone/protobuf/penumbra/core/app/v1/app_pb';
import { AssetId } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb';
import { CompactBlock } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/compact_block/v1/compact_block_pb';

export interface ServicesConfig {
readonly chainId: string;
Expand Down Expand Up @@ -103,7 +104,15 @@ export class Services implements ServicesInterface {
idbConstants: indexedDb.constants(),
});

// Dynamically fetch binary file for genesis compact block
const response = await fetch('./penumbra-1-genesis.bin');
const genesisBinaryData = await response.arrayBuffer();

const blockProcessor = new BlockProcessor({
genesisBlock:
chainId === 'penumbra-1'
? CompactBlock.fromBinary(new Uint8Array(genesisBinaryData))
: undefined,
viewServer,
querier,
indexedDb,
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
"@emotion/styled": "^11.11.5",
"@penumbra-labs/registry": "11.0.0",
"@penumbra-zone/bech32m": "^7.0.0",
"@penumbra-zone/getters": "^15.0.0",
"@penumbra-zone/perspective": "^25.0.0",
"@penumbra-zone/getters": "^16.0.0",
"@penumbra-zone/perspective": "^26.0.0",
"@penumbra-zone/protobuf": "^6.0.0",
"@penumbra-zone/types": "^20.0.0",
"@penumbra-zone/wasm": "^25.0.0",
"@penumbra-zone/types": "^21.0.0",
"@penumbra-zone/wasm": "^26.0.0",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "1.0.5",
Expand Down
Loading

0 comments on commit edd6fac

Please sign in to comment.