Skip to content

Commit

Permalink
Merge branch 'shwap-prototype' into prototype-v2
Browse files Browse the repository at this point in the history
# Conflicts:
#	core/listener_test.go
#	go.mod
#	go.sum
#	nodebuilder/core/module.go
#	nodebuilder/share/module.go
#	share/availability/light/availability.go
#	share/availability/light/availability_test.go
#	share/availability/light/testing.go
#	share/eds/byzantine/byzantine.go
#	share/eds/inverted_index.go
#	share/eds/metrics.go
#	share/eds/retriever_test.go
#	share/eds/store_test.go
#	share/getters/getter_test.go
#	share/getters/shrex.go
#	share/getters/shrex_test.go
#	share/ipld/corrupted_data_test.go
#	share/store/store_options.go
  • Loading branch information
walldiss committed Mar 28, 2024
2 parents 02030bf + 04ad041 commit 84241a4
Show file tree
Hide file tree
Showing 160 changed files with 9,329 additions and 5,806 deletions.
2 changes: 1 addition & 1 deletion api/docgen/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var ExampleValues = map[reflect.Type]interface{}{
&byzantine.ErrByzantine{
Index: 0,
Axis: rsmt2d.Axis(0),
Shares: []*byzantine.ShareWithProof{},
Shares: []*share.ShareWithProof{},
},
),
reflect.TypeOf((*error)(nil)).Elem(): errors.New("error"),
Expand Down
2 changes: 1 addition & 1 deletion api/gateway/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/shares"

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

func Test_dataFromShares(t *testing.T) {
Expand Down
19 changes: 0 additions & 19 deletions core/eds.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package core

import (
"context"
"errors"
"fmt"

"github.com/filecoin-project/dagstore"
"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/app"
Expand All @@ -15,9 +12,6 @@ import (
"github.com/celestiaorg/celestia-app/pkg/wrapper"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/rsmt2d"

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

// extendBlock extends the given block data, returning the resulting
Expand Down Expand Up @@ -49,16 +43,3 @@ func extendShares(s [][]byte, options ...nmt.Option) (*rsmt2d.ExtendedDataSquare
wrapper.NewConstructor(uint64(squareSize),
options...))
}

// storeEDS will only store extended block if it is not empty and doesn't already exist.
func storeEDS(ctx context.Context, hash share.DataHash, eds *rsmt2d.ExtendedDataSquare, store *eds.Store) error {
if eds == nil {
return nil
}
err := store.Put(ctx, hash, eds)
if errors.Is(err, dagstore.ErrShardExists) {
// block with given root already exists, return nil
return nil
}
return err
}
28 changes: 10 additions & 18 deletions core/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@ import (
"golang.org/x/sync/errgroup"

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

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/share/eds"
"github.com/celestiaorg/celestia-node/share/ipld"
"github.com/celestiaorg/celestia-node/libs/utils"
"github.com/celestiaorg/celestia-node/share/store"
)

const concurrencyLimit = 4

type Exchange struct {
fetcher *BlockFetcher
store *eds.Store
store *store.Store
construct header.ConstructFn

metrics *exchangeMetrics
}

func NewExchange(
fetcher *BlockFetcher,
store *eds.Store,
store *store.Store,
construct header.ConstructFn,
opts ...Option,
) (*Exchange, error) {
Expand Down Expand Up @@ -132,10 +131,7 @@ func (ce *Exchange) Get(ctx context.Context, hash libhead.Hash) (*header.Extende
}

// extend block data
adder := ipld.NewProofsAdder(int(block.Data.SquareSize))
defer adder.Purge()

eds, err := extendBlock(block.Data, block.Header.Version.App, nmt.NodeVisitor(adder.VisitFn()))
eds, err := extendBlock(block.Data, block.Header.Version.App)
if err != nil {
return nil, fmt.Errorf("extending block data for height %d: %w", &block.Height, err)
}
Expand All @@ -150,11 +146,11 @@ func (ce *Exchange) Get(ctx context.Context, hash libhead.Hash) (*header.Extende
&block.Height, hash, eh.Hash())
}

ctx = ipld.CtxWithProofsAdder(ctx, adder)
err = storeEDS(ctx, eh.DAH.Hash(), eds, ce.store)
f, err := ce.store.Put(ctx, eh.DAH.Hash(), eh.Height(), eds)
if err != nil {
return nil, fmt.Errorf("storing EDS to eds.Store for height %d: %w", &block.Height, err)
}
utils.CloseAndLog(log, "file", f)
return eh, nil
}

Expand All @@ -176,11 +172,7 @@ func (ce *Exchange) getExtendedHeaderByHeight(ctx context.Context, height *int64
}
log.Debugw("fetched signed block from core", "height", b.Header.Height)

// extend block data
adder := ipld.NewProofsAdder(int(b.Data.SquareSize))
defer adder.Purge()

eds, err := extendBlock(b.Data, b.Header.Version.App, nmt.NodeVisitor(adder.VisitFn()))
eds, err := extendBlock(b.Data, b.Header.Version.App)
if err != nil {
return nil, fmt.Errorf("extending block data for height %d: %w", b.Header.Height, err)
}
Expand All @@ -190,10 +182,10 @@ func (ce *Exchange) getExtendedHeaderByHeight(ctx context.Context, height *int64
panic(fmt.Errorf("constructing extended header for height %d: %w", b.Header.Height, err))
}

ctx = ipld.CtxWithProofsAdder(ctx, adder)
err = storeEDS(ctx, eh.DAH.Hash(), eds, ce.store)
f, err := ce.store.Put(ctx, eh.DAH.Hash(), eh.Height(), eds)
if err != nil {
return nil, fmt.Errorf("storing EDS to eds.Store for block height %d: %w", b.Header.Height, err)
}
utils.CloseAndLog(log, "file", f)
return eh, nil
}
10 changes: 4 additions & 6 deletions core/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import (
"testing"
"time"

ds "github.com/ipfs/go-datastore"
ds_sync "github.com/ipfs/go-datastore/sync"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/celestiaorg/celestia-app/test/util/testnode"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/share/eds"
"github.com/celestiaorg/celestia-node/share/store"
)

func TestCoreExchange_RequestHeaders(t *testing.T) {
Expand Down Expand Up @@ -62,11 +60,11 @@ func createCoreFetcher(t *testing.T, cfg *testnode.Config) (*BlockFetcher, testn
return NewBlockFetcher(cctx.Client), cctx
}

func createStore(t *testing.T) *eds.Store {
func createStore(t *testing.T) *store.Store {
t.Helper()

storeCfg := eds.DefaultParameters()
store, err := eds.NewStore(storeCfg, t.TempDir(), ds_sync.MutexWrap(ds.NewMapDatastore()))
storeCfg := store.DefaultParameters()
store, err := store.NewStore(storeCfg, t.TempDir())
require.NoError(t, err)
return store
}
Expand Down
18 changes: 7 additions & 11 deletions core/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
"go.opentelemetry.io/otel/attribute"

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

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/share/eds"
"github.com/celestiaorg/celestia-node/share/ipld"
"github.com/celestiaorg/celestia-node/libs/utils"
"github.com/celestiaorg/celestia-node/share/p2p/shrexsub"
"github.com/celestiaorg/celestia-node/share/store"
)

var (
Expand All @@ -38,7 +37,7 @@ type Listener struct {
fetcher *BlockFetcher

construct header.ConstructFn
store *eds.Store
store *store.Store

headerBroadcaster libhead.Broadcaster[*header.ExtendedHeader]
hashBroadcaster shrexsub.BroadcastFn
Expand All @@ -56,7 +55,7 @@ func NewListener(
fetcher *BlockFetcher,
hashBroadcaster shrexsub.BroadcastFn,
construct header.ConstructFn,
store *eds.Store,
store *store.Store,
blocktime time.Duration,
opts ...Option,
) (*Listener, error) {
Expand Down Expand Up @@ -206,11 +205,8 @@ func (cl *Listener) handleNewSignedBlock(ctx context.Context, b types.EventDataS
span.SetAttributes(
attribute.Int64("height", b.Header.Height),
)
// extend block data
adder := ipld.NewProofsAdder(int(b.Data.SquareSize))
defer adder.Purge()

eds, err := extendBlock(b.Data, b.Header.Version.App, nmt.NodeVisitor(adder.VisitFn()))
eds, err := extendBlock(b.Data, b.Header.Version.App)
if err != nil {
return fmt.Errorf("extending block data: %w", err)
}
Expand All @@ -222,11 +218,11 @@ func (cl *Listener) handleNewSignedBlock(ctx context.Context, b types.EventDataS
}

// attempt to store block data if not empty
ctx = ipld.CtxWithProofsAdder(ctx, adder)
err = storeEDS(ctx, b.Header.DataHash.Bytes(), eds, cl.store)
f, err := cl.store.Put(ctx, eh.DAH.Hash(), eh.Height(), eds)
if err != nil {
return fmt.Errorf("storing EDS: %w", err)
}
utils.CloseAndLog(log, "file", f)

syncing, err := cl.fetcher.IsSyncing(ctx)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions core/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
nodep2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p"
"github.com/celestiaorg/celestia-node/share/eds"
"github.com/celestiaorg/celestia-node/share/p2p/shrexsub"
"github.com/celestiaorg/celestia-node/share/store"
)

const networkID = "private"
Expand Down Expand Up @@ -84,11 +85,8 @@ func TestListenerWithWrongChainRPC(t *testing.T) {
eds := createEdsPubSub(ctx, t)

store := createStore(t)
err := store.Start(ctx)
require.NoError(t, err)
t.Cleanup(func() {
err = store.Stop(ctx)
require.NoError(t, err)
require.NoError(t, store.Close())
})

// create Listener and start listening
Expand Down Expand Up @@ -141,7 +139,7 @@ func createListener(
fetcher *BlockFetcher,
ps *pubsub.PubSub,
edsSub *shrexsub.PubSub,
store *eds.Store,
store *store.Store,
chainID string,
) *Listener {
p2pSub, err := p2p.NewSubscriber[*header.ExtendedHeader](ps, header.MsgID, p2p.WithSubscriberNetworkID(networkID))
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ require (
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-datastore v0.6.0
github.com/ipfs/go-ds-badger4 v0.1.5
github.com/ipfs/go-ipld-cbor v0.1.0
github.com/ipfs/go-ipld-format v0.6.0
github.com/ipfs/go-log/v2 v2.5.1
github.com/ipld/go-car v0.6.2
github.com/libp2p/go-libp2p v0.32.2
github.com/libp2p/go-libp2p-kad-dht v0.25.2
github.com/libp2p/go-libp2p-pubsub v0.10.0
Expand Down Expand Up @@ -78,6 +76,8 @@ require (
google.golang.org/protobuf v1.32.0
)

require github.com/ipfs/go-ipld-cbor v0.1.0 // indirect

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.23.3 // indirect
Expand Down Expand Up @@ -213,7 +213,6 @@ require (
github.com/ipfs/go-ipfs-util v0.0.3 // indirect
github.com/ipfs/go-ipld-legacy v0.2.1 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-merkledag v0.11.0 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
github.com/ipfs/go-peertaskqueue v0.8.1 // indirect
github.com/ipfs/go-verifcid v0.0.2 // indirect
Expand All @@ -228,7 +227,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/klauspost/reedsolomon v1.11.8 // indirect
github.com/klauspost/reedsolomon v1.12.1-0.20240110152930-bb8917fa442f
github.com/koron/go-ssdp v0.0.4 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
Expand Down Expand Up @@ -315,7 +314,7 @@ require (
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/atomic v1.11.0
go.uber.org/dig v1.17.1 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@ github.com/ipfs/go-bitswap v0.1.8/go.mod h1:TOWoxllhccevbWFUR2N7B1MTSVVge1s6XSMi
github.com/ipfs/go-bitswap v0.3.4/go.mod h1:4T7fvNv/LmOys+21tnLzGKncMeeXUYUd1nUiJ2teMvI=
github.com/ipfs/go-bitswap v0.5.1/go.mod h1:P+ckC87ri1xFLvk74NlXdP0Kj9RmWAh4+H78sC6Qopo=
github.com/ipfs/go-bitswap v0.6.0/go.mod h1:Hj3ZXdOC5wBJvENtdqsixmzzRukqd8EHLxZLZc3mzRA=
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=
github.com/ipfs/go-bitswap v0.11.0/go.mod h1:05aE8H3XOU+LXpTedeAS0OZpcO1WFsj5niYQH9a1Tmk=
github.com/ipfs/go-block-format v0.0.1/go.mod h1:DK/YYcsSUIVAFNwo/KZCdIIbpN0ROH/baNLgayt4pFc=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
Expand Down Expand Up @@ -1173,7 +1172,6 @@ github.com/ipfs/go-ipfs-pq v0.0.3/go.mod h1:btNw5hsHBpRcSSgZtiNm/SLj5gYIZ18AKtv3
github.com/ipfs/go-ipfs-redirects-file v0.1.1/go.mod h1:tAwRjCV0RjLTjH8DR/AU7VYvfQECg+lpUy2Mdzv7gyk=
github.com/ipfs/go-ipfs-routing v0.1.0/go.mod h1:hYoUkJLyAUKhF58tysKpids8RNDPO42BVMgK5dNsoqY=
github.com/ipfs/go-ipfs-routing v0.2.1/go.mod h1:xiNNiwgjmLqPS1cimvAw6EyB9rkVDbiocA4yY+wRNLM=
github.com/ipfs/go-ipfs-routing v0.3.0 h1:9W/W3N+g+y4ZDeffSgqhgo7BsBSJwPMcyssET9OWevc=
github.com/ipfs/go-ipfs-routing v0.3.0/go.mod h1:dKqtTFIql7e1zYsEuWLyuOU+E0WJWW8JjbTPLParDWo=
github.com/ipfs/go-ipfs-util v0.0.1/go.mod h1:spsl5z8KUnrve+73pOhSVZND1SIxPW5RyBCNzQxlJBc=
github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdrtMecczcsQ=
Expand Down Expand Up @@ -1259,8 +1257,6 @@ github.com/ipfs/go-verifcid v0.0.2/go.mod h1:40cD9x1y4OWnFXbLNJYRe7MpNvWlMn3LZAG
github.com/ipfs/interface-go-ipfs-core v0.9.0/go.mod h1:F3EcmDy53GFkF0H3iEJpfJC320fZ/4G60eftnItrrJ0=
github.com/ipfs/interface-go-ipfs-core v0.10.0/go.mod h1:F3EcmDy53GFkF0H3iEJpfJC320fZ/4G60eftnItrrJ0=
github.com/ipld/go-car v0.5.0/go.mod h1:ppiN5GWpjOZU9PgpAZ9HbZd9ZgSpwPMr48fGRJOWmvE=
github.com/ipld/go-car v0.6.2 h1:Hlnl3Awgnq8icK+ze3iRghk805lu8YNq3wlREDTF2qc=
github.com/ipld/go-car v0.6.2/go.mod h1:oEGXdwp6bmxJCZ+rARSkDliTeYnVzv3++eXajZ+Bmr8=
github.com/ipld/go-car/v2 v2.1.1/go.mod h1:+2Yvf0Z3wzkv7NeI69i8tuZ+ft7jyjPYIWZzeVNeFcI=
github.com/ipld/go-car/v2 v2.5.1/go.mod h1:jKjGOqoCj5zn6KjnabD6JbnCsMntqU2hLiU6baZVO3E=
github.com/ipld/go-car/v2 v2.8.0/go.mod h1:a+BnAxUqgr7wcWxW/lI6ctyEQ2v9gjBChPytwFMp2f4=
Expand Down Expand Up @@ -1367,8 +1363,8 @@ github.com/klauspost/cpuid/v2 v2.2.6 h1:ndNyv040zDGIDh8thGkXYjnFtiN02M1PVVF+JE/4
github.com/klauspost/cpuid/v2 v2.2.6/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/klauspost/crc32 v0.0.0-20161016154125-cb6bfca970f6/go.mod h1:+ZoRqAPRLkC4NPOvfYeR5KNOrY6TD+/sAC3HXPZgDYg=
github.com/klauspost/pgzip v1.0.2-0.20170402124221-0bf5dcad4ada/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
github.com/klauspost/reedsolomon v1.11.8 h1:s8RpUW5TK4hjr+djiOpbZJB4ksx+TdYbRH7vHQpwPOY=
github.com/klauspost/reedsolomon v1.11.8/go.mod h1:4bXRN+cVzMdml6ti7qLouuYi32KHJ5MGv0Qd8a47h6A=
github.com/klauspost/reedsolomon v1.12.1-0.20240110152930-bb8917fa442f h1:QEQvCKqgPSTRn9UIT65LSKY+7LCcGyiH6tIh6vCeHEw=
github.com/klauspost/reedsolomon v1.12.1-0.20240110152930-bb8917fa442f/go.mod h1:nEi5Kjb6QqtbofI6s+cbG/j1da11c96IBYBSnVGtuBs=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b/go.mod h1:5Ky9EC2xfoUKUor0Hjgi2BJhCSXJfMOFlmyYrVKGQMk=
Expand Down
15 changes: 7 additions & 8 deletions header/headertest/fraud/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import (
"github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/pkg/da"
"github.com/celestiaorg/nmt"
"github.com/celestiaorg/rsmt2d"

"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/header/headertest"
"github.com/celestiaorg/celestia-node/share/eds"
"github.com/celestiaorg/celestia-node/share/eds/edstest"
"github.com/celestiaorg/celestia-node/share/ipld"
"github.com/celestiaorg/celestia-node/share/store"
"github.com/celestiaorg/celestia-node/share/testing/edstest"
)

// FraudMaker allows to produce an invalid header at the specified height in order to produce the
Expand All @@ -45,7 +44,7 @@ func NewFraudMaker(t *testing.T, height int64, vals []types.PrivValidator, valSe
}
}

func (f *FraudMaker) MakeExtendedHeader(odsSize int, edsStore *eds.Store) header.ConstructFn {
func (f *FraudMaker) MakeExtendedHeader(odsSize int, edsStore *store.Store) header.ConstructFn {
return func(
h *types.Header,
comm *types.Commit,
Expand All @@ -58,14 +57,14 @@ func (f *FraudMaker) MakeExtendedHeader(odsSize int, edsStore *eds.Store) header

hdr := *h
if h.Height == f.height {
adder := ipld.NewProofsAdder(odsSize)
square := edstest.RandByzantineEDS(f.t, odsSize, nmt.NodeVisitor(adder.VisitFn()))
square := edstest.RandByzantineEDS(f.t, odsSize)
dah, err := da.NewDataAvailabilityHeader(square)
require.NoError(f.t, err)
hdr.DataHash = dah.Hash()

ctx := ipld.CtxWithProofsAdder(context.Background(), adder)
require.NoError(f.t, edsStore.Put(ctx, h.DataHash.Bytes(), square))
file, err := edsStore.Put(context.Background(), dah.Hash(), uint64(h.Height), square)
require.NoError(f.t, err)
require.NoError(f.t, file.Close())

*eds = *square
}
Expand Down
2 changes: 1 addition & 1 deletion libs/edssser/edssser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/celestiaorg/celestia-app/pkg/da"

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

Check failure on line 16 in libs/edssser/edssser.go

View workflow job for this annotation

GitHub Actions / go-ci / Lint

could not import github.com/celestiaorg/celestia-node/share/eds (-: no non-test Go files in share/eds) (typecheck)
"github.com/celestiaorg/celestia-node/share/eds/edstest"
"github.com/celestiaorg/celestia-node/share/testing/edstest"
)

type Config struct {
Expand Down
Loading

0 comments on commit 84241a4

Please sign in to comment.