Skip to content

Commit 52ff23e

Browse files
authored
Merge pull request #1445 from 0chain/sprint-1.16
Sprint 1.16
2 parents 82375a2 + d6dd9a6 commit 52ff23e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+7753
-659
lines changed

.github/workflows/build-&-publish-docker-image.yml

Lines changed: 13 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -215,83 +215,18 @@ jobs:
215215
version: '1.7'
216216
force: 'false'
217217

218-
- name: "Create Tenderly fork"
218+
- name: "Create Tenderly virtual testnet"
219219
run: |
220220
echo "TENDERLY_CREATION_INFO=$(curl -X POST \
221-
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
222-
-H "Content-Type: application/json" \
223-
-d '{"alias":"mainnet-dev-${{ env.RUNNER_NUMBER }}-${{ github.run_id }}${{ github.run_attempt }}", "description":"", "block_number": 18539779, "network_id":"1"}' \
224-
https://api.tenderly.co/api/v1/account/zus_network/project/project/fork)" >> $GITHUB_ENV
221+
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
222+
-H "Content-Type: application/json" \
223+
-d '{"slug":"mainnet-dev-${{ env.RUNNER_NUMBER }}-${{ github.run_id }}","displayName":"mainnet-dev-${{ env.RUNNER_NUMBER }}-${{ github.run_id }}","description":"","visibility":"TEAM","tags":{"purpose":"development"},"networkConfig":{"networkId":"1","blockNumber":"18512782","chainConfig":{"chainId":"1"},"baseFeePerGas":"1"},"explorerConfig":{"enabled":false,"verificationVisibility":"bytecode"},"syncState":false}' \
224+
https://api.tenderly.co/api/v1/account/zus_network/project/project/testnet/container)" >> $GITHUB_ENV
225225
226-
- name: "Parse Tenderly fork creation transaction result"
226+
- name: "Parse Tenderly virtual testnet creation transaction result"
227227
run: |
228-
echo "TENDERLY_FORK_ID=$(echo '${{ env.TENDERLY_CREATION_INFO }}' | jq -r '.simulation_fork.id')" >> $GITHUB_ENV
229-
echo "TENDERLY_ROOT_TRANSACTION_ID=$(echo '${{ env.TENDERLY_CREATION_INFO }}' | jq -r '.root_transaction.id')" >> $GITHUB_ENV
230-
231-
- name: "Retrieve Tenderly fork block number"
232-
run: |
233-
echo "TENDERLY_FORK_BLOCK_NUMBER=$(curl -X GET \
234-
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
235-
-H "Content-Type: application/json" \
236-
https://api.tenderly.co/api/v1/network/1/block-number | jq -r '.block_number')" >> $GITHUB_ENV
237-
238-
echo "TENDERLY_FORK_BLOCK_NUMBER=$((${{ env.TENDERLY_FORK_BLOCK_NUMBER }} + 1))" >> GITHUB_ENV
239-
240-
- name: "Transfer Bridge ownership in Tenderly fork"
241-
run: |
242-
echo "TENDERLY_ROOT_TRANSACTION_ID=$(curl -X POST \
243-
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
244-
-H "Content-Type: application/json" \
245-
-d '{
246-
"network_id": "1",
247-
"block_number": ${{ env.TENDERLY_FORK_BLOCK_NUMBER }},
248-
"transaction_index": null,
249-
"from": "0xed8f3170db6d1a71c8fa6d8d73cc2c51db95d5a4",
250-
"input": "0xf2fde38b0000000000000000000000008e25cfd9bd6c0ca67a5522cd920b3c66d39d6e97",
251-
"to": "0x7700d773022b19622095118fadf46f7b9448be9b",
252-
"gas": 8000000,
253-
"gas_price": "0",
254-
"value": "0",
255-
"access_list": [],
256-
"generate_access_list": true,
257-
"save": true,
258-
"source": "dashboard",
259-
"block_header": null,
260-
"root": "${{ env.TENDERLY_ROOT_TRANSACTION_ID }}",
261-
"skip_fork_head_update": false,
262-
"alias": "",
263-
"description": "Transfer ownership to 0x8E25cfd9bd6c0ca67a5522cd920b3c66D39d6E97"
264-
}' \
265-
https://api.tenderly.co/api/v1/account/zus_network/project/project/fork/${{ env.TENDERLY_FORK_ID }}/simulate | jq -r '.simulation.id')" >> $GITHUB_ENV
266-
267-
echo "TENDERLY_FORK_BLOCK_NUMBER=$((${{ env.TENDERLY_FORK_BLOCK_NUMBER }} + 1))" >> GITHUB_ENV
268-
269-
- name: "Transfer Authorizers ownership in Tenderly fork"
270-
run: |
271-
curl -X POST \
272-
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
273-
-H "Content-Type: application/json" \
274-
-d '{
275-
"network_id": "1",
276-
"block_number": ${{ env.TENDERLY_FORK_BLOCK_NUMBER }},
277-
"transaction_index": null,
278-
"from": "0xed8f3170db6d1a71c8fa6d8d73cc2c51db95d5a4",
279-
"input": "0xf2fde38b0000000000000000000000008e25cfd9bd6c0ca67a5522cd920b3c66d39d6e97",
280-
"to": "0x481dab4407b9880de0a68dc62e6af611c4949e42",
281-
"gas": 8000000,
282-
"gas_price": "0",
283-
"value": "0",
284-
"access_list": [],
285-
"generate_access_list": true,
286-
"save": true,
287-
"source": "dashboard",
288-
"block_header": null,
289-
"root": "${{ env.TENDERLY_ROOT_TRANSACTION_ID }}",
290-
"skip_fork_head_update": false,
291-
"alias": "",
292-
"description": "Transfer ownership to 0x8E25cfd9bd6c0ca67a5522cd920b3c66D39d6E97"
293-
}' \
294-
https://api.tenderly.co/api/v1/account/zus_network/project/project/fork/${{ env.TENDERLY_FORK_ID }}/simulate
228+
echo "TENDERLY_VIRTUAL_TESTNET_ID=$(echo '${{ env.TENDERLY_CREATION_INFO }}' | jq -r '.container.id')" >> $GITHUB_ENV
229+
echo "TENDERLY_VIRTUAL_TESTNET_RPC_ID=$(echo '${{ env.TENDERLY_CREATION_INFO }}' | jq -r '.container.connectivityConfig.endpoints[0].id')" >> $GITHUB_ENV
295230
296231
- name: "Deploy 0Chain"
297232
uses: 0chain/actions/deploy-0chain@master
@@ -302,10 +237,10 @@ jobs:
302237
blobber_image: ${{ env.TAG }}-${{ env.SHORT_SHA }}
303238
validator_image: ${{ env.TAG }}-${{ env.SHORT_SHA }}
304239
SUBGRAPH_API_URL: ${{ secrets.SUBGRAPH_API_URL }}
305-
TENDERLY_FORK_ID: ${{ env.TENDERLY_FORK_ID }}
240+
TENDERLY_VIRTUAL_TESTNET_RPC_ID: ${{ env.TENDERLY_VIRTUAL_TESTNET_RPC_ID }}
306241
graphnode_sc: ${{ secrets.GRAPHNODE_SC }}
307242
graphnode_network: ${{ secrets.GRAPHNODE_NETWORK }}
308-
graphnode_ethereum_node_url: https://rpc.tenderly.co/fork/${{ env.TENDERLY_FORK_ID }}
243+
graphnode_ethereum_node_url: https://virtual.mainnet.rpc.tenderly.co/${{ env.TENDERLY_VIRTUAL_TESTNET_RPC_ID }}
309244
svc_account_secret: ${{ secrets.SVC_ACCOUNT_SECRET }}
310245

311246
- name: "Run System tests"
@@ -319,18 +254,18 @@ jobs:
319254
run_flaky_tests: false
320255
retry_failures: true
321256
run_smoke_tests: ${{ github.ref != 'refs/heads/staging' && github.base_ref != 'staging' && github.ref != 'refs/heads/master' && github.base_ref != 'master' }}
322-
TENDERLY_FORK_ID: ${{ env.TENDERLY_FORK_ID }}
257+
TENDERLY_VIRTUAL_TESTNET_RPC_ID: ${{ env.TENDERLY_VIRTUAL_TESTNET_RPC_ID }}
323258
DEVOPS_CHANNEL_WEBHOOK_URL: ${{ secrets.DEVOPS_CHANNEL_WEBHOOK_URL }}
324259
S3_ACCESS_KEY: ${{ secrets.S3_ACCESS_KEY }}
325260
S3_SECRET_KEY: ${{ secrets.S3_SECRET_KEY }}
326261

327-
- name: "Remove Tenderly fork"
262+
- name: "Remove Tenderly virtual testnet"
328263
if: always()
329264
run: |
330265
curl -X DELETE \
331266
-H "x-access-key: ${{ secrets.TENDERLY_SECRET }}" \
332267
-H "Content-Type: application/json" \
333-
https://api.tenderly.co/api/v1/account/zus_network/project/project/fork/${{ env.TENDERLY_FORK_ID }}
268+
https://api.tenderly.co/api/v1/account/zus_network/project/project/testnet/container/${{ env.TENDERLY_VIRTUAL_TESTNET_ID }}
334269
335270
- name: "Set PR status as ${{ job.status }}"
336271
if: ${{ (success() || failure()) && steps.findPr.outputs.number }}

.github/workflows/tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ jobs:
3535
- name: Build Base
3636
run: ./docker.local/bin/build.base.sh
3737

38-
- name: Check swagger generation
39-
run: docker.local/bin/test.swagger.sh
40-
4138
- name: Golangci-lint
4239
uses: golangci/golangci-lint-action@v3
4340
with:

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,10 @@ else
188188
sed -i "s/BUF_VERSION := [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/BUF_VERSION := $(VERSION)/g" Makefile
189189
endif
190190
endif
191+
192+
.PHONY: markdown-docs
193+
markdown-docs:
194+
swagger generate spec -o ./swagger.yaml -w ./code/go/0chain.net -m
195+
sed -i '' "s/in\:\ form/in\:\ formData/g" ./swagger.yaml
196+
yq -i '(.paths.*.*.parameters.[] | select(.in == "formData") | select(.type == "object")).type = "file"' swagger.yaml
197+
swagger generate markdown -f ./swagger.yaml --output=swagger.md

code/go/0chain.net/blobber/main.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"github.com/0chain/blobber/code/go/0chain.net/core/common"
45
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
56
"github.com/0chain/blobber/code/go/0chain.net/core/node"
67
)
@@ -43,10 +44,14 @@ func main() {
4344
// when enabled "// +build integration_tests", this sets blobber for conductor tests.
4445
prepareBlobber(node.Self.ID)
4546

46-
if err := registerOnChain(); err != nil {
47-
logging.Logger.Error("Error register on blockchain" + err.Error())
48-
panic(err)
49-
}
47+
go func() {
48+
if err := registerOnChain(); err != nil {
49+
logging.Logger.Error("Error register on blockchain" + err.Error())
50+
panic(err)
51+
}
52+
53+
common.SetBlobberRegistered(true)
54+
}()
5055

5156
if err := setStorageScConfigFromChain(); err != nil {
5257
logging.Logger.Error("Error setStorageScConfigFromChain" + err.Error())

code/go/0chain.net/blobber/zcn.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package main
22

33
import (
44
"fmt"
5-
"time"
6-
75
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/config"
86
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
97
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/handler"
108
"github.com/0chain/blobber/code/go/0chain.net/core/chain"
119
"github.com/0chain/blobber/code/go/0chain.net/core/common"
1210
handleCommon "github.com/0chain/blobber/code/go/0chain.net/core/common/handler"
11+
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
1312
"github.com/0chain/blobber/code/go/0chain.net/core/node"
1413
"github.com/0chain/gosdk/zboxcore/sdk"
1514
"github.com/0chain/gosdk/zcncore"
15+
"go.uber.org/zap"
16+
"time"
1617
)
1718

1819
func registerOnChain() error {
@@ -31,8 +32,9 @@ func registerOnChain() error {
3132
return err
3233
}
3334

34-
// setup blobber (add or update) on the blockchain (multiple attempts)
35-
for i := 1; i <= 10; i++ {
35+
// setup blobber (add) on the blockchain (multiple attempts)
36+
i := 1
37+
for {
3638
if i == 1 {
3739
fmt.Printf("\r + connect to sharders:")
3840
} else {
@@ -50,6 +52,9 @@ func registerOnChain() error {
5052
err = handler.RegisterBlobber(common.GetRootContext())
5153
if err == nil {
5254
break
55+
} else {
56+
i++
57+
logging.Logger.Error("add_blobber_error", zap.Error(err))
5358
}
5459
}
5560

code/go/0chain.net/blobbercore/allocation/allocationchange.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (change *AllocationChange) Save(ctx context.Context) error {
100100

101101
func (change *AllocationChange) Update(ctx context.Context) error {
102102
db := datastore.GetStore().GetTransaction(ctx)
103-
return db.Table(change.TableName()).Where("lookup_hash = ?", change.LookupHash).Updates(map[string]interface{}{
103+
return db.Table(change.TableName()).Where("connection_id = ? AND lookup_hash = ?", change.ConnectionID, change.LookupHash).Updates(map[string]interface{}{
104104
"size": change.Size,
105105
"updated_at": time.Now(),
106106
"input": change.Input,
@@ -174,10 +174,11 @@ func GetAllocationChanges(ctx context.Context, connectionID, allocationID, clien
174174
func GetConnectionObj(ctx context.Context, connectionID, allocationID, clientID string) (*AllocationChangeCollector, error) {
175175
cc := &AllocationChangeCollector{}
176176
db := datastore.GetStore().GetTransaction(ctx)
177-
err := db.Where("id = ? and allocation_id = ? and client_id = ?",
177+
err := db.Where("id = ? and allocation_id = ? and client_id = ? AND status <> ?",
178178
connectionID,
179179
allocationID,
180180
clientID,
181+
DeletedConnection,
181182
).Take(cc).Error
182183

183184
if err == nil {
@@ -189,7 +190,7 @@ func GetConnectionObj(ctx context.Context, connectionID, allocationID, clientID
189190
cc.AllocationID = allocationID
190191
cc.ClientID = clientID
191192
cc.Status = NewConnection
192-
err = cc.Create(ctx)
193+
err = cc.Save(ctx)
193194
if err != nil {
194195
return nil, err
195196
}
@@ -400,7 +401,7 @@ func deleteFromFileStore(ctx context.Context, allocationID string) error {
400401
return datastore.GetStore().WithNewTransaction(func(ctx context.Context) error {
401402
db := datastore.GetStore().GetTransaction(ctx)
402403

403-
err := db.Model(&reference.Ref{}).Unscoped().Select("id", "validation_root", "thumbnail_hash").
404+
err := db.Model(&reference.Ref{}).Unscoped().Select("id", "validation_root", "thumbnail_hash", "filestore_version").
404405
Where("allocation_id=? AND is_precommit=? AND type=? AND deleted_at is not NULL", allocationID, true, reference.FILE).
405406
FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
406407

code/go/0chain.net/blobbercore/allocation/connection.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
var (
1717
// ConnectionObjCleanInterval start to clean the connectionObjMap
18-
ConnectionObjCleanInterval = 10 * time.Minute
18+
ConnectionObjCleanInterval = 45 * time.Minute
1919
// ConnectionObjTimout after which connectionObj entry should be invalid
2020
ConnectionObjTimeout = 30 * time.Minute
2121
)
@@ -182,7 +182,11 @@ func SaveFileChange(ctx context.Context, connectionID, pathHash, fileName string
182182
change.lock.Lock()
183183
defer change.lock.Unlock()
184184
connectionObj.lock.Unlock()
185-
err := cmd.AddChange(ctx)
185+
_, err := GetConnectionObj(ctx, connectionID, connectionObj.AllocationID, connectionObj.ClientID)
186+
if err != nil {
187+
return saveChange, err
188+
}
189+
err = cmd.AddChange(ctx)
186190
if err != nil {
187191
return saveChange, err
188192
}

code/go/0chain.net/blobbercore/allocation/deletefilechange.go

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@ package allocation
33
import (
44
"context"
55
"encoding/json"
6-
"fmt"
76
"path/filepath"
87
"sync"
98

10-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/datastore"
11-
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/filestore"
129
"github.com/0chain/blobber/code/go/0chain.net/blobbercore/reference"
1310
"github.com/0chain/blobber/code/go/0chain.net/core/common"
14-
"github.com/0chain/blobber/code/go/0chain.net/core/logging"
15-
"gorm.io/gorm"
16-
17-
"go.uber.org/zap"
1811
)
1912

2013
var (
@@ -58,73 +51,8 @@ func (nf *DeleteFileChange) DeleteTempFile() error {
5851
return nil
5952
}
6053

61-
func (nf *DeleteFileChange) CommitToFileStore(ctx context.Context, mut *sync.Mutex) error {
62-
db := datastore.GetStore().GetTransaction(ctx)
63-
type Result struct {
64-
Id string
65-
ValidationRoot string
66-
ThumbnailHash string
67-
FilestoreVersion int
68-
}
69-
70-
limitCh := make(chan struct{}, 10)
71-
wg := &sync.WaitGroup{}
72-
var results []Result
73-
mut.Lock()
74-
err := db.Model(&reference.Ref{}).Unscoped().
75-
Select("id", "validation_root", "thumbnail_hash", "filestore_version").
76-
Where("allocation_id=? AND path LIKE ? AND type=? AND deleted_at is not NULL",
77-
nf.AllocationID, nf.Path+"%", reference.FILE).
78-
FindInBatches(&results, 100, func(tx *gorm.DB, batch int) error {
79-
80-
for _, res := range results {
81-
var count int64
82-
tx.Model(&reference.Ref{}).
83-
Where("allocation_id=? AND validation_root=?", nf.AllocationID, res.ValidationRoot).
84-
Count(&count)
85-
86-
if count != 0 && res.ThumbnailHash == "" {
87-
continue
88-
}
89-
90-
limitCh <- struct{}{}
91-
wg.Add(1)
92-
93-
go func(res Result, count int64) {
94-
defer func() {
95-
<-limitCh
96-
wg.Done()
97-
}()
98-
99-
if count == 0 {
100-
err := filestore.GetFileStore().DeleteFile(nf.AllocationID, res.ValidationRoot, res.FilestoreVersion)
101-
if err != nil {
102-
logging.Logger.Error(fmt.Sprintf("Error while deleting file: %s", err.Error()),
103-
zap.String("validation_root", res.ValidationRoot))
104-
}
105-
}
106-
// We don't increase alloc size for thumbnail so we don't need to decrease it
107-
// if res.ThumbnailHash != "" {
108-
// err := filestore.GetFileStore().DeleteFile(nf.AllocationID, res.ThumbnailHash)
109-
// if err != nil {
110-
// logging.Logger.Error(fmt.Sprintf("Error while deleting thumbnail: %s", err.Error()),
111-
// zap.String("thumbnail", res.ThumbnailHash))
112-
// }
113-
// }
114-
115-
}(res, count)
116-
117-
}
118-
return nil
119-
}).Error
120-
mut.Unlock()
121-
wg.Wait()
122-
123-
return err
124-
// return db.Model(&reference.Ref{}).Unscoped().
125-
// Delete(&reference.Ref{},
126-
// "allocation_id = ? AND path LIKE ? AND deleted_at IS NOT NULL",
127-
// nf.AllocationID, nf.Path+"%").Error
54+
func (nf *DeleteFileChange) CommitToFileStore(_ context.Context, _ *sync.Mutex) error {
55+
return nil
12856
}
12957

13058
func (nf *DeleteFileChange) GetPath() []string {

code/go/0chain.net/blobbercore/allocation/entity.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const (
3838
CanRenameMask = uint16(32) // 0010 0000
3939
)
4040

41+
// swagger:model Allocation
4142
type Allocation struct {
4243
ID string `gorm:"column:id;size:64;primaryKey"`
4344
Tx string `gorm:"column:tx;size:64;not null;unique;index:idx_unique_allocations_tx,unique"`
@@ -207,7 +208,7 @@ func AddToPending(ctx context.Context, clientID, allocationID string, pendingWri
207208
defer lock.Unlock()
208209

209210
pending := new(Pending)
210-
err = db.Model(&Pending{}).Where("id=?", key).First(pending).Error
211+
err = db.Model(&Pending{}).Where("id=?", key).Take(pending).Error
211212
switch {
212213
case err == nil:
213214
pending.PendingWrite += pendingWrite
@@ -239,6 +240,7 @@ const (
239240
)
240241

241242
// Terms for allocation by its Tx.
243+
// swagger:model
242244
type Terms struct {
243245
ID int64 `gorm:"column:id;primaryKey"`
244246
BlobberID string `gorm:"blobber_id;size:64;not null"`

0 commit comments

Comments
 (0)