From 33d3d948a0ca61da6d7964b95531b4f6833cbe80 Mon Sep 17 00:00:00 2001 From: Vasyl Naumenko Date: Fri, 19 Jul 2024 16:32:23 +0300 Subject: [PATCH] ignore incomplete comment, fix namings for golint --- .github/workflows/go.yml | 2 +- example/wasm/main.go | 4 ++-- grpcutils/client.go | 4 ++-- grpcutils/util.go | 5 +++-- utils/linkedhashmap/iterator.go | 2 +- utils/sorting.go | 12 +++++----- vm/rpc.go | 10 ++++----- vm/types/block/block.go | 2 +- vm/types/config.go | 8 +++---- vm/vm.go | 40 ++++++++++++++++----------------- 10 files changed, 45 insertions(+), 44 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index dd1a60d..6e015d6 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -41,7 +41,7 @@ jobs: run: go install golang.org/x/lint/golint@latest - name: Run golint - run: golint ./... + run: golint ./... | grep -v "should have comment or be unexported" - name: Test run: go test -race -vet=off -v ./... diff --git a/example/wasm/main.go b/example/wasm/main.go index 581bcd7..ebfa9d3 100644 --- a/example/wasm/main.go +++ b/example/wasm/main.go @@ -58,7 +58,7 @@ func WasmCreator() vm.AppCreator { srvCfg := *srvconfig.DefaultConfig() grpcCfg := srvCfg.GRPC - var vmCfg vmtypes.VmConfig + var vmCfg vmtypes.VMConfig vmCfg.SetDefaults() if len(config.ConfigBytes) > 0 { if err := json.Unmarshal(config.ConfigBytes, &vmCfg); err != nil { @@ -101,7 +101,7 @@ func WasmCreator() vm.AppCreator { WithInterfaceRegistry(interfaceRegistry). WithChainID(chainID) - avaChainID, err := ids.ToID(config.ChainId) + avaChainID, err := ids.ToID(config.ChainID) if err != nil { return nil, err } diff --git a/grpcutils/client.go b/grpcutils/client.go index c35fcf4..fa427ce 100644 --- a/grpcutils/client.go +++ b/grpcutils/client.go @@ -51,7 +51,7 @@ var DefaultDialOptions = []grpc.DialOption{ grpc.WithTransportCredentials(insecure.NewCredentials()), } -// gRPC clients created from this ClientConn will wait forever for the Server to +// Dial gRPC clients created from this ClientConn will wait forever for the Server to // become Ready. If you desire a dial timeout ensure context is properly plumbed // to the client and use context.WithTimeout. // @@ -67,7 +67,7 @@ type DialOptions struct { opts []grpc.DialOption } -// append(DefaultDialOptions, ...) will always allocate a new slice and will +// newDialOpts append(DefaultDialOptions, ...) will always allocate a new slice and will // not overwrite any potential data that may have previously been appended to // DefaultServerOptions https://go.dev/ref/spec#Composite_literals func newDialOpts(opts ...DialOption) []grpc.DialOption { diff --git a/grpcutils/util.go b/grpcutils/util.go index 476a82c..0662ed7 100644 --- a/grpcutils/util.go +++ b/grpcutils/util.go @@ -12,9 +12,10 @@ import ( "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/anypb" - httppb "github.com/consideritdone/landslidevm/proto/http" spb "google.golang.org/genproto/googleapis/rpc/status" tspb "google.golang.org/protobuf/types/known/timestamppb" + + httppb "github.com/consideritdone/landslidevm/proto/http" ) func Errorf(code int, tmpl string, args ...interface{}) error { @@ -24,7 +25,7 @@ func Errorf(code int, tmpl string, args ...interface{}) error { }) } -// GetGRPCErrorFromHTTPRespone takes an HandleSimpleHTTPResponse as input and returns a gRPC error. +// GetGRPCErrorFromHTTPResponse takes an HandleSimpleHTTPResponse as input and returns a gRPC error. func GetGRPCErrorFromHTTPResponse(resp *httppb.HandleSimpleHTTPResponse) error { a, err := anypb.New(resp) if err != nil { diff --git a/utils/linkedhashmap/iterator.go b/utils/linkedhashmap/iterator.go index 2c9247c..9b233d7 100644 --- a/utils/linkedhashmap/iterator.go +++ b/utils/linkedhashmap/iterator.go @@ -8,7 +8,7 @@ import ( var _ Iter[int, struct{}] = (*iterator[int, struct{}])(nil) -// Iterates over the keys and values in a LinkedHashmap +// Iter Iterates over the keys and values in a LinkedHashmap // from oldest to newest elements. // Assumes the underlying LinkedHashmap is not modified while // the iterator is in use, except to delete elements that diff --git a/utils/sorting.go b/utils/sorting.go index c33a9e7..8f25e37 100644 --- a/utils/sorting.go +++ b/utils/sorting.go @@ -14,12 +14,12 @@ type Sortable[T any] interface { Compare(T) int } -// Sorts the elements of [s]. +// Sort sorts the elements of [s]. func Sort[T Sortable[T]](s []T) { slices.SortFunc(s, T.Compare) } -// Sorts the elements of [s] based on their hashes. +// SortByHash sorts the elements of [s] based on their hashes. func SortByHash[T ~[]byte](s []T) { slices.SortFunc(s, func(i, j T) int { iHash := hashing.ComputeHash256(i) @@ -28,7 +28,7 @@ func SortByHash[T ~[]byte](s []T) { }) } -// Returns true iff the elements in [s] are sorted. +// IsSortedBytes returns true iff the elements in [s] are sorted. func IsSortedBytes[T ~[]byte](s []T) bool { for i := 0; i < len(s)-1; i++ { if bytes.Compare(s[i], s[i+1]) == 1 { @@ -38,7 +38,7 @@ func IsSortedBytes[T ~[]byte](s []T) bool { return true } -// Returns true iff the elements in [s] are unique and sorted. +// IsSortedAndUnique returns true iff the elements in [s] are unique and sorted. func IsSortedAndUnique[T Sortable[T]](s []T) bool { for i := 0; i < len(s)-1; i++ { if s[i].Compare(s[i+1]) >= 0 { @@ -48,7 +48,7 @@ func IsSortedAndUnique[T Sortable[T]](s []T) bool { return true } -// Returns true iff the elements in [s] are unique and sorted. +// IsSortedAndUniqueOrdered returns true iff the elements in [s] are unique and sorted. func IsSortedAndUniqueOrdered[T cmp.Ordered](s []T) bool { for i := 0; i < len(s)-1; i++ { if s[i] >= s[i+1] { @@ -58,7 +58,7 @@ func IsSortedAndUniqueOrdered[T cmp.Ordered](s []T) bool { return true } -// Returns true iff the elements in [s] are unique and sorted +// IsSortedAndUniqueByHash returns true iff the elements in [s] are unique and sorted // based by their hashes. func IsSortedAndUniqueByHash[T ~[]byte](s []T) bool { if len(s) <= 1 { diff --git a/vm/rpc.go b/vm/rpc.go index ed0d91a..5ffe456 100644 --- a/vm/rpc.go +++ b/vm/rpc.go @@ -346,17 +346,17 @@ func (rpc *RPC) GenesisChunked(_ *rpctypes.Context, chunk uint) (*ctypes.ResultG }, nil } -// ToDo: no peers, because it's vm +// NetInfo ToDo: no peers, because it's vm func (rpc *RPC) NetInfo(_ *rpctypes.Context) (*ctypes.ResultNetInfo, error) { return nil, nil } -// ToDo: we doesn't have consensusState +// DumpConsensusState ToDo: we doesn't have consensusState func (rpc *RPC) DumpConsensusState(_ *rpctypes.Context) (*ctypes.ResultDumpConsensusState, error) { return nil, nil } -// ToDo: we doesn't have consensusState +// GetConsensusState ToDo: we doesn't have consensusState func (rpc *RPC) GetConsensusState(_ *rpctypes.Context) (*ctypes.ResultConsensusState, error) { return nil, nil } @@ -375,7 +375,7 @@ func (rpc *RPC) Health(*rpctypes.Context) (*ctypes.ResultHealth, error) { return &ctypes.ResultHealth{}, nil } -// bsHeight can be either latest committed or uncommitted (+1) height. +// getHeight bsHeight can be either latest committed or uncommitted (+1) height. func getHeight(bs *store.BlockStore, heightPtr *int64) (int64, error) { bsHeight := bs.Height() if heightPtr != nil { @@ -747,7 +747,7 @@ func (rpc *RPC) Status(_ *rpctypes.Context) (*ctypes.ResultStatus, error) { version.BlockProtocol, 0, ), - DefaultNodeID: p2p.ID(rpc.vm.appOpts.NodeId), + DefaultNodeID: p2p.ID(rpc.vm.appOpts.NodeID), ListenAddr: "", Network: rpc.vm.networkName, Version: version.TMCoreSemVer, diff --git a/vm/types/block/block.go b/vm/types/block/block.go index 8d9d0ae..80e95f1 100644 --- a/vm/types/block/block.go +++ b/vm/types/block/block.go @@ -4,7 +4,7 @@ import ( "github.com/cometbft/cometbft/types" ) -func BlockParentHash(block *types.Block) [32]byte { +func ParentHash(block *types.Block) [32]byte { var parentHash [32]byte if block.LastBlockID.Hash != nil { parentHash = [32]byte(block.LastBlockID.Hash) diff --git a/vm/types/config.go b/vm/types/config.go index c126ac5..1d92fe8 100644 --- a/vm/types/config.go +++ b/vm/types/config.go @@ -12,8 +12,8 @@ const ( defaultTimeoutBroadcastTxCommit time.Duration = 30 * time.Second ) -// VmConfig ... -type VmConfig struct { +// VMConfig ... +type VMConfig struct { RPCPort uint16 `json:"rpc_port"` GRPCPort uint16 `json:"grpc_port"` GRPCMaxOpenConnections int `json:"grpc_max_open_connections"` @@ -22,7 +22,7 @@ type VmConfig struct { } // SetDefaults sets the default values for the config. -func (c *VmConfig) SetDefaults() { +func (c *VMConfig) SetDefaults() { c.RPCPort = defaultRPCPort c.GRPCPort = defaultGRPCPort c.GRPCMaxOpenConnections = defaultMaxOpenConnections @@ -31,7 +31,7 @@ func (c *VmConfig) SetDefaults() { } // Validate returns an error if this is an invalid config. -func (c *VmConfig) Validate() error { +func (c *VMConfig) Validate() error { if c.GRPCMaxOpenConnections < 0 { return fmt.Errorf("grpc_max_open_connections can't be negative") } diff --git a/vm/vm.go b/vm/vm.go index 20cfebc..7a42b0d 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -79,14 +79,14 @@ type ( Application = abcitypes.Application AppCreatorOpts struct { - NetworkId uint32 - SubnetId []byte - ChainId []byte - NodeId []byte + NetworkID uint32 + SubnetID []byte + ChainID []byte + NodeID []byte PublicKey []byte - XChainId []byte - CChainId []byte - AvaxAssetId []byte + XChainID []byte + CChainID []byte + AvaxAssetID []byte GenesisBytes []byte UpgradeBytes []byte ConfigBytes []byte @@ -256,14 +256,14 @@ func (vm *LandslideVM) Initialize(_ context.Context, req *vmpb.InitializeRequest vm.stateStore = state.NewStore(dbStateStore, state.StoreOptions{DiscardABCIResponses: false}) vm.appOpts = &AppCreatorOpts{ - NetworkId: req.NetworkId, - SubnetId: req.SubnetId, - ChainId: req.ChainId, - NodeId: req.NodeId, + NetworkID: req.NetworkId, + SubnetID: req.SubnetId, + ChainID: req.ChainId, + NodeID: req.NodeId, PublicKey: req.PublicKey, - XChainId: req.XChainId, - CChainId: req.CChainId, - AvaxAssetId: req.AvaxAssetId, + XChainID: req.XChainId, + CChainID: req.CChainId, + AvaxAssetID: req.AvaxAssetId, GenesisBytes: req.GenesisBytes, UpgradeBytes: req.UpgradeBytes, ConfigBytes: req.ConfigBytes, @@ -275,7 +275,7 @@ func (vm *LandslideVM) Initialize(_ context.Context, req *vmpb.InitializeRequest } // Set the default configuration - var vmCfg vmtypes.VmConfig + var vmCfg vmtypes.VMConfig vmCfg.SetDefaults() if len(vm.appOpts.ConfigBytes) > 0 { if err := json.Unmarshal(vm.appOpts.ConfigBytes, &vmCfg); err != nil { @@ -405,10 +405,10 @@ func (vm *LandslideVM) Initialize(_ context.Context, req *vmpb.InitializeRequest if err != nil { return nil, err } - //vm.logger.Debug("initialize block", "bytes ", blockBytes) + // vm.logger.Debug("initialize block", "bytes ", blockBytes) vm.logger.Info("vm initialization completed") - parentHash := block.BlockParentHash(blk) + parentHash := block.ParentHash(blk) return &vmpb.InitializeResponse{ LastAcceptedId: blk.Hash(), @@ -437,7 +437,7 @@ func (vm *LandslideVM) SetState(_ context.Context, req *vmpb.SetStateRequest) (* } vm.logger.Debug("SetState", "LastAcceptedId", vm.state.LastBlockID.Hash, "block", blk.Hash()) - parentHash := block.BlockParentHash(blk) + parentHash := block.ParentHash(blk) res := vmpb.SetStateResponse{ LastAcceptedId: blk.Hash(), LastAcceptedParentId: parentHash[:], @@ -583,7 +583,7 @@ func (vm *LandslideVM) BuildBlock(context.Context, *vmpb.BuildBlockRequest) (*vm // ParseBlock attempt to create a block from a stream of bytes. func (vm *LandslideVM) ParseBlock(_ context.Context, req *vmpb.ParseBlockRequest) (*vmpb.ParseBlockResponse, error) { vm.logger.Info("ParseBlock") - //vm.logger.Debug("ParseBlock", "bytes", req.Bytes) + // vm.logger.Debug("ParseBlock", "bytes", req.Bytes) var ( blk *types.Block blkStatus vmpb.Status @@ -839,7 +839,7 @@ func (vm *LandslideVM) GetStateSummary(context.Context, *vmpb.GetStateSummaryReq func (vm *LandslideVM) BlockVerify(_ context.Context, req *vmpb.BlockVerifyRequest) (*vmpb.BlockVerifyResponse, error) { vm.logger.Info("BlockVerify") - //vm.logger.Debug("block verify", "bytes", req.Bytes) + // vm.logger.Debug("block verify", "bytes", req.Bytes) blk, blkStatus, err := vmstate.DecodeBlockWithStatus(req.Bytes) if err != nil {