Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minstake #2843

Merged
merged 13 commits into from Oct 10, 2023
2 changes: 2 additions & 0 deletions code/go/0chain.net/miner/testdata/config/sc.yaml
Expand Up @@ -42,6 +42,7 @@ smart_contracts:
# etc
min_stake: 0.0 # min stake can be set by a node (boundary for all nodes)
max_stake: 20000.0 # max stake can be set by a node (boundary for all nodes)
min_stake_per_delegate: 1
start_rounds: 50
contribute_rounds: 50
share_rounds: 50
Expand Down Expand Up @@ -104,6 +105,7 @@ smart_contracts:
time_unit: "720h"
min_stake: 0.01 # min stake can be set by a node (boundary for all nodes)
max_stake: 20000.0 # max stake can be set by a node (boundary for all nodes)
min_stake_per_delegate: 1
# max_mint
max_mint: 1500000.0 # tokens, max amount of tokens can be minted by SC
# min possible allocations size in bytes allowed by the SC
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/smartcontract/benchmark/benchmark.go
Expand Up @@ -176,6 +176,7 @@ const (
StorageMaxCharge = SmartContract + StorageSc + "max_charge"
StorageMinStake = SmartContract + StorageSc + "min_stake"
StorageMaxStake = SmartContract + StorageSc + "max_stake"
StorageMinStakePerDelegates = SmartContract + StorageSc + "min_stake_per_delegate"
StorageMaxDelegates = SmartContract + StorageSc + "max_delegates"
StorageDiverseBlobbers = SmartContract + StorageSc + "diverse_blobbers"
StorageReadPoolMinLock = SmartContract + StorageSc + "readpool.min_lock"
Expand Down
Expand Up @@ -74,6 +74,7 @@ smart_contracts:
max_delegates: 200
min_stake: 0.0
max_stake: 170.0
min_stake_per_delegate: 1
max_n: 7 # 100
min_n: 3 # 3
max_s: 2 # 30
Expand Down Expand Up @@ -135,6 +136,7 @@ smart_contracts:
max_charge: 0.2
min_stake: 0.0
max_stake: 20000.0
min_stake_per_delegate: 1
max_delegates: 200
diverse_blobbers: false
failed_challenges_to_cancel: 0
Expand Down Expand Up @@ -197,6 +199,7 @@ smart_contracts:
min_mint: 1
min_burn: 1
min_stake: 0
min_stake_per_delegate : 1
max_stake: 2.7
min_lock: 0
min_authorizers: 1
Expand Down
2 changes: 2 additions & 0 deletions code/go/0chain.net/smartcontract/minersc/miner.go
Expand Up @@ -51,6 +51,8 @@ func (msc *MinerSmartContract) AddMiner(t *transaction.Transaction,

lockAllMiners.Lock()
defer lockAllMiners.Unlock()

logging.Logger.Info("Jayash add_miner: The new miner info", zap.Any("minStakePerDelegate", gn.MinStakePerDelegate))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
newMiner.Settings.MinStake = gn.MinStakePerDelegate
magicBlockMiners := balances.GetChainCurrentMagicBlock().Miners

Expand Down
2 changes: 2 additions & 0 deletions code/go/0chain.net/smartcontract/minersc/models.go
Expand Up @@ -271,6 +271,7 @@ func (gn *GlobalNode) readConfig() (err error) {
return
}
gn.MinStakePerDelegate, err = currency.ParseZCN(config2.SmartContractConfig.GetFloat64(pfx + SettingName[MinStakePerDelegate]))
logging.Logger.Info("Jayash MinStakePerDelegate", zap.Any("MinStakePerDelegate", gn.MinStakePerDelegate), zap.Any("config", config2.SmartContractConfig.GetFloat64(pfx+SettingName[MinStakePerDelegate])))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return
}
Expand Down Expand Up @@ -380,6 +381,7 @@ func (gn *GlobalNode) Get(key Setting) (interface{}, error) {
case MinStake:
return gn.MinStake, nil
case MinStakePerDelegate:
logging.Logger.Info("Jayash get", zap.Any("MinStakePerDelegate", gn.MinStakePerDelegate))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
return gn.MinStakePerDelegate, nil
case HealthCheckPeriod:
return gn.HealthCheckPeriod, nil
Expand Down
3 changes: 3 additions & 0 deletions code/go/0chain.net/smartcontract/minersc/settings.go
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/0chain/common/core/logging"
"go.uber.org/zap"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -232,6 +234,7 @@ func (gn *GlobalNode) setBalance(key string, change currency.Coin) error {
case MinStake:
gn.MinStake = change
case MinStakePerDelegate:
logging.Logger.Info("Jayash setBalance", zap.Any("change", change))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
gn.MinStakePerDelegate = change
case MaxStake:
gn.MaxStake = change
Expand Down
2 changes: 2 additions & 0 deletions code/go/0chain.net/smartcontract/minersc/sharder.go
Expand Up @@ -130,6 +130,8 @@ func (msc *MinerSmartContract) AddSharder(

newSharder.NodeType = NodeTypeSharder // set node type
newSharder.ProviderType = spenum.Sharder
newSharder.Settings.MinStake = gn.MinStakePerDelegate

exist, err := msc.getSharderNode(newSharder.ID, balances)
if err != nil && err != util.ErrValueNotPresent {
return "", common.NewErrorf("add_sharder", "unexpected error: %v", err)
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/smartcontract/stakepool/stakepool.go
Expand Up @@ -390,6 +390,7 @@ func (sp *StakePool) DistributeRewardsRandN(
return err
}

logging.Logger.Info("Jayash DistributeRewardsRandN", zap.Any("Minstake", sp.Settings.MinStake), zap.Any("total", total), zap.Any("value", value), zap.Any("randN", randN))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
if value == 0 || sp.HasBeenKilled || total < sp.Settings.MinStake {
return nil // nothing to move
}
Expand Down
Expand Up @@ -770,13 +770,14 @@ func BenchmarkTests(
"blobber_slash": "0.1",
"max_read_price": "100",
"max_write_price": "100",
"max_file_size": "40000000000000",
"max_file_size": "40000000000000",
"challenge_enabled": "true",
"challenge_generation_gap": "1",
"validators_per_challenge": "2",
"num_validators_rewarded": "10",
"max_blobber_select_for_challenge": "5",
"max_delegates": "100",
"min_stake_per_delegate": "1",

"block_reward.block_reward": "1000",
"block_reward.qualifying_stake": "1",
Expand Down
3 changes: 3 additions & 0 deletions code/go/0chain.net/smartcontract/storagesc/config.go
Expand Up @@ -2,6 +2,8 @@ package storagesc

import (
"fmt"
"github.com/0chain/common/core/logging"
"go.uber.org/zap"
"time"

"0chain.net/core/config"
Expand Down Expand Up @@ -332,6 +334,7 @@ func getConfiguredConfig() (conf *Config, err error) {
return nil, err
}
conf.MinStakePerDelegate, err = currency.ParseZCN(scc.GetFloat64(pfx + "min_stake_per_delegate"))
logging.Logger.Info("Jayash getConfiguredConfig", zap.Any("MinStakePerDelegate", conf.MinStakePerDelegate))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions code/go/0chain.net/smartcontract/storagesc/config_settigns.go
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/0chain/common/core/logging"
"go.uber.org/zap"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -393,6 +395,7 @@ func (conf *Config) setCoin(key string, change currency.Coin) error {
case MinStake:
conf.MinStake = change
case MinStakePerDelegate:
logging.Logger.Info("Jayash setting min stake per delegate", zap.Any("change", change))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
conf.MinStakePerDelegate = change
case MaxTotalFreeAllocation:
conf.MaxTotalFreeAllocation = change
Expand Down Expand Up @@ -640,6 +643,7 @@ func (conf *Config) get(key Setting) interface{} {
case MinStake:
return conf.MinStake
case MinStakePerDelegate:
logging.Logger.Info("Jayash getting min stake per delegate", zap.Any("conf", conf.MinStakePerDelegate))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
return conf.MinStakePerDelegate
case TimeUnit:
return conf.TimeUnit
Expand Down
4 changes: 4 additions & 0 deletions code/go/0chain.net/smartcontract/storagesc/stakepool.go
Expand Up @@ -4,6 +4,8 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/0chain/common/core/logging"
"go.uber.org/zap"

"0chain.net/chaincore/state"
"0chain.net/smartcontract/dbs/event"
Expand Down Expand Up @@ -324,6 +326,7 @@ func (ssc *StorageSmartContract) getOrCreateStakePool(

sp.Settings.ServiceChargeRatio = settings.ServiceChargeRatio
sp.Settings.MaxNumDelegates = settings.MaxNumDelegates
logging.Logger.Info("Jayash getOrCreateStakePool", zap.Any("MinStakePerDelegate", conf.MinStakePerDelegate))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
sp.Settings.MinStake = conf.MinStakePerDelegate
return sp, nil
}
Expand All @@ -341,6 +344,7 @@ func (ssc *StorageSmartContract) createStakePool(
sp.Minter = chainstate.MinterStorage
sp.Settings.ServiceChargeRatio = settings.ServiceChargeRatio
sp.Settings.MaxNumDelegates = settings.MaxNumDelegates
logging.Logger.Info("Jayash 2getOrCreateStakePool", zap.Any("MinStakePerDelegate", conf.MinStakePerDelegate))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved
sp.Settings.MinStake = conf.MinStakePerDelegate

return sp, nil
Expand Down
5 changes: 5 additions & 0 deletions code/go/0chain.net/smartcontract/zcnsc/stakepool.go
Expand Up @@ -3,6 +3,8 @@ package zcnsc
import (
"errors"
"fmt"
"github.com/0chain/common/core/logging"
"go.uber.org/zap"

cstate "0chain.net/chaincore/chain/state"
"0chain.net/chaincore/state"
Expand Down Expand Up @@ -137,6 +139,9 @@ func (zcn *ZCNSmartContract) getOrUpdateStakePool(gn *GlobalNode,
sp.Settings.MaxNumDelegates = settings.MaxNumDelegates
changed = true
}

logging.Logger.Info("Jayash getOrCreateStakePool", zap.Any("MinStakePerDelegate", gn.MinStakePerDelegate))
Jayashsatolia403 marked this conversation as resolved.
Show resolved Hide resolved

if sp.Settings.MinStake != gn.MinStakePerDelegate {
sp.Settings.MinStake = gn.MinStakePerDelegate
changed = true
Expand Down
3 changes: 3 additions & 0 deletions docker.local/config/benchmark.yaml
Expand Up @@ -67,6 +67,7 @@ smart_contracts:
max_delegates: 200
min_stake: 0.0
max_stake: 170.0
min_stake_per_delegate: 1
max_n: 7 # 100
min_n: 3 # 3
max_s: 2 # 30
Expand Down Expand Up @@ -130,6 +131,7 @@ smart_contracts:
max_charge: 0.2
min_stake: 0.0
max_stake: 20000.0
min_stake_per_delegate: 1
max_delegates: 200
diverse_blobbers: false
failed_challenges_to_cancel: 0
Expand Down Expand Up @@ -192,6 +194,7 @@ smart_contracts:
min_mint: 1
min_burn: 1
min_stake: 0
min_stake_per_delegate : 1
max_stake: 2.7
min_lock: 0
min_authorizers: 1
Expand Down
3 changes: 3 additions & 0 deletions docker.local/config/loadtest_benchmark.yaml
Expand Up @@ -61,6 +61,7 @@ smart_contracts:
max_delegates: 200
min_stake: 0.0
max_stake: 170.0
min_stake_per_delegate: 1
max_n: 7 # 100
min_n: 3 # 3
max_s: 2 # 30
Expand Down Expand Up @@ -103,6 +104,7 @@ smart_contracts:
max_charge: 0.2
min_stake: 0.0
max_stake: 20000.0
min_stake_per_delegate: 1
max_delegates: 200
diverse_blobbers: false
failed_challenges_to_cancel: 0
Expand Down Expand Up @@ -156,6 +158,7 @@ smart_contracts:
min_mint: 1
min_burn: 1
min_stake: 3
min_stake_per_delegate : 1
min_lock: 0
min_authorizers: 1
percent_authorizers: 0
Expand Down
3 changes: 3 additions & 0 deletions docker.local/config/sc.yaml
Expand Up @@ -31,6 +31,7 @@ smart_contracts:
# etc
min_stake: 0.0 # min stake can be set by a node (boundary for all nodes)
max_stake: 20000.0 # max stake can be set by a node (boundary for all nodes)
min_stake_per_delegate: 1
start_rounds: 50
contribute_rounds: 50
share_rounds: 50
Expand Down Expand Up @@ -92,6 +93,7 @@ smart_contracts:
time_unit: "720h"
min_stake: 0.01 # min stake can be set by a node (boundary for all nodes)
max_stake: 20000.0 # max stake can be set by a node (boundary for all nodes)
min_stake_per_delegate: 1
# max_mint
max_mint: 75000000.0 # tokens, max amount of tokens can be minted by SC
# min possible allocations size in bytes allowed by the SC
Expand Down Expand Up @@ -232,6 +234,7 @@ smart_contracts:
min_mint: 1
min_burn: 1
min_stake: 0
min_stake_per_delegate : 1
min_authorizers: 1
percent_authorizers: 0.7
max_delegates: 10
Expand Down
Expand Up @@ -30,6 +30,7 @@ smart_contracts:
# etc
min_stake: 0.0 # 0.01 # min stake can be set by a node (boundary for all nodes)
max_stake: 20000.0 # max stake can be set by a node (boundary for all nodes)
min_stake_per_delegate: 1
start_rounds: 50
contribute_rounds: 50
share_rounds: 50
Expand Down Expand Up @@ -70,6 +71,7 @@ smart_contracts:
time_unit: '720h'
min_stake: 0.01 # min stake can be set by a node (boundary for all nodes)
max_stake: 20000.0 # max stake can be set by a node (boundary for all nodes)
min_stake_per_delegate: 1
# max_mint
max_mint: 4000000.0 # tokens, max amount of tokens can be minted by SC
# min possible allocations size in bytes allowed by the SC
Expand Down
Expand Up @@ -36,7 +36,6 @@ challenge_completion_time: 2m # duration to complete a challenge
# a task and redeem tokens, it should be big enough
read_lock_timeout: 1m
write_lock_timeout: 1m
max_file_size: 10485760 #10MB

# update_allocations_interval used to refresh known allocation objects from SC
update_allocations_interval: 1m
Expand Down
Expand Up @@ -30,6 +30,7 @@ smart_contracts:
# etc
min_stake: 0.0 # 0.01 # min stake can be set by a node (boundary for all nodes)
max_stake: 20000.0 # max stake can be set by a node (boundary for all nodes)
min_stake_per_delegate : 1
start_rounds: 50
contribute_rounds: 50
share_rounds: 50
Expand Down
Expand Up @@ -36,7 +36,6 @@ challenge_completion_time: 2m # duration to complete a challenge
# a task and redeem tokens, it should be big enough
read_lock_timeout: 1m
write_lock_timeout: 1m
max_file_size: 10485760 #10MB

# update_allocations_interval used to refresh known allocation objects from SC
update_allocations_interval: 1m
Expand Down