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

Feat: Bootstrap from previously seen peers #2133

Closed
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (m *mockGetter) generateHeaders(t *testing.T, bServ blockservice.BlockServi
m.head = int64(startHeight + endHeight)
}

func (m *mockGetter) Head(context.Context) (*header.ExtendedHeader, error) {
func (m *mockGetter) Head(context.Context, ...libhead.Option) (*header.ExtendedHeader, error) {
return m.headers[m.head], nil
}

Expand Down Expand Up @@ -354,7 +354,7 @@ func (m benchGetterStub) GetByHeight(context.Context, uint64) (*header.ExtendedH

type getterStub struct{}

func (m getterStub) Head(context.Context) (*header.ExtendedHeader, error) {
func (m getterStub) Head(context.Context, ...libhead.Option) (*header.ExtendedHeader, error) {
return &header.ExtendedHeader{RawHeader: header.RawHeader{Height: 1}}, nil
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.20

replace github.com/ipfs/go-verifcid => github.com/celestiaorg/go-verifcid v0.0.1-lazypatch

replace github.com/celestiaorg/go-header => github.com/derrandz/go-header v0.0.0-20230428151923-2da10fd92f76
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is temporary, you can ignore


require (
cosmossdk.io/math v1.0.0-beta.3
github.com/BurntSushi/toml v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,6 @@ github.com/celestiaorg/dagstore v0.0.0-20230413141458-735ab09a15d6 h1:/yCwMCoOPc
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.7 h1:r0X9Dl7lqBkQpwG3ekQHC61n/QdwO6epuIxDkQ4YX4o=
github.com/celestiaorg/go-header v0.2.7/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 Expand Up @@ -492,6 +490,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0/go.mod h1:DZGJHZMqrU4JJqFAWUS2U
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/deepmap/oapi-codegen v1.6.0/go.mod h1:ryDa9AgbELGeB+YEXE1dR53yAjHwFvE9iAUlWl9Al3M=
github.com/deepmap/oapi-codegen v1.8.2/go.mod h1:YLgSKSDv/bZQB7N4ws6luhozi3cEdRktEqrX88CvjIw=
github.com/derrandz/go-header v0.0.0-20230428151923-2da10fd92f76 h1:R35DAv5yMA8gk3Nplb/FwrIUycTL/uP782u8njbJXiQ=
github.com/derrandz/go-header v0.0.0-20230428151923-2da10fd92f76/go.mod h1:i9OpY70+PJ1xPw1IgMfF0Pk6vBD6VWPmjY3bgubJBcU=
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I=
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE=
github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
Expand Down
14 changes: 12 additions & 2 deletions nodebuilder/header/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (

"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/peerstore"
p2p_peerstore "github.com/libp2p/go-libp2p/core/peerstore"
"github.com/libp2p/go-libp2p/p2p/net/conngater"
"go.uber.org/fx"

libfraud "github.com/celestiaorg/go-fraud"
libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/go-header/p2p"
"github.com/celestiaorg/go-header/p2p/peerstore"
"github.com/celestiaorg/go-header/store"
"github.com/celestiaorg/go-header/sync"

Expand All @@ -29,6 +30,7 @@ func newP2PExchange(
host host.Host,
conngater *conngater.BasicConnectionGater,
cfg Config,
peerstore peerstore.Peerstore,
) (libhead.Exchange[*header.ExtendedHeader], error) {
peers, err := cfg.trustedPeers(bpeers)
if err != nil {
Expand All @@ -37,12 +39,20 @@ func newP2PExchange(
ids := make([]peer.ID, len(peers))
for index, peer := range peers {
ids[index] = peer.ID
host.Peerstore().AddAddrs(peer.ID, peer.Addrs, peerstore.PermanentAddrTTL)
host.Peerstore().AddAddrs(peer.ID, peer.Addrs, p2p_peerstore.PermanentAddrTTL)
}
peerlist, err := peerstore.Load(context.Background())
if err != nil {
log.Info("Error loading peerlist from disk", "err", err)
} else {
log.Info("Loaded peerlist from disk", peerlist)
}

exchange, err := p2p.NewExchange[*header.ExtendedHeader](host, ids, conngater,
p2p.WithParams(cfg.Client),
p2p.WithNetworkID[p2p.ClientParameters](network.String()),
p2p.WithChainID(network.String()),
p2p.WithPeerPersistence[p2p.ClientParameters](peerstore),
)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions nodebuilder/header/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

libhead "github.com/celestiaorg/go-header"
"github.com/celestiaorg/go-header/p2p"
"github.com/celestiaorg/go-header/p2p/peerstore"
"github.com/celestiaorg/go-header/store"
"github.com/celestiaorg/go-header/sync"

Expand Down Expand Up @@ -89,6 +90,9 @@ func ConstructModule(tp node.Type, cfg *Config) fx.Option {
return server.Stop(ctx)
}),
)),
fx.Provide(func(ds datastore.Batching) peerstore.Peerstore {
return peerstore.NewPeerStore(ds)
}),
)

switch tp {
Expand Down
3 changes: 2 additions & 1 deletion state/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/celestiaorg/celestia-app/testutil/testfactory"
"github.com/celestiaorg/celestia-app/testutil/testnode"
blobtypes "github.com/celestiaorg/celestia-app/x/blob/types"
libhead "github.com/celestiaorg/go-header"

"github.com/celestiaorg/celestia-node/core"
"github.com/celestiaorg/celestia-node/header"
Expand Down Expand Up @@ -95,7 +96,7 @@ type localHeader struct {
client rpcclient.Client
}

func (l localHeader) Head(ctx context.Context) (*header.ExtendedHeader, error) {
func (l localHeader) Head(ctx context.Context, _ ...libhead.Option) (*header.ExtendedHeader, error) {
latest, err := l.client.Block(ctx, nil)
if err != nil {
return nil, err
Expand Down