update aqua, readme

This commit is contained in:
boneyard93501 2021-11-08 23:43:05 -06:00
parent cdf911bd76
commit 452278b24d
6 changed files with 111 additions and 174 deletions

View File

@ -138,24 +138,80 @@ signed eip validation result: {
We should have one record in the node db and have 1 record(s). 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: 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: [ stdout: [
{ {
signature: '0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c', signature: '0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c',
event_address: '0xeF8305E140ac520225DAf050e2f71d5fBcC543e7', 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}}', 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', peer_id: '0x14791697260E4c9A71f18484C9f997B308e59325',
timestamp: 1636325528, timestamp: 1636435771,
eip_validation: 1, eip_validation: 1,
ts_validation: 0, ts_validation: 0,
signed_response: '0x4bb6846fd1adf2c2bfcedeae915007ff3e5a16675ae2f130749e5dc5bb17f99b095328460b12fddf2c743e06b28a9e40a970ac33f572da7bba3c4bf9b94f7a451b' signed_response: '0x6a59434f144f1b64e9e0a5b6516cee962a5fffaf382bb27158607a972b3ff7c06ec6620da307e237d9f621c76ec792f70f4a1b1995b10717573db6bca48af2861b'
} }
] ]
} }
result for call with bad 0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1cX: { stderr: '', stdout: [ null ] } 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 ## 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. 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.

View File

@ -84,29 +84,20 @@ data CResult:
service ConsensusService("ConsensusService"): service ConsensusService("ConsensusService"):
consensus(validations: []bool, threshold: f64) -> CResult 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) -> CResult:
-- func eip_consensus(signature: string, locations:[]EIPLocation, service_node: string, consensus_service: string, threshold: f64) -> []bool:
result: *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: on loc.node_id via loc.relay_id:
res <- DataProvider.get_record(signature) 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: on service_node:
ConsensusService consensus_service ConsensusService consensus_service
consensus <- ConsensusService.consensus(result, threshold) consensus <- ConsensusService.consensus(result, threshold)
<- consensus <- consensus

View File

@ -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<boolean[]>;
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<boolean[]>;
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 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<ValidateResult>; export function validate(eip712_url: string, node: string, relay: string, config?: {ttl?: number}): Promise<ValidateResult>;
export function validate(peer: FluencePeer, eip712_url: string, node: string, relay: string, config?: {ttl?: number}): Promise<ValidateResult>; export function validate(peer: FluencePeer, eip712_url: string, node: string, relay: string, config?: {ttl?: number}): Promise<ValidateResult>;
@ -796,50 +675,64 @@ export function eip_consensus(...args: any) {
) )
(call %init_peer_id% ("getDataSrv" "threshold") [] threshold) (call %init_peer_id% ("getDataSrv" "threshold") [] threshold)
) )
(par (fold locations loc
(seq (seq
(seq (seq
(fold locations loc (seq
(par (seq
(seq (seq
(call -relay- ("op" "noop") [])
(call loc.$.relay_id! ("op" "noop") [])
)
(xor
(seq (seq
(seq (call loc.$.node_id! ("DataProvider" "get_record") [signature] res)
(seq (xor
(call -relay- ("op" "noop") []) (match res.$.stdout.[0].ts_validation! true
(call loc.$.relay_id! ("op" "noop") []) (xor
) (ap true $result)
(xor
(seq
(call loc.$.node_id! ("DataProvider" "get_record") [signature] res)
(ap res.$.stdout.[0].ts_validation! $result)
)
(seq
(seq (seq
(seq (seq
(seq (seq
(call loc.$.relay_id! ("op" "noop") []) (seq
(call -relay- ("op" "noop") []) (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 -relay- ("op" "noop") [])
) )
(call service_node ("op" "noop") []) (next loc)
) )
(null)
) )
) )
(call -relay- ("op" "noop") []) (call -relay- ("op" "noop") [])
@ -851,7 +744,7 @@ export function eip_consensus(...args: any) {
) )
(seq (seq
(call -relay- ("op" "noop") []) (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 (xor
(call %init_peer_id% ("callbackSrv" "response") [consensus]) (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( return callFunction(

View File

@ -17,7 +17,7 @@
import { Fluence, setLogLevel, FluencePeer } from "@fluencelabs/fluence"; import { Fluence, setLogLevel, FluencePeer } from "@fluencelabs/fluence";
import { krasnodar, Node } from "@fluencelabs/fluence-network-environment"; import { krasnodar, Node } from "@fluencelabs/fluence-network-environment";
import { validate, get_record, get_records, get_record_count, delete_records } from "./_aqua/demo_validation"; 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"; const NODE_DB_PWD = "bad really bad"; const PWD_HASH = "bad really bad";
@ -107,9 +107,6 @@ async function main() {
let sig = "0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c"; let sig = "0xc0a90a0bf43c0b774570608bf0279143b366b7880798112b678b416a7500576b41e19f7b4eb457d58de29be3a201f700fafab1f02179da0faae653b7e8ecf82b1c";
console.log("\n\nsimple consensus calculation for one (1) node result with threshold ", threshold); 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); let consensus = await eip_consensus(sig, poc_topologies, service_topology.node_id, service_topology.service_id, threshold);
console.log("consensus: ", consensus); console.log("consensus: ", consensus);

Binary file not shown.

View File

@ -24,6 +24,6 @@
"ethers": "^5.4.7", "ethers": "^5.4.7",
"ethers-eip712": "^0.2.0", "ethers-eip712": "^0.2.0",
"got": "^11.8.2", "got": "^11.8.2",
"sqlite3": "^4.2.0" "sqlite3": "^5.0.2"
} }
} }