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: Remove IncreaseAllowance & Add shared nonce (#1) #43

Merged
merged 9 commits into from
Feb 2, 2024

Conversation

iljabvh
Copy link
Contributor

@iljabvh iljabvh commented Jan 9, 2024

This PR fixes #41 and modifies the depositing mechanism of the Ethereum backend for ERC20 assets. Both changes enable the backend to handle multiple payment channels for one Perun client.

@cryptphil
Copy link
Member

I would probably have split this PR into two separate PRs for the two main changes here, but for the sake of time, we'll just use this single PR here.

Copy link
Member

@cryptphil cryptphil left a comment

Choose a reason for hiding this comment

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

I have some other remarks to the ERC20 Depositor, which I will just fix in a different branch in perun-network and will then create another PR there.

Edit: I'm not really able to write my suggestions as there are some more uncertainties regarding the implementation, so I'll add my questions in this PR.

channel/contractbackend.go Outdated Show resolved Hide resolved
channel/contractbackend.go Outdated Show resolved Hide resolved
channel/contractbackend.go Outdated Show resolved Hide resolved
tx2, err := assetholder.Deposit(opts, req.FundingID, req.Balance)
err = cherrors.CheckIsChainNotReachableError(err)
return []*types.Transaction{tx1, tx2}, errors.WithMessage(err, "AssetHolderERC20 depositing")
return tx2, err
Copy link
Member

Choose a reason for hiding this comment

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

Rename tx2 to just tx.

var err1 error
lockAndUnlock(lock, func() {
allowance, err := token.Allowance(&callOpts, req.Account.Address, req.Asset.EthAddress())
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

If any of these ifs should be true, which means that an error has occurred, the function will still continue to execute

sophia1ch and others added 9 commits February 2, 2024 12:38
* channel: Include shared Nonce object, incrementing the nonce of an account while the transaction is broadcast. Implement sync.Mutex, locking the nonce incrementals.
In erc20_depositor.go, the depositing process is locked during the "Approve" function call with ```lockKey```. The function ```(d *ERC20Depositor) Deposit``` is renamed to `````(d *ERC20Depositor) DepositOnly`

* client: To avoid timeouts caused by the added locking mechanism during ERC20 deposits, ```context.WithTimeout``` and ```twoPartyTestTimeout``` has been increased in fund_test.go and payment_test.go.

* client/test: Timeouts have been increased to avoid premature timeout errors due to the locking mechanism above.

---------

Signed-off-by: Ilja von Hoessle <ilja@perun.network>
Signed-off-by: sophia1ch <sophia.koehler@outlook.com>
Remove unused SharedNonceMtx.

Signed-off-by: sophia1ch <sophia.koehler@outlook.com>
refactor(erc20_depositor):
- Create seperate function for Approval.
- Rename lock and mutex.

Signed-off-by: sophia1ch <sophia.koehler@outlook.com>
- Add description to Approve function.
- Put Error as last return element in Approve function.
fix(erc20_depositor):
- remove unnecessary locking of depositLocksMtx.

Signed-off-by: sophia1ch <sophia.koehler@outlook.com>
Fix comment and Argument order for Linter.

Signed-off-by: sophia1ch <sophia.koehler@outlook.com>
Signed-off-by: sophia1ch <sophia.koehler@outlook.com>
Co-authored-by: Philipp Lehwalder <philipp.lehwalder@gmail.com>
Signed-off-by: Sophia <118169531+sophia1ch@users.noreply.github.com>
- Change SharedMutex to SharedExpectedNoncesMutex.
refactor(erc20_depositor):
- Return directly if Approval returns error.
- Fix comments.

Signed-off-by: sophia1ch <sophia.koehler@outlook.com>
Change position of bracket.

Signed-off-by: sophia1ch <sophia.koehler@outlook.com>
@iljabvh
Copy link
Contributor Author

iljabvh commented Feb 2, 2024

This PR enables Perun clients to

  • participate in an arbitrary number of payment channels in parallel
  • use any native and ERC20 asset in said channels

@iljabvh iljabvh merged commit 2e7b344 into hyperledger-labs:main Feb 2, 2024
6 checks passed
@iljabvh iljabvh mentioned this pull request Feb 26, 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.

ContractBackend: Nonce is not incremented correctly across multiple CBs, leading to collusion
4 participants