Skip to content

Commit

Permalink
chore: add ValidatorExists into the returned Undelegations struct
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubFornadel committed Feb 28, 2023
1 parent 5516418 commit 7ee2d3c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions taraxa/state/dpos/precompiled/dpos_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,8 @@ func (self *Contract) getUndelegations(args sol.GetUndelegationsArgs) (undelegat

var undelegation_data sol.DposInterfaceUndelegationData
undelegation_data.Validator = validator_address
// Validator can be already deleted before confirming undelegation if he had 0 rewards and stake balances
undelegation_data.ValidatorExists = self.validators.ValidatorExists(&validator_address)
undelegation_data.Stake = undelegation.Amount
undelegation_data.Block = undelegation.Block

Expand Down
2 changes: 1 addition & 1 deletion taraxa/state/dpos/precompiled/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (self *Validators) DeleteValidator(validator_address *common.Address) {
rewards_key := stor_k_1(self.validator_rewards_field, validator_address[:])
self.storage.Put(rewards_key, nil)

// Removes validator into the list of all validators
// Removes validator from the list of all validators
self.validators_list.RemoveAccount(validator_address)
}

Expand Down
3 changes: 3 additions & 0 deletions taraxa/state/dpos/solidity/dpos_contract_interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ interface DposInterface {
uint256 stake;
// block number when it will be unlocked
uint64 block;
// Validator address
address validator;
// Flag if validator still exists - in case he has 0 stake and 0 rewards, validator is deleted from memory & db
bool validator_exists;
}

// Delegates tokens to specified validator
Expand Down
Loading

0 comments on commit 7ee2d3c

Please sign in to comment.