Skip to content

Commit

Permalink
Merge branch 'main' into swamp-cleanussy-p2p
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd committed Sep 4, 2023
2 parents 6e4b893 + 613d229 commit 426a169
Show file tree
Hide file tree
Showing 200 changed files with 7,115 additions and 3,909 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: CI and Release
on:
merge_group:
push:
branches:
- main
Expand All @@ -24,15 +25,15 @@ on:
jobs:
# Dockerfile Linting
hadolint:
uses: celestiaorg/.github/.github/workflows/reusable_dockerfile_lint.yml@v0.2.0 # yamllint disable-line rule:line-length
uses: celestiaorg/.github/.github/workflows/reusable_dockerfile_lint.yml@v0.2.2 # yamllint disable-line rule:line-length
with:
dockerfile: Dockerfile

yamllint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: celestiaorg/.github/.github/actions/yamllint@v0.2.0
- uses: celestiaorg/.github/.github/actions/yamllint@v0.2.2

markdown-lint:
name: Markdown Lint
Expand All @@ -58,7 +59,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Version Release
uses: celestiaorg/.github/.github/actions/version-release@v0.2.0
uses: celestiaorg/.github/.github/actions/version-release@v0.2.2
with:
github-token: ${{secrets.GITHUB_TOKEN}}
version-bump: ${{inputs.version}}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/docker-build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Docker Build & Publish

# Trigger on all push events, new semantic version tags, and all PRs
on:
merge_group:
push:
branches:
- "**"
Expand All @@ -17,6 +18,6 @@ jobs:
permissions:
contents: write
packages: write
uses: celestiaorg/.github/.github/workflows/reusable_dockerfile_pipeline.yml@v0.2.0 # yamllint disable-line rule:line-length
uses: celestiaorg/.github/.github/workflows/reusable_dockerfile_pipeline.yml@v0.2.2 # yamllint disable-line rule:line-length
with:
dockerfile: Dockerfile
4 changes: 2 additions & 2 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_call:

env:
GO_VERSION: '1.20'
GO_VERSION: '1.21'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand All @@ -25,7 +25,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.6.0
with:
version: v1.52.2
version: v1.54.2

go_mod_tidy_check:
name: Go Mod Tidy Check
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
with:
mode: minimum
count: 1
labels: "kind:fix, kind:misc, kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci, kind:chore" # yamllint disable-line rule:line-length
labels: "kind:fix, kind:misc, kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci, kind:chore, kind:testing" # yamllint disable-line rule:line-length
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run:
linters:
enable:
- bodyclose
- depguard
# - depguard as of v1.54.2, the default config throws errors on our repo
- dogsled
- dupl
- errcheck
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/golang:1.20-alpine3.17 as builder
FROM docker.io/golang:1.21-alpine3.18 as builder

# hadolint ignore=DL3018
RUN apk update && apk add --no-cache \
Expand All @@ -15,7 +15,7 @@ COPY . .

RUN make build && make cel-key

FROM docker.io/alpine:3.18.0
FROM docker.io/alpine:3.18.2

# Read here why UID 10001: https://github.com/hexops/dockerfile/blob/main/README.md#do-not-use-a-uid-below-10000
ARG UID=10001
Expand Down
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SHELL=/usr/bin/env bash
PROJECTNAME=$(shell basename "$(PWD)")
LDFLAGS=-ldflags="-X 'main.buildTime=$(shell date)' -X 'main.lastCommit=$(shell git rev-parse HEAD)' -X 'main.semanticVersion=$(shell git describe --tags --dirty=-dev)'"
versioningPath := "github.com/celestiaorg/celestia-node/nodebuilder/node"
LDFLAGS=-ldflags="-X '$(versioningPath).buildTime=$(shell date)' -X '$(versioningPath).lastCommit=$(shell git rev-parse HEAD)' -X '$(versioningPath).semanticVersion=$(shell git describe --tags --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)'"
ifeq (${PREFIX},)
PREFIX := /usr/local
endif
Expand Down Expand Up @@ -81,7 +82,7 @@ install-key:
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.17
@go mod tidy -compat=1.20
@cfmt -w -m=100 ./...
@markdownlint --fix --quiet --config .markdownlint.yaml .
.PHONY: fmt
Expand Down Expand Up @@ -136,13 +137,14 @@ PB_PKGS=$(shell find . -name 'pb' -type d)
PB_CORE=$(shell go list -f {{.Dir}} -m github.com/tendermint/tendermint)
PB_GOGO=$(shell go list -f {{.Dir}} -m github.com/gogo/protobuf)
PB_CELESTIA_APP=$(shell go list -f {{.Dir}} -m github.com/celestiaorg/celestia-app)
PB_NMT=$(shell go list -f {{.Dir}} -m github.com/celestiaorg/nmt)

## pb-gen: Generate protobuf code for all /pb/*.proto files in the project.
pb-gen:
@echo '--> Generating protobuf'
@for dir in $(PB_PKGS); \
do for file in `find $$dir -type f -name "*.proto"`; \
do protoc -I=. -I=${PB_CORE}/proto/ -I=${PB_GOGO} -I=${PB_CELESTIA_APP}/proto --gogofaster_out=paths=source_relative:. $$file; \
do protoc -I=. -I=${PB_CORE}/proto/ -I=${PB_GOGO} -I=${PB_CELESTIA_APP}/proto -I=${PB_NMT} --gogofaster_out=paths=source_relative:. $$file; \
echo '-->' $$file; \
done; \
done;
Expand All @@ -159,14 +161,14 @@ openrpc-gen:
lint-imports:
@echo "--> Running imports linter"
@for file in `find . -type f -name '*.go'`; \
do goimports-reviser -list-diff -set-exit-status -company-prefixes "github.com/celestiaorg" -project-name "github.com/celestiaorg/celestia-node" -output stdout $$file \
do goimports-reviser -list-diff -set-exit-status -company-prefixes "github.com/celestiaorg" -project-name "github.com/celestiaorg/"$(PROJECTNAME)"" -output stdout $$file \
|| exit 1; \
done;
.PHONY: lint-imports

## sort-imports: Sort Go imports.
sort-imports:
@goimports-reviser -company-prefixes "github.com/celestiaorg" -project-name "github.com/celestiaorg/celestia-node" -output stdout ./...
@goimports-reviser -company-prefixes "github.com/celestiaorg" -project-name "github.com/celestiaorg/"$(PROJECTNAME)"" -output stdout .
.PHONY: sort-imports

## adr-gen: Generate ADR from template. Must set NUM and TITLE parameters.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Continue reading [here](https://blog.celestia.org/celestia-mvp-release-data-avai

| Requirement | Notes |
| ----------- |----------------|
| Go version | 1.20 or higher |
| Go version | 1.21 or higher |

## System Requirements

Expand Down
6 changes: 3 additions & 3 deletions api/docgen/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var ExampleValues = map[reflect.Type]interface{}{
reflect.TypeOf(node.Full): node.Full,
reflect.TypeOf(auth.Permission("admin")): auth.Permission("admin"),
reflect.TypeOf(byzantine.BadEncoding): byzantine.BadEncoding,
reflect.TypeOf((*fraud.Proof)(nil)).Elem(): byzantine.CreateBadEncodingProof(
reflect.TypeOf((*fraud.Proof[*header.ExtendedHeader])(nil)).Elem(): byzantine.CreateBadEncodingProof(
[]byte("bad encoding proof"),
42,
&byzantine.ErrByzantine{
Expand Down Expand Up @@ -133,13 +133,13 @@ func init() {
}
addToExampleValues(addrInfo)

namespace, err := share.NewNamespaceV0([]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10})
namespace, err := share.NewBlobNamespaceV0([]byte{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x10})
if err != nil {
panic(err)
}
addToExampleValues(namespace)

generatedBlob, err := blob.NewBlob(0, namespace, []byte("This is an example of some blob data"))
generatedBlob, err := blob.NewBlobV0(namespace, []byte("This is an example of some blob data"))
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions api/gateway/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func (h *Handler) RegisterEndpoints(rpc *Server, deprecatedEndpointsEnabled bool
rpc.RegisterHandlerFunc(submitTxEndpoint, h.handleSubmitTx, http.MethodPost)

// share endpoints
rpc.RegisterHandlerFunc(fmt.Sprintf("%s/{%s}/height/{%s}", namespacedSharesEndpoint, nIDKey, heightKey),
rpc.RegisterHandlerFunc(fmt.Sprintf("%s/{%s}/height/{%s}", namespacedSharesEndpoint, namespaceKey, heightKey),
h.handleSharesByNamespaceRequest, http.MethodGet)
rpc.RegisterHandlerFunc(fmt.Sprintf("%s/{%s}", namespacedSharesEndpoint, nIDKey),
rpc.RegisterHandlerFunc(fmt.Sprintf("%s/{%s}", namespacedSharesEndpoint, namespaceKey),
h.handleSharesByNamespaceRequest, http.MethodGet)
rpc.RegisterHandlerFunc(fmt.Sprintf("%s/{%s}/height/{%s}", namespacedDataEndpoint, nIDKey, heightKey),
rpc.RegisterHandlerFunc(fmt.Sprintf("%s/{%s}/height/{%s}", namespacedDataEndpoint, namespaceKey, heightKey),
h.handleDataByNamespaceRequest, http.MethodGet)
rpc.RegisterHandlerFunc(fmt.Sprintf("%s/{%s}", namespacedDataEndpoint, nIDKey),
rpc.RegisterHandlerFunc(fmt.Sprintf("%s/{%s}", namespacedDataEndpoint, namespaceKey),
h.handleDataByNamespaceRequest, http.MethodGet)

// DAS endpoints
Expand Down
8 changes: 8 additions & 0 deletions api/gateway/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ func (h *Handler) RegisterMiddleware(srv *Server) {
setContentType,
checkPostDisabled(h.state),
wrapRequestContext,
enableCors,
)
}

func enableCors(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
next.ServeHTTP(w, r)
})
}

func setContentType(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
Expand Down
31 changes: 29 additions & 2 deletions api/gateway/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ import (
"github.com/stretchr/testify/require"
)

const (
address = "localhost"
port = "0"
)

func TestServer(t *testing.T) {
address, port := "localhost", "0"
server := NewServer(address, port)

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -42,10 +46,33 @@ func TestServer(t *testing.T) {
require.NoError(t, err)
}

func TestCorsEnabled(t *testing.T) {
server := NewServer(address, port)
server.RegisterMiddleware(enableCors)

ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

err := server.Start(ctx)
require.NoError(t, err)

// register ping handler
ping := new(ping)
server.RegisterHandlerFunc("/ping", ping.ServeHTTP, http.MethodGet)

url := fmt.Sprintf("http://%s/ping", server.ListenAddr())

resp, err := http.Get(url)
require.NoError(t, err)
defer resp.Body.Close()

require.NoError(t, err)
require.Equal(t, resp.Header.Get("Access-Control-Allow-Origin"), "*")
}

// TestServer_contextLeakProtection tests to ensure a context
// deadline was added by the context wrapper middleware server-side.
func TestServer_contextLeakProtection(t *testing.T) {
address, port := "localhost", "0"
server := NewServer(address, port)
server.RegisterMiddleware(wrapRequestContext)

Expand Down
24 changes: 11 additions & 13 deletions api/gateway/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/gorilla/mux"

"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/nmt/namespace"

"github.com/celestiaorg/celestia-node/share"
)
Expand All @@ -20,7 +19,7 @@ const (
namespacedDataEndpoint = "/namespaced_data"
)

var nIDKey = "nid"
var namespaceKey = "nid"

// NamespacedSharesResponse represents the response to a
// SharesByNamespace request.
Expand All @@ -37,12 +36,12 @@ type NamespacedDataResponse struct {
}

func (h *Handler) handleSharesByNamespaceRequest(w http.ResponseWriter, r *http.Request) {
height, nID, err := parseGetByNamespaceArgs(r)
height, namespace, err := parseGetByNamespaceArgs(r)
if err != nil {
writeError(w, http.StatusBadRequest, namespacedSharesEndpoint, err)
return
}
shares, err := h.getShares(r.Context(), height, nID)
shares, err := h.getShares(r.Context(), height, namespace)
if err != nil {
writeError(w, http.StatusInternalServerError, namespacedSharesEndpoint, err)
return
Expand All @@ -62,12 +61,12 @@ func (h *Handler) handleSharesByNamespaceRequest(w http.ResponseWriter, r *http.
}

func (h *Handler) handleDataByNamespaceRequest(w http.ResponseWriter, r *http.Request) {
height, nID, err := parseGetByNamespaceArgs(r)
height, namespace, err := parseGetByNamespaceArgs(r)
if err != nil {
writeError(w, http.StatusBadRequest, namespacedDataEndpoint, err)
return
}
shares, err := h.getShares(r.Context(), height, nID)
shares, err := h.getShares(r.Context(), height, namespace)
if err != nil {
writeError(w, http.StatusInternalServerError, namespacedDataEndpoint, err)
return
Expand All @@ -91,13 +90,13 @@ func (h *Handler) handleDataByNamespaceRequest(w http.ResponseWriter, r *http.Re
}
}

func (h *Handler) getShares(ctx context.Context, height uint64, nID namespace.ID) ([]share.Share, error) {
func (h *Handler) getShares(ctx context.Context, height uint64, namespace share.Namespace) ([]share.Share, error) {
header, err := h.header.GetByHeight(ctx, height)
if err != nil {
return nil, err
}

shares, err := h.share.GetSharesByNamespace(ctx, header.DAH, nID)
shares, err := h.share.GetSharesByNamespace(ctx, header.DAH, namespace)
if err != nil {
return nil, err
}
Expand All @@ -124,7 +123,7 @@ func dataFromShares(input []share.Share) (data [][]byte, err error) {
return data, nil
}

func parseGetByNamespaceArgs(r *http.Request) (height uint64, nID namespace.ID, err error) {
func parseGetByNamespaceArgs(r *http.Request) (height uint64, namespace share.Namespace, err error) {
vars := mux.Vars(r)
// if a height was given, parse it, otherwise get namespaced shares/data from the latest header
if strHeight, ok := vars[heightKey]; ok {
Expand All @@ -133,11 +132,10 @@ func parseGetByNamespaceArgs(r *http.Request) (height uint64, nID namespace.ID,
return 0, nil, err
}
}
hexNID := vars[nIDKey]
nID, err = hex.DecodeString(hexNID)
hexNamespace := vars[namespaceKey]
namespace, err = hex.DecodeString(hexNamespace)
if err != nil {
return 0, nil, err
}

return height, nID, nil
return height, namespace, namespace.ValidateForData()
}
9 changes: 5 additions & 4 deletions api/gateway/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
coretypes "github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/namespace"
"github.com/celestiaorg/celestia-app/pkg/shares"

"github.com/celestiaorg/celestia-node/share/sharetest"
)

func Test_dataFromShares(t *testing.T) {
Expand All @@ -19,13 +20,13 @@ func Test_dataFromShares(t *testing.T) {
[]byte("BEEEEAHP"),
}

ns := namespace.RandomBlobNamespace()
ns := sharetest.RandV0Namespace()
sss := shares.NewSparseShareSplitter()
for _, data := range testData {
b := coretypes.Blob{
Data: data,
NamespaceID: ns.ID,
NamespaceVersion: ns.Version,
NamespaceID: ns.ID(),
NamespaceVersion: ns.Version(),
ShareVersion: appconsts.ShareVersionZero,
}
err := sss.Write(b)
Expand Down
Loading

0 comments on commit 426a169

Please sign in to comment.