Skip to content

Commit

Permalink
Merge branch 'development' into dependabot/go_modules/golang.org/x/cr…
Browse files Browse the repository at this point in the history
…ypto-0.28.0
  • Loading branch information
EclesioMeloJunior authored Oct 8, 2024
2 parents 2e151c2 + b6f4df4 commit 2e0e200
Show file tree
Hide file tree
Showing 61 changed files with 162 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: Generate coverage report
run: |
go test ./... -coverprofile=coverage.out -covermode=atomic -timeout=20m
- uses: codecov/codecov-action@v4.5.0
- uses: codecov/codecov-action@v4.6.0
with:
files: ./coverage.out
flags: unit-tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Test - Race
run: make test-using-race-detector

- uses: codecov/codecov-action@v4.5.0
- uses: codecov/codecov-action@v4.6.0
with:
if_ci_failed: success
informational: true
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ tmp
# node_modules used by polkadot.js/api tests
tests/polkadotjs_test/node_modules
!tests/polkadotjs_test/test/*.wasm

# mac specific
.DS_Store
12 changes: 6 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ run:
build-tags:
- integration

skip-files:
- .*mock_.*\.go
- .*mocks\/.*\.go

linters-settings:
govet:
# report about shadowed variables
check-shadowing: true
shadow: true

revive:
severity: warning
Expand Down Expand Up @@ -41,12 +37,12 @@ linters-settings:
- finalized
- finalize
- initialize
- color

linters:
enable:
- bodyclose
- errcheck
- exportloopref
- goconst
- gocyclo
- gofmt
Expand All @@ -70,6 +66,10 @@ linters:
- unused

issues:
exclude-files:
- .*mock_.*\.go
- .*mocks\/.*\.go

exclude-rules:
- path: _test\.go
linters:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ help: Makefile

.PHONY: lint
lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61
golangci-lint run

clean:
Expand Down
2 changes: 1 addition & 1 deletion dot/network/block_announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (s *Service) getBlockAnnounceHandshake() (Handshake, error) {

return &BlockAnnounceHandshake{
Roles: s.cfg.Roles,
BestBlockNumber: uint32(latestBlock.Number),
BestBlockNumber: uint32(latestBlock.Number), //nolint:gosec
BestBlockHash: latestBlock.Hash(),
GenesisHash: s.blockState.GenesisHash(),
}, nil
Expand Down
4 changes: 2 additions & 2 deletions dot/network/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ func newHost(ctx context.Context, cfg *Config) (*host, error) {
// This needs to be explicitly mentioned

// maxInPeers is later used in peerstate only and defines available Incoming connection slots
uint32(cfg.MaxPeers-cfg.MinPeers),
uint32(cfg.MaxPeers-cfg.MinPeers), //nolint:gosec
// maxOutPeers is later used in peerstate only and defines available Outgoing connection slots
uint32(cfg.MaxPeers/2),
uint32(cfg.MaxPeers/2), //nolint:gosec
reservedOnly,
peerSetSlotAllocTime,
)
Expand Down
2 changes: 1 addition & 1 deletion dot/network/messages/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (x *FromBlock) Encode() (FromBlockType, []byte) {
if rawValue > uint(math.MaxUint32) {
rawValue = math.MaxUint32
}
binary.LittleEndian.PutUint32(encoded, uint32(rawValue))
binary.LittleEndian.PutUint32(encoded, uint32(rawValue)) //nolint:gosec
return FromBlockNumber, encoded
case common.Hash:
return FromBlockHash, rawValue.ToBytes()
Expand Down
2 changes: 1 addition & 1 deletion dot/network/ratelimiters/sliding_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (rl *SlidingWindowRateLimiter) IsLimitExceeded(id common.Hash) bool {
recentRequests := rl.recentRequests(id)
rl.limits.Put(id, recentRequests)

return uint32(len(recentRequests)) > rl.maxReqs
return uint32(len(recentRequests)) > rl.maxReqs //nolint:gosec
}

func (rl *SlidingWindowRateLimiter) recentRequests(id common.Hash) []time.Time {
Expand Down
12 changes: 6 additions & 6 deletions dot/network/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func generateKey(seed int64, fp string) (crypto.PrivKey, error) {
func loadKey(fp string) (crypto.PrivKey, error) {
pth := path.Join(filepath.Clean(fp), DefaultKeyFile)
if _, err := os.Stat(pth); os.IsNotExist(err) {
return nil, nil
return nil, nil //nolint:nilnil
}
keyData, err := os.ReadFile(filepath.Clean(pth))
if err != nil {
Expand All @@ -106,7 +106,7 @@ func loadKey(fp string) (crypto.PrivKey, error) {
func makeDir(fp string) error {
_, e := os.Stat(fp)
if os.IsNotExist(e) {
e = os.Mkdir(fp, os.ModePerm)
e = os.Mkdir(fp, os.ModePerm) //nolint:gosec
if e != nil {
return e
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func saveKey(priv crypto.PrivKey, fp string) (err error) {
func Uint64ToLEB128(in uint64) []byte {
var out []byte
for {
b := uint8(in & 0x7f)
b := uint8(in & 0x7f) //nolint:gosec
in >>= 7
if in != 0 {
b |= 0x80
Expand Down Expand Up @@ -200,7 +200,7 @@ func readStream(stream libp2pnetwork.Stream, bufPointer *[]byte, maxSize uint64)
buf := *bufPointer
if length > uint64(len(buf)) {
logger.Warnf("received message with size %d greater than allocated message buffer size %d", length, len(buf))
extraBytes := int(length) - len(buf)
extraBytes := int(length) - len(buf) //nolint:gosec
*bufPointer = append(buf, make([]byte, extraBytes)...)
buf = *bufPointer
}
Expand All @@ -210,7 +210,7 @@ func readStream(stream libp2pnetwork.Stream, bufPointer *[]byte, maxSize uint64)
return 0, fmt.Errorf("%w: max %d, got %d", ErrGreaterThanMaxSize, maxSize, length)
}

for tot < int(length) {
for tot < int(length) { //nolint:gosec
n, err := stream.Read(buf[tot:])
if err != nil {
return n + tot, err
Expand All @@ -219,7 +219,7 @@ func readStream(stream libp2pnetwork.Stream, bufPointer *[]byte, maxSize uint64)
tot += n
}

if tot != int(length) {
if tot != int(length) { //nolint:gosec
return tot, fmt.Errorf("%w: expected %d bytes, received %d bytes", ErrFailedToReadEntireMessage, length, tot)
}

Expand Down
16 changes: 8 additions & 8 deletions dot/peerset/peerset.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (ps *PeerSet) reportPeer(change ReputationChange, peers ...peer.ID) error {

ps.resultMsgCh <- Message{
Status: Drop,
setID: uint64(i),
setID: uint64(i), //nolint:gosec
PeerID: pid,
}

Expand Down Expand Up @@ -406,7 +406,7 @@ func (ps *PeerSet) allocSlots(setIdx int) error {

ps.resultMsgCh <- Message{
Status: Connect,
setID: uint64(setIdx),
setID: uint64(setIdx), //nolint:gosec
PeerID: reservePeer,
}
}
Expand Down Expand Up @@ -444,7 +444,7 @@ func (ps *PeerSet) allocSlots(setIdx int) error {

ps.resultMsgCh <- Message{
Status: Connect,
setID: uint64(setIdx),
setID: uint64(setIdx), //nolint:gosec
PeerID: peerID,
}

Expand Down Expand Up @@ -507,7 +507,7 @@ func (ps *PeerSet) removeReservedPeers(setID int, peers ...peer.ID) error {

ps.resultMsgCh <- Message{
Status: Drop,
setID: uint64(setID),
setID: uint64(setID), //nolint:gosec
PeerID: peerID,
}
}
Expand Down Expand Up @@ -577,7 +577,7 @@ func (ps *PeerSet) removePeer(setID int, peers ...peer.ID) error {
if status := ps.peerState.peerStatus(setID, pid); status == connectedPeer {
ps.resultMsgCh <- Message{
Status: Drop,
setID: uint64(setID),
setID: uint64(setID), //nolint:gosec
PeerID: pid,
}

Expand Down Expand Up @@ -614,7 +614,7 @@ func (ps *PeerSet) incoming(setID int, peers ...peer.ID) error {
if !has {
ps.resultMsgCh <- Message{
Status: Reject,
setID: uint64(setID),
setID: uint64(setID), //nolint:gosec
PeerID: pid,
}
continue
Expand Down Expand Up @@ -643,7 +643,7 @@ func (ps *PeerSet) incoming(setID int, peers ...peer.ID) error {
state.RUnlock()

message := Message{
setID: uint64(setID),
setID: uint64(setID), //nolint:gosec
PeerID: pid,
}

Expand Down Expand Up @@ -707,7 +707,7 @@ func (ps *PeerSet) disconnect(setIdx int, reason DropReason, peers ...peer.ID) e

ps.resultMsgCh <- Message{
Status: Drop,
setID: uint64(setIdx),
setID: uint64(setIdx), //nolint:gosec
PeerID: pid,
}

Expand Down
10 changes: 5 additions & 5 deletions dot/rpc/modules/grandpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,19 @@ func (gm *GrandpaModule) RoundState(r *http.Request, req *EmptyRequest, res *Rou
return err
}

totalWeight := uint32(len(voters))
totalWeight := uint32(len(voters)) //nolint:gosec
roundstate := RoundStateResponse{
SetID: uint32(gm.blockFinalityAPI.GetSetID()),
SetID: uint32(gm.blockFinalityAPI.GetSetID()), //nolint:gosec
Best: RoundState{
Round: uint32(gm.blockFinalityAPI.GetRound()),
Round: uint32(gm.blockFinalityAPI.GetRound()), //nolint:gosec
ThresholdWeight: thresholdWeight(totalWeight),
TotalWeight: totalWeight,
Prevotes: Votes{
CurrentWeight: uint32(len(votes)),
CurrentWeight: uint32(len(votes)), //nolint:gosec
Missing: missingPrevotes,
},
Precommits: Votes{
CurrentWeight: uint32(len(commits)),
CurrentWeight: uint32(len(commits)), //nolint:gosec
Missing: missingPrecommits,
},
},
Expand Down
6 changes: 3 additions & 3 deletions dot/rpc/modules/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ func (sm *SystemModule) SyncState(r *http.Request, req *EmptyRequest, res *SyncS
}

*res = SyncStateResponse{
CurrentBlock: uint32(h.Number),
HighestBlock: uint32(sm.syncAPI.HighestBlock()),
StartingBlock: uint32(sm.networkAPI.StartingBlock()),
CurrentBlock: uint32(h.Number), //nolint:gosec
HighestBlock: uint32(sm.syncAPI.HighestBlock()), //nolint:gosec
StartingBlock: uint32(sm.networkAPI.StartingBlock()), //nolint:gosec
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions dot/state/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ func (bs *BlockState) retrieveRangeFromDatabase(startHash common.Hash,
lastPosition := blocksInRange - 1

inLoopHash := endHeader.Hash()
for currentPosition := int(lastPosition); currentPosition >= 0; currentPosition-- {
for currentPosition := int(lastPosition); currentPosition >= 0; currentPosition-- { //nolint:gosec
hashes[currentPosition] = inLoopHash

inLoopHeader, err := bs.loadHeaderFromDatabase(inLoopHash)
Expand Down Expand Up @@ -840,12 +840,12 @@ func (bs *BlockState) GetArrivalTime(hash common.Hash) (time.Time, error) {
}

ns := binary.LittleEndian.Uint64(arrivalTime)
return time.Unix(0, int64(ns)), nil
return time.Unix(0, int64(ns)), nil //nolint:gosec
}

func (bs *BlockState) setArrivalTime(hash common.Hash, arrivalTime time.Time) error {
buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, uint64(arrivalTime.UnixNano()))
binary.LittleEndian.PutUint64(buf, uint64(arrivalTime.UnixNano())) //nolint:gosec
return bs.db.Put(arrivalTimeKey(hash), buf)
}

Expand Down
4 changes: 2 additions & 2 deletions dot/state/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (s *EpochState) GetConfigData(epoch uint64, header *types.Header) (configDa
}
}

for tryEpoch := int(epoch); tryEpoch >= 0; tryEpoch-- {
for tryEpoch := int(epoch); tryEpoch >= 0; tryEpoch-- { //nolint:gosec
if tryEpoch == 0 {
return s.genesisEpochDescriptor.ConfigData, nil
}
Expand Down Expand Up @@ -819,7 +819,7 @@ func (s *EpochState) GetStartSlotForEpoch(epoch uint64, bestBlockHash common.Has
if err != nil {
return 0, fmt.Errorf("getting slot duration: %w", err)
}
return uint64(time.Now().UnixNano()) / uint64(slotDuration.Nanoseconds()), nil
return uint64(time.Now().UnixNano()) / uint64(slotDuration.Nanoseconds()), nil //nolint:gosec
}

return 0, fmt.Errorf(
Expand Down
2 changes: 1 addition & 1 deletion dot/state/grandpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func (s *GrandpaState) GetSetIDByBlockNumber(blockNumber uint) (uint64, error) {

curr = curr - 1

if int(curr) < 0 {
if int(curr) < 0 { //nolint:gosec
return 0, nil
}
}
Expand Down
3 changes: 2 additions & 1 deletion dot/state/inmemory_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ func (s *InmemoryStorageState) StoreTrie(ts *storage.TrieState, header *types.He
return fmt.Errorf("getting trie changed node hashes for block hash %s: %w", header.Hash(), err)
}

err = s.pruner.StoreJournalRecord(deletedNodeHashes, insertedNodeHashes, header.Hash(), int64(header.Number))
err = s.pruner.StoreJournalRecord(
deletedNodeHashes, insertedNodeHashes, header.Hash(), int64(header.Number)) //nolint:gosec
if err != nil {
return fmt.Errorf("storing journal record: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion dot/state/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ func AddBlocksToStateWithFixedBranches(t *testing.T, blockState *BlockState, dep
bestBlockHash = branch.hash

for i := branch.depth; i < depth; i++ {
d, err := types.NewBabePrimaryPreDigest(0, uint64(i+uint(j)+99), [32]byte{}, [64]byte{}).ToPreRuntimeDigest()
d, err := types.NewBabePrimaryPreDigest(
0, uint64(i+uint(j)+99), [32]byte{}, [64]byte{}).ToPreRuntimeDigest() //nolint:gosec
require.NoError(t, err)
require.NotNil(t, d)
digest := types.NewDigest()
Expand Down
2 changes: 1 addition & 1 deletion dot/state/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *TransactionState) AddToPool(vt *transaction.ValidTransaction) common.Ha
hash := s.pool.Insert(vt)

s.telemetry.SendMessage(
telemetry.NewTxpoolImport(uint(s.queue.Len()), uint(s.pool.Len())),
telemetry.NewTxpoolImport(uint(s.queue.Len()), uint(s.pool.Len())), //nolint:gosec
)

return hash
Expand Down
8 changes: 4 additions & 4 deletions dot/sync/fullsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func (f *FullSyncStrategy) NextActions() ([]*SyncTask, error) {
// our best block is equal or ahead of current target.
// in the node's pov we are not legging behind so there's nothing to do
// or we didn't receive block announces, so lets ask for more blocks
if uint32(bestBlockHeader.Number) >= currentTarget {
if uint32(bestBlockHeader.Number) >= currentTarget { //nolint:gosec
return f.createTasks(reqsFromQueue), nil
}

startRequestAt := bestBlockHeader.Number + 1
targetBlockNumber := startRequestAt + uint(f.numOfTasks)*127
targetBlockNumber := startRequestAt + uint(f.numOfTasks)*127 //nolint:gosec

if targetBlockNumber > uint(currentTarget) {
targetBlockNumber = uint(currentTarget)
Expand Down Expand Up @@ -312,7 +312,7 @@ func (f *FullSyncStrategy) OnBlockAnnounce(from peer.ID, msg *network.BlockAnnou
}

if msg.BestBlock {
f.peers.update(from, blockAnnounceHeaderHash, uint32(blockAnnounceHeader.Number))
f.peers.update(from, blockAnnounceHeaderHash, uint32(blockAnnounceHeader.Number)) //nolint:gosec
}

highestFinalized, err := f.blockState.GetHighestFinalisedHeader()
Expand Down Expand Up @@ -387,7 +387,7 @@ func (f *FullSyncStrategy) IsSynced() bool {
}

logger.Infof("highest block: %d target %d", highestBlock, f.peers.getTarget())
return uint32(highestBlock)+messages.MaxBlocksInResponse >= f.peers.getTarget()
return uint32(highestBlock)+messages.MaxBlocksInResponse >= f.peers.getTarget() //nolint:gosec
}

type RequestResponseData struct {
Expand Down
Loading

0 comments on commit 2e0e200

Please sign in to comment.