-
Notifications
You must be signed in to change notification settings - Fork 43
fix(dapi): invalid state transition failed with already in chain error #2270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5267e4a
fix(dapi): invalid state transition failed with already in chain error
shumkov d5b6698
chore: accomplished implementation
shumkov 4ca4cb3
test: update broadcastStateTransitionHandler tests
shumkov 10f88c1
chore: handle ECONNRESET error code as well
shumkov 6a5f378
docs: improve JSDocs
shumkov 168032d
refactor: throw RPCError with original error
shumkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
packages/dapi/lib/externalApis/tenderdash/requestTenderRpc.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const UnavailableGrpcError = require('@dashevo/grpc-common/lib/server/error/UnavailableGrpcError'); | ||
const ResourceExhaustedGrpcError = require('@dashevo/grpc-common/lib/server/error/ResourceExhaustedGrpcError'); | ||
const RPCError = require('../../rpcServer/RPCError'); | ||
|
||
/** | ||
* @param {jaysonClient} rpcClient | ||
* @return {requestTenderRpc} A function to make RPC requests to Tenderdash. | ||
*/ | ||
function requestTenderRpcFactory(rpcClient) { | ||
/** | ||
* @function | ||
* @typedef requestTenderRpc | ||
* @param {string} uri | ||
* @param {Object} [params={}] | ||
* @return {Promise<Object>} | ||
*/ | ||
async function requestTenderRpc(uri, params = {}) { | ||
let response; | ||
try { | ||
response = await rpcClient.request(uri, params); | ||
} catch (e) { | ||
if (e.code === 'ECONNRESET' || e.message === 'socket hang up') { | ||
throw new UnavailableGrpcError('Tenderdash is not available'); | ||
} | ||
|
||
throw new RPCError( | ||
e.code || -32602, | ||
`Failed to request ${uri}: ${e.message}`, | ||
e, | ||
); | ||
} | ||
|
||
const { result, error: jsonRpcError } = response; | ||
|
||
if (jsonRpcError) { | ||
if (typeof jsonRpcError.data === 'string') { | ||
if (jsonRpcError.data.includes('too_many_resets')) { | ||
throw new ResourceExhaustedGrpcError('tenderdash is not responding: too many requests'); | ||
} | ||
} | ||
|
||
throw new RPCError( | ||
jsonRpcError.code || -32602, | ||
jsonRpcError.message || 'Internal error', | ||
jsonRpcError.data, | ||
); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
return requestTenderRpc; | ||
} | ||
|
||
module.exports = requestTenderRpcFactory; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.