delegation to not-registered PRep
When delegating to not-register PRep, PrepManager should write delegation value to Prep status.
TotalDelegated value of PRepManger should be adjusted accordingly.
@@ -410,6 +410,9 @@ func (pm *PRepManager) RegisterPRep(regInfo *RegInfo, irep *big.Int) error {
if ps := pm.state.GetPRepStatus(owner, false); ps != nil {
if ps.Status() != icstate.NotReady {
return errors.Errorf("Already in use: addr=%s status=%s", owner, ps.Status())
+ } else {
+ // if status is NotReady
+ pm.totalDelegated.Add(pm.totalDelegated, ps.Delegated())
}
}
@@ -542,9 +545,8 @@ func (pm *PRepManager) ChangeDelegation(od, nd icstate.Delegations) (map[string]
}
if value.Sign() != 0 {
ps := pm.state.GetPRepStatus(owner, true)
- if ps.IsActive() {
ps.Delegated().Add(ps.Delegated(), value)
- } else {
+ if !ps.IsActive() {
delegatedToInactiveNode.Add(delegatedToInactiveNode, value)
}
}
@@ -591,6 +593,7 @@ func (pm *PRepManager) ChangeBond(oBonds, nBonds icstate.Bonds) (map[string]*big
if ps.IsActive() {
ps.Bonded().Add(ps.Bonded(), value)
} else {
+ // this code is not reachable, because there is no case of bonding to not-registered PRep
bondedToInactiveNode.Add(bondedToInactiveNode, value)
}
}
