forked from TrueCloudLab/frostfs-node
[#1391] adm: Properly check whether transfers were made
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
62028cd7ee
commit
f83f7feb8c
1 changed files with 13 additions and 6 deletions
|
@ -27,12 +27,12 @@ const (
|
||||||
initialAlphabetGASAmount = 10_000 * native.GASFactor
|
initialAlphabetGASAmount = 10_000 * native.GASFactor
|
||||||
// initialProxyGASAmount represents the amount of GAS given to a proxy contract.
|
// initialProxyGASAmount represents the amount of GAS given to a proxy contract.
|
||||||
initialProxyGASAmount = 50_000 * native.GASFactor
|
initialProxyGASAmount = 50_000 * native.GASFactor
|
||||||
// alphabetGasRatio is a coefficient that defines the threshold below which
|
|
||||||
// the balance of the alphabet node is considered not replenished. The value
|
|
||||||
// of this coefficient is determined empirically.
|
|
||||||
alphabetGasRatio = 5
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func initialCommitteeGASAmount(c *helper.InitializeContext) int64 {
|
||||||
|
return (gasInitialTotalSupply - initialAlphabetGASAmount*int64(len(c.Wallets))) / 2
|
||||||
|
}
|
||||||
|
|
||||||
func transferFunds(c *helper.InitializeContext) error {
|
func transferFunds(c *helper.InitializeContext) error {
|
||||||
ok, err := transferFundsFinished(c)
|
ok, err := transferFundsFinished(c)
|
||||||
if ok || err != nil {
|
if ok || err != nil {
|
||||||
|
@ -59,7 +59,7 @@ func transferFunds(c *helper.InitializeContext) error {
|
||||||
transferTarget{
|
transferTarget{
|
||||||
Token: gas.Hash,
|
Token: gas.Hash,
|
||||||
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
Address: c.CommitteeAcc.Contract.ScriptHash(),
|
||||||
Amount: (gasInitialTotalSupply - initialAlphabetGASAmount*int64(len(c.Wallets))) / 2,
|
Amount: initialCommitteeGASAmount(c),
|
||||||
},
|
},
|
||||||
transferTarget{
|
transferTarget{
|
||||||
Token: neo.Hash,
|
Token: neo.Hash,
|
||||||
|
@ -80,12 +80,19 @@ func transferFunds(c *helper.InitializeContext) error {
|
||||||
return c.AwaitTx()
|
return c.AwaitTx()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// transferFundsFinished checks balances of accounts we transfer GAS to.
|
||||||
|
// The stage is considered finished if the balance is greater than the half of what we need to transfer.
|
||||||
func transferFundsFinished(c *helper.InitializeContext) (bool, error) {
|
func transferFundsFinished(c *helper.InitializeContext) (bool, error) {
|
||||||
acc := c.Accounts[0]
|
acc := c.Accounts[0]
|
||||||
|
|
||||||
r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash)
|
r := nep17.NewReader(c.ReadOnlyInvoker, gas.Hash)
|
||||||
res, err := r.BalanceOf(acc.Contract.ScriptHash())
|
res, err := r.BalanceOf(acc.Contract.ScriptHash())
|
||||||
return res.Cmp(big.NewInt(alphabetGasRatio*native.GASFactor)) == 1, err
|
if err != nil || res.Cmp(big.NewInt(initialAlphabetGASAmount/2)) != 1 {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err = r.BalanceOf(c.CommitteeAcc.ScriptHash())
|
||||||
|
return res != nil && res.Cmp(big.NewInt(initialCommitteeGASAmount(c)/2)) == 1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func transferGASToProxy(c *helper.InitializeContext) error {
|
func transferGASToProxy(c *helper.InitializeContext) error {
|
||||||
|
|
Loading…
Reference in a new issue