-
Notifications
You must be signed in to change notification settings - Fork 45
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
perf: unnecessary call to arweave.networkInfo when block height is re… #71
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af38c24
feat: contract definition load impl from RedStone Gateway
ppedziwiatr 936211d
perf: unnecessary call to arweave.networkInfo when block height is re…
ppedziwiatr a33210b
test: stable stringify in tests, new regression testcase
ppedziwiatr a46cc05
docs: performance best practices
ppedziwiatr 6858537
feat: saving last state read benchmark result
ppedziwiatr 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
This file contains 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 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 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
[ | ||
"Daj-MNSnH55TDfxqC7v4eq0lKzVIwh98srUaWqyuZtY", | ||
"t9T7DIOGxx4VWXoCEeYYarFYeERTpWIC1V3y-BPZgKE", | ||
"5pSyVjFI07z8mbLeQhYBMsQ4M_MPidXIGX6T77rnF2s", | ||
"-8A6RexFkpfWwuyVO98wzSFZh0d6VJuI-buTJvlwOJQ", | ||
"AVTqjPQGCCXim7Nl_gn3HMjE4k0Zi_eTFRJCNEVXZxw", | ||
|
@@ -86,7 +87,6 @@ | |
"2caOW6ol9T8LHCMO8tVAx4GHRwv1q3fFc79KzKOtoww", | ||
"HdZBZa0GfOEUYCubwvoSyxGUUgPmgy7RJb5l77T21bE", | ||
"7Dp5r-UpZLDvHqsDbZbqWhCBwbYdJMKBuC3tFC-FF7U", | ||
"YLVpmhSq5JmLltfg6R-5fL04rIRPrlSU22f6RQ6VyYE", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing. Slowing down the whole SDK just because of this one, abandoned contract, is not very wise :-) |
||
"EOtTxCGktZe_J2DTM0D5h04crjlpjgeygA1R6Pmo_qM", | ||
"92Tq6BKm6pvVkKW8_6Fb13QWTdUzBRLnG9scMBNWYZ4", | ||
"w27141UQGgrCFhkiw9tL7A0-qWMQjbapU3mq2TfI4Cg", | ||
|
This file contains 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 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 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 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 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 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
48 changes: 48 additions & 0 deletions
48
src/core/modules/impl/RedstoneGatewayContractDefinitionLoader.ts
This file contains 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,48 @@ | ||
import { ContractDefinition, LoggerFactory, stripTrailingSlash, SwCache } from '@smartweave'; | ||
import Arweave from 'arweave'; | ||
import 'isomorphic-fetch'; | ||
import { ContractDefinitionLoader } from './ContractDefinitionLoader'; | ||
|
||
/** | ||
* An extension to {@link ContractDefinitionLoader} that makes use of | ||
* Redstone Gateway ({@link https://github.com/redstone-finance/redstone-sw-gateway}) | ||
* to load Contract Data. | ||
* | ||
* If the contract data is not available on RedStone Gateway - it fallbacks to default implementation | ||
* in {@link ContractDefinitionLoader} - i.e. loads the definition from Arweave gateway. | ||
*/ | ||
export class RedstoneGatewayContractDefinitionLoader extends ContractDefinitionLoader { | ||
ppedziwiatr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private readonly rLogger = LoggerFactory.INST.create('RedstoneGatewayContractDefinitionLoader'); | ||
|
||
constructor( | ||
private readonly baseUrl: string, | ||
arweave: Arweave, | ||
cache?: SwCache<string, ContractDefinition<unknown>> | ||
) { | ||
super(arweave, cache); | ||
this.baseUrl = stripTrailingSlash(baseUrl); | ||
} | ||
|
||
async doLoad<State>(contractTxId: string, forcedSrcTxId?: string): Promise<ContractDefinition<State>> { | ||
if (forcedSrcTxId) { | ||
// no support for the evolve yet.. | ||
return await super.doLoad(contractTxId, forcedSrcTxId); | ||
} | ||
|
||
try { | ||
return await fetch(`${this.baseUrl}/gateway/contracts/${contractTxId}`) | ||
.then((res) => { | ||
return res.ok ? res.json() : Promise.reject(res); | ||
}) | ||
.catch((error) => { | ||
if (error.body?.message) { | ||
this.rLogger.error(error.body.message); | ||
} | ||
throw new Error(`Unable to retrieve contract data. Redstone gateway responded with status ${error.status}.`); | ||
}); | ||
} catch (e) { | ||
this.rLogger.warn('Falling back to default contracts loader'); | ||
return await super.doLoad(contractTxId, forcedSrcTxId); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the
t9T7DIOGxx4VWXoCEeYYarFYeERTpWIC1V3y-BPZgKE
contract the JSON.stringify turned to be non-deterministic.