forked from celestiaorg/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…stiaorg#1301) Closes celestiaorg#1278
- Loading branch information
Ryan
authored
Nov 25, 2022
1 parent
3d8817a
commit 95907f4
Showing
15 changed files
with
199 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package header | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/libp2p/go-libp2p-core/host" | ||
"github.com/libp2p/go-libp2p-core/peer" | ||
"github.com/libp2p/go-libp2p-core/peerstore" | ||
"go.uber.org/fx" | ||
|
||
"github.com/celestiaorg/celestia-node/header" | ||
"github.com/celestiaorg/celestia-node/header/p2p" | ||
"github.com/celestiaorg/celestia-node/header/store" | ||
"github.com/celestiaorg/celestia-node/header/sync" | ||
modp2p "github.com/celestiaorg/celestia-node/nodebuilder/p2p" | ||
) | ||
|
||
// newP2PServer constructs a new ExchangeServer using the given Network as a protocolID suffix. | ||
func newP2PServer(host host.Host, store header.Store, network modp2p.Network) *p2p.ExchangeServer { | ||
return p2p.NewExchangeServer(host, store, string(network)) | ||
} | ||
|
||
// newP2PExchange constructs a new Exchange for headers. | ||
func newP2PExchange(cfg Config) func(modp2p.Bootstrappers, modp2p.Network, host.Host) (header.Exchange, error) { | ||
return func(bpeers modp2p.Bootstrappers, network modp2p.Network, host host.Host) (header.Exchange, error) { | ||
peers, err := cfg.trustedPeers(bpeers) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ids := make([]peer.ID, len(peers)) | ||
for index, peer := range peers { | ||
ids[index] = peer.ID | ||
host.Peerstore().AddAddrs(peer.ID, peer.Addrs, peerstore.PermanentAddrTTL) | ||
} | ||
return p2p.NewExchange(host, ids, string(network)), nil | ||
} | ||
} | ||
|
||
// newSyncer constructs new Syncer for headers. | ||
func newSyncer(ex header.Exchange, store initStore, sub header.Subscriber, duration time.Duration) *sync.Syncer { | ||
return sync.NewSyncer(ex, store, sub, duration) | ||
} | ||
|
||
// initStore is a type representing initialized header store. | ||
// NOTE: It is needed to ensure that Store is always initialized before Syncer is started. | ||
type initStore header.Store | ||
|
||
// newInitStore constructs an initialized store | ||
func newInitStore( | ||
lc fx.Lifecycle, | ||
cfg Config, | ||
net modp2p.Network, | ||
s header.Store, | ||
ex header.Exchange, | ||
) (initStore, error) { | ||
trustedHash, err := cfg.trustedHash(net) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
lc.Append(fx.Hook{ | ||
OnStart: func(ctx context.Context) error { | ||
err = store.Init(ctx, s, ex, trustedHash) | ||
if err != nil { | ||
// TODO(@Wondertan): Error is ignored, as otherwise unit tests for Node construction fail. | ||
// This is due to requesting step of initialization, which fetches initial Header by trusted hash from | ||
// the network. The step can't be done during unit tests and fixing it would require either | ||
// * Having some test/dev/offline mode for Node that mocks out all the networking | ||
// * Hardcoding full extended header in params pkg, instead of hashes, so we avoid requesting step | ||
// * Or removing explicit initialization in favor of automated initialization by Syncer | ||
log.Errorf("initializing header store failed: %s", err) | ||
} | ||
return nil | ||
}, | ||
}) | ||
|
||
return s, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package share | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ipfs/go-blockservice" | ||
"github.com/ipfs/go-datastore" | ||
"github.com/libp2p/go-libp2p-core/host" | ||
"github.com/libp2p/go-libp2p-core/routing" | ||
routingdisc "github.com/libp2p/go-libp2p/p2p/discovery/routing" | ||
"go.uber.org/fx" | ||
|
||
"github.com/celestiaorg/celestia-node/share" | ||
"github.com/celestiaorg/celestia-node/share/availability/cache" | ||
disc "github.com/celestiaorg/celestia-node/share/availability/discovery" | ||
"github.com/celestiaorg/celestia-node/share/service" | ||
) | ||
|
||
func discovery(cfg Config) func(routing.ContentRouting, host.Host) *disc.Discovery { | ||
return func( | ||
r routing.ContentRouting, | ||
h host.Host, | ||
) *disc.Discovery { | ||
return disc.NewDiscovery( | ||
h, | ||
routingdisc.NewRoutingDiscovery(r), | ||
cfg.PeersLimit, | ||
cfg.DiscoveryInterval, | ||
cfg.AdvertiseInterval, | ||
) | ||
} | ||
} | ||
|
||
// cacheAvailability wraps either Full or Light availability with a cache for result sampling. | ||
func cacheAvailability[A share.Availability](lc fx.Lifecycle, ds datastore.Batching, avail A) share.Availability { | ||
ca := cache.NewShareAvailability(avail, ds) | ||
lc.Append(fx.Hook{ | ||
OnStop: ca.Close, | ||
}) | ||
return ca | ||
} | ||
|
||
func newModule(lc fx.Lifecycle, bServ blockservice.BlockService, avail share.Availability) Module { | ||
serv := service.NewShareService(bServ, avail) | ||
lc.Append(fx.Hook{ | ||
OnStart: func(ctx context.Context) error { | ||
return serv.Start(ctx) | ||
}, | ||
OnStop: func(ctx context.Context) error { | ||
return serv.Stop(ctx) | ||
}, | ||
}) | ||
return serv | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.