`pallet-treasury`: Ensure we respect `max_amount` for spend across batch calls (#13468)
* `pallet-treasury`: Ensure we respect `max_amount` for spend across batch calls When calling `spend` the origin defines the `max_amount` of tokens it is allowed to spend. The problem is that someone can send a `batch(spend, spend)` to circumvent this restriction as we don't check across different calls that the `max_amount` is respected. This pull request fixes this behavior by introducing a so-called dispatch context. This dispatch context is created once per outer most `dispatch` call. For more information see the docs in this pr. The treasury then uses this dispatch context to attach information about already spent funds per `max_amount` (we assume that each origin has a different `max_amount` configured). So, a `batch(spend, spend)` is now checked to stay inside the allowed spending bounds. Fixes: https://github.com/paritytech/substrate/issues/13167 * Import `Box` for wasm * FMT
Showing
- substrate/Cargo.lock 2 additions, 0 deletionssubstrate/Cargo.lock
- substrate/frame/support/Cargo.toml 2 additions, 0 deletionssubstrate/frame/support/Cargo.toml
- substrate/frame/support/procedural/src/pallet/expand/call.rs 17 additions, 15 deletionssubstrate/frame/support/procedural/src/pallet/expand/call.rs
- substrate/frame/support/src/dispatch_context.rs 232 additions, 0 deletionssubstrate/frame/support/src/dispatch_context.rs
- substrate/frame/support/src/lib.rs 1 addition, 0 deletionssubstrate/frame/support/src/lib.rs
- substrate/frame/support/test/tests/pallet.rs 30 additions, 2 deletionssubstrate/frame/support/test/tests/pallet.rs
- substrate/frame/treasury/Cargo.toml 1 addition, 0 deletionssubstrate/frame/treasury/Cargo.toml
- substrate/frame/treasury/src/lib.rs 30 additions, 5 deletionssubstrate/frame/treasury/src/lib.rs
- substrate/frame/treasury/src/tests.rs 38 additions, 2 deletionssubstrate/frame/treasury/src/tests.rs
Please register or sign in to comment