-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor how proving keys are stored and accesssed (#673)
- Loading branch information
1 parent
26bdf12
commit f918770
Showing
7 changed files
with
71 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,42 @@ | ||
import fetch from 'node-fetch'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { provingKeys } from '@penumbra-zone/types/src/proving-keys'; | ||
import { ProvingKey, provingKeysByActionType } from '@penumbra-zone/types/src/proving-keys'; | ||
|
||
const VERSION_TAG = 'v0.68.0'; | ||
const main = () => { | ||
const VERSION_TAG = 'v0.68.0'; | ||
|
||
const githubSourceDir = `https://github.com/penumbra-zone/penumbra/raw/${VERSION_TAG}/crates/crypto/proof-params/src/gen/`; | ||
const githubSourceDir = `https://github.com/penumbra-zone/penumbra/raw/${VERSION_TAG}/crates/crypto/proof-params/src/gen/`; | ||
|
||
const binDir = path.join('bin'); | ||
const binDir = path.join('bin'); | ||
|
||
console.log('Downloading keys', VERSION_TAG, provingKeys.map(({ file }) => file).join(', ')); | ||
const defined = (value: ProvingKey | undefined): value is ProvingKey => Boolean(value); | ||
const provingKeysAsArray = Object.values(provingKeysByActionType).filter(defined); | ||
|
||
fs.mkdirSync(binDir, { recursive: true }); | ||
const downloads = provingKeys.map(async ({ file }) => { | ||
const outputPath = path.join(binDir, file); | ||
const downloadPath = new URL(`${githubSourceDir}${file}`); | ||
console.log( | ||
'Downloading keys', | ||
VERSION_TAG, | ||
provingKeysAsArray.map(({ file }) => file).join(', '), | ||
); | ||
|
||
const response = await fetch(downloadPath); | ||
if (!response.ok) throw new Error(`Failed to fetch ${file}`); | ||
fs.mkdirSync(binDir, { recursive: true }); | ||
const downloads = provingKeysAsArray.map(async ({ file }) => { | ||
const outputPath = path.join(binDir, file); | ||
const downloadPath = new URL(`${githubSourceDir}${file}`); | ||
|
||
const fileStream = fs.createWriteStream(outputPath, { flags: 'w' }); | ||
fileStream.write(Buffer.from(await response.arrayBuffer())); | ||
fileStream.end().close(() => { | ||
const size = fs.statSync(outputPath).size; | ||
const sizeMB = size / 1024 / 1024; | ||
console.log(`Downloaded ${sizeMB.toFixed(2)}MiB ${outputPath}`); | ||
const response = await fetch(downloadPath); | ||
if (!response.ok) throw new Error(`Failed to fetch ${file}`); | ||
|
||
const fileStream = fs.createWriteStream(outputPath, { flags: 'w' }); | ||
fileStream.write(Buffer.from(await response.arrayBuffer())); | ||
fileStream.end().close(() => { | ||
const size = fs.statSync(outputPath).size; | ||
const sizeMB = size / 1024 / 1024; | ||
console.log(`Downloaded ${sizeMB.toFixed(2)}MiB ${outputPath}`); | ||
}); | ||
}); | ||
}); | ||
|
||
void Promise.allSettled(downloads); | ||
void Promise.allSettled(downloads); | ||
}; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,32 @@ | ||
export const provingKeys = [ | ||
{ keyType: 'spend', file: 'spend_pk.bin' }, | ||
{ keyType: 'output', file: 'output_pk.bin' }, | ||
{ keyType: 'swap', file: 'swap_pk.bin' }, | ||
{ keyType: 'swap_claim', file: 'swapclaim_pk.bin' }, | ||
{ keyType: 'nullifier_derivation', file: 'nullifier_derivation_pk.bin' }, | ||
{ keyType: 'delegator_vote', file: 'delegator_vote_pk.bin' }, | ||
{ keyType: 'convert', file: 'convert_pk.bin' }, | ||
]; | ||
import { Action } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/transaction/v1/transaction_pb'; | ||
|
||
type ActionType = Exclude<Action['action']['case'], undefined>; | ||
export interface ProvingKey { | ||
keyType: string; | ||
file: string; | ||
} | ||
|
||
export const provingKeysByActionType: Record<ActionType, ProvingKey | undefined> = { | ||
communityPoolDeposit: undefined, | ||
communityPoolOutput: undefined, | ||
communityPoolSpend: undefined, | ||
delegate: undefined, | ||
delegatorVote: { keyType: 'delegator_vote', file: 'delegator_vote_pk.bin' }, | ||
ibcRelayAction: undefined, | ||
ics20Withdrawal: undefined, | ||
output: { keyType: 'output', file: 'output_pk.bin' }, | ||
positionClose: undefined, | ||
positionOpen: undefined, | ||
positionRewardClaim: undefined, | ||
positionWithdraw: undefined, | ||
proposalDepositClaim: undefined, | ||
proposalSubmit: undefined, | ||
proposalWithdraw: undefined, | ||
spend: { keyType: 'spend', file: 'spend_pk.bin' }, | ||
swap: { keyType: 'swap', file: 'swap_pk.bin' }, | ||
swapClaim: { keyType: 'swap_claim', file: 'swapclaim_pk.bin' }, | ||
undelegate: undefined, | ||
undelegateClaim: { keyType: 'convert', file: 'convert_pk.bin' }, | ||
validatorDefinition: undefined, | ||
validatorVote: undefined, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters