From 452278b24d45c56e71fb031019cd67cad49f3d53 Mon Sep 17 00:00:00 2001 From: boneyard93501 <4523011+boneyard93501@users.noreply.github.com> Date: Mon, 8 Nov 2021 23:43:05 -0600 Subject: [PATCH] update aqua, readme --- README.md | 64 +++++++- client-peer/aqua/demo_validation.aqua | 25 +-- client-peer/src/_aqua/demo_validation.ts | 189 +++++------------------ client-peer/src/index.ts | 5 +- peer-node/data/snapshot.db | Bin 12288 -> 12288 bytes peer-node/package.json | 2 +- 6 files changed, 111 insertions(+), 174 deletions(-) diff --git a/README.md b/README.md index 92965f4..b767132 100644 --- a/README.md +++ b/README.md @@ -138,24 +138,80 @@ signed eip validation result: { We should have one record in the node db and have 1 record(s). We know from the EIP document that the snapshot is 9278489, which i used as a unique key in the sqlite db and we can call individual records by the signature: -``` -result for call with 0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c: stderr: '', + +```bash +result for call with 0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c: { + stderr: '', stdout: [ { signature: '0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c', event_address: '0xeF8305E140ac520225DAf050e2f71d5fBcC543e7', eip712_doc: '{"domain":{"name":"snapshot","version":"0.1.4"},"types":{"Proposal":[{"name":"from","type":"address"},{"name":"space","type":"string"},{"name":"timestamp","type":"uint64"},{"name":"type","type":"string"},{"name":"title","type":"string"},{"name":"body","type":"string"},{"name":"choices","type":"string[]"},{"name":"start","type":"uint64"},{"name":"end","type":"uint64"},{"name":"snapshot","type":"uint64"},{"name":"network","type":"string"},{"name":"strategies","type":"string"},{"name":"plugins","type":"string"},{"name":"metadata","type":"string"}]},"message":{"space":"fabien.eth","type":"single-choice","title":"This is a long title this is a long title this is a long title this is a long title this is a long title this is a long","body":"This is a long title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title title this is a long title this is a long title.","choices":["Approve","Reject"],"start":1630472400,"end":1640926800,"snapshot":9278489,"network":"4","strategies":"[{\\"name\\":\\"ticket\\",\\"params\\":{\\"value\\":100,\\"symbol\\":\\"$\\"}}]","plugins":"{}","metadata":"{}","from":"0xeF8305E140ac520225DAf050e2f71d5fBcC543e7","timestamp":1631432106}}', peer_id: '0x14791697260E4c9A71f18484C9f997B308e59325', - timestamp: 1636325528, + timestamp: 1636435771, eip_validation: 1, ts_validation: 0, - signed_response: '0x4bb6846fd1adf2c2bfcedeae915007ff3e5a16675ae2f130749e5dc5bb17f99b095328460b12fddf2c743e06b28a9e40a970ac33f572da7bba3c4bf9b94f7a451b' + signed_response: '0x6a59434f144f1b64e9e0a5b6516cee962a5fffaf382bb27158607a972b3ff7c06ec6620da307e237d9f621c76ec792f70f4a1b1995b10717573db6bca48af2861b' } ] } result for call with bad 0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1cX: { stderr: '', stdout: [ null ] } ``` +In addition, we added a [simple consensus service](./services/consensus/README.md) and implemented it into our Aqua workflow: + +```aqua +-- /client-peer/aqua/demo_validation.aqua +-- Example to collect many node validations and run them through a simple frequency count +-- algorithm +data EIPLocation: + node_id: string + relay_id: string + +data Consensus: + n: u64 + threshold: f64 + valid: u64 + invalid: u64 + consensus: bool + +data CResult: + stderr: string + stdout: []Consensus + +service ConsensusService("ConsensusService"): + consensus(validations: []bool, threshold: f64) -> CResult +func eip_consensus(signature: string, locations:[]EIPLocation, service_node: string, consensus_service: string, threshold: f64) -> CResult: +-- func eip_consensus(signature: string, locations:[]EIPLocation, service_node: string, consensus_service: string, threshold: f64) -> []bool: + result: *bool + + -- for loc <- locations par: + for loc <- locations: -- replace with above after compiler update + on loc.node_id via loc.relay_id: + res <- DataProvider.get_record(signature) + if res.stdout!0.ts_validation: + result <<- true + else: + result <<- false + + on service_node: + ConsensusService consensus_service + consensus <- ConsensusService.consensus(result, threshold) + <- consensus +``` + +Since we only have a single, not validated data point, we end up with no consensus on the validity of the proposal: + +```bash +simple consensus calculation for one (1) node result with threshold 0.666 +consensus: { + stderr: '', + stdout: [ + { consensus: false, invalid: 1, n: 1, threshold: 0.666, valid: 0 } + ] +} +``` + ## Integration With Additional Store Solutions Adding (distributed) store solutions for query and persistance on both node and client is straight forward. For Aqua-based IPFS and Ceramic integration examples see [aqua-ipfs](https://github.com/fluencelabs/examples/tree/main/aqua-examples/aqua-ipfs-integration) and [aqua-ipfs lib](https://doc.fluence.dev/aqua-book/libraries/aqua-ipfs) and [ceramic-ipfs](https://github.com/fluencelabs/examples/tree/main/aqua-examples/aqua-ceramic-integration), respectively. diff --git a/client-peer/aqua/demo_validation.aqua b/client-peer/aqua/demo_validation.aqua index abc64c0..0911ce8 100644 --- a/client-peer/aqua/demo_validation.aqua +++ b/client-peer/aqua/demo_validation.aqua @@ -84,29 +84,20 @@ data CResult: service ConsensusService("ConsensusService"): consensus(validations: []bool, threshold: f64) -> CResult - - -func eip_consensus_halfway(signature: string, locations:[]EIPLocation, service_node: string, consensus_service: string, threshold: f64) -> []bool: - result: *bool - - for loc <- locations: - on loc.node_id via loc.relay_id: - res <- DataProvider.get_record(signature) - result <<- res.stdout!0.ts_validation - <- result - func eip_consensus(signature: string, locations:[]EIPLocation, service_node: string, consensus_service: string, threshold: f64) -> CResult: +-- func eip_consensus(signature: string, locations:[]EIPLocation, service_node: string, consensus_service: string, threshold: f64) -> []bool: result: *bool - for loc <- locations par: + -- for loc <- locations par: + for loc <- locations: -- replace with above after compiler update on loc.node_id via loc.relay_id: res <- DataProvider.get_record(signature) - result <<- res.stdout!0.ts_validation + if res.stdout!0.ts_validation: + result <<- true + else: + result <<- false on service_node: ConsensusService consensus_service consensus <- ConsensusService.consensus(result, threshold) - <- consensus - - - + <- consensus \ No newline at end of file diff --git a/client-peer/src/_aqua/demo_validation.ts b/client-peer/src/_aqua/demo_validation.ts index 02934e0..1e48e98 100644 --- a/client-peer/src/_aqua/demo_validation.ts +++ b/client-peer/src/_aqua/demo_validation.ts @@ -380,127 +380,6 @@ export function delete_records(...args: any) { } - -export function eip_consensus_halfway(signature: string, locations: { node_id: string; relay_id: string; }[], service_node: string, consensus_service: string, threshold: number, config?: {ttl?: number}): Promise; -export function eip_consensus_halfway(peer: FluencePeer, signature: string, locations: { node_id: string; relay_id: string; }[], service_node: string, consensus_service: string, threshold: number, config?: {ttl?: number}): Promise; -export function eip_consensus_halfway(...args: any) { - - let script = ` - (xor - (seq - (seq - (seq - (seq - (seq - (seq - (seq - (call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-) - (call %init_peer_id% ("getDataSrv" "signature") [] signature) - ) - (call %init_peer_id% ("getDataSrv" "locations") [] locations) - ) - (call %init_peer_id% ("getDataSrv" "service_node") [] service_node) - ) - (call %init_peer_id% ("getDataSrv" "consensus_service") [] consensus_service) - ) - (call %init_peer_id% ("getDataSrv" "threshold") [] threshold) - ) - (fold locations loc - (seq - (seq - (seq - (seq - (seq - (call -relay- ("op" "noop") []) - (call loc.$.relay_id! ("op" "noop") []) - ) - (xor - (seq - (call loc.$.node_id! ("DataProvider" "get_record") [signature] res) - (ap res.$.stdout.[0].ts_validation! $result) - ) - (seq - (seq - (seq - (call loc.$.relay_id! ("op" "noop") []) - (call -relay- ("op" "noop") []) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) - ) - (call -relay- ("op" "noop") []) - ) - ) - ) - (call loc.$.relay_id! ("op" "noop") []) - ) - (call -relay- ("op" "noop") []) - ) - (next loc) - ) - ) - ) - (xor - (call %init_peer_id% ("callbackSrv" "response") [$result]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) - ) - ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) - ) - ` - return callFunction( - args, - { - "functionName" : "eip_consensus_halfway", - "returnType" : { - "tag" : "primitive" - }, - "argDefs" : [ - { - "name" : "signature", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "locations", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "service_node", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "consensus_service", - "argType" : { - "tag" : "primitive" - } - }, - { - "name" : "threshold", - "argType" : { - "tag" : "primitive" - } - } - ], - "names" : { - "relay" : "-relay-", - "getDataSrv" : "getDataSrv", - "callbackSrv" : "callbackSrv", - "responseSrv" : "callbackSrv", - "responseFnName" : "response", - "errorHandlingSrv" : "errorHandlingSrv", - "errorFnName" : "error" - } -}, - script - ) -} - - export type ValidateResult = { stderr: string; stdout: { signature: string; validation: { eip_validation: boolean; peer_id: string; timestamp: number; ts_validation: boolean; }; }; } export function validate(eip712_url: string, node: string, relay: string, config?: {ttl?: number}): Promise; export function validate(peer: FluencePeer, eip712_url: string, node: string, relay: string, config?: {ttl?: number}): Promise; @@ -796,50 +675,64 @@ export function eip_consensus(...args: any) { ) (call %init_peer_id% ("getDataSrv" "threshold") [] threshold) ) - (par + (fold locations loc (seq (seq - (fold locations loc - (par + (seq + (seq (seq + (call -relay- ("op" "noop") []) + (call loc.$.relay_id! ("op" "noop") []) + ) + (xor (seq - (seq - (seq - (call -relay- ("op" "noop") []) - (call loc.$.relay_id! ("op" "noop") []) - ) - (xor - (seq - (call loc.$.node_id! ("DataProvider" "get_record") [signature] res) - (ap res.$.stdout.[0].ts_validation! $result) - ) - (seq + (call loc.$.node_id! ("DataProvider" "get_record") [signature] res) + (xor + (match res.$.stdout.[0].ts_validation! true + (xor + (ap true $result) (seq (seq (seq - (call loc.$.relay_id! ("op" "noop") []) - (call -relay- ("op" "noop") []) + (seq + (call loc.$.relay_id! ("op" "noop") []) + (call -relay- ("op" "noop") []) + ) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1]) + (call -relay- ("op" "noop") []) ) - (call -relay- ("op" "noop") []) + (call loc.$.relay_id! ("op" "noop") []) ) - (call loc.$.relay_id! ("op" "noop") []) ) ) + (seq + (seq + (ap false $result) + (call loc.$.relay_id! ("op" "noop") []) + ) + (call -relay- ("op" "noop") []) + ) ) - (call loc.$.relay_id! ("op" "noop") []) ) - (call service_node ("op" "noop") []) + (seq + (seq + (seq + (call loc.$.relay_id! ("op" "noop") []) + (call -relay- ("op" "noop") []) + ) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) + ) + (call -relay- ("op" "noop") []) + ) ) - (next loc) ) + (call loc.$.relay_id! ("op" "noop") []) ) (call -relay- ("op" "noop") []) ) - (call service_node ("op" "noop") []) + (next loc) ) - (null) ) ) (call -relay- ("op" "noop") []) @@ -851,7 +744,7 @@ export function eip_consensus(...args: any) { ) (seq (call -relay- ("op" "noop") []) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) ) ) ) @@ -859,10 +752,10 @@ export function eip_consensus(...args: any) { ) (xor (call %init_peer_id% ("callbackSrv" "response") [consensus]) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) ) ) - (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4]) + (call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5]) ) ` return callFunction( diff --git a/client-peer/src/index.ts b/client-peer/src/index.ts index e87c1de..8ad63c8 100644 --- a/client-peer/src/index.ts +++ b/client-peer/src/index.ts @@ -17,7 +17,7 @@ import { Fluence, setLogLevel, FluencePeer } from "@fluencelabs/fluence"; import { krasnodar, Node } from "@fluencelabs/fluence-network-environment"; import { validate, get_record, get_records, get_record_count, delete_records } from "./_aqua/demo_validation"; -import { eip_consensus, eip_consensus_halfway } from "./_aqua/demo_validation"; +import { eip_consensus } from "./_aqua/demo_validation"; const NODE_DB_PWD = "bad really bad"; const PWD_HASH = "bad really bad"; @@ -107,9 +107,6 @@ async function main() { let sig = "0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c"; console.log("\n\nsimple consensus calculation for one (1) node result with threshold ", threshold); - let half_way = await eip_consensus_halfway(sig, poc_topologies, service_topology.node_id, service_topology.service_id, threshold); - console.log("just for testing half_way: ", half_way); - let consensus = await eip_consensus(sig, poc_topologies, service_topology.node_id, service_topology.service_id, threshold); console.log("consensus: ", consensus); diff --git a/peer-node/data/snapshot.db b/peer-node/data/snapshot.db index c32d452c021c5f42e1ff4a190167a445b1beb800..4f0fb4cbe3834aba31bcfb9a5d028aaacb3af7b6 100644 GIT binary patch delta 179 zcmWN}s}aIL5CG7CiXk5jA{8)u-_2=EW@sY2w|6z*h(?7LaM39Oi=`7Jc?G;_oW}XM z8=j|2I~3>Ze5ilLzFLZEso!hcg=$@@Pji2iU$|Me1n4sm1mi*?jUh(P3II7IF_-`- zSi_1ONwy}tNT{`yC_Rc|5pwK>P_)|?2FuQSWrIW?FlE?^+{3miFHYygs6ofR^p4nr Iim$Hu1F7UQtpET3 delta 179 zcmWN?F&aTJ3;^KAWbrUFIDs!|o3@z@E}}`BGcd8*xPt9X28Xa(-NeYh{OA37e_f8^ zZM9p(ZnOPNXWwqz4_!aZUeCpv`{&TV=cmi@0S8LT$W*H*FAxaCT+A3V=ZM7uI4Fcf zsj9K#MkdXpum@Ic;2a~M2XsI=mw;JP6VX~4SNc~ubG6(gdN4yviGo^D)=AWW=uqzK F`4324GY|j( diff --git a/peer-node/package.json b/peer-node/package.json index fcf6ba4..3e0a2fc 100644 --- a/peer-node/package.json +++ b/peer-node/package.json @@ -24,6 +24,6 @@ "ethers": "^5.4.7", "ethers-eip712": "^0.2.0", "got": "^11.8.2", - "sqlite3": "^4.2.0" + "sqlite3": "^5.0.2" } }