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
2 changes: 1 addition & 1 deletion cmd/config/config_decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func serverDecoder(dataType, targetType reflect.Type, rawData any) (result any,
if endpoint != nil {
ret = connection.ServerConfig{Endpoint: *endpoint}
}
return ret, true, errors.Wrap(err, "failed to parse orderer endpoint")
return ret, true, err
}

func getStringData(dataType reflect.Type, rawData any) (stringData string, isStringData bool) {
Expand Down
3 changes: 1 addition & 2 deletions cmd/loadgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"os"

"github.com/cockroachdb/errors"
"github.com/hyperledger/fabric/protoutil"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -75,7 +74,7 @@ func loadGenCMD() *cobra.Command {

client, err := loadgen.NewLoadGenClient(conf)
if err != nil {
return errors.Wrap(err, "failed to create loadgen client")
return err
}
return connection.StartService(cmd.Context(), client, conf.Server)
},
Expand Down
4 changes: 2 additions & 2 deletions loadgen/adapters/orderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewOrdererAdapter(config *OrdererClientConfig, res *ClientResources) *Order
func (c *OrdererAdapter) RunWorkload(ctx context.Context, txStream *workload.StreamWithSetup) error {
client, err := deliver.New(&c.config.Orderer)
if err != nil {
return errors.Wrap(err, "failed to create orderer clients")
return err
}
defer client.CloseConnections()

Expand Down Expand Up @@ -67,7 +67,7 @@ func (c *OrdererAdapter) RunWorkload(ctx context.Context, txStream *workload.Str
streams[i], err = test.NewBroadcastStream(gCtx, &c.config.Orderer)
if err != nil {
connection.CloseConnectionsLog(streams[:i]...)
return errors.Wrap(err, "failed to create a broadcast stream")
return err
}
}
defer connection.CloseConnectionsLog(streams...)
Expand Down
4 changes: 2 additions & 2 deletions loadgen/adapters/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *SidecarAdapter) RunWorkload(ctx context.Context, txStream *workload.Str
ServerConfigs: c.config.OrdererServers,
})
if err != nil {
return errors.Wrap(err, "failed to create orderer")
return err
}

dCtx, dCancel := context.WithCancel(ctx)
Expand All @@ -60,7 +60,7 @@ func (c *SidecarAdapter) RunWorkload(ctx context.Context, txStream *workload.Str
policy.OrdererEndpoints = ordererconn.NewEndpoints(0, "msp", c.config.OrdererServers...)
configBlock, err := workload.CreateConfigBlock(&policy)
if err != nil {
return errors.Wrap(err, "failed to create config block")
return err
}
if err = orderer.SubmitBlock(ctx, configBlock); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion loadgen/adapters/sidecar_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func runSidecarReceiver(ctx context.Context, params *sidecarReceiverParameters)
Client: params.ClientConfig,
})
if err != nil {
return errors.Wrap(err, "failed to create ledger receiver")
return err
}
return runDeliveryReceiver(ctx, params.Res, func(gCtx context.Context, committedBlock chan *common.Block) error {
return ledgerReceiver.Deliver(gCtx, &sidecarclient.DeliverParameters{
Expand Down
6 changes: 3 additions & 3 deletions loadgen/adapters/sigverifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func NewSVAdapter(config *connection.MultiClientConfig, res *ClientResources) *S
func (c *SvAdapter) RunWorkload(ctx context.Context, txStream *workload.StreamWithSetup) error {
updateMsg, err := createUpdate(c.res.Profile.Transaction.Policy)
if err != nil {
return errors.Wrap(err, "failed creating verification policy")
return err
}
connections, err := connection.OpenConnections(*c.config)
if err != nil {
return errors.Wrap(err, "failed opening connections")
return err
}
defer connection.CloseConnectionsLog(connections...)

Expand Down Expand Up @@ -86,7 +86,7 @@ func createUpdate(policy *workload.PolicyProfile) (*protosigverifierservice.Upda

envelopeBytes, err := workload.CreateConfigEnvelope(policy)
if err != nil {
return nil, errors.Wrap(err, "failed creating config")
return nil, err
}
updateMsg := &protosigverifierservice.Update{
Config: &protoblocktx.ConfigTransaction{
Expand Down
2 changes: 1 addition & 1 deletion loadgen/adapters/vcservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c *VcAdapter) RunWorkload(ctx context.Context, txStream *workload.StreamWi
}
connections, connErr := connection.OpenConnections(*c.config)
if connErr != nil {
return errors.Wrap(connErr, "failed opening connection to vc-service")
return connErr
}
defer connection.CloseConnectionsLog(connections...)

Expand Down
4 changes: 2 additions & 2 deletions loadgen/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,14 @@ func makeWorkloadSetupTXs(config *ClientConfig) ([]*protoloadgen.TX, error) {
if config.Generate.Config {
configTX, err := workload.CreateConfigTx(config.LoadProfile.Transaction.Policy)
if err != nil {
return nil, errors.Wrap(err, "failed to create a config tx")
return nil, err
}
workloadSetupTXs = append(workloadSetupTXs, configTX)
}
if config.Generate.Namespaces {
metaNsTX, err := workload.CreateLoadGenNamespacesTX(config.LoadProfile.Transaction.Policy)
if err != nil {
return nil, errors.Wrap(err, "failed to create namespaces meta tx")
return nil, err
}
workloadSetupTXs = append(workloadSetupTXs, metaNsTX)
}
Expand Down
4 changes: 2 additions & 2 deletions loadgen/workload/config_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func CreateConfigTx(policy *PolicyProfile) (*protoloadgen.TX, error) {
}
envelope, err := protoutil.GetEnvelopeFromBlock(envelopeBytes)
if err != nil {
return nil, err
return nil, errors.Wrap(err, "error getting envelope")
}
_, channelHdr, err := serialization.ParseEnvelope(envelope)
if err != nil {
Expand Down Expand Up @@ -115,7 +115,7 @@ func CreateDefaultConfigBlock(conf *ConfigBlock) (*common.Block, error) {
}
metaPubKeyPath, err := writeTempPem(conf.MetaNamespaceVerificationKey)
if err != nil {
return nil, errors.Wrap(err, "failed to create temp PEM file")
return nil, err
}
defer func() {
_ = os.Remove(metaPubKeyPath)
Expand Down
2 changes: 1 addition & 1 deletion loadgen/workload/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func CreateNamespacesTxFromSigner(
}
policyBytes, err := proto.Marshal(p.GetVerificationPolicy())
if err != nil {
return nil, errors.New("failed to serialize namespace policy")
return nil, errors.Wrap(err, "failed to serialize namespace policy")
}
readWrites = append(readWrites, &protoblocktx.ReadWrite{
Key: []byte(ns),
Expand Down
2 changes: 1 addition & 1 deletion mock/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func (c *Coordinator) sendTxsValidationStatus(
for len(info) > 0 {
chunkSize := rand.Intn(len(info)) + 1
if err := c.sendTxsStatusChunk(stream, info[:chunkSize]); err != nil {
return errors.Wrap(err, "submit chunk failed")
return err
}
info = info[chunkSize:]
}
Expand Down
7 changes: 4 additions & 3 deletions service/vc/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import (
"github.com/stretchr/testify/require"

"github.com/hyperledger/fabric-x-committer/utils/connection"
"github.com/hyperledger/fabric-x-committer/utils/test"
)

func TestDatasourceName(t *testing.T) {
t.Parallel()
c1 := &DatabaseConfig{
Endpoints: []*connection.Endpoint{
connection.CreateEndpoint("localhost:5433"),
test.MustCreateEndpoint("localhost:5433"),
},
Username: "yugabyte_user",
Password: "yugabyte_pass",
Expand All @@ -31,8 +32,8 @@ func TestDatasourceName(t *testing.T) {

c2 := &DatabaseConfig{
Endpoints: []*connection.Endpoint{
connection.CreateEndpoint("host1:1111"),
connection.CreateEndpoint("host2:2222"),
test.MustCreateEndpoint("host1:1111"),
test.MustCreateEndpoint("host2:2222"),
},
Username: "yugabyte",
Password: "yugabyte",
Expand Down
3 changes: 2 additions & 1 deletion service/vc/dbinit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/hyperledger/fabric-x-committer/api/types"
"github.com/hyperledger/fabric-x-committer/utils/connection"
"github.com/hyperledger/fabric-x-committer/utils/test"
)

func TestDBInit(t *testing.T) {
Expand Down Expand Up @@ -50,7 +51,7 @@ func TestRetry(t *testing.T) {
ctx,
&DatabaseConfig{
Endpoints: []*connection.Endpoint{
connection.CreateEndpoint(":1234"),
test.MustCreateEndpoint(":1234"),
},
Username: "name",
Password: "pwd",
Expand Down
4 changes: 2 additions & 2 deletions utils/connection/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (c TLSConfig) ServerCredentials() (credentials.TransportCredentials, error)
if c.Mode == MutualTLSMode {
tlsCfg.ClientCAs, err = buildCertPool(c.CACertPaths)
if err != nil {
return nil, errors.Wrap(err, "failed to build CA certificate pool")
return nil, err
}
tlsCfg.ClientAuth = tls.RequireAndVerifyClientCert
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func (c TLSConfig) ClientCredentials() (credentials.TransportCredentials, error)
var err error
tlsCfg.RootCAs, err = buildCertPool(c.CACertPaths)
if err != nil {
return nil, errors.Wrap(err, "failed to build CA certificate pool")
return nil, err
}

return credentials.NewTLS(tlsCfg), nil
Expand Down
10 changes: 0 additions & 10 deletions utils/connection/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ func CreateEndpointHP(host, port string) *Endpoint {
}
}

// CreateEndpoint parses an endpoint from an address string.
// It panics if it fails to parse.
func CreateEndpoint(value string) *Endpoint {
endpoint, err := NewEndpoint(value)
if err != nil {
panic(errors.Wrap(err, "could not create endpoint"))
}
return endpoint
}

// NewEndpoint parses an endpoint from an address string.
func NewEndpoint(hostPort string) (*Endpoint, error) {
if len(hostPort) == 0 {
Expand Down
7 changes: 4 additions & 3 deletions utils/monitoring/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func (p *Provider) StartPrometheusServer(

l, err := serverConfig.Listener()
if err != nil {
return errors.Wrap(err, "failed to start prometheus server")
return err
}
defer connection.CloseConnectionsLog(l)

p.url, err = MakeMetricsURL(l.Addr().String())
if err != nil {
return errors.Wrap(err, "failed formatting URL")
return err
}

g, gCtx := errgroup.WithContext(ctx)
Expand Down Expand Up @@ -195,5 +195,6 @@ func (p *Provider) Registry() *prometheus.Registry {

// MakeMetricsURL construct the Prometheus metrics URL.
func MakeMetricsURL(address string) (string, error) {
return url.JoinPath(scheme, address, metricsSubPath)
ret, err := url.JoinPath(scheme, address, metricsSubPath)
return ret, errors.Wrap(err, "failed to make prometheus URL")
}
7 changes: 4 additions & 3 deletions utils/serialization/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SPDX-License-Identifier: Apache-2.0
package serialization

import (
"github.com/cockroachdb/errors"
"github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/hyperledger/fabric/protoutil"
)
Expand All @@ -15,7 +16,7 @@ import (
func UnwrapEnvelope(message []byte) ([]byte, *common.ChannelHeader, error) {
envelope, err := protoutil.GetEnvelopeFromBlock(message)
if err != nil {
return nil, nil, err
return nil, nil, errors.Wrap(err, "error parsing envelope")
}

payload, channelHdr, err := ParseEnvelope(envelope)
Expand All @@ -30,11 +31,11 @@ func UnwrapEnvelope(message []byte) ([]byte, *common.ChannelHeader, error) {
func ParseEnvelope(envelope *common.Envelope) (*common.Payload, *common.ChannelHeader, error) {
payload, err := protoutil.UnmarshalPayload(envelope.Payload)
if err != nil {
return nil, nil, err
return nil, nil, errors.Wrap(err, "error unmarshaling payload")
}
channelHdr, err := protoutil.UnmarshalChannelHeader(payload.Header.ChannelHeader)
if err != nil {
return nil, nil, err
return nil, nil, errors.Wrap(err, "error unmarshaling channel header")
}
return payload, channelHdr, nil
}
13 changes: 6 additions & 7 deletions utils/signature/block_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"crypto/sha256"
"encoding/asn1"

"github.com/cockroachdb/errors"

"github.com/hyperledger/fabric-x-committer/api/protoblocktx"
)

Expand All @@ -27,16 +29,13 @@ func DigestTxNamespace(txID string, ns *protoblocktx.TxNamespace) ([]byte, error
// ASN1MarshalTxNamespace marshals a transactions for a given namespace index.
// It uses the schema described in tx_schema.asn.
func ASN1MarshalTxNamespace(txID string, ns *protoblocktx.TxNamespace) ([]byte, error) {
n, err := TranslateTx(txID, ns)
if err != nil {
return nil, err
}
return asn1.Marshal(*n)
ret, err := asn1.Marshal(*TranslateTx(txID, ns))
return ret, errors.Wrap(err, "failed to marshal tx namespace")
}

// TranslateTx translates a TX namespace to a stab struct for tx_schema.asn.
// Any change to [*protoblocktx.Tx] requires a change to this method.
func TranslateTx(txID string, ns *protoblocktx.TxNamespace) (*TxWithNamespace, error) {
func TranslateTx(txID string, ns *protoblocktx.TxNamespace) *TxWithNamespace {
n := TxWithNamespace{
TxID: txID,
NamespaceID: ns.NsId,
Expand Down Expand Up @@ -64,7 +63,7 @@ func TranslateTx(txID string, ns *protoblocktx.TxNamespace) (*TxWithNamespace, e
Value: w.Value,
}
}
return &n, nil
return &n
}

// ProtoToAsnVersion converts the proto version to ASN.1 version.
Expand Down
3 changes: 1 addition & 2 deletions utils/signature/block_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ func FuzzASN1MarshalTxNamespace(f *testing.F) {

func requireASN1Marshal(t *testing.T, txID string, ns *protoblocktx.TxNamespace) []byte {
t.Helper()
translated, err := signature.TranslateTx(txID, ns)
require.NoError(t, err)
translated := signature.TranslateTx(txID, ns)

// The marshalled object cannot distinguish between empty and nil slice.
// So, we convert all nils to empty slices to allow comparison with the unmarshalled object.
Expand Down
3 changes: 1 addition & 2 deletions utils/signature/sigtest/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ func (f *SignerVerifierFactory) Scheme() signature.Scheme {

// NewVerifier instantiate a verifier given a public key.
func (f *SignerVerifierFactory) NewVerifier(key signature.PublicKey) (*signature.NsVerifier, error) {
v, err := signature.NewNsVerifier(f.scheme, key)
return v, errors.Wrap(err, "error creating verifier")
return signature.NewNsVerifier(f.scheme, key)
}

// NewSigner instantiate a signer given a private key.
Expand Down
4 changes: 2 additions & 2 deletions utils/signature/sigtest/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewNsSigner(scheme signature.Scheme, key []byte) (*NsSigner, error) {
default:
return nil, errors.Newf("scheme '%v' not supported", scheme)
}
return &NsSigner{signer: s}, errors.Wrap(err, "failed creating signer")
return &NsSigner{signer: s}, err
}

// NewBlsSigner instantiate a BlsSigner given a key.
Expand Down Expand Up @@ -97,7 +97,7 @@ func (v *NsSigner) SignNs(txID string, tx *protoblocktx.Tx, nsIndex int) (signat
}
digest, err := signature.DigestTxNamespace(txID, tx.Namespaces[nsIndex])
if err != nil {
return nil, errors.Wrap(err, "failed creating digest")
return nil, err
}
return v.signer.Sign(digest)
}
Expand Down
2 changes: 1 addition & 1 deletion utils/signature/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewNsVerifier(scheme Scheme, key PublicKey) (*NsVerifier, error) {
default:
return nil, errors.Newf("scheme '%v' not supported", scheme)
}
return res, errors.Wrap(err, "failed creating verifier")
return res, err
}

// VerifyNs verifies a transaction's namespace signature.
Expand Down
11 changes: 11 additions & 0 deletions utils/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"testing"
"time"

"github.com/cockroachdb/errors"
"github.com/onsi/gomega"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -431,3 +432,13 @@ func flattenEndpoint(in map[string]any) *connection.Endpoint {
}
return &connection.Endpoint{Host: hostStr, Port: int(portFloat)}
}

// MustCreateEndpoint parses an endpoint from an address string.
// It panics if it fails to parse.
func MustCreateEndpoint(value string) *connection.Endpoint {
endpoint, err := connection.NewEndpoint(value)
if err != nil {
panic(errors.Wrap(err, "could not create endpoint"))
}
return endpoint
}