Skip to content

Commit

Permalink
perf: add pass tipset to StaterMinerInfo (#105)
Browse files Browse the repository at this point in the history
This makes it easier for Glif to cache this call.
  • Loading branch information
juliangruber authored Jan 28, 2025
1 parent 73f9fbb commit 48cb8d8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/miner-info.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import { retry } from '../vendor/deno-deps.js'
import { RPC_URL, RPC_AUTH } from './constants.js'

async function getChainHead ({ maxAttempts = 5 } = {}) {
try {
const res = await retry(() => rpc('Filecoin.ChainHead'), {
// The maximum amount of attempts until failure.
maxAttempts,
// The initial and minimum amount of milliseconds between attempts.
minTimeout: 5_000,
// How much to backoff after each retry.
multiplier: 1.5
})
return res.Cids
} catch (err) {
if (err.name === 'RetryError' && err.cause) {
// eslint-disable-next-line no-ex-assign
err = err.cause
}
err.message = `Cannot obtain chain head: ${err.message}`
throw err
}
}

/**
* @param {string} minerId A miner actor id, e.g. `f0142637`
* @param {object} options
* @param {number} [options.maxAttempts]
* @returns {Promise<string>} Miner's PeerId, e.g. `12D3KooWMsPmAA65yHAHgbxgh7CPkEctJHZMeM3rAvoW8CZKxtpG`
*/
export async function getMinerPeerId (minerId, { maxAttempts = 5 } = {}) {
const chainHead = await getChainHead({ maxAttempts })
try {
const res = await retry(() => rpc('Filecoin.StateMinerInfo', minerId, null), {
const res = await retry(() => rpc('Filecoin.StateMinerInfo', minerId, chainHead), {
// The maximum amount of attempts until failure.
maxAttempts,
// The initial and minimum amount of milliseconds between attempts.
Expand Down

0 comments on commit 48cb8d8

Please sign in to comment.