From b51c719531bc1d0a64a6798e5c6cc155a658c5d8 Mon Sep 17 00:00:00 2001 From: UlyanaAndrukhiv Date: Tue, 4 Feb 2025 14:21:01 +0200 Subject: [PATCH 1/3] Removed unused ID method from ChannelList --- network/channels/channel.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/network/channels/channel.go b/network/channels/channel.go index 07541ae6f8d..bbc3d24e868 100644 --- a/network/channels/channel.go +++ b/network/channels/channel.go @@ -2,9 +2,6 @@ package channels import ( "regexp" - "sort" - - "github.com/onflow/flow-go/model/flow" ) // Channel specifies a virtual and isolated communication medium. @@ -36,13 +33,6 @@ func (cl ChannelList) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] } -// ID returns hash of the content of ChannelList. It first sorts the ChannelList and then takes its -// hash value. -func (cl ChannelList) ID() flow.Identifier { - sort.Sort(cl) - return flow.MakeID(cl) -} - // Contains returns true if the ChannelList contains the given channel. func (cl ChannelList) Contains(channel Channel) bool { for _, c := range cl { From 4e8ab87c8a18996fb28272e858dabbb6d80db462 Mon Sep 17 00:00:00 2001 From: UlyanaAndrukhiv Date: Tue, 4 Feb 2025 16:26:25 +0200 Subject: [PATCH 2/3] Refactor BlockDigest: rename id to BlockID, remove ID() method, and update tests --- access/handler.go | 2 +- engine/access/rest/websockets/models/block_digest.go | 2 +- .../rpc/backend/backend_stream_block_digests_test.go | 2 +- model/flow/block.go | 11 +++-------- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/access/handler.go b/access/handler.go index bcf401a2884..59d37837a2b 100644 --- a/access/handler.go +++ b/access/handler.go @@ -1366,7 +1366,7 @@ func (h *Handler) SubscribeBlockDigestsFromLatest(request *access.SubscribeBlock func (h *Handler) handleBlockDigestsResponse(send sendSubscribeBlockDigestsResponseFunc) func(*flow.BlockDigest) error { return func(blockDigest *flow.BlockDigest) error { err := send(&access.SubscribeBlockDigestsResponse{ - BlockId: convert.IdentifierToMessage(blockDigest.ID()), + BlockId: convert.IdentifierToMessage(blockDigest.BlockID), BlockHeight: blockDigest.Height, BlockTimestamp: timestamppb.New(blockDigest.Timestamp), }) diff --git a/engine/access/rest/websockets/models/block_digest.go b/engine/access/rest/websockets/models/block_digest.go index a7f7dac500a..87b2755de73 100644 --- a/engine/access/rest/websockets/models/block_digest.go +++ b/engine/access/rest/websockets/models/block_digest.go @@ -7,7 +7,7 @@ import ( // Build creates a BlockDigest instance with data from the provided flow.BlockDigest. func (b *BlockDigest) Build(block *flow.BlockDigest) { - b.BlockId = block.ID().String() + b.BlockId = block.BlockID.String() b.Height = util.FromUint(block.Height) b.Timestamp = block.Timestamp } diff --git a/engine/access/rpc/backend/backend_stream_block_digests_test.go b/engine/access/rpc/backend/backend_stream_block_digests_test.go index e6df4ddb824..958c0bd355c 100644 --- a/engine/access/rpc/backend/backend_stream_block_digests_test.go +++ b/engine/access/rpc/backend/backend_stream_block_digests_test.go @@ -82,7 +82,7 @@ func (s *BackendBlockDigestSuite) requireBlockDigests(v interface{}, expectedBlo actualBlock, ok := v.(*flow.BlockDigest) require.True(s.T(), ok, "unexpected response type: %T", v) - s.Require().Equal(expectedBlock.Header.ID(), actualBlock.ID()) + s.Require().Equal(expectedBlock.Header.ID(), actualBlock.BlockID) s.Require().Equal(expectedBlock.Header.Height, actualBlock.Height) s.Require().Equal(expectedBlock.Header.Timestamp, actualBlock.Timestamp) } diff --git a/model/flow/block.go b/model/flow/block.go index 415721a8843..6fa4d9428e3 100644 --- a/model/flow/block.go +++ b/model/flow/block.go @@ -115,25 +115,20 @@ func (b *CertifiedBlock) Height() uint64 { // BlockDigest holds lightweight block information which includes only block id, block height and block timestamp type BlockDigest struct { - id Identifier + BlockID Identifier Height uint64 Timestamp time.Time } // NewBlockDigest constructs a new block digest. func NewBlockDigest( - id Identifier, + blockID Identifier, height uint64, timestamp time.Time, ) *BlockDigest { return &BlockDigest{ - id: id, + BlockID: blockID, Height: height, Timestamp: timestamp, } } - -// ID returns the id of the BlockDigest. -func (b *BlockDigest) ID() Identifier { - return b.id -} From 128d875c98f79c28f146f5b991fbbdde963667cd Mon Sep 17 00:00:00 2001 From: Uliana Andrukhiv Date: Thu, 6 Feb 2025 12:46:54 +0200 Subject: [PATCH 3/3] Updated godoc for BlockDigest Co-authored-by: Alexander Hentschel --- model/flow/block.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/model/flow/block.go b/model/flow/block.go index 6fa4d9428e3..c6510dca813 100644 --- a/model/flow/block.go +++ b/model/flow/block.go @@ -113,7 +113,7 @@ func (b *CertifiedBlock) Height() uint64 { return b.Block.Header.Height } -// BlockDigest holds lightweight block information which includes only block id, block height and block timestamp +// BlockDigest holds lightweight block information which includes only the block's id, height and timestamp type BlockDigest struct { BlockID Identifier Height uint64