Skip to content

Commit

Permalink
Merge branch 'sprint-july-4' into refactor/db-txn
Browse files Browse the repository at this point in the history
  • Loading branch information
din-mukhammed authored Aug 14, 2023
2 parents b7213aa + 3c08785 commit 6e789ab
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 49 deletions.
38 changes: 22 additions & 16 deletions code/go/0chain.net/blobbercore/reference/referencepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ func GetRefs(ctx context.Context, allocationID, path, offsetPath, _type string,

wg := sync.WaitGroup{}
wg.Add(2)
errChan := make(chan error, 2)
go func() {
_ = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
err1 := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)
db1 := tx.Model(&Ref{}).Where("allocation_id = ?", allocationID).
Where("path = ?", path).Or("path LIKE ?", path+"%")
db1 := tx.Model(&Ref{}).Where("allocation_id = ? AND (path=? OR path LIKE ?)", allocationID, path, path+"%")
if _type != "" {
db1 = db1.Where("type = ?", _type)
}
Expand All @@ -259,34 +259,42 @@ func GetRefs(ctx context.Context, allocationID, path, offsetPath, _type string,
db1 = db1.Where("path > ?", offsetPath)

db1 = db1.Order("path")
err = db1.Limit(pageLimit).Find(&pRefs).Error
err1 := db1.Limit(pageLimit).Find(&pRefs).Error
wg.Done()

return nil
return err1
})
if err1 != nil {
errChan <- err1
}

}()

go func() {
_ = datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
err2 := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)
db2 := tx.Model(&Ref{}).Where("allocation_id = ?", allocationID).
Where("path = ?", path).Or("path LIKE ?", path+"%")
db2 := tx.Model(&Ref{}).Where("allocation_id = ? AND (path=? OR path LIKE ?)", allocationID, path, path+"%")
if _type != "" {
db2 = db2.Where("type = ?", _type)
}
if level != 0 {
db2 = db2.Where("level = ?", level)
}
db2.Count(&totalRows)
err2 := db2.Count(&totalRows).Error
wg.Done()

return nil
return err2
})
if err2 != nil {
errChan <- err2
}
}()
wg.Wait()
if err != nil {
return
close(errChan)
for err := range errChan {
if err != nil {
return nil, 0, "", err
}
}

refs = &pRefs
Expand All @@ -313,8 +321,7 @@ func GetUpdatedRefs(ctx context.Context, allocationID, path, offsetPath, _type,
go func() {
err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)
db1 := tx.Model(&Ref{}).Where("allocation_id = ?", allocationID).
Where("path = ?", path).Or("path LIKE ?", path+"%")
db1 := tx.Model(&Ref{}).Where("allocation_id = ? AND (path=? OR path LIKE ?)", allocationID, path, path+"%")
if _type != "" {
db1 = db1.Where("type = ?", _type)
}
Expand Down Expand Up @@ -343,8 +350,7 @@ func GetUpdatedRefs(ctx context.Context, allocationID, path, offsetPath, _type,
go func() {
err := datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
tx := datastore.GetStore().GetTransaction(ctx)
db2 := tx.Model(&Ref{}).Where("allocation_id = ?", allocationID).
Where("path = ?", path).Or("path LIKE ?", path+"%")
db2 := tx.Model(&Ref{}).Where("allocation_id = ? AND (path=? OR path LIKE ?)", allocationID, path, path+"%")
if _type != "" {
db2 = db2.Where("type > ?", level)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,11 @@ func challengeHandler(ctx context.Context, r *http.Request) (interface{}, error)

err = challengeRequest.VerifyChallenge(challengeObj, allocationObj)
if err != nil {
statsMutex.Lock()
updateStats(false)
statsMutex.Unlock()
return InvalidValidationTicket(challengeObj, err)
}

statsMutex.Lock()
updateStats(false)
statsMutex.Unlock()
updateStats(true)

return ValidValidationTicket(challengeObj, challengeRequest.ChallengeID, challengeHash)
}
Expand Down
18 changes: 2 additions & 16 deletions config/0chain_blobber.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,6 @@ read_price: 0.00 # token / GB for reading
write_price: 0.10 # token / GB / time_unit for writing
price_in_usd: false
price_worker_in_hours: 12
# the time_unit configured in Storage SC and can be given using
#
# ./zbox sc-config
#

# min_lock_demand is value in [0; 1] range; it represents number of tokens the
# blobber earned even if a user will not read or write something
# to an allocation; the number of tokens will be calculated by the following
# formula (regarding the time_unit and allocation duration)
#
# allocation_size * write_price * min_lock_demand
#
min_lock_demand: 0.1


# update_allocations_interval used to refresh known allocation objects from SC
update_allocations_interval: 1m
Expand All @@ -38,11 +24,11 @@ max_dirs_files: 50000

# delegate wallet (must be set)
delegate_wallet: '9c693cb14f29917968d6e8c909ebbea3425b4c1bc64b6732cadc2a1869f49be9'
# maximum allowed number of stake holders
`# maximum allowed number of stake holders
num_delegates: 50
# service charge of the blobber
service_charge: 0.10
# min submit from miners
# min submit from miners`
min_submit: 50
# min confirmation from sharder
min_confirmation: 50
Expand Down
12 changes: 0 additions & 12 deletions docker.local/conductor-config/0chain_blobber.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,7 @@ read_price: 0.01 # token / GB for reading
write_price: 0.10 # token / GB / time_unit for writing
price_in_usd: false
price_worker_in_hours: 12
# the time_unit configured in Storage SC and can be given using
#
# ./zbox sc-config
#

# min_lock_demand is value in [0; 1] range; it represents number of tokens the
# blobber earned even if a user will not read or write something
# to an allocation; the number of tokens will be calculated by the following
# formula (regarding the time_unit and allocation duration)
#
# allocation_size * write_price * min_lock_demand
#
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
Expand Down

0 comments on commit 6e789ab

Please sign in to comment.