[#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:
parent
30c18d46cc
commit
aeb4bbc51e
1 changed files with 85 additions and 71 deletions
|
@ -18,7 +18,6 @@ const (
|
|||
alphabetUpdateIDPrefix = "AlphabetUpdate"
|
||||
)
|
||||
|
||||
// nolint: funlen
|
||||
func (gp *Processor) processAlphabetSync(txHash util.Uint256) {
|
||||
if !gp.alphabetState.IsAlphabet() {
|
||||
gp.log.Info("non alphabet mode, ignore alphabet sync")
|
||||
|
@ -69,79 +68,13 @@ func (gp *Processor) processAlphabetSync(txHash util.Uint256) {
|
|||
}
|
||||
|
||||
// 2. Update NeoFSAlphabet role in the sidechain.
|
||||
innerRing, err := gp.irFetcher.InnerRingKeys()
|
||||
if err != nil {
|
||||
gp.log.Error("can't fetch inner ring list from side chain",
|
||||
zap.String("error", err.Error()))
|
||||
} else {
|
||||
newInnerRing, err := updateInnerRing(innerRing, sidechainAlphabet, newAlphabet)
|
||||
if err != nil {
|
||||
gp.log.Error("can't create new inner ring list with new alphabet keys",
|
||||
zap.String("error", err.Error()))
|
||||
} else {
|
||||
sort.Sort(newInnerRing)
|
||||
gp.updateNeoFSAlphabetRoleInSidechain(sidechainAlphabet, newAlphabet, txHash)
|
||||
|
||||
gp.log.Info("update of the inner ring list",
|
||||
zap.String("before", prettyKeys(innerRing)),
|
||||
zap.String("after", prettyKeys(newInnerRing)),
|
||||
)
|
||||
|
||||
if gp.notaryDisabled {
|
||||
updPrm := nmClient.UpdateIRPrm{}
|
||||
|
||||
updPrm.SetKeys(newInnerRing)
|
||||
updPrm.SetHash(txHash)
|
||||
|
||||
err = gp.netmapClient.UpdateInnerRing(updPrm)
|
||||
} else {
|
||||
updPrm := client.UpdateAlphabetListPrm{}
|
||||
|
||||
updPrm.SetList(newInnerRing)
|
||||
updPrm.SetHash(txHash)
|
||||
|
||||
err = gp.morphClient.UpdateNeoFSAlphabetList(updPrm)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
gp.log.Error("can't update inner ring list with new alphabet keys",
|
||||
zap.String("error", err.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !gp.notaryDisabled {
|
||||
// 3. Update notary role in the sidechain.
|
||||
|
||||
updPrm := client.UpdateNotaryListPrm{}
|
||||
|
||||
updPrm.SetList(newAlphabet)
|
||||
updPrm.SetHash(txHash)
|
||||
|
||||
err = gp.morphClient.UpdateNotaryList(updPrm)
|
||||
if err != nil {
|
||||
gp.log.Error("can't update list of notary nodes in side chain",
|
||||
zap.String("error", err.Error()))
|
||||
}
|
||||
}
|
||||
// 3. Update notary role in the sidechain.
|
||||
gp.updateNotaryRoleInSidechain(newAlphabet, txHash)
|
||||
|
||||
// 4. Update FrostFS contract in the mainnet.
|
||||
epoch := gp.epochState.EpochCounter()
|
||||
|
||||
buf := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(buf, epoch)
|
||||
|
||||
id := append([]byte(alphabetUpdateIDPrefix), buf...)
|
||||
|
||||
prm := frostfscontract.AlphabetUpdatePrm{}
|
||||
|
||||
prm.SetID(id)
|
||||
prm.SetPubs(newAlphabet)
|
||||
|
||||
err = gp.frostfsClient.AlphabetUpdate(prm)
|
||||
if err != nil {
|
||||
gp.log.Error("can't update list of alphabet nodes in frostfs contract",
|
||||
zap.String("error", err.Error()))
|
||||
}
|
||||
gp.updateFrostFSContractInMainnet(newAlphabet)
|
||||
|
||||
gp.log.Info("finished alphabet list update")
|
||||
}
|
||||
|
@ -157,3 +90,84 @@ func prettyKeys(keys keys.PublicKeys) string {
|
|||
|
||||
return strings.TrimRight(sb.String(), delimiter)
|
||||
}
|
||||
|
||||
func (gp *Processor) updateNeoFSAlphabetRoleInSidechain(sidechainAlphabet, newAlphabet keys.PublicKeys, txHash util.Uint256) {
|
||||
innerRing, err := gp.irFetcher.InnerRingKeys()
|
||||
if err != nil {
|
||||
gp.log.Error("can't fetch inner ring list from side chain",
|
||||
zap.String("error", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
newInnerRing, err := updateInnerRing(innerRing, sidechainAlphabet, newAlphabet)
|
||||
if err != nil {
|
||||
gp.log.Error("can't create new inner ring list with new alphabet keys",
|
||||
zap.String("error", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
sort.Sort(newInnerRing)
|
||||
|
||||
gp.log.Info("update of the inner ring list",
|
||||
zap.String("before", prettyKeys(innerRing)),
|
||||
zap.String("after", prettyKeys(newInnerRing)),
|
||||
)
|
||||
|
||||
if gp.notaryDisabled {
|
||||
updPrm := nmClient.UpdateIRPrm{}
|
||||
|
||||
updPrm.SetKeys(newInnerRing)
|
||||
updPrm.SetHash(txHash)
|
||||
|
||||
err = gp.netmapClient.UpdateInnerRing(updPrm)
|
||||
} else {
|
||||
updPrm := client.UpdateAlphabetListPrm{}
|
||||
|
||||
updPrm.SetList(newInnerRing)
|
||||
updPrm.SetHash(txHash)
|
||||
|
||||
err = gp.morphClient.UpdateNeoFSAlphabetList(updPrm)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
gp.log.Error("can't update inner ring list with new alphabet keys",
|
||||
zap.String("error", err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
func (gp *Processor) updateNotaryRoleInSidechain(newAlphabet keys.PublicKeys, txHash util.Uint256) {
|
||||
if gp.notaryDisabled {
|
||||
return
|
||||
}
|
||||
|
||||
updPrm := client.UpdateNotaryListPrm{}
|
||||
|
||||
updPrm.SetList(newAlphabet)
|
||||
updPrm.SetHash(txHash)
|
||||
|
||||
err := gp.morphClient.UpdateNotaryList(updPrm)
|
||||
if err != nil {
|
||||
gp.log.Error("can't update list of notary nodes in side chain",
|
||||
zap.String("error", err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
func (gp *Processor) updateFrostFSContractInMainnet(newAlphabet keys.PublicKeys) {
|
||||
epoch := gp.epochState.EpochCounter()
|
||||
|
||||
buf := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(buf, epoch)
|
||||
|
||||
id := append([]byte(alphabetUpdateIDPrefix), buf...)
|
||||
|
||||
prm := frostfscontract.AlphabetUpdatePrm{}
|
||||
|
||||
prm.SetID(id)
|
||||
prm.SetPubs(newAlphabet)
|
||||
|
||||
err := gp.frostfsClient.AlphabetUpdate(prm)
|
||||
if err != nil {
|
||||
gp.log.Error("can't update list of alphabet nodes in frostfs contract",
|
||||
zap.String("error", err.Error()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue