forked from TrueCloudLab/frostfs-node
[#687] neofs-adm: check for initialization stage completion
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
c3f7ccaee6
commit
8ea67ec565
3 changed files with 51 additions and 3 deletions
|
@ -29,6 +29,7 @@ type initializeContext struct {
|
|||
Hashes []util.Uint256
|
||||
WaitDuration time.Duration
|
||||
PollInterval time.Duration
|
||||
Command *cobra.Command
|
||||
}
|
||||
|
||||
func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
||||
|
@ -38,7 +39,7 @@ func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
initCtx, err := newInitializeContext(viper.GetViper())
|
||||
initCtx, err := newInitializeContext(cmd, viper.GetViper())
|
||||
if err != nil {
|
||||
return fmt.Errorf("initialization error: %w", err)
|
||||
}
|
||||
|
@ -68,7 +69,7 @@ func initializeSideChainCmd(cmd *cobra.Command, args []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func newInitializeContext(v *viper.Viper) (*initializeContext, error) {
|
||||
func newInitializeContext(cmd *cobra.Command, v *viper.Viper) (*initializeContext, error) {
|
||||
walletDir := v.GetString(alphabetWalletsFlag)
|
||||
wallets, err := openAlphabetWallets(walletDir)
|
||||
if err != nil {
|
||||
|
@ -97,6 +98,7 @@ func newInitializeContext(v *viper.Viper) (*initializeContext, error) {
|
|||
Wallets: wallets,
|
||||
WaitDuration: time.Second * 30,
|
||||
PollInterval: time.Second,
|
||||
Command: cmd,
|
||||
}
|
||||
|
||||
return initCtx, nil
|
||||
|
@ -139,6 +141,8 @@ func openAlphabetWallets(walletDir string) ([]*wallet.Wallet, error) {
|
|||
}
|
||||
|
||||
func (c *initializeContext) awaitTx() error {
|
||||
c.Command.Println("Waiting for transactions to persist...")
|
||||
|
||||
tick := time.NewTicker(c.PollInterval)
|
||||
defer tick.Stop()
|
||||
|
||||
|
@ -149,6 +153,10 @@ func (c *initializeContext) awaitTx() error {
|
|||
|
||||
loop:
|
||||
for i := range c.Hashes {
|
||||
_, err := c.Client.GetApplicationLog(c.Hashes[i], &at)
|
||||
if err == nil {
|
||||
continue loop
|
||||
}
|
||||
for {
|
||||
select {
|
||||
case <-tick.C:
|
||||
|
|
|
@ -11,6 +11,13 @@ import (
|
|||
)
|
||||
|
||||
func (c *initializeContext) setNotaryAndAlphabetNodes() error {
|
||||
if ok, err := c.setRolesFinished(); ok || err != nil {
|
||||
if err == nil {
|
||||
c.Command.Println("Stage 2: already performed.")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
designateHash, err := c.Client.GetNativeContractHash(nativenames.Designation)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't fetch %s hash: %w", nativenames.Designation, err)
|
||||
|
@ -38,3 +45,13 @@ func (c *initializeContext) setNotaryAndAlphabetNodes() error {
|
|||
|
||||
return c.awaitTx()
|
||||
}
|
||||
|
||||
func (c *initializeContext) setRolesFinished() (bool, error) {
|
||||
height, err := c.Client.GetBlockCount()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
pubs, err := c.Client.GetDesignatedByRole(noderoles.NeoFSAlphabet, height)
|
||||
return len(pubs) == len(c.Wallets), err
|
||||
}
|
||||
|
|
|
@ -17,6 +17,14 @@ const (
|
|||
)
|
||||
|
||||
func (c *initializeContext) transferFunds() error {
|
||||
ok, err := c.transferFundsFinished()
|
||||
if ok || err != nil {
|
||||
if err == nil {
|
||||
c.Command.Println("Stage 1: already performed.")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
gasHash, err := c.Client.GetNativeContractHash(nativenames.Gas)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't fetch %s hash: %w", nativenames.Gas, err)
|
||||
|
@ -48,7 +56,7 @@ func (c *initializeContext) transferFunds() error {
|
|||
client.TransferTarget{
|
||||
Token: gasHash,
|
||||
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
||||
Amount: gasInitialTotalSupply - initialAlphabetGASAmount*int64(len(c.Wallets)),
|
||||
Amount: (gasInitialTotalSupply - initialAlphabetGASAmount*int64(len(c.Wallets))) / 2,
|
||||
},
|
||||
client.TransferTarget{
|
||||
Token: neoHash,
|
||||
|
@ -75,6 +83,21 @@ func (c *initializeContext) transferFunds() error {
|
|||
return c.awaitTx()
|
||||
}
|
||||
|
||||
func (c *initializeContext) transferFundsFinished() (bool, error) {
|
||||
gasHash, err := c.Client.GetNativeContractHash(nativenames.Gas)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
acc, err := getWalletAccount(c.Wallets[0], singleAccountName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
res, err := c.Client.NEP17BalanceOf(gasHash, acc.Contract.ScriptHash())
|
||||
return res > initialAlphabetGASAmount/2, err
|
||||
}
|
||||
|
||||
func (c *initializeContext) multiSignAndSend(tx *transaction.Transaction, accType string) error {
|
||||
if err := c.multiSign(tx, accType); err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in a new issue