diff --git a/.gitignore b/.gitignore index 867ddcf64ff..51ee66de6b9 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ proto/tendermint types/pb/tendermint .vscode/launch.json */**.html +*.idea \ No newline at end of file diff --git a/block/block-manager.md b/block/block-manager.md index 62c9e042b8f..b8fceb1105e 100644 --- a/block/block-manager.md +++ b/block/block-manager.md @@ -174,7 +174,7 @@ See [tutorial] for running a multi-node network with both sequencer and non-sequ [defaultDABlockTime]: https://github.com/rollkit/rollkit/blob/main/block/manager.go#L32 [initialBackoff]: https://github.com/rollkit/rollkit/blob/main/block/manager.go#L48 [go-header]: https://github.com/celestiaorg/go-header -[block-sync]: https://github.com/rollkit/rollkit/blob/main/node/block_sync.go +[block-sync]: https://github.com/rollkit/rollkit/blob/main/block/block_sync.go [full-node]: https://github.com/rollkit/rollkit/blob/main/node/full.go [block-manager]: https://github.com/rollkit/rollkit/blob/main/block/manager.go [tutorial]: https://rollkit.dev/tutorials/full-and-sequencer-node#getting-started diff --git a/block/block_sync.go b/block/block_sync.go index 8a3e2159efe..36846bc3fea 100644 --- a/block/block_sync.go +++ b/block/block_sync.go @@ -115,12 +115,22 @@ func (bSyncService *BlockSyncService) isInitialized() bool { return bSyncService.blockStore.Height() > 0 } -// OnStart is a part of Service interface. +// Start is a part of Service interface. func (bSyncService *BlockSyncService) Start() error { // have to do the initializations here to utilize the p2p node which is created on start ps := bSyncService.p2p.PubSub() chainIDBlock := bSyncService.genesis.ChainID + "-block" - bSyncService.sub = goheaderp2p.NewSubscriber[*types.Block](ps, pubsub.DefaultMsgIdFn, chainIDBlock) + + var err error + bSyncService.sub, err = goheaderp2p.NewSubscriber[*types.Block]( + ps, + pubsub.DefaultMsgIdFn, + goheaderp2p.WithSubscriberNetworkID(chainIDBlock), + ) + if err != nil { + return err + } + if err := bSyncService.sub.Start(bSyncService.ctx); err != nil { return fmt.Errorf("error while starting subscriber: %w", err) } @@ -132,7 +142,6 @@ func (bSyncService *BlockSyncService) Start() error { return fmt.Errorf("error while starting block store: %w", err) } - var err error _, _, network, err := bSyncService.p2p.Info() if err != nil { return fmt.Errorf("error while fetching the network: %w", err) @@ -154,7 +163,12 @@ func (bSyncService *BlockSyncService) Start() error { return fmt.Errorf("error while starting exchange: %w", err) } - if bSyncService.syncer, err = newBlockSyncer(bSyncService.ex, bSyncService.blockStore, bSyncService.sub, goheadersync.WithBlockTime(bSyncService.conf.BlockTime)); err != nil { + if bSyncService.syncer, err = newBlockSyncer( + bSyncService.ex, + bSyncService.blockStore, + bSyncService.sub, + []goheadersync.Option{goheadersync.WithBlockTime(bSyncService.conf.BlockTime)}, + ); err != nil { return fmt.Errorf("error while creating syncer: %w", err) } @@ -235,9 +249,9 @@ func newBlockSyncer( ex header.Exchange[*types.Block], store header.Store[*types.Block], sub header.Subscriber[*types.Block], - opt goheadersync.Options, + opts []goheadersync.Option, ) (*goheadersync.Syncer[*types.Block], error) { - return goheadersync.NewSyncer[*types.Block](ex, store, sub, opt) + return goheadersync.NewSyncer[*types.Block](ex, store, sub, opts...) } func (bSyncService *BlockSyncService) StartSyncer() error { diff --git a/block/header_sync.go b/block/header_sync.go index 14b2676d8e4..17f72ef1d58 100644 --- a/block/header_sync.go +++ b/block/header_sync.go @@ -119,7 +119,17 @@ func (hSyncService *HeaderSynceService) isInitialized() bool { func (hSyncService *HeaderSynceService) Start() error { // have to do the initializations here to utilize the p2p node which is created on start ps := hSyncService.p2p.PubSub() - hSyncService.sub = goheaderp2p.NewSubscriber[*types.SignedHeader](ps, pubsub.DefaultMsgIdFn, hSyncService.genesis.ChainID) + + var err error + hSyncService.sub, err = goheaderp2p.NewSubscriber[*types.SignedHeader]( + ps, + pubsub.DefaultMsgIdFn, + goheaderp2p.WithSubscriberNetworkID(hSyncService.genesis.ChainID), + ) + if err != nil { + return err + } + if err := hSyncService.sub.Start(hSyncService.ctx); err != nil { return fmt.Errorf("error while starting subscriber: %w", err) } @@ -131,7 +141,6 @@ func (hSyncService *HeaderSynceService) Start() error { return fmt.Errorf("error while starting header store: %w", err) } - var err error _, _, network, err := hSyncService.p2p.Info() if err != nil { return fmt.Errorf("error while fetching the network: %w", err) @@ -151,7 +160,12 @@ func (hSyncService *HeaderSynceService) Start() error { return fmt.Errorf("error while starting exchange: %w", err) } - if hSyncService.syncer, err = newSyncer(hSyncService.ex, hSyncService.headerStore, hSyncService.sub, goheadersync.WithBlockTime(hSyncService.conf.BlockTime)); err != nil { + if hSyncService.syncer, err = newSyncer( + hSyncService.ex, + hSyncService.headerStore, + hSyncService.sub, + []goheadersync.Option{goheadersync.WithBlockTime(hSyncService.conf.BlockTime)}, + ); err != nil { return fmt.Errorf("error while creating syncer: %w", err) } @@ -234,9 +248,9 @@ func newSyncer( ex header.Exchange[*types.SignedHeader], store header.Store[*types.SignedHeader], sub header.Subscriber[*types.SignedHeader], - opt goheadersync.Options, + opts []goheadersync.Option, ) (*goheadersync.Syncer[*types.SignedHeader], error) { - return goheadersync.NewSyncer[*types.SignedHeader](ex, store, sub, opt) + return goheadersync.NewSyncer[*types.SignedHeader](ex, store, sub, opts...) } func (hSyncService *HeaderSynceService) StartSyncer() error { diff --git a/go.mod b/go.mod index ce64b4214bf..354b4200cad 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/rollkit/rollkit go 1.20 require ( - github.com/celestiaorg/go-header v0.3.3 + github.com/celestiaorg/go-header v0.4.0 github.com/celestiaorg/nmt v0.20.0 github.com/celestiaorg/rsmt2d v0.11.0 github.com/celestiaorg/utils v0.1.0 @@ -23,7 +23,7 @@ require ( github.com/libp2p/go-libp2p-pubsub v0.9.3 github.com/multiformats/go-multiaddr v0.11.0 github.com/prometheus/client_golang v1.17.0 - github.com/rollkit/celestia-openrpc v0.2.0 + github.com/rollkit/celestia-openrpc v0.3.0 github.com/rs/cors v1.10.1 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.17.0 diff --git a/go.sum b/go.sum index 81064168d68..fdb2b8f66cb 100644 --- a/go.sum +++ b/go.sum @@ -192,8 +192,8 @@ github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n github.com/casbin/casbin/v2 v2.37.0/go.mod h1:vByNa/Fchek0KZUgG5wEsl7iFsiviAYKRtgrQfcJqHg= github.com/celestiaorg/go-fraud v0.2.0 h1:aaq2JiW0gTnhEdac3l51UCqSyJ4+VjFGTTpN83V4q7I= github.com/celestiaorg/go-fraud v0.2.0/go.mod h1:lNY1i4K6kUeeE60Z2VK8WXd+qXb8KRzfBhvwPkK6aUc= -github.com/celestiaorg/go-header v0.3.3 h1:Y04hdJIJfD5hapyqK0ZQMgMTH5PQGV9YpcIf56LGc4E= -github.com/celestiaorg/go-header v0.3.3/go.mod h1:H8xhnDLDLbkpwmWPhCaZyTnIV3dlVxBHPnxNXS2Qu6c= +github.com/celestiaorg/go-header v0.4.0 h1:Ine/xpvFx8o9p6fXW+h2RSPp68rn7VUxTkW1okJxcEY= +github.com/celestiaorg/go-header v0.4.0/go.mod h1:H8xhnDLDLbkpwmWPhCaZyTnIV3dlVxBHPnxNXS2Qu6c= 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/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc= @@ -1351,8 +1351,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -github.com/rollkit/celestia-openrpc v0.2.0 h1:miSxBgiKtDBZk0dUgreAMubIPXU/Qtf9Q36+E7yZdeE= -github.com/rollkit/celestia-openrpc v0.2.0/go.mod h1:0fNIcIMbG0ZceCoh4tINNhuzhmebUMDV0cJqZboe/wg= +github.com/rollkit/celestia-openrpc v0.3.0 h1:jMLsdLNQ7T20yiNDlisBhlyurFOpN1gZ6vC068FPrQA= +github.com/rollkit/celestia-openrpc v0.3.0/go.mod h1:2ZhU01YF2hsHIROWzxfMZOYM09Kgyy4roH5JWoNJzp0= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo=