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

core balances logic includes reactivation #108

Merged
merged 25 commits into from
Nov 10, 2022
Merged

Conversation

vadiminc
Copy link
Contributor

@vadiminc vadiminc commented Nov 1, 2022

No description provided.

if(_liquidatable(pod.disabled, _podBalance(pod, _clusterCurrentIndex(clusterId)), pod.validatorCount, operatorIds)) {
revert NotEnoughBalance();
}
/* TODO: Adam, Lior, Andrew - check following two lines */
Copy link
Contributor Author

@vadiminc vadiminc Nov 1, 2022

Choose a reason for hiding this comment

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

@adamzigdon @andrew-blox @lior-blox check these lines. 538, 539, 540 lines


function withdraw(bytes32 clusterId, uint256 tokenAmount) external;

function withdrawAll(bytes32 clusterId) external;

Choose a reason for hiding this comment

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

@vadiminc How does an operator withdraw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lior-blox right, missed - will add extra interface for operator

@@ -53,9 +53,13 @@ contract SSVNetwork is OwnableUpgradeable, ISSVNetwork {

struct Pod {
uint64 validatorCount;
uint64 withdrawn;

Choose a reason for hiding this comment

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

@vadiminc why do we need it? cant we deduct it from the snapshot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lior-blox removed

revert NotEnoughBalance();
}

if(_burnRatePerValidator(operatorIds) > 0) {

Choose a reason for hiding this comment

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

@vadiminc @andrew-blox In which case this can happen?

}

pod.withdrawn += podBalance;
_pods[hashedPod] = pod;

Choose a reason for hiding this comment

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

@vadiminc Shouldn't it mark the pod as disabled and update the operators?

Choose a reason for hiding this comment

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

or to do self-liquidation?

revert NotEnoughBalance();
}
/* TODO: Adam, Lior, Andrew - check following two lines */
pod = _updatePodData(clusterId, 0, hashedPod, false);

Choose a reason for hiding this comment

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

@vadiminc this is a bad hack.
maybe to change instead bool increase to uint? i.e (-1,0,1)?


it('Deposit', async () => {
minDepositAmount = (helpers.CONFIG.minimalBlocksBeforeLiquidation + 10) * helpers.CONFIG.minimalOperatorFee * 4;

Choose a reason for hiding this comment

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

@vadiminc Why do we need this?

Copy link
Contributor Author

@vadiminc vadiminc Nov 2, 2022

Choose a reason for hiding this comment

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

@lior-blox what do you mean why? instead of to use magic unclear numbers in the test - we know that minDepositAmount covers threshold period before liquidation for per validator

[GasGroup.REMOVE_VALIDATOR]: 120000,
[GasGroup.TRANSFER_VALIDATOR_NEW_CLUSTER]: 400000,
[GasGroup.TRANSFER_VALIDATOR]: 260000,
[GasGroup.TRANSFER_VALIDATOR_NON_EXISTING_POD]: 290000,
[GasGroup.BULK_TRANSFER_VALIDATOR]: 362000,
[GasGroup.BULK_TRANSFER_VALIDATOR_NON_EXISTING_POD]: 379000,
[GasGroup.LIQUIDATE_VALIDATOR]: 101000,
[GasGroup.LIQUIDATE_VALIDATOR]: 120000,

Choose a reason for hiding this comment

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

@vadiminc there is no liquidate validator, only POD so please rename, why it increased?

[GasGroup.REMOVE_VALIDATOR]: 120000,
[GasGroup.TRANSFER_VALIDATOR_NEW_CLUSTER]: 400000,
[GasGroup.TRANSFER_VALIDATOR]: 260000,
[GasGroup.TRANSFER_VALIDATOR_NON_EXISTING_POD]: 290000,
[GasGroup.BULK_TRANSFER_VALIDATOR]: 362000,
[GasGroup.BULK_TRANSFER_VALIDATOR_NON_EXISTING_POD]: 379000,
[GasGroup.LIQUIDATE_VALIDATOR]: 101000,
[GasGroup.LIQUIDATE_VALIDATOR]: 120000,
[GasGroup.DEPOSIT]: 84000,

Choose a reason for hiding this comment

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

@vadiminc @andrew-blox This new gases are too much
please revisit

Copy link
Contributor Author

@vadiminc vadiminc Nov 2, 2022

Choose a reason for hiding this comment

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

@andrew-blox @lior-blox i change deposit flow to work with pod and it saved us 5k gas. So now it's 77k gas usage
part of it:

  • 20k - token transfer
  • 2k - emit event,
    the rest is the logic.

[GasGroup.DEPOSIT]: 84000,
[GasGroup.WITHDRAW]: 96000,
[GasGroup.REGISTER_POD]: 141000,
[GasGroup.REACTIVATE_POD]: 251000,

Choose a reason for hiding this comment

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

@vadiminc @andrew-blox Not clear why reactivate is so expensive compared to register

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lior-blox @andrew-blox as I've removed "create pod" from the deposit func, we saved 10k for reactivepod as well

Comment on lines 375 to 384
function deposit(bytes calldata publicKey, uint256 amount) external {
_validatePublicKey(publicKey);
bytes32 hashedValidator = keccak256(publicKey);

if (_validatorPKs[hashedValidator].owner != msg.sender) {
revert ValidatorNotOwned();
}

_deposit(msg.sender, _validatorPKs[hashedValidator].clusterId, amount.shrink());
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lior-blox @vadiminc
I understand we have capability of getting cluster or pod id from a validators public key but its a little weird to deposit using a validators public key as the param instead of like a cluster id no?

This also applies for the other deposit and for withdraw.

}

function withdraw(bytes32 clusterId, uint256 amount) external override {
_validateClusterId(clusterId);
function withdraw(bytes calldata publicKey, uint256 amount) external override {
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this function you call amount.shrink twice (which in itself calls other functions), i suggest to make a var for it.

@@ -393,33 +408,51 @@ contract SSVNetwork is OwnableUpgradeable, ISSVNetwork {

_token.transfer(msg.sender, amount);

emit FundsWithdrawal(amount, clusterId, msg.sender);
emit ValidatorFundsWithdrawal(amount, publicKey, msg.sender);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@lior-blox
I think we should go over all emit names for all functions added.

}

function withdrawAll(bytes32 clusterId) external override {
_validateClusterId(clusterId);
function withdraw(uint64 operatorId, uint256 amount) external override {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Calling amount.shrink 4 times

emit OperatorFundsWithdrawal(amount.shrink(), operatorId, msg.sender);
}

function withdrawAll(uint64 operatorId) external override {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe make var for expand function

@liorrutenberg liorrutenberg merged commit 3030335 into contract-v3 Nov 10, 2022
@liorrutenberg liorrutenberg deleted the balances branch November 10, 2022 16:05
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.

4 participants