Skip to content

Commit

Permalink
feat: deviation and median configs (#116)
Browse files Browse the repository at this point in the history
* seperate median config

* test and config fixes

* minor bug fixes and arm64 test

* adding deviation log

* skip num events

* fixing tests

* minor fixes and removing unused function

* increase channel capacity
  • Loading branch information
dixitaniket authored Jun 28, 2023
1 parent 5418701 commit fb2be64
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 115 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ test-unit-contract:
compile-contract:
cosmwasm/scripts/build_artifacts.sh

compile-contract-arm:
cosmwasm/scripts/build_artifacts_arm.sh

start-relayer:
cd cw-relayer && ${MAKE} start

Expand All @@ -45,4 +48,11 @@ test-e2e:
cd cw-relayer && ${MAKE} test-e2e
rm cw-relayer/tests/e2e/config/std_reference.wasm

.PHONY: test-e2e
test-e2e-arm:
@echo "Running e2e tests"
${MAKE} compile-contract-arm
cp -f cosmwasm/artifacts/std_reference-aarch64.wasm cw-relayer/tests/e2e/config/std_reference.wasm
cd cw-relayer && ${MAKE} test-e2e
rm cw-relayer/tests/e2e/config/std_reference.wasm

.PHONY: test-e2e test-e2e-arm compile-contract compile-contract-arm
2 changes: 1 addition & 1 deletion cosmwasm/Cargo.lock

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

2 changes: 1 addition & 1 deletion cosmwasm/scripts/build_artifacts.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docker run --rm -v "$(pwd)/cosmwasm":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.12.7
cosmwasm/workspace-optimizer:0.12.7
4 changes: 4 additions & 0 deletions cosmwasm/scripts/build_artifacts_arm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docker run --rm -v "$(pwd)/cosmwasm":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer-arm64:0.12.7
13 changes: 9 additions & 4 deletions cw-relayer/cmd/cw-relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ func cwRelayerCmdHandler(cmd *cobra.Command, args []string) error {
cfg.MissedThreshold,
cfg.MaxRetries,
cfg.MedianDuration,
cfg.DeviationDuration,
cfg.SkipNumEvents,
cfg.IgnoreMedianErrors,
resolveDuration,
queryTimeout,
cfg.RequestID,
Expand All @@ -181,10 +184,12 @@ func cwRelayerCmdHandler(cmd *cobra.Command, args []string) error {
cfg.QueryRPCS,
)

g.Go(func() error {
// start the process that queries the prices on Ojo & submits them on Wasmd
return startPriceRelayer(ctx, logger, newRelayer)
})
g.Go(
func() error {
// start the process that queries the prices on Ojo & submits them on Wasmd
return startPriceRelayer(ctx, logger, newRelayer)
},
)

// Block main process until all spawned goroutines have gracefully exited and
// signal has been captured in the main process or if an error occurs.
Expand Down
5 changes: 5 additions & 0 deletions cw-relayer/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ max_retries = 1
gas_adjustment = 1.5
timeout_height = 10
gas_prices = "0.2stake"

# set median duration to 0 to disable posting medians
median_duration = 1

# set deviation duration to 0 to disable posting deviations
deviation_duration=1

# resolve duration is the estimated delay between price updates on the contract
resolve_duration = "1000ms"
missed_threshold = 2
Expand Down
13 changes: 10 additions & 3 deletions cw-relayer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ type (
DeviationRequestID uint64 `mapstructure:"deviation_request_id"`

// force relay prices and reset epoch time in contracts if err in broadcasting tx
MissedThreshold int64 `mapstructure:"missed_threshold"`
MedianDuration int64 `mapstructure:"median_duration"`
ResolveDuration string `mapstructure:"resolve_duration"`
MissedThreshold int64 `mapstructure:"missed_threshold"`
MedianDuration int64 `mapstructure:"median_duration"`
DeviationDuration int64 `mapstructure:"deviation_duration"`
ResolveDuration string `mapstructure:"resolve_duration"`

// skip price update events
SkipNumEvents int64 `mapstructure:"skip_num_events"`

// if true, would ignore any errors when querying median or deviations
IgnoreMedianErrors bool `mapstructure:"ignore_median_errors"`

GasAdjustment float64 `mapstructure:"gas_adjustment" validate:"required"`
GasPrices string `mapstructure:"gas_prices" validate:"required"`
Expand Down
5 changes: 3 additions & 2 deletions cw-relayer/relayer/client/chain_subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ func NewBlockHeightSubscription(
maxRetries int64,
) (*EventSubscribe, error) {
newEvent := &EventSubscribe{
logger: logger.With().Str("event", tickEventType).Logger(),
Tick: make(chan struct{}),
logger: logger.With().Str("event", tickEventType).Logger(),
// assuming 15-second price update
Tick: make(chan struct{}, 4),
timeout: timeout,
maxTickTimeout: maxTickTimeout,
rpcAddress: rpcAddress,
Expand Down
Loading

0 comments on commit fb2be64

Please sign in to comment.