forked from TrueCloudLab/frostfs-node
[#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:
parent
d6c0307431
commit
8fc1505351
5 changed files with 112 additions and 138 deletions
|
@ -636,7 +636,6 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
server.netmapProcessor, err = netmap.New(&netmap.Params{
|
||||
Log: log,
|
||||
PoolSize: cfg.GetInt("workers.netmap"),
|
||||
NetmapContract: server.contracts.netmap,
|
||||
NetmapClient: server.netmapClient,
|
||||
EpochTimer: server,
|
||||
EpochState: server,
|
||||
|
@ -668,14 +667,13 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
|
||||
// container processor
|
||||
containerProcessor, err := container.New(&container.Params{
|
||||
Log: log,
|
||||
PoolSize: cfg.GetInt("workers.container"),
|
||||
ContainerContract: server.contracts.container,
|
||||
AlphabetState: server,
|
||||
ContainerClient: cnrClient,
|
||||
NeoFSIDClient: neofsIDClient,
|
||||
NetworkState: server.netmapClient,
|
||||
NotaryDisabled: server.sideNotaryConfig.disabled,
|
||||
Log: log,
|
||||
PoolSize: cfg.GetInt("workers.container"),
|
||||
AlphabetState: server,
|
||||
ContainerClient: cnrClient,
|
||||
NeoFSIDClient: neofsIDClient,
|
||||
NetworkState: server.netmapClient,
|
||||
NotaryDisabled: server.sideNotaryConfig.disabled,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -688,12 +686,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
|
||||
// create balance processor
|
||||
balanceProcessor, err := balance.New(&balance.Params{
|
||||
Log: log,
|
||||
PoolSize: cfg.GetInt("workers.balance"),
|
||||
NeoFSClient: neofsClient,
|
||||
BalanceContract: server.contracts.balance,
|
||||
AlphabetState: server,
|
||||
Converter: &server.precision,
|
||||
Log: log,
|
||||
PoolSize: cfg.GetInt("workers.balance"),
|
||||
NeoFSClient: neofsClient,
|
||||
AlphabetState: server,
|
||||
Converter: &server.precision,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -753,12 +750,11 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
|
||||
// create reputation processor
|
||||
reputationProcessor, err := reputation.New(&reputation.Params{
|
||||
Log: log,
|
||||
PoolSize: cfg.GetInt("workers.reputation"),
|
||||
ReputationContract: server.contracts.reputation,
|
||||
EpochState: server,
|
||||
AlphabetState: server,
|
||||
ReputationWrapper: repClient,
|
||||
Log: log,
|
||||
PoolSize: cfg.GetInt("workers.reputation"),
|
||||
EpochState: server,
|
||||
AlphabetState: server,
|
||||
ReputationWrapper: repClient,
|
||||
ManagerBuilder: reputationcommon.NewManagerBuilder(
|
||||
reputationcommon.ManagersPrm{
|
||||
NetMapSource: server.netmapClient,
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||
neofscontract "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofs/wrapper"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
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 struct {
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
neofsClient *neofscontract.ClientWrapper
|
||||
balanceContract util.Uint160
|
||||
alphabetState AlphabetState
|
||||
converter PrecisionConverter
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
neofsClient *neofscontract.ClientWrapper
|
||||
alphabetState AlphabetState
|
||||
converter PrecisionConverter
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
Params struct {
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
NeoFSClient *neofscontract.ClientWrapper
|
||||
BalanceContract util.Uint160
|
||||
AlphabetState AlphabetState
|
||||
Converter PrecisionConverter
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
NeoFSClient *neofscontract.ClientWrapper
|
||||
AlphabetState AlphabetState
|
||||
Converter PrecisionConverter
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -67,12 +64,11 @@ func New(p *Params) (*Processor, error) {
|
|||
}
|
||||
|
||||
return &Processor{
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
neofsClient: p.NeoFSClient,
|
||||
balanceContract: p.BalanceContract,
|
||||
alphabetState: p.AlphabetState,
|
||||
converter: p.Converter,
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
neofsClient: p.NeoFSClient,
|
||||
alphabetState: p.AlphabetState,
|
||||
converter: p.Converter,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -83,7 +79,7 @@ func (bp *Processor) ListenerNotificationParsers() []event.NotificationParserInf
|
|||
// new lock event
|
||||
lock := event.NotificationParserInfo{}
|
||||
lock.SetType(lockNotification)
|
||||
lock.SetScriptHash(bp.balanceContract)
|
||||
lock.SetScriptHash(bp.neofsClient.ContractAddress())
|
||||
lock.SetParser(balanceEvent.ParseLock)
|
||||
parsers = append(parsers, lock)
|
||||
|
||||
|
@ -97,7 +93,7 @@ func (bp *Processor) ListenerNotificationHandlers() []event.NotificationHandlerI
|
|||
// lock handler
|
||||
lock := event.NotificationHandlerInfo{}
|
||||
lock.SetType(lockNotification)
|
||||
lock.SetScriptHash(bp.balanceContract)
|
||||
lock.SetScriptHash(bp.neofsClient.ContractAddress())
|
||||
lock.SetHandler(bp.handleLock)
|
||||
handlers = append(handlers, lock)
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"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"
|
||||
neofsid "github.com/nspcc-dev/neofs-node/pkg/morph/client/neofsid/wrapper"
|
||||
"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 struct {
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
containerContract util.Uint160
|
||||
alphabetState AlphabetState
|
||||
cnrClient *wrapper.Wrapper // notary must be enabled
|
||||
idClient *neofsid.ClientWrapper
|
||||
netState NetworkState
|
||||
notaryDisabled bool
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
alphabetState AlphabetState
|
||||
cnrClient *wrapper.Wrapper // notary must be enabled
|
||||
idClient *neofsid.ClientWrapper
|
||||
netState NetworkState
|
||||
notaryDisabled bool
|
||||
}
|
||||
|
||||
// Params of the processor constructor.
|
||||
Params struct {
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
ContainerContract util.Uint160
|
||||
AlphabetState AlphabetState
|
||||
ContainerClient *wrapper.Wrapper
|
||||
NeoFSIDClient *neofsid.ClientWrapper
|
||||
NetworkState NetworkState
|
||||
NotaryDisabled bool
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
AlphabetState AlphabetState
|
||||
ContainerClient *wrapper.Wrapper
|
||||
NeoFSIDClient *neofsid.ClientWrapper
|
||||
NetworkState NetworkState
|
||||
NotaryDisabled bool
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -85,14 +82,13 @@ func New(p *Params) (*Processor, error) {
|
|||
}
|
||||
|
||||
return &Processor{
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
containerContract: p.ContainerContract,
|
||||
alphabetState: p.AlphabetState,
|
||||
cnrClient: p.ContainerClient,
|
||||
idClient: p.NeoFSIDClient,
|
||||
netState: p.NetworkState,
|
||||
notaryDisabled: p.NotaryDisabled,
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
alphabetState: p.AlphabetState,
|
||||
cnrClient: p.ContainerClient,
|
||||
idClient: p.NeoFSIDClient,
|
||||
netState: p.NetworkState,
|
||||
notaryDisabled: p.NotaryDisabled,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -108,7 +104,7 @@ func (cp *Processor) ListenerNotificationParsers() []event.NotificationParserInf
|
|||
p event.NotificationParserInfo
|
||||
)
|
||||
|
||||
p.SetScriptHash(cp.containerContract)
|
||||
p.SetScriptHash(cp.cnrClient.ContractAddress())
|
||||
|
||||
// container put
|
||||
p.SetType(event.TypeFromString(putNotification))
|
||||
|
@ -140,7 +136,7 @@ func (cp *Processor) ListenerNotificationHandlers() []event.NotificationHandlerI
|
|||
h event.NotificationHandlerInfo
|
||||
)
|
||||
|
||||
h.SetScriptHash(cp.containerContract)
|
||||
h.SetScriptHash(cp.cnrClient.ContractAddress())
|
||||
|
||||
// container put
|
||||
h.SetType(event.TypeFromString(putNotification))
|
||||
|
@ -169,7 +165,7 @@ func (cp *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
|
|||
)
|
||||
|
||||
p.SetMempoolType(mempoolevent.TransactionAdded)
|
||||
p.SetScriptHash(cp.containerContract)
|
||||
p.SetScriptHash(cp.cnrClient.ContractAddress())
|
||||
|
||||
// container put
|
||||
p.SetRequestType(containerEvent.PutNotaryEvent)
|
||||
|
@ -197,7 +193,7 @@ func (cp *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
|
|||
hh = make([]event.NotaryHandlerInfo, 0, 3)
|
||||
)
|
||||
|
||||
h.SetScriptHash(cp.containerContract)
|
||||
h.SetScriptHash(cp.cnrClient.ContractAddress())
|
||||
h.SetMempoolType(mempoolevent.TransactionAdded)
|
||||
|
||||
// container put
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"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"
|
||||
container "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/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
|
||||
// and new epoch ticker, because it is related to contract.
|
||||
Processor struct {
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
netmapContract util.Uint160
|
||||
epochTimer EpochTimerReseter
|
||||
epochState EpochState
|
||||
alphabetState AlphabetState
|
||||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
epochTimer EpochTimerReseter
|
||||
epochState EpochState
|
||||
alphabetState AlphabetState
|
||||
|
||||
netmapClient *nmWrapper.Wrapper
|
||||
containerWrp *container.Wrapper
|
||||
|
@ -73,10 +71,8 @@ type (
|
|||
|
||||
// Params of the processor constructor.
|
||||
Params struct {
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
// TODO(@fyrchik): add `ContractHash` method to the NetmapClient and remove this parameter.
|
||||
NetmapContract util.Uint160
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
NetmapClient *nmWrapper.Wrapper
|
||||
EpochTimer EpochTimerReseter
|
||||
EpochState EpochState
|
||||
|
@ -134,7 +130,6 @@ func New(p *Params) (*Processor, error) {
|
|||
return &Processor{
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
netmapContract: p.NetmapContract,
|
||||
epochTimer: p.EpochTimer,
|
||||
epochState: p.EpochState,
|
||||
alphabetState: p.AlphabetState,
|
||||
|
@ -157,30 +152,28 @@ func New(p *Params) (*Processor, error) {
|
|||
func (np *Processor) ListenerNotificationParsers() []event.NotificationParserInfo {
|
||||
parsers := make([]event.NotificationParserInfo, 0, 3)
|
||||
|
||||
var p event.NotificationParserInfo
|
||||
|
||||
p.SetScriptHash(np.netmapClient.ContractAddress())
|
||||
|
||||
// new epoch event
|
||||
newEpoch := event.NotificationParserInfo{}
|
||||
newEpoch.SetType(newEpochNotification)
|
||||
newEpoch.SetScriptHash(np.netmapContract)
|
||||
newEpoch.SetParser(netmapEvent.ParseNewEpoch)
|
||||
parsers = append(parsers, newEpoch)
|
||||
p.SetType(newEpochNotification)
|
||||
p.SetParser(netmapEvent.ParseNewEpoch)
|
||||
parsers = append(parsers, p)
|
||||
|
||||
if !np.notaryDisabled {
|
||||
return parsers
|
||||
}
|
||||
|
||||
// new peer event
|
||||
addPeer := event.NotificationParserInfo{}
|
||||
addPeer.SetType(addPeerNotification)
|
||||
addPeer.SetScriptHash(np.netmapContract)
|
||||
addPeer.SetParser(netmapEvent.ParseAddPeer)
|
||||
parsers = append(parsers, addPeer)
|
||||
p.SetType(addPeerNotification)
|
||||
p.SetParser(netmapEvent.ParseAddPeer)
|
||||
parsers = append(parsers, p)
|
||||
|
||||
// update peer event
|
||||
updatePeer := event.NotificationParserInfo{}
|
||||
updatePeer.SetType(updatePeerStateNotification)
|
||||
updatePeer.SetScriptHash(np.netmapContract)
|
||||
updatePeer.SetParser(netmapEvent.ParseUpdatePeer)
|
||||
parsers = append(parsers, updatePeer)
|
||||
p.SetType(updatePeerStateNotification)
|
||||
p.SetParser(netmapEvent.ParseUpdatePeer)
|
||||
parsers = append(parsers, p)
|
||||
|
||||
return parsers
|
||||
}
|
||||
|
@ -189,30 +182,28 @@ func (np *Processor) ListenerNotificationParsers() []event.NotificationParserInf
|
|||
func (np *Processor) ListenerNotificationHandlers() []event.NotificationHandlerInfo {
|
||||
handlers := make([]event.NotificationHandlerInfo, 0, 3)
|
||||
|
||||
var i event.NotificationHandlerInfo
|
||||
|
||||
i.SetScriptHash(np.netmapClient.ContractAddress())
|
||||
|
||||
// new epoch handler
|
||||
newEpoch := event.NotificationHandlerInfo{}
|
||||
newEpoch.SetType(newEpochNotification)
|
||||
newEpoch.SetScriptHash(np.netmapContract)
|
||||
newEpoch.SetHandler(np.handleNewEpoch)
|
||||
handlers = append(handlers, newEpoch)
|
||||
i.SetType(newEpochNotification)
|
||||
i.SetHandler(np.handleNewEpoch)
|
||||
handlers = append(handlers, i)
|
||||
|
||||
if !np.notaryDisabled {
|
||||
return handlers
|
||||
}
|
||||
|
||||
// new peer handler
|
||||
addPeer := event.NotificationHandlerInfo{}
|
||||
addPeer.SetType(addPeerNotification)
|
||||
addPeer.SetScriptHash(np.netmapContract)
|
||||
addPeer.SetHandler(np.handleAddPeer)
|
||||
handlers = append(handlers, addPeer)
|
||||
i.SetType(addPeerNotification)
|
||||
i.SetHandler(np.handleAddPeer)
|
||||
handlers = append(handlers, i)
|
||||
|
||||
// update peer handler
|
||||
updatePeer := event.NotificationHandlerInfo{}
|
||||
updatePeer.SetType(updatePeerStateNotification)
|
||||
updatePeer.SetScriptHash(np.netmapContract)
|
||||
updatePeer.SetHandler(np.handleUpdateState)
|
||||
handlers = append(handlers, updatePeer)
|
||||
i.SetType(updatePeerStateNotification)
|
||||
i.SetHandler(np.handleUpdateState)
|
||||
handlers = append(handlers, i)
|
||||
|
||||
return handlers
|
||||
}
|
||||
|
@ -226,7 +217,7 @@ func (np *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
|
|||
)
|
||||
|
||||
p.SetMempoolType(mempoolevent.TransactionAdded)
|
||||
p.SetScriptHash(np.netmapContract)
|
||||
p.SetScriptHash(np.netmapClient.ContractAddress())
|
||||
|
||||
// new peer
|
||||
p.SetRequestType(netmapEvent.AddPeerNotaryEvent)
|
||||
|
@ -250,7 +241,7 @@ func (np *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
|
|||
)
|
||||
|
||||
h.SetMempoolType(mempoolevent.TransactionAdded)
|
||||
h.SetScriptHash(np.netmapContract)
|
||||
h.SetScriptHash(np.netmapClient.ContractAddress())
|
||||
|
||||
// new peer
|
||||
h.SetRequestType(netmapEvent.AddPeerNotaryEvent)
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"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"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||
reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation"
|
||||
|
@ -30,8 +29,6 @@ type (
|
|||
log *zap.Logger
|
||||
pool *ants.Pool
|
||||
|
||||
reputationContract util.Uint160
|
||||
|
||||
epochState EpochState
|
||||
alphabetState AlphabetState
|
||||
|
||||
|
@ -44,14 +41,13 @@ type (
|
|||
|
||||
// Params of the processor constructor.
|
||||
Params struct {
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
ReputationContract util.Uint160
|
||||
EpochState EpochState
|
||||
AlphabetState AlphabetState
|
||||
ReputationWrapper *reputationWrapper.ClientWrapper
|
||||
ManagerBuilder common.ManagerBuilder
|
||||
NotaryDisabled bool
|
||||
Log *zap.Logger
|
||||
PoolSize int
|
||||
EpochState EpochState
|
||||
AlphabetState AlphabetState
|
||||
ReputationWrapper *reputationWrapper.ClientWrapper
|
||||
ManagerBuilder common.ManagerBuilder
|
||||
NotaryDisabled bool
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -82,14 +78,13 @@ func New(p *Params) (*Processor, error) {
|
|||
}
|
||||
|
||||
return &Processor{
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
reputationContract: p.ReputationContract,
|
||||
epochState: p.EpochState,
|
||||
alphabetState: p.AlphabetState,
|
||||
reputationWrp: p.ReputationWrapper,
|
||||
mngBuilder: p.ManagerBuilder,
|
||||
notaryDisabled: p.NotaryDisabled,
|
||||
log: p.Log,
|
||||
pool: pool,
|
||||
epochState: p.EpochState,
|
||||
alphabetState: p.AlphabetState,
|
||||
reputationWrp: p.ReputationWrapper,
|
||||
mngBuilder: p.ManagerBuilder,
|
||||
notaryDisabled: p.NotaryDisabled,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -104,7 +99,7 @@ func (rp *Processor) ListenerNotificationParsers() []event.NotificationParserInf
|
|||
// put reputation event
|
||||
put := event.NotificationParserInfo{}
|
||||
put.SetType(putReputationNotification)
|
||||
put.SetScriptHash(rp.reputationContract)
|
||||
put.SetScriptHash(rp.reputationWrp.ContractAddress())
|
||||
put.SetParser(reputationEvent.ParsePut)
|
||||
parsers = append(parsers, put)
|
||||
|
||||
|
@ -122,7 +117,7 @@ func (rp *Processor) ListenerNotificationHandlers() []event.NotificationHandlerI
|
|||
// put reputation handler
|
||||
put := event.NotificationHandlerInfo{}
|
||||
put.SetType(putReputationNotification)
|
||||
put.SetScriptHash(rp.reputationContract)
|
||||
put.SetScriptHash(rp.reputationWrp.ContractAddress())
|
||||
put.SetHandler(rp.handlePutReputation)
|
||||
handlers = append(handlers, put)
|
||||
|
||||
|
@ -135,7 +130,7 @@ func (rp *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
|
|||
|
||||
p.SetMempoolType(mempoolevent.TransactionAdded)
|
||||
p.SetRequestType(reputationEvent.PutNotaryEvent)
|
||||
p.SetScriptHash(rp.reputationContract)
|
||||
p.SetScriptHash(rp.reputationWrp.ContractAddress())
|
||||
p.SetParser(reputationEvent.ParsePutNotary)
|
||||
|
||||
return []event.NotaryParserInfo{p}
|
||||
|
@ -147,7 +142,7 @@ func (rp *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
|
|||
|
||||
h.SetMempoolType(mempoolevent.TransactionAdded)
|
||||
h.SetRequestType(reputationEvent.PutNotaryEvent)
|
||||
h.SetScriptHash(rp.reputationContract)
|
||||
h.SetScriptHash(rp.reputationWrp.ContractAddress())
|
||||
h.SetHandler(rp.handlePutReputation)
|
||||
|
||||
return []event.NotaryHandlerInfo{h}
|
||||
|
|
Loading…
Reference in a new issue