-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: lift rollup address check & deplot kv-store to npm (#4483)
This moves the check on rollup address that `AztecLmdbStore.open` used to do to a utility function that's used by the node & pxe. It also publishes it to npm in order to be consumed by external devs. --------- Co-authored-by: PhilWindle <60546371+PhilWindle@users.noreply.github.com>
- Loading branch information
1 parent
e1d3f5a
commit 92d0aa4
Showing
35 changed files
with
184 additions
and
139 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
yarn-project/archiver/src/archiver/kv_archiver_store/kv_archiver_store.test.ts
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
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
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from './array.js'; | ||
export * from './map.js'; | ||
export * from './counter.js'; | ||
export * from './singleton.js'; | ||
export * from './store.js'; | ||
export { Range } from './common.js'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { AztecLmdbStore } from './store.js'; |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { EthAddress } from '@aztec/foundation/eth-address'; | ||
import { Logger } from '@aztec/foundation/log'; | ||
|
||
import { AztecKVStore } from './interfaces/store.js'; | ||
import { AztecLmdbStore } from './lmdb/store.js'; | ||
|
||
/** | ||
* Clears the store if the rollup address does not match the one stored in the database. | ||
* This is to prevent data from being accidentally shared between different rollup instances. | ||
* @param store - The store to check | ||
* @param rollupAddress - The ETH address of the rollup contract | ||
* @returns A promise that resolves when the store is cleared, or rejects if the rollup address does not match | ||
*/ | ||
export async function initStoreForRollup<T extends AztecKVStore>( | ||
store: T, | ||
rollupAddress: EthAddress, | ||
log?: Logger, | ||
): Promise<T> { | ||
const rollupAddressValue = store.openSingleton<ReturnType<EthAddress['toString']>>('rollupAddress'); | ||
const rollupAddressString = rollupAddress.toString(); | ||
const storedRollupAddressString = rollupAddressValue.get(); | ||
|
||
if (typeof storedRollupAddressString !== 'undefined' && storedRollupAddressString !== rollupAddressString) { | ||
log?.warn( | ||
`Rollup address mismatch: expected ${rollupAddress}, found ${rollupAddressValue}. Clearing entire database...`, | ||
); | ||
|
||
await store.clear(); | ||
} | ||
|
||
await rollupAddressValue.set(rollupAddressString); | ||
return store; | ||
} | ||
|
||
/** | ||
* Opens a temporary store for testing purposes. | ||
* @returns A new store | ||
*/ | ||
export function openTmpStore(): AztecKVStore { | ||
return AztecLmdbStore.open(); | ||
} |
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
Oops, something went wrong.