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
|
@ -56,6 +56,9 @@ type (
|
|||
precision precision.Fixed8Converter
|
||||
auditClient *auditWrapper.ClientWrapper
|
||||
|
||||
notaryDepositAmount fixedn.Fixed8
|
||||
notaryDuration uint32
|
||||
|
||||
// internal variables
|
||||
key *ecdsa.PrivateKey
|
||||
pubKey []byte
|
||||
|
@ -105,6 +108,10 @@ type (
|
|||
const (
|
||||
morphPrefix = "morph"
|
||||
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.
|
||||
|
@ -120,6 +127,12 @@ func (s *Server) Start(ctx context.Context, intError chan<- error) error {
|
|||
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
|
||||
err = s.voteForSidechainValidator(s.predefinedValidators)
|
||||
if err != nil {
|
||||
|
@ -533,6 +546,18 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
|||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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…
Add table
Add a link
Reference in a new issue