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

Fix Informational Issues #385

Merged
merged 29 commits into from
Oct 12, 2023
Merged

Fix Informational Issues #385

merged 29 commits into from
Oct 12, 2023

Conversation

b-yap
Copy link
Contributor

@b-yap b-yap commented Aug 9, 2023

closes for #257

This PR addresses the ff. items:

  • SYT-03 | Unnecessary Variable

    • from audit:

      • The linked variable account_id is only used once in the function. Thus, its value can be supplied directly instead of stored in a variable.
    • files covered:

      • system.rs
  • SRL-01 | Usage of Hard-coded Strings

    • from audit:

      • It is a good practice to declare and use Rust constants for such cases to better track their usage and avoid mistakes and bugs that may arise during several different development iterations.
    • files covered:

      • primitives/src/lib.rs
      • clients/
        • vault/tests/helper/constants.rs
        • wallet/src/
          • stellar_wallet.rs
          • horizon/responses.rs
  • PAL-03 | Usage of Magic Numbers

    • from audit:

      • We advise the team to declare constants to improve code maintainability and readability. E.g. the client could declare: HOURS_DURING_DAY , MINUTES_IN_HOUR , SECONDS_IN_HOUR, SECONDS_DURING_DAY, etc.
    • files covered:

      • pallets/
        • issue/src/lib.rs
        • redeem/src/lib.rs
  • PAL-02 | Unnecessary Result<...> Return Type

    • from audit:

      • methods return Result<..., DispatchError> but that Error will never be thrown.
    • files covered:

      • pallets/
        • replace/src/
          • types.rs
          • lib.rs
        • redeem/src/
          • types.rs
          • lib.rs
  • CLI-02 | Typos

    • from audit:

      • "insertin" should be "inserting".
      • "Oracle returned error" should be "Oracle returned an error".
      • "Not fetching missing envelopes from archive for slot {:?}, because on testnet" should be "Not fetching missing
      • envelopes from archive for slot {:?}, because it is on testnet"
      • "the slot where the txset is to get" should be "the slot from where we get the txset"
    • files covered:

      • clients/
        • runtime/src/shutdown.rs
        • vault/src/oracle/collector
          • collector.rs
          • proof_builder.rs
  • 9B2-03 | Unused Errors

    • from audit:

      • The errors HttpPostError and SeqNoParsingError are defined in vault/src/error.rs but are not used inside such crate.
      • The same thing happens for the errors NoOrganizationsRegisteredForNetwork, NoValidatorsRegisteredForNetwork, InvalidTransactionSet and InvalidTransactionXDR from stellar-relay/src/lib.rs.
    • files covered:

      • clients/vault/src/error.rs
      • pallets/stellar-relay-src/lib.rs
  • 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring (partial)

    • from audit:

      • The function execute_open_requests() has over 150 LOC and does different things at once. This approach is not recommended as it increases the complexity of the whole function, may introduce errors and decreases the code's readability.
      • The last portion of the function is in charge of executing all the remaining requests on the Hashmap. As this functionality can be done in isolation, it is advised that it is moved to a separate function that receives the hashmap or list of open transactions pending execution.
    • files covered:

      • the whole clients/vault/src/requests directory, which replaces execution.rs
      • took the initiative to breakdown vault_integration_tests.rs as well:
        • see clients/vault/tests/helper directory
  • STL-03 | Lack of Validation for destination_address on send_payment_to_address() (partial)

    • from audit:

      • The function send_payment_to_address() from stellar_wallet doesn't check if the destination address is the same user. Although this would not lead to malicious behavior, the action doesn't make sense and would make the user lose money in the fees involved in the transfer.
    • files covered:

      • clients/wallet/src/stellar_wallet.rs
        • see my comment on why I exclude the checking for feature testing-utils.

additional PRs:

@@ -21,13 +20,13 @@ mod system;

mod issue;
pub mod oracle;
mod requests;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

mod requests replaces mod execution. It splits the old execution.rs into 3:

  • execution.rs
  • helper.rs
  • structs.rs

@@ -152,14 +193,45 @@ pub struct TransactionResponse {
pub memo: Option<Vec<u8>>,
}

impl Debug for TransactionResponse {
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 simple derive debug prints the value of the fields in Vec<u8>. Converting them to a readable string will make it easier when we want to view the xdr.

@@ -6,7 +6,9 @@ name = "vault"
version = "0.0.1"

[features]
integration = []
integration = [
"wallet/testing-utils"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

see fn listen_for_new_transactions(...) in clients/wallet/src/horizon/horizon.rs

clients/wallet/src/horizon/responses.rs Outdated Show resolved Hide resolved
clients/wallet/src/horizon/responses.rs Outdated Show resolved Hide resolved
primitives/src/lib.rs Outdated Show resolved Hide resolved
pallets/issue/src/lib.rs Outdated Show resolved Hide resolved
pallets/redeem/src/lib.rs Outdated Show resolved Hide resolved
// and are just waiting to be executed on the parachain
spawn_tasks_to_execute_open_requests_async(
&mut open_requests,
wallet,
Copy link
Member

Choose a reason for hiding this comment

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

Now that I look and compare this call to spawn_tasks_to_execute_open_requests_async to spawn_tasks_to_pay_and_execute_open_requests, it's striking that one of these functions is passing the vault_id_manager and the other is just using the wallet.
This reveals a potential logical flaw because, although at the moment all the vaults that simultaneously live in the same vault client use the same Stellar wallet, this could change in the future and then we miss fetching the wallet per vault in this function. I think we shouldn't even pass a wallet parameter to the execute_open_requests function in the first place. It should be enough to pass the vault_id_manager like we do already and then iterating over all registered vaults with vault_id_manager.get_entries(), accessing their stored StellarWallet (in the spawn_tasks_to_execute_open_requests_async function).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea. I would prefer a new issue ticket for this.

Copy link
Member

Choose a reason for hiding this comment

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

Good point. I'll create a follow-up

Copy link
Member

Choose a reason for hiding this comment

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

Created the follow-up here.

clients/vault/src/requests/helper.rs Show resolved Hide resolved
clients/vault/src/requests/helper.rs Show resolved Hide resolved
clients/vault/src/requests/helper.rs Outdated Show resolved Hide resolved
clients/vault/tests/helper/mod.rs Outdated Show resolved Hide resolved
@b-yap b-yap linked an issue Aug 23, 2023 that may be closed by this pull request
26 tasks
@b-yap b-yap force-pushed the 257-fix-informational-issues branch from 1ea31da to 29669e2 Compare August 25, 2023 06:32
b-yap and others added 12 commits September 26, 2023 22:56
…unction - Refactoring (#388)

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - partial

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - for System's fn run_service()

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - fix from previous commit

* remove stray log

* remove extra space

* https://github.com/pendulum-chain/spacewalk/pull/388/files#r1312732850,
#388 (comment)
* IML-01 | Same Behavior Defined For Different Conditions

* LI7-05 | Mismatch in Variable Name and Pallet Name

* 9B2-02 | Inconsistent Comments

* PRF-01 | Unhandled Error

* LIH-03 | Values Length Not Validated in `feed_values` Function

* CLI-01 | Confusing Function Naming

* CLI-03 | Incorrect Error Type Thrown partial

* CLI-03 | Incorrect Error Type Thrown

* #390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
https://github.com/pendulum-chain/spacewalk/actions/runs/6048709746/job/16414585252?pr=390#step:12:38

* https://github.com/pendulum-chain/spacewalk/actions/runs/6069946336/job/16465120232?pr=390#step:11:1573

* fix rustfmt error: https://github.com/pendulum-chain/spacewalk/actions/runs/6072497871/job/16472578544?pr=390
* partial of 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring;

partial of STL-03 | Lack of Validation for `destination_address` on `send_payment_to_address()`

* 257 FIx Informational Issues - Logic Should be Moved To an Separate Function - Refactoring (#388)

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - partial

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - for System's fn run_service()

* 9B2-04 | Logic Should be Moved To an Separate Function - Refactoring - fix from previous commit

* remove stray log

* remove extra space

* https://github.com/pendulum-chain/spacewalk/pull/388/files#r1312732850,
#388 (comment)

* 257 Fix informational issues part 3 (#390)

* IML-01 | Same Behavior Defined For Different Conditions

* LI7-05 | Mismatch in Variable Name and Pallet Name

* 9B2-02 | Inconsistent Comments

* PRF-01 | Unhandled Error

* LIH-03 | Values Length Not Validated in `feed_values` Function

* CLI-01 | Confusing Function Naming

* CLI-03 | Incorrect Error Type Thrown partial

* CLI-03 | Incorrect Error Type Thrown

* #390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
https://github.com/pendulum-chain/spacewalk/actions/runs/6048709746/job/16414585252?pr=390#step:12:38

* https://github.com/pendulum-chain/spacewalk/actions/runs/6069946336/job/16465120232?pr=390#step:11:1573

* fix rustfmt error: https://github.com/pendulum-chain/spacewalk/actions/runs/6072497871/job/16472578544?pr=390

* CLI-01 | Confusing Function Naming

* #390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
#390 (comment),
https://github.com/pendulum-chain/spacewalk/actions/runs/6048709746/job/16414585252?pr=390#step:12:38

* STL-02 | Code Duplication

* SRC-01 | Unused Methods and Storage

* 9B2-05 | Commented Out Code (partial)

* LBC-03 | Inconsistent `match` Expression

* LIY-03 | Reduce Using `unwrap()` and `expect()` in Production Codebase

* TYL-01 | Confusing Variable Naming

* put back the removed dependencies

* https://github.com/pendulum-chain/spacewalk/actions/runs/6095148657/job/16538119439?pr=393#step:11:91

* https://github.com/pendulum-chain/spacewalk/actions/runs/6096401270/job/16541879632#step:11:93

* https://github.com/pendulum-chain/spacewalk/actions/runs/6096401270/job/16541879632#step:11:93

* https://github.com/pendulum-chain/spacewalk/actions/runs/6097368982/job/16544863469?pr=393#step:11:94

* https://github.com/pendulum-chain/spacewalk/actions/runs/6098205449/job/16547533143?pr=393#step:13:19

* #393 (comment),
partly #393 (review)

* #393 (comment)

* #393 (comment),
#393 (review) for vault

* #393 (comment)

* fix https://github.com/pendulum-chain/spacewalk/actions/runs/6263576242/job/17008273208?pr=393#step:12:894

* https://github.com/pendulum-chain/spacewalk/actions/runs/6272775696/job/17034964214?pr=393#step:12:434

* https://github.com/pendulum-chain/spacewalk/actions/runs/6275148901/job/17041998689?pr=393#step:12:587

* https://github.com/pendulum-chain/spacewalk/actions/runs/6276542346/job/17091576766#step:12:476

* #393 (comment)

* #393 (comment) and fix rebase

* 401 fix issues of connecting to stellar overlay network on testnet (#414)

* a 3rd try of #409

* cargo fmt and fix warnings in
https://github.com/pendulum-chain/spacewalk/actions/runs/6459806136/job/17536291785?pr=414

* update the `substrate-stellar-sdk` version

* #414 (comment),
#414 (comment),
#414 (comment),
#414 (comment)

* LIL-01 Dead Code in execute_replace()
LIT-03 Panic can happen between correlated storage modifications

* LIL-01 Dead Code in execute_replace() add back the comment
@b-yap b-yap requested a review from ebma October 11, 2023 12:05
Copy link
Member

@ebma ebma left a comment

Choose a reason for hiding this comment

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

LGTM. We really need to create a follow-up ticket to clean up the code that is commented out though

@ebma ebma mentioned this pull request Oct 11, 2023
@ebma ebma marked this pull request as ready for review October 12, 2023 09:31
@ebma
Copy link
Member

ebma commented Oct 12, 2023

We tested all the commands of the workflow locally and it works fine. I don't want to wait for the CI jobs to finish again so we merge this right away.

@ebma ebma merged commit 8bb0d63 into main Oct 12, 2023
0 of 2 checks passed
@ebma ebma deleted the 257-fix-informational-issues branch October 12, 2023 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants