Skip to content

Commit

Permalink
Merge branch 'sprint-june-5' into optimize-image
Browse files Browse the repository at this point in the history
  • Loading branch information
Kishan-Dhakan committed Jul 3, 2023
2 parents 6b5c0c0 + d409748 commit 6e62af0
Show file tree
Hide file tree
Showing 66 changed files with 666 additions and 618 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/automate-add-issue-in-project.yaml
@@ -0,0 +1,16 @@
name: Add Issue to Backend Issues Project Board

on:
issues:
types:
- opened

jobs:
add-to-project:
name: Add Issue to Backend Issues Project Board
runs-on: arc-runner
steps:
- uses: actions/add-to-project@v0.4.0
with:
project-url: https://github.com/orgs/0chain/projects/${{ secrets.PROJECT_NUMBER }}
github-token: ${{ secrets.ACCESS_TOKEN }}
3 changes: 0 additions & 3 deletions .github/workflows/build-&-publish-docker-image.yml
Expand Up @@ -234,10 +234,7 @@ jobs:
validator_image: staging
authorizer_image: staging
zbox_image: staging
zblock_image: staging
zdns_image: staging
explorer_image: latest
zsearch_image: staging
zbox_cli_branch: staging
zwallet_cli_branch: staging
custom_go_sdk_version: staging
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/unit-test.yml
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [ master, staging ]
pull_request:
branches: [ master, staging ]
workflow_dispatch:

jobs:
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -407,8 +407,12 @@ Now run the script containing unit tests .
```
./docker.local/bin/unit_test.sh
```
OR to run the unit tests without the mocks,
```
./docker.local/bin/unit_test.sh --no-mocks
```

The list of packages is optional, and if provided runs only the tests from those packages. Command for running unit tests with specific packages .
The list of packages is optional, and if provided runs only the tests from those packages. The command for running unit tests with specific packages.

```
./docker.local/bin/unit_test.sh [<packages>]
Expand Down
4 changes: 1 addition & 3 deletions code/go/0chain.net/go.mod
Expand Up @@ -41,10 +41,10 @@ require (
require (
github.com/0chain/common v0.0.6-0.20230529052949-41994a93b4f9
github.com/go-faker/faker/v4 v4.1.0
github.com/google/uuid v1.3.0
github.com/jackc/pgx/v5 v5.3.1
github.com/lib/pq v1.10.9
github.com/linxGnu/grocksdb v1.8.0
github.com/minio/minio-go v6.0.14+incompatible
github.com/ory/dockertest/v3 v3.10.0
github.com/pressly/goose/v3 v3.11.2
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc
Expand All @@ -68,7 +68,6 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
Expand All @@ -94,7 +93,6 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand Down
7 changes: 1 addition & 6 deletions code/go/0chain.net/go.sum
Expand Up @@ -105,8 +105,6 @@ github.com/go-faker/faker/v4 v4.1.0/go.mod h1:uuNc0PSRxF8nMgjGrrrU4Nw5cF30Jc6Kd0
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-openapi/analysis v0.21.2/go.mod h1:HZwRk4RRisyG8vx2Oe6aqeSQcoxRp47Xkp3+K6q+LdY=
github.com/go-openapi/analysis v0.21.4 h1:ZDFLvSNxpDaomuCueM0BlSXxpANBlFYiBvr+GXrvIHc=
github.com/go-openapi/analysis v0.21.4/go.mod h1:4zQ35W4neeZTqh3ol0rv/O8JBbka9QyAgQRPp9y3pfo=
Expand Down Expand Up @@ -238,6 +236,7 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
Expand Down Expand Up @@ -311,10 +310,6 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/minio/minio-go v6.0.14+incompatible h1:fnV+GD28LeqdN6vT2XdGKW8Qe/IfjJDswNVuni6km9o=
github.com/minio/minio-go v6.0.14+incompatible/go.mod h1:7guKYtitv8dktvNUGrhzmNlA5wrAABTQXCoesZdFQO8=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/miner/testdata/config/sc.yaml
Expand Up @@ -185,6 +185,7 @@ smart_contracts:
max_challenges_per_generation: 100
# number of validators per challenge
validators_per_challenge: 2
num_validators_rewarded: 10
# max delegates per stake pool allowed by SC
max_delegates: 200
# max_charge allowed for blobbers; the charge is part of blobber rewards
Expand Down
1 change: 1 addition & 0 deletions code/go/0chain.net/smartcontract/benchmark/benchmark.go
Expand Up @@ -171,6 +171,7 @@ const (
StorageMaxMint = SmartContract + StorageSc + "max_mint"
StorageValidatorsPerChallenge = SmartContract + StorageSc + "validators_per_challenge"
StorageMaxBlobbersPerAllocation = SmartContract + StorageSc + "max_blobbers_per_allocation"
StorageNumValidatorsRewarded = SmartContract + StorageSc + "num_validators_rewarded"

StorageBlockReward = SmartContract + StorageSc + BlockReward + "block_reward"
StorageBlockRewardTriggerPeriod = SmartContract + StorageSc + BlockReward + "trigger_period"
Expand Down
Expand Up @@ -135,6 +135,7 @@ smart_contracts:
max_challenges_per_generation: 1
max_blobbers_per_allocation: 40
validators_per_challenge: 2
num_validators_rewarded: 10
readpool:
min_lock: 0.3
writepool:
Expand Down
26 changes: 9 additions & 17 deletions code/go/0chain.net/smartcontract/dbs/event/allocation.go
Expand Up @@ -27,7 +27,7 @@ type Allocation struct {
ReadPriceMax currency.Coin `json:"read_price_max"`
WritePriceMin currency.Coin `json:"write_price_min"`
WritePriceMax currency.Coin `json:"write_price_max"`
StartTime int64 `json:"start_time" gorm:"index:idx_astart_time"`
StartTime int64 `json:"start_time"`
Finalized bool `json:"finalized"`
Cancelled bool `json:"cancelled"`
UsedSize int64 `json:"used_size"`
Expand All @@ -45,6 +45,7 @@ type Allocation struct {
WritePool currency.Coin `json:"write_pool"`
ThirdPartyExtendable bool `json:"third_party_extendable"`
FileOptions uint16 `json:"file_options"`
MinLockDemand float64 `json:"min_lock_demand"`

//ref
User User `gorm:"foreignKey:Owner;references:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Expand Down Expand Up @@ -132,6 +133,7 @@ func (edb *EventDb) updateAllocations(allocs []Allocation) error {
"latest_closed_challenge_txn",
"third_party_extendable",
"file_options",
"min_lock_demand",
}

columns, err := Columnize(allocs)
Expand Down Expand Up @@ -234,17 +236,7 @@ func mergeUpdateAllocStatsEvents() *eventsMergerImpl[Allocation] {
}

func mergeAllocationStatsEvents() *eventsMergerImpl[Allocation] {
return newEventsMerger[Allocation](TagUpdateAllocationStat, withAllocStatsMerged())
}

func withAllocStatsMerged() eventMergeMiddleware {
return withEventMerge(func(a, b *Allocation) (*Allocation, error) {
a.UsedSize += b.UsedSize
a.NumWrites += b.NumWrites
a.MovedToChallenge += b.MovedToChallenge
a.MovedBack += b.MovedBack
return a, nil
})
return newEventsMerger[Allocation](TagUpdateAllocationStat, withUniqueEventOverwrite())
}

func (edb *EventDb) updateAllocationsStats(allocs []Allocation) error {
Expand Down Expand Up @@ -284,11 +276,11 @@ func (edb *EventDb) updateAllocationsStats(allocs []Allocation) error {
}

return CreateBuilder("allocations", "allocation_id", allocationIdList).
AddUpdate("used_size", usedSizeList, "allocations.used_size + t.used_size").
AddUpdate("num_writes", numWritesList, "allocations.num_writes + t.num_writes").
AddUpdate("moved_to_challenge", movedToChallengeList, "allocations.moved_to_challenge + t.moved_to_challenge").
AddUpdate("moved_back", movedBackList, "allocations.moved_back + t.moved_back").
AddUpdate("write_pool", writePoolList, "allocations.write_pool - t.moved_to_challenge + t.moved_back").Exec(edb).Error
AddUpdate("used_size", usedSizeList).
AddUpdate("num_writes", numWritesList).
AddUpdate("moved_to_challenge", movedToChallengeList).
AddUpdate("moved_back", movedBackList).
AddUpdate("write_pool", writePoolList).Exec(edb).Error
}

func mergeUpdateAllocBlobbersTermsEvents() *eventsMergerImpl[AllocationBlobberTerm] {
Expand Down
Expand Up @@ -9,11 +9,10 @@ import (

type AllocationBlobberTerm struct {
gorm.Model
AllocationID string `json:"allocation_id" gorm:"uniqueIndex:idx_alloc_blob,priority:1; not null"` // Foreign Key, priority: lowest first
BlobberID string `json:"blobber_id" gorm:"uniqueIndex:idx_alloc_blob,priority:2; not null"` // Foreign Key
ReadPrice int64 `json:"read_price"`
WritePrice int64 `json:"write_price"`
MinLockDemand float64 `json:"min_lock_demand"`
AllocationID string `json:"allocation_id" gorm:"uniqueIndex:idx_alloc_blob,priority:1; not null"` // Foreign Key, priority: lowest first
BlobberID string `json:"blobber_id" gorm:"uniqueIndex:idx_alloc_blob,priority:2; not null"` // Foreign Key
ReadPrice int64 `json:"read_price"`
WritePrice int64 `json:"write_price"`
}

func (edb *EventDb) GetAllocationBlobberTerm(allocationID string, blobberID string) (*AllocationBlobberTerm, error) {
Expand Down Expand Up @@ -81,26 +80,24 @@ func (edb *EventDb) deleteAllocationBlobberTerms(terms []AllocationBlobberTerm)

func (edb *EventDb) updateAllocationBlobberTerms(terms []AllocationBlobberTerm) error {
var (
allocationIdList []string
blobberIdList []string
readPriceList []int64
writePriceList []int64
minLockDemandList []float64
allocationIdList []string
blobberIdList []string
readPriceList []int64
writePriceList []int64
)

for _, t := range terms {
allocationIdList = append(allocationIdList, t.AllocationID)
blobberIdList = append(blobberIdList, t.BlobberID)
readPriceList = append(readPriceList, t.ReadPrice)
writePriceList = append(writePriceList, t.WritePrice)
minLockDemandList = append(minLockDemandList, t.MinLockDemand)
}

return CreateBuilder("allocation_blobber_terms", "allocation_id", allocationIdList).
AddCompositeId("blobber_id", blobberIdList).
AddUpdate("read_price", readPriceList).
AddUpdate("write_price", writePriceList).
AddUpdate("min_lock_demand", minLockDemandList).Exec(edb).Error
Exec(edb).Error
}

func (edb *EventDb) addOrOverwriteAllocationBlobberTerms(terms []AllocationBlobberTerm) error {
Expand All @@ -126,4 +123,4 @@ func (edb *EventDb) GetAllocationsByBlobberId(blobberId string, limit common2.Pa
}).
Debug().Find(&result).Error
return result, err
}
}

0 comments on commit 6e62af0

Please sign in to comment.