-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add config.json based pre and post-processing #1008
Conversation
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.
Overall looks good to me. But I have some questions.
Do we want to land this to master
now? Shall it be released as part of 0.6 or we should first release 0.6 and then add this as part of 0.7?
If possible we should wait till 0.6 is released (shouldn't be long now, everything needed is merged it just needs to be tested). Worst case we should merge it to 0.7 branch and wait for the 0.6 release before merging is to master. But if think keeping it open is fine in this situation. |
Co-authored-by: Emanuel Tesař <[email protected]>
9d32273
to
e133372
Compare
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.
@aquarat I wanted to do sooner, but yesteday got unexpectedly busy for me so I found some more time today. Please take a look.
I will be heading off to vacation shortly, but will be able to take a look on Sunday :D
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.
Looks good, just a note, when looking up eval I came across Function which seems to be the preferred over eval due to the scope eval is invoked in . Here is the same code using Function someone else can have a look
function execute(_input: any, code: string) {
// this is the recommended way of executing code with Function
return Function(`
"use strict";
const ethers = require('ethers');
const {BigNumber} = ethers;
const input = _input;
${code};
return output;
`)(_input);
}
Interesting, I thought that I think for now this is fine, but thanks for pointing out |
@Siegrift Thanks for introducing these changes. It's perfect for now IMO. |
I agree with @Ashar2shahid suggestion. I do not see any reason why the postprocessing should have access to Airnode internals that we can are to change freely. That code should only care about One thing, shall we expose |
return Function(` | ||
"use strict"; | ||
const [ethers, input] = arguments | ||
const {BigNumber} = ethers; |
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.
@aquarat shall we have this line here? I am not sure why only expose BigNumber drectly and not other stuff.
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.
We can remove it, no problem :)
(To avoid ambiguity, the developer can be expected to import everything they need)
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.
...that was fast @ commit :P
Yes the more I think about it , we should definitely use Function instead, say the provider sets an |
All good, |
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.
I think this is good to go, but since I was the co-author I think someone else should give an approve as well.
Maybe @Ashar2shahid or @amarthadan
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.
Yeah looks good to me
I just tried using this for a real task and I needed to import various libraries. Unfortunately neither I could have gotten around the limitation by inserting a chunk of the of the libraries I wanted (lodash), but that just seems unfortunate and unnecessarily inefficient. I think If we really must have |
Ok, I'll revert it back to use |
Sorry for being difficult and thank you :) I'll make a few notes for when we document this (initially and for some time to come for our internal use). |
Just an additional note; I'm actively using this code and I've discovered a few interesting quirks along the way that we may want to address prior to merging/don't merge until I've documented these cases. As a taster, I think we might want this instead of |
It's probably best if I package up my changes and base them on this branch, opening a separate PR. |
Looks like something was introduced that broke one of the tests. I'll check it out tomorrow. |
I am working on this now fyi |
Tests are now passing locally, now just waiting for CI. |
This PR adds relatively simple pre and post-processing to Airnode.
This was originally in support of a specific provider, but I think it's usable in Airnode master and saves us from having more custom Airnodes.
Processing code is supplied per endpoint in the OIS in
config.json
, in a schema based on this documentationThis is discount airnode-plug:
input
(which is the result of the previous chunk's execution or the initial value)output
variable. We append an ending statement which returnsoutput
the calling code.reduce
is called insidego
and limited to 500ms gross timeout (perhaps this is too small or maybe this should be inconstants.ts
Processing code is not supplied on-chain.
The idea is to support other environments (like WASM) at a later stage.
The idea is that this enables a bunch of high value use cases for limited development time. Security mitigations for processing code are not required because we can reasonably expect the API provider to not hack themselves.
Post processing processes the API response prior to extraction and encoding.
Pre processing processes the parameters used for an API call.
An example from a testing
config.json
endpoint:Further context, these are discussions between Burak and I on this topic: