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

709 complete oracle #1487

Merged
merged 6 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libconsensus
Submodule libconsensus updated 42 files
+50 −36 .idea/workspace.xml
+4 −2 SkaleCommon.h
+1 −0 db/BlockProposalDB.cpp
+128 −0 docs/block_signature_verification.md
+1 −0 messages/NetworkMessage.cpp
+470 −440 node/ConsensusEngine.cpp
+11 −4 node/ConsensusEngine.h
+22 −1 node/ConsensusInterface.h
+22 −2 node/Node.cpp
+7 −2 node/Node.h
+4 −0 node/NodeGettersSetters.cpp
+138 −136 oracle/OracleClient.cpp
+10 −16 oracle/OracleClient.h
+0 −12 oracle/OracleErrors.h
+15 −33 oracle/OracleReceivedResults.cpp
+4 −11 oracle/OracleRequestBroadcastMessage.cpp
+351 −145 oracle/OracleRequestSpec.cpp
+102 −19 oracle/OracleRequestSpec.h
+12 −6 oracle/OracleResponseMessage.cpp
+2 −1 oracle/OracleResponseMessage.h
+181 −482 oracle/OracleResult.cpp
+18 −46 oracle/OracleResult.h
+134 −141 oracle/OracleServerAgent.cpp
+4 −3 oracle/OracleServerAgent.h
+68 −49 oracle/README.md
+11 −0 oracle_test/hardhat/.gitignore
+13 −0 oracle_test/hardhat/README.md
+105 −0 oracle_test/hardhat/contracts/Lock.sol
+112 −0 oracle_test/hardhat/contracts/MultiSend.sol
+22 −0 oracle_test/hardhat/hardhat.config.js
+13 −0 oracle_test/hardhat/package.json
+43 −0 oracle_test/hardhat/scripts/deploy.js
+89 −34 pendingqueue/TestMessageGeneratorAgent.cpp
+6 −0 pendingqueue/TestMessageGeneratorAgent.h
+2 −1 test/fournodes/node1/Node.json
+0 −2 test/fournodes/node1/schains/schain1.json
+2 −1 test/fournodes/node2/Node.json
+0 −1 test/fournodes/node2/schains/schain1.json
+2 −1 test/fournodes/node3/Node.json
+2 −1 test/fournodes/node4/Node.json
+1 −1 test/onenode/node1/Node.json
+2 −1 test/seven_one_catchup/node1/schains/schain1.json
24 changes: 11 additions & 13 deletions libweb3jsonrpc/Skale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,34 +517,34 @@ Json::Value Skale::skale_getDBUsage() {

std::string Skale::oracle_submitRequest( std::string& request ) {
try {
if ( this->m_client.chainParams().nodeInfo.syncNode )
if ( m_client.chainParams().nodeInfo.syncNode )
throw std::runtime_error( "Oracle is disabled on this instance" );
std::string receipt;
uint64_t status = this->m_client.submitOracleRequest( request, receipt );
if ( status != 0 ) {
// this function is guaranteed not to throw exceptions
uint64_t status = m_client.submitOracleRequest( request, receipt );
if ( status != ORACLE_SUCCESS ) {
throw jsonrpc::JsonRpcException(
status, skutils::tools::format( "Oracle request failed with status %zu", status ) );
}
return receipt;
} catch ( jsonrpc::JsonRpcException const& e ) {
throw e;
} catch ( InvalidStateException const& e ) {
throw e;
} catch ( const std::exception& e ) {
throw jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, e.what() );
throw jsonrpc::JsonRpcException( ORACLE_INTERNAL_SERVER_ERROR, e.what() );
}
}

std::string Skale::oracle_checkResult( std::string& receipt ) {
try {
if ( this->m_client.chainParams().nodeInfo.syncNode )
if ( m_client.chainParams().nodeInfo.syncNode )
throw std::runtime_error( "Oracle is disabled on this instance" );
std::string result;
uint64_t status = this->m_client.checkOracleResult( receipt, result );
// this function is guaranteed not to throw exceptions
uint64_t status = m_client.checkOracleResult( receipt, result );
switch ( status ) {
case 0:
case ORACLE_SUCCESS:
break;
case 5:
case ORACLE_RESULT_NOT_READY:
throw jsonrpc::JsonRpcException( status, "Oracle result is not ready" );
default:
throw jsonrpc::JsonRpcException(
Expand All @@ -553,10 +553,8 @@ std::string Skale::oracle_checkResult( std::string& receipt ) {
return result;
} catch ( jsonrpc::JsonRpcException const& e ) {
throw e;
} catch ( InvalidStateException const& e ) {
throw e;
} catch ( const std::exception& e ) {
throw jsonrpc::JsonRpcException( jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, e.what() );
throw jsonrpc::JsonRpcException( ORACLE_INTERNAL_SERVER_ERROR, e.what() );
}
}

Expand Down