Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint #556

Merged
merged 2 commits into from
Feb 28, 2024
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
58 changes: 58 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: golangci-lint

on:
push:
branches:
- master
- main
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.20'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit.
version: v1.54

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
#
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true, then all caching functionality will be completely disabled,
# takes precedence over all other caching options.
# skip-cache: true

# Optional: if set to true, then the action won't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build.
# skip-build-cache: true

# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'.
# install-mode: "goinstall"
8 changes: 6 additions & 2 deletions cmd/tokengen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ func main() {
mainFlags := mainCmd.PersistentFlags()

mainFlags.String("logging-level", "", "Legacy logging level flag")
viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level"))
mainFlags.MarkHidden("logging-level")
if err := viper.BindPFlag("logging_level", mainFlags.Lookup("logging-level")); err != nil {
panic(err)
}
if err := mainFlags.MarkHidden("logging-level"); err != nil {
panic(err)
}

mainCmd.AddCommand(pp2.GenCmd())
mainCmd.AddCommand(pp2.UpdateCmd())
Expand Down
3 changes: 1 addition & 2 deletions cmd/tokengen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package main

import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -211,7 +210,7 @@ func TestGenFailure(t *testing.T) {
testGenRunWithError(gt, tokengen, test.Args, test.ErrMsg)
}

tempOutput, err := ioutil.TempDir("", "tokengen-test")
tempOutput, err := os.MkdirTemp("", "tokengen-test")
gt.Expect(err).NotTo(HaveOccurred())

defer os.RemoveAll(tempOutput)
Expand Down
38 changes: 34 additions & 4 deletions integration/nwo/token/common/ppmgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,24 @@ func (f *FabTokenPublicParamsGenerator) Generate(tms *topology.TMS, wallets *gen
}
}

//lint:ignore SA9003 To-Do pending
if len(tms.Issuers) != 0 {
// TODO:
if len(wallets.Issuers) == 0 {
return nil, errors.Errorf("no issuer wallets provided")
}
for _, issuer := range wallets.Issuers {
// Build an MSP Identity
provider, err := x509.NewProviderWithBCCSPConfig(issuer.Path, "", msp2.AuditorMSPID, nil, issuer.Opts)
if err != nil {
return nil, errors.WithMessage(err, "failed to create x509 provider")
}
id, _, err := provider.Identity(nil)
if err != nil {
return nil, errors.WithMessage(err, "failed to get identity")
}
if tms.Issuers[0] == issuer.ID {
pp.AddIssuer(id)
}
}
}

ppRaw, err := pp.Serialize()
Expand Down Expand Up @@ -152,9 +167,24 @@ func (d *DLogPublicParamsGenerator) Generate(tms *topology.TMS, wallets *generat
}
}

//lint:ignore SA9003 To-Do pending
if len(tms.Issuers) != 0 {
// TODO
if len(wallets.Issuers) == 0 {
return nil, errors.Errorf("no issuer wallets provided")
}
for _, issuer := range wallets.Issuers {
// Build an MSP Identity
provider, err := x509.NewProviderWithBCCSPConfig(issuer.Path, "", msp2.AuditorMSPID, nil, issuer.Opts)
if err != nil {
return nil, errors.WithMessage(err, "failed to create x509 provider")
}
id, _, err := provider.Identity(nil)
if err != nil {
return nil, errors.WithMessage(err, "failed to get identity")
}
if tms.Issuers[0] == issuer.ID {
pp.AddIssuer(id)
}
}
}

ppRaw, err := pp.Serialize()
Expand Down
21 changes: 2 additions & 19 deletions token/core/zkatdlog/crypto/audit/auditor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,25 +182,8 @@ func createTransferWithBogusOutput(pp *crypto.PublicParams) (*transfer2.Transfer
return transfer, metadata, tokns
}

func getIssuers(N, index int, pk *math.G1, pp []*math.G1, curve *math.Curve) []*math.G1 {
rand, err := curve.Rand()
Expect(err).NotTo(HaveOccurred())
issuers := make([]*math.G1, N)
issuers[index] = pk
for i := 0; i < N; i++ {
if i != index {
sk := curve.NewRandomZr(rand)
t := curve.NewRandomZr(rand)
issuers[i] = pp[0].Mul(sk)
issuers[i].Add(pp[1].Mul(t))
}
}
return issuers
}

type fakeProv struct {
typ string
path string
typ string
}

func (f *fakeProv) GetString(key string) string {
Expand Down Expand Up @@ -245,7 +228,7 @@ func (f *fakeProv) TranslatePath(path string) string {

func getIdemixInfo(dir string) (view.Identity, *idemix2.AuditInfo) {
registry := registry2.New()
registry.RegisterService(&fakeProv{typ: "memory"})
Expect(registry.RegisterService(&fakeProv{typ: "memory"})).NotTo(HaveOccurred())

kvss, err := kvs.New(registry, "memory", "")
Expect(err).NotTo(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion token/core/zkatdlog/crypto/common/nym.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (v *NymVerifier) Verify(message []byte, signature []byte) error {
}
// compute challenge
if v.Curve == nil {
errors.Errorf("failed to verify nym signature: please initialize curve")
return errors.Errorf("failed to verify nym signature: please initialize curve")
}
chal := v.Curve.HashToZr(append(message, raw...))
// check challenge equality
Expand Down
2 changes: 1 addition & 1 deletion token/core/zkatdlog/crypto/issue/wellformedness.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (p *WellFormednessProver) Prove() ([]byte, error) {
// compute challenge for proof
raw, err := common.GetG1Array(p.Commitments, p.Tokens).Bytes()
if err != nil {
errors.Wrapf(err, "The computation of the issue proof failed")
return nil, errors.Wrapf(err, "The computation of the issue proof failed")
}
// compute proof
wf, err := p.computeProof(p.Curve.HashToZr(raw))
Expand Down
2 changes: 1 addition & 1 deletion token/core/zkatdlog/crypto/pssign/blindsign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ func getPedersenParameters(length int, curve *math.Curve) []*math.G1 {

func getSigner(length int, curve *math.Curve) *pssign.Signer {
s := pssign.NewSigner(nil, nil, nil, curve)
s.KeyGen(length)
Expect(s.KeyGen(length)).ToNot(HaveOccurred())
return s
}
2 changes: 1 addition & 1 deletion token/core/zkatdlog/crypto/range/proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func getRangeProver() *rp.Prover {

func getSigner(length int) *pssign.Signer {
s := pssign.NewSigner(nil, nil, nil, math.Curves[1])
s.KeyGen(length)
Expect(s.KeyGen(length)).ToNot(HaveOccurred())
return s
}

Expand Down
2 changes: 1 addition & 1 deletion token/core/zkatdlog/crypto/sigproof/pok_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ func prepareWitness(s *pssign.Signer) *sigproof.POKWitness {

func getSigner(length int, curve *math.Curve) *pssign.Signer {
s := &pssign.Signer{SignVerifier: &pssign.SignVerifier{Curve: curve}}
s.KeyGen(length)
Expect(s.KeyGen(length)).NotTo(HaveOccurred())
return s
}
23 changes: 2 additions & 21 deletions token/core/zkatdlog/crypto/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,6 @@ func prepareTransferRequest(pp *crypto.PublicParams, auditor *audit.Auditor) (*t
return prepareTransfer(pp, signer, auditor, auditInfo, id, owners)
}

func getIssuers(N, index int, pk *math.G1, pp []*math.G1, curve *math.Curve) []*math.G1 {
rand, err := curve.Rand()
Expect(err).NotTo(HaveOccurred())
issuers := make([]*math.G1, N)
issuers[index] = pk
for i := 0; i < N; i++ {
if i != index {
sk := curve.NewRandomZr(rand)
t := curve.NewRandomZr(rand)
issuers[i] = pp[0].Mul(sk)
issuers[i].Add(pp[1].Mul(t))
}
}

return issuers

}

func prepareTokens(values, bf []*math.Zr, ttype string, pp []*math.G1, curve *math.Curve) []*math.G1 {
tokens := make([]*math.G1, len(values))
for i := 0; i < len(values); i++ {
Expand All @@ -335,8 +317,7 @@ func prepareToken(value *math.Zr, rand *math.Zr, ttype string, pp []*math.G1, cu
}

type fakeProv struct {
typ string
path string
typ string
}

func (f *fakeProv) GetString(key string) string {
Expand Down Expand Up @@ -381,7 +362,7 @@ func (f *fakeProv) TranslatePath(path string) string {

func getIdemixInfo(dir string) (view.Identity, *idemix2.AuditInfo, driver.SigningIdentity) {
registry := registry2.New()
registry.RegisterService(&fakeProv{typ: "memory"})
Expect(registry.RegisterService(&fakeProv{typ: "memory"})).NotTo(HaveOccurred())

kvss, err := kvs.New(registry, "memory", "")
Expect(err).NotTo(HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions token/services/certifier/interactive/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func NewCertificationService(responderRegistry ResponderRegistry, mp metrics.Pro
}
}

func (c *CertificationService) Start() error {
func (c *CertificationService) Start() (err error) {
logger.Debugf("starting certifier service...")
(&sync.Once{}).Do(func() {
c.ResponderRegistry.RegisterResponder(c, &CertificationRequestView{})
err = c.ResponderRegistry.RegisterResponder(c, &CertificationRequestView{})
})
logger.Debugf("starting certifier service...done")
return nil
Expand Down
7 changes: 6 additions & 1 deletion token/services/db/sql/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"encoding/hex"
"fmt"
"regexp"
"runtime/debug"

"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/flogging"
"github.com/pkg/errors"
Expand All @@ -25,7 +26,11 @@ func initSchema(db *sql.DB, schemas ...string) error {
if err != nil {
return err
}
defer tx.Rollback()
defer func() {
if err := tx.Rollback(); err != nil {
logger.Errorf("failed to rollback [%s][%s]", err, debug.Stack())
}
}()

for _, schema := range schemas {
logger.Debug(schema)
Expand Down
7 changes: 6 additions & 1 deletion token/services/db/sql/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"os"
"path"
"runtime/debug"
"testing"
"time"

Expand Down Expand Up @@ -169,5 +170,9 @@ func startPostgresContainer(t *testing.T) (func(), string) {
t.Fatal(err)
}

return func() { pg.Terminate(ctx) }, pgConnStr
return func() {
if err := pg.Terminate(ctx); err != nil {
logger.Errorf("failed to terminate [%s][%s]", err, debug.Stack())
}
}, pgConnStr
}
12 changes: 10 additions & 2 deletions token/services/db/sql/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ func (db *TokenDB) storeToken(tr driver.TokenRecord, owners []string, table stri
if err != nil {
return errors.New("failed starting a db transaction")
}
defer tx.Rollback()
defer func() {
if err := tx.Rollback(); err != nil {
logger.Errorf("failed to rollback [%s][%s]", err, debug.Stack())
}
}()

// Store token
now := time.Now().UTC()
Expand Down Expand Up @@ -722,7 +726,11 @@ func (db *TokenDB) StoreCertifications(certifications map[*token.ID][]byte) erro
if err != nil {
return errors.New("failed starting a transaction")
}
defer tx.Rollback()
defer func() {
if err := tx.Rollback(); err != nil {
logger.Errorf("failed to rollback [%s][%s]", err, debug.Stack())
}
}()
for tokenID, certification := range certifications {
if tokenID == nil {
return errors.Errorf("invalid token-id, cannot be nil")
Expand Down
2 changes: 0 additions & 2 deletions token/services/db/sql/tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
"github.com/test-go/testify/assert"
)

var ns = "testing"

func TestTokensSqlite(t *testing.T) {
tempDir := t.TempDir()

Expand Down
13 changes: 11 additions & 2 deletions token/services/db/sql/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"fmt"
"math/big"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -248,7 +249,11 @@ func (db *TransactionDB) SetStatus(txID string, status driver.TxStatus) error {
if err != nil {
return errors.New("failed starting a transaction")
}
defer tx.Rollback()
defer func() {
if err := tx.Rollback(); err != nil {
logger.Errorf("failed to rollback [%s][%s]", err, debug.Stack())
}
}()

if err := db.setStatusIfExists(tx, db.table.Movements, txID, status); err != nil {
return err
Expand Down Expand Up @@ -364,7 +369,11 @@ func (db *TransactionDB) AddTransactionEndorsementAck(txID string, endorser view
if err != nil {
return errors.New("failed starting a transaction")
}
defer tx.Rollback()
defer func() {
if err := tx.Rollback(); err != nil {
logger.Errorf("failed to rollback [%s][%s]", err, debug.Stack())
}
}()
if _, err := tx.Exec(query, id, txID, endorser, sigma, now); err != nil {
return errors.Wrapf(err, "failed to execute")
}
Expand Down
Loading
Loading