-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add custom build tags to override certain global variables #3897
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM: Consistent use of new constant in BeginBlock request. The change to use Consider refactoring the upgrade height calculation into a separate variable to improve code maintainability. For example: +upgradeHeight := initialHeight + appconsts.DefaultUpgradeHeightDelay
_ = testApp.BeginBlock(abci.RequestBeginBlock{
Header: tmproto.Header{
ChainID: genesis.ChainID,
- Height: initialHeight + appconsts.DefaultUpgradeHeightDelay,
+ Height: upgradeHeight,
Version: tmversion.Consensus{App: 3},
},
}) This refactoring would make it easier to update the upgrade height calculation in the future if needed.
|
||
Version: tmversion.Consensus{App: 3}, | ||
}, | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
Comment on lines
+55
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Function implementation needs improvement. The
Consider the following improvements:
Analysis chainFunction implementation needs improvement. The
Consider the following improvements:
Here's a suggested implementation: var ErrInvalidUpgradeHeightDelay = errors.New("invalid UpgradeHeightDelay value")
func UpgradeHeightDelay() (int64, error) {
if OverrideUpgradeHeightDelayStr != "" {
parsedValue, err := strconv.ParseInt(OverrideUpgradeHeightDelayStr, 10, 64)
if err != nil {
return 0, fmt.Errorf("%w: %s", ErrInvalidUpgradeHeightDelay, err)
}
if parsedValue < 0 {
return 0, fmt.Errorf("%w: value must be non-negative", ErrInvalidUpgradeHeightDelay)
}
return parsedValue, nil
}
return DefaultUpgradeHeightDelay, nil
} This approach provides better error handling and ensures the returned value is always non-negative. To ensure |
||
|
||
// HashLength returns the length of a hash in bytes. | ||
func HashLength() int { | ||
return hashLength | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Issue Found: The variable
Recommended Actions:
Analysis chainVerify the definition of OverrideSquareSizeUpperBoundStr The global variable Run the following script to check for the definition of If the variable is not found, it needs to be defined and documented properly. Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Search for the definition of OverrideSquareSizeUpperBoundStr
# Test: Look for the variable definition
rg --type go -A 5 $'var OverrideSquareSizeUpperBoundStr'
# If not found as a var, check for const definition
rg --type go -A 5 $'const OverrideSquareSizeUpperBoundStr'
# If still not found, search for any occurrence to see if it's defined differently
rg --type go $'OverrideSquareSizeUpperBoundStr'
Length of output: 503 |
||
parsedValue, err := strconv.Atoi(OverrideSquareSizeUpperBoundStr) | ||
if err != nil { | ||
panic("Invalid OverrideSquareSizeUpperBoundStr value") | ||
} | ||
return parsedValue | ||
} | ||
Comment on lines
+27
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider updating the function signature The function still takes an unused If the parameter is no longer needed, update the function signature: -func SquareSizeUpperBound(_ uint64) int {
+func SquareSizeUpperBound() int { If it's kept for backward compatibility, add a comment explaining this: // SquareSizeUpperBound imposes an upper bound on the max effective square size.
// The uint64 parameter is kept for backward compatibility but is no longer used.
func SquareSizeUpperBound(_ uint64) int {
// ... (rest of the function)
} Implement additional validation for the override value While the implementation allows for customizable upper bounds as intended, consider adding validation to ensure the parsed value is positive and within a reasonable range. This will prevent potential issues with extremely large or negative values. Consider modifying the function as follows: if OverrideSquareSizeUpperBoundStr != "" {
parsedValue, err := strconv.Atoi(OverrideSquareSizeUpperBoundStr)
- if err != nil {
- panic("Invalid OverrideSquareSizeUpperBoundStr value")
+ if err != nil || parsedValue <= 0 {
+ panic(fmt.Sprintf("Invalid OverrideSquareSizeUpperBoundStr value: %s. Must be a positive integer.", OverrideSquareSizeUpperBoundStr))
}
+ // Add an upper limit check if necessary, e.g.:
+ // if parsedValue > someMaxAllowedValue {
+ // panic(fmt.Sprintf("OverrideSquareSizeUpperBoundStr value too large: %d. Maximum allowed: %d", parsedValue, someMaxAllowedValue))
+ // }
return parsedValue
} This change will provide more informative error messages and ensure the override value is valid.
|
||
return v3.SquareSizeUpperBound | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,18 +41,24 @@ 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. | ||
func NewKeeper( | ||
binaryCodec codec.BinaryCodec, | ||
storeKey storetypes.StoreKey, | ||
stakingKeeper StakingKeeper, | ||
upgradeHeightDelayBlocks int64, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tip Codebase Verification Missing Several calls to
Analysis chainLGTM! Verify impact on keeper initialization. The changes to the To ensure that these changes don't break existing code, please verify all calls to Make sure to update all instances of Also applies to: 61-61 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Find all calls to NewKeeper and verify they include the new parameter
# Search for NewKeeper calls
rg --type go "NewKeeper\s*\(" -A 10
Length of output: 23733 |
||
) 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) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
Inconsistent
NewKeeper
Function Usage DetectedThe recent addition of a new parameter to the
NewKeeper
function inconfigurator_test.go
is not reflected consistently across the codebase. Several instances ofNewKeeper
are still being called without the new parameter, which could lead to potential issues.Please ensure all
NewKeeper
function calls are updated accordingly to maintain consistency.Analysis chain
LGTM, but consider adding more test cases.
The addition of the new parameter to
NewKeeper
aligns with the changes mentioned in the AI summary. This change likely relates to the PR objectives of adding customizable upper bounds.Consider adding more test cases that use different values for this new parameter to ensure the
Keeper
behaves correctly with various inputs.Let's verify if this change is consistent across the codebase:
Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 12876