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

Enterprise blobber #1566

Draft
wants to merge 58 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
f9eb675
add version marker and block hasher
Hitenjain14 Jul 21, 2024
02e203d
add repair info in commit worker
Hitenjain14 Jul 21, 2024
c981f06
add check for repair marker
Hitenjain14 Jul 23, 2024
b5cbb79
add allocation version and check for directory
Hitenjain14 Jul 24, 2024
526a117
prefix delete
Hitenjain14 Jul 25, 2024
6486442
fix consensus in delete
Hitenjain14 Jul 25, 2024
f9f8237
fix consensus thresh check
Hitenjain14 Jul 26, 2024
e015027
fix path level in delete
Hitenjain14 Jul 26, 2024
a8bf8bb
remove vt from downloadworker
Hitenjain14 Jul 26, 2024
b91b592
rm vt in reader
Hitenjain14 Jul 27, 2024
9beaccc
Merge branch 'feat/enterprise-blobber' of https://github.com/0chain/g…
Hitenjain14 Jul 27, 2024
f5b51c0
remove single blobber for single client mode
Hitenjain14 Jul 27, 2024
4d33f27
add check for nil ref
Hitenjain14 Jul 27, 2024
796de38
remove mask reset
Hitenjain14 Jul 27, 2024
da1aa55
check change count
Hitenjain14 Jul 27, 2024
a9814df
chane ref check
Hitenjain14 Jul 27, 2024
08de511
remove validation root from Ref
Hitenjain14 Jul 29, 2024
e7df719
add list logs
Hitenjain14 Jul 31, 2024
3f00405
Merge branch 'feat/enterprise-blobber' of https://github.com/0chain/g…
Hitenjain14 Jul 31, 2024
c2e8b89
add response
Hitenjain14 Jul 31, 2024
4496ab6
add debug logs
Hitenjain14 Jul 31, 2024
daa353d
add log for selected file ref
Hitenjain14 Jul 31, 2024
974959f
add check for rate limit
Hitenjain14 Jul 31, 2024
ec1a470
remove get ref log
Hitenjain14 Jul 31, 2024
facdb4f
add repair for enterprise blobbers
Hitenjain14 Aug 5, 2024
d15f3ce
add delete for dir remotepath in move
Hitenjain14 Aug 7, 2024
f2bb064
fix no change check
Hitenjain14 Aug 7, 2024
b0e385f
fix consensus and add check for no change err
Hitenjain14 Aug 7, 2024
a2081f3
fix list completed repair
Hitenjain14 Aug 7, 2024
af515ba
use dir as destpath
Hitenjain14 Aug 8, 2024
e973828
base of dest name
Hitenjain14 Aug 8, 2024
f4ba999
fix copy op
Hitenjain14 Aug 8, 2024
94ef0df
check copy destpath
Hitenjain14 Aug 8, 2024
dbbc11b
join base and dest path
Hitenjain14 Aug 8, 2024
8390f11
set path hash
Hitenjain14 Aug 9, 2024
c552f97
add size for root dir
Hitenjain14 Aug 10, 2024
c14befd
Merge branch 'feat/enterprise-blobber' of https://github.com/0chain/g…
Hitenjain14 Aug 10, 2024
645ded9
check vm
Hitenjain14 Aug 13, 2024
007b982
move upload success to debug
Hitenjain14 Aug 14, 2024
b293286
Merge branch 'sprint-1.17' into feat/enterprise-blobber
Hitenjain14 Aug 16, 2024
a9a39a9
Merge branch 'sprint-1.17' of https://github.com/0chain/gosdk into fe…
Hitenjain14 Aug 16, 2024
2119c4a
fix nested move and rename
Hitenjain14 Aug 22, 2024
6648ada
fix nested rename
Hitenjain14 Aug 23, 2024
acf47eb
rmv log for invalid path
Hitenjain14 Aug 23, 2024
970cd10
Merge branch 'sprint-1.17' of https://github.com/0chain/gosdk into fe…
Hitenjain14 Aug 25, 2024
50adab4
Merge remote-tracking branch 'origin' into feat/enterprise-blobber
Hitenjain14 Aug 27, 2024
75bab85
Merge remote-tracking branch 'origin' into feat/enterprise-blobber
Hitenjain14 Sep 3, 2024
f71928d
Merge branch 'staging' into feat/enterprise-blobber
Hitenjain14 Sep 23, 2024
c8f84a9
Merge branch 'staging' into feat/enterprise-blobber
Hitenjain14 Sep 24, 2024
aaf11db
Merge branch 'staging' into feat/enterprise-blobber
Jayashsatolia403 Sep 24, 2024
271ccc6
Merge remote-tracking branch 'origin' into feat/enterprise-blobber
Hitenjain14 Oct 12, 2024
237970b
comment test
Hitenjain14 Oct 12, 2024
43dcb10
Merge branch 'feat/enterprise-blobber' of https://github.com/0chain/g…
Hitenjain14 Oct 12, 2024
d4d99f5
fix release of buffer
Hitenjain14 Oct 23, 2024
655bacd
change cdn and wasm path
Hitenjain14 Nov 8, 2024
f967f8a
update go version in make wasm
Hitenjain14 Nov 8, 2024
2f06303
add method for wasm type
Hitenjain14 Nov 14, 2024
d8f100c
set wasm type in window object
Hitenjain14 Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/build-sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Set up Go 1.22
uses: actions/setup-go@v3
with:
go-version: 1.22
go-version: 1.22.5

- name: Clean build
run: make clean-mobilesdk
Expand Down Expand Up @@ -99,7 +99,7 @@ jobs:
- name: Set up Go 1.22
uses: actions/setup-go@v3
with:
go-version: 1.22
go-version: 1.22.5

- name: Install deps
run: |
Expand Down Expand Up @@ -202,7 +202,7 @@ jobs:
- name: Set up Go 1.22
uses: actions/setup-go@v3
with:
go-version: 1.22
go-version: 1.22.5

- name: Clean build
run: make clean-mobilesdk
Expand Down Expand Up @@ -274,7 +274,7 @@ jobs:
- name: Set up Go 1.22
uses: actions/setup-go@v3
with:
go-version: 1.22
go-version: 1.22.5

- name: Install deps
run: |
Expand Down Expand Up @@ -338,7 +338,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.21.5
go-version: 1.22.5

- name: Checkout
uses: actions/checkout@v2
Expand All @@ -349,7 +349,7 @@ jobs:
sudo apt-get -y install build-essential nghttp2 libnghttp2-dev libssl-dev wget

- name: Build
run: docker run --rm -v $PWD:/gosdk -w /gosdk golang:1.21.5 make wasm-build
run: docker run --rm -v $PWD:/gosdk -w /gosdk golang:1.22.5 make wasm-build

- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.21.5
go-version: 1.22.5

- uses: actions/checkout@v3

Expand All @@ -51,7 +51,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.21.5
go-version: 1.22.5

- name: Install deps
run: |
Expand Down Expand Up @@ -170,7 +170,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.21.5
go-version: 1.22.5

- uses: actions/setup-node@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/0chain/gosdk

go 1.21
go 1.22.5

require (
github.com/0chain/common v0.0.6-0.20230127095721-8df4d1d72565
Expand Down
8 changes: 8 additions & 0 deletions wasmsdk/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,11 @@ func (h *hasher) WriteToValidationMT(_ []byte) error {
func (h *hasher) Finalize() error {
return nil
}

func (h *hasher) GetBlockHash() (string, error) {
return "", nil
}

func (h *hasher) WriteToBlockHasher(buf []byte) error {
return nil
}
2 changes: 1 addition & 1 deletion wasmsdk/jsbridge/template_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func buildJS(args, env []string, wasmPath string, tpl []byte) (string, error) {
if suffix == "" {
suffix = "dev"
}
cdnPath := fmt.Sprintf("https://d2os1u2xwjukgr.cloudfront.net/%s/zcn.wasm", suffix)
cdnPath := fmt.Sprintf("https://webapps-staticfiles.s3.us-east-2.amazonaws.com/%s/enterprise-zcn.wasm", suffix)
data := templateData{
Path: cdnPath,
Args: args,
Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/jsbridge/webworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewWasmWebWorker(blobberID, blobberURL, clientID, clientKey, peerPublicKey,
"IS_SPLIT=" + strconv.FormatBool(isSplit),
"MNEMONIC=" + mnemonic,
"ZAUTH_SERVER=" + gZauthServer},
Path: "zcn.wasm",
Path: "enterprise-zcn.wasm",
subscribers: make(map[string]chan worker.MessageEvent),
}

Expand Down
2 changes: 1 addition & 1 deletion wasmsdk/jsbridge/zcnworker.js.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.21.5/misc/wasm/wasm_exec.js','https://cdn.jsdelivr.net/gh/herumi/[email protected]/browser/bls.js');
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.22.5/misc/wasm/wasm_exec.js','https://cdn.jsdelivr.net/gh/herumi/[email protected]/browser/bls.js');

const go = new Go();
go.argv = {{.ArgsToJS}}
Expand Down
3 changes: 3 additions & 0 deletions wasmsdk/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func main() {
"getLookupHash": getLookupHash,
"createThumbnail": createThumbnail,
"makeSCRestAPICall": makeSCRestAPICall,
"getWasmType": getWasmType,

//blobber
"delete": Delete,
Expand Down Expand Up @@ -340,6 +341,7 @@ func main() {

fmt.Println("__wasm_initialized__ = true;")
zcn.Set("__wasm_initialized__", true)
zcn.Set("wasmType", "enterprise")
} else {
PrintError("__zcn_wasm__.sdk is not installed yet")
}
Expand All @@ -350,6 +352,7 @@ func main() {
}

if mode != "" {
fmt.Println("enterprise wasm sdk")
respChan := make(chan string, 1)
jsProxy := window.Get("__zcn_worker_wasm__")
if !(jsProxy.IsNull() || jsProxy.IsUndefined()) {
Expand Down
4 changes: 4 additions & 0 deletions wasmsdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func getVersion() string {
return sdk.GetVersion()
}

func getWasmType() string {
return "enterprise"
}

var sdkLogger *logger.Logger
var zcnLogger *logger.Logger
var logEnabled = false
Expand Down
11 changes: 0 additions & 11 deletions zboxcore/allocationchange/newfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,12 @@ func (ch *NewFileChange) ProcessChange(rootRef *fileref.Ref, fileIDMeta map[stri
return
}

if ch.File.ValidationRoot == "" {
err = errors.New("empty validation root field")
return
}

fileHashSign, err := client.Sign(ch.File.ActualFileHash)
if err != nil {
return
}

validationRootSign, err := client.Sign(fileHashSign + ch.File.ValidationRoot)
if err != nil {
return
}

ch.File.ActualFileHashSignature = fileHashSign
ch.File.ValidationRootSignature = validationRootSign

rootRef.HashToBeComputed = true
dirRef := rootRef
Expand Down
11 changes: 0 additions & 11 deletions zboxcore/allocationchange/updatefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,12 @@ func (ch *UpdateFileChange) ProcessChange(rootRef *fileref.Ref, _ map[string]str
return
}

if ch.NewFile.ValidationRoot == "" {
err = fmt.Errorf("empty validation root field")
return
}

fileHashSign, err := client.Sign(ch.NewFile.ActualFileHash)
if err != nil {
return
}

validationRootSign, err := client.Sign(fileHashSign + ch.NewFile.ValidationRoot)
if err != nil {
return
}

ch.NewFile.ActualFileHashSignature = fileHashSign
ch.NewFile.ValidationRootSignature = validationRootSign

fields, err := common.GetPathFields(pathutil.Dir(ch.NewFile.Path))

Expand Down
5 changes: 3 additions & 2 deletions zboxcore/blockchain/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ type UpdateValidationNode struct {

// StorageNode represents a storage node (blobber)
type StorageNode struct {
ID string `json:"id"`
Baseurl string `json:"url"`
ID string `json:"id"`
Baseurl string `json:"url"`
AllocationVersion int64 `json:"-"`

skip uint64 `json:"-"` // skip on error
}
Expand Down
26 changes: 14 additions & 12 deletions zboxcore/fileref/fileref.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ type Collaborator struct {
}

type FileRef struct {
Ref `mapstructure:",squash"`
CustomMeta string `json:"custom_meta" mapstructure:"custom_meta"`
ValidationRoot string `json:"validation_root" mapstructure:"validation_root"`
Ref `mapstructure:",squash"`
CustomMeta string `json:"custom_meta" mapstructure:"custom_meta"`
// ValidationRootSignature is signature signed by client for hash_of(ActualFileHashSignature + ValidationRoot)
ValidationRootSignature string `json:"validation_root_signature" mapstructure:"validation_root_signature"`
FixedMerkleRoot string `json:"fixed_merkle_root" mapstructure:"fixed_merkle_root"`
ThumbnailSize int64 `json:"thumbnail_size" mapstructure:"thumbnail_size"`
ThumbnailHash string `json:"thumbnail_hash" mapstructure:"thumbnail_hash"`
ActualFileSize int64 `json:"actual_file_size" mapstructure:"actual_file_size"`
ActualFileHash string `json:"actual_file_hash" mapstructure:"actual_file_hash"`
ThumbnailSize int64 `json:"thumbnail_size" mapstructure:"thumbnail_size"`
ThumbnailHash string `json:"thumbnail_hash" mapstructure:"thumbnail_hash"`
ActualFileSize int64 `json:"actual_file_size" mapstructure:"actual_file_size"`
ActualFileHash string `json:"actual_file_hash" mapstructure:"actual_file_hash"`
// ActualFileHashSignature is signature signed by client for ActualFileHash
ActualFileHashSignature string `json:"actual_file_hash_signature" mapstructure:"actual_file_hash_signature"`
ActualThumbnailSize int64 `json:"actual_thumbnail_size" mapstructure:"actual_thumbnail_size"`
Expand Down Expand Up @@ -75,6 +72,7 @@ type RefEntity interface {
GetFileID() string
GetCreatedAt() common.Timestamp
GetUpdatedAt() common.Timestamp
GetAllocationVersion() int64
}

type Ref struct {
Expand All @@ -95,6 +93,8 @@ type Ref struct {
ThumbnailSize int64 `json:"thumbnail_size" mapstructure:"thumbnail_size"`
ActualThumbnailHash string `json:"actual_thumbnail_hash" mapstructure:"actual_thumbnail_hash"`
ActualThumbnailSize int64 `json:"actual_thumbnail_size" mapstructure:"actual_thumbnail_size"`
IsEmpty bool `json:"is_empty" mapstructure:"is_empty"`
AllocationVersion int64 `json:"allocation_version" mapstructure:"allocation_version"`
HashToBeComputed bool
ChildrenLoaded bool
Children []RefEntity `json:"-" mapstructure:"-"`
Expand Down Expand Up @@ -240,6 +240,10 @@ func (r *Ref) RemoveChild(idx int) {
r.Children = append(r.Children[:idx], r.Children[idx+1:]...)
}

func (r *Ref) GetAllocationVersion() int64 {
return r.AllocationVersion
}

func (fr *FileRef) GetFileMetaHash() string {
return fr.FileMetaHash
}
Expand All @@ -252,14 +256,12 @@ func (fr *FileRef) GetFileMetaHashData() string {

func (fr *FileRef) GetHashData() string {
return fmt.Sprintf(
"%s:%s:%s:%s:%d:%s:%s:%d:%s:%d:%s",
"%s:%s:%s:%s:%d:%d:%s:%d:%s",
fr.AllocationID,
fr.Type, // don't need to add it as well
fr.Name, // don't see any utility as fr.Path below has name in it
fr.Path,
fr.Size,
fr.ValidationRoot,
fr.FixedMerkleRoot,
fr.ActualFileSize,
fr.ActualFileHash,
fr.ChunkSize,
Expand Down
50 changes: 50 additions & 0 deletions zboxcore/marker/versionmarker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package marker

import (
"fmt"

"github.com/0chain/errors"
"github.com/0chain/gosdk/core/encryption"
"github.com/0chain/gosdk/core/sys"
"github.com/0chain/gosdk/zboxcore/client"
)

type VersionMarker struct {
ClientID string `json:"client_id"`
BlobberID string `json:"blobber_id"`
AllocationID string `json:"allocation_id"`
Version int64 `json:"version"`
Timestamp int64 `json:"timestamp"`
Signature string `json:"signature"`
IsRepair bool `json:"is_repair"`
RepairVersion int64 `json:"repair_version"`
RepairOffset string `json:"repair_offset"`
}

func (vm *VersionMarker) GetHashData() string {
return fmt.Sprintf("%s:%s:%s:%d:%d", vm.AllocationID, vm.ClientID, vm.BlobberID, vm.Version, vm.Timestamp)
}

func (vm *VersionMarker) GetHash() string {
sigData := vm.GetHashData()
return encryption.Hash(sigData)
}

func (vm *VersionMarker) Sign() error {
var err error
vm.Signature, err = client.Sign(vm.GetHash())
return err
}

func (vm *VersionMarker) VerifySignature(clientPublicKey string) error {
hashData := vm.GetHashData()
signatureHash := encryption.Hash(hashData)
sigOK, err := sys.Verify(vm.Signature, signatureHash)
if err != nil {
return errors.New("write_marker_validation_failed", "Error during verifying signature. "+err.Error())
}
if !sigOK {
return errors.New("write_marker_validation_failed", "Write marker signature is not valid")
}
return nil
}
Loading