Skip to content

Commit

Permalink
Merge branch 'celestiaorg:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
tty47 authored Mar 25, 2024
2 parents 5642035 + 0c5ed2d commit 76bd3d7
Show file tree
Hide file tree
Showing 61 changed files with 876 additions and 649 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/ci_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ on:
push:
branches:
- main
# Trigger on version tags
tags:
- "v*"
release:
types: [published]
pull_request:
workflow_dispatch:
inputs:
Expand All @@ -29,7 +28,7 @@ jobs:
runs-on: ubuntu-latest
env:
# upgrade go version throughout pipeline here
GO_VERSION: "1.21"
GO_VERSION: "1.22"
outputs:
go-version: ${{ steps.set-vars.outputs.go-version }}
branch: ${{ steps.trim_ref.outputs.branch }}
Expand Down Expand Up @@ -99,7 +98,7 @@ jobs:
# version_bump section, it would skip and not run, which would result
# in goreleaser not running either.
if: ${{ github.event_name == 'workflow_dispatch' }}
uses: mathieudutour/github-tag-action@v6.1
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: ${{ inputs.version }}
Expand All @@ -111,7 +110,7 @@ jobs:
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && contains(github.ref, 'refs/tags/'))
github.event_name == 'release'
permissions: "write-all"
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
uses: golangci/[email protected]
with:
args: --timeout 10m
version: v1.55
version: v1.56
skip-pkg-cache: true
skip-build-cache: true

Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
retention-days: 5

- name: upload coverage
uses: codecov/codecov-action@v4.0.2
uses: codecov/codecov-action@v4.1.0
with:
env_vars: OS
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ issues:
- path: _test\.go
linters:
- gosec
- revive
- linters:
- lll
source: "https://"
Expand Down
20 changes: 11 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM docker.io/golang:1.21-alpine3.18 as builder
FROM --platform=$BUILDPLATFORM docker.io/golang:1.22-alpine3.18 as builder

ARG TARGETPLATFORM
ARG BUILDPLATFORM
Expand Down Expand Up @@ -40,16 +40,16 @@ ENV P2P_NETWORK mocha
# hadolint ignore=DL3018
RUN uname -a &&\
apk update && apk add --no-cache \
bash \
curl \
jq \
bash \
curl \
jq \
# Creates a user with $UID and $GID=$UID
&& adduser ${USER_NAME} \
-D \
-g ${USER_NAME} \
-h ${CELESTIA_HOME} \
-s /sbin/nologin \
-u ${UID}
-D \
-g ${USER_NAME} \
-h ${CELESTIA_HOME} \
-s /sbin/nologin \
-u ${UID}

# Copy in the binary
COPY --from=builder /src/build/celestia /bin/celestia
Expand All @@ -59,6 +59,8 @@ COPY --chown=${USER_NAME}:${USER_NAME} docker/entrypoint.sh /opt/entrypoint.sh

USER ${USER_NAME}

WORKDIR ${CELESTIA_HOME}

EXPOSE 2121

ENTRYPOINT [ "/bin/bash", "/opt/entrypoint.sh" ]
Expand Down
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ SHELL=/usr/bin/env bash
PROJECTNAME=$(shell basename "$(PWD)")
DIR_FULLPATH=$(shell pwd)
versioningPath := "github.com/celestiaorg/celestia-node/nodebuilder/node"
OS := $(shell uname -s)
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)'"
TAGS=integration
SHORT=
Expand Down Expand Up @@ -63,11 +64,19 @@ deps:
@go mod download
.PHONY: deps

## install: Install all build binaries into the $PREFIX (/usr/local/ by default) directory.
## install: Install the celestia-node binary.
install:
ifeq ($(OS),Darwin)
@$(MAKE) go-install
else
@$(MAKE) install-global
endif
.PHONY: install

install-global:
@echo "--> Installing Celestia"
@install -v ./build/* -t ${PREFIX}/bin/
.PHONY: install
.PHONY: install-global

## go-install: Build and install the celestia-node binary into the GOBIN directory.
go-install:
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.21 or higher |
| Go version | 1.22 or higher |

## System Requirements

Expand Down
4 changes: 3 additions & 1 deletion api/docgen/openrpc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// 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 @@ -95,7 +97,7 @@ func NewOpenRPCDocument(comments Comments, permissions Comments) *go_openrpc_ref

d.WithMeta(&go_openrpc_reflect.MetaT{
GetServersFn: func() func(listeners []net.Listener) (*meta_schema.Servers, error) {
return func(listeners []net.Listener) (*meta_schema.Servers, error) {
return func(_ []net.Listener) (*meta_schema.Servers, error) {
return nil, nil
}
},
Expand Down
86 changes: 23 additions & 63 deletions blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/shares"
"github.com/celestiaorg/celestia-app/x/blob/types"
"github.com/celestiaorg/nmt"

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

var errEmptyShares = errors.New("empty shares")

// Commitment is a Merkle Root of the subtree built from shares of the Blob.
// It is computed by splitting the blob into shares and building the Merkle subtree to be included
// after Submit.
Expand All @@ -31,37 +32,13 @@ func (com Commitment) Equal(c Commitment) bool {
}

// Proof is a collection of nmt.Proofs that verifies the inclusion of the data.
// Proof proves the WHOLE namespaced data for the particular row.
// TODO (@vgonkivs): rework `Proof` in order to prove a particular blob.
// https://github.com/celestiaorg/celestia-node/issues/2303
type Proof []*nmt.Proof

func (p Proof) Len() int { return len(p) }

func (p Proof) MarshalJSON() ([]byte, error) {
proofs := make([]string, 0, len(p))
for _, proof := range p {
proofBytes, err := proof.MarshalJSON()
if err != nil {
return nil, err
}
proofs = append(proofs, string(proofBytes))
}
return json.Marshal(proofs)
}

func (p *Proof) UnmarshalJSON(b []byte) error {
var proofs []string
if err := json.Unmarshal(b, &proofs); err != nil {
return err
}
for _, proof := range proofs {
var nmtProof nmt.Proof
if err := nmtProof.UnmarshalJSON([]byte(proof)); err != nil {
return err
}
*p = append(*p, &nmtProof)
}
return nil
}

// equal is a temporary method that compares two proofs.
// should be removed in BlobService V1.
func (p Proof) equal(input Proof) error {
Expand Down Expand Up @@ -99,6 +76,10 @@ type Blob struct {
// the celestia-node's namespace type
// this is to avoid converting to and from app's type
namespace share.Namespace

// index represents the index of the blob's first share in the EDS.
// Only retrieved, on-chain blobs will have the index set. Default is -1.
index int
}

// NewBlobV0 constructs a new blob from the provided Namespace and data.
Expand Down Expand Up @@ -127,19 +108,30 @@ func NewBlob(shareVersion uint8, namespace share.Namespace, data []byte) (*Blob,
if err != nil {
return nil, err
}
return &Blob{Blob: blob, Commitment: com, namespace: namespace}, nil
return &Blob{Blob: blob, Commitment: com, namespace: namespace, index: -1}, nil
}

// Namespace returns blob's namespace.
func (b *Blob) Namespace() share.Namespace {
return b.namespace
}

// Index returns the blob's first share index in the EDS.
// Only retrieved, on-chain blobs will have the index set. Default is -1.
func (b *Blob) Index() int {
return b.index
}

func (b *Blob) compareCommitments(com Commitment) bool {
return bytes.Equal(b.Commitment, com)
}

type jsonBlob struct {
Namespace share.Namespace `json:"namespace"`
Data []byte `json:"data"`
ShareVersion uint32 `json:"share_version"`
Commitment Commitment `json:"commitment"`
Index int `json:"index"`
}

func (b *Blob) MarshalJSON() ([]byte, error) {
Expand All @@ -148,6 +140,7 @@ func (b *Blob) MarshalJSON() ([]byte, error) {
Data: b.Data,
ShareVersion: b.ShareVersion,
Commitment: b.Commitment,
Index: b.index,
}
return json.Marshal(blob)
}
Expand All @@ -165,39 +158,6 @@ func (b *Blob) UnmarshalJSON(data []byte) error {
b.Blob.ShareVersion = blob.ShareVersion
b.Commitment = blob.Commitment
b.namespace = blob.Namespace
b.index = blob.Index
return nil
}

// buildBlobsIfExist takes shares and tries building the Blobs from them.
// It will build blobs either until appShares will be empty or the first incomplete blob will
// appear, so in this specific case it will return all built blobs + remaining shares.
func buildBlobsIfExist(appShares []shares.Share) ([]*Blob, []shares.Share, error) {
if len(appShares) == 0 {
return nil, nil, errors.New("empty shares received")
}
blobs := make([]*Blob, 0, len(appShares))
for {
length, err := appShares[0].SequenceLen()
if err != nil {
return nil, nil, err
}

amount := shares.SparseSharesNeeded(length)
if amount > len(appShares) {
return blobs, appShares, nil
}

b, err := parseShares(appShares[:amount])
if err != nil {
return nil, nil, err
}

// only 1 blob will be created bc we passed the exact amount of shares
blobs = append(blobs, b[0])

if amount == len(appShares) {
return blobs, nil, nil
}
appShares = appShares[amount:]
}
}
15 changes: 9 additions & 6 deletions blob/blob_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package blob

import (
"reflect"
"bytes"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -14,7 +14,7 @@ import (
)

func TestBlob(t *testing.T) {
appBlobs, err := blobtest.GenerateV0Blobs([]int{1}, false)
appBlobs, err := blobtest.GenerateV0Blobs([]int{16}, false)
require.NoError(t, err)
blob, err := convertBlobs(appBlobs...)
require.NoError(t, err)
Expand Down Expand Up @@ -53,10 +53,12 @@ func TestBlob(t *testing.T) {
expectedRes: func(t *testing.T) {
sh, err := BlobsToShares(blob...)
require.NoError(t, err)
b, err := SharesToBlobs(sh)
shares, err := toAppShares(sh...)
require.NoError(t, err)
assert.Equal(t, len(b), 1)
assert.Equal(t, blob[0].Commitment, b[0].Commitment)
p := &parser{length: len(shares), shares: shares}
b, err := p.parse()
require.NoError(t, err)
assert.Equal(t, blob[0].Commitment, b.Commitment)
},
},
{
Expand All @@ -67,7 +69,8 @@ func TestBlob(t *testing.T) {

newBlob := &Blob{}
require.NoError(t, newBlob.UnmarshalJSON(data))
require.True(t, reflect.DeepEqual(blob[0], newBlob))
require.True(t, bytes.Equal(blob[0].Blob.Data, newBlob.Data))
require.True(t, bytes.Equal(blob[0].Commitment, newBlob.Commitment))
},
},
}
Expand Down
Loading

0 comments on commit 76bd3d7

Please sign in to comment.