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

Oracle policy contract #1445

Merged
merged 47 commits into from
Mar 11, 2020
Merged

Oracle policy contract #1445

merged 47 commits into from
Mar 11, 2020

Conversation

doubiliu
Copy link
Contributor

@doubiliu doubiliu commented Feb 13, 2020

Oracle Policy Contract
Contains the following features:
1.Delegate a third party to become an Oracle node.
2.Get current Oracle node list.
3.Get the current number of Oracle nodes.
4.Set / read timeout.
5.Set / read but per-request fees

Close #1277

src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/neo.csproj Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/neo.csproj Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
@doubiliu doubiliu marked this pull request as ready for review February 17, 2020 03:12
Tommo-L
Tommo-L previously approved these changes Feb 17, 2020
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
@belane
Copy link
Member

belane commented Feb 17, 2020

Good job @doubiliu. Please, can you better move the pull request to the oracles branch? I just regenerated it, (https://github.com/neo-project/neo/tree/oracles).

src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
src/neo/Oracle/OraclePolicyContract.cs Outdated Show resolved Hide resolved
if (storage_count is null)
{
ECPoint[] validators = new ECPoint[Blockchain.StandbyValidators.Length];
System.Array.Copy(Blockchain.StandbyValidators, validators, validators.Length);
Copy link
Contributor

@Tommo-L Tommo-L Feb 27, 2020

Choose a reason for hiding this comment

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

It's not safe here, I've added a temporary array to prevent the data from being tampered outside.

Copy link
Member

Choose a reason for hiding this comment

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

Could you create another PR in master, because oracle will spend more time in be merged

Copy link
Contributor

@Tommo-L Tommo-L Feb 28, 2020

Choose a reason for hiding this comment

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

Okay, PR #1458. I'll reset it. But ut will fail.

@belane
Copy link
Member

belane commented Mar 1, 2020

We discussed that also during community assembly with NEOFS.
@belane, could you help to clarify this?

I'm sorry @vncoelho but the option of open oracles was ruled out in #1278.
We can study the possibility of including it in the future once the current implementation is stable, as it is definitely a very interesting option.

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

Only this doubt. But I think that we can advance.

/// <param name="args">Parameter Array</param>
/// <returns>Returns true if the execution is successful, otherwise returns false</returns>
[ContractMethod(0_03000000, ContractParameterType.Boolean, ParameterTypes = new[] { ContractParameterType.Integer }, ParameterNames = new[] { "httpConfig" })]
private StackItem SetHttpConfig(ApplicationEngine engine, Array args)
Copy link
Member

Choose a reason for hiding this comment

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

If we have multiple settings in HttpConfig, do we have to set all of them at once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but if you have other ideas, I can change

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 can get or set it by key. For example:

GetConfig("HttpTimeout");
SetConfig("HttpTimeout", 2000);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shargon What's your opinion?

Copy link
Contributor

Choose a reason for hiding this comment

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

Use this way?

SetHttpConfig("Timeout", 2000) // put: http+timeout => 2000
GetHttpConfig()  // return all the http configurations

Copy link
Member

Choose a reason for hiding this comment

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

If we use enum or const for the name, it's good for me :)

@@ -31,9 +32,9 @@ public OracleContract()
internal override bool Initialize(ApplicationEngine engine)
{
if (!base.Initialize(engine)) return false;
engine.Snapshot.Storages.Add(CreateStorageKey(Prefix_HttpConfig), new StorageItem
engine.Snapshot.Storages.Add(CreateStorageKey(Prefix_HttpConfig, Encoding.UTF8.GetBytes("Timeout")), new StorageItem
Copy link
Member

Choose a reason for hiding this comment

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

const ? :)

@Tommo-L
Copy link
Contributor

Tommo-L commented Mar 11, 2020

@shargon @erikzhang Could we speed up the progress of Oracle? Now that the scheme has been determined, there are still two PRs(Oracle Transaction Attributes + Filter) to be delivered.

If it is delivered early, we can test the whole Oracle and show it at the next Neo conference. If possible, could you @shargon send the rest PRs, plz.

@shargon
Copy link
Member

shargon commented Mar 11, 2020

I will merge it because oracle branch should improve this speed, any review can be done later in this branch

@shargon shargon merged commit e3f6b03 into neo-project:oracles Mar 11, 2020
@shargon shargon deleted the OraclePolicyContract branch March 11, 2020 08:05
belane pushed a commit that referenced this pull request Mar 26, 2020
* first commit

* format

* Simplify code

* add UT and add some feature

* Fix bug

* Add summary and fix bug

* format

* format

* little change

* little change

* little change

* change Fee & Fix bug

* Optimize

* add config class

* FiX UT

* Format

* Fix UT

* Fix format and Optimize

* Add some UT

* Fix bug and add UT

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Luchuan <luchuan@ngd.neo.org>

* little change

* format

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Shargon <shargon@gmail.com>

* add check

* change validator

* Add double initialization check

* add UT

* Add UT

* change UT

* fill UT

* up ut and fix NeoToken.GetValidators

* remove console

* reset NEO.getValidators

* fix GetOracleValidators

* Rename variable

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Fix bug

* change logic

* Fix name

* change to const

* Add double initialization check and fix ut

* optimize

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: Luchuan <luchuan@neo.org>
Co-authored-by: Erik Zhang <erik@neo.org>
shargon added a commit that referenced this pull request Apr 3, 2020
* first commit

* format

* Simplify code

* add UT and add some feature

* Fix bug

* Add summary and fix bug

* format

* format

* little change

* little change

* little change

* change Fee & Fix bug

* Optimize

* add config class

* FiX UT

* Format

* Fix UT

* Fix format and Optimize

* Add some UT

* Fix bug and add UT

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Luchuan <luchuan@ngd.neo.org>

* little change

* format

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Shargon <shargon@gmail.com>

* add check

* change validator

* Add double initialization check

* add UT

* Add UT

* change UT

* fill UT

* up ut and fix NeoToken.GetValidators

* remove console

* reset NEO.getValidators

* fix GetOracleValidators

* Rename variable

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Fix bug

* change logic

* Fix name

* change to const

* Add double initialization check and fix ut

* optimize

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: Luchuan <luchuan@neo.org>
Co-authored-by: Erik Zhang <erik@neo.org>
shargon added a commit to shargon/neo that referenced this pull request Apr 17, 2020
* first commit

* format

* Simplify code

* add UT and add some feature

* Fix bug

* Add summary and fix bug

* format

* format

* little change

* little change

* little change

* change Fee & Fix bug

* Optimize

* add config class

* FiX UT

* Format

* Fix UT

* Fix format and Optimize

* Add some UT

* Fix bug and add UT

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Luchuan <luchuan@ngd.neo.org>

* little change

* format

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Shargon <shargon@gmail.com>

* add check

* change validator

* Add double initialization check

* add UT

* Add UT

* change UT

* fill UT

* up ut and fix NeoToken.GetValidators

* remove console

* reset NEO.getValidators

* fix GetOracleValidators

* Rename variable

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Fix bug

* change logic

* Fix name

* change to const

* Add double initialization check and fix ut

* optimize

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: Luchuan <luchuan@neo.org>
Co-authored-by: Erik Zhang <erik@neo.org>
shargon added a commit to shargon/neo that referenced this pull request Apr 17, 2020
* first commit

* format

* Simplify code

* add UT and add some feature

* Fix bug

* Add summary and fix bug

* format

* format

* little change

* little change

* little change

* change Fee & Fix bug

* Optimize

* add config class

* FiX UT

* Format

* Fix UT

* Fix format and Optimize

* Add some UT

* Fix bug and add UT

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Luchuan <luchuan@ngd.neo.org>

* little change

* format

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Shargon <shargon@gmail.com>

* add check

* change validator

* Add double initialization check

* add UT

* Add UT

* change UT

* fill UT

* up ut and fix NeoToken.GetValidators

* remove console

* reset NEO.getValidators

* fix GetOracleValidators

* Rename variable

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Fix bug

* change logic

* Fix name

* change to const

* Add double initialization check and fix ut

* optimize

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: Luchuan <luchuan@neo.org>
Co-authored-by: Erik Zhang <erik@neo.org>
shargon added a commit that referenced this pull request Apr 17, 2020
* first commit

* format

* Simplify code

* add UT and add some feature

* Fix bug

* Add summary and fix bug

* format

* format

* little change

* little change

* little change

* change Fee & Fix bug

* Optimize

* add config class

* FiX UT

* Format

* Fix UT

* Fix format and Optimize

* Add some UT

* Fix bug and add UT

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Luchuan <luchuan@ngd.neo.org>

* little change

* format

* Update src/neo/SmartContract/Native/Oracle/OraclePolicyContract.cs

Co-Authored-By: Shargon <shargon@gmail.com>

* add check

* change validator

* Add double initialization check

* add UT

* Add UT

* change UT

* fill UT

* up ut and fix NeoToken.GetValidators

* remove console

* reset NEO.getValidators

* fix GetOracleValidators

* Rename variable

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Update src/neo/SmartContract/Native/Oracle/OracleContract.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Fix bug

* change logic

* Fix name

* change to const

* Add double initialization check and fix ut

* optimize

Co-authored-by: Shargon <shargon@gmail.com>
Co-authored-by: Luchuan <luchuan@ngd.neo.org>
Co-authored-by: Luchuan <luchuan@neo.org>
Co-authored-by: Erik Zhang <erik@neo.org>
Oracle Syscall (#1399)

* Plugins from List to array

* Move false to init

* Fix UT

* Refactor

* UT

* Change HTTP to HTTPS

* UT Syscall

* Remove Version

* Remove HTTP from the syscall name

* Check schema

* Rename

* Update src/neo/Oracle/OracleRequest.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Fix abstract

* Rename

* Remove Body

* Change order of members

* Rename Neo.Oracle.Get

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: erikzhang <erik@neo.org>
Co-authored-by: Belane <srbelane@gmail.com>
Oracle Syscall (#1399)

* Plugins from List to array

* Move false to init

* Fix UT

* Refactor

* UT

* Change HTTP to HTTPS

* UT Syscall

* Remove Version

* Remove HTTP from the syscall name

* Check schema

* Rename

* Update src/neo/Oracle/OracleRequest.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Fix abstract

* Rename

* Remove Body

* Change order of members

* Rename Neo.Oracle.Get

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: erikzhang <erik@neo.org>
Co-authored-by: Belane <srbelane@gmail.com>
Rename OracleResult->OracleResponse (#1516)

Removed hash from the response
Oracle Syscall (#1399)

* Plugins from List to array

* Move false to init

* Fix UT

* Refactor

* UT

* Change HTTP to HTTPS

* UT Syscall

* Remove Version

* Remove HTTP from the syscall name

* Check schema

* Rename

* Update src/neo/Oracle/OracleRequest.cs

Co-Authored-By: Erik Zhang <erik@neo.org>

* Fix abstract

* Rename

* Remove Body

* Change order of members

* Rename Neo.Oracle.Get

Co-authored-by: Vitor Nazário Coelho <vncoelho@gmail.com>
Co-authored-by: erikzhang <erik@neo.org>
Co-authored-by: Belane <srbelane@gmail.com>
Rename OracleResult->OracleResponse (#1516)

Removed hash from the response
Oracle Service (#1517)

* Oracle Service

* Fix fee

* Optimize load configuration

* Fix akka message

* Optimize

* dotnet format

* Fix sort

* Oracle Service

* Fix fee

* Optimize load configuration

* Fix akka message

* Optimize

* dotnet format

* Fix sort

* Apply rename

* Small changes

* Add UT

* Fix Start Stop

* dotnet-format

* Migrate to HTTPS test

* Change AKKA message

* Tommo recomendations

* Add comunication between OracleTx and UserTx

* Advance of signature

* Fix UT

* dotnet-format

* Advance of signature

Fix UT

dotnet-format

* Fix UT

* Remove duplica method

* Reduce timeout time

* Add log for fix UT

* Add filters

* Change port to 443

* Oracle Service

* Fix fee

* Optimize load configuration

* Fix akka message

* Optimize

* dotnet format

* Fix sort

* Oracle Service

* Fix fee

* Optimize load configuration

* Fix akka message

* Optimize

* dotnet format

* Fix sort

* Apply rename

* Small changes

* Add UT

* Fix Start Stop

* dotnet-format

* Migrate to HTTPS test

* Change AKKA message

* Tommo recomendations

* Add comunication between OracleTx and UserTx

* Advance of signature

* Fix UT

* dotnet-format

* Fix UT

* Remove duplica method

* Reduce timeout time

* Add log for fix UT

* Add filters

* Change port to 443

* Merge changes

* Change SSL Protocol

* Merge remote-tracking branch 'neo-project/oracle-service' into oracle-service

* Add UT certificate

* Clean code

* Add UT
fix GetOracleMultiSigAddress (#1538)

* fix GetOracleMultiSigAddress

* First lowercase

Co-authored-by: Shargon <shargon@gmail.com>
Oracle: Tx comunication (#1540)

* Tx comunication

* Some fixes
Transaction Version (#1539)


Oracle: Allow wallets to add assert for the oracle response (#1541)

* Add assert for each oracle request

* Change to goto

* Improve wallet asserts

* Optimize

* Fix URL type

* dotnet format

* Oracle: Tx comunication (#1540)

* Tx comunication

* Some fixes

* Optimize OracleExecutionCache

* Add assert for each oracle request

* Change to goto

* Improve wallet asserts

* Optimize

* Fix URL type

* dotnet format

* Optimize OracleExecutionCache

* MakeTransaction UT
Oracle: Set the right Tx version (#1542)

* Set the right Tx version

* Remove Error types from TX and VM

* Neo.Oracle.Get now only return the result or null
Oracle: P2P Response Signature Message (#1553)

* Oracle Response Signature P2P

* caches

* rename private fields

* remove comments

* remove more comments and fix size

* Clean code

Co-authored-by: Shargon <shargon@gmail.com>
Oracle: OracleService (#1555)

* Start pool

* Prepare for neo-node

* Fix double call

* Prepare pool

* Fix

* Join oracle pool with oracle service

* dotnet-format

* Try to fix UT

* UT pass

* Fix UT

* Fix p2p message

* Unify collections

* Relay p2p message

* Clean code and fixes

* Send tx to OracleService

* RequestTx will wait for ResponseTx

* Rename

* Remove supervisor

* Allow to put request, and response in the same block

* Check the sender of OracleResponses

* Remove OracleResponse message in OracleService

* Organize code

* Fix typo

* Remove task count TODO

* Remove Thread-safe TODO

* Remove TODO

* ResponseItem changes

* Read the oracle contract on my response

Receive oraclePayload

* Clean code

* Add Stop message

* Save only one response for PublicKey/RequestTx

Improve sorting response pool

* Improve sort

* Group sort methods in the same region

* Ask for the request TX if I don't have it

* Reorder code

* Rename

* First oracle TX
Oracle: Remove some TODOs (#1574)

* Remove some todos

* Remove one method

* Reuse ManualWitness

* dotnet format

* Allow both tx in the same block without change order or fee

* Fix p2p message serialization

* Fix p2p

* Fixes and IInventory

* Fix akka message

* Fix ut
Fix conflicts


Remove double call
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.

[Oracles] Native Oracle Policy
6 participants