-
Notifications
You must be signed in to change notification settings - Fork 27
fix: pieceStatus confuses piece ownership. Closes #296 #655
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
62179c1
fix(storage): `pieceStatus()` should check if piece in data set. #296
juliangruber 5717641
remove `hasPiece()` method, read from contract instead
juliangruber 047b42a
read and compare with contract state
juliangruber 30e3f96
run all async operations in parallel
juliangruber 2cb9a80
use on-chain state
juliangruber 6e0dcb2
use on-chain state
juliangruber 78afd2d
use on-chain state
juliangruber 26897c4
Merge branch 'master' into fix/piece-status-data-set
juliangruber 3242188
clean up
juliangruber 3ec6ab1
clean up
juliangruber 3bcbb7b
Apply suggestions from code review
juliangruber 8db206c
remove calls to SP
juliangruber 85a78f9
clean up diff
juliangruber 80ee3e4
Merge branch 'master' into fix/piece-status-data-set
juliangruber dd74125
Update packages/synapse-core/src/mocks/jsonrpc/pdp.ts
juliangruber e4cd1c3
Update packages/synapse-core/src/pdp-verifier/get-next-challenge-epoc…
juliangruber 958ee6b
clean up
juliangruber 341e493
fixup! clean up
juliangruber 2026609
fix lint
juliangruber 347d83e
remove unused import
juliangruber 60bbbbe
return `null` if doesn't exist
juliangruber 5f0cdab
simplify
juliangruber b11ef4f
Merge branch 'master' into fix/piece-status-data-set
juliangruber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
117 changes: 117 additions & 0 deletions
117
packages/synapse-core/src/pdp-verifier/get-next-challenge-epoch.ts
This file contains hidden or 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,117 @@ | ||
| import type { Simplify } from 'type-fest' | ||
| import type { | ||
| Address, | ||
| Chain, | ||
| Client, | ||
| ContractFunctionParameters, | ||
| ContractFunctionReturnType, | ||
| ReadContractErrorType, | ||
| Transport, | ||
| } from 'viem' | ||
| import { readContract } from 'viem/actions' | ||
| import type { pdpVerifierAbi } from '../abis/generated.ts' | ||
| import { asChain } from '../chains.ts' | ||
| import type { ActionCallChain } from '../types.ts' | ||
|
|
||
| export namespace getNextChallengeEpoch { | ||
| export type OptionsType = { | ||
| /** The ID of the data set to get next challenge epoch for. */ | ||
| dataSetId: bigint | ||
| /** PDP Verifier contract address. If not provided, the default is the PDP Verifier contract address for the chain. */ | ||
| contractAddress?: Address | ||
| } | ||
|
|
||
| export type OutputType = bigint | ||
| /** | ||
| * `uint256` | ||
| */ | ||
| export type ContractOutputType = ContractFunctionReturnType< | ||
| typeof pdpVerifierAbi, | ||
| 'pure' | 'view', | ||
| 'getNextChallengeEpoch' | ||
| > | ||
|
|
||
| export type ErrorType = asChain.ErrorType | ReadContractErrorType | ||
| } | ||
|
|
||
| /** | ||
| * Get next challenge epoch | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { getNextChallengeEpoch } from '@filoz/synapse-core/pdp-verifier' | ||
| * import { calibration } from '@filoz/synapse-core/chains' | ||
| * import { createPublicClient, http } from 'viem' | ||
| * | ||
| * const client = createPublicClient({ | ||
| * chain: calibration, | ||
| * transport: http(), | ||
| * }) | ||
| * | ||
| * const nextChallengeEpoch = await getNextChallengeEpoch(client, { | ||
| * dataSetId: 1n, | ||
| * }) | ||
| * ``` | ||
| * | ||
| * @param client - The client to use to get the active pieces. | ||
| * @param options - {@link getNextChallengeEpoch.OptionsType} | ||
| * @returns The next challenge epoch for the data set {@link getNextChallengeEpoch.OutputType} | ||
| * @throws Errors {@link getNextChallengeEpoch.ErrorType} | ||
| */ | ||
| export async function getNextChallengeEpoch( | ||
| client: Client<Transport, Chain>, | ||
| options: getNextChallengeEpoch.OptionsType | ||
| ): Promise<getNextChallengeEpoch.OutputType> { | ||
| const data = await readContract( | ||
| client, | ||
| getNextChallengeEpochCall({ | ||
| chain: client.chain, | ||
| dataSetId: options.dataSetId, | ||
| contractAddress: options.contractAddress, | ||
| }) | ||
| ) | ||
| return data | ||
| } | ||
|
|
||
| export namespace getNextChallengeEpochCall { | ||
| export type OptionsType = Simplify<getNextChallengeEpoch.OptionsType & ActionCallChain> | ||
| export type ErrorType = asChain.ErrorType | ||
| export type OutputType = ContractFunctionParameters<typeof pdpVerifierAbi, 'pure' | 'view', 'getNextChallengeEpoch'> | ||
| } | ||
|
|
||
| /** | ||
| * Create a call to the {@link getNextChallengeEpoch} function for use with the multicall or readContract function. | ||
| * | ||
| * @example | ||
| * ```ts | ||
| * import { getNextChallengeEpochCall } from '@filoz/synapse-core/pdp-verifier' | ||
| * import { calibration } from '@filoz/synapse-core/chains' | ||
| * import { createPublicClient, http } from 'viem' | ||
| * import { multicall } from 'viem/actions' | ||
| * | ||
| * const client = createPublicClient({ | ||
| * chain: calibration, | ||
| * transport: http(), | ||
| * }) | ||
| * | ||
| * const results = await multicall(client, { | ||
| * contracts: [ | ||
| * getNextChallengeEpochCall({ chain: calibration, dataSetId: 1n }), | ||
| * getNextChallengeEpochCall({ chain: calibration, dataSetId: 101n }), | ||
| * ], | ||
| * }) | ||
| * ``` | ||
| * | ||
| * @param options - {@link getNextChallengeEpochCall.OptionsType} | ||
| * @returns The call to the getNextChallengeEpoch function {@link getNextChallengeEpochCall.OutputType} | ||
| * @throws Errors {@link getNextChallengeEpochCall.ErrorType} | ||
| */ | ||
| export function getNextChallengeEpochCall(options: getNextChallengeEpochCall.OptionsType) { | ||
| const chain = asChain(options.chain) | ||
| return { | ||
| abi: chain.contracts.pdp.abi, | ||
| address: options.contractAddress ?? chain.contracts.pdp.address, | ||
| functionName: 'getNextChallengeEpoch', | ||
| args: [options.dataSetId], | ||
| } satisfies getNextChallengeEpochCall.OutputType | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.