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

Stream Payment pallet #391

Merged
merged 44 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e2ff7e8
pallet layout
nanocryk Jan 3, 2024
6c4faad
open stream + update logic
nanocryk Jan 4, 2024
56dd914
close stream + events
nanocryk Jan 4, 2024
0f75ed0
refill + change rate
nanocryk Jan 5, 2024
594ca74
adapter for fungible impl
nanocryk Jan 8, 2024
ce37805
rework pallet to not use fungibles traits
nanocryk Jan 15, 2024
ebe7a44
mock + some tests
nanocryk Jan 15, 2024
ffc0936
more tests
nanocryk Jan 17, 2024
61fb7df
refactor stream to prepare improved change requests
nanocryk Jan 22, 2024
322e1b6
refactor + allow to request bigger changes
nanocryk Jan 25, 2024
427cc35
crate doc
nanocryk Jan 25, 2024
515f2d0
clippy + skip 0 payment + prevent funds stuck on overflow
nanocryk Jan 25, 2024
b0c4291
payment == deposit => drained
nanocryk Jan 25, 2024
ed077d0
cleanup tests
nanocryk Jan 25, 2024
fb3c59b
rework deposit change + finish config change
nanocryk Jan 30, 2024
d7b60b8
update tests
nanocryk Jan 30, 2024
01e0c66
wip bench
nanocryk Jan 30, 2024
2c3a52e
Merge remote-tracking branch 'origin/master' into jeremy-stream-payme…
nanocryk Jan 30, 2024
f9fcaf1
fmt
nanocryk Jan 30, 2024
f4bebeb
switch to holds
nanocryk Jan 31, 2024
83c7e38
merge change_deposit into request_change/accept_requested_change + ca…
nanocryk Feb 2, 2024
011f7ff
cleanup tests
nanocryk Feb 2, 2024
7c74948
more tests
nanocryk Feb 5, 2024
3c61c41
update last_time_updated when changing time unit
nanocryk Feb 5, 2024
b8e859e
refactor possible immediate change
nanocryk Feb 6, 2024
eeca2ad
immediate deposit change
nanocryk Feb 7, 2024
e9db81d
more tests
nanocryk Feb 7, 2024
057a3ce
fix CI
nanocryk Feb 7, 2024
34b9207
support deadline in past
nanocryk Feb 9, 2024
b17754e
for benches (wip)
nanocryk Feb 9, 2024
4ebb9c8
fix rustfmt issue
nanocryk Feb 9, 2024
d704100
mock ready for running benchmarks as tests
girazoki Feb 9, 2024
3f9925b
all benches and weights
nanocryk Feb 9, 2024
0ff2f2a
Merge remote-tracking branch 'origin/master' into jeremy-stream-payme…
nanocryk Feb 9, 2024
5668b8e
fmt
nanocryk Feb 9, 2024
d27de8e
update docs
nanocryk Feb 9, 2024
376f30f
add pallet to flashbox
nanocryk Feb 9, 2024
3e5f1b1
typescript api
nanocryk Feb 12, 2024
c6feb68
Merge remote-tracking branch 'origin/master' into jeremy-stream-payme…
nanocryk Feb 13, 2024
c55bdf7
add integration tests
nanocryk Feb 14, 2024
0e0b000
Merge remote-tracking branch 'origin/master' into jeremy-stream-payme…
nanocryk Feb 15, 2024
f7185fa
fix test
nanocryk Feb 15, 2024
232ebe9
fmt
nanocryk Feb 15, 2024
b41db8f
clippy
nanocryk Feb 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pallet-pooled-staking = { path = "pallets/pooled-staking", default-features = fa
pallet-registrar = { path = "pallets/registrar", default-features = false }
pallet-registrar-runtime-api = { path = "pallets/registrar/rpc/runtime-api", default-features = false }
pallet-services-payment = { path = "pallets/services-payment", default-features = false }
pallet-stream-payment = { path = "pallets/stream-payment", default-features = false }

container-chain-template-frontier-runtime = { path = "container-chains/templates/frontier/runtime", default-features = false }
container-chain-template-simple-runtime = { path = "container-chains/templates/simple/runtime", default-features = false }
Expand All @@ -47,6 +48,7 @@ tc-consensus = { path = "client/consensus" }
tp-author-noting-inherent = { path = "primitives/author-noting-inherent", default-features = false }
tp-consensus = { path = "primitives/consensus", default-features = false }
tp-container-chain-genesis-data = { path = "primitives/container-chain-genesis-data", default-features = false }
tp-fungibles-ext = { path = "primitives/fungibles-ext", default-features = false }
tp-maths = { path = "primitives/maths", default-features = false }
tp-traits = { path = "primitives/traits", default-features = false }

Expand Down Expand Up @@ -251,6 +253,7 @@ num_enum = { version = "0.7.1", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
serde = { version = "1.0.152", default-features = false }
smallvec = "1.10.0"
tap = "1.0.1"

# General (client)
async-io = "1.3"
Expand Down
58 changes: 29 additions & 29 deletions client/consensus/src/collators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@

pub mod basic;

use cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface;
use cumulus_client_consensus_common::ParachainCandidate;
use cumulus_client_consensus_proposer::ProposerInterface;
use cumulus_primitives_core::{
relay_chain::Hash as PHash, DigestItem, ParachainBlockData, PersistedValidationData,
use {
crate::{find_pre_digest, AuthorityId, OrchestratorAuraWorkerAuxData},
cumulus_client_collator::service::ServiceInterface as CollatorServiceInterface,
cumulus_client_consensus_common::ParachainCandidate,
cumulus_client_consensus_proposer::ProposerInterface,
cumulus_primitives_core::{
relay_chain::Hash as PHash, DigestItem, ParachainBlockData, PersistedValidationData,
},
cumulus_primitives_parachain_inherent::ParachainInherentData,
cumulus_relay_chain_interface::RelayChainInterface,
futures::prelude::*,
nimbus_primitives::{CompatibleDigestItem as NimbusCompatibleDigestItem, NIMBUS_KEY_ID},
parity_scale_codec::{Codec, Encode},
polkadot_node_primitives::{Collation, MaybeCompressedPoV},
polkadot_primitives::Id as ParaId,
sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, StateAction},
sp_application_crypto::{AppCrypto, AppPublic},
sp_consensus::BlockOrigin,
sp_consensus_aura::{digests::CompatibleDigestItem, Slot},
sp_core::crypto::{ByteArray, Pair},
sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider},
sp_keystore::{Keystore, KeystorePtr},
sp_runtime::{
generic::Digest,
traits::{Block as BlockT, HashingFor, Header as HeaderT, Member, Zero},
},
sp_state_machine::StorageChanges,
sp_timestamp::Timestamp,
std::{convert::TryFrom, error::Error, time::Duration},
};
use cumulus_primitives_parachain_inherent::ParachainInherentData;
use cumulus_relay_chain_interface::RelayChainInterface;
use parity_scale_codec::{Codec, Encode};

use polkadot_node_primitives::{Collation, MaybeCompressedPoV};
use polkadot_primitives::Id as ParaId;

use crate::{find_pre_digest, AuthorityId, OrchestratorAuraWorkerAuxData};
use futures::prelude::*;
use nimbus_primitives::{CompatibleDigestItem as NimbusCompatibleDigestItem, NIMBUS_KEY_ID};
use sc_consensus::{BlockImport, BlockImportParams, ForkChoiceStrategy, StateAction};
use sp_application_crypto::{AppCrypto, AppPublic};
use sp_consensus::BlockOrigin;
use sp_consensus_aura::{digests::CompatibleDigestItem, Slot};
use sp_core::crypto::{ByteArray, Pair};
use sp_inherents::{CreateInherentDataProviders, InherentData, InherentDataProvider};
use sp_keystore::{Keystore, KeystorePtr};
use sp_runtime::{
generic::Digest,
traits::{Block as BlockT, HashingFor, Header as HeaderT, Member, Zero},
};
use sp_state_machine::StorageChanges;
use sp_timestamp::Timestamp;
use std::{convert::TryFrom, error::Error, time::Duration};

/// Parameters for instantiating a [`Collator`].
pub struct Params<BI, CIDP, RClient, Proposer, CS> {
Expand Down
63 changes: 32 additions & 31 deletions client/consensus/src/collators/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,39 @@
// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>.

use cumulus_client_collator::{
relay_chain_driven::CollationRequest, service::ServiceInterface as CollatorServiceInterface,
use {
crate::{
collators as collator_util, consensus_orchestrator::RetrieveAuthoritiesFromOrchestrator,
OrchestratorAuraWorkerAuxData,
},
cumulus_client_collator::{
relay_chain_driven::CollationRequest, service::ServiceInterface as CollatorServiceInterface,
},
cumulus_client_consensus_proposer::ProposerInterface,
cumulus_primitives_core::{
relay_chain::{BlockId as RBlockId, Hash as PHash},
PersistedValidationData,
},
cumulus_relay_chain_interface::RelayChainInterface,
futures::{channel::mpsc::Receiver, prelude::*},
parity_scale_codec::{Codec, Decode},
polkadot_node_primitives::CollationResult,
polkadot_overseer::Handle as OverseerHandle,
polkadot_primitives::{CollatorPair, Id as ParaId},
sc_client_api::{backend::AuxStore, BlockBackend, BlockOf},
sc_consensus::BlockImport,
sc_consensus_slots::InherentDataProviderExt,
sp_api::ProvideRuntimeApi,
sp_application_crypto::AppPublic,
sp_blockchain::HeaderBackend,
sp_consensus::SyncOracle,
sp_consensus_aura::SlotDuration,
sp_core::crypto::Pair,
sp_inherents::CreateInherentDataProviders,
sp_keystore::KeystorePtr,
sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member},
std::{convert::TryFrom, sync::Arc, time::Duration},
};
use cumulus_client_consensus_proposer::ProposerInterface;
use cumulus_primitives_core::{
relay_chain::{BlockId as RBlockId, Hash as PHash},
PersistedValidationData,
};
use cumulus_relay_chain_interface::RelayChainInterface;
use parity_scale_codec::{Codec, Decode};

use polkadot_node_primitives::CollationResult;
use polkadot_overseer::Handle as OverseerHandle;
use polkadot_primitives::{CollatorPair, Id as ParaId};

use futures::{channel::mpsc::Receiver, prelude::*};
use sc_client_api::{backend::AuxStore, BlockBackend, BlockOf};
use sc_consensus::BlockImport;
use sc_consensus_slots::InherentDataProviderExt;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::AppPublic;
use sp_blockchain::HeaderBackend;
use sp_consensus::SyncOracle;
use sp_consensus_aura::SlotDuration;
use sp_core::crypto::Pair;
use sp_inherents::CreateInherentDataProviders;
use sp_keystore::KeystorePtr;
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Member};
use std::{convert::TryFrom, sync::Arc, time::Duration};

use crate::consensus_orchestrator::RetrieveAuthoritiesFromOrchestrator;
use crate::{collators as collator_util, OrchestratorAuraWorkerAuxData};

/// Parameters for [`run`].
pub struct Params<BI, CIDP, Client, RClient, SO, Proposer, CS, GOH> {
Expand Down
4 changes: 1 addition & 3 deletions client/consensus/src/consensus_orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
//! the ParachainConsensus trait to access the orchestrator-dicated authorities, and further
//! it implements the TanssiWorker to TanssiOnSlot trait. This trait is
use {
crate::AuthorityId,
crate::Pair,
crate::Slot,
crate::{AuthorityId, Pair, Slot},
sc_consensus_slots::{SimpleSlotWorker, SlotInfo, SlotResult},
sp_consensus::Proposer,
sp_runtime::traits::Block as BlockT,
Expand Down
16 changes: 9 additions & 7 deletions client/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,26 @@
//! slot_author returns the author based on the slot number and authorities provided (aura-like)
//! authorities retrieves the current set of authorities based on the first eligible key found in the keystore
use {sp_consensus_slots::Slot, sp_core::crypto::Pair};

pub mod collators;
mod consensus_orchestrator;
mod manual_seal;

#[cfg(test)]
mod tests;

pub use crate::consensus_orchestrator::OrchestratorAuraWorkerAuxData;
pub use sc_consensus_aura::CompatibilityMode;

pub use {
crate::consensus_orchestrator::OrchestratorAuraWorkerAuxData,
cumulus_primitives_core::ParaId,
manual_seal::{
get_aura_id_from_seed, ContainerManualSealAuraConsensusDataProvider,
OrchestratorManualSealAuraConsensusDataProvider,
},
pallet_registrar_runtime_api::OnDemandBlockProductionApi,
parity_scale_codec::{Decode, Encode},
sc_consensus_aura::find_pre_digest,
sc_consensus_aura::{slot_duration, AuraVerifier, BuildAuraWorkerParams, SlotProportion},
sc_consensus_aura::{
find_pre_digest, slot_duration, AuraVerifier, BuildAuraWorkerParams, CompatibilityMode,
SlotProportion,
},
sc_consensus_slots::InherentDataProviderExt,
sp_api::{Core, ProvideRuntimeApi},
sp_application_crypto::AppPublic,
Expand All @@ -51,6 +50,9 @@ pub use {
std::hash::Hash,
tp_consensus::TanssiAuthorityAssignmentApi,
};

use {sp_consensus_slots::Slot, sp_core::crypto::Pair};

const LOG_TARGET: &str = "aura::tanssi";

type AuthorityId<P> = <P as Pair>::Public;
Expand Down
6 changes: 5 additions & 1 deletion pallets/collator-assignment/src/assignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ use {
cmp,
collections::{btree_map::BTreeMap, btree_set::BTreeSet},
marker::PhantomData,
mem, vec,
mem,
nanocryk marked this conversation as resolved.
Show resolved Hide resolved
vec::Vec,
},
tp_traits::{ParaId, RemoveInvulnerables as RemoveInvulnerablesT},
};

// Separate import of `sp_std::vec!` macro, which cause issues with rustfmt if grouped
// with `sp_std::vec::Vec`.
use sp_std::vec;

/// Helper methods to implement collator assignment algorithm
pub struct Assignment<T>(PhantomData<T>);

Expand Down
3 changes: 1 addition & 2 deletions pallets/registrar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ use {

#[frame_support::pallet]
pub mod pallet {
use super::*;
use tp_traits::SessionContainerChains;
use {super::*, tp_traits::SessionContainerChains};

#[pallet::pallet]
#[pallet::without_storage_info]
Expand Down
66 changes: 66 additions & 0 deletions pallets/stream-payment/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
[package]
name = "pallet-stream-payment"
authors = { workspace = true }
description = "Stream payment pallet"
edition = "2021"
license = "GPL-3.0-only"
version = "0.1.0"

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]

[dependencies]
log = { workspace = true }
serde = { workspace = true, optional = true }

dp-core = { workspace = true }
tp-maths = { workspace = true }
tp-traits = { workspace = true }

# Substrate
frame-benchmarking = { workspace = true, optional = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }

[dev-dependencies]
num-traits = { workspace = true }
pallet-balances = { workspace = true, features = [ "std" ] }
similar-asserts = { workspace = true }
sp-io = { workspace = true, features = [ "std" ] }
tap = { workspace = true }

[features]
default = [ "std" ]
std = [
"dp-core/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"parity-scale-codec/std",
"scale-info/std",
"serde",
"serde?/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"tp-maths/std",
"tp-traits/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"tp-maths/runtime-benchmarks",
"tp-traits/runtime-benchmarks",
]
Loading
Loading