Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 3 additions & 4 deletions platform/fabricx/core/committer/txhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package committer

import (
"context"
"fmt"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
Expand Down Expand Up @@ -37,7 +36,7 @@ type handler struct {

func (h *handler) HandleFabricxTransaction(ctx context.Context, blkMetadata *cb.BlockMetadata, tx committer.CommitTx) (*committer.FinalityEvent, error) {
if len(blkMetadata.Metadata) < statusIdx {
return nil, fmt.Errorf("block metadata lacks transaction filter")
return nil, errors.New("block metadata lacks transaction filter")
}

statusCode := protoblocktx.Status(blkMetadata.Metadata[statusIdx][tx.TxNum])
Expand All @@ -61,7 +60,7 @@ func (h *handler) HandleFabricxTransaction(ctx context.Context, blkMetadata *cb.
// escaping the switch and discard
break
}
return nil, fmt.Errorf("failed committing transaction [txID=%s]: %w", event.TxID, err)
return nil, errors.Wrapf(err, "committing endorser transaction [txID=%s]", event.TxID)
}
if !processed {
logger.Debugf("TODO: Should we try to get chaincode events?")
Expand All @@ -74,7 +73,7 @@ func (h *handler) HandleFabricxTransaction(ctx context.Context, blkMetadata *cb.

logger.Warnf("discarding transaction [txID=%s] [reason=%v]", tx.TxID, statusCode.String())
if err := h.committer.DiscardEndorserTransaction(ctx, event.TxID, tx.BlkNum, tx.Raw, event); err != nil {
return nil, fmt.Errorf("failed discarding transaction [txID=%s]: %w", event.TxID, err)
return nil, errors.Wrapf(err, "discarding endorser transaction [txID=%s]", event.TxID)
}

return event, nil
Expand Down
5 changes: 3 additions & 2 deletions platform/fabricx/core/finality/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ SPDX-License-Identifier: Apache-2.0
package finality

import (
"fmt"
"time"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
)

const DefaultRequestTimeout = 30 * time.Second
Expand Down Expand Up @@ -37,7 +38,7 @@ func NewConfig(configService ConfigService) (*Config, error) {

err := configService.UnmarshalKey("notificationService", &config)
if err != nil {
return config, fmt.Errorf("cannot get notify service config: %w", err)
return config, errors.Wrap(err, "unmarshal notificationService")
}

return config, nil
Expand Down
7 changes: 3 additions & 4 deletions platform/fabricx/core/finality/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,22 @@ SPDX-License-Identifier: Apache-2.0
package finality

import (
"errors"
"fmt"
"os"
"time"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

var ErrInvalidAddress = fmt.Errorf("empty address")
var ErrInvalidAddress = errors.New("empty address")

func GrpcClient(c *Config) (*grpc.ClientConn, error) {
// no endpoints in config
if len(c.Endpoints) != 1 {
return nil, fmt.Errorf("we need a single endpoint")
return nil, errors.New("we need a single endpoint")
}

// currently we only support connections to a single query service
Expand Down
2 changes: 1 addition & 1 deletion platform/fabricx/core/finality/nlm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ package finality

import (
"context"
"errors"
"slices"
"sync"
"time"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
Expand Down
2 changes: 1 addition & 1 deletion platform/fabricx/core/finality/nlm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ package finality

import (
"context"
"errors"
"sync"
"sync/atomic"
"testing"
"time"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
fdriver "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver"
Expand Down
2 changes: 1 addition & 1 deletion platform/fabricx/core/finality/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ package finality

import (
"context"
"errors"
"reflect"
"sync"
"testing"
"time"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/core/generic/driver/config"
mock2 "github.com/hyperledger-labs/fabric-smart-client/platform/fabricx/core/finality/mock"
Expand Down
2 changes: 1 addition & 1 deletion platform/fabricx/core/ledger/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package ledger

import (
"context"
"errors"
"sync"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
"github.com/hyperledger-labs/fabric-smart-client/platform/fabric/driver"
cb "github.com/hyperledger/fabric-protos-go-apiv2/common"
)
Expand Down
13 changes: 6 additions & 7 deletions platform/fabricx/core/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package ledger

import (
"context"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -53,7 +52,7 @@ func (c *ledger) OnBlock(_ context.Context, block *cb.Block) (bool, error) {
for i, tx := range block.Data.Data {
_, _, chdr, err := fabricutils.UnmarshalTx(tx)
if err != nil {
return false, err
return false, errors.Wrapf(err, "unmarshal transaction channel header")
}

statusCode := protoblocktx.Status(block.Metadata.Metadata[cb.BlockMetadataIndex_TRANSACTIONS_FILTER][i])
Expand Down Expand Up @@ -89,10 +88,10 @@ func (c *ledger) GetTransactionByID(txID string) (driver.ProcessedTransaction, e
status, ok := c.statuses[txID]
c.mu.RUnlock()
if ok {
logger.Debugf("Transaction [%s] found with status [%d]", txID, int32(status))
logger.Debugf("Transaction [txID=%s] found with status [%d]", txID, int32(status))
return &liteTx{txID: txID, validationCode: status}, nil
}
logger.Warnf("transaction [%s] not found. retrying...", txID)
logger.Warnf("Transaction [txID=%s] not found. retrying...", txID)
time.Sleep(1 * time.Second)
}

Expand All @@ -107,13 +106,13 @@ func (c *ledger) GetBlockNumberByTxID(txID string) (uint64, error) {
blockNum, ok := c.blockNums[txID]
c.mu.RUnlock()
if ok {
logger.Debugf("Transaction [%s] found with blockNum [%v]", txID, blockNum)
logger.Debugf("Transaction [txID=%s] found with blockNum [%v]", txID, blockNum)
return blockNum, nil
}
logger.Warnf("transaction [%s] not found. retrying...")
logger.Warnf("Transaction [txID=%s] not found. retrying...", txID)
time.Sleep(1 * time.Second)
}
return 0, fmt.Errorf("transaction [%s] not found", txID)
return 0, errors.Errorf("transaction [txID=%s] not found", txID)
}

func (c *ledger) GetBlockByNumber(number uint64) (driver.Block, error) {
Expand Down
7 changes: 4 additions & 3 deletions platform/fabricx/core/membership/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ SPDX-License-Identifier: Apache-2.0
package membership

import (
"fmt"
"regexp"
"strconv"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
)

const (
Expand All @@ -19,7 +20,7 @@ const (

var (
myExp = regexp.MustCompile(`id=(\d+),(` + OrdererBroadcastType + `|` + OrdererDeliverType + `),(.*)`)
ErrInvalidEndpointFormat = fmt.Errorf("invalid endpoint format")
ErrInvalidEndpointFormat = errors.New("invalid endpoint format")
)

type endpoint struct {
Expand All @@ -37,7 +38,7 @@ func parseEndpoint(str string) (*endpoint, error) {

id, err := strconv.Atoi(match[1])
if err != nil {
return nil, fmt.Errorf("invalid endpoint id: %w", err)
return nil, errors.Wrap(err, "invalid endpoint id")
}

return &endpoint{
Expand Down
23 changes: 11 additions & 12 deletions platform/fabricx/core/membership/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package membership

import (
"fmt"
"sync"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
Expand Down Expand Up @@ -72,30 +71,30 @@ func (c *Service) DryUpdate(env *cb.Envelope) error {
func (c *Service) validateConfig(env *cb.Envelope) (*channelconfig.Bundle, error) {
payload, err := protoutil.UnmarshalPayload(env.Payload)
if err != nil {
return nil, errors.Wrapf(err, "cannot get payload from config transaction")
return nil, errors.Wrapf(err, "unmarshal common payload")
}

cenv, err := configtx.UnmarshalConfigEnvelope(payload.Data)
if err != nil {
return nil, errors.Wrapf(err, "error unmarshalling config which passed initial validity checks")
return nil, errors.Wrapf(err, "unmarshal config envelope")
}

// check if config tx is valid
if c.channelResources != nil {
v := c.channelResources.ConfigtxValidator()
if err := v.Validate(cenv); err != nil {
return nil, errors.Wrap(err, "failed to validate config transaction")
return nil, errors.Wrap(err, "validate config transaction")
}
}

bundle, err := channelconfig.NewBundle(c.channelID, cenv.Config, factory.GetDefault())
if err != nil {
return nil, errors.Wrapf(err, "failed to build a new bundle")
return nil, errors.Wrapf(err, "build a new bundle")
}

channelconfig.LogSanityChecks(bundle)
if err := capabilitiesSupported(bundle); err != nil {
return nil, err
return nil, errors.Wrapf(err, "check bundle capabilities")
}

return bundle, nil
Expand All @@ -108,11 +107,11 @@ func capabilitiesSupported(res channelconfig.Resources) error {
}

if err := ac.Capabilities().Supported(); err != nil {
return errors.Wrapf(err, "[Channel %s] incompatible", res.ConfigtxValidator().ChannelID())
return errors.Wrapf(err, "[Channel %s] application config capabilities incompatible", res.ConfigtxValidator().ChannelID())
}

if err := res.ChannelConfig().Capabilities().Supported(); err != nil {
return errors.Wrapf(err, "[Channel %s] incompatible", res.ConfigtxValidator().ChannelID())
return errors.Wrapf(err, "[Channel %s] channel config capabilities incompatible", res.ConfigtxValidator().ChannelID())
}

return nil
Expand All @@ -121,7 +120,7 @@ func capabilitiesSupported(res channelconfig.Resources) error {
func (c *Service) IsValid(identity view.Identity) error {
id, err := c.resources().MSPManager().DeserializeIdentity(identity)
if err != nil {
return errors.Wrapf(err, "failed deserializing identity [%s]", identity.String())
return errors.Wrapf(err, "deserializing identity [%s]", identity.String())
}

return id.Validate()
Expand All @@ -130,7 +129,7 @@ func (c *Service) IsValid(identity view.Identity) error {
func (c *Service) GetVerifier(identity view.Identity) (driver.Verifier, error) {
id, err := c.resources().MSPManager().DeserializeIdentity(identity)
if err != nil {
return nil, errors.Wrapf(err, "failed deserializing identity [%s]", identity.String())
return nil, errors.Wrapf(err, "deserializing identity [%s]", identity.String())
}
return id, nil
}
Expand All @@ -154,7 +153,7 @@ func (c *Service) GetMSPIDs() []string {
func (c *Service) OrdererConfig(cs driver.ConfigService) (string, []*grpc.ConnectionConfig, error) {
oc, ok := c.resources().OrdererConfig()
if !ok || oc.Organizations() == nil {
return "", nil, fmt.Errorf("orderer config does not exist")
return "", nil, errors.New("orderer config does not exist")
}

tlsEnabled, isSet := cs.OrderingTLSEnabled()
Expand Down Expand Up @@ -182,7 +181,7 @@ func (c *Service) OrdererConfig(cs driver.ConfigService) (string, []*grpc.Connec

ep, err := parseEndpoint(epStr)
if err != nil {
return "", nil, fmt.Errorf("cannot parse orderer endpoint [%s]: %w", epStr, err)
return "", nil, errors.Wrapf(err, "parse orderer endpoint [%s]", epStr)
}
logger.Debugf("new OS endpoint: %s", epStr)

Expand Down
3 changes: 1 addition & 2 deletions platform/fabricx/core/transaction/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package transaction

import (
"context"
"fmt"
"sync"

"github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
Expand Down Expand Up @@ -46,7 +45,7 @@ func (m *Manager) transactionFactory(transactionType driver.TransactionType) (dr
logger.Debugf("transactionFactory called with transactionType [%v]", transactionType)
f, ok := m.transactionFactories.Load(transactionType)
if !ok {
return nil, fmt.Errorf("no transaction factory found for transaction type %v", transactionType)
return nil, errors.Errorf("no transaction factory found for transaction type %v", transactionType)
}

txFactory, ok := f.(driver.TransactionFactory)
Expand Down
Loading
Loading