Skip to content

Commit

Permalink
fixup! preserve error reported on failure
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <oss@bajtos.net>
  • Loading branch information
bajtos committed Sep 23, 2024
1 parent 914800c commit 2dc4fa1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/miner-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ import { RPC_URL, RPC_AUTH } from './constants.js'

/**
* @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) {
export async function getMinerPeerId (minerId, { maxAttempts = 5 } = {}) {
try {
const res = await retry(() => rpc('Filecoin.StateMinerInfo', minerId, null), {
// The maximum amount of attempts until failure.
maxAttempts: 5,
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.PeerId
} catch (err) {
if (err.name === 'RetryError' && err.cause) {
// eslint-disable-next-line no-ex-assign
err = err.cause
}
err.message = `Cannot obtain miner info for ${minerId}: ${err.message}`
throw err
}
Expand Down
2 changes: 1 addition & 1 deletion test/miner-info.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('get peer id of a known miner', async () => {

test('get peer id of a miner that does not exist', async () => {
try {
const result = await getMinerPeerId('f010')
const result = await getMinerPeerId('f010', { maxAttempts: 1 })
throw new AssertionError(
`Expected "getMinerPeerId()" to fail, but it resolved with "${result}" instead.`
)
Expand Down

0 comments on commit 2dc4fa1

Please sign in to comment.