[#185] ir: Refactor alphabet update

Resolve funlen linter for processAlphabetSync method

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-03-30 10:35:16 +03:00 committed by Gitea
parent 30c18d46cc
commit aeb4bbc51e

View file

@ -18,7 +18,6 @@ const (
alphabetUpdateIDPrefix = "AlphabetUpdate" alphabetUpdateIDPrefix = "AlphabetUpdate"
) )
// nolint: funlen
func (gp *Processor) processAlphabetSync(txHash util.Uint256) { func (gp *Processor) processAlphabetSync(txHash util.Uint256) {
if !gp.alphabetState.IsAlphabet() { if !gp.alphabetState.IsAlphabet() {
gp.log.Info("non alphabet mode, ignore alphabet sync") gp.log.Info("non alphabet mode, ignore alphabet sync")
@ -69,16 +68,44 @@ func (gp *Processor) processAlphabetSync(txHash util.Uint256) {
} }
// 2. Update NeoFSAlphabet role in the sidechain. // 2. Update NeoFSAlphabet role in the sidechain.
gp.updateNeoFSAlphabetRoleInSidechain(sidechainAlphabet, newAlphabet, txHash)
// 3. Update notary role in the sidechain.
gp.updateNotaryRoleInSidechain(newAlphabet, txHash)
// 4. Update FrostFS contract in the mainnet.
gp.updateFrostFSContractInMainnet(newAlphabet)
gp.log.Info("finished alphabet list update")
}
func prettyKeys(keys keys.PublicKeys) string {
const delimiter = ","
sb := strings.Builder{}
for _, key := range keys {
sb.WriteString(hex.EncodeToString(key.Bytes()))
sb.WriteString(delimiter)
}
return strings.TrimRight(sb.String(), delimiter)
}
func (gp *Processor) updateNeoFSAlphabetRoleInSidechain(sidechainAlphabet, newAlphabet keys.PublicKeys, txHash util.Uint256) {
innerRing, err := gp.irFetcher.InnerRingKeys() innerRing, err := gp.irFetcher.InnerRingKeys()
if err != nil { if err != nil {
gp.log.Error("can't fetch inner ring list from side chain", gp.log.Error("can't fetch inner ring list from side chain",
zap.String("error", err.Error())) zap.String("error", err.Error()))
} else { return
}
newInnerRing, err := updateInnerRing(innerRing, sidechainAlphabet, newAlphabet) newInnerRing, err := updateInnerRing(innerRing, sidechainAlphabet, newAlphabet)
if err != nil { if err != nil {
gp.log.Error("can't create new inner ring list with new alphabet keys", gp.log.Error("can't create new inner ring list with new alphabet keys",
zap.String("error", err.Error())) zap.String("error", err.Error()))
} else { return
}
sort.Sort(newInnerRing) sort.Sort(newInnerRing)
gp.log.Info("update of the inner ring list", gp.log.Info("update of the inner ring list",
@ -107,24 +134,25 @@ func (gp *Processor) processAlphabetSync(txHash util.Uint256) {
zap.String("error", err.Error())) zap.String("error", err.Error()))
} }
} }
}
if !gp.notaryDisabled { func (gp *Processor) updateNotaryRoleInSidechain(newAlphabet keys.PublicKeys, txHash util.Uint256) {
// 3. Update notary role in the sidechain. if gp.notaryDisabled {
return
}
updPrm := client.UpdateNotaryListPrm{} updPrm := client.UpdateNotaryListPrm{}
updPrm.SetList(newAlphabet) updPrm.SetList(newAlphabet)
updPrm.SetHash(txHash) updPrm.SetHash(txHash)
err = gp.morphClient.UpdateNotaryList(updPrm) err := gp.morphClient.UpdateNotaryList(updPrm)
if err != nil { if err != nil {
gp.log.Error("can't update list of notary nodes in side chain", gp.log.Error("can't update list of notary nodes in side chain",
zap.String("error", err.Error())) zap.String("error", err.Error()))
} }
} }
// 4. Update FrostFS contract in the mainnet. func (gp *Processor) updateFrostFSContractInMainnet(newAlphabet keys.PublicKeys) {
epoch := gp.epochState.EpochCounter() epoch := gp.epochState.EpochCounter()
buf := make([]byte, 8) buf := make([]byte, 8)
@ -137,23 +165,9 @@ func (gp *Processor) processAlphabetSync(txHash util.Uint256) {
prm.SetID(id) prm.SetID(id)
prm.SetPubs(newAlphabet) prm.SetPubs(newAlphabet)
err = gp.frostfsClient.AlphabetUpdate(prm) err := gp.frostfsClient.AlphabetUpdate(prm)
if err != nil { if err != nil {
gp.log.Error("can't update list of alphabet nodes in frostfs contract", gp.log.Error("can't update list of alphabet nodes in frostfs contract",
zap.String("error", err.Error())) zap.String("error", err.Error()))
} }
gp.log.Info("finished alphabet list update")
}
func prettyKeys(keys keys.PublicKeys) string {
const delimiter = ","
sb := strings.Builder{}
for _, key := range keys {
sb.WriteString(hex.EncodeToString(key.Bytes()))
sb.WriteString(delimiter)
}
return strings.TrimRight(sb.String(), delimiter)
} }