Skip to content

Commit

Permalink
fix(evmstaking): fix overwrite issue of withdraw and reward address
Browse files Browse the repository at this point in the history
  • Loading branch information
ezreal1997 committed Oct 30, 2024
1 parent bdc4e13 commit f2c0770
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
17 changes: 13 additions & 4 deletions client/x/evmstaking/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,20 @@ func (k Keeper) ProcessDeposit(ctx context.Context, ev *bindings.IPTokenStakingD
// Note that, after minting, we save the mapping between delegator bech32 address and evm address, which will be used in the withdrawal queue.
// The saving is done regardless of any error below, as the money is already minted and sent to the delegator, who can withdraw the minted amount.
// TODO: Confirm that bech32 address and evm address can be used interchangeably. Must be one-to-one or many-bech32-to-one-evm.
if err := k.DelegatorWithdrawAddress.Set(ctx, depositorAddr.String(), delEvmAddr.String()); err != nil {
return errors.Wrap(err, "set delegator withdraw address map")
// NOTE: Do not overwrite the existing withdraw/reward address set by the delegator.
if exists, err := k.DelegatorWithdrawAddress.Has(ctx, depositorAddr.String()); err != nil {
return errors.Wrap(err, "check delegator withdraw address existence")
} else if !exists {
if err := k.DelegatorWithdrawAddress.Set(ctx, depositorAddr.String(), delEvmAddr.String()); err != nil {
return errors.Wrap(err, "set delegator withdraw address map")
}
}
if err := k.DelegatorRewardAddress.Set(ctx, depositorAddr.String(), delEvmAddr.String()); err != nil {
return errors.Wrap(err, "set delegator reward address map")
if exists, err := k.DelegatorRewardAddress.Has(ctx, depositorAddr.String()); err != nil {
return errors.Wrap(err, "check delegator reward address existence")
} else if !exists {
if err := k.DelegatorRewardAddress.Set(ctx, depositorAddr.String(), delEvmAddr.String()); err != nil {
return errors.Wrap(err, "set delegator reward address map")
}
}

delID := ev.DelegationId.String()
Expand Down
17 changes: 13 additions & 4 deletions client/x/evmstaking/keeper/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ func (k Keeper) ProcessCreateValidator(ctx context.Context, ev *bindings.IPToken
// Note that, after minting, we save the mapping between delegator bech32 address and evm address, which will be used in the withdrawal queue.
// The saving is done regardless of any error below, as the money is already minted and sent to the delegator, who can withdraw the minted amount.
// TODO: Confirm that bech32 address and evm address can be used interchangeably. Must be one-to-one or many-bech32-to-one-evm.
if err := k.DelegatorWithdrawAddress.Set(ctx, delegatorAddr.String(), delEvmAddr.String()); err != nil {
return errors.Wrap(err, "set delegator withdraw address map")
// NOTE: Do not overwrite the existing withdraw/reward address set by the validator.
if exists, err := k.DelegatorWithdrawAddress.Has(ctx, delegatorAddr.String()); err != nil {
return errors.Wrap(err, "check delegator withdraw address existence")
} else if !exists {
if err := k.DelegatorWithdrawAddress.Set(ctx, delegatorAddr.String(), delEvmAddr.String()); err != nil {
return errors.Wrap(err, "set delegator withdraw address map")
}
}
if err := k.DelegatorRewardAddress.Set(ctx, delegatorAddr.String(), delEvmAddr.String()); err != nil {
return errors.Wrap(err, "set delegator reward address map")
if exists, err := k.DelegatorRewardAddress.Has(ctx, delegatorAddr.String()); err != nil {
return errors.Wrap(err, "check delegator reward address existence")
} else if !exists {
if err := k.DelegatorRewardAddress.Set(ctx, delegatorAddr.String(), delEvmAddr.String()); err != nil {
return errors.Wrap(err, "set delegator reward address map")
}
}

// TODO: Check if we can instantiate the msgServer without type assertion
Expand Down

0 comments on commit f2c0770

Please sign in to comment.