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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use minConfirmation to replace sharder consensus, do it in percent #1310

Open
wants to merge 1 commit into
base: sprint-1.11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions core/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ type Config struct {
ZboxHost string `json:"zbox_host"`
// ZboxAppType app type name
ZboxAppType string `json:"zbox_app_type"`
// SharderConsensous is consensous for when quering for SCRestAPI calls
SharderConsensous int `json:"sharder_consensous"`
}

// LoadConfigFile load and parse Config from file
Expand Down Expand Up @@ -149,19 +147,13 @@ func LoadConfig(v Reader) (Config, error) {
cfg.VerifyOptimistic = true
}

sharderConsensous := v.GetInt("sharder_consensous")
if sharderConsensous < 1 {
sharderConsensous = DefaultSharderConsensous
}

cfg.BlockWorker = blockWorker
cfg.PreferredBlobbers = v.GetStringSlice("preferred_blobbers")
cfg.MinSubmit = minSubmit
cfg.MinConfirmation = minCfm
cfg.ConfirmationChainLength = CfmChainLength
cfg.MaxTxnQuery = maxTxnQuery
cfg.QuerySleepTime = querySleepTime
cfg.SharderConsensous = sharderConsensous

cfg.SignatureScheme = v.GetString("signature_scheme")
cfg.ChainID = v.GetString("chain_id")
Expand Down
5 changes: 0 additions & 5 deletions core/conf/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ func GetClientConfig() (*Config, error) {
// InitClientConfig set global client config
func InitClientConfig(c *Config) {
onceCfg.Do(func() {
sharderConsensous := c.SharderConsensous
if sharderConsensous < 1 {
sharderConsensous = DefaultSharderConsensous
}
cfg = c
cfg.SharderConsensous = sharderConsensous
})
}

Expand Down
5 changes: 2 additions & 3 deletions wasmsdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var CreateObjectURL func(buf []byte, mimeType string) string

// initSDKs init sharder/miners ,
func initSDKs(chainID, blockWorker, signatureScheme string,
minConfirmation, minSubmit, confirmationChainLength int, zboxHost, zboxAppType string, sharderconsensous int) error {
minConfirmation, minSubmit, confirmationChainLength int, zboxHost, zboxAppType string) error {

zboxApiClient.SetRequest(zboxHost, zboxAppType)

Expand All @@ -38,8 +38,7 @@ func initSDKs(chainID, blockWorker, signatureScheme string,
zcncore.WithChainID(chainID),
zcncore.WithMinConfirmation(minConfirmation),
zcncore.WithMinSubmit(minSubmit),
zcncore.WithConfirmationChainLength(confirmationChainLength),
zcncore.WithSharderConsensous(sharderconsensous))
zcncore.WithConfirmationChainLength(confirmationChainLength))

if err != nil {
fmt.Println("wasm: InitZCNSDK ", err)
Expand Down
1 change: 0 additions & 1 deletion winsdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ func InitSDKs(configJson *C.char) *C.char {
cc.MinConfirmation = configObj.MinConfirmation
cc.EthNode = configObj.EthereumNode
cc.MinSubmit = configObj.MinSubmit
cc.SharderConsensous = configObj.SharderConsensous
cc.SignatureScheme = configObj.SignatureScheme

return nil
Expand Down
14 changes: 10 additions & 4 deletions zboxcore/blockchain/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blockchain

import (
"encoding/json"
"math"
"sync/atomic"

"github.com/0chain/gosdk/core/common"
Expand Down Expand Up @@ -140,14 +141,19 @@ func SetBlockWorker(blockWorker string) {
chain.BlockWorker = blockWorker
}

func GetReqConsensus(n, minReqNum, reqPercent int) int {
reqNum := int(math.Max(float64(minReqNum), float64(n*reqPercent/100)))
if reqNum > n {
reqNum = n
}
return reqNum
}

func SetSharders(sharderArray []string) {
consensus := conf.DefaultSharderConsensous
config, err := conf.GetClientConfig()
if err == nil && config != nil {
consensus = config.SharderConsensous
}
if len(sharderArray) < consensus {
consensus = len(sharderArray)
consensus = GetReqConsensus(len(sharderArray), consensus, config.MinConfirmation)
}
Sharders = node.NewHolder(sharderArray, consensus)
}
Expand Down
9 changes: 2 additions & 7 deletions zboxcore/zboxutil/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

"github.com/0chain/errors"
"github.com/0chain/gosdk/core/conf"
"github.com/0chain/gosdk/core/encryption"
"github.com/0chain/gosdk/core/logger"
"github.com/0chain/gosdk/zboxcore/blockchain"
Expand Down Expand Up @@ -812,11 +811,6 @@ func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]
dominant := 200
wg := sync.WaitGroup{}

cfg, err := conf.GetClientConfig()
if err != nil {
return nil, err
}

for _, sharder := range sharders {
wg.Add(1)
go func(sharder string) {
Expand Down Expand Up @@ -864,7 +858,8 @@ func MakeSCRestAPICall(scAddress string, relativePath string, params map[string]
}
wg.Wait()

rate := float32(maxCount*100) / float32(cfg.SharderConsensous)
var err error
rate := float32(maxCount*100) / float32(numSharders)
if rate < consensusThresh {
err = errors.New("consensus_failed", "consensus failed on sharders")
}
Expand Down
24 changes: 10 additions & 14 deletions zcncore/networkworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/0chain/gosdk/core/conf"
"github.com/0chain/gosdk/core/node"
"github.com/0chain/gosdk/core/util"
"github.com/0chain/gosdk/zboxcore/blockchain"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -57,13 +58,11 @@ func UpdateNetworkDetails() error {
_config.isConfigured = false
_config.chain.Miners = networkDetails.Miners
_config.chain.Sharders = networkDetails.Sharders
consensus := _config.chain.SharderConsensous
if consensus < conf.DefaultSharderConsensous {
consensus = conf.DefaultSharderConsensous
}
if len(networkDetails.Sharders) < consensus {
consensus = len(networkDetails.Sharders)
}

consensus := blockchain.GetReqConsensus(
len(networkDetails.Sharders),
conf.DefaultSharderConsensous,
_config.chain.MinConfirmation)

Sharders = node.NewHolder(networkDetails.Sharders, consensus)
node.InitCache(Sharders)
Expand Down Expand Up @@ -127,13 +126,10 @@ func SetNetwork(miners []string, sharders []string) {
_config.chain.Miners = miners
_config.chain.Sharders = sharders

consensus := _config.chain.SharderConsensous
if consensus < conf.DefaultSharderConsensous {
consensus = conf.DefaultSharderConsensous
}
if len(sharders) < consensus {
consensus = len(sharders)
}
consensus := blockchain.GetReqConsensus(
len(sharders),
conf.DefaultSharderConsensous,
_config.chain.MinConfirmation)

Sharders = node.NewHolder(sharders, consensus)
node.InitCache(Sharders)
Expand Down
23 changes: 9 additions & 14 deletions zcncore/networkworker_mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"github.com/0chain/gosdk/core/conf"
"github.com/0chain/gosdk/core/node"
"github.com/0chain/gosdk/core/util"
"github.com/0chain/gosdk/zboxcore/blockchain"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -72,13 +73,10 @@
_config.isConfigured = false
_config.chain.Miners = networkDetails.net.Miners
_config.chain.Sharders = networkDetails.net.Sharders
consensus := _config.chain.SharderConsensous
if consensus < conf.DefaultSharderConsensous {
consensus = conf.DefaultSharderConsensous
}
if len(networkDetails.net.Sharders) < consensus {
consensus = len(networkDetails.net.Sharders)
}
consensus := blockchain.GetReqConsensus(
len(networkDetails.net.Sharders),
config.DefaultSharderConsensous,

Check failure on line 78 in zcncore/networkworker_mobile.go

View workflow job for this annotation

GitHub Actions / Build-macos

undefined: config

Check failure on line 78 in zcncore/networkworker_mobile.go

View workflow job for this annotation

GitHub Actions / Build-macos

undefined: config

Check failure on line 78 in zcncore/networkworker_mobile.go

View workflow job for this annotation

GitHub Actions / Build-ios

undefined: config

Check failure on line 78 in zcncore/networkworker_mobile.go

View workflow job for this annotation

GitHub Actions / Build-ios

undefined: config

Check failure on line 78 in zcncore/networkworker_mobile.go

View workflow job for this annotation

GitHub Actions / Build-ios

undefined: config

Check failure on line 78 in zcncore/networkworker_mobile.go

View workflow job for this annotation

GitHub Actions / Build-android

undefined: config

Check failure on line 78 in zcncore/networkworker_mobile.go

View workflow job for this annotation

GitHub Actions / Build-android

undefined: config
_config.chain.MinConfirmation)

Sharders = node.NewHolder(networkDetails.net.Sharders, consensus)
node.InitCache(Sharders)
Expand Down Expand Up @@ -139,13 +137,10 @@
_config.chain.Miners = net.net.Miners
_config.chain.Sharders = net.net.Sharders

consensus := _config.chain.SharderConsensous
if consensus < conf.DefaultSharderConsensous {
consensus = conf.DefaultSharderConsensous
}
if len(net.net.Sharders) < consensus {
consensus = len(net.net.Sharders)
}
consensus := blockchain.GetReqConsensus(
len(_config.chain.Sharders),
conf.DefaultSharderConsensous,
_config.chain.MinConfirmation)

Sharders = node.NewHolder(_config.chain.Sharders, consensus)

Expand Down
7 changes: 0 additions & 7 deletions zcncore/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,13 +1364,6 @@ func WithConfirmationChainLength(m int) func(c *ChainConfig) error {
}
}

func WithSharderConsensous(m int) func(c *ChainConfig) error {
return func(c *ChainConfig) error {
c.SharderConsensous = m
return nil
}
}

// UpdateValidatorSettings update settings of a validator.
func (t *Transaction) UpdateValidatorSettings(v *Validator) (err error) {

Expand Down
2 changes: 0 additions & 2 deletions zcncore/transaction_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ type ChainConfig struct {
MinConfirmation int `json:"min_confirmation"`
ConfirmationChainLength int `json:"confirmation_chain_length"`
EthNode string `json:"eth_node"`
SharderConsensous int `json:"sharder_consensous"`
}

var Sharders *node.NodeHolder
Expand Down Expand Up @@ -150,7 +149,6 @@ func InitZCNSDK(blockWorker string, signscheme string, configs ...func(*ChainCon
SignatureScheme: _config.chain.SignatureScheme,
ChainID: _config.chain.ChainID,
EthereumNode: _config.chain.EthNode,
SharderConsensous: _config.chain.SharderConsensous,
}

conf.InitClientConfig(cfg)
Expand Down
1 change: 0 additions & 1 deletion zcncore/wallet_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ func Init(chainConfigJSON string) error {
SignatureScheme: _config.chain.SignatureScheme,
ChainID: _config.chain.ChainID,
EthereumNode: _config.chain.EthNode,
SharderConsensous: _config.chain.SharderConsensous,
}

conf.InitClientConfig(cfg)
Expand Down