-
Notifications
You must be signed in to change notification settings - Fork 4.1k
fix(grpc): return actual earliest_store_height in node.Status endpoint #25647
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
Open
Cordtus
wants to merge
4
commits into
cosmos:main
Choose a base branch
from
Cordtus:fix/earliest-store-height-upstream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+264
−16
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7369a4f
feat(store): implement EarliestVersion on CommitMultiStore
Cordtus 0df5ce9
feat(node): expose EarliestStoreHeight in Status gRPC endpoint
Cordtus 609ddf6
test(systemtests): add gRPC systemtest for node Status endpoint
Cordtus 3a3c034
Merge branch 'main' into fix/earliest-store-height-upstream
aljo242 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| //go:build system_test | ||
|
|
||
| package systemtests | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "path/filepath" | ||
| "strconv" | ||
| "testing" | ||
|
|
||
| "github.com/creachadair/tomledit" | ||
| "github.com/creachadair/tomledit/parser" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/credentials/insecure" | ||
|
|
||
| "cosmossdk.io/systemtests" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/client/grpc/node" | ||
| ) | ||
|
|
||
| // TestNodeStatusGRPC tests the Status gRPC endpoint to verify earliest_store_height. | ||
| func TestNodeStatusGRPC(t *testing.T) { | ||
| sut := systemtests.Sut | ||
| sut.ResetChain(t) | ||
| sut.StartChain(t) | ||
| sut.AwaitNBlocks(t, 3) | ||
|
|
||
| grpcAddr := fmt.Sprintf("localhost:%d", 9090) | ||
| conn, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
| require.NoError(t, err) | ||
| defer conn.Close() | ||
|
|
||
| queryClient := node.NewServiceClient(conn) | ||
|
|
||
| t.Run("returns valid store heights", func(t *testing.T) { | ||
| resp, err := queryClient.Status(context.Background(), &node.StatusRequest{}) | ||
| require.NoError(t, err) | ||
| t.Logf("Status response: earliest_store_height=%d, height=%d", resp.EarliestStoreHeight, resp.Height) | ||
|
|
||
| assert.GreaterOrEqual(t, resp.EarliestStoreHeight, uint64(1)) | ||
| assert.GreaterOrEqual(t, resp.Height, uint64(1)) | ||
| assert.GreaterOrEqual(t, resp.Height, resp.EarliestStoreHeight) | ||
| }) | ||
|
|
||
| t.Run("earliest stable on unpruned chain", func(t *testing.T) { | ||
| resp1, err := queryClient.Status(context.Background(), &node.StatusRequest{}) | ||
| require.NoError(t, err) | ||
| initial := resp1.EarliestStoreHeight | ||
|
|
||
| sut.AwaitNBlocks(t, 2) | ||
|
|
||
| resp2, err := queryClient.Status(context.Background(), &node.StatusRequest{}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, initial, resp2.EarliestStoreHeight) | ||
| }) | ||
| } | ||
|
|
||
| // TestNodeStatusWithStatePruning tests earliest_store_height increases with state pruning. | ||
| func TestNodeStatusWithStatePruning(t *testing.T) { | ||
| const pruningKeepRecent = 5 | ||
| const pruningInterval = 10 | ||
|
|
||
| sut := systemtests.Sut | ||
| sut.ResetChain(t) | ||
|
|
||
| // Configure state pruning | ||
| for i := 0; i < sut.NodesCount(); i++ { | ||
| appTomlPath := filepath.Join(sut.NodeDir(i), "config", "app.toml") | ||
| systemtests.EditToml(appTomlPath, func(doc *tomledit.Document) { | ||
| setNodeString(doc, "custom", "pruning") | ||
| setNodeString(doc, strconv.Itoa(pruningKeepRecent), "pruning-keep-recent") | ||
| setNodeString(doc, strconv.Itoa(pruningInterval), "pruning-interval") | ||
| }) | ||
| } | ||
|
|
||
| sut.StartChain(t) | ||
|
|
||
| grpcAddr := fmt.Sprintf("localhost:%d", 9090) | ||
| conn, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
| require.NoError(t, err) | ||
| defer conn.Close() | ||
|
|
||
| queryClient := node.NewServiceClient(conn) | ||
|
|
||
| resp, err := queryClient.Status(context.Background(), &node.StatusRequest{}) | ||
| require.NoError(t, err) | ||
| initialEarliest := resp.EarliestStoreHeight | ||
| t.Logf("Initial: earliest_store_height=%d, height=%d", initialEarliest, resp.Height) | ||
|
|
||
| // Wait for pruning to occur | ||
| blocksToWait := pruningInterval + pruningKeepRecent + 5 | ||
| t.Logf("Waiting %d blocks for state pruning...", blocksToWait) | ||
| sut.AwaitNBlocks(t, int64(blocksToWait)) | ||
|
|
||
| resp, err = queryClient.Status(context.Background(), &node.StatusRequest{}) | ||
| require.NoError(t, err) | ||
| t.Logf("After %d blocks: earliest_store_height=%d, height=%d", blocksToWait, resp.EarliestStoreHeight, resp.Height) | ||
|
|
||
| assert.Greater(t, resp.EarliestStoreHeight, initialEarliest, | ||
| "earliest_store_height should increase after pruning") | ||
| assert.GreaterOrEqual(t, resp.Height, resp.EarliestStoreHeight) | ||
| } | ||
|
|
||
| func setNodeString(doc *tomledit.Document, val string, xpath ...string) { | ||
| e := doc.First(xpath...) | ||
| if e == nil { | ||
| panic(fmt.Sprintf("not found: %v", xpath)) | ||
| } | ||
| e.Value = parser.MustValue(fmt.Sprintf("%q", val)) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is there a reason why we can't use the sdkCtx.MultiStore() to achieve this functionality?
Uh oh!
There was an error while loading. Please reload this page.
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.
Not that I know -- I can change it if that seems like a better way to go.
Edit: we would have to add a
ctx.EarliestHeight()to it first, which is more consistent but I guess more code as well. Which do you think is the better path?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.
can you explain why it would have to be a method on ctx?
Uh oh!
There was an error while loading. Please reload this page.
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.
It doesn't — my bad. I moved
EarliestVersion()fromMultiStoretoCommitMultiStoreinstead.The query context's
MultiStore()is an in-memoryCacheMultiStore— created inCreateQueryContextviaCacheMultiStoreWithVersion(height)with no reference to the root DB or its metadata.Placing it on
CommitMultiStoremeansCacheMultiStoredoesn't need to implement it at all and avoids a stub that just panics (likeLatestVersion()currently does onCacheMultiStore, which is the bad example I was following originally). This way the query/service receivesCommitMultiStoreat registration.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.
ok so if we go that route, we could just get EarliestHeight from ctx and then we don't have to pass around the cms? i'd prefer that