-
Notifications
You must be signed in to change notification settings - Fork 35
Add guide for debugging entropy callbacks #365
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Debug Callback Failures | ||
|
||
This guide explains how to identify and resolve issues with the Entropy callback. | ||
The intended audience for this guide is developers who have made an Entropy random number request, but their application hasn't received a callback. | ||
|
||
## Dependencies | ||
|
||
This guide uses [Foundry](https://book.getfoundry.sh/getting-started/installation) to submit transactions to the blockchain. | ||
Please install Foundry before continuing. | ||
|
||
## Run the Callback | ||
|
||
Developers can run the Entropy callback themselves to see the reason for the failure. | ||
To run the callback, invoke the `revealWithCallback` function on the Entropy contract on your blockchain. | ||
The function has the following signature: | ||
|
||
```solidity | ||
function revealWithCallback(address provider, uint64 sequenceNumber, bytes32 userRandomNumber, bytes32 providerRevelation) | ||
``` | ||
|
||
This call requires the chain id, contract address and four arguments. | ||
The chain id and contract address can be retrieved from [Contract Addresses](/entropy/contract-addresses). | ||
Export these values as environment variables for later use: | ||
|
||
```bash | ||
export CHAIN_ID=blast | ||
export ENTROPY_ADDRESS=0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb | ||
``` | ||
|
||
Three of the arguments can be retrieved from the request transaction's event logs. | ||
Look at the event logs of the request transaction in a block explorer. | ||
You should see a `RequestedWithCallback` event emitted from the Entropy contract, similar to the one below: | ||
|
||
 | ||
|
||
Copy the following values from the event into environment variables: | ||
|
||
```bash | ||
export PROVIDER=0x52DeaA1c84233F7bb8C8A45baeDE41091c616506 | ||
export SEQUENCE_NUMBER=264793 | ||
# First row of the "Data" field with a 0x prefix | ||
export USER_RANDOM_NUMBER=0xb1db70cfe95d9e823ac591362921c20eb45f136dbf417362f0a045dc7100519e | ||
``` | ||
|
||
Next, collect the provider's revelation. | ||
Every provider exposes a URL which allows users to get the provider's revelation for unfulfilled requests. | ||
The URLs for the default providers are as follows: | ||
|
||
| Network type | Provider URL | | ||
| ------------ | ---------------------------------------- | | ||
| testnet | `https://fortuna-staging.dourolabs.app/` | | ||
| mainnet | `https://fortuna.dourolabs.app` | | ||
|
||
Retrieve the `/v1/chains/$CHAIN_ID/revelations/$SEQUENCE_NUMBER` endpoint from this server: | ||
|
||
```bash | ||
curl https://fortuna.dourolabs.app/v1/chains/$CHAIN_ID/revelations/$SEQUENCE_NUMBER | ||
``` | ||
|
||
This endpoint will return the provider's revelation as a hexadecimal value, such as: | ||
|
||
```json | ||
{ | ||
"value": { | ||
"encoding": "hex", | ||
"data": "5d4bfa3abeaf15fe8b7771c74c0e3e210096015632831460870bc5374e05d4d8" | ||
} | ||
} | ||
``` | ||
|
||
Export this value as an environment variable (prefixed with 0x): | ||
|
||
```bash | ||
export PROVIDER_REVELATION=0x5d4bfa3abeaf15fe8b7771c74c0e3e210096015632831460870bc5374e05d4d8 | ||
``` | ||
|
||
Finally, submit the transaction to invoke `revealWithCallback`: | ||
|
||
```bash | ||
cast send $ENTROPY_ADDRESS 'revealWithCallback(address, uint64, bytes32, bytes32)' $ENTROPY_ADDRESS $SEQUENCE_NUMBER $USER_RANDOM_NUMBER $PROVIDER_REVELATION | ||
``` | ||
|
||
You may also need to provide the `-r` with an RPC for your chain, plus an additional argument (such as `--private-key`) to specify the wallet to use to sign the transaction. | ||
|
||
## Interpeting the Results | ||
|
||
If the transaction succeeds, check how much gas the transaction used. | ||
If the gas exceeds the callback gas limit for your chain as shown on [Contract Addresses](/entropy/contract-addresses), please reduce the gas usage to allow the provider to invoke the callback in the future. | ||
|
||
If the transaction fails, it typically indicates a failure originating from the implementation of the callback function. | ||
Check your implementation of the `entropyCallback` function to ensure that it does not throw an error when invoked. |
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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
# Generate Random Numbers | ||
|
||
Integrations use a simple one-step on-chain process: | ||
|
||
1. **Request** a random number. Send a transaction with a random number that you have generated off-chain and receive a sequence number. | ||
|
||
Entropy will callback your contract with the generated random number once the request is fullfilled by the provider. | ||
Integrations simply call an on-chain function to request a random number from Entropy. | ||
This function takes a random number that you have generated off-chain and returns a sequence number. | ||
Entropy will then callback your contract with the generated random number once the request is fullfilled by the provider. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive-by simplification of the text here |
||
|
||
See [How to Generate Random numbers in EVM dApps](generate-random-numbers/evm.mdx) to integrate your application with Pyth Entropy. |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we give a small explanation here about these arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to stick to the diataxis guideline to avoid explanation in how-to guides. I also think anyone reading this guide will know what these are (because they wrote the code to integrate the software in the first place)