diff --git a/code/go/0chain.net/blobber/main.go b/code/go/0chain.net/blobber/main.go index 57f004c8e..636f9a6bf 100644 --- a/code/go/0chain.net/blobber/main.go +++ b/code/go/0chain.net/blobber/main.go @@ -143,7 +143,7 @@ func checkForDBConnection() { retries := 0 var err error for retries < 600 { - err = datastore.GetStore().Open() + err = datastore.TheStore.Open() if err != nil { time.Sleep(1 * time.Second) retries++ diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 9cc289411..77d03f2cb 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -69,14 +69,14 @@ func (AllocationChange) TableName() string { func GetAllocationChanges(ctx context.Context, connectionID string, allocationID string, clientID string) (*AllocationChangeCollector, error) { cc := &AllocationChangeCollector{} - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) err := db.Where(&AllocationChangeCollector{ ConnectionID: connectionID, AllocationID: allocationID, ClientID: clientID, }).Not(&AllocationChangeCollector{ Status: DeletedConnection, - }).Preload("Changes").First(cc).Error + }).Preload("Changes").First(cc).Error() if err == nil { cc.ComputeProperties() @@ -101,13 +101,13 @@ func (cc *AllocationChangeCollector) AddChange(allocationChange *AllocationChang func (cc *AllocationChangeCollector) Save(ctx context.Context) error { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) if cc.Status == NewConnection { cc.Status = InProgressConnection - err := db.Create(cc).Error + err := db.Create(cc).Error() return err } else { - err := db.Save(cc).Error + err := db.Save(cc).Error() return err } } diff --git a/code/go/0chain.net/blobbercore/allocation/deletefilechange.go b/code/go/0chain.net/blobbercore/allocation/deletefilechange.go index 83affa99e..dd09556ca 100644 --- a/code/go/0chain.net/blobbercore/allocation/deletefilechange.go +++ b/code/go/0chain.net/blobbercore/allocation/deletefilechange.go @@ -5,10 +5,10 @@ import ( "encoding/json" "path/filepath" - "0chain.net/blobbercore/datastore" - "0chain.net/blobbercore/filestore" "0chain.net/blobbercore/reference" "0chain.net/core/common" + "0chain.net/blobbercore/datastore" + "0chain.net/blobbercore/filestore" . "0chain.net/core/logging" "go.uber.org/zap" @@ -118,7 +118,7 @@ func (nf *DeleteFileChange) DeleteTempFile() error { } func (nf *DeleteFileChange) CommitToFileStore(ctx context.Context) error { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) for contenthash := range nf.ContentHash { var count int64 err := db.Table((&reference.Ref{}).TableName()).Where(&reference.Ref{ThumbnailHash: contenthash}).Or(&reference.Ref{ContentHash: contenthash}).Count(&count).Error diff --git a/code/go/0chain.net/blobbercore/allocation/entity.go b/code/go/0chain.net/blobbercore/allocation/entity.go index 62a11125a..035efa6a1 100644 --- a/code/go/0chain.net/blobbercore/allocation/entity.go +++ b/code/go/0chain.net/blobbercore/allocation/entity.go @@ -1,6 +1,7 @@ package allocation import ( + "0chain.net/blobbercore/datastore" "errors" "time" @@ -110,7 +111,7 @@ func (a *Allocation) WantWrite(blobberID string, size int64, } // ReadPools from DB cache. -func ReadPools(tx *gorm.DB, clientID, allocID, blobberID string, +func ReadPools(tx datastore.Transaction, clientID, allocID, blobberID string, until common.Timestamp) (rps []*ReadPool, err error) { const query = `client_id = ? AND @@ -120,7 +121,7 @@ func ReadPools(tx *gorm.DB, clientID, allocID, blobberID string, err = tx.Model(&ReadPool{}). Where(query, clientID, allocID, blobberID, until). - Find(&rps).Error + Find(&rps).Error() return } @@ -149,7 +150,7 @@ func (*Pending) TableName() string { return "pendings" } -func GetPending(tx *gorm.DB, clientID, allocationID, blobberID string) ( +func GetPending(tx datastore.Transaction, clientID, allocationID, blobberID string) ( p *Pending, err error) { const query = `client_id = ? AND @@ -159,12 +160,12 @@ func GetPending(tx *gorm.DB, clientID, allocationID, blobberID string) ( p = new(Pending) err = tx.Model(&Pending{}). Where(query, clientID, allocationID, blobberID). - First(&p).Error + First(&p).Error() if errors.Is(err, gorm.ErrRecordNotFound) { p.ClientID = clientID p.AllocationID = allocationID p.BlobberID = blobberID - err = tx.Create(p).Error + err = tx.Create(p).Error() } return } @@ -179,7 +180,7 @@ func (p *Pending) SubPendingWrite(size int64) { } } -func (p *Pending) WritePools(tx *gorm.DB, blobberID string, +func (p *Pending) WritePools(tx datastore.Transaction, blobberID string, until common.Timestamp) (wps []*WritePool, err error) { const query = `client_id = ? AND @@ -189,7 +190,7 @@ func (p *Pending) WritePools(tx *gorm.DB, blobberID string, err = tx.Model(&WritePool{}). Where(query, p.ClientID, p.AllocationID, blobberID, until). - Find(&wps).Error + Find(&wps).Error() return } @@ -202,11 +203,11 @@ func (p *Pending) HaveWrite(wps []*WritePool, ww WantWriter, return have - ww.WantWrite(p.BlobberID, p.PendingWrite, wmt) } -func (p *Pending) Save(tx *gorm.DB) error { +func (p *Pending) Save(tx datastore.Transaction) error { if p.ID == 0 { - return tx.Create(p).Error + return tx.Create(p).Error() } - return tx.Save(p).Error + return tx.Save(p).Error() } // Terms for allocation by its Tx. @@ -253,7 +254,7 @@ func (*WritePool) TableName() string { return "write_pools" } -func SetReadPools(db *gorm.DB, clientID, allocationID, blobberID string, +func SetReadPools(db datastore.Transaction, clientID, allocationID, blobberID string, rps []*ReadPool) (err error) { // cleanup and batch insert (remove old pools, add / update new) @@ -265,7 +266,7 @@ func SetReadPools(db *gorm.DB, clientID, allocationID, blobberID string, var stub []*ReadPool err = db.Model(&ReadPool{}). Where(query, clientID, allocationID, blobberID). - Delete(&stub).Error + Delete(&stub).Error() if err != nil { return } @@ -277,11 +278,11 @@ func SetReadPools(db *gorm.DB, clientID, allocationID, blobberID string, err = db.Model(&ReadPool{}).Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "pool_id"}}, DoUpdates: clause.AssignmentColumns([]string{"balance"}), - }).Create(rps).Error + }).Create(rps).Error() return } -func SetWritePools(db *gorm.DB, clientID, allocationID, blobberID string, +func SetWritePools(db datastore.Transaction, clientID, allocationID, blobberID string, wps []*WritePool) (err error) { const query = `client_id = ? AND @@ -291,7 +292,7 @@ func SetWritePools(db *gorm.DB, clientID, allocationID, blobberID string, var stub []*WritePool err = db.Model(&WritePool{}). Where(query, clientID, allocationID, blobberID). - Delete(&stub).Error + Delete(&stub).Error() if err != nil { return } @@ -303,7 +304,7 @@ func SetWritePools(db *gorm.DB, clientID, allocationID, blobberID string, err = db.Model(&WritePool{}).Clauses(clause.OnConflict{ Columns: []clause.Column{{Name: "pool_id"}}, DoUpdates: clause.AssignmentColumns([]string{"balance"}), - }).Create(wps).Error + }).Create(wps).Error() return } diff --git a/code/go/0chain.net/blobbercore/allocation/protocol.go b/code/go/0chain.net/blobbercore/allocation/protocol.go index 01c07bf26..483b53f50 100644 --- a/code/go/0chain.net/blobbercore/allocation/protocol.go +++ b/code/go/0chain.net/blobbercore/allocation/protocol.go @@ -20,12 +20,12 @@ import ( func GetAllocationByID(ctx context.Context, allocID string) ( a *Allocation, err error) { - var tx = datastore.GetStore().GetTransaction(ctx) + var tx = datastore.GetTransaction(ctx) a = new(Allocation) err = tx.Model(&Allocation{}). Where(&Allocation{ID: allocID}). - First(a).Error + First(a).Error() return } @@ -34,12 +34,12 @@ func GetAllocationByID(ctx context.Context, allocID string) ( // loads the Terms for an allocation. func (a *Allocation) LoadTerms(ctx context.Context) (err error) { // get transaction - var tx = datastore.GetStore().GetTransaction(ctx) + var tx = datastore.GetTransaction(ctx) // load related terms var terms []*Terms err = tx.Model(terms). Where("allocation_id = ?", a.ID). - Find(&terms).Error + Find(&terms).Error() if err != nil { // unexpected DB error, including a RecordNotFoundError, since // an allocation can't be without its terms (the terms must exist) @@ -52,12 +52,12 @@ func (a *Allocation) LoadTerms(ctx context.Context) (err error) { func VerifyAllocationTransaction(ctx context.Context, allocationTx string, readonly bool) (a *Allocation, err error) { - var tx = datastore.GetStore().GetTransaction(ctx) + var tx = datastore.GetTransaction(ctx) a = new(Allocation) err = tx.Model(&Allocation{}). Where(&Allocation{Tx: allocationTx}). - First(a).Error + First(a).Error() if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return nil, err // unexpected DB error @@ -68,7 +68,7 @@ func VerifyAllocationTransaction(ctx context.Context, allocationTx string, var terms []*Terms err = tx.Model(terms). Where("allocation_id = ?", a.ID). - Find(&terms).Error + Find(&terms).Error() if err != nil { return // unexpected DB error } @@ -91,7 +91,7 @@ func VerifyAllocationTransaction(ctx context.Context, allocationTx string, var isExist bool err = tx.Model(&Allocation{}). Where("id = ?", sa.ID). - First(a).Error + First(a).Error() if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { return nil, err // unexpected } @@ -146,9 +146,9 @@ func VerifyAllocationTransaction(ctx context.Context, allocationTx string, Logger.Info("Saving the allocation to DB") if isExist { - err = tx.Save(a).Error + err = tx.Save(a).Error() } else { - err = tx.Create(a).Error + err = tx.Create(a).Error() } if err != nil { @@ -158,9 +158,9 @@ func VerifyAllocationTransaction(ctx context.Context, allocationTx string, // save/update related terms for _, t := range a.Terms { if isExist { - err = tx.Save(t).Error + err = tx.Save(t).Error() } else { - err = tx.Create(t).Error + err = tx.Create(t).Error() } if err != nil { return nil, err diff --git a/code/go/0chain.net/blobbercore/allocation/workers.go b/code/go/0chain.net/blobbercore/allocation/workers.go index bbd0c1c37..96e4434d4 100644 --- a/code/go/0chain.net/blobbercore/allocation/workers.go +++ b/code/go/0chain.net/blobbercore/allocation/workers.go @@ -13,11 +13,8 @@ import ( "0chain.net/core/chain" "0chain.net/core/common" "0chain.net/core/lock" - "0chain.net/core/transaction" - - "gorm.io/gorm" - . "0chain.net/core/logging" + "0chain.net/core/transaction" "go.uber.org/zap" ) @@ -113,12 +110,12 @@ func findAllocations(ctx context.Context, offset int64) ( const query = `finalized = false AND cleaned_up = false` - ctx = datastore.GetStore().CreateTransaction(ctx) + ctx = datastore.CreateTransaction(ctx) - var tx = datastore.GetStore().GetTransaction(ctx) + var tx = datastore.GetTransaction(ctx) defer tx.Rollback() - err = tx.Model(&Allocation{}).Where(query).Count(&count).Error + err = tx.Model(&Allocation{}).Where(query).Count(&count).Error() if err != nil { return } @@ -129,7 +126,7 @@ func findAllocations(ctx context.Context, offset int64) ( Limit(UPDATE_LIMIT). Offset(int(offset)). Order("id ASC"). - Find(&allocs).Error + Find(&allocs).Error() return } @@ -190,20 +187,20 @@ func requestAllocation(allocID string) ( return } -func commit(tx *gorm.DB, err *error) { +func commit(tx datastore.Transaction, err *error) { if (*err) != nil { tx.Rollback() return } - (*err) = tx.Commit().Error + (*err) = tx.Commit().Error() } func updateAllocationInDB(ctx context.Context, a *Allocation, sa *transaction.StorageAllocation) (ua *Allocation, err error) { - ctx = datastore.GetStore().CreateTransaction(ctx) + ctx = datastore.CreateTransaction(ctx) - var tx = datastore.GetStore().GetTransaction(ctx) + var tx = datastore.GetTransaction(ctx) defer commit(tx, &err) var changed bool = a.Tx != sa.Tx @@ -228,7 +225,7 @@ func updateAllocationInDB(ctx context.Context, a *Allocation, } // save allocations - if err = tx.Save(a).Error; err != nil { + if err = tx.Save(a).Error(); err != nil { return nil, err } @@ -238,7 +235,7 @@ func updateAllocationInDB(ctx context.Context, a *Allocation, // save allocation terms for _, t := range a.Terms { - if err = tx.Save(t).Error; err != nil { + if err = tx.Save(t).Error(); err != nil { return nil, err } } @@ -287,12 +284,12 @@ func cleanupAllocation(ctx context.Context, a *Allocation) { Logger.Error("cleaning finalized allocation", zap.Error(err)) } - ctx = datastore.GetStore().CreateTransaction(ctx) - var tx = datastore.GetStore().GetTransaction(ctx) + ctx = datastore.CreateTransaction(ctx) + var tx = datastore.GetTransaction(ctx) defer commit(tx, &err) a.CleanedUp = true - if err = tx.Model(a).Updates(a).Error; err != nil { + if err = tx.Model(a).Updates(a).Error(); err != nil { Logger.Error("updating allocation 'cleaned_up'", zap.Error(err)) } } @@ -306,8 +303,8 @@ func newConnectionID() string { } func deleteInFakeConnection(ctx context.Context, a *Allocation) (err error) { - ctx = datastore.GetStore().CreateTransaction(ctx) - var tx = datastore.GetStore().GetTransaction(ctx) + ctx = datastore.CreateTransaction(ctx) + var tx = datastore.GetTransaction(ctx) defer commit(tx, &err) var ( @@ -336,13 +333,13 @@ func deleteFiles(ctx context.Context, allocID string, conn *AllocationChangeCollector) (err error) { var ( - tx = datastore.GetStore().GetTransaction(ctx) + tx = datastore.GetTransaction(ctx) refs = make([]*reference.Ref, 0) ) err = tx.Where(&reference.Ref{ Type: reference.FILE, AllocationID: allocID, - }).Find(&refs).Error + }).Find(&refs).Error() if err != nil { return } diff --git a/code/go/0chain.net/blobbercore/challenge/entity.go b/code/go/0chain.net/blobbercore/challenge/entity.go index 283c90f46..d40c212d6 100644 --- a/code/go/0chain.net/blobbercore/challenge/entity.go +++ b/code/go/0chain.net/blobbercore/challenge/entity.go @@ -121,8 +121,8 @@ func (cr *ChallengeEntity) Save(ctx context.Context) error { //j, _ := json.Marshal(&cr.ObjectPathString) // Logger.Info("Object path", zap.Any("objectpath", string(j))) // Logger.Info("Object path object", zap.Any("object_path", cr.ObjectPath)) - db := datastore.GetStore().GetTransaction(ctx) - err = db.Save(cr).Error + db := datastore.GetTransaction(ctx) + err = db.Save(cr).Error() return err } @@ -157,9 +157,9 @@ func (cr *ChallengeEntity) UnmarshalFields() error { } func GetChallengeEntity(ctx context.Context, challengeID string) (*ChallengeEntity, error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) cr := &ChallengeEntity{} - err := db.Where(ChallengeEntity{ChallengeID: challengeID}).Take(cr).Error + err := db.Where(ChallengeEntity{ChallengeID: challengeID}).Take(cr).Error() if err != nil { return nil, err } @@ -171,9 +171,9 @@ func GetChallengeEntity(ctx context.Context, challengeID string) (*ChallengeEnti } func GetLastChallengeEntity(ctx context.Context) (*ChallengeEntity, error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) cr := &ChallengeEntity{} - err := db.Order("sequence desc").First(cr).Error + err := db.Order("sequence desc").First(cr).Error() if err != nil { return nil, err } diff --git a/code/go/0chain.net/blobbercore/challenge/stats.go b/code/go/0chain.net/blobbercore/challenge/stats.go index 4a0e4e701..ee9529edf 100644 --- a/code/go/0chain.net/blobbercore/challenge/stats.go +++ b/code/go/0chain.net/blobbercore/challenge/stats.go @@ -10,7 +10,7 @@ import ( ) func FileChallenged(ctx context.Context, refID int64, result ChallengeResult, challengeTxn string) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) stats := &stats.FileStats{RefID: refID} if result == ChallengeSuccess { db.Table(stats.TableName()).Where(stats).Updates(map[string]interface{}{"num_of_challenges": gorm.Expr("num_of_challenges + ?", 1), "last_challenge_txn": challengeTxn}) diff --git a/code/go/0chain.net/blobbercore/challenge/worker.go b/code/go/0chain.net/blobbercore/challenge/worker.go index 7fca5bc7e..e67182114 100644 --- a/code/go/0chain.net/blobbercore/challenge/worker.go +++ b/code/go/0chain.net/blobbercore/challenge/worker.go @@ -49,8 +49,8 @@ func SubmitProcessedChallenges(ctx context.Context) error { return ctx.Err() default: Logger.Info("Attempting to commit processed challenges...") - rctx := datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(rctx) + rctx := datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(rctx) //lastChallengeRedeemed := &ChallengeEntity{} rows, err := db.Table("challenges"). Select("commit_txn_id, sequence"). @@ -81,7 +81,7 @@ func SubmitProcessedChallenges(ctx context.Context) error { } mutex := lock.GetMutex(openchallenge.TableName(), openchallenge.ChallengeID) mutex.Lock() - redeemCtx := datastore.GetStore().CreateTransaction(ctx) + redeemCtx := datastore.CreateTransaction(ctx) err := openchallenge.CommitChallenge(redeemCtx, false) if err != nil { Logger.Error("Error committing to blockchain", @@ -89,7 +89,7 @@ func SubmitProcessedChallenges(ctx context.Context) error { zap.String("challenge_id", openchallenge.ChallengeID)) } mutex.Unlock() - db := datastore.GetStore().GetTransaction(redeemCtx) + db := datastore.GetTransaction(redeemCtx) db.Commit() if err == nil && openchallenge.Status == Committed { Logger.Info("Challenge has been submitted to blockchain", @@ -104,8 +104,8 @@ func SubmitProcessedChallenges(ctx context.Context) error { db.Rollback() rctx.Done() - rctx = datastore.GetStore().CreateTransaction(ctx) - db = datastore.GetStore().GetTransaction(rctx) + rctx = datastore.CreateTransaction(ctx) + db = datastore.GetTransaction(rctx) toBeVerifiedChallenges := make([]*ChallengeEntity, 0) // commit challenges on local state for all challenges that // have missed the commit txn from blockchain @@ -120,7 +120,7 @@ func SubmitProcessedChallenges(ctx context.Context) error { } mutex := lock.GetMutex(toBeVerifiedChallenge.TableName(), toBeVerifiedChallenge.ChallengeID) mutex.Lock() - redeemCtx := datastore.GetStore().CreateTransaction(ctx) + redeemCtx := datastore.CreateTransaction(ctx) err := toBeVerifiedChallenge.CommitChallenge(redeemCtx, true) if err != nil { Logger.Error("Error committing to blockchain", @@ -128,7 +128,7 @@ func SubmitProcessedChallenges(ctx context.Context) error { zap.String("challenge_id", toBeVerifiedChallenge.ChallengeID)) } mutex.Unlock() - db := datastore.GetStore().GetTransaction(redeemCtx) + db := datastore.GetTransaction(redeemCtx) db.Commit() if err == nil && toBeVerifiedChallenge.Status == Committed { Logger.Info("Challenge has been submitted to blockchain", @@ -149,7 +149,7 @@ func SubmitProcessedChallenges(ctx context.Context) error { time.Sleep(time.Duration(config.Configuration.ChallengeResolveFreq) * time.Second) } - return nil //nolint:govet // need more time to verify + return nil } var iterInprogress = false @@ -163,8 +163,8 @@ func FindChallenges(ctx context.Context) { case <-ticker.C: if !iterInprogress { iterInprogress = true - rctx := datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(rctx) + rctx := datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(rctx) openchallenges := make([]*ChallengeEntity, 0) db.Where(ChallengeEntity{Status: Accepted}).Find(&openchallenges) if len(openchallenges) > 0 { @@ -178,14 +178,14 @@ func FindChallenges(ctx context.Context) { } swg.Add() go func(redeemCtx context.Context, challengeEntity *ChallengeEntity) { - redeemCtx = datastore.GetStore().CreateTransaction(redeemCtx) + redeemCtx = datastore.CreateTransaction(redeemCtx) defer redeemCtx.Done() err := GetValidationTickets(redeemCtx, challengeEntity) if err != nil { Logger.Error("Getting validation tickets failed", zap.Any("challenge_id", challengeEntity.ChallengeID), zap.Error(err)) } - db := datastore.GetStore().GetTransaction(redeemCtx) - err = db.Commit().Error + db := datastore.GetTransaction(redeemCtx) + err = db.Commit().Error() if err != nil { Logger.Error("Error commiting the readmarker redeem", zap.Error(err)) } @@ -205,8 +205,8 @@ func FindChallenges(ctx context.Context) { if err != nil { Logger.Error("Error getting the open challenges from the blockchain", zap.Error(err)) } else { - tCtx := datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(tCtx) + tCtx := datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(tCtx) bytesReader := bytes.NewBuffer(retBytes) d := json.NewDecoder(bytesReader) d.UseNumber() diff --git a/code/go/0chain.net/blobbercore/datastore/mock.go b/code/go/0chain.net/blobbercore/datastore/mock.go new file mode 100644 index 000000000..cce80c313 --- /dev/null +++ b/code/go/0chain.net/blobbercore/datastore/mock.go @@ -0,0 +1,127 @@ +package datastore + +import ( + "context" + "database/sql" + "gorm.io/gorm/clause" +) + +func MockTheStore(mock Store) { + TheStore = mock +} + +type MockStore struct{} + +func (store *MockStore) Open() error { + return nil +} + +func (store *MockStore) Close() { +} + +func (store *MockStore) CreateTransaction(ctx context.Context) context.Context { + return ctx +} + +func (store *MockStore) GetTransaction(ctx context.Context) Transaction { + return &MockTransaction{} +} + +type MockTransaction struct{} + +func (t *MockTransaction) Model(value interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Table(name string, args ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Select(query interface{}, args ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Where(query interface{}, args ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Not(query interface{}, args ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Or(query interface{}, args ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Joins(query string, args ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Group(name string) (tx Transaction) { + return t +} +func (t *MockTransaction) Having(query interface{}, args ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Order(value interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Create(value interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Save(value interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) First(dest interface{}, conds ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Begin(opts ...*sql.TxOptions) Transaction { + return t +} +func (t *MockTransaction) Commit() Transaction { + return t +} +func (t *MockTransaction) Rollback() Transaction { + return t +} +func (t *MockTransaction) Find(dest interface{}, conds ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Limit(limit int) (tx Transaction) { + return t +} +func (t *MockTransaction) Rows() (*sql.Rows, error) { + return nil, nil +} +func (t *MockTransaction) Scan(dest interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Error() error { + return nil +} +func (t *MockTransaction) Delete(value interface{}, conds ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Take(dest interface{}, conds ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Raw(sql string, values ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Update(column string, value interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Updates(values interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Count(count *int64) (tx Transaction) { + return t +} +func (t *MockTransaction) Row() *sql.Row { + return nil +} +func (t *MockTransaction) Preload(query string, args ...interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Offset(offset int) (tx Transaction) { + return t +} +func (t *MockTransaction) Pluck(column string, dest interface{}) (tx Transaction) { + return t +} +func (t *MockTransaction) Clauses(conds ...clause.Expression) (tx Transaction) { + return t +} diff --git a/code/go/0chain.net/blobbercore/datastore/store.go b/code/go/0chain.net/blobbercore/datastore/store.go index 358ee50fc..0a6db7d5a 100644 --- a/code/go/0chain.net/blobbercore/datastore/store.go +++ b/code/go/0chain.net/blobbercore/datastore/store.go @@ -18,21 +18,28 @@ type contextKey int const CONNECTION_CONTEXT_KEY contextKey = iota -type Store struct { - db *gorm.DB +type Store interface { + Open() error + Close() + CreateTransaction(ctx context.Context) context.Context + GetTransaction(ctx context.Context) Transaction } -var store Store +var TheStore Store = &store{} -func SetDB(db *gorm.DB) { - store.db = db +type store struct { + db *gorm.DB } -func GetStore() *Store { - return &store -} +//func SetDB(db *gorm.DB) { +// store.db = db +//} -func (store *Store) Open() error { +//func GetStore() *Store { +// return &store +//} + +func (store *store) Open() error { db, err := gorm.Open(postgres.Open(fmt.Sprintf( "host=%v port=%v user=%v dbname=%v password=%v sslmode=disable", config.Configuration.DBHost, config.Configuration.DBPort, @@ -56,7 +63,7 @@ func (store *Store) Open() error { return nil } -func (store *Store) Close() { +func (store *store) Close() { if store.db != nil { if sqldb, _ := store.db.DB(); sqldb != nil { sqldb.Close() @@ -64,20 +71,16 @@ func (store *Store) Close() { } } -func (store *Store) CreateTransaction(ctx context.Context) context.Context { +func (store *store) CreateTransaction(ctx context.Context) context.Context { db := store.db.Begin() - return context.WithValue(ctx, CONNECTION_CONTEXT_KEY, db) //nolint:staticcheck // changing type might require further refactor + return context.WithValue(ctx, CONNECTION_CONTEXT_KEY, db) } -func (store *Store) GetTransaction(ctx context.Context) *gorm.DB { +func (store *store) GetTransaction(ctx context.Context) Transaction { conn := ctx.Value(CONNECTION_CONTEXT_KEY) if conn != nil { - return conn.(*gorm.DB) + return &transaction{conn.(*gorm.DB)} } Logger.Error("No connection in the context.") return nil } - -func (store *Store) GetDB() *gorm.DB { - return store.db -} diff --git a/code/go/0chain.net/blobbercore/datastore/transaction.go b/code/go/0chain.net/blobbercore/datastore/transaction.go new file mode 100644 index 000000000..42883b6c2 --- /dev/null +++ b/code/go/0chain.net/blobbercore/datastore/transaction.go @@ -0,0 +1,152 @@ +package datastore + +import ( + "context" + "database/sql" + gorm "gorm.io/gorm" + "gorm.io/gorm/clause" +) + +func CreateTransaction(ctx context.Context) context.Context { + return TheStore.CreateTransaction(ctx) +} + +func GetTransaction(ctx context.Context) Transaction { + return TheStore.GetTransaction(ctx) +} + +type Transaction interface { + Model(value interface{}) (tx Transaction) + Table(name string, args ...interface{}) (tx Transaction) + Select(query interface{}, args ...interface{}) (tx Transaction) + Where(query interface{}, args ...interface{}) (tx Transaction) + Not(query interface{}, args ...interface{}) (tx Transaction) + Or(query interface{}, args ...interface{}) (tx Transaction) + Joins(query string, args ...interface{}) (tx Transaction) + Group(name string) (tx Transaction) + Having(query interface{}, args ...interface{}) (tx Transaction) + Order(value interface{}) (tx Transaction) + Create(value interface{}) (tx Transaction) + Save(value interface{}) (tx Transaction) + First(dest interface{}, conds ...interface{}) (tx Transaction) + Begin(opts ...*sql.TxOptions) Transaction + Commit() Transaction + Rollback() Transaction + Find(dest interface{}, conds ...interface{}) (tx Transaction) + Limit(limit int) (tx Transaction) + Rows() (*sql.Rows, error) + Scan(dest interface{}) (tx Transaction) + Error() error + Delete(value interface{}, conds ...interface{}) (tx Transaction) + Take(dest interface{}, conds ...interface{}) (tx Transaction) + Raw(sql string, values ...interface{}) (tx Transaction) + Update(column string, value interface{}) (tx Transaction) + Updates(values interface{}) (tx Transaction) + Count(count *int64) (tx Transaction) + Row() *sql.Row + Preload(query string, args ...interface{}) (tx Transaction) + Offset(offset int) (tx Transaction) + Pluck(column string, dest interface{}) (tx Transaction) + Clauses(conds ...clause.Expression) (tx Transaction) +} + +type transaction struct { + *gorm.DB +} + +func (t *transaction) Model(value interface{}) (tx Transaction) { + return &transaction{t.DB.Model(value)} +} +func (t *transaction) Table(name string, args ...interface{}) (tx Transaction) { + return &transaction{t.DB.Table(name, args...)} +} +func (t *transaction) Select(query interface{}, args ...interface{}) (tx Transaction) { + return &transaction{t.DB.Select(query, args...)} +} +func (t *transaction) Where(query interface{}, args ...interface{}) (tx Transaction) { + return &transaction{t.DB.Where(query, args...)} +} +func (t *transaction) Not(query interface{}, args ...interface{}) (tx Transaction) { + return &transaction{t.DB.Not(query, args...)} +} +func (t *transaction) Or(query interface{}, args ...interface{}) (tx Transaction) { + return &transaction{t.DB.Or(query, args...)} +} +func (t *transaction) Joins(query string, args ...interface{}) (tx Transaction) { + return &transaction{t.DB.Joins(query, args...)} +} +func (t *transaction) Group(name string) (tx Transaction) { + return &transaction{t.DB.Group(name)} +} +func (t *transaction) Having(query interface{}, args ...interface{}) (tx Transaction) { + return &transaction{t.DB.Having(query, args...)} +} +func (t *transaction) Order(value interface{}) (tx Transaction) { + return &transaction{t.DB.Order(value)} +} +func (t *transaction) Create(value interface{}) (tx Transaction) { + return &transaction{t.DB.Create(value)} +} +func (t *transaction) Save(value interface{}) (tx Transaction) { + return &transaction{t.DB.Save(value)} +} +func (t *transaction) First(dest interface{}, conds ...interface{}) (tx Transaction) { + return &transaction{t.DB.First(dest, conds...)} +} +func (t *transaction) Begin(opts ...*sql.TxOptions) Transaction { + return &transaction{t.DB.Begin(opts...)} +} +func (t *transaction) Commit() Transaction { + return &transaction{t.DB.Commit()} +} +func (t *transaction) Rollback() Transaction { + return &transaction{t.DB.Rollback()} +} +func (t *transaction) Find(dest interface{}, conds ...interface{}) (tx Transaction) { + return &transaction{t.DB.Find(dest, conds...)} +} +func (t *transaction) Limit(limit int) (tx Transaction) { + return &transaction{t.DB.Limit(limit)} +} +func (t *transaction) Rows() (*sql.Rows, error) { + return t.DB.Rows() +} +func (t *transaction) Scan(dest interface{}) (tx Transaction) { + return &transaction{t.DB.Scan(dest)} +} +func (t *transaction) Error() error { + return t.DB.Error +} +func (t *transaction) Delete(value interface{}, conds ...interface{}) (tx Transaction) { + return &transaction{t.DB.Delete(value, conds...)} +} +func (t *transaction) Take(dest interface{}, conds ...interface{}) (tx Transaction) { + return &transaction{t.DB.Take(dest, conds...)} +} +func (t *transaction) Raw(sql string, values ...interface{}) (tx Transaction) { + return &transaction{t.DB.Raw(sql, values...)} +} +func (t *transaction) Update(column string, value interface{}) (tx Transaction) { + return &transaction{t.DB.Update(column, value)} +} +func (t *transaction) Updates(values interface{}) (tx Transaction) { + return &transaction{t.DB.Updates(values)} +} +func (t *transaction) Count(count *int64) (tx Transaction) { + return &transaction{t.DB.Count(count)} +} +func (t *transaction) Row() *sql.Row { + return t.DB.Row() +} +func (t *transaction) Preload(query string, args ...interface{}) (tx Transaction) { + return &transaction{t.DB.Preload(query, args...)} +} +func (t *transaction) Offset(offset int) (tx Transaction) { + return &transaction{t.DB.Offset(offset)} +} +func (t *transaction) Pluck(column string, dest interface{}) (tx Transaction) { + return &transaction{t.DB.Pluck(column, dest)} +} +func (t *transaction) Clauses(conds ...clause.Expression) (tx Transaction) { + return &transaction{t.DB.Clauses(conds...)} +} diff --git a/code/go/0chain.net/blobbercore/handler/grpchandler.go b/code/go/0chain.net/blobbercore/handler/grpchandler.go index 8346f5bc4..38e4d9f3e 100644 --- a/code/go/0chain.net/blobbercore/handler/grpchandler.go +++ b/code/go/0chain.net/blobbercore/handler/grpchandler.go @@ -42,7 +42,7 @@ func unaryDatabaseTransactionInjector() grpc.UnaryServerInterceptor { return nil, err } - err = GetMetaDataStore().GetTransaction(ctx).Commit().Error + err = GetMetaDataStore().GetTransaction(ctx).Commit().Error() if err != nil { return nil, common.NewErrorf("commit_error", "error committing to meta store: %v", err) diff --git a/code/go/0chain.net/blobbercore/handler/handler.go b/code/go/0chain.net/blobbercore/handler/handler.go index 740e3618d..fc8ada446 100644 --- a/code/go/0chain.net/blobbercore/handler/handler.go +++ b/code/go/0chain.net/blobbercore/handler/handler.go @@ -22,8 +22,8 @@ import ( var storageHandler StorageHandler -func GetMetaDataStore() *datastore.Store { - return datastore.GetStore() +func GetMetaDataStore() datastore.Store { + return datastore.TheStore } /*SetupHandlers sets up the necessary API end points */ @@ -90,7 +90,7 @@ func WithConnection(handler common.JSONResponderF) common.JSONResponderF { Logger.Error("Error in handling the request." + err.Error()) return } - err = GetMetaDataStore().GetTransaction(ctx).Commit().Error + err = GetMetaDataStore().GetTransaction(ctx).Commit().Error() if err != nil { return resp, common.NewErrorf("commit_error", "error committing to meta store: %v", err) @@ -293,7 +293,7 @@ func HandleShutdown(ctx context.Context) { select { case <-ctx.Done(): Logger.Info("Shutting down server") - datastore.GetStore().Close() + datastore.TheStore.Close() } }() } diff --git a/code/go/0chain.net/blobbercore/handler/handler_integration_tests.go b/code/go/0chain.net/blobbercore/handler/handler_integration_tests.go index d386f15b1..9849f2d80 100644 --- a/code/go/0chain.net/blobbercore/handler/handler_integration_tests.go +++ b/code/go/0chain.net/blobbercore/handler/handler_integration_tests.go @@ -28,8 +28,8 @@ import ( var storageHandler StorageHandler -func GetMetaDataStore() *datastore.Store { - return datastore.GetStore() +func GetMetaDataStore() datastore.Store { + return datastore.TheStore } /*SetupHandlers sets up the necessary API end points */ @@ -334,7 +334,7 @@ func HandleShutdown(ctx context.Context) { select { case <-ctx.Done(): Logger.Info("Shutting down server") - datastore.GetStore().Close() + datastore.TheStore.Close() } }() } diff --git a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go index d78f9d451..08c085820 100644 --- a/code/go/0chain.net/blobbercore/handler/object_operation_handler.go +++ b/code/go/0chain.net/blobbercore/handler/object_operation_handler.go @@ -41,7 +41,7 @@ func readPreRedeem(ctx context.Context, alloc *allocation.Allocation, // check out read pool tokens if read_price > 0 var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) blobberID = node.Self.ID until = common.Now() + common.Timestamp(config.Configuration.ReadLockTimeout) @@ -103,7 +103,7 @@ func writePreRedeem(ctx context.Context, alloc *allocation.Allocation, // check out read pool tokens if read_price > 0 var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) blobberID = node.Self.ID until = common.Now() + common.Timestamp(config.Configuration.WriteLockTimeout) @@ -556,14 +556,14 @@ func (fsh *StorageHandler) CommitWrite(ctx context.Context, r *http.Request) (*C return nil, common.NewError("write_marker_error", "Error persisting the write marker") } - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) allocationUpdates := make(map[string]interface{}) allocationUpdates["blobber_size_used"] = gorm.Expr("blobber_size_used + ?", connectionObj.Size) allocationUpdates["used_size"] = gorm.Expr("used_size + ?", connectionObj.Size) allocationUpdates["allocation_root"] = allocationRoot allocationUpdates["is_redeem_required"] = true - err = db.Model(allocationObj).Updates(allocationUpdates).Error + err = db.Model(allocationObj).Updates(allocationUpdates).Error() if err != nil { return nil, common.NewError("allocation_write_error", "Error persisting the allocation object") } diff --git a/code/go/0chain.net/blobbercore/handler/worker.go b/code/go/0chain.net/blobbercore/handler/worker.go index 0716501a0..c48a9f876 100644 --- a/code/go/0chain.net/blobbercore/handler/worker.go +++ b/code/go/0chain.net/blobbercore/handler/worker.go @@ -27,7 +27,7 @@ func SetupWorkers(ctx context.Context) { } func CleanupDiskFiles(ctx context.Context) error { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) var allocations []allocation.Allocation db.Find(&allocations) for _, allocationObj := range allocations { @@ -35,7 +35,7 @@ func CleanupDiskFiles(ctx context.Context) error { mutex.Lock() _ = filestore.GetFileStore().IterateObjects(allocationObj.ID, func(contentHash string, contentSize int64) { var refs []reference.Ref - err := db.Table((reference.Ref{}).TableName()).Where(reference.Ref{ContentHash: contentHash, Type: reference.FILE}).Or(reference.Ref{ThumbnailHash: contentHash, Type: reference.FILE}).Find(&refs).Error + err := db.Table((reference.Ref{}).TableName()).Where(reference.Ref{ContentHash: contentHash, Type: reference.FILE}).Or(reference.Ref{ThumbnailHash: contentHash, Type: reference.FILE}).Find(&refs).Error() if err != nil { Logger.Error("Error in cleanup of disk files.", zap.Error(err)) return @@ -46,6 +46,7 @@ func CleanupDiskFiles(ctx context.Context) error { Logger.Error("FileStore_DeleteFile", zap.String("content_hash", contentHash), zap.Error(err)) } } + return }) mutex.Unlock() } @@ -63,8 +64,8 @@ func CleanupTempFiles(ctx context.Context) { //Logger.Info("Trying to redeem writemarkers.", zap.Any("iterInprogress", iterInprogress), zap.Any("numOfWorkers", numOfWorkers)) if !iterInprogress { iterInprogress = true //nolint:ineffassign // probably has something to do with goroutines - rctx := datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(rctx) + rctx := datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(rctx) now := time.Now() then := now.Add(time.Duration(-config.Configuration.OpenConnectionWorkerTolerance) * time.Second) var openConnectionsToDelete []allocation.AllocationChangeCollector @@ -72,8 +73,8 @@ func CleanupTempFiles(ctx context.Context) { for _, connection := range openConnectionsToDelete { Logger.Info("Deleting temp files for the connection", zap.Any("connection", connection.ConnectionID)) connection.ComputeProperties() - nctx := datastore.GetStore().CreateTransaction(ctx) - ndb := datastore.GetStore().GetTransaction(nctx) + nctx := datastore.CreateTransaction(ctx) + ndb := datastore.GetTransaction(nctx) for _, changeProcessor := range connection.AllocationChanges { if err := changeProcessor.DeleteTempFile(); err != nil { Logger.Error("AllocationChangeProcessor_DeleteTempFile", zap.Error(err)) @@ -111,8 +112,8 @@ func MoveColdDataToCloud(ctx context.Context) { // Check if capacity exceded the start capacity size if totalDiskSizeUsed > config.Configuration.ColdStorageStartCapacitySize { - rctx := datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(rctx) + rctx := datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(rctx) // Get total number of fileRefs with size greater than limit and on_cloud = false var totalRecords int64 db.Table((&reference.Ref{}).TableName()). @@ -177,9 +178,9 @@ func moveFileToCloud(ctx context.Context, fileRef *reference.Ref) { } fileRef.OnCloud = true - ctx = datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(ctx) - err = db.Save(fileRef).Error + ctx = datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(ctx) + err = db.Save(fileRef).Error() if err != nil { Logger.Error("Failed to update reference_object for on cloud true", zap.Error(err)) db.Rollback() diff --git a/code/go/0chain.net/blobbercore/readmarker/entity.go b/code/go/0chain.net/blobbercore/readmarker/entity.go index be13cd12c..d3e01e86f 100644 --- a/code/go/0chain.net/blobbercore/readmarker/entity.go +++ b/code/go/0chain.net/blobbercore/readmarker/entity.go @@ -96,9 +96,9 @@ func (ReadMarkerEntity) TableName() string { } func GetLatestReadMarkerEntity(ctx context.Context, clientID string) (*ReadMarkerEntity, error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) rm := &ReadMarkerEntity{} - err := db.First(rm, "client_id = ?", clientID).Error + err := db.First(rm, "client_id = ?", clientID).Error() if err != nil { return nil, err } @@ -108,7 +108,7 @@ func GetLatestReadMarkerEntity(ctx context.Context, clientID string) (*ReadMarke func SaveLatestReadMarker(ctx context.Context, rm *ReadMarker, isCreate bool) error { var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) rmEntity = &ReadMarkerEntity{} ) @@ -116,16 +116,16 @@ func SaveLatestReadMarker(ctx context.Context, rm *ReadMarker, isCreate bool) er rmEntity.RedeemRequired = true if isCreate { - return db.Create(rmEntity).Error + return db.Create(rmEntity).Error() } - return db.Model(rmEntity).Updates(rmEntity).Error + return db.Model(rmEntity).Updates(rmEntity).Error() } // Sync read marker with 0chain to be sure its correct. func (rm *ReadMarkerEntity) Sync(ctx context.Context) (err error) { - var db = datastore.GetStore().GetTransaction(ctx) + var db = datastore.GetTransaction(ctx) var rmUpdates = make(map[string]interface{}) rmUpdates["latest_redeem_txn_id"] = "Synced from SC REST API" @@ -171,7 +171,7 @@ func (rm *ReadMarkerEntity) UpdateStatus(ctx context.Context, "can't decode transaction output: %v", err) } - var db = datastore.GetStore().GetTransaction(ctx) + var db = datastore.GetTransaction(ctx) var rmUpdates = make(map[string]interface{}) rmUpdates["latest_redeem_txn_id"] = redeemTxn @@ -188,7 +188,7 @@ func (rm *ReadMarkerEntity) UpdateStatus(ctx context.Context, // the saving looses the numBlocks information err = db.Model(rm). Where("counter = ?", rm.LatestRM.ReadCounter). - Updates(rmUpdates).Error + Updates(rmUpdates).Error() if err != nil { return common.NewError("rme_update_status", err.Error()) } diff --git a/code/go/0chain.net/blobbercore/readmarker/protocol.go b/code/go/0chain.net/blobbercore/readmarker/protocol.go index 1089a7dc9..e12cf070a 100644 --- a/code/go/0chain.net/blobbercore/readmarker/protocol.go +++ b/code/go/0chain.net/blobbercore/readmarker/protocol.go @@ -132,7 +132,7 @@ func (rme *ReadMarkerEntity) preRedeem(ctx context.Context, // check out read pool tokens if read_price > 0 var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) blobberID = rme.LatestRM.BlobberID // clientID = rme.LatestRM.ClientID // until = common.Now() // all pools until now @@ -182,7 +182,7 @@ func (rme *ReadMarkerEntity) preRedeem(ctx context.Context, if have < want { // so, not enough tokens, let's freeze the read marker - err = db.Model(rme).Update("suspend", rme.LatestRM.ReadCounter).Error + err = db.Model(rme).Update("suspend", rme.LatestRM.ReadCounter).Error() if err != nil { return nil, common.NewErrorf("rme_pre_redeem", "saving suspended read marker: %v", err) diff --git a/code/go/0chain.net/blobbercore/readmarker/worker.go b/code/go/0chain.net/blobbercore/readmarker/worker.go index d700e3400..f2e4358de 100644 --- a/code/go/0chain.net/blobbercore/readmarker/worker.go +++ b/code/go/0chain.net/blobbercore/readmarker/worker.go @@ -88,8 +88,8 @@ func RedeemMarkers(ctx context.Context) { case <-ticker.C: if !iterInprogress { iterInprogress = true - rctx := datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(rctx) + rctx := datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(rctx) readMarkers := make([]*ReadMarkerEntity, 0) rm := &ReadMarkerEntity{RedeemRequired: true} db.Where(rm). // redeem_required = true @@ -100,14 +100,14 @@ func RedeemMarkers(ctx context.Context) { for _, rmEntity := range readMarkers { swg.Add() go func(redeemCtx context.Context, rmEntity *ReadMarkerEntity) { - redeemCtx = datastore.GetStore().CreateTransaction(redeemCtx) + redeemCtx = datastore.CreateTransaction(redeemCtx) defer redeemCtx.Done() err := RedeemReadMarker(redeemCtx, rmEntity) if err != nil { Logger.Error("Error redeeming the read marker.", zap.Error(err)) } - db := datastore.GetStore().GetTransaction(redeemCtx) - err = db.Commit().Error + db := datastore.GetTransaction(redeemCtx) + err = db.Commit().Error() if err != nil { Logger.Error("Error commiting the readmarker redeem", zap.Error(err)) } diff --git a/code/go/0chain.net/blobbercore/reference/collaborator.go b/code/go/0chain.net/blobbercore/reference/collaborator.go index 65205ff67..3a6818cdd 100644 --- a/code/go/0chain.net/blobbercore/reference/collaborator.go +++ b/code/go/0chain.net/blobbercore/reference/collaborator.go @@ -18,39 +18,39 @@ func (Collaborator) TableName() string { } func AddCollaborator(ctx context.Context, refID int64, clientID string) error { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) return db.Create(&Collaborator{ RefID: refID, ClientID: clientID, - }).Error + }).Error() } func RemoveCollaborator(ctx context.Context, refID int64, clientID string) error { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) return db.Table((&Collaborator{}).TableName()). Where(&Collaborator{RefID: refID}). - Delete(&Collaborator{}).Error + Delete(&Collaborator{}).Error() } func GetCollaborators(ctx context.Context, refID int64) ([]Collaborator, error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) collaborators := []Collaborator{} err := db.Table((&Collaborator{}).TableName()). Where(&Collaborator{RefID: refID}). Order("created_at desc"). - Find(&collaborators).Error + Find(&collaborators).Error() return collaborators, err } func IsACollaborator(ctx context.Context, refID int64, clientID string) bool { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) var collaboratorCount int64 err := db.Table((&Collaborator{}).TableName()). Where(&Collaborator{ RefID: refID, ClientID: clientID, }). - Count(&collaboratorCount).Error + Count(&collaboratorCount).Error() if err != nil { return false } diff --git a/code/go/0chain.net/blobbercore/reference/commitmetatxn.go b/code/go/0chain.net/blobbercore/reference/commitmetatxn.go index 6e52caeab..66c2613e0 100644 --- a/code/go/0chain.net/blobbercore/reference/commitmetatxn.go +++ b/code/go/0chain.net/blobbercore/reference/commitmetatxn.go @@ -18,19 +18,19 @@ func (CommitMetaTxn) TableName() string { } func AddCommitMetaTxn(ctx context.Context, refID int64, txnID string) error { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) return db.Create(&CommitMetaTxn{ RefID: refID, TxnID: txnID, - }).Error + }).Error() } func GetCommitMetaTxns(ctx context.Context, refID int64) ([]CommitMetaTxn, error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) commitMetaTxns := []CommitMetaTxn{} err := db.Table((&CommitMetaTxn{}).TableName()). Where("ref_id = ?", refID). Order("created_at desc"). - Find(&commitMetaTxns).Error + Find(&commitMetaTxns).Error() return commitMetaTxns, err } diff --git a/code/go/0chain.net/blobbercore/reference/ref.go b/code/go/0chain.net/blobbercore/reference/ref.go index f422f501f..c820ba1b9 100644 --- a/code/go/0chain.net/blobbercore/reference/ref.go +++ b/code/go/0chain.net/blobbercore/reference/ref.go @@ -135,8 +135,8 @@ func (r *Ref) SetAttributes(attr *Attributes) (err error) { func GetReference(ctx context.Context, allocationID string, path string) (*Ref, error) { ref := &Ref{} - db := datastore.GetStore().GetTransaction(ctx) - err := db.Where(&Ref{AllocationID: allocationID, Path: path}).First(ref).Error + db := datastore.GetTransaction(ctx) + err := db.Where(&Ref{AllocationID: allocationID, Path: path}).First(ref).Error() if err == nil { return ref, nil } @@ -145,8 +145,8 @@ func GetReference(ctx context.Context, allocationID string, path string) (*Ref, func GetReferenceFromLookupHash(ctx context.Context, allocationID string, path_hash string) (*Ref, error) { ref := &Ref{} - db := datastore.GetStore().GetTransaction(ctx) - err := db.Where(&Ref{AllocationID: allocationID, LookupHash: path_hash}).First(ref).Error + db := datastore.GetTransaction(ctx) + err := db.Where(&Ref{AllocationID: allocationID, LookupHash: path_hash}).First(ref).Error() if err == nil { return ref, nil } @@ -168,9 +168,9 @@ func GetSubDirsFromPath(p string) []string { func GetRefWithChildren(ctx context.Context, allocationID string, path string) (*Ref, error) { var refs []Ref - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) db = db.Where(Ref{ParentPath: path, AllocationID: allocationID}).Or(Ref{Type: DIRECTORY, Path: path, AllocationID: allocationID}) - err := db.Order("level, created_at").Find(&refs).Error + err := db.Order("level, created_at").Find(&refs).Error() if err != nil { return nil, err } @@ -193,9 +193,9 @@ func GetRefWithChildren(ctx context.Context, allocationID string, path string) ( func GetRefWithSortedChildren(ctx context.Context, allocationID string, path string) (*Ref, error) { var refs []*Ref - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) db = db.Where(Ref{ParentPath: path, AllocationID: allocationID}).Or(Ref{Type: DIRECTORY, Path: path, AllocationID: allocationID}) - err := db.Order("level, lookup_hash").Find(&refs).Error + err := db.Order("level, lookup_hash").Find(&refs).Error() if err != nil { return nil, err } @@ -332,13 +332,13 @@ func DeleteReference(ctx context.Context, refID int64, pathHash string) error { if refID <= 0 { return common.NewError("invalid_ref_id", "Invalid reference ID to delete") } - db := datastore.GetStore().GetTransaction(ctx) - return db.Where("path_hash = ?", pathHash).Delete(&Ref{ID: refID}).Error + db := datastore.GetTransaction(ctx) + return db.Where("path_hash = ?", pathHash).Delete(&Ref{ID: refID}).Error() } func (r *Ref) Save(ctx context.Context) error { - db := datastore.GetStore().GetTransaction(ctx) - return db.Save(r).Error + db := datastore.GetTransaction(ctx) + return db.Save(r).Error() } func (r *Ref) GetListingData(ctx context.Context) map[string]interface{} { diff --git a/code/go/0chain.net/blobbercore/reference/referencepath.go b/code/go/0chain.net/blobbercore/reference/referencepath.go index cc424a25e..028f5cbf7 100644 --- a/code/go/0chain.net/blobbercore/reference/referencepath.go +++ b/code/go/0chain.net/blobbercore/reference/referencepath.go @@ -14,7 +14,7 @@ func GetReferencePath(ctx context.Context, allocationID string, path string) (*R func GetReferencePathFromPaths(ctx context.Context, allocationID string, paths []string) (*Ref, error) { var refs []Ref - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) pathsAdded := make(map[string]bool) for _, path := range paths { if _, ok := pathsAdded[path]; !ok { @@ -33,7 +33,7 @@ func GetReferencePathFromPaths(ctx context.Context, allocationID string, paths [ } db = db.Or("parent_path = ? AND allocation_id = ?", "", allocationID) - err := db.Order("level, lookup_hash").Find(&refs).Error + err := db.Order("level, lookup_hash").Find(&refs).Error() if err != nil { return nil, err } @@ -67,7 +67,7 @@ func GetReferencePathFromPaths(ctx context.Context, allocationID string, paths [ func GetObjectTree(ctx context.Context, allocationID string, path string) (*Ref, error) { path = filepath.Clean(path) var refs []Ref - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) db = db.Where(Ref{Path: path, AllocationID: allocationID}) if path != "/" { db = db.Or("path LIKE ? AND allocation_id = ?", (path + "/%"), allocationID) @@ -75,7 +75,7 @@ func GetObjectTree(ctx context.Context, allocationID string, path string) (*Ref, db = db.Or("path LIKE ? AND allocation_id = ?", (path + "%"), allocationID) } - err := db.Order("level, lookup_hash").Find(&refs).Error + err := db.Order("level, lookup_hash").Find(&refs).Error() if err != nil { return nil, err } diff --git a/code/go/0chain.net/blobbercore/stats/blobberstats.go b/code/go/0chain.net/blobbercore/stats/blobberstats.go index 9a2db17a9..5439aa86c 100644 --- a/code/go/0chain.net/blobbercore/stats/blobberstats.go +++ b/code/go/0chain.net/blobbercore/stats/blobberstats.go @@ -183,7 +183,7 @@ func (bs *BlobberStats) loadStats(ctx context.Context) { AND reference_objects.deleted_at IS NULL` var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) row *sql.Row err error ) @@ -208,7 +208,7 @@ func (bs *BlobberStats) loadStats(ctx context.Context) { func (bs *BlobberStats) loadMinioStats(ctx context.Context) { var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) row *sql.Row err error ) @@ -234,7 +234,7 @@ func (bs *BlobberStats) loadAllocationStats(ctx context.Context) { bs.AllocationStats = make([]*AllocationStats, 0) var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) rows *sql.Rows err error ) @@ -290,7 +290,7 @@ func (bs *BlobberStats) loadAllocationStats(ctx context.Context) { func (bs *BlobberStats) loadChallengeStats(ctx context.Context) { var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) rows *sql.Rows err error ) @@ -346,7 +346,7 @@ func (bs *BlobberStats) loadChallengeStats(ctx context.Context) { func (bs *BlobberStats) loadAllocationChallengeStats(ctx context.Context) { var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) rows *sql.Rows err error ) @@ -418,7 +418,7 @@ func loadAllocationList(ctx context.Context) (interface{}, error) { var ( allocations = make([]AllocationId, 0) - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) rows *sql.Rows err error ) @@ -466,7 +466,7 @@ func loadAllocReadMarkersStat(ctx context.Context, allocationID string) ( rms *ReadMarkersStat, err error) { var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) rme ReadMarkerEntity ) @@ -517,7 +517,7 @@ func loadAllocWriteMarkerStat(ctx context.Context, allocationID string) ( wms *WriteMarkersStat, err error) { var ( - db = datastore.GetStore().GetTransaction(ctx) + db = datastore.GetTransaction(ctx) rows *sql.Rows ) diff --git a/code/go/0chain.net/blobbercore/stats/filestats.go b/code/go/0chain.net/blobbercore/stats/filestats.go index 8ce642387..c02fd63c0 100644 --- a/code/go/0chain.net/blobbercore/stats/filestats.go +++ b/code/go/0chain.net/blobbercore/stats/filestats.go @@ -27,7 +27,7 @@ func (FileStats) TableName() string { } func NewFileCreated(ctx context.Context, refID int64) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) stats := &FileStats{RefID: refID} stats.NumBlockDownloads = 0 stats.NumUpdates = 1 @@ -35,21 +35,21 @@ func NewFileCreated(ctx context.Context, refID int64) { } func FileUpdated(ctx context.Context, refID int64) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) stats := &FileStats{RefID: refID} db.Model(stats).Where(stats).Update("num_of_updates", gorm.Expr("num_of_updates + ?", 1)) } func FileBlockDownloaded(ctx context.Context, refID int64) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) stats := &FileStats{RefID: refID} db.Model(stats).Where(FileStats{RefID: refID}).Update("num_of_block_downloads", gorm.Expr("num_of_block_downloads + ?", 1)) } func GetFileStats(ctx context.Context, refID int64) (*FileStats, error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) stats := &FileStats{RefID: refID} - err := db.Model(stats).Where(FileStats{RefID: refID}).First(stats).Error + err := db.Model(stats).Where(FileStats{RefID: refID}).First(stats).Error() if err != nil { return nil, err } diff --git a/code/go/0chain.net/blobbercore/stats/handler.go b/code/go/0chain.net/blobbercore/stats/handler.go index fb8025854..08aaf1e76 100644 --- a/code/go/0chain.net/blobbercore/stats/handler.go +++ b/code/go/0chain.net/blobbercore/stats/handler.go @@ -259,8 +259,8 @@ const tpl = ` func StatsHandler(w http.ResponseWriter, r *http.Request) { t := template.Must(template.New("diagnostics").Funcs(funcMap).Parse(tpl)) - ctx := datastore.GetStore().CreateTransaction(r.Context()) - db := datastore.GetStore().GetTransaction(ctx) + ctx := datastore.CreateTransaction(r.Context()) + db := datastore.GetTransaction(ctx) defer db.Rollback() bs := LoadBlobberStats(ctx) err := t.Execute(w, bs) @@ -270,8 +270,8 @@ func StatsHandler(w http.ResponseWriter, r *http.Request) { } func StatsJSONHandler(ctx context.Context, r *http.Request) (interface{}, error) { - ctx = datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(ctx) + ctx = datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(ctx) defer db.Rollback() bs := LoadBlobberStats(ctx) return bs, nil @@ -280,8 +280,8 @@ func StatsJSONHandler(ctx context.Context, r *http.Request) (interface{}, error) func GetStatsHandler(ctx context.Context, r *http.Request) (interface{}, error) { q := r.URL.Query() ctx = context.WithValue(ctx, constants.ALLOCATION_CONTEXT_KEY, q.Get("allocation_id")) - ctx = datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(ctx) + ctx = datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(ctx) defer db.Rollback() allocationID := ctx.Value(constants.ALLOCATION_CONTEXT_KEY).(string) bs := &BlobberStats{} diff --git a/code/go/0chain.net/blobbercore/writemarker/entity.go b/code/go/0chain.net/blobbercore/writemarker/entity.go index 64636208e..7a4da25d3 100644 --- a/code/go/0chain.net/blobbercore/writemarker/entity.go +++ b/code/go/0chain.net/blobbercore/writemarker/entity.go @@ -55,7 +55,7 @@ func (wm *WriteMarkerEntity) UpdateStatus(ctx context.Context, status WriteMarkerStatus, statusMessage string, redeemTxn string) ( err error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) statusBytes, _ := json.Marshal(statusMessage) fmt.Println(string(statusBytes)) if status == Failed { @@ -65,7 +65,7 @@ func (wm *WriteMarkerEntity) UpdateStatus(ctx context.Context, StatusMessage: string(statusBytes), CloseTxnID: redeemTxn, ReedeemRetries: wm.ReedeemRetries, - }).Error + }).Error() return } @@ -73,7 +73,7 @@ func (wm *WriteMarkerEntity) UpdateStatus(ctx context.Context, Status: status, StatusMessage: string(statusBytes), CloseTxnID: redeemTxn, - }).Error + }).Error() if err != nil { return } @@ -99,9 +99,9 @@ func (wm *WriteMarkerEntity) UpdateStatus(ctx context.Context, } func GetWriteMarkerEntity(ctx context.Context, allocation_root string) (*WriteMarkerEntity, error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) wm := &WriteMarkerEntity{} - err := db.First(wm, "allocation_root = ?", allocation_root).Error + err := db.First(wm, "allocation_root = ?", allocation_root).Error() if err != nil { return nil, err } @@ -109,13 +109,13 @@ func GetWriteMarkerEntity(ctx context.Context, allocation_root string) (*WriteMa } func GetWriteMarkersInRange(ctx context.Context, allocationID string, startAllocationRoot string, endAllocationRoot string) ([]*WriteMarkerEntity, error) { - db := datastore.GetStore().GetTransaction(ctx) + db := datastore.GetTransaction(ctx) var seqRange []int64 err := db.Table((WriteMarkerEntity{}).TableName()). Where(WriteMarker{AllocationRoot: startAllocationRoot, AllocationID: allocationID}). Or(WriteMarker{AllocationRoot: endAllocationRoot, AllocationID: allocationID}). Order("sequence"). - Pluck("sequence", &seqRange).Error + Pluck("sequence", &seqRange).Error() if err != nil { return nil, err } @@ -124,7 +124,7 @@ func GetWriteMarkersInRange(ctx context.Context, allocationID string, startAlloc } if len(seqRange) == 2 { retMarkers := make([]*WriteMarkerEntity, 0) - err = db.Where("sequence BETWEEN ? AND ?", seqRange[0], seqRange[1]).Order("sequence").Find(&retMarkers).Error + err = db.Where("sequence BETWEEN ? AND ?", seqRange[0], seqRange[1]).Order("sequence").Find(&retMarkers).Error() if err != nil { return nil, err } @@ -137,7 +137,7 @@ func GetWriteMarkersInRange(ctx context.Context, allocationID string, startAlloc } func (wm *WriteMarkerEntity) Save(ctx context.Context) error { - db := datastore.GetStore().GetTransaction(ctx) - err := db.Save(wm).Error + db := datastore.GetTransaction(ctx) + err := db.Save(wm).Error() return err } diff --git a/code/go/0chain.net/blobbercore/writemarker/worker.go b/code/go/0chain.net/blobbercore/writemarker/worker.go index 7456d5d49..ec6c37683 100644 --- a/code/go/0chain.net/blobbercore/writemarker/worker.go +++ b/code/go/0chain.net/blobbercore/writemarker/worker.go @@ -18,10 +18,10 @@ func SetupWorkers(ctx context.Context) { } func RedeemMarkersForAllocation(ctx context.Context, allocationObj *allocation.Allocation) error { - rctx := datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(rctx) + rctx := datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(rctx) defer func() { - err := db.Commit().Error + err := db.Commit().Error() if err != nil { Logger.Error("Error committing the writemarker redeem", zap.Error(err)) } @@ -33,7 +33,7 @@ func RedeemMarkersForAllocation(ctx context.Context, allocationObj *allocation.A err := db.Not(WriteMarkerEntity{Status: Committed}). Where(WriteMarker{AllocationID: allocationObj.ID}). Order("sequence"). - Find(&writemarkers).Error + Find(&writemarkers).Error() if err != nil { return err } @@ -48,7 +48,7 @@ func RedeemMarkersForAllocation(ctx context.Context, allocationObj *allocation.A Logger.Error("Error redeeming the write marker.", zap.Any("wm", wm.WM.AllocationID), zap.Any("error", err)) continue } - err = db.Model(allocationObj).Updates(allocation.Allocation{LatestRedeemedWM: wm.WM.AllocationRoot}).Error + err = db.Model(allocationObj).Updates(allocation.Allocation{LatestRedeemedWM: wm.WM.AllocationRoot}).Error() if err != nil { Logger.Error("Error redeeming the write marker. Allocation latest wm redeemed update failed", zap.Any("wm", wm.WM.AllocationRoot), zap.Any("error", err)) return err @@ -77,8 +77,8 @@ func RedeemWriteMarkers(ctx context.Context) { case <-ticker.C: // Logger.Info("Trying to redeem writemarkers.", // zap.Any("numOfWorkers", numOfWorkers)) - rctx := datastore.GetStore().CreateTransaction(ctx) - db := datastore.GetStore().GetTransaction(rctx) + rctx := datastore.CreateTransaction(ctx) + db := datastore.GetTransaction(rctx) allocations := make([]*allocation.Allocation, 0) alloc := &allocation.Allocation{IsRedeemRequired: true} db.Where(alloc).Find(&allocations) diff --git a/code/go/0chain.net/core/go.sum b/code/go/0chain.net/core/go.sum index cf8049351..bd3f1ce11 100644 --- a/code/go/0chain.net/core/go.sum +++ b/code/go/0chain.net/core/go.sum @@ -2,6 +2,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT github.com/0chain/gosdk v1.0.32/go.mod h1:TF9Yf4Z2dwYvAoqRACWK4rApeMFV+llAnYGlXTq7wjY= github.com/0chain/gosdk v1.0.40 h1:EDjJz0Q0bOQpkdnBG2qrnl3ym+qcB0tXFiQGoIH4kY8= github.com/0chain/gosdk v1.0.40/go.mod h1:TF9Yf4Z2dwYvAoqRACWK4rApeMFV+llAnYGlXTq7wjY= +github.com/0chain/gosdk v1.0.85 h1:ynXxR45bleZl/qV9u9kJDKTQkwUSwfL9J0fSTuSiDyw= github.com/0chain/gosdk v1.0.85/go.mod h1:edV5GwogiT6nK2+s4QcFCz3saUhkuFK6EIqNJfOt8xc= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= @@ -68,6 +69,7 @@ github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/reedsolomon v1.9.2 h1:E9CMS2Pqbv+C7tsrYad4YC9MfhnMVWhMRsTi7U0UB18= github.com/klauspost/reedsolomon v1.9.2/go.mod h1:CwCi+NUr9pqSVktrkN+Ondf06rkhYZ/pcNv7fu+8Un4= +github.com/koding/cache v0.0.0-20161222233015-e8a81b0b3f20 h1:R7RAW1p8wjhlHKFhS4X7h8EePqADev/PltCmW9qlJoM= github.com/koding/cache v0.0.0-20161222233015-e8a81b0b3f20/go.mod h1:sh5SGGmQVGUkWDnxevz0I2FJ4TeC18hRPRjKVBMb2kA= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -134,13 +136,16 @@ go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM= go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -148,6 +153,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= @@ -205,6 +211,7 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU= gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= diff --git a/config/0chain_blobber.yaml b/config/0chain_blobber.yaml index b43b2502d..7d4bac8e8 100755 --- a/config/0chain_blobber.yaml +++ b/config/0chain_blobber.yaml @@ -42,7 +42,7 @@ max_file_size: 10485760 #10MB update_allocations_interval: 1m # delegate wallet (must be set) -delegate_wallet: '8b87739cd6c966c150a8a6e7b327435d4a581d9d9cc1d86a88c8a13ae1ad7a96' +delegate_wallet: '67c086f116dc97a6f76e0657a2f8873a15919b893f345d38e5a58f3d75f9929d' # min stake allowed, tokens min_stake: 1.0 # max stake allowed, tokens