forked from TrueCloudLab/frostfs-node
[#404] innerring: Make notary deposit periodically
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
ccaf4f5d55
commit
71dce97b76
3 changed files with 56 additions and 0 deletions
|
@ -71,6 +71,7 @@ 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.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)
|
||||||
|
@ -78,6 +79,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("workers.netmap", "10")
|
cfg.SetDefault("workers.netmap", "10")
|
||||||
cfg.SetDefault("workers.balance", "10")
|
cfg.SetDefault("workers.balance", "10")
|
||||||
cfg.SetDefault("workers.neofs", "10")
|
cfg.SetDefault("workers.neofs", "10")
|
||||||
|
|
|
@ -42,6 +42,14 @@ type (
|
||||||
|
|
||||||
emitDuration uint32 // in blocks
|
emitDuration uint32 // in blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notaryDepositArgs struct {
|
||||||
|
l *zap.Logger
|
||||||
|
|
||||||
|
depositor func() error
|
||||||
|
|
||||||
|
notaryDuration uint32 // in blocks
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) addBlockTimer(t *timers.BlockTimer) {
|
func (s *Server) addBlockTimer(t *timers.BlockTimer) {
|
||||||
|
@ -130,3 +138,16 @@ func newEmissionTimer(args *emitTimerArgs) *timers.BlockTimer {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newNotaryDepositTimer(args *notaryDepositArgs) *timers.BlockTimer {
|
||||||
|
return timers.NewBlockTimer(
|
||||||
|
timers.StaticBlockMeter(args.notaryDuration),
|
||||||
|
func() {
|
||||||
|
err := args.depositor()
|
||||||
|
if err != nil {
|
||||||
|
args.l.Warn("can't deposit notary contract",
|
||||||
|
zap.String("error", err.Error()))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -56,6 +56,9 @@ type (
|
||||||
precision precision.Fixed8Converter
|
precision precision.Fixed8Converter
|
||||||
auditClient *auditWrapper.ClientWrapper
|
auditClient *auditWrapper.ClientWrapper
|
||||||
|
|
||||||
|
notaryDepositAmount fixedn.Fixed8
|
||||||
|
notaryDuration uint32
|
||||||
|
|
||||||
// internal variables
|
// internal variables
|
||||||
key *ecdsa.PrivateKey
|
key *ecdsa.PrivateKey
|
||||||
pubKey []byte
|
pubKey []byte
|
||||||
|
@ -105,6 +108,10 @@ type (
|
||||||
const (
|
const (
|
||||||
morphPrefix = "morph"
|
morphPrefix = "morph"
|
||||||
mainnetPrefix = "mainnet"
|
mainnetPrefix = "mainnet"
|
||||||
|
|
||||||
|
// extra blocks to overlap two deposits, we do that to make sure that
|
||||||
|
// there won't be any blocks without deposited assets in notary contract.
|
||||||
|
notaryExtraBlocks = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start runs all event providers.
|
// Start runs all event providers.
|
||||||
|
@ -120,6 +127,12 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make an initial deposit to notary contract to enable it
|
||||||
|
err = s.depositNotary()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// vote for sidechain validator if it is prepared in config
|
// vote for sidechain validator if it is prepared in config
|
||||||
err = s.voteForSidechainValidator(s.predefinedValidators)
|
err = s.voteForSidechainValidator(s.predefinedValidators)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -533,6 +546,18 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
|
|
||||||
server.addBlockTimer(emissionTimer)
|
server.addBlockTimer(emissionTimer)
|
||||||
|
|
||||||
|
// initialize notary deposit timer
|
||||||
|
server.notaryDepositAmount = fixedn.Fixed8(cfg.GetInt64("notary.deposit_amount"))
|
||||||
|
server.notaryDuration = cfg.GetUint32("timers.notary")
|
||||||
|
|
||||||
|
notaryTimer := newNotaryDepositTimer(¬aryDepositArgs{
|
||||||
|
l: log,
|
||||||
|
depositor: server.depositNotary,
|
||||||
|
notaryDuration: server.notaryDuration,
|
||||||
|
})
|
||||||
|
|
||||||
|
server.addBlockTimer(notaryTimer)
|
||||||
|
|
||||||
return server, nil
|
return server, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -707,3 +732,10 @@ func (s *Server) onlyActiveEventHandler(f event.Handler) event.Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) depositNotary() error {
|
||||||
|
return s.morphClient.DepositNotary(
|
||||||
|
s.notaryDepositAmount,
|
||||||
|
s.notaryDuration+notaryExtraBlocks,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue