diff --git a/code/go/0chain.net/blobbercore/allocation/workers.go b/code/go/0chain.net/blobbercore/allocation/workers.go index b00a29605..ab72bc6ea 100644 --- a/code/go/0chain.net/blobbercore/allocation/workers.go +++ b/code/go/0chain.net/blobbercore/allocation/workers.go @@ -246,14 +246,6 @@ type finalizeRequest struct { AllocationID string `json:"allocation_id"` } -func (fr *finalizeRequest) marshal() string { - var b, err = json.Marshal(fr) - if err != nil { - panic(err) // must never happens - } - return string(b) -} - func sendFinalizeAllocation(a *Allocation) { var tx, err = transaction.NewTransactionEntity() if err != nil { @@ -267,7 +259,7 @@ func sendFinalizeAllocation(a *Allocation) { err = tx.ExecuteSmartContract( transaction.STORAGE_CONTRACT_ADDRESS, transaction.FINALIZE_ALLOCATION, - request.marshal(), + request, 0) if err != nil { Logger.Error("sending finalize allocation", zap.Error(err)) diff --git a/code/go/0chain.net/blobbercore/challenge/protocol.go b/code/go/0chain.net/blobbercore/challenge/protocol.go index 71d7c9dc9..e5e429b0f 100644 --- a/code/go/0chain.net/blobbercore/challenge/protocol.go +++ b/code/go/0chain.net/blobbercore/challenge/protocol.go @@ -37,12 +37,7 @@ func (cr *ChallengeEntity) SubmitChallengeToBC(ctx context.Context) (*transactio sn.ChallengeID = cr.ChallengeID sn.ValidationTickets = cr.ValidationTickets - snBytes, err := json.Marshal(sn) - if err != nil { - return nil, err - } - - err = txn.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, transaction.CHALLENGE_RESPONSE, string(snBytes), 0) + err = txn.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, transaction.CHALLENGE_RESPONSE, sn, 0) if err != nil { Logger.Info("Failed submitting challenge to the mining network", zap.String("err:", err.Error())) return nil, err diff --git a/code/go/0chain.net/blobbercore/handler/protocol.go b/code/go/0chain.net/blobbercore/handler/protocol.go index 3948d7300..43249888a 100644 --- a/code/go/0chain.net/blobbercore/handler/protocol.go +++ b/code/go/0chain.net/blobbercore/handler/protocol.go @@ -2,7 +2,6 @@ package handler import ( "context" - "encoding/json" "errors" "sync" "time" @@ -185,15 +184,10 @@ func sendSmartContractBlobberUpdate(ctx context.Context) (string, error) { return "", err } - snBytes, err := json.Marshal(sn) - if err != nil { - return "", err - } - logging.Logger.Info("Adding or updating on the blockchain") err = txn.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, - transaction.UPDATE_BLOBBER_SC_NAME, string(snBytes), 0) + transaction.UPDATE_BLOBBER_SC_NAME, sn, 0) if err != nil { logging.Logger.Error("Failed to set blobber on the blockchain", zap.String("err:", err.Error())) diff --git a/code/go/0chain.net/blobbercore/readmarker/protocol.go b/code/go/0chain.net/blobbercore/readmarker/protocol.go index a5c0a8d80..bcf92a067 100644 --- a/code/go/0chain.net/blobbercore/readmarker/protocol.go +++ b/code/go/0chain.net/blobbercore/readmarker/protocol.go @@ -2,7 +2,6 @@ package readmarker import ( "context" - "encoding/json" "time" "github.com/0chain/blobber/code/go/0chain.net/core/chain" @@ -50,13 +49,7 @@ func (rme *ReadMarkerEntity) RedeemReadMarker(ctx context.Context) (err error) { ReadMarker: rme.LatestRM, } - var snBytes []byte - if snBytes, err = json.Marshal(sn); err != nil { - zLogger.Logger.Error("Error encoding SC input", zap.Error(err), zap.Any("scdata", sn)) - return common.NewErrorf("redeem_read_marker", "encoding SC data: %v", err) - } - - err = tx.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, transaction.READ_REDEEM, string(snBytes), 0) + err = tx.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, transaction.READ_REDEEM, sn, 0) if err != nil { zLogger.Logger.Info("Failed submitting read redeem", zap.Error(err)) return common.NewErrorf("redeem_read_marker", "sending transaction: %v", err) diff --git a/code/go/0chain.net/blobbercore/writemarker/protocol.go b/code/go/0chain.net/blobbercore/writemarker/protocol.go index 9d1e75d66..ea673f462 100644 --- a/code/go/0chain.net/blobbercore/writemarker/protocol.go +++ b/code/go/0chain.net/blobbercore/writemarker/protocol.go @@ -2,7 +2,6 @@ package writemarker import ( "context" - "encoding/json" "fmt" "time" @@ -98,19 +97,7 @@ func (wme *WriteMarkerEntity) RedeemMarker(ctx context.Context) error { sn.PrevAllocationRoot = wme.WM.PreviousAllocationRoot sn.WriteMarker = &wme.WM - snBytes, err := json.Marshal(sn) - if err != nil { - Logger.Error("Error encoding sc input", zap.String("err:", err.Error()), zap.Any("scdata", sn)) - wme.Status = Failed - wme.StatusMessage = "Error encoding sc input. " + err.Error() - wme.ReedeemRetries++ - if err := wme.UpdateStatus(ctx, Failed, "Error encoding sc input. "+err.Error(), ""); err != nil { - Logger.Error("WriteMarkerEntity_UpdateStatus", zap.Error(err)) - } - return err - } - - err = txn.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, transaction.CLOSE_CONNECTION_SC_NAME, string(snBytes), 0) + err = txn.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, transaction.CLOSE_CONNECTION_SC_NAME, sn, 0) if err != nil { Logger.Error("Failed during sending close connection to the miner. ", zap.String("err:", err.Error())) wme.Status = Failed diff --git a/code/go/0chain.net/blobbercore/writemarker/worker.go b/code/go/0chain.net/blobbercore/writemarker/worker.go index 4dbef3cf2..688228236 100644 --- a/code/go/0chain.net/blobbercore/writemarker/worker.go +++ b/code/go/0chain.net/blobbercore/writemarker/worker.go @@ -64,9 +64,9 @@ func redeemWriteMarker(allocationObj *allocation.Allocation, wm *WriteMarkerEnti defer func() { if shouldRollback { - if err := db.Rollback(); err != nil { + if rollbackErr := db.Rollback().Error; rollbackErr != nil { logging.Logger.Error("Error rollback on redeeming the write marker.", - zap.Any("wm", wm.WM.AllocationID), zap.Any("error", err)) + zap.Any("wm", wm.WM.AllocationID), zap.Error(rollbackErr)) } } }() diff --git a/code/go/0chain.net/core/transaction/entity.go b/code/go/0chain.net/core/transaction/entity.go index b852ee7ed..ece45c9ae 100644 --- a/code/go/0chain.net/core/transaction/entity.go +++ b/code/go/0chain.net/core/transaction/entity.go @@ -185,7 +185,7 @@ func (t *Transaction) Verify() error { var objmap map[string]json.RawMessage err = json.Unmarshal([]byte(output), &objmap) if err != nil { - return common.NewError("transaction_verify_error", "Error unmarshaling verify output. "+err.Error()) + return common.NewError("transaction_verify_error", "Error unmarshaling verify output: "+string(output)+" "+err.Error()) } err = json.Unmarshal(objmap["txn"], t) @@ -193,11 +193,11 @@ func (t *Transaction) Verify() error { var confirmation map[string]json.RawMessage err = json.Unmarshal(objmap["confirmation"], &confirmation) if err != nil { - return common.NewError("transaction_verify_error", "Error unmarshaling verify output. "+err.Error()) + return common.NewError("transaction_verify_error", "Error unmarshaling verify output->confirmation: "+string(output)+" "+err.Error()) } err = json.Unmarshal(confirmation["txn"], t) if err != nil { - return common.NewError("transaction_verify_error", "Error unmarshaling verify output. "+err.Error()) + return common.NewError("transaction_verify_error", "Error unmarshaling verify output->confirmation->txn: "+string(output)+" "+err.Error()) } } return nil diff --git a/code/go/0chain.net/validatorcore/storage/protocol.go b/code/go/0chain.net/validatorcore/storage/protocol.go index db6a87ed7..d592d5f20 100644 --- a/code/go/0chain.net/validatorcore/storage/protocol.go +++ b/code/go/0chain.net/validatorcore/storage/protocol.go @@ -152,12 +152,8 @@ func (sp *ValidatorProtocolImpl) RegisterValidator(ctx context.Context) (string, sn.StakePoolSettings.NumDelegates = config.Configuration.NumDelegates sn.StakePoolSettings.ServiceCharge = config.Configuration.ServiceCharge - snBytes, err := json.Marshal(sn) - if err != nil { - return "", err - } Logger.Info("Adding validator to the blockchain.") - err = txn.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, transaction.ADD_VALIDATOR_SC_NAME, string(snBytes), 0) + err = txn.ExecuteSmartContract(transaction.STORAGE_CONTRACT_ADDRESS, transaction.ADD_VALIDATOR_SC_NAME, sn, 0) if err != nil { Logger.Info("Failed during registering validator to the mining network", zap.String("err:", err.Error())) return "", err