referrerpolicy=no-referrer-when-downgrade

fp_coretime/
revenue.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18//! Interface between `pallet-broker` and the on-demand Coretime market it shares a chain with.
19
20use crate::Timeslice;
21use alloc::collections::BTreeMap;
22use sp_weights::Weight;
23
24/// The outcome of claiming on-demand revenue through [`OnDemandRevenue::claim_revenue`].
25#[derive(Clone, PartialEq, Eq, Debug)]
26pub struct RevenueClaim<Balance> {
27	/// The amount transferred for each timeslice whose revenue was paid out, possibly zero.
28	///
29	/// If a timeslice is not listed, but a later timeslice is, it means there was no revenue
30	/// booked for that timeslice. If no later timeslice is listed, the revenue should be
31	/// assumed to not have been paid out yet, and if it exists, it will be paid out in a later
32	/// claim.
33	pub paid: BTreeMap<Timeslice, Balance>,
34	/// The weight consumed by the claim.
35	pub weight: Weight,
36}
37
38/// A source of revenue from instantaneous (on-demand) Coretime sales.
39///
40/// The sales are expected to happen on the same chain as `pallet-broker`, so that the revenue can
41/// be claimed and paid out synchronously.
42pub trait OnDemandRevenue<Balance, AccountId> {
43	/// Whether on-demand Coretime is sold here.
44	///
45	/// Once it is, the claimer is expected to claim the revenue through [`Self::claim_revenue`].
46	/// Until then, no orders are accepted, and the claimer is expected to get its revenue from
47	/// elsewhere.
48	fn is_enabled() -> bool;
49
50	/// Claim the revenue from the on-demand orders placed during timeslice `up_to` and during
51	/// every earlier timeslice whose revenue has not been claimed yet, transferring it to
52	/// `beneficiary`.
53	///
54	/// The claimer is expected to claim every timeslice once it has ended.
55	///
56	/// The revenue of a timeslice is either paid out in full or not at all. The oldest revenue is
57	/// paid out first.
58	fn claim_revenue(up_to: Timeslice, beneficiary: &AccountId) -> RevenueClaim<Balance>;
59}
60
61/// No on-demand Coretime market on this chain, for a broker which gets its revenue from elsewhere.
62impl<Balance, AccountId> OnDemandRevenue<Balance, AccountId> for () {
63	fn is_enabled() -> bool {
64		false
65	}
66
67	fn claim_revenue(_up_to: Timeslice, _beneficiary: &AccountId) -> RevenueClaim<Balance> {
68		RevenueClaim { paid: BTreeMap::new(), weight: Weight::zero() }
69	}
70}