diff --git a/Dockerfile b/Dockerfile index 050d45a306..2b504642db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,12 @@ ARG BUILDER_IMAGE=docker.io/golang:1.22.6-alpine3.19 ARG RUNTIME_IMAGE=docker.io/alpine:3.19 ARG TARGETOS ARG TARGETARCH +# Use build args to override the maxuimum square size of the docker image i.e. +# docker build --build-arg MAX_SQUARE_SIZE=64 -t celestia-app:latest . +ARG MAX_SQUARE_SIZE +# Use build args to override the upgrade height delay of the docker image i.e. +# docker build --build-arg UPGRADE_HEIGHT_DELAY=1000 -t celestia-app:latest . +ARG UPGRADE_HEIGHT_DELAY # Stage 1: Build the celestia-appd binary inside a builder image that will be discarded later. # Ignore hadolint rule because hadolint can't parse the variable. @@ -28,6 +34,8 @@ COPY . /celestia-app WORKDIR /celestia-app RUN uname -a &&\ CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + OVERRIDE_MAX_SQUARE_SIZE=${MAX_SQUARE_SIZE} \ + OVERRIDE_UPGRADE_HEIGHT_DELAY=${UPGRADE_HEIGHT_DELAY} \ make build # Stage 2: Create a minimal image to run the celestia-appd binary diff --git a/Makefile b/Makefile index d291c6d2b3..afe8520e2f 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,18 @@ PROJECTNAME=$(shell basename "$(PWD)") HTTPS_GIT := https://github.com/celestiaorg/celestia-app.git PACKAGE_NAME := github.com/celestiaorg/celestia-app/v3 GOLANG_CROSS_VERSION ?= v1.22.6 +# Set this to override the max square size of the binary +OVERRIDE_MAX_SQUARE_SIZE ?= +# Set this to override the upgrade height delay of the binary +OVERRIDE_UPGRADE_HEIGHT_DELAY ?= # process linker flags ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=celestia-app \ -X github.com/cosmos/cosmos-sdk/version.AppName=celestia-appd \ -X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \ -X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \ + -X github.com/celestiaorg/celestia-app/v3/pkg/appconsts.OverrideSquareSizeUpperBoundStr=$(OVERRIDE_MAX_SQUARE_SIZE) \ + -X github.com/celestiaorg/celestia-app/v3/pkg/appconsts.OverrideUpgradeHeightDelayStr=$(OVERRIDE_UPGRADE_HEIGHT_DELAY) BUILD_FLAGS := -tags "ledger" -ldflags '$(ldflags)' @@ -31,7 +37,7 @@ build: mod .PHONY: build ## install: Build and install the celestia-appd binary into the $GOPATH/bin directory. -install: go.sum check-bbr +install: check-bbr @echo "--> Installing celestia-appd" @go install $(BUILD_FLAGS) ./cmd/celestia-appd .PHONY: install diff --git a/app/app.go b/app/app.go index d31d33fcbf..ce44df0b2f 100644 --- a/app/app.go +++ b/app/app.go @@ -10,6 +10,7 @@ import ( celestiatx "github.com/celestiaorg/celestia-app/v3/app/grpc/tx" "github.com/celestiaorg/celestia-app/v3/app/module" "github.com/celestiaorg/celestia-app/v3/app/posthandler" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" appv1 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v1" appv2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" appv3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" @@ -279,7 +280,7 @@ func New( ), ) - app.SignalKeeper = signal.NewKeeper(appCodec, keys[signaltypes.StoreKey], app.StakingKeeper) + app.SignalKeeper = signal.NewKeeper(appCodec, keys[signaltypes.StoreKey], app.StakingKeeper, appconsts.UpgradeHeightDelay()) app.IBCKeeper = ibckeeper.NewKeeper( appCodec, diff --git a/app/module/configurator_test.go b/app/module/configurator_test.go index a93713938a..ed504c9ac3 100644 --- a/app/module/configurator_test.go +++ b/app/module/configurator_test.go @@ -37,7 +37,7 @@ func TestConfigurator(t *testing.T) { stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) require.NoError(t, stateStore.LoadLatestVersion()) - keeper := signal.NewKeeper(config.Codec, storeKey, nil) + keeper := signal.NewKeeper(config.Codec, storeKey, nil, 0) require.NotNil(t, keeper) upgradeModule := signal.NewAppModule(keeper) manager, err := module.NewManager([]module.VersionedModule{ diff --git a/app/test/upgrade_test.go b/app/test/upgrade_test.go index 459a33aefc..ab188e01ac 100644 --- a/app/test/upgrade_test.go +++ b/app/test/upgrade_test.go @@ -17,7 +17,6 @@ import ( "github.com/celestiaorg/celestia-app/v3/test/util/testnode" blobstreamtypes "github.com/celestiaorg/celestia-app/v3/x/blobstream/types" "github.com/celestiaorg/celestia-app/v3/x/minfee" - "github.com/celestiaorg/celestia-app/v3/x/signal" signaltypes "github.com/celestiaorg/celestia-app/v3/x/signal/types" "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/go-square/v2/tx" @@ -99,7 +98,7 @@ func TestAppUpgradeV3(t *testing.T) { // brace yourselfs, this part may take a while initialHeight := int64(4) - for height := initialHeight; height < initialHeight+signal.DefaultUpgradeHeightDelay; height++ { + for height := initialHeight; height < initialHeight+appconsts.DefaultUpgradeHeightDelay; height++ { _ = testApp.BeginBlock(abci.RequestBeginBlock{ Header: tmproto.Header{ Height: height, @@ -108,7 +107,7 @@ func TestAppUpgradeV3(t *testing.T) { }) endBlockResp = testApp.EndBlock(abci.RequestEndBlock{ - Height: 3 + signal.DefaultUpgradeHeightDelay, + Height: 3 + appconsts.DefaultUpgradeHeightDelay, }) _ = testApp.Commit() @@ -130,7 +129,7 @@ func TestAppUpgradeV3(t *testing.T) { _ = testApp.BeginBlock(abci.RequestBeginBlock{ Header: tmproto.Header{ ChainID: genesis.ChainID, - Height: initialHeight + signal.DefaultUpgradeHeightDelay, + Height: initialHeight + appconsts.DefaultUpgradeHeightDelay, Version: tmversion.Consensus{App: 3}, }, }) diff --git a/pkg/appconsts/global_consts.go b/pkg/appconsts/global_consts.go index 340f651840..2903da0414 100644 --- a/pkg/appconsts/global_consts.go +++ b/pkg/appconsts/global_consts.go @@ -1,6 +1,8 @@ package appconsts import ( + "strconv" + "github.com/celestiaorg/go-square/v2/share" "github.com/celestiaorg/rsmt2d" "github.com/tendermint/tendermint/pkg/consts" @@ -24,6 +26,11 @@ const ( // BondDenom defines the native staking denomination BondDenom = "utia" + + // DefaultUpgradeHeightDelay is the number of blocks after a quorum has been + // reached that the chain should upgrade to the new version. Assuming a block + // interval of 12 seconds, this is 7 days. + DefaultUpgradeHeightDelay = int64(7 * 24 * 60 * 60 / 12) // 7 days * 24 hours * 60 minutes * 60 seconds / 12 seconds per block = 50,400 blocks. ) var ( @@ -44,6 +51,18 @@ var ( SupportedShareVersions = share.SupportedShareVersions ) +// returns the delay in blocks after a quorum has been reached that the chain should upgrade to the new version. +func UpgradeHeightDelay() int64 { + if OverrideUpgradeHeightDelayStr != "" { + parsedValue, err := strconv.ParseInt(OverrideUpgradeHeightDelayStr, 10, 64) + if err != nil { + panic("Invalid OverrideUpgradeHeightDelayStr value") + } + return parsedValue + } + return DefaultUpgradeHeightDelay +} + // HashLength returns the length of a hash in bytes. func HashLength() int { return hashLength diff --git a/pkg/appconsts/overrides.go b/pkg/appconsts/overrides.go new file mode 100644 index 0000000000..39c5f4c6d0 --- /dev/null +++ b/pkg/appconsts/overrides.go @@ -0,0 +1,10 @@ +package appconsts + +// Set of values that can be overridden at compile time to modify the behavior of the app. +// WARNING: This should only be modified for testing purposes. All nodes in a network +// must have the same values for these constants. +// Look at the Makefile to see how these are set. +var ( + OverrideSquareSizeUpperBoundStr string + OverrideUpgradeHeightDelayStr string +) diff --git a/pkg/appconsts/versioned_consts.go b/pkg/appconsts/versioned_consts.go index 7bb1088a8b..c5ffb952a6 100644 --- a/pkg/appconsts/versioned_consts.go +++ b/pkg/appconsts/versioned_consts.go @@ -1,6 +1,8 @@ package appconsts import ( + "strconv" + v3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" ) @@ -22,6 +24,13 @@ func SubtreeRootThreshold(_ uint64) int { // SquareSizeUpperBound imposes an upper bound on the max effective square size. func SquareSizeUpperBound(_ uint64) int { + if OverrideSquareSizeUpperBoundStr != "" { + parsedValue, err := strconv.Atoi(OverrideSquareSizeUpperBoundStr) + if err != nil { + panic("Invalid OverrideSquareSizeUpperBoundStr value") + } + return parsedValue + } return v3.SquareSizeUpperBound } diff --git a/x/signal/integration_test.go b/x/signal/integration_test.go index fb016e0813..23b8158dd2 100644 --- a/x/signal/integration_test.go +++ b/x/signal/integration_test.go @@ -4,9 +4,9 @@ import ( "testing" "github.com/celestiaorg/celestia-app/v3/app" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2" testutil "github.com/celestiaorg/celestia-app/v3/test/util" - "github.com/celestiaorg/celestia-app/v3/x/signal" "github.com/celestiaorg/celestia-app/v3/x/signal/types" "github.com/stretchr/testify/require" @@ -77,7 +77,7 @@ func TestUpgradeIntegration(t *testing.T) { require.False(t, shouldUpgrade) require.EqualValues(t, 0, version) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + signal.DefaultUpgradeHeightDelay) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + appconsts.DefaultUpgradeHeightDelay) shouldUpgrade, version = app.SignalKeeper.ShouldUpgrade(ctx) require.True(t, shouldUpgrade) diff --git a/x/signal/keeper.go b/x/signal/keeper.go index ed280c67f4..0a23d93119 100644 --- a/x/signal/keeper.go +++ b/x/signal/keeper.go @@ -12,11 +12,6 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) -// DefaultUpgradeHeightDelay is the number of blocks after a quorum has been -// reached that the chain should upgrade to the new version. Assuming a block -// interval of 12 seconds, this is 7 days. -const DefaultUpgradeHeightDelay = int64(7 * 24 * 60 * 60 / 12) // 7 days * 24 hours * 60 minutes * 60 seconds / 12 seconds per block = 50,400 blocks. - // Keeper implements the MsgServer and QueryServer interfaces var ( _ types.MsgServer = &Keeper{} @@ -46,6 +41,10 @@ type Keeper struct { // stakingKeeper is used to fetch validators to calculate the total power // signalled to a version. stakingKeeper StakingKeeper + + // upgradeHeightDelayBlocks is the number of blocks after a quorum has been + // reached that the chain should upgrade to the new version + upgradeHeightDelayBlocks int64 } // NewKeeper returns a signal keeper. @@ -53,11 +52,13 @@ func NewKeeper( binaryCodec codec.BinaryCodec, storeKey storetypes.StoreKey, stakingKeeper StakingKeeper, + upgradeHeightDelayBlocks int64, ) Keeper { return Keeper{ - binaryCodec: binaryCodec, - storeKey: storeKey, - stakingKeeper: stakingKeeper, + binaryCodec: binaryCodec, + storeKey: storeKey, + stakingKeeper: stakingKeeper, + upgradeHeightDelayBlocks: upgradeHeightDelayBlocks, } } @@ -108,7 +109,7 @@ func (k *Keeper) TryUpgrade(ctx context.Context, _ *types.MsgTryUpgrade) (*types } upgrade := types.Upgrade{ AppVersion: version, - UpgradeHeight: sdkCtx.BlockHeader().Height + DefaultUpgradeHeightDelay, + UpgradeHeight: sdkCtx.BlockHeader().Height + k.upgradeHeightDelayBlocks, } k.setUpgrade(sdkCtx, upgrade) } diff --git a/x/signal/keeper_test.go b/x/signal/keeper_test.go index a476562696..71627a8417 100644 --- a/x/signal/keeper_test.go +++ b/x/signal/keeper_test.go @@ -12,6 +12,7 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" 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/x/signal" @@ -68,7 +69,7 @@ func TestGetVotingPowerThreshold(t *testing.T) { t.Run(tc.name, func(t *testing.T) { config := encoding.MakeConfig(app.ModuleEncodingRegisters...) stakingKeeper := newMockStakingKeeper(tc.validators) - k := signal.NewKeeper(config.Codec, nil, stakingKeeper) + k := signal.NewKeeper(config.Codec, nil, stakingKeeper, appconsts.DefaultUpgradeHeightDelay) got := k.GetVotingPowerThreshold(sdk.Context{}) assert.Equal(t, tc.want, got, fmt.Sprintf("want %v, got %v", tc.want.String(), got.String())) }) @@ -182,7 +183,7 @@ func TestTallyingLogic(t *testing.T) { require.False(t, shouldUpgrade) // should be false because upgrade height hasn't been reached. require.Equal(t, uint64(0), version) - ctx = ctx.WithBlockHeight(ctx.BlockHeight() + signal.DefaultUpgradeHeightDelay) + ctx = ctx.WithBlockHeight(ctx.BlockHeight() + appconsts.DefaultUpgradeHeightDelay) shouldUpgrade, version = upgradeKeeper.ShouldUpgrade(ctx) require.True(t, shouldUpgrade) // should be true because upgrade height has been reached. @@ -425,7 +426,7 @@ func TestGetUpgrade(t *testing.T) { got, err := upgradeKeeper.GetUpgrade(ctx, &types.QueryGetUpgradeRequest{}) require.NoError(t, err) assert.Equal(t, v2.Version, got.Upgrade.AppVersion) - assert.Equal(t, signal.DefaultUpgradeHeightDelay, got.Upgrade.UpgradeHeight) + assert.Equal(t, appconsts.DefaultUpgradeHeightDelay, got.Upgrade.UpgradeHeight) }) } @@ -451,7 +452,7 @@ func setup(t *testing.T) (signal.Keeper, sdk.Context, *mockStakingKeeper) { ) config := encoding.MakeConfig(app.ModuleEncodingRegisters...) - upgradeKeeper := signal.NewKeeper(config.Codec, signalStore, mockStakingKeeper) + upgradeKeeper := signal.NewKeeper(config.Codec, signalStore, mockStakingKeeper, appconsts.DefaultUpgradeHeightDelay) return upgradeKeeper, mockCtx, mockStakingKeeper }