Skip to content

Commit 4c12e9b

Browse files
authored
Merge branch 'main' into issue-20630
2 parents 28d03fe + 3220aab commit 4c12e9b

296 files changed

Lines changed: 10048 additions & 3244 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
name: "${{ github.sha }}-e2e-coverage"
145145
path: ./tests/e2e-profile.out
146146

147-
test-system:
147+
test-system: # v2 system tests are in v2-test.yml
148148
runs-on: ubuntu-latest
149149
steps:
150150
- uses: actions/checkout@v4
@@ -183,16 +183,6 @@ jobs:
183183
name: "testnet-setup"
184184
path: ./systemtests/testnet/
185185
retention-days: 3
186-
- name: system tests v2
187-
if: env.GIT_DIFF
188-
run: |
189-
COSMOS_BUILD_OPTIONS=v2 make test-system
190-
- uses: actions/upload-artifact@v3
191-
if: failure()
192-
with:
193-
name: "testnet-setup"
194-
path: ./systemtests/testnet/
195-
retention-days: 3
196186

197187
repo-analysis:
198188
runs-on: ubuntu-latest

.github/workflows/v2-test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,43 @@ jobs:
109109
if: env.GIT_DIFF
110110
run: |
111111
cd server/v2/cometbft && go test -mod=readonly -race -timeout 30m -tags='ledger test_ledger_mock'
112+
113+
test-system-v2:
114+
runs-on: ubuntu-latest
115+
steps:
116+
- uses: actions/checkout@v4
117+
with:
118+
fetch-tags: true
119+
- uses: actions/setup-go@v5
120+
with:
121+
go-version: "1.23"
122+
check-latest: true
123+
cache: true
124+
cache-dependency-path: |
125+
simapp/v2/go.sum
126+
systemtest/go.sum
127+
- uses: technote-space/get-diff-action@v6.1.2
128+
id: git_diff
129+
with:
130+
PATTERNS: |
131+
**/*.go
132+
go.mod
133+
go.sum
134+
**/go.mod
135+
**/go.sum
136+
**/Makefile
137+
Makefile
138+
- name: Install musl lib for simd (docker) binary
139+
if: env.GIT_DIFF
140+
run: |
141+
sudo apt-get install -y musl
142+
- name: system tests v2
143+
if: env.GIT_DIFF
144+
run: |
145+
COSMOS_BUILD_OPTIONS=v2 make test-system
146+
- uses: actions/upload-artifact@v3
147+
if: failure()
148+
with:
149+
name: "testnet-setup"
150+
path: ./systemtests/testnet/
151+
retention-days: 3

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
5252

5353
### Improvements
5454

55+
* (crypto/ledger) [#22116](https://github.com/cosmos/cosmos-sdk/pull/22116) Improve error message when deriving paths using index >100
5556
* (sims) [#21613](https://github.com/cosmos/cosmos-sdk/pull/21613) Add sims2 framework and factory methods for simpler message factories in modules
5657
* (modules) [#21963](https://github.com/cosmos/cosmos-sdk/pull/21963) Duplicatable metrics are no more collected in modules. They were unecessary overhead.
5758

@@ -60,6 +61,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
6061
* (sims) [#21952](https://github.com/cosmos/cosmos-sdk/pull/21952) Use liveness matrix for validator sign status in sims
6162
* (sims) [#21906](https://github.com/cosmos/cosmos-sdk/pull/21906) Skip sims test when running dry on validators
6263
* (cli) [#21919](https://github.com/cosmos/cosmos-sdk/pull/21919) Query address-by-acc-num by account_id instead of id.
64+
* (baseapp) [#21003](https://github.com/cosmos/cosmos-sdk/pull/21003) Align block header when query with latest height.
6365

6466
### API Breaking Changes
6567

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ When extracting a package to its own go modules, some extra steps are required,
270270

271271
## Protobuf
272272

273-
We use [Protocol Buffers](https://developers.google.com/protocol-buffers) along with [gogoproto](https://github.com/cosmos/gogoproto) to generate code for use in Cosmos SDK.
273+
We use [Protocol Buffers](https://protobuf.dev) along with [gogoproto](https://github.com/cosmos/gogoproto) to generate code for use in Cosmos SDK.
274274

275-
For deterministic behavior around Protobuf tooling, everything is containerized using Docker. Make sure to have Docker installed on your machine, or head to [Docker's website](https://docs.docker.com/get-docker/) to install it.
275+
For deterministic behavior around Protobuf tooling, everything is containerized using Docker. Make sure to have Docker installed on your machine, or head to [Docker's website](https://docs.docker.com/get-started/get-docker/) to install it.
276276

277277
For formatting code in `.proto` files, you can run `make proto-format` command.
278278

api/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/cosmos/gogoproto v1.7.0
99
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142
1010
google.golang.org/grpc v1.67.1
11-
google.golang.org/protobuf v1.34.2
11+
google.golang.org/protobuf v1.35.1
1212
)
1313

1414
require (

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f h1:
2222
google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
2323
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
2424
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
25-
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
26-
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
25+
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
26+
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=

baseapp/abci.go

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"sort"
8+
"strconv"
89
"strings"
910
"time"
1011

@@ -142,7 +143,7 @@ func (app *BaseApp) Info(_ *abci.InfoRequest) (*abci.InfoResponse, error) {
142143
lastCommitID := app.cms.LastCommitID()
143144
appVersion := InitialAppVersion
144145
if lastCommitID.Version > 0 {
145-
ctx, err := app.CreateQueryContext(lastCommitID.Version, false)
146+
ctx, err := app.CreateQueryContextWithCheckHeader(lastCommitID.Version, false, false)
146147
if err != nil {
147148
return nil, fmt.Errorf("failed creating query context: %w", err)
148149
}
@@ -831,7 +832,7 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
831832
// NOTE: Not all raw transactions may adhere to the sdk.Tx interface, e.g.
832833
// vote extensions, so skip those.
833834
txResults := make([]*abci.ExecTxResult, 0, len(req.Txs))
834-
for _, rawTx := range req.Txs {
835+
for txIndex, rawTx := range req.Txs {
835836

836837
response := app.deliverTx(rawTx)
837838

@@ -843,6 +844,12 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
843844
// continue
844845
}
845846

847+
// append the tx index to the response.Events
848+
for i, event := range response.Events {
849+
response.Events[i].Attributes = append(event.Attributes,
850+
abci.EventAttribute{Key: "tx_index", Value: strconv.Itoa(txIndex)})
851+
}
852+
846853
txResults = append(txResults, response)
847854
}
848855

@@ -1215,6 +1222,12 @@ func checkNegativeHeight(height int64) error {
12151222
// CreateQueryContext creates a new sdk.Context for a query, taking as args
12161223
// the block height and whether the query needs a proof or not.
12171224
func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, error) {
1225+
return app.CreateQueryContextWithCheckHeader(height, prove, true)
1226+
}
1227+
1228+
// CreateQueryContextWithCheckHeader creates a new sdk.Context for a query, taking as args
1229+
// the block height, whether the query needs a proof or not, and whether to check the header or not.
1230+
func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, checkHeader bool) (sdk.Context, error) {
12181231
if err := checkNegativeHeight(height); err != nil {
12191232
return sdk.Context{}, err
12201233
}
@@ -1238,19 +1251,46 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
12381251
)
12391252
}
12401253

1241-
// when a client did not provide a query height, manually inject the latest
1242-
if height == 0 {
1243-
height = lastBlockHeight
1244-
}
1245-
1246-
if height <= 1 && prove {
1254+
if height > 0 && height <= 1 && prove {
12471255
return sdk.Context{},
12481256
errorsmod.Wrap(
12491257
sdkerrors.ErrInvalidRequest,
12501258
"cannot query with proof when height <= 1; please provide a valid height",
12511259
)
12521260
}
12531261

1262+
var header *cmtproto.Header
1263+
isLatest := height == 0
1264+
for _, state := range []*state{
1265+
app.checkState,
1266+
app.finalizeBlockState,
1267+
} {
1268+
if state != nil {
1269+
// branch the commit multi-store for safety
1270+
h := state.Context().BlockHeader()
1271+
if isLatest {
1272+
lastBlockHeight = qms.LatestVersion()
1273+
}
1274+
if !checkHeader || !isLatest || isLatest && h.Height == lastBlockHeight {
1275+
header = &h
1276+
break
1277+
}
1278+
}
1279+
}
1280+
1281+
if header == nil {
1282+
return sdk.Context{},
1283+
errorsmod.Wrapf(
1284+
sdkerrors.ErrInvalidHeight,
1285+
"header height in all state context is not latest height (%d)", lastBlockHeight,
1286+
)
1287+
}
1288+
1289+
// when a client did not provide a query height, manually inject the latest
1290+
if isLatest {
1291+
height = lastBlockHeight
1292+
}
1293+
12541294
cacheMS, err := qms.CacheMultiStoreWithVersion(height)
12551295
if err != nil {
12561296
return sdk.Context{},
@@ -1268,10 +1308,10 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
12681308
ChainID: app.chainID,
12691309
Height: height,
12701310
}).
1271-
WithBlockHeader(app.checkState.Context().BlockHeader()).
1311+
WithBlockHeader(*header).
12721312
WithBlockHeight(height)
12731313

1274-
if height != lastBlockHeight {
1314+
if !isLatest {
12751315
rms, ok := app.cms.(*rootmulti.Store)
12761316
if ok {
12771317
cInfo, err := rms.GetCommitInfo(height)
@@ -1280,7 +1320,6 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
12801320
}
12811321
}
12821322
}
1283-
12841323
return ctx, nil
12851324
}
12861325

baseapp/abci_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ func TestABCI_FinalizeBlock_DeliverTx(t *testing.T) {
676676

677677
events := res.TxResults[i].GetEvents()
678678
require.Len(t, events, 3, "should contain ante handler, message type and counter events respectively")
679-
require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0], events[0], "ante handler event")
679+
require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0].Attributes[0], events[0].Attributes[0], "ante handler event")
680680
require.Equal(t, sdk.MarkEventsToIndex(counterEvent(sdk.EventTypeMessage, counter).ToABCIEvents(), map[string]struct{}{})[0].Attributes[0], events[2].Attributes[0], "msg handler update counter event")
681681
}
682682

baseapp/baseapp.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,15 @@ func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) ([]abci.Event, erro
718718
ctx = ctx.WithBlockGasMeter(gasMeter)
719719
app.finalizeBlockState.SetContext(ctx)
720720
events = ctx.EventManager().ABCIEvents()
721+
722+
// append PreBlock attributes to all events
723+
for i, event := range events {
724+
events[i].Attributes = append(
725+
event.Attributes,
726+
abci.EventAttribute{Key: "mode", Value: "PreBlock"},
727+
abci.EventAttribute{Key: "event_index", Value: strconv.Itoa(i)},
728+
)
729+
}
721730
}
722731
return events, nil
723732
}
@@ -739,6 +748,7 @@ func (app *BaseApp) beginBlock(_ *abci.FinalizeBlockRequest) (sdk.BeginBlock, er
739748
resp.Events[i].Attributes = append(
740749
event.Attributes,
741750
abci.EventAttribute{Key: "mode", Value: "BeginBlock"},
751+
abci.EventAttribute{Key: "event_index", Value: strconv.Itoa(i)},
742752
)
743753
}
744754

@@ -801,6 +811,7 @@ func (app *BaseApp) endBlock(_ context.Context) (sdk.EndBlock, error) {
801811
eb.Events[i].Attributes = append(
802812
event.Attributes,
803813
abci.EventAttribute{Key: "mode", Value: "EndBlock"},
814+
abci.EventAttribute{Key: "event_index", Value: strconv.Itoa(i)},
804815
)
805816
}
806817

@@ -1151,6 +1162,12 @@ func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg, reflectMsg pr
11511162
}
11521163
}
11531164

1165+
// append the event_index attribute to all events
1166+
msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute("event_index", "0"))
1167+
for i, event := range events {
1168+
events[i] = event.AppendAttributes(sdk.NewAttribute("event_index", strconv.Itoa(i+1)))
1169+
}
1170+
11541171
return sdk.Events{msgEvent}.AppendEvents(events), nil
11551172
}
11561173

0 commit comments

Comments
 (0)