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

[schema] #2108: Add pagination #2107

Merged
merged 3 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 11 additions & 1 deletion .github/workflows/iroha2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ jobs:
with:
file: lcov.info


deploy:
runs-on: ubuntu-latest
container:
Expand Down Expand Up @@ -76,3 +75,14 @@ jobs:
PROFILE=--release
BIN=iroha_crypto_cli
- name: Build and push load-rs:release docker image
run: |
sleep 10s
echo "wait to finish other workflow"
- uses: convictional/[email protected]
with:
owner: soramitsu
repo: iroha2-longevity-load-rs
github_token: ${{ secrets.G_ACCESS_TOKEN }}
workflow_file_name: load-rs-push-from-release.yaml
ref: release
24 changes: 18 additions & 6 deletions cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//! Iroha you should add it here by creating a `handle_*` function,
//! and add it to impl Torii. This module also defines the `VerifiedQueryRequest`,
//! which is the only kind of query that is permitted to execute.
use std::num::TryFromIntError;

use eyre::WrapErr;
use iroha_actor::Addr;
use iroha_config::{Configurable, GetConfiguration, PostConfiguration};
Expand Down Expand Up @@ -95,7 +97,7 @@ pub(crate) async fn handle_instructions<W: WorldTrait>(
#[allow(clippy::map_err_ignore)]
let push_result = queue.push(transaction).map_err(|(_, err)| err);
if let Err(ref error) = push_result {
iroha_logger::warn!(%error, "Failed to push to queue")
iroha_logger::warn!(%error, "Failed to push into queue")
}
push_result
.map_err(Box::new)
Expand All @@ -109,17 +111,27 @@ pub(crate) async fn handle_queries<W: WorldTrait>(
query_validator: Arc<IsQueryAllowedBoxed<W>>,
pagination: Pagination,
request: VerifiedQueryRequest,
) -> Result<Scale<VersionedQueryResult>, warp::http::Response<warp::hyper::Body>> {
) -> Result<Scale<VersionedPaginatedQueryResult>, warp::http::Response<warp::hyper::Body>> {
Comment on lines -112 to +114
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strange thing is that Client still expects a VersionedQueryResult in request_with_pagination, but seems to successfully decode a query result that is actually a VersionedPaginatedQueryResult

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW maybe this PR should be categorized as [schema]?

Copy link
Contributor Author

@appetrosyan appetrosyan Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not PR, but commit. If you try to add schema to the PR title, it will not pass CI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The strange thing is that Client still expects a VersionedQueryResult in request_with_pagination, but seems to successfully decode a query result that is actually a VersionedPaginatedQueryResult

I'm guessing that it tries to decode the subset that is a VersionedQueryResult, but it should be updated. Good catch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not PR, but commit. If you try to add schema to the PR title, it will not pass CI.

Timely, #2115 shows an exception

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, later I can resolve the appearance discrepancy between VersionedPaginatedQueryResult and VersionedQueryResult

let valid_request = request
.validate(&wsv, &query_validator)
.map_err(into_reply)?;
let result = valid_request.execute(&wsv).map_err(into_reply)?;
let result = QueryResult(if let Value::Vec(value) = result {
let original_result = valid_request.execute(&wsv).map_err(into_reply)?;
let total: u64 = original_result
.len()
.try_into()
.map_err(|e: TryFromIntError| QueryError::Conversion(e.to_string()))
.map_err(into_reply)?;
let result = QueryResult(if let Value::Vec(value) = original_result {
Value::Vec(value.into_iter().paginate(pagination).collect())
} else {
result
original_result
});
Ok(Scale(result.into()))
let paginated_result = PaginatedQueryResult {
result,
pagination,
total,
};
Ok(Scale(paginated_result.into()))
}

#[allow(clippy::needless_pass_by_value)] // Required for `map_err`.
Expand Down
7 changes: 5 additions & 2 deletions cli/src/torii/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ async fn torii_pagination() {
)
.map(|result| {
let Scale(query_result) = result.unwrap();
if let VersionedQueryResult::V1(QueryResult(Value::Vec(domain))) = query_result {
domain
let VersionedPaginatedQueryResult::V1(PaginatedQueryResult { result, .. }) =
query_result;

if let QueryResult(Value::Vec(domains)) = result {
domains
} else {
unreachable!()
}
Expand Down
6 changes: 4 additions & 2 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,10 @@ impl Client {
std::str::from_utf8(response.body()).unwrap_or(""),
));
}
let result = VersionedQueryResult::decode_versioned(response.body())?;
let VersionedQueryResult::V1(QueryResult(result)) = result;
let result = VersionedPaginatedQueryResult::decode_versioned(response.body())?;

let VersionedPaginatedQueryResult::V1(PaginatedQueryResult { result, .. }) = result;
let QueryResult(result) = result;
R::Output::try_from(result)
.map_err(Into::into)
.wrap_err("Unexpected type")
Expand Down
2 changes: 1 addition & 1 deletion config/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod attrs {
pub const INNER: &str = "inner";
}

fn get_type_argument<'a, 'b>(s: &'a str, ty: &'b Type) -> Option<&'b GenericArgument> {
fn get_type_argument<'sl, 'tl>(s: &'sl str, ty: &'tl Type) -> Option<&'tl GenericArgument> {
let path = if let Type::Path(r#type) = ty {
r#type
} else {
Expand Down
8 changes: 4 additions & 4 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ pub trait Configurable: Serialize + DeserializeOwned {
/// Gets inner field of arbitrary inner depth and returns as json-value
/// # Errors
/// Fails if field was unknown
fn get_recursive<'a, T>(&self, inner_field: T) -> Result<Value, Self::Error>
fn get_recursive<'tl, T>(&self, inner_field: T) -> Result<Value, Self::Error>
where
T: AsRef<[&'a str]> + Send + 'a;
T: AsRef<[&'tl str]> + Send + 'tl;

/// Fails if fails to deserialize from environment
/// # Errors
Expand All @@ -184,8 +184,8 @@ pub trait Configurable: Serialize + DeserializeOwned {
/// Gets docs of inner field of arbitrary depth
/// # Errors
/// Fails if field was unknown
fn get_doc_recursive<'a>(
field: impl AsRef<[&'a str]>,
fn get_doc_recursive<'tl>(
field: impl AsRef<[&'tl str]>,
) -> Result<Option<&'static str>, Self::Error>;

/// Gets docs of field
Expand Down
3 changes: 2 additions & 1 deletion config/src/runtime_upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub enum ReloadError {
Other,
}

type PoisonErr<'a, T> = PoisonError<MutexGuard<'a, Option<Box<(dyn ReloadMut<T> + Send + Sync)>>>>;
type PoisonErr<'grd, T> =
PoisonError<MutexGuard<'grd, Option<Box<(dyn ReloadMut<T> + Send + Sync)>>>>;

impl<T> From<PoisonErr<'_, T>> for ReloadError {
fn from(_: PoisonErr<'_, T>) -> Self {
Expand Down
14 changes: 7 additions & 7 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ impl Chain {
}

/// Chain iterator
pub struct ChainIterator<'a> {
chain: &'a Chain,
pub struct ChainIterator<'itm> {
chain: &'itm Chain,
pos_front: u64,
pos_back: u64,
}

impl<'a> ChainIterator<'a> {
fn new(chain: &'a Chain) -> Self {
impl<'itm> ChainIterator<'itm> {
fn new(chain: &'itm Chain) -> Self {
ChainIterator {
chain,
pos_front: 1,
Expand All @@ -116,8 +116,8 @@ impl<'a> ChainIterator<'a> {
}
}

impl<'a> Iterator for ChainIterator<'a> {
type Item = MapRef<'a, u64, VersionedCommittedBlock>;
impl<'itm> Iterator for ChainIterator<'itm> {
type Item = MapRef<'itm, u64, VersionedCommittedBlock>;
fn next(&mut self) -> Option<Self::Item> {
if !self.is_exhausted() {
let val = self.chain.blocks.get(&self.pos_front);
Expand Down Expand Up @@ -150,7 +150,7 @@ impl<'a> Iterator for ChainIterator<'a> {
}
}

impl<'a> DoubleEndedIterator for ChainIterator<'a> {
impl<'itm> DoubleEndedIterator for ChainIterator<'itm> {
fn next_back(&mut self) -> Option<Self::Item> {
if !self.is_exhausted() {
let val = self.chain.blocks.get(&self.pos_back);
Expand Down
22 changes: 11 additions & 11 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl From<ParseError> for Error {
}
}

struct Validator<'a, W: WorldTrait> {
struct Validator<'wrld, W: WorldTrait> {
/// Number of instructions in the smartcontract
instruction_count: u64,
/// Max allowed number of instructions in the smartcontract
Expand All @@ -78,7 +78,7 @@ struct Validator<'a, W: WorldTrait> {
/// If this particular query is allowed
is_query_allowed: Arc<IsQueryAllowedBoxed<W>>,
/// Current [`WorldStateview`]
wsv: &'a WorldStateView<W>,
wsv: &'wrld WorldStateView<W>,
}

impl<W: WorldTrait> Validator<'_, W> {
Expand Down Expand Up @@ -125,16 +125,16 @@ impl<W: WorldTrait> Validator<'_, W> {
}
}

struct State<'a, W: WorldTrait> {
struct State<'wrld, W: WorldTrait> {
account_id: AccountId,
/// Ensures smartcontract adheres to limits
validator: Option<Validator<'a, W>>,
validator: Option<Validator<'wrld, W>>,
store_limits: StoreLimits,
wsv: &'a WorldStateView<W>,
wsv: &'wrld WorldStateView<W>,
}

impl<'a, W: WorldTrait> State<'a, W> {
fn new(wsv: &'a WorldStateView<W>, account_id: AccountId, config: Configuration) -> Self {
impl<'wrld, W: WorldTrait> State<'wrld, W> {
fn new(wsv: &'wrld WorldStateView<W>, account_id: AccountId, config: Configuration) -> Self {
Self {
wsv,
account_id,
Expand Down Expand Up @@ -171,13 +171,13 @@ impl<'a, W: WorldTrait> State<'a, W> {
}

/// `WebAssembly` virtual machine
pub struct Runtime<'a, W: WorldTrait> {
pub struct Runtime<'wrld, W: WorldTrait> {
engine: Engine,
linker: Linker<State<'a, W>>,
linker: Linker<State<'wrld, W>>,
config: Configuration,
}

impl<'a, W: WorldTrait> Runtime<'a, W> {
impl<'wrld, W: WorldTrait> Runtime<'wrld, W> {
/// `Runtime` constructor with default configuration.
///
/// # Errors
Expand Down Expand Up @@ -344,7 +344,7 @@ impl<'a, W: WorldTrait> Runtime<'a, W> {
Ok(())
}

fn create_linker(engine: &Engine) -> Result<Linker<State<'a, W>>, Error> {
fn create_linker(engine: &Engine) -> Result<Linker<State<'wrld, W>>, Error> {
let mut linker = Linker::new(engine);

linker
Expand Down
4 changes: 2 additions & 2 deletions core/src/sumeragi/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ impl VersionedMessage {
/// Send this message over the network to multiple `peers`.
/// # Errors
/// Fails if network sending fails
pub async fn send_to_multiple<'a, I>(self, broker: &Broker, peers: I)
pub async fn send_to_multiple<'itm, I>(self, broker: &Broker, peers: I)
where
I: IntoIterator<Item = &'a PeerId> + Send,
I: IntoIterator<Item = &'itm PeerId> + Send,
{
let futures = peers
.into_iter()
Expand Down
12 changes: 6 additions & 6 deletions core/src/sumeragi/network_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ impl Topology {
}

/// Returns signatures of the peers with the specified `roles` from all `signatures`.
pub fn filter_signatures_by_roles<'a>(
&'a self,
roles: &'a [Role],
signatures: impl IntoIterator<Item = &'a SignatureOf<VersionedValidBlock>> + 'a,
pub fn filter_signatures_by_roles<'slf>(
&'slf self,
roles: &'slf [Role],
signatures: impl IntoIterator<Item = &'slf SignatureOf<VersionedValidBlock>> + 'slf,
) -> Vec<SignatureOf<VersionedValidBlock>> {
let roles: HashSet<Role> = roles.iter().copied().collect();
let public_keys: HashSet<_> = roles
Expand Down Expand Up @@ -484,8 +484,8 @@ mod tests {
fn correct_number_of_peers_genesis() {
let peers = topology_test_peers();
// set_a.len() = 2, is wrong as it is not possible to get integer f in: 2f + 1 = 2
let set_a: HashSet<_> = topology_test_peers().iter().cloned().take(3).collect();
let set_b: HashSet<_> = topology_test_peers().iter().cloned().skip(3).collect();
let set_a: HashSet<_> = topology_test_peers().iter().take(3).cloned().collect();
let set_b: HashSet<_> = topology_test_peers().iter().skip(3).cloned().collect();
let _network_topology = GenesisBuilder::new()
.with_leader(peers.iter().next().unwrap().clone())
.with_set_a(set_a)
Expand Down
4 changes: 2 additions & 2 deletions core/src/triggers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ impl TriggerSet {
///
/// Users should not try to modify [`TriggerSet`] before dropping actions,
/// returned by the current function
pub fn find_matching<'e, E>(&self, events: E) -> Vec<Action>
pub fn find_matching<'evnt, E>(&self, events: E) -> Vec<Action>
where
E: IntoIterator<Item = &'e Event>,
E: IntoIterator<Item = &'evnt Event>,
{
let mut result = Vec::new();

Expand Down
18 changes: 9 additions & 9 deletions crypto/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub enum Node<T> {

#[derive(Debug)]
/// BFS iterator over the Merkle tree
pub struct BreadthFirstIter<'a, T> {
queue: Vec<&'a Node<T>>,
pub struct BreadthFirstIter<'itm, T> {
queue: Vec<&'itm Node<T>>,
}

#[cfg(feature = "std")]
Expand Down Expand Up @@ -196,8 +196,8 @@ impl<T> Node<T> {
}
}

impl<'a, T> BreadthFirstIter<'a, T> {
fn new(root_node: &'a Node<T>) -> Self {
impl<'itm, T> BreadthFirstIter<'itm, T> {
fn new(root_node: &'itm Node<T>) -> Self {
BreadthFirstIter {
queue: vec![root_node],
}
Expand All @@ -208,8 +208,8 @@ impl<'a, T> BreadthFirstIter<'a, T> {
/// `'a` lifetime specified for `Node`. Because `Node` is recursive data structure with self
/// composition in case of `Node::Subtree` we use `Box` to know size of each `Node` object in
/// memory.
impl<'a, T> Iterator for BreadthFirstIter<'a, T> {
type Item = &'a Node<T>;
impl<'itm, T> Iterator for BreadthFirstIter<'itm, T> {
type Item = &'itm Node<T>;

fn next(&mut self) -> Option<Self::Item> {
match &self.queue.pop() {
Expand All @@ -225,9 +225,9 @@ impl<'a, T> Iterator for BreadthFirstIter<'a, T> {
}
}

impl<'a, T> IntoIterator for &'a MerkleTree<T> {
type Item = &'a Node<T>;
type IntoIter = BreadthFirstIter<'a, T>;
impl<'itm, T> IntoIterator for &'itm MerkleTree<T> {
type Item = &'itm Node<T>;
type IntoIter = BreadthFirstIter<'itm, T>;

fn into_iter(self) -> Self::IntoIter {
BreadthFirstIter::new(&self.root_node)
Expand Down
8 changes: 4 additions & 4 deletions crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ impl<T> IntoIterator for SignaturesOf<T> {
}
}

impl<'a, T> IntoIterator for &'a SignaturesOf<T> {
type Item = &'a SignatureOf<T>;
type IntoIter = btree_map::Values<'a, PublicKey, SignatureOf<T>>;
impl<'itm, T> IntoIterator for &'itm SignaturesOf<T> {
type Item = &'itm SignatureOf<T>;
type IntoIter = btree_map::Values<'itm, PublicKey, SignatureOf<T>>;
fn into_iter(self) -> Self::IntoIter {
self.signatures.values()
}
Expand Down Expand Up @@ -406,7 +406,7 @@ impl<T> SignaturesOf<T> {
/// # Warning:
///
/// This method uses [`core::mem::transmute`] internally
#[allow(unsafe_code)]
#[allow(unsafe_code, clippy::transmute_undefined_repr)]
pub fn transmute<F>(self) -> SignaturesOf<F> {
// SAFETY: Safe because we are transmuting to a pointer of
// type `<F>` which is related to type `<T>`.
Expand Down
17 changes: 11 additions & 6 deletions data_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,11 @@ pub enum Value {
LimitedMetadata(metadata::Metadata),
/// `Id` of `Asset`, `Account`, etc.
Id(IdBox),
/// `Identifiable` as `Asset`, `Account` etc.
/// `impl Identifiable` as in `Asset`, `Account` etc.
Identifiable(IdentifiableBox),
/// [`PublicKey`].
PublicKey(PublicKey),
/// Iroha `Parameter` variant.
/// Iroha [`Parameter`] variant.
Parameter(Parameter),
/// Signature check condition.
SignatureCheckCondition(SignatureCheckCondition),
Expand Down Expand Up @@ -718,10 +718,15 @@ pub mod prelude {
#[cfg(feature = "roles")]
pub use super::role::prelude::*;
pub use super::{
account::prelude::*, asset::prelude::*, domain::prelude::*, fixed::prelude::*,
pagination::prelude::*, peer::prelude::*, trigger::prelude::*, uri, EnumTryAsError, IdBox,
Identifiable, IdentifiableBox, Name, Parameter, RegistrableBox, TryAsMut, TryAsRef,
ValidationError, Value,
account::prelude::*,
asset::prelude::*,
domain::prelude::*,
fixed::prelude::*,
pagination::{prelude::*, Pagination},
peer::prelude::*,
trigger::prelude::*,
uri, EnumTryAsError, IdBox, Identifiable, IdentifiableBox, Name, Parameter, RegistrableBox,
TryAsMut, TryAsRef, ValidationError, Value,
};
pub use crate::{
events::prelude::*, expression::prelude::*, isi::prelude::*, metadata::prelude::*,
Expand Down
Loading