Skip to content

Commit

Permalink
chore: lint green
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Nov 4, 2024
1 parent 3f1ff7f commit a0b2032
Show file tree
Hide file tree
Showing 45 changed files with 137 additions and 76 deletions.
5 changes: 3 additions & 2 deletions abci/cmd/abci-cli/abci-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/dashpay/tenderdash/abci/types"
"github.com/dashpay/tenderdash/config"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/proto/tendermint/crypto"
tmproto "github.com/dashpay/tenderdash/proto/tendermint/types"
pbversion "github.com/dashpay/tenderdash/proto/tendermint/version"
Expand Down Expand Up @@ -568,7 +569,7 @@ func cmdFinalizeBlock(cmd *cobra.Command, args []string) error {
txs[i] = txBytes
}
res, err := client.FinalizeBlock(cmd.Context(), &types.RequestFinalizeBlock{
Height: int64(height),
Height: tmmath.MustConvertInt64(height),
Block: &tmproto.Block{
Header: tmproto.Header{AppHash: appHash},
Data: tmproto.Data{Txs: txs},
Expand Down Expand Up @@ -837,5 +838,5 @@ func processProposalArgs(args []string) (int64, [][]byte, error) {
}
txsBytesArray[i] = txBytes
}
return int64(height), txsBytesArray, nil
return tmmath.MustConvertInt64(height), txsBytesArray, nil
}
9 changes: 5 additions & 4 deletions abci/example/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
tmcrypto "github.com/dashpay/tenderdash/crypto"
tmbytes "github.com/dashpay/tenderdash/libs/bytes"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/libs/service"
tmproto "github.com/dashpay/tenderdash/proto/tendermint/types"
pbversion "github.com/dashpay/tenderdash/proto/tendermint/version"
Expand Down Expand Up @@ -51,7 +52,7 @@ func testKVStore(ctx context.Context, t *testing.T, app types.Application, tx []
reqProcess := &types.RequestProcessProposal{
Txs: [][]byte{tx},
Height: height,
Version: &pbversion.Consensus{App: uint64(height)},
Version: &pbversion.Consensus{App: tmmath.MustConvertUint64(height)},
}
respProcess, err := app.ProcessProposal(ctx, reqProcess)
require.NoError(t, err)
Expand Down Expand Up @@ -290,7 +291,7 @@ func makeApplyBlock(
Hash: hash,
Height: height,
Txs: txs,
Version: &pbversion.Consensus{App: uint64(height)},
Version: &pbversion.Consensus{App: tmmath.MustConvertUint64(height)},
})
require.NoError(t, err)
require.NotZero(t, respProcessProposal)
Expand Down Expand Up @@ -415,7 +416,7 @@ func testClient(ctx context.Context, t *testing.T, app abciclient.Client, height
rpp, err := app.ProcessProposal(ctx, &types.RequestProcessProposal{
Txs: [][]byte{tx},
Height: height,
Version: &pbversion.Consensus{App: uint64(height)},
Version: &pbversion.Consensus{App: tmmath.MustConvertUint64(height)},
})
require.NoError(t, err)
require.NotZero(t, rpp)
Expand Down Expand Up @@ -555,7 +556,7 @@ func assertRespInfo(t *testing.T, expectLastBlockHeight int64, expectAppHash tmb
LastBlockHeight: expectLastBlockHeight,
LastBlockAppHash: expectAppHash,
Version: version.ABCIVersion,
AppVersion: uint64(expectLastBlockHeight + 1),
AppVersion: tmmath.MustConvertUint64(expectLastBlockHeight + 1),
Data: fmt.Sprintf(`{"appHash":"%s"}`, expectAppHash.String()),
}

Expand Down
2 changes: 1 addition & 1 deletion crypto/secp256k1/secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/dashpay/tenderdash/internal/jsontypes"

// necessary for Bitcoin address format
"golang.org/x/crypto/ripemd160" //nolint:staticcheck,deprecated
"golang.org/x/crypto/ripemd160" //nolint:staticcheck,deprecated,#nosec:G507

Check failure on line 20 in crypto/secp256k1/secp256k1.go

View workflow job for this annotation

GitHub Actions / golangci-lint

G507: Blocklisted import golang.org/x/crypto/ripemd160: deprecated and weak cryptographic primitive (gosec)
)

// -------------------------------------
Expand Down
7 changes: 5 additions & 2 deletions internal/blocksync/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/dashpay/tenderdash/internal/store"
"github.com/dashpay/tenderdash/internal/test/factory"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/types"
)

Expand Down Expand Up @@ -419,9 +420,11 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) {
// XXX: This causes a potential race condition.
// See: https://github.com/tendermint/tendermint/issues/6005
otherGenDoc, otherPrivVals := factory.RandGenesisDoc(1, factory.ConsensusParams())

newNode := rts.network.MakeNode(ctx, t, nil, p2ptest.NodeOptions{
MaxPeers: uint16(len(rts.nodes) + 1),
MaxConnected: uint16(len(rts.nodes) + 1),

MaxPeers: tmmath.MustConvertUint16(len(rts.nodes) + 1),
MaxConnected: tmmath.MustConvertUint16(len(rts.nodes) + 1),
ChanDescr: p2p.ChannelDescriptors(cfg),
})
rts.addNode(ctx, t, newNode.NodeID, otherGenDoc, otherPrivVals[0], maxBlockHeight)
Expand Down
3 changes: 2 additions & 1 deletion internal/consensus/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/dashpay/tenderdash/internal/consensus/types"
"github.com/dashpay/tenderdash/internal/libs/autofile"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
tmtime "github.com/dashpay/tenderdash/libs/time"
tmtypes "github.com/dashpay/tenderdash/types"
)
Expand Down Expand Up @@ -156,7 +157,7 @@ func TestWALWriteCommit(t *testing.T) {
// Prepare and write commit msg
height := rand.Int63()
stateID := tmtypes.RandStateID()
stateID.Height = uint64(height)
stateID.Height = tmmath.MustConvertUint64(height)
blockID := tmtypes.BlockID{
Hash: crypto.CRandBytes(crypto.HashSize),
PartSetHeader: tmtypes.PartSetHeader{
Expand Down
2 changes: 1 addition & 1 deletion internal/eventlog/cursor/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *Cursor) UnmarshalText(data []byte) error {
return fmt.Errorf("invalid sequence: %w", err)
}
c.timestamp = ts
c.sequence = uint16(sn)
c.sequence = tmmath.MustConvertUint16(sn)
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion internal/mempool/mempool_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
abciclient "github.com/dashpay/tenderdash/abci/client"
"github.com/dashpay/tenderdash/abci/example/kvstore"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
)

func BenchmarkTxMempool_CheckTx(b *testing.B) {
Expand Down Expand Up @@ -43,7 +44,7 @@ func BenchmarkTxMempool_CheckTx(b *testing.B) {

priority := int64(rng.Intn(9999-1000) + 1000)
tx := []byte(fmt.Sprintf("sender-%d-%d=%X=%d", n, peerID, prefix, priority))
txInfo := TxInfo{SenderID: uint16(peerID)}
txInfo := TxInfo{SenderID: tmmath.MustConvertUint16(peerID)}

b.StartTimer()

Expand Down
3 changes: 2 additions & 1 deletion internal/p2p/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/types"
)

Expand Down Expand Up @@ -74,7 +75,7 @@ func ParseNodeAddress(urlString string) (NodeAddress, error) {
if err != nil {
return NodeAddress{}, fmt.Errorf("invalid port %q: %w", portString, err)
}
address.Port = uint16(port64)
address.Port = tmmath.MustConvertUint16(port64)
}

address.Path = url.Path
Expand Down
6 changes: 4 additions & 2 deletions internal/p2p/rqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"time"

"github.com/gogo/protobuf/proto"

"github.com/dashpay/tenderdash/libs/math"
)

type simpleQueue struct {
Expand Down Expand Up @@ -48,7 +50,7 @@ func (q *simpleQueue) run(ctx context.Context) {
var chPriorities = make(map[ChannelID]uint, len(q.chDescs))
for _, chDesc := range q.chDescs {
chID := chDesc.ID
chPriorities[chID] = uint(chDesc.Priority)
chPriorities[chID] = chDesc.Priority
}

pq := make(priorityQueue, 0, q.maxSize)
Expand All @@ -68,7 +70,7 @@ func (q *simpleQueue) run(ctx context.Context) {
// enqueue the incoming Envelope
heap.Push(&pq, &pqEnvelope{
envelope: e,
size: uint(proto.Size(e.Message)),
size: math.MustConvertUint(proto.Size(e.Message)),
priority: chPriorities[e.ChannelID],
timestamp: time.Now().UTC(),
})
Expand Down
7 changes: 4 additions & 3 deletions internal/p2p/transport_mconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/dashpay/tenderdash/internal/libs/protoio"
"github.com/dashpay/tenderdash/internal/p2p/conn"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
p2pproto "github.com/dashpay/tenderdash/proto/tendermint/p2p"
"github.com/dashpay/tenderdash/types"
)
Expand Down Expand Up @@ -96,7 +97,7 @@ func (m *MConnTransport) Endpoint() (*Endpoint, error) {
}
if addr, ok := m.listener.Addr().(*net.TCPAddr); ok {
endpoint.IP = addr.IP
endpoint.Port = uint16(addr.Port)
endpoint.Port = tmmath.MustConvertUint16(addr.Port)
}
return endpoint, nil
}
Expand Down Expand Up @@ -488,7 +489,7 @@ func (c *mConnConnection) LocalEndpoint() Endpoint {
}
if addr, ok := c.conn.LocalAddr().(*net.TCPAddr); ok {
endpoint.IP = addr.IP
endpoint.Port = uint16(addr.Port)
endpoint.Port = tmmath.MustConvertUint16(addr.Port)
}
return endpoint
}
Expand All @@ -500,7 +501,7 @@ func (c *mConnConnection) RemoteEndpoint() Endpoint {
}
if addr, ok := c.conn.RemoteAddr().(*net.TCPAddr); ok {
endpoint.IP = addr.IP
endpoint.Port = uint16(addr.Port)
endpoint.Port = tmmath.MustConvertUint16(addr.Port)
}
return endpoint
}
Expand Down
3 changes: 2 additions & 1 deletion internal/rpc/core/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

abci "github.com/dashpay/tenderdash/abci/types"
"github.com/dashpay/tenderdash/internal/proxy"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/rpc/coretypes"
)

Expand All @@ -14,7 +15,7 @@ func (env *Environment) ABCIQuery(ctx context.Context, req *coretypes.RequestABC
resQuery, err := env.ProxyApp.Query(ctx, &abci.RequestQuery{
Path: req.Path,
Data: req.Data,
Height: int64(req.Height),
Height: tmmath.MustConvertInt64(req.Height),
Prove: req.Prove,
})
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/state/test/factory/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/dashpay/tenderdash/crypto"
sm "github.com/dashpay/tenderdash/internal/state"
"github.com/dashpay/tenderdash/internal/test/factory"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/types"
)

Expand All @@ -39,7 +40,7 @@ func MakeBlocks(ctx context.Context, t *testing.T, n int, state *sm.State, privV

// update state
appHash := make([]byte, crypto.DefaultAppHashSize)
binary.BigEndian.PutUint64(appHash, uint64(height))
binary.BigEndian.PutUint64(appHash, tmmath.MustConvertUint64(height))
changes, err := state.NewStateChangeset(ctx, sm.RoundParams{AppHash: appHash})
require.NoError(t, err)
err = changes.UpdateState(state)
Expand Down
3 changes: 2 additions & 1 deletion internal/statesync/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/dashpay/tenderdash/internal/p2p"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/light/provider"
ssproto "github.com/dashpay/tenderdash/proto/tendermint/statesync"
tmproto "github.com/dashpay/tenderdash/proto/tendermint/types"
Expand Down Expand Up @@ -106,7 +107,7 @@ func (d *Dispatcher) dispatch(ctx context.Context, peer types.NodeID, height int
if err := d.requestCh.Send(ctx, p2p.Envelope{
To: peer,
Message: &ssproto.LightBlockRequest{
Height: uint64(height),
Height: tmmath.MustConvertUint64(height),
},
}); err != nil {
close(ch)
Expand Down
5 changes: 3 additions & 2 deletions internal/statesync/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
sm "github.com/dashpay/tenderdash/internal/state"
"github.com/dashpay/tenderdash/internal/store"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/libs/service"
"github.com/dashpay/tenderdash/light/provider"
ssproto "github.com/dashpay/tenderdash/proto/tendermint/statesync"
Expand Down Expand Up @@ -848,7 +849,7 @@ func (r *Reactor) handleParamsMessage(ctx context.Context, envelope *p2p.Envelop
switch msg := envelope.Message.(type) {
case *ssproto.ParamsRequest:
r.logger.Debug("received consensus params request", "height", msg.Height)
cp, err := r.stateStore.LoadConsensusParams(int64(msg.Height))
cp, err := r.stateStore.LoadConsensusParams(tmmath.MustConvertInt64(msg.Height))
if err != nil {
r.logger.Error("failed to fetch requested consensus params",
"height", msg.Height,
Expand Down Expand Up @@ -1077,7 +1078,7 @@ func (r *Reactor) recentSnapshots(ctx context.Context, n uint32) ([]*snapshot, e
// fetchLightBlock works out whether the node has a light block at a particular
// height and if so returns it so it can be gossiped to peers
func (r *Reactor) fetchLightBlock(height uint64) (*types.LightBlock, error) {
h := int64(height)
h := tmmath.MustConvertInt64(height)

blockMeta := r.blockStore.LoadBlockMeta(h)
if blockMeta == nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/statesync/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
sm "github.com/dashpay/tenderdash/internal/state"
"github.com/dashpay/tenderdash/internal/store"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/types"
)

Expand All @@ -22,7 +23,7 @@ type LightBlockRepository struct {
// Get works out whether the node has a light block at a particular
// height and if so returns it so it can be gossiped to peers
func (r *LightBlockRepository) Get(height uint64) (*types.LightBlock, error) {
h := int64(height)
h := tmmath.MustConvertInt64(height)

blockMeta := r.blockStore.LoadBlockMeta(h)
if blockMeta == nil {
Expand Down
7 changes: 4 additions & 3 deletions internal/statesync/stateprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
sm "github.com/dashpay/tenderdash/internal/state"
tmbytes "github.com/dashpay/tenderdash/libs/bytes"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/light"
lightprovider "github.com/dashpay/tenderdash/light/provider"
lighthttp "github.com/dashpay/tenderdash/light/provider/http"
Expand Down Expand Up @@ -94,7 +95,7 @@ func NewRPCStateProvider(
func (s *stateProviderRPC) verifyLightBlockAtHeight(ctx context.Context, height uint64, ts time.Time) (*types.LightBlock, error) {
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
return s.lc.VerifyLightBlockAtHeight(ctx, int64(height), ts)
return s.lc.VerifyLightBlockAtHeight(ctx, tmmath.MustConvertInt64(height), ts)
}

// AppHash implements part of StateProvider. It calls the application to verify the
Expand Down Expand Up @@ -235,7 +236,7 @@ func NewP2PStateProvider(
func (s *stateProviderP2P) verifyLightBlockAtHeight(ctx context.Context, height uint64, ts time.Time) (*types.LightBlock, error) {
ctx, cancel := context.WithTimeout(ctx, 20*time.Second)
defer cancel()
return s.lc.VerifyLightBlockAtHeight(ctx, int64(height), ts)
return s.lc.VerifyLightBlockAtHeight(ctx, tmmath.MustConvertInt64(height), ts)
}

// AppHash implements StateProvider.
Expand Down Expand Up @@ -368,7 +369,7 @@ func (s *stateProviderP2P) consensusParams(ctx context.Context, height int64) (t
if err := s.paramsSendCh.Send(ctx, p2p.Envelope{
To: peer,
Message: &ssproto.ParamsRequest{
Height: uint64(height),
Height: tmmath.MustConvertUint64(height),
},
}); err != nil {
// this only errors if
Expand Down
5 changes: 3 additions & 2 deletions internal/statesync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
sm "github.com/dashpay/tenderdash/internal/state"
tmbytes "github.com/dashpay/tenderdash/libs/bytes"
"github.com/dashpay/tenderdash/libs/log"
tmmath "github.com/dashpay/tenderdash/libs/math"
"github.com/dashpay/tenderdash/light"
ssproto "github.com/dashpay/tenderdash/proto/tendermint/statesync"
"github.com/dashpay/tenderdash/types"
Expand Down Expand Up @@ -215,7 +216,7 @@ func (s *syncer) SyncAny(
switch {
case err == nil:
s.metrics.SnapshotHeight.Set(float64(snapshot.Height))
s.lastSyncedSnapshotHeight = int64(snapshot.Height)
s.lastSyncedSnapshotHeight = tmmath.MustConvertInt64(snapshot.Height)
return newState, commit, nil

case errors.Is(err, errAbort):
Expand Down Expand Up @@ -595,7 +596,7 @@ func (s *syncer) verifyApp(ctx context.Context, snapshot *snapshot, appVersion u
return errVerifyFailed
}

if uint64(resp.LastBlockHeight) != snapshot.Height {
if tmmath.MustConvertUint64(resp.LastBlockHeight) != snapshot.Height {
s.logger.Error(
"ABCI app reported unexpected last block height",
"expected", snapshot.Height,
Expand Down
3 changes: 2 additions & 1 deletion internal/test/factory/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package factory
import (
"context"

tmmath "github.com/dashpay/tenderdash/libs/math"
tmproto "github.com/dashpay/tenderdash/proto/tendermint/types"
"github.com/dashpay/tenderdash/types"
)
Expand All @@ -24,7 +25,7 @@ func MakeCommit(
}
vote := &types.Vote{
ValidatorProTxHash: proTxHash,
ValidatorIndex: int32(i),
ValidatorIndex: tmmath.MustConvertInt32(i),
Height: height,
Round: round,
Type: tmproto.PrecommitType,
Expand Down
Loading

0 comments on commit a0b2032

Please sign in to comment.