Skip to content

Commit 05a1b38

Browse files
authored
[refactor]: #3268 Globally unique item identifiers (#3317)
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
1 parent 95ec1c1 commit 05a1b38

File tree

149 files changed

+7004
-7847
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+7004
-7847
lines changed

CONTRIBUTING.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ If you intend to implement the suggestion yourself, do the following:
9191
1. Assign the issue you created to yourself **before** you start working on it.
9292
2. Work on the feature you suggested and follow our [guidelines for code and documentation](#style-guides).
9393
3. When you are ready to open a pull request, make sure you follow the [pull request guidelines](#pull-request-etiquette) and mark it as implementing the previously created issue:
94-
94+
9595
```
9696
[feature] #<issue number>: Description
9797
```
9898

9999
4. If your change requires an API change, use the `api-changes` tag.
100-
100+
101101
**Note:** features that require API changes may take longer to implement and approve as they require Iroha library makers to update their code.
102102

103103
### Asking Questions
@@ -132,7 +132,7 @@ Committing your work:
132132
- Follow the [Git Style Guide](#git-workflow).
133133
- Squash your commits [either before](https://www.git-tower.com/learn/git/faq/git-squash/) or [during the merge](https://rietta.com/blog/github-merge-types/).
134134
- If during the preparation of your pull request your branch got out of date, rebase it locally with `git pull --rebase upstream iroha2-dev`. Alternatively, you may use the drop-down menu for the `Update branch` button and choose the `Update with rebase` option.
135-
135+
136136
In the interest of making this process easier for everyone, try not to have more than a handful of commits for a pull request, and avoid re-using feature branches.
137137

138138
Creating a pull request:
@@ -164,10 +164,10 @@ To pass the *`check-PR-title`* check, the pull request should have the title tha
164164
```
165165
166166
2. Add the issue number the pull request addresses:
167-
167+
168168
- For `feature` and `fix` adding the issue number to the title is mandatory.
169169
- For all other types it is optional but highly encouraged.
170-
170+
171171
If your pull request solves multiple issues simultaneously, you can chain them with commas:
172172
173173
```
@@ -196,7 +196,7 @@ To pass the *`check-PR-title`* check, the pull request should have the title tha
196196
Follow these commit guidelines:
197197
198198
- **Sign-off every commit**. If you don't, [DCO](https://github.com/apps/dco) will not let you merge.
199-
199+
200200
Use `git commit -s` to automatically add `Signed-off-by: $NAME <$EMAIL>` as the final line of your commit message. Your name and email should be the same as specified in your GitHub account.
201201
202202
We also encourage you to sign your commits with GPG key using `git commit -sS` ([learn more](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits)).
@@ -257,16 +257,16 @@ Code guidelines:
257257
258258
- Unless otherwise specified, refer to [Rust best practices](https://github.com/mre/idiomatic-rust).
259259
- Use the `mod.rs` style. [Self-named modules](https://rust-lang.github.io/rust-clippy/master/) will not pass static analysis, except as [`trybuild`](https://crates.io/crates/trybuild) tests.
260-
- Use a domain-first modules structure.
261-
260+
- Use a domain-first modules structure.
261+
262262
Example: don't do `constants::logger`. Instead, invert the hierarchy, putting the object for which it is used first: `iroha_logger::constants`.
263263
- Use [`expect`](https://learning-rust.github.io/docs/e4.unwrap_and_expect.html) with an explicit error message or proof of infallibility instead of `unwrap`.
264264
- Never ignore an error. If you can't `panic` and can't recover, it at least needs to be recorded in the log.
265265
- Prefer to return a `Result` instead of `panic!`.
266-
266+
267267
Exception: when implementing something that uses `issue_send` instead of `send` ([more about actors](docs/source/guides/actor.md)). Actors and parallelism don't mix; you could deadlock the entire peer, so it's better to `panic!` if something goes wrong. This is a necessary concession for asynchronous programming.
268268
- Group related functionality spatially, preferably inside appropriate modules.
269-
269+
270270
For example, instead of having a block with `struct` definitions and then `impl`s for each individual struct, it is better to have the `impl`s related to that `struct` next to it.
271271
- Declare before implementation: `use` statements and constants at the top, unit tests at the bottom.
272272
- Try to avoid `use` statements if the imported name is used only once. This makes moving your code into a different file easier.
@@ -276,7 +276,7 @@ Code guidelines:
276276
- Avoid `Box<dyn Error>` if possible (we prefer strong typing).
277277
- If your function is a getter/setter, mark it `#[inline]`.
278278
- If your function is a constructor (i.e., it's creating a new value from the input parameters and calls `default()`), mark it `#[inline]`.
279-
- Avoid tying your code to concrete data structures; `rustc` is smart enough to turn a `Vec<Instruction>` into `impl IntoIterator<Item = Instruction>` and vice versa when it needs to.
279+
- Avoid tying your code to concrete data structures; `rustc` is smart enough to turn a `Vec<InstructionBox>` into `impl IntoIterator<Item = InstructionBox>` and vice versa when it needs to.
280280
281281
Naming guidelines:
282282
- Use only full words in *public* structure, variable, method, trait, constant, and module names. However, abbreviations are allowed if:
@@ -292,7 +292,7 @@ Comment guidelines:
292292
- You may leave `TODO` markers in code as long as you reference an issue that you created for it. Not creating an issue means it doesn't get merged.
293293
294294
We use pinned dependencies. Follow these guideline for versioning:
295-
295+
296296
- If your work depends on a particular crate, see if it wasn't already installed using [`cargo tree`](https://doc.rust-lang.org/cargo/commands/cargo-tree.html) (use `bat` or `grep`), and try to use that version, instead of the latest version.
297297
- Use the full version "X.Y.Z" in `Cargo.toml`.
298298
- Provide version bumps in a separate PR.

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actor/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
clippy::expect_used,
55
clippy::same_name_method
66
)]
7-
#[cfg(feature = "deadlock_detection")]
8-
use core::any::type_name;
97
use core::{
108
fmt::Debug,
119
ops::{Deref, DerefMut},
@@ -85,7 +83,7 @@ impl<A: Actor> Addr<A> {
8583
Self {
8684
sender,
8785
#[cfg(feature = "deadlock_detection")]
88-
actor_id: ActorId::new(Some(type_name::<A>())),
86+
actor_id: ActorId::new(Some(core::any::type_name::<A>())),
8987
}
9088
}
9189

@@ -432,7 +430,7 @@ impl<A: Actor> InitializedActor<A> {
432430
}
433431
}
434432
}
435-
iroha_logger::error!(actor = %std::any::type_name::<A>(), "Actor stopped");
433+
iroha_logger::error!(actor = %core::any::type_name::<A>(), "Actor stopped");
436434
actor.on_stop(&mut ctx).await;
437435
}
438436
.in_current_span();

cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ iroha_macro = { version = "=2.0.0-pre-rc.13", path = "../macro" }
4444
iroha_logger = { version = "=2.0.0-pre-rc.13", path = "../logger" }
4545
iroha_futures = { version = "=2.0.0-pre-rc.13", path = "../futures" }
4646
iroha_actor = { version = "=2.0.0-pre-rc.13", path = "../actor" }
47-
iroha_data_model = { version = "=2.0.0-pre-rc.13", path = "../data_model", features = ["transparent_api", "http"] }
47+
iroha_data_model = { version = "=2.0.0-pre-rc.13", path = "../data_model", features = ["http"] }
4848
iroha_telemetry = { version = "=2.0.0-pre-rc.13", path = "../telemetry", optional = true }
4949
iroha_version = { version = "=2.0.0-pre-rc.13", path = "../version", features = ["http"] }
5050
iroha_config = { version = "=2.0.0-pre-rc.13", path = "../config" }

cli/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use iroha_core::{
2626
kura::Kura,
2727
prelude::{World, WorldStateView},
2828
queue::Queue,
29+
smartcontracts::isi::Registrable as _,
2930
sumeragi::Sumeragi,
3031
tx::{PeerId, TransactionValidator},
3132
IrohaNetwork,

cli/src/samples.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use iroha_config::{
88
torii::{uri::DEFAULT_API_URL, DEFAULT_TORII_P2P_ADDR, DEFAULT_TORII_TELEMETRY_URL},
99
};
1010
use iroha_crypto::{KeyPair, PublicKey};
11-
use iroha_data_model::peer::Id as PeerId;
11+
use iroha_data_model::peer::PeerId;
1212

1313
/// Get sample trusted peers. The public key must be the same as `configuration.public_key`
1414
///

cli/src/torii/mod.rs

+2-33
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,15 @@ pub enum Error {
4848
/// Failed to execute or validate query
4949
#[error("Failed to execute or validate query")]
5050
Query(#[from] iroha_data_model::query::error::QueryExecutionFailure),
51-
/// Failed to decode transaction
52-
#[error("Failed to decode transaction")]
53-
VersionedSignedTransaction(#[source] iroha_version::error::Error),
5451
/// Failed to accept transaction
5552
#[error("Failed to accept transaction: {0}")]
5653
AcceptTransaction(#[from] iroha_data_model::transaction::error::AcceptTransactionFailure),
57-
/// Failed to get pending transaction
58-
#[error("Failed to get pending transactions: {0}")]
59-
RequestPendingTransactions(#[source] eyre::Report),
60-
/// Failed to decode pending transactions from leader
61-
#[error("Failed to decode pending transactions from leader")]
62-
DecodeRequestPendingTransactions(#[source] iroha_version::error::Error),
63-
/// Failed to encode pending transactions
64-
#[error("Failed to encode pending transactions")]
65-
EncodePendingTransactions(#[source] iroha_version::error::Error),
66-
/// The block sync message channel is full. Dropping the incoming message
67-
#[error("Transaction is too big")]
68-
TxTooBig,
6954
/// Error while getting or setting configuration
7055
#[error("Configuration error: {0}")]
7156
Config(#[source] eyre::Report),
7257
/// Failed to push into queue
7358
#[error("Failed to push into queue")]
7459
PushIntoQueue(#[from] Box<queue::Error>),
75-
#[cfg(feature = "telemetry")]
76-
/// Error while getting status
77-
#[error("Failed to get status")]
78-
Status(#[from] iroha_actor::Error),
7960
/// Configuration change error.
8061
#[error("Attempt to change configuration failed")]
8162
ConfigurationReload(#[from] iroha_config::base::runtime_upgrades::ReloadError),
@@ -106,12 +87,6 @@ impl Reply for Error {
10687
Query(err) => {
10788
reply::with_status(utils::Scale(&err), query_status_code(&err)).into_response()
10889
}
109-
// TODO Have a type-preserved response body instead of a stringified one #2279
110-
VersionedSignedTransaction(err)
111-
| DecodeRequestPendingTransactions(err)
112-
| EncodePendingTransactions(err) => {
113-
reply::with_status(err.to_string(), err.status_code()).into_response()
114-
}
11590
_ => reply::with_status(Self::to_string(&self), self.status_code()).into_response(),
11691
}
11792
}
@@ -122,21 +97,15 @@ impl Error {
12297
use Error::*;
12398
match self {
12499
Query(e) => query_status_code(e),
125-
VersionedSignedTransaction(err)
126-
| DecodeRequestPendingTransactions(err)
127-
| EncodePendingTransactions(err) => err.status_code(),
128-
AcceptTransaction(_)
129-
| RequestPendingTransactions(_)
130-
| ConfigurationReload(_)
131-
| TxTooBig => StatusCode::BAD_REQUEST,
100+
AcceptTransaction(_) | ConfigurationReload(_) => StatusCode::BAD_REQUEST,
132101
Config(_) => StatusCode::NOT_FOUND,
133102
PushIntoQueue(err) => match **err {
134103
queue::Error::Full => StatusCode::INTERNAL_SERVER_ERROR,
135104
queue::Error::SignatureCondition { .. } => StatusCode::UNAUTHORIZED,
136105
_ => StatusCode::BAD_REQUEST,
137106
},
138107
#[cfg(feature = "telemetry")]
139-
Prometheus(_) | Status(_) => StatusCode::INTERNAL_SERVER_ERROR,
108+
Prometheus(_) => StatusCode::INTERNAL_SERVER_ERROR,
140109
}
141110
}
142111

cli/src/torii/routing.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Routing functions for Torii. If you want to add an endpoint to
22
//! Iroha you should add it here by creating a `handle_*` function,
3-
//! and add it to impl Torii. This module also defines the `VerifiedQueryRequest`,
3+
//! and add it to impl Torii. This module also defines the `VerifiedQuery`,
44
//! which is the only kind of query that is permitted to execute.
55
66
// FIXME: This can't be fixed, because one trait in `warp` is private.
@@ -47,15 +47,15 @@ pub fn sorting() -> impl warp::Filter<Extract = (Sorting,), Error = warp::Reject
4747

4848
/// Query Request verified on the Iroha node side.
4949
#[derive(Debug, Decode, Encode)]
50-
pub struct VerifiedQueryRequest {
50+
pub struct VerifiedQuery {
5151
/// Payload, containing the time, the query, the authenticating
5252
/// user account and a filter
53-
payload: query::http::Payload,
53+
payload: query::http::QueryPayload,
5454
/// Signature of the authenticating user
55-
signature: SignatureOf<query::http::Payload>,
55+
signature: SignatureOf<query::http::QueryPayload>,
5656
}
5757

58-
impl VerifiedQueryRequest {
58+
impl VerifiedQuery {
5959
/// Validate query.
6060
///
6161
/// # Errors
@@ -84,10 +84,10 @@ impl VerifiedQueryRequest {
8484
}
8585
}
8686

87-
impl TryFrom<SignedQueryRequest> for VerifiedQueryRequest {
87+
impl TryFrom<SignedQuery> for VerifiedQuery {
8888
type Error = QueryExecutionFailure;
8989

90-
fn try_from(query: SignedQueryRequest) -> Result<Self, Self::Error> {
90+
fn try_from(query: SignedQuery) -> Result<Self, Self::Error> {
9191
query
9292
.signature
9393
.verify(&query.payload)
@@ -131,10 +131,10 @@ pub(crate) async fn handle_queries(
131131
sumeragi: Arc<Sumeragi>,
132132
pagination: Pagination,
133133
sorting: Sorting,
134-
request: VersionedSignedQueryRequest,
134+
request: VersionedSignedQuery,
135135
) -> Result<Scale<VersionedPaginatedQueryResult>> {
136-
let VersionedSignedQueryRequest::V1(request) = request;
137-
let request: VerifiedQueryRequest = request.try_into()?;
136+
let VersionedSignedQuery::V1(request) = request;
137+
let request: VerifiedQuery = request.try_into()?;
138138

139139
let (result, filter) = {
140140
let wsv = sumeragi.wsv_mutex_access().clone();

client/benches/tps/utils.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl MeasurerUnit {
173173
.with_params([("asset_id".parse()?, asset_id.clone().into())]);
174174
let allow_alice_to_transfer_my_asset =
175175
GrantBox::new(can_transfer_my_asset, alice_id).into();
176-
let grant_tx = Transaction::new(
176+
let grant_tx = TransactionBuilder::new(
177177
account_id,
178178
vec![
179179
allow_alice_to_burn_my_asset,
@@ -222,15 +222,15 @@ impl MeasurerUnit {
222222
let submitter = self.client.clone();
223223
let interval_us_per_tx = self.config.interval_us_per_tx;
224224
let instructions = self.instructions();
225-
let alice_id = <Account as Identifiable>::Id::from_str("alice@wonderland")
226-
.expect("Failed to parse account id");
225+
let account_id = account_id(self.name);
226+
227227
let mut nonce = 0;
228228
thread::spawn(move || {
229229
for instruction in instructions {
230230
match shutdown_signal.try_recv() {
231231
Err(mpsc::TryRecvError::Empty) => {
232232
let transaction =
233-
Transaction::new(alice_id.clone(), [instruction], u64::MAX)
233+
TransactionBuilder::new(account_id.clone(), [instruction], u64::MAX)
234234
.with_nonce(nonce); // Use nonce to avoid transaction duplication within the same thread
235235
let transaction = submitter
236236
.sign_transaction(transaction)
@@ -254,13 +254,13 @@ impl MeasurerUnit {
254254
}
255255

256256
#[allow(clippy::expect_used)]
257-
fn instructions(&self) -> impl Iterator<Item = Instruction> {
257+
fn instructions(&self) -> impl Iterator<Item = InstructionBox> {
258258
[self.mint_or_burn(), self.relay_a_rose()]
259259
.into_iter()
260260
.cycle()
261261
}
262262

263-
fn mint_or_burn(&self) -> Instruction {
263+
fn mint_or_burn(&self) -> InstructionBox {
264264
let is_running_out = Less::new(
265265
EvaluatesTo::new_unchecked(
266266
Expression::Query(FindAssetQuantityById::new(asset_id(self.name)).into()).into(),
@@ -270,10 +270,10 @@ impl MeasurerUnit {
270270
let supply_roses = MintBox::new(100_u32.to_value(), asset_id(self.name));
271271
let burn_a_rose = BurnBox::new(1_u32.to_value(), asset_id(self.name));
272272

273-
IfInstruction::with_otherwise(is_running_out, supply_roses, burn_a_rose).into()
273+
Conditional::with_otherwise(is_running_out, supply_roses, burn_a_rose).into()
274274
}
275275

276-
fn relay_a_rose(&self) -> Instruction {
276+
fn relay_a_rose(&self) -> InstructionBox {
277277
// Save at least one rose
278278
// because if asset value hits 0 it's automatically deleted from account
279279
// and query `FindAssetQuantityById` return error
@@ -289,7 +289,7 @@ impl MeasurerUnit {
289289
asset_id(self.next_name),
290290
);
291291

292-
IfInstruction::new(enough_to_transfer, transfer_rose).into()
292+
Conditional::new(enough_to_transfer, transfer_rose).into()
293293
}
294294
}
295295

0 commit comments

Comments
 (0)