frostfs-node/pkg/innerring/processors/balance/processor.go
Evgenii Stratonikov b1614a284d
All checks were successful
Tests and linters / Run gofumpt (push) Successful in 1m26s
Tests and linters / Staticcheck (push) Successful in 3m21s
Vulncheck / Vulncheck (push) Successful in 3m36s
Build / Build Components (push) Successful in 3m58s
Tests and linters / Lint (push) Successful in 4m30s
Pre-commit hooks / Pre-commit (push) Successful in 4m35s
Tests and linters / Tests (push) Successful in 5m15s
Tests and linters / Tests with -race (push) Successful in 5m33s
Tests and linters / gopls check (push) Successful in 5m45s
[#1546] morph/event: Export NotificationHandlerInfo fields
Hiding them achieves nothing, as the struct has no methods and is not
used concurrently.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2024-12-11 07:39:49 +00:00

111 lines
3 KiB
Go

package balance
import (
"context"
"errors"
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/metrics"
frostfscontract "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/frostfs"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event"
balanceEvent "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/event/balance"
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
"github.com/nspcc-dev/neo-go/pkg/util"
"github.com/panjf2000/ants/v2"
)
type (
// AlphabetState is a callback interface for inner ring global state.
AlphabetState interface {
IsAlphabet(context.Context) bool
}
// PrecisionConverter converts balance amount values.
PrecisionConverter interface {
ToFixed8(int64) int64
}
FrostFSClient interface {
Cheque(ctx context.Context, p frostfscontract.ChequePrm) error
}
// Processor of events produced by balance contract in the morphchain.
Processor struct {
log *logger.Logger
metrics metrics.Register
pool *ants.Pool
frostfsClient FrostFSClient
balanceSC util.Uint160
alphabetState AlphabetState
converter PrecisionConverter
}
// Params of the processor constructor.
Params struct {
Log *logger.Logger
Metrics metrics.Register
PoolSize int
FrostFSClient FrostFSClient
BalanceSC util.Uint160
AlphabetState AlphabetState
Converter PrecisionConverter
}
)
const (
lockNotification = "Lock"
)
// New creates a balance contract processor instance.
func New(p *Params) (*Processor, error) {
switch {
case p.Log == nil:
return nil, errors.New("ir/balance: logger is not set")
case p.AlphabetState == nil:
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")
}
pool, err := ants.NewPool(p.PoolSize, ants.WithNonblocking(true))
if err != nil {
return nil, fmt.Errorf("ir/balance: can't create worker pool: %w", err)
}
metricsRegister := p.Metrics
if metricsRegister == nil {
metricsRegister = metrics.DefaultRegister{}
}
return &Processor{
log: p.Log,
metrics: metricsRegister,
pool: pool,
frostfsClient: p.FrostFSClient,
balanceSC: p.BalanceSC,
alphabetState: p.AlphabetState,
converter: p.Converter,
}, nil
}
// ListenerNotificationHandlers for the 'event.Listener' event producer.
func (bp *Processor) ListenerNotificationHandlers() []event.NotificationHandlerInfo {
return []event.NotificationHandlerInfo{
{
Contract: bp.balanceSC,
Type: lockNotification,
Parser: balanceEvent.ParseLock,
Handlers: []event.Handler{bp.handleLock},
},
}
}
// ListenerNotaryParsers for the 'event.Listener' event producer.
func (bp *Processor) ListenerNotaryParsers() []event.NotaryParserInfo {
return nil
}
// ListenerNotaryHandlers for the 'event.Listener' event producer.
func (bp *Processor) ListenerNotaryHandlers() []event.NotaryHandlerInfo {
return nil
}