Skip to content

Commit

Permalink
fixed lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dan13ram committed Jun 24, 2024
1 parent 5fa08fc commit 5046267
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ clean_tmp_data :; if [ -d "/tmp/data" ]; then sudo rm -rf /tmp/data; fi
.PHONY: install
install :; go mod download && go mod verify

.PHONY: lint
lint :; golangci-lint run

.PHONY: test
test :; go test -v ./...

Expand Down
1 change: 1 addition & 0 deletions config/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ NUM_ETHEREUM_NETWORKS=2
defer os.Remove(".test.env")

assert.Panics(t, func() {
//nolint:errcheck
loadConfigFromEnv(".test.env")
})

Expand Down
1 change: 1 addition & 0 deletions cosmos/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func (x *CosmosMessageMonitorRunnable) ValidateTxAndCreate(txDoc *models.Transac
logger.WithError(err).Errorf("Error locking transaction")
return false
} else {
//nolint:errcheck
defer x.db.Unlock(lockID)
}

Expand Down
27 changes: 14 additions & 13 deletions cosmos/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func (x *CosmosMessageSignerRunnable) SignMessage(
logger.WithError(err).Error("Error locking sequence")
return false
} else {
//nolint:errcheck
defer x.db.Unlock(lockID)
}

Expand Down Expand Up @@ -361,6 +362,7 @@ func (x *CosmosMessageSignerRunnable) ValidateEthereumTxAndSignMessage(messageDo
logger.WithError(err).Error("Error locking message")
return false
} else {
//nolint:errcheck
defer x.db.Unlock(lockID)
}

Expand Down Expand Up @@ -499,6 +501,7 @@ func (x *CosmosMessageSignerRunnable) FindMaxSequence() (uint64, error) {
if err != nil {
return 0, fmt.Errorf("could not lock sequences: %w", err)
}
//nolint:errcheck
defer x.db.Unlock(lockID)

maxSequence, err := x.db.FindMaxSequence(x.chain)
Expand Down Expand Up @@ -669,14 +672,14 @@ func (x *CosmosMessageSignerRunnable) SignRefund(
update["status"] = models.RefundStatusSigned
}

lockID, err := x.db.LockWriteSequence()
if err != nil {
if lockID, err := x.db.LockWriteSequence(); err != nil {
logger.WithError(err).Error("Error locking sequence")
return false
} else {
//nolint:errcheck
defer x.db.Unlock(lockID)
}

defer x.db.Unlock(lockID)

err = x.db.UpdateRefund(refundDoc.ID, update)
if err != nil {
logger.WithError(err).Errorf("Error updating refund")
Expand Down Expand Up @@ -829,14 +832,14 @@ func (x *CosmosMessageSignerRunnable) ValidateEthereumTxAndBroadcastMessage(mess
return x.UpdateMessage(messageDoc, bson.M{"status": models.MessageStatusInvalid})
}

lockID, err := x.db.LockWriteMessage(messageDoc)
// lock before signing so that no other validator adds a signature at the same time
if err != nil {
if lockID, err := x.db.LockWriteMessage(messageDoc); err != nil {
logger.WithError(err).Error("Error locking message")
return false
}
} else {

defer x.db.Unlock(lockID)
//nolint:errcheck
defer x.db.Unlock(lockID)
}

return x.BroadcastMessage(messageDoc)

Expand Down Expand Up @@ -1144,10 +1147,8 @@ func (x *CosmosMessageSignerRunnable) SignRefunds() bool {

success = x.SignRefund(txResponse, &refundDoc, result.SenderAddress, result.Amount) && success

if err = x.db.Unlock(lockID); err != nil {
logger.WithError(err).Error("Error unlocking refund")
success = false
}
//nolint:errcheck
x.db.Unlock(lockID)
}

return success
Expand Down
1 change: 1 addition & 0 deletions db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func InitDB(config models.MongoConfig) {

func DisconnectDB() {
if mongoDB != nil {
//nolint:errcheck
mongoDB.Disconnect()
}
}
2 changes: 0 additions & 2 deletions db/lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ type LockTestSuite struct {
db LockDB
}

var oldMongoDB Database

func (suite *LockTestSuite) SetupTest() {
suite.mockDB = mocks.NewMockDatabase(suite.T())
suite.oldMongoDB = mongoDB
Expand Down
5 changes: 2 additions & 3 deletions ethereum/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"math/big"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -34,8 +33,6 @@ type EthMessageMonitorRunnable struct {

chain models.Chain

minimumAmount *big.Int

logger *log.Entry

db db.DB
Expand Down Expand Up @@ -262,6 +259,7 @@ func (x *EthMessageMonitorRunnable) CreateMessagesForTx(txDoc *models.Transactio
logger.WithError(err).Error("Error locking transaction")
return false
} else {
//nolint:errcheck
defer x.db.Unlock(lockID)
}

Expand All @@ -270,6 +268,7 @@ func (x *EthMessageMonitorRunnable) CreateMessagesForTx(txDoc *models.Transactio
for _, event := range result.Events {
var messageContent models.MessageContent

//nolint:errcheck
messageContent.DecodeFromBytes(event.Message) // event was validated already

message, err := x.db.NewMessage(txDoc, messageContent, models.MessageStatusPending)
Expand Down
1 change: 1 addition & 0 deletions ethereum/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func (x *EthMessageRelayerRunnable) ConfirmMessagesForTx(txDoc *models.Transacti
logger.WithError(err).Error("Error locking transaction")
return false
} else {
//nolint:errcheck
defer x.db.Unlock(lockID)
}

Expand Down
1 change: 1 addition & 0 deletions ethereum/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (x *EthMessageSignerRunnable) SignMessage(messageDoc *models.Message) bool
logger.WithError(err).Errorf("Error locking message")
return false
} else {
//nolint:errcheck
defer x.db.Unlock(lockID)
}

Expand Down
4 changes: 4 additions & 0 deletions scripts/generate_keys/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func main() {
{
// ethereum
wallet, err := hdwallet.NewFromMnemonic(mnemonic)
if err != nil {
fmt.Printf("Error creating wallet: %v\n", err)
return
}

path := hdwallet.MustParseDerivationPath(common.DefaultETHHDPath)
account, err := wallet.Derive(path, false)
Expand Down

0 comments on commit 5046267

Please sign in to comment.