Skip to content

Commit 48cb8d8

Browse files
authored
perf: add pass tipset to StaterMinerInfo (#105)
This makes it easier for Glif to cache this call.
1 parent 73f9fbb commit 48cb8d8

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

lib/miner-info.js

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
import { retry } from '../vendor/deno-deps.js'
22
import { RPC_URL, RPC_AUTH } from './constants.js'
33

4+
async function getChainHead ({ maxAttempts = 5 } = {}) {
5+
try {
6+
const res = await retry(() => rpc('Filecoin.ChainHead'), {
7+
// The maximum amount of attempts until failure.
8+
maxAttempts,
9+
// The initial and minimum amount of milliseconds between attempts.
10+
minTimeout: 5_000,
11+
// How much to backoff after each retry.
12+
multiplier: 1.5
13+
})
14+
return res.Cids
15+
} catch (err) {
16+
if (err.name === 'RetryError' && err.cause) {
17+
// eslint-disable-next-line no-ex-assign
18+
err = err.cause
19+
}
20+
err.message = `Cannot obtain chain head: ${err.message}`
21+
throw err
22+
}
23+
}
24+
425
/**
526
* @param {string} minerId A miner actor id, e.g. `f0142637`
627
* @param {object} options
728
* @param {number} [options.maxAttempts]
829
* @returns {Promise<string>} Miner's PeerId, e.g. `12D3KooWMsPmAA65yHAHgbxgh7CPkEctJHZMeM3rAvoW8CZKxtpG`
930
*/
1031
export async function getMinerPeerId (minerId, { maxAttempts = 5 } = {}) {
32+
const chainHead = await getChainHead({ maxAttempts })
1133
try {
12-
const res = await retry(() => rpc('Filecoin.StateMinerInfo', minerId, null), {
34+
const res = await retry(() => rpc('Filecoin.StateMinerInfo', minerId, chainHead), {
1335
// The maximum amount of attempts until failure.
1436
maxAttempts,
1537
// The initial and minimum amount of milliseconds between attempts.

0 commit comments

Comments
 (0)