From df0dee1515de3ccd85f198b879b615101574ad8f Mon Sep 17 00:00:00 2001 From: zwanga Date: Tue, 14 Jan 2025 22:42:09 +0200 Subject: [PATCH 1/6] refactor: change mebibyte to a constant Signed-off-by: zwanga --- app/benchmarks/benchmark_msg_send_test.go | 5 +---- app/default_overrides.go | 10 +++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/benchmarks/benchmark_msg_send_test.go b/app/benchmarks/benchmark_msg_send_test.go index 7e79db9a67..9d4b36c1c4 100644 --- a/app/benchmarks/benchmark_msg_send_test.go +++ b/app/benchmarks/benchmark_msg_send_test.go @@ -307,9 +307,6 @@ func generateMsgSendTransactions(b *testing.B, count int) (*app.App, [][]byte) { return testApp, rawTxs } -// mebibyte the number of bytes in a mebibyte -const mebibyte = 1048576 - // calculateBlockSizeInMb returns the block size in mb given a set // of raw transactions. func calculateBlockSizeInMb(txs [][]byte) float64 { @@ -317,7 +314,7 @@ func calculateBlockSizeInMb(txs [][]byte) float64 { for _, tx := range txs { numberOfBytes += len(tx) } - mb := float64(numberOfBytes) / mebibyte + mb := float64(numberOfBytes) / app.Mebibyte return mb } diff --git a/app/default_overrides.go b/app/default_overrides.go index f0e7d13cba..fcc3711e15 100644 --- a/app/default_overrides.go +++ b/app/default_overrides.go @@ -36,6 +36,8 @@ import ( coretypes "github.com/tendermint/tendermint/types" ) +const Mebibyte = 1048576 + // bankModule defines a custom wrapper around the x/bank module's AppModuleBasic // implementation to provide custom default genesis state. type bankModule struct { @@ -274,9 +276,8 @@ func DefaultConsensusConfig() *tmcfg.Config { cfg.TxIndex.Indexer = "null" cfg.Storage.DiscardABCIResponses = true - const mebibyte = 1048576 - cfg.P2P.SendRate = 10 * mebibyte - cfg.P2P.RecvRate = 10 * mebibyte + cfg.P2P.SendRate = 10 * Mebibyte + cfg.P2P.RecvRate = 10 * Mebibyte return cfg } @@ -295,7 +296,6 @@ func DefaultAppConfig() *serverconfig.Config { cfg.StateSync.SnapshotKeepRecent = 2 cfg.MinGasPrices = fmt.Sprintf("%v%s", appconsts.DefaultMinGasPrice, BondDenom) - const mebibyte = 1048576 - cfg.GRPC.MaxRecvMsgSize = 20 * mebibyte + cfg.GRPC.MaxRecvMsgSize = 20 * Mebibyte return cfg } From 7cf298a721467d9677ac9b3a8e70eb8c31e405f9 Mon Sep 17 00:00:00 2001 From: zwanga Date: Wed, 15 Jan 2025 00:12:39 +0200 Subject: [PATCH 2/6] refactor: refactor mebibyte in the test files --- app/default_overrides_test.go | 9 ++++----- app/test/big_blob_test.go | 4 ++-- app/test/integration_test.go | 2 +- app/test/unit_test.go | 1 - test/util/testnode/comet_node_test.go | 2 +- test/util/testnode/config.go | 2 +- x/blob/ante/blob_share_decorator_test.go | 9 ++++----- x/blob/ante/max_total_blob_size_ante_test.go | 7 ++++--- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/app/default_overrides_test.go b/app/default_overrides_test.go index 69d3c876a6..0afdabbc48 100644 --- a/app/default_overrides_test.go +++ b/app/default_overrides_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/cosmos/cosmos-sdk/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -65,8 +66,7 @@ func TestDefaultAppConfig(t *testing.T) { assert.Equal(t, uint32(2), cfg.StateSync.SnapshotKeepRecent) assert.Equal(t, "0.002utia", cfg.MinGasPrices) - mebibyte := 1048576 - assert.Equal(t, 20*mebibyte, cfg.GRPC.MaxRecvMsgSize) + assert.Equal(t, 20*app.Mebibyte, cfg.GRPC.MaxRecvMsgSize) } func TestDefaultConsensusConfig(t *testing.T) { @@ -93,9 +93,8 @@ func TestDefaultConsensusConfig(t *testing.T) { assert.Equal(t, want, *got.Mempool) }) t.Run("p2p overrides", func(t *testing.T) { - const mebibyte = 1048576 - assert.Equal(t, int64(10*mebibyte), got.P2P.SendRate) - assert.Equal(t, int64(10*mebibyte), got.P2P.RecvRate) + assert.Equal(t, int64(10*app.Mebibyte), got.P2P.SendRate) + assert.Equal(t, int64(10*app.Mebibyte), got.P2P.RecvRate) }) } diff --git a/app/test/big_blob_test.go b/app/test/big_blob_test.go index bbce473016..2909980de6 100644 --- a/app/test/big_blob_test.go +++ b/app/test/big_blob_test.go @@ -39,10 +39,10 @@ func (s *BigBlobSuite) SetupSuite() { s.accounts = testfactory.GenerateAccounts(1) tmConfig := testnode.DefaultTendermintConfig() - tmConfig.Mempool.MaxTxBytes = 10 * mebibyte + tmConfig.Mempool.MaxTxBytes = 10 * app.Mebibyte cParams := testnode.DefaultConsensusParams() - cParams.Block.MaxBytes = 10 * mebibyte + cParams.Block.MaxBytes = 10 * app.Mebibyte cfg := testnode.DefaultConfig(). WithFundedAccounts(s.accounts...). diff --git a/app/test/integration_test.go b/app/test/integration_test.go index 7ee8e08d2d..6acabc783f 100644 --- a/app/test/integration_test.go +++ b/app/test/integration_test.go @@ -128,7 +128,7 @@ func (s *IntegrationTestSuite) TestMaxBlockSize() { for i, tx := range txs { // The default CometBFT mempool MaxTxBytes is 1 MiB so the generators in // this test must create transactions that are smaller than that. - require.LessOrEqual(t, len(tx), 1*mebibyte) + require.LessOrEqual(t, len(tx), 1*app.Mebibyte) res, err := s.cctx.Context.BroadcastTxSync(tx) require.NoError(t, err) diff --git a/app/test/unit_test.go b/app/test/unit_test.go index 83fa292438..63c9fa5483 100644 --- a/app/test/unit_test.go +++ b/app/test/unit_test.go @@ -2,5 +2,4 @@ package app_test const ( kibibyte = 1024 - mebibyte = 1024 * kibibyte ) diff --git a/test/util/testnode/comet_node_test.go b/test/util/testnode/comet_node_test.go index 63222ca66e..741dcec881 100644 --- a/test/util/testnode/comet_node_test.go +++ b/test/util/testnode/comet_node_test.go @@ -46,7 +46,7 @@ func customTendermintConfig() *tmconfig.Config { // Override the MaxBodyBytes to allow the testnode to accept very large // transactions and respond to queries with large responses (200 MiB was // chosen only as an arbitrary large number). - tmCfg.RPC.MaxBodyBytes = 200 * mebibyte + tmCfg.RPC.MaxBodyBytes = 200 * Mebibyte tmCfg.RPC.TimeoutBroadcastTxCommit = time.Minute return tmCfg diff --git a/test/util/testnode/config.go b/test/util/testnode/config.go index 32b94a3a9c..2cc3b903a6 100644 --- a/test/util/testnode/config.go +++ b/test/util/testnode/config.go @@ -22,7 +22,7 @@ import ( const ( kibibyte = 1024 // bytes - mebibyte = 1_048_576 // bytes + Mebibyte = 1_048_576 // bytes DefaultValidatorAccountName = "validator" DefaultInitialBalance = genesis.DefaultInitialBalance ) diff --git a/x/blob/ante/blob_share_decorator_test.go b/x/blob/ante/blob_share_decorator_test.go index e65dca6c3f..27de086ab1 100644 --- a/x/blob/ante/blob_share_decorator_test.go +++ b/x/blob/ante/blob_share_decorator_test.go @@ -24,7 +24,6 @@ import ( ) const ( - mebibyte = 1_048_576 // 1 MiB squareSize = 64 ) @@ -42,7 +41,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "want no error if appVersion v1 and 8 MiB blob", blobsPerPFB: 1, - blobSize: 8 * mebibyte, + blobSize: 8 * testnode.Mebibyte, appVersion: v1.Version, }, { @@ -54,13 +53,13 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 MiB", blobsPerPFB: 1, - blobSize: 1 * mebibyte, + blobSize: 1 * testnode.Mebibyte, appVersion: v2.Version, }, { name: "PFB with 1 blob that is 2 MiB", blobsPerPFB: 1, - blobSize: 2 * mebibyte, + blobSize: 2 * testnode.Mebibyte, appVersion: v2.Version, // This test case should return an error because a square size of 64 // has exactly 2 MiB of total capacity so the total blob capacity @@ -76,7 +75,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 2 blobs that are 1 MiB each", blobsPerPFB: 2, - blobSize: 1 * mebibyte, + blobSize: 1 * testnode.Mebibyte, appVersion: v2.Version, // This test case should return an error for the same reason a // single blob that is 2 MiB returns an error. diff --git a/x/blob/ante/max_total_blob_size_ante_test.go b/x/blob/ante/max_total_blob_size_ante_test.go index 5156bc89a7..18089e7faa 100644 --- a/x/blob/ante/max_total_blob_size_ante_test.go +++ b/x/blob/ante/max_total_blob_size_ante_test.go @@ -7,6 +7,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app/encoding" v1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" ante "github.com/celestiaorg/celestia-app/v3/x/blob/ante" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" @@ -43,14 +44,14 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 MiB", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{mebibyte}, + BlobSizes: []uint32{testnode.Mebibyte}, }, appVersion: v1.Version, }, { name: "PFB with 1 blob that is 2 MiB", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{2 * mebibyte}, + BlobSizes: []uint32{2 * testnode.Mebibyte}, }, appVersion: v1.Version, // This test case should return an error because a square size of 64 @@ -68,7 +69,7 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { { name: "PFB with 2 blobs that are 1 MiB each", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{mebibyte, mebibyte}, + BlobSizes: []uint32{testnode.Mebibyte, testnode.Mebibyte}, }, appVersion: v1.Version, // This test case should return an error for the same reason a From 79a4e479acddd8cfdfe8f30baae468fdaeef18d3 Mon Sep 17 00:00:00 2001 From: zwanga Date: Wed, 15 Jan 2025 21:28:10 +0200 Subject: [PATCH 3/6] fix: remove circular dependencies --- app/benchmarks/benchmark_msg_send_test.go | 2 +- app/default_overrides_test.go | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/benchmarks/benchmark_msg_send_test.go b/app/benchmarks/benchmark_msg_send_test.go index 9d4b36c1c4..072792c4cf 100644 --- a/app/benchmarks/benchmark_msg_send_test.go +++ b/app/benchmarks/benchmark_msg_send_test.go @@ -314,7 +314,7 @@ func calculateBlockSizeInMb(txs [][]byte) float64 { for _, tx := range txs { numberOfBytes += len(tx) } - mb := float64(numberOfBytes) / app.Mebibyte + mb := float64(numberOfBytes) / Mebibyte return mb } diff --git a/app/default_overrides_test.go b/app/default_overrides_test.go index 0afdabbc48..a41feb06c6 100644 --- a/app/default_overrides_test.go +++ b/app/default_overrides_test.go @@ -4,7 +4,6 @@ import ( "testing" "time" - "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/cosmos/cosmos-sdk/types" distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" @@ -66,7 +65,7 @@ func TestDefaultAppConfig(t *testing.T) { assert.Equal(t, uint32(2), cfg.StateSync.SnapshotKeepRecent) assert.Equal(t, "0.002utia", cfg.MinGasPrices) - assert.Equal(t, 20*app.Mebibyte, cfg.GRPC.MaxRecvMsgSize) + assert.Equal(t, 20*Mebibyte, cfg.GRPC.MaxRecvMsgSize) } func TestDefaultConsensusConfig(t *testing.T) { @@ -93,8 +92,8 @@ func TestDefaultConsensusConfig(t *testing.T) { assert.Equal(t, want, *got.Mempool) }) t.Run("p2p overrides", func(t *testing.T) { - assert.Equal(t, int64(10*app.Mebibyte), got.P2P.SendRate) - assert.Equal(t, int64(10*app.Mebibyte), got.P2P.RecvRate) + assert.Equal(t, int64(10*Mebibyte), got.P2P.SendRate) + assert.Equal(t, int64(10*Mebibyte), got.P2P.RecvRate) }) } From f0c9ecf8cf4de384600332b49e4ed08a038ac88d Mon Sep 17 00:00:00 2001 From: zwanga Date: Wed, 15 Jan 2025 21:59:52 +0200 Subject: [PATCH 4/6] fix: fix further linter changes --- pkg/da/data_availability_header.go | 4 ++-- test/txsim/blob.go | 4 ++-- x/blob/ante/max_total_blob_size_ante.go | 6 +++--- x/mint/types/minter_test.go | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/da/data_availability_header.go b/pkg/da/data_availability_header.go index 1bd2dc5d26..b5445da67b 100644 --- a/pkg/da/data_availability_header.go +++ b/pkg/da/data_availability_header.go @@ -203,8 +203,8 @@ func EmptySquareShares() []share.Share { // SquareSize is a copy of the function defined in the square package to avoid // a circular dependency. TODO deduplicate -func SquareSize(len int) int { - return RoundUpPowerOfTwo(int(math.Ceil(math.Sqrt(float64(len))))) +func SquareSize(length int) int { + return RoundUpPowerOfTwo(int(math.Ceil(math.Sqrt(float64(length))))) } // RoundUpPowerOfTwo returns the next power of two greater than or equal to input. diff --git a/test/txsim/blob.go b/test/txsim/blob.go index 3fcef2fa33..c5433d3d25 100644 --- a/test/txsim/blob.go +++ b/test/txsim/blob.go @@ -123,8 +123,8 @@ type Range struct { Max int } -func NewRange(min, max int) Range { - return Range{Min: min, Max: max} +func NewRange(minimum, maximum int) Range { + return Range{Min: minimum, Max: maximum} } // Rand returns a random number between min (inclusive) and max (exclusive). diff --git a/x/blob/ante/max_total_blob_size_ante.go b/x/blob/ante/max_total_blob_size_ante.go index 98cd67549f..43bc6e47ad 100644 --- a/x/blob/ante/max_total_blob_size_ante.go +++ b/x/blob/ante/max_total_blob_size_ante.go @@ -31,11 +31,11 @@ func (d MaxTotalBlobSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula return next(ctx, tx, simulate) } - max := d.maxTotalBlobSize(ctx) + maximum := d.maxTotalBlobSize(ctx) for _, m := range tx.GetMsgs() { if pfb, ok := m.(*blobtypes.MsgPayForBlobs); ok { - if total := getTotal(pfb.BlobSizes); total > max { - return ctx, errors.Wrapf(blobtypes.ErrTotalBlobSizeTooLarge, "total blob size %d exceeds max %d", total, max) + if total := getTotal(pfb.BlobSizes); total > maximum { + return ctx, errors.Wrapf(blobtypes.ErrTotalBlobSizeTooLarge, "total blob size %d exceeds max %d", total, maximum) } } } diff --git a/x/mint/types/minter_test.go b/x/mint/types/minter_test.go index bafe19898b..6cd44e5821 100644 --- a/x/mint/types/minter_test.go +++ b/x/mint/types/minter_test.go @@ -156,14 +156,14 @@ func TestCalculateBlockProvisionError(t *testing.T) { } func randomBlockInterval() time.Duration { - min := (14 * time.Second).Nanoseconds() - max := (16 * time.Second).Nanoseconds() - return time.Duration(randInRange(min, max)) + minimum := (14 * time.Second).Nanoseconds() + maximum := (16 * time.Second).Nanoseconds() + return time.Duration(randInRange(minimum, maximum)) } // randInRange returns a random number in the range (min, max) inclusive. -func randInRange(min int64, max int64) int64 { - return rand.Int63n(max-min) + min +func randInRange(minimum int64, maximum int64) int64 { + return rand.Int63n(maximum-minimum) + minimum } func BenchmarkCalculateBlockProvision(b *testing.B) { From 6116a94f755e04eadc2b680b6e9c9bcb60bfb3a1 Mon Sep 17 00:00:00 2001 From: zwanga Date: Wed, 15 Jan 2025 23:26:25 +0200 Subject: [PATCH 5/6] fix: add seperate mebibyte constant in x/blob/ante/blob_share_decorator_test.go --- x/blob/ante/blob_share_decorator_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x/blob/ante/blob_share_decorator_test.go b/x/blob/ante/blob_share_decorator_test.go index 27de086ab1..95b0bba2f1 100644 --- a/x/blob/ante/blob_share_decorator_test.go +++ b/x/blob/ante/blob_share_decorator_test.go @@ -25,6 +25,7 @@ import ( const ( squareSize = 64 + mebibyte = 1_048_576 // bytes ) func TestBlobShareDecorator(t *testing.T) { @@ -41,7 +42,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "want no error if appVersion v1 and 8 MiB blob", blobsPerPFB: 1, - blobSize: 8 * testnode.Mebibyte, + blobSize: 8 * mebibyte, appVersion: v1.Version, }, { @@ -53,13 +54,13 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 MiB", blobsPerPFB: 1, - blobSize: 1 * testnode.Mebibyte, + blobSize: 1 * mebibyte, appVersion: v2.Version, }, { name: "PFB with 1 blob that is 2 MiB", blobsPerPFB: 1, - blobSize: 2 * testnode.Mebibyte, + blobSize: 2 * mebibyte, appVersion: v2.Version, // This test case should return an error because a square size of 64 // has exactly 2 MiB of total capacity so the total blob capacity @@ -75,7 +76,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 2 blobs that are 1 MiB each", blobsPerPFB: 2, - blobSize: 1 * testnode.Mebibyte, + blobSize: 1 * mebibyte, appVersion: v2.Version, // This test case should return an error for the same reason a // single blob that is 2 MiB returns an error. From 1114ebeff9bdb62efb562f8142d4b051250dee9e Mon Sep 17 00:00:00 2001 From: zwanga Date: Wed, 15 Jan 2025 23:37:33 +0200 Subject: [PATCH 6/6] chore: use Mebibyte seperately in ant_test package --- x/blob/ante/blob_share_decorator_test.go | 10 +++++----- x/blob/ante/max_total_blob_size_ante_test.go | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/x/blob/ante/blob_share_decorator_test.go b/x/blob/ante/blob_share_decorator_test.go index 95b0bba2f1..fb6801fa12 100644 --- a/x/blob/ante/blob_share_decorator_test.go +++ b/x/blob/ante/blob_share_decorator_test.go @@ -25,7 +25,7 @@ import ( const ( squareSize = 64 - mebibyte = 1_048_576 // bytes + Mebibyte = 1_048_576 // bytes ) func TestBlobShareDecorator(t *testing.T) { @@ -42,7 +42,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "want no error if appVersion v1 and 8 MiB blob", blobsPerPFB: 1, - blobSize: 8 * mebibyte, + blobSize: 8 * Mebibyte, appVersion: v1.Version, }, { @@ -54,13 +54,13 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 MiB", blobsPerPFB: 1, - blobSize: 1 * mebibyte, + blobSize: 1 * Mebibyte, appVersion: v2.Version, }, { name: "PFB with 1 blob that is 2 MiB", blobsPerPFB: 1, - blobSize: 2 * mebibyte, + blobSize: 2 * Mebibyte, appVersion: v2.Version, // This test case should return an error because a square size of 64 // has exactly 2 MiB of total capacity so the total blob capacity @@ -76,7 +76,7 @@ func TestBlobShareDecorator(t *testing.T) { { name: "PFB with 2 blobs that are 1 MiB each", blobsPerPFB: 2, - blobSize: 1 * mebibyte, + blobSize: 1 * Mebibyte, appVersion: v2.Version, // This test case should return an error for the same reason a // single blob that is 2 MiB returns an error. diff --git a/x/blob/ante/max_total_blob_size_ante_test.go b/x/blob/ante/max_total_blob_size_ante_test.go index 18089e7faa..fd20fcd66e 100644 --- a/x/blob/ante/max_total_blob_size_ante_test.go +++ b/x/blob/ante/max_total_blob_size_ante_test.go @@ -7,7 +7,6 @@ import ( "github.com/celestiaorg/celestia-app/v3/app/encoding" v1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" - "github.com/celestiaorg/celestia-app/v3/test/util/testnode" ante "github.com/celestiaorg/celestia-app/v3/x/blob/ante" blob "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/share" @@ -44,14 +43,14 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { { name: "PFB with 1 blob that is 1 MiB", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{testnode.Mebibyte}, + BlobSizes: []uint32{Mebibyte}, }, appVersion: v1.Version, }, { name: "PFB with 1 blob that is 2 MiB", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{2 * testnode.Mebibyte}, + BlobSizes: []uint32{2 * Mebibyte}, }, appVersion: v1.Version, // This test case should return an error because a square size of 64 @@ -69,7 +68,7 @@ func TestMaxTotalBlobSizeDecorator(t *testing.T) { { name: "PFB with 2 blobs that are 1 MiB each", pfb: &blob.MsgPayForBlobs{ - BlobSizes: []uint32{testnode.Mebibyte, testnode.Mebibyte}, + BlobSizes: []uint32{Mebibyte, Mebibyte}, }, appVersion: v1.Version, // This test case should return an error for the same reason a