Skip to content

Commit b1df434

Browse files
tzdybaladlerjohn
andauthored
ci: stronger and more explicit linter options (#267)
* stronger and more explicit linter options * exclude mempool and state/indexer from golangci-lint Co-authored-by: John Adler <adlerjohn@users.noreply.github.com>
1 parent 8cd8832 commit b1df434

37 files changed

Lines changed: 352 additions & 190 deletions

.golangci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
run:
22
timeout: 5m
33
modules-download-mode: readonly
4+
# mempool and indexer code is borrowed from Tendermint
5+
skip-dirs:
6+
- mempool
7+
- state/indexer
8+
- state/txindex
49

510
linters:
611
enable:
712
- gofmt
813
- goimports
914
- misspell
15+
- revive
16+
- deadcode
17+
- errcheck
18+
- gofmt
19+
- goimports
20+
- gosimple
21+
- govet
22+
- ineffassign
23+
- misspell
24+
- staticcheck
25+
- structcheck
26+
- typecheck
27+
- unused
28+
- varcheck
29+
30+
issues:
31+
exclude-use-default: false

block/manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func getInitialState(store store.Store, genesis *tmtypes.GenesisDoc) (types.Stat
8080
return s, err
8181
}
8282

83+
// NewManager creates new block Manager.
8384
func NewManager(
8485
proposerKey crypto.PrivKey,
8586
conf config.BlockManagerConfig,
@@ -153,11 +154,13 @@ func getAddress(key crypto.PrivKey) ([]byte, error) {
153154
return tmcrypto.AddressHash(rawKey), nil
154155
}
155156

157+
// SetDALC is used to set DataAvailabilityLayerClient used by Manager.
156158
func (m *Manager) SetDALC(dalc da.DataAvailabilityLayerClient) {
157159
m.dalc = dalc
158160
m.retriever = dalc.(da.BlockRetriever)
159161
}
160162

163+
// AggregationLoop is responsible for aggregating transactions into rollup-blocks.
161164
func (m *Manager) AggregationLoop(ctx context.Context) {
162165
timer := time.NewTimer(0)
163166
for {
@@ -175,6 +178,10 @@ func (m *Manager) AggregationLoop(ctx context.Context) {
175178
}
176179
}
177180

181+
// SyncLoop is responsible for syncing blocks.
182+
//
183+
// SyncLoop processes headers gossiped in P2p network to know what's the latest block height,
184+
// block data is retrieved from DA layer.
178185
func (m *Manager) SyncLoop(ctx context.Context) {
179186
daTicker := time.NewTicker(m.conf.DABlockTime)
180187
for {

block/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestInitialState(t *testing.T) {
8787
}
8888

8989
func getMockDALC(logger log.Logger) da.DataAvailabilityLayerClient {
90-
dalc := &mockda.MockDataAvailabilityLayerClient{}
90+
dalc := &mockda.DataAvailabilityLayerClient{}
9191
_ = dalc.Init(nil, nil, logger)
9292
_ = dalc.Start()
9393
return dalc

config/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ type BlockManagerConfig struct {
4343
NamespaceID [8]byte `mapstructure:"namespace_id"`
4444
}
4545

46+
// GetViperConfig reads configuration parameters from Viper instance.
47+
//
48+
// This method is called in cosmos-sdk.
4649
func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
4750
nc.Aggregator = v.GetBool(flagAggregator)
4851
nc.DALayer = v.GetString(flagDALayer)
@@ -59,6 +62,9 @@ func (nc *NodeConfig) GetViperConfig(v *viper.Viper) error {
5962
return nil
6063
}
6164

65+
// AddFlags adds Optimint specific configuration options to cobra Command.
66+
//
67+
// This function is called in cosmos-sdk.
6268
func AddFlags(cmd *cobra.Command) {
6369
def := DefaultNodeConfig
6470
cmd.Flags().Bool(flagAggregator, def.Aggregator, "run node in aggregator mode")

config/rpc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package config
22

3+
// RPCConfig holds RPC configuration params.
34
type RPCConfig struct {
45
ListenAddress string
56

conv/abci/block.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ func ToABCIBlockMeta(block *types.Block) (*tmtypes.BlockMeta, error) {
102102
if err != nil {
103103
return nil, err
104104
}
105-
blockId := tmtypes.BlockID{Hash: tmblock.Hash()}
105+
blockID := tmtypes.BlockID{Hash: tmblock.Hash()}
106106

107107
return &tmtypes.BlockMeta{
108-
BlockID: blockId,
108+
BlockID: blockID,
109109
BlockSize: tmblock.Size(),
110110
Header: tmblock.Header,
111111
NumTxs: len(tmblock.Txs),

da/celestia/celestia.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ type DataAvailabilityLayerClient struct {
2727
var _ da.DataAvailabilityLayerClient = &DataAvailabilityLayerClient{}
2828
var _ da.BlockRetriever = &DataAvailabilityLayerClient{}
2929

30+
// Config stores Celestia DALC configuration parameters.
3031
type Config struct {
3132
BaseURL string `json:"base_url"`
3233
Timeout time.Duration `json:"timeout"`
3334
GasLimit uint64 `json:"gas_limit"`
3435
NamespaceID [8]byte `json:"namespace_id"`
3536
}
3637

38+
// Init initializes DataAvailabilityLayerClient instance.
3739
func (c *DataAvailabilityLayerClient) Init(config []byte, kvStore store.KVStore, logger log.Logger) error {
3840
c.logger = logger
3941

@@ -44,23 +46,26 @@ func (c *DataAvailabilityLayerClient) Init(config []byte, kvStore store.KVStore,
4446
return nil
4547
}
4648

49+
// Start prepares DataAvailabilityLayerClient to work.
4750
func (c *DataAvailabilityLayerClient) Start() error {
4851
c.logger.Info("starting Celestia Data Availability Layer Client", "baseURL", c.config.BaseURL)
4952
var err error
5053
c.client, err = cnc.NewClient(c.config.BaseURL, cnc.WithTimeout(c.config.Timeout))
5154
return err
5255
}
5356

57+
// Stop stops DataAvailabilityLayerClient.
5458
func (c *DataAvailabilityLayerClient) Stop() error {
5559
c.logger.Info("stopping Celestia Data Availability Layer Client")
5660
return nil
5761
}
5862

63+
// SubmitBlock submits a block to DA layer.
5964
func (c *DataAvailabilityLayerClient) SubmitBlock(block *types.Block) da.ResultSubmitBlock {
6065
blob, err := block.MarshalBinary()
6166
if err != nil {
6267
return da.ResultSubmitBlock{
63-
DAResult: da.DAResult{
68+
BaseResult: da.BaseResult{
6469
Code: da.StatusError,
6570
Message: err.Error(),
6671
},
@@ -71,7 +76,7 @@ func (c *DataAvailabilityLayerClient) SubmitBlock(block *types.Block) da.ResultS
7176

7277
if err != nil {
7378
return da.ResultSubmitBlock{
74-
DAResult: da.DAResult{
79+
BaseResult: da.BaseResult{
7580
Code: da.StatusError,
7681
Message: err.Error(),
7782
},
@@ -80,47 +85,49 @@ func (c *DataAvailabilityLayerClient) SubmitBlock(block *types.Block) da.ResultS
8085

8186
if txResponse.Code != 0 {
8287
return da.ResultSubmitBlock{
83-
DAResult: da.DAResult{
88+
BaseResult: da.BaseResult{
8489
Code: da.StatusError,
8590
Message: fmt.Sprintf("Codespace: '%s', Code: %d, Message: %s", txResponse.Codespace, txResponse.Code, txResponse.RawLog),
8691
},
8792
}
8893
}
8994

9095
return da.ResultSubmitBlock{
91-
DAResult: da.DAResult{
96+
BaseResult: da.BaseResult{
9297
Code: da.StatusSuccess,
9398
Message: "tx hash: " + txResponse.TxHash,
9499
DAHeight: uint64(txResponse.Height),
95100
},
96101
}
97102
}
98103

104+
// CheckBlockAvailability queries DA layer to check data availability of block at given height.
99105
func (c *DataAvailabilityLayerClient) CheckBlockAvailability(dataLayerHeight uint64) da.ResultCheckBlock {
100106
shares, err := c.client.NamespacedShares(context.TODO(), c.config.NamespaceID, dataLayerHeight)
101107
if err != nil {
102108
return da.ResultCheckBlock{
103-
DAResult: da.DAResult{
109+
BaseResult: da.BaseResult{
104110
Code: da.StatusError,
105111
Message: err.Error(),
106112
},
107113
}
108114
}
109115

110116
return da.ResultCheckBlock{
111-
DAResult: da.DAResult{
117+
BaseResult: da.BaseResult{
112118
Code: da.StatusSuccess,
113119
DAHeight: dataLayerHeight,
114120
},
115121
DataAvailable: len(shares) > 0,
116122
}
117123
}
118124

125+
// RetrieveBlocks gets a batch of blocks from DA layer.
119126
func (c *DataAvailabilityLayerClient) RetrieveBlocks(dataLayerHeight uint64) da.ResultRetrieveBlocks {
120127
data, err := c.client.NamespacedData(context.TODO(), c.config.NamespaceID, dataLayerHeight)
121128
if err != nil {
122129
return da.ResultRetrieveBlocks{
123-
DAResult: da.DAResult{
130+
BaseResult: da.BaseResult{
124131
Code: da.StatusError,
125132
Message: err.Error(),
126133
},
@@ -139,7 +146,7 @@ func (c *DataAvailabilityLayerClient) RetrieveBlocks(dataLayerHeight uint64) da.
139146
err := blocks[i].FromProto(&block)
140147
if err != nil {
141148
return da.ResultRetrieveBlocks{
142-
DAResult: da.DAResult{
149+
BaseResult: da.BaseResult{
143150
Code: da.StatusError,
144151
Message: err.Error(),
145152
},
@@ -148,7 +155,7 @@ func (c *DataAvailabilityLayerClient) RetrieveBlocks(dataLayerHeight uint64) da.
148155
}
149156

150157
return da.ResultRetrieveBlocks{
151-
DAResult: da.DAResult{
158+
BaseResult: da.BaseResult{
152159
Code: da.StatusSuccess,
153160
DAHeight: dataLayerHeight,
154161
},

da/celestia/mock/messages.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,30 @@ import (
99
// TODO(tzdybal): if we stop using `/namespaced_shares` we can get rid of this file.
1010

1111
const (
12-
ShareSize = 256
13-
NamespaceSize = 8
14-
MsgShareSize = ShareSize - NamespaceSize
12+
shareSize = 256
13+
namespaceSize = 8
14+
msgShareSize = shareSize - namespaceSize
1515
)
1616

1717
// splitMessage breaks the data in a message into the minimum number of
1818
// namespaced shares
1919
func splitMessage(rawData []byte, nid []byte) []NamespacedShare {
2020
shares := make([]NamespacedShare, 0)
2121
firstRawShare := append(append(
22-
make([]byte, 0, ShareSize),
22+
make([]byte, 0, shareSize),
2323
nid...),
24-
rawData[:MsgShareSize]...,
24+
rawData[:msgShareSize]...,
2525
)
2626
shares = append(shares, NamespacedShare{firstRawShare, nid})
27-
rawData = rawData[MsgShareSize:]
27+
rawData = rawData[msgShareSize:]
2828
for len(rawData) > 0 {
29-
shareSizeOrLen := min(MsgShareSize, len(rawData))
29+
shareSizeOrLen := min(msgShareSize, len(rawData))
3030
rawShare := append(append(
31-
make([]byte, 0, ShareSize),
31+
make([]byte, 0, shareSize),
3232
nid...),
3333
rawData[:shareSizeOrLen]...,
3434
)
35-
paddedShare := zeroPadIfNecessary(rawShare, ShareSize)
35+
paddedShare := zeroPadIfNecessary(rawShare, shareSize)
3636
share := NamespacedShare{paddedShare, nid}
3737
shares = append(shares, share)
3838
rawData = rawData[shareSizeOrLen:]
@@ -80,16 +80,16 @@ func marshalDelimited(data []byte) ([]byte, error) {
8080
// appendToShares appends raw data as shares.
8181
// Used to build shares from blocks/messages.
8282
func appendToShares(shares []NamespacedShare, nid []byte, rawData []byte) []NamespacedShare {
83-
if len(rawData) <= MsgShareSize {
83+
if len(rawData) <= msgShareSize {
8484
rawShare := append(append(
8585
make([]byte, 0, len(nid)+len(rawData)),
8686
nid...),
8787
rawData...,
8888
)
89-
paddedShare := zeroPadIfNecessary(rawShare, ShareSize)
89+
paddedShare := zeroPadIfNecessary(rawShare, shareSize)
9090
share := NamespacedShare{paddedShare, nid}
9191
shares = append(shares, share)
92-
} else { // len(rawData) > MsgShareSize
92+
} else { // len(rawData) > msgShareSize
9393
shares = append(shares, splitMessage(rawData, nid)...)
9494
}
9595
return shares

da/celestia/mock/server.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,24 @@ import (
2020
"github.com/celestiaorg/optimint/types"
2121
)
2222

23+
// Server mocks celestia-node HTTP API.
2324
type Server struct {
24-
mock *mockda.MockDataAvailabilityLayerClient
25+
mock *mockda.DataAvailabilityLayerClient
2526
blockTime time.Duration
2627
server *http.Server
2728
logger log.Logger
2829
}
2930

31+
// NewServer creates new instance of Server.
3032
func NewServer(blockTime time.Duration, logger log.Logger) *Server {
3133
return &Server{
32-
mock: new(mockda.MockDataAvailabilityLayerClient),
34+
mock: new(mockda.DataAvailabilityLayerClient),
3335
blockTime: blockTime,
3436
logger: logger,
3537
}
3638
}
3739

40+
// Start starts HTTP server with given listener.
3841
func (s *Server) Start(listener net.Listener) error {
3942
err := s.mock.Init([]byte(s.blockTime.String()), store.NewDefaultInMemoryKVStore(), s.logger)
4043
if err != nil {
@@ -53,6 +56,7 @@ func (s *Server) Start(listener net.Listener) error {
5356
return nil
5457
}
5558

59+
// Stop shuts down the Server.
5660
func (s *Server) Stop() {
5761
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
5862
defer cancel()

da/da.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const (
2020
StatusError
2121
)
2222

23-
type DAResult struct {
23+
// BaseResult contains basic information returned by DA layer.
24+
type BaseResult struct {
2425
// Code is to determine if the action succeeded.
2526
Code StatusCode
2627
// Message may contain DA layer specific information (like DA block height/hash, detailed error message, etc)
@@ -31,22 +32,23 @@ type DAResult struct {
3132

3233
// ResultSubmitBlock contains information returned from DA layer after block submission.
3334
type ResultSubmitBlock struct {
34-
DAResult
35+
BaseResult
3536
// Not sure if this needs to be bubbled up to other
3637
// parts of Optimint.
3738
// Hash hash.Hash
3839
}
3940

4041
// ResultCheckBlock contains information about block availability, returned from DA layer client.
4142
type ResultCheckBlock struct {
42-
DAResult
43+
BaseResult
4344
// DataAvailable is the actual answer whether the block is available or not.
4445
// It can be true if and only if Code is equal to StatusSuccess.
4546
DataAvailable bool
4647
}
4748

49+
// ResultRetrieveBlocks contains batch of blocks returned from DA layer client.
4850
type ResultRetrieveBlocks struct {
49-
DAResult
51+
BaseResult
5052
// Block is the full block retrieved from Data Availability Layer.
5153
// If Code is not equal to StatusSuccess, it has to be nil.
5254
Blocks []*types.Block
@@ -58,15 +60,18 @@ type DataAvailabilityLayerClient interface {
5860
// Init is called once to allow DA client to read configuration and initialize resources.
5961
Init(config []byte, kvStore store.KVStore, logger log.Logger) error
6062

63+
// Start is called once, after Init. It's implementation should start operation of DataAvailabilityLayerClient.
6164
Start() error
65+
66+
// Stop is called once, when DataAvailabilityLayerClient is no longer needed.
6267
Stop() error
6368

6469
// SubmitBlock submits the passed in block to the DA layer.
6570
// This should create a transaction which (potentially)
6671
// triggers a state transition in the DA layer.
6772
SubmitBlock(block *types.Block) ResultSubmitBlock
6873

69-
// CheckBlockAvailability queries DA layer to check data availability of block corresponding to given header.
74+
// CheckBlockAvailability queries DA layer to check data availability of block corresponding at given height.
7075
CheckBlockAvailability(dataLayerHeight uint64) ResultCheckBlock
7176
}
7277

0 commit comments

Comments
 (0)