forked from TrueCloudLab/frostfs-node
[#486] innerring: Add option to disable only main chain notary support
For N3 Testnet RC2 release inner ring app supports three modes: - notary enabled in all chains (default), - notary disabled in all chains, - notary enabled only in side chain. All notary related functions are moved to notary.go Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
94a1947482
commit
dddbf0368c
4 changed files with 149 additions and 83 deletions
|
@ -50,6 +50,7 @@ func defaultConfiguration(cfg *viper.Viper) {
|
||||||
|
|
||||||
cfg.SetDefault("without_mainnet", false)
|
cfg.SetDefault("without_mainnet", false)
|
||||||
cfg.SetDefault("without_notary", false)
|
cfg.SetDefault("without_notary", false)
|
||||||
|
cfg.SetDefault("without_main_notary", false)
|
||||||
|
|
||||||
cfg.SetDefault("morph.endpoint.client", "")
|
cfg.SetDefault("morph.endpoint.client", "")
|
||||||
cfg.SetDefault("morph.endpoint.notification", "")
|
cfg.SetDefault("morph.endpoint.notification", "")
|
||||||
|
@ -75,7 +76,8 @@ func defaultConfiguration(cfg *viper.Viper) {
|
||||||
|
|
||||||
cfg.SetDefault("timers.epoch", "0")
|
cfg.SetDefault("timers.epoch", "0")
|
||||||
cfg.SetDefault("timers.emit", "0")
|
cfg.SetDefault("timers.emit", "0")
|
||||||
cfg.SetDefault("timers.notary", "1000")
|
cfg.SetDefault("timers.main_notary", "1000")
|
||||||
|
cfg.SetDefault("timers.side_notary", "1000")
|
||||||
cfg.SetDefault("timers.stop_estimation.mul", 1)
|
cfg.SetDefault("timers.stop_estimation.mul", 1)
|
||||||
cfg.SetDefault("timers.stop_estimation.div", 1)
|
cfg.SetDefault("timers.stop_estimation.div", 1)
|
||||||
cfg.SetDefault("timers.collect_basic_income.mul", 1)
|
cfg.SetDefault("timers.collect_basic_income.mul", 1)
|
||||||
|
@ -83,7 +85,8 @@ func defaultConfiguration(cfg *viper.Viper) {
|
||||||
cfg.SetDefault("timers.distribute_basic_income.mul", 1)
|
cfg.SetDefault("timers.distribute_basic_income.mul", 1)
|
||||||
cfg.SetDefault("timers.distribute_basic_income.div", 1)
|
cfg.SetDefault("timers.distribute_basic_income.div", 1)
|
||||||
|
|
||||||
cfg.SetDefault("notary.deposit_amount", 1_0000_0000) // 1.0 Fixed8
|
cfg.SetDefault("notary.side.deposit_amount", 1_0000_0000) // 1.0 Fixed8
|
||||||
|
cfg.SetDefault("notary.main.deposit_amount", 2000_0000) // 0.2 Fixed8
|
||||||
|
|
||||||
cfg.SetDefault("workers.netmap", "10")
|
cfg.SetDefault("workers.netmap", "10")
|
||||||
cfg.SetDefault("workers.balance", "10")
|
cfg.SetDefault("workers.balance", "10")
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package innerring
|
package innerring
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/alphabet"
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/alphabet"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap"
|
"github.com/nspcc-dev/neofs-node/pkg/innerring/processors/netmap"
|
||||||
|
@ -47,10 +49,13 @@ type (
|
||||||
emitDuration uint32 // in blocks
|
emitDuration uint32 // in blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
depositor func() (util.Uint256, error)
|
||||||
|
awaiter func(context.Context, util.Uint256) error
|
||||||
|
|
||||||
notaryDepositArgs struct {
|
notaryDepositArgs struct {
|
||||||
l *zap.Logger
|
l *zap.Logger
|
||||||
|
|
||||||
depositor func() (util.Uint256, util.Uint256, error)
|
depositor depositor
|
||||||
|
|
||||||
notaryDuration uint32 // in blocks
|
notaryDuration uint32 // in blocks
|
||||||
}
|
}
|
||||||
|
@ -154,7 +159,7 @@ func newNotaryDepositTimer(args *notaryDepositArgs) *timer.BlockTimer {
|
||||||
return timer.NewBlockTimer(
|
return timer.NewBlockTimer(
|
||||||
timer.StaticBlockMeter(args.notaryDuration),
|
timer.StaticBlockMeter(args.notaryDuration),
|
||||||
func() {
|
func() {
|
||||||
_, _, err := args.depositor()
|
_, err := args.depositor()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
args.l.Warn("can't deposit notary contract",
|
args.l.Warn("can't deposit notary contract",
|
||||||
zap.String("error", err.Error()))
|
zap.String("error", err.Error()))
|
||||||
|
|
|
@ -57,10 +57,10 @@ type (
|
||||||
precision precision.Fixed8Converter
|
precision precision.Fixed8Converter
|
||||||
auditClient *auditWrapper.ClientWrapper
|
auditClient *auditWrapper.ClientWrapper
|
||||||
|
|
||||||
notaryDisabled bool
|
// notary configuration
|
||||||
feeConfig *config.FeeConfig
|
feeConfig *config.FeeConfig
|
||||||
notaryDepositAmount fixedn.Fixed8
|
mainNotaryConfig *notaryConfig
|
||||||
notaryDuration uint32
|
sideNotaryConfig *notaryConfig
|
||||||
|
|
||||||
// internal variables
|
// internal variables
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
|
@ -140,17 +140,23 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.notaryDisabled {
|
if !s.mainNotaryConfig.disabled {
|
||||||
// make an initial deposit to notary contract to enable it
|
err = s.initNotary(ctx,
|
||||||
mainTx, sideTx, err := s.depositNotary()
|
s.depositMainNotary,
|
||||||
|
s.awaitMainNotaryDeposit,
|
||||||
|
"waiting to accept main notary deposit",
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// wait a bit for notary contract deposit
|
if !s.sideNotaryConfig.disabled {
|
||||||
s.log.Info("waiting to accept notary deposit")
|
err = s.initNotary(ctx,
|
||||||
|
s.depositSideNotary,
|
||||||
err = s.awaitNotaryDeposit(ctx, mainTx, sideTx)
|
s.awaitSideNotaryDeposit,
|
||||||
|
"waiting to accept side notary deposit",
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -237,10 +243,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
server := &Server{log: log}
|
server := &Server{log: log}
|
||||||
|
|
||||||
// parse notary support
|
// parse notary support
|
||||||
server.notaryDisabled = cfg.GetBool("without_notary")
|
|
||||||
if server.notaryDisabled {
|
|
||||||
server.feeConfig = config.NewFeeConfig(cfg)
|
server.feeConfig = config.NewFeeConfig(cfg)
|
||||||
}
|
server.mainNotaryConfig, server.sideNotaryConfig = parseNotaryConfigs(cfg)
|
||||||
|
|
||||||
// prepare inner ring node private key
|
// prepare inner ring node private key
|
||||||
server.key, err = crypto.LoadPrivateKey(cfg.GetString("key"))
|
server.key, err = crypto.LoadPrivateKey(cfg.GetString("key"))
|
||||||
|
@ -280,7 +284,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable notary support in the client
|
// enable notary support in the client
|
||||||
if !server.notaryDisabled {
|
if !server.sideNotaryConfig.disabled {
|
||||||
err = server.morphClient.EnableNotarySupport(server.contracts.proxy)
|
err = server.morphClient.EnableNotarySupport(server.contracts.proxy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -312,7 +316,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable notary support in the client
|
// enable notary support in the client
|
||||||
if !server.notaryDisabled {
|
if !server.mainNotaryConfig.disabled {
|
||||||
err = server.mainnetClient.EnableNotarySupport(
|
err = server.mainnetClient.EnableNotarySupport(
|
||||||
server.contracts.processing,
|
server.contracts.processing,
|
||||||
client.WithAlphabetSource(server.morphClient.Committee),
|
client.WithAlphabetSource(server.morphClient.Committee),
|
||||||
|
@ -420,7 +424,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
nmSrc: nmClient,
|
nmSrc: nmClient,
|
||||||
clientCache: clientCache,
|
clientCache: clientCache,
|
||||||
balanceClient: balClient,
|
balanceClient: balClient,
|
||||||
notaryDisabled: server.notaryDisabled,
|
notaryDisabled: server.sideNotaryConfig.disabled,
|
||||||
}
|
}
|
||||||
|
|
||||||
auditCalcDeps := &auditSettlementDeps{
|
auditCalcDeps := &auditSettlementDeps{
|
||||||
|
@ -470,7 +474,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
Voter: server,
|
Voter: server,
|
||||||
MorphClient: server.morphClient,
|
MorphClient: server.morphClient,
|
||||||
MainnetClient: server.mainnetClient,
|
MainnetClient: server.mainnetClient,
|
||||||
NotaryDisabled: server.notaryDisabled,
|
NotaryDisabled: server.sideNotaryConfig.disabled,
|
||||||
FeeProvider: server.feeConfig,
|
FeeProvider: server.feeConfig,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -507,7 +511,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
),
|
),
|
||||||
AlphabetSyncHandler: alphaSync,
|
AlphabetSyncHandler: alphaSync,
|
||||||
NodeValidator: locodeValidator,
|
NodeValidator: locodeValidator,
|
||||||
NotaryDisabled: server.notaryDisabled,
|
NotaryDisabled: server.sideNotaryConfig.disabled,
|
||||||
FeeProvider: server.feeConfig,
|
FeeProvider: server.feeConfig,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -608,7 +612,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
reputationProcessor, err := reputation.New(&reputation.Params{
|
reputationProcessor, err := reputation.New(&reputation.Params{
|
||||||
Log: log,
|
Log: log,
|
||||||
PoolSize: cfg.GetInt("workers.reputation"),
|
PoolSize: cfg.GetInt("workers.reputation"),
|
||||||
NotaryDisabled: server.notaryDisabled,
|
NotaryDisabled: server.sideNotaryConfig.disabled,
|
||||||
ReputationContract: server.contracts.reputation,
|
ReputationContract: server.contracts.reputation,
|
||||||
EpochState: server,
|
EpochState: server,
|
||||||
AlphabetState: server,
|
AlphabetState: server,
|
||||||
|
@ -628,7 +632,7 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
// initialize epoch timers
|
// initialize epoch timers
|
||||||
server.epochTimer = newEpochTimer(&epochTimerArgs{
|
server.epochTimer = newEpochTimer(&epochTimerArgs{
|
||||||
l: server.log,
|
l: server.log,
|
||||||
notaryDisabled: server.notaryDisabled,
|
notaryDisabled: server.sideNotaryConfig.disabled,
|
||||||
nm: netmapProcessor,
|
nm: netmapProcessor,
|
||||||
cnrWrapper: cnrClient,
|
cnrWrapper: cnrClient,
|
||||||
epoch: server,
|
epoch: server,
|
||||||
|
@ -657,18 +661,25 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
|
|
||||||
server.addBlockTimer(emissionTimer)
|
server.addBlockTimer(emissionTimer)
|
||||||
|
|
||||||
if !server.notaryDisabled {
|
// initialize notary timers
|
||||||
// initialize notary deposit timer
|
if !server.mainNotaryConfig.disabled {
|
||||||
server.notaryDepositAmount = fixedn.Fixed8(cfg.GetInt64("notary.deposit_amount"))
|
mainNotaryTimer := newNotaryDepositTimer(¬aryDepositArgs{
|
||||||
server.notaryDuration = cfg.GetUint32("timers.notary")
|
|
||||||
|
|
||||||
notaryTimer := newNotaryDepositTimer(¬aryDepositArgs{
|
|
||||||
l: log,
|
l: log,
|
||||||
depositor: server.depositNotary,
|
depositor: server.depositMainNotary,
|
||||||
notaryDuration: server.notaryDuration,
|
notaryDuration: server.mainNotaryConfig.duration,
|
||||||
})
|
})
|
||||||
|
|
||||||
server.addBlockTimer(notaryTimer)
|
server.addBlockTimer(mainNotaryTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !server.sideNotaryConfig.disabled {
|
||||||
|
sideNotaryTimer := newNotaryDepositTimer(¬aryDepositArgs{
|
||||||
|
l: log,
|
||||||
|
depositor: server.depositSideNotary,
|
||||||
|
notaryDuration: server.sideNotaryConfig.duration,
|
||||||
|
})
|
||||||
|
|
||||||
|
server.addBlockTimer(sideNotaryTimer)
|
||||||
}
|
}
|
||||||
|
|
||||||
return server, nil
|
return server, nil
|
||||||
|
@ -858,51 +869,3 @@ func (s *Server) onlyAlphabetEventHandler(f event.Handler) event.Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) depositNotary() (mainTx, sideTx util.Uint256, err error) {
|
|
||||||
mainTx, err = s.mainnetClient.DepositNotary(
|
|
||||||
s.notaryDepositAmount,
|
|
||||||
s.notaryDuration+notaryExtraBlocks,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
sideTx, err = s.morphClient.DepositNotary(
|
|
||||||
s.notaryDepositAmount,
|
|
||||||
s.notaryDuration+notaryExtraBlocks,
|
|
||||||
)
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) awaitNotaryDeposit(ctx context.Context, mainTx, sideTx util.Uint256) error {
|
|
||||||
err := awaitNotaryDepositInClient(ctx, s.mainnetClient, mainTx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return awaitNotaryDepositInClient(ctx, s.morphClient, sideTx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func awaitNotaryDepositInClient(ctx context.Context, cli *client.Client, txHash util.Uint256) error {
|
|
||||||
for i := 0; i < notaryDepositTimeout; i++ {
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
ok, err := cli.TxHalt(txHash)
|
|
||||||
if err == nil {
|
|
||||||
if ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return errDepositFail
|
|
||||||
}
|
|
||||||
|
|
||||||
cli.Wait(ctx, 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return errDepositTimeout
|
|
||||||
}
|
|
||||||
|
|
95
pkg/innerring/notary.go
Normal file
95
pkg/innerring/notary.go
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
package innerring
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
notaryConfig struct {
|
||||||
|
amount fixedn.Fixed8 // amount of deposited GAS to notary contract
|
||||||
|
duration uint32 // lifetime of notary deposit in blocks
|
||||||
|
disabled bool // true if notary disabled on chain
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) depositMainNotary() (tx util.Uint256, err error) {
|
||||||
|
return s.mainnetClient.DepositNotary(
|
||||||
|
s.mainNotaryConfig.amount,
|
||||||
|
s.mainNotaryConfig.duration+notaryExtraBlocks,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) depositSideNotary() (tx util.Uint256, err error) {
|
||||||
|
return s.morphClient.DepositNotary(
|
||||||
|
s.sideNotaryConfig.amount,
|
||||||
|
s.sideNotaryConfig.duration+notaryExtraBlocks,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) awaitMainNotaryDeposit(ctx context.Context, tx util.Uint256) error {
|
||||||
|
return awaitNotaryDepositInClient(ctx, s.mainnetClient, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) awaitSideNotaryDeposit(ctx context.Context, tx util.Uint256) error {
|
||||||
|
return awaitNotaryDepositInClient(ctx, s.morphClient, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) initNotary(ctx context.Context, deposit depositor, await awaiter, msg string) error {
|
||||||
|
tx, err := deposit()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.log.Info(msg)
|
||||||
|
|
||||||
|
return await(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func awaitNotaryDepositInClient(ctx context.Context, cli *client.Client, txHash util.Uint256) error {
|
||||||
|
for i := 0; i < notaryDepositTimeout; i++ {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := cli.TxHalt(txHash)
|
||||||
|
if err == nil {
|
||||||
|
if ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return errDepositFail
|
||||||
|
}
|
||||||
|
|
||||||
|
cli.Wait(ctx, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return errDepositTimeout
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseNotaryConfigs(cfg *viper.Viper) (main, side *notaryConfig) {
|
||||||
|
main = new(notaryConfig)
|
||||||
|
side = new(notaryConfig)
|
||||||
|
|
||||||
|
if cfg.GetBool("without_notary") {
|
||||||
|
main.disabled = true
|
||||||
|
side.disabled = true
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
main.disabled = cfg.GetBool("without_main_notary")
|
||||||
|
main.amount = fixedn.Fixed8(cfg.GetInt64("notary.main.deposit_amount"))
|
||||||
|
main.duration = cfg.GetUint32("timers.main_notary")
|
||||||
|
|
||||||
|
side.amount = fixedn.Fixed8(cfg.GetInt64("notary.side.deposit_amount"))
|
||||||
|
side.duration = cfg.GetUint32("timers.side_notary")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
Loading…
Reference in a new issue