Skip to content

Commit

Permalink
fix(quorum): fix parsing quorum result (#98)
Browse files Browse the repository at this point in the history
* fix(readme): remove trailing spaces

* feat: fix quorum, remove quickstart from git, local

* fix: switch to stage

* fix: cleanup

* fix: quorum error reporting
  • Loading branch information
folex authored Sep 27, 2023
1 parent d88bfc1 commit 34d6340
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 104 deletions.
8 changes: 4 additions & 4 deletions .fluence/aqua/deals.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ data Deals:
func get() -> Deals:
<- Deals(
defaultWorker=?[Deal(
definition="bafkreigvoitfoutkvtlx2obdajsjnujtmabtkcox5cdunv34a47vplydwi",
timestamp="2023-09-25T08:18:41.888Z",
dealIdOriginal="0x65ccab7a0C276381620cE502B3671EF6B296301c",
dealId="65ccab7a0c276381620ce502b3671ef6b296301c",
definition="bafkreifncwgw7vgktf7j7qectsinrkhbhxjwfdvemmrshdsgi2ydelpvs4",
timestamp="2023-09-27T12:11:50.777Z",
dealIdOriginal="0x8d9C53312f0A4ad1Ba280ac197D371a33627E3bE",
dealId="8d9c53312f0a4ad1ba280ac197d371a33627e3be",
chainNetwork="testnet",
chainNetworkId=80001
)]
Expand Down
53 changes: 10 additions & 43 deletions .fluence/workers.yaml
Original file line number Diff line number Diff line change
@@ -1,49 +1,16 @@
# yaml-language-server: $schema=schemas/workers.json

# A result of app deployment.
# This file is updated automatically after successful deployment using `fluence workers deploy` command
# A result of app deployment. This file is created automatically after successful deployment using `fluence workers deploy` command

# Documentation: https://github.com/fluencelabs/cli/tree/main/docs/configs/workers.md

# config version
version: 0

deals:
defaultWorker:
definition: bafkreigvoitfoutkvtlx2obdajsjnujtmabtkcox5cdunv34a47vplydwi
timestamp: 2023-09-25T08:18:41.888Z
dealIdOriginal: "0x65ccab7a0C276381620cE502B3671EF6B296301c"
dealId: 65ccab7a0c276381620ce502b3671ef6b296301c
chainNetwork: testnet
chainNetworkId: 80001

# # A map of created deals
# deals:
# # worker name
# defaultWorker:
# # worker CID
# definition: bafkreigvy3k4racm6i6vvavtr5mdkllmfi2lfkmdk72gnzwk7zdnhajw4y
# # ISO timestamp of the time when the worker was deployed
# timestamp: 2023-07-07T11:23:52.353Z
# # deal ID used in aqua to resolve workers
# dealId: 799c4beb18ae084d57a90582c2cb8bb19098139e
# # original deal ID that you get after signing the contract
# dealIdOriginal: "0x799C4BEB18Ae084D57a90582c2Cb8Bb19098139E"
# # network name that was used when deploying worker
# chainNetwork: testnet
# # network ID that was used when deploying worker
# chainNetworkId: 1313161555

# # A map of deployed workers
# hosts:
# # worker name
# defaultWorker:
# # worker CID
# definition: bafkreicoctafgctpxf7jk4nynpnma4wdxpcecjtspsjmuidmag6enctnqa
# # worker installation spells
# # host_id and worker_id can be used to access the worker
# installation_spells:
# - host_id: 12D3KooWBM3SdXWqGaawQDGQ6JprtwswEg3FWGvGhmgmMez1vRbR
# spell_id: 9dbe4003-1232-4a20-9d52-5651c5cf4c5c
# worker_id: 12D3KooWLBQAdDFXz9vWnmgs6MyMfo25bhUTUEiLPsG94ppYq35w
# # ISO timestamp of the time when the worker was deployed
# timestamp: 2023-07-07T11:39:57.610Z
# # relay that was used when connecting to the network
# relayId: 12D3KooWPisGn7JhooWhggndz25WM7vQ2JmA121EV8jUDQ5xMovJ
definition: "bafkreifncwgw7vgktf7j7qectsinrkhbhxjwfdvemmrshdsgi2ydelpvs4"
timestamp: "2023-09-27T12:11:50.777Z"
dealIdOriginal: "0x8d9C53312f0A4ad1Ba280ac197D371a33627E3bE"
dealId: "8d9c53312f0a4ad1ba280ac197d371a33627e3be"
chainNetwork: "testnet"
chainNetworkId: 8000
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ aqua-compiled
/.fluence/project-secrets.yaml
/.fluence/schemas
/.fluence/tmp

# to avoid accidental publish of RPC URLs
gateway/configs/quickstart_config.json
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
resolver = "2"
members = [ "wasm-modules/eth-rpc", "wasm-modules/curl-adapter" ]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ curl http://127.0.0.1:3000 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":100}'

{"jsonrpc":"2.0","id":100,"result":"0x82b956"
{"jsonrpc":"2.0","id":100,"result":"0x82b956"}

# with the corresponding gateway log output

Expand Down
30 changes: 16 additions & 14 deletions gateway/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import express from "express";
import bodyParser from "body-parser";
import {JSONRPCServer} from "json-rpc-2.0";
import {Fluence} from '@fluencelabs/js-client';
import { JSONRPCServer } from "json-rpc-2.0";
import { Fluence } from '@fluencelabs/js-client';
import {
quorumEth,
randomLoadBalancingEth,
Expand All @@ -14,9 +14,9 @@ import {
registerQuorumChecker,
roundRobinEth
} from "../aqua-compiled/rpc.js";
import {readArguments} from "./arguments.js";
import {readConfig} from "./config.js";
import {methods} from "./methods.js";
import { readArguments } from "./arguments.js";
import { readConfig } from "./config.js";
import { methods } from "./methods.js";

const args = readArguments(process.argv.slice(2));

Expand All @@ -26,7 +26,7 @@ if (args.errors.length > 0) {
process.exit(1);
}

const {config, errors, help} = readConfig(args.configPath);
const { config, errors, help } = readConfig(args.configPath);

if (errors.length > 0) {
errors.forEach((err) => console.log(err));
Expand Down Expand Up @@ -70,7 +70,7 @@ registerCounter("counter", {
})

function findSameResults(results, minNum) {
const resultCounts = results.filter((obj) => obj.success).map((obj) => obj.value).reduce(function(i, v) {
const resultCounts = results.filter((obj) => obj.success).map((obj) => obj.value).reduce(function (i, v) {
if (i[v] === undefined) {
i[v] = 1
} else {
Expand Down Expand Up @@ -107,9 +107,9 @@ registerQuorumChecker("quorum",
}
)

const counterServiceId = config.counterServiceId || 'counter'
const counterServiceId = config.counterServiceId || 'counter'
const counterPeerId = config.counterPeerId || peerId
const quorumServiceId = config.quorumServiceId || 'quorum'
const quorumServiceId = config.quorumServiceId || 'quorum'
const quorumPeerId = config.quorumPeerId || peerId
const quorumNumber = config.quorumNumber || 2

Expand All @@ -120,13 +120,15 @@ async function methodHandler(reqRaw, method) {
if (!config.mode || config.mode === "random") {
result = await randomLoadBalancingEth(config.providers, method, req);
} else if (config.mode === "round-robin") {
result = await roundRobinEth(config.providers, method, req, counterServiceId, counterPeerId,
config.serviceId);
result = await roundRobinEth(config.providers, method, req, counterServiceId, counterPeerId, config.serviceId);
} else if (config.mode === "quorum") {
result = await quorumEth(config.providers, quorumNumber, 10000, method, req, quorumServiceId, quorumPeerId, {ttl: 20000});
const quorumResult = await quorumEth(config.providers, quorumNumber, 10000, method, req, quorumServiceId, quorumPeerId, { ttl: 20000 });

if (result.error) {
return {error: result.error, results: result.results}
if (quorumResult.error) {
console.error(`quorum failed: ${quorumResult.error}\n${JSON.stringify(quorumResult.results)}`);
result = { success: false, error: quorumResult.error };
} else {
result = { success: true, error: quorumResult.error, value: quorumResult.value };
}
}

Expand Down
17 changes: 12 additions & 5 deletions gateway/web3run.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@ import Web3 from 'web3';
const web3 = new Web3("http://localhost:3000");

async function main() {
const bn = await web3.eth.getBlockNumber()
console.log(bn)
try {
const bn = await web3.eth.getBlockNumber()
console.log("Block number is: ", bn);
} catch (e) {
console.error("Error requesting block number\n", e);
}

const resp = await web3.eth.getTransaction("0x8bad403edde37642e4dab6c91eeca77b979fce1c979c14ca8755f5c3573eaeb4")
console.log(resp)
try {
const resp = await web3.eth.getTransaction("0x8bad403edde37642e4dab6c91eeca77b979fce1c979c14ca8755f5c3573eaeb4")
console.log("Transaction is", resp);
} catch (e) {
console.log("Erro requesting transaction info\n", e)
}
}

main();

6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 40 additions & 37 deletions src/aqua/main.aqua
Original file line number Diff line number Diff line change
@@ -1,42 +1,57 @@
aqua Main

import "@fluencelabs/aqua-lib/builtin.aqua"
import "@fluencelabs/registry/subnetwork.aqua"
import Registry, Record from "@fluencelabs/registry/registry-service.aqua"
import "@fluencelabs/spell/spell_service.aqua"
import "@fluencelabs/aqua-lib/subnet.aqua"

import get from "deals.aqua"
use "deals.aqua"
use "hosts.aqua"
import "services.aqua"

-- import App from "deployed.app.aqua"
-- export App, addOne



-- IMPORTANT: Add exports for all functions that you want to run
export helloWorld, helloWorldRemote, getInfo, getInfos, getInfosInParallel, getWorkers
export helloWorld, helloWorldRemote, getInfo, getInfos

-- DOCUMENTATION:
-- https://fluence.dev


-- export status

-- service Console("run-console"):
-- print(any: ⊤)
-- example of running services deployed using `fluence deal deploy`
-- with worker 'defaultWorker' which has service 'MyService' with method 'greeting'

export showSubnet

data WorkerServices:
host_id: string
worker_id: ?string
services: ?[]string

func showSubnet() -> []WorkerServices:
deals <- Deals.get()
dealId = deals.defaultWorker!.dealIdOriginal
on HOST_PEER_ID:
subnet <- Subnet.resolve(dealId)
if subnet.success == false:
Console.print(["Failed to resolve subnet: ", subnet.error])

services: *WorkerServices
for w <- subnet.workers:
if w.worker_id != nil:
on w.worker_id! via w.host_id:
-- get list of all services on this worker
srvs <- Srv.list()

-- gather aliases
aliases: *string
for s <- srvs:
if s.aliases.length != 0:
aliases <<- s.aliases[0]

services <<- WorkerServices(host_id=w.host_id, worker_id=w.worker_id, services=?[aliases])
else:
services <<- WorkerServices(host_id=w.host_id, worker_id=nil, services=nil)

<- services

func getWorkers() -> u32, [][]Service:
workersInfo <- get()
dealId = workersInfo.defaultWorker!.dealId
services: *[]Service
on HOST_PEER_ID:
workersOp <- resolveSubnetwork(dealId)
workers = workersOp!
for worker <- workers par:
on worker.metadata.peer_id via worker.metadata.relay_id:
services <- Srv.list()
join services[workers.length - 1]
<- workers.length, services

-- local
func helloWorld(name: string) -> string:
Expand All @@ -63,15 +78,3 @@ func getInfos(peers: []PeerId) -> []Info:
on p:
infos <- Peer.identify()
<- infos

-- parallel computation
func getInfosInParallel(peers: []PeerId) -> []Info:
infos: *Info
for p <- peers par:
on p:
infos <- Peer.identify()

join infos[Op.array_length(peers) - 1] -- "-1" because it's 0-based
par Peer.timeout(PARTICLE_TTL / 2, "")

<- infos

0 comments on commit 34d6340

Please sign in to comment.