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: enable withdraw all stake endpoint #3662

Merged
8 commits merged into from Dec 16, 2022
Merged

refactor: enable withdraw all stake endpoint #3662

8 commits merged into from Dec 16, 2022

Conversation

ghost
Copy link

@ghost ghost commented Dec 16, 2022

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

Adds an endpoint to delete all existing stake.

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

Screenshots (if appropriate):


This change is Reviewable

@ghost ghost requested review from istae, aloknerurkar and mrekucci December 16, 2022 13:59
@ghost ghost marked this pull request as ready for review December 16, 2022 14:08
@ghost ghost changed the title refactor: enable deleting stake refactor: enable withdraw all stake endpoint Dec 16, 2022
@ghost ghost requested a review from metacertain December 16, 2022 14:24
pkg/api/staking.go Outdated Show resolved Hide resolved
pkg/storageincentives/staking/contract_test.go Outdated Show resolved Hide resolved
@ghost ghost requested a review from istae December 16, 2022 14:56
pkg/api/staking.go Outdated Show resolved Hide resolved
return
}
logger.Debug("delete stake failed", "error", err)
logger.Error(nil, "withdraw stake failed")
Copy link
Contributor

Choose a reason for hiding this comment

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

The log message should be the same as the debug message.

pkg/api/staking_test.go Outdated Show resolved Hide resolved
pkg/storageincentives/staking/contract.go Show resolved Hide resolved

func (c *contract) withdrawFromStake(ctx context.Context, stakedAmount *big.Int) (*types.Receipt, error) {
var overlayAddr [32]byte
copy(overlayAddr[:], c.overlay.Bytes())
Copy link
Member

Choose a reason for hiding this comment

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

I think the abi packing needs a [32]byte and not a byte slice

Copy link
Author

@ghost ghost Dec 16, 2022

Choose a reason for hiding this comment

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

nope, it needs byte slice, just checked

pkg/storageincentives/staking/contract.go Show resolved Hide resolved

func (c *contract) withdrawFromStake(ctx context.Context, stakedAmount *big.Int) (*types.Receipt, error) {
var overlayAddr [32]byte
copy(overlayAddr[:], c.overlay.Bytes())
Copy link
Member

Choose a reason for hiding this comment

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

I think the abi packing needs a [32]byte and not a byte slice

@@ -1056,6 +1056,23 @@ paths:
$ref: "SwarmCommon.yaml#/components/responses/500"
default:
description: Default response
delete:
summary: Withdraw all staked amount.
description: Be aware, this endpoint creates an on-chain transactions and transfers BZZ from the node's Ethereum account and hence directly manipulates the wallet balance.
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: we can either drop the an or use transaction (singular)


txHash, err := s.stakingContract.WithdrawAllStake(r.Context())
if err != nil {
if errors.Is(err, staking.ErrInsufficientStake) {
Copy link
Contributor

Choose a reason for hiding this comment

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

just wondering: if we withdraw the entire amount of the stake, can we gen the insufficient stake error?

Copy link
Author

Choose a reason for hiding this comment

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

nope, this edge case deals with the fact that we did not have any stake to begin with

@ghost ghost merged commit 94ff34d into master Dec 16, 2022
@ghost ghost deleted the withdraw branch December 16, 2022 18:18
@aloknerurkar aloknerurkar added this to the 1.10.0 milestone Dec 20, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants