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

Implementation of EthSwap mechanism #2276

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft

Implementation of EthSwap mechanism #2276

wants to merge 21 commits into from

Conversation

rmoreliovlabs
Copy link
Contributor

Description

This pull request is not intended to be merged, its purpose is to review the proof of contect of the EthSwap mechanism.

Motivation and Context

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • Tests for the changes have been added (for bug fixes / features)
  • Requires Activation Code (Hard Fork)
  • Other information:

@fmacleal fmacleal changed the title Implmentation of EthSwap mechanism Implementation of EthSwap mechanism May 9, 2024
Copy link
Contributor

@fmacleal fmacleal left a comment

Choose a reason for hiding this comment

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

Very good job, I have a few suggestions to simplify some functions and ideas to avoid some changes that could be skipped.

Let me know your thoughts. 🙂

rskj-core/src/test/java/org/ethereum/rpc/Web3ImplTest.java Outdated Show resolved Hide resolved
rskj-core/src/test/java/co/rsk/util/ContractUtilTest.java Outdated Show resolved Hide resolved
@rmoreliovlabs
Copy link
Contributor Author

pipeline:run

rskj-core/src/main/java/co/rsk/core/bc/BlockExecutor.java Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Good refactor. 👍

Copy link
Contributor

@asoto-iov asoto-iov left a comment

Choose a reason for hiding this comment

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

Added some comments, most of then related with the utility class but I'm still reviewing the PR.

rskj-core/src/main/java/co/rsk/util/EthSwapUtil.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/util/EthSwapUtil.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/util/EthSwapUtil.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/util/EthSwapUtil.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/util/EthSwapUtil.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/util/EthSwapUtil.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/util/EthSwapUtil.java Outdated Show resolved Hide resolved
rskj-core/src/main/java/co/rsk/util/EthSwapUtil.java Outdated Show resolved Hide resolved
@rmoreliovlabs
Copy link
Contributor Author

pipeline:run

1 similar comment
@rmoreliovlabs
Copy link
Contributor Author

pipeline:run

@jurajpiar jurajpiar force-pushed the ethswap-poc branch 2 times, most recently from 4c74307 to 8c3fc89 Compare May 27, 2024 09:32
@Vovchyk Vovchyk marked this pull request as ready for review June 4, 2024 07:48
@Vovchyk Vovchyk marked this pull request as draft June 4, 2024 07:49
fmacleal
fmacleal previously approved these changes Jun 6, 2024
Copy link
Contributor

@fmacleal fmacleal left a comment

Choose a reason for hiding this comment

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

Good job mate, it's a complex issue and I know you had to change it lots of time.
Congrats!
:)

Copy link

sonarcloud bot commented Jun 6, 2024

logger.warn("block: [{}] discarded claim tx: [{}], because the funds it tries to claim no longer exist in contract",
block.getNumber(),
tx.getHash());
continue;
Copy link

Choose a reason for hiding this comment

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

may cause an issue if just skipped. should be analyzed in more detail.

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 reason I used this approach is that it aligns with the existing logic in the BlockExecutor. Just like how invalid transactions are managed there, invalid Claim transactions are discarded if discardInvalidTxs is set to true. If not, the execution is stopped

For General Transactions, the handling is similar:

if (!acceptInvalidTransactions && !transactionExecuted) {
    if (discardInvalidTxs) {
        logger.warn("block: [{}] discarded tx: [{}]", block.getNumber(), tx.getHash());
        continue;
    } else {
        logger.warn("block: [{}] execution interrupted because of invalid tx: [{}]",
                    block.getNumber(), tx.getHash());
        profiler.stop(metric);
        return BlockResult.INTERRUPTED_EXECUTION_BLOCK_RESULT;
    }
}

Just as we discard invalid general transactions, we also discard invalid Claim transactions based on specific validation criteria. This ensures we maintain consistency in handling invalid transactions across the code
Let me know if you have any further questions!

Copy link

Choose a reason for hiding this comment

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

But Claim transactions that don't have locked funds !claimTransactionValidator.hasLockedFunds(tx, track)) would be just discarded without interrupting the execution regardless of discardInvalidTxs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, invalid claim transactions (those without locked funds) are indeed discarded without interrupting block execution, regardless of the discardInvalidTxs value. This behavior is intentional and aligned with the design outlined in the TDD and Sergio's proposal

The logic was implemented to ensure that claim transactions, which don't meet the requirement of having locked funds, are simply discarded to prevent them from affecting the overall block processing. This ensures that the chain execution continues smoothly without being interrupted by these invalid claim transactions. The proposal specifies that invalid claims should not stop the block execution but rather be skipped to maintain stability and performance. You can find the detailed reasoning behind this in the initial Sergio's proposal document here

Happy to explain further if needed!

@rmoreliovlabs rmoreliovlabs force-pushed the ethswap-poc branch 2 times, most recently from 5bb1765 to f56c49d Compare August 12, 2024 00:13
Copy link

sonarcloud bot commented Aug 12, 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.

5 participants