forked from TrueCloudLab/frostfs-node
[#122] Use balance precision converter in inner ring
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
90984ee219
commit
330c4b42d9
1 changed files with 12 additions and 0 deletions
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
"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/subscriber"
|
"github.com/nspcc-dev/neofs-node/pkg/morph/subscriber"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/util/precision"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
|
@ -39,6 +40,7 @@ type (
|
||||||
mainnetClient *client.Client
|
mainnetClient *client.Client
|
||||||
epochCounter atomic.Uint64
|
epochCounter atomic.Uint64
|
||||||
innerRingIndex atomic.Int32
|
innerRingIndex atomic.Int32
|
||||||
|
precision precision.Fixed8Converter
|
||||||
|
|
||||||
// internal variables
|
// internal variables
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
|
@ -213,6 +215,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
BalanceContract: server.contracts.balance,
|
BalanceContract: server.contracts.balance,
|
||||||
MainnetClient: server.mainnetClient,
|
MainnetClient: server.mainnetClient,
|
||||||
ActiveState: server,
|
ActiveState: server,
|
||||||
|
Converter: &server.precision,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -235,6 +238,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
MorphClient: server.morphClient,
|
MorphClient: server.morphClient,
|
||||||
EpochState: server,
|
EpochState: server,
|
||||||
ActiveState: server,
|
ActiveState: server,
|
||||||
|
Converter: &server.precision,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -377,12 +381,20 @@ func (s *Server) initConfigFromBlockchain() error {
|
||||||
return errors.Wrap(err, "can't read inner ring list")
|
return errors.Wrap(err, "can't read inner ring list")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get balance precision
|
||||||
|
balancePrecision, err := invoke.BalancePrecision(s.morphClient, s.contracts.balance)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "can't read balance contract precision")
|
||||||
|
}
|
||||||
|
|
||||||
s.epochCounter.Store(uint64(epoch))
|
s.epochCounter.Store(uint64(epoch))
|
||||||
s.innerRingIndex.Store(index)
|
s.innerRingIndex.Store(index)
|
||||||
|
s.precision.SetBalancePrecision(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.Int64("epoch", epoch),
|
zap.Int64("epoch", epoch),
|
||||||
|
zap.Uint32("precision", balancePrecision),
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue