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
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ linters:
- errcheck
- gofmt
- goimports
- gosec
- gosimple
- govet
- ineffassign
Expand Down
3 changes: 1 addition & 2 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func (m *Manager) publishBlock(ctx context.Context) error {
block = m.executor.CreateBlock(newHeight, lastCommit, lastHeaderHash, m.lastState)
m.logger.Debug("block info", "num_tx", len(block.Data.Txs))

commit, err := m.getCommit(block.Header)
commit, err = m.getCommit(block.Header)
if err != nil {
return err
}
Expand All @@ -496,7 +496,6 @@ func (m *Manager) publishBlock(ctx context.Context) error {

// Apply the block but DONT commit
newState, responses, err := m.executor.ApplyBlock(ctx, m.lastState, block)

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion da/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ func getKey(daHeight uint64, height uint64) ds.Key {
}

func (m *DataAvailabilityLayerClient) updateDAHeight() {
blockStep := rand.Uint64()%10 + 1
blockStep := rand.Uint64()%10 + 1 //nolint:gosec
atomic.AddUint64(&m.daHeight, blockStep)
}
10 changes: 5 additions & 5 deletions da/test/da_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func startMockGRPCServ(t *testing.T) *grpc.Server {
func startMockCelestiaNodeServer(t *testing.T) *cmock.Server {
t.Helper()
httpSrv := cmock.NewServer(mockDaBlockTime, test.NewLogger(t))
l, err := net.Listen("tcp4", ":26658")
l, err := net.Listen("tcp4", "127.0.0.1:26658")
Comment thread
nashqueue marked this conversation as resolved.
if err != nil {
t.Fatal("failed to create listener for mock celestia-node RPC server", "error", err)
}
Expand Down Expand Up @@ -209,10 +209,10 @@ func doTestRetrieve(t *testing.T, dalc da.DataAvailabilityLayerClient) {
blocks := make(map[*types.Block]uint64)

for i := uint64(0); i < 100; i++ {
b := getRandomBlock(i, rand.Int()%20)
b := getRandomBlock(i, rand.Int()%20) //nolint:gosec
resp := dalc.SubmitBlock(ctx, b)
assert.Equal(da.StatusSuccess, resp.Code, resp.Message)
time.Sleep(time.Duration(rand.Int63() % mockDaBlockTime.Milliseconds()))
time.Sleep(time.Duration(rand.Int63() % mockDaBlockTime.Milliseconds())) //nolint:gosec

countAtHeight[resp.DAHeight]++
blocks[b] = resp.DAHeight
Expand Down Expand Up @@ -270,12 +270,12 @@ func getRandomBlock(height uint64, nTxs int) *types.Block {
}

func getRandomTx() types.Tx {
size := rand.Int()%100 + 100
size := rand.Int()%100 + 100 //nolint:gosec
return types.Tx(getRandomBytes(size))
}

func getRandomBytes(n int) []byte {
data := make([]byte, n)
_, _ = rand.Read(data)
_, _ = rand.Read(data) //nolint:gosec
return data
}
2 changes: 1 addition & 1 deletion mempool/v1/mempool_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func BenchmarkTxMempool_CheckTx(b *testing.B) {
txmp := setup(b, 10000)
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec

b.ResetTimer()

Expand Down
12 changes: 6 additions & 6 deletions mempool/v1/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func checkTxs(t *testing.T, txmp *TxMempool, numTxs int, peerID uint16) []testTx
txs := make([]testTx, numTxs)
txInfo := mempool.TxInfo{SenderID: peerID}

rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec

for i := 0; i < numTxs; i++ {
prefix := make([]byte, 20)
Expand Down Expand Up @@ -405,7 +405,7 @@ func TestTxMempool_ReapMaxTxs(t *testing.T) {
func TestTxMempool_CheckTxExceedsMaxSize(t *testing.T) {
txmp := setup(t, 0)

rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec
tx := make([]byte, txmp.config.MaxTxBytes+1)
_, err := rng.Read(tx)
require.NoError(t, err)
Expand All @@ -422,7 +422,7 @@ func TestTxMempool_CheckTxExceedsMaxSize(t *testing.T) {
func TestTxMempool_CheckTxSamePeer(t *testing.T) {
txmp := setup(t, 100)
peerID := uint16(1)
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec

prefix := make([]byte, 20)
_, err := rng.Read(prefix)
Expand All @@ -437,7 +437,7 @@ func TestTxMempool_CheckTxSamePeer(t *testing.T) {
func TestTxMempool_CheckTxSameSender(t *testing.T) {
txmp := setup(t, 100)
peerID := uint16(1)
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec

prefix1 := make([]byte, 20)
_, err := rng.Read(prefix1)
Expand All @@ -458,7 +458,7 @@ func TestTxMempool_CheckTxSameSender(t *testing.T) {

func TestTxMempool_ConcurrentTxs(t *testing.T) {
txmp := setup(t, 100)
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec
checkTxDone := make(chan struct{})

var wg sync.WaitGroup
Expand Down Expand Up @@ -635,7 +635,7 @@ func TestTxMempool_CheckTxPostCheckError(t *testing.T) {
return testCase.err
}
txmp := setup(t, 0, WithPostCheck(postCheckFn))
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
rng := rand.New(rand.NewSource(time.Now().UnixNano())) //nolint:gosec
tx := make([]byte, txmp.config.MaxTxBytes-1)
_, err := rng.Read(tx)
require.NoError(t, err)
Expand Down
3 changes: 1 addition & 2 deletions node/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type FullNode struct {
cancel context.CancelFunc
}

// NewNode creates new Rollkit node.
// newFullNode creates a new Rollkit full node.
func newFullNode(
ctx context.Context,
conf config.NodeConfig,
Expand Down Expand Up @@ -392,7 +392,6 @@ func createAndStartIndexerService(
eventBus *tmtypes.EventBus,
logger log.Logger,
) (*txindex.IndexerService, txindex.TxIndexer, indexer.BlockIndexer, error) {

var (
txIndexer txindex.TxIndexer
blockIndexer indexer.BlockIndexer
Expand Down
4 changes: 2 additions & 2 deletions node/full_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,13 @@ func getRandomBlockWithProposer(height uint64, nTxs int, proposerAddr []byte) *t
}

func getRandomTx() types.Tx {
size := rand.Int()%100 + 100
size := rand.Int()%100 + 100 //nolint:gosec
return types.Tx(getRandomBytes(size))
}

func getRandomBytes(n int) []byte {
data := make([]byte, n)
_, _ = rand.Read(data)
_, _ = crand.Read(data)
return data
}

Expand Down
2 changes: 1 addition & 1 deletion node/full_node_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestAggregatorMode(t *testing.T) {
return
default:
node.incomingTxCh <- &p2p.GossipMessage{Data: []byte(time.Now().String()), From: pid}
time.Sleep(time.Duration(mrand.Uint32()%20) * time.Millisecond)
time.Sleep(time.Duration(mrand.Uint32()%20) * time.Millisecond) //nolint:gosec
}
}
}()
Expand Down
5 changes: 4 additions & 1 deletion rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ func (s *Server) startRPC() error {

func (s *Server) serve(listener net.Listener, handler http.Handler) error {
s.Logger.Info("serving HTTP", "listen address", listener.Addr())
s.server = http.Server{Handler: handler}
s.server = http.Server{
Handler: handler,
ReadHeaderTimeout: time.Second * 2,
}
if s.config.TLSCertFile != "" && s.config.TLSKeyFile != "" {
return s.server.ServeTLS(listener, s.config.CertFile(), s.config.KeyFile())
}
Expand Down
4 changes: 2 additions & 2 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ func getRandomBlock(height uint64, nTxs int) *types.Block {
}

func getRandomTx() types.Tx {
size := rand.Int()%100 + 100
size := rand.Int()%100 + 100 //nolint:gosec
return types.Tx(getRandomBytes(size))
}

func getRandomBytes(n int) []byte {
data := make([]byte, n)
_, _ = rand.Read(data)
_, _ = rand.Read(data) //nolint:gosec
return data
}

Expand Down
3 changes: 2 additions & 1 deletion types/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ func byteSlicesToTxs(bytes [][]byte) Txs {
func evidenceToProto(evidence EvidenceData) []*abci.Evidence {
var ret []*abci.Evidence
for _, e := range evidence.Evidence {
for _, ae := range e.ABCI() {
for i := range e.ABCI() {
ae := e.ABCI()[i]
ret = append(ret, &ae)
}
}
Expand Down