Skip to content

Commit

Permalink
resolve upstream conflicts while reconciling main, nodebuilder/state/…
Browse files Browse the repository at this point in the history
…core.go, state/core_access.go, state/core_access_test.go, state/integration_test.go
  • Loading branch information
ramin committed May 2, 2024
2 parents 7ffb07f + 40ee3c5 commit c8a91ca
Show file tree
Hide file tree
Showing 122 changed files with 928 additions and 661 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/create_release_tracking_epic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Create Release Tracking Epic
# on slack for tracking the deployment of a release to testnets and mainnet.
on:
release:
types: [published]
types: [released]
jobs:
trigger_issue:
uses: celestiaorg/.github/.github/workflows/[email protected]
Expand Down
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ run:

linters:
enable:
- bidichk
- bodyclose
# - depguard as of v1.54.2, the default config throws errors on our repo
- dogsled
- dupl
- errcheck
- errorlint
# - funlen
# - gochecknoglobals
# - gochecknoinits
- exportloopref
- gocheckcompilerdirectives
- goconst
- gocritic
# - gocyclo
# - godox
- gofmt
- gofumpt
- goimports
# - golint - deprecated since v1.41. revive will be used instead
- revive
Expand All @@ -25,10 +30,15 @@ linters:
- ineffassign
# - interfacer
- lll
- loggercheck
- misspell
# - maligned
- nakedret
- nilerr
- nilnil
- nolintlint
- prealloc
- protogetter
# - scopelint - deprecated since v1.39. exportloopref will be used instead
- exportloopref
- staticcheck
Expand All @@ -40,6 +50,8 @@ linters:
# - whitespace
# - wsl
# - gocognit
- wastedassign
- whitespace
- nolintlint
- asciicheck

Expand Down Expand Up @@ -67,3 +79,5 @@ linters-settings:
local-prefixes: github.com/celestiaorg/celestia-node
dupl:
threshold: 200
gofumpt:
extra-rules: true
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ install-key:
## fmt: Formats only *.go (excluding *.pb.go *pb_test.go). Runs `gofmt & goimports` internally.
fmt: sort-imports
@find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s
@find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/celestiaorg
@go mod tidy -compat=1.20
@cfmt -w -m=100 ./...
@gofumpt -w -extra .
@markdownlint --fix --quiet --config .markdownlint.yaml .
.PHONY: fmt

Expand Down
1 change: 0 additions & 1 deletion api/docgen/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ func ExampleValue(t, parent reflect.Type) (interface{}, error) {
case reflect.Interface:
return struct{}{}, nil
}

return nil, fmt.Errorf("failed to retrieve example value for type: %s on parent '%s')", t, parent)
}

Expand Down
12 changes: 5 additions & 7 deletions api/docgen/openrpc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Package docgen generates an OpenRPC spec for the Celestia Node. It has been inspired by and
// adapted from Filecoin's Lotus API implementation.

//nolint:revive
package docgen

import (
Expand Down Expand Up @@ -92,7 +90,7 @@ func ParseCommentsFromNodebuilderModules(moduleNames ...string) (Comments, Comme
return nodeComments, permComments
}

func NewOpenRPCDocument(comments Comments, permissions Comments) *go_openrpc_reflect.Document {
func NewOpenRPCDocument(comments, permissions Comments) *go_openrpc_reflect.Document {
d := &go_openrpc_reflect.Document{}

d.WithMeta(&go_openrpc_reflect.MetaT{
Expand Down Expand Up @@ -163,7 +161,7 @@ func NewOpenRPCDocument(comments Comments, permissions Comments) *go_openrpc_ref
}

// remove the default implementation from the method descriptions
appReflector.FnGetMethodDescription = func(r reflect.Value, m reflect.Method, funcDecl *ast.FuncDecl) (string, error) {
appReflector.FnGetMethodDescription = func(_ reflect.Value, m reflect.Method, _ *ast.FuncDecl) (string, error) {
if v, ok := permissions[m.Name]; ok {
return "Auth level: " + v, nil
}
Expand All @@ -172,14 +170,14 @@ func NewOpenRPCDocument(comments Comments, permissions Comments) *go_openrpc_ref

appReflector.FnGetMethodName = func(
moduleName string,
r reflect.Value,
_ reflect.Value,
m reflect.Method,
funcDecl *ast.FuncDecl,
_ *ast.FuncDecl,
) (string, error) {
return moduleName + "." + m.Name, nil
}

appReflector.FnGetMethodSummary = func(r reflect.Value, m reflect.Method, funcDecl *ast.FuncDecl) (string, error) {
appReflector.FnGetMethodSummary = func(_ reflect.Value, m reflect.Method, _ *ast.FuncDecl) (string, error) {
if v, ok := comments[extractPackageNameFromAPIMethod(m)+m.Name]; ok {
return v, nil
}
Expand Down
7 changes: 4 additions & 3 deletions api/gateway/availability.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gateway

import (
"encoding/json"
"errors"
"net/http"
"strconv"

Expand Down Expand Up @@ -33,8 +34,8 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http
}

err = h.share.SharesAvailable(r.Context(), header)
switch err {
case nil:
switch {
case err == nil:
resp, err := json.Marshal(&AvailabilityResponse{Available: true})
if err != nil {
writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err)
Expand All @@ -44,7 +45,7 @@ func (h *Handler) handleHeightAvailabilityRequest(w http.ResponseWriter, r *http
if werr != nil {
log.Errorw("serving request", "endpoint", heightAvailabilityEndpoint, "err", err)
}
case share.ErrNotAvailable:
case errors.Is(err, share.ErrNotAvailable):
resp, err := json.Marshal(&AvailabilityResponse{Available: false})
if err != nil {
writeError(w, http.StatusInternalServerError, heightAvailabilityEndpoint, err)
Expand Down
3 changes: 1 addition & 2 deletions api/gateway/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestRegisterEndpoints(t *testing.T) {
}
}

func hasEndpointRegistered(router *mux.Router, path string, method string) bool {
func hasEndpointRegistered(router *mux.Router, path, method string) bool {
var registered bool
err := router.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error {
template, err := route.GetPathTemplate()
Expand All @@ -109,7 +109,6 @@ func hasEndpointRegistered(router *mux.Router, path string, method string) bool
}
return nil
})

if err != nil {
fmt.Println("Error walking through routes:", err)
return false
Expand Down
4 changes: 1 addition & 3 deletions api/gateway/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const (
headerByHeightEndpoint = "/header"
)

var (
heightKey = "height"
)
var heightKey = "height"

func (h *Handler) handleHeadRequest(w http.ResponseWriter, r *http.Request) {
head, err := h.header.LocalHead(r.Context())
Expand Down
2 changes: 1 addition & 1 deletion api/rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *Client) Close() {

// NewClient creates a new Client with one connection per namespace with the
// given token as the authorization token.
func NewClient(ctx context.Context, addr string, token string) (*Client, error) {
func NewClient(ctx context.Context, addr, token string) (*Client, error) {
authHeader := http.Header{perms.AuthKey: []string{fmt.Sprintf("Bearer %s", token)}}
return newClient(ctx, addr, authHeader)
}
Expand Down
2 changes: 1 addition & 1 deletion api/rpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *Server) verifyAuth(_ context.Context, token string) ([]auth.Permission,

// RegisterService registers a service onto the RPC server. All methods on the service will then be
// exposed over the RPC.
func (s *Server) RegisterService(namespace string, service interface{}, out interface{}) {
func (s *Server) RegisterService(namespace string, service, out interface{}) {
if s.authDisabled {
s.rpc.Register(namespace, service)
return
Expand Down
3 changes: 1 addition & 2 deletions api/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestAuthedRPC(t *testing.T) {
adminToken, err := perms.NewTokenWithPerms(signer, perms.AllPerms)
require.NoError(t, err)

var tests = []struct {
tests := []struct {
perm int
token string
}{
Expand Down Expand Up @@ -280,7 +280,6 @@ func implementsMarshaler(t *testing.T, typ reflect.Type) {
default:
return
}

}

// setupNodeWithAuthedRPC sets up a node and overrides its JWT
Expand Down
1 change: 0 additions & 1 deletion blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (p Proof) equal(input Proof) error {
if !bytes.Equal(proof.LeafHash(), input[i].LeafHash()) {
return ErrInvalidProof
}

}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion blob/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestBlob(t *testing.T) {
blob, err := convertBlobs(appBlobs...)
require.NoError(t, err)

var test = []struct {
test := []struct {
name string
expectedRes func(t *testing.T)
}{
Expand Down
3 changes: 2 additions & 1 deletion blob/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type parser struct {
verifyFn func(blob *Blob) bool
}

// NOTE: passing shares here needed to detect padding shares(as we do not need this check in addShares)
// NOTE: passing shares here needed to detect padding shares(as we do not need this check in
// addShares)
func (p *parser) set(index int, shrs []shares.Share) ([]shares.Share, error) {
if len(shrs) == 0 {
return nil, errEmptyShares
Expand Down
6 changes: 3 additions & 3 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ func (s *Service) Included(
return blob.compareCommitments(commitment)
}}
_, resProof, err := s.retrieve(ctx, height, namespace, sharesParser)
switch err {
case nil:
case ErrBlobNotFound:
switch {
case err == nil:
case errors.Is(err, ErrBlobNotFound):
return false, nil
default:
return false, err
Expand Down
6 changes: 2 additions & 4 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package blob
import (
"bytes"
"context"
"crypto/sha256"
"encoding/json"
"fmt"
"sort"
Expand Down Expand Up @@ -49,7 +48,7 @@ func TestBlobService_Get(t *testing.T) {
require.NoError(t, err)

service := createService(ctx, t, append(blobs0, blobs1...))
var test = []struct {
test := []struct {
name string
doFn func() (interface{}, error)
expectedResult func(interface{}, error)
Expand Down Expand Up @@ -203,7 +202,7 @@ func TestBlobService_Get(t *testing.T) {
for _, p := range *proof {
from := to
to = p.End() - p.Start() + from
eq := p.VerifyInclusion(sha256.New(), namespace.ToNMT(), rawShares[from:to], row)
eq := p.VerifyInclusion(share.NewSHA256Hasher(), namespace.ToNMT(), rawShares[from:to], row)
if eq == true {
return
}
Expand Down Expand Up @@ -305,7 +304,6 @@ func TestBlobService_Get(t *testing.T) {
assert.Empty(t, blobs)
require.Error(t, err)
require.ErrorIs(t, err, ErrBlobNotFound)

},
},
{
Expand Down
3 changes: 1 addition & 2 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func AuthCmd(fsets ...*flag.FlagSet) *cobra.Command {
var cmd = &cobra.Command{
cmd := &cobra.Command{
Use: "auth [permission-level (e.g. read || write || admin)]",
Short: "Signs and outputs a hex-encoded JWT token with the given permissions.",
Long: "Signs and outputs a hex-encoded JWT token with the given permissions. NOTE: only use this command when " +
Expand All @@ -37,7 +37,6 @@ func AuthCmd(fsets ...*flag.FlagSet) *cobra.Command {
ks, err := newKeystore(StorePath(cmd.Context()))
if err != nil {
return err

}

key, err := ks.Get(nodemod.SecretName)
Expand Down
4 changes: 2 additions & 2 deletions cmd/cel-shed/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var p2pCmd = &cobra.Command{
var p2pNewKeyCmd = &cobra.Command{
Use: "new-key",
Short: "Generate and print new Ed25519 private key for p2p networking",
RunE: func(cmd *cobra.Command, _ []string) error { //nolint:revive
RunE: func(_ *cobra.Command, _ []string) error {
privkey, _, err := crypto.GenerateEd25519Key(rand.Reader)
if err != nil {
return err
Expand All @@ -42,7 +42,7 @@ var p2pNewKeyCmd = &cobra.Command{
var p2pPeerIDCmd = &cobra.Command{
Use: "peer-id",
Short: "Get peer-id out of public or private Ed25519 key",
RunE: func(cmd *cobra.Command, args []string) error { //nolint:revive
RunE: func(_ *cobra.Command, args []string) error {
decKey, err := hex.DecodeString(args[0])
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions cmd/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func InitClient(cmd *cobra.Command, _ []string) error {

storePath, err := getStorePath(cmd)
if err != nil {
return fmt.Errorf("%s: %v", rootErrMsg, err)
return fmt.Errorf("%s: %w", rootErrMsg, err)
}

cfg, err := nodebuilder.LoadConfig(filepath.Join(storePath, "config.toml"))
if err != nil {
return fmt.Errorf("%s: root directory was not specified: %v", rootErrMsg, err)
return fmt.Errorf("%s: root directory was not specified: %w", rootErrMsg, err)
}

if requestURL == "" {
Expand All @@ -66,7 +66,7 @@ func InitClient(cmd *cobra.Command, _ []string) error {
} else {
token, err := getToken(storePath)
if err != nil {
return fmt.Errorf("%s: %v", rootErrMsg, err)
return fmt.Errorf("%s: %w", rootErrMsg, err)
}

authTokenFlag = token
Expand Down
4 changes: 2 additions & 2 deletions core/eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// nil is returned in place of the eds.
func extendBlock(data types.Data, appVersion uint64, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare, error) {
if app.IsEmptyBlock(data, appVersion) {
return nil, nil
return share.EmptyExtendedDataSquare(), nil
}

// Construct the data square from the block's transactions
Expand Down Expand Up @@ -62,7 +62,7 @@ func storeEDS(
store *eds.Store,
window pruner.AvailabilityWindow,
) error {
if eds == nil {
if eds.Equals(share.EmptyExtendedDataSquare()) {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions core/eds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestTrulyEmptySquare(t *testing.T) {

eds, err := extendBlock(data, appconsts.LatestVersion)
require.NoError(t, err)
assert.Nil(t, eds)
require.True(t, eds.Equals(share.EmptyExtendedDataSquare()))
}

// TestNonZeroSquareSize tests that the DAH hash of a block with no transactions
Expand All @@ -39,8 +39,8 @@ func TestEmptySquareWithZeroTxs(t *testing.T) {
}

eds, err := extendBlock(data, appconsts.LatestVersion)
require.Nil(t, eds)
require.NoError(t, err)
require.True(t, eds.Equals(share.EmptyExtendedDataSquare()))

// force extend the square using an empty block and compare with the min DAH
eds, err = app.ExtendBlock(data, appconsts.LatestVersion)
Expand Down
2 changes: 1 addition & 1 deletion core/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (f *BlockFetcher) Commit(ctx context.Context, height *int64) (*types.Commit
// ValidatorSet queries Core for the ValidatorSet from the
// block at the given height.
func (f *BlockFetcher) ValidatorSet(ctx context.Context, height *int64) (*types.ValidatorSet, error) {
var perPage = 100
perPage := 100

vals, total := make([]*types.Validator, 0), -1
for page := 1; len(vals) != total; page++ {
Expand Down
Loading

0 comments on commit c8a91ca

Please sign in to comment.