Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defensive ops API design #221

Open
benluelo opened this issue Jan 28, 2023 · 4 comments
Open

Defensive ops API design #221

benluelo opened this issue Jan 28, 2023 · 4 comments
Labels
C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. I4-refactor Code needs refactoring. T1-FRAME This PR/Issue is related to core FRAME, the framework.

Comments

@benluelo
Copy link
Contributor

The current API design for the DefensiveSaturating trait isn't great - it's unnecessarily monolithic. It should be split into several smaller traits, and then DefensiveSaturating can be retained as a super trait so this won't be a breaking change.

I propose DefensiveSaturating{Add,Sub,Mul}, and then DefensiveSaturatingInc as a super trait of DefensiveSaturatingAdd + One and DefensiveSaturatingDec as a super trait of DefensiveSaturatingSub + One. This will allow users more granular control over the functionality they need, and removes this issue: https://github.com/paritytech/substrate/blob/master/frame/support/src/traits/misc.rs#L367-L368 (why does a type need to me Mul to use defensive_saturating_sub?)

I'm happy to implement this if it's accepted 🙂

@kianenigma
Copy link
Contributor

Please, go ahead :)

@benluelo
Copy link
Contributor Author

So after some experimentation, I've hit the following blockers:

  1. DefensiveSaturating's blanket impl depends on Saturating, and Saturating has the same API issues as mentioned in this issue.

  2. sp_arithmetic::Saturating methods take self (and other, where applicable) by value, and num_traits::Saturating{Add, Sub, Mul} take them by reference. The original num_traits::Saturating trait, (which I'm assuming sp_arithmetic::Saturating was originally based off of), takes it's parameters by value, but it's been pseudo-deprecated (not sure why it's not fully deprecated, see Officially deprecate Saturating rust-num/num-traits#255). To attempt to work around this (since all uses of sp_arithmetic::Saturating take their arguments by value), I created Saturating{Add, Sub, Mul} traits mirroring the current implementation, but that caused more issues than it solved (name collisions and ambiguous method resolution, oh boy!)

  3. Super-traits are a bit of a pain. See this playground link for a full example of the issue: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=134e923ebec434a4996a6934e8274a9c

TLDR is that this can't be done in a backwards-incompatible way (afaict on a Friday night 😛). If I'm missing something, please let me know! Otherwise, if this refactor is deemed worthy of a breaking change (which IMO it is, lest these traits get even larger and more unwieldy) then I can open a PR with the changes and relevant fixes. (mostly just replacing sp_arithmetic::traits::Saturating with the required Saturating* traits, and adding a bunch of &)

@burdges
Copy link

burdges commented Jan 29, 2023

Arithmetic crates like num_traits should support big nums, so they should pass by reference. You might as well pass by value if you're just trying to be even more precise than regular Rust about how you handle u64s.

@benluelo
Copy link
Contributor Author

Arithmetic crates like num_traits should support big nums, so they should pass by reference. You might as well pass by value if you're just trying to be even more precise than regular Rust about how you handle u64s.

IMO, the traits should take their parameters by reference, since the traits should be usable by types that aren't Copy. There are currently a few structs within substrate that impl Saturating (that also just so happen to be Copy):

@juangirini juangirini transferred this issue from paritytech/substrate Aug 24, 2023
@the-right-joyce the-right-joyce added C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. T1-FRAME This PR/Issue is related to core FRAME, the framework. D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. and removed Z6-mentor labels Aug 25, 2023
@ggwpez ggwpez added the I4-refactor Code needs refactoring. label Feb 4, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 8, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 9, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 10, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
serban300 pushed a commit to serban300/polkadot-sdk that referenced this issue Apr 10, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
jonathanudd pushed a commit to jonathanudd/polkadot-sdk that referenced this issue Apr 10, 2024
* Add Prometheus and Grafana to Docker Compose

* Expose relay's Prometheus metrics port

* Use Docker network references intead of localhost

When you have containers on the same network they don't communicate
over localhost, they instead refer to their container names

* Move dashboard components into deployment folder

* Update folder structure for Grafana and Prometheus config files

The new folder structure more closely matches the expected defaults
by Grafana and Prometheus, which allows us to clean up the paths
in our docker-compose file a bit.

* Add documentation about Prometheus and Grafana

* Refer to Prometheus server instead of node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C1-mentor A task where a mentor is available. Please indicate in the issue who the mentor could be. D0-easy Can be fixed primarily by duplicating and adapting code by an intermediate coder. I4-refactor Code needs refactoring. T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
Status: Backlog
Development

No branches or pull requests

6 participants