[#502] innerring: synchronize validators on mainnet alphabet update
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
7eab752923
commit
2e31cd34e6
6 changed files with 98 additions and 4 deletions
|
@ -490,6 +490,10 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
}
|
||||
} else {
|
||||
alphaSync = governanceProcessor.HandleAlphabetSync
|
||||
err = bindMainnetProcessor(governanceProcessor, server)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// create netmap processor
|
||||
|
|
|
@ -1,12 +1,29 @@
|
|||
package governance
|
||||
|
||||
import (
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/rolemanagement"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func (gp *Processor) HandleAlphabetSync(_ event.Event) {
|
||||
gp.log.Info("new event", zap.String("type", "sync"))
|
||||
func (gp *Processor) HandleAlphabetSync(e event.Event) {
|
||||
var typ string
|
||||
|
||||
switch et := e.(type) {
|
||||
case Sync:
|
||||
typ = "sync"
|
||||
case rolemanagement.Designate:
|
||||
if et.Role != noderoles.NeoFSAlphabet {
|
||||
return
|
||||
}
|
||||
typ = native.DesignationEventName
|
||||
default:
|
||||
return
|
||||
}
|
||||
|
||||
gp.log.Info("new event", zap.String("type", typ))
|
||||
|
||||
// send event to the worker pool
|
||||
|
||||
|
|
|
@ -4,11 +4,13 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/rolemanagement"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
@ -111,12 +113,20 @@ func New(p *Params) (*Processor, error) {
|
|||
|
||||
// ListenerParsers for the 'event.Listener' event producer.
|
||||
func (gp *Processor) ListenerParsers() []event.ParserInfo {
|
||||
return nil
|
||||
var pi event.ParserInfo
|
||||
pi.SetScriptHash(gp.mainnetClient.GetDesignateHash())
|
||||
pi.SetType(event.TypeFromString(native.DesignationEventName))
|
||||
pi.SetParser(rolemanagement.ParseDesignate)
|
||||
return []event.ParserInfo{pi}
|
||||
}
|
||||
|
||||
// ListenerHandlers for the 'event.Listener' event producer.
|
||||
func (gp *Processor) ListenerHandlers() []event.HandlerInfo {
|
||||
return nil
|
||||
var hi event.HandlerInfo
|
||||
hi.SetScriptHash(gp.mainnetClient.GetDesignateHash())
|
||||
hi.SetType(event.TypeFromString(native.DesignationEventName))
|
||||
hi.SetHandler(gp.HandleAlphabetSync)
|
||||
return []event.HandlerInfo{hi}
|
||||
}
|
||||
|
||||
// TimersHandlers for the 'Timers' event producer.
|
||||
|
|
|
@ -236,6 +236,11 @@ func (c *Client) NeoFSAlphabetList() (keys.PublicKeys, error) {
|
|||
return list, nil
|
||||
}
|
||||
|
||||
// GetDesignateHash returns hash of the native `RoleManagement` contract.
|
||||
func (c *Client) GetDesignateHash() util.Uint160 {
|
||||
return c.designate
|
||||
}
|
||||
|
||||
func (c *Client) roleList(r noderoles.Role) (keys.PublicKeys, error) {
|
||||
height, err := c.client.GetBlockCount()
|
||||
if err != nil {
|
||||
|
|
31
pkg/morph/event/rolemanagement/designate.go
Normal file
31
pkg/morph/event/rolemanagement/designate.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package rolemanagement
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
)
|
||||
|
||||
// Designate represents designation event of the mainnet RoleManagement contract.
|
||||
type Designate struct {
|
||||
Role noderoles.Role
|
||||
}
|
||||
|
||||
// MorphEvent implements Neo:Morph Event interface.
|
||||
func (Designate) MorphEvent() {}
|
||||
|
||||
// ParseDesignate from notification into container event structure.
|
||||
func ParseDesignate(params []stackitem.Item) (event.Event, error) {
|
||||
if len(params) != 2 {
|
||||
return nil, event.WrongNumberOfParameters(2, len(params))
|
||||
}
|
||||
|
||||
bi, err := params[0].TryInteger()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid stackitem type: %w", err)
|
||||
}
|
||||
|
||||
return Designate{Role: noderoles.Role(bi.Int64())}, nil
|
||||
}
|
27
pkg/morph/event/rolemanagement/designate_test.go
Normal file
27
pkg/morph/event/rolemanagement/designate_test.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package rolemanagement
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestParseRoleUpdate(t *testing.T) {
|
||||
t.Run("wrong number of arguments", func(t *testing.T) {
|
||||
_, err := ParseDesignate([]stackitem.Item{})
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("invalid item type", func(t *testing.T) {
|
||||
args := []stackitem.Item{stackitem.NewMap(), stackitem.Make(123)}
|
||||
_, err := ParseDesignate(args)
|
||||
require.Error(t, err)
|
||||
})
|
||||
t.Run("good", func(t *testing.T) {
|
||||
args := []stackitem.Item{stackitem.Make(int(noderoles.NeoFSAlphabet)), stackitem.Make(123)}
|
||||
e, err := ParseDesignate(args)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, noderoles.NeoFSAlphabet, e.(Designate).Role)
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue