Skip to content
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

OracleService #326

Merged
merged 176 commits into from
Jan 15, 2021
Merged

OracleService #326

merged 176 commits into from
Jan 15, 2021

Conversation

Tommo-L
Copy link
Contributor

@Tommo-L Tommo-L commented Aug 18, 2020

No description provided.

neo-modules.sln Outdated Show resolved Hide resolved
src/Oracle/Oracle.csproj Outdated Show resolved Hide resolved
return input;

JObject beforeObject = JObject.Parse(input);
JArray afterObjects = new JArray(beforeObject.SelectTokens(filterArgs).ToArray()); // TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filter will be a json filter (XPATH), or a contract execution?

-> Contract execution it's harder because the execution fee but it's transparent to the nodes, if we use a XPATH filters we will have a lot of underterminism betwen different implementations or libraries.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSONPath?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to neo-project/neo#1259 it seems that was decided JSONPath but for me it has two important dissadvantages.

  • Cost of gas, we will not have control over how much time was spent in this filter.
  • Same implementation throughout the different systems.

But it's ok for me, I am not against to use JsonPath.

src/Oracle/Protocol/OracleHttpProtocol.cs Outdated Show resolved Hide resolved
src/Oracle/Protocol/OracleHttpProtocol.cs Outdated Show resolved Hide resolved
private CancellationTokenSource cancelSource;

private static readonly IOracleProtocol Https = new OracleHttpProtocol();
private static readonly TimeSpan MaxTaskTimeout = TimeSpan.FromMinutes(5);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be configurable or stored in the policy

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be related to the fees?

src/Oracle/Oracle.cs Outdated Show resolved Hide resolved
src/Oracle/Oracle.cs Outdated Show resolved Hide resolved
src/Oracle/Oracle.cs Outdated Show resolved Hide resolved
src/Oracle/Oracle.cs Outdated Show resolved Hide resolved
src/Oracle/Oracle.cs Outdated Show resolved Hide resolved
{
try
{
var url = new Uri("http://" + node + "/");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should force oracles to have https with his publicKey

src/Oracle/Oracle.cs Outdated Show resolved Hide resolved
src/Oracle/Oracle.cs Outdated Show resolved Hide resolved
ECPoint[] nodes = NativeContract.Oracle.GetOracleNodes(snapshot);
if (task.Signs.Count >= nodes.Length / 3 && task.Tx != null)
{
var contract = Contract.CreateMultiSigContract(nodes.Length - (nodes.Length - 1) / 3, nodes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shargon
Copy link
Member

shargon commented Aug 26, 2020

We should add in rpc allowed nodes, or allowed client certificates, in order to allow or not only the oracle nodes, because otherwise anyone can fill the rpc queue and deny the service.
Oracle nodes should allow only oracles nodes to his rpc servers.

@erikzhang
Copy link
Member

We should add in rpc allowed nodes, or allowed client certificates

I think it has been done in:

"TrustedAuthorities": [],

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Aug 26, 2020

I'll fix them tomorrow.

src/Oracle/Oracle.cs Outdated Show resolved Hide resolved
@Tommo-L Tommo-L marked this pull request as ready for review September 8, 2020 11:03
@superboyiii superboyiii mentioned this pull request Sep 15, 2020
44 tasks
@Tommo-L
Copy link
Contributor Author

Tommo-L commented Jan 12, 2021

@Tommo-L it seems that the fee is different than expected.

Fixed.

It's because the script of native contract has been adjusted. See https://github.com/neo-project/neo/blob/8b1509f3a2fb7fa62a958a997fef18b7a30cfe1a/src/neo/SmartContract/Native/NativeContract.cs#L41-L49

@cloud8little
Copy link
Contributor

cloud8little commented Jan 14, 2021

Test passed with following scenarios:

  1. http request, the request transaction and response transaction both on-chain. but the response TX executed with FAULT result.

5fe247e71f66f6e946155c5436200ec

  1. https service is down, response code is Timeout.
  2. getapplicationlog of the request TX, the oracle contract address get the GAS user paid.
  3. After dealing with a round of oracle request and response, the oracle node get the reward 0.5 GAS.
  4. Filter like "$.result.subdir" , null, empty string "" are all ok.
  5. When response body is too large, return error

ffd2c70bf80d30dd11a849603de67fd

  1. gasForResponse<Oracle.MinimumResponseFee

c23d2049c7d723919480766df59d6de

  1. Consensus of Oracle nodes. [Updates]
    Multiple oracle nodes work well.

@shargon @Tommo-L @erikzhang please help review the cases, in case I miss something.

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Jan 14, 2021

These cases are fine. Thanks.

@erikzhang
Copy link
Member

Conflicts

@Tommo-L
Copy link
Contributor Author

Tommo-L commented Jan 14, 2021

Conflicts

Done.

src/OracleService/OracleService.cs Show resolved Hide resolved
src/OracleService/OracleService.cs Outdated Show resolved Hide resolved
src/OracleService/OracleService.cs Show resolved Hide resolved
@cloud8little
Copy link
Contributor

Let me do a smoke test.

Assert.AreEqual(@"[""Acme Co""]", Utility.StrictUTF8.GetString(OracleService.Filter(json, "Manufacturers[0].Name")));
Assert.AreEqual("[50]", Utility.StrictUTF8.GetString(OracleService.Filter(json, "Manufacturers[0].Products[0].Price")));
Assert.AreEqual(@"[""Elbow Grease""]", Utility.StrictUTF8.GetString(OracleService.Filter(json, "Manufacturers[1].Products[0].Name")));
Assert.AreEqual(@"[{""Name"":""Elbow Grease"",""Price"":99.95}]", Utility.StrictUTF8.GetString(OracleService.Filter(json, "Manufacturers[1].Products[0]")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should add Filter(json,"") and Filter(json,null)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (string.IsNullOrEmpty(filterArgs))
return Utility.StrictUTF8.GetBytes(input);

It returns the unmodified input.

@cloud8little
Copy link
Contributor

Smoke test passed.

@erikzhang
Copy link
Member

Merge?

@shargon shargon merged commit 2a6ef3a into neo-project:master Jan 15, 2021
joeqian10 pushed a commit to joeqian10/neo-modules that referenced this pull request Apr 7, 2021
* init

* move

* Clean code

* Update src/Oracle/Oracle.cs

* fix

* Update src/Oracle/Oracle.cs

* fix oracle

* format

* fix

* optimize

* optimize

* format

* fix

* add CheckOracleAccount

* fix

* Update src/Oracle/Protocol/OracleHttpProtocol.cs

* Update src/Oracle/Oracle.cs

* fix

* format

* fix

* Update Oracle.cs

* fix timeout

* fix timeout2

* optimze

* format

* Apply OracleHttpProtocol.cs

* optimize

* fix

* remove

* fix

* optimize

* Apply recommmendations

* fix

* add backupTx

* sort public key

* avoid two txs

* send backup sign after timeout

* exchange arguments of AddResponseTxSign

* format

* format

* add cache

* fix

* optimize password

* up error code

* format

* fix and add lock

* fix

* optimize

* up oracle response code

* use base64

* fix

* remove useless library

* fix

* optimize

* optimize

* rename to OracleService

* avoid duplicate request

* Replace HashsetCache by ConcurrentDictionary

* fix

* fix

* fix

* clean code

* rename Designate to Designation

* Update src/Oracle/OracleService.cs

Co-authored-by: Shargon <[email protected]>

* fix

* Update projects

* Rename

* optimize code

* static AllowPrivateHost/Timeout

* Update src/OracleService/Protocols/OracleHttpProtocol.cs

Co-authored-by: Erik Zhang <[email protected]>

* apply erik's suggestion

* fix

* fix

* fix 2/2

* Update OracleService.cs

* CI01118

* add Process

* Optimize

* Remove unused parameter

* readonly

* Use System.Threading.Timer

* Rename

* Update OracleService.cs

* Update OracleService.cs

* Rename

* Add Settings.cs

* Move IsInternal to Helper.cs

* Update OracleService.cs

* Remove Utility alias

* Use a single HttpClient

* Use HttpCompletionOption.ResponseContentRead

* private class

* Simplify OracleService.cs

* Use Interlocked

* fix

* Using lock in OnTimer method

* Replace lock by concurrentdictionary

* Optimize

* Simplify

* async

* Prevent reentry

* Optimize

* private

* Prevent multiple starts

* fix

* fix

* Optimize CheckOracleAccount

* Fix OnStop

* Reorder methods

* Optimize CreateResponseTx

* fix

* Remove WithTimeout

* Add check

* add oracle ut

* Delete Neo.Plugins.OracleService.Tests.csproj

* Delete OracleServiceTest.cs

* add try-catch when call Filter

* fix and add UT

* Remove empty line

* Fix OnPersist

* Optimize iteration

* more optimize

* fix ut

* fix

* Optimize

* use random

* Json un-indented

* Replace nonce for deterministic value

* Replace nonce

* Add UT for filters

Co-authored-by: Shargon <[email protected]>
Co-authored-by: Owen Zhang <[email protected]>
Co-authored-by: Erik Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants