quorum implementation

This commit is contained in:
DieMyst
2023-02-21 16:31:21 +04:00
parent e9e57b09f4
commit d302f269ad
7 changed files with 821 additions and 54 deletions

View File

@ -20,6 +20,45 @@ import {
export function registerNumOp(...args) {
registerService$$(
args,
{
"defaultServiceId" : "op",
"functions" : {
"tag" : "labeledProduct",
"fields" : {
"identity" : {
"tag" : "arrow",
"domain" : {
"tag" : "labeledProduct",
"fields" : {
"n" : {
"tag" : "scalar",
"name" : "u64"
}
}
},
"codomain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "scalar",
"name" : "i64"
}
]
}
}
}
}
}
);
}
export function registerLogger(...args) {
registerService$$(
args,
@ -71,6 +110,97 @@ export function registerLogger(...args) {
export function registerQuorumChecker(...args) {
registerService$$(
args,
{
"defaultServiceId" : "quorum",
"functions" : {
"tag" : "labeledProduct",
"fields" : {
"check" : {
"tag" : "arrow",
"domain" : {
"tag" : "labeledProduct",
"fields" : {
"results" : {
"tag" : "array",
"type" : {
"tag" : "struct",
"name" : "EthResult",
"fields" : {
"error" : {
"tag" : "scalar",
"name" : "string"
},
"success" : {
"tag" : "scalar",
"name" : "bool"
},
"value" : {
"tag" : "scalar",
"name" : "string"
}
}
}
},
"minResults" : {
"tag" : "scalar",
"name" : "u32"
}
}
},
"codomain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "struct",
"name" : "QuorumResult",
"fields" : {
"error" : {
"tag" : "scalar",
"name" : "string"
},
"results" : {
"tag" : "array",
"type" : {
"tag" : "struct",
"name" : "EthResult",
"fields" : {
"error" : {
"tag" : "scalar",
"name" : "string"
},
"success" : {
"tag" : "scalar",
"name" : "bool"
},
"value" : {
"tag" : "scalar",
"name" : "string"
}
}
}
},
"value" : {
"tag" : "scalar",
"name" : "string"
}
}
}
]
}
}
}
}
}
);
}
export function registerEthCaller(...args) {
registerService$$(
args,
@ -163,45 +293,6 @@ export function registerCounter(...args) {
);
}
export function registerNumOp(...args) {
registerService$$(
args,
{
"defaultServiceId" : "op",
"functions" : {
"tag" : "labeledProduct",
"fields" : {
"identity" : {
"tag" : "arrow",
"domain" : {
"tag" : "labeledProduct",
"fields" : {
"n" : {
"tag" : "scalar",
"name" : "u64"
}
}
},
"codomain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "scalar",
"name" : "i64"
}
]
}
}
}
}
}
);
}
// Functions
export function roundRobinEth(...args) {
@ -417,6 +508,242 @@ export function empty(...args) {
}
export function quorumEth(...args) {
let script = `
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "uris") [] uris)
)
(call %init_peer_id% ("getDataSrv" "quorumNumber") [] quorumNumber)
)
(call %init_peer_id% ("getDataSrv" "timeout") [] timeout)
)
(call %init_peer_id% ("getDataSrv" "method") [] method)
)
(call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
)
(call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
)
(call %init_peer_id% ("getDataSrv" "quorumServiceId") [] quorumServiceId)
)
(call %init_peer_id% ("getDataSrv" "quorumPeerId") [] quorumPeerId)
)
(new $results
(seq
(seq
(seq
(xor
(par
(fold uris uri-0
(par
(seq
(seq
(xor
(call -relay- (serviceId "eth_call") [uri-0 method jsonArgs] res)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(ap res $results)
)
(call %init_peer_id% ("op" "noop") [])
)
(next uri-0)
)
(never)
)
(null)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
(par
(seq
(seq
(seq
(seq
(seq
(seq
(ap uris uris_to_functor)
(ap uris_to_functor.length uris_length)
)
(call %init_peer_id% ("math" "sub") [uris_length 1] sub)
)
(new $results_test
(seq
(seq
(seq
(call %init_peer_id% ("math" "add") [sub 1] results_incr)
(fold $results s
(seq
(seq
(ap s $results_test)
(canon %init_peer_id% $results_test #results_iter_canon)
)
(xor
(match #results_iter_canon.length results_incr
(null)
)
(next s)
)
)
(never)
)
)
(canon %init_peer_id% $results_test #results_result_canon)
)
(ap #results_result_canon results_gate)
)
)
)
(ap uris uris_to_functor-0)
)
(ap uris_to_functor-0.length uris_length-0)
)
(call %init_peer_id% ("math" "sub") [uris_length-0 1] sub-0)
)
(call %init_peer_id% ("peer" "timeout") [timeout ""])
)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(canon quorumPeerId $results #results_canon)
(call quorumPeerId ("quorum" "check") [#results_canon quorumNumber] quorumResult)
)
(call -relay- ("op" "noop") [])
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
)
)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [quorumResult])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)
`
return callFunction$$(
args,
{
"functionName" : "quorumEth",
"arrow" : {
"tag" : "arrow",
"domain" : {
"tag" : "labeledProduct",
"fields" : {
"uris" : {
"tag" : "array",
"type" : {
"tag" : "scalar",
"name" : "string"
}
},
"quorumNumber" : {
"tag" : "scalar",
"name" : "u32"
},
"timeout" : {
"tag" : "scalar",
"name" : "u32"
},
"method" : {
"tag" : "scalar",
"name" : "string"
},
"jsonArgs" : {
"tag" : "array",
"type" : {
"tag" : "scalar",
"name" : "string"
}
},
"serviceId" : {
"tag" : "scalar",
"name" : "string"
},
"quorumServiceId" : {
"tag" : "scalar",
"name" : "string"
},
"quorumPeerId" : {
"tag" : "scalar",
"name" : "string"
}
}
},
"codomain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "struct",
"name" : "QuorumResult",
"fields" : {
"error" : {
"tag" : "scalar",
"name" : "string"
},
"results" : {
"tag" : "array",
"type" : {
"tag" : "struct",
"name" : "EthResult",
"fields" : {
"error" : {
"tag" : "scalar",
"name" : "string"
},
"success" : {
"tag" : "scalar",
"name" : "bool"
},
"value" : {
"tag" : "scalar",
"name" : "string"
}
}
}
},
"value" : {
"tag" : "scalar",
"name" : "string"
}
}
}
]
}
},
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
}
export function randomLoadBalancing(...args) {
let script = `
@ -711,6 +1038,292 @@ export function randomLoadBalancingEth(...args) {
}
export function quorum(...args) {
let script = `
(xor
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(seq
(call %init_peer_id% ("getDataSrv" "-relay-") [] -relay-)
(call %init_peer_id% ("getDataSrv" "uris") [] uris)
)
(call %init_peer_id% ("getDataSrv" "quorumNumber") [] quorumNumber)
)
(call %init_peer_id% ("getDataSrv" "timeout") [] timeout)
)
(call %init_peer_id% ("getDataSrv" "method") [] method)
)
(call %init_peer_id% ("getDataSrv" "jsonArgs") [] jsonArgs)
)
(call %init_peer_id% ("getDataSrv" "serviceId") [] serviceId)
)
(call %init_peer_id% ("getDataSrv" "quorumServiceId") [] quorumServiceId)
)
(call %init_peer_id% ("getDataSrv" "quorumPeerId") [] quorumPeerId)
)
(new $results
(seq
(seq
(seq
(xor
(par
(fold uris uri-0
(par
(seq
(seq
(xor
(call %init_peer_id% ("callbackSrv" "callFunc") [uri-0 method jsonArgs serviceId] init_call_res0)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 1])
)
(ap init_call_res0 $results)
)
(call %init_peer_id% ("op" "noop") [])
)
(next uri-0)
)
(never)
)
(null)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 2])
)
(par
(seq
(seq
(seq
(seq
(seq
(seq
(ap uris uris_to_functor)
(ap uris_to_functor.length uris_length)
)
(call %init_peer_id% ("math" "sub") [uris_length 1] sub)
)
(new $results_test
(seq
(seq
(seq
(call %init_peer_id% ("math" "add") [sub 1] results_incr)
(fold $results s
(seq
(seq
(ap s $results_test)
(canon %init_peer_id% $results_test #results_iter_canon)
)
(xor
(match #results_iter_canon.length results_incr
(null)
)
(next s)
)
)
(never)
)
)
(canon %init_peer_id% $results_test #results_result_canon)
)
(ap #results_result_canon results_gate)
)
)
)
(ap uris uris_to_functor-0)
)
(ap uris_to_functor-0.length uris_length-0)
)
(call %init_peer_id% ("math" "sub") [uris_length-0 1] sub-0)
)
(call %init_peer_id% ("peer" "timeout") [timeout ""])
)
)
(call -relay- ("op" "noop") [])
)
(xor
(seq
(seq
(canon quorumPeerId $results #results_canon)
(call quorumPeerId ("quorum" "check") [#results_canon quorumNumber] quorumResult)
)
(call -relay- ("op" "noop") [])
)
(seq
(call -relay- ("op" "noop") [])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 3])
)
)
)
)
)
(xor
(call %init_peer_id% ("callbackSrv" "response") [quorumResult])
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 4])
)
)
(call %init_peer_id% ("errorHandlingSrv" "error") [%last_error% 5])
)
`
return callFunction$$(
args,
{
"functionName" : "quorum",
"arrow" : {
"tag" : "arrow",
"domain" : {
"tag" : "labeledProduct",
"fields" : {
"uris" : {
"tag" : "array",
"type" : {
"tag" : "scalar",
"name" : "string"
}
},
"quorumNumber" : {
"tag" : "scalar",
"name" : "u32"
},
"timeout" : {
"tag" : "scalar",
"name" : "u32"
},
"method" : {
"tag" : "scalar",
"name" : "string"
},
"jsonArgs" : {
"tag" : "array",
"type" : {
"tag" : "scalar",
"name" : "string"
}
},
"serviceId" : {
"tag" : "scalar",
"name" : "string"
},
"quorumServiceId" : {
"tag" : "scalar",
"name" : "string"
},
"quorumPeerId" : {
"tag" : "scalar",
"name" : "string"
},
"callFunc" : {
"tag" : "arrow",
"domain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "scalar",
"name" : "string"
},
{
"tag" : "scalar",
"name" : "string"
},
{
"tag" : "array",
"type" : {
"tag" : "scalar",
"name" : "string"
}
},
{
"tag" : "scalar",
"name" : "string"
}
]
},
"codomain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "struct",
"name" : "EthResult",
"fields" : {
"error" : {
"tag" : "scalar",
"name" : "string"
},
"success" : {
"tag" : "scalar",
"name" : "bool"
},
"value" : {
"tag" : "scalar",
"name" : "string"
}
}
}
]
}
}
}
},
"codomain" : {
"tag" : "unlabeledProduct",
"items" : [
{
"tag" : "struct",
"name" : "QuorumResult",
"fields" : {
"error" : {
"tag" : "scalar",
"name" : "string"
},
"results" : {
"tag" : "array",
"type" : {
"tag" : "struct",
"name" : "EthResult",
"fields" : {
"error" : {
"tag" : "scalar",
"name" : "string"
},
"success" : {
"tag" : "scalar",
"name" : "bool"
},
"value" : {
"tag" : "scalar",
"name" : "string"
}
}
}
},
"value" : {
"tag" : "scalar",
"name" : "string"
}
}
}
]
}
},
"names" : {
"relay" : "-relay-",
"getDataSrv" : "getDataSrv",
"callbackSrv" : "callbackSrv",
"responseSrv" : "callbackSrv",
"responseFnName" : "response",
"errorHandlingSrv" : "errorHandlingSrv",
"errorFnName" : "error"
}
},
script
)
}
export function roundRobin(...args) {
let script = `