Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IPFS code #523

Merged
merged 4 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions cmd/tendermint/commands/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"errors"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
Expand All @@ -25,7 +24,6 @@ import (
lproxy "github.com/celestiaorg/celestia-core/light/proxy"
lrpc "github.com/celestiaorg/celestia-core/light/rpc"
dbs "github.com/celestiaorg/celestia-core/light/store/db"
"github.com/celestiaorg/celestia-core/pkg/da/ipfs"
rpchttp "github.com/celestiaorg/celestia-core/rpc/client/http"
rpcserver "github.com/celestiaorg/celestia-core/rpc/jsonrpc/server"
)
Expand Down Expand Up @@ -178,18 +176,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
}),
}

var ipfsCloser io.Closer
switch {
case daSampling:
cfg := ipfs.DefaultConfig()
cfg.RootDir = dir
cfg.ServeAPI = true
// TODO(ismail): share badger instance
ipfsNode, err := ipfs.Embedded(true, cfg, logger)()
if err != nil {
return fmt.Errorf("could not start ipfs API: %w", err)
}
options = append(options, light.DataAvailabilitySampling(numSamples, ipfsNode.DAG))
case sequential:
options = append(options, light.SequentialVerification())
default:
Expand Down Expand Up @@ -250,9 +237,6 @@ func runProxy(cmd *cobra.Command, args []string) error {
// Stop upon receiving SIGTERM or CTRL-C.
tmos.TrapSignal(logger, func() {
p.Listener.Close()
if ipfsCloser != nil {
ipfsCloser.Close()
}
})

logger.Info("Starting proxy...", "laddr", listenAddr)
Expand Down
30 changes: 2 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,50 +16,24 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/protobuf v1.5.2
github.com/google/btree v1.0.0
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is necessary because github.com/gopherjs/gopherjs/js is imported in:

- github.com/celestiaorg/celestia-core/cmd/tendermint/commands
-- github.com/spf13/viper
--- gopkg.in/ini.v1
---- gopkg.in/ini.v1.test
----- github.com/smartystreets/goconvey/convey
------ github.com/jtolds/gls

github.com/gorilla/websocket v1.4.2
github.com/gtank/merlin v0.1.1
github.com/hdevalence/ed25519consensus v0.0.0-20201207055737-7fde80a9d5ff
github.com/ipfs/go-bitswap v0.3.3
github.com/ipfs/go-block-format v0.0.2
github.com/ipfs/go-blockservice v0.1.4
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.5
github.com/ipfs/go-ipfs v0.8.0
github.com/ipfs/go-ipfs-api v0.2.0
github.com/ipfs/go-ipfs-blockstore v0.1.4
github.com/ipfs/go-ipfs-config v0.11.0
github.com/ipfs/go-ipfs-routing v0.1.0
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-merkledag v0.3.2 // indirect
github.com/ipfs/go-path v0.0.9 // indirect
github.com/ipfs/go-verifcid v0.0.1
github.com/ipfs/interface-go-ipfs-core v0.4.0
github.com/libp2p/go-buffer-pool v0.0.2
github.com/libp2p/go-libp2p v0.12.0
github.com/libp2p/go-libp2p-core v0.7.0
github.com/libp2p/go-libp2p-kad-dht v0.11.1
github.com/libp2p/go-libp2p-kbucket v0.4.7
github.com/minio/highwayhash v1.0.1
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multihash v0.0.14
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.0
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0
github.com/rs/cors v1.8.0
github.com/sasha-s/go-deadlock v0.2.0
github.com/smartystreets/assertions v1.0.1 // indirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module is necessary because github.com/smartystreets/assertions is imported in:

- github.com/celestiaorg/celestia-core/cmd/tendermint/commands
-- github.com/spf13/viper
--- gopkg.in/ini.v1
---- gopkg.in/ini.v1.test
----- github.com/smartystreets/goconvey/convey

perhaps a different version of viper doesn't have these

github.com/snikch/goodman v0.0.0-20171125024755-10e37e294daa
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
github.com/stretchr/testify v1.7.0
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca // indirect
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
google.golang.org/grpc v1.39.0
)

replace (
github.com/ipfs/go-ipfs => github.com/celestiaorg/go-ipfs v0.8.0-lazypatch
// adding an extra replace statement here enforces usage of our fork of go-cerifcid
github.com/ipfs/go-verifcid => github.com/celestiaorg/go-verifcid v0.0.1-lazypatch
)
889 changes: 0 additions & 889 deletions go.sum

Large diffs are not rendered by default.

67 changes: 1 addition & 66 deletions light/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ import (
"fmt"
"time"

"github.com/celestiaorg/nmt/namespace"
format "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"

"github.com/celestiaorg/celestia-core/libs/log"
tmmath "github.com/celestiaorg/celestia-core/libs/math"
tmsync "github.com/celestiaorg/celestia-core/libs/sync"
"github.com/celestiaorg/celestia-core/light/provider"
"github.com/celestiaorg/celestia-core/light/store"
"github.com/celestiaorg/celestia-core/pkg/da/ipld"
"github.com/celestiaorg/celestia-core/types"
)

Expand Down Expand Up @@ -70,15 +65,6 @@ func SkippingVerification(trustLevel tmmath.Fraction) Option {
}
}

func DataAvailabilitySampling(numSamples uint32, dag format.DAGService) Option {
return func(c *Client) {
c.verificationMode = dataAvailabilitySampling
c.numSamples = numSamples
c.dag = dag
c.sessionDAG = merkledag.NewSession(context.TODO(), dag)
}
}

// PruningSize option sets the maximum amount of light blocks that the light
// client stores. When Prune() is run, all light blocks that are earlier than
// the h amount of light blocks will be removed from the store.
Expand Down Expand Up @@ -131,7 +117,6 @@ type Client struct {
trustingPeriod time.Duration // see TrustOptions.Period
verificationMode mode
trustLevel tmmath.Fraction
numSamples uint32
maxRetryAttempts uint16 // see MaxRetryAttempts option
maxClockDrift time.Duration

Expand All @@ -155,9 +140,6 @@ type Client struct {
quit chan struct{}

logger log.Logger

dag format.DAGService
sessionDAG format.NodeGetter
}

// NewClient returns a new light client. It returns an error if it fails to
Expand Down Expand Up @@ -246,12 +228,6 @@ func NewClientFromTrustedStore(
return nil, err
}

if c.verificationMode == dataAvailabilitySampling {
if err := ValidateNumSamples(c.numSamples); err != nil {
return nil, err
}
}

if err := c.restoreTrustedLightBlock(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -683,35 +659,6 @@ func (c *Client) verifySequential(
}
}

// 2.1) Verify that the data behind the block data is actually available.
if c.verificationMode == dataAvailabilitySampling {
start := time.Now()
// TODO: decide how to handle this case:
// https://github.com/celestiaorg/celestia-core/issues/319
numRows := len(interimBlock.DataAvailabilityHeader.RowsRoots)
numSamples := min(c.numSamples, uint32(numRows*numRows))
c.logger.Info("Starting Data Availability sampling",
"height", height,
"numSamples", numSamples,
"squareWidth", numRows)

err = ipld.ValidateAvailability(
ctx,
c.dag,
interimBlock.DataAvailabilityHeader,
numSamples,
func(data namespace.PrefixedData8) {}, // noop
)
if err != nil {
return fmt.Errorf("data availability sampling failed; ipld.ValidateAvailability: %w", err)
}
elapsed := time.Since(start)
c.logger.Info("Successfully finished DAS sampling",
"height", height,
"numSamples", numSamples,
"elapsed time", elapsed)
}

// 3) Update verifiedBlock
verifiedBlock = interimBlock

Expand All @@ -727,13 +674,6 @@ func (c *Client) verifySequential(
return c.detectDivergence(ctx, trace, now)
}

func min(a, b uint32) int {
if a < b {
return int(a)
}
return int(b)
}

// see VerifyHeader
//
// verifySkipping finds the middle light block between a trusted and new light block,
Expand Down Expand Up @@ -1039,12 +979,7 @@ func (c *Client) lightBlockFromPrimary(ctx context.Context, height int64) (*type
l *types.LightBlock
err error
)
switch c.verificationMode {
case dataAvailabilitySampling:
l, err = c.primary.DASLightBlock(ctx, height)
default:
l, err = c.primary.LightBlock(ctx, height)
}
l, err = c.primary.LightBlock(ctx, height)
c.providerMutex.Unlock()
if err != nil {
c.logger.Debug("Error on light block request from primary", "error", err, "primary", c.primary)
Expand Down
3 changes: 0 additions & 3 deletions light/provider/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ var (
// requested header.
ErrLightBlockNotFound = errors.New("light block not found")

// ErrDAHeaderNotFound is returned when a provider can't find the
// requested DataAvailabilityHeader.
ErrDAHeaderNotFound = errors.New("data availability header not found")
// ErrNoResponse is returned if the provider doesn't respond to the
// request in a given time
ErrNoResponse = errors.New("client failed to respond")
Expand Down
46 changes: 0 additions & 46 deletions light/provider/http/http.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package http

import (
"bytes"
"context"
"fmt"
"math/rand"
Expand Down Expand Up @@ -87,35 +86,6 @@ func (p *http) LightBlock(ctx context.Context, height int64) (*types.LightBlock,
return lb, nil
}

func (p *http) DASLightBlock(ctx context.Context, height int64) (*types.LightBlock, error) {
h, err := validateHeight(height)
if err != nil {
return nil, provider.ErrBadLightBlock{Reason: err}
}

lb, err := p.LightBlock(ctx, height)
if err != nil {
return nil, err
}
// additionally get DAHeader from rpc:
dah, err := p.daHeader(ctx, h)
if err != nil {
return nil, provider.ErrBadLightBlock{Reason: err}
}
// do LightBlock and DAHeader match hashes?
if !bytes.Equal(dah.Hash(), lb.DataHash) {
return nil, provider.ErrBadLightBlock{
Reason: fmt.Errorf("mismatching data hashes, dah.Hash(): %X != lb.DataHash: %X\ndah: %v",
dah.Hash(),
lb.DataHash,
dah),
}
}
lb.DataAvailabilityHeader = dah

return lb, nil
}

// ReportEvidence calls `/broadcast_evidence` endpoint.
func (p *http) ReportEvidence(ctx context.Context, ev types.Evidence) error {
_, err := p.client.BroadcastEvidence(ctx, ev)
Expand Down Expand Up @@ -181,22 +151,6 @@ func (p *http) signedHeader(ctx context.Context, height *int64) (*types.SignedHe
return nil, provider.ErrNoResponse
}

func (p *http) daHeader(ctx context.Context, height *int64) (*types.DataAvailabilityHeader, error) {
for attempt := 1; attempt <= maxRetryAttempts; attempt++ {
daHeaderRes, err := p.client.DataAvailabilityHeader(ctx, height)
if err != nil {
if regexpMissingHeight.MatchString(err.Error()) {
return nil, provider.ErrDAHeaderNotFound
}
// we wait and try again with exponential backoff
time.Sleep(backoffTimeout(uint16(attempt)))
continue
}
return &daHeaderRes.DataAvailabilityHeader, nil
}
return nil, provider.ErrNoResponse
}

func validateHeight(height int64) (*int64, error) {
if height < 0 {
return nil, fmt.Errorf("expected height >= 0, got height %d", height)
Expand Down
4 changes: 0 additions & 4 deletions light/provider/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ func (p *Mock) LightBlock(_ context.Context, height int64) (*types.LightBlock, e
return lb, nil
}

func (p *Mock) DASLightBlock(ctx context.Context, height int64) (*types.LightBlock, error) {
panic("not implemented")
}

func (p *Mock) ReportEvidence(_ context.Context, ev types.Evidence) error {
p.evidenceToReport[string(ev.Hash())] = ev
return nil
Expand Down
7 changes: 0 additions & 7 deletions light/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ type Provider interface {
// error is returned.
LightBlock(ctx context.Context, height int64) (*types.LightBlock, error)

// DASLightBlock returns the LightBlock containing the DataAvailabilityHeader.
// Other than including the DataAvailabilityHeader it behaves exactly the same
// as LightBlock.
//
// It can be used by DAS light clients.
DASLightBlock(ctx context.Context, height int64) (*types.LightBlock, error)

// ReportEvidence reports an evidence of misbehavior.
ReportEvidence(context.Context, types.Evidence) error
}
31 changes: 0 additions & 31 deletions pkg/da/ipfs/config.go

This file was deleted.

Loading