Skip to content

Commit

Permalink
Merge branch 'main-celestia' into shrex_err_not_found
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Apr 14, 2023
2 parents c2be8be + 71b5078 commit 9335ff1
Show file tree
Hide file tree
Showing 54 changed files with 308 additions and 2,298 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,8 @@ lint-imports:
sort-imports:
@goimports-reviser -company-prefixes "github.com/celestiaorg" -project-name "github.com/celestiaorg/celestia-node" -output stdout ./...
.PHONY: sort-imports

adr-gen:
@echo "--> Generating ADRs"
@curl -sSL https://raw.githubusercontent.com/celestiaorg/.github/main/adr-template.md > docs/architecture/adr-$(NUM)-$(TITLE).md
.PHONY: adr-gen
2 changes: 1 addition & 1 deletion api/docgen/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/celestiaorg/go-fraud"
"github.com/celestiaorg/rsmt2d"

"github.com/celestiaorg/celestia-node/das"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/libs/fraud"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/eds/byzantine"
Expand Down
28 changes: 28 additions & 0 deletions cmd/celestia/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,39 @@ import (
"bytes"
"context"
"os"
"reflect"
"testing"

"github.com/stretchr/testify/require"

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

func TestCompletionHelpString(t *testing.T) {
type TestFields struct {
NoInputOneOutput func(context.Context) (*header.ExtendedHeader, error)
TwoInputsOneOutputArray func(
context.Context,
*header.ExtendedHeader,
uint64,
) ([]*header.ExtendedHeader, error)
OneInputOneOutput func(context.Context, uint64) (*header.ExtendedHeader, error)
NoInputsNoOutputs func(ctx context.Context) error
NoInputsChanOutput func(ctx context.Context) (<-chan *header.ExtendedHeader, error)
}
testOutputs := []string{
"() -> (*header.ExtendedHeader)",
"(*header.ExtendedHeader, uint64) -> ([]*header.ExtendedHeader)",
"(uint64) -> (*header.ExtendedHeader)",
"() -> ()",
"() -> (<-chan *header.ExtendedHeader)",
}
methods := reflect.VisibleFields(reflect.TypeOf(TestFields{}))
for i, method := range methods {
require.Equal(t, testOutputs[i], parseSignatureForHelpstring(method))
}
}

func TestLight(t *testing.T) {
// Run the tests in a temporary directory
tmpDir := t.TempDir()
Expand Down
22 changes: 21 additions & 1 deletion cmd/celestia/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var rpcCmd = &cobra.Command{
methods := reflect.VisibleFields(reflect.TypeOf(module).Elem())
var methodNames []string
for _, m := range methods {
methodNames = append(methodNames, m.Name)
methodNames = append(methodNames, m.Name+"\t"+parseSignatureForHelpstring(m))
}
return methodNames, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -297,3 +297,23 @@ func parseAddressFromString(addrStr string) (state.Address, error) {

return addr, nil
}

func parseSignatureForHelpstring(methodSig reflect.StructField) string {
simplifiedSignature := "("
in, out := methodSig.Type.NumIn(), methodSig.Type.NumOut()
for i := 1; i < in; i++ {
simplifiedSignature += methodSig.Type.In(i).String()
if i != in-1 {
simplifiedSignature += ", "
}
}
simplifiedSignature += ") -> ("
for i := 0; i < out-1; i++ {
simplifiedSignature += methodSig.Type.Out(i).String()
if i != out-2 {
simplifiedSignature += ", "
}
}
simplifiedSignature += ")"
return simplifiedSignature
}
2 changes: 1 addition & 1 deletion cmd/flags_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func ParseMiscFlags(ctx context.Context, cmd *cobra.Command) (context.Context, e
tp,
otelpyroscope.WithAppName("celestia.da-node"),
otelpyroscope.WithPyroscopeURL(cmd.Flag(pyroscopeEndpoint).Value.String()),
otelpyroscope.WithRootSpanOnly(false),
otelpyroscope.WithRootSpanOnly(true),
otelpyroscope.WithAddSpanName(true),
otelpyroscope.WithProfileURL(true),
otelpyroscope.WithProfileBaselineURL(true),
Expand Down
2 changes: 1 addition & 1 deletion das/daser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log/v2"

"github.com/celestiaorg/go-fraud"
libhead "github.com/celestiaorg/go-header"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/libs/fraud"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/eds/byzantine"
"github.com/celestiaorg/celestia-node/share/p2p/shrexsub"
Expand Down
21 changes: 11 additions & 10 deletions das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/go-fraud"
"github.com/celestiaorg/go-fraud/fraudserv"
"github.com/celestiaorg/go-fraud/fraudtest"
libhead "github.com/celestiaorg/go-header"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/header/headertest"
"github.com/celestiaorg/celestia-node/libs/fraud"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/availability/full"
"github.com/celestiaorg/celestia-node/share/availability/light"
Expand Down Expand Up @@ -160,7 +162,7 @@ func TestDASer_stopsAfter_BEFP(t *testing.T) {
getter := func(ctx context.Context, height uint64) (libhead.Header, error) {
return mockGet.GetByHeight(ctx, height)
}
f := fraud.NewProofService(ps, net.Hosts()[0], getter, ds, false, "private")
f := fraudserv.NewProofService(ps, net.Hosts()[0], getter, ds, false, "private")
require.NoError(t, f.Start(ctx))
mockGet.headers[1], _ = headertest.CreateFraudExtHeader(t, mockGet.headers[1], bServ)
newCtx := context.Background()
Expand Down Expand Up @@ -205,8 +207,8 @@ func TestDASerSampleTimeout(t *testing.T) {
})

ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
sub := new(headertest.DummySubscriber)
f := new(fraud.DummyService)
sub := new(headertest.Subscriber)
f := new(fraudtest.DummyService)

// create and start DASer
daser, err := NewDASer(avail, sub, getter, ds, f, newBroadcastMock(1), WithSampleTimeout(1))
Expand All @@ -231,9 +233,9 @@ func createDASerSubcomponents(
bServ blockservice.BlockService,
numGetter,
numSub int,
) (*mockGetter, *headertest.DummySubscriber, *fraud.DummyService) {
) (*mockGetter, *headertest.Subscriber, *fraudtest.DummyService) {
mockGet, sub := createMockGetterAndSub(t, bServ, numGetter, numSub)
fraud := new(fraud.DummyService)
fraud := new(fraudtest.DummyService)
return mockGet, sub, fraud
}

Expand All @@ -242,7 +244,7 @@ func createMockGetterAndSub(
bServ blockservice.BlockService,
numGetter,
numSub int,
) (*mockGetter, *headertest.DummySubscriber) {
) (*mockGetter, *headertest.Subscriber) {
mockGet := &mockGetter{
headers: make(map[int64]*header.ExtendedHeader),
doneCh: make(chan struct{}),
Expand All @@ -251,16 +253,15 @@ func createMockGetterAndSub(

mockGet.generateHeaders(t, bServ, 0, numGetter)

sub := new(headertest.DummySubscriber)
sub := new(headertest.Subscriber)
mockGet.fillSubWithHeaders(t, sub, bServ, numGetter, numGetter+numSub)

return mockGet, sub
}

// fillSubWithHeaders generates `num` headers from the future for p2pSub to pipe through to DASer.
func (m *mockGetter) fillSubWithHeaders(
t *testing.T,
sub *headertest.DummySubscriber,
sub *headertest.Subscriber,
bServ blockservice.BlockService,
startHeight,
endHeight int,
Expand Down
6 changes: 5 additions & 1 deletion docs/adr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ If recorded decisions turned out to be lacking, convene a discussion, record the

Note the context/background should be written in the present tense.

To start a new ADR, you can use this template: [adr-template.md](./adr-template.md)
To start a new ADR, you can generate a new file with the following command:

```bash
make adr-gen NUM=001 TITLE=my-adr-title
```

## Table of Contents
72 changes: 0 additions & 72 deletions docs/adr/adr-template.md

This file was deleted.

5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ require (
github.com/alecthomas/jsonschema v0.0.0-20200530073317-71f438968921
github.com/benbjohnson/clock v1.3.0
github.com/celestiaorg/celestia-app v0.12.2
github.com/celestiaorg/go-header v0.2.3
github.com/celestiaorg/go-fraud v0.1.0
github.com/celestiaorg/go-header v0.2.5
github.com/celestiaorg/go-libp2p-messenger v0.2.0
github.com/celestiaorg/nmt v0.15.0
github.com/celestiaorg/rsmt2d v0.8.0
Expand Down Expand Up @@ -327,7 +328,7 @@ require (

replace (
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.8.0-sdk-v0.46.7
github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230404123415-177451f83136
github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230413141458-735ab09a15d6
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.15.0-tm-v0.34.23
)
10 changes: 6 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ github.com/celestiaorg/celestia-core v1.15.0-tm-v0.34.23 h1:BHvn41IHOtvHeX1VZqO/
github.com/celestiaorg/celestia-core v1.15.0-tm-v0.34.23/go.mod h1:nL+vkAMKy/A8wWemWqMwBy4pOGWYYbboAVTEe3N5gIU=
github.com/celestiaorg/cosmos-sdk v1.8.0-sdk-v0.46.7 h1:EADZy33ufskVIy6Rj6jbi3SOVCeYYo26zUi7iYx+QR0=
github.com/celestiaorg/cosmos-sdk v1.8.0-sdk-v0.46.7/go.mod h1:vg3Eza9adJJ5Mdx6boz5MpZsZcTZyrfTVYZHyi2zLm4=
github.com/celestiaorg/dagstore v0.0.0-20230404123415-177451f83136 h1:LBvY3NDA18fcS72pBAEd2pENoUpz1iV4cCXBN2Zrj/I=
github.com/celestiaorg/dagstore v0.0.0-20230404123415-177451f83136/go.mod h1:ta/DlqIH10bvhwqJIw51Nq3QU4XVMp6pz3f0Deve9fM=
github.com/celestiaorg/go-header v0.2.3 h1:41r60OtAeexWC3J3eTELgWfzcdKR2taFlfcJ/2IHZD4=
github.com/celestiaorg/go-header v0.2.3/go.mod h1:6XKf0yhoEQqfKQTZnyTZjTjF5jH5Wq9uO9AvDMkdYbs=
github.com/celestiaorg/dagstore v0.0.0-20230413141458-735ab09a15d6 h1:/yCwMCoOPcYCiG18u8/1pv5eXF04xczoQO3sR0bKsgM=
github.com/celestiaorg/dagstore v0.0.0-20230413141458-735ab09a15d6/go.mod h1:ta/DlqIH10bvhwqJIw51Nq3QU4XVMp6pz3f0Deve9fM=
github.com/celestiaorg/go-fraud v0.1.0 h1:v6mZvlmf2J5ELZfPnrtmmOvKbaYIUs/erDWPO8NbZyY=
github.com/celestiaorg/go-fraud v0.1.0/go.mod h1:yoNM35cKMAkt5Mi/Qx3Wi9bnPilLi8n6RpHZVglTUDs=
github.com/celestiaorg/go-header v0.2.5 h1:TV1EybWjRRJfYc8Wf5UFVytGxEQJdPdNbVEfenUVXzo=
github.com/celestiaorg/go-header v0.2.5/go.mod h1:i9OpY70+PJ1xPw1IgMfF0Pk6vBD6VWPmjY3bgubJBcU=
github.com/celestiaorg/go-libp2p-messenger v0.2.0 h1:/0MuPDcFamQMbw9xTZ73yImqgTO3jHV7wKHvWD/Irao=
github.com/celestiaorg/go-libp2p-messenger v0.2.0/go.mod h1:s9PIhMi7ApOauIsfBcQwbr7m+HBzmVfDIS+QLdgzDSo=
github.com/celestiaorg/go-verifcid v0.0.1-lazypatch h1:9TSe3w1cmJmbWlweCwCTIZkan7jV8M+KwglXpdD+UG8=
Expand Down
48 changes: 11 additions & 37 deletions header/headertest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/ipfs/go-blockservice"
logging "github.com/ipfs/go-log/v2"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/libs/bytes"
Expand All @@ -23,7 +22,7 @@ import (

"github.com/celestiaorg/celestia-app/pkg/da"
libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/go-header/test"
"github.com/celestiaorg/go-header/headertest"
"github.com/celestiaorg/rsmt2d"

"github.com/celestiaorg/celestia-node/header"
Expand All @@ -44,6 +43,10 @@ type TestSuite struct {
head *header.ExtendedHeader
}

func NewStore(t *testing.T) libhead.Store[*header.ExtendedHeader] {
return headertest.NewStore[*header.ExtendedHeader](t, NewTestSuite(t, 3), 10)
}

// NewTestSuite setups a new test suite with a given number of validators.
func NewTestSuite(t *testing.T, num int) *TestSuite {
valSet, vals := RandValidatorSet(num, 10)
Expand Down Expand Up @@ -125,18 +128,14 @@ func (s *TestSuite) Head() *header.ExtendedHeader {
func (s *TestSuite) GenExtendedHeaders(num int) []*header.ExtendedHeader {
headers := make([]*header.ExtendedHeader, num)
for i := range headers {
headers[i] = s.GenExtendedHeader()
headers[i] = s.NextHeader()
}
return headers
}

func (s *TestSuite) GetRandomHeader() *header.ExtendedHeader {
return s.GenExtendedHeader()
}

var _ test.Generator[*header.ExtendedHeader] = &TestSuite{}
var _ headertest.Generator[*header.ExtendedHeader] = &TestSuite{}

func (s *TestSuite) GenExtendedHeader() *header.ExtendedHeader {
func (s *TestSuite) NextHeader() *header.ExtendedHeader {
if s.head == nil {
s.head = s.genesis()
return s.head
Expand Down Expand Up @@ -334,33 +333,8 @@ func CreateFraudExtHeader(
return eh, extended
}

type DummySubscriber struct {
Headers []*header.ExtendedHeader
}

func (mhs *DummySubscriber) AddValidator(func(context.Context, *header.ExtendedHeader) pubsub.ValidationResult) error {
return nil
}

func (mhs *DummySubscriber) Subscribe() (libhead.Subscription[*header.ExtendedHeader], error) {
return mhs, nil
}

func (mhs *DummySubscriber) NextHeader(context.Context) (*header.ExtendedHeader, error) {
defer func() {
if len(mhs.Headers) > 1 {
// pop the already-returned header
cp := mhs.Headers
mhs.Headers = cp[1:]
} else {
mhs.Headers = make([]*header.ExtendedHeader, 0)
}
}()
if len(mhs.Headers) == 0 {
return nil, context.Canceled
}
return mhs.Headers[0], nil
type Subscriber struct {
headertest.Subscriber[*header.ExtendedHeader]
}

func (mhs *DummySubscriber) Stop(context.Context) error { return nil }
func (mhs *DummySubscriber) Cancel() {}
var _ libhead.Subscriber[*header.ExtendedHeader] = &Subscriber{}
Loading

0 comments on commit 9335ff1

Please sign in to comment.