forked from TrueCloudLab/frostfs-node
[#496] pkg/innerring: provide wrappers to processors
The only thing we need hashes for is to process notifications. Balance contract if left for now, as it has some initialization. Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
9b87e6267d
commit
8a2b7f4501
24 changed files with 215 additions and 228 deletions
|
@ -67,6 +67,8 @@ type (
|
||||||
precision precision.Fixed8Converter
|
precision precision.Fixed8Converter
|
||||||
auditClient *auditWrapper.ClientWrapper
|
auditClient *auditWrapper.ClientWrapper
|
||||||
healthStatus atomic.Value
|
healthStatus atomic.Value
|
||||||
|
balanceClient *balanceWrapper.Wrapper
|
||||||
|
netmapClient *nmWrapper.Wrapper
|
||||||
|
|
||||||
// notary configuration
|
// notary configuration
|
||||||
feeConfig *config.FeeConfig
|
feeConfig *config.FeeConfig
|
||||||
|
@ -139,10 +141,6 @@ const (
|
||||||
notaryExtraBlocks = 300
|
notaryExtraBlocks = 300
|
||||||
// amount of tries before notary deposit timeout.
|
// amount of tries before notary deposit timeout.
|
||||||
notaryDepositTimeout = 100
|
notaryDepositTimeout = 100
|
||||||
|
|
||||||
precisionMethod = "decimals"
|
|
||||||
// netmap
|
|
||||||
getEpochMethod = "epoch"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -404,12 +402,12 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nmClient, err := nmWrapper.NewFromMorph(server.morphClient, server.contracts.netmap, fee)
|
server.netmapClient, err = nmWrapper.NewFromMorph(server.morphClient, server.contracts.netmap, fee)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
balClient, err := balanceWrapper.NewFromMorph(server.morphClient, server.contracts.balance, fee, balanceWrapper.TryNotary())
|
server.balanceClient, err = balanceWrapper.NewFromMorph(server.morphClient, server.contracts.balance, fee, balanceWrapper.TryNotary())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -425,7 +423,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// create global runtime config reader
|
// create global runtime config reader
|
||||||
globalConfig := config.NewGlobalConfigReader(cfg, nmClient)
|
globalConfig := config.NewGlobalConfigReader(cfg, server.netmapClient)
|
||||||
|
|
||||||
clientCache := newClientCache(&clientCacheParams{
|
clientCache := newClientCache(&clientCacheParams{
|
||||||
Log: log,
|
Log: log,
|
||||||
|
@ -459,18 +457,18 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
|
|
||||||
// create audit processor
|
// create audit processor
|
||||||
auditProcessor, err := audit.New(&audit.Params{
|
auditProcessor, err := audit.New(&audit.Params{
|
||||||
Log: log,
|
Log: log,
|
||||||
NetmapContract: server.contracts.netmap,
|
NetmapClient: server.netmapClient,
|
||||||
ContainerContract: server.contracts.container,
|
ContainerClient: cnrClient,
|
||||||
AuditContract: server.contracts.audit,
|
AuditContract: server.contracts.audit,
|
||||||
MorphClient: server.morphClient,
|
MorphClient: server.morphClient,
|
||||||
IRList: server,
|
IRList: server,
|
||||||
FeeProvider: server.feeConfig,
|
FeeProvider: server.feeConfig,
|
||||||
ClientCache: clientCache,
|
ClientCache: clientCache,
|
||||||
Key: &server.key.PrivateKey,
|
Key: &server.key.PrivateKey,
|
||||||
RPCSearchTimeout: cfg.GetDuration("audit.timeout.search"),
|
RPCSearchTimeout: cfg.GetDuration("audit.timeout.search"),
|
||||||
TaskManager: auditTaskManager,
|
TaskManager: auditTaskManager,
|
||||||
Reporter: server,
|
Reporter: server,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -482,9 +480,9 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
log: server.log,
|
log: server.log,
|
||||||
cnrSrc: cntWrapper.AsContainerSource(cnrClient),
|
cnrSrc: cntWrapper.AsContainerSource(cnrClient),
|
||||||
auditClient: server.auditClient,
|
auditClient: server.auditClient,
|
||||||
nmSrc: nmClient,
|
nmSrc: server.netmapClient,
|
||||||
clientCache: clientCache,
|
clientCache: clientCache,
|
||||||
balanceClient: balClient,
|
balanceClient: server.balanceClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
auditCalcDeps := &auditSettlementDeps{
|
auditCalcDeps := &auditSettlementDeps{
|
||||||
|
@ -528,7 +526,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
governanceProcessor, err := governance.New(&governance.Params{
|
governanceProcessor, err := governance.New(&governance.Params{
|
||||||
Log: log,
|
Log: log,
|
||||||
NeoFSContract: server.contracts.neofs,
|
NeoFSContract: server.contracts.neofs,
|
||||||
NetmapContract: server.contracts.netmap,
|
NetmapClient: server.netmapClient,
|
||||||
AlphabetState: server,
|
AlphabetState: server,
|
||||||
EpochState: server,
|
EpochState: server,
|
||||||
Voter: server,
|
Voter: server,
|
||||||
|
@ -560,8 +558,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
Log: log,
|
Log: log,
|
||||||
PoolSize: cfg.GetInt("workers.netmap"),
|
PoolSize: cfg.GetInt("workers.netmap"),
|
||||||
NetmapContract: server.contracts.netmap,
|
NetmapContract: server.contracts.netmap,
|
||||||
|
NetmapClient: server.netmapClient,
|
||||||
EpochTimer: server,
|
EpochTimer: server,
|
||||||
MorphClient: server.morphClient,
|
|
||||||
EpochState: server,
|
EpochState: server,
|
||||||
AlphabetState: server,
|
AlphabetState: server,
|
||||||
CleanupEnabled: cfg.GetBool("netmap_cleaner.enabled"),
|
CleanupEnabled: cfg.GetBool("netmap_cleaner.enabled"),
|
||||||
|
@ -596,7 +594,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
FeeProvider: server.feeConfig,
|
FeeProvider: server.feeConfig,
|
||||||
ContainerClient: cnrClient,
|
ContainerClient: cnrClient,
|
||||||
NeoFSIDClient: neofsIDClient,
|
NeoFSIDClient: neofsIDClient,
|
||||||
NetworkState: nmClient,
|
NetworkState: server.netmapClient,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -632,9 +630,9 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
Log: log,
|
Log: log,
|
||||||
PoolSize: cfg.GetInt("workers.neofs"),
|
PoolSize: cfg.GetInt("workers.neofs"),
|
||||||
NeoFSContract: server.contracts.neofs,
|
NeoFSContract: server.contracts.neofs,
|
||||||
BalanceContract: server.contracts.balance,
|
NeoFSIDClient: neofsIDClient,
|
||||||
NetmapContract: server.contracts.netmap,
|
BalanceClient: server.balanceClient,
|
||||||
NeoFSIDContract: server.contracts.neofsID,
|
NetmapClient: server.netmapClient,
|
||||||
MorphClient: server.morphClient,
|
MorphClient: server.morphClient,
|
||||||
EpochState: server,
|
EpochState: server,
|
||||||
AlphabetState: server,
|
AlphabetState: server,
|
||||||
|
@ -659,7 +657,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
Log: log,
|
Log: log,
|
||||||
PoolSize: cfg.GetInt("workers.alphabet"),
|
PoolSize: cfg.GetInt("workers.alphabet"),
|
||||||
AlphabetContracts: server.contracts.alphabet,
|
AlphabetContracts: server.contracts.alphabet,
|
||||||
NetmapContract: server.contracts.netmap,
|
NetmapClient: server.netmapClient,
|
||||||
MorphClient: server.morphClient,
|
MorphClient: server.morphClient,
|
||||||
IRList: server,
|
IRList: server,
|
||||||
StorageEmission: cfg.GetUint64("emit.storage.amount"),
|
StorageEmission: cfg.GetUint64("emit.storage.amount"),
|
||||||
|
@ -683,7 +681,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
ReputationWrapper: repClient,
|
ReputationWrapper: repClient,
|
||||||
ManagerBuilder: reputationcommon.NewManagerBuilder(
|
ManagerBuilder: reputationcommon.NewManagerBuilder(
|
||||||
reputationcommon.ManagersPrm{
|
reputationcommon.ManagersPrm{
|
||||||
NetMapSource: nmClient,
|
NetMapSource: server.netmapClient,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
@ -946,35 +944,25 @@ func parseAlphabetContracts(cfg *viper.Viper) (alphabetContracts, error) {
|
||||||
|
|
||||||
func (s *Server) initConfigFromBlockchain() error {
|
func (s *Server) initConfigFromBlockchain() error {
|
||||||
// get current epoch
|
// get current epoch
|
||||||
val, err := s.morphClient.TestInvoke(s.contracts.netmap, getEpochMethod)
|
epoch, err := s.netmapClient.Epoch()
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("can't read epoch: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
epoch, err := client.IntFromStackItem(val[0])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't parse epoch: %w", err)
|
return fmt.Errorf("can't parse epoch: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get balance precision
|
// get balance precision
|
||||||
v, err := s.morphClient.TestInvoke(s.contracts.balance, precisionMethod)
|
balancePrecision, err := s.balanceClient.Decimals()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't read balance contract precision: %w", err)
|
return fmt.Errorf("can't read balance contract precision: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
balancePrecision, err := client.IntFromStackItem(v[0])
|
s.epochCounter.Store(epoch)
|
||||||
if err != nil {
|
s.precision.SetBalancePrecision(balancePrecision)
|
||||||
return fmt.Errorf("can't parse balance contract precision: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
s.epochCounter.Store(uint64(epoch))
|
|
||||||
s.precision.SetBalancePrecision(uint32(balancePrecision))
|
|
||||||
|
|
||||||
s.log.Debug("read config from blockchain",
|
s.log.Debug("read config from blockchain",
|
||||||
zap.Bool("active", s.IsActive()),
|
zap.Bool("active", s.IsActive()),
|
||||||
zap.Bool("alphabet", s.IsAlphabet()),
|
zap.Bool("alphabet", s.IsAlphabet()),
|
||||||
zap.Int64("epoch", epoch),
|
zap.Uint64("epoch", epoch),
|
||||||
zap.Uint32("precision", uint32(balancePrecision)),
|
zap.Uint32("precision", balancePrecision),
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/snapshot"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ func (np *Processor) processEmit() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
networkMap, err := snapshot.Fetch(np.morphClient, np.netmapContract)
|
networkMap, err := np.netmapClient.Snapshot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Warn("can't get netmap snapshot to emit gas to storage nodes",
|
np.log.Warn("can't get netmap snapshot to emit gas to storage nodes",
|
||||||
zap.String("error", err.Error()))
|
zap.String("error", err.Error()))
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
|
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -34,7 +35,7 @@ type (
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
pool *ants.Pool
|
pool *ants.Pool
|
||||||
alphabetContracts Contracts
|
alphabetContracts Contracts
|
||||||
netmapContract util.Uint160
|
netmapClient *nmWrapper.Wrapper
|
||||||
morphClient *client.Client
|
morphClient *client.Client
|
||||||
irList Indexer
|
irList Indexer
|
||||||
storageEmission uint64
|
storageEmission uint64
|
||||||
|
@ -45,7 +46,7 @@ type (
|
||||||
Log *zap.Logger
|
Log *zap.Logger
|
||||||
PoolSize int
|
PoolSize int
|
||||||
AlphabetContracts Contracts
|
AlphabetContracts Contracts
|
||||||
NetmapContract util.Uint160
|
NetmapClient *nmWrapper.Wrapper
|
||||||
MorphClient *client.Client
|
MorphClient *client.Client
|
||||||
IRList Indexer
|
IRList Indexer
|
||||||
StorageEmission uint64
|
StorageEmission uint64
|
||||||
|
@ -74,7 +75,7 @@ func New(p *Params) (*Processor, error) {
|
||||||
log: p.Log,
|
log: p.Log,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
alphabetContracts: p.AlphabetContracts,
|
alphabetContracts: p.AlphabetContracts,
|
||||||
netmapContract: p.NetmapContract,
|
netmapClient: p.NetmapClient,
|
||||||
morphClient: p.MorphClient,
|
morphClient: p.MorphClient,
|
||||||
irList: p.IRList,
|
irList: p.IRList,
|
||||||
storageEmission: p.StorageEmission,
|
storageEmission: p.StorageEmission,
|
||||||
|
|
|
@ -42,15 +42,14 @@ type (
|
||||||
|
|
||||||
// Processor of events related with data audit.
|
// Processor of events related with data audit.
|
||||||
Processor struct {
|
Processor struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
pool *ants.Pool
|
pool *ants.Pool
|
||||||
containerContract util.Uint160
|
auditContract util.Uint160
|
||||||
auditContract util.Uint160
|
morphClient *client.Client
|
||||||
morphClient *client.Client
|
irList Indexer
|
||||||
irList Indexer
|
clientCache NeoFSClientCache
|
||||||
clientCache NeoFSClientCache
|
key *ecdsa.PrivateKey
|
||||||
key *ecdsa.PrivateKey
|
searchTimeout time.Duration
|
||||||
searchTimeout time.Duration
|
|
||||||
|
|
||||||
containerClient *wrapContainer.Wrapper
|
containerClient *wrapContainer.Wrapper
|
||||||
netmapClient *wrapNetmap.Wrapper
|
netmapClient *wrapNetmap.Wrapper
|
||||||
|
@ -62,18 +61,18 @@ type (
|
||||||
|
|
||||||
// Params of the processor constructor.
|
// Params of the processor constructor.
|
||||||
Params struct {
|
Params struct {
|
||||||
Log *zap.Logger
|
Log *zap.Logger
|
||||||
NetmapContract util.Uint160
|
NetmapClient *wrapNetmap.Wrapper
|
||||||
ContainerContract util.Uint160
|
ContainerClient *wrapContainer.Wrapper
|
||||||
AuditContract util.Uint160
|
AuditContract util.Uint160
|
||||||
MorphClient *client.Client
|
MorphClient *client.Client
|
||||||
IRList Indexer
|
IRList Indexer
|
||||||
FeeProvider *config.FeeConfig
|
FeeProvider *config.FeeConfig
|
||||||
ClientCache NeoFSClientCache
|
ClientCache NeoFSClientCache
|
||||||
RPCSearchTimeout time.Duration
|
RPCSearchTimeout time.Duration
|
||||||
TaskManager TaskManager
|
TaskManager TaskManager
|
||||||
Reporter audit.Reporter
|
Reporter audit.Reporter
|
||||||
Key *ecdsa.PrivateKey
|
Key *ecdsa.PrivateKey
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -114,30 +113,17 @@ func New(p *Params) (*Processor, error) {
|
||||||
return nil, fmt.Errorf("ir/audit: can't create worker pool: %w", err)
|
return nil, fmt.Errorf("ir/audit: can't create worker pool: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// creating enhanced client for getting network map
|
|
||||||
netmapClient, err := wrapNetmap.NewFromMorph(p.MorphClient, p.NetmapContract, p.FeeProvider.SideChainFee())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// creating enhanced client for getting containers
|
|
||||||
containerClient, err := wrapContainer.NewFromMorph(p.MorphClient, p.ContainerContract, p.FeeProvider.SideChainFee())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Processor{
|
return &Processor{
|
||||||
log: p.Log,
|
log: p.Log,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
containerContract: p.ContainerContract,
|
containerClient: p.ContainerClient,
|
||||||
auditContract: p.AuditContract,
|
auditContract: p.AuditContract,
|
||||||
morphClient: p.MorphClient,
|
morphClient: p.MorphClient,
|
||||||
irList: p.IRList,
|
irList: p.IRList,
|
||||||
clientCache: p.ClientCache,
|
clientCache: p.ClientCache,
|
||||||
key: p.Key,
|
key: p.Key,
|
||||||
searchTimeout: p.RPCSearchTimeout,
|
searchTimeout: p.RPCSearchTimeout,
|
||||||
containerClient: containerClient,
|
netmapClient: p.NetmapClient,
|
||||||
netmapClient: netmapClient,
|
|
||||||
taskManager: p.TaskManager,
|
taskManager: p.TaskManager,
|
||||||
reporter: p.Reporter,
|
reporter: p.Reporter,
|
||||||
prevAuditCanceler: func() {},
|
prevAuditCanceler: func() {},
|
||||||
|
|
|
@ -11,7 +11,6 @@ const (
|
||||||
alphabetUpdateIDPrefix = "AlphabetUpdate"
|
alphabetUpdateIDPrefix = "AlphabetUpdate"
|
||||||
|
|
||||||
alphabetUpdateMethod = "alphabetUpdate"
|
alphabetUpdateMethod = "alphabetUpdate"
|
||||||
setInnerRingMethod = "updateInnerRing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gp *Processor) processAlphabetSync() {
|
func (gp *Processor) processAlphabetSync() {
|
||||||
|
@ -70,8 +69,7 @@ func (gp *Processor) processAlphabetSync() {
|
||||||
sort.Sort(newInnerRing)
|
sort.Sort(newInnerRing)
|
||||||
|
|
||||||
if gp.notaryDisabled {
|
if gp.notaryDisabled {
|
||||||
err = gp.morphClient.NotaryInvoke(gp.netmapContract, gp.feeProvider.SideChainFee(), setInnerRingMethod,
|
err = gp.netmapClient.SetInnerRing(newInnerRing)
|
||||||
newInnerRing)
|
|
||||||
} else {
|
} else {
|
||||||
err = gp.morphClient.UpdateNeoFSAlphabetList(newInnerRing)
|
err = gp.morphClient.UpdateNeoFSAlphabetList(newInnerRing)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
|
"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/client"
|
||||||
|
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event/rolemanagement"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event/rolemanagement"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
|
@ -38,10 +39,10 @@ type (
|
||||||
|
|
||||||
// Processor of events related to governance in the network.
|
// Processor of events related to governance in the network.
|
||||||
Processor struct {
|
Processor struct {
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
pool *ants.Pool
|
pool *ants.Pool
|
||||||
neofsContract util.Uint160
|
neofsContract util.Uint160
|
||||||
netmapContract util.Uint160
|
netmapClient *nmWrapper.Wrapper
|
||||||
|
|
||||||
alphabetState AlphabetState
|
alphabetState AlphabetState
|
||||||
epochState EpochState
|
epochState EpochState
|
||||||
|
@ -56,9 +57,8 @@ type (
|
||||||
|
|
||||||
// Params of the processor constructor.
|
// Params of the processor constructor.
|
||||||
Params struct {
|
Params struct {
|
||||||
Log *zap.Logger
|
Log *zap.Logger
|
||||||
NeoFSContract util.Uint160
|
NeoFSContract util.Uint160
|
||||||
NetmapContract util.Uint160
|
|
||||||
|
|
||||||
AlphabetState AlphabetState
|
AlphabetState AlphabetState
|
||||||
EpochState EpochState
|
EpochState EpochState
|
||||||
|
@ -66,6 +66,7 @@ type (
|
||||||
|
|
||||||
MorphClient *client.Client
|
MorphClient *client.Client
|
||||||
MainnetClient *client.Client
|
MainnetClient *client.Client
|
||||||
|
NetmapClient *nmWrapper.Wrapper
|
||||||
|
|
||||||
NotaryDisabled bool
|
NotaryDisabled bool
|
||||||
FeeProvider *config.FeeConfig
|
FeeProvider *config.FeeConfig
|
||||||
|
@ -100,7 +101,7 @@ func New(p *Params) (*Processor, error) {
|
||||||
log: p.Log,
|
log: p.Log,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
neofsContract: p.NeoFSContract,
|
neofsContract: p.NeoFSContract,
|
||||||
netmapContract: p.NetmapContract,
|
netmapClient: p.NetmapClient,
|
||||||
alphabetState: p.AlphabetState,
|
alphabetState: p.AlphabetState,
|
||||||
epochState: p.EpochState,
|
epochState: p.EpochState,
|
||||||
voter: p.Voter,
|
voter: p.Voter,
|
||||||
|
|
|
@ -9,10 +9,6 @@ import (
|
||||||
const (
|
const (
|
||||||
// lockAccountLifeTime defines amount of epochs when lock account is valid.
|
// lockAccountLifeTime defines amount of epochs when lock account is valid.
|
||||||
lockAccountLifetime uint64 = 20
|
lockAccountLifetime uint64 = 20
|
||||||
|
|
||||||
burnMethod = "burn"
|
|
||||||
lockMethod = "lock"
|
|
||||||
mintMethod = "mint"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Process deposit event by invoking balance contract and sending native
|
// Process deposit event by invoking balance contract and sending native
|
||||||
|
@ -24,8 +20,8 @@ func (np *Processor) processDeposit(deposit *neofsEvent.Deposit) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// send transferX to balance contract
|
// send transferX to balance contract
|
||||||
err := np.morphClient.NotaryInvoke(np.balanceContract, np.feeProvider.SideChainFee(), mintMethod,
|
err := np.balanceClient.Mint(
|
||||||
deposit.To().BytesBE(),
|
deposit.To(),
|
||||||
np.converter.ToBalancePrecision(deposit.Amount()),
|
np.converter.ToBalancePrecision(deposit.Amount()),
|
||||||
deposit.ID())
|
deposit.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -95,7 +91,7 @@ func (np *Processor) processWithdraw(withdraw *neofsEvent.Withdraw) {
|
||||||
|
|
||||||
curEpoch := np.epochState.EpochCounter()
|
curEpoch := np.epochState.EpochCounter()
|
||||||
|
|
||||||
err = np.morphClient.NotaryInvoke(np.balanceContract, np.feeProvider.SideChainFee(), lockMethod,
|
err = np.balanceClient.Lock(
|
||||||
withdraw.ID(),
|
withdraw.ID(),
|
||||||
withdraw.User(),
|
withdraw.User(),
|
||||||
lock,
|
lock,
|
||||||
|
@ -114,8 +110,8 @@ func (np *Processor) processCheque(cheque *neofsEvent.Cheque) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := np.morphClient.NotaryInvoke(np.balanceContract, np.feeProvider.SideChainFee(), burnMethod,
|
err := np.balanceClient.Burn(
|
||||||
cheque.LockAccount().BytesBE(),
|
cheque.LockAccount(),
|
||||||
np.converter.ToBalancePrecision(cheque.Amount()),
|
np.converter.ToBalancePrecision(cheque.Amount()),
|
||||||
cheque.ID())
|
cheque.ID())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const setConfigMethod = "setConfig"
|
|
||||||
|
|
||||||
// Process config event by setting configuration value from main chain in
|
// Process config event by setting configuration value from main chain in
|
||||||
// side chain.
|
// side chain.
|
||||||
func (np *Processor) processConfig(config *neofsEvent.Config) {
|
func (np *Processor) processConfig(config *neofsEvent.Config) {
|
||||||
|
@ -15,8 +13,7 @@ func (np *Processor) processConfig(config *neofsEvent.Config) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := np.morphClient.NotaryInvoke(np.netmapContract, np.feeProvider.SideChainFee(), setConfigMethod,
|
err := np.netmapClient.SetConfig(config.ID(), config.Key(), config.Value())
|
||||||
config.ID(), config.Key(), config.Value())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Error("can't relay set config event", zap.Error(err))
|
np.log.Error("can't relay set config event", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
|
"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/client"
|
||||||
|
balanceWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/balance/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"
|
||||||
|
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
|
neofsEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/neofs"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
|
@ -38,9 +40,9 @@ type (
|
||||||
log *zap.Logger
|
log *zap.Logger
|
||||||
pool *ants.Pool
|
pool *ants.Pool
|
||||||
neofsContract util.Uint160
|
neofsContract util.Uint160
|
||||||
balanceContract util.Uint160
|
|
||||||
netmapContract util.Uint160
|
|
||||||
neofsIDContract util.Uint160
|
neofsIDContract util.Uint160
|
||||||
|
balanceClient *balanceWrapper.Wrapper
|
||||||
|
netmapClient *nmWrapper.Wrapper
|
||||||
morphClient *client.Client
|
morphClient *client.Client
|
||||||
epochState EpochState
|
epochState EpochState
|
||||||
alphabetState AlphabetState
|
alphabetState AlphabetState
|
||||||
|
@ -60,9 +62,9 @@ type (
|
||||||
Log *zap.Logger
|
Log *zap.Logger
|
||||||
PoolSize int
|
PoolSize int
|
||||||
NeoFSContract util.Uint160
|
NeoFSContract util.Uint160
|
||||||
BalanceContract util.Uint160
|
NeoFSIDClient *neofsid.ClientWrapper
|
||||||
NetmapContract util.Uint160
|
BalanceClient *balanceWrapper.Wrapper
|
||||||
NeoFSIDContract util.Uint160
|
NetmapClient *nmWrapper.Wrapper
|
||||||
MorphClient *client.Client
|
MorphClient *client.Client
|
||||||
EpochState EpochState
|
EpochState EpochState
|
||||||
AlphabetState AlphabetState
|
AlphabetState AlphabetState
|
||||||
|
@ -113,17 +115,12 @@ func New(p *Params) (*Processor, error) {
|
||||||
return nil, fmt.Errorf("ir/neofs: can't create LRU cache for gas emission: %w", err)
|
return nil, fmt.Errorf("ir/neofs: can't create LRU cache for gas emission: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
clientWrapper, err := neofsid.NewFromMorph(p.MorphClient, p.NeoFSIDContract, p.FeeProvider.SideChainFee())
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("could not create NeoFS ID client wrapper: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Processor{
|
return &Processor{
|
||||||
log: p.Log,
|
log: p.Log,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
neofsContract: p.NeoFSContract,
|
neofsContract: p.NeoFSContract,
|
||||||
balanceContract: p.BalanceContract,
|
balanceClient: p.BalanceClient,
|
||||||
netmapContract: p.NetmapContract,
|
netmapClient: p.NetmapClient,
|
||||||
morphClient: p.MorphClient,
|
morphClient: p.MorphClient,
|
||||||
epochState: p.EpochState,
|
epochState: p.EpochState,
|
||||||
alphabetState: p.AlphabetState,
|
alphabetState: p.AlphabetState,
|
||||||
|
@ -135,7 +132,7 @@ func New(p *Params) (*Processor, error) {
|
||||||
mintEmitValue: p.MintEmitValue,
|
mintEmitValue: p.MintEmitValue,
|
||||||
gasBalanceThreshold: p.GasBalanceThreshold,
|
gasBalanceThreshold: p.GasBalanceThreshold,
|
||||||
|
|
||||||
neofsIDClient: clientWrapper,
|
neofsIDClient: p.NeoFSIDClient,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const updatePeerStateMethod = "updateState"
|
|
||||||
|
|
||||||
func (np *Processor) processNetmapCleanupTick(epoch uint64) {
|
func (np *Processor) processNetmapCleanupTick(epoch uint64) {
|
||||||
if !np.alphabetState.IsAlphabet() {
|
if !np.alphabetState.IsAlphabet() {
|
||||||
np.log.Info("non alphabet mode, ignore new netmap cleanup tick")
|
np.log.Info("non alphabet mode, ignore new netmap cleanup tick")
|
||||||
|
@ -26,9 +24,7 @@ func (np *Processor) processNetmapCleanupTick(epoch uint64) {
|
||||||
|
|
||||||
np.log.Info("vote to remove node from netmap", zap.String("key", s))
|
np.log.Info("vote to remove node from netmap", zap.String("key", s))
|
||||||
|
|
||||||
err = np.morphClient.NotaryInvoke(np.netmapContract, np.feeProvider.SideChainFee(), updatePeerStateMethod,
|
err = np.netmapClient.UpdatePeerState(key.Bytes(), netmap.NodeStateOffline)
|
||||||
int64(netmap.NodeStateOffline.ToV2()),
|
|
||||||
key.Bytes())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Error("can't invoke netmap.UpdateState", zap.Error(err))
|
np.log.Error("can't invoke netmap.UpdateState", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,10 @@ package netmap
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/audit"
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/audit"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/governance"
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/governance"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap/snapshot"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement"
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/settlement"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const setNewEpochMethod = "newEpoch"
|
|
||||||
|
|
||||||
// Process new epoch notification by setting global epoch value and resetting
|
// Process new epoch notification by setting global epoch value and resetting
|
||||||
// local epoch timer.
|
// local epoch timer.
|
||||||
func (np *Processor) processNewEpoch(epoch uint64) {
|
func (np *Processor) processNewEpoch(epoch uint64) {
|
||||||
|
@ -20,7 +17,7 @@ func (np *Processor) processNewEpoch(epoch uint64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get new netmap snapshot
|
// get new netmap snapshot
|
||||||
networkMap, err := snapshot.Fetch(np.morphClient, np.netmapContract)
|
networkMap, err := np.netmapClient.Snapshot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Warn("can't get netmap snapshot to perform cleanup",
|
np.log.Warn("can't get netmap snapshot to perform cleanup",
|
||||||
zap.String("error", err.Error()))
|
zap.String("error", err.Error()))
|
||||||
|
@ -55,7 +52,7 @@ func (np *Processor) processNewEpochTick() {
|
||||||
nextEpoch := np.epochState.EpochCounter() + 1
|
nextEpoch := np.epochState.EpochCounter() + 1
|
||||||
np.log.Debug("next epoch", zap.Uint64("value", nextEpoch))
|
np.log.Debug("next epoch", zap.Uint64("value", nextEpoch))
|
||||||
|
|
||||||
err := np.morphClient.NotaryInvoke(np.netmapContract, np.feeProvider.SideChainFee(), setNewEpochMethod, int64(nextEpoch))
|
err := np.netmapClient.NewEpoch(nextEpoch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Error("can't invoke netmap.NewEpoch", zap.Error(err))
|
np.log.Error("can't invoke netmap.NewEpoch", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,6 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const approvePeerMethod = "addPeer"
|
|
||||||
|
|
||||||
// Process add peer notification by sanity check of new node
|
// Process add peer notification by sanity check of new node
|
||||||
// local epoch timer.
|
// local epoch timer.
|
||||||
func (np *Processor) processAddPeer(node []byte) {
|
func (np *Processor) processAddPeer(node []byte) {
|
||||||
|
@ -52,14 +50,6 @@ func (np *Processor) processAddPeer(node []byte) {
|
||||||
})
|
})
|
||||||
nodeInfo.SetAttributes(a...)
|
nodeInfo.SetAttributes(a...)
|
||||||
|
|
||||||
// marshal node info back to binary
|
|
||||||
node, err = nodeInfo.Marshal()
|
|
||||||
if err != nil {
|
|
||||||
np.log.Warn("can't marshal approved network map candidate",
|
|
||||||
zap.String("error", err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
keyString := hex.EncodeToString(nodeInfo.PublicKey())
|
keyString := hex.EncodeToString(nodeInfo.PublicKey())
|
||||||
|
|
||||||
exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter())
|
exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter())
|
||||||
|
@ -67,7 +57,7 @@ func (np *Processor) processAddPeer(node []byte) {
|
||||||
np.log.Info("approving network map candidate",
|
np.log.Info("approving network map candidate",
|
||||||
zap.String("key", keyString))
|
zap.String("key", keyString))
|
||||||
|
|
||||||
err := np.morphClient.NotaryInvoke(np.netmapContract, np.feeProvider.SideChainFee(), approvePeerMethod, node)
|
err := np.netmapClient.AddPeer(nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Error("can't invoke netmap.AddPeer", zap.Error(err))
|
np.log.Error("can't invoke netmap.AddPeer", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
@ -94,9 +84,7 @@ func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) {
|
||||||
// again before new epoch will tick
|
// again before new epoch will tick
|
||||||
np.netmapSnapshot.flag(hex.EncodeToString(ev.PublicKey().Bytes()))
|
np.netmapSnapshot.flag(hex.EncodeToString(ev.PublicKey().Bytes()))
|
||||||
|
|
||||||
err := np.morphClient.NotaryInvoke(np.netmapContract, np.feeProvider.SideChainFee(), updatePeerStateMethod,
|
err := np.netmapClient.UpdatePeerState(ev.PublicKey().Bytes(), ev.Status())
|
||||||
int64(ev.Status().ToV2()),
|
|
||||||
ev.PublicKey().Bytes())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
np.log.Error("can't invoke netmap.UpdatePeer", zap.Error(err))
|
np.log.Error("can't invoke netmap.UpdatePeer", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"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"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
|
"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"
|
container "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper"
|
||||||
|
nmWrapper "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap/wrapper"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
|
||||||
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
|
||||||
"github.com/panjf2000/ants/v2"
|
"github.com/panjf2000/ants/v2"
|
||||||
|
@ -57,7 +57,7 @@ type (
|
||||||
epochState EpochState
|
epochState EpochState
|
||||||
alphabetState AlphabetState
|
alphabetState AlphabetState
|
||||||
|
|
||||||
morphClient *client.Client
|
netmapClient *nmWrapper.Wrapper
|
||||||
containerWrp *container.Wrapper
|
containerWrp *container.Wrapper
|
||||||
|
|
||||||
netmapSnapshot cleanupTable
|
netmapSnapshot cleanupTable
|
||||||
|
@ -73,11 +73,12 @@ 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
|
NetmapContract util.Uint160
|
||||||
|
NetmapClient *nmWrapper.Wrapper
|
||||||
EpochTimer EpochTimerReseter
|
EpochTimer EpochTimerReseter
|
||||||
MorphClient *client.Client
|
|
||||||
EpochState EpochState
|
EpochState EpochState
|
||||||
AlphabetState AlphabetState
|
AlphabetState AlphabetState
|
||||||
CleanupEnabled bool
|
CleanupEnabled bool
|
||||||
|
@ -105,8 +106,6 @@ func New(p *Params) (*Processor, error) {
|
||||||
switch {
|
switch {
|
||||||
case p.Log == nil:
|
case p.Log == nil:
|
||||||
return nil, errors.New("ir/netmap: logger is not set")
|
return nil, errors.New("ir/netmap: logger is not set")
|
||||||
case p.MorphClient == nil:
|
|
||||||
return nil, errors.New("ir/netmap: morph client is not set")
|
|
||||||
case p.EpochTimer == nil:
|
case p.EpochTimer == nil:
|
||||||
return nil, errors.New("ir/netmap: epoch itmer is not set")
|
return nil, errors.New("ir/netmap: epoch itmer is not set")
|
||||||
case p.EpochState == nil:
|
case p.EpochState == nil:
|
||||||
|
@ -141,7 +140,7 @@ func New(p *Params) (*Processor, error) {
|
||||||
epochTimer: p.EpochTimer,
|
epochTimer: p.EpochTimer,
|
||||||
epochState: p.EpochState,
|
epochState: p.EpochState,
|
||||||
alphabetState: p.AlphabetState,
|
alphabetState: p.AlphabetState,
|
||||||
morphClient: p.MorphClient,
|
netmapClient: p.NetmapClient,
|
||||||
containerWrp: p.ContainerWrapper,
|
containerWrp: p.ContainerWrapper,
|
||||||
netmapSnapshot: newCleanupTable(p.CleanupEnabled, p.CleanupThreshold),
|
netmapSnapshot: newCleanupTable(p.CleanupEnabled, p.CleanupThreshold),
|
||||||
handleNewAudit: p.HandleAudit,
|
handleNewAudit: p.HandleAudit,
|
||||||
|
|
|
@ -1,61 +0,0 @@
|
||||||
package snapshot
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
|
||||||
)
|
|
||||||
|
|
||||||
const getNetmapSnapshotMethod = "netmap"
|
|
||||||
|
|
||||||
// Fetch returns current netmap node infos.
|
|
||||||
// Consider using pkg/morph/client/netmap for this.
|
|
||||||
func Fetch(cli *client.Client, contract util.Uint160) (*netmap.Netmap, error) {
|
|
||||||
rawNetmapStack, err := cli.TestInvoke(contract, getNetmapSnapshotMethod)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if ln := len(rawNetmapStack); ln != 1 {
|
|
||||||
return nil, errors.New("invalid RPC response")
|
|
||||||
}
|
|
||||||
|
|
||||||
rawNodeInfos, err := client.ArrayFromStackItem(rawNetmapStack[0])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := make([]netmap.NodeInfo, 0, len(rawNodeInfos))
|
|
||||||
|
|
||||||
for i := range rawNodeInfos {
|
|
||||||
nodeInfo, err := peerInfoFromStackItem(rawNodeInfos[i])
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid RPC response: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
result = append(result, *nodeInfo)
|
|
||||||
}
|
|
||||||
|
|
||||||
return netmap.NewNetmap(netmap.NodesFromInfo(result))
|
|
||||||
}
|
|
||||||
|
|
||||||
func peerInfoFromStackItem(prm stackitem.Item) (*netmap.NodeInfo, error) {
|
|
||||||
node := netmap.NewNodeInfo()
|
|
||||||
|
|
||||||
subItems, err := client.ArrayFromStackItem(prm)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if ln := len(subItems); ln != 1 {
|
|
||||||
return nil, errors.New("invalid RPC response")
|
|
||||||
} else if rawNodeInfo, err := client.BytesFromStackItem(subItems[0]); err != nil {
|
|
||||||
return nil, err
|
|
||||||
} else if err = node.Unmarshal(rawNodeInfo); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return node, nil
|
|
||||||
}
|
|
|
@ -29,12 +29,18 @@ type Option func(*cfg)
|
||||||
|
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
transferXMethod, // transferX method name for invocation
|
transferXMethod, // transferX method name for invocation
|
||||||
|
mintMethod,
|
||||||
|
burnMethod,
|
||||||
|
lockMethod,
|
||||||
balanceOfMethod, // balanceOf method name for invocation
|
balanceOfMethod, // balanceOf method name for invocation
|
||||||
decimalsMethod string // decimals method name for invocation
|
decimalsMethod string // decimals method name for invocation
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultTransferXMethod = "transferX" // default "transferX" method name
|
defaultTransferXMethod = "transferX" // default "transferX" method name
|
||||||
|
defaultMintMethod = "mint" // default "mint" method name
|
||||||
|
defaultBurnMethod = "burn" // default "burn" method name
|
||||||
|
defaultLockMethod = "lock" // default "lock" method name
|
||||||
defaultBalanceOfMethod = "balanceOf" // default "balance of" method name
|
defaultBalanceOfMethod = "balanceOf" // default "balance of" method name
|
||||||
defaultDecimalsMethod = "decimals" // default decimals method name
|
defaultDecimalsMethod = "decimals" // default decimals method name
|
||||||
)
|
)
|
||||||
|
@ -42,6 +48,9 @@ const (
|
||||||
func defaultConfig() *cfg {
|
func defaultConfig() *cfg {
|
||||||
return &cfg{
|
return &cfg{
|
||||||
transferXMethod: defaultTransferXMethod,
|
transferXMethod: defaultTransferXMethod,
|
||||||
|
mintMethod: defaultMintMethod,
|
||||||
|
burnMethod: defaultBurnMethod,
|
||||||
|
lockMethod: defaultLockMethod,
|
||||||
balanceOfMethod: defaultBalanceOfMethod,
|
balanceOfMethod: defaultBalanceOfMethod,
|
||||||
decimalsMethod: defaultDecimalsMethod,
|
decimalsMethod: defaultDecimalsMethod,
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,3 +56,18 @@ func (c *Client) TransferX(args TransferXArgs) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mint invokes `mint` method of the balance contract.
|
||||||
|
func (c *Client) Mint(to []byte, amount int64, id []byte) error {
|
||||||
|
return c.client.Invoke(c.mintMethod, to, amount, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Burn invokes `burn` method of the balance contract.
|
||||||
|
func (c *Client) Burn(to []byte, amount int64, id []byte) error {
|
||||||
|
return c.client.Invoke(c.burnMethod, to, amount, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock invokes `lock` method of the balance contract.
|
||||||
|
func (c *Client) Lock(id, user, lock []byte, amount, dueEpoch int64) error {
|
||||||
|
return c.client.Invoke(c.lockMethod, id, user, lock, amount, dueEpoch)
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package wrapper
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
"github.com/nspcc-dev/neofs-api-go/pkg/owner"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
|
||||||
)
|
)
|
||||||
|
@ -40,3 +41,18 @@ func (w *Wrapper) TransferX(p TransferPrm) error {
|
||||||
|
|
||||||
return w.client.TransferX(args)
|
return w.client.TransferX(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mint sends funds to the account.
|
||||||
|
func (w *Wrapper) Mint(to util.Uint160, amount int64, id []byte) error {
|
||||||
|
return w.client.Mint(to.BytesBE(), amount, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Burn destroys funds from the account.
|
||||||
|
func (w *Wrapper) Burn(to util.Uint160, amount int64, id []byte) error {
|
||||||
|
return w.client.Burn(to.BytesBE(), amount, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock locks fund on the user account.
|
||||||
|
func (w *Wrapper) Lock(id []byte, user, lock util.Uint160, amount, dueEpoch int64) error {
|
||||||
|
return w.client.Lock(id, user.BytesBE(), lock.BytesBE(), amount, dueEpoch)
|
||||||
|
}
|
||||||
|
|
|
@ -38,17 +38,21 @@ type cfg struct {
|
||||||
epochSnapshotMethod, // get network map snapshot by epoch method name
|
epochSnapshotMethod, // get network map snapshot by epoch method name
|
||||||
updateStateMethod, // update state method name for invocation
|
updateStateMethod, // update state method name for invocation
|
||||||
epochMethod, // get epoch number method name
|
epochMethod, // get epoch number method name
|
||||||
|
setInnerRing, // set inner ring method name
|
||||||
|
setConfigMethod, // set config method name
|
||||||
configMethod string // get config value method name
|
configMethod string // get config value method name
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultAddPeerMethod = "addPeer" // default add peer method name
|
defaultAddPeerMethod = "addPeer" // default add peer method name
|
||||||
defaultNewEpochMethod = "newEpoch" // default new epoch method name
|
defaultNewEpochMethod = "newEpoch" // default new epoch method name
|
||||||
defaultNetMapMethod = "netmap" // default get network map method name
|
defaultNetMapMethod = "netmap" // default get network map method name
|
||||||
defaultSnapshotMethod = "snapshot" // default get network map snapshot method name
|
defaultSnapshotMethod = "snapshot" // default get network map snapshot method name
|
||||||
defaultUpdateStateMethod = "updateState" // default update state method name
|
defaultUpdateStateMethod = "updateState" // default update state method name
|
||||||
defaultEpochMethod = "epoch" // default get epoch number method name
|
defaultEpochMethod = "epoch" // default get epoch number method name
|
||||||
defaultConfigMethod = "config" // default get config value method name
|
defaultSetInnerRingMethod = "updateInnerRing" // default set innerring method name
|
||||||
|
defaultSetConfigMethod = "setConfig" // default get config value method name
|
||||||
|
defaultConfigMethod = "config" // default get config value method name
|
||||||
|
|
||||||
defaultEpochSnapshotMethod = "snapshotByEpoch" // default get network map snapshot by epoch method name
|
defaultEpochSnapshotMethod = "snapshotByEpoch" // default get network map snapshot by epoch method name
|
||||||
)
|
)
|
||||||
|
@ -62,6 +66,7 @@ func defaultConfig() *cfg {
|
||||||
epochSnapshotMethod: defaultEpochSnapshotMethod,
|
epochSnapshotMethod: defaultEpochSnapshotMethod,
|
||||||
updateStateMethod: defaultUpdateStateMethod,
|
updateStateMethod: defaultUpdateStateMethod,
|
||||||
epochMethod: defaultEpochMethod,
|
epochMethod: defaultEpochMethod,
|
||||||
|
setConfigMethod: defaultSetConfigMethod,
|
||||||
configMethod: defaultConfigMethod,
|
configMethod: defaultConfigMethod,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,11 @@ func (c *Client) Config(args ConfigArgs, assert func(stackitem.Item) (interface{
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetConfig invokes `setConfig` method of NeoFS Netmap contract.
|
||||||
|
func (c *Client) SetConfig(id, key []byte, value interface{}) error {
|
||||||
|
return c.client.Invoke(c.setConfigMethod, id, key, value)
|
||||||
|
}
|
||||||
|
|
||||||
func IntegerAssert(item stackitem.Item) (interface{}, error) {
|
func IntegerAssert(item stackitem.Item) (interface{}, error) {
|
||||||
return client.IntFromStackItem(item)
|
return client.IntFromStackItem(item)
|
||||||
}
|
}
|
||||||
|
|
13
pkg/morph/client/netmap/innerring.go
Normal file
13
pkg/morph/client/netmap/innerring.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package netmap
|
||||||
|
|
||||||
|
import "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
|
||||||
|
// SetInnerRing updates inner ring members in netmap contract.
|
||||||
|
func (c *Client) SetInnerRing(keys keys.PublicKeys) error {
|
||||||
|
args := make([][]byte, len(keys))
|
||||||
|
for i := range args {
|
||||||
|
args[i] = keys[i].Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.client.Invoke(c.setInnerRing, args)
|
||||||
|
}
|
|
@ -154,3 +154,8 @@ func (w *Wrapper) readStringConfig(key string) (string, error) {
|
||||||
|
|
||||||
return str, nil
|
return str, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetConfig sets config field.
|
||||||
|
func (w *Wrapper) SetConfig(id, key []byte, value interface{}) error {
|
||||||
|
return w.client.SetConfig(id, key, value)
|
||||||
|
}
|
||||||
|
|
8
pkg/morph/client/netmap/wrapper/innerring.go
Normal file
8
pkg/morph/client/netmap/wrapper/innerring.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package wrapper
|
||||||
|
|
||||||
|
import "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
|
||||||
|
// SetInnerRing updates inner ring keys.
|
||||||
|
func (w *Wrapper) SetInnerRing(keys keys.PublicKeys) error {
|
||||||
|
return w.client.SetInnerRing(keys)
|
||||||
|
}
|
|
@ -1,11 +1,12 @@
|
||||||
package wrapper
|
package wrapper
|
||||||
|
|
||||||
// Epoch represents the NeoFS epoch.
|
import "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||||
// FIXME: correct the definition.
|
|
||||||
type Epoch struct{}
|
|
||||||
|
|
||||||
// NewEpoch updates NeoFS epoch number through
|
// NewEpoch updates NeoFS epoch number through
|
||||||
// Netmap contract call.
|
// Netmap contract call.
|
||||||
func (w *Wrapper) NewEpoch(e Epoch) error {
|
func (w *Wrapper) NewEpoch(e uint64) error {
|
||||||
panic("implement me")
|
var args netmap.NewEpochArgs
|
||||||
|
args.SetEpochNumber(int64(e))
|
||||||
|
|
||||||
|
return w.client.NewEpoch(args)
|
||||||
}
|
}
|
||||||
|
|
28
pkg/morph/client/netmap/wrapper/snapshot.go
Normal file
28
pkg/morph/client/netmap/wrapper/snapshot.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package wrapper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
|
||||||
|
netmap2 "github.com/nspcc-dev/neofs-node/pkg/morph/client/netmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Fetch returns current netmap node infos.
|
||||||
|
// Consider using pkg/morph/client/netmap for this.
|
||||||
|
func (w *Wrapper) Snapshot() (*netmap.Netmap, error) {
|
||||||
|
res, err := w.client.Snapshot(netmap2.GetSnapshotArgs{})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
peers := res.Peers()
|
||||||
|
result := make([]netmap.NodeInfo, len(peers))
|
||||||
|
|
||||||
|
for i := range peers {
|
||||||
|
if err := result[i].Unmarshal(peers[i]); err != nil {
|
||||||
|
return nil, fmt.Errorf("can't unmarshal node info: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return netmap.NewNetmap(netmap.NodesFromInfo(result))
|
||||||
|
}
|
Loading…
Reference in a new issue