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

refactor: move TxPoolError from fuel-core-types to fuel-core-txpool #2088

Merged

Conversation

netrome
Copy link
Contributor

@netrome netrome commented Aug 15, 2024

Linked Issues/PRs

Description

This PR does three things:

  1. The Error type defined in crates/types/src/services/txpool.rs is moved to crates/services/txpool/src/error.rs.
  2. This error type now also implements From<WasmValidityError>.
  3. Refactor to use derive_more instead of thiserror for the error type.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

@netrome netrome self-assigned this Aug 15, 2024
@netrome
Copy link
Contributor Author

netrome commented Aug 15, 2024

Will rebase on master and mark the PR as ready once #2080 is merged.

@netrome netrome force-pushed the 2082-move-txpoolerror-from-fuel-core-types-to-fuel-core-txpool branch 2 times, most recently from 4b4b47b to 287eee2 Compare August 15, 2024 11:04
@netrome netrome force-pushed the 2082-move-txpoolerror-from-fuel-core-types-to-fuel-core-txpool branch from 7639759 to 7f14fc2 Compare August 15, 2024 12:49
Base automatically changed from dento/validate-wasm-before-upgrade to master August 15, 2024 14:39
@netrome netrome force-pushed the 2082-move-txpoolerror-from-fuel-core-types-to-fuel-core-txpool branch from 7f14fc2 to 2cfe982 Compare August 15, 2024 18:39
@netrome netrome marked this pull request as ready for review August 15, 2024 19:29
@netrome netrome requested a review from a team August 15, 2024 19:29
@netrome netrome linked an issue Aug 15, 2024 that may be closed by this pull request
Copy link
Member

@rymnc rymnc left a comment

Choose a reason for hiding this comment

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

I understand most of this code has been copied from a previous PR, so I apologize for the review comments changing some semantics of the display messages :)

crates/services/txpool/src/error.rs Outdated Show resolved Hide resolved
crates/services/txpool/src/error.rs Outdated Show resolved Hide resolved
)]
NotInsertedCollision(TxId, UtxoId),
#[display(
fmt = "Transaction is not inserted. More priced tx has created contract with ContractId {_0:#x}"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt = "Transaction is not inserted. More priced tx has created contract with ContractId {_0:#x}"
fmt = "Transaction is not inserted. Higher priced tx has created contract with ContractId {_0:#x}"

Copy link
Member

Choose a reason for hiding this comment

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

perhaps we also want to add the tx hash for the already spent utxo like the above error :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can see, we only have ContractId here so I believe you mistook this for the previous NotInsertedCollision variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I've updated the message ✅

Copy link
Member

Choose a reason for hiding this comment

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

yup, I meant to ask if we should include the higher priced tx hash like we have done in other error cases, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sorry I misunderstood you. Yeah that sounds helpful. I'll see if I can include it.

Copy link
Contributor Author

@netrome netrome Aug 16, 2024

Choose a reason for hiding this comment

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

Getting the txid here doesn't look trivial based on my limited understanding of the code unfortunately.

Reasoning:
This variant is only created in crates/services/txpool/src/containers/dependency.rs in a loop that looks like this:

        for output in tx.outputs() {
            if let Output::ContractCreated { contract_id, .. } = output {
                if let Some(contract) = self.contracts.get(contract_id) {
                    // we have a collision :(
                    if contract.is_in_database() {
                        return Err(Error::NotInsertedContractIdAlreadyTaken(*contract_id))
                    }
                    // check who is priced more
                    if contract.tip > tx.tip() {
                        // new tx is priced less then current tx
                        return Err(Error::NotInsertedCollisionContractId(*contract_id))
                    }
                    // if we are prices more, mark current contract origin for removal.
                    let origin = contract.origin.expect(
                        "Only contract without origin are the ones that are inside DB. And we check depth for that, so we are okay to just unwrap"
                        );
                    collided.push(*origin.tx_id());
                }
            }
            // collision of other outputs is not possible.
        }

The contract variable here is of the following type

#[derive(Debug, Clone)]
pub struct ContractState {
    /// is Utxo spend as other Tx input
    used_by: HashSet<TxId>,
    /// how deep are we inside UTXO dependency
    depth: usize,
    /// origin is needed for child to parent rel, in case when contract is in dependency this is how we make a chain.
    origin: Option<UtxoId>,
    /// gas_price. We can probably derive this from Tx
    tip: Word,
}

which does not seem to hold the information about which txid created the contract.

There may be other ways to fetch the txid, but that would complect the code for what seems to be a very unusual error scenario so I'll leave this as-is for now if that's alright with you.

crates/services/txpool/src/error.rs Outdated Show resolved Hide resolved
crates/services/txpool/src/error.rs Outdated Show resolved Hide resolved
crates/services/txpool/src/error.rs Outdated Show resolved Hide resolved
crates/services/txpool/src/error.rs Outdated Show resolved Hide resolved
Comment on lines +128 to +131
#[display(fmt = "The UTXO `{_0}` is blacklisted")]
BlacklistedUTXO(UtxoId),
#[display(fmt = "The owner `{_0}` is blacklisted")]
BlacklistedOwner(Address),
#[display(fmt = "The contract `{_0}` is blacklisted")]
BlacklistedContract(ContractId),
#[display(fmt = "The message `{_0}` is blacklisted")]
BlacklistedMessage(Nonce),
Copy link
Member

Choose a reason for hiding this comment

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

not a review comment, but rather a question
is this for regulatory purposes? @xgreenx

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, it is for the case of bugs in the network that causes money printing=)

crates/services/txpool/src/lib.rs Show resolved Hide resolved
crates/services/txpool/src/lib.rs Show resolved Hide resolved
@netrome
Copy link
Contributor Author

netrome commented Aug 16, 2024

I understand most of this code has been copied from a previous PR, so I apologize for the review comments changing some semantics of the display messages :)

No worries, and thanks for the suggestions. This is a good opportunity to improve the messages. I'll update them.

@netrome netrome force-pushed the 2082-move-txpoolerror-from-fuel-core-types-to-fuel-core-txpool branch from 5133ad6 to df129d0 Compare August 16, 2024 06:22
@netrome netrome force-pushed the 2082-move-txpoolerror-from-fuel-core-types-to-fuel-core-txpool branch from cd5c113 to 33c8643 Compare August 16, 2024 07:24
@netrome netrome requested review from xgreenx, rymnc and a team August 16, 2024 07:31
Copy link
Member

@rymnc rymnc left a comment

Choose a reason for hiding this comment

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

LGTM, but won't approve (in case it gets automerged) because someone with more experience with the codebase should probably sign off on it :)

@netrome netrome requested a review from a team August 16, 2024 09:02
Copy link
Collaborator

@xgreenx xgreenx left a comment

Choose a reason for hiding this comment

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

LGTM=)

CHANGELOG.md Outdated Show resolved Hide resolved
crates/services/txpool/src/txpool.rs Outdated Show resolved Hide resolved
Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
@netrome netrome requested a review from xgreenx August 16, 2024 09:42
CHANGELOG.md Outdated Show resolved Hide resolved
@netrome netrome requested a review from xgreenx August 16, 2024 09:52
@xgreenx xgreenx enabled auto-merge (squash) August 16, 2024 09:52
@xgreenx xgreenx merged commit 6effb64 into master Aug 16, 2024
30 checks passed
@xgreenx xgreenx deleted the 2082-move-txpoolerror-from-fuel-core-types-to-fuel-core-txpool branch August 16, 2024 10:11
@xgreenx xgreenx mentioned this pull request Aug 18, 2024
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.

Move TxPoolError from fuel-core-types to fuel-core-txpool
3 participants