Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/sc-1249-gofer-ignores-circuit-breaker-on-depende…
Browse files Browse the repository at this point in the history
…ncies'
  • Loading branch information
teghnet committed Nov 3, 2022
2 parents 3a7a812 + 833332e commit 09147fe
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
32 changes: 20 additions & 12 deletions exec/source-gofer
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@
set -eo pipefail
if [[ -n $OMNIA_DEBUG ]]; then set -x; fi

gofer price --config "$GOFER_CONFIG" --format ndjson "$1" \
| jq -c '{
asset: (.base+"/"+.quote),
median: .price,
sources: (
[ ..
| select(type == "object" and .type == "origin" and .error == null)
| {(.base+"/"+.quote+"@"+.params.origin): (.price|tostring)}
]
| add
)
}'
cd "$(cd "${0%/*/*}" && pwd)/lib"
. ./log.sh

if _goferData="$(gofer price --config "$GOFER_CONFIG" --format ndjson "$1")"
then
jq -c '{
asset: (.base+"/"+.quote),
median: .price,
sources: (
[ ..
| select(type == "object" and .type == "origin" and .error == null)
| {(.base+"/"+.quote+"@"+.params.origin): (.price|tostring)}
]
| add
)
}' <<<"$_goferData"
else
error "could not get price" "$(jq -r '.error' <<<"$_goferData")"
exit 1
fi
27 changes: 17 additions & 10 deletions exec/source-setzer
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ _mapSetzer() {
'{($s):$p}'
else
error "failed to get asset price" "asset=$_assetPair" "source=$_source"
return 1
fi
}

Expand All @@ -32,19 +33,25 @@ readSourcesWithSetzer() {
_setzerAssetPair="${_setzerAssetPair,,}"

local _prices
_prices=$(setzer sources "$_setzerAssetPair" \
| while IFS= read -r _src; do _mapSetzer "$_setzerAssetPair" "$_src"; done)
_prices="$(while IFS= read -r _src; do _mapSetzer "$_setzerAssetPair" "$_src"; done < <(setzer sources "$_setzerAssetPair"))"

# Check minimal available prices for setzer
_length=$(jq 'add|tonumber' <<<"$_prices" | jq -s 'length')
if [[ $_length -lt $SETZER_MIN_MEDIAN ]]; then
error "Error: not enough sources to provide a median: ${#_prices[@]} < $SETZER_MIN_MEDIAN"
return 1
fi
# Check minimal available prices for setzer
local _length
_length="$(jq 'add|tonumber' <<<"$_prices" | jq -s 'length')"
if [[ $_length -lt $SETZER_MIN_MEDIAN ]]; then
error "Error: not enough sources to provide a median: ${#_prices[@]} < $SETZER_MIN_MEDIAN"
return 1
fi

local _median
_median=$(jq 'add|tonumber' <<<"$_prices" \
| jq -s 'sort | if length == 0 then null elif length % 2 == 0 then (.[length/2] + .[length/2-1])/2 else .[length/2|floor] end')
case "$_setzerAssetPair" in
rethusd)
_median="$(setzer price "$_setzerAssetPair")"
;;
*)
_median="$(jq 'add|tonumber' <<<"$_prices" | jq -s 'sort | if length == 0 then null elif length % 2 == 0 then (.[length/2] + .[length/2-1])/2 else .[length/2|floor] end')"
;;
esac

local _output
_output="$(jq -cs \
Expand Down
29 changes: 19 additions & 10 deletions lib/feed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ readSourcesAndBroadcastAllPriceMessages() {
break
fi

readSource "$_src" "${!_unpublishedPairs[@]}" \
| while IFS= read -r _json
while IFS= read -r _json
do
if [[ -z "$_json" ]]; then
continue
Expand All @@ -43,28 +42,38 @@ readSourcesAndBroadcastAllPriceMessages() {
unset _unpublishedPairs["$_assetPair"]

transportPublish "$_assetPair" "$_message" || error "all transports failed" "asset=$_assetPair"
done
done < <(readSource "$_src" "${!_unpublishedPairs[@]}")
done
}

readSource() {
local _src="${1,,}"
local _assetPairs=("${@:2}")

verbose --list "readSource" "src=$_src" "${_assetPairs[@]}"
verbose --list "read source" "src=$_src" "${_assetPairs[@]}"

case "$_src" in
setzer|gofer)
for _assetPair in "${_assetPairs[@]}"; do
log "Querying price and calculating median" "source=$_src" "asset=${_assetPair}"

"source-$_src" "$_assetPair" \
| tee >(_data="$(cat)"; [[ -z "$_data" ]] || verbose --raw "source-$_src" "$(jq -sc <<<"$_data")") \
|| error "Failed to get price" "app=source-$_src" "asset=$_assetPair"
log "querying price and calculating median" "source=$_src" "asset=${_assetPair}"

local _data
if _data="$("source-$_src" "$_assetPair")"
then
if [[ -n "$_data" ]]
then
verbose --raw "source-$_src" "$(jq -sc <<<"$_data")"
echo "$_data"
else
error "no data from source" "app=source-$_src" "asset=$_assetPair"
fi
else
error "failed to get price" "app=source-$_src" "asset=$_assetPair"
fi
done
;;
*)
error "Unknown Feed Source: $_src"
error "unknown Feed Source: $_src"
return 1
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.13.1
1.13.2

0 comments on commit 09147fe

Please sign in to comment.