Skip to content

Commit

Permalink
Fix/remove cct from terms (#727)
Browse files Browse the repository at this point in the history
* fix(gomod): upgraded gosdk

* fix(zcn): remove cct from smartcontracts: add_blobber and update_blobber_settings

* fix(config): removed challenge_completion_time from config

* fix(config): removed challenge_completion_time from config

* fix(zcn): removed ChallengeCompletionTime from all code

* - fix gomod

Co-authored-by: Kishan-Dhakan <kishandhakan17@gmail.com>
Co-authored-by: Sumit <sardana.sumit08@gmail.com>
  • Loading branch information
3 people authored Jun 18, 2022
1 parent a98ac1a commit a2eaa88
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 49 deletions.
2 changes: 1 addition & 1 deletion code/go/0chain.net/blobber/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func reloadConfig() error {
}

config.Configuration.Capacity = viper.GetInt64("capacity")
config.Configuration.ChallengeCompletionTime = viper.GetDuration("challenge_completion_time")

config.Configuration.MaxOfferDuration = viper.GetDuration("max_offer_duration")
config.Configuration.MaxStake = int64(viper.GetFloat64("max_stake") * 1e10)
config.Configuration.MinLockDemand = viper.GetFloat64("min_lock_demand")
Expand Down
13 changes: 6 additions & 7 deletions code/go/0chain.net/blobbercore/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func SetupDefaultConfig() {
viper.SetDefault("write_price", 0.0)
viper.SetDefault("min_lock_demand", 0.0)
viper.SetDefault("max_offer_duration", time.Duration(0))
viper.SetDefault("challenge_completion_time", time.Duration(-1))

viper.SetDefault("read_lock_timeout", time.Duration(-1))
viper.SetDefault("write_lock_timeout", time.Duration(-1))
viper.SetDefault("write_marker_lock_timeout", time.Second*30)
Expand Down Expand Up @@ -120,12 +120,11 @@ type Config struct {
MinioBucket string
MinioRegion string

ReadPrice float64
WritePrice float64
PriceInUSD bool
MinLockDemand float64
MaxOfferDuration time.Duration
ChallengeCompletionTime time.Duration
ReadPrice float64
WritePrice float64
PriceInUSD bool
MinLockDemand float64
MaxOfferDuration time.Duration

ReadLockTimeout int64 // seconds
WriteLockTimeout int64 // seconds
Expand Down
30 changes: 11 additions & 19 deletions code/go/0chain.net/blobbercore/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ import (
const TableNameSettings = "settings"

type Settings struct {
ID string `gorm:"column:id;size:10;primaryKey"`
Capacity int64 `gorm:"column:capacity;not null;default:0"`
ChallengeCompletionTime string `gorm:"column:challenge_completion_time;size:30;default:'-1ns';not null"`
MaxOfferDuration string `gorm:"column:max_offer_duration;size:30;default:'-1ns';not null"`
MaxStake int64 `gorm:"column:max_stake;not null;default:100"`
MinLockDemand float64 `gorm:"column:min_lock_demand;not null;default:0"`
MinStake int64 `gorm:"column:min_stake;not null;default:1"`
NumDelegates int `gorm:"column:num_delegates;not null;default:100"`
ReadPrice float64 `gorm:"column:read_price;not null;default:0"`
WritePrice float64 `gorm:"column:write_price;not null;default:0"`
ServiceCharge float64 `gorm:"column:service_charge;not null;default:0"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:NOW()"`
ID string `gorm:"column:id;size:10;primaryKey"`
Capacity int64 `gorm:"column:capacity;not null;default:0"`
MaxOfferDuration string `gorm:"column:max_offer_duration;size:30;default:'-1ns';not null"`
MaxStake int64 `gorm:"column:max_stake;not null;default:100"`
MinLockDemand float64 `gorm:"column:min_lock_demand;not null;default:0"`
MinStake int64 `gorm:"column:min_stake;not null;default:1"`
NumDelegates int `gorm:"column:num_delegates;not null;default:100"`
ReadPrice float64 `gorm:"column:read_price;not null;default:0"`
WritePrice float64 `gorm:"column:write_price;not null;default:0"`
ServiceCharge float64 `gorm:"column:service_charge;not null;default:0"`
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:NOW()"`
}

func (s Settings) TableName() string {
Expand All @@ -43,11 +42,6 @@ func (s *Settings) CopyTo(c *Config) error {
}

c.Capacity = s.Capacity
cct, err := time.ParseDuration(s.ChallengeCompletionTime)
if err != nil {
return errors.Throw(constants.ErrInvalidParameter, "ChallengeCompletionTime")
}
c.ChallengeCompletionTime = cct

maxOfferDuration, err := time.ParseDuration(s.MaxOfferDuration)
if err != nil {
Expand All @@ -72,7 +66,6 @@ func (s *Settings) CopyFrom(c *Config) error {
}

s.Capacity = c.Capacity
s.ChallengeCompletionTime = c.ChallengeCompletionTime.String()
s.MaxOfferDuration = c.MaxOfferDuration.String()
s.MaxStake = c.MaxStake
s.MinLockDemand = c.MinLockDemand
Expand Down Expand Up @@ -138,7 +131,6 @@ func ReloadFromChain(ctx context.Context, db *gorm.DB) (*zcncore.Blobber, error)
}

Configuration.Capacity = int64(b.Capacity)
Configuration.ChallengeCompletionTime = b.Terms.ChallengeCompletionTime
Configuration.MaxOfferDuration = b.Terms.MaxOfferDuration
Configuration.MaxStake = int64(b.StakePoolSettings.MaxStake)
Configuration.MinLockDemand = b.Terms.MinLockDemand
Expand Down
1 change: 0 additions & 1 deletion code/go/0chain.net/blobbercore/handler/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func getStorageNode() (*transaction.StorageNode, error) {
sn.Terms.WritePrice = int64(zcncore.ConvertToValue(writePrice))
sn.Terms.MinLockDemand = config.Configuration.MinLockDemand
sn.Terms.MaxOfferDuration = config.Configuration.MaxOfferDuration
sn.Terms.ChallengeCompletionTime = config.Configuration.ChallengeCompletionTime

sn.StakePoolSettings.DelegateWallet = config.Configuration.DelegateWallet
sn.StakePoolSettings.MinStake = config.Configuration.MinStake
Expand Down
16 changes: 7 additions & 9 deletions code/go/0chain.net/blobbercore/stats/blobberstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ type BlobberStats struct {
AllocationListPagination *Pagination `json:"allocation_list_pagination,omitempty"`

// configurations
Capacity int64 `json:"capacity"`
ReadPrice float64 `json:"read_price"`
WritePrice float64 `json:"write_price"`
MinLockDemand float64 `json:"min_lock_demand"`
MaxOfferDuration time.Duration `json:"max_offer_duration"`
ChallengeCompletionTime time.Duration `json:"challnge_completion_time"`
ReadLockTimeout Duration `json:"read_lock_timeout"`
WriteLockTimeout Duration `json:"write_lock_timeout"`
Capacity int64 `json:"capacity"`
ReadPrice float64 `json:"read_price"`
WritePrice float64 `json:"write_price"`
MinLockDemand float64 `json:"min_lock_demand"`
MaxOfferDuration time.Duration `json:"max_offer_duration"`
ReadLockTimeout Duration `json:"read_lock_timeout"`
WriteLockTimeout Duration `json:"write_lock_timeout"`

AllocationStats []*AllocationStats `json:"-"`

Expand Down Expand Up @@ -121,7 +120,6 @@ func (bs *BlobberStats) loadBasicStats(ctx context.Context) {
bs.WritePrice = config.Configuration.WritePrice
bs.MinLockDemand = config.Configuration.MinLockDemand
bs.MaxOfferDuration = config.Configuration.MaxOfferDuration
bs.ChallengeCompletionTime = config.Configuration.ChallengeCompletionTime
bs.ReadLockTimeout = Duration(config.Configuration.ReadLockTimeout)
bs.WriteLockTimeout = Duration(config.Configuration.WriteLockTimeout)
//
Expand Down
1 change: 0 additions & 1 deletion code/go/0chain.net/blobbercore/stats/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ const tpl = `
<tr><td>Write price</td><td>{{ .WritePrice }}</td></tr>
<tr><td>Min lock demand</td><td>{{ .MinLockDemand }}</td></tr>
<tr><td>Max offer duration</td><td>{{ .MaxOfferDuration }}</td></tr>
<tr><td>Challenge completion_time</td><td>{{ .ChallengeCompletionTime }}</td></tr>
<tr><td>Read lock timeout</td><td>{{ .ReadLockTimeout }}</td></tr>
<tr><td>Write lock timeout</td><td>{{ .WriteLockTimeout }}</td></tr>
</table>
Expand Down
3 changes: 0 additions & 3 deletions code/go/0chain.net/core/transaction/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ type Terms struct {
MinLockDemand float64 `json:"min_lock_demand"`
// MaxOfferDuration with this prices and the demand.
MaxOfferDuration time.Duration `json:"max_offer_duration"`
// ChallengeCompletionTime is duration required to complete a
// challenge.
ChallengeCompletionTime time.Duration `json:"challenge_completion_time"`
}

type StakePoolSettings struct {
Expand Down
2 changes: 1 addition & 1 deletion config/0chain_blobber.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ min_lock_demand: 0.1
# max_offer_duration restrict long contracts where,
# in the future, prices can be changed
max_offer_duration: 744h # 31 day
challenge_completion_time: 2m # duration to complete a challenge

# these timeouts required by blobber to check client pools, perform
# a task and redeem tokens, it should be big enough
read_lock_timeout: 1m
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.8.5-0.20220617011132-aa10bcd8eaf5
github.com/0chain/gosdk v1.8.5-0.20220616142527-4950deef2e5b
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/didip/tollbooth/v6 v6.1.2
github.com/gorilla/handlers v1.5.1
Expand Down
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.8.5-0.20220613143600-467045b66aa9 h1:cFpFnunxOMKNwAq0bX/jp1S5AWoxvwYcAf7wCHzAXUU=
github.com/0chain/gosdk v1.8.5-0.20220613143600-467045b66aa9/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/0chain/gosdk v1.8.5-0.20220616093649-03165f9e0990 h1:/JArJaa1OVlhebTSNmQzD85OWPbk+Rx0cks5wVdzCP0=
github.com/0chain/gosdk v1.8.5-0.20220616093649-03165f9e0990/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/0chain/gosdk v1.8.5-0.20220617011132-aa10bcd8eaf5 h1:DUalOG9rNmgGVhU3e7gd8uOBspd8axvBApDqIPuUiw4=
github.com/0chain/gosdk v1.8.5-0.20220617011132-aa10bcd8eaf5/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/0chain/gosdk v1.8.5-0.20220615000522-eb3ca6c70dea h1:HC7yfcjPHr2r4no/Fybt7kqtU9lE2/6mryUVYjGCr/s=
github.com/0chain/gosdk v1.8.5-0.20220615000522-eb3ca6c70dea/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/0chain/gosdk v1.8.5-0.20220616142527-4950deef2e5b h1:iyNzc0FRLs54Sg9KdAm+2xjfYOkpQ+1qKtnF8l3hLlU=
github.com/0chain/gosdk v1.8.5-0.20220616142527-4950deef2e5b/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0=
Expand Down

0 comments on commit a2eaa88

Please sign in to comment.