From b69cac140e3d2bf8879dbf09b28c3cf1a5e88b1e Mon Sep 17 00:00:00 2001 From: sweexordious Date: Wed, 27 Nov 2024 16:46:24 +0100 Subject: [PATCH 1/2] chore: check if a block is empty by taking its reference --- app/extend_block.go | 11 ++++++++++- app/test/integration_test.go | 13 ++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/extend_block.go b/app/extend_block.go index f14a764b26..a9c1bbe072 100644 --- a/app/extend_block.go +++ b/app/extend_block.go @@ -25,8 +25,17 @@ func ExtendBlock(data coretypes.Data, appVersion uint64) (*rsmt2d.ExtendedDataSq return da.ExtendShares(share.ToBytes(dataSquare)) } -// EmptyBlock returns true if the given block data is considered empty by the +// IsEmptyBlock returns true if the given block data is considered empty by the // application at a given version. +// +// Deprecated: Use IsEmptyBlockRef for better performance with large data structures. func IsEmptyBlock(data coretypes.Data, _ uint64) bool { return len(data.Txs) == 0 } + +// IsEmptyBlockRef returns true if the application considers the given block data +// empty at a given version. +// This method passes the block data by reference for improved performance. +func IsEmptyBlockRef(data *coretypes.Data, _ uint64) bool { + return len(data.Txs) == 0 +} diff --git a/app/test/integration_test.go b/app/test/integration_test.go index aec6d86e46..c64546b48e 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -275,7 +275,7 @@ func ExtendBlockTest(t *testing.T, block *coretypes.Block) { } } -func (s *IntegrationTestSuite) TestEmptyBlock() { +func (s *IntegrationTestSuite) TestIsEmptyBlock() { t := s.T() emptyHeights := []int64{1, 2, 3} for _, h := range emptyHeights { @@ -286,6 +286,17 @@ func (s *IntegrationTestSuite) TestEmptyBlock() { } } +func (s *IntegrationTestSuite) TestIsEmptyBlockRef() { + t := s.T() + emptyHeights := []int64{1, 2, 3} + for _, h := range emptyHeights { + blockRes, err := s.cctx.Client.Block(s.cctx.GoContext(), &h) + require.NoError(t, err) + require.True(t, app.IsEmptyBlockRef(&blockRes.Block.Data, blockRes.Block.Header.Version.App)) + ExtendBlockTest(t, blockRes.Block) + } +} + func newBlobWithSize(size int) *share.Blob { ns := share.MustNewV0Namespace(bytes.Repeat([]byte{1}, share.NamespaceVersionZeroIDSize)) data := tmrand.Bytes(size) From d4d9237f2e5b492f481e7c3c711b4d88638a3c11 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Wed, 27 Nov 2024 16:51:46 +0100 Subject: [PATCH 2/2] chore: remove static check for deprecated method --- app/test/integration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/integration_test.go b/app/test/integration_test.go index c64546b48e..7ee8e08d2d 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -281,7 +281,7 @@ func (s *IntegrationTestSuite) TestIsEmptyBlock() { for _, h := range emptyHeights { blockRes, err := s.cctx.Client.Block(s.cctx.GoContext(), &h) require.NoError(t, err) - require.True(t, app.IsEmptyBlock(blockRes.Block.Data, blockRes.Block.Header.Version.App)) + require.True(t, app.IsEmptyBlock(blockRes.Block.Data, blockRes.Block.Header.Version.App)) //nolint:staticcheck ExtendBlockTest(t, blockRes.Block) } }