Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Ermolin committed Jan 20, 2022
1 parent 2dd5fe5 commit 8c9ad51
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 22 deletions.
13 changes: 7 additions & 6 deletions contracts/staking/stakeManager/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,17 @@ contract StakeManager is
address currentSigner = validators[validatorId].signer;
// update signer event
logger.logSignerChange(validatorId, currentSigner, signer, signerPubkey);

if (validators[validatorId].deactivationEpoch == 0) {
// didn't unstake, safe to remove the signer from the list
_removeSigner(currentSigner);
}

_insertSigner(signer);

This comment has been minimized.

Copy link
@jdkanani

jdkanani Jan 20, 2022

Contributor

We don't need to insert since the validator is already unstaked. Since unstake already removes signer from signers.

We can just stop updateSigner if the validator is already unstaked.


signerToValidator[currentSigner] = INCORRECT_VALIDATOR_ID;
signerToValidator[signer] = validatorId;
validators[validatorId].signer = signer;
_updateSigner(currentSigner, signer);

// reset update time to current time
latestSignerUpdateEpoch[validatorId] = _currentEpoch;
Expand Down Expand Up @@ -1202,11 +1208,6 @@ contract StakeManager is
}
}

function _updateSigner(address prevSigner, address newSigner) internal {
_removeSigner(prevSigner);
_insertSigner(newSigner);
}

function _removeSigner(address signerToDelete) internal {
uint256 totalSigners = signers.length;
address swapSigner = signers[totalSigners - 1];
Expand Down
25 changes: 9 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions test/units/staking/stakeManager/StakeManager.Staking.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '../../../helpers/utils.js'
import { expectEvent, expectRevert, BN } from '@openzeppelin/test-helpers'
import { wallets, walletAmounts, freshDeploy, approveAndStake } from '../deployment'
import { assert } from 'chai'

module.exports = function(accounts) {
let owner = accounts[0]
Expand Down Expand Up @@ -317,6 +318,48 @@ module.exports = function(accounts) {
})

describe('unstake', function() {
describe('when Alice unstakes and update the signer', function() {
const AliceWallet = wallets[1]
const BobWallet = wallets[3]
const AliceNewWallet = wallets[2]

before(freshDeploy)
before(doStake(AliceWallet))
before(doStake(BobWallet))
before('Change signer', async function() {
const signerUpdateLimit = await this.stakeManager.signerUpdateLimit()
await this.stakeManager.advanceEpoch(signerUpdateLimit)

this.validatorId = await this.stakeManager.getValidatorId(AliceWallet.getAddressString())

})

it('Alice should unstake', async function() {
this.receipt = await this.stakeManager.unstake(this.validatorId, {
from: AliceWallet.getAddressString()
})
})

it('Signers list should have only Bob\'s signer', async function() {
assert((await this.stakeManager.signers(0)) == BobWallet.getChecksumAddressString(), 'no Bob signer!')
await expectRevert.unspecified(this.stakeManager.signers(1))
})

it('Alice should update signer', async function() {
await this.stakeManager.updateSigner(this.validatorId, AliceNewWallet.getPublicKeyString(), {
from: AliceWallet.getAddressString()
})
})

it('Signers list should have new Alice\'s signer and Bob\'s signer', async function() {
const signers = [await this.stakeManager.signers(0), await this.stakeManager.signers(1)]


assert(signers.findIndex(x => x == AliceNewWallet.getChecksumAddressString()) !== -1, 'no Alice signer!')
assert(signers.findIndex(x => x == BobWallet.getChecksumAddressString()) !== -1, 'no Bob signer!')
})
})

describe('when user unstakes right after stake', async function() {
const user = wallets[2].getChecksumAddressString()
const amounts = walletAmounts[wallets[2].getAddressString()]
Expand Down

0 comments on commit 8c9ad51

Please sign in to comment.