Skip to content

Commit 7e7b863

Browse files
authored
Merge pull request #2 from rpcpool/feb2025-fixes
Refactor
2 parents e7becbe + f86d6da commit 7e7b863

File tree

3 files changed

+525
-347
lines changed

3 files changed

+525
-347
lines changed

README.md

Lines changed: 10 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -5,98 +5,30 @@ Validate PoH (proof of history) on the data in an epoch CAR file.
55
## Usage
66

77

8+
Automatically find all the limits and assertions via RPC:
9+
810
```bash
911
$ poh-check-car \
1012
--workers=12 \
11-
--auto \
1213
--epoch=0 \
13-
--car=/media/laptop/solana-history/cars/epoch-0.car
14+
--car=/media/runner/solana-2/cars/epoch-0.car
1415
```
1516

16-
OR with more options:
17+
OR provide the limits and assertions manually:
1718

1819
```bash
1920
$ poh-check-car \
2021
--workers=12 \
2122
--epoch=0 \
2223
--car=/media/laptop/solana-history/cars/epoch-0.car \
23-
--prevhash=5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d
24-
```
25-
26-
To find the prevhash, use
27-
28-
```bash
29-
POH_CHECK_EPOCH=131
30-
POH_CHECK_EPOCH_FIRST_SLOT=$((POH_CHECK_EPOCH * 432000))
31-
32-
# use getBlocks to find the actual slot
33-
POH_CHECK_EPOCH_FIRST_SLOT=$(curl https://api.mainnet-beta.solana.com -X POST -H "Content-Type: application/json" -d '
34-
{"jsonrpc": "2.0", "id": "99", "method": "getBlocks", "params": ['$POH_CHECK_EPOCH_FIRST_SLOT', '$((POH_CHECK_EPOCH_FIRST_SLOT + 1000))'] }' | jq -r '.result[0]'
35-
)
36-
37-
# check that POH_CHECK_EPOCH_FIRST_SLOT has a value, and is a number
38-
if [[ -z "$POH_CHECK_EPOCH_FIRST_SLOT" || ! "$POH_CHECK_EPOCH_FIRST_SLOT" =~ ^[0-9]+$ ]]; then
39-
echo "Failed to find the first slot for epoch $POH_CHECK_EPOCH"
40-
exit 1
41-
fi
42-
43-
POH_CHECK_FIRST_SLOT_DATA=$(curl https://api.mainnet-beta.solana.com \
44-
-X POST \
45-
-H "Content-Type: application/json" \
46-
--data '{"jsonrpc":"2.0","id":1, "method":"getBlock","params":['$POH_CHECK_EPOCH_FIRST_SLOT',{"transactionDetails":"none","rewards":false}]}')
47-
48-
POH_CHECK_PREVIOUS_BLOCKHASH=$(echo $POH_CHECK_FIRST_SLOT_DATA | jq -r '.result.previousBlockhash')
49-
POH_CHECK_PREVIOUS_SLOT=$(echo $POH_CHECK_FIRST_SLOT_DATA | jq -r '.result.parentSlot')
50-
51-
# check that POH_CHECK_PREVIOUS_BLOCKHASH has a value, and is a string without spaces and is base58
52-
if [[ -z "$POH_CHECK_PREVIOUS_BLOCKHASH" || ! "$POH_CHECK_PREVIOUS_BLOCKHASH" =~ ^[1-9A-HJ-NP-Za-km-z]+$ ]]; then
53-
echo "Failed to find the previous blockhash for epoch $POH_CHECK_EPOCH 's first slot $POH_CHECK_EPOCH_FIRST_SLOT"
54-
exit 1
55-
fi
56-
57-
echo "Epoch $POH_CHECK_EPOCH 's first slot is $POH_CHECK_EPOCH_FIRST_SLOT; its parent slot is $POH_CHECK_PREVIOUS_SLOT which has blockhash $POH_CHECK_PREVIOUS_BLOCKHASH"
58-
59-
echo "Use that as the --prevhash argument to poh-check-car like this:"
60-
61-
echo "poh-check-car --workers=12 --car=/media/laptop/solana-history/cars/epoch-$POH_CHECK_EPOCH.car --prevhash=$POH_CHECK_PREVIOUS_BLOCKHASH --epoch=$POH_CHECK_EPOCH"
62-
63-
# now calculate the last slot of the epoch, and the last blockhash by using the previous slot of next epoch
64-
POH_NEXT_EPOCH=$(($POH_CHECK_EPOCH + 1))
65-
POH_NEXT_EPOCH_FIRST_SLOT=$((POH_NEXT_EPOCH * 432000))
66-
67-
# use getBlocks to find the actual slot
68-
POH_NEXT_EPOCH_FIRST_SLOT=$(curl https://api.mainnet-beta.solana.com -s -X POST -H "Content-Type: application/json" -d '
69-
{"jsonrpc": "2.0", "id": "99", "method": "getBlocks", "params": ['$POH_NEXT_EPOCH_FIRST_SLOT', '$((POH_NEXT_EPOCH_FIRST_SLOT + 1000))'] }' | jq -r '.result[0]'
70-
)
71-
72-
# check that POH_NEXT_EPOCH_FIRST_SLOT has a value, and is a number
73-
if [[ -z "$POH_NEXT_EPOCH_FIRST_SLOT" || ! "$POH_NEXT_EPOCH_FIRST_SLOT" =~ ^[0-9]+$ ]]; then
74-
echo "Failed to find the first slot for epoch $POH_NEXT_EPOCH"
75-
exit 1
76-
fi
77-
78-
POH_NEXT_EPOCH_FIRST_SLOT_DATA=$(curl https://api.mainnet-beta.solana.com \
79-
-X POST -s \
80-
-H "Content-Type: application/json" \
81-
--data '{"jsonrpc":"2.0","id":1, "method":"getBlock","params":['$POH_NEXT_EPOCH_FIRST_SLOT',{"transactionDetails":"none","rewards":false}]}')
82-
83-
POH_NEXT_EPOCH_PREVIOUS_BLOCKHASH=$(echo $POH_NEXT_EPOCH_FIRST_SLOT_DATA | jq -r '.result.previousBlockhash')
84-
POH_NEXT_EPOCH_PREVIOUS_SLOT=$(echo $POH_NEXT_EPOCH_FIRST_SLOT_DATA | jq -r '.result.parentSlot')
85-
86-
# check that POH_NEXT_EPOCH_PREVIOUS_BLOCKHASH has a value, and is a string without spaces and is base58
87-
if [[ -z "$POH_NEXT_EPOCH_PREVIOUS_BLOCKHASH" || ! "$POH_NEXT_EPOCH_PREVIOUS_BLOCKHASH" =~ ^[1-9A-HJ-NP-Za-km-z]+$ ]]; then
88-
echo "Failed to find the previous blockhash for epoch $POH_NEXT_EPOCH 's first slot $POH_NEXT_EPOCH_FIRST_SLOT"
89-
exit 1
90-
fi
91-
92-
echo "Epoch $POH_CHECK_EPOCH 's last slot is $POH_NEXT_EPOCH_PREVIOUS_SLOT with blockhash $POH_NEXT_EPOCH_PREVIOUS_BLOCKHASH"
93-
94-
echo "Use --assert-last-slot=$POH_NEXT_EPOCH_PREVIOUS_SLOT --assert-last-hash=$POH_NEXT_EPOCH_PREVIOUS_BLOCKHASH to check the last slot and blockhash of the epoch"
95-
96-
echo "If you don't want to see the progress bar, use --no-progress"
24+
--prev-hash=5eykt4UsFv8P8NJdTREpY1vzqKqZKvdpKuc147dw2N9d \
25+
--first-slot=0 \
26+
--first-hash=4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZAMdL4VZHirAn \
27+
--last-slot=431999 \
28+
--last-hash=4WxiJQL77oMLb8mkQ3vQynd6DVhhqttdZkC1gQKy1Dcy
9729
```
9830

99-
NOTE: for epoch 0, the `--prevhash` is the genesis hash.
31+
NOTE: for epoch 0, the `--prev-hash` is the genesis hash.
10032

10133
```bash
10234
$ curl https://api.mainnet-beta.solana.com \

0 commit comments

Comments
 (0)