[#627] ir: Read addresses of contracts from the client wrappers

After recent changes morph client wrappers provide contract address getter.
It can be used to compose notification parsers and handlers.

Use `ContractAddress` method in constructors of notification parsers and
handlers. Remove no longer used script hash parameters of event processors.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-09-15 13:50:07 +03:00 committed by Alex Vanin
parent d6c0307431
commit 8fc1505351
5 changed files with 112 additions and 138 deletions

View file

@ -636,7 +636,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
server.netmapProcessor, err = netmap.New(&netmap.Params{ server.netmapProcessor, err = netmap.New(&netmap.Params{
Log: log, Log: log,
PoolSize: cfg.GetInt("workers.netmap"), PoolSize: cfg.GetInt("workers.netmap"),
NetmapContract: server.contracts.netmap,
NetmapClient: server.netmapClient, NetmapClient: server.netmapClient,
EpochTimer: server, EpochTimer: server,
EpochState: server, EpochState: server,
@ -668,14 +667,13 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
// container processor // container processor
containerProcessor, err := container.New(&container.Params{ containerProcessor, err := container.New(&container.Params{
Log: log, Log: log,
PoolSize: cfg.GetInt("workers.container"), PoolSize: cfg.GetInt("workers.container"),
ContainerContract: server.contracts.container, AlphabetState: server,
AlphabetState: server, ContainerClient: cnrClient,
ContainerClient: cnrClient, NeoFSIDClient: neofsIDClient,
NeoFSIDClient: neofsIDClient, NetworkState: server.netmapClient,
NetworkState: server.netmapClient, NotaryDisabled: server.sideNotaryConfig.disabled,
NotaryDisabled: server.sideNotaryConfig.disabled,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -688,12 +686,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
// create balance processor // create balance processor
balanceProcessor, err := balance.New(&balance.Params{ balanceProcessor, err := balance.New(&balance.Params{
Log: log, Log: log,
PoolSize: cfg.GetInt("workers.balance"), PoolSize: cfg.GetInt("workers.balance"),
NeoFSClient: neofsClient, NeoFSClient: neofsClient,
BalanceContract: server.contracts.balance, AlphabetState: server,
AlphabetState: server, Converter: &server.precision,
Converter: &server.precision,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -753,12 +750,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
// create reputation processor // create reputation processor
reputationProcessor, err := reputation.New(&reputation.Params{ reputationProcessor, err := reputation.New(&reputation.Params{
Log: log, Log: log,
PoolSize: cfg.GetInt("workers.reputation"), PoolSize: cfg.GetInt("workers.reputation"),
ReputationContract: server.contracts.reputation, EpochState: server,
EpochState: server, AlphabetState: server,
AlphabetState: server, ReputationWrapper: repClient,
ReputationWrapper: repClient,
ManagerBuilder: reputationcommon.NewManagerBuilder( ManagerBuilder: reputationcommon.NewManagerBuilder(
reputationcommon.ManagersPrm{ reputationcommon.ManagersPrm{
NetMapSource: server.netmapClient, NetMapSource: server.netmapClient,

View file

@ -4,7 +4,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/util"
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper" neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance" balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance"
@ -25,22 +24,20 @@ type (
// Processor of events produced by balance contract in morph chain. // Processor of events produced by balance contract in morph chain.
Processor struct { Processor struct {
log *zap.Logger log *zap.Logger
pool *ants.Pool pool *ants.Pool
neofsClient *neofscontract.ClientWrapper neofsClient *neofscontract.ClientWrapper
balanceContract util.Uint160 alphabetState AlphabetState
alphabetState AlphabetState converter PrecisionConverter
converter PrecisionConverter
} }
// Params of the processor constructor. // Params of the processor constructor.
Params struct { Params struct {
Log *zap.Logger Log *zap.Logger
PoolSize int PoolSize int
NeoFSClient *neofscontract.ClientWrapper NeoFSClient *neofscontract.ClientWrapper
BalanceContract util.Uint160 AlphabetState AlphabetState
AlphabetState AlphabetState Converter PrecisionConverter
Converter PrecisionConverter
} }
) )
@ -67,12 +64,11 @@ func New(p *Params) (*Processor, error) {
} }
return &Processor{ return &Processor{
log: p.Log, log: p.Log,
pool: pool, pool: pool,
neofsClient: p.NeoFSClient, neofsClient: p.NeoFSClient,
balanceContract: p.BalanceContract, alphabetState: p.AlphabetState,
alphabetState: p.AlphabetState, converter: p.Converter,
converter: p.Converter,
}, nil }, nil
} }
@ -83,7 +79,7 @@ func (bp *Processor) ListenerNotificationParsers() []event.NotificationParserInf
// new lock event // new lock event
lock := event.NotificationParserInfo{} lock := event.NotificationParserInfo{}
lock.SetType(lockNotification) lock.SetType(lockNotification)
lock.SetScriptHash(bp.balanceContract) lock.SetScriptHash(bp.neofsClient.ContractAddress())
lock.SetParser(balanceEvent.ParseLock) lock.SetParser(balanceEvent.ParseLock)
parsers = append(parsers, lock) parsers = append(parsers, lock)
@ -97,7 +93,7 @@ func (bp *Processor) ListenerNotificationHandlers() []event.NotificationHandlerI
// lock handler // lock handler
lock := event.NotificationHandlerInfo{} lock := event.NotificationHandlerInfo{}
lock.SetType(lockNotification) lock.SetType(lockNotification)
lock.SetScriptHash(bp.balanceContract) lock.SetScriptHash(bp.neofsClient.ContractAddress())
lock.SetHandler(bp.handleLock) lock.SetHandler(bp.handleLock)
handlers = append(handlers, lock) handlers = append(handlers, lock)

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent" "github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper" neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
@ -22,26 +21,24 @@ type (
// Processor of events produced by container contract in morph chain. // Processor of events produced by container contract in morph chain.
Processor struct { Processor struct {
log *zap.Logger log *zap.Logger
pool *ants.Pool pool *ants.Pool
containerContract util.Uint160 alphabetState AlphabetState
alphabetState AlphabetState cnrClient *wrapper.Wrapper // notary must be enabled
cnrClient *wrapper.Wrapper // notary must be enabled idClient *neofsid.ClientWrapper
idClient *neofsid.ClientWrapper netState NetworkState
netState NetworkState notaryDisabled bool
notaryDisabled bool
} }
// Params of the processor constructor. // Params of the processor constructor.
Params struct { Params struct {
Log *zap.Logger Log *zap.Logger
PoolSize int PoolSize int
ContainerContract util.Uint160 AlphabetState AlphabetState
AlphabetState AlphabetState ContainerClient *wrapper.Wrapper
ContainerClient *wrapper.Wrapper NeoFSIDClient *neofsid.ClientWrapper
NeoFSIDClient *neofsid.ClientWrapper NetworkState NetworkState
NetworkState NetworkState NotaryDisabled bool
NotaryDisabled bool
} }
) )
@ -85,14 +82,13 @@ func New(p *Params) (*Processor, error) {
} }
return &Processor{ return &Processor{
log: p.Log, log: p.Log,
pool: pool, pool: pool,
containerContract: p.ContainerContract, alphabetState: p.AlphabetState,
alphabetState: p.AlphabetState, cnrClient: p.ContainerClient,
cnrClient: p.ContainerClient, idClient: p.NeoFSIDClient,
idClient: p.NeoFSIDClient, netState: p.NetworkState,
netState: p.NetworkState, notaryDisabled: p.NotaryDisabled,
notaryDisabled: p.NotaryDisabled,
}, nil }, nil
} }
@ -108,7 +104,7 @@ func (cp *Processor) ListenerNotificationParsers() []event.NotificationParserInf
p event.NotificationParserInfo p event.NotificationParserInfo
) )
p.SetScriptHash(cp.containerContract) p.SetScriptHash(cp.cnrClient.ContractAddress())
// container put // container put
p.SetType(event.TypeFromString(putNotification)) p.SetType(event.TypeFromString(putNotification))
@ -140,7 +136,7 @@ func (cp *Processor) ListenerNotificationHandlers() []event.NotificationHandlerI
h event.NotificationHandlerInfo h event.NotificationHandlerInfo
) )
h.SetScriptHash(cp.containerContract) h.SetScriptHash(cp.cnrClient.ContractAddress())
// container put // container put
h.SetType(event.TypeFromString(putNotification)) h.SetType(event.TypeFromString(putNotification))
@ -169,7 +165,7 @@ func (cp *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
) )
p.SetMempoolType(mempoolevent.TransactionAdded) p.SetMempoolType(mempoolevent.TransactionAdded)
p.SetScriptHash(cp.containerContract) p.SetScriptHash(cp.cnrClient.ContractAddress())
// container put // container put
p.SetRequestType(containerEvent.PutNotaryEvent) p.SetRequestType(containerEvent.PutNotaryEvent)
@ -197,7 +193,7 @@ func (cp *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
hh = make([]event.NotaryHandlerInfo, 0, 3) hh = make([]event.NotaryHandlerInfo, 0, 3)
) )
h.SetScriptHash(cp.containerContract) h.SetScriptHash(cp.cnrClient.ContractAddress())
h.SetMempoolType(mempoolevent.TransactionAdded) h.SetMempoolType(mempoolevent.TransactionAdded)
// container put // container put

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent" "github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap" "github.com/nspcc-dev/neofs-api-go/pkg/netmap"
container "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" container "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper" nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
@ -50,12 +49,11 @@ type (
// Processor of events produced by network map contract // Processor of events produced by network map contract
// and new epoch ticker, because it is related to contract. // and new epoch ticker, because it is related to contract.
Processor struct { Processor struct {
log *zap.Logger log *zap.Logger
pool *ants.Pool pool *ants.Pool
netmapContract util.Uint160 epochTimer EpochTimerReseter
epochTimer EpochTimerReseter epochState EpochState
epochState EpochState alphabetState AlphabetState
alphabetState AlphabetState
netmapClient *nmWrapper.Wrapper netmapClient *nmWrapper.Wrapper
containerWrp *container.Wrapper containerWrp *container.Wrapper
@ -73,10 +71,8 @@ type (
// Params of the processor constructor. // Params of the processor constructor.
Params struct { Params struct {
Log *zap.Logger Log *zap.Logger
PoolSize int PoolSize int
// TODO(@fyrchik): add `ContractHash` method to the NetmapClient and remove this parameter.
NetmapContract util.Uint160
NetmapClient *nmWrapper.Wrapper NetmapClient *nmWrapper.Wrapper
EpochTimer EpochTimerReseter EpochTimer EpochTimerReseter
EpochState EpochState EpochState EpochState
@ -134,7 +130,6 @@ func New(p *Params) (*Processor, error) {
return &Processor{ return &Processor{
log: p.Log, log: p.Log,
pool: pool, pool: pool,
netmapContract: p.NetmapContract,
epochTimer: p.EpochTimer, epochTimer: p.EpochTimer,
epochState: p.EpochState, epochState: p.EpochState,
alphabetState: p.AlphabetState, alphabetState: p.AlphabetState,
@ -157,30 +152,28 @@ func New(p *Params) (*Processor, error) {
func (np *Processor) ListenerNotificationParsers() []event.NotificationParserInfo { func (np *Processor) ListenerNotificationParsers() []event.NotificationParserInfo {
parsers := make([]event.NotificationParserInfo, 0, 3) parsers := make([]event.NotificationParserInfo, 0, 3)
var p event.NotificationParserInfo
p.SetScriptHash(np.netmapClient.ContractAddress())
// new epoch event // new epoch event
newEpoch := event.NotificationParserInfo{} p.SetType(newEpochNotification)
newEpoch.SetType(newEpochNotification) p.SetParser(netmapEvent.ParseNewEpoch)
newEpoch.SetScriptHash(np.netmapContract) parsers = append(parsers, p)
newEpoch.SetParser(netmapEvent.ParseNewEpoch)
parsers = append(parsers, newEpoch)
if !np.notaryDisabled { if !np.notaryDisabled {
return parsers return parsers
} }
// new peer event // new peer event
addPeer := event.NotificationParserInfo{} p.SetType(addPeerNotification)
addPeer.SetType(addPeerNotification) p.SetParser(netmapEvent.ParseAddPeer)
addPeer.SetScriptHash(np.netmapContract) parsers = append(parsers, p)
addPeer.SetParser(netmapEvent.ParseAddPeer)
parsers = append(parsers, addPeer)
// update peer event // update peer event
updatePeer := event.NotificationParserInfo{} p.SetType(updatePeerStateNotification)
updatePeer.SetType(updatePeerStateNotification) p.SetParser(netmapEvent.ParseUpdatePeer)
updatePeer.SetScriptHash(np.netmapContract) parsers = append(parsers, p)
updatePeer.SetParser(netmapEvent.ParseUpdatePeer)
parsers = append(parsers, updatePeer)
return parsers return parsers
} }
@ -189,30 +182,28 @@ func (np *Processor) ListenerNotificationParsers() []event.NotificationParserInf
func (np *Processor) ListenerNotificationHandlers() []event.NotificationHandlerInfo { func (np *Processor) ListenerNotificationHandlers() []event.NotificationHandlerInfo {
handlers := make([]event.NotificationHandlerInfo, 0, 3) handlers := make([]event.NotificationHandlerInfo, 0, 3)
var i event.NotificationHandlerInfo
i.SetScriptHash(np.netmapClient.ContractAddress())
// new epoch handler // new epoch handler
newEpoch := event.NotificationHandlerInfo{} i.SetType(newEpochNotification)
newEpoch.SetType(newEpochNotification) i.SetHandler(np.handleNewEpoch)
newEpoch.SetScriptHash(np.netmapContract) handlers = append(handlers, i)
newEpoch.SetHandler(np.handleNewEpoch)
handlers = append(handlers, newEpoch)
if !np.notaryDisabled { if !np.notaryDisabled {
return handlers return handlers
} }
// new peer handler // new peer handler
addPeer := event.NotificationHandlerInfo{} i.SetType(addPeerNotification)
addPeer.SetType(addPeerNotification) i.SetHandler(np.handleAddPeer)
addPeer.SetScriptHash(np.netmapContract) handlers = append(handlers, i)
addPeer.SetHandler(np.handleAddPeer)
handlers = append(handlers, addPeer)
// update peer handler // update peer handler
updatePeer := event.NotificationHandlerInfo{} i.SetType(updatePeerStateNotification)
updatePeer.SetType(updatePeerStateNotification) i.SetHandler(np.handleUpdateState)
updatePeer.SetScriptHash(np.netmapContract) handlers = append(handlers, i)
updatePeer.SetHandler(np.handleUpdateState)
handlers = append(handlers, updatePeer)
return handlers return handlers
} }
@ -226,7 +217,7 @@ func (np *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
) )
p.SetMempoolType(mempoolevent.TransactionAdded) p.SetMempoolType(mempoolevent.TransactionAdded)
p.SetScriptHash(np.netmapContract) p.SetScriptHash(np.netmapClient.ContractAddress())
// new peer // new peer
p.SetRequestType(netmapEvent.AddPeerNotaryEvent) p.SetRequestType(netmapEvent.AddPeerNotaryEvent)
@ -250,7 +241,7 @@ func (np *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
) )
h.SetMempoolType(mempoolevent.TransactionAdded) h.SetMempoolType(mempoolevent.TransactionAdded)
h.SetScriptHash(np.netmapContract) h.SetScriptHash(np.netmapClient.ContractAddress())
// new peer // new peer
h.SetRequestType(netmapEvent.AddPeerNotaryEvent) h.SetRequestType(netmapEvent.AddPeerNotaryEvent)

View file

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent" "github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
"github.com/nspcc-dev/neo-go/pkg/util"
reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper" reputationWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event" "github.com/nspcc-dev/neofs-node/pkg/morph/event"
reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation" reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation"
@ -30,8 +29,6 @@ type (
log *zap.Logger log *zap.Logger
pool *ants.Pool pool *ants.Pool
reputationContract util.Uint160
epochState EpochState epochState EpochState
alphabetState AlphabetState alphabetState AlphabetState
@ -44,14 +41,13 @@ type (
// Params of the processor constructor. // Params of the processor constructor.
Params struct { Params struct {
Log *zap.Logger Log *zap.Logger
PoolSize int PoolSize int
ReputationContract util.Uint160 EpochState EpochState
EpochState EpochState AlphabetState AlphabetState
AlphabetState AlphabetState ReputationWrapper *reputationWrapper.ClientWrapper
ReputationWrapper *reputationWrapper.ClientWrapper ManagerBuilder common.ManagerBuilder
ManagerBuilder common.ManagerBuilder NotaryDisabled bool
NotaryDisabled bool
} }
) )
@ -82,14 +78,13 @@ func New(p *Params) (*Processor, error) {
} }
return &Processor{ return &Processor{
log: p.Log, log: p.Log,
pool: pool, pool: pool,
reputationContract: p.ReputationContract, epochState: p.EpochState,
epochState: p.EpochState, alphabetState: p.AlphabetState,
alphabetState: p.AlphabetState, reputationWrp: p.ReputationWrapper,
reputationWrp: p.ReputationWrapper, mngBuilder: p.ManagerBuilder,
mngBuilder: p.ManagerBuilder, notaryDisabled: p.NotaryDisabled,
notaryDisabled: p.NotaryDisabled,
}, nil }, nil
} }
@ -104,7 +99,7 @@ func (rp *Processor) ListenerNotificationParsers() []event.NotificationParserInf
// put reputation event // put reputation event
put := event.NotificationParserInfo{} put := event.NotificationParserInfo{}
put.SetType(putReputationNotification) put.SetType(putReputationNotification)
put.SetScriptHash(rp.reputationContract) put.SetScriptHash(rp.reputationWrp.ContractAddress())
put.SetParser(reputationEvent.ParsePut) put.SetParser(reputationEvent.ParsePut)
parsers = append(parsers, put) parsers = append(parsers, put)
@ -122,7 +117,7 @@ func (rp *Processor) ListenerNotificationHandlers() []event.NotificationHandlerI
// put reputation handler // put reputation handler
put := event.NotificationHandlerInfo{} put := event.NotificationHandlerInfo{}
put.SetType(putReputationNotification) put.SetType(putReputationNotification)
put.SetScriptHash(rp.reputationContract) put.SetScriptHash(rp.reputationWrp.ContractAddress())
put.SetHandler(rp.handlePutReputation) put.SetHandler(rp.handlePutReputation)
handlers = append(handlers, put) handlers = append(handlers, put)
@ -135,7 +130,7 @@ func (rp *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
p.SetMempoolType(mempoolevent.TransactionAdded) p.SetMempoolType(mempoolevent.TransactionAdded)
p.SetRequestType(reputationEvent.PutNotaryEvent) p.SetRequestType(reputationEvent.PutNotaryEvent)
p.SetScriptHash(rp.reputationContract) p.SetScriptHash(rp.reputationWrp.ContractAddress())
p.SetParser(reputationEvent.ParsePutNotary) p.SetParser(reputationEvent.ParsePutNotary)
return []event.NotaryParserInfo{p} return []event.NotaryParserInfo{p}
@ -147,7 +142,7 @@ func (rp *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
h.SetMempoolType(mempoolevent.TransactionAdded) h.SetMempoolType(mempoolevent.TransactionAdded)
h.SetRequestType(reputationEvent.PutNotaryEvent) h.SetRequestType(reputationEvent.PutNotaryEvent)
h.SetScriptHash(rp.reputationContract) h.SetScriptHash(rp.reputationWrp.ContractAddress())
h.SetHandler(rp.handlePutReputation) h.SetHandler(rp.handlePutReputation)
return []event.NotaryHandlerInfo{h} return []event.NotaryHandlerInfo{h}