From 9bfe2a9c1bdfe26e396abbbae9069173a45991c5 Mon Sep 17 00:00:00 2001 From: sidenaio Date: Fri, 26 Mar 2021 02:03:32 +0500 Subject: [PATCH 1/2] Respect delegation switch in RPC calls --- api/dna_api.go | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/api/dna_api.go b/api/dna_api.go index 1c2337f7..e194ec0f 100644 --- a/api/dna_api.go +++ b/api/dna_api.go @@ -296,15 +296,11 @@ func (api *DnaApi) Identities() []Identity { if addr == api.GetCoinbaseAddr() { flipKeyWordPairs = api.ceremony.FlipKeyWordPairs() } - identities = append(identities, convertIdentity(epoch, addr, data, flipKeyWordPairs, appState.ValidatorsCache.IsPool(addr))) + identities = append(identities, convertIdentity(epoch, addr, data, flipKeyWordPairs, appState)) return false }) - for idx := range identities { - identities[idx].Online = getIdentityOnlineStatus(api.baseApi.getReadonlyAppState(), identities[idx].Address) - } - return identities } @@ -317,22 +313,10 @@ func (api *DnaApi) Identity(address *common.Address) Identity { } appState := api.baseApi.getReadonlyAppState() - converted := convertIdentity(appState.State.Epoch(), *address, appState.State.GetIdentity(*address), flipKeyWordPairs, appState.ValidatorsCache.IsPool(*address)) - converted.Online = getIdentityOnlineStatus(appState, *address) - return converted -} - -func getIdentityOnlineStatus(state *appstate.AppState, addr common.Address) bool { - isOnline := state.ValidatorsCache.IsOnlineIdentity(addr) - hasPendingStatusSwitch := state.State.HasStatusSwitchAddresses(addr) - if hasPendingStatusSwitch { - return !isOnline - } else { - return isOnline - } + return convertIdentity(appState.State.Epoch(), *address, appState.State.GetIdentity(*address), flipKeyWordPairs, appState) } -func convertIdentity(currentEpoch uint16, address common.Address, data state.Identity, flipKeyWordPairs []int, isPool bool) Identity { +func convertIdentity(currentEpoch uint16, address common.Address, data state.Identity, flipKeyWordPairs []int, appState *appstate.AppState) Identity { var s string switch data.State { case state.Invite: @@ -402,6 +386,18 @@ func convertIdentity(currentEpoch uint16, address common.Address, data state.Ide totalPoints, totalFlips := common.CalculateIdentityScores(data.Scores, data.GetShortFlipPoints(), data.QualifiedFlips) + isOnline := appState.ValidatorsCache.IsOnlineIdentity(address) + hasPendingStatusSwitch := appState.State.HasStatusSwitchAddresses(address) + if hasPendingStatusSwitch { + isOnline = !isOnline + } + + delegatee := data.Delegatee + switchDelegation := appState.State.DelegationSwitch(address) + if switchDelegation != nil { + delegatee = &switchDelegation.Delegatee + } + return Identity{ Address: address, State: s, @@ -422,10 +418,11 @@ func convertIdentity(currentEpoch uint16, address common.Address, data state.Ide Invitees: invitees, Penalty: blockchain.ConvertToFloat(data.Penalty), LastValidationFlags: flags, - Delegatee: data.Delegatee, + Delegatee: delegatee, DelegationEpoch: data.DelegationEpoch, DelegationNonce: data.DelegationNonce, - IsPool: isPool, + Online: isOnline, + IsPool: appState.ValidatorsCache.IsPool(address), } } From 34922b59b3420091b9bf7a889b5a6d313dff2366 Mon Sep 17 00:00:00 2001 From: sidenaio Date: Fri, 26 Mar 2021 11:13:01 +0500 Subject: [PATCH 2/2] PR fix --- api/dna_api.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/dna_api.go b/api/dna_api.go index e194ec0f..a24a0406 100644 --- a/api/dna_api.go +++ b/api/dna_api.go @@ -395,7 +395,11 @@ func convertIdentity(currentEpoch uint16, address common.Address, data state.Ide delegatee := data.Delegatee switchDelegation := appState.State.DelegationSwitch(address) if switchDelegation != nil { - delegatee = &switchDelegation.Delegatee + if switchDelegation.Delegatee.IsEmpty() { + delegatee = nil + } else { + delegatee = &switchDelegation.Delegatee + } } return Identity{