dfinity / exchange-rate-canister

The exchange rate canister (XRC) makes use of the HTTP requests feature to provide exchange rates as a service to the IC.
Apache License 2.0
37 stars 10 forks source link

Validating the collected rates #210

Closed THLO closed 1 year ago

THLO commented 1 year ago

This PR changes the way the QueriedExchangeRate struct handles the collected rates. In particular, it verifies that the rates lie within a range of values that are deemed valid. If half or more of the received rates are invalid, all rates are dropped. The median computation is also adapted as a result of this change, ensuring that less than half of the rates can be off arbitrarily - even for cryptocurrency pairs - and the returned rate is still valid.

Since the QueriedExchangeRate struct is no more strict in assessing the validity of the given data in the constructor, several tests needed to be adapted.

Finally, the PR introduces several convenience functions to define assets (which could have been done in a separate PR but it was convenient to do it in one go).