Skip to content

Commit 813474c

Browse files
jayantkaditya520
andauthored
Add guide for debugging entropy callbacks (#365)
* Add docs for debugging entropy callbacks * fixes --------- Co-authored-by: Aditya Arora <arora.aditya520@gmail.com>
1 parent 58ce0d7 commit 813474c

File tree

5 files changed

+99
-5
lines changed

5 files changed

+99
-5
lines changed

images/entropy_event_log.png

333 KB
Loading

pages/entropy/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
},
2525

2626
"generate-random-numbers": "Generate Random Numbers",
27+
"debug-callback-failures": "Debug Callback Failures",
2728

2829
"-- Reference Material": {
2930
"title": "Reference Material",
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Debug Callback Failures
2+
3+
This guide explains how to identify and resolve issues with the Entropy callback.
4+
The intended audience for this guide is developers who have made an Entropy random number request, but their application hasn't received a callback.
5+
6+
## Dependencies
7+
8+
This guide uses [Foundry](https://book.getfoundry.sh/getting-started/installation) to submit transactions to the blockchain.
9+
Please install Foundry before continuing.
10+
11+
## Run the Callback
12+
13+
Developers can run the Entropy callback themselves to see the reason for the failure.
14+
To run the callback, invoke the `revealWithCallback` function on the Entropy contract on your blockchain.
15+
The function has the following signature:
16+
17+
```solidity
18+
function revealWithCallback(address provider, uint64 sequenceNumber, bytes32 userRandomNumber, bytes32 providerRevelation)
19+
```
20+
21+
This call requires the chain id, contract address and four arguments.
22+
The chain id and contract address can be retrieved from [Contract Addresses](/entropy/contract-addresses).
23+
Export these values as environment variables for later use:
24+
25+
```bash copy
26+
export CHAIN_ID=blast
27+
export ENTROPY_ADDRESS=0x5744Cbf430D99456a0A8771208b674F27f8EF0Fb
28+
```
29+
30+
Three of the arguments can be retrieved from the request transaction's event logs.
31+
Look at the event logs of the request transaction in a block explorer.
32+
You should see a `RequestedWithCallback` event emitted from the Entropy contract, similar to the one below:
33+
34+
![Example Entropy event logs](../../images/entropy_event_log.png)
35+
36+
Copy the following values from the event into environment variables:
37+
38+
```bash
39+
export PROVIDER=0x52DeaA1c84233F7bb8C8A45baeDE41091c616506
40+
export SEQUENCE_NUMBER=264793
41+
# First row of the "Data" field with a 0x prefix
42+
export USER_RANDOM_NUMBER=0xb1db70cfe95d9e823ac591362921c20eb45f136dbf417362f0a045dc7100519e
43+
```
44+
45+
Next, collect the provider's revelation.
46+
Every provider exposes a URL that allows users to get the provider's revelation for unfulfilled requests.
47+
The URLs for the default providers are as follows:
48+
49+
| Network type | Provider URL |
50+
| ------------ | ---------------------------------------- |
51+
| testnet | `https://fortuna-staging.dourolabs.app/` |
52+
| mainnet | `https://fortuna.dourolabs.app` |
53+
54+
Retrieve the `/v1/chains/$CHAIN_ID/revelations/$SEQUENCE_NUMBER` endpoint from this server:
55+
56+
```bash copy
57+
curl https://fortuna.dourolabs.app/v1/chains/$CHAIN_ID/revelations/$SEQUENCE_NUMBER
58+
```
59+
60+
This endpoint will return the provider's revelation as a hexadecimal value, such as:
61+
62+
```json
63+
{
64+
"value": {
65+
"encoding": "hex",
66+
"data": "5d4bfa3abeaf15fe8b7771c74c0e3e210096015632831460870bc5374e05d4d8"
67+
}
68+
}
69+
```
70+
71+
Export this value as an environment variable (prefixed with 0x):
72+
73+
```bash copy
74+
export PROVIDER_REVELATION=0x5d4bfa3abeaf15fe8b7771c74c0e3e210096015632831460870bc5374e05d4d8
75+
```
76+
77+
Finally, submit the transaction to invoke `revealWithCallback`:
78+
79+
```bash copy
80+
cast send $ENTROPY_ADDRESS 'revealWithCallback(address, uint64, bytes32, bytes32)' $ENTROPY_ADDRESS $SEQUENCE_NUMBER $USER_RANDOM_NUMBER $PROVIDER_REVELATION
81+
```
82+
83+
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.
84+
85+
## Interpeting the Results
86+
87+
If the transaction succeeds, check how much gas the transaction used.
88+
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.
89+
90+
If the transaction fails, it typically indicates a failure originating from the implementation of the callback function.
91+
Check your implementation of the `entropyCallback` function to ensure that it does not throw an error when invoked.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Generate Random Numbers
22

3-
Integrations use a simple one-step on-chain process:
4-
5-
1. **Request** a random number. Send a transaction with a random number that you have generated off-chain and receive a sequence number.
6-
7-
Entropy will callback your contract with the generated random number once the request is fullfilled by the provider.
3+
Integrations simply call an on-chain function to request a random number from Entropy.
4+
This function takes a random number that you have generated off-chain and returns a sequence number.
5+
Entropy will then callback your contract with the generated random number once the request is fullfilled by the provider.
86

97
See [How to Generate Random numbers in EVM dApps](generate-random-numbers/evm.mdx) to integrate your application with Pyth Entropy.

pages/entropy/generate-random-numbers/evm.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ function entropyCallback(
9595
```
9696

9797
When the final random number is ready to use, the entropyCallback function will be called by the Entropy contract. This will happen in a separate transaction submitted by the requested provider. The entropyCallback function should be implemented in the same contract that is requesting the random number.
98+
99+
## Additional Resources
100+
101+
If you are having trouble getting the callback to run, please see the guide on how to [Debug Callback Failures](/entropy/debug-callback-failures).

0 commit comments

Comments
 (0)