Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
srene committed Jul 22, 2024
2 parents 0d1a783 + 0d3be11 commit 4a29f85
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion block/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestInitialState(t *testing.T) {
privKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
p2pClient, err := p2p.NewClient(config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
}, privKey, "TestChain", emptyStore, pubsubServer, datastore.NewMapDatastore(), logger)
Expand Down
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func fullNodeConfig() config.NodeConfig {
Port: 9090,
},
P2PConfig: config.P2PConfig{
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
ListenAddress: config.DefaultListenAddress,
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DefaultConfig(home, chainId string) *NodeConfig {
PrometheusListenAddr: ":2112",
},
P2PConfig: P2PConfig{
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
ListenAddress: DefaultListenAddress,
Expand Down
2 changes: 1 addition & 1 deletion config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func AddNodeFlags(cmd *cobra.Command) {
cmd.Flags().String(FlagP2PListenAddress, def.P2PConfig.ListenAddress, "P2P listen address")
cmd.Flags().String(FlagP2PBootstrapNodes, def.P2PConfig.BootstrapNodes, "P2P bootstrap nodes")
cmd.Flags().Duration(FlagP2PBootstrapRetryTime, def.P2PConfig.BootstrapRetryTime, "P2P bootstrap time")
cmd.Flags().Uint64(FlagP2PGossipCacheSize, uint64(def.P2PConfig.GossipedBlocksCacheSize), "P2P Gossiped blocks cache size")
cmd.Flags().Uint64(FlagP2PGossipCacheSize, uint64(def.P2PConfig.GossipSubCacheSize), "P2P Gossiped blocks cache size")
}

func BindDymintFlags(cmd *cobra.Command, v *viper.Viper) error {
Expand Down
6 changes: 3 additions & 3 deletions config/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type P2PConfig struct {
// List of nodes persistent P2P nodes
PersistentNodes string `mapstructure:"p2p_persistent_nodes"`
// Size of the Gossipsub router cache
GossipedBlocksCacheSize int `mapstructure:"p2p_gossiped_blocks_cache_size"`
GossipSubCacheSize int `mapstructure:"p2p_gossip_cache_size"`
// Time interval a node tries to bootstrap again, in case no nodes connected
BootstrapRetryTime time.Duration `mapstructure:"p2p_bootstrap_retry_time"`
// Param used to enable block sync from p2p
Expand All @@ -27,8 +27,8 @@ type P2PConfig struct {

// Validate P2PConfig
func (c P2PConfig) Validate() error {
if c.GossipedBlocksCacheSize <= 0 {
return fmt.Errorf("gossipsub cache size must be positive")
if c.GossipSubCacheSize < 0 {
return fmt.Errorf("gossipsub cache size cannot be negative")
}
if c.BootstrapRetryTime <= 0 {
return fmt.Errorf("bootstrap time must be positive")
Expand Down
2 changes: 1 addition & 1 deletion config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ p2p_bootstrap_nodes = "{{ .P2PConfig.BootstrapNodes }}"
p2p_persistent_nodes = "{{ .P2PConfig.PersistentNodes }}"
# max number of cached messages by gossipsub protocol
p2p_gossiped_blocks_cache_size = {{ .P2PConfig.GossipedBlocksCacheSize }}
p2p_gossip_cache_size = {{ .P2PConfig.GossipSubCacheSize }}
# time interval to check if no p2p nodes are connected to bootstrap again
p2p_bootstrap_retry_time = "{{ .P2PConfig.BootstrapRetryTime }}"
Expand Down
2 changes: 1 addition & 1 deletion node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestMempoolDirectly(t *testing.T) {
DBPath: "",
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BootstrapNodes: "",
BlockSyncRequestIntervalTime: 30 * time.Second,
Expand Down
5 changes: 2 additions & 3 deletions p2p/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,9 @@ func (c *Client) tryConnect(ctx context.Context, peer peer.AddrInfo) {
}

func (c *Client) setupGossiping(ctx context.Context) error {
pubsub.GossipSubHistoryGossip = c.conf.GossipedBlocksCacheSize
pubsub.GossipSubHistoryLength = c.conf.GossipedBlocksCacheSize
pubsub.GossipSubHistoryGossip = c.conf.GossipSubCacheSize
pubsub.GossipSubHistoryLength = c.conf.GossipSubCacheSize

// We add WithSeenMessagesTTL (with 1 year time) option to avoid ever requesting already seen blocks
ps, err := pubsub.NewGossipSub(ctx, c.Host)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions p2p/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestClientStartup(t *testing.T) {
store := store.New(store.NewDefaultInMemoryKVStore())
client, err := p2p.NewClient(config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
}, privKey, "TestChain", store, pubsubServer, datastore.NewMapDatastore(), log.TestingLogger())
Expand Down Expand Up @@ -272,8 +272,8 @@ func TestSeedStringParsing(t *testing.T) {
logger := &testutil.MockLogger{}
store := store.New(store.NewDefaultInMemoryKVStore())
client, err := p2p.NewClient(config.P2PConfig{
GossipedBlocksCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
}, privKey, "TestNetwork", store, pubsubServer, datastore.NewMapDatastore(), logger)
require.NoError(err)
require.NotNil(client)
Expand Down
6 changes: 4 additions & 2 deletions p2p/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
"github.com/dymensionxyz/dymint/types"
)

// buffer size used by gossipSub router to consume received packets (blocks or txs). packets are dropped in case buffer overflows. in case of blocks, it can buffer up to 5 minutes (assuming 200ms block rate)
const pubsubBufferSize = 3000

// GossipMessage represents message gossiped via P2P network (e.g. transaction, Block etc).
type GossipMessage struct {
Data []byte
Expand Down Expand Up @@ -50,8 +53,7 @@ func NewGossiper(host host.Host, ps *pubsub.PubSub, topicStr string, msgHandler
if err != nil {
return nil, err
}

subscription, err := topic.Subscribe()
subscription, err := topic.Subscribe(pubsub.WithBufferSize(max(pubsub.GossipSubHistoryGossip, pubsubBufferSize)))
if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion rpc/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,6 @@ func (c *Client) Status(ctx context.Context) (*ctypes.ResultStatus, error) {
if validator == nil {
return nil, fmt.Errorf("find proposer %s in the valSet", string(latest.Header.ProposerAddress))
}

state, err := c.node.Store.LoadState()
if err != nil {
return nil, fmt.Errorf("load the last saved state: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions rpc/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestGenesisChunked(t *testing.T) {
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
BootstrapNodes: "",
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
Expand Down Expand Up @@ -707,7 +707,7 @@ func TestValidatorSetHandling(t *testing.T) {
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
BootstrapNodes: "",
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
Expand Down Expand Up @@ -865,7 +865,7 @@ func getRPCInternal(t *testing.T, sequencer bool) (*tmmocks.MockApplication, *cl
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
BootstrapNodes: "",
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
Expand Down Expand Up @@ -977,7 +977,7 @@ func TestMempool2Nodes(t *testing.T) {
P2PConfig: config.P2PConfig{
ListenAddress: "/ip4/127.0.0.1/tcp/9001",
BootstrapNodes: "",
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
Expand Down Expand Up @@ -1009,7 +1009,7 @@ func TestMempool2Nodes(t *testing.T) {
ListenAddress: "/ip4/127.0.0.1/tcp/9002",
BootstrapNodes: "/ip4/127.0.0.1/tcp/9001/p2p/" + id1.String(),
BootstrapRetryTime: 30 * time.Second,
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
MempoolConfig: *tmcfg.DefaultMempoolConfig(),
Expand Down
2 changes: 1 addition & 1 deletion rpc/json/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func getRPC(t *testing.T) (*tmmocks.MockApplication, *client.Client) {
},
P2PConfig: config.P2PConfig{
ListenAddress: config.DefaultListenAddress,
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
},
Expand Down
2 changes: 1 addition & 1 deletion testutil/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func GetManagerWithProposerKey(conf config.BlockManagerConfig, proposerKey crypt
// Init p2p client and validator
p2pKey, _, _ := crypto.GenerateEd25519Key(rand.Reader)
p2pClient, err := p2p.NewClient(config.P2PConfig{
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
}, p2pKey, "TestChain", managerStore, pubsubServer, datastore.NewMapDatastore(), logger)
Expand Down
2 changes: 1 addition & 1 deletion testutil/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func StartTestNetwork(ctx context.Context, t *testing.T, n int, conf map[int]Hos
for i := 0; i < n; i++ {
client, err := p2p.NewClient(config.P2PConfig{
BootstrapNodes: seeds[i],
GossipedBlocksCacheSize: 50,
GossipSubCacheSize: 50,
BootstrapRetryTime: 30 * time.Second,
BlockSyncRequestIntervalTime: 30 * time.Second,
ListenAddress: config.DefaultListenAddress,
Expand Down

0 comments on commit 4a29f85

Please sign in to comment.