Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
InversionSpaces committed Mar 8, 2024
1 parent 4fc0409 commit aa9957e
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 851 deletions.
13 changes: 1 addition & 12 deletions gateway/aqua/logger.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ export LoggerSrv
import Worker from "@fluencelabs/aqua-lib/subnet.aqua"

ability Logger:
log(s: []string)
logNum(n: u32)
logCall(s: string)
logWorker(w: Worker)

service LoggerSrv("logger"):
log(s: []string)
logNum(n: u32)
logCall(s: string)
logWorker(w: Worker)

Expand All @@ -21,18 +17,11 @@ service LoggerSrv("logger"):
-- through LoggerSrv
func initPeerLogger() -> Logger:
-- closures do not capture topology here

log = func (s: []string):
on INIT_PEER_ID via HOST_PEER_ID:
LoggerSrv.log(s)
logNum = func (n: u32):
on INIT_PEER_ID via HOST_PEER_ID:
LoggerSrv.logNum(n)
logCall = func (s: string):
on INIT_PEER_ID via HOST_PEER_ID:
LoggerSrv.logCall(s)
logWorker = func (w: Worker):
on INIT_PEER_ID via HOST_PEER_ID:
LoggerSrv.logWorker(w)

<- Logger(log=log, logNum=logNum, logCall=logCall, logWorker=logWorker)
<- Logger(logCall=logCall, logWorker=logWorker)
13 changes: 4 additions & 9 deletions gateway/aqua/quorum.aqua
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
aqua Quorum declares QuorumChecker, QuorumResult, onPeerQuorumChecker
aqua Quorum declares QuorumChecker, onPeerQuorumChecker

import JsonString from "services.aqua"

export QuorumCheckerSrv

data QuorumResult:
value: string
results: []JsonString
error: string

-- Ability to check if a quorum on results is reached
ability QuorumChecker:
check(results: []JsonString, minResults: u32) -> QuorumResult
check(results: []JsonString, minResults: u32) -> JsonString

service QuorumCheckerSrv("quorum"):
check(results: []JsonString, minResults: u32) -> QuorumResult
check(results: []JsonString, minResults: u32) -> JsonString

-- Create a QuorumChecker ability
-- that checks quorum on peer through QuorumCheckerSrv(id)
func onPeerQuorumChecker(peer: string, id: string) -> QuorumChecker:
-- closure does not capture topology here
check = func (results: []JsonString, minResults: u32) -> QuorumResult:
check = func (results: []JsonString, minResults: u32) -> JsonString:
on peer:
QuorumCheckerSrv id
res <- QuorumCheckerSrv.check(results, minResults)
Expand Down
13 changes: 5 additions & 8 deletions gateway/aqua/rpc.aqua
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@ use "deals.aqua"
import Logger, initPeerLogger from "logger.aqua"
import Balancer, ProviderBalancer, randomBalancer, cycleBalancer from "balancer.aqua"
import onPeerCounter from "counter.aqua"
import QuorumChecker, QuorumResult, onPeerQuorumChecker from "quorum.aqua"
import QuorumChecker, onPeerQuorumChecker from "quorum.aqua"
import timeRandom from "random.aqua"
import RPCEth, fromWorkerProvider from "eth_rpc.aqua"

import NumOp from "utils.aqua"

export randomLoadBalancingEth, roundRobinEth, quorumEth

func errorQuorumResult(msg: string) -> QuorumResult:
<- QuorumResult(value = "", results = [], error = msg)

func errorJsonString(msg: string) -> JsonString:
<- JsonString(value = "", success = false, error = msg)

Expand Down Expand Up @@ -77,7 +74,7 @@ func roundRobinEth(uris: []string, method: string, jsonArgs: []string, counterSe
<- result!

-- Call RPC method with workers quorum and provider load balancing
func quorum{ProviderBalancer, QuorumChecker}(workers: []Worker, quorumNumber: u32, timeout: u32, method: string, jsonArgs: []string) -> QuorumResult:
func quorum{ProviderBalancer, QuorumChecker}(workers: []Worker, quorumNumber: u32, timeout: u32, method: string, jsonArgs: []string) -> JsonString:
results: *JsonString
on HOST_PEER_ID:
for worker <- workers par:
Expand All @@ -92,12 +89,12 @@ func quorum{ProviderBalancer, QuorumChecker}(workers: []Worker, quorumNumber: u3
<- QuorumChecker.check(results, quorumNumber)

-- Call RPC method with workers quorum and provider load balancing
func quorumEth(uris: []string, quorumNumber: u32, timeout: u32, method: string, jsonArgs: []string, quorumServiceId: string, quorumPeerId: string) -> QuorumResult:
result: *QuorumResult
func quorumEth(uris: []string, quorumNumber: u32, timeout: u32, method: string, jsonArgs: []string, quorumServiceId: string, quorumPeerId: string) -> JsonString:
result: *JsonString

workers, error <- getWorkers()
if error != nil:
result <- errorQuorumResult(error!)
result <- errorJsonString(error!)
else:
random <- timeRandom()
balancer <- randomBalancer{random}(workers, uris)
Expand Down
Loading

0 comments on commit aa9957e

Please sign in to comment.