2021-03-25 13:23:53 +00:00
|
|
|
package governance
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/binary"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-05-21 07:45:15 +00:00
|
|
|
const (
|
|
|
|
alphabetUpdateIDPrefix = "AlphabetUpdate"
|
|
|
|
)
|
2021-03-25 13:23:53 +00:00
|
|
|
|
|
|
|
func (gp *Processor) processAlphabetSync() {
|
|
|
|
if !gp.alphabetState.IsAlphabet() {
|
|
|
|
gp.log.Info("non alphabet mode, ignore alphabet sync")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
mainnetAlphabet, err := gp.mainnetClient.NeoFSAlphabetList()
|
|
|
|
if err != nil {
|
|
|
|
gp.log.Error("can't fetch alphabet list from main net",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
sidechainAlphabet, err := gp.morphClient.Committee()
|
|
|
|
if err != nil {
|
|
|
|
gp.log.Error("can't fetch alphabet list from side chain",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
newAlphabet, err := newAlphabetList(sidechainAlphabet, mainnetAlphabet)
|
|
|
|
if err != nil {
|
|
|
|
gp.log.Error("can't merge alphabet lists from main net and side chain",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if newAlphabet == nil {
|
|
|
|
gp.log.Info("no governance update, alphabet list has not been changed")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
gp.log.Info("alphabet list has been changed, starting update")
|
|
|
|
|
|
|
|
// 1. Vote to side chain committee via alphabet contracts.
|
|
|
|
err = gp.voter.VoteForSidechainValidator(newAlphabet)
|
|
|
|
if err != nil {
|
|
|
|
gp.log.Error("can't vote for side chain committee",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. Update NeoFSAlphabet role in side chain.
|
2021-07-22 10:04:37 +00:00
|
|
|
innerRing, err := gp.irFetcher.InnerRingKeys()
|
2021-03-25 13:23:53 +00:00
|
|
|
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)
|
|
|
|
|
2021-04-29 13:40:34 +00:00
|
|
|
if gp.notaryDisabled {
|
2021-07-21 09:24:14 +00:00
|
|
|
err = gp.netmapClient.UpdateInnerRing(newInnerRing)
|
2021-04-29 13:40:34 +00:00
|
|
|
} else {
|
|
|
|
err = gp.morphClient.UpdateNeoFSAlphabetList(newInnerRing)
|
|
|
|
}
|
|
|
|
|
2021-03-25 13:23:53 +00:00
|
|
|
if err != nil {
|
|
|
|
gp.log.Error("can't update inner ring list with new alphabet keys",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-29 13:40:34 +00:00
|
|
|
if !gp.notaryDisabled {
|
|
|
|
// 3. Update notary role in side chain.
|
|
|
|
err = gp.morphClient.UpdateNotaryList(newAlphabet)
|
|
|
|
if err != nil {
|
|
|
|
gp.log.Error("can't update list of notary nodes in side chain",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
2021-03-25 13:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 4. Update NeoFS contract in main net.
|
|
|
|
epoch := gp.epochState.EpochCounter()
|
|
|
|
|
|
|
|
buf := make([]byte, 8)
|
|
|
|
binary.LittleEndian.PutUint64(buf, epoch)
|
|
|
|
|
|
|
|
id := append([]byte(alphabetUpdateIDPrefix), buf...)
|
|
|
|
|
2021-06-01 11:35:53 +00:00
|
|
|
err = gp.neofsClient.AlphabetUpdate(id, newAlphabet)
|
2021-03-25 13:23:53 +00:00
|
|
|
if err != nil {
|
|
|
|
gp.log.Error("can't update list of alphabet nodes in neofs contract",
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
|
|
|
|
gp.log.Info("finished alphabet list update")
|
|
|
|
}
|