From ae3e6bef437dd214145ec4b2c697b5fcf814e46b Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Wed, 21 Aug 2024 10:17:45 +0200 Subject: [PATCH 1/2] logs improved --- block/p2p.go | 2 +- block/pruning.go | 2 +- config/p2p.go | 2 +- p2p/block_sync.go | 2 +- p2p/client.go | 32 ++++++++++++++++---------------- p2p/client_test.go | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/block/p2p.go b/block/p2p.go index 2522a4099..6b42adfd4 100644 --- a/block/p2p.go +++ b/block/p2p.go @@ -47,7 +47,7 @@ func (m *Manager) onReceivedBlock(event pubsub.Message) { m.UpdateTargetHeight(height) types.LastReceivedP2PHeightGauge.Set(float64(height)) - m.logger.Debug("Received new block via gossip.", "block height", height, "store height", m.State.Height(), "n cachedBlocks", m.blockCache.Size()) + m.logger.Debug("Received new block from p2p.", "block height", height, "source", source.String(), "store height", m.State.Height(), "n cachedBlocks", m.blockCache.Size()) nextHeight := m.State.NextHeight() if height >= nextHeight { diff --git a/block/pruning.go b/block/pruning.go index bc222783d..5de96960d 100644 --- a/block/pruning.go +++ b/block/pruning.go @@ -17,7 +17,7 @@ func (m *Manager) PruneBlocks(retainHeight uint64) error { err := m.p2pClient.RemoveBlocks(context.TODO(), m.State.BaseHeight, retainHeight) if err != nil { - m.logger.Error("pruning block-sync store", "retain_height", retainHeight, "err", err) + m.logger.Error("pruning blocksync store", "retain_height", retainHeight, "err", err) } pruned, err := m.Store.PruneBlocks(m.State.BaseHeight, retainHeight) if err != nil { diff --git a/config/p2p.go b/config/p2p.go index a569d023c..a2449ed43 100644 --- a/config/p2p.go +++ b/config/p2p.go @@ -19,7 +19,7 @@ type P2PConfig struct { BootstrapRetryTime time.Duration `mapstructure:"p2p_bootstrap_retry_time"` // Param used to enable block sync from p2p BlockSyncEnabled bool `mapstructure:"p2p_blocksync_enabled"` - // Time interval used by a node to request missing blocks (gap between cached blocks and local height) on demand from other peers using block-sync + // Time interval used by a node to request missing blocks (gap between cached blocks and local height) on demand from other peers using blocksync BlockSyncRequestIntervalTime time.Duration `mapstructure:"p2p_blocksync_block_request_interval"` // Param used to enable the advertisement of the node to be part of the P2P network in the DHT AdvertisingEnabled bool `mapstructure:"p2p_advertising_enabled"` diff --git a/p2p/block_sync.go b/p2p/block_sync.go index e7bda4bf2..a6f551801 100644 --- a/p2p/block_sync.go +++ b/p2p/block_sync.go @@ -50,7 +50,7 @@ func SetupBlockSync(ctx context.Context, h host.Host, store datastore.Datastore, bs := blockstore.NewBlockstore(ds) // initialize bitswap network used to retrieve data chunks from other peers in the P2P network - bsnet := network.NewFromIpfsHost(h, &routinghelpers.Null{}, network.Prefix("/dymension/block-sync/")) + bsnet := network.NewFromIpfsHost(h, &routinghelpers.Null{}, network.Prefix("/dymension/blocksync/")) // Bitswap server that provides data to the network. bsserver := server.New( diff --git a/p2p/client.go b/p2p/client.go index e257f4523..e6830bd06 100644 --- a/p2p/client.go +++ b/p2p/client.go @@ -46,8 +46,8 @@ const ( // blockTopicSuffix is added after namespace to create pubsub topic for block gossiping. blockTopicSuffix = "-block" - // blockSyncProtocolSuffix is added after namespace to create block-sync protocol prefix. - blockSyncProtocolPrefix = "block-sync" + // blockSyncProtocolSuffix is added after namespace to create blocksync protocol prefix. + blockSyncProtocolPrefix = "blocksync" ) // Client is a P2P client, implemented with libp2p. @@ -78,10 +78,10 @@ type Client struct { logger types.Logger - // block-sync instance used to save and retrieve blocks from the P2P network on demand + // blocksync instance used to save and retrieve blocks from the P2P network on demand blocksync *BlockSync - // store used to store retrievable blocks using block-sync + // store used to store retrievable blocks using blocksync blockSyncStore datastore.Datastore store store.Store @@ -199,22 +199,22 @@ func (c *Client) GossipBlock(ctx context.Context, blockBytes []byte) error { return c.blockGossiper.Publish(ctx, blockBytes) } -// SaveBlock stores the block in the block-sync datastore, stores locally the returned identifier and advertises the identifier to the DHT, so other nodes can know the identifier for the block height. +// SaveBlock stores the block in the blocksync datastore, stores locally the returned identifier and advertises the identifier to the DHT, so other nodes can know the identifier for the block height. func (c *Client) SaveBlock(ctx context.Context, height uint64, blockBytes []byte) error { if !c.conf.BlockSyncEnabled { return nil } cid, err := c.blocksync.SaveBlock(ctx, blockBytes) if err != nil { - return fmt.Errorf("block-sync add block: %w", err) + return fmt.Errorf("blocksync add block: %w", err) } _, err = c.store.SaveBlockCid(height, cid, nil) if err != nil { - return fmt.Errorf("block-sync store block id: %w", err) + return fmt.Errorf("blocksync store block id: %w", err) } advErr := c.AdvertiseBlockIdToDHT(ctx, height, cid) if advErr != nil { - return fmt.Errorf("block-sync advertise block %w", advErr) + return fmt.Errorf("blocksync advertise block %w", advErr) } return nil } @@ -498,13 +498,13 @@ func (c *Client) NewTxValidator() GossipValidator { } } -// blockSyncReceived is called on reception of new block via block-sync protocol +// blockSyncReceived is called on reception of new block via blocksync protocol func (c *Client) blockSyncReceived(block *BlockData) { err := c.localPubsubServer.PublishWithEvents(context.Background(), *block, map[string][]string{EventTypeKey: {EventNewBlockSyncBlock}}) if err != nil { c.logger.Error("Publishing event.", "err", err) } - // Received block is cached and no longer needed to request using block-sync + // Received block is cached and no longer needed to request using blocksync c.blocksReceived.AddBlockReceived(block.Block.Header.Height) } @@ -523,7 +523,7 @@ func (c *Client) blockGossipReceived(ctx context.Context, block []byte) { if err != nil { c.logger.Error("Adding block to blocksync store.", "err", err, "height", gossipedBlock.Block.Header.Height) } - // Received block is cached and no longer needed to request using block-sync + // Received block is cached and no longer needed to request using blocksync c.blocksReceived.AddBlockReceived(gossipedBlock.Block.Header.Height) } } @@ -578,24 +578,24 @@ func (c *Client) retrieveBlockSyncLoop(ctx context.Context, msgHandler BlockSync if ok { continue } - c.logger.Debug("Getting block.", "height", h) + c.logger.Debug("Blocksync getting block.", "height", h) id, err := c.GetBlockIdFromDHT(ctx, h) if err != nil || id == cid.Undef { - c.logger.Error("unable to find cid", "height", h) + c.logger.Error("Blocksync unable to find cid", "height", h) continue } _, err = c.store.SaveBlockCid(h, id, nil) if err != nil { - c.logger.Error("storing block cid", "height", h, "cid", id) + c.logger.Error("Blocksync storing block cid", "height", h, "cid", id) continue } block, err := c.blocksync.LoadBlock(ctx, id) if err != nil { - c.logger.Error("Blocksync GetBlock", "err", err) + c.logger.Error("Blocksync LoadBlock", "err", err) continue } - c.logger.Debug("Blocksync block received ", "cid", id) + c.logger.Debug("Blocksync block received ", "height", h) msgHandler(&block) } c.blocksReceived.RemoveBlocksReceivedUpToHeight(state.NextHeight()) diff --git a/p2p/client_test.go b/p2p/client_test.go index e2d291a22..4446023fc 100644 --- a/p2p/client_test.go +++ b/p2p/client_test.go @@ -220,7 +220,7 @@ func TestAdvertiseWrongCid(t *testing.T) { time.Sleep(1 * time.Second) // advertise cid for height 1 - receivedError := clients[2].DHT.PutValue(ctx, "/block-sync/"+strconv.FormatUint(1, 10), []byte("test")) + receivedError := clients[2].DHT.PutValue(ctx, "/blocksync/"+strconv.FormatUint(1, 10), []byte("test")) require.Error(t, cid.ErrInvalidCid{}, receivedError) From 83c6d77fb808233ef519d9b34190f4a33b73689d Mon Sep 17 00:00:00 2001 From: Sergi Rene Date: Wed, 21 Aug 2024 10:58:00 +0200 Subject: [PATCH 2/2] rollback prot id change --- p2p/block_sync.go | 2 +- p2p/client.go | 2 +- p2p/client_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/block_sync.go b/p2p/block_sync.go index a6f551801..e7bda4bf2 100644 --- a/p2p/block_sync.go +++ b/p2p/block_sync.go @@ -50,7 +50,7 @@ func SetupBlockSync(ctx context.Context, h host.Host, store datastore.Datastore, bs := blockstore.NewBlockstore(ds) // initialize bitswap network used to retrieve data chunks from other peers in the P2P network - bsnet := network.NewFromIpfsHost(h, &routinghelpers.Null{}, network.Prefix("/dymension/blocksync/")) + bsnet := network.NewFromIpfsHost(h, &routinghelpers.Null{}, network.Prefix("/dymension/block-sync/")) // Bitswap server that provides data to the network. bsserver := server.New( diff --git a/p2p/client.go b/p2p/client.go index e6830bd06..8d18496b3 100644 --- a/p2p/client.go +++ b/p2p/client.go @@ -47,7 +47,7 @@ const ( blockTopicSuffix = "-block" // blockSyncProtocolSuffix is added after namespace to create blocksync protocol prefix. - blockSyncProtocolPrefix = "blocksync" + blockSyncProtocolPrefix = "block-sync" ) // Client is a P2P client, implemented with libp2p. diff --git a/p2p/client_test.go b/p2p/client_test.go index 4446023fc..e2d291a22 100644 --- a/p2p/client_test.go +++ b/p2p/client_test.go @@ -220,7 +220,7 @@ func TestAdvertiseWrongCid(t *testing.T) { time.Sleep(1 * time.Second) // advertise cid for height 1 - receivedError := clients[2].DHT.PutValue(ctx, "/blocksync/"+strconv.FormatUint(1, 10), []byte("test")) + receivedError := clients[2].DHT.PutValue(ctx, "/block-sync/"+strconv.FormatUint(1, 10), []byte("test")) require.Error(t, cid.ErrInvalidCid{}, receivedError)