[#486] innerring: Use fee provider and notary disabled flag in processors

Processors that use `invoke` package to make chain invocation should provide
fee config and client with enabled or disabled notary support. If notary
support is disabled, then functions from `invoke` package will perform
ordinary method invocation with extra fee.

Processors that use `morph/client` wrappers should check `notaryDisabled`
flag to call corresponding wrapper function.

Netmap processor omits some actions during validator syncronization
if notary is disabled.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2021-04-29 16:40:34 +03:00 committed by Alex Vanin
parent 91a1896b8b
commit f2562e8c47
16 changed files with 111 additions and 38 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util"
SDKClient "github.com/nspcc-dev/neofs-api-go/pkg/client"
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
"github.com/nspcc-dev/neofs-node/pkg/innerring/invoke"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
wrapContainer "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
@ -66,6 +67,7 @@ type (
AuditContract util.Uint160
MorphClient *client.Client
IRList Indexer
FeeProvider *config.FeeConfig
ClientCache NeoFSClientCache
RPCSearchTimeout time.Duration
TaskManager TaskManager
@ -94,6 +96,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/audit: neo:morph client is not set")
case p.IRList == nil:
return nil, errors.New("ir/audit: global state is not set")
case p.FeeProvider == nil:
return nil, errors.New("ir/audit: fee provider is not set")
case p.ClientCache == nil:
return nil, errors.New("ir/audit: neofs RPC client cache is not set")
case p.TaskManager == nil:
@ -110,13 +114,13 @@ func New(p *Params) (*Processor, error) {
}
// creating enhanced client for getting network map
netmapClient, err := invoke.NewNetmapClient(p.MorphClient, p.NetmapContract)
netmapClient, err := invoke.NewNetmapClient(p.MorphClient, p.NetmapContract, p.FeeProvider)
if err != nil {
return nil, err
}
// creating enhanced client for getting containers
containerClient, err := invoke.NewContainerClient(p.MorphClient, p.ContainerContract)
containerClient, err := invoke.NewContainerClient(p.MorphClient, p.ContainerContract, p.FeeProvider)
if err != nil {
return nil, err
}

View file

@ -14,7 +14,7 @@ func (bp *Processor) processLock(lock *balanceEvent.Lock) {
return
}
err := invoke.CashOutCheque(bp.mainnetClient, bp.neofsContract,
err := invoke.CashOutCheque(bp.mainnetClient, bp.neofsContract, bp.feeProvider,
&invoke.ChequeParams{
ID: lock.ID(),
Amount: bp.converter.ToFixed8(lock.Amount()),

View file

@ -2,6 +2,7 @@ package balance
import (
"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"
balanceEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/balance"
@ -30,6 +31,7 @@ type (
mainnetClient *client.Client
alphabetState AlphabetState
converter PrecisionConverter
feeProvider *config.FeeConfig
}
// Params of the processor constructor.
@ -41,6 +43,7 @@ type (
MainnetClient *client.Client
AlphabetState AlphabetState
Converter PrecisionConverter
FeeProvider *config.FeeConfig
}
)
@ -59,6 +62,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/balance: global state is not set")
case p.Converter == nil:
return nil, errors.New("ir/balance: balance precision converter is not set")
case p.FeeProvider == nil:
return nil, errors.New("ir/balance: fee provider is not set")
}
p.Log.Debug("balance worker pool", zap.Int("size", p.PoolSize))
@ -76,6 +81,7 @@ func New(p *Params) (*Processor, error) {
mainnetClient: p.MainnetClient,
alphabetState: p.AlphabetState,
converter: p.Converter,
feeProvider: p.FeeProvider,
}, nil
}

View file

@ -37,7 +37,7 @@ func (cp *Processor) processContainerPut(put *containerEvent.Put) {
return
}
err := invoke.RegisterContainer(cp.morphClient, cp.containerContract,
err := invoke.RegisterContainer(cp.morphClient, cp.containerContract, cp.feeProvider,
&invoke.ContainerParams{
Key: put.PublicKey(),
Container: cnrData,
@ -56,7 +56,7 @@ func (cp *Processor) processContainerDelete(delete *containerEvent.Delete) {
return
}
err := invoke.RemoveContainer(cp.morphClient, cp.containerContract,
err := invoke.RemoveContainer(cp.morphClient, cp.containerContract, cp.feeProvider,
&invoke.RemoveContainerParams{
ContainerID: delete.ContainerID(),
Signature: delete.Signature(),

View file

@ -2,6 +2,7 @@ package container
import (
"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"
containerEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/container"
@ -23,6 +24,7 @@ type (
containerContract util.Uint160
morphClient *client.Client
alphabetState AlphabetState
feeProvider *config.FeeConfig
}
// Params of the processor constructor.
@ -32,6 +34,7 @@ type (
ContainerContract util.Uint160
MorphClient *client.Client
AlphabetState AlphabetState
FeeProvider *config.FeeConfig
}
)
@ -49,6 +52,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/container: neo:morph client is not set")
case p.AlphabetState == nil:
return nil, errors.New("ir/container: global state is not set")
case p.FeeProvider == nil:
return nil, errors.New("ir/container: fee provider is not set")
}
p.Log.Debug("container worker pool", zap.Int("size", p.PoolSize))
@ -64,6 +69,7 @@ func New(p *Params) (*Processor, error) {
containerContract: p.ContainerContract,
morphClient: p.MorphClient,
alphabetState: p.AlphabetState,
feeProvider: p.FeeProvider,
}, nil
}

View file

@ -65,7 +65,12 @@ func (gp *Processor) processAlphabetSync() {
} else {
sort.Sort(newInnerRing)
if gp.notaryDisabled {
err = invoke.SetInnerRing(gp.morphClient, gp.netmapContract, gp.feeProvider, newInnerRing)
} else {
err = gp.morphClient.UpdateNeoFSAlphabetList(newInnerRing)
}
if err != nil {
gp.log.Error("can't update inner ring list with new alphabet keys",
zap.String("error", err.Error()))
@ -73,12 +78,14 @@ func (gp *Processor) processAlphabetSync() {
}
}
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()))
}
}
// 4. Update NeoFS contract in main net.
epoch := gp.epochState.EpochCounter()
@ -88,7 +95,7 @@ func (gp *Processor) processAlphabetSync() {
id := append([]byte(alphabetUpdateIDPrefix), buf...)
err = invoke.AlphabetUpdate(gp.mainnetClient, gp.neofsContract, id, newAlphabet)
err = invoke.AlphabetUpdate(gp.mainnetClient, gp.neofsContract, gp.feeProvider, id, newAlphabet)
if err != nil {
gp.log.Error("can't update list of alphabet nodes in neofs contract",
zap.String("error", err.Error()))

View file

@ -3,6 +3,7 @@ package governance
import (
"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/panjf2000/ants/v2"
@ -36,6 +37,7 @@ type (
log *zap.Logger
pool *ants.Pool
neofsContract util.Uint160
netmapContract util.Uint160
alphabetState AlphabetState
epochState EpochState
@ -43,12 +45,16 @@ type (
mainnetClient *client.Client
morphClient *client.Client
notaryDisabled bool
feeProvider *config.FeeConfig
}
// Params of the processor constructor.
Params struct {
Log *zap.Logger
NeoFSContract util.Uint160
NetmapContract util.Uint160
AlphabetState AlphabetState
EpochState EpochState
@ -56,6 +62,9 @@ type (
MorphClient *client.Client
MainnetClient *client.Client
NotaryDisabled bool
FeeProvider *config.FeeConfig
}
)
@ -74,6 +83,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/governance: global state is not set")
case p.Voter == nil:
return nil, errors.New("ir/governance: global state is not set")
case p.FeeProvider == nil:
return nil, errors.New("ir/governance: fee provider is not set")
}
pool, err := ants.NewPool(ProcessorPoolSize, ants.WithNonblocking(true))
@ -85,11 +96,14 @@ func New(p *Params) (*Processor, error) {
log: p.Log,
pool: pool,
neofsContract: p.NeoFSContract,
netmapContract: p.NetmapContract,
alphabetState: p.AlphabetState,
epochState: p.EpochState,
voter: p.Voter,
mainnetClient: p.MainnetClient,
morphClient: p.MorphClient,
notaryDisabled: p.NotaryDisabled,
feeProvider: p.FeeProvider,
}, nil
}

View file

@ -21,7 +21,7 @@ func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) {
}
// send transferX to balance contract
err := invoke.Mint(np.morphClient, np.balanceContract,
err := invoke.Mint(np.morphClient, np.balanceContract, np.feeProvider,
&invoke.MintBurnParams{
ScriptHash: deposit.To().BytesBE(),
Amount: np.converter.ToBalancePrecision(deposit.Amount()),
@ -94,7 +94,7 @@ func (np *Processor) processWithdraw(withdraw *neofsEvent.Withdraw) {
curEpoch := np.epochState.EpochCounter()
err = invoke.LockAsset(np.morphClient, np.balanceContract,
err = invoke.LockAsset(np.morphClient, np.balanceContract, np.feeProvider,
&invoke.LockParams{
ID: withdraw.ID(),
User: withdraw.User(),
@ -115,7 +115,7 @@ func (np *Processor) processCheque(cheque *neofsEvent.Cheque) {
return
}
err := invoke.Burn(np.morphClient, np.balanceContract,
err := invoke.Burn(np.morphClient, np.balanceContract, np.feeProvider,
&invoke.MintBurnParams{
ScriptHash: cheque.LockAccount().BytesBE(),
Amount: np.converter.ToBalancePrecision(cheque.Amount()),

View file

@ -14,7 +14,7 @@ func (np *Processor) processConfig(config *neofsEvent.Config) {
return
}
err := invoke.SetConfig(np.morphClient, np.netmapContract,
err := invoke.SetConfig(np.morphClient, np.netmapContract, np.feeProvider,
&invoke.SetConfigArgs{
ID: config.ID(),
Key: config.Key(),

View file

@ -6,6 +6,7 @@ import (
lru "github.com/hashicorp/golang-lru"
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
"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"
neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
@ -41,6 +42,7 @@ type (
epochState EpochState
alphabetState AlphabetState
converter PrecisionConverter
feeProvider *config.FeeConfig
mintEmitLock *sync.Mutex
mintEmitCache *lru.Cache
mintEmitThreshold uint64
@ -59,6 +61,7 @@ type (
EpochState EpochState
AlphabetState AlphabetState
Converter PrecisionConverter
FeeProvider *config.FeeConfig
MintEmitCacheSize int
MintEmitThreshold uint64 // in epochs
MintEmitValue fixedn.Fixed8
@ -86,6 +89,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/neofs: global state is not set")
case p.Converter == nil:
return nil, errors.New("ir/neofs: balance precision converter is not set")
case p.FeeProvider == nil:
return nil, errors.New("ir/neofs: fee provider is not set")
}
p.Log.Debug("neofs worker pool", zap.Int("size", p.PoolSize))
@ -110,6 +115,7 @@ func New(p *Params) (*Processor, error) {
epochState: p.EpochState,
alphabetState: p.AlphabetState,
converter: p.Converter,
feeProvider: p.FeeProvider,
mintEmitLock: new(sync.Mutex),
mintEmitCache: lruCache,
mintEmitThreshold: p.MintEmitThreshold,

View file

@ -25,7 +25,8 @@ func (np *Processor) processNetmapCleanupTick(epoch uint64) {
np.log.Info("vote to remove node from netmap", zap.String("key", s))
err = invoke.UpdatePeerState(np.morphClient, np.netmapContract, &invoke.UpdatePeerArgs{
err = invoke.UpdatePeerState(np.morphClient, np.netmapContract, np.feeProvider,
&invoke.UpdatePeerArgs{
Key: key,
Status: netmap.NodeStateOffline,
})

View file

@ -27,7 +27,12 @@ func (np *Processor) processNewEpoch(epoch uint64) {
}
if epoch > 0 { // estimates are invalid in genesis epoch
if np.notaryDisabled {
err = np.containerWrp.StartEstimation(epoch - 1)
} else {
err = np.containerWrp.StartEstimationNotary(epoch - 1)
}
if err != nil {
np.log.Warn("can't start container size estimation",
zap.Uint64("epoch", epoch),
@ -52,7 +57,7 @@ func (np *Processor) processNewEpochTick() {
nextEpoch := np.epochState.EpochCounter() + 1
np.log.Debug("next epoch", zap.Uint64("value", nextEpoch))
err := invoke.SetNewEpoch(np.morphClient, np.netmapContract, nextEpoch)
err := invoke.SetNewEpoch(np.morphClient, np.netmapContract, np.feeProvider, nextEpoch)
if err != nil {
np.log.Error("can't invoke netmap.NewEpoch", zap.Error(err))
}

View file

@ -66,7 +66,8 @@ func (np *Processor) processAddPeer(node []byte) {
np.log.Info("approving network map candidate",
zap.String("key", keyString))
if err := invoke.ApprovePeer(np.morphClient, np.netmapContract, node); err != nil {
err := invoke.ApprovePeer(np.morphClient, np.netmapContract, np.feeProvider, node)
if err != nil {
np.log.Error("can't invoke netmap.AddPeer", zap.Error(err))
}
}
@ -92,7 +93,7 @@ func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) {
// again before new epoch will tick
np.netmapSnapshot.flag(hex.EncodeToString(ev.PublicKey().Bytes()))
err := invoke.UpdatePeerState(np.morphClient, np.netmapContract,
err := invoke.UpdatePeerState(np.morphClient, np.netmapContract, np.feeProvider,
&invoke.UpdatePeerArgs{
Key: ev.PublicKey(),
Status: ev.Status(),

View file

@ -3,6 +3,7 @@ package netmap
import (
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
container "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
@ -64,6 +65,9 @@ type (
handleAlphabetSync event.Handler
nodeValidator NodeValidator
notaryDisabled bool
feeProvider *config.FeeConfig
}
// Params of the processor constructor.
@ -84,6 +88,9 @@ type (
AlphabetSyncHandler event.Handler
NodeValidator NodeValidator
NotaryDisabled bool
FeeProvider *config.FeeConfig
}
)
@ -116,6 +123,8 @@ func New(p *Params) (*Processor, error) {
return nil, errors.New("ir/netmap: container contract wrapper is not set")
case p.NodeValidator == nil:
return nil, errors.New("ir/netmap: node validator is not set")
case p.FeeProvider == nil:
return nil, errors.New("ir/netmap: fee provider is not set")
}
p.Log.Debug("netmap worker pool", zap.Int("size", p.PoolSize))
@ -142,6 +151,9 @@ func New(p *Params) (*Processor, error) {
handleAlphabetSync: p.AlphabetSyncHandler,
nodeValidator: p.NodeValidator,
notaryDisabled: p.NotaryDisabled,
feeProvider: p.FeeProvider,
}, nil
}

View file

@ -41,7 +41,14 @@ func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputa
args.SetPeerID(id)
args.SetValue(value)
err := rp.reputationWrp.PutViaNotary(args)
var err error
if rp.notaryDisabled {
err = rp.reputationWrp.Put(args)
} else {
err = rp.reputationWrp.PutViaNotary(args)
}
if err != nil {
rp.log.Warn("can't send approval tx for reputation value",
zap.String("peer_id", hex.EncodeToString(id.ToV2().GetValue())),

View file

@ -26,6 +26,8 @@ type (
log *zap.Logger
pool *ants.Pool
notaryDisabled bool
reputationContract util.Uint160
epochState EpochState
@ -38,6 +40,7 @@ type (
Params struct {
Log *zap.Logger
PoolSize int
NotaryDisabled bool
ReputationContract util.Uint160
EpochState EpochState
AlphabetState AlphabetState
@ -72,6 +75,7 @@ func New(p *Params) (*Processor, error) {
return &Processor{
log: p.Log,
pool: pool,
notaryDisabled: p.NotaryDisabled,
reputationContract: p.ReputationContract,
epochState: p.EpochState,
alphabetState: p.AlphabetState,